[cfe-commits] r151809 - in /cfe/trunk: docs/LanguageExtensions.html lib/Lex/PPMacroExpansion.cpp test/Preprocessor/has_attribute.c
Jean-Daniel Dupas
devlists at shadowlab.org
Thu Mar 1 06:53:16 PST 2012
Author: jddupas
Date: Thu Mar 1 08:53:16 2012
New Revision: 151809
URL: http://llvm.org/viewvc/llvm-project?rev=151809&view=rev
Log:
Implement double underscore names support in __has_attribute
Added:
cfe/trunk/test/Preprocessor/has_attribute.c (with props)
Modified:
cfe/trunk/docs/LanguageExtensions.html
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
Modified: cfe/trunk/docs/LanguageExtensions.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.html?rev=151809&r1=151808&r2=151809&view=diff
==============================================================================
--- cfe/trunk/docs/LanguageExtensions.html (original)
+++ cfe/trunk/docs/LanguageExtensions.html Thu Mar 1 08:53:16 2012
@@ -257,6 +257,11 @@
</pre>
</blockquote>
+<p>The attribute name can also be specified with a preceding and
+following <code>__</code> (double underscore) to avoid interference from a macro
+with the same name. For instance, <code>__always_inline__</code> can be used
+instead of <code>always_inline</code>.</p>
+
<!-- ======================================================================= -->
<h2 id="has_include">Include File Checking Macros</h2>
<!-- ======================================================================= -->
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=151809&r1=151808&r2=151809&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu Mar 1 08:53:16 2012
@@ -760,7 +760,12 @@
/// HasAttribute - Return true if we recognize and implement the attribute
/// specified by the given identifier.
static bool HasAttribute(const IdentifierInfo *II) {
- return llvm::StringSwitch<bool>(II->getName())
+ StringRef Name = II->getName();
+ // Normalize the attribute name, __foo__ becomes foo.
+ if (Name.startswith("__") && Name.endswith("__") && Name.size() >= 4)
+ Name = Name.substr(2, Name.size() - 4);
+
+ return llvm::StringSwitch<bool>(Name)
#include "clang/Lex/AttrSpellings.inc"
.Default(false);
}
Added: cfe/trunk/test/Preprocessor/has_attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_attribute.c?rev=151809&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/has_attribute.c (added)
+++ cfe/trunk/test/Preprocessor/has_attribute.c Thu Mar 1 08:53:16 2012
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s
+// RUN: %clang_cc1 %s -E
+#ifndef __has_attribute
+#error Should have __has_attribute
+#endif
+
+#if __has_attribute(something_we_dont_have)
+#error Bad
+#endif
+
+#if !__has_attribute(__always_inline__) || \
+ !__has_attribute(always_inline)
+#error Clang should have this
+#endif
Propchange: cfe/trunk/test/Preprocessor/has_attribute.c
------------------------------------------------------------------------------
svn:eol-style = native
More information about the cfe-commits
mailing list