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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits