From 6568eef9f90d7c843676f47ee2938a8af2600bf3 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 26 Mar 2009 07:32:37 +0000 Subject: [PATCH] Sanity-check argument to indirect goto. llvm-svn: 67746 --- clang/lib/Sema/SemaStmt.cpp | 10 +++++++--- clang/test/Sema/indirect-goto.c | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 clang/test/Sema/indirect-goto.c diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 4ef0fda36123..bbcc71d6e4d2 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -687,10 +687,14 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, Action::OwningStmtResult Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc, ExprArg DestExp) { - // FIXME: Verify that the operand is convertible to void*. // Convert operand to void* - Expr* E = (Expr*)DestExp.release(); - ImpCastExprToType(E, Context.VoidPtrTy); + Expr* E = DestExp.takeAs(); + QualType ETy = E->getType(); + AssignConvertType ConvTy = + CheckSingleAssignmentConstraints(Context.VoidPtrTy, E); + if (DiagnoseAssignmentResult(ConvTy, StarLoc, Context.VoidPtrTy, ETy, + E, "passing")) + return StmtError(); return Owned(new (Context) IndirectGotoStmt(E)); } diff --git a/clang/test/Sema/indirect-goto.c b/clang/test/Sema/indirect-goto.c new file mode 100644 index 000000000000..35fb5e6315e2 --- /dev/null +++ b/clang/test/Sema/indirect-goto.c @@ -0,0 +1,8 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +struct c {int x;}; +int a(struct c x, long long y) { + goto *x; // expected-error{{incompatible type}} + goto *y; // expected-warning{{incompatible integer to pointer conversion}} +} +