Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions clang/include/clang/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention ABI_EXTENSION here?

//===----------------------------------------------------------------------===//

#if !defined(FEATURE) && !defined(EXTENSION)
# error Define either the FEATURE or EXTENSION macro to handle features
#if !defined(FEATURE) && !defined(EXTENSION) && !defined(ABI_EXTENSION)
# error Define either the FEATURE, EXTENSION, or ABI_EXTENSION macro to handle features
#endif

#ifndef FEATURE
Expand All @@ -36,6 +36,10 @@
#define EXTENSION(Name, Predicate)
#endif

#ifndef ABI_EXTENSION
#define ABI_EXTENSION(Name, Predicate)
#endif

FEATURE(speculative_load_hardening, LangOpts.SpeculativeLoadHardening)
FEATURE(address_sanitizer,
LangOpts.Sanitize.hasOneOf(SanitizerKind::Address |
Expand Down Expand Up @@ -148,7 +152,7 @@ FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
FEATURE(ptrauth_intrinsics, LangOpts.PointerAuthIntrinsics)
EXTENSION(ptrauth_qualifier, LangOpts.PointerAuthIntrinsics)
ABI_EXTENSION(ptrauth_qualifier, LangOpts.PointerAuthIntrinsics)
FEATURE(ptrauth_calls, LangOpts.PointerAuthCalls)
FEATURE(ptrauth_returns, LangOpts.PointerAuthReturns)
FEATURE(ptrauth_vtable_pointer_address_discrimination, LangOpts.PointerAuthVTPtrAddressDiscrimination)
Expand Down Expand Up @@ -385,3 +389,4 @@ EXTENSION(cxx_type_aware_allocators, true)

#undef EXTENSION
#undef FEATURE
#undef ABI_EXTENSION
6 changes: 5 additions & 1 deletion clang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,11 +1183,15 @@ void DumpCompilerOptionsAction::ExecuteAction() {
OS << "\n\"extensions\" : [\n";
{
llvm::SmallString<128> Str;
#define EXTENSION(Name, Predicate) \
#define EXTENSION_OPTION(Name, Predicate) \
("\t{\"" #Name "\" : " + llvm::Twine(Predicate ? "true" : "false") + "},\n") \
.toVector(Str);
#define EXTENSION(Name, Predicate) EXTENSION_OPTION(Name, Predicate)
#define ABI_EXTENSION(Name, Predicate) EXTENSION_OPTION(Name, Predicate)
#include "clang/Basic/Features.def"
#undef EXTENSION
#undef ABI_EXTENSION
#undef EXTENSION_OPTION
// Remove the newline and comma from the last entry to ensure this remains
// valid JSON.
OS << Str.substr(0, Str.size() - 2);
Expand Down
21 changes: 14 additions & 7 deletions clang/lib/Lex/PPMacroExpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,19 +1109,26 @@ static bool HasExtension(const Preprocessor &PP, StringRef Extension) {
if (HasFeature(PP, Extension))
return true;

// Normalize the extension name, __foo__ becomes foo.
if (Extension.starts_with("__") && Extension.ends_with("__") &&
Extension.size() >= 4)
Extension = Extension.substr(2, Extension.size() - 4);

const LangOptions &LangOpts = PP.getLangOpts();
#define ABI_EXTENSION(Name, Predicate) .Case(#Name, Predicate)
bool IsABIExtension = llvm::StringSwitch<bool>(Extension)
#include "clang/Basic/Features.def"
.Default(false);
#undef ABI_EXTENSION
if (IsABIExtension)
return true;

// If the use of an extension results in an error diagnostic, extensions are
// effectively unavailable, so just return false here.
if (PP.getDiagnostics().getExtensionHandlingBehavior() >=
diag::Severity::Error)
return false;

const LangOptions &LangOpts = PP.getLangOpts();

// Normalize the extension name, __foo__ becomes foo.
if (Extension.starts_with("__") && Extension.ends_with("__") &&
Extension.size() >= 4)
Extension = Extension.substr(2, Extension.size() - 4);

// Because we inherit the feature list from HasFeature, this string switch
// must be less restrictive than HasFeature's.
#define EXTENSION(Name, Predicate) .Case(#Name, Predicate)
Expand Down
1 change: 1 addition & 0 deletions clang/test/Sema/ptrauth-qualifier.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -triple arm64-apple-ios -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s
// RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c23 -fsyntax-only -verify -fptrauth-intrinsics %s
// RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c23 -fsyntax-only -verify -fptrauth-intrinsics -pedantic-errors -Wno-c2y-extensions %s

#if !__has_extension(ptrauth_qualifier)
// This error means that the __ptrauth qualifier availability test says that it
Expand Down