[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 16 09:36:36 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG827ba67e3833: [Sema] Validate calls to GetExprRange. (authored by Mordante).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85601/new/
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,20 @@
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;
+ long d = a = b ? 1 : throw 0;
+ // expected-error at +1 {{assigning to 'int' from incompatible type 'void'}}
+ long e = a = b ? throw 0 : throw 1;
+}
+} // namespace PR46484
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10368,10 +10368,16 @@
MaxWidth, InConstantContext);
// Otherwise, conservatively merge.
- IntRange L =
- GetExprRange(C, CO->getTrueExpr(), MaxWidth, InConstantContext);
- IntRange R =
- GetExprRange(C, CO->getFalseExpr(), MaxWidth, InConstantContext);
+ // GetExprRange requires an integer expression, but a throw expression
+ // results in a void type.
+ Expr *E = CO->getTrueExpr();
+ IntRange L = E->getType()->isVoidType()
+ ? IntRange{0, true}
+ : GetExprRange(C, E, MaxWidth, InConstantContext);
+ E = CO->getFalseExpr();
+ IntRange R = E->getType()->isVoidType()
+ ? IntRange{0, true}
+ : GetExprRange(C, E, MaxWidth, InConstantContext);
return IntRange::join(L, R);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85601.285892.patch
Type: text/x-patch
Size: 1806 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200816/bb14d44e/attachment.bin>
More information about the cfe-commits
mailing list