Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[memtag] Plug in stack safety analysis.
Summary: Run StackSafetyAnalysis at the end of the IR pipeline and annotate proven safe allocas with !stack-safe metadata. Do not instrument such allocas in the AArch64StackTagging pass. Reviewers: pcc, vitalybuka, ostannard Reviewed By: vitalybuka Subscribers: merge_guards_bot, kristof.beyls, hiraditya, cfe-commits, gilang, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D73513
- Loading branch information
Showing
8 changed files
with
142 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// REQUIRES: aarch64-registered-target | ||
|
||
// Old pass manager. | ||
// RUN: %clang -fno-experimental-new-pass-manager -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-NO-SAFETY | ||
// RUN: %clang -O1 -fno-experimental-new-pass-manager -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-SAFETY | ||
// RUN: %clang -O2 -fno-experimental-new-pass-manager -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-SAFETY | ||
// RUN: %clang -O3 -fno-experimental-new-pass-manager -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-SAFETY | ||
|
||
// New pass manager. | ||
// RUN: %clang -fexperimental-new-pass-manager -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-NO-SAFETY | ||
// RUN: %clang -O1 -fexperimental-new-pass-manager -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-SAFETY | ||
// RUN: %clang -O2 -fexperimental-new-pass-manager -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-SAFETY | ||
// RUN: %clang -O3 -fexperimental-new-pass-manager -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag %s -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-SAFETY | ||
|
||
int z; | ||
__attribute__((noinline)) void use(int *p) { *p = z; } | ||
int foo() { int x; use(&x); return x; } | ||
|
||
// CHECK-NO-SAFETY: define dso_local i32 @foo() | ||
// CHECK-NO-SAFETY: %x = alloca i32, align 4{{$}} | ||
|
||
// CHECK-SAFETY: define dso_local i32 @foo() | ||
// CHECK-SAFETY: %x = alloca i32, align 4, !stack-safe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
; RUN: llvm-as %s -o %t0.bc | ||
; RUN: llvm-as %S/Inputs/ipa.ll -o %t1.bc | ||
; RUN: llvm-link -disable-lazy-loading %t0.bc %t1.bc -o %t.combined.bc | ||
; RUN: opt -S -passes="stack-safety-annotator" %t.combined.bc -o - 2>&1 | FileCheck %s | ||
|
||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
declare void @Write1(i8* %p) | ||
declare void @Write8(i8* %p) | ||
|
||
; Basic out-of-bounds. | ||
define void @f1() { | ||
; CHECK-LABEL: define void @f1() { | ||
; CHECK: alloca i32, align 4{{$}} | ||
entry: | ||
%x = alloca i32, align 4 | ||
%x1 = bitcast i32* %x to i8* | ||
call void @Write8(i8* %x1) | ||
ret void | ||
} | ||
|
||
; Basic in-bounds. | ||
define void @f2() { | ||
; CHECK-LABEL: define void @f2() { | ||
; CHECK: alloca i32, align 4, !stack-safe ![[A:[0-9]+]]{{$}} | ||
entry: | ||
%x = alloca i32, align 4 | ||
%x1 = bitcast i32* %x to i8* | ||
call void @Write1(i8* %x1) | ||
ret void | ||
} | ||
|
||
; CHECK: ![[A]] = !{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters