Skip to content

Commit d541a4c

Browse files
committed
Added an assertion about overflow in sizeof evaluation. This does not solve the underlying structural issue that is waiting for a proper solution.
llvm-svn: 146482
1 parent 2f1d93f commit d541a4c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,9 @@ ASTContext::getTypeInfo(const Type *T) const {
852852
const ConstantArrayType *CAT = cast<ConstantArrayType>(T);
853853

854854
std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType());
855-
Width = EltInfo.first*CAT->getSize().getZExtValue();
855+
uint64_t Size = CAT->getSize().getZExtValue();
856+
assert((Size == 0 || EltInfo.first <= (uint64_t)(-1)/Size) && "Overflow in array type bit size evaluation");
857+
Width = EltInfo.first*Size;
856858
Align = EltInfo.second;
857859
Width = llvm::RoundUpToAlignment(Width, Align);
858860
break;

0 commit comments

Comments
 (0)