Dear All,
I’m trying to add a command line option to Clang/Clang++.I want to let clang do the actions coresponding to the new command option.
What I have done is that I have modified the driver of Clang, including the “Dirver.cpp” ,“options.td”, “Tools.cpp” and “Action.cpp”.
But the compilation instance( namely Clang cc1) of Clang cannot identify the new option. And the console prints the ERROR:" unsupported argumnet". Perhaps, I should modified the Clang cc1 to make it be albe to accept the new option. But I don’t know how to deal with the “Clang cc1”.
what’s more, when I have add the new command line argumnet to the “CC1Options.td”, the console prints the “ast infomation”(in my opinion) of the source File. I have no idea about the reason.
Thanks in advance.
----Redder.
I can recommend doing a global search of all Clang files for an existing option, try the one for Objective-C rewriting. Then you can see all the files you need to change to add new option.
Did you get my email answering this question? If so, was there something unclear in my response?
My original response is archived here: . Modifying CC1Options.td will add a new command-line option to Clang’s cc1. However, that isn’t enough: you have to modify Clang to pass the new option to cc1 when it appears on the clang command line (that is the change in lib/Drivers/Tools.cpp). You also need to modify cc1 to do whatever it is you want to do when it sees that command line option. In the case of the SAFECode patch, that change (or part of it) is in lib/CodeGen/BackendUtil.cpp (if I remember the filenames correctly). – John T.
Hi all.
I too, encountered problems adding a command line options:
I added my option both to Options.td and to CC1Options.td, but since this
option is an analyzer option, I am trying to copy it into the analyzer
options in CompilerInvocation::ParseAnalyzerArgs.
To do that, I need to read it from the general ArgList, for which I need an
OptSpecifier.
I see that the clangdriver.pdb binary has this OPT_my_option in it, but I
still cannot compile my CompilerInvocation class.
BTW, the link in John's replay isn't working.
Regards, Yuval.
Yuval,
Have you tried using -analyzer-config options instead of adding a higher level option for the analyzer? We’ve recently added this mechanism and plan to make all analyzer options go through analyzer-config.
All you need to do is add the supporting code to AnalyzerOptions.h and AnalyzerOptions.cpp. For example, we’ve added “-analyzer-config max-times-inline-large=xx” option as part of r170361.
Anna.