[cfe-commits] r149605 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGenObjCXX/address-safety-attr.mm
Alexander Potapenko
glider at google.com
Thu Feb 2 03:49:28 PST 2012
Author: glider
Date: Thu Feb 2 05:49:28 2012
New Revision: 149605
URL: http://llvm.org/viewvc/llvm-project?rev=149605&view=rev
Log:
Move the code that sets the AddressSafety
attribute into CodeGenModule::SetLLVMFunctionAttributesForDefinition().
Previously it resided in CodeGenModule::GetOrCreateLLVMFunction, which
for some reason wasn't called for ObjC class methods, see
http://code.google.com/p/address-sanitizer/issues/detail?id=33
Added:
cfe/trunk/test/CodeGenObjCXX/address-safety-attr.mm (with props)
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=149605&r1=149604&r2=149605&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Feb 2 05:49:28 2012
@@ -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.
Added: cfe/trunk/test/CodeGenObjCXX/address-safety-attr.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/address-safety-attr.mm?rev=149605&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/address-safety-attr.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/address-safety-attr.mm Thu Feb 2 05:49:28 2012
@@ -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
+
+ at interface MyClass
++ (int) addressSafety:(int*)a;
+ at end
+
+ at implementation MyClass
+
+// CHECK-NOT: +[MyClass load]{{.*}} address_safety
+// CHECK: +[MyClass load]{{.*}}
+// ASAN: +[MyClass load]{{.*}} address_safety
++(void) load { }
+
+// CHECK-NOT: +[MyClass addressSafety:]{{.*}} address_safety
+// CHECK: +[MyClass addressSafety:]{{.*}}
+// ASAN: +[MyClass addressSafety:]{{.*}} address_safety
++ (int) addressSafety:(int*)a { return *a; }
+
+ at end
Propchange: cfe/trunk/test/CodeGenObjCXX/address-safety-attr.mm
------------------------------------------------------------------------------
svn:eol-style = LF
More information about the cfe-commits
mailing list