]> granicus.if.org Git - clang/commitdiff
When mapping no_sanitize_* attributes to no_sanitize attributes, handle GNU-style...
authorAaron Ballman <aaron@aaronballman.com>
Thu, 8 Oct 2015 19:24:08 +0000 (19:24 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 8 Oct 2015 19:24:08 +0000 (19:24 +0000)
Patch by Adrian Zgorzalek!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249721 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/SemaCXX/attr-no-sanitize-address.cpp
test/SemaCXX/attr-no-sanitize-memory.cpp
test/SemaCXX/attr-no-sanitize-thread.cpp

index 3cf9567889f520f7906750ee9e38c63c5e3a7ca2..2b38e0f8705d9648e2aab553d4001e5fd4a45192 100644 (file)
@@ -1308,6 +1308,17 @@ void Sema::AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
             AssumeAlignedAttr(AttrRange, Context, E, OE, SpellingListIndex));
 }
 
+/// Normalize the attribute, __foo__ becomes foo.
+/// Returns true if normalization was applied.
+static bool normalizeName(StringRef &AttrName) {
+  if (AttrName.startswith("__") && AttrName.endswith("__")) {
+    assert(AttrName.size() > 4 && "Name too short");
+    AttrName = AttrName.drop_front(2).drop_back(2);
+    return true;
+  }
+  return false;
+}
+
 static void handleOwnershipAttr(Sema &S, Decl *D, const AttributeList &AL) {
   // This attribute must be applied to a function declaration. The first
   // argument to the attribute must be an identifier, the name of the resource,
@@ -1349,11 +1360,8 @@ static void handleOwnershipAttr(Sema &S, Decl *D, const AttributeList &AL) {
 
   IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident;
 
-  // Normalize the argument, __foo__ becomes foo.
   StringRef ModuleName = Module->getName();
-  if (ModuleName.startswith("__") && ModuleName.endswith("__") &&
-      ModuleName.size() > 4) {
-    ModuleName = ModuleName.drop_front(2).drop_back(2);
+  if (normalizeName(ModuleName)) {
     Module = &S.PP.getIdentifierTable().get(ModuleName);
   }
 
@@ -2648,9 +2656,7 @@ static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   IdentifierInfo *II = Attr.getArgAsIdent(0)->Ident;
   StringRef Format = II->getName();
 
-  // Normalize the argument, __foo__ becomes foo.
-  if (Format.startswith("__") && Format.endswith("__")) {
-    Format = Format.substr(2, Format.size() - 4);
+  if (normalizeName(Format)) {
     // If we've modified the string name, we need a new identifier for it.
     II = &S.Context.Idents.get(Format);
   }
@@ -3131,9 +3137,7 @@ static void handleModeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   IdentifierInfo *Name = Attr.getArgAsIdent(0)->Ident;
   StringRef Str = Name->getName();
 
-  // Normalize the attribute name, __foo__ becomes foo.
-  if (Str.startswith("__") && Str.endswith("__"))
-    Str = Str.substr(2, Str.size() - 4);
+  normalizeName(Str);
 
   unsigned DestWidth = 0;
   bool IntegerMode = true;
@@ -4533,8 +4537,10 @@ static void handleNoSanitizeAttr(Sema &S, Decl *D, const AttributeList &Attr) {
 
 static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D,
                                          const AttributeList &Attr) {
+  StringRef AttrName = Attr.getName()->getName();
+  normalizeName(AttrName);
   std::string SanitizerName =
-      llvm::StringSwitch<std::string>(Attr.getName()->getName())
+      llvm::StringSwitch<std::string>(AttrName)
           .Case("no_address_safety_analysis", "address")
           .Case("no_sanitize_address", "address")
           .Case("no_sanitize_thread", "thread")
index 9ca28630552bc8542e617b00336bd43cecc8a0f9..0aafe06af980a7b1db3d20bedda3dbeb8496065f 100644 (file)
@@ -5,12 +5,14 @@
 #if !__has_attribute(no_sanitize_address)
 #error "Should support no_sanitize_address"
 #endif
-
-void noanal_fun() NO_SANITIZE_ADDRESS;
-
-void noanal_fun_args() __attribute__((no_sanitize_address(1))); // \
-  // expected-error {{'no_sanitize_address' attribute takes no arguments}}
-
+\r
+void noanal_fun() NO_SANITIZE_ADDRESS;\r
+\r
+void noanal_fun_alt() __attribute__((__no_sanitize_address__));\r
+\r
+void noanal_fun_args() __attribute__((no_sanitize_address(1))); // \\r
+  // expected-error {{'no_sanitize_address' attribute takes no arguments}}\r
+\r
 int noanal_testfn(int y) NO_SANITIZE_ADDRESS;
 
 int noanal_testfn(int y) {
index 9cbcb03d6ecf1a6d19d331f2cde8b71ebfbfcf68..8a8d847562af77f5989f2c847c9f723d78df6866 100644 (file)
@@ -5,12 +5,14 @@
 #if !__has_attribute(no_sanitize_memory)
 #error "Should support no_sanitize_memory"
 #endif
-
-void noanal_fun() NO_SANITIZE_MEMORY;
-
-void noanal_fun_args() __attribute__((no_sanitize_memory(1))); // \
-  // expected-error {{'no_sanitize_memory' attribute takes no arguments}}
-
+\r
+void noanal_fun() NO_SANITIZE_MEMORY;\r
+\r
+void noanal_fun_alt() __attribute__((__no_sanitize_memory__));\r
+\r
+void noanal_fun_args() __attribute__((no_sanitize_memory(1))); // \\r
+  // expected-error {{'no_sanitize_memory' attribute takes no arguments}}\r
+\r
 int noanal_testfn(int y) NO_SANITIZE_MEMORY;
 
 int noanal_testfn(int y) {
index 6cb9c715bf6cc40effc7a0688d837b1ef6260110..92a3fa96194cd8fdcff4860bde3804d705ab7c67 100644 (file)
@@ -5,12 +5,14 @@
 #if !__has_attribute(no_sanitize_thread)
 #error "Should support no_sanitize_thread"
 #endif
-
-void noanal_fun() NO_SANITIZE_THREAD;
-
-void noanal_fun_args() __attribute__((no_sanitize_thread(1))); // \
-  // expected-error {{'no_sanitize_thread' attribute takes no arguments}}
-
+\r
+void noanal_fun() NO_SANITIZE_THREAD;\r
+\r
+void noanal_fun_alt() __attribute__((__no_sanitize_thread__));\r
+\r
+void noanal_fun_args() __attribute__((no_sanitize_thread(1))); // \\r
+  // expected-error {{'no_sanitize_thread' attribute takes no arguments}}\r
+\r
 int noanal_testfn(int y) NO_SANITIZE_THREAD;
 
 int noanal_testfn(int y) {