-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[Clang]Throw frontend error for target feature mismatch when using flatten
attribute
#150044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…atten attribute Fixes llvm#149866
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Abhishek Kaushik (abhishek-kaushik22) ChangesFixes #149866 Full diff: https://github.com/llvm/llvm-project/pull/150044.diff 2 Files Affected:
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'}}
+}
|
@topperc can you please review since you've reviewed similar commits in the past? |
(TargetDecl->hasAttr<TargetAttr>() || | ||
(CurFuncDecl && CurFuncDecl->hasAttr<TargetAttr>()))) || | ||
(CurFuncDecl && CurFuncDecl->hasAttr<FlattenAttr>() && | ||
TargetDecl->hasAttr<TargetAttr>())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also need the CurFuncDecl && CurFuncDecl->hasAttr<TargetAttr>()
check for flatten?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand, we only need to check that the callee function has TargetAttr
because the error is inlining a function that uses a target feature which the caller isn't compiled for. The caller having TargetAttr
isn't required to reproduce the crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe in some weird cases, you can use a target attribute to remove features?
Anyway, if we need the check for always_inline, we probably also need it for flatten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(The condition for always_inline is that either the callee has a TargetAttr, or the caller has a TargetAttr.)
} | ||
|
||
__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'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diagnostic refers to always_inline
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming from tablegen, do you think we should change that as well?
def err_function_needs_feature : Error<
"always_inline function %1 requires target feature '%2', but would "
"be inlined into function %0 that is compiled without support for '%2'">;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Probably simplest to define a new error so you can use different phrasing.
Fixes #149866