-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][CodeGen] Don't crash on output whose size is zero. #99849
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
@llvm/pr-subscribers-clang-codegen Author: Yeting Kuo (yetingk) ChangesThis fixes issue #63878 caused by creating an integer with zero bitwidth. Full diff: https://github.com/llvm/llvm-project/pull/99849.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index aa97f685ac7a9..92955e6cf4c96 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2751,7 +2751,10 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
if (RequiresCast) {
unsigned Size = getContext().getTypeSize(QTy);
- Ty = llvm::IntegerType::get(getLLVMContext(), Size);
+ if (Size)
+ Ty = llvm::IntegerType::get(getLLVMContext(), Size);
+ else
+ CGM.Error(S.getAsmLoc(), "Output operand is sizeless!");
}
ResultRegTypes.push_back(Ty);
// If this output is tied to an input, and if the input is larger, then
diff --git a/clang/test/CodeGen/inline-asm-sizeless.c b/clang/test/CodeGen/inline-asm-sizeless.c
new file mode 100644
index 0000000000000..29c1fc5b0b8f7
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-sizeless.c
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -S %s -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: Output operand is sizeless!
+void foo(void) {
+ extern long bar[];
+ asm ("" : "=r"(bar));
+}
|
@llvm/pr-subscribers-clang Author: Yeting Kuo (yetingk) ChangesThis fixes issue #63878 caused by creating an integer with zero bitwidth. Full diff: https://github.com/llvm/llvm-project/pull/99849.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index aa97f685ac7a9..92955e6cf4c96 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2751,7 +2751,10 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
if (RequiresCast) {
unsigned Size = getContext().getTypeSize(QTy);
- Ty = llvm::IntegerType::get(getLLVMContext(), Size);
+ if (Size)
+ Ty = llvm::IntegerType::get(getLLVMContext(), Size);
+ else
+ CGM.Error(S.getAsmLoc(), "Output operand is sizeless!");
}
ResultRegTypes.push_back(Ty);
// If this output is tied to an input, and if the input is larger, then
diff --git a/clang/test/CodeGen/inline-asm-sizeless.c b/clang/test/CodeGen/inline-asm-sizeless.c
new file mode 100644
index 0000000000000..29c1fc5b0b8f7
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-sizeless.c
@@ -0,0 +1,7 @@
+// RUN: not %clang_cc1 -S %s -o /dev/null 2>&1 | FileCheck %s
+
+// CHECK: error: Output operand is sizeless!
+void foo(void) {
+ extern long bar[];
+ asm ("" : "=r"(bar));
+}
|
@@ -0,0 +1,7 @@ | |||
// RUN: not %clang_cc1 -S %s -o /dev/null 2>&1 | FileCheck %s |
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.
Please use "-verify" to check clang diagnostics, not FileCheck.
Is there any existing file with inline asm diagnostics this can be added to?
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.
Used "-verify". I think the only one suitable file is clang/test/CodeGen/LoongArch/inline-asm-constraints-error.c, but it is target related.
clang/lib/CodeGen/CGStmt.cpp
Outdated
if (Size) | ||
Ty = llvm::IntegerType::get(getLLVMContext(), Size); | ||
else | ||
CGM.Error(S.getAsmLoc(), "Output operand is sizeless!"); |
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.
Can we use the SourceLocation of the specific operand in question, instead of using S.getAsmLoc()
, which points at the beginning of the asm statement?
Diagnostics aren't capitalized, and don't end in punctuation.
Maybe say "size zero" instead of "sizeless".
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.
Replaced to OutExpr->getExprLoc()
and change error message to output size should not be zero
.
This fixes issue llvm#63878 caused by creating an integer with zero bitwidth.
Rebase and ping. |
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.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/2870 Here is the relevant piece of the build log for the reference:
|
This fixes issue #63878 caused by creating an integer with zero bitwidth.