From afd0e6d06ba05cf3cd8b0bb91b6506242de78a4d Mon Sep 17 00:00:00 2001 From: Chen Zheng Date: Mon, 8 Jul 2024 09:30:01 +0800 Subject: [PowerPC] Diagnose musttail instead of crash inside backend (#93267) musttail is not often possible to be generated on PPC targets as when calling to a function defined in another module, PPC needs to restore the TOC pointer. To restore the TOC pointer, compiler needs to emit a nop after the call to let linker generate codes to restore TOC pointer. Tail call cannot generate expected call sequence for this case. To avoid the crash inside the compiler backend, a diagnosis is added in the frontend. Fixes #63214 --- clang/lib/CodeGen/CodeGenModule.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenModule.h') diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 0444f9f..8b65348 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -485,6 +485,14 @@ private: typedef std::pair GlobalInitData; + // When a tail call is performed on an "undefined" symbol, on PPC without pc + // relative feature, the tail call is not allowed. In "EmitCall" for such + // tail calls, the "undefined" symbols may be forward declarations, their + // definitions are provided in the module after the callsites. For such tail + // calls, diagnose message should not be emitted. + llvm::SmallSetVector, 4> + MustTailCallUndefinedGlobals; + struct GlobalInitPriorityCmp { bool operator()(const GlobalInitData &LHS, const GlobalInitData &RHS) const { @@ -1647,6 +1655,11 @@ public: return getTriple().isSPIRVLogical(); } + void addUndefinedGlobalForTailCall( + std::pair Global) { + MustTailCallUndefinedGlobals.insert(Global); + } + private: bool shouldDropDLLAttribute(const Decl *D, const llvm::GlobalValue *GV) const; -- cgit v1.1