Skip to content

Commit 8ff44e6

Browse files
committed
[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
1 parent ddd48cd commit 8ff44e6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
19891989
}
19901990

19911991
void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
1992-
assert(!GV->isDeclaration() &&
1992+
assert(isa<llvm::Function>(GV) || !GV->isDeclaration() &&
19931993
"Only globals with definition can force usage.");
19941994
LLVMUsed.emplace_back(GV);
19951995
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 %s -S -emit-llvm -o - | FileCheck %s
2+
3+
// CHECK: @llvm.used =
4+
// CHECK-SAME: @"\01-[X m]"
5+
6+
// CHECK: define internal void @"\01-[X m]"(
7+
8+
@interface X @end
9+
@implementation X
10+
-(void) m __attribute__((used)) {}
11+
@end

0 commit comments

Comments
 (0)