Skip to content

Commit 3f568c1

Browse files
committed
Patch for handling C99 veriadic macros when using precompiled headers,
from Filipe Cabecinhas! llvm-svn: 159446
1 parent 4a031bd commit 3f568c1

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

clang/lib/Lex/Preprocessor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,19 @@ void Preprocessor::HandleIdentifier(Token &Identifier) {
515515

516516
// If the information about this identifier is out of date, update it from
517517
// the external source.
518+
// We have to treat __VA_ARGS__ in a special way, since it gets
519+
// serialized with isPoisoned = true, but our preprocessor may have
520+
// unpoisoned it if we're defining a C99 macro.
518521
if (II.isOutOfDate()) {
522+
bool CurrentIsPoisoned = false;
523+
if (&II == Ident__VA_ARGS__)
524+
CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
525+
519526
ExternalSource->updateOutOfDateIdentifier(II);
520527
Identifier.setKind(II.getTokenID());
528+
529+
if (&II == Ident__VA_ARGS__)
530+
II.setIsPoisoned(CurrentIsPoisoned);
521531
}
522532

523533
// If this identifier was poisoned, and if it was not produced from a macro

clang/test/PCH/pch__VA_ARGS__.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Test with pch.
2+
// RUN: %clang_cc1 -emit-pch -o %t %S/pch__VA_ARGS__.h
3+
// RUN: %clang_cc1 -include-pch %t -fsyntax-only -Weverything %s 2>&1 | FileCheck %s
4+
5+
#define mylog(...) printf(__VA_ARGS__)
6+
// CHECK-NOT: warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro

clang/test/PCH/pch__VA_ARGS__.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Header for PCH test fuzzy-pch.c
2+
void f(int X);

0 commit comments

Comments
 (0)