]> granicus.if.org Git - clang/commitdiff
Sanity-check argument to indirect goto.
authorEli Friedman <eli.friedman@gmail.com>
Thu, 26 Mar 2009 07:32:37 +0000 (07:32 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 26 Mar 2009 07:32:37 +0000 (07:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67746 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp
test/Sema/indirect-goto.c [new file with mode: 0644]

index 4ef0fda36123be9dc784d9a28c86d71db2e48b54..bbcc71d6e4d238b18ff679d6cf4b3b3867ac99f9 100644 (file)
@@ -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<Expr>();
+  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/test/Sema/indirect-goto.c b/test/Sema/indirect-goto.c
new file mode 100644 (file)
index 0000000..35fb5e6
--- /dev/null
@@ -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}}
+}
+