[llvm-branch-commits] [llvm] [AMDGPU] Fix sign confusion in performMulLoHiCombine (PR #106977)

2024-09-13 Thread via llvm-branch-commits

h-vetinari wrote:

> I am unsure what ROCm is in this case

[Radeon Open Compute](https://github.com/ROCm), which is (very roughly) AMD's 
CUDA.

https://github.com/llvm/llvm-project/pull/106977
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port EarlyIfConversion pass to NPM. (PR #108508)

2024-09-13 Thread Matt Arsenault via llvm-branch-commits


@@ -128,6 +128,7 @@ MACHINE_FUNCTION_ANALYSIS("slot-indexes", 
SlotIndexesAnalysis())
 #ifndef MACHINE_FUNCTION_PASS
 #define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
 #endif
+MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
 MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass())

arsenm wrote:

These should be alphabetical order 

https://github.com/llvm/llvm-project/pull/108508
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port machine trace metrics analysis to new pass manager. (PR #108507)

2024-09-13 Thread Matt Arsenault via llvm-branch-commits


@@ -39,41 +39,68 @@ using namespace llvm;
 
 #define DEBUG_TYPE "machine-trace-metrics"
 
-char MachineTraceMetrics::ID = 0;
+AnalysisKey MachineTraceMetricsAnalysis::Key;
 
-char &llvm::MachineTraceMetricsID = MachineTraceMetrics::ID;
+MachineTraceMetricsAnalysis::Result
+MachineTraceMetricsAnalysis::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+  return Result(MF, MFAM.getResult(MF));
+}
+
+PreservedAnalyses
+MachineTraceMetricsVerifierPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+  MFAM.getResult(MF).verifyAnalysis();

arsenm wrote:

Leftover debugging code? 

https://github.com/llvm/llvm-project/pull/108507
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/19.x: [Clang] Fix crash due to invalid source location in __is_trivially_equality_comparable (#107815) (PR #108147)

2024-09-13 Thread Dimitry Andric via llvm-branch-commits

DimitryAndric wrote:

> Is this PR a fix for a regression or a critical issue?

Regression (assertion/crash while building the chromium parts of qt webengine)

> What is the risk of accepting this into the release branch?

Very low. This only initializes a function parameter which was previously empty.

> What is the risk of NOT accepting this into the release branch?

People will file tickets that their qt webengine builds are crashing. :)


https://github.com/llvm/llvm-project/pull/108147
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/19.x: [DAGCombiner] cache negative result from getMergeStoreCandidates() (#106949) (PR #108397)

2024-09-13 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

This is a fix for a slow compilation issue, and it's not an LLVM 19 regression, 
so it's fine if this doesn't go into the 19.1.0 release.

https://github.com/llvm/llvm-project/pull/108397
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port machine trace metrics analysis to new pass manager. (PR #108507)

2024-09-13 Thread Christudasan Devadasan via llvm-branch-commits


@@ -39,41 +39,68 @@ using namespace llvm;
 
 #define DEBUG_TYPE "machine-trace-metrics"
 
-char MachineTraceMetrics::ID = 0;
+AnalysisKey MachineTraceMetricsAnalysis::Key;
 
-char &llvm::MachineTraceMetricsID = MachineTraceMetrics::ID;
+MachineTraceMetricsAnalysis::Result
+MachineTraceMetricsAnalysis::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+  return Result(MF, MFAM.getResult(MF));
+}
+
+PreservedAnalyses
+MachineTraceMetricsVerifierPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+  MFAM.getResult(MF).verifyAnalysis();

cdevadas wrote:

In the NPM infrastructure verifyAnalysis is done separately. There are many 
such instances in the opt pipeline. This is the first attempt to port CodeGen 
analysis with verify. 

https://github.com/llvm/llvm-project/pull/108507
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port EarlyIfConversion pass to NPM. (PR #108508)

2024-09-13 Thread Christudasan Devadasan via llvm-branch-commits

https://github.com/cdevadas updated 
https://github.com/llvm/llvm-project/pull/108508

>From 8c819329488c087fce339d4fd65761bc986ed80e Mon Sep 17 00:00:00 2001
From: Christudasan Devadasan 
Date: Fri, 13 Sep 2024 12:22:03 +0530
Subject: [PATCH 1/2] [CodeGen][NewPM] Port EarlyIfConversion pass to NPM.

---
 llvm/include/llvm/CodeGen/EarlyIfConversion.h | 24 ++
 llvm/include/llvm/CodeGen/Passes.h|  2 +-
 llvm/include/llvm/InitializePasses.h  |  2 +-
 llvm/include/llvm/Passes/CodeGenPassBuilder.h |  1 +
 .../llvm/Passes/MachinePassRegistry.def   |  2 +-
 llvm/lib/CodeGen/CodeGen.cpp  |  2 +-
 llvm/lib/CodeGen/EarlyIfConversion.cpp| 79 ++-
 llvm/lib/CodeGen/TargetPassConfig.cpp |  4 +-
 llvm/lib/Passes/PassBuilder.cpp   |  1 +
 .../Target/AArch64/AArch64TargetMachine.cpp   |  2 +-
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  2 +-
 llvm/lib/Target/PowerPC/PPCTargetMachine.cpp  |  2 +-
 .../Target/SystemZ/SystemZTargetMachine.cpp   |  2 +-
 llvm/lib/Target/X86/X86TargetMachine.cpp  |  2 +-
 .../early-ifcvt-likely-predictable.mir|  1 +
 .../AArch64/early-ifcvt-regclass-mismatch.mir |  1 +
 .../AArch64/early-ifcvt-same-value.mir|  1 +
 .../CodeGen/PowerPC/early-ifcvt-no-isel.mir   |  2 +
 18 files changed, 102 insertions(+), 30 deletions(-)
 create mode 100644 llvm/include/llvm/CodeGen/EarlyIfConversion.h

diff --git a/llvm/include/llvm/CodeGen/EarlyIfConversion.h 
b/llvm/include/llvm/CodeGen/EarlyIfConversion.h
new file mode 100644
index 00..78bf12ade02c3d
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/EarlyIfConversion.h
@@ -0,0 +1,24 @@
+//===- llvm/CodeGen/EarlyIfConversion.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
+//
+//===--===//
+
+#ifndef LLVM_CODEGEN_EARLYIFCONVERSION_H
+#define LLVM_CODEGEN_EARLYIFCONVERSION_H
+
+#include "llvm/CodeGen/MachinePassManager.h"
+
+namespace llvm {
+
+class EarlyIfConverterPass : public PassInfoMixin {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+MachineFunctionAnalysisManager &MFAM);
+};
+
+} // namespace llvm
+
+#endif // LLVM_CODEGEN_EARLYIFCONVERSION_H
diff --git a/llvm/include/llvm/CodeGen/Passes.h 
b/llvm/include/llvm/CodeGen/Passes.h
index ddb2012cd2bffc..5d042d8daa5630 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -273,7 +273,7 @@ namespace llvm {
 
   /// EarlyIfConverter - This pass performs if-conversion on SSA form by
   /// inserting cmov instructions.
-  extern char &EarlyIfConverterID;
+  extern char &EarlyIfConverterLegacyID;
 
   /// EarlyIfPredicator - This pass performs if-conversion on SSA form by
   /// predicating if/else block and insert select at the join point.
diff --git a/llvm/include/llvm/InitializePasses.h 
b/llvm/include/llvm/InitializePasses.h
index 3fa6fabaeccd64..9d98e80a4fd365 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -98,7 +98,7 @@ void initializeDominatorTreeWrapperPassPass(PassRegistry &);
 void initializeDwarfEHPrepareLegacyPassPass(PassRegistry &);
 void initializeEarlyCSELegacyPassPass(PassRegistry &);
 void initializeEarlyCSEMemSSALegacyPassPass(PassRegistry &);
-void initializeEarlyIfConverterPass(PassRegistry &);
+void initializeEarlyIfConverterLegacyPass(PassRegistry &);
 void initializeEarlyIfPredicatorPass(PassRegistry &);
 void initializeEarlyMachineLICMPass(PassRegistry &);
 void initializeEarlyTailDuplicatePass(PassRegistry &);
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h 
b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index a99fed86d168d1..5f005707fe3cc0 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -27,6 +27,7 @@
 #include "llvm/CodeGen/CodeGenPrepare.h"
 #include "llvm/CodeGen/DeadMachineInstructionElim.h"
 #include "llvm/CodeGen/DwarfEHPrepare.h"
+#include "llvm/CodeGen/EarlyIfConversion.h"
 #include "llvm/CodeGen/ExpandLargeDivRem.h"
 #include "llvm/CodeGen/ExpandLargeFpConvert.h"
 #include "llvm/CodeGen/ExpandMemCmp.h"
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def 
b/llvm/include/llvm/Passes/MachinePassRegistry.def
index e92d6dd97c655a..949936e55a0f06 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -128,6 +128,7 @@ MACHINE_FUNCTION_ANALYSIS("slot-indexes", 
SlotIndexesAnalysis())
 #ifndef MACHINE_FUNCTION_PASS
 #define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
 #endif
+MACHINE_FUNCTION_PASS("early-ifcvt", EarlyIfConverterPass())
 MACHINE_FUNCTION_PASS("dead-mi-elimination", DeadMachineInstructionElimPass())
 MACHINE_FUNCTION_P

[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port EarlyIfConversion pass to NPM. (PR #108508)

2024-09-13 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm approved this pull request.


https://github.com/llvm/llvm-project/pull/108508
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port machine trace metrics analysis to new pass manager. (PR #108507)

2024-09-13 Thread Matt Arsenault via llvm-branch-commits


@@ -102,19 +103,22 @@ class MachineTraceMetrics : public MachineFunctionPass {
   TargetSchedModel SchedModel;
 
 public:
+  friend class MachineTraceMetricsWrapperPass;
   friend class Ensemble;
   friend class Trace;
 
   class Ensemble;
 
-  static char ID;
+  // For legacy pass.
+  MachineTraceMetrics() {
+std::fill(std::begin(Ensembles), std::end(Ensembles), nullptr);
+  }

arsenm wrote:

This is odd to split the constructors, do it in init? 

https://github.com/llvm/llvm-project/pull/108507
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/19.x: [AVR] Fix 16-bit LDDs with immediate overflows (#104923) (PR #106993)

2024-09-13 Thread Patryk Wychowaniec via llvm-branch-commits

Patryk27 wrote:

> Is this PR a fix for a regression or a critical issue?

It's a fix for critical issue within the AVR codegen which causes it to 
generate invalid binaries and/or crash llvm (depending on which concrete code 
path is taken).

It was spotted downstream in Rust, https://github.com/Rahix/avr-hal/issues/573.

> What is the risk of accepting this into the release branch?

The fix has been tested both within LLVM (as proven by the new tests added 
here) and by recompiling rustc and making sure the downstream project works 
correctly as well, so the risk is small.

What's more, the change is isolated to the AVR target - there's no way it could 
affect other targets.

> What is the risk of NOT accepting this into the release branch?

Not huge, I think - rustc has its own fork of llvm-project`where I could 
cherry-pick this commit anyway. Having backport is just the preferred way of 
the rustc team, but I think it's not a rule set in stone. 

https://github.com/llvm/llvm-project/pull/106993
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU][NewPM] Fill out addILPOpts. (PR #108514)

2024-09-13 Thread Christudasan Devadasan via llvm-branch-commits

https://github.com/cdevadas created 
https://github.com/llvm/llvm-project/pull/108514

None

>From 2941048b558ae43ff0c96a1cc301976435c95a7f Mon Sep 17 00:00:00 2001
From: Christudasan Devadasan 
Date: Fri, 13 Sep 2024 13:53:01 +0530
Subject: [PATCH] [AMDGPU][NewPM] Fill out addILPOpts.

---
 llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 7 +++
 llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h   | 1 +
 2 files changed, 8 insertions(+)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 8c45e6b5e589c2..6cc9ff6a981fee 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1898,6 +1898,13 @@ void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass 
&addPass) const {
   addPass(RequireAnalysisPass());
 }
 
+void AMDGPUCodeGenPassBuilder::addILPOpts(AddMachinePass &addPass) const {
+  if (EnableEarlyIfConversion)
+addPass(EarlyIfConverterPass());
+
+  Base::addILPOpts(addPass);
+}
+
 void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
  CreateMCStreamer) const {
   // TODO: Add AsmPrinter.
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h 
b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
index 5b7257ddb36f1e..96b414f294ee70 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
@@ -172,6 +172,7 @@ class AMDGPUCodeGenPassBuilder
   void addIRPasses(AddIRPass &) const;
   void addCodeGenPrepare(AddIRPass &) const;
   void addPreISel(AddIRPass &addPass) const;
+  void addILPOpts(AddMachinePass &) const;
   void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
   Error addInstSelector(AddMachinePass &) const;
 

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU][NewPM] Fill out addILPOpts. (PR #108514)

2024-09-13 Thread Christudasan Devadasan via llvm-branch-commits

cdevadas wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/108514?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#108514** https://app.graphite.dev/github/pr/llvm/llvm-project/108514?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈
* **#108508** https://app.graphite.dev/github/pr/llvm/llvm-project/108508?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#108507** https://app.graphite.dev/github/pr/llvm/llvm-project/108507?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#108506** https://app.graphite.dev/github/pr/llvm/llvm-project/108506?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`

This stack of pull requests is managed by Graphite. https://stacking.dev/?utm_source=stack-comment";>Learn more about 
stacking.


 Join @cdevadas and the rest of your teammates on https://graphite.dev?utm-source=stack-comment";>https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="11px" height="11px"/> Graphite
  

https://github.com/llvm/llvm-project/pull/108514
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU][NewPM] Fill out addILPOpts. (PR #108514)

2024-09-13 Thread Christudasan Devadasan via llvm-branch-commits

https://github.com/cdevadas ready_for_review 
https://github.com/llvm/llvm-project/pull/108514
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU][NewPM] Fill out addILPOpts. (PR #108514)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Christudasan Devadasan (cdevadas)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/108514.diff


2 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+7) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h (+1) 


``diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 8c45e6b5e589c2..6cc9ff6a981fee 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1898,6 +1898,13 @@ void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass 
&addPass) const {
   addPass(RequireAnalysisPass());
 }
 
+void AMDGPUCodeGenPassBuilder::addILPOpts(AddMachinePass &addPass) const {
+  if (EnableEarlyIfConversion)
+addPass(EarlyIfConverterPass());
+
+  Base::addILPOpts(addPass);
+}
+
 void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
  CreateMCStreamer) const {
   // TODO: Add AsmPrinter.
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h 
b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
index 5b7257ddb36f1e..96b414f294ee70 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
@@ -172,6 +172,7 @@ class AMDGPUCodeGenPassBuilder
   void addIRPasses(AddIRPass &) const;
   void addCodeGenPrepare(AddIRPass &) const;
   void addPreISel(AddIRPass &addPass) const;
+  void addILPOpts(AddMachinePass &) const;
   void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
   Error addInstSelector(AddMachinePass &) const;
 

``




https://github.com/llvm/llvm-project/pull/108514
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AMDGPU][NewPM] Fill out addILPOpts. (PR #108514)

2024-09-13 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm approved this pull request.


https://github.com/llvm/llvm-project/pull/108514
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/19.x: [Clang][Concepts] Fix the constraint equivalence checking involving parameter packs (#102131) (PR #106043)

2024-09-13 Thread via llvm-branch-commits

cor3ntin wrote:

How about we deploy that in 19.0.2? It seems like the safest course of action 
at this point.

https://github.com/llvm/llvm-project/pull/106043
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/19.x: Guard an include of `` in `` with availability macro (#108429) (PR #108515)

2024-09-13 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/108515

Backport 127c34948bd54e92ef2ee544e8bc42acecf321ad

Requested by: @var-const

>From b240a4e402e2db9e096a8bb114616bad4f5a2ab3 Mon Sep 17 00:00:00 2001
From: Konstantin Varlamov 
Date: Fri, 13 Sep 2024 01:26:57 -0700
Subject: [PATCH] Guard an include of `` in `` with
 availability macro (#108429)

This fixes a regression introduced in
https://github.com/llvm/llvm-project/pull/96035.

(cherry picked from commit 127c34948bd54e92ef2ee544e8bc42acecf321ad)
---
 libcxx/include/chrono | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 990c415ec2e972..7bec5e5a26ef4a 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -1015,8 +1015,8 @@ constexpr chrono::year  
operator ""y(unsigned lo
 #  include 
 #  if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
 #include 
+#include 
 #  endif
-#  include 
 #endif
 
 #endif // _LIBCPP_CHRONO

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/19.x: Guard an include of `` in `` with availability macro (#108429) (PR #108515)

2024-09-13 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/108515
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/19.x: Guard an include of `` in `` with availability macro (#108429) (PR #108515)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:

@ldionne What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/108515
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/19.x: Guard an include of `` in `` with availability macro (#108429) (PR #108515)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: None (llvmbot)


Changes

Backport 127c34948bd54e92ef2ee544e8bc42acecf321ad

Requested by: @var-const

---
Full diff: https://github.com/llvm/llvm-project/pull/108515.diff


1 Files Affected:

- (modified) libcxx/include/chrono (+1-1) 


``diff
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 990c415ec2e972..7bec5e5a26ef4a 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -1015,8 +1015,8 @@ constexpr chrono::year  
operator ""y(unsigned lo
 #  include 
 #  if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
 #include 
+#include 
 #  endif
-#  include 
 #endif
 
 #endif // _LIBCPP_CHRONO

``




https://github.com/llvm/llvm-project/pull/108515
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Serialization] Code cleanups and polish 83233 (PR #83237)

2024-09-13 Thread Ilya Biryukov via llvm-branch-commits

ilya-biryukov wrote:

I had to replicate what our build was doing very thoroughly, the exact PCMs 
each build action receives were important.
Here's the repro: 
[maps.tgz](https://github.com/user-attachments/files/16992332/maps.tgz). Just 
like last time, it works without the patch and starts failing with the patch.


https://github.com/llvm/llvm-project/pull/83237
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/19.x: [RISCV] Don't outline pcrel_lo when the function has a section prefix (#107943) (PR #108288)

2024-09-13 Thread Sam Elliott via llvm-branch-commits

lenary wrote:

I believe the risk of bringing this in to be fairly small (we did the smallest 
fix possible to make it more amenable to back-porting), but I also knew this 
was fairly close to the 19.1.0 release date. If you think there will be a 
19.1.1, then it can probably wait for that.

https://github.com/llvm/llvm-project/pull/108288
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] [TySan] Fix struct access with different bases (PR #108385)

2024-09-13 Thread via llvm-branch-commits

gbMattN wrote:

Documenting this here as its part of the same issue: the following reproducer 
can be made (see the pull request above)

```
#include 
#include 

struct inner {
struct inner *n;
};

struct outer {
struct inner *i;
};

struct outer* getOuter(){
struct outer *out = malloc(sizeof(struct outer));
struct inner *in = malloc(sizeof(struct inner));

in->n = 0;
out->i = in;

return out;
}

int main(void) {

struct outer* out = getOuter();

while (out->i) {
//out->i = out->i->n;
memcpy(&out->i, &out->i->n, sizeof(out->i));
}

return 0;
}
```
If memcpy is replaced by the commented code, no error is detected. Both code 
runs the same checking function, but they are inserted at different places in 
the Transformation pass. This implies that the wrong checks are being inserted 
for memcpy calls.
The failing check is checking any pointer (in outer at offset 0) against any 
pointer (in inner at offset 0), but due to how the outer is set up, its member 
is recorded simply as "any pointer", with no reference to inner anymore. The 
commented out path doesn't call tysan_check, meaning that their actual TDs 
should be an exact match.

https://github.com/llvm/llvm-project/pull/108385
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/19.x: Guard an include of `` in `` with availability macro (#108429) (PR #108515)

2024-09-13 Thread Louis Dionne via llvm-branch-commits

https://github.com/ldionne approved this pull request.


https://github.com/llvm/llvm-project/pull/108515
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [MLIR][OpenMP][Docs] NFC: Document clause-based op representation (PR #107234)

2024-09-13 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak updated 
https://github.com/llvm/llvm-project/pull/107234

>From 47e8403d4adaba03696862ac3ea353fc0feb37d3 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 3 Sep 2024 17:09:57 +0100
Subject: [PATCH 1/2] [MLIR][OpenMP] NFC: Document clause-based op
 representation

This patch documents the clause-based op represetation discussed in
[this 
RFC](https://discourse.llvm.org/t/rfc-clause-based-representation-of-openmp-dialect-operations/79053).
---
 mlir/docs/Dialects/OpenMPDialect/_index.md | 192 +
 1 file changed, 192 insertions(+)

diff --git a/mlir/docs/Dialects/OpenMPDialect/_index.md 
b/mlir/docs/Dialects/OpenMPDialect/_index.md
index 43e82a871db066..8abdc731675fc0 100644
--- a/mlir/docs/Dialects/OpenMPDialect/_index.md
+++ b/mlir/docs/Dialects/OpenMPDialect/_index.md
@@ -39,3 +39,195 @@ mapping information is named `MapInfoOp` / `omp.map.info`. 
The same rules are
 followed if multiple operations are created for different variants of the same
 directive, e.g. `atomic` becomes `Atomic{Read,Write,Update,Capture}Op` /
 `omp.atomic.{read,write,update,capture}`.
+
+## Clause-Based Operation Definition
+
+One main feature of the OpenMP specification is that, even though the set of
+clauses that could be applied to a given directive is independent from other
+directives, these clauses can generally apply to multiple directives. Since
+clauses usually define which arguments the corresponding MLIR operation takes,
+it is possible (and preferred) to define OpenMP dialect operations based on the
+list of clauses taken by the corresponding directive. This makes it simpler to
+keep their representation consistent across operations and minimizes redundancy
+in the dialect.
+
+To achieve this, the base `OpenMP_Clause` tablegen class has been created. It 
is
+intended to be used to create clause definitions that can be then attached to
+multiple `OpenMP_Op` definitions, resulting in the latter inheriting by default
+all properties defined by clauses attached, similarly to the trait mechanism.
+This mechanism is implemented in
+[OpenMPOpBase.td](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/OpenMP/OpenMPOpBase.td).
+
+### Adding a Clause
+
+OpenMP clause definitions are located in
+[OpenMPClauses.td](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td).
+For each clause, an `OpenMP_Clause` subclass and a definition based on it must
+be created. The subclass must take a `bit` template argument for each of the
+properties it may define, listed below, which is forwarded to the base class.
+The definition must be an instantiation of the base class where all these
+template arguments are set to `false`. The definition's name must be
+`OpenMP_Clause`, whereas its base class' must be
+`OpenMP_ClauseSkip`. Following this pattern makes it possible to
+optionally skip the inheritance of some properties when defining operations:
+[more info](#overriding-clause-inherited-properties).
+
+Clauses can define the following properties:
+  - `list traits`: To be used when having a certain clause always
+implies some op trait, like the `map` clause and the 
`MapClauseOwningInterface`.
+  - `dag(ins) arguments`: Mandatory property holding values and attributes
+used to represent the clause. Argument names use snake_case and should contain
+the clause name to avoid name clashes between clauses. Variadic arguments
+(non-attributes) must contain the "_vars" suffix.
+  - `string assemblyFormat`: Optional formatting string to produce custom
+human-friendly printers and parsers for arguments associated with the clause.
+It will be combined with assembly formats for other clauses depending on the
+`isRequired` template argument passed to the parent `OpenMP_Clause` class, as
+explained [below](#adding-an-operation). 
+  - `string description`: Optional description text to describe the clause and
+its representation.
+  - `string extraClassDeclaration`: Optional C++ declarations to be added to
+operation classes including the clause.
+
+For example:
+
+```tablegen
+class OpenMP_ExampleClauseSkip<
+bit traits = false, bit arguments = false, bit assemblyFormat = false,
+bit description = false, bit extraClassDeclaration = false
+  > : OpenMP_Clause {
+  let arguments = (ins
+Optional:$example_var
+  );
+
+  let assemblyFormat = [{
+`example` `(` $example_var `:` type($example_var) `)`
+  }];
+
+  let description = [{
+The `example_var` argument defines the variable to which the EXAMPLE clause
+applies.
+  }];
+}
+
+def OpenMP_ExampleClause : OpenMP_ExampleClauseSkip<>;
+```
+
+### Adding an Operation
+
+Operations in the OpenMP dialect, located in
+[OpenMPOps.td](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td),
+can be defined like any other regular operation by just specifying a `mnemonic`
+and optional list of `traits` when inheriting from `OpenMP_Op`, and 

[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-13 Thread Victor Campos via llvm-branch-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/108585

Replace code that relies on iterators by LLVM helper functions that take 
ranges. This makes the code simpler and more readable.

>From a2438ce9a61d8e80aa32fa58ca5368a64deacd52 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 9 Aug 2024 13:56:31 +0100
Subject: [PATCH] [ADT] Use range-based helper functions in SmallSet

Replace code that relies on iterators by LLVM helper functions that take
ranges. This makes the code simpler and more readable.
---
 llvm/include/llvm/ADT/SmallSet.h | 36 +---
 1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index 630c98504261aa..d5f64e4f20f854 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -139,10 +139,6 @@ class SmallSet {
   SmallVector Vector;
   std::set Set;
 
-  using VIterator = typename SmallVector::const_iterator;
-  using SIterator = typename std::set::const_iterator;
-  using mutable_iterator = typename SmallVector::iterator;
-
   // In small mode SmallPtrSet uses linear search for the elements, so it is
   // not a good idea to choose this value too high. You may consider using a
   // DenseSet<> instead if you expect many elements in the set.
@@ -163,13 +159,7 @@ class SmallSet {
   }
 
   /// count - Return 1 if the element is in the set, 0 otherwise.
-  size_type count(const T &V) const {
-if (isSmall()) {
-  // Since the collection is small, just do a linear search.
-  return vfind(V) == Vector.end() ? 0 : 1;
-}
-return Set.count(V);
-  }
+  size_type count(const T &V) const { return contains(V) ? 1 : 0; }
 
   /// insert - Insert an element into the set if it isn't already there.
   /// Returns a pair. The first value of it is an iterator to the inserted
@@ -181,7 +171,7 @@ class SmallSet {
   return std::make_pair(const_iterator(I), Inserted);
 }
 
-VIterator I = vfind(V);
+auto I = llvm::find(Vector, V);
 if (I != Vector.end())// Don't reinsert if it already exists.
   return std::make_pair(const_iterator(I), false);
 if (Vector.size() < N) {
@@ -206,11 +196,12 @@ class SmallSet {
   bool erase(const T &V) {
 if (!isSmall())
   return Set.erase(V);
-for (mutable_iterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
-  if (*I == V) {
-Vector.erase(I);
-return true;
-  }
+
+auto It = llvm::find(Vector, V);
+if (It != Vector.end()) {
+  Vector.erase(It);
+  return true;
+}
 return false;
   }
 
@@ -234,19 +225,12 @@ class SmallSet {
   /// Check if the SmallSet contains the given element.
   bool contains(const T &V) const {
 if (isSmall())
-  return vfind(V) != Vector.end();
-return Set.find(V) != Set.end();
+  return llvm::is_contained(Vector, V);
+return llvm::is_contained(Set, V);
   }
 
 private:
   bool isSmall() const { return Set.empty(); }
-
-  VIterator vfind(const T &V) const {
-for (VIterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
-  if (*I == V)
-return I;
-return Vector.end();
-  }
 };
 
 /// If this set is of pointer values, transparently switch over to using

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-adt

Author: Victor Campos (vhscampos)


Changes

Replace code that relies on iterators by LLVM helper functions that take 
ranges. This makes the code simpler and more readable.

---
Full diff: https://github.com/llvm/llvm-project/pull/108585.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/SmallSet.h (+10-26) 


``diff
diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index 630c98504261aa..d5f64e4f20f854 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -139,10 +139,6 @@ class SmallSet {
   SmallVector Vector;
   std::set Set;
 
-  using VIterator = typename SmallVector::const_iterator;
-  using SIterator = typename std::set::const_iterator;
-  using mutable_iterator = typename SmallVector::iterator;
-
   // In small mode SmallPtrSet uses linear search for the elements, so it is
   // not a good idea to choose this value too high. You may consider using a
   // DenseSet<> instead if you expect many elements in the set.
@@ -163,13 +159,7 @@ class SmallSet {
   }
 
   /// count - Return 1 if the element is in the set, 0 otherwise.
-  size_type count(const T &V) const {
-if (isSmall()) {
-  // Since the collection is small, just do a linear search.
-  return vfind(V) == Vector.end() ? 0 : 1;
-}
-return Set.count(V);
-  }
+  size_type count(const T &V) const { return contains(V) ? 1 : 0; }
 
   /// insert - Insert an element into the set if it isn't already there.
   /// Returns a pair. The first value of it is an iterator to the inserted
@@ -181,7 +171,7 @@ class SmallSet {
   return std::make_pair(const_iterator(I), Inserted);
 }
 
-VIterator I = vfind(V);
+auto I = llvm::find(Vector, V);
 if (I != Vector.end())// Don't reinsert if it already exists.
   return std::make_pair(const_iterator(I), false);
 if (Vector.size() < N) {
@@ -206,11 +196,12 @@ class SmallSet {
   bool erase(const T &V) {
 if (!isSmall())
   return Set.erase(V);
-for (mutable_iterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
-  if (*I == V) {
-Vector.erase(I);
-return true;
-  }
+
+auto It = llvm::find(Vector, V);
+if (It != Vector.end()) {
+  Vector.erase(It);
+  return true;
+}
 return false;
   }
 
@@ -234,19 +225,12 @@ class SmallSet {
   /// Check if the SmallSet contains the given element.
   bool contains(const T &V) const {
 if (isSmall())
-  return vfind(V) != Vector.end();
-return Set.find(V) != Set.end();
+  return llvm::is_contained(Vector, V);
+return llvm::is_contained(Set, V);
   }
 
 private:
   bool isSmall() const { return Set.empty(); }
-
-  VIterator vfind(const T &V) const {
-for (VIterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
-  if (*I == V)
-return I;
-return Vector.end();
-  }
 };
 
 /// If this set is of pointer values, transparently switch over to using

``




https://github.com/llvm/llvm-project/pull/108585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits

https://github.com/kuhar approved this pull request.

Nice

https://github.com/llvm/llvm-project/pull/108585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits

https://github.com/kuhar edited https://github.com/llvm/llvm-project/pull/108585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits


@@ -206,11 +196,12 @@ class SmallSet {
   bool erase(const T &V) {
 if (!isSmall())
   return Set.erase(V);
-for (mutable_iterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
-  if (*I == V) {
-Vector.erase(I);
-return true;
-  }
+
+auto It = llvm::find(Vector, V);
+if (It != Vector.end()) {

kuhar wrote:

nit: this is not used outside of the `if`
```suggestion
if (auto It = llvm::find(Vector, V); It != Vector.end()) {
```

https://github.com/llvm/llvm-project/pull/108585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use perfect forwarding in SmallSet::insert() (PR #108590)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits

https://github.com/kuhar edited https://github.com/llvm/llvm-project/pull/108590
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use perfect forwarding in SmallSet::insert() (PR #108590)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits


@@ -231,6 +215,31 @@ class SmallSet {
 
 private:
   bool isSmall() const { return Set.empty(); }
+
+  template 
+  std::pair insertImpl(ArgType &&V) {
+static_assert(std::is_convertible_v,
+  "ArgType must be convertible to T!");
+if (!isSmall()) {
+  auto [I, Inserted] = Set.insert(std::forward(V));
+  return std::make_pair(const_iterator(I), Inserted);

kuhar wrote:

```suggestion
  return {const_iterator(I), Inserted};
```

https://github.com/llvm/llvm-project/pull/108590
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use perfect forwarding in SmallSet::insert() (PR #108590)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits

https://github.com/kuhar commented:

Could you add a test showing the values are forwarded?

https://github.com/llvm/llvm-project/pull/108590
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use perfect forwarding in SmallSet::insert() (PR #108590)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits


@@ -231,6 +215,31 @@ class SmallSet {
 
 private:
   bool isSmall() const { return Set.empty(); }
+
+  template 
+  std::pair insertImpl(ArgType &&V) {
+static_assert(std::is_convertible_v,
+  "ArgType must be convertible to T!");
+if (!isSmall()) {
+  auto [I, Inserted] = Set.insert(std::forward(V));
+  return std::make_pair(const_iterator(I), Inserted);
+}
+
+auto I = llvm::find(Vector, V);
+if (I != Vector.end()) // Don't reinsert if it already exists.
+  return std::make_pair(const_iterator(I), false);

kuhar wrote:

```suggestion
  return {const_iterator(I), false};
```

https://github.com/llvm/llvm-project/pull/108590
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use perfect forwarding in SmallSet::insert() (PR #108590)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits


@@ -231,6 +215,31 @@ class SmallSet {
 
 private:
   bool isSmall() const { return Set.empty(); }
+
+  template 
+  std::pair insertImpl(ArgType &&V) {
+static_assert(std::is_convertible_v,
+  "ArgType must be convertible to T!");
+if (!isSmall()) {
+  auto [I, Inserted] = Set.insert(std::forward(V));
+  return std::make_pair(const_iterator(I), Inserted);
+}
+
+auto I = llvm::find(Vector, V);
+if (I != Vector.end()) // Don't reinsert if it already exists.
+  return std::make_pair(const_iterator(I), false);
+if (Vector.size() < N) {
+  Vector.push_back(std::forward(V));
+  return std::make_pair(const_iterator(std::prev(Vector.end())), true);

kuhar wrote:

```suggestion
  return{const_iterator(std::prev(Vector.end())), true};
```

https://github.com/llvm/llvm-project/pull/108590
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use perfect forwarding in SmallSet::insert() (PR #108590)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits


@@ -231,6 +215,31 @@ class SmallSet {
 
 private:
   bool isSmall() const { return Set.empty(); }
+
+  template 
+  std::pair insertImpl(ArgType &&V) {
+static_assert(std::is_convertible_v,
+  "ArgType must be convertible to T!");
+if (!isSmall()) {
+  auto [I, Inserted] = Set.insert(std::forward(V));
+  return std::make_pair(const_iterator(I), Inserted);
+}
+
+auto I = llvm::find(Vector, V);
+if (I != Vector.end()) // Don't reinsert if it already exists.

kuhar wrote:

```suggestion
if (auto I = llvm::find(Vector, V); I != Vector.end()) // Don't reinsert if 
it already exists.
```

https://github.com/llvm/llvm-project/pull/108590
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use perfect forwarding in SmallSet::insert() (PR #108590)

2024-09-13 Thread Jakub Kuderski via llvm-branch-commits


@@ -231,6 +215,31 @@ class SmallSet {
 
 private:
   bool isSmall() const { return Set.empty(); }
+
+  template 
+  std::pair insertImpl(ArgType &&V) {
+static_assert(std::is_convertible_v,
+  "ArgType must be convertible to T!");
+if (!isSmall()) {
+  auto [I, Inserted] = Set.insert(std::forward(V));
+  return std::make_pair(const_iterator(I), Inserted);
+}
+
+auto I = llvm::find(Vector, V);
+if (I != Vector.end()) // Don't reinsert if it already exists.
+  return std::make_pair(const_iterator(I), false);
+if (Vector.size() < N) {
+  Vector.push_back(std::forward(V));
+  return std::make_pair(const_iterator(std::prev(Vector.end())), true);
+}
+
+// Otherwise, grow from vector to set.
+Set.insert(std::make_move_iterator(Vector.begin()),
+   std::make_move_iterator(Vector.end()));
+Vector.clear();
+return std::make_pair(
+const_iterator(Set.insert(std::forward(V)).first), true);

kuhar wrote:

```suggestion
return {const_iterator(Set.insert(std::forward(V)).first), true};
```

https://github.com/llvm/llvm-project/pull/108590
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Add more useful methods to SmallSet API (PR #108601)

2024-09-13 Thread Victor Campos via llvm-branch-commits

https://github.com/vhscampos created 
https://github.com/llvm/llvm-project/pull/108601

This patch adds useful methods to the SmallSet API:

 - Constructor that takes pair of iterators.
 - Constructor that takes a range.
 - Constructor that takes an initializer list.
 - Copy constructor.
 - Move constructor.
 - Copy assignment operator.
 - Move assignment operator.

>From d05069198321f3bab9de7db65f48f3c2b15b34bc Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Fri, 9 Aug 2024 14:00:32 +0100
Subject: [PATCH] [ADT] Add more useful methods to SmallSet API

This patch adds useful methods to the SmallSet API:

 - Constructor that takes pair of iterators.
 - Constructor that takes a range.
 - Constructor that takes an initializer list.
 - Copy constructor.
 - Move constructor.
 - Copy assignment operator.
 - Move assignment operator.
---
 llvm/include/llvm/ADT/SmallSet.h| 21 --
 llvm/unittests/ADT/SmallSetTest.cpp | 60 +
 2 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index c864eda8f8..2e26ad65eb2dd6 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -14,14 +14,13 @@
 #ifndef LLVM_ADT_SMALLSET_H
 #define LLVM_ADT_SMALLSET_H
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/iterator.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/type_traits.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -151,6 +150,22 @@ class SmallSet {
   using const_iterator = SmallSetIterator;
 
   SmallSet() = default;
+  SmallSet(const SmallSet &) = default;
+  SmallSet(SmallSet &&) = default;
+
+  template  SmallSet(IterT Begin, IterT End) {
+this->insert(Begin, End);
+  }
+
+  template 
+  explicit SmallSet(const iterator_range &R) {
+this->insert(R.begin(), R.end());
+  }
+
+  SmallSet(std::initializer_list L) { this->insert(L.begin(), L.end()); }
+
+  SmallSet &operator=(const SmallSet &) = default;
+  SmallSet &operator=(SmallSet &&) = default;
 
   [[nodiscard]] bool empty() const { return Vector.empty() && Set.empty(); }
 
diff --git a/llvm/unittests/ADT/SmallSetTest.cpp 
b/llvm/unittests/ADT/SmallSetTest.cpp
index b50b368ae66361..ced1ba5dce34d8 100644
--- a/llvm/unittests/ADT/SmallSetTest.cpp
+++ b/llvm/unittests/ADT/SmallSetTest.cpp
@@ -17,6 +17,66 @@
 
 using namespace llvm;
 
+TEST(SmallSetTest, ConstructorIteratorPair) {
+  auto L = {1, 2, 3, 4, 5};
+  SmallSet S(std::begin(L), std::end(L));
+  for (int Value : L)
+EXPECT_TRUE(S.contains(Value));
+}
+
+TEST(SmallSet, ConstructorRange) {
+  auto L = {1, 2, 3, 4, 5};
+
+  SmallSet S(llvm::make_range(std::begin(L), std::end(L)));
+  for (int Value : L)
+EXPECT_TRUE(S.contains(Value));
+}
+
+TEST(SmallSet, ConstructorInitializerList) {
+  auto L = {1, 2, 3, 4, 5};
+  SmallSet S = {1, 2, 3, 4, 5};
+  for (int Value : L)
+EXPECT_TRUE(S.contains(Value));
+}
+
+TEST(SmallSet, CopyConstructor) {
+  SmallSet S = {1, 2, 3};
+  SmallSet T = S;
+
+  EXPECT_EQ(S, T);
+}
+
+TEST(SmallSet, MoveConstructor) {
+  auto L = {1, 2, 3};
+  SmallSet S = L;
+  SmallSet T = std::move(S);
+
+  EXPECT_TRUE(T.size() == L.size());
+  for (int Value : L) {
+EXPECT_TRUE(T.contains(Value));
+  }
+}
+
+TEST(SmallSet, CopyAssignment) {
+  SmallSet S = {1, 2, 3};
+  SmallSet T;
+  T = S;
+
+  EXPECT_EQ(S, T);
+}
+
+TEST(SmallSet, MoveAssignment) {
+  auto L = {1, 2, 3};
+  SmallSet S = L;
+  SmallSet T;
+  T = std::move(S);
+
+  EXPECT_TRUE(T.size() == L.size());
+  for (int Value : L) {
+EXPECT_TRUE(T.contains(Value));
+  }
+}
+
 TEST(SmallSetTest, Insert) {
 
   SmallSet s1;

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Add more useful methods to SmallSet API (PR #108601)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-adt

Author: Victor Campos (vhscampos)


Changes

This patch adds useful methods to the SmallSet API:

 - Constructor that takes pair of iterators.
 - Constructor that takes a range.
 - Constructor that takes an initializer list.
 - Copy constructor.
 - Move constructor.
 - Copy assignment operator.
 - Move assignment operator.

---
Full diff: https://github.com/llvm/llvm-project/pull/108601.diff


2 Files Affected:

- (modified) llvm/include/llvm/ADT/SmallSet.h (+18-3) 
- (modified) llvm/unittests/ADT/SmallSetTest.cpp (+60) 


``diff
diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index c864eda8f8..2e26ad65eb2dd6 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -14,14 +14,13 @@
 #ifndef LLVM_ADT_SMALLSET_H
 #define LLVM_ADT_SMALLSET_H
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/iterator.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/type_traits.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -151,6 +150,22 @@ class SmallSet {
   using const_iterator = SmallSetIterator;
 
   SmallSet() = default;
+  SmallSet(const SmallSet &) = default;
+  SmallSet(SmallSet &&) = default;
+
+  template  SmallSet(IterT Begin, IterT End) {
+this->insert(Begin, End);
+  }
+
+  template 
+  explicit SmallSet(const iterator_range &R) {
+this->insert(R.begin(), R.end());
+  }
+
+  SmallSet(std::initializer_list L) { this->insert(L.begin(), L.end()); }
+
+  SmallSet &operator=(const SmallSet &) = default;
+  SmallSet &operator=(SmallSet &&) = default;
 
   [[nodiscard]] bool empty() const { return Vector.empty() && Set.empty(); }
 
diff --git a/llvm/unittests/ADT/SmallSetTest.cpp 
b/llvm/unittests/ADT/SmallSetTest.cpp
index b50b368ae66361..ced1ba5dce34d8 100644
--- a/llvm/unittests/ADT/SmallSetTest.cpp
+++ b/llvm/unittests/ADT/SmallSetTest.cpp
@@ -17,6 +17,66 @@
 
 using namespace llvm;
 
+TEST(SmallSetTest, ConstructorIteratorPair) {
+  auto L = {1, 2, 3, 4, 5};
+  SmallSet S(std::begin(L), std::end(L));
+  for (int Value : L)
+EXPECT_TRUE(S.contains(Value));
+}
+
+TEST(SmallSet, ConstructorRange) {
+  auto L = {1, 2, 3, 4, 5};
+
+  SmallSet S(llvm::make_range(std::begin(L), std::end(L)));
+  for (int Value : L)
+EXPECT_TRUE(S.contains(Value));
+}
+
+TEST(SmallSet, ConstructorInitializerList) {
+  auto L = {1, 2, 3, 4, 5};
+  SmallSet S = {1, 2, 3, 4, 5};
+  for (int Value : L)
+EXPECT_TRUE(S.contains(Value));
+}
+
+TEST(SmallSet, CopyConstructor) {
+  SmallSet S = {1, 2, 3};
+  SmallSet T = S;
+
+  EXPECT_EQ(S, T);
+}
+
+TEST(SmallSet, MoveConstructor) {
+  auto L = {1, 2, 3};
+  SmallSet S = L;
+  SmallSet T = std::move(S);
+
+  EXPECT_TRUE(T.size() == L.size());
+  for (int Value : L) {
+EXPECT_TRUE(T.contains(Value));
+  }
+}
+
+TEST(SmallSet, CopyAssignment) {
+  SmallSet S = {1, 2, 3};
+  SmallSet T;
+  T = S;
+
+  EXPECT_EQ(S, T);
+}
+
+TEST(SmallSet, MoveAssignment) {
+  auto L = {1, 2, 3};
+  SmallSet S = L;
+  SmallSet T;
+  T = std::move(S);
+
+  EXPECT_TRUE(T.size() == L.size());
+  for (int Value : L) {
+EXPECT_TRUE(T.contains(Value));
+  }
+}
+
 TEST(SmallSetTest, Insert) {
 
   SmallSet s1;

``




https://github.com/llvm/llvm-project/pull/108601
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 4e53d12 - Revert "[Utils] add update-verify-tests.py (#97369)"

2024-09-13 Thread via llvm-branch-commits

Author: Rahul Joshi
Date: 2024-09-13T12:13:02-07:00
New Revision: 4e53d121f3f83f7ffe23a9dc835a0ffd68a5a1c9

URL: 
https://github.com/llvm/llvm-project/commit/4e53d121f3f83f7ffe23a9dc835a0ffd68a5a1c9
DIFF: 
https://github.com/llvm/llvm-project/commit/4e53d121f3f83f7ffe23a9dc835a0ffd68a5a1c9.diff

LOG: Revert "[Utils] add update-verify-tests.py (#97369)"

This reverts commit d4f41befb7256f8e8378ae358b2b3d802454d6a4.

Added: 


Modified: 


Removed: 
clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected
clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c
clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c.expected
clang/test/utils/update-verify-tests/Inputs/multiple-errors.c
clang/test/utils/update-verify-tests/Inputs/multiple-errors.c.expected

clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c

clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c.expected
clang/test/utils/update-verify-tests/Inputs/no-checks.c
clang/test/utils/update-verify-tests/Inputs/no-checks.c.expected
clang/test/utils/update-verify-tests/Inputs/no-diags.c
clang/test/utils/update-verify-tests/Inputs/no-diags.c.expected
clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c
clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c.expected
clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c
clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c.expected
clang/test/utils/update-verify-tests/Inputs/update-same-line.c
clang/test/utils/update-verify-tests/Inputs/update-same-line.c.expected
clang/test/utils/update-verify-tests/Inputs/update-single-check.c
clang/test/utils/update-verify-tests/Inputs/update-single-check.c.expected
clang/test/utils/update-verify-tests/duplicate-diag.test
clang/test/utils/update-verify-tests/infer-indentation.test
clang/test/utils/update-verify-tests/leave-existing-diags.test
clang/test/utils/update-verify-tests/lit.local.cfg
clang/test/utils/update-verify-tests/multiple-errors.test
clang/test/utils/update-verify-tests/multiple-missing-errors-same-line.test
clang/test/utils/update-verify-tests/no-checks.test
clang/test/utils/update-verify-tests/no-diags.test
clang/test/utils/update-verify-tests/no-expected-diags.test
clang/test/utils/update-verify-tests/non-default-prefix.test
clang/test/utils/update-verify-tests/update-same-line.test
clang/test/utils/update-verify-tests/update-single-check.test
clang/utils/UpdateVerifyTests/core.py
clang/utils/update-verify-tests.py



diff  --git a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c 
b/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
deleted file mode 100644
index 8c7e46c6eca9c1..00
--- a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
-// expected-error@+1{{use of undeclared identifier 'a'}}
-a = 2; a = 2;
-b = 2; b = 2;
-// expected-error@+1 3{{use of undeclared identifier 'c'}}
-c = 2; c = 2;
-// expected-error 2{{asdf}}
-}

diff  --git 
a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected 
b/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
deleted file mode 100644
index 6214ff382f4495..00
--- a/clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
-// expected-error@+1 2{{use of undeclared identifier 'a'}}
-a = 2; a = 2;
-// expected-error@+1 2{{use of undeclared identifier 'b'}}
-b = 2; b = 2;
-// expected-error@+1 2{{use of undeclared identifier 'c'}}
-c = 2; c = 2;
-}

diff  --git a/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c 
b/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
deleted file mode 100644
index 0210ac35fd5cd1..00
--- a/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c
+++ /dev/null
@@ -1,8 +0,0 @@
-void foo() {
- // expected-error@+12  {{use of undeclared identifier 
'a'}}
-a = 2; a = 2; b = 2; b = 2; c = 2;
- // expected-error@+12  {{asdf}}
-d = 2;
-e = 2; f = 2; // expected-error2  {{use of 
undeclared identifier 'e'}}
-}
-

diff  --git 
a/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected 
b/clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected
deleted file mode 100644
index 5c5aaeeef97acf..00
--- a/clang/test/utils/update-verify-tests/Inputs

[llvm-branch-commits] Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)" (PR #108645)

2024-09-13 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer created 
https://github.com/llvm/llvm-project/pull/108645

This reverts commit e7f782e7481cea23ef452a75607d3d61f5bd0d22.

This had UBSan failures:

[--] 1 test from ConfigCompileTests
[ RUN  ] ConfigCompileTests.DiagnosticSuppression
Config fragment: compiling :0 -> 0x7B8366E2F7D8 (trusted=false)
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33:
 runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs'

UndefinedBehaviorSanitizer: undefined-behavior 
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)" (PR #108645)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-clangd

Author: Florian Mayer (fmayer)


Changes

This reverts commit e7f782e7481cea23ef452a75607d3d61f5bd0d22.

This had UBSan failures:

[--] 1 test from ConfigCompileTests
[ RUN  ] ConfigCompileTests.DiagnosticSuppression
Config fragment: compiling :0 -> 0x7B8366E2F7D8 
(trusted=false)
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33:
 runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs'

UndefinedBehaviorSanitizer: undefined-behavior 
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33


---

Patch is 65.53 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/108645.diff


29 Files Affected:

- (modified) clang-tools-extra/clangd/Diagnostics.cpp (+7-20) 
- (modified) clang-tools-extra/clangd/Diagnostics.h (+4-4) 
- (modified) clang-tools-extra/clangd/ParsedAST.cpp (+3-3) 
- (modified) clang-tools-extra/clangd/Preamble.cpp (+2-2) 
- (modified) clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp (+13-34) 
- (modified) clang/include/clang/Basic/Attr.td (+7-5) 
- (modified) clang/include/clang/Basic/Diagnostic.h (+2-6) 
- (modified) clang/include/clang/Basic/DiagnosticCategories.h (+2-3) 
- (modified) clang/include/clang/Basic/DiagnosticIDs.h (+18-135) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-6) 
- (modified) clang/lib/Basic/Diagnostic.cpp (+8-14) 
- (modified) clang/lib/Basic/DiagnosticIDs.cpp (+117-163) 
- (modified) clang/lib/Frontend/LogDiagnosticPrinter.cpp (+2-2) 
- (modified) clang/lib/Frontend/SerializedDiagnosticPrinter.cpp (+5-7) 
- (modified) clang/lib/Frontend/TextDiagnosticPrinter.cpp (+3-7) 
- (modified) clang/lib/Sema/Sema.cpp (+2-3) 
- (modified) clang/lib/Sema/SemaCUDA.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+5-21) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+5-27) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+1-2) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp (+1) 
- (modified) clang/test/Sema/diagnose_if.c (+4-4) 
- (removed) clang/test/SemaCXX/diagnose_if-warning-group.cpp (-63) 
- (modified) clang/tools/diagtool/ListWarnings.cpp (+4-3) 
- (modified) clang/tools/diagtool/ShowEnabledWarnings.cpp (+3-3) 
- (modified) clang/tools/libclang/CXStoredDiagnostic.cpp (+1-3) 
- (modified) flang/lib/Frontend/TextDiagnosticPrinter.cpp (+2-2) 


``diff
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 552dd36b6900bf..d5eca083eb6512 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,17 +579,7 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto &Diag : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  const StringRef Warning = [&] {
-if (OrigSrcMgr) {
-  return OrigSrcMgr->getDiagnostics()
-  .getDiagnosticIDs()
-  ->getWarningOptionForDiag(Diag.ID);
-}
-if (!DiagnosticIDs::IsCustomDiag(Diag.ID))
-  return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID);
-return StringRef{};
-  }();
-
+  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -906,23 +896,20 @@ void StoreDiags::flushLastDiag() {
   Output.push_back(std::move(*LastDiag));
 }
 
-bool isDiagnosticSuppressed(const clang::Diagnostic &Diag,
-const llvm::StringSet<> &Suppress,
-const LangOptions &LangOpts) {
+bool isBuiltinDiagnosticSuppressed(unsigned ID,
+   const llvm::StringSet<> &Suppress,
+   const LangOptions &LangOpts) {
   // Don't complain about header-only stuff in mainfiles if it's a header.
   // FIXME: would be cleaner to suppress in clang, once we decide whether the
   //behavior should be to silently-ignore or respect the pragma.
-  if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file &&
-  LangOpts.IsHeaderFile)
+  if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile)
 return true;
 
-  if (const char *CodePtr = getDiagnosticCode(Diag.getID())) {
+  if (const char *CodePtr = getDiagnosticCode(ID)) {
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning =
-  Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag(
-  Diag.getID());
+  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(I

[llvm-branch-commits] Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)" (PR #108645)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Florian Mayer (fmayer)


Changes

This reverts commit e7f782e7481cea23ef452a75607d3d61f5bd0d22.

This had UBSan failures:

[--] 1 test from ConfigCompileTests
[ RUN  ] ConfigCompileTests.DiagnosticSuppression
Config fragment: compiling :0 -> 0x7B8366E2F7D8 
(trusted=false)
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33:
 runtime error: reference binding to null pointer of type 'clang::DiagnosticIDs'

UndefinedBehaviorSanitizer: undefined-behavior 
/usr/local/google/home/fmayer/large/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:203:33


---

Patch is 65.53 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/108645.diff


29 Files Affected:

- (modified) clang-tools-extra/clangd/Diagnostics.cpp (+7-20) 
- (modified) clang-tools-extra/clangd/Diagnostics.h (+4-4) 
- (modified) clang-tools-extra/clangd/ParsedAST.cpp (+3-3) 
- (modified) clang-tools-extra/clangd/Preamble.cpp (+2-2) 
- (modified) clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp (+13-34) 
- (modified) clang/include/clang/Basic/Attr.td (+7-5) 
- (modified) clang/include/clang/Basic/Diagnostic.h (+2-6) 
- (modified) clang/include/clang/Basic/DiagnosticCategories.h (+2-3) 
- (modified) clang/include/clang/Basic/DiagnosticIDs.h (+18-135) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (-6) 
- (modified) clang/lib/Basic/Diagnostic.cpp (+8-14) 
- (modified) clang/lib/Basic/DiagnosticIDs.cpp (+117-163) 
- (modified) clang/lib/Frontend/LogDiagnosticPrinter.cpp (+2-2) 
- (modified) clang/lib/Frontend/SerializedDiagnosticPrinter.cpp (+5-7) 
- (modified) clang/lib/Frontend/TextDiagnosticPrinter.cpp (+3-7) 
- (modified) clang/lib/Sema/Sema.cpp (+2-3) 
- (modified) clang/lib/Sema/SemaCUDA.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+5-21) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+5-27) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+1-2) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp (+1) 
- (modified) clang/test/Sema/diagnose_if.c (+4-4) 
- (removed) clang/test/SemaCXX/diagnose_if-warning-group.cpp (-63) 
- (modified) clang/tools/diagtool/ListWarnings.cpp (+4-3) 
- (modified) clang/tools/diagtool/ShowEnabledWarnings.cpp (+3-3) 
- (modified) clang/tools/libclang/CXStoredDiagnostic.cpp (+1-3) 
- (modified) flang/lib/Frontend/TextDiagnosticPrinter.cpp (+2-2) 


``diff
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 552dd36b6900bf..d5eca083eb6512 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,17 +579,7 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto &Diag : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  const StringRef Warning = [&] {
-if (OrigSrcMgr) {
-  return OrigSrcMgr->getDiagnostics()
-  .getDiagnosticIDs()
-  ->getWarningOptionForDiag(Diag.ID);
-}
-if (!DiagnosticIDs::IsCustomDiag(Diag.ID))
-  return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID);
-return StringRef{};
-  }();
-
+  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -906,23 +896,20 @@ void StoreDiags::flushLastDiag() {
   Output.push_back(std::move(*LastDiag));
 }
 
-bool isDiagnosticSuppressed(const clang::Diagnostic &Diag,
-const llvm::StringSet<> &Suppress,
-const LangOptions &LangOpts) {
+bool isBuiltinDiagnosticSuppressed(unsigned ID,
+   const llvm::StringSet<> &Suppress,
+   const LangOptions &LangOpts) {
   // Don't complain about header-only stuff in mainfiles if it's a header.
   // FIXME: would be cleaner to suppress in clang, once we decide whether the
   //behavior should be to silently-ignore or respect the pragma.
-  if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file &&
-  LangOpts.IsHeaderFile)
+  if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile)
 return true;
 
-  if (const char *CodePtr = getDiagnosticCode(Diag.getID())) {
+  if (const char *CodePtr = getDiagnosticCode(ID)) {
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning =
-  Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag(
-  Diag.getID());
+  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
   if (!Warning.empty()

[llvm-branch-commits] Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)" (PR #108645)

2024-09-13 Thread Florian Mayer via llvm-branch-commits

fmayer wrote:

I submitted this to get the buildbot back to green, happy to help if you have 
more questions on how to reproduce!

https://github.com/llvm/llvm-project/pull/108645
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)" (PR #108645)

2024-09-13 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer closed 
https://github.com/llvm/llvm-project/pull/108645
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/19.x: [lld] select a default eflags for hexagon (#108431) (PR #108661)

2024-09-13 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/108661
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/19.x: [lld] select a default eflags for hexagon (#108431) (PR #108661)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:

@quic-akaryaki What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/108661
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/19.x: [lld] select a default eflags for hexagon (#108431) (PR #108661)

2024-09-13 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/108661

Backport d1ba432533aafc52fc59158350af937a8b6b9538

Requested by: @androm3da

>From c7dd9ed62e59f26057e86aa872ad9a166f9f645f Mon Sep 17 00:00:00 2001
From: Brian Cain 
Date: Fri, 13 Sep 2024 17:10:03 -0500
Subject: [PATCH] [lld] select a default eflags for hexagon (#108431)

Empty archives are apparently routine in linux kernel builds, so instead
of asserting, we should handle this case with a sane default value.

(cherry picked from commit d1ba432533aafc52fc59158350af937a8b6b9538)
---
 lld/ELF/Arch/Hexagon.cpp | 8 +++-
 lld/test/ELF/hexagon-eflag.s | 5 +
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 54821c299bde9e..abde3cd964917e 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -60,17 +60,15 @@ Hexagon::Hexagon() {
 }
 
 uint32_t Hexagon::calcEFlags() const {
-  assert(!ctx.objectFiles.empty());
-
   // The architecture revision must always be equal to or greater than
   // greatest revision in the list of inputs.
-  uint32_t ret = 0;
+  std::optional ret;
   for (InputFile *f : ctx.objectFiles) {
 uint32_t eflags = cast>(f)->getObj().getHeader().e_flags;
-if (eflags > ret)
+if (!ret || eflags > *ret)
   ret = eflags;
   }
-  return ret;
+  return ret.value_or(/* Default Arch Rev: */ 0x60);
 }
 
 static uint32_t applyMask(uint32_t mask, uint32_t data) {
diff --git a/lld/test/ELF/hexagon-eflag.s b/lld/test/ELF/hexagon-eflag.s
index 01cb5e5b0f2935..dbe8604f69fda3 100644
--- a/lld/test/ELF/hexagon-eflag.s
+++ b/lld/test/ELF/hexagon-eflag.s
@@ -5,3 +5,8 @@
 # RUN: llvm-readelf -h  %t3 | FileCheck %s
 # Verify that the largest arch in the input list is selected.
 # CHECK: Flags: 0x62
+
+# RUN: llvm-ar rcsD %t4
+# RUN: ld.lld -m hexagonelf %t4 -o %t5
+# RUN: llvm-readelf -h  %t5 | FileCheck --check-prefix=CHECK-EMPTYARCHIVE %s
+# CHECK-EMPTYARCHIVE: Flags: 0x60

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/19.x: [lld] select a default eflags for hexagon (#108431) (PR #108661)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lld-elf

Author: None (llvmbot)


Changes

Backport d1ba432533aafc52fc59158350af937a8b6b9538

Requested by: @androm3da

---
Full diff: https://github.com/llvm/llvm-project/pull/108661.diff


2 Files Affected:

- (modified) lld/ELF/Arch/Hexagon.cpp (+3-5) 
- (modified) lld/test/ELF/hexagon-eflag.s (+5) 


``diff
diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp
index 54821c299bde9e..abde3cd964917e 100644
--- a/lld/ELF/Arch/Hexagon.cpp
+++ b/lld/ELF/Arch/Hexagon.cpp
@@ -60,17 +60,15 @@ Hexagon::Hexagon() {
 }
 
 uint32_t Hexagon::calcEFlags() const {
-  assert(!ctx.objectFiles.empty());
-
   // The architecture revision must always be equal to or greater than
   // greatest revision in the list of inputs.
-  uint32_t ret = 0;
+  std::optional ret;
   for (InputFile *f : ctx.objectFiles) {
 uint32_t eflags = cast>(f)->getObj().getHeader().e_flags;
-if (eflags > ret)
+if (!ret || eflags > *ret)
   ret = eflags;
   }
-  return ret;
+  return ret.value_or(/* Default Arch Rev: */ 0x60);
 }
 
 static uint32_t applyMask(uint32_t mask, uint32_t data) {
diff --git a/lld/test/ELF/hexagon-eflag.s b/lld/test/ELF/hexagon-eflag.s
index 01cb5e5b0f2935..dbe8604f69fda3 100644
--- a/lld/test/ELF/hexagon-eflag.s
+++ b/lld/test/ELF/hexagon-eflag.s
@@ -5,3 +5,8 @@
 # RUN: llvm-readelf -h  %t3 | FileCheck %s
 # Verify that the largest arch in the input list is selected.
 # CHECK: Flags: 0x62
+
+# RUN: llvm-ar rcsD %t4
+# RUN: ld.lld -m hexagonelf %t4 -o %t5
+# RUN: llvm-readelf -h  %t5 | FileCheck --check-prefix=CHECK-EMPTYARCHIVE %s
+# CHECK-EMPTYARCHIVE: Flags: 0x60

``




https://github.com/llvm/llvm-project/pull/108661
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] Revert "Reapply "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" (#108453)" (PR #108645)

2024-09-13 Thread Florian Mayer via llvm-branch-commits

fmayer wrote:

The error is gone in the first buildbot build with this revert: 
https://lab.llvm.org/buildbot/#/builders/169/builds/3191/steps/9/logs/stdio

https://github.com/llvm/llvm-project/pull/108645
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Fix intersecting stacks workaround (PR #108672)

2024-09-13 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka created 
https://github.com/llvm/llvm-project/pull/108672

I don't have reproducers, and don't know if this
branch is even possible but it looks like a typo
in 031c40dc3c71e1e08d0c459b81fc6b54184cec58.

Before the patch:
For order "stk_begin, tls_begin, stk_end, tls_end", range [stk_end, tls_end) 
was discarded.
For order "stk_begin, tls_begin, tls_end, stk_end", range [stk_end, stk_end) 
was discarded.

After the patch:
For order "stk_begin, tls_begin, stk_end, tls_end", range [stk_end, tls_end) 
goes to tls.
For order "stk_begin, tls_begin, tls_end, stk_end", range [stk_end, stk_end) 
goes to tls.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Fix intersecting stacks workaround (PR #108672)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)


Changes

I don't have reproducers, and don't know if this
branch is even possible but it looks like a typo
in 031c40dc3c71e1e08d0c459b81fc6b54184cec58.

Before the patch:
For order "stk_begin, tls_begin, stk_end, tls_end", range [stk_end, tls_end) 
was discarded.
For order "stk_begin, tls_begin, tls_end, stk_end", range [stk_end, stk_end) 
was discarded.

After the patch:
For order "stk_begin, tls_begin, stk_end, tls_end", range [stk_end, tls_end) 
goes to tls.
For order "stk_begin, tls_begin, tls_end, stk_end", range [stk_end, stk_end) 
goes to tls.


---
Full diff: https://github.com/llvm/llvm-project/pull/108672.diff


1 Files Affected:

- (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp 
(+1-1) 


``diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index c3c717bbdbe4c9..579d163479858c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -642,7 +642,7 @@ void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr 
*stk_size,
   if (!main) {
 // If stack and tls intersect, make them non-intersecting.
 if (*tls_addr > *stk_addr && *tls_addr < *stk_addr + *stk_size) {
-  if (*stk_addr + *stk_size < *tls_addr + *tls_size)
+  if (*stk_addr + *stk_size > *tls_addr + *tls_size)
 *tls_size = *stk_addr + *stk_size - *tls_addr;
   *stk_size = *tls_addr - *stk_addr;
 }

``




https://github.com/llvm/llvm-project/pull/108672
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Fix intersecting stacks workaround (PR #108672)

2024-09-13 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/108672


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Fix intersecting stacks workaround (PR #108672)

2024-09-13 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/108672


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [lld] release/19.x: [lld] select a default eflags for hexagon (#108431) (PR #108661)

2024-09-13 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/108661
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-13 Thread via llvm-branch-commits

https://github.com/piggynl approved this pull request.


https://github.com/llvm/llvm-project/pull/108585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Add CHECK that static TLS info is ready (PR #108684)

2024-09-13 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka created 
https://github.com/llvm/llvm-project/pull/108684

There is possibility of
static_tls_begin is set and static_tls_end is not yet

The test reproduces the case.
Stack trace looks like this:
   `MsanThread::Init`
   `SetThreadStackAndTls`
   `GetThreadStackAndTls`
   `GetThreadStackTopAndBottom`
   `pthread_getattr_np`
   `realloc`
   `__sanitizer_malloc_hook`
   TLS access
   `___interceptor___tls_get_addr`
   `DTLS_on_tls_get_addr`

The issue is that `SetThreadStackAndTls` implementation
stores `tls_begin` before `GetThreadStackTopAndBottom`,
and `tls_end` after. So we have partially initialized
state in `DTLS_on_tls_get_addr`.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Add CHECK that static TLS info is ready (PR #108684)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)


Changes

There is possibility of
static_tls_begin is set and static_tls_end is not yet

The test reproduces the case.
Stack trace looks like this:
   `MsanThread::Init`
   `SetThreadStackAndTls`
   `GetThreadStackAndTls`
   `GetThreadStackTopAndBottom`
   `pthread_getattr_np`
   `realloc`
   `__sanitizer_malloc_hook`
   TLS access
   `___interceptor___tls_get_addr`
   `DTLS_on_tls_get_addr`

The issue is that `SetThreadStackAndTls` implementation
stores `tls_begin` before `GetThreadStackTopAndBottom`,
and `tls_end` after. So we have partially initialized
state in `DTLS_on_tls_get_addr`.


---
Full diff: https://github.com/llvm/llvm-project/pull/108684.diff


2 Files Affected:

- (modified) compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp (+1) 
- (added) compiler-rt/test/sanitizer_common/TestCases/Linux/tls_malloc_hook.c 
(+60) 


``diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
index 087bd801b6e5ff..a17a14882d0e15 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -130,6 +130,7 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
   DTLS::DTV *dtv = DTLS_Find(dso_id);
   if (!dtv || dtv->beg)
 return nullptr;
+  CHECK_LE(static_tls_begin, static_tls_end);
   uptr tls_size = 0;
   uptr tls_beg = reinterpret_cast(res) - arg->offset - kDtvOffset;
   VReport(2,
diff --git 
a/compiler-rt/test/sanitizer_common/TestCases/Linux/tls_malloc_hook.c 
b/compiler-rt/test/sanitizer_common/TestCases/Linux/tls_malloc_hook.c
new file mode 100644
index 00..c582372ab9763d
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/tls_malloc_hook.c
@@ -0,0 +1,60 @@
+// Test that we don't crash accessing DTLS from malloc hook.
+
+// RUN: %clang %s -o %t
+// RUN: %clang %s -DBUILD_SO -fPIC -o %t-so.so -shared
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: glibc
+
+// No allocator and hooks.
+// XFAIL: ubsan
+
+// FIXME: Crashes on CHECK.
+// XFAIL: asan && !i386-linux
+// XFAIL: msan && !i386-linux
+
+#ifndef BUILD_SO
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+
+typedef long *(*get_t)();
+get_t GetTls;
+void *Thread(void *unused) { return GetTls(); }
+
+__thread long recursive_hook;
+
+// CHECK: __sanitizer_malloc_hook:
+void __sanitizer_malloc_hook(const volatile void *ptr, size_t sz)
+__attribute__((disable_sanitizer_instrumentation)) {
+  ++recursive_hook;
+  if (recursive_hook == 1 && GetTls)
+fprintf(stderr, "__sanitizer_malloc_hook: %p\n", GetTls());
+  --recursive_hook;
+}
+
+int main(int argc, char *argv[]) {
+  char path[4096];
+  snprintf(path, sizeof(path), "%s-so.so", argv[0]);
+  int i;
+
+  void *handle = dlopen(path, RTLD_LAZY);
+  if (!handle)
+fprintf(stderr, "%s\n", dlerror());
+  assert(handle != 0);
+  GetTls = (get_t)dlsym(handle, "GetTls");
+  assert(dlerror() == 0);
+
+  pthread_t t;
+  pthread_create(&t, 0, Thread, 0);
+  pthread_join(t, 0);
+  pthread_create(&t, 0, Thread, 0);
+  pthread_join(t, 0);
+  return 0;
+}
+#else // BUILD_SO
+__thread long huge_thread_local_array[1 << 17];
+long *GetTls() { return &huge_thread_local_array[0]; }
+#endif

``




https://github.com/llvm/llvm-project/pull/108684
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Add CHECK that static TLS info is ready (PR #108684)

2024-09-13 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/108684
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Fix partially initialized static TLS range (PR #108685)

2024-09-13 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka created 
https://github.com/llvm/llvm-project/pull/108685

Fixes asan,msan crash on check added in #108684.
The #108684 includes reproducer of the issue.

Change interface of `GetThreadStackAndTls` to
set `tls_begin` and `tls_end` at the same time.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Fix partially initialized static TLS range (PR #108685)

2024-09-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-pgo

Author: Vitaly Buka (vitalybuka)


Changes

Fixes asan,msan crash on check added in #108684.
The #108684 includes reproducer of the issue.

Change interface of `GetThreadStackAndTls` to
set `tls_begin` and `tls_end` at the same time.


---
Full diff: https://github.com/llvm/llvm-project/pull/108685.diff


16 Files Affected:

- (modified) compiler-rt/lib/asan/asan_posix.cpp (+4-4) 
- (modified) compiler-rt/lib/asan/asan_rtl.cpp (+2-4) 
- (modified) compiler-rt/lib/asan/asan_thread.cpp (+3-6) 
- (modified) compiler-rt/lib/dfsan/dfsan_thread.cpp (+2-7) 
- (modified) compiler-rt/lib/hwasan/hwasan_linux.cpp (+2-6) 
- (modified) compiler-rt/lib/lsan/lsan_posix.cpp (+2-6) 
- (modified) compiler-rt/lib/memprof/memprof_thread.cpp (+2-6) 
- (modified) compiler-rt/lib/msan/msan_thread.cpp (+2-7) 
- (modified) compiler-rt/lib/nsan/nsan_thread.cpp (+2-7) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common.h (+2-2) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp 
(+18-10) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp (+12-15) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_win.cpp (+12-15) 
- (modified) compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp 
(+16-17) 
- (modified) compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp (+6-4) 
- (modified) 
compiler-rt/test/sanitizer_common/TestCases/Linux/tls_malloc_hook.c (-4) 


``diff
diff --git a/compiler-rt/lib/asan/asan_posix.cpp 
b/compiler-rt/lib/asan/asan_posix.cpp
index 76564538bd5d77..cd57f750d897cc 100644
--- a/compiler-rt/lib/asan/asan_posix.cpp
+++ b/compiler-rt/lib/asan/asan_posix.cpp
@@ -59,10 +59,10 @@ bool PlatformUnpoisonStacks() {
 
   // Since we're on the signal alternate stack, we cannot find the DEFAULT
   // stack bottom using a local variable.
-  uptr default_bottom, tls_addr, tls_size, stack_size;
-  GetThreadStackAndTls(/*main=*/false, &default_bottom, &stack_size, &tls_addr,
-   &tls_size);
-  UnpoisonStack(default_bottom, default_bottom + stack_size, "default");
+  uptr stack_begin, stack_end, tls_begin, tls_end;
+  GetThreadStackAndTls(/*main=*/false, &stack_begin, &stack_end, &tls_begin,
+   &tls_end);
+  UnpoisonStack(stack_begin, stack_end, "default");
   return true;
 }
 
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp 
b/compiler-rt/lib/asan/asan_rtl.cpp
index d42a75e9e5211a..a390802af28d09 100644
--- a/compiler-rt/lib/asan/asan_rtl.cpp
+++ b/compiler-rt/lib/asan/asan_rtl.cpp
@@ -580,10 +580,8 @@ static void UnpoisonDefaultStack() {
   } else {
 CHECK(!SANITIZER_FUCHSIA);
 // If we haven't seen this thread, try asking the OS for stack bounds.
-uptr tls_addr, tls_size, stack_size;
-GetThreadStackAndTls(/*main=*/false, &bottom, &stack_size, &tls_addr,
- &tls_size);
-top = bottom + stack_size;
+uptr tls_begin, tls_end;
+GetThreadStackAndTls(/*main=*/false, &bottom, &top, &tls_begin, &tls_end);
   }
 
   UnpoisonStack(bottom, top, "default");
diff --git a/compiler-rt/lib/asan/asan_thread.cpp 
b/compiler-rt/lib/asan/asan_thread.cpp
index c79c33ab01342f..c1a804b9fcccd3 100644
--- a/compiler-rt/lib/asan/asan_thread.cpp
+++ b/compiler-rt/lib/asan/asan_thread.cpp
@@ -306,13 +306,10 @@ AsanThread *CreateMainThread() {
 // OS-specific implementations that need more information passed through.
 void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
   DCHECK_EQ(options, nullptr);
-  uptr tls_size = 0;
-  uptr stack_size = 0;
-  GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_size,
-   &tls_begin_, &tls_size);
-  stack_top_ = RoundDownTo(stack_bottom_ + stack_size, 
ASAN_SHADOW_GRANULARITY);
+  GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_top_,
+   &tls_begin_, &tls_end_);
+  stack_top_ = RoundDownTo(stack_top_, ASAN_SHADOW_GRANULARITY);
   stack_bottom_ = RoundDownTo(stack_bottom_, ASAN_SHADOW_GRANULARITY);
-  tls_end_ = tls_begin_ + tls_size;
   dtls_ = DTLS_Get();
 
   if (stack_top_ != stack_bottom_) {
diff --git a/compiler-rt/lib/dfsan/dfsan_thread.cpp 
b/compiler-rt/lib/dfsan/dfsan_thread.cpp
index c1d47514f4bd99..55d38916ead9e0 100644
--- a/compiler-rt/lib/dfsan/dfsan_thread.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_thread.cpp
@@ -21,13 +21,8 @@ DFsanThread *DFsanThread::Create(thread_callback_t 
start_routine, void *arg,
 }
 
 void DFsanThread::SetThreadStackAndTls() {
-  uptr tls_size = 0;
-  uptr stack_size = 0;
-  GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_size, 
&tls_begin_,
-   &tls_size);
-  stack_.top = stack_.bottom + stack_size;
-  tls_end_ = tls_begin_ + tls_size;
-
+  GetThreadStackAndTls(IsMainThread(), &stack_.bottom, &stack_.top, 
&tls_begin_,
+   &tls_end_);
   int local;
   CHECK(AddrIsInStack((uptr)&local));
 }
diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp 
b/compiler-rt/