https://github.com/abhishek-kaushik22 created 
https://github.com/llvm/llvm-project/pull/150044

Fixes #149866

>From 480f5521ff5f0767ea295ef61a054f35961be3b0 Mon Sep 17 00:00:00 2001
From: Abhishek Kaushik <abhishek.kaus...@intel.com>
Date: Tue, 22 Jul 2025 21:03:17 +0530
Subject: [PATCH] [Clang]Throw frontend error for target feature mismatch when
 using flatten attribute

Fixes #149866
---
 clang/lib/CodeGen/CGCall.cpp                 |  8 +++++---
 clang/test/CodeGen/target-features-error-3.c | 12 ++++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/target-features-error-3.c

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'}}
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to