[PATCH] D72242: Fix crash on value dependent bitfields in if conditions in templates
Elizabeth Andrews via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 5 19:39:21 PST 2020
eandrews created this revision.
eandrews added reviewers: rnk, erichkeane, alexfh, alexfh_.
This patch is a follow up to D69950 <https://reviews.llvm.org/D69950>, to fix a new crash on CXX condition expressions in templates, for value dependent bitfields. Clang currently crashes when integral promotion is attempted on the condition. This patch adds a guard to prevent the promotion for value dependent bitfields. Prior to D69950 <https://reviews.llvm.org/D69950>, the guard was unnecessary because incorrect type dependency of bitfield prevented the compiler from reaching this code.
https://reviews.llvm.org/D72242
Files:
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template<int b>
+class a {
+ int c : b;
+ void f() {
+ if (c)
+ ;
+ }
+};
+
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -2158,6 +2158,7 @@
if (FieldDecl *MemberDecl = From->getSourceBitField()) {
llvm::APSInt BitWidth;
if (FromType->isIntegralType(Context) &&
+ !MemberDecl->getBitWidth()->isValueDependent() &&
MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) {
llvm::APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned());
ToSize = Context.getTypeSize(ToType);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72242.236290.patch
Type: text/x-patch
Size: 997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200106/7ac86c71/attachment.bin>
More information about the cfe-commits
mailing list