llvm.org GIT mirror llvm / 0213fce
[SSP] In opt remarks, stream Function directly With this, it shows up as an attribute in YAML and non-printable characters are properly removed by GlobalValue::getRealLinkageName. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297362 91177308-0d34-0410-b5e6-96231b3b80d8 Adam Nemet 2 years ago
2 changed file(s) with 26 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
233233 // using the analysis pass to avoid building DominatorTree and LoopInfo which
234234 // are not available this late in the IR pipeline.
235235 OptimizationRemarkEmitter ORE(F);
236 auto ReasonStub =
237 Twine("Stack protection applied to function " + F->getName() + " due to ")
238 .str();
239236
240237 if (F->hasFnAttribute(Attribute::StackProtectReq)) {
241238 ORE.emit(OptimizationRemark(DEBUG_TYPE, "StackProtectorRequested", F)
242 << ReasonStub << "a function attribute or command-line switch");
239 << "Stack protection applied to function "
240 << ore::NV("Function", F)
241 << " due to a function attribute or command-line switch");
243242 NeedsProtector = true;
244243 Strong = true; // Use the same heuristic as strong to determine SSPLayout
245244 } else if (F->hasFnAttribute(Attribute::StackProtectStrong))
255254 if (AI->isArrayAllocation()) {
256255 OptimizationRemark Remark(DEBUG_TYPE, "StackProtectorAllocaOrArray",
257256 &I);
258 Remark << ReasonStub
259 << "a call to alloca or use of a variable length array";
257 Remark
258 << "Stack protection applied to function "
259 << ore::NV("Function", F)
260 << " due to a call to alloca or use of a variable length array";
260261 if (const auto *CI = dyn_cast(AI->getArraySize())) {
261262 if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) {
262263 // A call to alloca with size >= SSPBufferSize requires
284285 Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
285286 : SSPLK_SmallArray));
286287 ORE.emit(OptimizationRemark(DEBUG_TYPE, "StackProtectorBuffer", &I)
287 << ReasonStub
288 << "a stack allocated buffer or struct containing a buffer");
288 << "Stack protection applied to function "
289 << ore::NV("Function", F)
290 << " due to a stack allocated buffer or struct containing a "
291 "buffer");
289292 NeedsProtector = true;
290293 continue;
291294 }
295298 Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
296299 ORE.emit(
297300 OptimizationRemark(DEBUG_TYPE, "StackProtectorAddressTaken", &I)
298 << ReasonStub << "the address of a local variable being taken");
301 << "Stack protection applied to function "
302 << ore::NV("Function", F)
303 << " due to the address of a local variable being taken");
299304 NeedsProtector = true;
300305 }
301306 }
2828 ; Check that no remark is emitted when the switch is not specified.
2929 ; RUN: llc %s -mtriple=x86_64-unknown-unknown -o /dev/null 2>&1 | FileCheck %s -check-prefix=NOREMARK -allow-empty
3030 ; NOREMARK-NOT: ssp
31
32 ; RUN: llc %s -mtriple=x86_64-unknown-unknown -o /dev/null -pass-remarks-output=%t.yaml
33 ; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML
34 ; YAML: --- !Passed
35 ; YAML-NEXT: Pass: stack-protector
36 ; YAML-NEXT: Name: StackProtectorRequested
37 ; YAML-NEXT: Function: attribute_ssp
38 ; YAML-NEXT: Args:
39 ; YAML-NEXT: - String: 'Stack protection applied to function '
40 ; YAML-NEXT: - Function: attribute_ssp
41 ; YAML-NEXT: - String: ' due to a function attribute or command-line switch'
42 ; YAML-NEXT: ...
3143
3244 define void @nossp() ssp {
3345 ret void