Skip to content

Commit

Permalink
[IRGen] Fix an assert when __attribute__((used)) is used on an ObjC m…
Browse files Browse the repository at this point in the history
…ethod

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
  • Loading branch information
epilk committed Sep 2, 2020
1 parent ddd48cd commit 8ff44e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions clang/test/CodeGenObjC/attr-used-on-method.m
Original file line number Diff line number Diff line change
@@ -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]"(

@interface X @end
@implementation X
-(void) m __attribute__((used)) {}
@end

0 comments on commit 8ff44e6

Please sign in to comment.