[clang] 8ff44e6 - [IRGen] Fix an assert when __attribute__((used)) is used on an ObjC method

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 2 09:19:25 PDT 2020


Author: Erik Pilkington
Date: 2020-09-02T12:19:11-04:00
New Revision: 8ff44e644bb70dfb8decc397a42679df6e6f8ba1

URL: https://github.com/llvm/llvm-project/commit/8ff44e644bb70dfb8decc397a42679df6e6f8ba1
DIFF: https://github.com/llvm/llvm-project/commit/8ff44e644bb70dfb8decc397a42679df6e6f8ba1.diff

LOG: [IRGen] Fix an assert when __attribute__((used)) is used on an ObjC method

This assert doesn't really make sense for functions in general, since they
start life as declarations, and there isn't really any reason to require them
to be defined before attributes are applied to them.

rdar://67895846

Added: 
    clang/test/CodeGenObjC/attr-used-on-method.m

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 77a5079bd0f1..1f362e2b6b31 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1989,7 +1989,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
 }
 
 void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
-  assert(!GV->isDeclaration() &&
+  assert(isa<llvm::Function>(GV) || !GV->isDeclaration() &&
          "Only globals with definition can force usage.");
   LLVMUsed.emplace_back(GV);
 }

diff  --git a/clang/test/CodeGenObjC/attr-used-on-method.m b/clang/test/CodeGenObjC/attr-used-on-method.m
new file mode 100644
index 000000000000..d8b2a5d29184
--- /dev/null
+++ b/clang/test/CodeGenObjC/attr-used-on-method.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 %s -S -emit-llvm -o - | FileCheck %s
+
+// CHECK: @llvm.used =
+// CHECK-SAME: @"\01-[X m]"
+
+// CHECK: define internal void @"\01-[X m]"(
+
+ at interface X @end
+ at implementation X
+-(void) m __attribute__((used)) {}
+ at end


        


More information about the cfe-commits mailing list