-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Add __builtin_common_reference #121199
Draft
philnik777
wants to merge
1
commit into
llvm:main
Choose a base branch
from
philnik777:builtin_common_reference
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+738
−117
Conversation
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
You can test this locally with the following command:git-clang-format --diff f334db92be168876b618db72dc93078ce23ffa89 e0db7316b2705398a2ac7e69cd1e3e83ece52613 --extensions h,cpp -- clang/test/SemaCXX/type-trait-common-reference.cpp clang/include/clang/AST/ASTContext.h clang/include/clang/AST/ASTNodeTraverser.h clang/include/clang/AST/DeclID.h clang/include/clang/AST/DeclTemplate.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/Basic/Builtins.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ASTImporter.cpp clang/lib/AST/DeclBase.cpp clang/lib/AST/DeclTemplate.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/Lex/PPMacroExpansion.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Sema/SemaType.cpp clang/lib/Serialization/ASTCommon.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/tools/libclang/CIndex.cpp libcxx/include/__type_traits/common_reference.h View the diff from clang-format here.diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index b765e0d17c..e94dcdb612 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -1807,9 +1807,7 @@ public:
return new (C, DC) CVRefQualifyingTemplateDecl(C, DC, Ref);
}
- SourceRange getSourceRange() const override LLVM_READONLY {
- return {};
- }
+ SourceRange getSourceRange() const override LLVM_READONLY { return {}; }
CVRefQuals getQuals() { return Quals; }
};
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 635e2eb348..c43ebb2086 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -1697,11 +1697,9 @@ static TemplateParameterList *createBuiltinCommonTypeList(const ASTContext &C,
nullptr);
}
-static TemplateTypeParmDecl *BICreateTemplateParm(const ASTContext &C,
- DeclContext *DC,
- unsigned Depth,
- unsigned Position,
- bool ParameterPack = false) {
+static TemplateTypeParmDecl *
+BICreateTemplateParm(const ASTContext &C, DeclContext *DC, unsigned Depth,
+ unsigned Position, bool ParameterPack = false) {
return TemplateTypeParmDecl::Create(
C, DC, SourceLocation(), SourceLocation(), Depth, Position,
/*Id=*/nullptr, /*Typename=*/false, ParameterPack);
@@ -1733,8 +1731,8 @@ createBuiltinCommonReferenceBasicCommonReferenceT(const ASTContext &C,
/*Position=*/0);
}
-static TemplateParameterList *createBuiltinCommonReferenceList(const ASTContext &C,
- DeclContext *DC) {
+static TemplateParameterList *
+createBuiltinCommonReferenceList(const ASTContext &C, DeclContext *DC) {
// template <class, class, template <class> class, template <class> class>
// class
auto *BasicCommonReference =
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 4706013ff7..6672fdedd0 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3232,26 +3232,24 @@ static QualType CondRes(Sema &S, QualType X, QualType Y, SourceLocation Loc) {
Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl());
// false
- OpaqueValueExpr CondExpr(SourceLocation(), S.Context.BoolTy,
- VK_PRValue);
+ OpaqueValueExpr CondExpr(SourceLocation(), S.Context.BoolTy, VK_PRValue);
ExprResult Cond = &CondExpr;
// declval<X(&)()>()()
OpaqueValueExpr LHSExpr(Loc, X.getNonLValueExprType(S.Context),
- Expr::getValueKindForType(X));
+ Expr::getValueKindForType(X));
ExprResult LHS = &LHSExpr;
// declval<Y(&)()>()()
OpaqueValueExpr RHSExpr(Loc, Y.getNonLValueExprType(S.Context),
- Expr::getValueKindForType(Y));
+ Expr::getValueKindForType(Y));
ExprResult RHS = &RHSExpr;
ExprValueKind VK = VK_PRValue;
ExprObjectKind OK = OK_Ordinary;
// decltype(false ? declval<X(&)()>()() : declval<Y(&)()>()())
- QualType Result =
- S.CheckConditionalOperands(Cond, LHS, RHS, VK, OK, Loc);
+ QualType Result = S.CheckConditionalOperands(Cond, LHS, RHS, VK, OK, Loc);
if (SFINAE.hasErrorOccurred())
return QualType();
@@ -3260,8 +3258,7 @@ static QualType CondRes(Sema &S, QualType X, QualType Y, SourceLocation Loc) {
return Result;
}
-static QualType CommonRef(Sema &S, QualType A, QualType B,
- SourceLocation Loc) {
+static QualType CommonRef(Sema &S, QualType A, QualType B, SourceLocation Loc) {
// Given types A and B, let X be remove_reference_t<A>, let Y be
// remove_reference_t<B>, and let COMMON-REF(A, B) be:
assert(A->isReferenceType() && B->isReferenceType() &&
@@ -3394,13 +3391,15 @@ static QualType builtinCommonReferenceImpl(Sema &S,
auto T1 = Ts[0];
auto T2 = Ts[1];
auto Rest = Ts.drop_front(2);
- auto C = builtinCommonReferenceImpl(S, CommonReference, CommonType, TemplateLoc, {T1, T2});
+ auto C = builtinCommonReferenceImpl(S, CommonReference, CommonType,
+ TemplateLoc, {T1, T2});
if (C.isNull())
return QualType();
llvm::SmallVector<TemplateArgument, 4> Args;
Args.emplace_back(C);
Args.append(Rest.begin(), Rest.end());
- return builtinCommonReferenceImpl(S, CommonReference, CommonType, TemplateLoc, Args);
+ return builtinCommonReferenceImpl(S, CommonReference, CommonType,
+ TemplateLoc, Args);
}
}
}
diff --git a/libcxx/include/__type_traits/common_reference.h b/libcxx/include/__type_traits/common_reference.h
index a41143670b..31889b2c61 100644
--- a/libcxx/include/__type_traits/common_reference.h
+++ b/libcxx/include/__type_traits/common_reference.h
@@ -38,15 +38,16 @@ using common_reference_t = typename common_reference<_Types...>::type;
template <class, class, template <class> class, template <class> class>
struct basic_common_reference {};
-#if __has_builtin(__builtin_common_reference)
+# if __has_builtin(__builtin_common_reference)
template <class _Tp, class _Up, template <class> class _Tx, template <class> class _Ux>
using __basic_common_reference_t = basic_common_reference<_Tp, _Up, _Tx, _Ux>::type;
template <class... _Args>
-struct common_reference : __builtin_common_reference<__basic_common_reference_t, common_type_t, type_identity, __empty, _Args...> {};
+struct common_reference
+ : __builtin_common_reference<__basic_common_reference_t, common_type_t, type_identity, __empty, _Args...> {};
-#else
+# else
// Let COND_RES(X, Y) be:
template <class _Xp, class _Yp>
@@ -198,7 +199,7 @@ struct common_reference<_Tp, _Up, _Vp, _Rest...> : common_reference<common_refer
template <class...>
struct common_reference {};
-#endif // __has_builtin(__builtin_common_reference)
+# endif // __has_builtin(__builtin_common_reference)
_LIBCPP_END_NAMESPACE_STD
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.