-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][bytecode] Handle invalid temporary descriptors #125033
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
Conversation
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesThis happens e.g. when a vector element type is not primitive. Full diff: https://github.com/llvm/llvm-project/pull/125033.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 4659d0e00784d9..f7f4f713c787f2 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -562,8 +562,10 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
// We're creating a complex value here, so we need to
// allocate storage for it.
if (!Initializing) {
- unsigned LocalIndex = allocateTemporary(CE);
- if (!this->emitGetPtrLocal(LocalIndex, CE))
+ std::optional<unsigned> LocalIndex = allocateTemporary(CE);
+ if (!LocalIndex)
+ return false;
+ if (!this->emitGetPtrLocal(*LocalIndex, CE))
return false;
}
@@ -679,8 +681,10 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
assert(CE->getType()->isVectorType());
if (!Initializing) {
- unsigned LocalIndex = allocateTemporary(CE);
- if (!this->emitGetPtrLocal(LocalIndex, CE))
+ std::optional<unsigned> LocalIndex = allocateTemporary(CE);
+ if (!LocalIndex)
+ return false;
+ if (!this->emitGetPtrLocal(*LocalIndex, CE))
return false;
}
unsigned ToSize = CE->getType()->getAs<VectorType>()->getNumElements();
@@ -759,8 +763,10 @@ bool Compiler<Emitter>::VisitImaginaryLiteral(const ImaginaryLiteral *E) {
return true;
if (!Initializing) {
- unsigned LocalIndex = allocateTemporary(E);
- if (!this->emitGetPtrLocal(LocalIndex, E))
+ std::optional<unsigned> LocalIndex = allocateTemporary(E);
+ if (!LocalIndex)
+ return false;
+ if (!this->emitGetPtrLocal(*LocalIndex, E))
return false;
}
@@ -1118,8 +1124,10 @@ template <class Emitter>
bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
// Prepare storage for result.
if (!Initializing) {
- unsigned LocalIndex = allocateTemporary(E);
- if (!this->emitGetPtrLocal(LocalIndex, E))
+ std::optional<unsigned> LocalIndex = allocateTemporary(E);
+ if (!LocalIndex)
+ return false;
+ if (!this->emitGetPtrLocal(*LocalIndex, E))
return false;
}
@@ -1175,7 +1183,10 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
if (!LHSIsComplex) {
// This is using the RHS type for the fake-complex LHS.
- LHSOffset = allocateTemporary(RHS);
+ std::optional<unsigned> LocalIndex = allocateTemporary(RHS);
+ if (!LocalIndex)
+ return false;
+ LHSOffset = *LocalIndex;
if (!this->emitGetPtrLocal(LHSOffset, E))
return false;
@@ -1347,8 +1358,10 @@ bool Compiler<Emitter>::VisitVectorBinOp(const BinaryOperator *E) {
// Prepare storage for result.
if (!Initializing && !E->isCompoundAssignmentOp()) {
- unsigned LocalIndex = allocateTemporary(E);
- if (!this->emitGetPtrLocal(LocalIndex, E))
+ std::optional<unsigned> LocalIndex = allocateTemporary(E);
+ if (!LocalIndex)
+ return false;
+ if (!this->emitGetPtrLocal(*LocalIndex, E))
return false;
}
@@ -4170,14 +4183,16 @@ Compiler<Emitter>::allocateLocal(DeclTy &&Src, QualType Ty,
}
template <class Emitter>
-unsigned Compiler<Emitter>::allocateTemporary(const Expr *E) {
+std::optional<unsigned> Compiler<Emitter>::allocateTemporary(const Expr *E) {
QualType Ty = E->getType();
assert(!Ty->isRecordType());
Descriptor *D = P.createDescriptor(
E, Ty.getTypePtr(), Descriptor::InlineDescMD, Ty.isConstQualified(),
/*IsTemporary=*/true, /*IsMutable=*/false, /*Init=*/nullptr);
- assert(D);
+
+ if (!D)
+ return std::nullopt;
Scope::Local Local = this->createLocal(D);
VariableScope<Emitter> *S = VarScope;
diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h
index f9a597a16ef4ae..5a02f38d78dec8 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -309,7 +309,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
std::optional<unsigned>
allocateLocal(DeclTy &&Decl, QualType Ty = QualType(),
const ValueDecl *ExtendingDecl = nullptr);
- unsigned allocateTemporary(const Expr *E);
+ std::optional<unsigned> allocateTemporary(const Expr *E);
private:
friend class VariableScope<Emitter>;
|
This happens e.g. when a vector element type is not primitive.
c63d51e
to
0269823
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/50/builds/9675 Here is the relevant piece of the build log for the reference
|
This happens e.g. when a vector element type is not primitive.