[clang] b10a341 - [Pipelines] Introduce DAE after ArgumentPromotion

2022-08-28 Thread Pavel Samolysov via cfe-commits

Author: Pavel Samolysov
Date: 2022-08-28T10:47:03+03:00
New Revision: b10a341aa5b0b93b9175a8f11efc9a0955ab361e

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

LOG: [Pipelines] Introduce DAE after ArgumentPromotion

The ArgumentPromotion pass uses Mem2Reg promotion at the end to cutting
down generated `alloca` instructions as well as meaningless `store`s and
this behavior can leave unused (dead) arguments. To eliminate the dead
arguments and therefore let the DeadCodeElimination remove becoming dead
inserted `GEP`s as well as `load`s and `cast`s in the callers, the
DeadArgumentElimination pass should be run after the ArgumentPromotion
one.

Differential Revision: https://reviews.llvm.org/D128830

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Transforms/InstCombine/unused-nonnull.ll
llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 463fc522c6a28..64ac49420cbdc 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -34,7 +34,6 @@
 ; CHECK-O: Running pass: CalledValuePropagationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: PromotePass
-; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: InstCombinePass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InlinerPass on (main)
@@ -74,6 +73,7 @@
 ; CHECK-O: Running pass: LCSSAPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InstCombinePass on main
+; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: EliminateAvailableExternallyPass

diff  --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index bd07638b37617..2587c8ce900b9 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -639,7 +639,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
 
 FunctionPassManager FPM;
 FPM.addPass(SROAPass());
-FPM.addPass(EarlyCSEPass());// Catch trivial redundancies.
+FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
 FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
 true)));// Merge & remove basic blocks.
 FPM.addPass(InstCombinePass()); // Combine silly sequences.
@@ -734,10 +734,9 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   if (PGOOpt)
 IP.EnableDeferral = EnablePGOInlineDeferral;
 
-  ModuleInlinerWrapperPass MIWP(
-  IP, PerformMandatoryInliningsFirst,
-  InlineContext{Phase, InlinePass::CGSCCInliner},
-  UseInlineAdvisor, MaxDevirtIterations);
+  ModuleInlinerWrapperPass MIWP(IP, PerformMandatoryInliningsFirst,
+InlineContext{Phase, InlinePass::CGSCCInliner},
+UseInlineAdvisor, MaxDevirtIterations);
 
   // Require the GlobalsAA analysis for the module so we can query it within
   // the CGSCC pipeline.
@@ -961,10 +960,6 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // constants.
   MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
 
-  // Remove any dead arguments exposed by cleanups and constant folding
-  // globals.
-  MPM.addPass(DeadArgumentEliminationPass());
-
   // Create a small function pass pipeline to cleanup after all the global
   // optimizations.
   FunctionPassManager GlobalCleanupPM;
@@ -999,6 +994,10 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   else
 MPM.addPass(buildInlinerPipeline(Level, Phase));
 
+  // Remove any dead arguments exposed by cleanups, constant folding globals,
+  // and argument promotion.
+  MPM.addPass(DeadArgumentEliminationPass());
+
   MPM.addPass(CoroCleanupPass());
 
   if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
@@ -1596,9 +1595,6 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
   // keep one copy of each constant.
   MPM.addPass(ConstantMergePass());
 
-  // Remove unused arguments fro

[clang] 3f20dcb - [Pipelines] Introduce DAE after ArgumentPromotion

2022-08-24 Thread Pavel Samolysov via cfe-commits

Author: Pavel Samolysov
Date: 2022-08-24T10:36:12+03:00
New Revision: 3f20dcbf708cb23f79c4866d8285a8ae7bd885de

URL: 
https://github.com/llvm/llvm-project/commit/3f20dcbf708cb23f79c4866d8285a8ae7bd885de
DIFF: 
https://github.com/llvm/llvm-project/commit/3f20dcbf708cb23f79c4866d8285a8ae7bd885de.diff

LOG: [Pipelines] Introduce DAE after ArgumentPromotion

The ArgumentPromotion pass uses Mem2Reg promotion at the end to cutting
down generated `alloca` instructions as well as meaningless `store`s and
this behavior can leave unused (dead) arguments. To eliminate the dead
arguments and therefore let the DeadCodeElimination remove becoming dead
inserted `GEP`s as well as `load`s and `cast`s in the callers, the
DeadArgumentElimination pass should be run after the ArgumentPromotion
one.

Differential Revision: https://reviews.llvm.org/D128830

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Transforms/InstCombine/unused-nonnull.ll
llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 463fc522c6a28..64ac49420cbdc 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -34,7 +34,6 @@
 ; CHECK-O: Running pass: CalledValuePropagationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: PromotePass
-; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: InstCombinePass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InlinerPass on (main)
@@ -74,6 +73,7 @@
 ; CHECK-O: Running pass: LCSSAPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InstCombinePass on main
+; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: EliminateAvailableExternallyPass

diff  --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index bd07638b37617..2587c8ce900b9 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -639,7 +639,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
 
 FunctionPassManager FPM;
 FPM.addPass(SROAPass());
-FPM.addPass(EarlyCSEPass());// Catch trivial redundancies.
+FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
 FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
 true)));// Merge & remove basic blocks.
 FPM.addPass(InstCombinePass()); // Combine silly sequences.
@@ -734,10 +734,9 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   if (PGOOpt)
 IP.EnableDeferral = EnablePGOInlineDeferral;
 
-  ModuleInlinerWrapperPass MIWP(
-  IP, PerformMandatoryInliningsFirst,
-  InlineContext{Phase, InlinePass::CGSCCInliner},
-  UseInlineAdvisor, MaxDevirtIterations);
+  ModuleInlinerWrapperPass MIWP(IP, PerformMandatoryInliningsFirst,
+InlineContext{Phase, InlinePass::CGSCCInliner},
+UseInlineAdvisor, MaxDevirtIterations);
 
   // Require the GlobalsAA analysis for the module so we can query it within
   // the CGSCC pipeline.
@@ -961,10 +960,6 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // constants.
   MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
 
-  // Remove any dead arguments exposed by cleanups and constant folding
-  // globals.
-  MPM.addPass(DeadArgumentEliminationPass());
-
   // Create a small function pass pipeline to cleanup after all the global
   // optimizations.
   FunctionPassManager GlobalCleanupPM;
@@ -999,6 +994,10 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   else
 MPM.addPass(buildInlinerPipeline(Level, Phase));
 
+  // Remove any dead arguments exposed by cleanups, constant folding globals,
+  // and argument promotion.
+  MPM.addPass(DeadArgumentEliminationPass());
+
   MPM.addPass(CoroCleanupPass());
 
   if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
@@ -1596,9 +1595,6 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
   // keep one copy of each constant.
   MPM.addPass(ConstantMergePass());
 
-  // Remove unused arguments fro

[clang] 6703ad1 - Revert "[Pipelines] Introduce DAE after ArgumentPromotion"

2022-08-24 Thread Pavel Samolysov via cfe-commits

Author: Pavel Samolysov
Date: 2022-08-24T12:44:13+03:00
New Revision: 6703ad1e0c2a30153c75139764672d2ad16069c8

URL: 
https://github.com/llvm/llvm-project/commit/6703ad1e0c2a30153c75139764672d2ad16069c8
DIFF: 
https://github.com/llvm/llvm-project/commit/6703ad1e0c2a30153c75139764672d2ad16069c8.diff

LOG: Revert "[Pipelines] Introduce DAE after ArgumentPromotion"

This reverts commit 3f20dcbf708cb23f79c4866d8285a8ae7bd885de.

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Transforms/InstCombine/unused-nonnull.ll
llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 64ac49420cbdc..463fc522c6a28 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -34,6 +34,7 @@
 ; CHECK-O: Running pass: CalledValuePropagationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: PromotePass
+; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: InstCombinePass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InlinerPass on (main)
@@ -73,7 +74,6 @@
 ; CHECK-O: Running pass: LCSSAPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InstCombinePass on main
-; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: EliminateAvailableExternallyPass

diff  --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 2587c8ce900b9..bd07638b37617 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -639,7 +639,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
 
 FunctionPassManager FPM;
 FPM.addPass(SROAPass());
-FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
+FPM.addPass(EarlyCSEPass());// Catch trivial redundancies.
 FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
 true)));// Merge & remove basic blocks.
 FPM.addPass(InstCombinePass()); // Combine silly sequences.
@@ -734,9 +734,10 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   if (PGOOpt)
 IP.EnableDeferral = EnablePGOInlineDeferral;
 
-  ModuleInlinerWrapperPass MIWP(IP, PerformMandatoryInliningsFirst,
-InlineContext{Phase, InlinePass::CGSCCInliner},
-UseInlineAdvisor, MaxDevirtIterations);
+  ModuleInlinerWrapperPass MIWP(
+  IP, PerformMandatoryInliningsFirst,
+  InlineContext{Phase, InlinePass::CGSCCInliner},
+  UseInlineAdvisor, MaxDevirtIterations);
 
   // Require the GlobalsAA analysis for the module so we can query it within
   // the CGSCC pipeline.
@@ -960,6 +961,10 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // constants.
   MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
 
+  // Remove any dead arguments exposed by cleanups and constant folding
+  // globals.
+  MPM.addPass(DeadArgumentEliminationPass());
+
   // Create a small function pass pipeline to cleanup after all the global
   // optimizations.
   FunctionPassManager GlobalCleanupPM;
@@ -994,10 +999,6 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   else
 MPM.addPass(buildInlinerPipeline(Level, Phase));
 
-  // Remove any dead arguments exposed by cleanups, constant folding globals,
-  // and argument promotion.
-  MPM.addPass(DeadArgumentEliminationPass());
-
   MPM.addPass(CoroCleanupPass());
 
   if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
@@ -1595,6 +1596,9 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
   // keep one copy of each constant.
   MPM.addPass(ConstantMergePass());
 
+  // Remove unused arguments from functions.
+  MPM.addPass(DeadArgumentEliminationPass());
+
   // Reduce the code after globalopt and ipsccp.  Both can open up significant
   // simplification opportunities, and both can propagate functions through
   // function pointers.  When this happens, we often have to resolve varargs
@@ -1617,7 +1621,7 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
   getInlineParamsFromOptLevel(L

[clang] 879f511 - [Pipelines] Introduce DAE after ArgumentPromotion

2022-08-25 Thread Pavel Samolysov via cfe-commits

Author: Pavel Samolysov
Date: 2022-08-25T10:55:47+03:00
New Revision: 879f5118fc74657e4a5c4eff6810098e1eed75ac

URL: 
https://github.com/llvm/llvm-project/commit/879f5118fc74657e4a5c4eff6810098e1eed75ac
DIFF: 
https://github.com/llvm/llvm-project/commit/879f5118fc74657e4a5c4eff6810098e1eed75ac.diff

LOG: [Pipelines] Introduce DAE after ArgumentPromotion

The ArgumentPromotion pass uses Mem2Reg promotion at the end to cutting
down generated `alloca` instructions as well as meaningless `store`s and
this behavior can leave unused (dead) arguments. To eliminate the dead
arguments and therefore let the DeadCodeElimination remove becoming dead
inserted `GEP`s as well as `load`s and `cast`s in the callers, the
DeadArgumentElimination pass should be run after the ArgumentPromotion
one.

Differential Revision: https://reviews.llvm.org/D128830

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Transforms/InstCombine/unused-nonnull.ll
llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 463fc522c6a28..64ac49420cbdc 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -34,7 +34,6 @@
 ; CHECK-O: Running pass: CalledValuePropagationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: PromotePass
-; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: InstCombinePass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InlinerPass on (main)
@@ -74,6 +73,7 @@
 ; CHECK-O: Running pass: LCSSAPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InstCombinePass on main
+; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: EliminateAvailableExternallyPass

diff  --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index bd07638b37617..2587c8ce900b9 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -639,7 +639,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
 
 FunctionPassManager FPM;
 FPM.addPass(SROAPass());
-FPM.addPass(EarlyCSEPass());// Catch trivial redundancies.
+FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
 FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
 true)));// Merge & remove basic blocks.
 FPM.addPass(InstCombinePass()); // Combine silly sequences.
@@ -734,10 +734,9 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   if (PGOOpt)
 IP.EnableDeferral = EnablePGOInlineDeferral;
 
-  ModuleInlinerWrapperPass MIWP(
-  IP, PerformMandatoryInliningsFirst,
-  InlineContext{Phase, InlinePass::CGSCCInliner},
-  UseInlineAdvisor, MaxDevirtIterations);
+  ModuleInlinerWrapperPass MIWP(IP, PerformMandatoryInliningsFirst,
+InlineContext{Phase, InlinePass::CGSCCInliner},
+UseInlineAdvisor, MaxDevirtIterations);
 
   // Require the GlobalsAA analysis for the module so we can query it within
   // the CGSCC pipeline.
@@ -961,10 +960,6 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // constants.
   MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
 
-  // Remove any dead arguments exposed by cleanups and constant folding
-  // globals.
-  MPM.addPass(DeadArgumentEliminationPass());
-
   // Create a small function pass pipeline to cleanup after all the global
   // optimizations.
   FunctionPassManager GlobalCleanupPM;
@@ -999,6 +994,10 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   else
 MPM.addPass(buildInlinerPipeline(Level, Phase));
 
+  // Remove any dead arguments exposed by cleanups, constant folding globals,
+  // and argument promotion.
+  MPM.addPass(DeadArgumentEliminationPass());
+
   MPM.addPass(CoroCleanupPass());
 
   if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
@@ -1596,9 +1595,6 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
   // keep one copy of each constant.
   MPM.addPass(ConstantMergePass());
 
-  // Remove unused arguments fro

[clang] f964417 - Revert "[Pipelines] Introduce DAE after ArgumentPromotion"

2022-08-26 Thread Pavel Samolysov via cfe-commits

Author: Pavel Samolysov
Date: 2022-08-26T13:43:09+03:00
New Revision: f964417c32d05a88c80db315e97ada639d97eda1

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

LOG: Revert "[Pipelines] Introduce DAE after ArgumentPromotion"

The commit breaks the compiler when a function is used as a function
parameter (hm... for a function from the standard C library?):

```
static float strtof(char *, char *) {}
void a() { strtof(a, 0); }
```

This reverts commit 879f5118fc74657e4a5c4eff6810098e1eed75ac.

Added: 


Modified: 
clang/test/CodeGen/thinlto-distributed-newpm.ll
llvm/lib/Passes/PassBuilderPipelines.cpp
llvm/test/Other/new-pm-defaults.ll
llvm/test/Other/new-pm-lto-defaults.ll
llvm/test/Other/new-pm-thinlto-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
llvm/test/Transforms/InstCombine/unused-nonnull.ll
llvm/test/Transforms/PhaseOrdering/dce-after-argument-promotion.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-newpm.ll 
b/clang/test/CodeGen/thinlto-distributed-newpm.ll
index 64ac49420cbdc..463fc522c6a28 100644
--- a/clang/test/CodeGen/thinlto-distributed-newpm.ll
+++ b/clang/test/CodeGen/thinlto-distributed-newpm.ll
@@ -34,6 +34,7 @@
 ; CHECK-O: Running pass: CalledValuePropagationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: PromotePass
+; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: InstCombinePass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InlinerPass on (main)
@@ -73,7 +74,6 @@
 ; CHECK-O: Running pass: LCSSAPass on main
 ; CHECK-O: Running pass: SimplifyCFGPass on main
 ; CHECK-O: Running pass: InstCombinePass on main
-; CHECK-O: Running pass: DeadArgumentEliminationPass
 ; CHECK-O: Running pass: GlobalOptPass
 ; CHECK-O: Running pass: GlobalDCEPass
 ; CHECK-O: Running pass: EliminateAvailableExternallyPass

diff  --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 2587c8ce900b9..bd07638b37617 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -639,7 +639,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
 
 FunctionPassManager FPM;
 FPM.addPass(SROAPass());
-FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
+FPM.addPass(EarlyCSEPass());// Catch trivial redundancies.
 FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(
 true)));// Merge & remove basic blocks.
 FPM.addPass(InstCombinePass()); // Combine silly sequences.
@@ -734,9 +734,10 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   if (PGOOpt)
 IP.EnableDeferral = EnablePGOInlineDeferral;
 
-  ModuleInlinerWrapperPass MIWP(IP, PerformMandatoryInliningsFirst,
-InlineContext{Phase, InlinePass::CGSCCInliner},
-UseInlineAdvisor, MaxDevirtIterations);
+  ModuleInlinerWrapperPass MIWP(
+  IP, PerformMandatoryInliningsFirst,
+  InlineContext{Phase, InlinePass::CGSCCInliner},
+  UseInlineAdvisor, MaxDevirtIterations);
 
   // Require the GlobalsAA analysis for the module so we can query it within
   // the CGSCC pipeline.
@@ -960,6 +961,10 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // constants.
   MPM.addPass(createModuleToFunctionPassAdaptor(PromotePass()));
 
+  // Remove any dead arguments exposed by cleanups and constant folding
+  // globals.
+  MPM.addPass(DeadArgumentEliminationPass());
+
   // Create a small function pass pipeline to cleanup after all the global
   // optimizations.
   FunctionPassManager GlobalCleanupPM;
@@ -994,10 +999,6 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   else
 MPM.addPass(buildInlinerPipeline(Level, Phase));
 
-  // Remove any dead arguments exposed by cleanups, constant folding globals,
-  // and argument promotion.
-  MPM.addPass(DeadArgumentEliminationPass());
-
   MPM.addPass(CoroCleanupPass());
 
   if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
@@ -1595,6 +1596,9 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel 
Level,
   // keep one copy of each constant.
   MPM.addPass(ConstantMergePass());
 
+  // Remove unused arguments from functions.
+  MPM.addPass(DeadArgumentEliminationPass());
+
   // Reduce the code after globalopt and ipsccp.  Both can open up significant
   // simplification opportunities, and both can propagate functions

[libunwind] e251fb4 - [libunwind][CMake] Fix name of LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG

2022-05-26 Thread Pavel Samolysov via cfe-commits

Author: Pavel Samolysov
Date: 2022-05-27T09:20:57+03:00
New Revision: e251fb4cdeb723eff5507be1efeb3fc69f7a2ce7

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

LOG: [libunwind][CMake] Fix name of LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG

The CMake variable LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG has been renamed
into C_SUPPORTS_NODEFAULTLIBS_FLAG because the last one is used in the
confix-ix.cmake file while the variable with the original name is not used
at al.

Differential Revision: https://reviews.llvm.org/D126466

Added: 


Modified: 
libunwind/cmake/config-ix.cmake

Removed: 




diff  --git a/libunwind/cmake/config-ix.cmake b/libunwind/cmake/config-ix.cmake
index f716532fdf1b5..c9b65b3cefc08 100644
--- a/libunwind/cmake/config-ix.cmake
+++ b/libunwind/cmake/config-ix.cmake
@@ -35,7 +35,7 @@ llvm_check_compiler_linker_flag(C "-nostdlib++" 
CXX_SUPPORTS_NOSTDLIBXX_FLAG)
 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
