On Mon, Mar 25, 2013 at 2:09 PM, Bill Wendling <span dir="ltr"><<a href="mailto:isanbard@gmail.com" target="_blank">isanbard@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: void<br>
Date: Mon Mar 25 16:09:49 2013<br>
New Revision: 177915<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=177915&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=177915&view=rev</a><br>
Log:<br>
Emit an error message instead of crashing when dereferencing an incomplete pointer type.<br>
<br>
If the ASM statement is dereferencing an incomplete pointer type, issue an error<br>
instead of crashing.<br>
<rdar://problem/12700799><br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
    cfe/trunk/lib/Sema/SemaStmtAsm.cpp<br>
    cfe/trunk/test/CodeGen/x86_32-inline-asm.c<br>
    cfe/trunk/test/Sema/asm.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=177915&r1=177914&r2=177915&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=177915&r1=177914&r2=177915&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Mar 25 16:09:49 2013<br>
@@ -4057,6 +4057,8 @@ def err_subscript_function_type : Error<<br>
   "subscript of pointer to function type %0">;<br>
 def err_subscript_incomplete_type : Error<<br>
   "subscript of pointer to incomplete type %0">;<br>
+def err_dereference_incomplete_type : Error<<br>
+  "dereference of pointer to incomplete type %0">;<br>
 def ext_gnu_subscript_void_type : Extension<<br>
   "subscript of a pointer to void is a GNU extension">, InGroup<PointerArith>;<br>
 def err_typecheck_member_reference_struct_union : Error<<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=177915&r1=177914&r2=177915&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=177915&r1=177914&r2=177915&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Mon Mar 25 16:09:49 2013<br>
@@ -124,11 +124,15 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL<br>
<br>
     // Check that the output exprs are valid lvalues.<br>
     Expr *OutputExpr = Exprs[i];<br>
-    if (CheckAsmLValue(OutputExpr, *this)) {<br>
+    if (CheckAsmLValue(OutputExpr, *this))<br>
       return StmtError(Diag(OutputExpr->getLocStart(),<br>
-                  diag::err_asm_invalid_lvalue_in_output)<br>
-        << OutputExpr->getSourceRange());<br>
-    }<br>
+                            diag::err_asm_invalid_lvalue_in_output)<br>
+                       << OutputExpr->getSourceRange());<br>
+<br>
+    if (RequireCompleteType(OutputExpr->getLocStart(), Exprs[i]->getType(), 0))<br>
+      return StmtError(Diag(OutputExpr->getLocStart(),<br>
+                            diag::err_dereference_incomplete_type)<br>
+                       << Exprs[i]->getType());<br></blockquote><div><br></div><div>Please pass diag::err_reference_incomplete_type to RequireCompleteType instead of issuing your own diagnostic. (That way, we'll print out helpful notes alongside the diagnostic).</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
     OutputConstraintInfos.push_back(Info);<br>
   }<br>
@@ -181,11 +185,15 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL<br>
     InputConstraintInfos.push_back(Info);<br>
<br>
     const Type *Ty = Exprs[i]->getType().getTypePtr();<br>
-    if (Ty->isDependentType() ||<br>
-        RequireCompleteType(InputExpr->getLocStart(),<br>
-                            Exprs[i]->getType(), 0))<br>
+    if (Ty->isDependentType())<br>
       continue;<br>
<br>
+    if (!Ty->isVoidType() || !Info.allowsMemory())<br>
+      if (RequireCompleteType(InputExpr->getLocStart(), Exprs[i]->getType(), 0))<br>
+        return StmtError(Diag(InputExpr->getLocStart(),<br>
+                              diag::err_dereference_incomplete_type)<br>
+                         << Exprs[i]->getType());<br></blockquote><div><br></div><div>Likewise.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+<br>
     unsigned Size = Context.getTypeSize(Ty);<br>
     if (!Context.getTargetInfo().validateInputSize(Literal->getString(),<br>
                                                    Size))<br>
<br>
Modified: cfe/trunk/test/CodeGen/x86_32-inline-asm.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_32-inline-asm.c?rev=177915&r1=177914&r2=177915&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_32-inline-asm.c?rev=177915&r1=177914&r2=177915&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/CodeGen/x86_32-inline-asm.c (original)<br>
+++ cfe/trunk/test/CodeGen/x86_32-inline-asm.c Mon Mar 25 16:09:49 2013<br>
@@ -22,10 +22,3 @@ int func1() {<br>
   unsigned int port;<br>
   __asm__ volatile("outb %0, %w1" : : "a" (data), "Nd" (port)); // No error expected.<br>
 }<br>
-<br>
-struct S;<br>
-void func2(struct S *s) {<br>
-  __asm__ volatile(""<br>
-                   :<br>
-                   : "a" (*s));<br>
-}<br>
<br>
Modified: cfe/trunk/test/Sema/asm.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm.c?rev=177915&r1=177914&r2=177915&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm.c?rev=177915&r1=177914&r2=177915&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/Sema/asm.c (original)<br>
+++ cfe/trunk/test/Sema/asm.c Mon Mar 25 16:09:49 2013<br>
@@ -123,3 +123,10 @@ void test13(void) {<br>
   void *esp;<br>
   __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}}<br>
 }<br>
+<br>
+// <rdar://problem/12700799><br>
+struct S;<br>
+void test14(struct S *s) {<br>
+  __asm("": : "a"(*s)); // expected-error {{dereference of pointer to incomplete type 'struct S'}}<br>
+  __asm("": "=a" (*s) :); // expected-error {{dereference of pointer to incomplete type 'struct S'}}<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br>