[cfe-dev] Disable Header Search Option and errors related to it

Sean Silva silvas at purdue.edu
Tue Jul 10 01:52:12 PDT 2012


Just ran into this today :)

The builtins are not getting registered. Use

    Preprocessor &PP = CI.getPreprocessor();
    PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
                                           PP.getLangOpts());

Check out FrontendAction::BeginSourceFile in
lib/Frontend/FrontendAction.cpp for some of the other setup that makes
clang behave "as usual".

> So I require my code to be made such that it should skip validating
> the includes and process the file.
This is not really possible, unfortunately. It is literally impossible
to correctly parse C++ without knowing all the types and other
declarations (which come from the headers). So unless your source file
doesn't use anything from the header (if so, why does it include it in
the first place?), you *have* to deal with the includes. You might
find HeaderSearchOptions::UseBuiltinIncludes,
HeaderSearchOptions::UseStandardSystemIncludes, and
HeaderSearchOptions::UseStandardCXXIncludes helpful. The logic for
finding the "default" includes is in lib/Frontend/InitHeaderSearch.cpp

--Sean Silva

On Tue, Jul 10, 2012 at 12:12 AM, Satya Prakash Prasad
<satyaprakash.prasad at gmail.com> wrote:
> My issue is that when my program tries to keep including header files
> it gives issues which I cannot resolve. Like as mentioned below:
>
>     HeaderSearchOptions &HS = TheCompInst.getHeaderSearchOpts();
>     HS.AddPath("/usr/include/c++/4.1.2/backward/", frontend::Angled,
> true, false, true);
>     HS.AddPath("/usr/include/c++/4.1.2/", frontend::Angled, true, false, true);
>     HS.AddPath("/usr/include/c++/", frontend::Angled, true, false, true);
>     HS.AddPath("/usr/include/", frontend::Angled, true, false, true);
>     HS.AddPath("/usr/include/linux/", frontend::Angled, true, false, true);
>     HS.AddPath("/x/local/satprasad/gcc-4.1.2/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.1.2/include/",
> frontend::Angled, true, false, true);
>     HS.AddPath("/usr/include/c++/4.1.1/", frontend::Angled, true, false, true);
>     HS.AddPath("/usr/include/c++/4.1.1/x86_64-redhat-linux/",
> frontend::Angled, true, false, true);
>
>
> When I run the program to parse a .cpp file which has multiple
> #include directive I get below error:
> ……………………………………………………………………………………………………………
> /usr/include/c++/4.1.2/limits:1013:16: error: use of undeclared
> identifier '__builtin_huge_valf'
>       { return __builtin_huge_valf (); }
>                ^
> /usr/include/c++/4.1.2/limits:1015:16: error: use of undeclared
> identifier '__builtin_nanf'
>       { return __builtin_nanf (""); }
>                ^
> /usr/include/c++/4.1.2/limits:1017:16: error: use of undeclared
> identifier '__builtin_nansf'
>       { return __builtin_nansf (""); }
>                ^
> /usr/include/c++/4.1.2/limits:1070:16: error: use of undeclared
> identifier '__builtin_huge_val'
>       { return __builtin_huge_val(); }
>                ^
> /usr/include/c++/4.1.2/limits:1072:16: error: use of undeclared
> identifier '__builtin_nan'
>       { return __builtin_nan (""); }
>                ^
> /usr/include/c++/4.1.2/limits:1074:16: error: use of undeclared
> identifier '__builtin_nans'
>       { return __builtin_nans (""); }
>                ^
> /usr/include/c++/4.1.2/limits:1128:16: error: use of undeclared
> identifier '__builtin_huge_vall'
>       { return __builtin_huge_vall (); }
>                ^
> /usr/include/c++/4.1.2/limits:1130:16: error: use of undeclared
> identifier '__builtin_nanl'
>       { return __builtin_nanl (""); }
>                ^
> /usr/include/c++/4.1.2/limits:1132:16: error: use of undeclared
> identifier '__builtin_nansl'
>       { return __builtin_nansl (""); }
>                ^
> Stack dump:
> 0.      /usr/include/c++/4.1.2/memory:61:1: current parser token 'namespace'
> Segmentation fault
>
> After rectifying a few I still get many of those.
>
> Since my program is to process statements of an input .cpp file - i am
> not in need to really include header files and do validation a)
> whether it is there or not in system path b)if all declarations are
> there
>
> So I require my code to be made such that it should skip validating
> the includes and process the file. When I comment the HeaderSearch
> Option I get :
>
> W.cpp:1:10: fatal error: 'system/Tools.h' file not found
> #include "system/Tools.h"
>              ^
> The program runs via a command line
>
> rewrite test.cpp
>
> And the program logic breaks.
>
> Please advise how can I overrule these header search options?
>
> Thanks in advance.
>
> Regards,
> Prakash
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list