Skip to content

Commit 305390c

Browse files
committed
Tidy up and style fix
1 parent 0c15dc2 commit 305390c

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
137137
Alloca =
138138
new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
139139
ArraySize, Name, AllocaInsertPt->getIterator());
140-
llvm::errs() << "Alloca name '" << Alloca->getName() << "'\n";
141-
llvm::errs() << "NAME str '" << Name.str() << "'\n";
142140
if (Alloca->getName() != Name.str() &&
143141
SanOpts.Mask & SanitizerKind::Address) {
144142
Alloca->addAnnotationMetadata({"alloca_name_altered", Name.str()});

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,21 +3391,23 @@ static void findStoresToUninstrumentedArgAllocas(
33913391
}
33923392
}
33933393

3394-
StringRef getAllocaName(AllocaInst *AI) {
3394+
static StringRef getAllocaName(AllocaInst *AI) {
33953395
// Alloca could have been renamed for uniqueness. Its true name will have been
33963396
// recorded as an annotation.
33973397
if (AI->hasMetadata(LLVMContext::MD_annotation)) {
3398-
MDTuple *Annotation =
3399-
(MDTuple *)AI->getMetadata(LLVMContext::MD_annotation);
3400-
for (int i = 0; i < Annotation->getNumOperands(); i++) {
3401-
if (auto Tuple = dyn_cast<MDTuple>(Annotation->getOperand(i))) {
3402-
for (int i = 0; i < Tuple->getNumOperands(); i++) {
3403-
if (auto stringMetadata = dyn_cast<MDString>(Tuple->getOperand(i))) {
3404-
if (stringMetadata->getString() == "alloca_name_altered") {
3405-
return ((MDString *)Tuple->getOperand(i + 1).get())->getString();
3406-
}
3407-
}
3408-
}
3398+
MDTuple *AllocaAnnotations =
3399+
cast<MDTuple>(AI->getMetadata(LLVMContext::MD_annotation));
3400+
for (auto &Annotation : AllocaAnnotations->operands()) {
3401+
if (!isa<MDTuple>(Annotation))
3402+
continue;
3403+
auto AnnotationTuple = cast<MDTuple>(Annotation);
3404+
for (int Index = 0; Index < AnnotationTuple->getNumOperands(); Index++) {
3405+
// All annotations are strings
3406+
auto MetadataString =
3407+
cast<MDString>(AnnotationTuple->getOperand(Index));
3408+
if (MetadataString->getString() == "alloca_name_altered")
3409+
return cast<MDString>(AnnotationTuple->getOperand(Index + 1))
3410+
->getString();
34093411
}
34103412
}
34113413
}
@@ -3446,8 +3448,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
34463448
ArgInitInst->moveBefore(InsBefore);
34473449

34483450
// If we have a call to llvm.localescape, keep it in the entry block.
3449-
if (LocalEscapeCall)
3450-
LocalEscapeCall->moveBefore(InsBefore);
3451+
if (LocalEscapeCall) LocalEscapeCall->moveBefore(InsBefore);
34513452

34523453
SmallVector<ASanStackVariableDescription, 16> SVD;
34533454
SVD.reserve(AllocaVec.size());

0 commit comments

Comments
 (0)