Skip to content

Commit

Permalink
changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
gitoleg committed Jan 25, 2024
1 parent 124db70 commit 6b829fa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 41 deletions.
46 changes: 27 additions & 19 deletions clang/lib/CIR/CodeGen/CIRGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,33 +151,41 @@ CIRGenFunction::buildAutoVarAlloca(const VarDecl &D) {
assert(!UnimplementedFeature::shouldEmitLifetimeMarkers());
}
} else { // not openmp nor constant sized type
bool VarAllocated = false;
if (getLangOpts().OpenMPIsTargetDevice)
llvm_unreachable("NYI");

if (!DidCallStackSave) {
// Save the stack.
auto defaultTy = AllocaInt8PtrTy;
CharUnits Align = CharUnits::fromQuantity(
CGM.getDataLayout().getAlignment(defaultTy, false));
Address Stack = CreateTempAlloca(defaultTy, Align, loc, "saved_stack");
if (!VarAllocated) {
if (!DidCallStackSave) {
// Save the stack.
auto defaultTy = AllocaInt8PtrTy;
CharUnits Align = CharUnits::fromQuantity(
CGM.getDataLayout().getAlignment(defaultTy, false));
Address Stack = CreateTempAlloca(defaultTy, Align, loc, "saved_stack");

mlir::Value V = builder.createStackSave(loc, defaultTy);
assert(V.getType() == AllocaInt8PtrTy);
builder.createStore(loc, V, Stack);
mlir::Value V = builder.createStackSave(loc, defaultTy);
assert(V.getType() == AllocaInt8PtrTy);
builder.createStore(loc, V, Stack);

DidCallStackSave = true;
DidCallStackSave = true;

// Push a cleanup block and restore the stack there.
// FIXME: in general circumstances, this should be an EH cleanup.
pushStackRestore(NormalCleanup, Stack);
}
// Push a cleanup block and restore the stack there.
// FIXME: in general circumstances, this should be an EH cleanup.
pushStackRestore(NormalCleanup, Stack);
}

auto VlaSize = getVLASize(Ty);
mlir::Type mTy = convertTypeForMem(VlaSize.Type);
auto VlaSize = getVLASize(Ty);
mlir::Type mTy = convertTypeForMem(VlaSize.Type);

// Allocate memory for the array.
address = CreateTempAlloca(mTy, alignment, loc, "vla", VlaSize.NumElts,
&allocaAddr, builder.saveInsertionPoint());
}

// Allocate memory for the array.
address = CreateTempAlloca(mTy, alignment, loc, "vla", VlaSize.NumElts,
&allocaAddr, builder.saveInsertionPoint());
// If we have debug info enabled, properly describe the VLA dimensions for
// this type by registering the vla size expression for each of the
// dimensions.
assert(!UnimplementedFeature::generateDebugInfo());
}

emission.Addr = address;
Expand Down
25 changes: 4 additions & 21 deletions clang/lib/CIR/CodeGen/CIRGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,9 +1423,12 @@ CIRGenFunction::getVLASize(const VariableArrayType *type) {
}
} while ((type = getContext().getAsVariableArrayType(elementType)));

assert(numElements && "Undefined elements number");
return {numElements, elementType};
}

// TODO(cir): most part of this function can be shared between CIRGen
// and traditional LLVM codegen
void CIRGenFunction::buildVariablyModifiedType(QualType type) {
assert(type->isVariablyModifiedType() &&
"Must pass variably modified type to EmitVLASizes!");
Expand Down Expand Up @@ -1510,27 +1513,7 @@ void CIRGenFunction::buildVariablyModifiedType(QualType type) {
mlir::Value &entry = VLASizeMap[sizeExpr];
if (!entry) {
mlir::Value size = buildScalarExpr(sizeExpr);

// // C11 6.7.6.2p5:
// // If the size is an expression that is not an integer constant
// // expression [...] each time it is evaluated it shall have a
// // value greater than zero.
// if (SanOpts.has(SanitizerKind::VLABound)) {
// SanitizerScope SanScope(this);
// llvm::Value *Zero =
// llvm::Constant::getNullValue(size->getType()); clang::QualType
// SEType = sizeExpr->getType(); llvm::Value *CheckCondition =
// SEType->isSignedIntegerType()
// ? Builder.CreateICmpSGT(size, Zero)
// : Builder.CreateICmpUGT(size, Zero);
// llvm::Constant *StaticArgs[] = {
// EmitCheckSourceLocation(sizeExpr->getBeginLoc()),
// EmitCheckTypeDescriptor(SEType)};
// EmitCheck(std::make_pair(CheckCondition,
// SanitizerKind::VLABound),
// SanitizerHandler::VLABoundNotPositive, StaticArgs,
// size);
// }
assert(!UnimplementedFeature::sanitizeVLABound());

// Always zexting here would be wrong if it weren't
// undefined behavior to have a negative bound.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CIRGenFunction : public CIRGenTypeCache {
llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues;
llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues;

// VLASizeMap - This keeps track of the associated size for each VLA type.
// This keeps track of the associated size for each VLA type.
// We track this by the size expression rather than the type itself because
// in certain situations, like a const qualifier applied to an VLA typedef,
// multiple VLA types can share the same size expression.
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/CodeGen/UnimplementedFeatureGuarding.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct UnimplementedFeature {
static bool emitCheckedInBoundsGEP() { return false; }
static bool pointerOverflowSanitizer() { return false; }
static bool sanitizeDtor() { return false; }
static bool sanitizeVLABound() { return false; }

// ObjC
static bool setObjCGCLValueClass() { return false; }
Expand Down

0 comments on commit 6b829fa

Please sign in to comment.