[cfe-commits] r67746 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/Sema/indirect-goto.c

Eli Friedman eli.friedman at gmail.com
Thu Mar 26 00:32:37 PDT 2009


Author: efriedma
Date: Thu Mar 26 02:32:37 2009
New Revision: 67746

URL: http://llvm.org/viewvc/llvm-project?rev=67746&view=rev
Log:
Sanity-check argument to indirect goto.


Added:
    cfe/trunk/test/Sema/indirect-goto.c
Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=67746&r1=67745&r2=67746&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Mar 26 02:32:37 2009
@@ -687,10 +687,14 @@
 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));
 }
 

Added: cfe/trunk/test/Sema/indirect-goto.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/indirect-goto.c?rev=67746&view=auto

==============================================================================
--- cfe/trunk/test/Sema/indirect-goto.c (added)
+++ cfe/trunk/test/Sema/indirect-goto.c Thu Mar 26 02:32:37 2009
@@ -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}}
+}
+





More information about the cfe-commits mailing list