Skip to content

[clang][Interp] Fix BooleanToSignedIntegral casts for IntAP(S) #102302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions clang/lib/AST/Interp/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,25 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
}
}

auto maybeNegate = [&]() -> bool {
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
return this->emitNeg(*ToT, CE);
return true;
};

if (ToT == PT_IntAP)
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
maybeNegate();
if (ToT == PT_IntAPS)
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
maybeNegate();

if (FromT == ToT)
return true;
if (!this->emitCast(*FromT, *ToT, CE))
return false;

if (CE->getCastKind() == CK_BooleanToSignedIntegral)
return this->emitNeg(*ToT, CE);
return true;
return maybeNegate();
}

case CK_PointerToBoolean:
Expand Down
11 changes: 11 additions & 0 deletions clang/test/AST/Interp/vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,14 @@ namespace Temporaries {
};
int &&s = S().w[1];
}

#ifdef __SIZEOF_INT128__
namespace bigint {
typedef __attribute__((__ext_vector_type__(4))) __int128 bigint4;
constexpr bigint4 A = (bigint4)true;
static_assert(A[0] == -1, "");
static_assert(A[1] == -1, "");
static_assert(A[2] == -1, "");
static_assert(A[3] == -1, "");
}
#endif
Loading