versioner: compile headers in both C and C++ mode.
Bug: https://github.com/android-ndk/ndk/issues/440
Test: python run_tests.py
Change-Id: Ib572a8fdcc00f6b88a25003a085b16ce9698d692
diff --git a/tools/versioner/src/DeclarationDatabase.cpp b/tools/versioner/src/DeclarationDatabase.cpp
index 33bccf3..4443834 100644
--- a/tools/versioner/src/DeclarationDatabase.cpp
+++ b/tools/versioner/src/DeclarationDatabase.cpp
@@ -35,6 +35,22 @@
using namespace clang;
+static bool shouldMangle(MangleContext* mangler, NamedDecl* decl) {
+ // Passing a decl with static linkage to the mangler gives incorrect results.
+ // Check some things ourselves before handing it off to the mangler.
+ if (auto FD = dyn_cast<FunctionDecl>(decl)) {
+ if (FD->isExternC()) {
+ return false;
+ }
+
+ if (FD->isInExternCContext()) {
+ return false;
+ }
+ }
+
+ return mangler->shouldMangleDeclName(decl);
+}
+
class Visitor : public RecursiveASTVisitor<Visitor> {
HeaderDatabase& database;
CompilationType type;
@@ -61,7 +77,7 @@
// The decl might not have a name (e.g. bitfields).
if (auto identifier = decl->getIdentifier()) {
- if (mangler->shouldMangleDeclName(decl)) {
+ if (shouldMangle(mangler.get(), decl)) {
std::string mangled;
llvm::raw_string_ostream ss(mangled);
mangler->mangleName(decl, ss);