[cfe-commits] r66614 - in /cfe/trunk: include/clang/Basic/DiagnosticASTKinds.def lib/AST/Stmt.cpp test/Sema/asm.c
Chris Lattner
sabre at nondot.org
Tue Mar 10 17:06:36 PDT 2009
Author: lattner
Date: Tue Mar 10 19:06:36 2009
New Revision: 66614
URL: http://llvm.org/viewvc/llvm-project?rev=66614&view=rev
Log:
checking for symbolic operands as well as % at end of string.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.def
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/test/Sema/asm.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.def?rev=66614&r1=66613&r2=66614&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.def Tue Mar 10 19:06:36 2009
@@ -20,3 +20,10 @@
// inline asm related.
DIAG(err_asm_invalid_escape, ERROR,
"invalid %% escape in inline assembly string")
+DIAG(err_asm_unknown_symbolic_operand_name, ERROR,
+ "unknown symbolic operand name in inline assembly string")
+
+DIAG(err_asm_unterminated_symbolic_operand_name, ERROR,
+ "unterminated symbolic operand name in inline assembly string")
+DIAG(err_asm_empty_symbolic_operand_name, ERROR,
+ "empty symbolic operand name in inline assembly string")
\ No newline at end of file
Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=66614&r1=66613&r2=66614&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Tue Mar 10 19:06:36 2009
@@ -229,8 +229,11 @@
}
// Escaped "%" character in asm string.
- // FIXME: This should be caught during Sema.
- assert(CurPtr != StrEnd && "Trailing '%' in asm string.");
+ if (CurPtr == StrEnd) {
+ // % at end of string is invalid (no escape).
+ DiagOffs = CurPtr-StrStart-1;
+ return diag::err_asm_invalid_escape;
+ }
char EscapedChar = *CurPtr++;
if (EscapedChar == '%') { // %% -> %
@@ -275,16 +278,26 @@
// Handle %[foo], a symbolic operand reference.
if (EscapedChar == '[') {
+ DiagOffs = CurPtr-StrStart-1;
+
+ // Find the ']'.
const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
- // FIXME: Should be caught by sema.
- // FIXME: Does sema catch multiple operands with the same name?
- assert(NameEnd != 0 && "Could not parse symbolic name");
+ if (NameEnd == 0)
+ return diag::err_asm_unterminated_symbolic_operand_name;
+ if (NameEnd == CurPtr)
+ return diag::err_asm_empty_symbolic_operand_name;
+
std::string SymbolicName(CurPtr, NameEnd);
- CurPtr = NameEnd+1;
int N = getNamedOperand(SymbolicName);
- assert(N != -1 && "FIXME: Catch in Sema.");
+ if (N == -1) {
+ // Verify that an operand with that name exists.
+ DiagOffs = CurPtr-StrStart;
+ return diag::err_asm_unknown_symbolic_operand_name;
+ }
Pieces.push_back(AsmStringPiece(N, Modifier));
+
+ CurPtr = NameEnd+1;
continue;
}
Modified: cfe/trunk/test/Sema/asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm.c?rev=66614&r1=66613&r2=66614&view=diff
==============================================================================
--- cfe/trunk/test/Sema/asm.c (original)
+++ cfe/trunk/test/Sema/asm.c Tue Mar 10 19:06:36 2009
@@ -1,8 +1,6 @@
// RUN: clang %s -arch=i386 -verify -fsyntax-only
-void
-f()
-{
+void f() {
int i;
asm ("foo\n" : : "a" (i + 2));
@@ -17,9 +15,7 @@
asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}}
}
-void
-clobbers()
-{
+void clobbers() {
asm ("nop" : : : "ax", "#ax", "%ax");
asm ("nop" : : : "eax", "rax", "ah", "al");
asm ("nop" : : : "0", "%0", "#0");
@@ -59,7 +55,13 @@
asm("nop" : : "er"(i));
}
-void test7() {
+void asm_string_tests() {
asm("%!"); // simple asm string, %! is not an error.
asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}}
+ asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}}
+
+ asm ("%[somename]" :: [somename] "i"(4)); // ok
+ asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}}
+ asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}}
+ asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}}
}
More information about the cfe-commits
mailing list