Skip to content
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
5 changes: 1 addition & 4 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3600,8 +3600,6 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
if (PlacementDest) {
if (!this->visit(PlacementDest))
return false;
if (!this->emitStartLifetime(E))
return false;
if (!this->emitGetLocal(SizeT, ArrayLen, E))
return false;
if (!this->emitCheckNewTypeMismatchArray(SizeT, E, E))
Expand Down Expand Up @@ -3741,10 +3739,9 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
if (PlacementDest) {
if (!this->visit(PlacementDest))
return false;
if (!this->emitStartLifetime(E))
return false;
if (!this->emitCheckNewTypeMismatch(E, E))
return false;

} else {
// Allocate just one element.
if (!this->emitAlloc(Desc, E))
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,12 +1903,19 @@ bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, const Expr *E,
if (Ptr.inUnion() && Ptr.getBase().getRecord()->isUnion())
Ptr.activate();

if (Ptr.isZero()) {
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_null)
<< AK_Construct;
return false;
}

if (!Ptr.isBlockPointer())
return false;

startLifetimeRecurse(Ptr);

// Similar to CheckStore(), but with the additional CheckTemporary() call and
// the AccessKinds are different.

if (!Ptr.block()->isAccessible()) {
if (!CheckExtern(S, OpPC, Ptr))
return false;
Expand Down
10 changes: 2 additions & 8 deletions clang/lib/AST/ByteCode/Opcodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -853,19 +853,13 @@ def Free : Opcode {
let Args = [ArgBool, ArgBool];
}

def CheckNewTypeMismatch : Opcode {
let Args = [ArgExpr];
}

def InvalidNewDeleteExpr : Opcode {
let Args = [ArgExpr];
}

def CheckNewTypeMismatch : Opcode { let Args = [ArgExpr]; }
def CheckNewTypeMismatchArray : Opcode {
let Types = [IntegerTypeClass];
let Args = [ArgExpr];
let HasGroup = 1;
}
def InvalidNewDeleteExpr : Opcode { let Args = [ArgExpr]; }

def IsConstantContext: Opcode;
def CheckAllocations : Opcode;
Expand Down
29 changes: 29 additions & 0 deletions clang/test/AST/ByteCode/placement-new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,32 @@ constexpr int modify_const_variable() {
}
static_assert(modify_const_variable()); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}

constexpr int nullDest() {
new (nullptr) int{12}; // both-note {{construction of dereferenced null pointer}}
return 0;
}
static_assert(nullDest() == 0); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}

constexpr int nullArrayDest() {
new (nullptr) int{12}; // both-note {{construction of dereferenced null pointer}}
return 0;
}
static_assert(nullArrayDest() == 0); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}

constexpr int intDest() {
new ((void*)2) int{3}; // both-note {{cast that performs the conversions of a reinterpret_cast}}
return 0;
}
static_assert(intDest() == 0); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}

constexpr int intDestArray() {
new ((void*)2) int[4]; // both-note {{cast that performs the conversions of a reinterpret_cast}}
return 0;
}
static_assert(intDestArray() == 0); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}