[cfe-commits] r44462 - in /cfe/trunk: AST/Expr.cpp Analysis/UninitializedValues.cpp Sema/SemaChecking.cpp test/Analysis/conditional-op-missing-lhs.c
Anders Carlsson
andersca at mac.com
Fri Nov 30 11:04:31 PST 2007
Author: andersca
Date: Fri Nov 30 13:04:31 2007
New Revision: 44462
URL: http://llvm.org/viewvc/llvm-project?rev=44462&view=rev
Log:
GCC has an extension where the left hand side of the ? : operator can be omitted. Handle this in a few more places.
Added:
cfe/trunk/test/Analysis/conditional-op-missing-lhs.c
Modified:
cfe/trunk/AST/Expr.cpp
cfe/trunk/Analysis/UninitializedValues.cpp
cfe/trunk/Sema/SemaChecking.cpp
Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=44462&r1=44461&r2=44462&view=diff
==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Fri Nov 30 13:04:31 2007
@@ -494,7 +494,8 @@
case ConditionalOperatorClass: {
const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
if (!Exp->getCond()->isConstantExpr(Ctx, Loc) ||
- !Exp->getLHS()->isConstantExpr(Ctx, Loc) ||
+ // Handle the GNU extension for missing LHS.
+ !(Exp->getLHS() && Exp->getLHS()->isConstantExpr(Ctx, Loc)) ||
!Exp->getRHS()->isConstantExpr(Ctx, Loc))
return false;
return true;
@@ -809,10 +810,11 @@
if (Result == 0) std::swap(TrueExp, FalseExp);
// Evaluate the false one first, discard the result.
- if (!FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
+ if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
return false;
// Evalute the true one, capture the result.
- if (!TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
+ if (TrueExp &&
+ !TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
return false;
break;
}
Modified: cfe/trunk/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/UninitializedValues.cpp?rev=44462&r1=44461&r2=44462&view=diff
==============================================================================
--- cfe/trunk/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/Analysis/UninitializedValues.cpp Fri Nov 30 13:04:31 2007
@@ -145,7 +145,13 @@
bool TransferFuncs::VisitConditionalOperator(ConditionalOperator* C) {
Visit(C->getCond());
- return Visit(C->getLHS()) & Visit(C->getRHS()); // Yes: we want &, not &&.
+
+ bool rhsResult = Visit(C->getRHS());
+ // Handle the GNU extension for missing LHS.
+ if (Expr *lhs = C->getLHS())
+ return Visit(lhs) & rhsResult; // Yes: we want &, not &&.
+ else
+ return rhsResult;
}
bool TransferFuncs::VisitStmt(Stmt* S) {
Modified: cfe/trunk/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaChecking.cpp?rev=44462&r1=44461&r2=44462&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/Sema/SemaChecking.cpp Fri Nov 30 13:04:31 2007
@@ -564,10 +564,12 @@
case Stmt::ConditionalOperatorClass: {
ConditionalOperator *C = cast<ConditionalOperator>(E);
- if (DeclRefExpr* LHS = EvalAddr(C->getLHS()))
- return LHS;
- else
- return EvalAddr(C->getRHS());
+ // Handle the GNU extension for missing LHS.
+ if (Expr *lhsExpr = C->getLHS())
+ if (DeclRefExpr* LHS = EvalAddr(lhsExpr))
+ return LHS;
+
+ return EvalAddr(C->getRHS());
}
// For implicit casts, we need to handle conversions from arrays to
@@ -674,10 +676,12 @@
// non-NULL DeclRefExpr's. If one is non-NULL, we return it.
ConditionalOperator *C = cast<ConditionalOperator>(E);
- if (DeclRefExpr *LHS = EvalVal(C->getLHS()))
- return LHS;
- else
- return EvalVal(C->getRHS());
+ // Handle the GNU extension for missing LHS.
+ if (Expr *lhsExpr = C->getLHS())
+ if (DeclRefExpr *LHS = EvalVal(lhsExpr))
+ return LHS;
+
+ return EvalVal(C->getRHS());
}
// Accesses to members are potential references to data on the stack.
Added: cfe/trunk/test/Analysis/conditional-op-missing-lhs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/conditional-op-missing-lhs.c?rev=44462&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/conditional-op-missing-lhs.c (added)
+++ cfe/trunk/test/Analysis/conditional-op-missing-lhs.c Fri Nov 30 13:04:31 2007
@@ -0,0 +1,26 @@
+// RUN: clang -warn-dead-stores -warn-uninit-values -verify %s
+
+void f1()
+{
+ int i;
+
+ int j = i ? : 1; // expected-warning{{use of uninitialized variable}}
+}
+
+void *f2(int *i)
+{
+ return i ? : 0;
+}
+
+void *f3(int *i)
+{
+ int a;
+
+ return &a ? : i;
+}
+
+void f4()
+{
+ char c[1 ? : 2];
+}
+
More information about the cfe-commits
mailing list