[cfe-dev] Undeclared builtin identifiers in C++
Oscar Neilson
on502 at york.ac.uk
Fri Feb 11 10:35:30 PST 2011
Hi all,
I'm trying to use clang to parse a simple C++ file, using the
tutorials from https://github.com/loarabia/Clang-tutorial as my guide.
With files that use standard library types I get errors about
undeclared builtin identifiers:
------------------------------------------------------------
In file included from test.cpp:1:
In file included from
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4/vector:61:
In file included from
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4/bits/allocator.h:48:
In file included from
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4/x86_64-pc-linux-gnu/bits/c++allocator.h:34:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4/ext/new_allocator.h:86:6:
error: use of undeclared identifier '__builtin_expect'
if (__builtin_expect(__n > this->max_size(), false))
^
------------------------------------------------------------
I've seen some threads where people have similar problems but haven't
found a solution. Does anyone have any suggestions as to what I'm
missing? Some code snippets to show what I'm currently doing:
------------------------------------------------------------
clang::LangOptions languageOptions;
clang::CompilerInvocation::setLangDefaults(languageOptions,
clang::IK_CXX);
...
clang::HeaderSearch headerSearch(fileManager);
clang::HeaderSearchOptions headerSearchOptions;
headerSearchOptions.ResourceDir = LLVM_PREFIX "/lib/clang/"
CLANG_VERSION_STRING;
clang::ApplyHeaderSearchOptions(headerSearch,
headerSearchOptions,
languageOptions,
targetInfo->getTriple());
...
clang::Builtin::Context builtinContext(*targetInfo);
builtinContext.InitializeBuiltins(identifierTable, languageOptions);
------------------------------------------------------------
If I populate a vector with all the builtin names:
------------------------------------------------------------
llvm::SmallVector<const char *, 32> builtinNames;
builtinContext.GetBuiltinNames(builtinNames, languageOptions.NoBuiltin);
------------------------------------------------------------
Then there is an entry for __builtin_expect.
Thanks,
Oscar
More information about the cfe-dev
mailing list