Skip to content

Commit 55c9356

Browse files
committed
Also allow nocf_check only with -fsanitize=kcfi
1 parent b4a52f4 commit 55c9356

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,8 @@ static void handleStandardNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &A) {
20282028
}
20292029

20302030
static void handleNoCfCheckAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) {
2031-
if (!S.getLangOpts().CFProtectionBranch)
2031+
if (!S.getLangOpts().CFProtectionBranch &&
2032+
!S.getLangOpts().Sanitize.has(SanitizerKind::KCFI))
20322033
S.Diag(Attrs.getLoc(), diag::warn_nocf_check_attribute_ignored);
20332034
else
20342035
handleSimpleAttribute<AnyX86NoCfCheckAttr>(S, D, Attrs);

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7936,7 +7936,8 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
79367936
}
79377937

79387938
if (attr.getKind() == ParsedAttr::AT_AnyX86NoCfCheck) {
7939-
if (!S.getLangOpts().CFProtectionBranch) {
7939+
if (!S.getLangOpts().CFProtectionBranch &&
7940+
!S.getLangOpts().Sanitize.has(SanitizerKind::KCFI)) {
79407941
S.Diag(attr.getLoc(), diag::warn_nocf_check_attribute_ignored);
79417942
attr.setInvalid();
79427943
return true;

clang/test/Sema/attr-nocf_check.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fcf-protection=branch -fsyntax-only %s
2+
// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fsanitize=kcfi -fsyntax-only %s
23

34
// Function pointer definition.
45
typedef void (*FuncPointerWithNoCfCheck)(void) __attribute__((nocf_check)); // no-warning

0 commit comments

Comments
 (0)