]> granicus.if.org Git - clang/commitdiff
Emit an error message instead of crashing when dereferencing an incomplete pointer...
authorBill Wendling <isanbard@gmail.com>
Mon, 25 Mar 2013 21:09:49 +0000 (21:09 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 25 Mar 2013 21:09:49 +0000 (21:09 +0000)
If the ASM statement is dereferencing an incomplete pointer type, issue an error
instead of crashing.
<rdar://problem/12700799>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177915 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaStmtAsm.cpp
test/CodeGen/x86_32-inline-asm.c
test/Sema/asm.c

index 1bc3dab93ee5acae42486324d1319c2208830f9b..b93dc3294f6ebb7ac6b7cc877c66ce502f6ec210 100644 (file)
@@ -4057,6 +4057,8 @@ def err_subscript_function_type : Error<
   "subscript of pointer to function type %0">;
 def err_subscript_incomplete_type : Error<
   "subscript of pointer to incomplete type %0">;
+def err_dereference_incomplete_type : Error<
+  "dereference of pointer to incomplete type %0">;
 def ext_gnu_subscript_void_type : Extension<
   "subscript of a pointer to void is a GNU extension">, InGroup<PointerArith>;
 def err_typecheck_member_reference_struct_union : Error<
index 95964e20a7ea5b4cbe4eb72450238914a16370a8..fc693e6cd786d8082a754c65ec42e9acce844141 100644 (file)
@@ -124,11 +124,15 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
 
     // Check that the output exprs are valid lvalues.
     Expr *OutputExpr = Exprs[i];
-    if (CheckAsmLValue(OutputExpr, *this)) {
+    if (CheckAsmLValue(OutputExpr, *this))
       return StmtError(Diag(OutputExpr->getLocStart(),
-                  diag::err_asm_invalid_lvalue_in_output)
-        << OutputExpr->getSourceRange());
-    }
+                            diag::err_asm_invalid_lvalue_in_output)
+                       << OutputExpr->getSourceRange());
+
+    if (RequireCompleteType(OutputExpr->getLocStart(), Exprs[i]->getType(), 0))
+      return StmtError(Diag(OutputExpr->getLocStart(),
+                            diag::err_dereference_incomplete_type)
+                       << Exprs[i]->getType());
 
     OutputConstraintInfos.push_back(Info);
   }
@@ -181,11 +185,15 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
     InputConstraintInfos.push_back(Info);
 
     const Type *Ty = Exprs[i]->getType().getTypePtr();
-    if (Ty->isDependentType() ||
-        RequireCompleteType(InputExpr->getLocStart(),
-                            Exprs[i]->getType(), 0))
+    if (Ty->isDependentType())
       continue;
 
+    if (!Ty->isVoidType() || !Info.allowsMemory())
+      if (RequireCompleteType(InputExpr->getLocStart(), Exprs[i]->getType(), 0))
+        return StmtError(Diag(InputExpr->getLocStart(),
+                              diag::err_dereference_incomplete_type)
+                         << Exprs[i]->getType());
+
     unsigned Size = Context.getTypeSize(Ty);
     if (!Context.getTargetInfo().validateInputSize(Literal->getString(),
                                                    Size))
index aebc4e4a0684d1a52614517b1719abaa92b9d45a..473f78ebcae61252f4fb56e6e7dcfe3e72822fdb 100644 (file)
@@ -22,10 +22,3 @@ int func1() {
   unsigned int port;
   __asm__ volatile("outb %0, %w1" : : "a" (data), "Nd" (port)); // No error expected.
 }
-
-struct S;
-void func2(struct S *s) {
-  __asm__ volatile(""
-                   :
-                   : "a" (*s));
-}
index 155d736b9956c1e245c6b60b8ab6dd791d0577e8..b901e378cf3f6ad746a992f6569b427b35e972b5 100644 (file)
@@ -123,3 +123,10 @@ void test13(void) {
   void *esp;
   __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}}
 }
+
+// <rdar://problem/12700799>
+struct S;
+void test14(struct S *s) {
+  __asm("": : "a"(*s)); // expected-error {{dereference of pointer to incomplete type 'struct S'}}
+  __asm("": "=a" (*s) :); // expected-error {{dereference of pointer to incomplete type 'struct S'}}
+}