From 3d6f49a56995b845c40be5827ded5d1e3f692cec Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Thu, 16 Sep 2021 18:13:15 +0200 Subject: Simplify handling of builtin with inline redefinition It is a common practice in glibc header to provide an inline redefinition of an existing function. It is especially the case for fortified function. Clang currently has an imperfect approach to the problem, using a combination of trivially recursive function detection and noinline attribute. Simplify the logic by suffixing these functions by `.inline` during codegen, so that they are not recognized as builtin by llvm. After that patch, clang passes all tests from https://github.com/serge-sans-paille/fortify-test-suite Differential Revision: https://reviews.llvm.org/D109967 --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 5f63461a..fbb0688 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1301,6 +1301,11 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn, FunctionArgList Args; QualType ResTy = BuildFunctionArgList(GD, Args); + // Give a different name to inline builtin to avoid conflict with actual + // builtins. + if (FD->isInlineBuiltinDeclaration() && Fn) + Fn->setName(Fn->getName() + ".inline"); + // Check if we should generate debug info for this function. if (FD->hasAttr()) { // Clear non-distinct debug info that was possibly attached to the function -- cgit v1.1