[cfe-commits] r66442 - in /cfe/trunk: lib/Lex/MacroInfo.cpp test/Preprocessor/macro_misc.c
Chris Lattner
sabre at nondot.org
Mon Mar 9 13:33:33 PDT 2009
Author: lattner
Date: Mon Mar 9 15:33:32 2009
New Revision: 66442
URL: http://llvm.org/viewvc/llvm-project?rev=66442&view=rev
Log:
fix PR3764 - A redefinition of a pre-processor macro fails
Redefinition checking should ignore the leading whitespace and
start of line flags on the first token of an expansion.
Modified:
cfe/trunk/lib/Lex/MacroInfo.cpp
cfe/trunk/test/Preprocessor/macro_misc.c
Modified: cfe/trunk/lib/Lex/MacroInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=66442&r1=66441&r2=66442&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/MacroInfo.cpp (original)
+++ cfe/trunk/lib/Lex/MacroInfo.cpp Mon Mar 9 15:33:32 2009
@@ -49,9 +49,14 @@
for (unsigned i = 0, e = ReplacementTokens.size(); i != e; ++i) {
const Token &A = ReplacementTokens[i];
const Token &B = Other.ReplacementTokens[i];
- if (A.getKind() != B.getKind() ||
- A.isAtStartOfLine() != B.isAtStartOfLine() ||
- A.hasLeadingSpace() != B.hasLeadingSpace())
+ if (A.getKind() != B.getKind())
+ return false;
+
+ // If this isn't the first first token, check that the whitespace and
+ // start-of-line characteristics match.
+ if (i != 0 &&
+ (A.isAtStartOfLine() != B.isAtStartOfLine() ||
+ A.hasLeadingSpace() != B.hasLeadingSpace()))
return false;
// If this is an identifier, it is easy.
Modified: cfe/trunk/test/Preprocessor/macro_misc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_misc.c?rev=66442&r1=66441&r2=66442&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_misc.c (original)
+++ cfe/trunk/test/Preprocessor/macro_misc.c Mon Mar 9 15:33:32 2009
@@ -4,3 +4,20 @@
#ifdef defined
#endif
+
+
+// PR3764
+
+// This should not produce a redefinition warning.
+#define FUNC_LIKE(a) (a)
+#define FUNC_LIKE(a)(a)
+
+// This either.
+#define FUNC_LIKE2(a)\
+(a)
+#define FUNC_LIKE2(a) (a)
+
+// This should.
+#define FUNC_LIKE3(a) ( a) // expected-note {{previous definition is here}}
+#define FUNC_LIKE3(a) (a) // expected-warning {{'FUNC_LIKE3' macro redefined}}
+
More information about the cfe-commits
mailing list