[cfe-commits] r60319 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/Sema.h lib/Sema/SemaExpr.cpp test/Sema/i-c-e3.c

Anders Carlsson andersca at mac.com
Sun Nov 30 18:17:22 PST 2008


Author: andersca
Date: Sun Nov 30 20:17:22 2008
New Revision: 60319

URL: http://llvm.org/viewvc/llvm-project?rev=60319&view=rev
Log:
Add Sema::isNullPointerConstant which extwarns if necessary. Use it in Sema::CheckConditionalOperands.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/i-c-e3.c

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sun Nov 30 20:17:22 2008
@@ -622,6 +622,9 @@
 DIAG(ext_expr_not_ice, EXTENSION,
      "expression is not integer constant expression "
      "(but is allowed as an extension)")
+DIAG(ext_null_pointer_expr_not_ice, EXTENSION,
+     "null pointer expression is not an integer constant expression "
+     "(but is allowed as an extension)")
 
 DIAG(note_comma_in_ice, NOTE,
      "C does not permit evaluated commas in an integer constant expression")
@@ -965,8 +968,6 @@
      "ISO C restricts enumerator values to range of 'int' (%0 is too large)")
 DIAG(warn_enum_too_large, WARNING,
      "enumeration values exceed range of largest integer")
-DIAG(err_case_label_not_integer_constant_expr, ERROR,
-     "case label does not reduce to an integer constant")
 DIAG(warn_illegal_constant_array_size, EXTENSION,
      "size of static array must be an integer constant expression")
 DIAG(err_typecheck_illegal_vla, ERROR,

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=60319&r1=60318&r2=60319&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Nov 30 20:17:22 2008
@@ -1350,7 +1350,9 @@
   /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
   /// and reports the appropriate diagnostics. Returns false on success.
   /// Can optionally return the value of the expression.
-  bool VerifyIntegerConstantExpression(const Expr* E, llvm::APSInt *Result = 0);
+  bool VerifyIntegerConstantExpression(const Expr*E, llvm::APSInt *Result = 0);
+
+  bool isNullPointerConstant(const Expr *E);
 
   //===--------------------------------------------------------------------===//
   // Extra semantic analysis beyond the C type system

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Nov 30 20:17:22 2008
@@ -1582,13 +1582,13 @@
   // the type of the other operand."
   if ((lexT->isPointerType() || lexT->isBlockPointerType() ||
        Context.isObjCObjectPointerType(lexT)) &&
-      rex->isNullPointerConstant(Context)) {
+      isNullPointerConstant(rex)) {
     ImpCastExprToType(rex, lexT); // promote the null to a pointer.
     return lexT;
   }
   if ((rexT->isPointerType() || rexT->isBlockPointerType() ||
        Context.isObjCObjectPointerType(rexT)) &&
-      lex->isNullPointerConstant(Context)) {
+      isNullPointerConstant(lex)) {
     ImpCastExprToType(lex, rexT); // promote the null to a pointer.
     return rexT;
   }
@@ -3706,3 +3706,23 @@
     *Result = EvalResult.Val.getInt();
   return false;
 }
+
+bool Sema::isNullPointerConstant(const Expr *E)
+{
+  Expr::EvalResult EvalResult;
+  
+  if (!E->isNullPointerConstant(EvalResult, Context))
+    return false;
+  
+  if (EvalResult.Diag) {
+    Diag(E->getExprLoc(), diag::ext_null_pointer_expr_not_ice) << 
+      E->getSourceRange();
+
+    // Print the reason it's not a constant.
+    if (Diags.getDiagnosticLevel(diag::ext_null_pointer_expr_not_ice) != 
+        Diagnostic::Ignored)
+      Diag(EvalResult.DiagLoc, EvalResult.Diag);
+  }
+
+  return true;
+}

Modified: cfe/trunk/test/Sema/i-c-e3.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/i-c-e3.c?rev=60319&r1=60318&r2=60319&view=diff

==============================================================================
--- cfe/trunk/test/Sema/i-c-e3.c (original)
+++ cfe/trunk/test/Sema/i-c-e3.c Sun Nov 30 20:17:22 2008
@@ -1,3 +1,3 @@
-// RUN: clang %s -fsyntax-only -verify -pedantic
+// RUN: clang %s -fsyntax-only -verify -pedantic-errors
 
-int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{not assignable}}
+int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{null pointer expression is not an integer constant expression (but is allowed as an extension)}} // expected-note{{C does not permit evaluated commas in an integer constant expression}}





More information about the cfe-commits mailing list