[clang] [Clang] Fix handling of brace ellison when building deduction guides (PR #94889)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/94889 >From 217c00f47aaa65b113d1c1cfd93a9c4e1d235c1a Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sun, 9 Jun 2024 11:49:18 +0800 Subject: [PATCH 1/6] [Clang] Fix two issues of CTAD for aggregates --- clang/lib/Sema/SemaInit.cpp | 56 +++-- clang/test/SemaTemplate/deduction-guide.cpp | 19 +++ 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 79bdc8e9f8783..de2ea639bbba8 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -313,6 +313,8 @@ class InitListChecker { InitListExpr *FullyStructuredList = nullptr; NoInitExpr *DummyExpr = nullptr; SmallVectorImpl *AggrDeductionCandidateParamTypes = nullptr; + SmallVectorImpl + *AggrDeductionCandidateParamTypesWithoutBraceElision = nullptr; NoInitExpr *getDummyInit() { if (!DummyExpr) @@ -506,14 +508,19 @@ class InitListChecker { Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T, bool VerifyOnly, bool TreatUnavailableAsInvalid, bool InOverloadResolution = false, - SmallVectorImpl *AggrDeductionCandidateParamTypes = nullptr); + SmallVectorImpl *AggrDeductionCandidateParamTypes = nullptr, + SmallVectorImpl + *AggrDeductionCandidateParamTypesWithoutBraceElision = nullptr); InitListChecker(Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T, - SmallVectorImpl &AggrDeductionCandidateParamTypes) + SmallVectorImpl &AggrDeductionCandidateParamTypes, + SmallVectorImpl + &AggrDeductionCandidateParamTypesWithoutBraceElision) : InitListChecker(S, Entity, IL, T, /*VerifyOnly=*/true, /*TreatUnavailableAsInvalid=*/false, /*InOverloadResolution=*/false, -&AggrDeductionCandidateParamTypes){}; +&AggrDeductionCandidateParamTypes, +&AggrDeductionCandidateParamTypesWithoutBraceElision) {} bool HadError() { return hadError; } @@ -982,11 +989,15 @@ static bool hasAnyDesignatedInits(const InitListExpr *IL) { InitListChecker::InitListChecker( Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T, bool VerifyOnly, bool TreatUnavailableAsInvalid, bool InOverloadResolution, -SmallVectorImpl *AggrDeductionCandidateParamTypes) +SmallVectorImpl *AggrDeductionCandidateParamTypes, +SmallVectorImpl +*AggrDeductionCandidateParamTypesWithoutBraceElision) : SemaRef(S), VerifyOnly(VerifyOnly), TreatUnavailableAsInvalid(TreatUnavailableAsInvalid), InOverloadResolution(InOverloadResolution), - AggrDeductionCandidateParamTypes(AggrDeductionCandidateParamTypes) { + AggrDeductionCandidateParamTypes(AggrDeductionCandidateParamTypes), + AggrDeductionCandidateParamTypesWithoutBraceElision( + AggrDeductionCandidateParamTypesWithoutBraceElision) { if (!VerifyOnly || hasAnyDesignatedInits(IL)) { FullyStructuredList = createInitListExpr(T, IL->getSourceRange(), IL->getNumInits()); @@ -1448,13 +1459,17 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity, // brace elision is not considered for any aggregate element that has a // dependent non-array type or an array type with a value-dependent // bound - assert(AggrDeductionCandidateParamTypes); - if (!isa_and_nonnull( + assert(AggrDeductionCandidateParamTypes && + AggrDeductionCandidateParamTypesWithoutBraceElision); + if (!isa_and_present( SemaRef.Context.getAsArrayType(ElemType))) { ++Index; AggrDeductionCandidateParamTypes->push_back(ElemType); return; } + // For array types with known bounds, we still want the brace version even + // though the braces can be elided. + AggrDeductionCandidateParamTypesWithoutBraceElision->push_back(ElemType); } else { InitializationSequence Seq(SemaRef, TmpEntity, Kind, expr, /*TopLevelOfInitList*/ true); @@ -10918,22 +10933,24 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( if (!(RD->getDefinition() && RD->isAggregate())) return; QualType Ty = Context.getRecordType(RD); - SmallVector ElementTypes; - - InitListChecker CheckInitList(*this, Entity, ListInit, Ty, ElementTypes); - if (!CheckInitList.HadError()) { + auto BuildAggregateDeductionGuide = [&](MutableArrayRef + ElementTypes, + bool BracedVersion = false) { +if (ElementTypes.empty()) + return; // C++ [over.match.class.deduct]p1.8:
[clang] [llvm] [analyzer][NFC] Reorganize Z3 report refutation (PR #95128)
https://github.com/steakhal updated https://github.com/llvm/llvm-project/pull/95128 >From 6b9a5a6902c3efca6ac7d6a5dabc8950767560cc Mon Sep 17 00:00:00 2001 From: Balazs Benics Date: Tue, 11 Jun 2024 16:53:46 +0200 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- .../Core/BugReporter/BugReporterVisitors.h| 23 .../Core/BugReporter/Z3CrosscheckVisitor.h| 66 ++ .../Core/PathSensitive/SMTConstraintManager.h | 5 +- clang/lib/StaticAnalyzer/Core/BugReporter.cpp | 28 - .../Core/BugReporterVisitors.cpp | 76 --- clang/lib/StaticAnalyzer/Core/CMakeLists.txt | 1 + .../Core/Z3CrosscheckVisitor.cpp | 118 ++ .../test/Analysis/z3/crosscheck-statistics.c | 33 + clang/unittests/StaticAnalyzer/CMakeLists.txt | 1 + .../StaticAnalyzer/Z3CrosscheckOracleTest.cpp | 59 + llvm/include/llvm/Support/SMTAPI.h| 19 +++ llvm/lib/Support/Z3Solver.cpp | 103 --- 12 files changed, 408 insertions(+), 124 deletions(-) create mode 100644 clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h create mode 100644 clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp create mode 100644 clang/test/Analysis/z3/crosscheck-statistics.c create mode 100644 clang/unittests/StaticAnalyzer/Z3CrosscheckOracleTest.cpp diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h index cc3d93aabafda..f97514955a591 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h @@ -597,29 +597,6 @@ class SuppressInlineDefensiveChecksVisitor final : public BugReporterVisitor { PathSensitiveBugReport &BR) override; }; -/// The bug visitor will walk all the nodes in a path and collect all the -/// constraints. When it reaches the root node, will create a refutation -/// manager and check if the constraints are satisfiable -class FalsePositiveRefutationBRVisitor final : public BugReporterVisitor { -private: - /// Holds the constraints in a given path - ConstraintMap Constraints; - -public: - FalsePositiveRefutationBRVisitor(); - - void Profile(llvm::FoldingSetNodeID &ID) const override; - - PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, - BugReporterContext &BRC, - PathSensitiveBugReport &BR) override; - - void finalizeVisitor(BugReporterContext &BRC, const ExplodedNode *EndPathNode, - PathSensitiveBugReport &BR) override; - void addConstraints(const ExplodedNode *N, - bool OverwriteConstraintsOnExistingSyms); -}; - /// The visitor detects NoteTags and displays the event notes they contain. class TagVisitor : public BugReporterVisitor { public: diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h new file mode 100644 index 0..3ec59e3037363 --- /dev/null +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/Z3CrosscheckVisitor.h @@ -0,0 +1,66 @@ +//===- Z3CrosscheckVisitor.h - Crosscheck reports with Z3 ---*- C++ -*-===// +// +// 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 +// +//===--===// +// +// This file defines the visitor and utilities around it for Z3 report +// refutation. +// +//===--===// + +#ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_Z3CROSSCHECKVISITOR_H +#define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_Z3CROSSCHECKVISITOR_H + +#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h" + +namespace clang::ento { + +/// The bug visitor will walk all the nodes in a path and collect all the +/// constraints. When it reaches the root node, will create a refutation +/// manager and check if the constraints are satisfiable. +class Z3CrosscheckVisitor final : public BugReporterVisitor { +public: + struct Z3Result { +std::optional IsSAT = std::nullopt; + }; + explicit Z3CrosscheckVisitor(Z3CrosscheckVisitor::Z3Result &Result); + + void Profile(llvm::FoldingSetNodeID &ID) const override; + + PathDiagnosticPieceRef VisitNode(const ExplodedNode *N, + BugReporterContext &BRC, + PathSensitiveBugReport &BR) override; + + void f
[clang] [Clang] Fix handling of brace ellison when building deduction guides (PR #94889)
zyn0217 wrote: @hokein I realized the entire patch could be significantly simplified, in which we just don't need to perform the brace elision on a braced initializer. Can you take a second look at it? https://github.com/llvm/llvm-project/pull/94889 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix handling of brace ellison when building deduction guides (PR #94889)
https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/94889 >From 217c00f47aaa65b113d1c1cfd93a9c4e1d235c1a Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sun, 9 Jun 2024 11:49:18 +0800 Subject: [PATCH 1/5] [Clang] Fix two issues of CTAD for aggregates --- clang/lib/Sema/SemaInit.cpp | 56 +++-- clang/test/SemaTemplate/deduction-guide.cpp | 19 +++ 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 79bdc8e9f8783..de2ea639bbba8 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -313,6 +313,8 @@ class InitListChecker { InitListExpr *FullyStructuredList = nullptr; NoInitExpr *DummyExpr = nullptr; SmallVectorImpl *AggrDeductionCandidateParamTypes = nullptr; + SmallVectorImpl + *AggrDeductionCandidateParamTypesWithoutBraceElision = nullptr; NoInitExpr *getDummyInit() { if (!DummyExpr) @@ -506,14 +508,19 @@ class InitListChecker { Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T, bool VerifyOnly, bool TreatUnavailableAsInvalid, bool InOverloadResolution = false, - SmallVectorImpl *AggrDeductionCandidateParamTypes = nullptr); + SmallVectorImpl *AggrDeductionCandidateParamTypes = nullptr, + SmallVectorImpl + *AggrDeductionCandidateParamTypesWithoutBraceElision = nullptr); InitListChecker(Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T, - SmallVectorImpl &AggrDeductionCandidateParamTypes) + SmallVectorImpl &AggrDeductionCandidateParamTypes, + SmallVectorImpl + &AggrDeductionCandidateParamTypesWithoutBraceElision) : InitListChecker(S, Entity, IL, T, /*VerifyOnly=*/true, /*TreatUnavailableAsInvalid=*/false, /*InOverloadResolution=*/false, -&AggrDeductionCandidateParamTypes){}; +&AggrDeductionCandidateParamTypes, +&AggrDeductionCandidateParamTypesWithoutBraceElision) {} bool HadError() { return hadError; } @@ -982,11 +989,15 @@ static bool hasAnyDesignatedInits(const InitListExpr *IL) { InitListChecker::InitListChecker( Sema &S, const InitializedEntity &Entity, InitListExpr *IL, QualType &T, bool VerifyOnly, bool TreatUnavailableAsInvalid, bool InOverloadResolution, -SmallVectorImpl *AggrDeductionCandidateParamTypes) +SmallVectorImpl *AggrDeductionCandidateParamTypes, +SmallVectorImpl +*AggrDeductionCandidateParamTypesWithoutBraceElision) : SemaRef(S), VerifyOnly(VerifyOnly), TreatUnavailableAsInvalid(TreatUnavailableAsInvalid), InOverloadResolution(InOverloadResolution), - AggrDeductionCandidateParamTypes(AggrDeductionCandidateParamTypes) { + AggrDeductionCandidateParamTypes(AggrDeductionCandidateParamTypes), + AggrDeductionCandidateParamTypesWithoutBraceElision( + AggrDeductionCandidateParamTypesWithoutBraceElision) { if (!VerifyOnly || hasAnyDesignatedInits(IL)) { FullyStructuredList = createInitListExpr(T, IL->getSourceRange(), IL->getNumInits()); @@ -1448,13 +1459,17 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity, // brace elision is not considered for any aggregate element that has a // dependent non-array type or an array type with a value-dependent // bound - assert(AggrDeductionCandidateParamTypes); - if (!isa_and_nonnull( + assert(AggrDeductionCandidateParamTypes && + AggrDeductionCandidateParamTypesWithoutBraceElision); + if (!isa_and_present( SemaRef.Context.getAsArrayType(ElemType))) { ++Index; AggrDeductionCandidateParamTypes->push_back(ElemType); return; } + // For array types with known bounds, we still want the brace version even + // though the braces can be elided. + AggrDeductionCandidateParamTypesWithoutBraceElision->push_back(ElemType); } else { InitializationSequence Seq(SemaRef, TmpEntity, Kind, expr, /*TopLevelOfInitList*/ true); @@ -10918,22 +10933,24 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( if (!(RD->getDefinition() && RD->isAggregate())) return; QualType Ty = Context.getRecordType(RD); - SmallVector ElementTypes; - - InitListChecker CheckInitList(*this, Entity, ListInit, Ty, ElementTypes); - if (!CheckInitList.HadError()) { + auto BuildAggregateDeductionGuide = [&](MutableArrayRef + ElementTypes, + bool BracedVersion = false) { +if (ElementTypes.empty()) + return; // C++ [over.match.class.deduct]p1.8:
[clang] [llvm] [RISCV] Add Smcsrind and Sscsrind extension (PR #93952)
https://github.com/dtcxzyw closed https://github.com/llvm/llvm-project/pull/93952 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2fe7238 - [RISCV] Add Smcsrind and Sscsrind extension (#93952)
Author: Monad Date: 2024-06-12T14:33:12+08:00 New Revision: 2fe72385a4964f80e7a1c5abcd426455e4127c03 URL: https://github.com/llvm/llvm-project/commit/2fe72385a4964f80e7a1c5abcd426455e4127c03 DIFF: https://github.com/llvm/llvm-project/commit/2fe72385a4964f80e7a1c5abcd426455e4127c03.diff LOG: [RISCV] Add Smcsrind and Sscsrind extension (#93952) Specification link: https://github.com/riscv/riscv-isa-manual/blob/main/src/indirect-csr.adoc Some CSRs (`*ireg` and `*iselect`) in Smcsrind/Sscsrind extensions are originally defined as part of the Smaia/Ssaia extensions and are already supported in LLVM. The missing CSRs (`*ireg2` to `*ireg6` for `m`, `s`, and `vs`) are added in this PR. Added: Modified: clang/test/Preprocessor/riscv-target-features.c llvm/docs/RISCVUsage.rst llvm/docs/ReleaseNotes.rst llvm/lib/Target/RISCV/RISCVFeatures.td llvm/lib/Target/RISCV/RISCVSystemOperands.td llvm/test/CodeGen/RISCV/attributes.ll llvm/test/MC/RISCV/attribute-arch.s llvm/test/MC/RISCV/hypervisor-csr-names.s llvm/test/MC/RISCV/machine-csr-names.s llvm/test/MC/RISCV/supervisor-csr-names.s llvm/unittests/TargetParser/RISCVISAInfoTest.cpp Removed: diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index 576101b6ae50f..d7935af532dfa 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -28,6 +28,7 @@ // CHECK-NOT: __riscv_shvstvecd {{.*$}} // CHECK-NOT: __riscv_smaia {{.*$}} // CHECK-NOT: __riscv_smcdeleg {{.*$}} +// CHECK-NOT: __riscv_smcsrind {{.*$}} // CHECK-NOT: __riscv_smepmp {{.*$}} // CHECK-NOT: __riscv_smstateen {{.*$}} // CHECK-NOT: __riscv_ssaia {{.*$}} @@ -35,6 +36,7 @@ // CHECK-NOT: __riscv_ssccptr {{.*$}} // CHECK-NOT: __riscv_sscofpmf {{.*$}} // CHECK-NOT: __riscv_sscounterenw {{.*$}} +// CHECK-NOT: __riscv_sscsrind {{.*$}} // CHECK-NOT: __riscv_ssstateen {{.*$}} // CHECK-NOT: __riscv_ssstrict {{.*$}} // CHECK-NOT: __riscv_sstc {{.*$}} @@ -1403,6 +1405,22 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s // CHECK-SSAIA-EXT: __riscv_ssaia 100{{$}} +// RUN: %clang --target=riscv32 \ +// RUN: -march=rv32ismcsrind1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SMCSRIND-EXT %s +// RUN: %clang --target=riscv64 \ +// RUN: -march=rv64ismcsrind1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SMCSRIND-EXT %s +// CHECK-SMCSRIND-EXT: __riscv_smcsrind 100{{$}} + +// RUN: %clang --target=riscv32 \ +// RUN: -march=rv32isscsrind1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SSCSRIND-EXT %s +// RUN: %clang --target=riscv64 \ +// RUN: -march=rv64isscsrind1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SSCSRIND-EXT %s +// CHECK-SSCSRIND-EXT: __riscv_sscsrind 100{{$}} + // RUN: %clang --target=riscv32 \ // RUN: -march=rv32ismcdeleg1p0 -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst index ffe93d7569a71..152849a01c37f 100644 --- a/llvm/docs/RISCVUsage.rst +++ b/llvm/docs/RISCVUsage.rst @@ -100,6 +100,7 @@ on support follow. ``Shvstvecd`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Smaia`` Supported ``Smcdeleg`` Supported + ``Smcsrind`` Supported ``Smepmp``Supported ``Smstateen`` Assembly Support ``Ssaia`` Supported @@ -107,6 +108,7 @@ on support follow. ``Ssccptr`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Sscofpmf`` Assembly Support ``Sscounterenw`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) + ``Sscsrind`` Supported ``Ssstateen`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Ssstrict`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Sstc`` Assembly Support diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst index 4efede4609481..69fa6c31ded19 100644 --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -157,7 +157,7 @@ Changes to the RISC-V Backend * Processors that enable post reg-alloc scheduling (PostMachineScheduler) by default should use the `UsePostRAScheduler` subtarget feature. Setting `PostRAScheduler = 1` in the scheduler model will have no effect on the enabling of the PostMachineScheduler. * Zabha is no longer experimental. * B (the collection of the Zba, Zbb, Zbs extensions) is supported. -* Added smcdeleg and ssccfg extensions to -march. +* Added smcdeleg, ssccfg, smcsrind, and sscsrind extensions to -march. Changes to the WebAssembly Backend -- diff --git a/llvm/lib/Target/RISCV/RISCVFe
[clang] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior in Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs() (PR #95195)
cor3ntin wrote: as @mizvekov said, there is no UB here. A better improvement would be to let `runWithSufficientStackSpace` return a value, so we can write ```cpp bool AtLeastAsSpecialized = runWithSufficientStackSpace(/*...*/); ``` https://github.com/llvm/llvm-project/pull/95195 ___ 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 basic e2e test (PR #93928)
PeterChou1 wrote: > Do we really need a full CSS when we're only checking the HTML? Could we just > include a super minimal (or even empty) CSS? I just realize we probably don't need any css or js we just need the files https://github.com/llvm/llvm-project/pull/93928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add Smcsrind and Sscsrind extension (PR #93952)
YanWQ-monad wrote: > Conflicting files rebased. https://github.com/llvm/llvm-project/pull/93952 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add Smcsrind and Sscsrind extension (PR #93952)
https://github.com/YanWQ-monad updated https://github.com/llvm/llvm-project/pull/93952 >From afd92de1d6a04144110eaf358117a0ad3b37343b Mon Sep 17 00:00:00 2001 From: YanWQ-monad Date: Fri, 31 May 2024 16:11:43 +0800 Subject: [PATCH 1/4] [RISCV] Add smcsrind and sscsrind extension --- .../test/Preprocessor/riscv-target-features.c | 18 ++ llvm/docs/RISCVUsage.rst | 2 ++ llvm/lib/Target/RISCV/RISCVFeatures.td | 7 +++ llvm/test/CodeGen/RISCV/attributes.ll | 8 llvm/test/MC/RISCV/attribute-arch.s| 6 ++ .../TargetParser/RISCVISAInfoTest.cpp | 2 ++ 6 files changed, 43 insertions(+) diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index 576101b6ae50f..d7935af532dfa 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -28,6 +28,7 @@ // CHECK-NOT: __riscv_shvstvecd {{.*$}} // CHECK-NOT: __riscv_smaia {{.*$}} // CHECK-NOT: __riscv_smcdeleg {{.*$}} +// CHECK-NOT: __riscv_smcsrind {{.*$}} // CHECK-NOT: __riscv_smepmp {{.*$}} // CHECK-NOT: __riscv_smstateen {{.*$}} // CHECK-NOT: __riscv_ssaia {{.*$}} @@ -35,6 +36,7 @@ // CHECK-NOT: __riscv_ssccptr {{.*$}} // CHECK-NOT: __riscv_sscofpmf {{.*$}} // CHECK-NOT: __riscv_sscounterenw {{.*$}} +// CHECK-NOT: __riscv_sscsrind {{.*$}} // CHECK-NOT: __riscv_ssstateen {{.*$}} // CHECK-NOT: __riscv_ssstrict {{.*$}} // CHECK-NOT: __riscv_sstc {{.*$}} @@ -1403,6 +1405,22 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s // CHECK-SSAIA-EXT: __riscv_ssaia 100{{$}} +// RUN: %clang --target=riscv32 \ +// RUN: -march=rv32ismcsrind1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SMCSRIND-EXT %s +// RUN: %clang --target=riscv64 \ +// RUN: -march=rv64ismcsrind1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SMCSRIND-EXT %s +// CHECK-SMCSRIND-EXT: __riscv_smcsrind 100{{$}} + +// RUN: %clang --target=riscv32 \ +// RUN: -march=rv32isscsrind1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SSCSRIND-EXT %s +// RUN: %clang --target=riscv64 \ +// RUN: -march=rv64isscsrind1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SSCSRIND-EXT %s +// CHECK-SSCSRIND-EXT: __riscv_sscsrind 100{{$}} + // RUN: %clang --target=riscv32 \ // RUN: -march=rv32ismcdeleg1p0 -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst index ffe93d7569a71..152849a01c37f 100644 --- a/llvm/docs/RISCVUsage.rst +++ b/llvm/docs/RISCVUsage.rst @@ -100,6 +100,7 @@ on support follow. ``Shvstvecd`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Smaia`` Supported ``Smcdeleg`` Supported + ``Smcsrind`` Supported ``Smepmp``Supported ``Smstateen`` Assembly Support ``Ssaia`` Supported @@ -107,6 +108,7 @@ on support follow. ``Ssccptr`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Sscofpmf`` Assembly Support ``Sscounterenw`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) + ``Sscsrind`` Supported ``Ssstateen`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Ssstrict`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Sstc`` Assembly Support diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index bb8c95829b9e0..4685c93baefbe 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -855,6 +855,13 @@ def FeatureStdExtSsaia "'Ssaia' (Advanced Interrupt Architecture Supervisor " "Level)">; +def FeatureStdExtSmcsrind +: RISCVExtension<"smcsrind", 1, 0, + "'Smcsrind' (Indirect CSR Access Machine Level)">; +def FeatureStdExtSscsrind +: RISCVExtension<"sscsrind", 1, 0, + "'Sscsrind' (Indirect CSR Access Supervisor Level)">; + def FeatureStdExtSmepmp : RISCVExtension<"smepmp", 1, 0, "'Smepmp' (Enhanced Physical Memory Protection)">; diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll index b1cf7198937fb..539f0e1a67947 100644 --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -112,6 +112,8 @@ ; RUN: llc -mtriple=riscv32 -mattr=+zcmop %s -o - | FileCheck --check-prefix=RV32ZCMOP %s ; RUN: llc -mtriple=riscv32 -mattr=+smaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SMAIA %s ; RUN: llc -mtriple=riscv32 -mattr=+ssaia %s -o - | FileCheck --check-prefixes=CHECK,RV32SSAIA %s +; RUN: llc -mtriple=riscv32 -mattr=+smcsrind %s -o - | FileCheck --check-prefixes=CHECK,RV32SMCSRIND %
[clang] 93d4fb0 - [clang][Interp] Support floats in APValues
Author: Timm Bäder Date: 2024-06-12T08:15:36+02:00 New Revision: 93d4fb032ec1e069cfa5b800f3ca1c807f0d87ac URL: https://github.com/llvm/llvm-project/commit/93d4fb032ec1e069cfa5b800f3ca1c807f0d87ac DIFF: https://github.com/llvm/llvm-project/commit/93d4fb032ec1e069cfa5b800f3ca1c807f0d87ac.diff LOG: [clang][Interp] Support floats in APValues Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/records.cpp Removed: diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 820e4cc44a7bc..1393ef1f2ec35 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -3223,6 +3223,8 @@ bool ByteCodeExprGen::visitAPValue(const APValue &Val, assert(!DiscardResult); if (Val.isInt()) return this->emitConst(Val.getInt(), ValType, E); + else if (Val.isFloat()) +return this->emitConstFloat(Val.getFloat(), E); if (Val.isLValue()) { if (Val.isNullPointer()) @@ -3253,7 +3255,7 @@ bool ByteCodeExprGen::visitAPValueInitializer(const APValue &Val, const APValue &F = Val.getStructField(I); const Record::Field *RF = R->getField(I); - if (F.isInt() || F.isLValue() || F.isMemberPointer()) { + if (F.isInt() || F.isFloat() || F.isLValue() || F.isMemberPointer()) { PrimType T = classifyPrim(RF->Decl->getType()); if (!this->visitAPValue(F, T, E)) return false; diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp index 0a89c81bafd57..8a18f7a2a4890 100644 --- a/clang/test/AST/Interp/records.cpp +++ b/clang/test/AST/Interp/records.cpp @@ -1479,4 +1479,17 @@ namespace VirtOperator { }; constexpr bool cmp_base_derived = D() == D(); // both-warning {{ambiguous}} } + +namespace FloatAPValue { + struct ClassTemplateArg { +int a; +float f; + }; + template struct ClassTemplateArgTemplate { +static constexpr const ClassTemplateArg &Arg = A; + }; + ClassTemplateArgTemplate ClassTemplateArgObj; + template struct ClassTemplateArgRefTemplate {}; + ClassTemplateArgRefTemplate ClassTemplateArgRefObj; +} #endif ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [clangd] Avoid bogus error about recursive inclusion (PR #95200)
HighCommander4 wrote: Converted to a draft because, as mentioned in https://github.com/clangd/clangd/issues/337#issuecomment-2162175454, the patch doesn't seem to actually fix the issue it's supposed to fix. https://github.com/llvm/llvm-project/pull/95200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [clangd] Avoid bogus error about recursive inclusion (PR #95200)
https://github.com/HighCommander4 converted_to_draft https://github.com/llvm/llvm-project/pull/95200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix-it hint for `++this` -> `++*this` when deref is modifiable (PR #94159)
Rajveer100 wrote: @Sirraide Can you land this for me? https://github.com/llvm/llvm-project/pull/94159 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [clangd] Avoid bogus error about recursive inclusion (PR #95200)
HighCommander4 wrote: The title of the PR can probably be improved. The current title describes the symptom the patch fixes rather than the change it makes (which I don't understand well). (I changed it from the Phabricator revision's title, which was "[clangd] WIP: fix several bugs relating to include insertion", since I don't think that's accurate any more.) https://github.com/llvm/llvm-project/pull/95200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [clangd] Avoid bogus error about recursive inclusion (PR #95200)
HighCommander4 wrote: This is @sam-mccall's patch from https://reviews.llvm.org/D78038, rebased and posted as a Github PR https://github.com/llvm/llvm-project/pull/95200 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [clangd] Avoid bogus error about recursive inclusion (PR #95200)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Nathan Ridge (HighCommander4) Changes Fixes https://github.com/clangd/clangd/issues/337 --- Full diff: https://github.com/llvm/llvm-project/pull/95200.diff 4 Files Affected: - (modified) clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp (+39) - (modified) clang/lib/Serialization/ASTReader.cpp (+11) - (modified) clang/lib/Serialization/ASTWriter.cpp (+12) - (modified) llvm/include/llvm/Support/OnDiskHashTable.h (+2-2) ``diff diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index 1e7a30e69fabe..75c31f88d0fed 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -1719,6 +1719,45 @@ TEST_F(SymbolCollectorTest, HeaderGuardDetected) { EXPECT_THAT(Symbols, Each(includeHeader())); } +TEST_F(SymbolCollectorTest, HeaderGuardDetectedPragmaInPreamble) { + // TestTU builds with a preamble. + auto TU = TestTU::withCode(R"cpp( +#pragma once + +// Symbols are seen before the header guard is complete. +#define MACRO +int decl(); +#define MACRO2 + )cpp"); + TU.HeaderFilename = "Foo.h"; + auto Symbols = TU.headerSymbols(); + EXPECT_THAT(Symbols, Not(Contains(qName("HEADER_GUARD_"; + EXPECT_THAT(Symbols, Contains(qName("MACRO"))); + EXPECT_THAT(Symbols, Contains(qName("MACRO2"))); + EXPECT_THAT(Symbols, Contains(qName("decl"))); +} + +TEST_F(SymbolCollectorTest, HeaderGuardDetectedIfdefInPreamble) { + // TestTU builds with a preamble. + auto TU = TestTU::withCode(R"cpp( +#ifndef HEADER_GUARD_ +#define HEADER_GUARD_ + +// Symbols are seen before the header guard is complete. +#define MACRO +int decl(); +#define MACRO2 + +#endif // Header guard is recognized here. + )cpp"); + TU.HeaderFilename = "Foo.h"; + auto Symbols = TU.headerSymbols(); + EXPECT_THAT(Symbols, Not(Contains(qName("HEADER_GUARD_"; + EXPECT_THAT(Symbols, Contains(qName("MACRO"))); + EXPECT_THAT(Symbols, Contains(qName("MACRO2"))); + EXPECT_THAT(Symbols, Contains(qName("decl"))); +} + TEST_F(SymbolCollectorTest, NonModularHeader) { auto TU = TestTU::withHeaderCode("int x();"); EXPECT_THAT(TU.headerSymbols(), ElementsAre(includeHeader())); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 44e23919ea18e..36d0e499e72b8 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -6518,6 +6518,17 @@ namespace { // Look in the on-disk hash table for an entry for this file name. HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); + // Preambles may be reused with different main-file content. + // A second entry with size zero is stored for the main-file, try that. + // To avoid doing this on every miss, require the bare filename to match. + if (Pos == Table->end() && M.Kind == clang::serialization::MK_Preamble && + llvm::sys::path::filename(FE.getName()) == + llvm::sys::path::filename(M.OriginalSourceFileName)) { +auto InternalKey = Table->getInfoObj().GetInternalKey(FE); +InternalKey.Size = 0; +Pos = Table->find_hashed(InternalKey, + Table->getInfoObj().ComputeHash(InternalKey)); + } if (Pos == Table->end()) return false; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 8a4b36207c473..0a9093e0d189b 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2044,6 +2044,10 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { SmallVector FilesByUID; HS.getFileMgr().GetUniqueIDMapping(FilesByUID); + const auto &SM = Context->getSourceManager(); + unsigned MainFileUID = -1; + if (const auto *Entry = SM.getFileEntryForID(SM.getMainFileID())) +MainFileUID = Entry->getUID(); if (FilesByUID.size() > HS.header_file_size()) FilesByUID.resize(HS.header_file_size()); @@ -2082,6 +2086,14 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { }; Generator.insert(Key, Data, GeneratorTrait); ++NumHeaderSearchEntries; +// We may reuse a preamble even if the rest of the file is different, so +// allow looking up info for the main file with a zero size. +if (this->getASTContext().getLangOpts().CompilingPCH && +File->getUID() == MainFileUID) { + Key.Size = 0; + Generator.insert(Key, Data, GeneratorTrait); + ++NumHeaderSearchEntries; +} } // Create the on-disk hash table in a buffer. diff --git a/llvm/include/llvm/Support/OnDiskHashTable.h b/llvm/include/llvm/Support/OnDiskHashTable.h index f6b4055e74de7..561208aa9a679 100644 --- a/llvm/include/llvm/Support/OnDiskHashTable.h +++ b/llvm/include/llvm/Support/OnDiskHas
[clang] [clang-tools-extra] [llvm] [clangd] Avoid bogus error about recursive inclusion (PR #95200)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-llvm-support Author: Nathan Ridge (HighCommander4) Changes Fixes https://github.com/clangd/clangd/issues/337 --- Full diff: https://github.com/llvm/llvm-project/pull/95200.diff 4 Files Affected: - (modified) clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp (+39) - (modified) clang/lib/Serialization/ASTReader.cpp (+11) - (modified) clang/lib/Serialization/ASTWriter.cpp (+12) - (modified) llvm/include/llvm/Support/OnDiskHashTable.h (+2-2) ``diff diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index 1e7a30e69fabe..75c31f88d0fed 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -1719,6 +1719,45 @@ TEST_F(SymbolCollectorTest, HeaderGuardDetected) { EXPECT_THAT(Symbols, Each(includeHeader())); } +TEST_F(SymbolCollectorTest, HeaderGuardDetectedPragmaInPreamble) { + // TestTU builds with a preamble. + auto TU = TestTU::withCode(R"cpp( +#pragma once + +// Symbols are seen before the header guard is complete. +#define MACRO +int decl(); +#define MACRO2 + )cpp"); + TU.HeaderFilename = "Foo.h"; + auto Symbols = TU.headerSymbols(); + EXPECT_THAT(Symbols, Not(Contains(qName("HEADER_GUARD_"; + EXPECT_THAT(Symbols, Contains(qName("MACRO"))); + EXPECT_THAT(Symbols, Contains(qName("MACRO2"))); + EXPECT_THAT(Symbols, Contains(qName("decl"))); +} + +TEST_F(SymbolCollectorTest, HeaderGuardDetectedIfdefInPreamble) { + // TestTU builds with a preamble. + auto TU = TestTU::withCode(R"cpp( +#ifndef HEADER_GUARD_ +#define HEADER_GUARD_ + +// Symbols are seen before the header guard is complete. +#define MACRO +int decl(); +#define MACRO2 + +#endif // Header guard is recognized here. + )cpp"); + TU.HeaderFilename = "Foo.h"; + auto Symbols = TU.headerSymbols(); + EXPECT_THAT(Symbols, Not(Contains(qName("HEADER_GUARD_"; + EXPECT_THAT(Symbols, Contains(qName("MACRO"))); + EXPECT_THAT(Symbols, Contains(qName("MACRO2"))); + EXPECT_THAT(Symbols, Contains(qName("decl"))); +} + TEST_F(SymbolCollectorTest, NonModularHeader) { auto TU = TestTU::withHeaderCode("int x();"); EXPECT_THAT(TU.headerSymbols(), ElementsAre(includeHeader())); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 44e23919ea18e..36d0e499e72b8 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -6518,6 +6518,17 @@ namespace { // Look in the on-disk hash table for an entry for this file name. HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); + // Preambles may be reused with different main-file content. + // A second entry with size zero is stored for the main-file, try that. + // To avoid doing this on every miss, require the bare filename to match. + if (Pos == Table->end() && M.Kind == clang::serialization::MK_Preamble && + llvm::sys::path::filename(FE.getName()) == + llvm::sys::path::filename(M.OriginalSourceFileName)) { +auto InternalKey = Table->getInfoObj().GetInternalKey(FE); +InternalKey.Size = 0; +Pos = Table->find_hashed(InternalKey, + Table->getInfoObj().ComputeHash(InternalKey)); + } if (Pos == Table->end()) return false; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 8a4b36207c473..0a9093e0d189b 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2044,6 +2044,10 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { SmallVector FilesByUID; HS.getFileMgr().GetUniqueIDMapping(FilesByUID); + const auto &SM = Context->getSourceManager(); + unsigned MainFileUID = -1; + if (const auto *Entry = SM.getFileEntryForID(SM.getMainFileID())) +MainFileUID = Entry->getUID(); if (FilesByUID.size() > HS.header_file_size()) FilesByUID.resize(HS.header_file_size()); @@ -2082,6 +2086,14 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { }; Generator.insert(Key, Data, GeneratorTrait); ++NumHeaderSearchEntries; +// We may reuse a preamble even if the rest of the file is different, so +// allow looking up info for the main file with a zero size. +if (this->getASTContext().getLangOpts().CompilingPCH && +File->getUID() == MainFileUID) { + Key.Size = 0; + Generator.insert(Key, Data, GeneratorTrait); + ++NumHeaderSearchEntries; +} } // Create the on-disk hash table in a buffer. diff --git a/llvm/include/llvm/Support/OnDiskHashTable.h b/llvm/include/llvm/Support/OnDiskHashTable.h index f6b4055e74de7..561208aa9a679 100644 --- a/llvm/include/llvm/Support/OnDiskHashTable.h +++ b/llvm/include/
[clang] [clang-tools-extra] [llvm] [clangd] Avoid bogus error about recursive inclusion (PR #95200)
https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/95200 Fixes https://github.com/clangd/clangd/issues/337 >From 063d7f4977f0d75f88484c1110ca465aa50fc90a Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Wed, 12 Jun 2024 01:20:15 -0400 Subject: [PATCH] [clangd] Avoid bogus error about recursive inclusion Fixes https://github.com/clangd/clangd/issues/337 --- .../clangd/unittests/SymbolCollectorTests.cpp | 39 +++ clang/lib/Serialization/ASTReader.cpp | 11 ++ clang/lib/Serialization/ASTWriter.cpp | 12 ++ llvm/include/llvm/Support/OnDiskHashTable.h | 4 +- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index 1e7a30e69fabe..75c31f88d0fed 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -1719,6 +1719,45 @@ TEST_F(SymbolCollectorTest, HeaderGuardDetected) { EXPECT_THAT(Symbols, Each(includeHeader())); } +TEST_F(SymbolCollectorTest, HeaderGuardDetectedPragmaInPreamble) { + // TestTU builds with a preamble. + auto TU = TestTU::withCode(R"cpp( +#pragma once + +// Symbols are seen before the header guard is complete. +#define MACRO +int decl(); +#define MACRO2 + )cpp"); + TU.HeaderFilename = "Foo.h"; + auto Symbols = TU.headerSymbols(); + EXPECT_THAT(Symbols, Not(Contains(qName("HEADER_GUARD_"; + EXPECT_THAT(Symbols, Contains(qName("MACRO"))); + EXPECT_THAT(Symbols, Contains(qName("MACRO2"))); + EXPECT_THAT(Symbols, Contains(qName("decl"))); +} + +TEST_F(SymbolCollectorTest, HeaderGuardDetectedIfdefInPreamble) { + // TestTU builds with a preamble. + auto TU = TestTU::withCode(R"cpp( +#ifndef HEADER_GUARD_ +#define HEADER_GUARD_ + +// Symbols are seen before the header guard is complete. +#define MACRO +int decl(); +#define MACRO2 + +#endif // Header guard is recognized here. + )cpp"); + TU.HeaderFilename = "Foo.h"; + auto Symbols = TU.headerSymbols(); + EXPECT_THAT(Symbols, Not(Contains(qName("HEADER_GUARD_"; + EXPECT_THAT(Symbols, Contains(qName("MACRO"))); + EXPECT_THAT(Symbols, Contains(qName("MACRO2"))); + EXPECT_THAT(Symbols, Contains(qName("decl"))); +} + TEST_F(SymbolCollectorTest, NonModularHeader) { auto TU = TestTU::withHeaderCode("int x();"); EXPECT_THAT(TU.headerSymbols(), ElementsAre(includeHeader())); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 44e23919ea18e..36d0e499e72b8 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -6518,6 +6518,17 @@ namespace { // Look in the on-disk hash table for an entry for this file name. HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); + // Preambles may be reused with different main-file content. + // A second entry with size zero is stored for the main-file, try that. + // To avoid doing this on every miss, require the bare filename to match. + if (Pos == Table->end() && M.Kind == clang::serialization::MK_Preamble && + llvm::sys::path::filename(FE.getName()) == + llvm::sys::path::filename(M.OriginalSourceFileName)) { +auto InternalKey = Table->getInfoObj().GetInternalKey(FE); +InternalKey.Size = 0; +Pos = Table->find_hashed(InternalKey, + Table->getInfoObj().ComputeHash(InternalKey)); + } if (Pos == Table->end()) return false; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 8a4b36207c473..0a9093e0d189b 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2044,6 +2044,10 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { SmallVector FilesByUID; HS.getFileMgr().GetUniqueIDMapping(FilesByUID); + const auto &SM = Context->getSourceManager(); + unsigned MainFileUID = -1; + if (const auto *Entry = SM.getFileEntryForID(SM.getMainFileID())) +MainFileUID = Entry->getUID(); if (FilesByUID.size() > HS.header_file_size()) FilesByUID.resize(HS.header_file_size()); @@ -2082,6 +2086,14 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { }; Generator.insert(Key, Data, GeneratorTrait); ++NumHeaderSearchEntries; +// We may reuse a preamble even if the rest of the file is different, so +// allow looking up info for the main file with a zero size. +if (this->getASTContext().getLangOpts().CompilingPCH && +File->getUID() == MainFileUID) { + Key.Size = 0; + Generator.insert(Key, Data, GeneratorTrait); + ++NumHeaderSearchEntries; +} } // Create the on-disk hash table in a buffer. diff --git a/llvm/include/llvm/Support/OnDiskHashTable.h b/llvm/inc
[clang] [llvm] [KMSAN] Enable on PowerPC64 (PR #73611)
https://github.com/dtcxzyw closed https://github.com/llvm/llvm-project/pull/73611 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1b66306 - [KMSAN] Enable on PowerPC64 (#73611)
Author: NMiehlbradt Date: 2024-06-12T13:32:39+08:00 New Revision: 1b66306c9c1adce20e2f3cfb1df0af2fb6a10318 URL: https://github.com/llvm/llvm-project/commit/1b66306c9c1adce20e2f3cfb1df0af2fb6a10318 DIFF: https://github.com/llvm/llvm-project/commit/1b66306c9c1adce20e2f3cfb1df0af2fb6a10318.diff LOG: [KMSAN] Enable on PowerPC64 (#73611) Enable -fsanitize=kernel-memory support in Clang. Add tests. - Co-authored-by: Nicholas Miehlbradt Added: llvm/test/Instrumentation/MemorySanitizer/PowerPC/kernel-ppc64le.ll Modified: clang/lib/Driver/ToolChains/Linux.cpp llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 2c583ac724a2a..dea431c3c 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -815,7 +815,7 @@ SanitizerMask Linux::getSupportedSanitizers() const { if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ || IsLoongArch64 || IsRISCV64) Res |= SanitizerKind::Thread; - if (IsX86_64 || IsSystemZ) + if (IsX86_64 || IsSystemZ || IsPowerPC64) Res |= SanitizerKind::KernelMemory; if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsMIPS || IsArmArch || IsPowerPC64 || IsHexagon || IsLoongArch64 || IsRISCV64) diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index ffb4e5b94c20b..499f79965f4bc 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -124,8 +124,9 @@ /// __msan_metadata_ptr_for_store_n(ptr, size); ///Note that the sanitizer code has to deal with how shadow/origin pairs ///returned by the these functions are represented in diff erent ABIs. In -///the X86_64 ABI they are returned in RDX:RAX, and in the SystemZ ABI they -///are written to memory pointed to by a hidden parameter. +///the X86_64 ABI they are returned in RDX:RAX, in PowerPC64 they are +///returned in r3 and r4, and in the SystemZ ABI they are written to memory +///pointed to by a hidden parameter. /// - TLS variables are stored in a single per-task struct. A call to a ///function __msan_get_context_state() returning a pointer to that struct ///is inserted into every instrumented function before the entry block; @@ -139,7 +140,8 @@ /// Also, KMSAN currently ignores uninitialized memory passed into inline asm /// calls, making sure we're on the safe side wrt. possible false positives. /// -/// KernelMemorySanitizer only supports X86_64 and SystemZ at the moment. +/// KernelMemorySanitizer only supports X86_64, SystemZ and PowerPC64 at the +/// moment. /// // // FIXME: This sanitizer does not yet handle scalable vectors diff --git a/llvm/test/Instrumentation/MemorySanitizer/PowerPC/kernel-ppc64le.ll b/llvm/test/Instrumentation/MemorySanitizer/PowerPC/kernel-ppc64le.ll new file mode 100644 index 0..b4e472a134abd --- /dev/null +++ b/llvm/test/Instrumentation/MemorySanitizer/PowerPC/kernel-ppc64le.ll @@ -0,0 +1,149 @@ +; RUN: opt < %s -S -msan-kernel=1 -passes=msan 2>&1 | FileCheck %s + +target datalayout = "e-m:e-i64:64-n32:64" +target triple = "powerpc64le--linux" + +define void @Store1(ptr %p, i8 %x) sanitize_memory { +entry: + store i8 %x, ptr %p + ret void +} + +; CHECK-LABEL: define {{[^@]+}}@Store1( +; CHECK: [[META:%[a-z0-9_]+]] = call { ptr, ptr } @__msan_metadata_ptr_for_store_1(ptr %p) +; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0 +; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1 +; CHECK: store i8 {{.+}}, ptr [[SHADOW]] +; CHECK: ret void + +define void @Store2(ptr %p, i16 %x) sanitize_memory { +entry: + store i16 %x, ptr %p + ret void +} + +; CHECK-LABEL: define {{[^@]+}}@Store2( +; CHECK: [[META:%[a-z0-9_]+]] = call { ptr, ptr } @__msan_metadata_ptr_for_store_2(ptr %p) +; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0 +; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1 +; CHECK: store i16 {{.+}}, ptr [[SHADOW]] +; CHECK: ret void + +define void @Store4(ptr %p, i32 %x) sanitize_memory { +entry: + store i32 %x, ptr %p + ret void +} + +; CHECK-LABEL: define {{[^@]+}}@Store4( +; CHECK: [[META:%[a-z0-9_]+]] = call { ptr, ptr } @__msan_metadata_ptr_for_store_4(ptr %p) +; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0 +; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1 +; CHECK: store i32 {{.+}}, ptr [[SHADOW]] +; CHECK: ret void + +define void @Store8(ptr %p, i64 %x) sanitize_memory { +entry: + store i64 %x, ptr %p + ret void +} + +; CHECK-LABEL: define {{[^@]+}}@Store8( +; CHECK: [[META:%[a-z0-9_]+]] = call { ptr, ptr } @__msan_metadata_ptr_for_st
[clang] [llvm] [KMSAN] Enable on PowerPC64 (PR #73611)
NMiehlbradt wrote: Apologies, this fell off my radar. Thanks for your review @MaskRay. I don’t have commit access, can you merge this PR for me? https://github.com/llvm/llvm-project/pull/73611 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior in Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs() (PR #95195)
@@ -6447,7 +6447,7 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs( if (Inst.isInvalid()) return false; - bool AtLeastAsSpecialized; + bool AtLeastAsSpecialized = false; runWithSufficientStackSpace(Info.getLocation(), [&] { mizvekov wrote: runWithSufficientStackSpace is a small helper used to prevent stack exhaustion. https://github.com/llvm/llvm-project/pull/95195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior in Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs() (PR #95195)
mizvekov wrote: There is no potential UB, this is a false positive: this lambda will always be executed before runWithSufficientStackSpace returns. https://github.com/llvm/llvm-project/pull/95195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ARM][clang] Fix warning for VFP function calls from interrupts. (PR #91870)
chrisnc wrote: Ping @DavidSpickett @jthackray https://github.com/llvm/llvm-project/pull/91870 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add smcdeleg and ssccfg extensions (PR #95163)
https://github.com/dtcxzyw closed https://github.com/llvm/llvm-project/pull/95163 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 307d91e - [RISCV] Add smcdeleg and ssccfg extensions (#95163)
Author: Monad Date: 2024-06-12T12:43:39+08:00 New Revision: 307d91ee62f27e8f1c6ac27fdf014001ab1f4484 URL: https://github.com/llvm/llvm-project/commit/307d91ee62f27e8f1c6ac27fdf014001ab1f4484 DIFF: https://github.com/llvm/llvm-project/commit/307d91ee62f27e8f1c6ac27fdf014001ab1f4484.diff LOG: [RISCV] Add smcdeleg and ssccfg extensions (#95163) Specification: https://github.com/riscv/riscv-isa-manual/blob/main/src/smcdeleg.adoc `Ssccfg` introduces one new CSR `scountinhibit`. Added: Modified: clang/test/Preprocessor/riscv-target-features.c llvm/docs/RISCVUsage.rst llvm/docs/ReleaseNotes.rst llvm/lib/Target/RISCV/RISCVFeatures.td llvm/lib/Target/RISCV/RISCVSystemOperands.td llvm/test/CodeGen/RISCV/attributes.ll llvm/test/MC/RISCV/attribute-arch.s llvm/test/MC/RISCV/supervisor-csr-names.s llvm/unittests/TargetParser/RISCVISAInfoTest.cpp Removed: diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index 91307141e0406..576101b6ae50f 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -27,9 +27,11 @@ // CHECK-NOT: __riscv_shvstvala {{.*$}} // CHECK-NOT: __riscv_shvstvecd {{.*$}} // CHECK-NOT: __riscv_smaia {{.*$}} +// CHECK-NOT: __riscv_smcdeleg {{.*$}} // CHECK-NOT: __riscv_smepmp {{.*$}} // CHECK-NOT: __riscv_smstateen {{.*$}} // CHECK-NOT: __riscv_ssaia {{.*$}} +// CHECK-NOT: __riscv_ssccfg {{.*$}} // CHECK-NOT: __riscv_ssccptr {{.*$}} // CHECK-NOT: __riscv_sscofpmf {{.*$}} // CHECK-NOT: __riscv_sscounterenw {{.*$}} @@ -362,6 +364,14 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-SHVSTVECD-EXT %s // CHECK-SHVSTVECD-EXT: __riscv_shvstvecd 100{{$}} +// RUN: %clang --target=riscv32-unknown-linux-gnu \ +// RUN: -march=rv32issccfg -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SSCCFG-EXT %s +// RUN: %clang --target=riscv64-unknown-linux-gnu \ +// RUN: -march=rv64issccfg -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SSCCFG-EXT %s +// CHECK-SSCCFG-EXT: __riscv_ssccfg 100{{$}} + // RUN: %clang --target=riscv32-unknown-linux-gnu \ // RUN: -march=rv32issccptr -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-SSCCPTR-EXT %s @@ -1393,6 +1403,14 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-SSAIA-EXT %s // CHECK-SSAIA-EXT: __riscv_ssaia 100{{$}} +// RUN: %clang --target=riscv32 \ +// RUN: -march=rv32ismcdeleg1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s +// RUN: %clang --target=riscv64 \ +// RUN: -march=rv64ismcdeleg1p0 -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-SMCDELEG-EXT %s +// CHECK-SMCDELEG-EXT: __riscv_smcdeleg 100{{$}} + // RUN: %clang --target=riscv32 \ // RUN: -march=rv32ismepmp1p0 -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-SMEPMP-EXT %s diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst index ef06f80c747f9..ffe93d7569a71 100644 --- a/llvm/docs/RISCVUsage.rst +++ b/llvm/docs/RISCVUsage.rst @@ -99,9 +99,11 @@ on support follow. ``Shvstvala`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Shvstvecd`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Smaia`` Supported + ``Smcdeleg`` Supported ``Smepmp``Supported ``Smstateen`` Assembly Support ``Ssaia`` Supported + ``Ssccfg``Supported ``Ssccptr`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) ``Sscofpmf`` Assembly Support ``Sscounterenw`` Assembly Support (`See note <#riscv-profiles-extensions-note>`__) diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst index 50c43fef3ad12..4efede4609481 100644 --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -157,6 +157,7 @@ Changes to the RISC-V Backend * Processors that enable post reg-alloc scheduling (PostMachineScheduler) by default should use the `UsePostRAScheduler` subtarget feature. Setting `PostRAScheduler = 1` in the scheduler model will have no effect on the enabling of the PostMachineScheduler. * Zabha is no longer experimental. * B (the collection of the Zba, Zbb, Zbs extensions) is supported. +* Added smcdeleg and ssccfg extensions to -march. Changes to the WebAssembly Backend -- diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index 011edca019fd6..bb8c95829b9e0 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -859,6 +859,13 @@ def FeatureStdExtSmepmp : RISCVExtension<"smepmp", 1, 0, "'Smepmp' (Enhanced Physical Memory Protection)">; +def FeatureStdExtSmcdeleg +: RISCVExtension<"sm
[clang] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior in Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs() (PR #95195)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/95195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior… (PR #95195)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/95195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior… (PR #95195)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (smanna12) Changes … in Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs() This patch fixes a static analyzer bug where the boolean variable `AtLeastAsSpecialized` was used uninitialized. The variable is now explicitly initialized to false before its potential modification within a lambda function to ensure that it always holds a valid value when returned, preventing undefined behavior due to uninitialized variable usage in `Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs()`. --- Full diff: https://github.com/llvm/llvm-project/pull/95195.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+1-1) ``diff diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index befeb38e1fe5b..df0d6908d0a78 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -6447,7 +6447,7 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs( if (Inst.isInvalid()) return false; - bool AtLeastAsSpecialized; + bool AtLeastAsSpecialized = false; runWithSufficientStackSpace(Info.getLocation(), [&] { AtLeastAsSpecialized = ::FinishTemplateArgumentDeduction( `` https://github.com/llvm/llvm-project/pull/95195 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add Smcsrind and Sscsrind extension (PR #93952)
dtcxzyw wrote: Conflicting files > llvm/docs/ReleaseNotes.rst https://github.com/llvm/llvm-project/pull/93952 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior… (PR #95195)
https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/95195 … in Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs() This patch fixes a static analyzer bug where the boolean variable `AtLeastAsSpecialized` was used uninitialized. The variable is now explicitly initialized to false before its potential modification within a lambda function to ensure that it always holds a valid value when returned, preventing undefined behavior due to uninitialized variable usage in `Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs()`. >From d73bb37285e7ec440fe5906d7b0e8177ab9d61cb Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 21:38:47 -0700 Subject: [PATCH] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior in Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs() This patch fixes a static analyzer bug where the boolean variable `AtLeastAsSpecialized` was used uninitialized. The variable is now explicitly initialized to false before its potential modification within a lambda function to ensure that it always holds a valid value when returned, preventing undefined behavior due to uninitialized variable usage in `Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs()`. --- clang/lib/Sema/SemaTemplateDeduction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index befeb38e1fe5b..df0d6908d0a78 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -6447,7 +6447,7 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs( if (Inst.isInvalid()) return false; - bool AtLeastAsSpecialized; + bool AtLeastAsSpecialized = false; runWithSufficientStackSpace(Info.getLocation(), [&] { AtLeastAsSpecialized = ::FinishTemplateArgumentDeduction( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix potential null pointer dereferences in retain cycle detection (PR #95192)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/95192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix potential null pointer dereference in retain cycle detection (PR #95192)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/95192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix potential null pointer dereference in retain cycle detection (PR #95192)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/95192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix potential null pointer dereference in retain cycle detection (PR #95192)
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/95192 >From 6852bd6773c13dd9e573df460e74e2b7306c63f0 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 19:52:03 -0700 Subject: [PATCH 1/3] [Clang] Fix potential null pointer dereference in retain cycle detection This patch resolves a static analyzer bug where `S.getCurMethodDecl()` could return `nullptr` when calling getSelfDecl(() and was being dereferenced without a null check. The fix introduces a check for a non-null return value before accessing `getSelfDecl()` to ensure safe dereferencing. This change prevents undefined behavior in scenarios where the current method declaration is not available, thus enhancing the robustness of the retain cycle detection logic. --- clang/lib/Sema/SemaObjC.cpp | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index d396258cfc7d1..69c78f034bd43 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -848,12 +848,16 @@ static bool findRetainCycleOwner(Sema &S, Expr *e, RetainCycleOwner &owner) { owner.Indirect = true; if (pre->isSuperReceiver()) { -owner.Variable = S.getCurMethodDecl()->getSelfDecl(); -if (!owner.Variable) +if (const auto *CurMethodDecl = S.getCurMethodDecl()) { + owner.Variable = CurMethodDecl()->getSelfDecl(); + if (!owner.Variable) +return false; + owner.Loc = pre->getLocation(); + owner.Range = pre->getSourceRange(); + return true; +} else { return false; -owner.Loc = pre->getLocation(); -owner.Range = pre->getSourceRange(); -return true; +} } e = const_cast( cast(pre->getBase())->getSourceExpr()); >From dcf371b72e3d1fbfdeaa6658aebdcdabc7b6f4ae Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 20:08:45 -0700 Subject: [PATCH 2/3] Fix build errors --- clang/lib/Sema/SemaObjC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index 69c78f034bd43..65e297b3b1249 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -849,7 +849,7 @@ static bool findRetainCycleOwner(Sema &S, Expr *e, RetainCycleOwner &owner) { owner.Indirect = true; if (pre->isSuperReceiver()) { if (const auto *CurMethodDecl = S.getCurMethodDecl()) { - owner.Variable = CurMethodDecl()->getSelfDecl(); + owner.Variable = CurMethodDecl->getSelfDecl(); if (!owner.Variable) return false; owner.Loc = pre->getLocation(); >From 969d0a85dd0516e914b4d9fad00c9350f5009a2e Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 21:18:28 -0700 Subject: [PATCH 3/3] Add new bug --- clang/lib/Sema/SemaObjC.cpp | 10 +++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index 65e297b3b1249..4b951ea536034 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -1173,9 +1173,13 @@ void SemaObjC::checkRetainCycles(ObjCMessageExpr *msg) { return; } else { assert(msg->getReceiverKind() == ObjCMessageExpr::SuperInstance); -owner.Variable = SemaRef.getCurMethodDecl()->getSelfDecl(); -owner.Loc = msg->getSuperLoc(); -owner.Range = msg->getSuperLoc(); +if (const auto *CurMethodDecl = SemaRef.getCurMethodDecl()) { + owner.Variable = CurMethodDecl->getSelfDecl(); + owner.Loc = msg->getSuperLoc(); + owner.Range = msg->getSuperLoc(); +} else { + return; +} } // Check whether the receiver is captured by any of the arguments. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add riscv_atomic.h and Zawrs/Zalrsc builtins (PR #94578)
efriedma-quic wrote: > I don't know much about there intrinsics on ARM, what are the stronger > guarantees? The Arm specifies that there's a memory reservation, and you can write whatever operations you want as long as you don't break that reservation. And the reservation is usually only a few bytes. RISC-V specifically only guarantees behavior for sequences of integer instructions. https://github.com/llvm/llvm-project/pull/94578 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent null pointer dereferences in SVE tuple functions (PR #94267)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/94267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent null pointer dereferences in SVE tuple functions (PR #94267)
@@ -10211,8 +10211,8 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, "Expects TypleFlag isTupleSet or TypeFlags.isTupleSet()"); unsigned I = cast(Ops[1])->getSExtValue(); - auto *SingleVecTy = dyn_cast( - TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); + auto *SingleVecTy = cast( smanna12 wrote: Thank you @CarolineConcatto for reviews. I have updated patch. Could you please review again? >>Is it possible to add a test for this change too? The issues are reported by Static Analyzer tool, I am not sure how we can add a test here to verify the fix. @tahonermann, any opinion? https://github.com/llvm/llvm-project/pull/94267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent null pointer dereferences in SVE tuple functions (PR #94267)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/94267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent null pointer dereferences in SVE tuple functions (PR #94267)
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/94267 >From 14e4f23d90d3a1590de5b9a1350ecf56aa89cc17 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Mon, 3 Jun 2024 11:17:33 -0700 Subject: [PATCH 1/4] [Clang] Prevent null pointer dereferencein SVE tuple functions This patch replaces dyn_cast<> with cast<> for obtaining ScalableVectorType pointers in the EmitSVETupleSetOrGet() and EmitSVETupleCreate() functions to ensure that the code expects valid ScalableVectorType instances and will cause an assertion if the cast is invalid, preventing possible null pointer dereferences and improving codes safety. --- clang/lib/CodeGen/CGBuiltin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 37d0c478e0330..3ba9f4693170f 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -10211,7 +10211,7 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, "Expects TypleFlag isTupleSet or TypeFlags.isTupleSet()"); unsigned I = cast(Ops[1])->getSExtValue(); - auto *SingleVecTy = dyn_cast( + auto *SingleVecTy = cast( TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); Value *Idx = ConstantInt::get(CGM.Int64Ty, I * SingleVecTy->getMinNumElements()); @@ -10226,7 +10226,7 @@ Value *CodeGenFunction::EmitSVETupleCreate(const SVETypeFlags &TypeFlags, ArrayRef Ops) { assert(TypeFlags.isTupleCreate() && "Expects TypleFlag isTupleCreate"); - auto *SrcTy = dyn_cast(Ops[0]->getType()); + auto *SrcTy = cast(Ops[0]->getType()); unsigned MinElts = SrcTy->getMinNumElements(); Value *Call = llvm::PoisonValue::get(Ty); for (unsigned I = 0; I < Ops.size(); I++) { >From 2e3942a0acee4a4c9586128d9b9c6019d008cfb7 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Mon, 3 Jun 2024 11:31:49 -0700 Subject: [PATCH 2/4] Fix Clang format error --- clang/lib/CodeGen/CGBuiltin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 3ba9f4693170f..cc366241ac804 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -10212,7 +10212,7 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, unsigned I = cast(Ops[1])->getSExtValue(); auto *SingleVecTy = cast( - TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); + TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); Value *Idx = ConstantInt::get(CGM.Int64Ty, I * SingleVecTy->getMinNumElements()); >From 74c3433eb3296bacd31fd852fa50006e9efffdc3 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 20:42:09 -0700 Subject: [PATCH 3/4] Update patch --- clang/lib/CodeGen/CGBuiltin.cpp | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index cc366241ac804..204fbaf12daa4 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -10208,11 +10208,14 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, llvm::Type *Ty, ArrayRef Ops) { assert((TypeFlags.isTupleSet() || TypeFlags.isTupleGet()) && - "Expects TypleFlag isTupleSet or TypeFlags.isTupleSet()"); + "Expects TypleFlags.isTupleSet() or TypeFlags.isTupleGet()"); unsigned I = cast(Ops[1])->getSExtValue(); - auto *SingleVecTy = cast( + auto *SingleVecTy = dyn_cast( TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); + + if (!SingleVecTy) +retutn nullptr; Value *Idx = ConstantInt::get(CGM.Int64Ty, I * SingleVecTy->getMinNumElements()); >From 0d5eb5125079035d36b5135b408ef2f34ef387c0 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 20:52:13 -0700 Subject: [PATCH 4/4] Fix build errors --- clang/lib/CodeGen/CGBuiltin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 204fbaf12daa4..3fa8cf7bf02aa 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -10215,7 +10215,7 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); if (!SingleVecTy) -retutn nullptr; +return nullptr; Value *Idx = ConstantInt::get(CGM.Int64Ty, I * SingleVecTy->getMinNumElements()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent null pointer dereferences in SVE tuple functions (PR #94267)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/94267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent null pointer dereferences in SVE tuple functions (PR #94267)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/94267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Prevent null pointer dereferences in SVE tuple functions (PR #94267)
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/94267 >From 14e4f23d90d3a1590de5b9a1350ecf56aa89cc17 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Mon, 3 Jun 2024 11:17:33 -0700 Subject: [PATCH 1/3] [Clang] Prevent null pointer dereferencein SVE tuple functions This patch replaces dyn_cast<> with cast<> for obtaining ScalableVectorType pointers in the EmitSVETupleSetOrGet() and EmitSVETupleCreate() functions to ensure that the code expects valid ScalableVectorType instances and will cause an assertion if the cast is invalid, preventing possible null pointer dereferences and improving codes safety. --- clang/lib/CodeGen/CGBuiltin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 37d0c478e0330..3ba9f4693170f 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -10211,7 +10211,7 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, "Expects TypleFlag isTupleSet or TypeFlags.isTupleSet()"); unsigned I = cast(Ops[1])->getSExtValue(); - auto *SingleVecTy = dyn_cast( + auto *SingleVecTy = cast( TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); Value *Idx = ConstantInt::get(CGM.Int64Ty, I * SingleVecTy->getMinNumElements()); @@ -10226,7 +10226,7 @@ Value *CodeGenFunction::EmitSVETupleCreate(const SVETypeFlags &TypeFlags, ArrayRef Ops) { assert(TypeFlags.isTupleCreate() && "Expects TypleFlag isTupleCreate"); - auto *SrcTy = dyn_cast(Ops[0]->getType()); + auto *SrcTy = cast(Ops[0]->getType()); unsigned MinElts = SrcTy->getMinNumElements(); Value *Call = llvm::PoisonValue::get(Ty); for (unsigned I = 0; I < Ops.size(); I++) { >From 2e3942a0acee4a4c9586128d9b9c6019d008cfb7 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Mon, 3 Jun 2024 11:31:49 -0700 Subject: [PATCH 2/3] Fix Clang format error --- clang/lib/CodeGen/CGBuiltin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 3ba9f4693170f..cc366241ac804 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -10212,7 +10212,7 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, unsigned I = cast(Ops[1])->getSExtValue(); auto *SingleVecTy = cast( - TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); + TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); Value *Idx = ConstantInt::get(CGM.Int64Ty, I * SingleVecTy->getMinNumElements()); >From 74c3433eb3296bacd31fd852fa50006e9efffdc3 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 20:42:09 -0700 Subject: [PATCH 3/3] Update patch --- clang/lib/CodeGen/CGBuiltin.cpp | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index cc366241ac804..204fbaf12daa4 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -10208,11 +10208,14 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, llvm::Type *Ty, ArrayRef Ops) { assert((TypeFlags.isTupleSet() || TypeFlags.isTupleGet()) && - "Expects TypleFlag isTupleSet or TypeFlags.isTupleSet()"); + "Expects TypleFlags.isTupleSet() or TypeFlags.isTupleGet()"); unsigned I = cast(Ops[1])->getSExtValue(); - auto *SingleVecTy = cast( + auto *SingleVecTy = dyn_cast( TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty); + + if (!SingleVecTy) +retutn nullptr; Value *Idx = ConstantInt::get(CGM.Int64Ty, I * SingleVecTy->getMinNumElements()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)
@@ -6853,6 +6853,13 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) DI->completeUnusedClass(*CRD); } +// If we're emitting a dynamic class from the importable module we're +// emitting, we always need to emit the virtual table according to the ABI +// requirement. +if (CRD->getDefinition() && CRD->isDynamicClass() && +CRD->isInCurrentModuleUnit()) + EmitVTable(CRD); efriedma-quic wrote: So DefineUsedVTables is called, but the ASTWriter eats the call without actually recording the fact anywhere? Okay, that makes more sense. So I guess that gives a potential alternate approach; we could teach ASTWriter to record the fact that HandleVTable was called, and replay it later. But if we can reliably handle emitting vtables in EmitTopLevelDecl, it's probably simpler to just eliminate HandleVTable. https://github.com/llvm/llvm-project/pull/75912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)
@@ -1227,7 +1241,8 @@ void CodeGenModule::EmitDeferredVTables() { #endif for (const CXXRecordDecl *RD : DeferredVTables) -if (shouldEmitVTableAtEndOfTranslationUnit(*this, RD)) +if (shouldEmitVTableAtEndOfTranslationUnit(*this, RD) && +!RD->shouldEmitInExternalSource()) efriedma-quic wrote: I think this is redundant? https://github.com/llvm/llvm-project/pull/75912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add winsysroot alias to the GNU driver (PR #94731)
https://github.com/Andarwinux updated https://github.com/llvm/llvm-project/pull/94731 >From f44404f33675f4e72157c270954a1bf65881079c Mon Sep 17 00:00:00 2001 From: Andarwinux <144242044+andarwi...@users.noreply.github.com> Date: Fri, 7 Jun 2024 07:07:40 + Subject: [PATCH] [Driver] Add winsysroot alias to the GNU driver fixes #91216 --- clang/include/clang/Driver/Options.td | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d44faa55c456f..1cce7a5146dd8 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -8569,6 +8569,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">, Alias<_SLASH_winsdkdir>; def : Separate<["-"], "Xmicrosoft-windows-sdk-version">, Alias<_SLASH_winsdkversion>; +def : Separate<["-"], "Xmicrosoft-windows-sys-root">, +Alias<_SLASH_winsysroot>; // Ignored: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix potential null pointer dereference in retain cycle detection (PR #95192)
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/95192 >From 6852bd6773c13dd9e573df460e74e2b7306c63f0 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 19:52:03 -0700 Subject: [PATCH 1/2] [Clang] Fix potential null pointer dereference in retain cycle detection This patch resolves a static analyzer bug where `S.getCurMethodDecl()` could return `nullptr` when calling getSelfDecl(() and was being dereferenced without a null check. The fix introduces a check for a non-null return value before accessing `getSelfDecl()` to ensure safe dereferencing. This change prevents undefined behavior in scenarios where the current method declaration is not available, thus enhancing the robustness of the retain cycle detection logic. --- clang/lib/Sema/SemaObjC.cpp | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index d396258cfc7d1..69c78f034bd43 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -848,12 +848,16 @@ static bool findRetainCycleOwner(Sema &S, Expr *e, RetainCycleOwner &owner) { owner.Indirect = true; if (pre->isSuperReceiver()) { -owner.Variable = S.getCurMethodDecl()->getSelfDecl(); -if (!owner.Variable) +if (const auto *CurMethodDecl = S.getCurMethodDecl()) { + owner.Variable = CurMethodDecl()->getSelfDecl(); + if (!owner.Variable) +return false; + owner.Loc = pre->getLocation(); + owner.Range = pre->getSourceRange(); + return true; +} else { return false; -owner.Loc = pre->getLocation(); -owner.Range = pre->getSourceRange(); -return true; +} } e = const_cast( cast(pre->getBase())->getSourceExpr()); >From dcf371b72e3d1fbfdeaa6658aebdcdabc7b6f4ae Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 20:08:45 -0700 Subject: [PATCH 2/2] Fix build errors --- clang/lib/Sema/SemaObjC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index 69c78f034bd43..65e297b3b1249 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -849,7 +849,7 @@ static bool findRetainCycleOwner(Sema &S, Expr *e, RetainCycleOwner &owner) { owner.Indirect = true; if (pre->isSuperReceiver()) { if (const auto *CurMethodDecl = S.getCurMethodDecl()) { - owner.Variable = CurMethodDecl()->getSelfDecl(); + owner.Variable = CurMethodDecl->getSelfDecl(); if (!owner.Variable) return false; owner.Loc = pre->getLocation(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix potential null pointer dereference in retain cycle detection (PR #95192)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (smanna12) Changes This patch resolves a static analyzer bug where `S.getCurMethodDecl()` could return `nullptr` when calling `getSelfDecl(()` and was being dereferenced without a null check. The fix introduces a check for a non-null return value before accessing `getSelfDecl()` to ensure safe dereferencing. This change prevents undefined behavior in scenarios where the current method declaration is not available, thus enhancing the robustness of the retain cycle detection logic. --- Full diff: https://github.com/llvm/llvm-project/pull/95192.diff 1 Files Affected: - (modified) clang/lib/Sema/SemaObjC.cpp (+9-5) ``diff diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index d396258cfc7d1..69c78f034bd43 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -848,12 +848,16 @@ static bool findRetainCycleOwner(Sema &S, Expr *e, RetainCycleOwner &owner) { owner.Indirect = true; if (pre->isSuperReceiver()) { -owner.Variable = S.getCurMethodDecl()->getSelfDecl(); -if (!owner.Variable) +if (const auto *CurMethodDecl = S.getCurMethodDecl()) { + owner.Variable = CurMethodDecl()->getSelfDecl(); + if (!owner.Variable) +return false; + owner.Loc = pre->getLocation(); + owner.Range = pre->getSourceRange(); + return true; +} else { return false; -owner.Loc = pre->getLocation(); -owner.Range = pre->getSourceRange(); -return true; +} } e = const_cast( cast(pre->getBase())->getSourceExpr()); `` https://github.com/llvm/llvm-project/pull/95192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix potential null pointer dereference in retain cycle detection (PR #95192)
https://github.com/smanna12 edited https://github.com/llvm/llvm-project/pull/95192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix potential null pointer dereference in retain cycle detection (PR #95192)
https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/95192 This patch resolves a static analyzer bug where `S.getCurMethodDecl()` could return `nullptr` when calling getSelfDecl(() and was being dereferenced without a null check. The fix introduces a check for a non-null return value before accessing `getSelfDecl()` to ensure safe dereferencing. This change prevents undefined behavior in scenarios where the current method declaration is not available, thus enhancing the robustness of the retain cycle detection logic. >From 6852bd6773c13dd9e573df460e74e2b7306c63f0 Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Tue, 11 Jun 2024 19:52:03 -0700 Subject: [PATCH] [Clang] Fix potential null pointer dereference in retain cycle detection This patch resolves a static analyzer bug where `S.getCurMethodDecl()` could return `nullptr` when calling getSelfDecl(() and was being dereferenced without a null check. The fix introduces a check for a non-null return value before accessing `getSelfDecl()` to ensure safe dereferencing. This change prevents undefined behavior in scenarios where the current method declaration is not available, thus enhancing the robustness of the retain cycle detection logic. --- clang/lib/Sema/SemaObjC.cpp | 14 +- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index d396258cfc7d1..69c78f034bd43 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -848,12 +848,16 @@ static bool findRetainCycleOwner(Sema &S, Expr *e, RetainCycleOwner &owner) { owner.Indirect = true; if (pre->isSuperReceiver()) { -owner.Variable = S.getCurMethodDecl()->getSelfDecl(); -if (!owner.Variable) +if (const auto *CurMethodDecl = S.getCurMethodDecl()) { + owner.Variable = CurMethodDecl()->getSelfDecl(); + if (!owner.Variable) +return false; + owner.Loc = pre->getLocation(); + owner.Range = pre->getSourceRange(); + return true; +} else { return false; -owner.Loc = pre->getLocation(); -owner.Range = pre->getSourceRange(); -return true; +} } e = const_cast( cast(pre->getBase())->getSourceExpr()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StructuralEquivalence] improve NTTP and CXXDependentScopeMemberExpr comparison (PR #95190)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/95190 >From ba081d51a0cc803188760eec2847bfc73d2192b8 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 12 Jun 2024 09:47:16 +0800 Subject: [PATCH] [StructuralEquivalence] improve NTTP and CXXDependentScopeMemberExpr comparison --- clang/lib/AST/ASTStructuralEquivalence.cpp| 14 - .../AST/StructuralEquivalenceTest.cpp | 57 ++- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index d56bf21b459e0..37555c324282f 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -348,6 +348,15 @@ class StmtComparer { return true; } + bool IsStmtEquivalent(const CXXDependentScopeMemberExpr *E1, +const CXXDependentScopeMemberExpr *E2) { +if (!IsStructurallyEquivalent(Context, E1->getMember(), E2->getMember())) { + return false; +} +return IsStructurallyEquivalent(Context, E1->getBaseType(), +E2->getBaseType()); + } + bool IsStmtEquivalent(const UnaryExprOrTypeTraitExpr *E1, const UnaryExprOrTypeTraitExpr *E2) { if (E1->getKind() != E2->getKind()) @@ -1997,7 +2006,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } return false; } - + if (!Context.IgnoreTemplateParmDepth && D1->getDepth() != D2->getDepth()) +return false; + if (D1->getIndex() != D2->getIndex()) +return false; // Check types. if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType())) { if (Context.Complain) { diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 91dd717d7b25e..952c83be0cb64 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1877,6 +1877,34 @@ TEST_F(StructuralEquivalenceCacheTest, VarDeclWithDifferentStorageClassNoEq) { EXPECT_FALSE(Ctx.IsEquivalent(Var.first, Var.second)); } +TEST_F(StructuralEquivalenceCacheTest, + NonTypeTemplateParmWithDifferentPositionNoEq) { + auto TU = makeTuDecls( + R"( + template + struct A { +template +void foo() {} + }; + )", + R"( + template + struct A { +template +void foo() {} + }; + )", + Lang_CXX03); + + StructuralEquivalenceContext Ctx( + get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(), + NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false); + + auto NTTP = findDeclPair( + TU, nonTypeTemplateParmDecl(hasName("T"))); + EXPECT_FALSE(Ctx.IsEquivalent(NTTP.first, NTTP.second)); +} + TEST_F(StructuralEquivalenceCacheTest, VarDeclWithInitNoEq) { auto TU = makeTuDecls( R"( @@ -2441,8 +2469,7 @@ TEST_F(StructuralEquivalenceStmtTest, NonTypeTemplateParm) { void foo(A); )", Lang_CXX11); - // FIXME: These should not match, - EXPECT_TRUE(testStructuralMatch(t)); + EXPECT_FALSE(testStructuralMatch(t)); } TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookupDifferentName) { @@ -2595,5 +2622,31 @@ TEST_F(StructuralEquivalenceStmtTest, DeclRefExpr) { EXPECT_FALSE(testStructuralMatch(t)); } +TEST_F(StructuralEquivalenceCacheTest, CXXDependentScopeMemberExprNoEq) { + auto S = makeStmts( + R"( + template + void foo() { +(void)T().x; + } + struct A { int x; }; + void bar() { +foo(); + } + )", + R"( + template + void foo() { +(void)T().y; + } + struct A { int y; }; + void bar() { +foo(); + } + )", + Lang_CXX11, cxxDependentScopeMemberExpr()); + EXPECT_FALSE(testStructuralMatch(S)); +} + } // end namespace ast_matchers } // end namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [RISCV] Make M imply Zmmul (PR #95070)
jacquesguan wrote: > We intentionally didn't do this because it makes LLVM not work with binutils > that doesn't know about Zmmul. Maybe enough time has passed that it is no > longer an issue? Since Zmmul was ratified at june 2022, I think it's OK to update it now. https://github.com/llvm/llvm-project/pull/95070 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in annotating lambda l_square (PR #95084)
@@ -1591,6 +1591,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) { EXPECT_TOKEN(Tokens[15], tok::arrow, TT_TrailingReturnArrow); EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace); + Tokens = annotate("auto l = [] -> struct S { return {}; };"); owenca wrote: Not really. I removed the assignment. https://github.com/llvm/llvm-project/pull/95084 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in annotating lambda l_square (PR #95084)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/95084 >From b89f8a5bcbf525d779565219951359162655929e Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 11 Jun 2024 01:32:32 -0700 Subject: [PATCH 1/2] [clang-format] Fix a bug in annotating lambda l_square Fixes #95072. --- clang/lib/Format/UnwrappedLineParser.cpp | 2 ++ clang/unittests/Format/TokenAnnotatorTest.cpp | 6 ++ 2 files changed, 8 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index eb96b54ec4c96..08387d2e08ee0 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2257,6 +2257,8 @@ bool UnwrappedLineParser::tryToParseLambda() { break; case tok::kw_auto: case tok::kw_class: +case tok::kw_struct: +case tok::kw_union: case tok::kw_template: case tok::kw_typename: case tok::amp: diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 3d609a1f041bc..0a1fb8c657ceb 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1591,6 +1591,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) { EXPECT_TOKEN(Tokens[15], tok::arrow, TT_TrailingReturnArrow); EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace); + Tokens = annotate("auto l = [] -> struct S { return {}; };"); + ASSERT_EQ(Tokens.size(), 16u) << Tokens; + EXPECT_TOKEN(Tokens[3], tok::l_square, TT_LambdaLSquare); + EXPECT_TOKEN(Tokens[5], tok::arrow, TT_TrailingReturnArrow); + EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_LambdaLBrace); + Tokens = annotate("[] () {}"); ASSERT_EQ(Tokens.size(), 11u) << Tokens; EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare); >From 14cd4ea57ed78a5f08780882f5ec5d3d237b0316 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 11 Jun 2024 19:16:54 -0700 Subject: [PATCH 2/2] Simplify the test case. --- clang/unittests/Format/TokenAnnotatorTest.cpp | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 0a1fb8c657ceb..27b903468de4b 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1585,18 +1585,18 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) { EXPECT_TOKEN(Tokens[2], tok::arrow, TT_TrailingReturnArrow); EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_LambdaLBrace); + Tokens = annotate("[] -> struct S { return {}; }"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare); + EXPECT_TOKEN(Tokens[2], tok::arrow, TT_TrailingReturnArrow); + EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace); + Tokens = annotate("foo([&](u32 bar) __attribute__((attr)) -> void {});"); ASSERT_EQ(Tokens.size(), 22u) << Tokens; EXPECT_TOKEN(Tokens[2], tok::l_square, TT_LambdaLSquare); EXPECT_TOKEN(Tokens[15], tok::arrow, TT_TrailingReturnArrow); EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace); - Tokens = annotate("auto l = [] -> struct S { return {}; };"); - ASSERT_EQ(Tokens.size(), 16u) << Tokens; - EXPECT_TOKEN(Tokens[3], tok::l_square, TT_LambdaLSquare); - EXPECT_TOKEN(Tokens[5], tok::arrow, TT_TrailingReturnArrow); - EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_LambdaLBrace); - Tokens = annotate("[] () {}"); ASSERT_EQ(Tokens.size(), 11u) << Tokens; EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StructuralEquivalence] improve NTTP and CXXDependentScopeMemberExpr comparison (PR #95190)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/95190 >From 157f664408062da41f4d82d20ddc06e0e563fe31 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 12 Jun 2024 09:47:16 +0800 Subject: [PATCH] [StructuralEquivalence] improve NTTP and CXXDependentScopeMemberExpr comparison --- clang/lib/AST/ASTStructuralEquivalence.cpp| 14 +- .../AST/StructuralEquivalenceTest.cpp | 49 ++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index d56bf21b459e0..37555c324282f 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -348,6 +348,15 @@ class StmtComparer { return true; } + bool IsStmtEquivalent(const CXXDependentScopeMemberExpr *E1, +const CXXDependentScopeMemberExpr *E2) { +if (!IsStructurallyEquivalent(Context, E1->getMember(), E2->getMember())) { + return false; +} +return IsStructurallyEquivalent(Context, E1->getBaseType(), +E2->getBaseType()); + } + bool IsStmtEquivalent(const UnaryExprOrTypeTraitExpr *E1, const UnaryExprOrTypeTraitExpr *E2) { if (E1->getKind() != E2->getKind()) @@ -1997,7 +2006,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } return false; } - + if (!Context.IgnoreTemplateParmDepth && D1->getDepth() != D2->getDepth()) +return false; + if (D1->getIndex() != D2->getIndex()) +return false; // Check types. if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType())) { if (Context.Complain) { diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 91dd717d7b25e..cea1ce87a7eb9 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1877,6 +1877,34 @@ TEST_F(StructuralEquivalenceCacheTest, VarDeclWithDifferentStorageClassNoEq) { EXPECT_FALSE(Ctx.IsEquivalent(Var.first, Var.second)); } +TEST_F(StructuralEquivalenceCacheTest, + NonTypeTemplateParmWithDifferentPositionNoEq) { + auto TU = makeTuDecls( + R"( + template + struct A { +template +void foo() {} + }; + )", + R"( + template + struct A { +template +void foo() {} + }; + )", + Lang_CXX03); + + StructuralEquivalenceContext Ctx( + get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(), + NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false); + + auto NTTP = findDeclPair( + TU, nonTypeTemplateParmDecl(hasName("T"))); + EXPECT_FALSE(Ctx.IsEquivalent(NTTP.first, NTTP.second)); +} + TEST_F(StructuralEquivalenceCacheTest, VarDeclWithInitNoEq) { auto TU = makeTuDecls( R"( @@ -2441,8 +2469,7 @@ TEST_F(StructuralEquivalenceStmtTest, NonTypeTemplateParm) { void foo(A); )", Lang_CXX11); - // FIXME: These should not match, - EXPECT_TRUE(testStructuralMatch(t)); + EXPECT_FALSE(testStructuralMatch(t)); } TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookupDifferentName) { @@ -2595,5 +2622,23 @@ TEST_F(StructuralEquivalenceStmtTest, DeclRefExpr) { EXPECT_FALSE(testStructuralMatch(t)); } +TEST_F(StructuralEquivalenceCacheTest, CXXDependentScopeMemberExprNoEq) { + auto S = makeStmts( + R"( + template + void foo() { +T().x; + } + )", + R"( + template + void foo() { +T().y; + } + )", + Lang_CXX11, cxxDependentScopeMemberExpr()); + EXPECT_FALSE(testStructuralMatch(S)); +} + } // end namespace ast_matchers } // end namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StructuralEquivalence] improve NTTP and CXXDependentScopeMemberExpr comparison (PR #95190)
https://github.com/mizvekov approved this pull request. LGTM, Thanks! https://github.com/llvm/llvm-project/pull/95190 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StructuralEquivalence] improve NTTP and CXXDependentScopeMemberExpr comparison (PR #95190)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Qizhi Hu (jcsxky) Changes improve `ASTStructuralEquivalenceTest`: 1. compare the depth and index of NTTP 2. provide comparison of `CXXDependentScopeMemberExpr` to `StmtCompare`. --- Full diff: https://github.com/llvm/llvm-project/pull/95190.diff 2 Files Affected: - (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+13-1) - (modified) clang/unittests/AST/StructuralEquivalenceTest.cpp (+50-2) ``diff diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index d56bf21b459e0..37555c324282f 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -348,6 +348,15 @@ class StmtComparer { return true; } + bool IsStmtEquivalent(const CXXDependentScopeMemberExpr *E1, +const CXXDependentScopeMemberExpr *E2) { +if (!IsStructurallyEquivalent(Context, E1->getMember(), E2->getMember())) { + return false; +} +return IsStructurallyEquivalent(Context, E1->getBaseType(), +E2->getBaseType()); + } + bool IsStmtEquivalent(const UnaryExprOrTypeTraitExpr *E1, const UnaryExprOrTypeTraitExpr *E2) { if (E1->getKind() != E2->getKind()) @@ -1997,7 +2006,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } return false; } - + if (!Context.IgnoreTemplateParmDepth && D1->getDepth() != D2->getDepth()) +return false; + if (D1->getIndex() != D2->getIndex()) +return false; // Check types. if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType())) { if (Context.Complain) { diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 91dd717d7b25e..55b2580bfce3b 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1877,6 +1877,34 @@ TEST_F(StructuralEquivalenceCacheTest, VarDeclWithDifferentStorageClassNoEq) { EXPECT_FALSE(Ctx.IsEquivalent(Var.first, Var.second)); } +TEST_F(StructuralEquivalenceCacheTest, + NonTypeTemplateParmWithDifferentPositionNoEq) { + auto TU = makeTuDecls( + R"( + template + struct A { +template +void foo() {} + }; + )", + R"( + template + struct A { +template +void foo() {} + }; + )", + Lang_CXX03); + + StructuralEquivalenceContext Ctx( + get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(), + NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false); + + auto NTTP = findDeclPair( + TU, nonTypeTemplateParmDecl(hasName("T"))); + EXPECT_FALSE(Ctx.IsEquivalent(NTTP.first, NTTP.second)); +} + TEST_F(StructuralEquivalenceCacheTest, VarDeclWithInitNoEq) { auto TU = makeTuDecls( R"( @@ -2441,8 +2469,7 @@ TEST_F(StructuralEquivalenceStmtTest, NonTypeTemplateParm) { void foo(A); )", Lang_CXX11); - // FIXME: These should not match, - EXPECT_TRUE(testStructuralMatch(t)); + EXPECT_FALSE(testStructuralMatch(t)); } TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookupDifferentName) { @@ -2595,5 +2622,26 @@ TEST_F(StructuralEquivalenceStmtTest, DeclRefExpr) { EXPECT_FALSE(testStructuralMatch(t)); } +const internal::VariadicDynCastAllOfMatcher +cxxDependentScopeMemberExpr; + +TEST_F(StructuralEquivalenceCacheTest, CXXDependentScopeMemberExprNoEq) { + auto S = makeStmts( + R"( + template + void foo() { +T().x; + } + )", + R"( + template + void foo() { +T().y; + } + )", + Lang_CXX11, cxxDependentScopeMemberExpr()); + EXPECT_FALSE(testStructuralMatch(S)); +} + } // end namespace ast_matchers } // end namespace clang `` https://github.com/llvm/llvm-project/pull/95190 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StructuralEquivalence] improve NTTP and CXXDependentScopeMemberExpr comparison (PR #95190)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/95190 improve `ASTStructuralEquivalenceTest`: 1. compare the depth and index of NTTP 2. provide comparison of `CXXDependentScopeMemberExpr` to `StmtCompare`. >From 644c6e8499285e5b3ab17193ec63eed051dae583 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Wed, 12 Jun 2024 09:47:16 +0800 Subject: [PATCH] [StructuralEquivalence] improve NTTP and CXXDependentScopeMemberExpr comparison --- clang/lib/AST/ASTStructuralEquivalence.cpp| 14 - .../AST/StructuralEquivalenceTest.cpp | 52 ++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index d56bf21b459e0..37555c324282f 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -348,6 +348,15 @@ class StmtComparer { return true; } + bool IsStmtEquivalent(const CXXDependentScopeMemberExpr *E1, +const CXXDependentScopeMemberExpr *E2) { +if (!IsStructurallyEquivalent(Context, E1->getMember(), E2->getMember())) { + return false; +} +return IsStructurallyEquivalent(Context, E1->getBaseType(), +E2->getBaseType()); + } + bool IsStmtEquivalent(const UnaryExprOrTypeTraitExpr *E1, const UnaryExprOrTypeTraitExpr *E2) { if (E1->getKind() != E2->getKind()) @@ -1997,7 +2006,10 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, } return false; } - + if (!Context.IgnoreTemplateParmDepth && D1->getDepth() != D2->getDepth()) +return false; + if (D1->getIndex() != D2->getIndex()) +return false; // Check types. if (!IsStructurallyEquivalent(Context, D1->getType(), D2->getType())) { if (Context.Complain) { diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 91dd717d7b25e..55b2580bfce3b 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1877,6 +1877,34 @@ TEST_F(StructuralEquivalenceCacheTest, VarDeclWithDifferentStorageClassNoEq) { EXPECT_FALSE(Ctx.IsEquivalent(Var.first, Var.second)); } +TEST_F(StructuralEquivalenceCacheTest, + NonTypeTemplateParmWithDifferentPositionNoEq) { + auto TU = makeTuDecls( + R"( + template + struct A { +template +void foo() {} + }; + )", + R"( + template + struct A { +template +void foo() {} + }; + )", + Lang_CXX03); + + StructuralEquivalenceContext Ctx( + get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(), + NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false); + + auto NTTP = findDeclPair( + TU, nonTypeTemplateParmDecl(hasName("T"))); + EXPECT_FALSE(Ctx.IsEquivalent(NTTP.first, NTTP.second)); +} + TEST_F(StructuralEquivalenceCacheTest, VarDeclWithInitNoEq) { auto TU = makeTuDecls( R"( @@ -2441,8 +2469,7 @@ TEST_F(StructuralEquivalenceStmtTest, NonTypeTemplateParm) { void foo(A); )", Lang_CXX11); - // FIXME: These should not match, - EXPECT_TRUE(testStructuralMatch(t)); + EXPECT_FALSE(testStructuralMatch(t)); } TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookupDifferentName) { @@ -2595,5 +2622,26 @@ TEST_F(StructuralEquivalenceStmtTest, DeclRefExpr) { EXPECT_FALSE(testStructuralMatch(t)); } +const internal::VariadicDynCastAllOfMatcher +cxxDependentScopeMemberExpr; + +TEST_F(StructuralEquivalenceCacheTest, CXXDependentScopeMemberExprNoEq) { + auto S = makeStmts( + R"( + template + void foo() { +T().x; + } + )", + R"( + template + void foo() { +T().y; + } + )", + Lang_CXX11, cxxDependentScopeMemberExpr()); + EXPECT_FALSE(testStructuralMatch(S)); +} + } // end namespace ast_matchers } // end namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
https://github.com/owenca deleted https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
@@ -584,6 +584,23 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator); } +TEST_F(TokenAnnotatorTest, UnderstandsTemplateTemplateParameters) { + auto Tokens = annotate("template typename X,\n" + " template typename Y,\n" + " typename... T>\n" + "class A {};"); + ASSERT_EQ(Tokens.size(), 28u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[3], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser); + EXPECT_EQ(Tokens[6]->ClosesTemplateDeclaration, 0u); + EXPECT_TOKEN(Tokens[11], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[14], tok::greater, TT_TemplateCloser); + EXPECT_EQ(Tokens[14]->ClosesTemplateDeclaration, 0u); + EXPECT_TOKEN(Tokens[21], tok::greater, TT_TemplateCloser); + EXPECT_EQ(Tokens[21]->ClosesTemplateDeclaration, 1u); owenca wrote: ```suggestion EXPECT_TRUE(Tokens[21]->ClosesTemplateDeclaration); ``` https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
@@ -584,6 +584,23 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator); } +TEST_F(TokenAnnotatorTest, UnderstandsTemplateTemplateParameters) { + auto Tokens = annotate("template typename X,\n" + " template typename Y,\n" + " typename... T>\n" + "class A {};"); + ASSERT_EQ(Tokens.size(), 28u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[3], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser); + EXPECT_EQ(Tokens[6]->ClosesTemplateDeclaration, 0u); + EXPECT_TOKEN(Tokens[11], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[14], tok::greater, TT_TemplateCloser); + EXPECT_EQ(Tokens[14]->ClosesTemplateDeclaration, 0u); owenca wrote: Ditto. https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
@@ -584,6 +584,23 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator); } +TEST_F(TokenAnnotatorTest, UnderstandsTemplateTemplateParameters) { + auto Tokens = annotate("template typename X,\n" + " template typename Y,\n" + " typename... T>\n" + "class A {};"); + ASSERT_EQ(Tokens.size(), 28u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[3], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser); + EXPECT_EQ(Tokens[6]->ClosesTemplateDeclaration, 0u); owenca wrote: ```suggestion EXPECT_FALSE(Tokens[6]->ClosesTemplateDeclaration); ``` https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
@@ -1269,10 +1269,17 @@ class AnnotatingParser { if (CurrentToken && CurrentToken->is(tok::less)) { CurrentToken->setType(TT_TemplateOpener); next(); - if (!parseAngle()) + TemplateDeclarationDepth++; + if (!parseAngle()) { +TemplateDeclarationDepth--; return false; - if (CurrentToken) + } + TemplateDeclarationDepth--; + if (CurrentToken && + (TemplateDeclarationDepth == 0 || + !CurrentToken->isOneOf(tok::kw_typename, tok::kw_class))) { owenca wrote: Maybe something like the following? ``` - bool parseTemplateDeclaration() { + bool parseTemplateDeclaration(bool InTemplateParameter) { if (CurrentToken && CurrentToken->is(tok::less)) { CurrentToken->setType(TT_TemplateOpener); + InTemplateDeclaration = true; next(); if (!parseAngle()) return false; - if (CurrentToken) -CurrentToken->Previous->ClosesTemplateDeclaration = true; + if (!InTemplateParameter) { +InTemplateDeclaration = false; +if (CurrentToken) + CurrentToken->Previous->ClosesTemplateDeclaration = true; + } return true; } ``` And call it in `consumeToken()` like this: ``` case tok::kw_template: - parseTemplateDeclaration(); + parseTemplateDeclaration(InTemplateDeclaration); break; ``` https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
@@ -1269,10 +1269,17 @@ class AnnotatingParser { if (CurrentToken && CurrentToken->is(tok::less)) { CurrentToken->setType(TT_TemplateOpener); next(); - if (!parseAngle()) + TemplateDeclarationDepth++; + if (!parseAngle()) { +TemplateDeclarationDepth--; return false; - if (CurrentToken) + } + TemplateDeclarationDepth--; + if (CurrentToken && + !(TemplateDeclarationDepth > 0 && +CurrentToken->isOneOf(tok::kw_typename, tok::kw_class))) { owenca wrote: Maybe something like the following: ``` - bool parseTemplateDeclaration() { + bool parseTemplateDeclaration(bool IsParameter) { if (CurrentToken && CurrentToken->is(tok::less)) { CurrentToken->setType(TT_TemplateOpener); + InTemplateDeclaration = true; next(); if (!parseAngle()) return false; - if (CurrentToken) -CurrentToken->Previous->ClosesTemplateDeclaration = true; + if (!IsParameter) { +InTemplateDeclaration = false; +if (CurrentToken) + CurrentToken->Previous->ClosesTemplateDeclaration = true; + } ``` And call the function in `consumeToken()` like this: ``` case tok::kw_template: - parseTemplateDeclaration(); + parseTemplateDeclaration(InTemplateDeclaration); break; ``` https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
@@ -127,7 +127,7 @@ class AnnotatingParser { SmallVector &Scopes) : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false), IsCpp(Style.isCpp()), LangOpts(getFormattingLangOpts(Style)), -Keywords(Keywords), Scopes(Scopes) { +Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) { owenca wrote: ```suggestion Keywords(Keywords), Scopes(Scopes), InTemplateDeclaration(false) { ``` https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't count template template parameter as declaration (PR #95025)
@@ -584,6 +584,23 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator); } +TEST_F(TokenAnnotatorTest, UnderstandsTemplateTemplateParameters) { + auto Tokens = annotate("template typename X,\n" + " template typename Y,\n" owenca wrote: ```suggestion " template class Y,\n" ``` To cover both type-parameter keys. https://github.com/llvm/llvm-project/pull/95025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add DiagHandler for getStyle function (PR #91317)
owenca wrote: @mydeveloperday requested it. See https://github.com/llvm/llvm-project/pull/91317#pullrequestreview-2095010527. There are calls to `getStyle()` in `ConfigParseTest.cpp`. Maybe add a test there? https://github.com/llvm/llvm-project/pull/91317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)
@@ -110,15 +117,32 @@ bool UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall, BlockMap = std::make_unique(TheCFG.get(), Context); Visited.clear(); - const CFGBlock *Block = BlockMap->blockContainingStmt(MovingCall); - if (!Block) { + const CFGBlock *MoveBlock = BlockMap->blockContainingStmt(MovingCall); + if (!MoveBlock) { // This can happen if MovingCall is in a constructor initializer, which is // not included in the CFG because the CFG is built only from the function // body. -Block = &TheCFG->getEntry(); +MoveBlock = &TheCFG->getEntry(); } - return findInternal(Block, MovingCall, MovedVariable, TheUseAfterMove); + bool Found = findInternal(MoveBlock, MovingCall, MovedVariable->getDecl(), +TheUseAfterMove); + + if (Found) { +if (const CFGBlock *UseBlock = +BlockMap->blockContainingStmt(TheUseAfterMove->DeclRef)) { + // Does the use happen in a later loop iteration than the move? + // - If they are in the same CFG block, we know the use happened in a + // later iteration if we visited that block a second time. + // - Otherwise, we know the use happened in a later iteration if the + // move is reachable from the use. + auto CFA = std::make_unique(*TheCFG); + TheUseAfterMove->UseHappensInLaterLoopIteration = + UseBlock == MoveBlock ? Visited.contains(UseBlock) +: CFA->isReachable(UseBlock, MoveBlock); tchaikov wrote: thank you Martin! for the detailed explanation. i concur with you and Julian now. https://github.com/llvm/llvm-project/pull/93623 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [serialization] no transitive decl change (PR #92083)
ChuanqiXu9 wrote: Oh, this is surprising. Are arm CPUs 32 bit? And how much do these tests get slowed down? https://github.com/llvm/llvm-project/pull/92083 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc][cmake] Copy assets to build directory (PR #95187)
ilovepi wrote: @petrhosek I'm pretty sure there's a better way to spell this, but I think we need something similar to properly test clang-doc w/o an install step. cc: @PeterChou1 https://github.com/llvm/llvm-project/pull/95187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc][cmake] Copy assets to build directory (PR #95187)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Paul Kirth (ilovepi) Changes While we copy the asset files, like index.js, into the correct location in the install step, tests do not have access to those resources in the build directory. This patch copies the contents of the clang-doc/assets directory into the build folder, so that they can be used in testing. Pull Request: https://github.com/llvm/llvm-project/pull/95185 --- Full diff: https://github.com/llvm/llvm-project/pull/95187.diff 1 Files Affected: - (modified) clang-tools-extra/clang-doc/tool/CMakeLists.txt (+8) ``diff diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt index fb8317b272932..c2425747562b9 100644 --- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt +++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt @@ -25,3 +25,11 @@ install(FILES ../assets/clang-doc-default-stylesheet.css install(FILES ../assets/index.js DESTINATION "${CMAKE_INSTALL_DATADIR}/clang" COMPONENT clang-doc) + +add_custom_target(copy-clang-doc-assets + COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${CMAKE_CURRENT_SOURCE_DIR}/../assets" "${CMAKE_BINARY_DIR}/share/clang" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../assets" + COMMENT "Copying Clang-Doc Assets" + ) +set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER "Clang-Doc/Assets") +add_dependencies(clang-doc copy-clang-doc-assets) `` https://github.com/llvm/llvm-project/pull/95187 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc][cmake] Copy assets to build directory (PR #95187)
https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/95187 While we copy the asset files, like index.js, into the correct location in the install step, tests do not have access to those resources in the build directory. This patch copies the contents of the clang-doc/assets directory into the build folder, so that they can be used in testing. Pull Request: https://github.com/llvm/llvm-project/pull/95185 >From 753c6d43e44911cc7478738f1fc5d95d5780dbda Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Wed, 12 Jun 2024 01:05:59 + Subject: [PATCH] [clang-doc][cmake] Copy assets to build directory While we copy the asset files, like index.js, into the correct location in the install step, tests do not have access to those resources in the build directory. This patch copies the contents of the clang-doc/assets directory into the build folder, so that they can be used in testing. Pull Request: https://github.com/llvm/llvm-project/pull/95185 --- clang-tools-extra/clang-doc/tool/CMakeLists.txt | 8 1 file changed, 8 insertions(+) diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt index fb8317b272932..c2425747562b9 100644 --- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt +++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt @@ -25,3 +25,11 @@ install(FILES ../assets/clang-doc-default-stylesheet.css install(FILES ../assets/index.js DESTINATION "${CMAKE_INSTALL_DATADIR}/clang" COMPONENT clang-doc) + +add_custom_target(copy-clang-doc-assets + COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${CMAKE_CURRENT_SOURCE_DIR}/../assets" "${CMAKE_BINARY_DIR}/share/clang" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../assets" + COMMENT "Copying Clang-Doc Assets" + ) +set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER "Clang-Doc/Assets") +add_dependencies(clang-doc copy-clang-doc-assets) ___ 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 basic e2e test (PR #93928)
petrhosek wrote: Do we really need a full CSS when we're only checking the HTML? Could we just include a super minimal (or even empty) CSS? https://github.com/llvm/llvm-project/pull/93928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [clang-doc][cmake] Copy assets to build directory (PR #95185)
https://github.com/ilovepi closed https://github.com/llvm/llvm-project/pull/95185 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [clang-doc][cmake] Copy assets to build directory (PR #95185)
ilovepi wrote: Jeez. IDK what I've done w/ SPR to do this, but I apologize. https://github.com/llvm/llvm-project/pull/95185 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [clang-doc][cmake] Copy assets to build directory (PR #95185)
https://github.com/ilovepi edited https://github.com/llvm/llvm-project/pull/95185 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #94981)
https://github.com/mizvekov updated https://github.com/llvm/llvm-project/pull/94981 >From d12c7d50b67cd669f09b3701ccf34154876786c9 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Mon, 20 May 2024 01:15:03 -0300 Subject: [PATCH] [clang] Implement CWG2398 provisional TTP matching to class templates This extends default argument deduction to cover class templates as well, and also applies outside of partial ordering, adding to the provisional wording introduced in https://github.com/llvm/llvm-project/pull/89807. This solves some ambuguity introduced in P0522 regarding how template template parameters are partially ordered, and should reduce the negative impact of enabling `-frelaxed-template-template-args` by default. Given the following example: ```C++ template struct A; template struct B; template class TT1, class T5> struct B>; // #1 template struct B>; // #2 template struct B>; ``` Prior to P0522, `#2` was picked. Afterwards, this became ambiguous. This patch restores the pre-P0522 behavior, `#2` is picked again. As the consequences are not restricted to partial ordering, the following code becomes valid: ```C++ template struct A {}; A v; template class TT> void f(TT); // OK: TT picks 'float' as the default argument for the second parameter. void g() { f(v); } ``` Also, since 'f' deduced from `A` is different from 'f' deduced from `A`, this implements an additional mangling rule. --- Since this changes provisional implementation of CWG2398 which has not been released yet, and already contains a changelog entry, we don't provide a changelog entry here. --- clang-tools-extra/clangd/DumpAST.cpp | 1 + .../clangd/SemanticHighlighting.cpp | 1 + clang/include/clang/AST/ASTContext.h | 8 +- clang/include/clang/AST/ASTImporter.h | 5 + clang/include/clang/AST/DependenceFlags.h | 5 + clang/include/clang/AST/PropertiesBase.td | 17 ++ clang/include/clang/AST/TemplateName.h| 59 ++- clang/include/clang/Sema/Sema.h | 10 +- clang/lib/AST/ASTContext.cpp | 129 -- clang/lib/AST/ASTDiagnostic.cpp | 24 +-- clang/lib/AST/ASTImporter.cpp | 15 ++ clang/lib/AST/ASTStructuralEquivalence.cpp| 3 + clang/lib/AST/ItaniumMangle.cpp | 11 ++ clang/lib/AST/ODRHash.cpp | 1 + clang/lib/AST/TemplateName.cpp| 157 ++ clang/lib/AST/TextNodeDumper.cpp | 12 ++ clang/lib/AST/Type.cpp| 3 +- clang/lib/Sema/SemaTemplate.cpp | 63 +-- clang/lib/Sema/SemaTemplateDeduction.cpp | 128 -- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 24 +-- .../CXX/temp/temp.decls/temp.alias/p2.cpp | 5 +- clang/test/CodeGenCXX/mangle-cwg2398.cpp | 11 ++ clang/test/SemaTemplate/cwg2398.cpp | 60 +-- clang/tools/libclang/CIndex.cpp | 3 + clang/unittests/AST/ASTImporterTest.cpp | 17 ++ 25 files changed, 564 insertions(+), 208 deletions(-) create mode 100644 clang/test/CodeGenCXX/mangle-cwg2398.cpp diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp index 9a525efb938e8..e605f82e91fe4 100644 --- a/clang-tools-extra/clangd/DumpAST.cpp +++ b/clang-tools-extra/clangd/DumpAST.cpp @@ -187,6 +187,7 @@ class DumpVisitor : public RecursiveASTVisitor { TEMPLATE_KIND(SubstTemplateTemplateParm); TEMPLATE_KIND(SubstTemplateTemplateParmPack); TEMPLATE_KIND(UsingTemplate); + TEMPLATE_KIND(DeducedTemplate); #undef TEMPLATE_KIND } llvm_unreachable("Unhandled NameKind enum"); diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index a366f1331c2d3..e6d16af2495fe 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -1120,6 +1120,7 @@ class CollectExtraHighlightings case TemplateName::SubstTemplateTemplateParm: case TemplateName::SubstTemplateTemplateParmPack: case TemplateName::UsingTemplate: +case TemplateName::DeducedTemplate: // Names that could be resolved to a TemplateDecl are handled elsewhere. break; } diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 8bce4812f0d48..8818314de9364 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -262,6 +262,8 @@ class ASTContext : public RefCountedBase { mutable llvm::ContextualFoldingSet SubstTemplateTemplateParmPacks; + mutable llvm::ContextualFoldingSet + DeducedTemplates; mutable llvm::ContextualFoldingSet ArrayParameterTypes; @@ -2247,6 +2249,9 @@ class ASTContext : public RefCountedBase { unsigned Index,
[clang] [HLSL] Strict Availability Diagnostics (PR #93860)
https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/93860 >From 532f10f77c862f6d429366f0d6903773da8fa79b Mon Sep 17 00:00:00 2001 From: Helena Kotas Date: Thu, 30 May 2024 11:40:27 -0700 Subject: [PATCH 1/3] Implement HLSL strict diagnostic mode --- clang/include/clang/Basic/Attr.td | 5 - clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Driver/Options.td | 9 ++ clang/lib/AST/DeclBase.cpp| 2 +- clang/lib/Sema/SemaAvailability.cpp | 76 ++ clang/lib/Sema/SemaHLSL.cpp | 54 +-- .../avail-diag-strict-compute.hlsl| 129 .../Availability/avail-diag-strict-lib.hlsl | 142 ++ 8 files changed, 369 insertions(+), 50 deletions(-) create mode 100644 clang/test/SemaHLSL/Availability/avail-diag-strict-compute.hlsl create mode 100644 clang/test/SemaHLSL/Availability/avail-diag-strict-lib.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 2665b7353ca4a..6ac2e3b50ee54 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1060,11 +1060,6 @@ static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) { .Case("ShaderModel", "shadermodel") .Default(Platform); } -static llvm::StringRef getPrettyEnviromentName(llvm::Triple::EnvironmentType EnvironmentType) { - if (EnvironmentType >= llvm::Triple::Pixel && EnvironmentType <= llvm::Triple::Amplification) -return llvm::Triple::getEnvironmentTypeName(EnvironmentType); - return ""; -} static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef Environment) { return llvm::StringSwitch(Environment) .Case("pixel", llvm::Triple::Pixel) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 4061451b2150a..443b49d0e2779 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -276,6 +276,8 @@ LANGOPT(RenderScript , 1, 0, "RenderScript") LANGOPT(HLSL, 1, 0, "HLSL") ENUM_LANGOPT(HLSLVersion, HLSLLangStd, 16, HLSL_Unset, "HLSL Version") +LANGOPT(HLSLStrictAvailability, 1, 0, +"Strict availability diagnostic mode for HLSL built-in functions.") LANGOPT(CUDAIsDevice , 1, 0, "compiling for CUDA device") LANGOPT(CUDAAllowVariadicFunctions, 1, 0, "allowing variadic functions in CUDA device code") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1637a114fcce1..cb380450d0425 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -196,6 +196,10 @@ def m_Group : OptionGroup<"">, Group, DocName<"Target-dependent compilation options">, Visibility<[ClangOption, CLOption]>; +def hlsl_Group : OptionGroup<"">, Group, + DocName<"HLSL options">, + Visibility<[ClangOption]>; + // Feature groups - these take command line options that correspond directly to // target specific features and can be translated directly from command line // options. @@ -7863,6 +7867,11 @@ def finclude_default_header : Flag<["-"], "finclude-default-header">, def fdeclare_opencl_builtins : Flag<["-"], "fdeclare-opencl-builtins">, HelpText<"Add OpenCL builtin function declarations (experimental)">; +def fhlsl_strict_availability : Flag<["-"], "fhlsl-strict-availability">, + HelpText<"Enables strict availability diagnostic mode for HLSL built-in functions.">, + Group, + MarshallingInfoFlag>; + def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">, HelpText<"Preserve 3-component vector type">, MarshallingInfoFlag>, diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index ffb22194bce52..f481019eff51a 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -669,7 +669,7 @@ static AvailabilityResult CheckAvailability(ASTContext &Context, IdentifierInfo *IIEnv = A->getEnvironment(); StringRef TargetEnv = Context.getTargetInfo().getTriple().getEnvironmentName(); -StringRef EnvName = AvailabilityAttr::getPrettyEnviromentName( +StringRef EnvName = llvm::Triple::getEnvironmentTypeName( Context.getTargetInfo().getTriple().getEnvironment()); // Matching environment or no environment on attribute if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) { diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp index 330cd602297d4..0e448c8b13985 100644 --- a/clang/lib/Sema/SemaAvailability.cpp +++ b/clang/lib/Sema/SemaAvailability.cpp @@ -229,9 +229,7 @@ shouldDiagnoseAvailabilityByDefault(const ASTContext &Context, ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13); break; case llvm::Triple::ShaderModel: -// FIXME: This
[clang] [CMake][Fuchsia] Enable libc++ in the baremetal build (PR #95017)
https://github.com/petrhosek closed https://github.com/llvm/llvm-project/pull/95017 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d9012d8 - [CMake][Fuchsia] Enable libc++ in the baremetal build (#95017)
Author: Petr Hosek Date: 2024-06-11T17:00:15-07:00 New Revision: d9012d8775b45e3edc33394684050cf06b394fb0 URL: https://github.com/llvm/llvm-project/commit/d9012d8775b45e3edc33394684050cf06b394fb0 DIFF: https://github.com/llvm/llvm-project/commit/d9012d8775b45e3edc33394684050cf06b394fb0.diff LOG: [CMake][Fuchsia] Enable libc++ in the baremetal build (#95017) For now, we include headers and don't use libc++abi. Added: Modified: clang/cmake/caches/Fuchsia-stage2.cmake Removed: diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake index 66e764968e85c..aa07b04be65cc 100644 --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -328,9 +328,24 @@ foreach(target armv6m-unknown-eabi) endforeach() set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "") set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "") + set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_RTTI OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_THREADS OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_INSTALL_LIBRARY OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "") set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE BOOL "") set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "") - set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc" CACHE STRING "") + set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc;libcxx" CACHE STRING "") endforeach() foreach(target riscv32-unknown-elf) @@ -361,9 +376,24 @@ foreach(target riscv32-unknown-elf) endforeach() set(RUNTIMES_${target}_LLVM_LIBC_FULL_BUILD ON CACHE BOOL "") set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "") + set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_RTTI OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_THREADS OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_INSTALL_LIBRARY OFF CACHE BOOL "") + set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "") set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE BOOL "") set(RUNTIMES_${target}_LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "") - set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc" CACHE STRING "") + set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "libc;libcxx" CACHE STRING "") endforeach() set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [InstallAPI] Pick up input headers by directory traversal (PR #94508)
https://github.com/cyndyishida updated https://github.com/llvm/llvm-project/pull/94508 >From 95cc0c9a2b135706e80a5e73ef5e4257aa89984c Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Fri, 10 May 2024 09:19:22 -0700 Subject: [PATCH] [InstallAPI] Pick up input headers by directory traversal Match TAPI behavior and allow input headers to be resolved via a passed directory, which is expected to be a library sitting in a build directory. --- .../clang/Basic/DiagnosticInstallAPIKinds.td | 2 + .../clang/InstallAPI/DirectoryScanner.h | 81 + clang/include/clang/InstallAPI/HeaderFile.h | 13 + clang/include/clang/InstallAPI/Library.h | 65 clang/include/clang/InstallAPI/MachO.h| 1 + clang/lib/InstallAPI/CMakeLists.txt | 2 + clang/lib/InstallAPI/DirectoryScanner.cpp | 300 ++ clang/lib/InstallAPI/Library.cpp | 40 +++ clang/test/InstallAPI/asm.test| 2 +- clang/test/InstallAPI/basic.test | 4 +- clang/test/InstallAPI/binary-attributes.test | 6 +- clang/test/InstallAPI/cpp.test| 4 +- clang/test/InstallAPI/diagnostics-dsym.test | 4 +- .../InstallAPI/directory-scanning-dylib.test | 57 .../directory-scanning-frameworks.test| 88 + clang/test/InstallAPI/functions.test | 2 +- clang/test/InstallAPI/variables.test | 2 +- clang/tools/clang-installapi/Options.cpp | 51 ++- clang/tools/clang-installapi/Options.h| 3 + 19 files changed, 703 insertions(+), 24 deletions(-) create mode 100644 clang/include/clang/InstallAPI/DirectoryScanner.h create mode 100644 clang/include/clang/InstallAPI/Library.h create mode 100644 clang/lib/InstallAPI/DirectoryScanner.cpp create mode 100644 clang/lib/InstallAPI/Library.cpp create mode 100644 clang/test/InstallAPI/directory-scanning-dylib.test create mode 100644 clang/test/InstallAPI/directory-scanning-frameworks.test diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index cdf27247602f2..e10fa71011f30 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -26,6 +26,8 @@ def err_unsupported_environment : Error<"environment '%0' is not supported: '%1' def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; def err_cannot_read_input_list : Error<"could not read %0 input list '%1': %2">; def err_invalid_label: Error<"label '%0' is reserved: use a different label name for -X">; +def err_directory_scanning: Error<"could not read directory '%0': %1">; +def err_more_than_one_library: Error<"more than one framework/dynamic library found">; } // end of command line category. let CategoryName = "Verification" in { diff --git a/clang/include/clang/InstallAPI/DirectoryScanner.h b/clang/include/clang/InstallAPI/DirectoryScanner.h new file mode 100644 index 0..803328982ec87 --- /dev/null +++ b/clang/include/clang/InstallAPI/DirectoryScanner.h @@ -0,0 +1,81 @@ +//===- InstallAPI/DirectoryScanner.h *- C++ -*-===// +// +// 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 +// +//===--===// +/// +/// The DirectoryScanner for collecting library files on the file system. +/// +//===--===// +#ifndef LLVM_CLANG_INSTALLAPI_DIRECTORYSCANNER_H +#define LLVM_CLANG_INSTALLAPI_DIRECTORYSCANNER_H + +#include "clang/Basic/FileManager.h" +#include "clang/InstallAPI/Library.h" + +namespace clang::installapi { + +enum ScanMode { + /// Scanning Framework directory. + ScanFrameworks, + /// Scanning Dylib directory. + ScanDylibs, +}; + +class DirectoryScanner { +public: + DirectoryScanner(FileManager &FM, ScanMode Mode = ScanMode::ScanFrameworks) + : FM(FM), Mode(Mode) {} + + /// Scan for all input files throughout directory. + /// + /// \param Directory Path of input directory. + llvm::Error scan(StringRef Directory); + + /// Take over ownership of stored libraries. + std::vector takeLibraries() { return std::move(Libraries); }; + + /// Get all the header files in libraries. + /// + /// \param Libraries Reference of collection of libraries. + static HeaderSeq getHeaders(ArrayRef Libraries); + +private: + /// Collect files for dylibs in usr/(local)/lib within directory. + llvm::Error scanForUnwrappedLibraries(StringRef Directory); + + /// Collect files for any frameworks within directory. + llvm::Error scanForFrameworks(StringRef Directory); + + /// Get a library from the libraries collection. + Library &getOrCreateLibrary(StringRef Path, std::vector &Libs) const; + + /// Collect multiple f
[clang] [llvm] [WebAssembly] Implement f16x8 madd and nmadd instructions. (PR #95151)
https://github.com/brendandahl closed https://github.com/llvm/llvm-project/pull/95151 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3ab6d12 - [WebAssembly] Implement f16x8 madd and nmadd instructions. (#95151)
Author: Brendan Dahl Date: 2024-06-11T16:10:00-07:00 New Revision: 3ab6d126250f03982d3110517d407f7e951133f6 URL: https://github.com/llvm/llvm-project/commit/3ab6d126250f03982d3110517d407f7e951133f6 DIFF: https://github.com/llvm/llvm-project/commit/3ab6d126250f03982d3110517d407f7e951133f6.diff LOG: [WebAssembly] Implement f16x8 madd and nmadd instructions. (#95151) Implemented with intrinsics and builtins. Specified at: https://github.com/WebAssembly/half-precision/blob/main/proposals/half-precision/Overview.md Added: Modified: clang/include/clang/Basic/BuiltinsWebAssembly.def clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/builtins-wasm.c llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td llvm/test/MC/WebAssembly/simd-encodings.s Removed: diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def b/clang/include/clang/Basic/BuiltinsWebAssembly.def index 4e48ff48b60f5..2a45f8a6582a2 100644 --- a/clang/include/clang/Basic/BuiltinsWebAssembly.def +++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def @@ -170,6 +170,8 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f32x4, "V4fV4fV4fV4f", "nc", "relaxed TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f32x4, "V4fV4fV4fV4f", "nc", "relaxed-simd") TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f64x2, "V2dV2dV2dV2d", "nc", "relaxed-simd") TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f64x2, "V2dV2dV2dV2d", "nc", "relaxed-simd") +TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f16x8, "V8hV8hV8hV8h", "nc", "half-precision") +TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f16x8, "V8hV8hV8hV8h", "nc", "half-precision") TARGET_BUILTIN(__builtin_wasm_relaxed_laneselect_i8x16, "V16ScV16ScV16ScV16Sc", "nc", "relaxed-simd") TARGET_BUILTIN(__builtin_wasm_relaxed_laneselect_i16x8, "V8sV8sV8sV8s", "nc", "relaxed-simd") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 06e201fa71e6f..511e1fd4016d7 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -21149,6 +21149,8 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_shuffle); return Builder.CreateCall(Callee, Ops); } + case WebAssembly::BI__builtin_wasm_relaxed_madd_f16x8: + case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f16x8: case WebAssembly::BI__builtin_wasm_relaxed_madd_f32x4: case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f32x4: case WebAssembly::BI__builtin_wasm_relaxed_madd_f64x2: @@ -21158,10 +21160,12 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, Value *C = EmitScalarExpr(E->getArg(2)); unsigned IntNo; switch (BuiltinID) { +case WebAssembly::BI__builtin_wasm_relaxed_madd_f16x8: case WebAssembly::BI__builtin_wasm_relaxed_madd_f32x4: case WebAssembly::BI__builtin_wasm_relaxed_madd_f64x2: IntNo = Intrinsic::wasm_relaxed_madd; break; +case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f16x8: case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f32x4: case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f64x2: IntNo = Intrinsic::wasm_relaxed_nmadd; diff --git a/clang/test/CodeGen/builtins-wasm.c b/clang/test/CodeGen/builtins-wasm.c index d6ee4f68700dc..75861b1b4bd6d 100644 --- a/clang/test/CodeGen/builtins-wasm.c +++ b/clang/test/CodeGen/builtins-wasm.c @@ -690,6 +690,20 @@ f64x2 nmadd_f64x2(f64x2 a, f64x2 b, f64x2 c) { // WEBASSEMBLY-NEXT: ret } +f16x8 madd_f16x8(f16x8 a, f16x8 b, f16x8 c) { + return __builtin_wasm_relaxed_madd_f16x8(a, b, c); + // WEBASSEMBLY: call <8 x half> @llvm.wasm.relaxed.madd.v8f16( + // WEBASSEMBLY-SAME: <8 x half> %a, <8 x half> %b, <8 x half> %c) + // WEBASSEMBLY-NEXT: ret +} + +f16x8 nmadd_f16x8(f16x8 a, f16x8 b, f16x8 c) { + return __builtin_wasm_relaxed_nmadd_f16x8(a, b, c); + // WEBASSEMBLY: call <8 x half> @llvm.wasm.relaxed.nmadd.v8f16( + // WEBASSEMBLY-SAME: <8 x half> %a, <8 x half> %b, <8 x half> %c) + // WEBASSEMBLY-NEXT: ret +} + i8x16 laneselect_i8x16(i8x16 a, i8x16 b, i8x16 c) { return __builtin_wasm_relaxed_laneselect_i8x16(a, b, c); // WEBASSEMBLY: call <16 x i8> @llvm.wasm.relaxed.laneselect.v16i8( diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td index 3c97befcea1a4..3888175efd115 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td @@ -1480,23 +1480,24 @@ defm "" : RelaxedConvert simdopA, bits<32> simdopS> { +multiclass SIMDMADD simdopA, bits<32> simdopS, list reqs> { defm MADD_#vec : -RELAXED_I<(outs V128:$dst), (ins V128:$a, V128:$b, V128:$c), (outs), (ins), - [(set (vec.vt V128:$dst), (int_wasm_relaxed_madd -(vec.vt V128:$a), (vec.vt V128:$b), (vec.vt V128:$c)))], - vec.prefix#"
[clang] [libcxxabi] [llvm] Add support for WASI builds (PR #91051)
https://github.com/ldionne approved this pull request. FWIW I am happy with the one line change in `libcxxabi/`. For libc++ to officially support this beyond just a fun proof of concept, we'd need a story for running the tests and set up a pre-commit CI for it though. I'm approving just to get the `reviewers-libcxxabi` group out of your way, I didn't look at the rest of the PR. Also, if you think we should go ahead with the other PR instead and don't plan on merging this, please close this PR to help us keep our PR queue tidy. Thanks! https://github.com/llvm/llvm-project/pull/91051 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [CLANG][LLVM][AArch64]Add SME2.1 intrinsics for MOVAZ tile to vector,… (PR #88499)
aemerson wrote: Can #88901 #88710 and this be merged? https://github.com/llvm/llvm-project/pull/88499 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Implement CWG2137 (list-initialization from objects of the same type) (PR #94355)
https://github.com/ldionne approved this pull request. Thanks for fixing the libc++ tests. That part of the patch LGTM. https://github.com/llvm/llvm-project/pull/94355 ___ 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)
@@ -127,16 +133,85 @@ 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) { + std::error_code Code; + llvm::SmallString<128> FilePath = llvm::SmallString<128>(UserAssetPath); + for (auto DirIt = llvm::sys::fs::directory_iterator(UserAssetPath, Code), +DirEnd = llvm::sys::fs::directory_iterator(); + !Code && DirIt != DirEnd; DirIt.increment(Code)) { +FilePath = llvm::SmallString<128>(DirIt->path()); ilovepi wrote: You can either directly assign to an `std::string` or by using the `.assign()` method. I think this will have at least 1 extra copy by constructing the small string and then assigning it through the implicit conversion from `SmallString` to `StringRef`. ```suggestion FilePath = DirIt->path(); ``` 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] [clang-doc] Add --asset option to clang-doc (PR #94717)
@@ -127,16 +133,85 @@ 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) { + std::error_code Code; + llvm::SmallString<128> FilePath = llvm::SmallString<128>(UserAssetPath); ilovepi wrote: ```suggestion llvm::SmallString<128> FilePath(UserAssetPath); ``` won't this work? 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] [clang-doc] Add --asset option to clang-doc (PR #94717)
https://github.com/ilovepi approved this pull request. LGTM, modulo the one nit, and premerge checks passing. 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] [clang-doc] Add --asset option to clang-doc (PR #94717)
https://github.com/ilovepi edited 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] Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. #94100" (PR #95174)
https://github.com/huangjd closed https://github.com/llvm/llvm-project/pull/95174 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3fce145 - Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. #94100" (#95174)
Author: William Junda Huang Date: 2024-06-11T17:33:20-04:00 New Revision: 3fce14569fc3611eddca41db055143285244736a URL: https://github.com/llvm/llvm-project/commit/3fce14569fc3611eddca41db055143285244736a DIFF: https://github.com/llvm/llvm-project/commit/3fce14569fc3611eddca41db055143285244736a.diff LOG: Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. #94100" (#95174) The option is causing the binary output to be different when compiled under `-O0`, because it introduce dbg.declare on pseudovariables. Going to change this implementation to use dbg.value instead. Added: Modified: clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDebugInfo.h clang/lib/CodeGen/CGExprScalar.cpp Removed: clang/test/CodeGenCXX/debug-info-ptr-to-ptr.cpp diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 11e2d549d8a45..99e12da0081af 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5746,78 +5746,6 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var, Var->addDebugInfo(GVE); } -void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder, - llvm::Instruction *Value, QualType Ty) { - // Only when -g2 or above is specified, debug info for variables will be - // generated. - if (CGM.getCodeGenOpts().getDebugInfo() <= - llvm::codegenoptions::DebugLineTablesOnly) -return; - - llvm::DebugLoc SaveDebugLoc = Builder.getCurrentDebugLocation(); - if (!SaveDebugLoc.get()) -return; - - llvm::DIFile *Unit = SaveDebugLoc->getFile(); - llvm::DIType *Type = getOrCreateType(Ty, Unit); - - // Check if Value is already a declared variable and has debug info, in this - // case we have nothing to do. Clang emits declared variable as alloca, and - // it is loaded upon use, so we identify such pattern here. - if (llvm::LoadInst *Load = dyn_cast(Value)) { -llvm::Value *Var = Load->getPointerOperand(); -// There can be implicit type cast applied on a variable if it is an opaque -// ptr, in this case its debug info may not match the actual type of object -// being used as in the next instruction, so we will need to emit a pseudo -// variable for type-casted value. -auto DeclareTypeMatches = [&](auto *DbgDeclare) { - return DbgDeclare->getVariable()->getType() == Type; -}; -if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) || -any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches)) - return; - } - - // Find the correct location to insert a sequence of instructions to - // materialize Value on the stack. - auto SaveInsertionPoint = Builder.saveIP(); - if (llvm::InvokeInst *Invoke = dyn_cast(Value)) -Builder.SetInsertPoint(Invoke->getNormalDest()->begin()); - else if (llvm::Instruction *Next = Value->getIterator()->getNextNode()) -Builder.SetInsertPoint(Next); - else -Builder.SetInsertPoint(Value->getParent()); - llvm::DebugLoc DL = Value->getDebugLoc(); - if (DL.get()) -Builder.SetCurrentDebugLocation(DL); - else if (!Builder.getCurrentDebugLocation().get()) -Builder.SetCurrentDebugLocation(SaveDebugLoc); - - llvm::AllocaInst *PseudoVar = Builder.CreateAlloca(Value->getType()); - Address PseudoVarAddr(PseudoVar, Value->getType(), -CharUnits::fromQuantity(PseudoVar->getAlign())); - llvm::LoadInst *Load = Builder.CreateLoad(PseudoVarAddr); - Value->replaceAllUsesWith(Load); - Builder.SetInsertPoint(Load); - Builder.CreateStore(Value, PseudoVarAddr); - - // Emit debug info for materialized Value. - unsigned Line = Builder.getCurrentDebugLocation().getLine(); - unsigned Column = Builder.getCurrentDebugLocation().getCol(); - llvm::DILocalVariable *D = DBuilder.createAutoVariable( - LexicalBlockStack.back(), "", nullptr, 0, Type, false, - llvm::DINode::FlagArtificial); - llvm::DILocation *DIL = - llvm::DILocation::get(CGM.getLLVMContext(), Line, Column, -LexicalBlockStack.back(), CurInlinedAt); - SmallVector Expr; - DBuilder.insertDeclare(PseudoVar, D, DBuilder.createExpression(Expr), DIL, - Load); - - Builder.restoreIP(SaveInsertionPoint); - Builder.SetCurrentDebugLocation(SaveDebugLoc); -} - void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl GD) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index da466837aa3c3..8fe738be21568 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -530,12 +530,6 @@ class CGDebugInfo { /// Emit information about an external variable. void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); - /// Emit a pseudo variable and debug info for an intermediate v
[clang] Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. #94100" (PR #95174)
https://github.com/dwblaikie approved this pull request. https://github.com/llvm/llvm-project/pull/95174 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. #94100" (PR #95174)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: William Junda Huang (huangjd) Changes The option is causing the binary output to be different when compiled under `-O0`, because it introduce dbg.declare on pseudovariables. Going to change this implementation to use dbg.value instead. --- Full diff: https://github.com/llvm/llvm-project/pull/95174.diff 4 Files Affected: - (modified) clang/lib/CodeGen/CGDebugInfo.cpp (-72) - (modified) clang/lib/CodeGen/CGDebugInfo.h (-6) - (modified) clang/lib/CodeGen/CGExprScalar.cpp (+1-20) - (removed) clang/test/CodeGenCXX/debug-info-ptr-to-ptr.cpp (-120) ``diff diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 11e2d549d8a45..99e12da0081af 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5746,78 +5746,6 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var, Var->addDebugInfo(GVE); } -void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder, - llvm::Instruction *Value, QualType Ty) { - // Only when -g2 or above is specified, debug info for variables will be - // generated. - if (CGM.getCodeGenOpts().getDebugInfo() <= - llvm::codegenoptions::DebugLineTablesOnly) -return; - - llvm::DebugLoc SaveDebugLoc = Builder.getCurrentDebugLocation(); - if (!SaveDebugLoc.get()) -return; - - llvm::DIFile *Unit = SaveDebugLoc->getFile(); - llvm::DIType *Type = getOrCreateType(Ty, Unit); - - // Check if Value is already a declared variable and has debug info, in this - // case we have nothing to do. Clang emits declared variable as alloca, and - // it is loaded upon use, so we identify such pattern here. - if (llvm::LoadInst *Load = dyn_cast(Value)) { -llvm::Value *Var = Load->getPointerOperand(); -// There can be implicit type cast applied on a variable if it is an opaque -// ptr, in this case its debug info may not match the actual type of object -// being used as in the next instruction, so we will need to emit a pseudo -// variable for type-casted value. -auto DeclareTypeMatches = [&](auto *DbgDeclare) { - return DbgDeclare->getVariable()->getType() == Type; -}; -if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) || -any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches)) - return; - } - - // Find the correct location to insert a sequence of instructions to - // materialize Value on the stack. - auto SaveInsertionPoint = Builder.saveIP(); - if (llvm::InvokeInst *Invoke = dyn_cast(Value)) -Builder.SetInsertPoint(Invoke->getNormalDest()->begin()); - else if (llvm::Instruction *Next = Value->getIterator()->getNextNode()) -Builder.SetInsertPoint(Next); - else -Builder.SetInsertPoint(Value->getParent()); - llvm::DebugLoc DL = Value->getDebugLoc(); - if (DL.get()) -Builder.SetCurrentDebugLocation(DL); - else if (!Builder.getCurrentDebugLocation().get()) -Builder.SetCurrentDebugLocation(SaveDebugLoc); - - llvm::AllocaInst *PseudoVar = Builder.CreateAlloca(Value->getType()); - Address PseudoVarAddr(PseudoVar, Value->getType(), -CharUnits::fromQuantity(PseudoVar->getAlign())); - llvm::LoadInst *Load = Builder.CreateLoad(PseudoVarAddr); - Value->replaceAllUsesWith(Load); - Builder.SetInsertPoint(Load); - Builder.CreateStore(Value, PseudoVarAddr); - - // Emit debug info for materialized Value. - unsigned Line = Builder.getCurrentDebugLocation().getLine(); - unsigned Column = Builder.getCurrentDebugLocation().getCol(); - llvm::DILocalVariable *D = DBuilder.createAutoVariable( - LexicalBlockStack.back(), "", nullptr, 0, Type, false, - llvm::DINode::FlagArtificial); - llvm::DILocation *DIL = - llvm::DILocation::get(CGM.getLLVMContext(), Line, Column, -LexicalBlockStack.back(), CurInlinedAt); - SmallVector Expr; - DBuilder.insertDeclare(PseudoVar, D, DBuilder.createExpression(Expr), DIL, - Load); - - Builder.restoreIP(SaveInsertionPoint); - Builder.SetCurrentDebugLocation(SaveDebugLoc); -} - void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl GD) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index da466837aa3c3..8fe738be21568 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -530,12 +530,6 @@ class CGDebugInfo { /// Emit information about an external variable. void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); - /// Emit a pseudo variable and debug info for an intermediate value if it does - /// not correspond to a variable in the source code, so that a profiler can - /// track more accurate usage of certain instructions of interest. - void EmitPseudoVariable(CGBuilderTy &Builder, llvm::Instruction *Value, - QualT
[clang] Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. #94100" (PR #95174)
https://github.com/huangjd created https://github.com/llvm/llvm-project/pull/95174 The option is causing the binary output to be different when compiled under `-O0`, because it introduce dbg.declare on pseudovariables. Going to change this implementation to use dbg.value instead. >From c72d4de2a1dc4e641d61b3f31185181855a1d434 Mon Sep 17 00:00:00 2001 From: William Huang Date: Tue, 11 Jun 2024 17:19:07 -0400 Subject: [PATCH 1/2] Revert "[Clang] Extend EmitPseudoVariable to support debug records (#94956)" This reverts commit 5c268cfaae521dc2db1af58085e3c8d66a5533fe. --- clang/lib/CodeGen/CGDebugInfo.cpp | 32 +-- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 11e2d549d8a45..681a475f9e4be 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5766,16 +5766,28 @@ void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder, // it is loaded upon use, so we identify such pattern here. if (llvm::LoadInst *Load = dyn_cast(Value)) { llvm::Value *Var = Load->getPointerOperand(); -// There can be implicit type cast applied on a variable if it is an opaque -// ptr, in this case its debug info may not match the actual type of object -// being used as in the next instruction, so we will need to emit a pseudo -// variable for type-casted value. -auto DeclareTypeMatches = [&](auto *DbgDeclare) { - return DbgDeclare->getVariable()->getType() == Type; -}; -if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) || -any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches)) - return; +if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) { + if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists( + CGM.getLLVMContext(), MDValue)) { +for (llvm::User *U : DbgValue->users()) { + if (llvm::CallInst *DbgDeclare = dyn_cast(U)) { +if (DbgDeclare->getCalledFunction()->getIntrinsicID() == +llvm::Intrinsic::dbg_declare && +DbgDeclare->getArgOperand(0) == DbgValue) { + // There can be implicit type cast applied on a variable if it is + // an opaque ptr, in this case its debug info may not match the + // actual type of object being used as in the next instruction, so + // we will need to emit a pseudo variable for type-casted value. + llvm::DILocalVariable *MDNode = cast( + cast(DbgDeclare->getOperand(1)) + ->getMetadata()); + if (MDNode->getType() == Type) +return; +} + } +} + } +} } // Find the correct location to insert a sequence of instructions to >From 83a179ba9db812492f37ccbe00f58f534a993fe1 Mon Sep 17 00:00:00 2001 From: William Huang Date: Tue, 11 Jun 2024 17:19:22 -0400 Subject: [PATCH 2/2] Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. (#94100)" This reverts commit 5cb00785aa56d4acc97b083df5305d2959f6bd4a. --- clang/lib/CodeGen/CGDebugInfo.cpp | 84 clang/lib/CodeGen/CGDebugInfo.h | 6 - clang/lib/CodeGen/CGExprScalar.cpp| 21 +-- .../test/CodeGenCXX/debug-info-ptr-to-ptr.cpp | 120 -- 4 files changed, 1 insertion(+), 230 deletions(-) delete mode 100644 clang/test/CodeGenCXX/debug-info-ptr-to-ptr.cpp diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 681a475f9e4be..99e12da0081af 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5746,90 +5746,6 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var, Var->addDebugInfo(GVE); } -void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder, - llvm::Instruction *Value, QualType Ty) { - // Only when -g2 or above is specified, debug info for variables will be - // generated. - if (CGM.getCodeGenOpts().getDebugInfo() <= - llvm::codegenoptions::DebugLineTablesOnly) -return; - - llvm::DebugLoc SaveDebugLoc = Builder.getCurrentDebugLocation(); - if (!SaveDebugLoc.get()) -return; - - llvm::DIFile *Unit = SaveDebugLoc->getFile(); - llvm::DIType *Type = getOrCreateType(Ty, Unit); - - // Check if Value is already a declared variable and has debug info, in this - // case we have nothing to do. Clang emits declared variable as alloca, and - // it is loaded upon use, so we identify such pattern here. - if (llvm::LoadInst *Load = dyn_cast(Value)) { -llvm::Value *Var = Load->getPointerOperand(); -if (llvm::Metadata *MDValue = llvm::ValueAsMetadata::getIfExists(Var)) { - if (llvm::Value *DbgValue = llvm::MetadataAsValue::getIfExists( - CGM.getLLVMContext(), MDValue)) { -
[clang] [HLSL] Fix FileCheck annotation typos (PR #95155)
https://github.com/bogner closed https://github.com/llvm/llvm-project/pull/95155 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add option to generate additional debug info for expression dereferencing pointer to pointers. (PR #94100)
huangjd wrote: Ok lets revert this first, and I will work on the dbg.value implementation https://github.com/llvm/llvm-project/pull/94100 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c6ee562 - [HLSL] Fix FileCheck annotation typos (#95155)
Author: Justin Bogner Date: 2024-06-11T14:16:11-07:00 New Revision: c6ee5628a75feeb4fccc8272a68eb8303fb1734b URL: https://github.com/llvm/llvm-project/commit/c6ee5628a75feeb4fccc8272a68eb8303fb1734b DIFF: https://github.com/llvm/llvm-project/commit/c6ee5628a75feeb4fccc8272a68eb8303fb1734b.diff LOG: [HLSL] Fix FileCheck annotation typos (#95155) These are the HLSL specific fixes from #93193. Thanks klensy! Added: Modified: clang/test/CodeGenHLSL/convergence/for.hlsl clang/test/SemaHLSL/standard_conversion_sequences.hlsl Removed: diff --git a/clang/test/CodeGenHLSL/convergence/for.hlsl b/clang/test/CodeGenHLSL/convergence/for.hlsl index 180fae74ba751..95f9a196bdb67 100644 --- a/clang/test/CodeGenHLSL/convergence/for.hlsl +++ b/clang/test/CodeGenHLSL/convergence/for.hlsl @@ -92,7 +92,7 @@ void test6() { // CHECK: [[C1:%[a-zA-Z0-9]+]] = call spir_func noundef i1 @_Z4condv() [[A3]] [ "convergencectrl"(token [[T1]]) ] // CHECK: br i1 [[C1]], label %if.then, label %if.end // CHECK: if.then: -// CHECKcall spir_func void @_Z3foov() [[A3:#[0-9]+]] [ "convergencectrl"(token [[T1]]) ] +// CHECK: call spir_func void @_Z3foov() [[A3:#[0-9]+]] [ "convergencectrl"(token [[T1]]) ] // CHECK: br label %for.end // CHECK: if.end: // CHECK: br label %for.inc diff --git a/clang/test/SemaHLSL/standard_conversion_sequences.hlsl b/clang/test/SemaHLSL/standard_conversion_sequences.hlsl index a0d398105f15d..256981d2c1e2e 100644 --- a/clang/test/SemaHLSL/standard_conversion_sequences.hlsl +++ b/clang/test/SemaHLSL/standard_conversion_sequences.hlsl @@ -4,9 +4,8 @@ void test() { // CHECK: VarDecl {{.*}} used f3 'vector':'float __attribute__((ext_vector_type(3)))' cinit - // CHECK-NEXt: ImplicitCastExpr {{.*}} 'vector':'float __attribute__((ext_vector_type(3)))' - // CHECK-NEXt: ImplicitCastExpr {{.*}} 'float' - // CHECK-NEXt: FloatingLiteral {{.*}} 'double' 1.00e+00 + // CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector':'float __attribute__((ext_vector_type(3)))' + // CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.00e+00 vector f3 = 1.0; // No warning for splatting to a vector from a literal. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clangd] Show struct fields and enum members in hovers (PR #89557)
https://github.com/tom-anders edited https://github.com/llvm/llvm-project/pull/89557 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits