I've added a simple test into CodeGenObjCXX
Looks like ObjC does not support the __attribute__ syntax, so it's
unclear how to prevent a specific function from being instrumented.
On Tue, Jan 31, 2012 at 10:27 PM, Chandler Carruth <[email protected]> wrote:
> On Tue, Jan 31, 2012 at 10:21 AM, Kostya Serebryany <[email protected]> wrote:
>>
>> Could you please also extend the test
>> (cfe/trunk/test/CodeGen/address-safety-attr.cpp)?
>> Ok for me, but I'd prefer to have 'ok' from someone else on the clang
>> side.
>
>
> Your comment is the same as mine -- we should add a test that would fail
> without this change. Otherwise LGTM. =]
--
Alexander Potapenko
Software Engineer
Google Moscow
Index: tools/clang/test/CodeGenObjCXX/address-safety-attr.mm
===================================================================
--- tools/clang/test/CodeGenObjCXX/address-safety-attr.mm (revision 0)
+++ tools/clang/test/CodeGenObjCXX/address-safety-attr.mm (revision 0)
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -o - %s -faddress-sanitizer | FileCheck -check-prefix ASAN %s
+
+#import <Foundation/NSObject.h>
+
+@interface MyClass : NSObject
++ (int) addressSafety:(int*)a;
+@end
+
+@implementation MyClass
+
+// CHECK-NOT: +[MyClass load]{{.*}} address_safety
+// ASAN: +[MyClass load]{{.*}} address_safety
++(void) load { }
+
+// CHECK-NOT: +[MyClass addressSafety:]{{.*}} address_safety
+// ASAN: +[MyClass addressSafety:]{{.*}} address_safety
++ (int) addressSafety:(int*)a { return *a; }
+
+@end
Property changes on: tools/clang/test/CodeGenObjCXX/address-safety-attr.mm
___________________________________________________________________
Added: svn:eol-style
+ LF
Index: tools/clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- tools/clang/lib/CodeGen/CodeGenModule.cpp (revision 149369)
+++ tools/clang/lib/CodeGen/CodeGenModule.cpp (working copy)
@@ -520,6 +520,13 @@
else if (Features.getStackProtector() == LangOptions::SSPReq)
F->addFnAttr(llvm::Attribute::StackProtectReq);
+ if (Features.AddressSanitizer) {
+ // When AddressSanitizer is enabled, set AddressSafety attribute
+ // unless __attribute__((no_address_safety_analysis)) is used.
+ if (!D->hasAttr<NoAddressSafetyAnalysisAttr>())
+ F->addFnAttr(llvm::Attribute::AddressSafety);
+ }
+
unsigned alignment = D->getMaxAlignment() / Context.getCharWidth();
if (alignment)
F->setAlignment(alignment);
@@ -1019,14 +1026,6 @@
if (ExtraAttrs != llvm::Attribute::None)
F->addFnAttr(ExtraAttrs);
- if (Features.AddressSanitizer) {
- // When AddressSanitizer is enabled, set AddressSafety attribute
- // unless __attribute__((no_address_safety_analysis)) is used.
- const FunctionDecl *FD = cast_or_null<FunctionDecl>(D.getDecl());
- if (!FD || !FD->hasAttr<NoAddressSafetyAnalysisAttr>())
- F->addFnAttr(llvm::Attribute::AddressSafety);
- }
-
// This is the first use or definition of a mangled name. If there is a
// deferred decl with this name, remember that we need to emit it at the end
// of the file.
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits