Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][slh] add Clang attr no_speculative_load_hardening
Summary: This attribute will allow users to opt specific functions out of speculative load hardening. This compliments the Clang attribute named speculative_load_hardening. When this attribute or the attribute speculative_load_hardening is used in combination with the flags -mno-speculative-load-hardening or -mspeculative-load-hardening, the function level attribute will override the default during LLVM IR generation. For example, in the case, where the flag opposes the function attribute, the function attribute will take precendence. The sticky inlining behavior of the speculative_load_hardening attribute may cause a function with the no_speculative_load_hardening attribute to be tagged with the speculative_load_hardening tag in subsequent compiler phases which is desired behavior since the speculative_load_hardening LLVM attribute is designed to be maximally conservative. If both attributes are specified for a function, then an error will be thrown. Reviewers: chandlerc, echristo, kristof.beyls, aaron.ballman Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D54909 llvm-svn: 351565
- Loading branch information
Showing
12 changed files
with
216 additions
and
25 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
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 was deleted.
Oops, something went wrong.
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,62 @@ | ||
// Check that we correctly set or did not set the attribute for each function. | ||
// RUN: %clang_cc1 -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK1 | ||
// RUN: %clang_cc1 -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK2 | ||
|
||
// Check that we correctly set or did not set the attribute on each function despite the | ||
// -mspeculative-load-hardening flag. | ||
// RUN: %clang_cc1 -mspeculative-load-hardening -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK3 | ||
// RUN: %clang_cc1 -mspeculative-load-hardening -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK4 | ||
|
||
|
||
// Check that we correctly set or did not set the attribute on each function despite the | ||
// -mno-speculative-load-hardening flag. | ||
// RUN: %clang -mno-speculative-load-hardening -S -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK5 | ||
// RUN: %clang -mno-speculative-load-hardening -S -std=c++11 -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK6 | ||
|
||
|
||
[[clang::speculative_load_hardening]] | ||
int test1() { | ||
return 42; | ||
} | ||
|
||
int __attribute__((speculative_load_hardening)) test2() { | ||
return 42; | ||
} | ||
|
||
[[clang::no_speculative_load_hardening]] | ||
int test3() { | ||
return 42; | ||
} | ||
|
||
int __attribute__((no_speculative_load_hardening)) test4() { | ||
return 42; | ||
} | ||
// CHECK1: @{{.*}}test1{{.*}}[[SLH:#[0-9]+]] | ||
// CHECK1: @{{.*}}test3{{.*}}[[NOSLH:#[0-9]+]] | ||
// CHECK1: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
// CHECK1-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
|
||
// CHECK2: @{{.*}}test2{{.*}}[[SLH:#[0-9]+]] | ||
// CHECK2: @{{.*}}test4{{.*}}[[NOSLH:#[0-9]+]] | ||
// CHECK2: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
// CHECK2-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
|
||
// CHECK3: @{{.*}}test1{{.*}}[[SLH:#[0-9]+]] | ||
// CHECK3: @{{.*}}test3{{.*}}[[NOSLH:#[0-9]+]] | ||
// CHECK3: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
// CHECK3-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
|
||
// CHECK4: @{{.*}}test2{{.*}}[[SLH:#[0-9]+]] | ||
// CHECK4: @{{.*}}test4{{.*}}[[NOSLH:#[0-9]+]] | ||
// CHECK4: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
// CHECK4-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
|
||
// CHECK5: @{{.*}}test1{{.*}}[[SLH:#[0-9]+]] | ||
// CHECK5: @{{.*}}test3{{.*}}[[NOSLH:#[0-9]+]] | ||
// CHECK5: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
// CHECK5-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
|
||
// CHECK6: @{{.*}}test2{{.*}}[[SLH:#[0-9]+]] | ||
// CHECK6: @{{.*}}test4{{.*}}[[NOSLH:#[0-9]+]] | ||
// CHECK6: attributes [[SLH]] = { {{.*}}speculative_load_hardening{{.*}} } | ||
// CHECK6-NOT: attributes [[NOSLH]] = { {{.*}}speculative_load_hardening{{.*}} } |
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: %clang_cc1 -std=c++11 -fsyntax-only -verify %s | ||
|
||
int i __attribute__((no_speculative_load_hardening)); // expected-error {{'no_speculative_load_hardening' attribute only applies to functions}} | ||
|
||
void f1() __attribute__((no_speculative_load_hardening)); | ||
void f2() __attribute__((no_speculative_load_hardening(1))); // expected-error {{'no_speculative_load_hardening' attribute takes no arguments}} | ||
|
||
template <typename T> | ||
void tf1() __attribute__((no_speculative_load_hardening)); | ||
|
||
int f3(int __attribute__((no_speculative_load_hardening)), int); // expected-error {{'no_speculative_load_hardening' attribute only applies to functions}} | ||
|
||
struct A { | ||
int f __attribute__((no_speculative_load_hardening)); // expected-error {{'no_speculative_load_hardening' attribute only applies to functions}} | ||
void mf1() __attribute__((no_speculative_load_hardening)); | ||
static void mf2() __attribute__((no_speculative_load_hardening)); | ||
}; | ||
|
||
int ci [[clang::no_speculative_load_hardening]]; // expected-error {{'no_speculative_load_hardening' attribute only applies to functions}} | ||
|
||
[[clang::no_speculative_load_hardening]] void cf1(); | ||
[[clang::no_speculative_load_hardening(1)]] void cf2(); // expected-error {{'no_speculative_load_hardening' attribute takes no arguments}} | ||
|
||
template <typename T> | ||
[[clang::no_speculative_load_hardening]] | ||
void ctf1(); | ||
|
||
int cf3(int c[[clang::no_speculative_load_hardening]], int); // expected-error {{'no_speculative_load_hardening' attribute only applies to functions}} | ||
|
||
struct CA { | ||
int f [[clang::no_speculative_load_hardening]]; // expected-error {{'no_speculative_load_hardening' attribute only applies to functions}} | ||
[[clang::no_speculative_load_hardening]] void mf1(); | ||
[[clang::no_speculative_load_hardening]] static void mf2(); | ||
}; |
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