[clang-tools-extra] reapply [clang-doc] Add --asset option to clang-doc (PR #96358)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/96358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc] [llvm] [libc] Implement (v|f)printf on the GPU (PR #96369)
@@ -1671,6 +1671,7 @@ int main(int Argc, char **Argv) { NewArgv.push_back(Arg->getValue()); for (const opt::Arg *Arg : Args.filtered(OPT_offload_opt_eq_minus)) NewArgv.push_back(Args.MakeArgString(StringRef("-") + Arg->getValue())); + llvm::errs() << "asdfasdf\n"; arsenm wrote: Leftover debug print https://github.com/llvm/llvm-project/pull/96369 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] fix access checking inside return-type-requirement of compound requirements (PR #95651)
https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/95651 >From 1c283900fc4bc984ebd917ead6ddd8c5d0364d80 Mon Sep 17 00:00:00 2001 From: Backl1ght Date: Sat, 15 Jun 2024 16:56:00 +0800 Subject: [PATCH] fix --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Sema/SemaTemplateInstantiate.cpp| 2 +- .../expr.prim.req/compound-requirement.cpp| 36 +++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7ac0fa0141b47..9c8f8c4a4fbaf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -914,6 +914,7 @@ Bug Fixes to C++ Support - Clang now diagnoses explicit specializations with storage class specifiers in all contexts. - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a forward-declared class. (#GH93512). +- Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788). Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 863cc53c55afa..1fe1fe9d4f833 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2735,7 +2735,7 @@ TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { if (TPLInst.isInvalid()) return nullptr; TemplateParameterList *TPL = TransformTemplateParameterList(OrigTPL); -if (!TPL) +if (!TPL || Trap.hasErrorOccurred()) TransRetReq.emplace(createSubstDiag(SemaRef, Info, [&] (llvm::raw_ostream& OS) { RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp index b7366207882f9..dc0e84280e056 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp @@ -189,3 +189,39 @@ namespace std_example { template struct C5_check {}; // expected-note{{because 'short' does not satisfy 'C5'}} using c5 = C5_check; // expected-error{{constraints not satisfied for class template 'C5_check' [with T = short]}} } + +namespace access_checks { +namespace in_return_type_requirement { + +// https://github.com/llvm/llvm-project/issues/93788 +template +concept is_assignable = requires(From from, To to) { + from = to; +}; + +template +class trait { + public: + using public_type = int; + private: + using private_type = int; +}; + +template +concept has_field = requires(T t) { + { t.field } -> is_assignable::private_type>; // expected-note {{'private_type' is a private member}} +}; +template +concept has_field2 = requires(T t) { + { t.field } -> is_assignable::public_type>; +}; + +struct A { + int field; +}; +static_assert(has_field); // expected-error {{static assertion failed}} \ + // expected-note {{because 'A' does not satisfy 'has_field'}} +static_assert(has_field2); + +} // namespace access_checks +} // namespace in_return_type_requirement ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Adjust MSVC version range for ARM64 build performance regression (PR #90731)
https://github.com/MaxEW707 approved this pull request. LGTM! Looks CI failed due to MSVC "fatal error C1060: compiler is out of heap space" inside a flang source file. I would try syncing upto main since I know flang has had quite of changes that overall reduce MSVC's memory usage at least anecdotally from my personal PRs that failed in similar files around the time this PR was made. https://github.com/llvm/llvm-project/pull/90731 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)
https://github.com/trcrsired updated https://github.com/llvm/llvm-project/pull/79667 >From d105b0c1435cb5a8cc31eadd8a92f774b440f507 Mon Sep 17 00:00:00 2001 From: cqwrteur <100043421+trcrsi...@users.noreply.github.com> Date: Sat, 1 Jun 2024 02:55:50 -0400 Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm The wasm unwind build appears to be dysfunctional, likely because the author has only supplied a customized LLVM build on request, rather than a fully functional patch. This patch fixes the build Apply formatting patch proposed by github bot use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined [libunwind] logAPI functions should also be built [libcxxabi] Fix function signatures for wasm wasm does not define the function signatures correctly for cxxabi Fix them Fix formatting issues for libcxxabi's wasm eh change Merge remote-tracking branch 'parent/main' into wasmlibunwindfix remove unwanted changes in unwind-wasm.c Make Unwind-wasm.c compile correctly without workaround in CMakeLists.txt using __wasm__ macro to guard against all wasm eh build fix UnwindLevel.c's formatting issue ISO C requires a translation unit to contain at least one declaration [-Werror,-Wempty-translation-unit] compiler-rt does not define CMP_RESULT correct on wasm64 Fixed Merge code --- compiler-rt/lib/builtins/fp_compare_impl.inc | 2 +- libcxx/include/__exception/exception_ptr.h | 21 +- libcxxabi/include/cxxabi.h | 179 ++--- libcxxabi/src/cxa_exception.cpp | 712 --- libcxxabi/src/cxa_exception.h| 7 +- libunwind/include/libunwind.h| 2 + libunwind/src/Unwind-wasm.c | 13 +- libunwind/src/UnwindRegistersRestore.S | 3 +- libunwind/src/UnwindRegistersSave.S | 3 + libunwind/src/assembly.h | 2 + libunwind/src/cet_unwind.h | 3 + libunwind/src/config.h | 15 +- libunwind/src/libunwind.cpp | 2 + libunwind/src/libunwind_ext.h| 2 + 14 files changed, 423 insertions(+), 543 deletions(-) diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc b/compiler-rt/lib/builtins/fp_compare_impl.inc index a9a4f6fbf5dfe..83bdea46a45da 100644 --- a/compiler-rt/lib/builtins/fp_compare_impl.inc +++ b/compiler-rt/lib/builtins/fp_compare_impl.inc @@ -12,7 +12,7 @@ // functions. We need to ensure that the return value is sign-extended in the // same way as GCC expects (since otherwise GCC-generated __builtin_isinf // returns true for finite 128-bit floating-point numbers). -#ifdef __aarch64__ +#if defined(__aarch64__) || defined(__wasm__) // AArch64 GCC overrides libgcc_cmp_return to use int instead of long. typedef int CMP_RESULT; #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4 diff --git a/libcxx/include/__exception/exception_ptr.h b/libcxx/include/__exception/exception_ptr.h index 0a8337fa39de3..01f340a587ec3 100644 --- a/libcxx/include/__exception/exception_ptr.h +++ b/libcxx/include/__exception/exception_ptr.h @@ -29,22 +29,21 @@ namespace __cxxabiv1 { +#if defined(__wasm__) +typedef void* (*__libcpp_exception_destructor_func)(void*); +#elif defined(_WIN32) +typedef void(__thiscall* __libcpp_exception_destructor_func)(void*); +#else +typedef void (*__libcpp_exception_destructor_func)(void*); +#endif + extern "C" { _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw(); _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw(); struct __cxa_exception; -_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception( -void*, -std::type_info*, -#if defined(_WIN32) -void(__thiscall*)(void*)) throw(); -#elif defined(__wasm__) -// In Wasm, a destructor returns its argument -void* (*)(void*)) throw(); -#else -void (*)(void*)) throw(); -#endif +_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* +__cxa_init_primary_exception(void*, std::type_info*, __libcpp_exception_destructor_func) throw(); } } // namespace __cxxabiv1 diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h index 0e3969084e04f..4162fd7ec2ba7 100644 --- a/libcxxabi/include/cxxabi.h +++ b/libcxxabi/include/cxxabi.h @@ -20,62 +20,51 @@ #include <__cxxabi_config.h> #define _LIBCPPABI_VERSION 15000 -#define _LIBCXXABI_NORETURN __attribute__((noreturn)) +#define _LIBCXXABI_NORETURN __attribute__((noreturn)) #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold)) #ifdef __cplusplus namespace std { -#if defined(_WIN32) +# if defined(_WIN32) class _LIBCXXABI_TYPE_VIS type_info; // forward declaration -#else +# else class type_info; // forward declaration -#endif -} - +# endif +} // namespace std // runtime routines use C calling conventions, but are in __cxxabiv1 namespace namespace __cxxabiv1 { struct __cxa_exception; +# if defined(__wasm__) +typedef void*
[clang] [clang][Sema] Fix crash on atomic builtins with incomplete type args (PR #96374)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Takuya Shimizu (hazohelet) Changes This patch fixes the crash when pointers to incomplete type are passed to atomic builtins such as `__atomic_load`. `ASTContext::getTypeInfoInChars` assumes that the argument type is a complete type, so I added a check to eliminate cases where incomplete types gets passed to this function Relevant PR: https://github.com/llvm/llvm-project/pull/91057 Fixes https://github.com/llvm/llvm-project/issues/96289 --- Full diff: https://github.com/llvm/llvm-project/pull/96374.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaChecking.cpp (+2-1) - (modified) clang/test/Sema/atomic-ops.c (+30) ``diff diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 7a2076d139c69..1872bdb5767f0 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4570,7 +4570,8 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, } // Pointer to object of size zero is not allowed. - if (Context.getTypeInfoInChars(AtomTy).Width.isZero()) { + if (!AtomTy->isIncompleteType() && + Context.getTypeInfoInChars(AtomTy).Width.isZero()) { Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer) << Ptr->getType() << 1 << Ptr->getSourceRange(); return ExprError(); diff --git a/clang/test/Sema/atomic-ops.c b/clang/test/Sema/atomic-ops.c index 2024b81ce6aec..d957461b6cb75 100644 --- a/clang/test/Sema/atomic-ops.c +++ b/clang/test/Sema/atomic-ops.c @@ -671,6 +671,36 @@ void zeroSizeArgError(struct Z *a, struct Z *b, struct Z *c) { } +struct IncompleteTy IncA, IncB, IncC; // expected-error 3{{tentative definition has type 'struct IncompleteTy' that is never completed}} \ + // expected-note 3{{forward declaration of 'struct IncompleteTy'}} +void incompleteTypeArgError() { + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_acq_rel); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_acquire); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_consume); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_release); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_seq_cst); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_acq_rel); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_acquire); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_consume); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_release); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_seq_cst); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_acq_rel); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_acquire); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_consume); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_release); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_seq_cst); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_relaxed, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_acq_rel, memory_order_acq_rel); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_acquire, memory_order_acquire); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_consume, memory_order_consume); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_release,
[clang] [clang][Sema] Fix crash on atomic builtins with incomplete type args (PR #96374)
https://github.com/hazohelet created https://github.com/llvm/llvm-project/pull/96374 This patch fixes the crash when pointers to incomplete type are passed to atomic builtins such as `__atomic_load`. `ASTContext::getTypeInfoInChars` assumes that the argument type is a complete type, so I added a check to eliminate cases where incomplete types gets passed to this function Relevant PR: https://github.com/llvm/llvm-project/pull/91057 Fixes https://github.com/llvm/llvm-project/issues/96289 >From 7a76e4fe198eb2b9751ccd40f8e3850e7bae119c Mon Sep 17 00:00:00 2001 From: Takuya Shimizu Date: Sat, 22 Jun 2024 12:05:50 +0900 Subject: [PATCH] [clang][Sema] Fix crash on atomic with incomplete type args --- clang/lib/Sema/SemaChecking.cpp | 3 ++- clang/test/Sema/atomic-ops.c| 30 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 7a2076d139c69..1872bdb5767f0 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4570,7 +4570,8 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, } // Pointer to object of size zero is not allowed. - if (Context.getTypeInfoInChars(AtomTy).Width.isZero()) { + if (!AtomTy->isIncompleteType() && + Context.getTypeInfoInChars(AtomTy).Width.isZero()) { Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer) << Ptr->getType() << 1 << Ptr->getSourceRange(); return ExprError(); diff --git a/clang/test/Sema/atomic-ops.c b/clang/test/Sema/atomic-ops.c index 2024b81ce6aec..d957461b6cb75 100644 --- a/clang/test/Sema/atomic-ops.c +++ b/clang/test/Sema/atomic-ops.c @@ -671,6 +671,36 @@ void zeroSizeArgError(struct Z *a, struct Z *b, struct Z *c) { } +struct IncompleteTy IncA, IncB, IncC; // expected-error 3{{tentative definition has type 'struct IncompleteTy' that is never completed}} \ + // expected-note 3{{forward declaration of 'struct IncompleteTy'}} +void incompleteTypeArgError() { + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_acq_rel); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_acquire); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_consume); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_release); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_exchange(&IncB, &IncB, &IncC, memory_order_seq_cst); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_acq_rel); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_acquire); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_consume); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_release); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_load(&IncA, &IncB, memory_order_seq_cst); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_acq_rel); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_acquire); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_consume); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_release); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_store(&IncA, &IncB, memory_order_seq_cst); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_relaxed, memory_order_relaxed); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_acq_rel, memory_order_acq_rel); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_acquire, memory_order_acquire); // expected-error {{must be a pointer to a trivially-copyable type}} + __atomic_compare_exchange(&IncA, &IncB, &IncC, 0, memory_order_consume, memor
[clang] [clang-format] Annotate r_paren before braced list as TT_CastRParen (PR #96271)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/96271 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d69050d - [clang-format] Annotate r_paren before braced list as TT_CastRParen (#96271)
Author: Owen Pan Date: 2024-06-21T20:23:18-07:00 New Revision: d69050d614cc3348fb639f4a1862e8b9a9ad9885 URL: https://github.com/llvm/llvm-project/commit/d69050d614cc3348fb639f4a1862e8b9a9ad9885 DIFF: https://github.com/llvm/llvm-project/commit/d69050d614cc3348fb639f4a1862e8b9a9ad9885.diff LOG: [clang-format] Annotate r_paren before braced list as TT_CastRParen (#96271) Fixes #96096. Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 63a028a6f4779..55c5ecee45e0c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2837,6 +2837,11 @@ class AnnotatingParser { if (!AfterRParen->Next) return false; +if (AfterRParen->is(tok::l_brace) && +AfterRParen->getBlockKind() == BK_BracedInit) { + return true; +} + // If the next token after the parenthesis is a unary operator, assume // that this is cast, unless there are unexpected tokens inside the // parenthesis. diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 0dc506458f7c3..12c4b7fdd5ac2 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -662,6 +662,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) { EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown); EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator); + Tokens = annotate("return (struct foo){};"); + ASSERT_EQ(Tokens.size(), 9u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_CastRParen); + Tokens = annotate("#define FOO(bar) foo((uint64_t)&bar)"); ASSERT_EQ(Tokens.size(), 15u) << Tokens; EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_CastRParen); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][Driver] Add HIPAMD Driver support for AMDGCN flavoured SPIR-V (PR #95061)
https://github.com/AlexVlx edited https://github.com/llvm/llvm-project/pull/95061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][Driver] Add HIPAMD Driver support for AMDGCN flavoured SPIR-V (PR #95061)
https://github.com/jhuber6 approved this pull request. Out of curiosity, how badly does this fail when you use `--offload-new-driver` w/ HIP? I swear I'll get that passing the internal test suite eventually, there's a single case for emitting IR that comgr uses that I can't seem to fix. https://github.com/llvm/llvm-project/pull/95061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] add option to avoid "no checks enabled" error (PR #96122)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/96122 >From 41993ea6903668c41eef8a4477f5914c894f7109 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Wed, 19 Jun 2024 23:20:09 + Subject: [PATCH 1/5] [clang-tidy] add option to avoid "no checks enabled" error When clang-tidy get an empty checks, it will throw "no checks enabled" error and exit with non-zero return value. It make clang-tidy's wrapper program confused when in big project some files don't want to be checked and use `-checks=-*` to disable all checks. --- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp | 12 ++-- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index 7388f20ef288e..b579aff4394c9 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -325,6 +325,14 @@ option is recognized. )"), cl::init(false), cl::cat(ClangTidyCategory)); +static cl::opt AllowEmptyCheckList("allow-empty-checks", desc(R"( +Allow empty enabled checks. This suppresses +the "no checks enabled" error when disabling +all of the checks. +)"), + cl::init(false), + cl::cat(ClangTidyCategory)); + namespace clang::tidy { static void printStats(const ClangTidyStats &Stats) { @@ -598,7 +606,7 @@ int clangTidyMain(int argc, const char **argv) { } if (ListChecks) { -if (EnabledChecks.empty()) { +if (EnabledChecks.empty() && !AllowEmptyCheckList) { llvm::errs() << "No checks enabled.\n"; return 1; } @@ -651,7 +659,7 @@ int clangTidyMain(int argc, const char **argv) { return 0; } - if (EnabledChecks.empty()) { + if (EnabledChecks.empty() && !AllowEmptyCheckList) { llvm::errs() << "Error: no checks enabled.\n"; llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 3bdd735f7dcf7..54cfcafd121b6 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -125,6 +125,9 @@ Improvements to clang-tidy - Added argument `--exclude-header-filter` and config option `ExcludeHeaderFilterRegex` to exclude headers from analysis via a RegEx. +- Added argument `--allow-empty-checks` and config option `AllowEmptyCheckList` + to suppress "no checks enabled" error when disabling all of the checks. + New checks ^^ >From 9302feee8fa9d19711ad2126dddbd73c044502b0 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 20 Jun 2024 17:58:10 +0800 Subject: [PATCH 2/5] fix acc comment --- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp | 6 +++--- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++-- clang-tools-extra/docs/clang-tidy/index.rst | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index b579aff4394c9..1475816827ac4 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -325,7 +325,7 @@ option is recognized. )"), cl::init(false), cl::cat(ClangTidyCategory)); -static cl::opt AllowEmptyCheckList("allow-empty-checks", desc(R"( +static cl::opt AllowNoChecks("allow-no-checks", desc(R"( Allow empty enabled checks. This suppresses the "no checks enabled" error when disabling all of the checks. @@ -606,7 +606,7 @@ int clangTidyMain(int argc, const char **argv) { } if (ListChecks) { -if (EnabledChecks.empty() && !AllowEmptyCheckList) { +if (EnabledChecks.empty() && !AllowNoChecks) { llvm::errs() << "No checks enabled.\n"; return 1; } @@ -659,7 +659,7 @@ int clangTidyMain(int argc, const char **argv) { return 0; } - if (EnabledChecks.empty() && !AllowEmptyCheckList) { + if (EnabledChecks.empty() && !AllowNoChecks) { llvm::errs() << "Error: no checks enabled.\n"; llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 54cfcafd121b6..e9a9cd47e9215 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -125,8 +125,8 @@ Improvements to clang-tidy - Added argument `--exclude-header-filter` and config option `ExcludeHeaderFilterRegex` to exclude headers from analysis via a RegEx. -- Added argument `--allow-empty-checks` and config option `AllowEmptyCheckList` - to suppress "no checks enabled" error when disabling all of the checks. +- Added arg
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
h-vetinari wrote: Failing bootstrap build still has: ``` from packaging import version ModuleNotFoundError: No module named 'packaging' ``` which is clearly unrelated to this PR. https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM] Fix incorrect alignment on AMDGPU variadics (PR #96370)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Joseph Huber (jhuber6) Changes Summary: The variadics lowering for AMDGPU puts all the arguments into a void pointer struct. The current logic dictates that the minimum alignment is four regardless of what the underlying type is. This is incorrect in the following case. ```c void foo(int, ...); void bar() { int x; void *p; foo(0, x, p); } ``` Here, because the minimum alignment is 4, we will only increment the buffer by 4, resulting in an incorrect alignment when we then try to access the void pointer. We need to set a minimum of 4, but increase it to 8 in cases like this. --- Patch is 56.64 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96370.diff 4 Files Affected: - (modified) clang/lib/CodeGen/Targets/AMDGPU.cpp (+3-8) - (modified) clang/test/CodeGen/amdgpu-variadic-call.c (+12-20) - (modified) llvm/lib/Transforms/IPO/ExpandVariadics.cpp (+5-1) - (modified) llvm/test/CodeGen/AMDGPU/expand-variadic-call.ll (+296-278) ``diff diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp b/clang/lib/CodeGen/Targets/AMDGPU.cpp index 4d3275e17c386..a169a7d920456 100644 --- a/clang/lib/CodeGen/Targets/AMDGPU.cpp +++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp @@ -121,7 +121,7 @@ void AMDGPUABIInfo::computeInfo(CGFunctionInfo &FI) const { RValue AMDGPUABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const { const bool IsIndirect = false; - const bool AllowHigherAlign = false; + const bool AllowHigherAlign = true; return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, getContext().getTypeInfoInChars(Ty), CharUnits::fromQuantity(4), AllowHigherAlign, Slot); @@ -212,13 +212,8 @@ ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType Ty, bool Variadic, Ty = useFirstFieldIfTransparentUnion(Ty); - if (Variadic) { -return ABIArgInfo::getDirect(/*T=*/nullptr, - /*Offset=*/0, - /*Padding=*/nullptr, - /*CanBeFlattened=*/false, - /*Align=*/0); - } + if (Variadic) +return ABIArgInfo::getDirect(); if (isAggregateTypeForABI(Ty)) { // Records with non-trivial destructors/copy-constructors should not be diff --git a/clang/test/CodeGen/amdgpu-variadic-call.c b/clang/test/CodeGen/amdgpu-variadic-call.c index 17eda215211a2..0529d6b3171c8 100644 --- a/clang/test/CodeGen/amdgpu-variadic-call.c +++ b/clang/test/CodeGen/amdgpu-variadic-call.c @@ -1,4 +1,3 @@ -// REQUIRES: amdgpu-registered-target // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature // RUN: %clang_cc1 -cc1 -std=c23 -triple amdgcn-amd-amdhsa -emit-llvm -O1 %s -o - | FileCheck %s @@ -179,11 +178,9 @@ typedef struct // CHECK-LABEL: define {{[^@]+}}@one_pair_f64 // CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], double [[V0_COERCE0:%.*]], double [[V0_COERCE1:%.*]]) local_unnamed_addr #[[ATTR0]] { // CHECK-NEXT: entry: -// CHECK-NEXT:[[DOTFCA_0_INSERT:%.*]] = insertvalue [[STRUCT_PAIR_F64:%.*]] poison, double [[V0_COERCE0]], 0 -// CHECK-NEXT:[[DOTFCA_1_INSERT:%.*]] = insertvalue [[STRUCT_PAIR_F64]] [[DOTFCA_0_INSERT]], double [[V0_COERCE1]], 1 -// CHECK-NEXT:tail call void (...) @sink_0([[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] -// CHECK-NEXT:tail call void (i32, ...) @sink_1(i32 noundef [[F0]], [[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] -// CHECK-NEXT:tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], [[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] +// CHECK-NEXT:tail call void (...) @sink_0(double [[V0_COERCE0]], double [[V0_COERCE1]]) #[[ATTR2]] +// CHECK-NEXT:tail call void (i32, ...) @sink_1(i32 noundef [[F0]], double [[V0_COERCE0]], double [[V0_COERCE1]]) #[[ATTR2]] +// CHECK-NEXT:tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], double [[V0_COERCE0]], double [[V0_COERCE1]]) #[[ATTR2]] // CHECK-NEXT:ret void // void one_pair_f64(int f0, double f1, pair_f64 v0) @@ -220,10 +217,9 @@ typedef union // CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], i32 [[V0_COERCE:%.*]]) local_unnamed_addr #[[ATTR0]] { // CHECK-NEXT: entry: // CHECK-NEXT:[[TMP0:%.*]] = bitcast i32 [[V0_COERCE]] to float -// CHECK-NEXT:[[DOTFCA_0_INSERT:%.*]] = insertvalue [[UNION_UNION_F32_I32:%.*]] poison, float [[TMP0]], 0 -// CHECK-NEXT:tail call void (...) @sink_0([[UNION_UNION_F32_I32]] [[DOTFCA_0_INSERT]]) #[[ATTR2]] -// CHECK-NEXT:tail call void (i32, ...) @sink_1(i32 noundef [[F0]], [[UNION_UNION_F32_I32]] [[DOTFCA_0_INSERT]]) #[[ATTR2]] -// CHECK-NEXT:tail call void (double, i32, ...) @sink_2(double noundef [[F1]],
[clang] [llvm] [LLVM] Fix incorrect alignment on AMDGPU variadics (PR #96370)
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/96370 Summary: The variadics lowering for AMDGPU puts all the arguments into a void pointer struct. The current logic dictates that the minimum alignment is four regardless of what the underlying type is. This is incorrect in the following case. ```c void foo(int, ...); void bar() { int x; void *p; foo(0, x, p); } ``` Here, because the minimum alignment is 4, we will only increment the buffer by 4, resulting in an incorrect alignment when we then try to access the void pointer. We need to set a minimum of 4, but increase it to 8 in cases like this. >From 5ee5bccb5dd4bd1d78dc04ead3c334d88b86f4fd Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Fri, 21 Jun 2024 19:17:42 -0500 Subject: [PATCH] [LLVM] Fix incorrect alignment on AMDGPU variadics Summary: The variadics lowering for AMDGPU puts all the arguments into a void pointer struct. The current logic dictates that the minimum alignment is four regardless of what the underlying type is. This is incorrect in the following case. ```c void foo(int, ...); void bar() { int x; void *p; foo(0, x, p); } ``` Here, because the minimum alignment is 4, we will only increment the buffer by 4, resulting in an incorrect alignment when we then try to access the void pointer. We need to set a minimum of 4, but increase it to 8 in cases like this. --- clang/lib/CodeGen/Targets/AMDGPU.cpp | 11 +- clang/test/CodeGen/amdgpu-variadic-call.c | 32 +- llvm/lib/Transforms/IPO/ExpandVariadics.cpp | 6 +- .../CodeGen/AMDGPU/expand-variadic-call.ll| 574 +- 4 files changed, 316 insertions(+), 307 deletions(-) diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp b/clang/lib/CodeGen/Targets/AMDGPU.cpp index 4d3275e17c386..a169a7d920456 100644 --- a/clang/lib/CodeGen/Targets/AMDGPU.cpp +++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp @@ -121,7 +121,7 @@ void AMDGPUABIInfo::computeInfo(CGFunctionInfo &FI) const { RValue AMDGPUABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const { const bool IsIndirect = false; - const bool AllowHigherAlign = false; + const bool AllowHigherAlign = true; return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect, getContext().getTypeInfoInChars(Ty), CharUnits::fromQuantity(4), AllowHigherAlign, Slot); @@ -212,13 +212,8 @@ ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType Ty, bool Variadic, Ty = useFirstFieldIfTransparentUnion(Ty); - if (Variadic) { -return ABIArgInfo::getDirect(/*T=*/nullptr, - /*Offset=*/0, - /*Padding=*/nullptr, - /*CanBeFlattened=*/false, - /*Align=*/0); - } + if (Variadic) +return ABIArgInfo::getDirect(); if (isAggregateTypeForABI(Ty)) { // Records with non-trivial destructors/copy-constructors should not be diff --git a/clang/test/CodeGen/amdgpu-variadic-call.c b/clang/test/CodeGen/amdgpu-variadic-call.c index 17eda215211a2..0529d6b3171c8 100644 --- a/clang/test/CodeGen/amdgpu-variadic-call.c +++ b/clang/test/CodeGen/amdgpu-variadic-call.c @@ -1,4 +1,3 @@ -// REQUIRES: amdgpu-registered-target // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature // RUN: %clang_cc1 -cc1 -std=c23 -triple amdgcn-amd-amdhsa -emit-llvm -O1 %s -o - | FileCheck %s @@ -179,11 +178,9 @@ typedef struct // CHECK-LABEL: define {{[^@]+}}@one_pair_f64 // CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], double [[V0_COERCE0:%.*]], double [[V0_COERCE1:%.*]]) local_unnamed_addr #[[ATTR0]] { // CHECK-NEXT: entry: -// CHECK-NEXT:[[DOTFCA_0_INSERT:%.*]] = insertvalue [[STRUCT_PAIR_F64:%.*]] poison, double [[V0_COERCE0]], 0 -// CHECK-NEXT:[[DOTFCA_1_INSERT:%.*]] = insertvalue [[STRUCT_PAIR_F64]] [[DOTFCA_0_INSERT]], double [[V0_COERCE1]], 1 -// CHECK-NEXT:tail call void (...) @sink_0([[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] -// CHECK-NEXT:tail call void (i32, ...) @sink_1(i32 noundef [[F0]], [[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] -// CHECK-NEXT:tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], [[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] +// CHECK-NEXT:tail call void (...) @sink_0(double [[V0_COERCE0]], double [[V0_COERCE1]]) #[[ATTR2]] +// CHECK-NEXT:tail call void (i32, ...) @sink_1(i32 noundef [[F0]], double [[V0_COERCE0]], double [[V0_COERCE1]]) #[[ATTR2]] +// CHECK-NEXT:tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], double [[V0_COERCE0]], double [[V0_COERCE1]]) #[[ATTR2]] // CHECK-NEXT:ret void // void one_pair_f64(int f0, double f1, pair_f64 v0) @@ -220,10 +217,9 @@ typedef union // CHECK-SAME: (i32 nounde
[clang] [libc] [llvm] [libc] Implement (v|f)printf on the GPU (PR #96369)
llvmbot wrote: @llvm/pr-subscribers-libc @llvm/pr-subscribers-clang Author: Joseph Huber (jhuber6) Changes Summary: This patch implements the `printf` family of functions on the GPU using the new variadic support. This patch adapts the old handling in the `rpc_fprintf` placeholder, but adds an extra RPC call to get the size of the buffer to copy. This prevents the GPU from needing to parse the string. While it's theoretically possible for the pass to know the size of the struct, it's prohibitively difficult to do while maintaining ABI compatibility with NVIDIA's varargs. Depends on https://github.com/llvm/llvm-project/pull/96015. --- Patch is 20.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96369.diff 18 Files Affected: - (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+1) - (modified) libc/config/gpu/entrypoints.txt (+8-11) - (modified) libc/src/__support/arg_list.h (+2-1) - (modified) libc/src/gpu/rpc_fprintf.cpp (+4-1) - (modified) libc/src/stdio/CMakeLists.txt (+2-22) - (modified) libc/src/stdio/generic/CMakeLists.txt (+25) - (renamed) libc/src/stdio/generic/fprintf.cpp () - (renamed) libc/src/stdio/generic/vfprintf.cpp () - (modified) libc/src/stdio/gpu/CMakeLists.txt (+48) - (added) libc/src/stdio/gpu/fprintf.cpp (+32) - (added) libc/src/stdio/gpu/printf.cpp (+30) - (added) libc/src/stdio/gpu/vfprintf.cpp (+29) - (added) libc/src/stdio/gpu/vfprintf_utils.h (+73) - (added) libc/src/stdio/gpu/vprintf.cpp (+28) - (modified) libc/test/integration/src/stdio/gpu/CMakeLists.txt (+1-1) - (modified) libc/test/integration/src/stdio/gpu/printf.cpp (+13-30) - (modified) libc/utils/gpu/server/rpc_server.cpp (+23-1) - (modified) llvm/lib/Transforms/IPO/ExpandVariadics.cpp (+7-1) ``diff diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp index cdfe8cfbd9379..03fd23ae39c29 100644 --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp @@ -1671,6 +1671,7 @@ int main(int Argc, char **Argv) { NewArgv.push_back(Arg->getValue()); for (const opt::Arg *Arg : Args.filtered(OPT_offload_opt_eq_minus)) NewArgv.push_back(Args.MakeArgString(StringRef("-") + Arg->getValue())); + llvm::errs() << "asdfasdf\n"; cl::ParseCommandLineOptions(NewArgv.size(), &NewArgv[0]); Verbose = Args.hasArg(OPT_verbose); diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 2217a696fc5d1..de1ca6bfd151f 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -1,13 +1,3 @@ -if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU) - set(extra_entrypoints - # stdio.h entrypoints - libc.src.stdio.sprintf - libc.src.stdio.snprintf - libc.src.stdio.vsprintf - libc.src.stdio.vsnprintf - ) -endif() - set(TARGET_LIBC_ENTRYPOINTS # assert.h entrypoints libc.src.assert.__assert_fail @@ -185,7 +175,14 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.errno.errno # stdio.h entrypoints -${extra_entrypoints} +libc.src.stdio.printf +libc.src.stdio.vprintf +libc.src.stdio.fprintf +libc.src.stdio.vfprintf +libc.src.stdio.sprintf +libc.src.stdio.snprintf +libc.src.stdio.vsprintf +libc.src.stdio.vsnprintf libc.src.stdio.feof libc.src.stdio.ferror libc.src.stdio.fseek diff --git a/libc/src/__support/arg_list.h b/libc/src/__support/arg_list.h index 0965e12afd562..3a4e5ad0fab3c 100644 --- a/libc/src/__support/arg_list.h +++ b/libc/src/__support/arg_list.h @@ -54,7 +54,8 @@ class MockArgList { } template LIBC_INLINE T next_var() { -++arg_counter; +arg_counter = +((arg_counter + alignof(T) - 1) / alignof(T)) * alignof(T) + sizeof(T); return T(arg_counter); } diff --git a/libc/src/gpu/rpc_fprintf.cpp b/libc/src/gpu/rpc_fprintf.cpp index 7b0e60b59baf3..659144d133004 100644 --- a/libc/src/gpu/rpc_fprintf.cpp +++ b/libc/src/gpu/rpc_fprintf.cpp @@ -29,6 +29,9 @@ int fprintf_impl(::FILE *__restrict file, const char *__restrict format, } port.send_n(format, format_size); + port.recv([&](rpc::Buffer *buffer) { +args_size = static_cast(buffer->data[0]); + }); port.send_n(args, args_size); uint32_t ret = 0; @@ -50,7 +53,7 @@ int fprintf_impl(::FILE *__restrict file, const char *__restrict format, return ret; } -// TODO: This is a stand-in function that uses a struct pointer and size in +// TODO: Delete this and port OpenMP to use `printf`. // place of varargs. Once varargs support is added we will use that to // implement the real version. LLVM_LIBC_FUNCTION(int, rpc_fprintf, diff --git a/libc/src/stdio/CMakeLists.txt b/libc/src/stdio/CMakeLists.txt index a659d9e847a9e..3c536a287b2c4 100644 --- a/libc/src/stdio/CMakeLists.txt +++ b/libc/src/stdio/CMakeLists.txt @@ -159,17 +159,6 @@ add_entrypoint_object( libc
[clang] [libc] [llvm] [libc] Implement (v|f)printf on the GPU (PR #96369)
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/96369 Summary: This patch implements the `printf` family of functions on the GPU using the new variadic support. This patch adapts the old handling in the `rpc_fprintf` placeholder, but adds an extra RPC call to get the size of the buffer to copy. This prevents the GPU from needing to parse the string. While it's theoretically possible for the pass to know the size of the struct, it's prohibitively difficult to do while maintaining ABI compatibility with NVIDIA's varargs. Depends on https://github.com/llvm/llvm-project/pull/96015. >From 42a7a45c845de377b9b714af39a449fdc49eb768 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Fri, 21 Jun 2024 19:10:40 -0500 Subject: [PATCH] [libc] Implement (v|f)printf on the GPU Summary: This patch implements the `printf` family of functions on the GPU using the new variadic support. This patch adapts the old handling in the `rpc_fprintf` placeholder, but adds an extra RPC call to get the size of the buffer to copy. This prevents the GPU from needing to parse the string. While it's theoretically possible for the pass to know the size of the struct, it's prohibitively difficult to do while maintaining ABI compatibility with NVIDIA's varargs. Depends on https://github.com/llvm/llvm-project/pull/96015. --- .../ClangLinkerWrapper.cpp| 1 + libc/config/gpu/entrypoints.txt | 19 ++--- libc/src/__support/arg_list.h | 3 +- libc/src/gpu/rpc_fprintf.cpp | 5 +- libc/src/stdio/CMakeLists.txt | 24 +- libc/src/stdio/generic/CMakeLists.txt | 25 +++ libc/src/stdio/{ => generic}/fprintf.cpp | 0 libc/src/stdio/{ => generic}/vfprintf.cpp | 0 libc/src/stdio/gpu/CMakeLists.txt | 48 libc/src/stdio/gpu/fprintf.cpp| 32 libc/src/stdio/gpu/printf.cpp | 30 libc/src/stdio/gpu/vfprintf.cpp | 29 libc/src/stdio/gpu/vfprintf_utils.h | 73 +++ libc/src/stdio/gpu/vprintf.cpp| 28 +++ .../integration/src/stdio/gpu/CMakeLists.txt | 2 +- .../test/integration/src/stdio/gpu/printf.cpp | 43 --- libc/utils/gpu/server/rpc_server.cpp | 24 +- llvm/lib/Transforms/IPO/ExpandVariadics.cpp | 8 +- 18 files changed, 326 insertions(+), 68 deletions(-) rename libc/src/stdio/{ => generic}/fprintf.cpp (100%) rename libc/src/stdio/{ => generic}/vfprintf.cpp (100%) create mode 100644 libc/src/stdio/gpu/fprintf.cpp create mode 100644 libc/src/stdio/gpu/printf.cpp create mode 100644 libc/src/stdio/gpu/vfprintf.cpp create mode 100644 libc/src/stdio/gpu/vfprintf_utils.h create mode 100644 libc/src/stdio/gpu/vprintf.cpp diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp index cdfe8cfbd9379..03fd23ae39c29 100644 --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp @@ -1671,6 +1671,7 @@ int main(int Argc, char **Argv) { NewArgv.push_back(Arg->getValue()); for (const opt::Arg *Arg : Args.filtered(OPT_offload_opt_eq_minus)) NewArgv.push_back(Args.MakeArgString(StringRef("-") + Arg->getValue())); + llvm::errs() << "asdfasdf\n"; cl::ParseCommandLineOptions(NewArgv.size(), &NewArgv[0]); Verbose = Args.hasArg(OPT_verbose); diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 2217a696fc5d1..de1ca6bfd151f 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -1,13 +1,3 @@ -if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU) - set(extra_entrypoints - # stdio.h entrypoints - libc.src.stdio.sprintf - libc.src.stdio.snprintf - libc.src.stdio.vsprintf - libc.src.stdio.vsnprintf - ) -endif() - set(TARGET_LIBC_ENTRYPOINTS # assert.h entrypoints libc.src.assert.__assert_fail @@ -185,7 +175,14 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.errno.errno # stdio.h entrypoints -${extra_entrypoints} +libc.src.stdio.printf +libc.src.stdio.vprintf +libc.src.stdio.fprintf +libc.src.stdio.vfprintf +libc.src.stdio.sprintf +libc.src.stdio.snprintf +libc.src.stdio.vsprintf +libc.src.stdio.vsnprintf libc.src.stdio.feof libc.src.stdio.ferror libc.src.stdio.fseek diff --git a/libc/src/__support/arg_list.h b/libc/src/__support/arg_list.h index 0965e12afd562..3a4e5ad0fab3c 100644 --- a/libc/src/__support/arg_list.h +++ b/libc/src/__support/arg_list.h @@ -54,7 +54,8 @@ class MockArgList { } template LIBC_INLINE T next_var() { -++arg_counter; +arg_counter = +((arg_counter + alignof(T) - 1) / alignof(T)) * alignof(T) + sizeof(T); return T(arg_counter); } diff --git a/libc/src/gpu/rpc_fprintf.cpp b/libc/src/gpu/rpc_fprintf.cpp index 7b0e60b59b
[clang] [libcxx] [clang] Add builtin to clear padding bytes (prework for P0528R3) (PR #75371)
efriedma-quic wrote: If you want to modify part of a bitfield unit, you need to load/store the whole bitfield unit, as computed by the CGRecordLayout. This is true whether you're modifying an actual field, or padding adjacent to a field. Since any padding has to be adjacent to a bitfield, you can get the relevant information out of the CGBitFieldInfo for that bitfield. https://github.com/llvm/llvm-project/pull/75371 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)
efriedma-quic wrote: I'm not sure I understand the goal here. For return-address signing, each function can make its own choice about whether to sign; the function that's doing the signing is the same function that does the auth, so it doesn't directly impact any other function. For branch target enforcement, though, everything needs to agree that branch targets are supposed to be enforced, or else the process crashes. So there's no point to modifying whether it's enabled for a single function. https://github.com/llvm/llvm-project/pull/82819 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL][clang] Add elementwise builtins for trig intrinsics (PR #95999)
https://github.com/efriedma-quic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/95999 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add builtins for instrinsic `llvm.amdgcn.raw.ptr.buffer.store` (PR #94576)
https://github.com/shiltian edited https://github.com/llvm/llvm-project/pull/94576 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Fix argument passing in reserved registers for preserve_nonecc (PR #96259)
https://github.com/efriedma-quic approved this pull request. LGTM. Please don't forget about the varargs issue, though https://github.com/llvm/llvm-project/pull/96259 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang: Relax LangOpts checks when lexing quoted numbers during preprocessing (PR #95798)
@@ -2068,7 +2068,8 @@ bool Lexer::LexNumericConstant(Token &Result, const char *CurPtr) { } // If we have a digit separator, continue. - if (C == '\'' && (LangOpts.CPlusPlus14 || LangOpts.C23)) { + if (C == '\'' && + (LangOpts.CPlusPlus14 || LangOpts.C23 || ParsingPreprocessorDirective)) { jansvoboda11 wrote: Why is `ParsingPreprocessorDirective` used here? I think I would prefer introducing new `LangOptions::AllowLiteralDigitSeparator` member that would be set to true whenever `CPlusPlus14 || C23` evaluates to `true` and that could be set to `true` explicitly from the scanner. WDYT? https://github.com/llvm/llvm-project/pull/95798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)
jansvoboda11 wrote: I assume that @benlangmuir added the scanner unit-test to demonstrate the current behavior instead of trying to make sure it's preserved. I think making it so that the test passes (actually handles raw string literals) and updating the FIXME in `DependencyDirectivesScanner.cpp` should be fine. CC @Bigcheese https://github.com/llvm/llvm-project/pull/88265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] reapply [clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/96358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][Coroutines] Introducing the `[[clang::coro_inplace_task]]` attribute (PR #94693)
https://github.com/yuxuanchen1997 updated https://github.com/llvm/llvm-project/pull/94693 >From 065f965d6649a56a27c39321a553188b4230f5f6 Mon Sep 17 00:00:00 2001 From: Yuxuan Chen Date: Tue, 4 Jun 2024 23:22:00 -0700 Subject: [PATCH] [Clang] Introduce [[clang::coro_inplace_task]] --- clang/include/clang/AST/ExprCXX.h | 26 -- clang/include/clang/Basic/Attr.td | 8 ++ clang/include/clang/Basic/AttrDocs.td | 19 + clang/lib/CodeGen/CGBlocks.cpp| 5 +- clang/lib/CodeGen/CGCUDARuntime.cpp | 5 +- clang/lib/CodeGen/CGCUDARuntime.h | 8 +- clang/lib/CodeGen/CGCXXABI.h | 10 +-- clang/lib/CodeGen/CGClass.cpp | 16 ++-- clang/lib/CodeGen/CGCoroutine.cpp | 29 +-- clang/lib/CodeGen/CGExpr.cpp | 41 + clang/lib/CodeGen/CGExprCXX.cpp | 60 +++-- clang/lib/CodeGen/CodeGenFunction.h | 64 -- clang/lib/CodeGen/ItaniumCXXABI.cpp | 16 ++-- clang/lib/CodeGen/MicrosoftCXXABI.cpp | 18 ++-- clang/lib/Sema/SemaCoroutine.cpp | 54 +++- clang/lib/Serialization/ASTReaderStmt.cpp | 10 ++- clang/lib/Serialization/ASTWriterStmt.cpp | 3 +- clang/test/CodeGenCoroutines/Inputs/utility.h | 13 +++ .../coro-structured-concurrency.cpp | 84 +++ ...a-attribute-supported-attributes-list.test | 1 + llvm/include/llvm/IR/Intrinsics.td| 3 + .../lib/Transforms/Coroutines/CoroCleanup.cpp | 11 ++- llvm/lib/Transforms/Coroutines/CoroElide.cpp | 58 - llvm/lib/Transforms/Coroutines/Coroutines.cpp | 1 + .../coro-elide-structured-concurrency.ll | 64 ++ 25 files changed, 493 insertions(+), 134 deletions(-) create mode 100644 clang/test/CodeGenCoroutines/Inputs/utility.h create mode 100644 clang/test/CodeGenCoroutines/coro-structured-concurrency.cpp create mode 100644 llvm/test/Transforms/Coroutines/coro-elide-structured-concurrency.ll diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index c2feac525c1ea..0cf62aee41b66 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -5082,7 +5082,8 @@ class CoroutineSuspendExpr : public Expr { enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count }; Stmt *SubExprs[SubExpr::Count]; - OpaqueValueExpr *OpaqueValue = nullptr; + OpaqueValueExpr *CommonExprOpaqueValue = nullptr; + OpaqueValueExpr *InplaceCallOpaqueValue = nullptr; public: // These types correspond to the three C++ 'await_suspend' return variants @@ -5090,10 +5091,10 @@ class CoroutineSuspendExpr : public Expr { CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand, Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume, - OpaqueValueExpr *OpaqueValue) + OpaqueValueExpr *CommonExprOpaqueValue) : Expr(SC, Resume->getType(), Resume->getValueKind(), Resume->getObjectKind()), -KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) { +KeywordLoc(KeywordLoc), CommonExprOpaqueValue(CommonExprOpaqueValue) { SubExprs[SubExpr::Operand] = Operand; SubExprs[SubExpr::Common] = Common; SubExprs[SubExpr::Ready] = Ready; @@ -5128,7 +5129,16 @@ class CoroutineSuspendExpr : public Expr { } /// getOpaqueValue - Return the opaque value placeholder. - OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } + OpaqueValueExpr *getCommonExprOpaqueValue() const { +return CommonExprOpaqueValue; + } + + OpaqueValueExpr *getInplaceCallOpaqueValue() const { +return InplaceCallOpaqueValue; + } + void setInplaceCallOpaqueValue(OpaqueValueExpr *E) { +InplaceCallOpaqueValue = E; + } Expr *getReadyExpr() const { return static_cast(SubExprs[SubExpr::Ready]); @@ -5194,9 +5204,9 @@ class CoawaitExpr : public CoroutineSuspendExpr { public: CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume, - OpaqueValueExpr *OpaqueValue, bool IsImplicit = false) + OpaqueValueExpr *CommonExprOpaqueValue, bool IsImplicit = false) : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common, - Ready, Suspend, Resume, OpaqueValue) { + Ready, Suspend, Resume, CommonExprOpaqueValue) { CoawaitBits.IsImplicit = IsImplicit; } @@ -5275,9 +5285,9 @@ class CoyieldExpr : public CoroutineSuspendExpr { public: CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume, - OpaqueValueExpr *OpaqueValue) + OpaqueValueExpr *CommonExprOpaqueValue) : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common, -
[clang-tools-extra] reapply [clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
https://github.com/ilovepi commented: LGTM, but wait for Nico to chime in please. https://github.com/llvm/llvm-project/pull/96358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] reapply [clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/96358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -0,0 +1,101 @@ +REQUIRES: x86_64-linux + +This is a copy of memprof-basict.test with slight changes to check that we can still read v3 of memprofraw. + +To update the inputs used below run Inputs/update_memprof_inputs.sh /path/to/updated/clang teresajohnson wrote: I think this comment is wrong - we can't update the v3 version, is that correct? Nor would we want to. https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -38,4 +38,5 @@ MEMPROF_FLAG(bool, allocator_frees_and_returns_null_on_realloc_zero, true, MEMPROF_FLAG(bool, print_text, false, "If set, prints the heap profile in text format. Else use the raw binary serialization format.") MEMPROF_FLAG(bool, print_terse, false, - "If set, prints memory profile in a terse format. Only applicable if print_text = true.") + "If set, prints memory profile in a terse format. Only applicable " teresajohnson wrote: Formatting change only, remove from patch https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -205,8 +205,14 @@ class RawMemProfReader final : public MemProfReader { object::SectionedAddress getModuleOffset(uint64_t VirtualAddress); + llvm::SmallVector> + readMemInfoBlocks(const char *Ptr); + // The profiled binary. object::OwningBinary Binary; + // Version of raw memprof binary currently being read. Defaults to most update teresajohnson wrote: typo: s/update to date/up to date/ https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -610,13 +670,33 @@ RawMemProfReader::peekBuildIds(MemoryBuffer *DataBuffer) { return BuildIds.takeVector(); } +// FIXME: Add a schema for serializing similiar to IndexedMemprofReader. This +// will help being able to deserialize different versions raw memprof versions +// more easily. +llvm::SmallVector> +RawMemProfReader::readMemInfoBlocks(const char *Ptr) { + if (MemprofRawVersion == 3ULL) { +errs() << "Reading V3\n"; teresajohnson wrote: Once you do that, the braces can be removed from all of the if else conditions here which have single statement bodies https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -610,13 +670,33 @@ RawMemProfReader::peekBuildIds(MemoryBuffer *DataBuffer) { return BuildIds.takeVector(); } +// FIXME: Add a schema for serializing similiar to IndexedMemprofReader. This +// will help being able to deserialize different versions raw memprof versions +// more easily. +llvm::SmallVector> +RawMemProfReader::readMemInfoBlocks(const char *Ptr) { + if (MemprofRawVersion == 3ULL) { +errs() << "Reading V3\n"; teresajohnson wrote: Leftover debugging message that should be removed? https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -0,0 +1,101 @@ +REQUIRES: x86_64-linux + +This is a copy of memprof-basict.test with slight changes to check that we can still read v3 of memprofraw. teresajohnson wrote: typo: basict https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -216,6 +228,35 @@ u64 GetShadowCount(uptr p, u32 size) { return count; } +// Accumulates the access count from the shadow for the given pointer and size. +// See memprof_mapping.h for an overview on histogram counters. +u64 GetShadowCountHistogram(uptr p, u32 size) { + u8 *shadow = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p); + u8 *shadow_end = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p + size); + u64 count = 0; + for (; shadow <= shadow_end; shadow++) +count += *shadow; + return count; +} + +// If we use the normal approach from clearCountersWithoutHistogram, the +// histogram will clear too much data and may overwrite shadow counters that are +// in use. Likely because of rounding up the shadow_end pointer. +// See memprof_mapping.h for an overview on histogram counters. +void clearCountersHistogram(uptr addr, uptr size) { + u8 *shadow_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr); + u8 *shadow_end_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr + size); + for (; shadow_8 < shadow_end_8; shadow_8++) { +*shadow_8 = 0; + } +} + +void clearCountersWithoutHistogram(uptr addr, uptr size) { + uptr shadow_beg = MEM_TO_SHADOW(addr); + uptr shadow_end = MEM_TO_SHADOW(addr + size - SHADOW_GRANULARITY) + 1; + REAL(memset)((void *)shadow_beg, 0, shadow_end - shadow_beg); +} + // Clears the shadow counters (when memory is allocated). void ClearShadow(uptr addr, uptr size) { teresajohnson wrote: Looking at this function more, there are a lot of uses of the MEM_TO_SHADOW computed values, which is not the right mapping function to use with the smaller granularity of the histogram case. I think you probably need to version the calls to MEM_TO_SHADOW here, then all of the rest of the code can work as is? I.e. you wouldn't need the 2 versions of `clearCounters*` https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -124,6 +124,13 @@ struct PortableMemInfoBlock { OS << "" << #Name << ": " << Name << "\n"; #include "llvm/ProfileData/MIBEntryDef.inc" #undef MIBEntryDef +if (AccessHistogramSize > 0) { + OS << "" << "AccessHistogramValues" << ":"; + for (uint32_t I = 0; I < AccessHistogramSize; ++I) { +OS << " -" << ((uint64_t *)AccessHistogram)[I]; teresajohnson wrote: Why the " -" in the outputs? I noticed when looking at the text that they look like negative values as a result. Any reason not to just delimit with the space? https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -508,7 +519,26 @@ void createProfileFileNameVar(Module &M) { } } +// Set MemprofHistogramFlag as a Global veriable in IR. This makes it accessible +// to teresajohnson wrote: nit: fix line wrapping https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -96,19 +102,63 @@ llvm::SmallVector readSegmentEntries(const char *Ptr) { } llvm::SmallVector> -readMemInfoBlocks(const char *Ptr) { +readMemInfoBlocksV3(const char *Ptr) { using namespace support; const uint64_t NumItemsToRead = - endian::readNext(Ptr); + endian::readNext(Ptr); + llvm::SmallVector> Items; for (uint64_t I = 0; I < NumItemsToRead; I++) { const uint64_t Id = -endian::readNext(Ptr); -const MemInfoBlock MIB = *reinterpret_cast(Ptr); +endian::readNext(Ptr); + +// We cheat a bit here and remove the const from cast to set the +// Histogram Pointer to newly allocated buffer. We also cheat, since V3 and +// V4 do not have the same fields. V3 is missing AccessHistogramSize and +// AccessHistogram. This means we read "dirty" data in here, but it should +// not segfault, since there will be callstack data placed after this in the +// binary format. +MemInfoBlock MIB = *reinterpret_cast(Ptr); +// Overwrite dirty data. teresajohnson wrote: Isn't this going to overwrite some callstack data? https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -20,25 +20,25 @@ CHECK-NEXT: - CHECK: Records: CHECK-NEXT: - -CHECK-NEXT:FunctionGUID: 15505678318020221912 +CHECK-NEXT:FunctionGUID: 3873612792189045660 CHECK-NEXT:AllocSites: CHECK-NEXT:- CHECK-NEXT: Callstack: CHECK-NEXT: - -CHECK-NEXT:Function: 15505678318020221912 -CHECK-NEXT:SymbolName: qux +CHECK-NEXT:Function: 3873612792189045660 +CHECK-NEXT:SymbolName: _Z3quxi teresajohnson wrote: Why did the function symbol names change with your patch? https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -508,7 +519,26 @@ void createProfileFileNameVar(Module &M) { } } +// Set MemprofHistogramFlag as a Global veriable in IR. This makes it accessible +// to +// the runtime, changing shadow count behavior. +void createMemprofHistogramFlagVar(Module &M) { + const StringRef VarName(MemProfHistogramFlagVar); + Type *IntTy1 = Type::getInt1Ty(M.getContext()); + auto MemprofHistogramFlag = new GlobalVariable( + M, IntTy1, true, GlobalValue::WeakAnyLinkage, + Constant::getIntegerValue(IntTy1, APInt(1, ClHistogram)), VarName); + // MemprofHistogramFlag->setVisibility(GlobalValue::HiddenVisibility); teresajohnson wrote: remove? https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)
@@ -216,6 +228,35 @@ u64 GetShadowCount(uptr p, u32 size) { return count; } +// Accumulates the access count from the shadow for the given pointer and size. +// See memprof_mapping.h for an overview on histogram counters. +u64 GetShadowCountHistogram(uptr p, u32 size) { + u8 *shadow = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p); + u8 *shadow_end = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p + size); + u64 count = 0; + for (; shadow <= shadow_end; shadow++) +count += *shadow; + return count; +} + +// If we use the normal approach from clearCountersWithoutHistogram, the +// histogram will clear too much data and may overwrite shadow counters that are +// in use. Likely because of rounding up the shadow_end pointer. +// See memprof_mapping.h for an overview on histogram counters. +void clearCountersHistogram(uptr addr, uptr size) { + u8 *shadow_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr); + u8 *shadow_end_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr + size); + for (; shadow_8 < shadow_end_8; shadow_8++) { teresajohnson wrote: Why not use REAL(memset) like the non-histogram version below? https://github.com/llvm/llvm-project/pull/94264 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Parse] Fix ambiguity with nested-name-specifiers that may declarative (PR #96364)
https://github.com/sdkrystian edited https://github.com/llvm/llvm-project/pull/96364 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Parse] Fix ambiguity with nested-name-specifiers that may declarative (PR #96364)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Krystian Stasiowski (sdkrystian) Changes Consider the following: ```cpp templatestruct A { }; template int A ::B::* f(); // error: no member named 'B' in 'A ' ``` Although this is clearly valid, clang rejects it because the _nested-name-specifier_ `A ::` is parsed as-if it was declarative, meaning, we parse it as-if it was the _nested-name-specifier_ in a redeclaration/specialization. However, we don't (and can't) know whether the _nested-name-specifier_ is declarative until we see the '`*`' token, but at that point we have already complained that `A` has no member named `B`! This patch addresses this bug by adding support for _fully_ unannotated _and_ unbounded tentative parsing, which allows for us to parse past tokens without having to cache tokens up to a point we can guarantee aren't part of the construct we are disambiguating. I don't know where the approach taken here is ideal -- alternatives are welcome. However, the performance impact (as measured by [llvm-compile-time-tracker](https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=sdkrystian)) is quite minimal (0.09%, which I plan to further improve). --- Patch is 20.70 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96364.diff 8 Files Affected: - (modified) clang/include/clang/Lex/Preprocessor.h (+11-3) - (modified) clang/include/clang/Parse/Parser.h (+6-7) - (modified) clang/lib/Lex/PPCaching.cpp (+35-4) - (modified) clang/lib/Parse/ParseCXXInlineMethods.cpp (+2-39) - (modified) clang/lib/Parse/ParseDecl.cpp (+51-32) - (modified) clang/lib/Parse/ParseExprCXX.cpp (+9-10) - (added) clang/test/CXX/dcl.decl/dcl.meaning/dcl.mptr/p2.cpp (+64) - (modified) clang/test/CXX/temp/temp.res/p3.cpp (+4-6) ``diff diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 9d8a1aae23df3..838857b6b8833 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1150,6 +1150,9 @@ class Preprocessor { /// invoked (at which point the last position is popped). std::vector BacktrackPositions; + std::vector> + UnannotatedBacktrackPositions; + /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running. /// This is used to guard against calling this function recursively. /// @@ -1712,7 +1715,7 @@ class Preprocessor { /// at some point after EnableBacktrackAtThisPos. If you don't, caching of /// tokens will continue indefinitely. /// - void EnableBacktrackAtThisPos(); + void EnableBacktrackAtThisPos(bool Unannotated = false); /// Disable the last EnableBacktrackAtThisPos call. void CommitBacktrackedTokens(); @@ -1723,7 +1726,11 @@ class Preprocessor { /// True if EnableBacktrackAtThisPos() was called and /// caching of tokens is on. + bool isBacktrackEnabled() const { return !BacktrackPositions.empty(); } + bool isUnannotatedBacktrackEnabled() const { +return !UnannotatedBacktrackPositions.empty(); + } /// Lex the next token for this preprocessor. void Lex(Token &Result); @@ -1827,8 +1834,9 @@ class Preprocessor { void RevertCachedTokens(unsigned N) { assert(isBacktrackEnabled() && "Should only be called when tokens are cached for backtracking"); -assert(signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back()) - && "Should revert tokens up to the last backtrack position, not more"); +assert(signed(CachedLexPos) - signed(N) >= + signed(BacktrackPositions.back() >> 1) && + "Should revert tokens up to the last backtrack position, not more"); assert(signed(CachedLexPos) - signed(N) >= 0 && "Corrupted backtrack positions ?"); CachedLexPos -= N; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index d054b8cf0d240..fc0bae6bdec2b 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -1033,7 +1033,7 @@ class Parser : public CodeCompletionHandler { bool isActive; public: -explicit TentativeParsingAction(Parser &p) +explicit TentativeParsingAction(Parser &p, bool Unannotated = false) : P(p), PrevPreferredType(P.PreferredType) { PrevTok = P.Tok; PrevTentativelyDeclaredIdentifierCount = @@ -1041,7 +1041,7 @@ class Parser : public CodeCompletionHandler { PrevParenCount = P.ParenCount; PrevBracketCount = P.BracketCount; PrevBraceCount = P.BraceCount; - P.PP.EnableBacktrackAtThisPos(); + P.PP.EnableBacktrackAtThisPos(Unannotated); isActive = true; } void Commit() { @@ -1072,13 +1072,11 @@ class Parser : public CodeCompletionHandler { class RevertingTentativeParsingAction : private Parser::TentativeParsingAction { public: -RevertingTentativeParsingAction(Parse
[clang] [Clang][Parse] Fix ambiguity with nested-name-specifiers that may declarative (PR #96364)
https://github.com/sdkrystian created https://github.com/llvm/llvm-project/pull/96364 Consider the following: ```cpp template struct A { }; template int A::B::* f(); // error: no member named 'B' in 'A' ``` Although this is clearly valid, clang rejects it because the _nested-name-specifier_ `A::` is parsed as-if it was declarative, meaning, we parse it as-if it was the _nested-name-specifier_ in a redeclaration/specialization. However, we don't (and can't) know whether the _nested-name-specifier_ is declarative until we see the '`*`' token, but at that point we have already complained that `A` has no member named `B`! This patch addresses this bug by adding support for _fully_ unannotated _and_ unbounded tentative parsing, which allows for us to parse past tokens without having to cache tokens up to a point we can guarantee aren't part of the construct we are disambiguating. I don't know where the approach taken here is ideal -- alternatives are welcome. However, the performance impact (as measured by [llvm-compile-time-tracker](https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=sdkrystian)) is quite minimal (0.09%, which I plan to further improve). >From 2b0ac4e04f3eb9f8ececa874001c96a5ff8ee235 Mon Sep 17 00:00:00 2001 From: Krystian Stasiowski Date: Wed, 12 Jun 2024 14:14:26 -0400 Subject: [PATCH] [Clang][Parse] Fix ambiguity with nested-name-specifiers that may be declarative --- clang/include/clang/Lex/Preprocessor.h| 14 +++- clang/include/clang/Parse/Parser.h| 13 ++- clang/lib/Lex/PPCaching.cpp | 39 - clang/lib/Parse/ParseCXXInlineMethods.cpp | 41 + clang/lib/Parse/ParseDecl.cpp | 83 --- clang/lib/Parse/ParseExprCXX.cpp | 19 ++--- .../CXX/dcl.decl/dcl.meaning/dcl.mptr/p2.cpp | 64 ++ clang/test/CXX/temp/temp.res/p3.cpp | 10 +-- 8 files changed, 182 insertions(+), 101 deletions(-) create mode 100644 clang/test/CXX/dcl.decl/dcl.meaning/dcl.mptr/p2.cpp diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 9d8a1aae23df3..838857b6b8833 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1150,6 +1150,9 @@ class Preprocessor { /// invoked (at which point the last position is popped). std::vector BacktrackPositions; + std::vector> + UnannotatedBacktrackPositions; + /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running. /// This is used to guard against calling this function recursively. /// @@ -1712,7 +1715,7 @@ class Preprocessor { /// at some point after EnableBacktrackAtThisPos. If you don't, caching of /// tokens will continue indefinitely. /// - void EnableBacktrackAtThisPos(); + void EnableBacktrackAtThisPos(bool Unannotated = false); /// Disable the last EnableBacktrackAtThisPos call. void CommitBacktrackedTokens(); @@ -1723,7 +1726,11 @@ class Preprocessor { /// True if EnableBacktrackAtThisPos() was called and /// caching of tokens is on. + bool isBacktrackEnabled() const { return !BacktrackPositions.empty(); } + bool isUnannotatedBacktrackEnabled() const { +return !UnannotatedBacktrackPositions.empty(); + } /// Lex the next token for this preprocessor. void Lex(Token &Result); @@ -1827,8 +1834,9 @@ class Preprocessor { void RevertCachedTokens(unsigned N) { assert(isBacktrackEnabled() && "Should only be called when tokens are cached for backtracking"); -assert(signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back()) - && "Should revert tokens up to the last backtrack position, not more"); +assert(signed(CachedLexPos) - signed(N) >= + signed(BacktrackPositions.back() >> 1) && + "Should revert tokens up to the last backtrack position, not more"); assert(signed(CachedLexPos) - signed(N) >= 0 && "Corrupted backtrack positions ?"); CachedLexPos -= N; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index d054b8cf0d240..fc0bae6bdec2b 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -1033,7 +1033,7 @@ class Parser : public CodeCompletionHandler { bool isActive; public: -explicit TentativeParsingAction(Parser &p) +explicit TentativeParsingAction(Parser &p, bool Unannotated = false) : P(p), PrevPreferredType(P.PreferredType) { PrevTok = P.Tok; PrevTentativelyDeclaredIdentifierCount = @@ -1041,7 +1041,7 @@ class Parser : public CodeCompletionHandler { PrevParenCount = P.ParenCount; PrevBracketCount = P.BracketCount; PrevBraceCount = P.BraceCount; - P.PP.EnableBacktrackAtThisPos(); + P.PP.EnableBacktrackAtThisPos(Unannotated); isActive = true; } void Commit() { @@ -1072,13 +1072,11 @@ cl
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
e-kud wrote: Initially I've implemented the target errors through std::string. Then changed to diag::kind after reading InternalsManual. I'm not sure what is better. The drawback of returning diagnoistics by reference is that we can't customize them, only fixed messages. Maybe this is not a big problem because we don't have constantly changing constraints. https://github.com/llvm/llvm-project/pull/96363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
llvmbot wrote: @llvm/pr-subscribers-backend-amdgpu Author: Evgenii Kudriashov (e-kud) Changes Introduce more detailed diagnostics for the constrains. Also provide an opportunity for backends to provide detailed diagnostics for target specific constraints based on enabled features. We provide features as a pointer intentionally because they are not available in some of existing uses. So backends need to consider whether features are available or not. --- Patch is 56.39 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96363.diff 43 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticCommonKinds.td (+33) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-4) - (modified) clang/include/clang/Basic/TargetInfo.h (+12-7) - (modified) clang/lib/Basic/TargetInfo.cpp (+45-18) - (modified) clang/lib/Basic/Targets/AArch64.cpp (+4-2) - (modified) clang/lib/Basic/Targets/AArch64.h (+3-1) - (modified) clang/lib/Basic/Targets/AMDGPU.h (+5-2) - (modified) clang/lib/Basic/Targets/ARC.h (+3-1) - (modified) clang/lib/Basic/Targets/ARM.cpp (+4-2) - (modified) clang/lib/Basic/Targets/ARM.h (+3-1) - (modified) clang/lib/Basic/Targets/AVR.h (+3-1) - (modified) clang/lib/Basic/Targets/BPF.h (+3-1) - (modified) clang/lib/Basic/Targets/CSKY.cpp (+4-2) - (modified) clang/lib/Basic/Targets/CSKY.h (+3-1) - (modified) clang/lib/Basic/Targets/DirectX.h (+3-1) - (modified) clang/lib/Basic/Targets/Hexagon.h (+3-1) - (modified) clang/lib/Basic/Targets/Lanai.h (+3-1) - (modified) clang/lib/Basic/Targets/Le64.h (+3-1) - (modified) clang/lib/Basic/Targets/LoongArch.cpp (+2-1) - (modified) clang/lib/Basic/Targets/LoongArch.h (+3-1) - (modified) clang/lib/Basic/Targets/M68k.cpp (+16-14) - (modified) clang/lib/Basic/Targets/M68k.h (+3-1) - (modified) clang/lib/Basic/Targets/MSP430.h (+3-1) - (modified) clang/lib/Basic/Targets/Mips.h (+3-1) - (modified) clang/lib/Basic/Targets/NVPTX.h (+3-1) - (modified) clang/lib/Basic/Targets/PNaCl.h (+3-1) - (modified) clang/lib/Basic/Targets/PPC.h (+3-1) - (modified) clang/lib/Basic/Targets/RISCV.cpp (+4-2) - (modified) clang/lib/Basic/Targets/RISCV.h (+3-1) - (modified) clang/lib/Basic/Targets/SPIR.cpp (+3-2) - (modified) clang/lib/Basic/Targets/SPIR.h (+6-2) - (modified) clang/lib/Basic/Targets/Sparc.h (+4-2) - (modified) clang/lib/Basic/Targets/SystemZ.cpp (+4-2) - (modified) clang/lib/Basic/Targets/SystemZ.h (+3-1) - (modified) clang/lib/Basic/Targets/TCE.h (+3-1) - (modified) clang/lib/Basic/Targets/VE.h (+3-1) - (modified) clang/lib/Basic/Targets/WebAssembly.h (+3-1) - (modified) clang/lib/Basic/Targets/X86.cpp (+4-2) - (modified) clang/lib/Basic/Targets/X86.h (+3-1) - (modified) clang/lib/Basic/Targets/XCore.h (+3-1) - (modified) clang/lib/CodeGen/CGStmt.cpp (+15-6) - (modified) clang/lib/Sema/SemaStmtAsm.cpp (+10-8) - (modified) clang/test/Sema/asm.c (+40-32) ``diff diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td index de758cbe679dc..d4b0862337165 100644 --- a/clang/include/clang/Basic/DiagnosticCommonKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -309,6 +309,39 @@ def err_asm_invalid_type : Error< def err_ms_asm_bitfield_unsupported : Error< "an inline asm block cannot have an operand which is a bit-field">; +def asm_invalid_constraint_generic : TextSubstitution< + "invalid %select{input|output}0 constraint '%1' in asm">; +def err_asm_invalid_constraint : Error< + "%sub{asm_invalid_constraint_generic}0,1">; +def err_asm_invalid_constraint_start : Error< + "%sub{asm_invalid_constraint_generic}0,1: output constraint must start with" + " '=' or '+'">; +def err_asm_invalid_constraint_rw_clobber : Error< + "%sub{asm_invalid_constraint_generic}0,1: early clobber with a read-write" + " constraint must be a register">; +def err_asm_invalid_constraint_mem_or_reg : Error< + "%sub{asm_invalid_constraint_generic}0,1: constraint must allow either" + " memory or register operands">; +def err_asm_invalid_constraint_missing_bracket : Error< + "%sub{asm_invalid_constraint_generic}0,1: missing ']'">; +def err_asm_invalid_constraint_wrong_symbol : Error< + "%sub{asm_invalid_constraint_generic}0,1: cannot find an output constraint" + " with the specified name">; +def err_asm_invalid_constraint_empty : Error< + "%sub{asm_invalid_constraint_generic}0,1: empty constraint has been" + " provided">; +def err_asm_invalid_constraint_oob : Error< + "%sub{asm_invalid_constraint_generic}0,1: the index is out of bounds">; +def err_asm_invalid_constraint_missing : Error< + "%sub{asm_invalid_constraint_generic}0,1: references to a non-existing output" + " constraint">; +def err_asm_invalid_constraint_wrongly_tied : Error< + "%sub{asm_invalid_constraint_generic}0,1: tied constraint must be tied to" + " the same operand referenced to by the number">; +def err_asm_invalid_constraint_out
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Evgenii Kudriashov (e-kud) Changes Introduce more detailed diagnostics for the constrains. Also provide an opportunity for backends to provide detailed diagnostics for target specific constraints based on enabled features. We provide features as a pointer intentionally because they are not available in some of existing uses. So backends need to consider whether features are available or not. --- Patch is 56.39 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96363.diff 43 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticCommonKinds.td (+33) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-4) - (modified) clang/include/clang/Basic/TargetInfo.h (+12-7) - (modified) clang/lib/Basic/TargetInfo.cpp (+45-18) - (modified) clang/lib/Basic/Targets/AArch64.cpp (+4-2) - (modified) clang/lib/Basic/Targets/AArch64.h (+3-1) - (modified) clang/lib/Basic/Targets/AMDGPU.h (+5-2) - (modified) clang/lib/Basic/Targets/ARC.h (+3-1) - (modified) clang/lib/Basic/Targets/ARM.cpp (+4-2) - (modified) clang/lib/Basic/Targets/ARM.h (+3-1) - (modified) clang/lib/Basic/Targets/AVR.h (+3-1) - (modified) clang/lib/Basic/Targets/BPF.h (+3-1) - (modified) clang/lib/Basic/Targets/CSKY.cpp (+4-2) - (modified) clang/lib/Basic/Targets/CSKY.h (+3-1) - (modified) clang/lib/Basic/Targets/DirectX.h (+3-1) - (modified) clang/lib/Basic/Targets/Hexagon.h (+3-1) - (modified) clang/lib/Basic/Targets/Lanai.h (+3-1) - (modified) clang/lib/Basic/Targets/Le64.h (+3-1) - (modified) clang/lib/Basic/Targets/LoongArch.cpp (+2-1) - (modified) clang/lib/Basic/Targets/LoongArch.h (+3-1) - (modified) clang/lib/Basic/Targets/M68k.cpp (+16-14) - (modified) clang/lib/Basic/Targets/M68k.h (+3-1) - (modified) clang/lib/Basic/Targets/MSP430.h (+3-1) - (modified) clang/lib/Basic/Targets/Mips.h (+3-1) - (modified) clang/lib/Basic/Targets/NVPTX.h (+3-1) - (modified) clang/lib/Basic/Targets/PNaCl.h (+3-1) - (modified) clang/lib/Basic/Targets/PPC.h (+3-1) - (modified) clang/lib/Basic/Targets/RISCV.cpp (+4-2) - (modified) clang/lib/Basic/Targets/RISCV.h (+3-1) - (modified) clang/lib/Basic/Targets/SPIR.cpp (+3-2) - (modified) clang/lib/Basic/Targets/SPIR.h (+6-2) - (modified) clang/lib/Basic/Targets/Sparc.h (+4-2) - (modified) clang/lib/Basic/Targets/SystemZ.cpp (+4-2) - (modified) clang/lib/Basic/Targets/SystemZ.h (+3-1) - (modified) clang/lib/Basic/Targets/TCE.h (+3-1) - (modified) clang/lib/Basic/Targets/VE.h (+3-1) - (modified) clang/lib/Basic/Targets/WebAssembly.h (+3-1) - (modified) clang/lib/Basic/Targets/X86.cpp (+4-2) - (modified) clang/lib/Basic/Targets/X86.h (+3-1) - (modified) clang/lib/Basic/Targets/XCore.h (+3-1) - (modified) clang/lib/CodeGen/CGStmt.cpp (+15-6) - (modified) clang/lib/Sema/SemaStmtAsm.cpp (+10-8) - (modified) clang/test/Sema/asm.c (+40-32) ``diff diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td index de758cbe679dc..d4b0862337165 100644 --- a/clang/include/clang/Basic/DiagnosticCommonKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -309,6 +309,39 @@ def err_asm_invalid_type : Error< def err_ms_asm_bitfield_unsupported : Error< "an inline asm block cannot have an operand which is a bit-field">; +def asm_invalid_constraint_generic : TextSubstitution< + "invalid %select{input|output}0 constraint '%1' in asm">; +def err_asm_invalid_constraint : Error< + "%sub{asm_invalid_constraint_generic}0,1">; +def err_asm_invalid_constraint_start : Error< + "%sub{asm_invalid_constraint_generic}0,1: output constraint must start with" + " '=' or '+'">; +def err_asm_invalid_constraint_rw_clobber : Error< + "%sub{asm_invalid_constraint_generic}0,1: early clobber with a read-write" + " constraint must be a register">; +def err_asm_invalid_constraint_mem_or_reg : Error< + "%sub{asm_invalid_constraint_generic}0,1: constraint must allow either" + " memory or register operands">; +def err_asm_invalid_constraint_missing_bracket : Error< + "%sub{asm_invalid_constraint_generic}0,1: missing ']'">; +def err_asm_invalid_constraint_wrong_symbol : Error< + "%sub{asm_invalid_constraint_generic}0,1: cannot find an output constraint" + " with the specified name">; +def err_asm_invalid_constraint_empty : Error< + "%sub{asm_invalid_constraint_generic}0,1: empty constraint has been" + " provided">; +def err_asm_invalid_constraint_oob : Error< + "%sub{asm_invalid_constraint_generic}0,1: the index is out of bounds">; +def err_asm_invalid_constraint_missing : Error< + "%sub{asm_invalid_constraint_generic}0,1: references to a non-existing output" + " constraint">; +def err_asm_invalid_constraint_wrongly_tied : Error< + "%sub{asm_invalid_constraint_generic}0,1: tied constraint must be tied to" + " the same operand referenced to by the number">; +def err_
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
https://github.com/e-kud created https://github.com/llvm/llvm-project/pull/96363 Introduce more detailed diagnostics for the constrains. Also provide an opportunity for backends to provide detailed diagnostics for target specific constraints based on enabled features. We provide features as a pointer intentionally because they are not available in some of existing uses. So backends need to consider whether features are available or not. >From 4f8504878da33925609d52912e8d0e1f64c41066 Mon Sep 17 00:00:00 2001 From: Evgenii Kudriashov Date: Fri, 21 Jun 2024 14:00:58 -0700 Subject: [PATCH] [clang] Improve diagnostics for constraints of inline asm Introduce more detailed diagnostics for the constrains. Also provide an opportunity for backends to provide detailed diagnostics for target specific constraints based on enabled features. --- .../clang/Basic/DiagnosticCommonKinds.td | 33 + .../clang/Basic/DiagnosticSemaKinds.td| 4 -- clang/include/clang/Basic/TargetInfo.h| 19 +++-- clang/lib/Basic/TargetInfo.cpp| 63 +++- clang/lib/Basic/Targets/AArch64.cpp | 6 +- clang/lib/Basic/Targets/AArch64.h | 4 +- clang/lib/Basic/Targets/AMDGPU.h | 7 +- clang/lib/Basic/Targets/ARC.h | 4 +- clang/lib/Basic/Targets/ARM.cpp | 6 +- clang/lib/Basic/Targets/ARM.h | 4 +- clang/lib/Basic/Targets/AVR.h | 4 +- clang/lib/Basic/Targets/BPF.h | 4 +- clang/lib/Basic/Targets/CSKY.cpp | 6 +- clang/lib/Basic/Targets/CSKY.h| 4 +- clang/lib/Basic/Targets/DirectX.h | 4 +- clang/lib/Basic/Targets/Hexagon.h | 4 +- clang/lib/Basic/Targets/Lanai.h | 4 +- clang/lib/Basic/Targets/Le64.h| 4 +- clang/lib/Basic/Targets/LoongArch.cpp | 3 +- clang/lib/Basic/Targets/LoongArch.h | 4 +- clang/lib/Basic/Targets/M68k.cpp | 30 clang/lib/Basic/Targets/M68k.h| 4 +- clang/lib/Basic/Targets/MSP430.h | 4 +- clang/lib/Basic/Targets/Mips.h| 4 +- clang/lib/Basic/Targets/NVPTX.h | 4 +- clang/lib/Basic/Targets/PNaCl.h | 4 +- clang/lib/Basic/Targets/PPC.h | 4 +- clang/lib/Basic/Targets/RISCV.cpp | 6 +- clang/lib/Basic/Targets/RISCV.h | 4 +- clang/lib/Basic/Targets/SPIR.cpp | 5 +- clang/lib/Basic/Targets/SPIR.h| 8 ++- clang/lib/Basic/Targets/Sparc.h | 6 +- clang/lib/Basic/Targets/SystemZ.cpp | 6 +- clang/lib/Basic/Targets/SystemZ.h | 4 +- clang/lib/Basic/Targets/TCE.h | 4 +- clang/lib/Basic/Targets/VE.h | 4 +- clang/lib/Basic/Targets/WebAssembly.h | 4 +- clang/lib/Basic/Targets/X86.cpp | 6 +- clang/lib/Basic/Targets/X86.h | 4 +- clang/lib/Basic/Targets/XCore.h | 4 +- clang/lib/CodeGen/CGStmt.cpp | 21 -- clang/lib/Sema/SemaStmtAsm.cpp| 18 ++--- clang/test/Sema/asm.c | 72 ++- 43 files changed, 287 insertions(+), 134 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td index de758cbe679dc..d4b0862337165 100644 --- a/clang/include/clang/Basic/DiagnosticCommonKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -309,6 +309,39 @@ def err_asm_invalid_type : Error< def err_ms_asm_bitfield_unsupported : Error< "an inline asm block cannot have an operand which is a bit-field">; +def asm_invalid_constraint_generic : TextSubstitution< + "invalid %select{input|output}0 constraint '%1' in asm">; +def err_asm_invalid_constraint : Error< + "%sub{asm_invalid_constraint_generic}0,1">; +def err_asm_invalid_constraint_start : Error< + "%sub{asm_invalid_constraint_generic}0,1: output constraint must start with" + " '=' or '+'">; +def err_asm_invalid_constraint_rw_clobber : Error< + "%sub{asm_invalid_constraint_generic}0,1: early clobber with a read-write" + " constraint must be a register">; +def err_asm_invalid_constraint_mem_or_reg : Error< + "%sub{asm_invalid_constraint_generic}0,1: constraint must allow either" + " memory or register operands">; +def err_asm_invalid_constraint_missing_bracket : Error< + "%sub{asm_invalid_constraint_generic}0,1: missing ']'">; +def err_asm_invalid_constraint_wrong_symbol : Error< + "%sub{asm_invalid_constraint_generic}0,1: cannot find an output constraint" + " with the specified name">; +def err_asm_invalid_constraint_empty : Error< + "%sub{asm_invalid_constraint_generic}0,1: empty constraint has been" + " provided">; +def err_asm_invalid_constraint_oob : Error< + "%sub{asm_invalid_constraint_generic}0,1: the index is out of bounds">; +de
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
h-vetinari wrote: The failing tests here previously were clearly unrelated (missing python module `packaging` somewhere). The failure I see now is due to a timeout (also unrelated): ``` llvm-lit: /home/runner/_work/llvm-project/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 1500 seconds was requested on the command line. Forcing timeout to be 1500 seconds. -- Testing: 9661 tests, 30 workers -- interrupted by user, skipping remaining tests ``` CI hasn't finished yet, so there may be others things hiding still, but I don't consider it realistic (to be caused by the changes here). The code before/after this PR should work exactly as before, we're just stripping the fallbacks for old CMake. https://github.com/llvm/llvm-project/pull/96171 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)
@@ -0,0 +1,19 @@ +.. title:: clang-tidy - bugprone-move-shared-pointer-contents + +bugprone-move-shared-pointer-contents += + + +Detects calls to move the contents out of a ``std::shared_ptr`` rather +than moving the pointer itself. In other words, calling +``std::move(*p)`` or ``std::move(*p.get())``. Other reference holders +may not be expecting the move and suddenly getting empty or otherwise +indeterminate states can cause issues. + pizzud wrote: Done. We could support C++98 for anybody using boost::shared_pointer, but it seems like overkill. https://github.com/llvm/llvm-project/pull/67467 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)
@@ -383,7 +388,7 @@ Changes in existing checks - Improved :doc:`misc-unused-using-decls ` check to avoid false positive when - using in elaborated type and only check cpp files. pizzud wrote: Done. https://github.com/llvm/llvm-project/pull/67467 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)
@@ -0,0 +1,145 @@ +//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include +#include + +#include "MoveSharedPointerContentsCheck.h" +#include "../ClangTidyCheck.h" +#include "../utils/Matchers.h" +#include "../utils/OptionsUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { +namespace { + +// Reports whether the QualType matches the inner matcher, which is expected to be +// matchesAnyListedName. The QualType is expected to either point to a RecordDecl +// (for concrete types) or an ElaboratedType (for dependent ones). +AST_MATCHER_P(QualType, isSharedPointer, + clang::ast_matchers::internal::Matcher, InnerMatcher) { + if (const auto *RD = Node.getTypePtr()->getAsCXXRecordDecl(); RD != nullptr) { +return InnerMatcher.matches(*RD, Finder, Builder); + } else if (const auto *ED = Node.getTypePtr()->getAs(); + ED != nullptr) { +if (const auto *TS = ED->getNamedType() + .getTypePtr() + ->getAs(); +TS != nullptr) { + return InnerMatcher.matches(*TS->getTemplateName().getAsTemplateDecl(), + Finder, Builder); +} + } + + return false; +} + +} // namespace + +MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck( +StringRef Name, ClangTidyContext *Context) +: ClangTidyCheck(Name, Context), + SharedPointerClasses(utils::options::parseStringList( + Options.get("SharedPointerClasses", "::std::shared_ptr"))) {} + +void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) { + auto isStdMove = callee(functionDecl(hasName("::std::move"))); pizzud wrote: Good idea! Done. https://github.com/llvm/llvm-project/pull/67467 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)
@@ -368,8 +374,7 @@ Changes in existing checks ` check to avoid false positive when using pointer to member function. Additionally, the check no longer emits a diagnostic when a variable that is not type-dependent is an operand of a - type-dependent binary operator. Improved performance of the check through pizzud wrote: Done. https://github.com/llvm/llvm-project/pull/67467 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)
https://github.com/pizzud updated https://github.com/llvm/llvm-project/pull/67467 >From 04a3e8d8cbd6943f44a81fddb0524902202a1a78 Mon Sep 17 00:00:00 2001 From: David Pizzuto Date: Tue, 26 Sep 2023 10:45:42 -0700 Subject: [PATCH 1/6] [clang-tidy] Add bugprone-move-shared-pointer-contents check. This check detects moves of the contents of a shared pointer rather than the pointer itself. Other code with a reference to the shared pointer is probably not expecting the move. The set of shared pointer classes is configurable via options to allow individual projects to cover additional types. --- .../MoveSharedPointerContentsCheck.cpp| 157 ++ .../bugprone/MoveSharedPointerContentsCheck.h | 45 + .../bugprone/move-shared-pointer-contents.rst | 19 +++ .../docs/clang-tidy/checks/list.rst | 4 + 4 files changed, 225 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/bugprone/move-shared-pointer-contents.rst diff --git a/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp new file mode 100644 index 0..461fe91267e63 --- /dev/null +++ b/clang-tools-extra/clang-tidy/bugprone/MoveSharedPointerContentsCheck.cpp @@ -0,0 +1,157 @@ +//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "MoveSharedPointerContentsCheck.h" +#include "../ClangTidyCheck.h" +#include "../utils/Matchers.h" +#include "../utils/OptionsUtils.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::bugprone { + +MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck( +StringRef Name, ClangTidyContext *Context) +: ClangTidyCheck(Name, Context), + SharedPointerClasses(utils::options::parseStringList( + Options.get("SharedPointerClasses", "::std::shared_ptr"))) {} + +void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) { + auto isStdMove = callee(functionDecl(hasName("::std::move"))); + + // Resolved type, direct move. + Finder->addMatcher( + callExpr(isStdMove, hasArgument(0, cxxOperatorCallExpr( + hasOverloadedOperatorName("*"), + callee(cxxMethodDecl(ofClass( + matchers::matchesAnyListedName( + SharedPointerClasses))) + .bind("call"), + this); + + // Resolved type, move out of get(). + Finder->addMatcher( + callExpr( + isStdMove, + hasArgument( + 0, unaryOperator( + hasOperatorName("*"), + hasUnaryOperand(cxxMemberCallExpr(callee(cxxMethodDecl( + hasName("get"), ofClass(matchers::matchesAnyListedName( + SharedPointerClasses) + .bind("get_call"), + this); + + auto isStdMoveUnresolved = callee(unresolvedLookupExpr( + hasAnyDeclaration(namedDecl(hasUnderlyingDecl(hasName("::std::move")); + + // Unresolved type, direct move. + Finder->addMatcher( + callExpr( + isStdMoveUnresolved, + hasArgument(0, unaryOperator(hasOperatorName("*"), + hasUnaryOperand(declRefExpr(hasType( + qualType().bind("unresolved_p"))) + .bind("unresolved_call"), + this); + // Annoyingly, the declRefExpr in the unresolved-move-of-get() case + // is of rather than shared_ptr, so we have to + // just fetch the variable. This does leave a gap where a temporary + // shared_ptr wouldn't be caught, but moving out of a temporary + // shared pointer is a truly wild thing to do so it should be okay. + + // Unresolved type, move out of get(). + Finder->addMatcher( + callExpr(isStdMoveUnresolved, + hasArgument( + 0, unaryOperator(hasOperatorName("*"), +hasDescendant(cxxDependentScopeMemberExpr( +hasMemberName("get"))), +hasDescendant(declRefExpr(to( + varDecl().bind("unresolved_get_p"))) + .bind("unresolved_get_call"), + this); +} + +bool
[clang] [Clang] use parent declaration context to avoid asserting cast failure in defaulted comparison method (PR #96228)
shafik wrote: There are several test failures that look related to this change, please check them out. https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] use parent declaration context to avoid asserting cast failure in defaulted comparison method (PR #96228)
@@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s shafik wrote: I think this is a better location for the test: https://github.com/llvm/llvm-project/blob/main/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp We normally wrap tests in a namespace starting with `GH` and then the issue number, for this case `namespace GH96043`. https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] use parent declaration context to avoid asserting cast failure in defaulted comparison method (PR #96228)
https://github.com/shafik commented: Thank you for the fix. I am curious what specifically about this code triggers the crash. We do have a test w/ a defaulted outside the class. So there is another condition needed to trigger this. It looks like removing `constexpr` from `operator==(d h, g i)` prevents the crash. Once we understand the specific condition we should add that to the summary. https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] use parent declaration context to avoid asserting cast failure in defaulted comparison method (PR #96228)
https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/96228 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)
banach-space wrote: > if I do so should I also move the target-features-*.f90 tests? Yes, but to me that would qualify as an "unrelated change" (i.e. sth for a separate PR, no need to worry about it here). In general, this PR is about enabling a flag in Flang and making sure that it actually works. This kind of "integration" is a driver task, hence my suggestion. https://github.com/llvm/llvm-project/pull/95043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ThreadSafety] Check trylock function success and return types (PR #95290)
https://github.com/dmcardle edited https://github.com/llvm/llvm-project/pull/95290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ThreadSafety] Check trylock function success and return types (PR #95290)
https://github.com/dmcardle updated https://github.com/llvm/llvm-project/pull/95290 >From 807953fc74920e3d5ed727a00c0e1177870c56fe Mon Sep 17 00:00:00 2001 From: Dan McArdle Date: Thu, 20 Jun 2024 17:43:16 -0400 Subject: [PATCH] [clang][ThreadSafety] Check trylock function success and return types With this change, Clang will generate errors when trylock functions have improper return types. Today, it silently fails to apply the trylock attribute to these functions which may incorrectly lead users to believe they have correctly acquired locks before accessing guarded data. As a side effect of explicitly checking the success argument type, I seem to have fixed a false negative in the analysis that could occur when a trylock's success argument is an enumerator. I've added a regression test to warn-thread-safety-analysis.cpp named `TrylockSuccessEnumFalseNegative`. This change also improves the documentation with descriptions of of the subtle gotchas that arise from the analysis interpreting the success arg as a boolean. Issue #92408 --- clang/docs/ReleaseNotes.rst | 10 ++ clang/docs/ThreadSafetyAnalysis.rst | 52 +++- .../clang/Basic/DiagnosticSemaKinds.td| 23 +++- clang/include/clang/Sema/ParsedAttr.h | 2 + clang/lib/Analysis/ThreadSafety.cpp | 82 +++- clang/lib/Sema/SemaDeclAttr.cpp | 34 +++-- clang/test/Sema/attr-capabilities.c | 12 +- .../SemaCXX/warn-thread-safety-analysis.cpp | 123 +- .../SemaCXX/warn-thread-safety-parsing.cpp| 107 --- clang/unittests/AST/ASTImporterTest.cpp | 6 +- 10 files changed, 369 insertions(+), 82 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7ac0fa0141b47..28ec3d54a5a77 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -71,6 +71,11 @@ C++ Specific Potentially Breaking Changes To fix this, update libstdc++ to version 14.1.1 or greater. +- Clang now emits errors when Thread Safety Analysis trylock attributes are + applied to functions or methods with incompatible return values, such as + constructors, destructors, and void-returning functions. This only affects the + ``TRY_ACQUIRE`` and ``TRY_ACQUIRE_SHARED`` attributes (and any synonyms). + ABI Changes in This Version --- - Fixed Microsoft name mangling of implicitly defined variables used for thread @@ -720,6 +725,11 @@ Bug Fixes in This Version - Fixed `static_cast` to array of unknown bound. Fixes (#GH62863). +- Clang's Thread Safety Analysis now evaluates trylock success arguments of enum + types rather than silently defaulting to false. This fixes a class of false + negatives where the analysis failed to detect unchecked access to guarded + data. + Bug Fixes to Compiler Builtins ^^ diff --git a/clang/docs/ThreadSafetyAnalysis.rst b/clang/docs/ThreadSafetyAnalysis.rst index dcde0c706c704..0ecbebe7a692f 100644 --- a/clang/docs/ThreadSafetyAnalysis.rst +++ b/clang/docs/ThreadSafetyAnalysis.rst @@ -420,10 +420,17 @@ TRY_ACQUIRE(, ...), TRY_ACQUIRE_SHARED(, ...) *Previously:* ``EXCLUSIVE_TRYLOCK_FUNCTION``, ``SHARED_TRYLOCK_FUNCTION`` These are attributes on a function or method that tries to acquire the given -capability, and returns a boolean value indicating success or failure. -The first argument must be ``true`` or ``false``, to specify which return value -indicates success, and the remaining arguments are interpreted in the same way -as ``ACQUIRE``. See :ref:`mutexheader`, below, for example uses. +capability, and returns a boolean, integer, or pointer value indicating success +or failure. + +The attribute's first argument defines whether a zero or non-zero return value +indicates success. Syntactically, it accepts ``NULL`` or ``nullptr``, ``bool`` +and ``int`` literals, as well as enumerator values. *The analysis only cares +whether this success value is zero or non-zero.* This leads to some subtle +consequences, discussed in the next section. + +The remaining arguments are interpreted in the same way as ``ACQUIRE``. See +:ref:`mutexheader`, below, for example uses. Because the analysis doesn't support conditional locking, a capability is treated as acquired after the first branch on the return value of a try-acquire @@ -445,6 +452,43 @@ function. } } +Subtle Consequences of Non-Boolean Success Values +^ + +The trylock attributes accept non-boolean expressions for the success value, but +the analysis only cares whether the value is zero or non-zero. + +Suppose you define an enum with two non-zero enumerators: ``LockAcquired = 1`` +and ``LockNotAcquired = 2``. If your trylock function returns ``LockAcquired`` +on success and ``LockNotAcquired`` on failure, the analysis may fail to detect +access to guarded data without holding the mutex because they
[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)
efriedma-quic wrote: I can't think of any obvious reason this would cause timeouts. I mean, you're adding metadata to a bunch of functions, and if something handles that metadata inefficiently, things could easily explode. But nothing specific comes to mind. https://github.com/llvm/llvm-project/pull/96025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)
@@ -707,7 +707,34 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD, const CallExpr *E, llvm::Constant *calleeValue) { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E); CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD)); - return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot()); + RValue Call = + CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot()); + + // Check the supported intrinsic. + if (unsigned BuiltinID = FD->getBuiltinID()) { +auto IntrinsicID = [&]() -> unsigned { + switch (BuiltinID) { + case Builtin::BIexpf: + case Builtin::BI__builtin_expf: + case Builtin::BI__builtin_expf128: +return true; + } + // TODO: support more FP math libcalls + return false; +}(); + +if (IntrinsicID) { + llvm::MDBuilder MDHelper(CGF.getLLVMContext()); + MDNode *RootMD = CGF.CGM.getTBAARoot(); + // Emit "int" TBAA metadata on FP math libcalls. + MDNode *AliasType = MDHelper.createTBAANode("int", RootMD); efriedma-quic wrote: We should have code somewhere for getting metadata for "int"? https://github.com/llvm/llvm-project/pull/96025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)
efriedma-quic wrote: > > Can we restrict this to targets where libm actually modifies errno? > > Do you mean it is better to have a function list, which actually modifies > `errno` ? For example, we should restrict to `__exp10`, but but not a general > top call `__exp `? I said targets, not functions. For example, MacOS never set errno for math functions. https://github.com/llvm/llvm-project/pull/96025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Revert "Revert "[clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
PeterChou1 wrote: @ilovepi https://github.com/llvm/llvm-project/pull/96358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Revert "Revert "[clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/96358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [libcxx] [libunwind] [llvm] [openmp] [cmake] switch to CMake's native `check_{compiler,linker}_flag` (PR #96171)
https://github.com/h-vetinari updated https://github.com/llvm/llvm-project/pull/96171 >From 1df587efeb71fb1929667f008d7e9b251863d9d8 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 20 Jun 2024 21:43:31 +1100 Subject: [PATCH 1/3] [cmake] switch to CMake's native check_linker_flag, delete LLVMCheckLinkerFlag.cmake now that CMake baseline has moved past 3.18; see https://cmake.org/cmake/help/latest/module/CheckLinkerFlag.html --- clang/tools/driver/CMakeLists.txt| 4 +-- llvm/cmake/modules/AddLLVM.cmake | 4 +-- llvm/cmake/modules/HandleLLVMOptions.cmake | 8 +++--- llvm/cmake/modules/HandleLLVMStdlib.cmake| 6 ++--- llvm/cmake/modules/LLVMCheckLinkerFlag.cmake | 28 5 files changed, 11 insertions(+), 39 deletions(-) delete mode 100644 llvm/cmake/modules/LLVMCheckLinkerFlag.cmake diff --git a/clang/tools/driver/CMakeLists.txt b/clang/tools/driver/CMakeLists.txt index 290bf2a42536d..018605c2fd4f2 100644 --- a/clang/tools/driver/CMakeLists.txt +++ b/clang/tools/driver/CMakeLists.txt @@ -107,7 +107,7 @@ endif() if(CLANG_ORDER_FILE AND (LLVM_LINKER_IS_APPLE OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD)) - include(LLVMCheckLinkerFlag) + include(CheckLinkerFlag) if (LLVM_LINKER_IS_APPLE OR (LLVM_LINKER_IS_LLD AND APPLE)) set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}") @@ -118,7 +118,7 @@ if(CLANG_ORDER_FILE AND endif() # This is a test to ensure the actual order file works with the linker. - llvm_check_linker_flag(CXX ${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS) + check_linker_flag(CXX ${LINKER_ORDER_FILE_OPTION} LINKER_ORDER_FILE_WORKS) # Passing an empty order file disables some linker layout optimizations. # To work around this and enable workflows for re-linking when the order file diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 03f4e1f190fd9..cac5470435d91 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -327,8 +327,8 @@ function(add_link_opts target_name) elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD) # Support for ld -z discard-unused=sections was only added in # Solaris 11.4. GNU ld ignores it, but warns every time. -include(LLVMCheckLinkerFlag) -llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED) +include(CheckLinkerFlag) +check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED) if (LINKER_SUPPORTS_Z_DISCARD_UNUSED) set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-z,discard-unused=sections") diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake index 5ca580fbb59c5..bdbd36174fc7a 100644 --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -1061,8 +1061,8 @@ if (LLVM_USE_SPLIT_DWARF AND if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_compile_options($<$:-gsplit-dwarf>) -include(LLVMCheckLinkerFlag) -llvm_check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX) +include(CheckLinkerFlag) +check_linker_flag(CXX "-Wl,--gdb-index" LINKER_SUPPORTS_GDB_INDEX) append_if(LINKER_SUPPORTS_GDB_INDEX "-Wl,--gdb-index" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) endif() @@ -1083,8 +1083,8 @@ endif() # lld doesn't print colored diagnostics when invoked from Ninja if (UNIX AND CMAKE_GENERATOR MATCHES "Ninja") - include(LLVMCheckLinkerFlag) - llvm_check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) + include(CheckLinkerFlag) + check_linker_flag(CXX "-Wl,--color-diagnostics" LINKER_SUPPORTS_COLOR_DIAGNOSTICS) append_if(LINKER_SUPPORTS_COLOR_DIAGNOSTICS "-Wl,--color-diagnostics" CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) endif() diff --git a/llvm/cmake/modules/HandleLLVMStdlib.cmake b/llvm/cmake/modules/HandleLLVMStdlib.cmake index 7afc10cff74ff..a7e138aa0789b 100644 --- a/llvm/cmake/modules/HandleLLVMStdlib.cmake +++ b/llvm/cmake/modules/HandleLLVMStdlib.cmake @@ -13,12 +13,12 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED) endfunction() include(CheckCXXCompilerFlag) - include(LLVMCheckLinkerFlag) + include(CheckLinkerFlag) set(LLVM_LIBCXX_USED 0) if(LLVM_ENABLE_LIBCXX) if(LLVM_COMPILER_IS_GCC_COMPATIBLE) check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB) - llvm_check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB) + check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB) if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB) append("-stdlib=libc++" CMAKE_CXX_FLAGS CMAKE_EXE_
[clang-tools-extra] Revert "Revert "[clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/96358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AMDGPU] Add builtins for instrinsic `llvm.amdgcn.raw.buffer.store` (PR #94576)
https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/94576 >From f16b927ab1b582d1b53c24b846618a5bb87a52e1 Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Fri, 21 Jun 2024 16:58:02 -0400 Subject: [PATCH] [Clang][AMDGPU] Add builtins for instrinsic `llvm.amdgcn.raw.buffer.store` --- clang/include/clang/Basic/BuiltinsAMDGPU.def | 6 + clang/lib/CodeGen/CGBuiltin.cpp | 8 + .../builtins-amdgcn-raw-buffer-store.cl | 172 ++ .../builtins-amdgcn-raw-buffer-store-error.cl | 35 4 files changed, 221 insertions(+) create mode 100644 clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-store.cl create mode 100644 clang/test/SemaOpenCL/builtins-amdgcn-raw-buffer-store-error.cl diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def b/clang/include/clang/Basic/BuiltinsAMDGPU.def index a73e63355cfd7..56bba448e12a4 100644 --- a/clang/include/clang/Basic/BuiltinsAMDGPU.def +++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def @@ -149,6 +149,12 @@ BUILTIN(__builtin_amdgcn_mqsad_pk_u16_u8, "WUiWUiUiWUi", "nc") BUILTIN(__builtin_amdgcn_mqsad_u32_u8, "V4UiWUiUiV4Ui", "nc") BUILTIN(__builtin_amdgcn_make_buffer_rsrc, "Qbv*sii", "nc") +BUILTIN(__builtin_amdgcn_raw_buffer_store_b8, "vcQbiiIi", "n") +BUILTIN(__builtin_amdgcn_raw_buffer_store_b16, "vsQbiiIi", "n") +BUILTIN(__builtin_amdgcn_raw_buffer_store_b32, "viQbiiIi", "n") +BUILTIN(__builtin_amdgcn_raw_buffer_store_b64, "vV2iQbiiIi", "n") +BUILTIN(__builtin_amdgcn_raw_buffer_store_b96, "vV3iQbiiIi", "n") +BUILTIN(__builtin_amdgcn_raw_buffer_store_b128, "vV4iQbiiIi", "n") //===--===// // Ballot builtins. diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index dc09f8972dd15..34424670f303d 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -19118,6 +19118,14 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, case AMDGPU::BI__builtin_amdgcn_make_buffer_rsrc: return emitBuiltinWithOneOverloadedType<4>( *this, E, Intrinsic::amdgcn_make_buffer_rsrc); + case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b8: + case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b16: + case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b32: + case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b64: + case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b96: + case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b128: +return emitBuiltinWithOneOverloadedType<5>( +*this, E, Intrinsic::amdgcn_raw_ptr_buffer_store); default: return nullptr; } diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-store.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-store.cl new file mode 100644 index 0..37975d59730c5 --- /dev/null +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-raw-buffer-store.cl @@ -0,0 +1,172 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// REQUIRES: amdgpu-registered-target +// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu verde -emit-llvm -o - %s | FileCheck %s + +typedef char i8; +typedef short i16; +typedef int i32; +typedef int i64 __attribute__((ext_vector_type(2))); +typedef int i96 __attribute__((ext_vector_type(3))); +typedef int i128 __attribute__((ext_vector_type(4))); + +// CHECK-LABEL: @test_amdgcn_raw_ptr_buffer_store_b8( +// CHECK-NEXT: entry: +// CHECK-NEXT:tail call void @llvm.amdgcn.raw.ptr.buffer.store.i8(i8 [[VDATA:%.*]], ptr addrspace(8) [[RSRC:%.*]], i32 0, i32 0, i32 0) +// CHECK-NEXT:ret void +// +void test_amdgcn_raw_ptr_buffer_store_b8(i8 vdata, __amdgpu_buffer_rsrc_t rsrc, int offset, int soffset) { + __builtin_amdgcn_raw_buffer_store_b8(vdata, rsrc, /*offset=*/0, /*soffset=*/0, /*aux=*/0); +} + +// CHECK-LABEL: @test_amdgcn_raw_ptr_buffer_store_b16( +// CHECK-NEXT: entry: +// CHECK-NEXT:tail call void @llvm.amdgcn.raw.ptr.buffer.store.i16(i16 [[VDATA:%.*]], ptr addrspace(8) [[RSRC:%.*]], i32 0, i32 0, i32 0) +// CHECK-NEXT:ret void +// +void test_amdgcn_raw_ptr_buffer_store_b16(i16 vdata, __amdgpu_buffer_rsrc_t rsrc, int offset, int soffset) { + __builtin_amdgcn_raw_buffer_store_b16(vdata, rsrc, /*offset=*/0, /*soffset=*/0, /*aux=*/0); +} + +// CHECK-LABEL: @test_amdgcn_raw_ptr_buffer_store_b32( +// CHECK-NEXT: entry: +// CHECK-NEXT:tail call void @llvm.amdgcn.raw.ptr.buffer.store.i32(i32 [[VDATA:%.*]], ptr addrspace(8) [[RSRC:%.*]], i32 0, i32 0, i32 0) +// CHECK-NEXT:ret void +// +void test_amdgcn_raw_ptr_buffer_store_b32(i32 vdata, __amdgpu_buffer_rsrc_t rsrc, int offset, int soffset) { + __builtin_amdgcn_raw_buffer_store_b32(vdata, rsrc, /*offset=*/0, /*soffset=*/0, /*aux=*/0); +} + +// CHECK-LABEL: @test_amdgcn_raw_ptr_buffer_store_b64( +// CHECK-NEXT: entry: +// CHECK-NEXT:tail call void @llvm.amdgcn.raw.ptr.buffer.store.v2i32(<2 x i32> [[VDATA:%.*]], ptr addrspace(8) [[RSRC:%.*
[clang-tools-extra] Revert "Revert "[clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: None (PeterChou1) Changes @ilovepi re-reverts clang-doc --- Full diff: https://github.com/llvm/llvm-project/pull/96358.diff 2 Files Affected: - (modified) clang-tools-extra/clang-doc/tool/ClangDocMain.cpp (+81-19) - (added) clang-tools-extra/test/clang-doc/single-source-html.cpp (+2) ``diff diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 5517522d7967d..5a43c70a5ebc3 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -81,6 +81,12 @@ static llvm::cl::list UserStylesheets( llvm::cl::desc("CSS stylesheets to extend the default styles."), llvm::cl::cat(ClangDocCategory)); +static llvm::cl::opt UserAssetPath( +"asset", +llvm::cl::desc("User supplied asset path to " + "override the default css and js files for html output"), +llvm::cl::cat(ClangDocCategory)); + static llvm::cl::opt SourceRoot("source-root", llvm::cl::desc(R"( Directory where processed files are stored. Links to definition locations will only be @@ -127,16 +133,86 @@ std::string getFormatString() { // GetMainExecutable (since some platforms don't support taking the // address of main, and some platforms can't implement GetMainExecutable // without being given the address of a function in the main executable). -std::string GetExecutablePath(const char *Argv0, void *MainAddr) { +std::string getExecutablePath(const char *Argv0, void *MainAddr) { return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } +llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) { + using DirIt = llvm::sys::fs::directory_iterator; + std::error_code FileErr; + llvm::SmallString<128> FilePath(UserAssetPath); + for (DirIt DirStart = DirIt(UserAssetPath, FileErr), + DirEnd; + !FileErr && DirStart != DirEnd; DirStart.increment(FileErr)) { +FilePath = DirStart->path(); +if (llvm::sys::fs::is_regular_file(FilePath)) { + if (llvm::sys::path::extension(FilePath) == ".css") +CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), + std::string(FilePath)); + else if (llvm::sys::path::extension(FilePath) == ".js") +CDCtx.FilesToCopy.emplace_back(FilePath.str()); +} + } + if (FileErr) +return llvm::createFileError(FilePath, FileErr); + return llvm::Error::success(); +} + +llvm::Error getDefaultAssetFiles(const char *Argv0, + clang::doc::ClangDocContext &CDCtx) { + void *MainAddr = (void *)(intptr_t)getExecutablePath; + std::string ClangDocPath = getExecutablePath(Argv0, MainAddr); + llvm::SmallString<128> NativeClangDocPath; + llvm::sys::path::native(ClangDocPath, NativeClangDocPath); + + llvm::SmallString<128> AssetsPath; + AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath); + llvm::sys::path::append(AssetsPath, "..", "share", "clang"); + llvm::SmallString<128> DefaultStylesheet; + llvm::sys::path::native(AssetsPath, DefaultStylesheet); + llvm::sys::path::append(DefaultStylesheet, + "clang-doc-default-stylesheet.css"); + llvm::SmallString<128> IndexJS; + llvm::sys::path::native(AssetsPath, IndexJS); + llvm::sys::path::append(IndexJS, "index.js"); + + llvm::outs() << "Using default asset: " << AssetsPath << "\n"; + + if (!llvm::sys::fs::is_regular_file(IndexJS)) +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "default index.js file missing at " + + IndexJS + "\n"); + + if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +"default clang-doc-default-stylesheet.css file missing at " + +DefaultStylesheet + "\n"); + + CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), + std::string(DefaultStylesheet)); + CDCtx.FilesToCopy.emplace_back(IndexJS.str()); + + return llvm::Error::success(); +} + +llvm::Error getHtmlAssetFiles(const char *Argv0, + clang::doc::ClangDocContext &CDCtx) { + if (!UserAssetPath.empty() && + !llvm::sys::fs::is_directory(std::string(UserAssetPath))) +llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath + << " falling back to default\n"; + if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) +return getAssetFiles(CDCtx); + return getDefaultAssetFiles(Argv0, CDCtx); +} + int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); std::error_code OK; const char *Overview = -R"(Generates documentation from source code and comments. + R"(Generates documentation from source code and comments. Example usage for files w
[clang-tools-extra] Revert "Revert "[clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
https://github.com/PeterChou1 edited https://github.com/llvm/llvm-project/pull/96358 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Revert "Revert "[clang-doc] Add --asset option to clang-doc" (#96354)" (PR #96358)
https://github.com/PeterChou1 created https://github.com/llvm/llvm-project/pull/96358 @ilovepi re-reverts clang-doc, i think it was false alarm? >From bb407e7c6de15d7ed2f0dd645ca2a469ee1f8a8e Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 21 Jun 2024 16:57:30 -0400 Subject: [PATCH] Revert "Revert "[clang-doc] Add --asset option to clang-doc" (#96354)" This reverts commit bf824d98c06099c50413cd6c957a75b894a8ac26. --- .../clang-doc/tool/ClangDocMain.cpp | 100 ++ .../test/clang-doc/single-source-html.cpp | 2 + 2 files changed, 83 insertions(+), 19 deletions(-) create mode 100644 clang-tools-extra/test/clang-doc/single-source-html.cpp diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 5517522d7967d..5a43c70a5ebc3 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -81,6 +81,12 @@ static llvm::cl::list UserStylesheets( llvm::cl::desc("CSS stylesheets to extend the default styles."), llvm::cl::cat(ClangDocCategory)); +static llvm::cl::opt UserAssetPath( +"asset", +llvm::cl::desc("User supplied asset path to " + "override the default css and js files for html output"), +llvm::cl::cat(ClangDocCategory)); + static llvm::cl::opt SourceRoot("source-root", llvm::cl::desc(R"( Directory where processed files are stored. Links to definition locations will only be @@ -127,16 +133,86 @@ std::string getFormatString() { // GetMainExecutable (since some platforms don't support taking the // address of main, and some platforms can't implement GetMainExecutable // without being given the address of a function in the main executable). -std::string GetExecutablePath(const char *Argv0, void *MainAddr) { +std::string getExecutablePath(const char *Argv0, void *MainAddr) { return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } +llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) { + using DirIt = llvm::sys::fs::directory_iterator; + std::error_code FileErr; + llvm::SmallString<128> FilePath(UserAssetPath); + for (DirIt DirStart = DirIt(UserAssetPath, FileErr), + DirEnd; + !FileErr && DirStart != DirEnd; DirStart.increment(FileErr)) { +FilePath = DirStart->path(); +if (llvm::sys::fs::is_regular_file(FilePath)) { + if (llvm::sys::path::extension(FilePath) == ".css") +CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), + std::string(FilePath)); + else if (llvm::sys::path::extension(FilePath) == ".js") +CDCtx.FilesToCopy.emplace_back(FilePath.str()); +} + } + if (FileErr) +return llvm::createFileError(FilePath, FileErr); + return llvm::Error::success(); +} + +llvm::Error getDefaultAssetFiles(const char *Argv0, + clang::doc::ClangDocContext &CDCtx) { + void *MainAddr = (void *)(intptr_t)getExecutablePath; + std::string ClangDocPath = getExecutablePath(Argv0, MainAddr); + llvm::SmallString<128> NativeClangDocPath; + llvm::sys::path::native(ClangDocPath, NativeClangDocPath); + + llvm::SmallString<128> AssetsPath; + AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath); + llvm::sys::path::append(AssetsPath, "..", "share", "clang"); + llvm::SmallString<128> DefaultStylesheet; + llvm::sys::path::native(AssetsPath, DefaultStylesheet); + llvm::sys::path::append(DefaultStylesheet, + "clang-doc-default-stylesheet.css"); + llvm::SmallString<128> IndexJS; + llvm::sys::path::native(AssetsPath, IndexJS); + llvm::sys::path::append(IndexJS, "index.js"); + + llvm::outs() << "Using default asset: " << AssetsPath << "\n"; + + if (!llvm::sys::fs::is_regular_file(IndexJS)) +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "default index.js file missing at " + + IndexJS + "\n"); + + if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) +return llvm::createStringError( +llvm::inconvertibleErrorCode(), +"default clang-doc-default-stylesheet.css file missing at " + +DefaultStylesheet + "\n"); + + CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), + std::string(DefaultStylesheet)); + CDCtx.FilesToCopy.emplace_back(IndexJS.str()); + + return llvm::Error::success(); +} + +llvm::Error getHtmlAssetFiles(const char *Argv0, + clang::doc::ClangDocContext &CDCtx) { + if (!UserAssetPath.empty() && + !llvm::sys::fs::is_directory(std::string(UserAssetPath))) +llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath + << " falling back to default\n"; + if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) +return getAssetFiles(CDCtx); + return getDefaultAssetFiles(Argv0, CDCt
[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
ilovepi wrote: @nico Actually, I probably shouldn't have reverted. It seems like your GN build is incorrect, and isn't copying the asset files into the right place. The patch that updated that landed in https://github.com/llvm/llvm-project/pull/95187. @PeterChou1 is going to add you as a reviewer on the reland in question, but I think the existing premerge and post-submit bots are sufficient to show that this isn't something affecting the CMake build. https://github.com/llvm/llvm-project/pull/94717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ParserHLSL] Attempt to parse HLSL annotations on Field Decls. (PR #96346)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/96346 >From c267be670adf7aac050484dc1b243aa0eff60b5f Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 21 Jun 2024 11:25:22 -0700 Subject: [PATCH 1/4] parse hlsl annotations on struct, add test --- clang/lib/Parse/ParseDeclCXX.cpp | 3 ++ .../hlsl_annotations_on_struct_members.hlsl | 30 +++ 2 files changed, 33 insertions(+) create mode 100644 clang/test/ParserHLSL/hlsl_annotations_on_struct_members.hlsl diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index d02548f6441f9..c4a4657cbd04f 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2646,6 +2646,9 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( else DeclaratorInfo.SetIdentifier(nullptr, Tok.getLocation()); + if (getLangOpts().HLSL) +MaybeParseHLSLAnnotations(DeclaratorInfo); + if (!DeclaratorInfo.isFunctionDeclarator() && TryConsumeToken(tok::colon)) { assert(DeclaratorInfo.isPastIdentifier() && "don't know where identifier would go yet?"); diff --git a/clang/test/ParserHLSL/hlsl_annotations_on_struct_members.hlsl b/clang/test/ParserHLSL/hlsl_annotations_on_struct_members.hlsl new file mode 100644 index 0..f1e258b0d853c --- /dev/null +++ b/clang/test/ParserHLSL/hlsl_annotations_on_struct_members.hlsl @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - %s -verify + +// previously, this test would result in an error shown below on the line that +// declares variable a in struct Eg9: +// error: use of undeclared identifier +// 'SV_DispatchThreadID' +// This is because the annotation is parsed as if it was a c++ bit field, and an identifier +// that represents an integer is expected, but not found. + +// This test ensures that hlsl annotations are attempted to be parsed when parsing struct decls. +// Ideally, we'd validate this behavior by ensuring the annotation is parsed and properly +// attached as an attribute to the member in the struct in the AST. However, in this case +// this can't happen presently because there are other issues with annotations on field decls. +// This test just ensures we make progress by moving the validation error from the realm of +// C++ and expecting bitfields, to HLSL and a specialized error for the recognized annotation. + +struct Eg9{ +// expected-error@+1{{attribute 'SV_DispatchThreadID' only applies to parameter}} + int a : SV_DispatchThreadID; +}; +Eg9 e9; + + +RWBuffer In : register(u1); + + +[numthreads(1,1,1)] +void main() { + In[0] = e9.a; +} >From 5c98dd990b938258bd94057220c61e85c1333e85 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 21 Jun 2024 12:37:21 -0700 Subject: [PATCH 2/4] unconsume colon if bitfield detected, add bitfield test --- clang/include/clang/Parse/Parser.h | 8 +--- clang/lib/Parse/ParseDeclCXX.cpp | 3 ++- clang/lib/Parse/ParseHLSL.cpp | 8 +++- clang/test/ParserHLSL/bitfields.hlsl | 18 ++ .../hlsl_annotations_on_struct_members.hlsl| 14 +- 5 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 clang/test/ParserHLSL/bitfields.hlsl diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 95c0655f9a214..dc154c93a3b44 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -3017,11 +3017,12 @@ class Parser : public CodeCompletionHandler { const IdentifierInfo *EnclosingScope = nullptr); void MaybeParseHLSLAnnotations(Declarator &D, - SourceLocation *EndLoc = nullptr) { + SourceLocation *EndLoc = nullptr, + bool CouldBeBitField = false) { assert(getLangOpts().HLSL && "MaybeParseHLSLAnnotations is for HLSL only"); if (Tok.is(tok::colon)) { ParsedAttributes Attrs(AttrFactory); - ParseHLSLAnnotations(Attrs, EndLoc); + ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField); D.takeAttributes(Attrs); } } @@ -3034,7 +3035,8 @@ class Parser : public CodeCompletionHandler { } void ParseHLSLAnnotations(ParsedAttributes &Attrs, -SourceLocation *EndLoc = nullptr); +SourceLocation *EndLoc = nullptr, +bool CouldBeBitField = false); Decl *ParseHLSLBuffer(SourceLocation &DeclEnd); void MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) { diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index c4a4657cbd04f..461dbb2743c76 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2647,7 +2647,8 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( DeclaratorInfo.SetIdentifier(nullptr, Tok.getLocation()
[clang] [ParserHLSL] Attempt to parse HLSL annotations on Field Decls. (PR #96346)
@@ -2646,6 +2646,9 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( else DeclaratorInfo.SetIdentifier(nullptr, Tok.getLocation()); + if (getLangOpts().HLSL) bob80905 wrote: Though both would hit an assert if they're called outside of HLSL mode, I do believe that one overload has a redundant check for HLSL mode, I'll remove that. https://github.com/llvm/llvm-project/pull/96346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ParserHLSL] Attempt to parse HLSL annotations on Field Decls. (PR #96346)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/96346 >From c267be670adf7aac050484dc1b243aa0eff60b5f Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 21 Jun 2024 11:25:22 -0700 Subject: [PATCH 1/3] parse hlsl annotations on struct, add test --- clang/lib/Parse/ParseDeclCXX.cpp | 3 ++ .../hlsl_annotations_on_struct_members.hlsl | 30 +++ 2 files changed, 33 insertions(+) create mode 100644 clang/test/ParserHLSL/hlsl_annotations_on_struct_members.hlsl diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index d02548f6441f9..c4a4657cbd04f 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2646,6 +2646,9 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( else DeclaratorInfo.SetIdentifier(nullptr, Tok.getLocation()); + if (getLangOpts().HLSL) +MaybeParseHLSLAnnotations(DeclaratorInfo); + if (!DeclaratorInfo.isFunctionDeclarator() && TryConsumeToken(tok::colon)) { assert(DeclaratorInfo.isPastIdentifier() && "don't know where identifier would go yet?"); diff --git a/clang/test/ParserHLSL/hlsl_annotations_on_struct_members.hlsl b/clang/test/ParserHLSL/hlsl_annotations_on_struct_members.hlsl new file mode 100644 index 0..f1e258b0d853c --- /dev/null +++ b/clang/test/ParserHLSL/hlsl_annotations_on_struct_members.hlsl @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - %s -verify + +// previously, this test would result in an error shown below on the line that +// declares variable a in struct Eg9: +// error: use of undeclared identifier +// 'SV_DispatchThreadID' +// This is because the annotation is parsed as if it was a c++ bit field, and an identifier +// that represents an integer is expected, but not found. + +// This test ensures that hlsl annotations are attempted to be parsed when parsing struct decls. +// Ideally, we'd validate this behavior by ensuring the annotation is parsed and properly +// attached as an attribute to the member in the struct in the AST. However, in this case +// this can't happen presently because there are other issues with annotations on field decls. +// This test just ensures we make progress by moving the validation error from the realm of +// C++ and expecting bitfields, to HLSL and a specialized error for the recognized annotation. + +struct Eg9{ +// expected-error@+1{{attribute 'SV_DispatchThreadID' only applies to parameter}} + int a : SV_DispatchThreadID; +}; +Eg9 e9; + + +RWBuffer In : register(u1); + + +[numthreads(1,1,1)] +void main() { + In[0] = e9.a; +} >From 5c98dd990b938258bd94057220c61e85c1333e85 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Fri, 21 Jun 2024 12:37:21 -0700 Subject: [PATCH 2/3] unconsume colon if bitfield detected, add bitfield test --- clang/include/clang/Parse/Parser.h | 8 +--- clang/lib/Parse/ParseDeclCXX.cpp | 3 ++- clang/lib/Parse/ParseHLSL.cpp | 8 +++- clang/test/ParserHLSL/bitfields.hlsl | 18 ++ .../hlsl_annotations_on_struct_members.hlsl| 14 +- 5 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 clang/test/ParserHLSL/bitfields.hlsl diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 95c0655f9a214..dc154c93a3b44 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -3017,11 +3017,12 @@ class Parser : public CodeCompletionHandler { const IdentifierInfo *EnclosingScope = nullptr); void MaybeParseHLSLAnnotations(Declarator &D, - SourceLocation *EndLoc = nullptr) { + SourceLocation *EndLoc = nullptr, + bool CouldBeBitField = false) { assert(getLangOpts().HLSL && "MaybeParseHLSLAnnotations is for HLSL only"); if (Tok.is(tok::colon)) { ParsedAttributes Attrs(AttrFactory); - ParseHLSLAnnotations(Attrs, EndLoc); + ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField); D.takeAttributes(Attrs); } } @@ -3034,7 +3035,8 @@ class Parser : public CodeCompletionHandler { } void ParseHLSLAnnotations(ParsedAttributes &Attrs, -SourceLocation *EndLoc = nullptr); +SourceLocation *EndLoc = nullptr, +bool CouldBeBitField = false); Decl *ParseHLSLBuffer(SourceLocation &DeclEnd); void MaybeParseMicrosoftAttributes(ParsedAttributes &Attrs) { diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index c4a4657cbd04f..461dbb2743c76 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2647,7 +2647,8 @@ bool Parser::ParseCXXMemberDeclaratorBeforeInitializer( DeclaratorInfo.SetIdentifier(nullptr, Tok.getLocation()
[clang] [llvm] [llvm][AArch64] Move Apple aliases into the CpuAlias map (PR #96249)
jroelofs wrote: > Can all the cpu aliases work in the same way? Or do you want them to work > different, where they are not just frontend aliases? I hadn't noticed that mechanism. There were some holes that needed to be addressed, but after fixing them, this does look like a better way to handle them. https://github.com/llvm/llvm-project/pull/96249 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Replace `emitXXXBuiltin` with a unified interface (PR #96313)
https://github.com/shiltian closed https://github.com/llvm/llvm-project/pull/96313 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e52016a - [Clang] Replace `emitXXXBuiltin` with a unified interface (#96313)
Author: Shilei Tian Date: 2024-06-21T16:35:53-04:00 New Revision: e52016a2361a35773e8c1ad969b4b33a2b30d018 URL: https://github.com/llvm/llvm-project/commit/e52016a2361a35773e8c1ad969b4b33a2b30d018 DIFF: https://github.com/llvm/llvm-project/commit/e52016a2361a35773e8c1ad969b4b33a2b30d018.diff LOG: [Clang] Replace `emitXXXBuiltin` with a unified interface (#96313) Added: Modified: clang/lib/CodeGen/CGBuiltin.cpp Removed: diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index d11e7a95d833d..dc09f8972dd15 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -581,49 +581,19 @@ static Value *emitCallMaybeConstrainedFPBuiltin(CodeGenFunction &CGF, return CGF.Builder.CreateCall(F, Args); } -// Emit a simple mangled intrinsic that has 1 argument and a return type -// matching the argument type. -static Value *emitUnaryBuiltin(CodeGenFunction &CGF, const CallExpr *E, - unsigned IntrinsicID, - llvm::StringRef Name = "") { - llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); - - Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); - return CGF.Builder.CreateCall(F, Src0, Name); -} - -// Emit an intrinsic that has 2 operands of the same type as its result. -static Value *emitBinaryBuiltin(CodeGenFunction &CGF, -const CallExpr *E, -unsigned IntrinsicID) { - llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); - llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); - - Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); - return CGF.Builder.CreateCall(F, { Src0, Src1 }); -} - -// Emit an intrinsic that has 3 operands of the same type as its result. -static Value *emitTernaryBuiltin(CodeGenFunction &CGF, - const CallExpr *E, - unsigned IntrinsicID) { - llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); - llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); - llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2)); - - Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); - return CGF.Builder.CreateCall(F, { Src0, Src1, Src2 }); -} - -static Value *emitQuaternaryBuiltin(CodeGenFunction &CGF, const CallExpr *E, -unsigned IntrinsicID) { - llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); - llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); - llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2)); - llvm::Value *Src3 = CGF.EmitScalarExpr(E->getArg(3)); - - Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); - return CGF.Builder.CreateCall(F, {Src0, Src1, Src2, Src3}); +// Emit a simple intrinsic that has N scalar arguments and a return type +// matching the argument type. It is assumed that only the first argument is +// overloaded. +template +Value *emitBuiltinWithOneOverloadedType(CodeGenFunction &CGF, const CallExpr *E, +unsigned IntrinsicID, +llvm::StringRef Name = "") { + static_assert(N, "expect non-empty argument"); + SmallVector Args; + for (unsigned I = 0; I < N; ++I) +Args.push_back(CGF.EmitScalarExpr(E->getArg(I))); + Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Args[0]->getType()); + return CGF.Builder.CreateCall(F, Args, Name); } // Emit an intrinsic that has 1 float or double operand, and 1 integer. @@ -2689,7 +2659,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_copysignf16: case Builtin::BI__builtin_copysignl: case Builtin::BI__builtin_copysignf128: - return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::copysign)); + return RValue::get( + emitBuiltinWithOneOverloadedType<2>(*this, E, Intrinsic::copysign)); case Builtin::BIcos: case Builtin::BIcosf: @@ -2734,7 +2705,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, // TODO: strictfp support if (Builder.getIsFPConstrained()) break; - return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::exp10)); + return RValue::get( + emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::exp10)); } case Builtin::BIfabs: case Builtin::BIfabsf: @@ -2744,7 +2716,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fabsf16: case Builtin::BI__builtin_fabsl: case Builtin::BI__builtin_fabsf128: - return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::fabs)); + return RValue::get( + emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::fabs)); case Builtin::BIfloor: case Builtin::BIfloorf: @@
[clang] [clang][ThreadSafety] Check trylock function success and return types (PR #95290)
https://github.com/dmcardle updated https://github.com/llvm/llvm-project/pull/95290 >From 66715ea5566946f0608d77dc4c86b23e70179760 Mon Sep 17 00:00:00 2001 From: Dan McArdle Date: Thu, 20 Jun 2024 17:43:16 -0400 Subject: [PATCH] [clang][ThreadSafety] Check trylock function success and return types With this change, Clang will generate errors when trylock functions have improper return types. Today, it silently fails to apply the trylock attribute to these functions which may incorrectly lead users to believe they have correctly acquired locks before accessing guarded data. As a side effect of explicitly checking the success argument type, I seem to have fixed a false negative in the analysis that occurred when a trylock's success argument is negative. I've added a regression test to warn-thread-safety-analysis.cpp named `TrylockSuccessEnumFalseNegative`. This change also improves the documentation with descriptions of of the subtle gotchas that arise from the analysis interpreting the success arg as a boolean. Issue #92408 --- clang/docs/ReleaseNotes.rst | 10 ++ clang/docs/ThreadSafetyAnalysis.rst | 52 +++- .../clang/Basic/DiagnosticSemaKinds.td| 23 +++- clang/include/clang/Sema/ParsedAttr.h | 2 + clang/lib/Analysis/ThreadSafety.cpp | 82 +++- clang/lib/Sema/SemaDeclAttr.cpp | 34 +++-- clang/test/Sema/attr-capabilities.c | 12 +- .../SemaCXX/warn-thread-safety-analysis.cpp | 123 +- .../SemaCXX/warn-thread-safety-parsing.cpp| 107 --- clang/unittests/AST/ASTImporterTest.cpp | 6 +- 10 files changed, 369 insertions(+), 82 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7ac0fa0141b47..28ec3d54a5a77 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -71,6 +71,11 @@ C++ Specific Potentially Breaking Changes To fix this, update libstdc++ to version 14.1.1 or greater. +- Clang now emits errors when Thread Safety Analysis trylock attributes are + applied to functions or methods with incompatible return values, such as + constructors, destructors, and void-returning functions. This only affects the + ``TRY_ACQUIRE`` and ``TRY_ACQUIRE_SHARED`` attributes (and any synonyms). + ABI Changes in This Version --- - Fixed Microsoft name mangling of implicitly defined variables used for thread @@ -720,6 +725,11 @@ Bug Fixes in This Version - Fixed `static_cast` to array of unknown bound. Fixes (#GH62863). +- Clang's Thread Safety Analysis now evaluates trylock success arguments of enum + types rather than silently defaulting to false. This fixes a class of false + negatives where the analysis failed to detect unchecked access to guarded + data. + Bug Fixes to Compiler Builtins ^^ diff --git a/clang/docs/ThreadSafetyAnalysis.rst b/clang/docs/ThreadSafetyAnalysis.rst index dcde0c706c704..0ecbebe7a692f 100644 --- a/clang/docs/ThreadSafetyAnalysis.rst +++ b/clang/docs/ThreadSafetyAnalysis.rst @@ -420,10 +420,17 @@ TRY_ACQUIRE(, ...), TRY_ACQUIRE_SHARED(, ...) *Previously:* ``EXCLUSIVE_TRYLOCK_FUNCTION``, ``SHARED_TRYLOCK_FUNCTION`` These are attributes on a function or method that tries to acquire the given -capability, and returns a boolean value indicating success or failure. -The first argument must be ``true`` or ``false``, to specify which return value -indicates success, and the remaining arguments are interpreted in the same way -as ``ACQUIRE``. See :ref:`mutexheader`, below, for example uses. +capability, and returns a boolean, integer, or pointer value indicating success +or failure. + +The attribute's first argument defines whether a zero or non-zero return value +indicates success. Syntactically, it accepts ``NULL`` or ``nullptr``, ``bool`` +and ``int`` literals, as well as enumerator values. *The analysis only cares +whether this success value is zero or non-zero.* This leads to some subtle +consequences, discussed in the next section. + +The remaining arguments are interpreted in the same way as ``ACQUIRE``. See +:ref:`mutexheader`, below, for example uses. Because the analysis doesn't support conditional locking, a capability is treated as acquired after the first branch on the return value of a try-acquire @@ -445,6 +452,43 @@ function. } } +Subtle Consequences of Non-Boolean Success Values +^ + +The trylock attributes accept non-boolean expressions for the success value, but +the analysis only cares whether the value is zero or non-zero. + +Suppose you define an enum with two non-zero enumerators: ``LockAcquired = 1`` +and ``LockNotAcquired = 2``. If your trylock function returns ``LockAcquired`` +on success and ``LockNotAcquired`` on failure, the analysis may fail to detect +access to guarded data without holding the mutex because they are bot
[clang] [llvm] [llvm][AArch64] Move Apple aliases into the CpuAlias map (PR #96249)
https://github.com/jroelofs edited https://github.com/llvm/llvm-project/pull/96249 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][AArch64] Move Apple aliases into the CpuAlias map (PR #96249)
https://github.com/jroelofs edited https://github.com/llvm/llvm-project/pull/96249 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ThreadSafety] Check trylock function success and return types (PR #95290)
dmcardle wrote: So... I appear to have accidentally fixed a bug. Looks like enum success values were not being evaluated, and defaulted to false. As a result, the analysis could fail to detect unguarded access [[demo on godbolt.org](https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGIAMwA7KSuADJ4DJgAcj4ARpjEIABsAKykAA6oCoRODB7evgHBmdmOAuGRMSzxiam2mPZlDEIETMQE%2BT5%2BQfWNuS1tBBXRcQnJaQqt7Z2FPZODw1U14wCUtqhexMjsHAD0uwDUALJMyMRZB0QHjEyx9JeYkxHAB6hUB7GoBAgHAG5teEMBAUr3e30wlwQxEwTHQBwUTComAIAE8DoYxCjsgoAHQmDQAQXxRLM/jw7zkQmwAH03ATlASLABJUJMgAqAE1ieZ/FgaJEDqEAPJuADSjNC2AO0plsrl8pl1OpTAIBGIeFiXgImCVUFE6VudEIKIg5jMLC1mFUZpWtu5pL5EQhBKEVIASmzqdgABpuUKUpkANRpwrFEBxEZW8qVKrVGstuogTAUSna1P1htoxogSsDBOpBLdAHEhErbSt7bzMPzna7sB7qUIABKF7AAEWpodF4cjCulMdV6s12sTydTBGpCgQbUw6HTTANsSNqJz1LzBeLpep5crjoFPr9AeDnZFoupADE5FE3GymUKoj2cVHFcrB/GR9SoKcAI5ePDQ%2BdF2XE1c3zQsSzLO1CR5PcIWbVsOy7C8rxvO8HwjJ8FQHONhx1T8k2QX9/x1KcZznDMlyzFdQI3CDtygkkqxrA4ryQy9r1ve9H2fPt%2B1fHCE3w6F6GTHVgEYBI8GQQDM2zGjwK3HdoIdasnQOA9/SEIMaTZN0OTYlDOPQ3tsKHQSoDVFFlUIv8AIo4DV3XBTIIrZSmLU%2BC3XbaldP009kI4tDuNlUz3zwiziCsn9bJI6doXIhdZOotcwM3Fzd1U/dfU07STzFUsvIARTkJkvLbYK%2BNjMyPygaEiOhBQZMouSUtoxSGJgzK4JbMq8tFArsGK0r2wqkL%2BOq8KIDqmLGtI%2BKmoc%2BS0vo1zGIaJQMuYrsJSlXi9rGqqwsTWhUGQABrW56A6lTmJdd1PQ0o8Q1PUaX0O3DRxTBIJytZBvGyX4dRO87HNSuilMY2CDju%2BtPU87yu1euVQo%2B/Cx2%2Byc4tnalgbO0G2vStyocerTjwMwKuIwniDhR8yIF%2B/68EBnHTrO6kqC8BgHFyfHnJWzaPJ6hH/PY1DKd7aNxqO/C5ux3H2c57mBF55aIc65jWJFwygqp/aaal1GoE5%2BWOa5poVfB673Kyw9SZ0vTybF4zMNpmr6dUP6vABnVLJNxXzaWy3VvVwWEJ8h2tYp53qddybZbnX3WYVs2ecD9rg5utSSdyrsBqGsrRtjxMGa9pmgdZxrpuI9ALfTgWBXhxDTzzkqC915GDbp%2BOWfOyvMHq2da8JtaGHwKhuUJfZBVZ%2BFMBYIEpJBARaBReuISLORCzbby8zdPXeKL/DgC8NosDnf5iCtqHlE9Det53wt947966fSCdj9P7GL46yfDjcRLmqOEeK8BgK817qWyk9akmsxQBSdhVQ%2BtUGgwiUAtKiIFWp8zVpnBuQsOwwLPKLIySNEFTWQaJTGZE0EtScqrK%2BXUDh3zdNvDsFgOQQFUNTJ%2B%2BsX5uw/sQM%2B1JYgmk4fQ5iN9qRMJYdSNhHCuH7VIW/ak/DBHCLkT/AkU8PAsBYAIcBQg3BCmUMLMUO1uGVTfIbCACg0DpDlqzS6mAxFqQJG4fO3kCTnjZPWJGfZSHRWrsqKg2piBD35kTBhrj3GsOwOeIUXlfGS14ZNAJ814j8GhGE7B1sIRIS8myOQboogjU4eY0h8toQEE2JEGuoiM45MFM3L0kCWGJKSZYumuNGolzPlk5xAoohCh8k2LyBIOxCE8dgTkBYogElCByLSQgsKdzdgwVA1JvjQlhJOREyIorMBXtiDRU83SYGAA1bIAgHiTAOBky4kVcbog6dqEEAB3QgPxDDXAYD4BIKoSDwi8MgbYKZ0TEGPmwQQeJf4HGUOqAFgNiCXIYEvMECAIQYkOXgEE2R6CCBXrcpgdBZyXFQNcf43gVQQgUECkFII2gQsYMCYkU9vgqgOK8hIEJIgfISAcEwSQNBuG9N6CwqBPDhBCWIbAqh0jEAFRoA4aziD8sFUyQQZyEiSr%2BbQBV6JR7ohTL8uE4IWWHApV4CErzkyEtoEoaFBJmBsAUAabYBw2QPNZkIWljwFDYB%2BSwc8YglBRDOSqMu/LAhWGgoSRgPh3WevOqcmltACCRosAcINdBNgQhMP4NsBwNCkAON64Fvr%2BX5oOFwSNbY83RqJISP6Y5GmmIsJKY4lpVDpuJOkLwdwpIgGJNKD1KJcbJq8KmhNKJQiswgFGbOx5fKO2IaWulFZ/D1ulL8VAeA4RyFAbO%2BdkC7bQKiMuoK6760mECLWjdE8CRNtBSO3GbJHhpuvZujt2ou0WmpHWodBwIhpqYNSRhm9mHeVkb%2BqMeaC0aH/TGgkW6d0mrfUI8VtBqRWjlb6nmMGo0AelOSA4EAwBgF/TiEdM6Qa2nTdKKeUQvgQnBIBhgiLtRwliMQQwyAfhoFHjkAQDr5QgesGJjd5ip5sgQNi%2BECANi0E4xCKgBhgDiU42iFj0mtlwiELs1E0MDlYmxWRwjMoKP7txnOhDSGZTXtrYSaU9nuQ3ps/Zg4U8nWPFdRCZ9XqfUpn9T4INdrohhscIDDgaxaCcBSLwPw3BeCoE4G4MTlh4QbC2Lm0kPBSAEE0FFtYZ0Aj%2BBxP4crFXKuVaSPoTgkh4sFdIMljgvAFAgCLfljgWg1hwFgEgNALB0jErIBQCAA2hv0ESE2owGziCczOnwOgIS2sQFiI1pczBIqcFyxttoKIhSxG0JgBw23eADchQQIUoCUSNawJqYA/9aB2tO6QLA88jDiC67wfA0JuaAza19kIqhjuWhe0BhojWsxcb2x4LAjW4wsBe4iz4Sg2xz0MMALMRgCtrBU0wYAChAx4EwK8oUdiEu5f4IIEQYh2BSBkIIRQKh1CA90FwfQGOUBpZsFDtrkA1ioDfrkAHABaSY6BYOmEsNYLg1aRcAHUEjnHlfmzZMJ0Bi/02iEXbZKQ0jpAyZkrJOSwdy6gRF6osB87nb0Y7TQXCjxmH4dnYQnRLDGOzkogm8ieC6HoL3TRFijESOzuwdv%2BhTA6L7woofkFK2aJHoP1QPe2Ej07vQ8x2hJ%2BWFwNYChMvbAkNF2LDXAfNYOKoAAHEkEXSRJAHGmy8CAap5tRggLgQgAKeS594J17rax0WwjGDb4r5WytVYn%2BVmrMWOD1dIAlrQTXOCtfa3lnHpBeuIBABsAgvaCDkEoON4bURWA7CrzXuvDeDBGBIy3hgZ0Vi8FnJ3y3egqfCFEOIen7%2BmdqEa2z0gV5bjdIU7YvDgOLefRrZrIULUPfUECvavWvevRvW/Obe/NvbRCbPlbvR/NfL7W0UgUfUrSfSfWrWfUvRfZrFfDrHHMAswCgpLZfPA/vUgRFZFEASQIAA%3D%3D%3D)]. I think that the old `isIntOrBool()` function accidentally let enumerator values through, but the analysis assumed it would only ever see `CXXBoolLiteralExpr ` or `IntegerLiteral `. I'm adding a regression test that closely resembles the demo, but verifies that the analysis actually detects the unguarded access. I also realized I was supposed to update the release notes. New patch with these changes coming momentarily. https://github.com/llvm/llvm-project/pull/95290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][AArch64][TableGen] Create a ProcessorAlias record. NFC (PR #96249)
https://github.com/jroelofs updated https://github.com/llvm/llvm-project/pull/96249 >From ee1389a36aac9eecf00513d98cc99787b2cfe17a Mon Sep 17 00:00:00 2001 From: Jon Roelofs Date: Thu, 20 Jun 2024 16:26:45 -0700 Subject: [PATCH 1/3] [llvm][AArch64][TableGen] Create a ProcessorAlias record. NFC ... and use it to organize all of the Apple CPU aliases. --- llvm/lib/Target/AArch64/AArch64Processors.td | 35 +--- llvm/utils/TableGen/ARMTargetDefEmitter.cpp | 25 -- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64Processors.td b/llvm/lib/Target/AArch64/AArch64Processors.td index 53b46ff42b72f..46f665cb15a9a 100644 --- a/llvm/lib/Target/AArch64/AArch64Processors.td +++ b/llvm/lib/Target/AArch64/AArch64Processors.td @@ -930,6 +930,12 @@ def ProcessorFeatures { list Generic = [FeatureFPARMv8, FeatureNEON, FeatureETE]; } +// Define an alternative name for a given Processor. +class ProcessorAlias { + string Name = n; + string Alias = alias; +} + // FeatureFuseAdrpAdd is enabled under Generic to allow linker merging // optimizations. def : ProcessorModel<"generic", CortexA510Model, ProcessorFeatures.Generic, @@ -1050,15 +1056,12 @@ def : ProcessorModel<"tsv110", TSV110Model, ProcessorFeatures.TSV110, // Apple CPUs -// Support cyclone as an alias for apple-a7 so we can still LTO old bitcode. -def : ProcessorModel<"cyclone", CycloneModel, ProcessorFeatures.AppleA7, - [TuneAppleA7]>; def : ProcessorModel<"apple-a7", CycloneModel, ProcessorFeatures.AppleA7, [TuneAppleA7]>; -def : ProcessorModel<"apple-a8", CycloneModel, ProcessorFeatures.AppleA7, - [TuneAppleA7]>; -def : ProcessorModel<"apple-a9", CycloneModel, ProcessorFeatures.AppleA7, - [TuneAppleA7]>; +// Support cyclone as an alias for apple-a7 so we can still LTO old bitcode. +def : ProcessorAlias<"cyclone", "apple-a7">; +def : ProcessorAlias<"apple-a8", "apple-a7">; +def : ProcessorAlias<"apple-a9", "apple-a7">; def : ProcessorModel<"apple-a10", CycloneModel, ProcessorFeatures.AppleA10, [TuneAppleA10]>; @@ -1068,28 +1071,23 @@ def : ProcessorModel<"apple-a11", CycloneModel, ProcessorFeatures.AppleA11, def : ProcessorModel<"apple-a12", CycloneModel, ProcessorFeatures.AppleA12, [TuneAppleA12]>; -def : ProcessorModel<"apple-s4", CycloneModel, ProcessorFeatures.AppleA12, - [TuneAppleA12]>; -def : ProcessorModel<"apple-s5", CycloneModel, ProcessorFeatures.AppleA12, - [TuneAppleA12]>; +def : ProcessorAlias<"apple-s4", "apple-a12">; +def : ProcessorAlias<"apple-s5", "apple-a12">; def : ProcessorModel<"apple-a13", CycloneModel, ProcessorFeatures.AppleA13, [TuneAppleA13]>; def : ProcessorModel<"apple-a14", CycloneModel, ProcessorFeatures.AppleA14, [TuneAppleA14]>; -def : ProcessorModel<"apple-m1", CycloneModel, ProcessorFeatures.AppleA14, - [TuneAppleA14]>; +def : ProcessorAlias<"apple-m1", "apple-a14">; def : ProcessorModel<"apple-a15", CycloneModel, ProcessorFeatures.AppleA15, [TuneAppleA15]>; -def : ProcessorModel<"apple-m2", CycloneModel, ProcessorFeatures.AppleA15, - [TuneAppleA15]>; +def : ProcessorAlias<"apple-m2", "apple-a15">; def : ProcessorModel<"apple-a16", CycloneModel, ProcessorFeatures.AppleA16, [TuneAppleA16]>; -def : ProcessorModel<"apple-m3", CycloneModel, ProcessorFeatures.AppleA16, - [TuneAppleA16]>; +def : ProcessorAlias<"apple-m3", "apple-a16">; def : ProcessorModel<"apple-a17", CycloneModel, ProcessorFeatures.AppleA17, [TuneAppleA17]>; @@ -1098,8 +1096,7 @@ def : ProcessorModel<"apple-m4", CycloneModel, ProcessorFeatures.AppleM4, [TuneAppleM4]>; // Alias for the latest Apple processor model supported by LLVM. -def : ProcessorModel<"apple-latest", CycloneModel, ProcessorFeatures.AppleM4, - [TuneAppleM4]>; +def : ProcessorAlias<"apple-latest", "apple-m4">; // Fujitsu A64FX diff --git a/llvm/utils/TableGen/ARMTargetDefEmitter.cpp b/llvm/utils/TableGen/ARMTargetDefEmitter.cpp index e22f353b451f9..3e111813280a3 100644 --- a/llvm/utils/TableGen/ARMTargetDefEmitter.cpp +++ b/llvm/utils/TableGen/ARMTargetDefEmitter.cpp @@ -221,8 +221,28 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) { OS << "#ifdef EMIT_CPU_INFO\n" << "inline constexpr CpuInfo CpuInfos[] = {\n"; + std::map> ProcessorModels; for (const Record *Rec : RK.getAllDerivedDefinitions("ProcessorModel")) { auto Name = Rec->getValueAsString("Name"); +ProcessorModels.insert(std::make_pair(Name, std::make_pair(Name, Rec))); + } + + for (const Record *Rec : RK.getAllDerivedDefinitions("ProcessorAlias")) { +std::string Name = Rec->getValueAsString("Name
[clang] [clang][modules] Fix use-after-free in header serialization (PR #96356)
llvmbot wrote: @llvm/pr-subscribers-clang-modules Author: Jan Svoboda (jansvoboda11) Changes With the pruning of unused module map files disabled (`-fno-modules-prune-non-affecting-module-map-files`), `HeaderFileInfo` no longer gets deserialized before `ASTWriter::WriteHeaderSearch()`. This function then interleaves the stores of references to `KnownHeader` with their lazy deserialization. Lazy deserialization may cause reallocation of `ModuleMap::Headers` entries (including its `SmallVector` values) thus making previously-stored `ArrayRef ` dangling. This patch fixes that situation by storing a copy instead. --- Full diff: https://github.com/llvm/llvm-project/pull/96356.diff 2 Files Affected: - (modified) clang/lib/Serialization/ASTWriter.cpp (+8-2) - (added) clang/test/Modules/use-after-free-2.c (+180) ``diff diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index e6a58dcc61e3f..95b1165154c05 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1973,9 +1973,15 @@ namespace { llvm::PointerIntPair; struct data_type { - const HeaderFileInfo &HFI; + data_type(const HeaderFileInfo &HFI, bool AlreadyIncluded, +ArrayRef KnownHeaders, +UnresolvedModule Unresolved) + : HFI(HFI), AlreadyIncluded(AlreadyIncluded), +KnownHeaders(KnownHeaders), Unresolved(Unresolved) {} + + HeaderFileInfo HFI; bool AlreadyIncluded; - ArrayRef KnownHeaders; + SmallVector KnownHeaders; UnresolvedModule Unresolved; }; using data_type_ref = const data_type &; diff --git a/clang/test/Modules/use-after-free-2.c b/clang/test/Modules/use-after-free-2.c new file mode 100644 index 0..0c89c759bcb75 --- /dev/null +++ b/clang/test/Modules/use-after-free-2.c @@ -0,0 +1,180 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t + +//--- A.modulemap +module A { + header "A.h" + + textual header "A00.h" + textual header "A01.h" + textual header "A02.h" + textual header "A03.h" + textual header "A04.h" + textual header "A05.h" + textual header "A06.h" + textual header "A07.h" + textual header "A08.h" + textual header "A09.h" + + textual header "A10.h" + textual header "A11.h" + textual header "A12.h" + textual header "A13.h" + textual header "A14.h" + textual header "A15.h" + textual header "A16.h" + textual header "A17.h" + textual header "A18.h" + textual header "A19.h" + + textual header "A20.h" + textual header "A21.h" + textual header "A22.h" + textual header "A23.h" + textual header "A24.h" + textual header "A25.h" + textual header "A26.h" + textual header "A27.h" + textual header "A28.h" + textual header "A29.h" + + textual header "A30.h" + textual header "A31.h" + textual header "A32.h" + textual header "A33.h" + textual header "A34.h" + textual header "A35.h" + textual header "A36.h" + textual header "A37.h" + textual header "A38.h" + textual header "A39.h" + + textual header "A40.h" + textual header "A41.h" + textual header "A42.h" + textual header "A43.h" + textual header "A44.h" + textual header "A45.h" +} +//--- A.h + +//--- A00.h +//--- A01.h +//--- A02.h +//--- A03.h +//--- A04.h +//--- A05.h +//--- A06.h +//--- A07.h +//--- A08.h +//--- A09.h + +//--- A10.h +//--- A11.h +//--- A12.h +//--- A13.h +//--- A14.h +//--- A15.h +//--- A16.h +//--- A17.h +//--- A18.h +//--- A19.h + +//--- A20.h +//--- A21.h +//--- A22.h +//--- A23.h +//--- A24.h +//--- A25.h +//--- A26.h +//--- A27.h +//--- A28.h +//--- A29.h + +//--- A30.h +//--- A31.h +//--- A32.h +//--- A33.h +//--- A34.h +//--- A35.h +//--- A36.h +//--- A37.h +//--- A38.h +//--- A39.h + +//--- A40.h +//--- A41.h +//--- A42.h +//--- A43.h +//--- A44.h +//--- A45.h + +//--- B.modulemap +module B { header "B.h" } +//--- B.h +#include "A.h" + +//--- C.modulemap +module C { header "C.h" } +//--- C.h +#include "A00.h" +#include "A01.h" +#include "A02.h" +#include "A03.h" +#include "A04.h" +#include "A05.h" +#include "A06.h" +#include "A07.h" +#include "A08.h" +#include "A09.h" + +#include "A10.h" +#include "A11.h" +#include "A12.h" +#include "A13.h" +#include "A14.h" +#include "A15.h" +#include "A16.h" +#include "A17.h" +#include "A18.h" +#include "A19.h" + +#include "A20.h" +#include "A21.h" +#include "A22.h" +#include "A23.h" +#include "A24.h" +#include "A25.h" +#include "A26.h" +#include "A27.h" +#include "A28.h" +#include "A29.h" + +#include "A30.h" +#include "A31.h" +#include "A32.h" +#include "A33.h" +#include "A34.h" +#include "A35.h" +#include "A36.h" +#include "A37.h" +#include "A38.h" +#include "A39.h" + +#include "A40.h" +#include "A41.h" +#include "A42.h" +#include "A43.h" +#include "A44.h" +#include "A45.h" + +#include "B.h" + +// RUN: %clang_cc1 -fmodules -fno-modules-prune-non-affecting-module-map-files \ +// RUN: -emit-module %t/A.modulemap -fmodule-name=A -o %t/A
[clang] [clang][modules] Fix use-after-free in header serialization (PR #96356)
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/96356 With the pruning of unused module map files disabled (`-fno-modules-prune-non-affecting-module-map-files`), `HeaderFileInfo` no longer gets deserialized before `ASTWriter::WriteHeaderSearch()`. This function then interleaves the stores of references to `KnownHeader` with their lazy deserialization. Lazy deserialization may cause reallocation of `ModuleMap::Headers` entries (including its `SmallVector` values) thus making previously-stored `ArrayRef` dangling. This patch fixes that situation by storing a copy instead. >From 6cf30dcea3f70927916b37bc58cdbf255355e5ad Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Fri, 21 Jun 2024 13:28:01 -0700 Subject: [PATCH] [clang][modules] Fix use-after-free in header serialization With the pruning of unused module map files disabled (`-fno-modules-prune-non-affecting-module-map-files`), `HeaderFileInfo` no longer gets deserialized before `ASTWriter::WriteHeaderSearch()`. This function then interleaves the stores of references to `KnownHeader` with their lazy deserialization. Lazy deserialization may cause reallocation of `ModuleMap::Headers` entries (including its `SmallVector` values) thus making previously-stored `ArrayRef` dangling. This patch fixes that situation by storing a copy instead. --- clang/lib/Serialization/ASTWriter.cpp | 10 +- clang/test/Modules/use-after-free-2.c | 180 ++ 2 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 clang/test/Modules/use-after-free-2.c diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index e6a58dcc61e3f..95b1165154c05 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1973,9 +1973,15 @@ namespace { llvm::PointerIntPair; struct data_type { - const HeaderFileInfo &HFI; + data_type(const HeaderFileInfo &HFI, bool AlreadyIncluded, +ArrayRef KnownHeaders, +UnresolvedModule Unresolved) + : HFI(HFI), AlreadyIncluded(AlreadyIncluded), +KnownHeaders(KnownHeaders), Unresolved(Unresolved) {} + + HeaderFileInfo HFI; bool AlreadyIncluded; - ArrayRef KnownHeaders; + SmallVector KnownHeaders; UnresolvedModule Unresolved; }; using data_type_ref = const data_type &; diff --git a/clang/test/Modules/use-after-free-2.c b/clang/test/Modules/use-after-free-2.c new file mode 100644 index 0..0c89c759bcb75 --- /dev/null +++ b/clang/test/Modules/use-after-free-2.c @@ -0,0 +1,180 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t + +//--- A.modulemap +module A { + header "A.h" + + textual header "A00.h" + textual header "A01.h" + textual header "A02.h" + textual header "A03.h" + textual header "A04.h" + textual header "A05.h" + textual header "A06.h" + textual header "A07.h" + textual header "A08.h" + textual header "A09.h" + + textual header "A10.h" + textual header "A11.h" + textual header "A12.h" + textual header "A13.h" + textual header "A14.h" + textual header "A15.h" + textual header "A16.h" + textual header "A17.h" + textual header "A18.h" + textual header "A19.h" + + textual header "A20.h" + textual header "A21.h" + textual header "A22.h" + textual header "A23.h" + textual header "A24.h" + textual header "A25.h" + textual header "A26.h" + textual header "A27.h" + textual header "A28.h" + textual header "A29.h" + + textual header "A30.h" + textual header "A31.h" + textual header "A32.h" + textual header "A33.h" + textual header "A34.h" + textual header "A35.h" + textual header "A36.h" + textual header "A37.h" + textual header "A38.h" + textual header "A39.h" + + textual header "A40.h" + textual header "A41.h" + textual header "A42.h" + textual header "A43.h" + textual header "A44.h" + textual header "A45.h" +} +//--- A.h + +//--- A00.h +//--- A01.h +//--- A02.h +//--- A03.h +//--- A04.h +//--- A05.h +//--- A06.h +//--- A07.h +//--- A08.h +//--- A09.h + +//--- A10.h +//--- A11.h +//--- A12.h +//--- A13.h +//--- A14.h +//--- A15.h +//--- A16.h +//--- A17.h +//--- A18.h +//--- A19.h + +//--- A20.h +//--- A21.h +//--- A22.h +//--- A23.h +//--- A24.h +//--- A25.h +//--- A26.h +//--- A27.h +//--- A28.h +//--- A29.h + +//--- A30.h +//--- A31.h +//--- A32.h +//--- A33.h +//--- A34.h +//--- A35.h +//--- A36.h +//--- A37.h +//--- A38.h +//--- A39.h + +//--- A40.h +//--- A41.h +//--- A42.h +//--- A43.h +//--- A44.h +//--- A45.h + +//--- B.modulemap +module B { header "B.h" } +//--- B.h +#include "A.h" + +//--- C.modulemap +module C { header "C.h" } +//--- C.h +#include "A00.h" +#include "A01.h" +#include "A02.h" +#include "A03.h" +#include "A04.h" +#include "A05.h" +#include "A06.h" +#include "A07.h" +#include "A08.h" +#include "A09.h" + +#include "A10.h" +#include "A11.h" +#include "A12.h" +#include "A13.h" +#include "A14.h" +#include "A15.h"
[clang] [llvm] [clang][OpenMP] Shorten directive classification in ParseOpenMP (PR #94691)
kparzysz wrote: Ping. Anyone? https://github.com/llvm/llvm-project/pull/94691 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Add --asset option to clang-doc (PR #94717)
ilovepi wrote: > Looks Like this might break tests: http://45.33.8.238/linux/141118/step_7.txt > > Please take a look and revert for now if it takes a while to fix. Sorry for the late revert @nico. I'll have @PeterChou1 investigate before relanding. https://github.com/llvm/llvm-project/pull/94717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Revert "[clang-doc] Add --asset option to clang-doc" (PR #96354)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Paul Kirth (ilovepi) Changes Reverts llvm/llvm-project#94717 This breaks on some buildbots: http://45.33.8.238/linux/141118/step_7.txt --- Full diff: https://github.com/llvm/llvm-project/pull/96354.diff 2 Files Affected: - (modified) clang-tools-extra/clang-doc/tool/ClangDocMain.cpp (+19-81) - (removed) clang-tools-extra/test/clang-doc/single-source-html.cpp (-2) ``diff diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 5a43c70a5ebc3..5517522d7967d 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -81,12 +81,6 @@ static llvm::cl::list UserStylesheets( llvm::cl::desc("CSS stylesheets to extend the default styles."), llvm::cl::cat(ClangDocCategory)); -static llvm::cl::opt UserAssetPath( -"asset", -llvm::cl::desc("User supplied asset path to " - "override the default css and js files for html output"), -llvm::cl::cat(ClangDocCategory)); - static llvm::cl::opt SourceRoot("source-root", llvm::cl::desc(R"( Directory where processed files are stored. Links to definition locations will only be @@ -133,86 +127,16 @@ std::string getFormatString() { // GetMainExecutable (since some platforms don't support taking the // address of main, and some platforms can't implement GetMainExecutable // without being given the address of a function in the main executable). -std::string getExecutablePath(const char *Argv0, void *MainAddr) { +std::string GetExecutablePath(const char *Argv0, void *MainAddr) { return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } -llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) { - using DirIt = llvm::sys::fs::directory_iterator; - std::error_code FileErr; - llvm::SmallString<128> FilePath(UserAssetPath); - for (DirIt DirStart = DirIt(UserAssetPath, FileErr), - DirEnd; - !FileErr && DirStart != DirEnd; DirStart.increment(FileErr)) { -FilePath = DirStart->path(); -if (llvm::sys::fs::is_regular_file(FilePath)) { - if (llvm::sys::path::extension(FilePath) == ".css") -CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), - std::string(FilePath)); - else if (llvm::sys::path::extension(FilePath) == ".js") -CDCtx.FilesToCopy.emplace_back(FilePath.str()); -} - } - if (FileErr) -return llvm::createFileError(FilePath, FileErr); - return llvm::Error::success(); -} - -llvm::Error getDefaultAssetFiles(const char *Argv0, - clang::doc::ClangDocContext &CDCtx) { - void *MainAddr = (void *)(intptr_t)getExecutablePath; - std::string ClangDocPath = getExecutablePath(Argv0, MainAddr); - llvm::SmallString<128> NativeClangDocPath; - llvm::sys::path::native(ClangDocPath, NativeClangDocPath); - - llvm::SmallString<128> AssetsPath; - AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath); - llvm::sys::path::append(AssetsPath, "..", "share", "clang"); - llvm::SmallString<128> DefaultStylesheet; - llvm::sys::path::native(AssetsPath, DefaultStylesheet); - llvm::sys::path::append(DefaultStylesheet, - "clang-doc-default-stylesheet.css"); - llvm::SmallString<128> IndexJS; - llvm::sys::path::native(AssetsPath, IndexJS); - llvm::sys::path::append(IndexJS, "index.js"); - - llvm::outs() << "Using default asset: " << AssetsPath << "\n"; - - if (!llvm::sys::fs::is_regular_file(IndexJS)) -return llvm::createStringError(llvm::inconvertibleErrorCode(), - "default index.js file missing at " + - IndexJS + "\n"); - - if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) -return llvm::createStringError( -llvm::inconvertibleErrorCode(), -"default clang-doc-default-stylesheet.css file missing at " + -DefaultStylesheet + "\n"); - - CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), - std::string(DefaultStylesheet)); - CDCtx.FilesToCopy.emplace_back(IndexJS.str()); - - return llvm::Error::success(); -} - -llvm::Error getHtmlAssetFiles(const char *Argv0, - clang::doc::ClangDocContext &CDCtx) { - if (!UserAssetPath.empty() && - !llvm::sys::fs::is_directory(std::string(UserAssetPath))) -llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath - << " falling back to default\n"; - if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) -return getAssetFiles(CDCtx); - return getDefaultAssetFiles(Argv0, CDCtx); -} - int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); std::error_code OK; const char *Overview = - R"(Generates documentation from source code and comments. +R"(Gen
[clang-tools-extra] Revert "[clang-doc] Add --asset option to clang-doc" (PR #96354)
https://github.com/ilovepi closed https://github.com/llvm/llvm-project/pull/96354 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] bf824d9 - Revert "[clang-doc] Add --asset option to clang-doc" (#96354)
Author: Paul Kirth Date: 2024-06-21T13:18:37-07:00 New Revision: bf824d98c06099c50413cd6c957a75b894a8ac26 URL: https://github.com/llvm/llvm-project/commit/bf824d98c06099c50413cd6c957a75b894a8ac26 DIFF: https://github.com/llvm/llvm-project/commit/bf824d98c06099c50413cd6c957a75b894a8ac26.diff LOG: Revert "[clang-doc] Add --asset option to clang-doc" (#96354) Reverts llvm/llvm-project#94717 This breaks on some buildbots: http://45.33.8.238/linux/141118/step_7.txt Added: Modified: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp Removed: clang-tools-extra/test/clang-doc/single-source-html.cpp diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 5a43c70a5ebc3..5517522d7967d 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -81,12 +81,6 @@ static llvm::cl::list UserStylesheets( llvm::cl::desc("CSS stylesheets to extend the default styles."), llvm::cl::cat(ClangDocCategory)); -static llvm::cl::opt UserAssetPath( -"asset", -llvm::cl::desc("User supplied asset path to " - "override the default css and js files for html output"), -llvm::cl::cat(ClangDocCategory)); - static llvm::cl::opt SourceRoot("source-root", llvm::cl::desc(R"( Directory where processed files are stored. Links to definition locations will only be @@ -133,86 +127,16 @@ std::string getFormatString() { // GetMainExecutable (since some platforms don't support taking the // address of main, and some platforms can't implement GetMainExecutable // without being given the address of a function in the main executable). -std::string getExecutablePath(const char *Argv0, void *MainAddr) { +std::string GetExecutablePath(const char *Argv0, void *MainAddr) { return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } -llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) { - using DirIt = llvm::sys::fs::directory_iterator; - std::error_code FileErr; - llvm::SmallString<128> FilePath(UserAssetPath); - for (DirIt DirStart = DirIt(UserAssetPath, FileErr), - DirEnd; - !FileErr && DirStart != DirEnd; DirStart.increment(FileErr)) { -FilePath = DirStart->path(); -if (llvm::sys::fs::is_regular_file(FilePath)) { - if (llvm::sys::path::extension(FilePath) == ".css") -CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), - std::string(FilePath)); - else if (llvm::sys::path::extension(FilePath) == ".js") -CDCtx.FilesToCopy.emplace_back(FilePath.str()); -} - } - if (FileErr) -return llvm::createFileError(FilePath, FileErr); - return llvm::Error::success(); -} - -llvm::Error getDefaultAssetFiles(const char *Argv0, - clang::doc::ClangDocContext &CDCtx) { - void *MainAddr = (void *)(intptr_t)getExecutablePath; - std::string ClangDocPath = getExecutablePath(Argv0, MainAddr); - llvm::SmallString<128> NativeClangDocPath; - llvm::sys::path::native(ClangDocPath, NativeClangDocPath); - - llvm::SmallString<128> AssetsPath; - AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath); - llvm::sys::path::append(AssetsPath, "..", "share", "clang"); - llvm::SmallString<128> DefaultStylesheet; - llvm::sys::path::native(AssetsPath, DefaultStylesheet); - llvm::sys::path::append(DefaultStylesheet, - "clang-doc-default-stylesheet.css"); - llvm::SmallString<128> IndexJS; - llvm::sys::path::native(AssetsPath, IndexJS); - llvm::sys::path::append(IndexJS, "index.js"); - - llvm::outs() << "Using default asset: " << AssetsPath << "\n"; - - if (!llvm::sys::fs::is_regular_file(IndexJS)) -return llvm::createStringError(llvm::inconvertibleErrorCode(), - "default index.js file missing at " + - IndexJS + "\n"); - - if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) -return llvm::createStringError( -llvm::inconvertibleErrorCode(), -"default clang-doc-default-stylesheet.css file missing at " + -DefaultStylesheet + "\n"); - - CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), - std::string(DefaultStylesheet)); - CDCtx.FilesToCopy.emplace_back(IndexJS.str()); - - return llvm::Error::success(); -} - -llvm::Error getHtmlAssetFiles(const char *Argv0, - clang::doc::ClangDocContext &CDCtx) { - if (!UserAssetPath.empty() && - !llvm::sys::fs::is_directory(std::string(UserAssetPath))) -llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath - << " falling back to default\n"; - if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) -return getAssetFiles(CDCtx); - return getDefaultAssetF
[clang-tools-extra] Revert "[clang-doc] Add --asset option to clang-doc" (PR #96354)
https://github.com/ilovepi ready_for_review https://github.com/llvm/llvm-project/pull/96354 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Revert "[clang-doc] Add --asset option to clang-doc" (PR #96354)
https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/96354 Reverts llvm/llvm-project#94717 This breaks on some buildbots: http://45.33.8.238/linux/141118/step_7.txt >From d9075144100406eed753f1b7ca3df933a596bb3a Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Fri, 21 Jun 2024 13:17:41 -0700 Subject: [PATCH] Revert "[clang-doc] Add --asset option to clang-doc (#94717)" This reverts commit 724d903e03aaf7ee7d4bcdf3cd9fe1e1bda33f9a. --- .../clang-doc/tool/ClangDocMain.cpp | 100 -- .../test/clang-doc/single-source-html.cpp | 2 - 2 files changed, 19 insertions(+), 83 deletions(-) delete mode 100644 clang-tools-extra/test/clang-doc/single-source-html.cpp diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 5a43c70a5ebc3..5517522d7967d 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -81,12 +81,6 @@ static llvm::cl::list UserStylesheets( llvm::cl::desc("CSS stylesheets to extend the default styles."), llvm::cl::cat(ClangDocCategory)); -static llvm::cl::opt UserAssetPath( -"asset", -llvm::cl::desc("User supplied asset path to " - "override the default css and js files for html output"), -llvm::cl::cat(ClangDocCategory)); - static llvm::cl::opt SourceRoot("source-root", llvm::cl::desc(R"( Directory where processed files are stored. Links to definition locations will only be @@ -133,86 +127,16 @@ std::string getFormatString() { // GetMainExecutable (since some platforms don't support taking the // address of main, and some platforms can't implement GetMainExecutable // without being given the address of a function in the main executable). -std::string getExecutablePath(const char *Argv0, void *MainAddr) { +std::string GetExecutablePath(const char *Argv0, void *MainAddr) { return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } -llvm::Error getAssetFiles(clang::doc::ClangDocContext &CDCtx) { - using DirIt = llvm::sys::fs::directory_iterator; - std::error_code FileErr; - llvm::SmallString<128> FilePath(UserAssetPath); - for (DirIt DirStart = DirIt(UserAssetPath, FileErr), - DirEnd; - !FileErr && DirStart != DirEnd; DirStart.increment(FileErr)) { -FilePath = DirStart->path(); -if (llvm::sys::fs::is_regular_file(FilePath)) { - if (llvm::sys::path::extension(FilePath) == ".css") -CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), - std::string(FilePath)); - else if (llvm::sys::path::extension(FilePath) == ".js") -CDCtx.FilesToCopy.emplace_back(FilePath.str()); -} - } - if (FileErr) -return llvm::createFileError(FilePath, FileErr); - return llvm::Error::success(); -} - -llvm::Error getDefaultAssetFiles(const char *Argv0, - clang::doc::ClangDocContext &CDCtx) { - void *MainAddr = (void *)(intptr_t)getExecutablePath; - std::string ClangDocPath = getExecutablePath(Argv0, MainAddr); - llvm::SmallString<128> NativeClangDocPath; - llvm::sys::path::native(ClangDocPath, NativeClangDocPath); - - llvm::SmallString<128> AssetsPath; - AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath); - llvm::sys::path::append(AssetsPath, "..", "share", "clang"); - llvm::SmallString<128> DefaultStylesheet; - llvm::sys::path::native(AssetsPath, DefaultStylesheet); - llvm::sys::path::append(DefaultStylesheet, - "clang-doc-default-stylesheet.css"); - llvm::SmallString<128> IndexJS; - llvm::sys::path::native(AssetsPath, IndexJS); - llvm::sys::path::append(IndexJS, "index.js"); - - llvm::outs() << "Using default asset: " << AssetsPath << "\n"; - - if (!llvm::sys::fs::is_regular_file(IndexJS)) -return llvm::createStringError(llvm::inconvertibleErrorCode(), - "default index.js file missing at " + - IndexJS + "\n"); - - if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) -return llvm::createStringError( -llvm::inconvertibleErrorCode(), -"default clang-doc-default-stylesheet.css file missing at " + -DefaultStylesheet + "\n"); - - CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(), - std::string(DefaultStylesheet)); - CDCtx.FilesToCopy.emplace_back(IndexJS.str()); - - return llvm::Error::success(); -} - -llvm::Error getHtmlAssetFiles(const char *Argv0, - clang::doc::ClangDocContext &CDCtx) { - if (!UserAssetPath.empty() && - !llvm::sys::fs::is_directory(std::string(UserAssetPath))) -llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath - << " falling back to default\n"; - if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) -return getAssetFiles(CDCtx); - return
[clang] [Clang] Replace `emitXXXBuiltin` with a unified interface (PR #96313)
https://github.com/arsenm approved this pull request. https://github.com/llvm/llvm-project/pull/96313 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][Coroutines] Introducing the `[[clang::coro_inplace_task]]` attribute (PR #94693)
https://github.com/yuxuanchen1997 updated https://github.com/llvm/llvm-project/pull/94693 >From 4854a2ed15e983740c8c38c4363d7311fd46cfc7 Mon Sep 17 00:00:00 2001 From: Yuxuan Chen Date: Tue, 4 Jun 2024 23:22:00 -0700 Subject: [PATCH] [Clang] Introduce [[clang::coro_inplace_task]] --- clang/include/clang/AST/ExprCXX.h | 26 -- clang/include/clang/Basic/Attr.td | 8 ++ clang/include/clang/Basic/AttrDocs.td | 19 + clang/lib/CodeGen/CGBlocks.cpp| 5 +- clang/lib/CodeGen/CGCUDARuntime.cpp | 5 +- clang/lib/CodeGen/CGCUDARuntime.h | 8 +- clang/lib/CodeGen/CGCXXABI.h | 10 +-- clang/lib/CodeGen/CGClass.cpp | 16 ++-- clang/lib/CodeGen/CGCoroutine.cpp | 29 +-- clang/lib/CodeGen/CGExpr.cpp | 41 + clang/lib/CodeGen/CGExprCXX.cpp | 60 +++-- clang/lib/CodeGen/CodeGenFunction.h | 64 -- clang/lib/CodeGen/ItaniumCXXABI.cpp | 16 ++-- clang/lib/CodeGen/MicrosoftCXXABI.cpp | 18 ++-- clang/lib/Sema/SemaCoroutine.cpp | 54 +++- clang/lib/Serialization/ASTReaderStmt.cpp | 10 ++- clang/lib/Serialization/ASTWriterStmt.cpp | 3 +- clang/test/CodeGenCoroutines/Inputs/utility.h | 13 +++ .../coro-structured-concurrency.cpp | 84 +++ ...a-attribute-supported-attributes-list.test | 1 + llvm/include/llvm/IR/Intrinsics.td| 3 + .../lib/Transforms/Coroutines/CoroCleanup.cpp | 11 ++- llvm/lib/Transforms/Coroutines/CoroElide.cpp | 58 - llvm/lib/Transforms/Coroutines/Coroutines.cpp | 1 + .../coro-elide-structured-concurrency.ll | 62 ++ 25 files changed, 491 insertions(+), 134 deletions(-) create mode 100644 clang/test/CodeGenCoroutines/Inputs/utility.h create mode 100644 clang/test/CodeGenCoroutines/coro-structured-concurrency.cpp create mode 100644 llvm/test/Transforms/Coroutines/coro-elide-structured-concurrency.ll diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index c2feac525c1ea..0cf62aee41b66 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -5082,7 +5082,8 @@ class CoroutineSuspendExpr : public Expr { enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count }; Stmt *SubExprs[SubExpr::Count]; - OpaqueValueExpr *OpaqueValue = nullptr; + OpaqueValueExpr *CommonExprOpaqueValue = nullptr; + OpaqueValueExpr *InplaceCallOpaqueValue = nullptr; public: // These types correspond to the three C++ 'await_suspend' return variants @@ -5090,10 +5091,10 @@ class CoroutineSuspendExpr : public Expr { CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand, Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume, - OpaqueValueExpr *OpaqueValue) + OpaqueValueExpr *CommonExprOpaqueValue) : Expr(SC, Resume->getType(), Resume->getValueKind(), Resume->getObjectKind()), -KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) { +KeywordLoc(KeywordLoc), CommonExprOpaqueValue(CommonExprOpaqueValue) { SubExprs[SubExpr::Operand] = Operand; SubExprs[SubExpr::Common] = Common; SubExprs[SubExpr::Ready] = Ready; @@ -5128,7 +5129,16 @@ class CoroutineSuspendExpr : public Expr { } /// getOpaqueValue - Return the opaque value placeholder. - OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } + OpaqueValueExpr *getCommonExprOpaqueValue() const { +return CommonExprOpaqueValue; + } + + OpaqueValueExpr *getInplaceCallOpaqueValue() const { +return InplaceCallOpaqueValue; + } + void setInplaceCallOpaqueValue(OpaqueValueExpr *E) { +InplaceCallOpaqueValue = E; + } Expr *getReadyExpr() const { return static_cast(SubExprs[SubExpr::Ready]); @@ -5194,9 +5204,9 @@ class CoawaitExpr : public CoroutineSuspendExpr { public: CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume, - OpaqueValueExpr *OpaqueValue, bool IsImplicit = false) + OpaqueValueExpr *CommonExprOpaqueValue, bool IsImplicit = false) : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common, - Ready, Suspend, Resume, OpaqueValue) { + Ready, Suspend, Resume, CommonExprOpaqueValue) { CoawaitBits.IsImplicit = IsImplicit; } @@ -5275,9 +5285,9 @@ class CoyieldExpr : public CoroutineSuspendExpr { public: CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume, - OpaqueValueExpr *OpaqueValue) + OpaqueValueExpr *CommonExprOpaqueValue) : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common, -
[clang] Enable ASAN in amdgpu toolchain for OpenCL (PR #96262)
https://github.com/yxsamliu closed https://github.com/llvm/llvm-project/pull/96262 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 60fa7c7 - Enable ASAN in amdgpu toolchain for OpenCL (#96262)
Author: Yaxun (Sam) Liu Date: 2024-06-21T16:12:56-04:00 New Revision: 60fa7c7690d65f23636c5ca51e0fbfc54ed09370 URL: https://github.com/llvm/llvm-project/commit/60fa7c7690d65f23636c5ca51e0fbfc54ed09370 DIFF: https://github.com/llvm/llvm-project/commit/60fa7c7690d65f23636c5ca51e0fbfc54ed09370.diff LOG: Enable ASAN in amdgpu toolchain for OpenCL (#96262) Added: Modified: clang/lib/Driver/ToolChains/AMDGPU.cpp clang/lib/Driver/ToolChains/AMDGPU.h clang/test/Driver/rocm-device-libs.cl Removed: diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 20f879e2f75cb..453daed7cc7d5 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -14,6 +14,7 @@ #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/InputInfo.h" #include "clang/Driver/Options.h" +#include "clang/Driver/SanitizerArgs.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Option/ArgList.h" #include "llvm/Support/Error.h" @@ -946,6 +947,11 @@ void ROCMToolChain::addClangTargetOptions( DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt, FastRelaxedMath, CorrectSqrt, ABIVer, false)); + if (getSanitizerArgs(DriverArgs).needsAsanRt()) { +CC1Args.push_back("-mlink-bitcode-file"); +CC1Args.push_back( +DriverArgs.MakeArgString(RocmInstallation->getAsanRTLPath())); + } for (StringRef BCFile : BCLibs) { CC1Args.push_back("-mlink-builtin-bitcode"); CC1Args.push_back(DriverArgs.MakeArgString(BCFile)); diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h index 13c0e138f08f3..7e70dae8ce152 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.h +++ b/clang/lib/Driver/ToolChains/AMDGPU.h @@ -140,6 +140,9 @@ class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain { getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs, const std::string &GPUArch, bool isOpenMP = false) const; + SanitizerMask getSupportedSanitizers() const override { +return SanitizerKind::Address; + } }; } // end namespace toolchains diff --git a/clang/test/Driver/rocm-device-libs.cl b/clang/test/Driver/rocm-device-libs.cl index 415719105d5dc..6837e219dc35d 100644 --- a/clang/test/Driver/rocm-device-libs.cl +++ b/clang/test/Driver/rocm-device-libs.cl @@ -132,9 +132,20 @@ // RUN: %S/opencl.cl \ // RUN: 2>&1 | FileCheck --check-prefixes=COMMON,COMMON-DEFAULT,GFX900-DEFAULT,GFX900,WAVE64 %s +// RUN: %clang -### -target amdgcn-amd-amdhsa \ +// RUN: -x cl -mcpu=gfx908:xnack+ -fsanitize=address \ +// RUN: --rocm-path=%S/Inputs/rocm \ +// RUN: %s \ +// RUN: 2>&1 | FileCheck --check-prefixes=ASAN,COMMON %s +// RUN: %clang -### -target amdgcn-amd-amdhsa \ +// RUN: -x cl -mcpu=gfx908:xnack+ \ +// RUN: --rocm-path=%S/Inputs/rocm \ +// RUN: %s \ +// RUN: 2>&1 | FileCheck --check-prefixes=NOASAN %s // COMMON: "-triple" "amdgcn-amd-amdhsa" +// ASAN-SAME: "-mlink-bitcode-file" "{{.*}}/amdgcn/bitcode/asanrtl.bc" // COMMON-SAME: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/opencl.bc" // COMMON-SAME: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/ocml.bc" // COMMON-SAME: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/ockl.bc" @@ -169,6 +180,11 @@ // COMMON-UNSAFE-MATH-SAME: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/oclc_finite_only_off.bc" // COMMON-UNSAFE-MATH-SAME: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/oclc_correctly_rounded_sqrt_off.bc" +// ASAN-SAME: "-fsanitize=address" + +// NOASAN-NOT: "-fsanitize=address" +// NOASAN-NOT: amdgcn/bitcode/asanrtl.bc + // WAVE64: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/oclc_wavefrontsize64_on.bc" // WAVE32: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/oclc_wavefrontsize64_off.bc" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Enable ASAN in amdgpu toolchain for OpenCL (PR #96262)
@@ -169,6 +180,11 @@ // COMMON-UNSAFE-MATH-SAME: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/oclc_finite_only_off.bc" // COMMON-UNSAFE-MATH-SAME: "-mlink-builtin-bitcode" "{{.*}}/amdgcn/bitcode/oclc_correctly_rounded_sqrt_off.bc" +// ASAN-SAME: "-fsanitize=address" + +// NOASAN-NOT: "-fsanitize=address" +// NOASAN-NOT: amdgcn/bitcode/asanrtl.bc yxsamliu wrote: understood. that's why I single out the negative tests to a separate run line. since there is only negative check in this run, they do not depend on order. hopefully it will be stable https://github.com/llvm/llvm-project/pull/96262 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC][clang][Driver] Add signed GOT flag (PR #96160)
asl wrote: > Do we want a lot of `-fptrauth-xxx` instead of > `-fptrauth-something=xxx,yyy,zzz`? I would lean towards a single flag. However, I do not know how this would affect Apple downstream and what are preferences there. Tagging @ahmedbougacha @ahatanak @ojhunt https://github.com/llvm/llvm-project/pull/96160 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ParserHLSL] Attempt to parse HLSL annotations on Field Decls. (PR #96346)
https://github.com/damyanp edited https://github.com/llvm/llvm-project/pull/96346 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits