[cfe-commits] r82129 - in /cfe/trunk: lib/AST/Expr.cpp lib/Sema/SemaExpr.cpp test/SemaCXX/value-dependent-exprs.cpp
Daniel Dunbar
daniel at zuster.org
Wed Sep 16 23:31:28 PDT 2009
Author: ddunbar
Date: Thu Sep 17 01:31:27 2009
New Revision: 82129
URL: http://llvm.org/viewvc/llvm-project?rev=82129&view=rev
Log:
Fix two crashes on value dependent expressions (shift and null-pointer check).
- Doug, please check.
- PR4940.
Added:
cfe/trunk/test/SemaCXX/value-dependent-exprs.cpp
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=82129&r1=82128&r2=82129&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu Sep 17 01:31:27 2009
@@ -1626,6 +1626,9 @@
/// integer constant expression with the value zero, or if this is one that is
/// cast to void*.
bool Expr::isNullPointerConstant(ASTContext &Ctx) const {
+ // Ignore value dependent expressions.
+ if (isValueDependent())
+ return true;
// Strip off a cast to void*, if it exists. Except in C++.
if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
if (!Ctx.getLangOptions().CPlusPlus) {
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=82129&r1=82128&r2=82129&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 17 01:31:27 2009
@@ -4339,7 +4339,8 @@
// Sanity-check shift operands
llvm::APSInt Right;
// Check right/shifter operand
- if (rex->isIntegerConstantExpr(Right, Context)) {
+ if (!rex->isValueDependent() &&
+ rex->isIntegerConstantExpr(Right, Context)) {
if (Right.isNegative())
Diag(Loc, diag::warn_shift_negative) << rex->getSourceRange();
else {
Added: cfe/trunk/test/SemaCXX/value-dependent-exprs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/value-dependent-exprs.cpp?rev=82129&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/value-dependent-exprs.cpp (added)
+++ cfe/trunk/test/SemaCXX/value-dependent-exprs.cpp Thu Sep 17 01:31:27 2009
@@ -0,0 +1,44 @@
+// RUN: clang-cc -verify %s
+
+template <unsigned I>
+class C0 {
+ static const int iv0 = 1 << I;
+
+ enum {
+ A = I,
+ B = I + 1
+ };
+
+ struct s0 {
+ int a : I;
+ int b[I];
+ };
+
+ void f0(int *p) {
+ if (p == I) {
+ }
+ }
+
+#if 0
+ // FIXME: Not sure whether we care about these.
+ void f1(int *a)
+ __attribute__((nonnull(1 + I)))
+ __attribute__((constructor(1 + I)))
+ __attribute__((destructor(1 + I)))
+ __attribute__((sentinel(1 + I, 2 + I))),
+ __attribute__((reqd_work_group_size(1 + I, 2 + I, 3 + I))),
+ __attribute__((format_arg(1 + I))),
+ __attribute__((aligned(1 + I))),
+ __attribute__((regparm(1 + I)));
+
+ typedef int int_a0 __attribute__((address_space(1 + B)));
+#endif
+
+#if 0
+ // FIXME: This doesn't work. PR4996.
+ int f2() {
+ return __builtin_choose_expr(I, 1, 2);
+ }
+#endif
+
+};
More information about the cfe-commits
mailing list