pengfei updated this revision to Diff 414276.
pengfei added a comment.
Address review comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107141/new/
https://reviews.llvm.org/D107141
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGStmt.cpp
clang/lib/Sema/SemaStmtAsm.cpp
clang/test/Sema/asm.c
Index: clang/test/Sema/asm.c
===================================================================
--- clang/test/Sema/asm.c
+++ clang/test/Sema/asm.c
@@ -313,3 +313,52 @@
asm ("jne %l0":::);
asm goto ("jne %l0"::::lab);
}
+
+typedef struct _st_size64 {
+ int a;
+ char b;
+} st_size64;
+
+typedef struct _st_size96 {
+ int a;
+ int b;
+ int c;
+} st_size96;
+
+typedef struct _st_size16 {
+ char a;
+ char b;
+} st_size16;
+
+typedef struct _st_size32 {
+ char a;
+ char b;
+ char c;
+ char d;
+} st_size32;
+
+typedef struct _st_size128 {
+ int a;
+ int b;
+ int c;
+ int d;
+} st_size128;
+
+void test19(long long x)
+{
+ st_size64 a;
+ st_size96 b;
+ st_size16 c;
+ st_size32 d;
+ st_size128 e;
+ asm ("" : "=rm" (a): "0" (1)); // no-error
+ asm ("" : "=rm" (d): "0" (1)); // no-error
+ asm ("" : "=rm" (c): "0" (x)); // no-error
+ asm ("" : "=rm" (x): "0" (a)); // no-error
+ asm ("" : "=rm" (a): "0" (d)); // no-error
+ // Check the output size is pow of 2
+ asm ("" : "=rm" (b): "0" (1)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+ // Check the output size is <= 64
+ asm ("" : "=rm" (e): "0" (1)); // no-error
+ asm ("" : "=rm" (x): "0" (e)); // no-error
+}
Index: clang/lib/Sema/SemaStmtAsm.cpp
===================================================================
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -618,14 +618,16 @@
AD_Int, AD_FP, AD_Other
} InputDomain, OutputDomain;
- if (InTy->isIntegerType() || InTy->isPointerType())
+ if (InTy->isIntegerType() || InTy->isPointerType() ||
+ InTy->isStructureType() || InTy->isConstantArrayType())
InputDomain = AD_Int;
else if (InTy->isRealFloatingType())
InputDomain = AD_FP;
else
InputDomain = AD_Other;
- if (OutTy->isIntegerType() || OutTy->isPointerType())
+ if (OutTy->isIntegerType() || OutTy->isPointerType() ||
+ OutTy->isStructureType() || OutTy->isConstantArrayType())
OutputDomain = AD_Int;
else if (OutTy->isRealFloatingType())
OutputDomain = AD_FP;
@@ -667,8 +669,15 @@
// output was a register, just extend the shorter one to the size of the
// larger one.
if (!SmallerValueMentioned && InputDomain != AD_Other &&
- OutputConstraintInfos[TiedTo].allowsRegister())
+ 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.
+ if (OutputDomain == AD_Int &&
+ Context.getIntTypeForBitwidth(OutSize, /*Signed*/ false).isNull())
+ targetDiag(OutputExpr->getExprLoc(), diag::err_store_value_to_reg);
+
continue;
+ }
// Either both of the operands were mentioned or the smaller one was
// mentioned. One more special case that we'll allow: if the tied input is
Index: clang/lib/CodeGen/CGStmt.cpp
===================================================================
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2725,9 +2725,8 @@
QualType Ty = getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
if (Ty.isNull()) {
const Expr *OutExpr = S.getOutputExpr(i);
- CGM.Error(
- OutExpr->getExprLoc(),
- "impossible constraint in asm: can't store value into a register");
+ CGM.getDiags().Report(OutExpr->getExprLoc(),
+ diag::err_store_value_to_reg);
return;
}
Dest = MakeAddrLValue(A, Ty);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8763,6 +8763,8 @@
" in asm %select{input|output}1 with a memory constraint '%2'">;
def err_asm_input_duplicate_match : Error<
"more than one input constraint matches the same output '%0'">;
+ def err_store_value_to_reg : Error<
+ "impossible constraint in asm: can't store value into a register">;
def warn_asm_label_on_auto_decl : Warning<
"ignored asm label '%0' on automatic variable">;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits