Skip to content

Commit 7f46fbe

Browse files
author
Chen Zheng
committed
address comments
1 parent 20e10f0 commit 7f46fbe

File tree

6 files changed

+61
-12
lines changed

6 files changed

+61
-12
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5760,16 +5760,22 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
57605760
CGM.getDiags().Report(Loc, diag::err_ppc_impossible_musttail) << 0;
57615761
else if (Call->isIndirectCall())
57625762
CGM.getDiags().Report(Loc, diag::err_ppc_impossible_musttail) << 1;
5763-
else if (isa_and_nonnull<FunctionDecl>(TargetDecl) &&
5764-
cast<FunctionDecl>(TargetDecl)->isWeak())
5765-
CGM.getDiags().Report(Loc, diag::err_ppc_impossible_musttail) << 2;
5766-
else if (isa_and_nonnull<FunctionDecl>(TargetDecl) &&
5767-
!cast<FunctionDecl>(TargetDecl)->isDefined())
5768-
// The undefined callee may be a forward declaration. Without
5769-
// knowning all symbols in the module, we won't know the symbol is
5770-
// defined or not. Collect all these symbols for later diagnosing.
5771-
CGM.addUndefinedGlobalForTailCall(
5772-
{cast<FunctionDecl>(TargetDecl), Loc});
5763+
else if (isa_and_nonnull<FunctionDecl>(TargetDecl)) {
5764+
if (!cast<FunctionDecl>(TargetDecl)->isDefined())
5765+
// The undefined callee may be a forward declaration. Without
5766+
// knowning all symbols in the module, we won't know the symbol is
5767+
// defined or not. Collect all these symbols for later diagnosing.
5768+
CGM.addUndefinedGlobalForTailCall(
5769+
{cast<FunctionDecl>(TargetDecl), Loc});
5770+
else {
5771+
llvm::GlobalValue::LinkageTypes Linkage = CGM.getFunctionLinkage(
5772+
GlobalDecl(cast<FunctionDecl>(TargetDecl)));
5773+
if (llvm::GlobalValue::isWeakForLinker(Linkage) ||
5774+
llvm::GlobalValue::isDiscardableIfUnused(Linkage))
5775+
CGM.getDiags().Report(Loc, diag::err_ppc_impossible_musttail)
5776+
<< 2;
5777+
}
5778+
}
57735779
}
57745780
}
57755781
Call->setTailCallKind(llvm::CallInst::TCK_MustTail);

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,13 @@ void CodeGenModule::Release() {
14001400
for (auto &I : MustTailCallUndefinedGlobals) {
14011401
if (!I.first->isDefined())
14021402
getDiags().Report(I.second, diag::err_ppc_impossible_musttail) << 2;
1403+
else {
1404+
StringRef MangledName = getMangledName(GlobalDecl(I.first));
1405+
llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
1406+
if (!Entry || Entry->isWeakForLinker() ||
1407+
Entry->isDeclarationForLinker())
1408+
getDiags().Report(I.second, diag::err_ppc_impossible_musttail) << 2;
1409+
}
14031410
}
14041411
}
14051412
}

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ class CodeGenModule : public CodeGenTypeCache {
488488
// When a tail call is performed on an "undefined" symbol, on PPC without pc
489489
// relative feature, the tail call is not allowed. In "EmitCall" for such
490490
// tail calls, the "undefined" symbols may be forward declarations, their
491-
// definitions are provided in the module but after the callsites. For such
492-
// tail calls, diagnose message should be not emitted.
491+
// definitions are provided in the module after the callsites. For such tail
492+
// calls, diagnose message should not be emitted.
493493
llvm::SmallSetVector<std::pair<const FunctionDecl *, SourceLocation>, 4>
494494
MustTailCallUndefinedGlobals;
495495

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify
2+
// RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify
3+
4+
inline int func2(int i);
5+
int external_call2(int i) {
6+
// expected-error@+1 {{'musttail' attribute for this call is impossible because external calls can not be tail called on PPC}}
7+
[[clang::musttail]] return func2(i);
8+
}
9+
10+
inline int func2(int i) {
11+
return 0;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify
2+
// RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify
3+
4+
int func2(int i);
5+
int external_call2(int i) {
6+
// expected-error@+1 {{'musttail' attribute for this call is impossible because external calls can not be tail called on PPC}}
7+
[[clang::musttail]] return func2(i);
8+
}
9+
10+
__attribute__((weak)) int func2(int i) {
11+
return 0;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify
2+
// RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify
3+
4+
inline int foo(int x) {
5+
return x;
6+
}
7+
8+
int bar(int x)
9+
{
10+
// expected-error@+1 {{'musttail' attribute for this call is impossible because external calls can not be tail called on PPC}}
11+
[[clang::musttail]] return foo(1);
12+
}

0 commit comments

Comments
 (0)