r228089 - [inlineasm] Fix an incorrect warning about register constraint and modifier.
Akira Hatanaka
ahatanaka at apple.com
Tue Feb 3 16:27:14 PST 2015
Author: ahatanak
Date: Tue Feb 3 18:27:13 2015
New Revision: 228089
URL: http://llvm.org/viewvc/llvm-project?rev=228089&view=rev
Log:
[inlineasm] Fix an incorrect warning about register constraint and modifier.
Previously, when the following piece of code was compiled, clang would
incorrectly warn that the size of "wide_two" does not match register size
specified by the constraint and modifier":
long wide_two = two;
asm ("%w0 %1" : "+r" (one), "+r"(wide_two));
This was caused by a miscalculation of ConstraintIdx in Sema::ActOnGCCAsmStmt.
This commit fixes PR21270 and rdar://problem/18668354.
Modified:
cfe/trunk/lib/Sema/SemaStmtAsm.cpp
cfe/trunk/test/Sema/inline-asm-validate-aarch64.c
Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=228089&r1=228088&r2=228089&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Tue Feb 3 18:27:13 2015
@@ -313,32 +313,22 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL
if (!Piece.isOperand()) continue;
// Look for the correct constraint index.
- unsigned Idx = 0;
- unsigned ConstraintIdx = 0;
- for (unsigned i = 0, e = NS->getNumOutputs(); i != e; ++i, ++ConstraintIdx) {
- TargetInfo::ConstraintInfo &Info = OutputConstraintInfos[i];
- if (Idx == Piece.getOperandNo())
- break;
- ++Idx;
+ unsigned ConstraintIdx = Piece.getOperandNo();
+ unsigned NumOperands = NS->getNumOutputs() + NS->getNumInputs();
- if (Info.isReadWrite()) {
- if (Idx == Piece.getOperandNo())
- break;
- ++Idx;
- }
- }
+ // Look for the (ConstraintIdx - NumOperands + 1)th constraint with
+ // modifier '+'.
+ if (ConstraintIdx >= NumOperands) {
+ unsigned I = 0, E = NS->getNumOutputs();
- for (unsigned i = 0, e = NS->getNumInputs(); i != e; ++i, ++ConstraintIdx) {
- TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
- if (Idx == Piece.getOperandNo())
- break;
- ++Idx;
-
- if (Info.isReadWrite()) {
- if (Idx == Piece.getOperandNo())
+ for (unsigned Cnt = ConstraintIdx - NumOperands; I != E; ++I)
+ if (OutputConstraintInfos[I].isReadWrite() && Cnt-- == 0) {
+ ConstraintIdx = I;
break;
- ++Idx;
- }
+ }
+
+ assert(I != E && "Invalid operand number should have been caught in "
+ " AnalyzeAsmString");
}
// Now that we have the right indexes go ahead and check.
Modified: cfe/trunk/test/Sema/inline-asm-validate-aarch64.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/inline-asm-validate-aarch64.c?rev=228089&r1=228088&r2=228089&view=diff
==============================================================================
--- cfe/trunk/test/Sema/inline-asm-validate-aarch64.c (original)
+++ cfe/trunk/test/Sema/inline-asm-validate-aarch64.c Tue Feb 3 18:27:13 2015
@@ -36,3 +36,19 @@ uint8_t constraint_r_symbolic_macro(uint
return byte;
}
+
+// CHECK: warning: value size does not match register size specified by the constraint and modifier
+// CHECK: asm ("%w0 %w1 %2" : "+r" (one) : "r" (wide_two));
+// CHECK: note: use constraint modifier "w"
+// CHECK: fix-it:{{.*}}:{47:17-47:19}:"%w2"
+
+void read_write_modifier0(int one, int two) {
+ long wide_two = two;
+ asm ("%w0 %w1 %2" : "+r" (one) : "r" (wide_two));
+}
+
+// CHECK-NOT: warning:
+void read_write_modifier1(int one, int two) {
+ long wide_two = two;
+ asm ("%w0 %1" : "+r" (one), "+r" (wide_two));
+}
More information about the cfe-commits
mailing list