From 193f91ba7ed28709a1e730aedb3582353f9075d0 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 29 Jun 2012 18:27:59 +0000 Subject: [PATCH] Patch for handling C99 veriadic macros when using precompiled headers, from Filipe Cabecinhas! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159446 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/Preprocessor.cpp | 10 ++++++++++ test/PCH/pch__VA_ARGS__.c | 6 ++++++ test/PCH/pch__VA_ARGS__.h | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 test/PCH/pch__VA_ARGS__.c create mode 100644 test/PCH/pch__VA_ARGS__.h diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 70be2cf7a6..c699c4a790 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -515,9 +515,19 @@ void Preprocessor::HandleIdentifier(Token &Identifier) { // If the information about this identifier is out of date, update it from // the external source. + // We have to treat __VA_ARGS__ in a special way, since it gets + // serialized with isPoisoned = true, but our preprocessor may have + // unpoisoned it if we're defining a C99 macro. if (II.isOutOfDate()) { + bool CurrentIsPoisoned = false; + if (&II == Ident__VA_ARGS__) + CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned(); + ExternalSource->updateOutOfDateIdentifier(II); Identifier.setKind(II.getTokenID()); + + if (&II == Ident__VA_ARGS__) + II.setIsPoisoned(CurrentIsPoisoned); } // If this identifier was poisoned, and if it was not produced from a macro diff --git a/test/PCH/pch__VA_ARGS__.c b/test/PCH/pch__VA_ARGS__.c new file mode 100644 index 0000000000..9bc1d3c66b --- /dev/null +++ b/test/PCH/pch__VA_ARGS__.c @@ -0,0 +1,6 @@ +// Test with pch. +// RUN: %clang_cc1 -emit-pch -o %t %S/pch__VA_ARGS__.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -Weverything %s 2>&1 | FileCheck %s + +#define mylog(...) printf(__VA_ARGS__) +// CHECK-NOT: warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro diff --git a/test/PCH/pch__VA_ARGS__.h b/test/PCH/pch__VA_ARGS__.h new file mode 100644 index 0000000000..9eb1005ce4 --- /dev/null +++ b/test/PCH/pch__VA_ARGS__.h @@ -0,0 +1,2 @@ +// Header for PCH test fuzzy-pch.c +void f(int X); -- 2.50.1