Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17078,7 +17078,24 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
case CK_HLSLAggregateSplatCast:
llvm_unreachable("invalid cast kind for integral value");

case CK_BitCast:
case CK_BitCast:{
APValue Sub;
if (!Evaluate(Sub, Info, E->getSubExpr()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know the types before evaluating the subexpression, so we don't have to do this unless the sizes match.

return false;

QualType SrcTy = E->getSubExpr()->getType();
QualType DstTy = E->getType();

// Allow reinterpretation if bit widths match
if (Info.Ctx.getTypeSize(SrcTy) == Info.Ctx.getTypeSize(DstTy)) {
// Use APValue::BitCast if available, else just copy value bits
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is APValue::BitCast?

Result = Sub;
return true;
}

return Error(E);
}

case CK_Dependent:
case CK_LValueBitCast:
case CK_ARCProduceObject:
Expand Down
Loading