[llvm-branch-commits] [cfe-branch] r227243 - Merging r227220:

Hans Wennborg hans at hanshq.net
Tue Jan 27 12:53:44 PST 2015


Author: hans
Date: Tue Jan 27 14:53:43 2015
New Revision: 227243

URL: http://llvm.org/viewvc/llvm-project?rev=227243&view=rev
Log:
Merging r227220:
------------------------------------------------------------------------
r227220 | rikka | 2015-01-27 10:26:18 -0800 (Tue, 27 Jan 2015) | 7 lines

Properly handle typos in the conditional of ?: expressions in C.

In particular, remove the OpaqueExpr transformation from r225389 and
move the correction of the conditional from CheckConditionalOperands to
ActOnConditionalOp before the OpaqueExpr is created. This fixes the
typo correction behavior in C code that uses the GNU extension for a
binary ?: (without an expression between the "?" and the ":").
------------------------------------------------------------------------

Modified:
    cfe/branches/release_36/   (props changed)
    cfe/branches/release_36/lib/Sema/SemaExpr.cpp
    cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp
    cfe/branches/release_36/test/Sema/typo-correction.c

Propchange: cfe/branches/release_36/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 27 14:53:43 2015
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:226008,226049,226136,226282,226624,226707,226754,226863,226877,227062
+/cfe/trunk:226008,226049,226136,226282,226624,226707,226754,226863,226877,227062,227220
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_36/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/lib/Sema/SemaExpr.cpp?rev=227243&r1=227242&r2=227243&view=diff
==============================================================================
--- cfe/branches/release_36/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/release_36/lib/Sema/SemaExpr.cpp Tue Jan 27 14:53:43 2015
@@ -5785,15 +5785,6 @@ QualType Sema::CheckConditionalOperands(
                                         ExprObjectKind &OK,
                                         SourceLocation QuestionLoc) {
 
-  if (!getLangOpts().CPlusPlus) {
-    // C cannot handle TypoExpr nodes on either side of a binop because it
-    // doesn't handle dependent types properly, so make sure any TypoExprs have
-    // been dealt with before checking the operands.
-    ExprResult CondResult = CorrectDelayedTyposInExpr(Cond);
-    if (!CondResult.isUsable()) return QualType();
-    Cond = CondResult;
-  }
-
   ExprResult LHSResult = CheckPlaceholderExpr(LHS.get());
   if (!LHSResult.isUsable()) return QualType();
   LHS = LHSResult;
@@ -6173,6 +6164,15 @@ ExprResult Sema::ActOnConditionalOp(Sour
                                     SourceLocation ColonLoc,
                                     Expr *CondExpr, Expr *LHSExpr,
                                     Expr *RHSExpr) {
+  if (!getLangOpts().CPlusPlus) {
+    // C cannot handle TypoExpr nodes in the condition because it
+    // doesn't handle dependent types properly, so make sure any TypoExprs have
+    // been dealt with before checking the operands.
+    ExprResult CondResult = CorrectDelayedTyposInExpr(CondExpr);
+    if (!CondResult.isUsable()) return ExprError();
+    CondExpr = CondResult.get();
+  }
+
   // If this is the gnu "x ?: y" extension, analyze the types as though the LHS
   // was the condition.
   OpaqueValueExpr *opaqueValue = nullptr;

Modified: cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp?rev=227243&r1=227242&r2=227243&view=diff
==============================================================================
--- cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/branches/release_36/lib/Sema/SemaExprCXX.cpp Tue Jan 27 14:53:43 2015
@@ -6143,12 +6143,6 @@ public:
 
   ExprResult TransformLambdaExpr(LambdaExpr *E) { return Owned(E); }
 
-  ExprResult TransformOpaqueValueExpr(OpaqueValueExpr *E) {
-    if (Expr *SE = E->getSourceExpr())
-      return TransformExpr(SE);
-    return BaseTransform::TransformOpaqueValueExpr(E);
-  }
-
   ExprResult Transform(Expr *E) {
     ExprResult Res;
     while (true) {

Modified: cfe/branches/release_36/test/Sema/typo-correction.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_36/test/Sema/typo-correction.c?rev=227243&r1=227242&r2=227243&view=diff
==============================================================================
--- cfe/branches/release_36/test/Sema/typo-correction.c (original)
+++ cfe/branches/release_36/test/Sema/typo-correction.c Tue Jan 27 14:53:43 2015
@@ -13,6 +13,11 @@ void PR21656() {
 a = b ? : 0;  // expected-warning {{type specifier missing, defaults to 'int'}} \
               // expected-error {{use of undeclared identifier 'b'}}
 
+int foobar;  // expected-note {{'foobar' declared here}}
+a = goobar ?: 4;  // expected-warning {{type specifier missing, defaults to 'int'}} \
+                  // expected-error {{use of undeclared identifier 'goobar'; did you mean 'foobar'?}} \
+                  // expected-error {{initializer element is not a compile-time constant}}
+
 struct ContainerStuct {
   enum { SOME_ENUM }; // expected-note {{'SOME_ENUM' declared here}}
 };





More information about the llvm-branch-commits mailing list