-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Clang] Fix crash for incompatible types in inline assembly #119098
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
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang Author: None (AdUhTkJm) ChangesFixed issue #118892. Full diff: https://github.com/llvm/llvm-project/pull/119098.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 0b272b806391c4..5e236b59d14b7d 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -668,6 +668,7 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
// output was a register, just extend the shorter one to the size of the
// larger one.
if (!SmallerValueMentioned && InputDomain != AD_Other &&
+ InputDomain == OutputDomain &&
OutputConstraintInfos[TiedTo].allowsRegister()) {
// FIXME: GCC supports the OutSize to be 128 at maximum. Currently codegen
// crash when the size larger than the register size. So we limit it here.
diff --git a/clang/test/Sema/inline-asm-incompatible-types.c b/clang/test/Sema/inline-asm-incompatible-types.c
new file mode 100644
index 00000000000000..849543e8027c20
--- /dev/null
+++ b/clang/test/Sema/inline-asm-incompatible-types.c
@@ -0,0 +1,19 @@
+extern __inline double
+fabs (char __x)
+{
+ register double __value;
+ __asm __volatile__
+ ("fabs"
+ : "=t" (__value) : "0" (__x));
+ return __value;
+}
+int
+foo ()
+{
+ int i, j, k;
+ double x = 0, y = ((i == j) ? 1 : 0);
+ for (i = 0; i < 10; i++)
+ ;
+ fabs (x - y);
+ return 0;
+}
\ No newline at end of file
|
|
By the way, I don't have write access to the project - if the PR is approved, could anyone merge it for me? |
| void test20(char x) { | ||
| double value; | ||
| asm ("fabs" : "=t" (value): "0" (x)); // expected-error {{unsupported inline asm: input with type 'char' matching output with type 'double'}} | ||
| } |
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.
Test both directions. And what about other kinds of types, like vectors
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.
Not sure about vectors (is it std::vector)? I'll add test against structs and floats.
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.
No, I mean like int2 typedef int int2 __attribute__((ext_vector_type(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.
Added.
|
@AdUhTkJm Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
shafik
left a comment
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.
Thank you for the fix. Please add a more detailed summary, these are important since they go into the git log and can be important for debugging downstream breaks.
Something like "Fix by adding check in ActOnGCCAsmStmt that the domains of the input and output match and reject if not" or something along those lines.
|
I just realized it was already merged |
Fixed issue #118892.