[cfe-commits] r51002 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaExpr.cpp test/Sema/conditional-expr.c

Steve Naroff snaroff at apple.com
Mon May 12 14:44:40 PDT 2008


Author: snaroff
Date: Mon May 12 16:44:38 2008
New Revision: 51002

URL: http://llvm.org/viewvc/llvm-project?rev=51002&view=rev
Log:
Fix <rdar://problem/5928590> clang -fsyntax-only: "incompatible operand types ('int' and 'void')" on input that 'gcc -fsyntax-only' eats

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/conditional-expr.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=51002&r1=51001&r2=51002&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Mon May 12 16:44:38 2008
@@ -904,6 +904,8 @@
      "ordered compare requires two args of floating point type ('%0' and '%1')")
 DIAG(err_typecheck_cond_expect_scalar, ERROR,
      "used type '%0' where arithmetic or pointer type is required")
+DIAG(ext_typecheck_cond_one_void, EXTENSION,
+     "C99 forbids conditional expressions with only one void side")
 DIAG(err_typecheck_expect_scalar_operand, ERROR,
      "operand of type '%0' where arithmetic or pointer type is required")
 DIAG(err_typecheck_cond_incompatible_operands, ERROR,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon May 12 16:44:38 2008
@@ -856,9 +856,16 @@
   }
   
   // C99 6.5.15p5: "If both operands have void type, the result has void type."
-  if (lexT->isVoidType() && rexT->isVoidType())
+  // The following || allows only one side to be void (a GCC-ism).
+  if (lexT->isVoidType() || rexT->isVoidType()) {
+    if (!lexT->isVoidType())
+      Diag(rex->getLocStart(), diag::ext_typecheck_cond_one_void, 
+           rex->getSourceRange());
+    if (!rexT->isVoidType())
+      Diag(lex->getLocStart(), diag::ext_typecheck_cond_one_void,
+           lex->getSourceRange());    
     return lexT.getUnqualifiedType();
-
+  }
   // C99 6.5.15p6 - "if one operand is a null pointer constant, the result has
   // the type of the other operand."
   if (lexT->isPointerType() && rex->isNullPointerConstant(Context)) {

Modified: cfe/trunk/test/Sema/conditional-expr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/conditional-expr.c?rev=51002&r1=51001&r2=51002&view=diff

==============================================================================
--- cfe/trunk/test/Sema/conditional-expr.c (original)
+++ cfe/trunk/test/Sema/conditional-expr.c Mon May 12 16:44:38 2008
@@ -36,3 +36,7 @@
   *(0 ? (asdf) 0 : &x) = 10;
 }
 
+int Postgresql() {
+  char x;
+  return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+}





More information about the cfe-commits mailing list