Skip to content

Commit ffdf120

Browse files
author
git apple-llvm automerger
committed
Merge commit 'dedbdfb70daf' from llvm.org/release/19.x into stable/20240723
2 parents 92b7a8e + dedbdfb commit ffdf120

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

clang/include/clang/Basic/TokenKinds.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
#ifndef EXPRESSION_TRAIT
6565
#define EXPRESSION_TRAIT(I,E,K) KEYWORD(I,K)
6666
#endif
67+
#ifndef TRANSFORM_TYPE_TRAIT_DEF
68+
#define TRANSFORM_TYPE_TRAIT_DEF(K, Trait) KEYWORD(__##Trait, KEYCXX)
69+
#endif
70+
6771
#ifndef ALIAS
6872
#define ALIAS(X,Y,Z)
6973
#endif
@@ -535,7 +539,6 @@ TYPE_TRAIT_1(__has_unique_object_representations,
535539
TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible, KEYCXX)
536540
TYPE_TRAIT_2(__is_pointer_interconvertible_base_of, IsPointerInterconvertibleBaseOf, KEYCXX)
537541

538-
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) KEYWORD(__##Trait, KEYCXX)
539542
#include "clang/Basic/TransformTypeTraits.def"
540543

541544
// Clang-only C++ Type Traits

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,34 @@ static bool isTargetVariantEnvironment(const TargetInfo &TI,
16201620
return false;
16211621
}
16221622

1623+
static bool IsBuiltinTrait(Token &Tok) {
1624+
1625+
#define TYPE_TRAIT_1(Spelling, Name, Key) \
1626+
case tok::kw_##Spelling: \
1627+
return true;
1628+
#define TYPE_TRAIT_2(Spelling, Name, Key) \
1629+
case tok::kw_##Spelling: \
1630+
return true;
1631+
#define TYPE_TRAIT_N(Spelling, Name, Key) \
1632+
case tok::kw_##Spelling: \
1633+
return true;
1634+
#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
1635+
case tok::kw_##Spelling: \
1636+
return true;
1637+
#define EXPRESSION_TRAIT(Spelling, Name, Key) \
1638+
case tok::kw_##Spelling: \
1639+
return true;
1640+
#define TRANSFORM_TYPE_TRAIT_DEF(K, Spelling) \
1641+
case tok::kw___##Spelling: \
1642+
return true;
1643+
1644+
switch (Tok.getKind()) {
1645+
default:
1646+
return false;
1647+
#include "clang/Basic/TokenKinds.def"
1648+
}
1649+
}
1650+
16231651
/// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
16241652
/// as a builtin macro, handle it and return the next token as 'Tok'.
16251653
void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
@@ -1832,25 +1860,11 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
18321860
getTargetInfo().getTargetOpts().FeatureMap);
18331861
}
18341862
return true;
1835-
} else if (II->getTokenID() != tok::identifier ||
1836-
II->hasRevertedTokenIDToIdentifier()) {
1837-
// Treat all keywords that introduce a custom syntax of the form
1838-
//
1839-
// '__some_keyword' '(' [...] ')'
1840-
//
1841-
// as being "builtin functions", even if the syntax isn't a valid
1842-
// function call (for example, because the builtin takes a type
1843-
// argument).
1844-
if (II->getName().starts_with("__builtin_") ||
1845-
II->getName().starts_with("__is_") ||
1846-
II->getName().starts_with("__has_"))
1847-
return true;
1848-
return llvm::StringSwitch<bool>(II->getName())
1849-
.Case("__array_rank", true)
1850-
.Case("__array_extent", true)
1851-
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) .Case("__" #Trait, true)
1852-
#include "clang/Basic/TransformTypeTraits.def"
1853-
.Default(false);
1863+
} else if (IsBuiltinTrait(Tok)) {
1864+
return true;
1865+
} else if (II->getTokenID() != tok::identifier &&
1866+
II->getName().starts_with("__builtin_")) {
1867+
return true;
18541868
} else {
18551869
return llvm::StringSwitch<bool>(II->getName())
18561870
// Report builtin templates as being builtins.

clang/test/Preprocessor/feature_tests.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
!__has_builtin(__underlying_type) || \
3232
!__has_builtin(__is_trivial) || \
3333
!__has_builtin(__is_same_as) || \
34-
!__has_builtin(__has_unique_object_representations)
34+
!__has_builtin(__has_unique_object_representations) || \
35+
!__has_builtin(__is_trivially_equality_comparable) || \
36+
!__has_builtin(__reference_constructs_from_temporary) || \
37+
!__has_builtin(__reference_binds_to_temporary) || \
38+
!__has_builtin(__reference_converts_from_temporary)
3539
#error Clang should have these
3640
#endif
3741

0 commit comments

Comments
 (0)