Author: Qiu Chaofan Date: 2023-03-15T14:21:52+08:00 New Revision: 608212a0ff2f9e9a2cee8b5b0fa206fd15eb6472
URL: https://github.com/llvm/llvm-project/commit/608212a0ff2f9e9a2cee8b5b0fa206fd15eb6472 DIFF: https://github.com/llvm/llvm-project/commit/608212a0ff2f9e9a2cee8b5b0fa206fd15eb6472.diff LOG: [Clang] Check feature requirement from inlined callee Currently clang emits error when both always_inline and target attributes are on callee, but caller doesn't have some feature. This patch makes clang emit error when caller cannot meet target feature requirements from an always-inlined callee. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D143479 Added: clang/test/Sema/ppc-attr-target-inline.c Modified: clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CodeGenFunction.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index dd8bd2bb82a5..aaa5d4e70d7d 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -4802,7 +4802,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, // the proper cpu features (and it won't cause code generation issues due to // function based code generation). if (TargetDecl->hasAttr<AlwaysInlineAttr>() && - TargetDecl->hasAttr<TargetAttr>()) + (TargetDecl->hasAttr<TargetAttr>() || + (CurFuncDecl && CurFuncDecl->hasAttr<TargetAttr>()))) checkTargetFeatures(Loc, FD); // Some architectures (such as x86-64) have the ABI changed based on diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index af60b3166d75..a5cbf7223ad6 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2612,6 +2612,16 @@ void CodeGenFunction::checkTargetFeatures(SourceLocation Loc, })) CGM.getDiags().Report(Loc, diag::err_function_needs_feature) << FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature; + } else if (!FD->isMultiVersion() && FD->hasAttr<TargetAttr>()) { + llvm::StringMap<bool> CalleeFeatureMap; + CGM.getContext().getFunctionFeatureMap(CalleeFeatureMap, TargetDecl); + + for (const auto &F : CalleeFeatureMap) { + if (F.getValue() && (!CallerFeatureMap.lookup(F.getKey()) || + !CallerFeatureMap.find(F.getKey())->getValue())) + CGM.getDiags().Report(Loc, diag::err_function_needs_feature) + << FD->getDeclName() << TargetDecl->getDeclName() << F.getKey(); + } } } diff --git a/clang/test/Sema/ppc-attr-target-inline.c b/clang/test/Sema/ppc-attr-target-inline.c new file mode 100644 index 000000000000..07ed00682265 --- /dev/null +++ b/clang/test/Sema/ppc-attr-target-inline.c @@ -0,0 +1,14 @@ +// REQUIRES: powerpc-registered-target +// RUN: %clang_cc1 -triple powerpc64le -target-feature +htm -fsyntax-only -emit-llvm %s -verify + +__attribute__((always_inline)) +int test1(int *x) { + *x = __builtin_ttest(); + return *x; +} + +__attribute__((target("no-htm"))) +int test2(int *x) { + *x = test1(x); // expected-error {{always_inline function 'test1' requires target feature 'htm', but would be inlined into function 'test2' that is compiled without support for 'htm'}} + return 0; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits