r177915 - Emit an error message instead of crashing when dereferencing an incomplete pointer type.

Bill Wendling isanbard at gmail.com
Tue Mar 26 23:47:17 PDT 2013


Okay. Done.

-bw

On Mar 26, 2013, at 5:43 PM, Richard Smith <richard at metafoo.co.uk> wrote:

> On Mon, Mar 25, 2013 at 2:09 PM, Bill Wendling <isanbard at gmail.com> wrote:
> Author: void
> Date: Mon Mar 25 16:09:49 2013
> New Revision: 177915
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=177915&view=rev
> Log:
> Emit an error message instead of crashing when dereferencing an incomplete pointer type.
> 
> If the ASM statement is dereferencing an incomplete pointer type, issue an error
> instead of crashing.
> <rdar://problem/12700799>
> 
> Modified:
>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>     cfe/trunk/lib/Sema/SemaStmtAsm.cpp
>     cfe/trunk/test/CodeGen/x86_32-inline-asm.c
>     cfe/trunk/test/Sema/asm.c
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=177915&r1=177914&r2=177915&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Mar 25 16:09:49 2013
> @@ -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<
> 
> Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=177915&r1=177914&r2=177915&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Mon Mar 25 16:09:49 2013
> @@ -124,11 +124,15 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL
> 
>      // 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());
> 
> 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).
>  
> 
>      OutputConstraintInfos.push_back(Info);
>    }
> @@ -181,11 +185,15 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceL
>      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());
> 
> Likewise.
>  
> +
>      unsigned Size = Context.getTypeSize(Ty);
>      if (!Context.getTargetInfo().validateInputSize(Literal->getString(),
>                                                     Size))
> 
> Modified: cfe/trunk/test/CodeGen/x86_32-inline-asm.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_32-inline-asm.c?rev=177915&r1=177914&r2=177915&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGen/x86_32-inline-asm.c (original)
> +++ cfe/trunk/test/CodeGen/x86_32-inline-asm.c Mon Mar 25 16:09:49 2013
> @@ -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));
> -}
> 
> Modified: cfe/trunk/test/Sema/asm.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm.c?rev=177915&r1=177914&r2=177915&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/asm.c (original)
> +++ cfe/trunk/test/Sema/asm.c Mon Mar 25 16:09:49 2013
> @@ -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'}}
> +}
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 





More information about the cfe-commits mailing list