[PATCH] D85601: Fixes an assertion when IntRange processes a throw expression

Mark de Wever via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 9 04:58:49 PDT 2020


Mordante created this revision.
Mordante added reviewers: rsmith, rjmccall.
Mordante added a project: clang.
Mordante requested review of this revision.

Fixes PR46484: Clang crash in clang/lib/Sema/SemaChecking.cpp:10028


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85601

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/conditional-expr.cpp


Index: clang/test/SemaCXX/conditional-expr.cpp
===================================================================
--- clang/test/SemaCXX/conditional-expr.cpp
+++ clang/test/SemaCXX/conditional-expr.cpp
@@ -409,3 +409,17 @@
     D d = b ? D{B()} : D{C()};
   }
 }
+
+namespace PR46484 {
+// expected-error at +4{{expected ':'}}
+// expected-note at +3{{to match this '?'}}
+// expected-warning at +2{{variable 'b' is uninitialized}}
+// expected-error at +1 2 {{expected ';' after top level declarator}}
+int a long b = a = b ? throw 0 1
+
+void g() {
+  extern int a;
+  extern long b;
+  long c = a = b ? throw 0 : 1;
+}
+} // namespace PR46484
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10161,7 +10161,13 @@
       return IntRange(EIT->getNumBits(), EIT->isUnsigned());
 
     const BuiltinType *BT = cast<BuiltinType>(T);
-    assert(BT->isInteger());
+    if (!BT->isInteger()) {
+      // This can happen in a conditional expression with a throw statement
+      // C++11 [expr.cond]p2
+      //   If either the second or the third operand has type (cv) void, ...
+      assert(BT->isVoidType());
+      IntRange(1, true /*NonNegative*/);
+    }
 
     return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85601.284187.patch
Type: text/x-patch
Size: 1365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200809/8a3b3191/attachment.bin>


More information about the cfe-commits mailing list