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@+4{{expected ':'}}
+// expected-note@+3{{to match this '?'}}
+// expected-warning@+2{{variable 'b' is uninitialized}}
+// expected-error@+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());
   }


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@+4{{expected ':'}}
+// expected-note@+3{{to match this '?'}}
+// expected-warning@+2{{variable 'b' is uninitialized}}
+// expected-error@+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());
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D85601: F... Mark de Wever via Phabricator via cfe-commits

Reply via email to