[PATCH] D60943: Delay diagnosing asm constraints that require immediates until after inlining
Bill Wendling via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 27 23:39:50 PDT 2019
void updated this revision to Diff 212079.
void added a comment.
Don't emit errors here. Wait until codegen.
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60943/new/
https://reviews.llvm.org/D60943
Files:
lib/CodeGen/CGStmt.cpp
lib/Sema/SemaStmtAsm.cpp
test/Sema/inline-asm-validate-x86.c
Index: test/Sema/inline-asm-validate-x86.c
===================================================================
--- test/Sema/inline-asm-validate-x86.c
+++ test/Sema/inline-asm-validate-x86.c
@@ -147,9 +147,9 @@
// This offset-from-null pointer can be used as an integer constant expression.
__asm__ __volatile__("\n#define S_B abcd%0\n" : : "n"(&((struct s*)0)->b));
// This pointer cannot be used as an integer constant expression.
- __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "n"(&s.a)); // expected-error{{constraint 'n' expects an integer constant expression}}
+ __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "e"(&s.a)); // expected-error{{constraint 'e' expects an integer constant expression}}
// Floating-point is also not okay.
- __asm__ __volatile__("\n#define PI abcd%0\n" : : "n"(3.14f)); // expected-error{{constraint 'n' expects an integer constant expression}}
+ __asm__ __volatile__("\n#define PI abcd%0\n" : : "e"(3.14f)); // expected-error{{constraint 'e' expects an integer constant expression}}
#ifdef AMD64
// This arbitrary pointer is fine.
__asm__ __volatile__("\n#define BEEF abcd%0\n" : : "n"((int*)0xdeadbeeeeeef));
Index: lib/Sema/SemaStmtAsm.cpp
===================================================================
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -383,25 +383,19 @@
} else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
if (!InputExpr->isValueDependent()) {
Expr::EvalResult EVResult;
- if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
- return StmtError(
- Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
- << Info.getConstraintStr() << InputExpr->getSourceRange());
-
- // For compatibility with GCC, we also allow pointers that would be
- // integral constant expressions if they were cast to int.
- llvm::APSInt IntResult;
- if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
- Context))
- return StmtError(
- Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
- << Info.getConstraintStr() << InputExpr->getSourceRange());
-
- if (!Info.isValidAsmImmediate(IntResult))
- return StmtError(Diag(InputExpr->getBeginLoc(),
- diag::err_invalid_asm_value_for_constraint)
- << IntResult.toString(10) << Info.getConstraintStr()
- << InputExpr->getSourceRange());
+ if (InputExpr->EvaluateAsRValue(EVResult, Context, true)) {
+ // For compatibility with GCC, we also allow pointers that would be
+ // integral constant expressions if they were cast to int.
+ llvm::APSInt IntResult;
+ if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
+ Context))
+ if (!Info.isValidAsmImmediate(IntResult))
+ return StmtError(Diag(InputExpr->getBeginLoc(),
+ diag::err_invalid_asm_value_for_constraint)
+ << IntResult.toString(10)
+ << Info.getConstraintStr()
+ << InputExpr->getSourceRange());
+ }
}
} else {
Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1846,11 +1846,9 @@
InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
llvm::APSInt IntResult;
- if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
- getContext()))
- llvm_unreachable("Invalid immediate constant!");
-
- return llvm::ConstantInt::get(getLLVMContext(), IntResult);
+ if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
+ getContext()))
+ return llvm::ConstantInt::get(getLLVMContext(), IntResult);
}
Expr::EvalResult Result;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60943.212079.patch
Type: text/x-patch
Size: 4193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190728/34a2d021/attachment.bin>
More information about the cfe-commits
mailing list