Skip to content

Commit 4b5224a

Browse files
Disable PGO instrumentation on naked function (#75224)
We only allow for assembly code in naked function, and PGO instrumentation (esp. temporal instrumentation that introduces a function call) can wreak havoc in this. Fix #74573
1 parent 3bedc93 commit 4b5224a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,8 @@ static bool skipPGOUse(const Function &F) {
17831783
static bool skipPGOGen(const Function &F) {
17841784
if (skipPGOUse(F))
17851785
return true;
1786+
if (F.hasFnAttribute(llvm::Attribute::Naked))
1787+
return true;
17861788
if (F.hasFnAttribute(llvm::Attribute::NoProfile))
17871789
return true;
17881790
if (F.hasFnAttribute(llvm::Attribute::SkipProfile))

llvm/test/Transforms/PGOProfile/timestamp.ll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@
33
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
44
target triple = "x86_64-unknown-linux-gnu"
55

6+
; CHECK-LABEL: define void @foo(
67
define void @foo() {
78
entry:
89
; CHECK: call void @llvm.instrprof.timestamp({{.*}})
910
ret void
1011
}
1112

12-
; CHECK: declare void @llvm.instrprof.timestamp(
13+
; CHECK-LABEL: define void @bar(
14+
define void @bar() #0 {
15+
entry:
16+
; CHECK-NOT: call void @llvm.instrprof.timestamp({{.*}})
17+
call void asm sideeffect "retq;", "~{dirflag},~{fpsr},~{flags}"()
18+
unreachable
19+
}
20+
21+
; CHECK-LABEL: declare void @llvm.instrprof.timestamp(
22+
23+
attributes #0 = { naked }

0 commit comments

Comments
 (0)