[clang] [Clang]Throw frontend error for target feature mismatch when using `flatten` attribute (PR #150044)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 22 08:35:55 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Abhishek Kaushik (abhishek-kaushik22)
<details>
<summary>Changes</summary>
Fixes #<!-- -->149866
---
Full diff: https://github.com/llvm/llvm-project/pull/150044.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGCall.cpp (+5-3)
- (added) clang/test/CodeGen/target-features-error-3.c (+12)
``````````diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 0bceecec6e555..589716460b2de 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5232,9 +5232,11 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
// since otherwise we could be making a conditional call after a check for
// 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>() ||
- (CurFuncDecl && CurFuncDecl->hasAttr<TargetAttr>())))
+ if ((TargetDecl->hasAttr<AlwaysInlineAttr>() &&
+ (TargetDecl->hasAttr<TargetAttr>() ||
+ (CurFuncDecl && CurFuncDecl->hasAttr<TargetAttr>()))) ||
+ (CurFuncDecl && CurFuncDecl->hasAttr<FlattenAttr>() &&
+ TargetDecl->hasAttr<TargetAttr>()))
checkTargetFeatures(Loc, FD);
}
diff --git a/clang/test/CodeGen/target-features-error-3.c b/clang/test/CodeGen/target-features-error-3.c
new file mode 100644
index 0000000000000..8900edfa257c7
--- /dev/null
+++ b/clang/test/CodeGen/target-features-error-3.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o -
+
+typedef double __v2df __attribute__((__vector_size__(16)));
+
+__v2df __attribute__((target("sse4.1"))) foo() {
+ __v2df v = {0.0, 0.0};
+ return __builtin_ia32_roundpd(v, 2);
+}
+
+__v2df __attribute__((flatten)) bar() {
+ return foo(); // expected-error {{always_inline function 'foo' requires target feature 'sse4.1', but would be inlined into function 'bar' that is compiled without support for 'sse4.1'}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/150044
More information about the cfe-commits
mailing list