[cfe-commits] r168268 - in /cfe/trunk: lib/Lex/PPMacroExpansion.cpp test/Preprocessor/feature_tests.c
Andy Gibbs
andyg1001 at hotmail.co.uk
Sat Nov 17 11:18:27 PST 2012
Author: andyg
Date: Sat Nov 17 13:18:27 2012
New Revision: 168268
URL: http://llvm.org/viewvc/llvm-project?rev=168268&view=rev
Log:
Prevent premature macro expansion in __has_builtin, __has_feature,
__has_attribute, __has_extension, making them behave more akin to
conventional macros.
Modified:
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/test/Preprocessor/feature_tests.c
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=168268&r1=168267&r2=168268&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sat Nov 17 13:18:27 2012
@@ -1228,15 +1228,15 @@
IdentifierInfo *FeatureII = 0;
// Read the '('.
- Lex(Tok);
+ LexUnexpandedToken(Tok);
if (Tok.is(tok::l_paren)) {
// Read the identifier
- Lex(Tok);
+ LexUnexpandedToken(Tok);
if (Tok.is(tok::identifier) || Tok.is(tok::kw_const)) {
FeatureII = Tok.getIdentifierInfo();
// Read the ')'.
- Lex(Tok);
+ LexUnexpandedToken(Tok);
if (Tok.is(tok::r_paren))
IsValid = true;
}
Modified: cfe/trunk/test/Preprocessor/feature_tests.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/feature_tests.c?rev=168268&r1=168267&r2=168268&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/feature_tests.c (original)
+++ cfe/trunk/test/Preprocessor/feature_tests.c Sat Nov 17 13:18:27 2012
@@ -32,3 +32,23 @@
__has_builtin(__builtin_altivec_abs_v4sf)
#error Broken handling of target-specific builtins
#endif
+
+// Macro expansion does not occur in the parameter to __has_builtin,
+// __has_feature, etc. (as is also expected behaviour for ordinary
+// macros), so the following should not expand:
+
+#define MY_ALIAS_BUILTIN __c11_atomic_init
+#define MY_ALIAS_FEATURE attribute_overloadable
+
+#if __has_builtin(MY_ALIAS_BUILTIN) || __has_feature(MY_ALIAS_FEATURE)
+#error Alias expansion not allowed
+#endif
+
+// But deferring should expand:
+
+#define HAS_BUILTIN(X) __has_builtin(X)
+#define HAS_FEATURE(X) __has_feature(X)
+
+#if !HAS_BUILTIN(MY_ALIAS_BUILTIN) || !HAS_FEATURE(MY_ALIAS_FEATURE)
+#error Expansion should have occurred
+#endif
More information about the cfe-commits
mailing list