-  llvm_check_compiler_linker_flag(C "-nodefaultlibs" 
LIBUNWIND_SUPPORTS_NODEFAULTLIBS_FLAG)
+  llvm_check_compiler_linker_flag(C "-nodefaultlibs" 
C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
   endif()



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


[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-07-01 Thread Pavel Samolysov via cfe-commits


@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s

samolisov wrote:

Unfortunately, I have no idea how to generate tests for clang. This test has 
been manually written.

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


[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-07-07 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov updated 
https://github.com/llvm/llvm-project/pull/97164

>From edf0d10b41099068ef49a2d2fe0ce60356d2f2fd Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Sat, 29 Jun 2024 15:18:11 +0300
Subject: [PATCH 1/2] [Clang][Sema] Add a test for move ctor calling for a base
 class. NFC

When clang compiles the following expression:

```c++
  return A{B{"Move Ctor"}};
```
(where `B` is a base class for `A`), it adds a call to the move
constructor of `B`. When the code is changed to...

```c++
  return A{{"No Move Ctor"}};
```
... a move constructor is invoked neither for `A` nor for `B`.

The lit test demonstrates the difference in the generated AST.

Issue: #92495
---
 .../AST/explicit-base-class-move-cntr.cpp | 43 +++
 1 file changed, 43 insertions(+)
 create mode 100644 clang/test/AST/explicit-base-class-move-cntr.cpp

diff --git a/clang/test/AST/explicit-base-class-move-cntr.cpp 
b/clang/test/AST/explicit-base-class-move-cntr.cpp
new file mode 100644
index 00..b9b591ebc79d7e
--- /dev/null
+++ b/clang/test/AST/explicit-base-class-move-cntr.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s
+
+struct ExplicitBase {
+  explicit ExplicitBase(const char *) { }
+  ExplicitBase(const ExplicitBase &) {}
+  ExplicitBase(ExplicitBase &&) {}
+  ExplicitBase &operator=(const ExplicitBase &) { return *this; }
+  ExplicitBase &operator=(ExplicitBase &&) { return *this; }
+  ~ExplicitBase() { }
+};
+
+struct Derived1 : ExplicitBase {};
+
+Derived1 makeDerived1() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived1 'Derived1 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-DAG:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ExplicitBase' xvalue
+  // CHECK-NEXT: CXXBindTemporaryExpr 0x[[TEMP:[^ ]*]]  'ExplicitBase' (CXXTemporary 0x[[TEMP]])
+  // CHECK-NEXT: CXXTemporaryObjectExpr 0x{{[^ ]*}}  'ExplicitBase' 'void (const char *)' list
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const char *' 

+  // CHECK-NEXT: StringLiteral 0x{{[^ ]*}}  'const char[10]' 
lvalue "Move Ctor"
+  return Derived1{ExplicitBase{"Move Ctor"}};
+}
+
+struct ImplicitBase {
+  ImplicitBase(const char *) { }
+  ImplicitBase(const ImplicitBase &) {}
+  ImplicitBase(ImplicitBase &&) {}
+  ImplicitBase &operator=(const ImplicitBase &) { return *this; }
+  ImplicitBase &operator=(ImplicitBase &&) { return *this; }
+  ~ImplicitBase() { }
+};
+
+struct Derived2 : ImplicitBase {};
+
+Derived2 makeDerived2() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived2 'Derived2 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-NOT:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ImplicitBase' xvalue
+  return Derived2{{"No Ctor"}};
+}

>From a29869ad88f546563404f7f1d60ca9ca2c3a255b Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Sun, 7 Jul 2024 13:29:06 +0300
Subject: [PATCH 2/2] Regenerate the test using the
 llvm-project/clang/test/AST/gen_ast_dump_json_test.py tool

---
 .../AST/explicit-base-class-move-cntr.cpp | 154 --
 1 file changed, 141 insertions(+), 13 deletions(-)

diff --git a/clang/test/AST/explicit-base-class-move-cntr.cpp 
b/clang/test/AST/explicit-base-class-move-cntr.cpp
index b9b591ebc79d7e..808af2fc94336f 100644
--- a/clang/test/AST/explicit-base-class-move-cntr.cpp
+++ b/clang/test/AST/explicit-base-class-move-cntr.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -ast-dump=json %s | FileCheck -strict-whitespace %s
 
 struct ExplicitBase {
   explicit ExplicitBase(const char *) { }
@@ -12,14 +12,85 @@ struct ExplicitBase {
 struct Derived1 : ExplicitBase {};
 
 Derived1 makeDerived1() {
-  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived1 'Derived1 ()'
-  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
-  // CHECK-DAG:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ExplicitBase' xvalue
-  // CHECK-NEXT: CXXBindTemporaryExpr 0x[[TEMP:[^ ]*]]  'ExplicitBase' (CXXTemporary 0x[[TEMP]])
-  // CHECK-NEXT: CXXTemporaryObjectExpr 0x{{[^ ]*}}  'ExplicitBase' 'void (const char *)' list
-  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const char *' 

-  // CHECK-NEXT: StringLiteral 0x{{[^ ]*}}  'const char[10]' 
lvalue "Move Ctor"
+// CHECK:  "kind": "FunctionDecl",
+// CHECK:  "name": "makeDerived1",
+
+// CHECK:"kind": "CompoundStmt",
+
+// CHECK:  "kind": "ReturnStmt",
+// CHECK:"kind": "ExprWithCleanups",
+// CHECK:"type": {
+// CHECK-NEXT: "qualType": "Derived1"
+// CHECK-NEXT:   },
+
+// CHECK:  "kind": "CXXFunctionalCastExpr",
+// CHECK:  "type": {
+// CHECK-NEXT:   "qualType": "Derived1"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "prvalue",
+// CHECK-NEXT: "castKind": "NoOp",
+
+// CHECK:"kind": "CXXBindTemporaryExpr",
+// CHECK:"type": {
+// CHECK-NEXT: "qualType": "Derived1"
+// CH

[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-07-07 Thread Pavel Samolysov via cfe-commits


@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s

samolisov wrote:

@vitalybuka Thank you for the suggestion. I've regenerated the test using the 
tool and cut the dump to make it a bit shorter.

https://github.com/llvm/llvm-project/pull/97164
___
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)

2024-06-10 Thread Pavel Samolysov via cfe-commits


@@ -8777,6 +8777,9 @@ def err_typecheck_incomplete_type_not_modifiable_lvalue : 
Error<
 def err_typecheck_lvalue_casts_not_supported : Error<
   "assignment to cast is illegal, lvalue casts are not supported">;
 
+def note_typecheck_expression_not_modifiable_lvalue : Note<

samolisov wrote:

I believe this is very general naming for the note: 
`note_typecheck_expression_not_modifiable_lvalue`. Actually, we only suggest to 
add a star to dereference some not modifiable lvalue here (`this`, I think). 
What about to rename it to better reflect the suggested change? 
`note_typecheck_add_star_to_not_modifiable_this` or something like this. 
Unfortunately, I'm not familiar well with the widespread naming for notes, and 
am not able to make a good suggestion, sorry.

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] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)

2024-06-10 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov created 
https://github.com/llvm/llvm-project/pull/94987

This addresses a clang-tidy suggestion.

>From 34352ddc7cb351c74ff3758c3990a480adc4c2c2 Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Mon, 10 Jun 2024 17:35:14 +0300
Subject: [PATCH] [clang] Replace X && isa(X) with isa_and_nonnull(X).
 NFC

This addresses a clang-tidy suggestion.
---
 .../include/clang/Analysis/Analyses/ThreadSafetyCommon.h  | 4 ++--
 clang/include/clang/Lex/Preprocessor.h| 2 +-
 clang/include/clang/Sema/SemaObjC.h   | 2 +-
 .../clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h   | 2 +-
 clang/lib/ARCMigrate/TransUnbridgedCasts.cpp  | 2 +-
 clang/lib/AST/ASTImporter.cpp | 2 +-
 clang/lib/AST/DeclBase.cpp| 2 +-
 clang/lib/AST/Expr.cpp| 4 ++--
 clang/lib/AST/ExprConstant.cpp| 2 +-
 clang/lib/AST/Mangle.cpp  | 2 +-
 clang/lib/AST/MicrosoftMangle.cpp | 2 +-
 clang/lib/AST/ParentMap.cpp   | 5 +++--
 clang/lib/AST/StmtPrinter.cpp | 4 ++--
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 2 +-
 clang/lib/CodeGen/CGBlocks.cpp| 2 +-
 clang/lib/CodeGen/CGClass.cpp | 4 ++--
 clang/lib/CodeGen/CGExprConstant.cpp  | 2 +-
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 3 ++-
 clang/lib/CodeGen/CGStmtOpenMP.cpp| 6 +++---
 clang/lib/CodeGen/CodeGenFunction.cpp | 2 +-
 clang/lib/Index/IndexBody.cpp | 2 +-
 clang/lib/Lex/PPMacroExpansion.cpp| 2 +-
 clang/lib/Sema/AnalysisBasedWarnings.cpp  | 8 
 clang/lib/Sema/SemaCXXScopeSpec.cpp   | 2 +-
 clang/lib/Sema/SemaChecking.cpp   | 4 ++--
 clang/lib/Sema/SemaExprCXX.cpp| 8 
 clang/lib/Sema/SemaInit.cpp   | 6 +++---
 clang/lib/Sema/SemaStmt.cpp   | 2 +-
 clang/lib/Sema/SemaTemplate.cpp   | 2 +-
 29 files changed, 47 insertions(+), 45 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 7bdb9052e57e7..e99c5b2466334 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -330,9 +330,9 @@ class CapabilityExpr {
 
   bool shouldIgnore() const { return sexpr() == nullptr; }
 
-  bool isInvalid() const { return sexpr() && isa(sexpr()); }
+  bool isInvalid() const { return isa_and_nonnull(sexpr()); }
 
-  bool isUniversal() const { return sexpr() && isa(sexpr()); }
+  bool isUniversal() const { return isa_and_nonnull(sexpr()); }
 };
 
 // Translate clang::Expr to til::SExpr.
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index c0850a8fa9f7f..9b1628d2d86f9 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1360,7 +1360,7 @@ class Preprocessor {
 
 MacroState &S = CurSubmoduleState->Macros[II];
 auto *MD = S.getLatest();
-while (MD && isa(MD))
+while (isa_and_nonnull(MD))
   MD = MD->getPrevious();
 return MacroDefinition(dyn_cast_or_null(MD),
S.getActiveModuleMacros(*this, II),
diff --git a/clang/include/clang/Sema/SemaObjC.h 
b/clang/include/clang/Sema/SemaObjC.h
index 91430797e5ed8..bb8887691ce5d 100644
--- a/clang/include/clang/Sema/SemaObjC.h
+++ b/clang/include/clang/Sema/SemaObjC.h
@@ -383,7 +383,7 @@ class SemaObjC : public SemaBase {
   void AddAnyMethodToGlobalPool(Decl *D);
 
   void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
-  bool isObjCMethodDecl(Decl *D) { return D && isa(D); }
+  bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull(D); }
 
   /// CheckImplementationIvars - This routine checks if the instance variables
   /// listed in the implelementation match those listed in the interface.
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
index 151d3e57c1cb8..59805d01be5db 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion {
   : SubRegion(sreg, SymbolicRegionKind), sym(s) {
 // Because pointer arithmetic is represented by ElementRegion layers,
 // the base symbol here should not contain any arithmetic.
-assert(s && isa(s));
+assert(isa_and_nonnull(s));
 assert(s->getType()->isAnyPointerType(

[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)

2024-06-10 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov updated 
https://github.com/llvm/llvm-project/pull/94987

>From 691223b4e873257a74b295bfb77839406adc742a Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Mon, 10 Jun 2024 17:35:14 +0300
Subject: [PATCH] [clang] Replace X && isa(X) with isa_and_nonnull(X).
 NFC

This addresses a clang-tidy suggestion.
---
 .../clang/Analysis/Analyses/ThreadSafetyCommon.h   |  4 ++--
 clang/include/clang/Lex/Preprocessor.h |  2 +-
 clang/include/clang/Sema/SemaObjC.h|  2 +-
 .../StaticAnalyzer/Core/PathSensitive/MemRegion.h  |  2 +-
 clang/lib/ARCMigrate/TransUnbridgedCasts.cpp   |  2 +-
 clang/lib/AST/ASTImporter.cpp  |  2 +-
 clang/lib/AST/DeclBase.cpp |  2 +-
 clang/lib/AST/Expr.cpp |  4 ++--
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/lib/AST/Mangle.cpp   |  2 +-
 clang/lib/AST/MicrosoftMangle.cpp  |  2 +-
 clang/lib/AST/ParentMap.cpp|  7 +--
 clang/lib/AST/StmtPrinter.cpp  |  4 ++--
 clang/lib/Analysis/UnsafeBufferUsage.cpp   |  2 +-
 clang/lib/CodeGen/CGBlocks.cpp |  2 +-
 clang/lib/CodeGen/CGClass.cpp  |  4 ++--
 clang/lib/CodeGen/CGExprConstant.cpp   |  2 +-
 clang/lib/CodeGen/CGOpenMPRuntime.cpp  |  3 ++-
 clang/lib/CodeGen/CGStmtOpenMP.cpp |  6 +++---
 clang/lib/CodeGen/CodeGenFunction.cpp  |  2 +-
 clang/lib/Index/IndexBody.cpp  |  2 +-
 clang/lib/Lex/PPMacroExpansion.cpp |  2 +-
 clang/lib/Sema/AnalysisBasedWarnings.cpp   |  8 
 clang/lib/Sema/SemaCXXScopeSpec.cpp|  2 +-
 clang/lib/Sema/SemaChecking.cpp| 10 +-
 clang/lib/Sema/SemaExprCXX.cpp |  8 
 clang/lib/Sema/SemaInit.cpp|  6 +++---
 clang/lib/Sema/SemaStmt.cpp|  2 +-
 clang/lib/Sema/SemaTemplate.cpp|  2 +-
 29 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 7bdb9052e57e7..e99c5b2466334 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -330,9 +330,9 @@ class CapabilityExpr {
 
   bool shouldIgnore() const { return sexpr() == nullptr; }
 
-  bool isInvalid() const { return sexpr() && isa(sexpr()); }
+  bool isInvalid() const { return isa_and_nonnull(sexpr()); }
 
-  bool isUniversal() const { return sexpr() && isa(sexpr()); }
+  bool isUniversal() const { return isa_and_nonnull(sexpr()); }
 };
 
 // Translate clang::Expr to til::SExpr.
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index c0850a8fa9f7f..9b1628d2d86f9 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1360,7 +1360,7 @@ class Preprocessor {
 
 MacroState &S = CurSubmoduleState->Macros[II];
 auto *MD = S.getLatest();
-while (MD && isa(MD))
+while (isa_and_nonnull(MD))
   MD = MD->getPrevious();
 return MacroDefinition(dyn_cast_or_null(MD),
S.getActiveModuleMacros(*this, II),
diff --git a/clang/include/clang/Sema/SemaObjC.h 
b/clang/include/clang/Sema/SemaObjC.h
index 91430797e5ed8..bb8887691ce5d 100644
--- a/clang/include/clang/Sema/SemaObjC.h
+++ b/clang/include/clang/Sema/SemaObjC.h
@@ -383,7 +383,7 @@ class SemaObjC : public SemaBase {
   void AddAnyMethodToGlobalPool(Decl *D);
 
   void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
-  bool isObjCMethodDecl(Decl *D) { return D && isa(D); }
+  bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull(D); }
 
   /// CheckImplementationIvars - This routine checks if the instance variables
   /// listed in the implelementation match those listed in the interface.
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
index 151d3e57c1cb8..59805d01be5db 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion {
   : SubRegion(sreg, SymbolicRegionKind), sym(s) {
 // Because pointer arithmetic is represented by ElementRegion layers,
 // the base symbol here should not contain any arithmetic.
-assert(s && isa(s));
+assert(isa_and_nonnull(s));
 assert(s->getType()->isAnyPointerType() ||
s->getType()->isReferenceType() ||
s->getType()->isBlockPointe

[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)

2024-06-10 Thread Pavel Samolysov via cfe-commits


@@ -302,7 +302,7 @@ void MangleContext::mangleBlock(const DeclContext *DC, 
const BlockDecl *BD,
 assert((isa(DC) || isa(DC)) &&
"expected a NamedDecl or BlockDecl");
 if (isa(DC))
-  for (; DC && isa(DC); DC = DC->getParent())
+  for (; isa_and_nonnull(DC); DC = DC->getParent())
 (void) getBlockId(cast(DC), true);

samolisov wrote:

@NagyDonat thank you for the suggestion. I can remove the check after merging 
this PR as a separate change.

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


[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)

2024-06-10 Thread Pavel Samolysov via cfe-commits


@@ -2772,7 +2772,7 @@ fixVariable(const VarDecl *VD, FixitStrategy::Kind K,
 // also covers call-operator of lamdas
 isa(FD) ||
 // skip when the function body is a try-block
-(FD->hasBody() && isa(FD->getBody())) ||
+isa_and_nonnull(FD->getBody()) ||

samolisov wrote:

I believe this is just my bad, I undistinguished `->hasBody()` and 
`->getBody()`. I'll fix it, thank you.

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


[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)

2024-06-10 Thread Pavel Samolysov via cfe-commits


@@ -8510,7 +8510,8 @@ class MappableExprsHandler {
 assert(VDecl == VD && "We got information for the wrong 
declaration??");
 assert(!Components.empty() &&
"Not expecting declaration with no component lists.");
-if (VD && E && VD->getType()->isAnyPointerType() && 
isa(E))
+if (VD && VD->getType()->isAnyPointerType() &&
+isa_and_nonnull(E))
   HasMapBasePtr = true;
 if (VD && E && VD->getType()->isAnyPointerType() &&
 (isa(E) || isa(E)))

samolisov wrote:

I agree and will return this change back to preserve the consistence.

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


[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)

2024-06-10 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov updated 
https://github.com/llvm/llvm-project/pull/94987

>From 691223b4e873257a74b295bfb77839406adc742a Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Mon, 10 Jun 2024 17:35:14 +0300
Subject: [PATCH 1/2] [clang] Replace X && isa(X) with
 isa_and_nonnull(X). NFC

This addresses a clang-tidy suggestion.
---
 .../clang/Analysis/Analyses/ThreadSafetyCommon.h   |  4 ++--
 clang/include/clang/Lex/Preprocessor.h |  2 +-
 clang/include/clang/Sema/SemaObjC.h|  2 +-
 .../StaticAnalyzer/Core/PathSensitive/MemRegion.h  |  2 +-
 clang/lib/ARCMigrate/TransUnbridgedCasts.cpp   |  2 +-
 clang/lib/AST/ASTImporter.cpp  |  2 +-
 clang/lib/AST/DeclBase.cpp |  2 +-
 clang/lib/AST/Expr.cpp |  4 ++--
 clang/lib/AST/ExprConstant.cpp |  2 +-
 clang/lib/AST/Mangle.cpp   |  2 +-
 clang/lib/AST/MicrosoftMangle.cpp  |  2 +-
 clang/lib/AST/ParentMap.cpp|  7 +--
 clang/lib/AST/StmtPrinter.cpp  |  4 ++--
 clang/lib/Analysis/UnsafeBufferUsage.cpp   |  2 +-
 clang/lib/CodeGen/CGBlocks.cpp |  2 +-
 clang/lib/CodeGen/CGClass.cpp  |  4 ++--
 clang/lib/CodeGen/CGExprConstant.cpp   |  2 +-
 clang/lib/CodeGen/CGOpenMPRuntime.cpp  |  3 ++-
 clang/lib/CodeGen/CGStmtOpenMP.cpp |  6 +++---
 clang/lib/CodeGen/CodeGenFunction.cpp  |  2 +-
 clang/lib/Index/IndexBody.cpp  |  2 +-
 clang/lib/Lex/PPMacroExpansion.cpp |  2 +-
 clang/lib/Sema/AnalysisBasedWarnings.cpp   |  8 
 clang/lib/Sema/SemaCXXScopeSpec.cpp|  2 +-
 clang/lib/Sema/SemaChecking.cpp| 10 +-
 clang/lib/Sema/SemaExprCXX.cpp |  8 
 clang/lib/Sema/SemaInit.cpp|  6 +++---
 clang/lib/Sema/SemaStmt.cpp|  2 +-
 clang/lib/Sema/SemaTemplate.cpp|  2 +-
 29 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 7bdb9052e57e7..e99c5b2466334 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -330,9 +330,9 @@ class CapabilityExpr {
 
   bool shouldIgnore() const { return sexpr() == nullptr; }
 
-  bool isInvalid() const { return sexpr() && isa(sexpr()); }
+  bool isInvalid() const { return isa_and_nonnull(sexpr()); }
 
-  bool isUniversal() const { return sexpr() && isa(sexpr()); }
+  bool isUniversal() const { return isa_and_nonnull(sexpr()); }
 };
 
 // Translate clang::Expr to til::SExpr.
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index c0850a8fa9f7f..9b1628d2d86f9 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1360,7 +1360,7 @@ class Preprocessor {
 
 MacroState &S = CurSubmoduleState->Macros[II];
 auto *MD = S.getLatest();
-while (MD && isa(MD))
+while (isa_and_nonnull(MD))
   MD = MD->getPrevious();
 return MacroDefinition(dyn_cast_or_null(MD),
S.getActiveModuleMacros(*this, II),
diff --git a/clang/include/clang/Sema/SemaObjC.h 
b/clang/include/clang/Sema/SemaObjC.h
index 91430797e5ed8..bb8887691ce5d 100644
--- a/clang/include/clang/Sema/SemaObjC.h
+++ b/clang/include/clang/Sema/SemaObjC.h
@@ -383,7 +383,7 @@ class SemaObjC : public SemaBase {
   void AddAnyMethodToGlobalPool(Decl *D);
 
   void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
-  bool isObjCMethodDecl(Decl *D) { return D && isa(D); }
+  bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull(D); }
 
   /// CheckImplementationIvars - This routine checks if the instance variables
   /// listed in the implelementation match those listed in the interface.
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
index 151d3e57c1cb8..59805d01be5db 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion {
   : SubRegion(sreg, SymbolicRegionKind), sym(s) {
 // Because pointer arithmetic is represented by ElementRegion layers,
 // the base symbol here should not contain any arithmetic.
-assert(s && isa(s));
+assert(isa_and_nonnull(s));
 assert(s->getType()->isAnyPointerType() ||
s->getType()->isReferenceType() ||
s->getType()->isBlockPo

[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)

2024-06-10 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov closed 
https://github.com/llvm/llvm-project/pull/94987
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Remove a redundant check in Mangle. NFC (PR #95071)

2024-06-10 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov created 
https://github.com/llvm/llvm-project/pull/95071

This addresses a review comment for PR #94987 Because that PR is a big 
automatic change, this change was moved in a separate one.

>From c0e810f0a8d17ce222ad0775874539e09a90eb33 Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Mon, 10 Jun 2024 20:29:16 +0300
Subject: [PATCH] [clang] Remove a redundant check in Mangle. NFC

This addresses a review comment for PR #94987 Because that PR is a big
automatic change, this change was moved in a separate one.
---
 clang/lib/AST/Mangle.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index 4af4d7c00c5cb..4fbf0e3b42dbc 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -301,9 +301,8 @@ void MangleContext::mangleBlock(const DeclContext *DC, 
const BlockDecl *BD,
   } else {
 assert((isa(DC) || isa(DC)) &&
"expected a NamedDecl or BlockDecl");
-if (isa(DC))
-  for (; isa_and_nonnull(DC); DC = DC->getParent())
-(void) getBlockId(cast(DC), true);
+for (; isa_and_nonnull(DC); DC = DC->getParent())
+  (void)getBlockId(cast(DC), true);
 assert((isa(DC) || isa(DC)) &&
"expected a TranslationUnitDecl or a NamedDecl");
 if (const auto *CD = dyn_cast(DC))

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


[clang] [clang] Remove a redundant check in Mangle. NFC (PR #95071)

2024-06-11 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov closed 
https://github.com/llvm/llvm-project/pull/95071
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix a typo: ExplicitObje[C]tArgument. NFC (PR #94094)

2024-05-31 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov created 
https://github.com/llvm/llvm-project/pull/94094

None

>From 3ad23f75eff822360f349f5101d832fb769fe11d Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Sat, 1 Jun 2024 07:56:23 +0300
Subject: [PATCH] [clang] Fix a typo: ExplicitObje[C]tArgument. NFC

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 440b8bc60eaab..8ec49fcf553d0 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4501,7 +4501,7 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
 
   // Deduce an argument of type ParamType from an expression with index ArgIdx.
   auto DeduceCallArgument = [&](QualType ParamType, unsigned ArgIdx,
-bool ExplicitObjetArgument) {
+bool ExplicitObjectArgument) {
 // C++ [demp.deduct.call]p1: (DR1391)
 //   Template argument deduction is done by comparing each function 
template
 //   parameter that contains template-parameters that participate in
@@ -4509,7 +4509,7 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
 if (!hasDeducibleTemplateParameters(*this, FunctionTemplate, ParamType))
   return TemplateDeductionResult::Success;
 
-if (ExplicitObjetArgument) {
+if (ExplicitObjectArgument) {
   //   ... with the type of the corresponding argument
   return DeduceTemplateArgumentsFromCallArgument(
   *this, TemplateParams, FirstInnerIndex, ParamType, ObjectType,
@@ -4544,14 +4544,14 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
 
   if (ParamIdx == 0 && HasExplicitObject) {
 if (auto Result = DeduceCallArgument(ParamType, 0,
- /*ExplicitObjetArgument=*/true);
+ /*ExplicitObjectArgument=*/true);
 Result != TemplateDeductionResult::Success)
   return Result;
 continue;
   }
 
   if (auto Result = DeduceCallArgument(ParamType, ArgIdx++,
-   /*ExplicitObjetArgument=*/false);
+   /*ExplicitObjectArgument=*/false);
   Result != TemplateDeductionResult::Success)
 return Result;
 
@@ -4586,7 +4586,7 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
PackScope.nextPackElement(), ++ArgIdx) {
 ParamTypesForArgChecking.push_back(ParamPattern);
 if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
- /*ExplicitObjetArgument=*/false);
+ /*ExplicitObjectArgument=*/false);
 Result != TemplateDeductionResult::Success)
   return Result;
   }
@@ -4626,8 +4626,9 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
 unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
 for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
   ParamTypesForArgChecking.push_back(ParamPattern);
-  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
-   
/*ExplicitObjetArgument=*/false);
+  if (auto Result =
+  DeduceCallArgument(ParamPattern, ArgIdx,
+ /*ExplicitObjectArgument=*/false);
   Result != TemplateDeductionResult::Success)
 return Result;
 

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


[clang] [clang] Fix a typo: ExplicitObje[C]tArgument. NFC (PR #94094)

2024-05-31 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov closed 
https://github.com/llvm/llvm-project/pull/94094
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-07-28 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov closed 
https://github.com/llvm/llvm-project/pull/97164
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-07-19 Thread Pavel Samolysov via cfe-commits

samolisov wrote:

Gentle ping.

I've addressed all the comments (thank you, @vitalybuka).

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


[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-06-29 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov created 
https://github.com/llvm/llvm-project/pull/97164

When clang compiles the following expression:

```c++
  return A{B{"Move Ctor"}};
```
(where `B` is a base class for `A`), it adds a call to the move constructor of 
`B`. When the code is changed to...

```c++
  return A{{"No Move Ctor"}};
```
... a move constructor is invoked neither for `A` nor for `B`.

The lit test demonstrates the difference in the generated AST.

>From 2cf5a4e016fb7b5cc58a0d2ca5411df65e17a8cb Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Sat, 29 Jun 2024 15:18:11 +0300
Subject: [PATCH] [Clang][Sema] Add a test for move ctor calling for a base
 class. NFC

When clang compiles the following expression:

```c++
  return A{B{"Move Ctor"}};
```
(where `B` is a base class for `A`), it adds a call to the move
constructor of `B`. When the code is changed to...

```c++
  return A{{"No Move Ctor"}};
```
... a move constructor is invoked neither for `A` nor for `B`.

The lit test demonstrates the difference in the generated AST.
---
 .../AST/explicit-base-class-move-cntr.cpp | 43 +++
 1 file changed, 43 insertions(+)
 create mode 100644 clang/test/AST/explicit-base-class-move-cntr.cpp

diff --git a/clang/test/AST/explicit-base-class-move-cntr.cpp 
b/clang/test/AST/explicit-base-class-move-cntr.cpp
new file mode 100644
index 0..b9b591ebc79d7
--- /dev/null
+++ b/clang/test/AST/explicit-base-class-move-cntr.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s
+
+struct ExplicitBase {
+  explicit ExplicitBase(const char *) { }
+  ExplicitBase(const ExplicitBase &) {}
+  ExplicitBase(ExplicitBase &&) {}
+  ExplicitBase &operator=(const ExplicitBase &) { return *this; }
+  ExplicitBase &operator=(ExplicitBase &&) { return *this; }
+  ~ExplicitBase() { }
+};
+
+struct Derived1 : ExplicitBase {};
+
+Derived1 makeDerived1() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived1 'Derived1 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-DAG:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ExplicitBase' xvalue
+  // CHECK-NEXT: CXXBindTemporaryExpr 0x[[TEMP:[^ ]*]]  'ExplicitBase' (CXXTemporary 0x[[TEMP]])
+  // CHECK-NEXT: CXXTemporaryObjectExpr 0x{{[^ ]*}}  'ExplicitBase' 'void (const char *)' list
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const char *' 

+  // CHECK-NEXT: StringLiteral 0x{{[^ ]*}}  'const char[10]' 
lvalue "Move Ctor"
+  return Derived1{ExplicitBase{"Move Ctor"}};
+}
+
+struct ImplicitBase {
+  ImplicitBase(const char *) { }
+  ImplicitBase(const ImplicitBase &) {}
+  ImplicitBase(ImplicitBase &&) {}
+  ImplicitBase &operator=(const ImplicitBase &) { return *this; }
+  ImplicitBase &operator=(ImplicitBase &&) { return *this; }
+  ~ImplicitBase() { }
+};
+
+struct Derived2 : ImplicitBase {};
+
+Derived2 makeDerived2() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived2 'Derived2 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-NOT:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ImplicitBase' xvalue
+  return Derived2{{"No Ctor"}};
+}

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


[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-06-29 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov updated 
https://github.com/llvm/llvm-project/pull/97164

>From 0d9db6b69674dc3e33ab6b411c062b0126486d4c Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Sat, 29 Jun 2024 15:18:11 +0300
Subject: [PATCH] [Clang][Sema] Add a test for move ctor calling for a base
 class. NFC

When clang compiles the following expression:

```c++
  return A{B{"Move Ctor"}};
```
(where `B` is a base class for `A`), it adds a call to the move
constructor of `B`. When the code is changed to...

```c++
  return A{{"No Move Ctor"}};
```
... a move constructor is invoked neither for `A` nor for `B`.

The lit test demonstrates the difference in the generated AST.

#Issue: 92495
---
 .../AST/explicit-base-class-move-cntr.cpp | 43 +++
 1 file changed, 43 insertions(+)
 create mode 100644 clang/test/AST/explicit-base-class-move-cntr.cpp

diff --git a/clang/test/AST/explicit-base-class-move-cntr.cpp 
b/clang/test/AST/explicit-base-class-move-cntr.cpp
new file mode 100644
index 0..b9b591ebc79d7
--- /dev/null
+++ b/clang/test/AST/explicit-base-class-move-cntr.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s
+
+struct ExplicitBase {
+  explicit ExplicitBase(const char *) { }
+  ExplicitBase(const ExplicitBase &) {}
+  ExplicitBase(ExplicitBase &&) {}
+  ExplicitBase &operator=(const ExplicitBase &) { return *this; }
+  ExplicitBase &operator=(ExplicitBase &&) { return *this; }
+  ~ExplicitBase() { }
+};
+
+struct Derived1 : ExplicitBase {};
+
+Derived1 makeDerived1() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived1 'Derived1 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-DAG:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ExplicitBase' xvalue
+  // CHECK-NEXT: CXXBindTemporaryExpr 0x[[TEMP:[^ ]*]]  'ExplicitBase' (CXXTemporary 0x[[TEMP]])
+  // CHECK-NEXT: CXXTemporaryObjectExpr 0x{{[^ ]*}}  'ExplicitBase' 'void (const char *)' list
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const char *' 

+  // CHECK-NEXT: StringLiteral 0x{{[^ ]*}}  'const char[10]' 
lvalue "Move Ctor"
+  return Derived1{ExplicitBase{"Move Ctor"}};
+}
+
+struct ImplicitBase {
+  ImplicitBase(const char *) { }
+  ImplicitBase(const ImplicitBase &) {}
+  ImplicitBase(ImplicitBase &&) {}
+  ImplicitBase &operator=(const ImplicitBase &) { return *this; }
+  ImplicitBase &operator=(ImplicitBase &&) { return *this; }
+  ~ImplicitBase() { }
+};
+
+struct Derived2 : ImplicitBase {};
+
+Derived2 makeDerived2() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived2 'Derived2 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-NOT:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ImplicitBase' xvalue
+  return Derived2{{"No Ctor"}};
+}

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


[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-06-29 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov updated 
https://github.com/llvm/llvm-project/pull/97164

>From edf0d10b41099068ef49a2d2fe0ce60356d2f2fd Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Sat, 29 Jun 2024 15:18:11 +0300
Subject: [PATCH] [Clang][Sema] Add a test for move ctor calling for a base
 class. NFC

When clang compiles the following expression:

```c++
  return A{B{"Move Ctor"}};
```
(where `B` is a base class for `A`), it adds a call to the move
constructor of `B`. When the code is changed to...

```c++
  return A{{"No Move Ctor"}};
```
... a move constructor is invoked neither for `A` nor for `B`.

The lit test demonstrates the difference in the generated AST.

Issue: #92495
---
 .../AST/explicit-base-class-move-cntr.cpp | 43 +++
 1 file changed, 43 insertions(+)
 create mode 100644 clang/test/AST/explicit-base-class-move-cntr.cpp

diff --git a/clang/test/AST/explicit-base-class-move-cntr.cpp 
b/clang/test/AST/explicit-base-class-move-cntr.cpp
new file mode 100644
index 0..b9b591ebc79d7
--- /dev/null
+++ b/clang/test/AST/explicit-base-class-move-cntr.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s
+
+struct ExplicitBase {
+  explicit ExplicitBase(const char *) { }
+  ExplicitBase(const ExplicitBase &) {}
+  ExplicitBase(ExplicitBase &&) {}
+  ExplicitBase &operator=(const ExplicitBase &) { return *this; }
+  ExplicitBase &operator=(ExplicitBase &&) { return *this; }
+  ~ExplicitBase() { }
+};
+
+struct Derived1 : ExplicitBase {};
+
+Derived1 makeDerived1() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived1 'Derived1 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-DAG:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ExplicitBase' xvalue
+  // CHECK-NEXT: CXXBindTemporaryExpr 0x[[TEMP:[^ ]*]]  'ExplicitBase' (CXXTemporary 0x[[TEMP]])
+  // CHECK-NEXT: CXXTemporaryObjectExpr 0x{{[^ ]*}}  'ExplicitBase' 'void (const char *)' list
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const char *' 

+  // CHECK-NEXT: StringLiteral 0x{{[^ ]*}}  'const char[10]' 
lvalue "Move Ctor"
+  return Derived1{ExplicitBase{"Move Ctor"}};
+}
+
+struct ImplicitBase {
+  ImplicitBase(const char *) { }
+  ImplicitBase(const ImplicitBase &) {}
+  ImplicitBase(ImplicitBase &&) {}
+  ImplicitBase &operator=(const ImplicitBase &) { return *this; }
+  ImplicitBase &operator=(ImplicitBase &&) { return *this; }
+  ~ImplicitBase() { }
+};
+
+struct Derived2 : ImplicitBase {};
+
+Derived2 makeDerived2() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived2 'Derived2 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-NOT:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ImplicitBase' xvalue
+  return Derived2{{"No Ctor"}};
+}

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


[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-06-29 Thread Pavel Samolysov via cfe-commits

samolisov wrote:

This is a pre-fix test (but, actually, I have no fix for now) to demonstrate 
the difference in compilation between some looking very similar pieces of the 
code. I sure the root cause (if this is an issue at all) lies in 
`SemaInit.cpp`, this is why I've added the developers who were working with 
this file recently as reviewers. Because this is my first lit test for clang, 
I'm not sure `AST` is the correct directory for such kind of tests but I didn't 
manage to find a better place: all the tests in the `SemaCXX` as well as in the 
`Parser` directories check some error messages or work with some IR, not AST 
dumps. If you think there is more appropriate directory for the test, please 
let me know.

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