[clang] 1a3a2ee - [NFC] Move function definition to cpp file

2022-07-22 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-07-23T13:43:42+08:00
New Revision: 1a3a2eec717b6067e29d8a07318257d2d96da238

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

LOG: [NFC] Move function definition to cpp file

Signed-off-by: Jun Zhang 

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index a8b008b11435..101080b6fe13 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6973,3 +6973,31 @@ void 
CodeGenModule::printPostfixForExternalizedDecl(llvm::raw_ostream ,
 OS << getContext().getCUIDHash();
   }
 }
+
+void CodeGenModule::moveLazyEmissionStates(CodeGenModule *NewBuilder) {
+  assert(DeferredDeclsToEmit.empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(NewBuilder->DeferredDecls.empty() &&
+ "Newly created module should not have deferred decls");
+  NewBuilder->DeferredDecls = std::move(DeferredDecls);
+
+  assert(NewBuilder->DeferredVTables.empty() &&
+ "Newly created module should not have deferred vtables");
+  NewBuilder->DeferredVTables = std::move(DeferredVTables);
+
+  assert(NewBuilder->MangledDeclNames.empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(NewBuilder->Manglings.empty() &&
+ "Newly created module should not have manglings");
+  NewBuilder->Manglings = std::move(Manglings);
+
+  assert(WeakRefReferences.empty() && "Not all WeakRefRefs have been applied");
+  NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
+
+  NewBuilder->TBAA = std::move(TBAA);
+
+  assert(NewBuilder->EmittedDeferredDecls.empty() &&
+ "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
+  NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+}

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index aa57dc5a28d2..c939e7a309f5 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1514,34 +1514,7 @@ class CodeGenModule : public CodeGenTypeCache {
   /// Move some lazily-emitted states to the NewBuilder. This is especially
   /// essential for the incremental parsing environment like Clang Interpreter,
   /// because we'll lose all important information after each repl.
-  void moveLazyEmissionStates(CodeGenModule *NewBuilder) {
-assert(DeferredDeclsToEmit.empty() &&
-   "Should have emitted all decls deferred to emit.");
-assert(NewBuilder->DeferredDecls.empty() &&
-   "Newly created module should not have deferred decls");
-NewBuilder->DeferredDecls = std::move(DeferredDecls);
-
-assert(NewBuilder->DeferredVTables.empty() &&
-   "Newly created module should not have deferred vtables");
-NewBuilder->DeferredVTables = std::move(DeferredVTables);
-
-assert(NewBuilder->MangledDeclNames.empty() &&
-   "Newly created module should not have mangled decl names");
-assert(NewBuilder->Manglings.empty() &&
-   "Newly created module should not have manglings");
-NewBuilder->Manglings = std::move(Manglings);
-
-assert(WeakRefReferences.empty() &&
-   "Not all WeakRefRefs have been applied");
-NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
-
-NewBuilder->TBAA = std::move(TBAA);
-
-assert(NewBuilder->EmittedDeferredDecls.empty() &&
-   "Still have (unmerged) EmittedDeferredDecls deferred decls");
-
-NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
-  }
+  void moveLazyEmissionStates(CodeGenModule *NewBuilder);
 
 private:
   llvm::Constant *GetOrCreateLLVMFunction(



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


[PATCH] D128619: [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)

2022-07-22 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/DeclCXX.cpp:899
+  // triviality properties of the class until selecting a destructor and
+  // computing the eligibility of SMFs. This is because those member
+  // functions may have constraints that we need to evaluate and compare

I think we should spell out `Special Member Function` instead of using `SMF` 



Comment at: clang/lib/Sema/SemaDecl.cpp:17875
+return true;
+  if (!Context.hasSameType(M1->getParamDecl(0)->getType(),
+   M2->getParamDecl(0)->getType()))

What happens if we have further parameters with default arguments? Unless I am 
missing something they are still special member functions but the proposal does 
not seem to cover them.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128619/new/

https://reviews.llvm.org/D128619

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


[PATCH] D130299: [clang-format] FIX: Misformatting lambdas with trailing return type 'auto' in braced lists

2022-07-22 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks requested changes to this revision.
HazardyKnusperkeks added a comment.
This revision now requires changes to proceed.

In D130299#3672486 , @denis-fatkulin 
wrote:

>> Could you please add full git context?
>
> I updated the patch with properly git context. Thanks!
>
>> Was the problem due to misannotation of auto? If so, could you add an 
>> annotator test?
>
> I'm not sure about the questions. I will try to explain my patch purpose. 
> Actually there was two problems:
>
> 1. `auto` wasn't detected as properly type keyword in lambda's trailing 
> return type. So, formatting was completely wrong for this case (fixed in 
> `clang/lib/Format/UnwrappedLineParser.cpp`)
> 2. The keyword `auto` and left brace `{` was interpreted as declaration 
> `auto{}`. So, formatting delete a space symbol between them. (fixed in 
> `clang/lib/Format/TokenAnnotator.cpp`)
>
> Both cases are checked in changes at `clang/unittests/Format/FormatTest.cpp` 
> and I think the unit test is sufficient.

The question is, wether `auto` did get the type `kw_auto` before your change or 
not. If not a test for the token annotator would be in place. See e.g. D129946 
.
And I actually think you should amend the test case from there, because as far 
as I can see if there was an `auto` we would stop parsing the lambda and not 
assign the `TT_LambdaLBrace`, etc. In fact I can't see the anything related to 
braced lists in your fixes. The error was primarily an annotation error, with 
the adding space as a formation error. The fucked up braced list is just a 
follow up error.




Comment at: clang/lib/Format/TokenAnnotator.cpp:3314
+  // Lambda with trailing return type 'auto': []() -> auto { return T; }
+  if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace)
+return true;





Comment at: clang/lib/Format/TokenAnnotator.cpp:3314
+  // Lambda with trailing return type 'auto': []() -> auto { return T; }
+  if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace)
+return true;

HazardyKnusperkeks wrote:
> 
Maybe split it up in two changes, and change it to this, because I think we 
would have the same problem.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130299/new/

https://reviews.llvm.org/D130299

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


[PATCH] D130406: Use llvm::sort instead of std::sort where possible

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: bzcheeseman, sdasgup3, carlosgalvezp, wenzhicui, 
wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, 
grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, 
shauheen, rriddle, mehdi_amini, usaxena95, kadircet, arphaman, mgrang, 
hiraditya, arichardson, emaste.
Herald added a reviewer: rriddle.
Herald added a reviewer: MaskRay.
Herald added a reviewer: bondhugula.
Herald added a project: All.
gribozavr requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: cfe-commits, llvm-commits, StephenFan, 
stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, MLIR, LLVM, clang-tools-extra.

llvm::sort is beneficial even when we use the iterator-based overload,
since it can optionally shuffle the elements (to detect
non-determinism). However llvm::sort is not usable everywhere, for
example, in compiler-rt.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130406

Files:
  clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
  clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
  
clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/unittests/Tooling/TransformerTest.cpp
  lld/COFF/Chunks.cpp
  lld/COFF/DLL.cpp
  lld/COFF/DriverUtils.cpp
  lld/ELF/SyntheticSections.cpp
  llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
  llvm/lib/MC/MCPseudoProbe.cpp
  llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
  llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp
  llvm/lib/Target/XCore/XCoreFrameLowering.cpp
  llvm/unittests/ADT/SmallSetTest.cpp
  llvm/unittests/MIR/MachineMetadata.cpp
  llvm/unittests/Support/AlignmentTest.cpp
  llvm/utils/TableGen/DXILEmitter.cpp
  llvm/utils/TableGen/DirectiveEmitter.cpp
  llvm/utils/TableGen/SearchableTableEmitter.cpp
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
  mlir/lib/Analysis/Liveness.cpp
  mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
  mlir/lib/Dialect/SCF/Utils/Utils.cpp
  mlir/lib/IR/AffineExpr.cpp

Index: mlir/lib/IR/AffineExpr.cpp
===
--- mlir/lib/IR/AffineExpr.cpp
+++ mlir/lib/IR/AffineExpr.cpp
@@ -1073,7 +1073,7 @@
   // Constructing the simplified semi-affine sum of product/division/mod
   // expression from the flattened form in the desired sorted order of indices
   // of the various individual product/division/mod expressions.
-  std::sort(indices.begin(), indices.end());
+  llvm::sort(indices);
   for (const std::pair index : indices) {
 assert(indexToExprMap.lookup(index) &&
"cannot find key in `indexToExprMap` map");
Index: mlir/lib/Dialect/SCF/Utils/Utils.cpp
===
--- mlir/lib/Dialect/SCF/Utils/Utils.cpp
+++ mlir/lib/Dialect/SCF/Utils/Utils.cpp
@@ -673,7 +673,7 @@
   // Presort combined dimensions.
   auto sortedDimensions = llvm::to_vector<3>(combinedDimensions);
   for (auto  : sortedDimensions)
-std::sort(dims.begin(), dims.end());
+llvm::sort(dims);
 
   // Normalize ParallelOp's iteration pattern.
   SmallVector normalizedLowerBounds, normalizedSteps,
Index: mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
===
--- mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
+++ mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
@@ -26,6 +26,7 @@
 #include "mlir/Transforms/Passes.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -683,7 +684,7 @@
   srcIdCandidates.push_back(srcNode->id);
   }
 
-  std::sort(srcIdCandidates.begin(), srcIdCandidates.end());
+  llvm::sort(srcIdCandidates);
   srcIdCandidates.erase(
   std::unique(srcIdCandidates.begin(), srcIdCandidates.end()),
   srcIdCandidates.end());
Index: mlir/lib/Analysis/Liveness.cpp
===
--- mlir/lib/Analysis/Liveness.cpp
+++ mlir/lib/Analysis/Liveness.cpp
@@ -15,6 +15,7 @@
 #include "mlir/IR/Operation.h"
 #include "mlir/IR/Region.h"
 #include "mlir/IR/Value.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetOperations.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/Support/raw_ostream.h"
@@ -288,10 +289,9 @@
 
   auto printValueRefs = [&](const ValueSetT ) {
 std::vector orderedValues(values.begin(), values.end());

[PATCH] D129573: [clang] add a diagnostic note 'while loop outside functions' at global scope

2022-07-22 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov accepted this revision as: mizvekov.
mizvekov added a comment.
This revision is now accepted and ready to land.

Thanks! The patch itself LGTM.

Please update / fix up the commit message before merging. It still mentions 
`note` and has some minor English spelling issues.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129573/new/

https://reviews.llvm.org/D129573

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


[PATCH] D130063: [Driver] Enable sanitizers on FreeBSD AArch64

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
Herald added a subscriber: StephenFan.

> [Driver] Enable sanitizers on FreeBSD AArch64

Be specific what sanitizers are enabled.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130063/new/

https://reviews.llvm.org/D130063

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


[PATCH] D130403: Use the range-based overload of llvm::sort where possible

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: carlosgalvezp, cishida, cmtice, usaxena95, kadircet, 
arphaman, mgrang.
Herald added a reviewer: jhenderson.
Herald added a reviewer: aaron.ballman.
Herald added a reviewer: ributzka.
Herald added a project: All.
gribozavr requested review of this revision.
Herald added subscribers: cfe-commits, llvm-commits, lldb-commits, MaskRay.
Herald added projects: clang, LLDB, LLVM, clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130403

Files:
  clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  clang-tools-extra/clang-include-fixer/SymbolIndexManager.cpp
  clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
  clang-tools-extra/clangd/index/StdLib.cpp
  clang/include/clang/Basic/Attr.td
  clang/lib/Driver/Multilib.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  lldb/source/Interpreter/OptionValueArray.cpp
  lldb/source/Interpreter/OptionValueFileSpecList.cpp
  lldb/source/Interpreter/OptionValuePathMappings.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Symbol/ArmUnwindInfo.cpp
  lldb/source/Symbol/CompileUnit.cpp
  lldb/source/Symbol/Symtab.cpp
  lldb/source/Target/DynamicRegisterInfo.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Utility/ReproducerProvider.cpp
  lldb/source/Utility/Timer.cpp
  llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
  llvm/unittests/ADT/SmallPtrSetTest.cpp
  llvm/unittests/TextAPI/TextStubV1Tests.cpp
  llvm/unittests/TextAPI/TextStubV2Tests.cpp
  llvm/unittests/TextAPI/TextStubV3Tests.cpp
  llvm/unittests/TextAPI/TextStubV4Tests.cpp

Index: llvm/unittests/TextAPI/TextStubV4Tests.cpp
===
--- llvm/unittests/TextAPI/TextStubV4Tests.cpp
+++ llvm/unittests/TextAPI/TextStubV4Tests.cpp
@@ -125,9 +125,9 @@
   Sym->isReexported() ? Reexports.emplace_back(std::move(temp))
   : Exports.emplace_back(std::move(temp));
   }
-  llvm::sort(Exports.begin(), Exports.end());
-  llvm::sort(Reexports.begin(), Reexports.end());
-  llvm::sort(Undefineds.begin(), Undefineds.end());
+  llvm::sort(Exports);
+  llvm::sort(Reexports);
+  llvm::sort(Undefineds);
 
   static ExportedSymbol ExpectedExportedSymbols[] = {
   {SymbolKind::GlobalSymbol, "_symA", false, false},
@@ -296,9 +296,9 @@
   Sym->isReexported() ? Reexports.emplace_back(std::move(Temp))
   : Exports.emplace_back(std::move(Temp));
   }
-  llvm::sort(Exports.begin(), Exports.end());
-  llvm::sort(Reexports.begin(), Reexports.end());
-  llvm::sort(Undefineds.begin(), Undefineds.end());
+  llvm::sort(Exports);
+  llvm::sort(Reexports);
+  llvm::sort(Undefineds);
 
   static ExportedSymbol ExpectedExportedSymbols[] = {
   {SymbolKind::GlobalSymbol, "_symA", false, false},
Index: llvm/unittests/TextAPI/TextStubV3Tests.cpp
===
--- llvm/unittests/TextAPI/TextStubV3Tests.cpp
+++ llvm/unittests/TextAPI/TextStubV3Tests.cpp
@@ -111,7 +111,7 @@
 ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),
Sym->isWeakDefined(), Sym->isThreadLocalValue()});
   }
-  llvm::sort(Exports.begin(), Exports.end());
+  llvm::sort(Exports);
 
   EXPECT_EQ(sizeof(TBDv3Symbols) / sizeof(ExportedSymbol), Exports.size());
   EXPECT_TRUE(
@@ -203,7 +203,7 @@
 Sym->isWeakDefined(),
 Sym->isThreadLocalValue()});
   }
-  llvm::sort(Exports.begin(), Exports.end());
+  llvm::sort(Exports);
 
   EXPECT_EQ(sizeof(TBDv3Symbols) / sizeof(ExportedSymbol), Exports.size());
   EXPECT_TRUE(
@@ -228,7 +228,7 @@
 Sym->isWeakDefined(),
 Sym->isThreadLocalValue()});
   }
-  llvm::sort(Exports.begin(), Exports.end());
+  llvm::sort(Exports);
 
   ExportedSymbolSeq DocumentSymbols{
   {SymbolKind::GlobalSymbol, "_sym5", false, false},
Index: llvm/unittests/TextAPI/TextStubV2Tests.cpp
===
--- llvm/unittests/TextAPI/TextStubV2Tests.cpp
+++ llvm/unittests/TextAPI/TextStubV2Tests.cpp
@@ -103,7 +103,7 @@
 ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),
Sym->isWeakDefined(), Sym->isThreadLocalValue()});
   }
-  llvm::sort(Exports.begin(), Exports.end());
+  llvm::sort(Exports);
 
   EXPECT_EQ(sizeof(TBDv2Symbols) / sizeof(ExportedSymbol), Exports.size());
   EXPECT_TRUE(
Index: llvm/unittests/TextAPI/TextStubV1Tests.cpp
===
--- llvm/unittests/TextAPI/TextStubV1Tests.cpp
+++ llvm/unittests/TextAPI/TextStubV1Tests.cpp
@@ -102,7 +102,7 @@
 ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),

[PATCH] D130190: [Driver] Error for -gsplit-dwarf with RISC-V linker relaxation

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG80a4e6fd31a0: [Driver] Error for -gsplit-dwarf with RISC-V 
linker relaxation (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D130190?vs=446239=447011#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130190/new/

https://reviews.llvm.org/D130190

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Clang.h
  clang/test/Driver/riscv-features.c


Index: clang/test/Driver/riscv-features.c
===
--- clang/test/Driver/riscv-features.c
+++ clang/test/Driver/riscv-features.c
@@ -35,3 +35,10 @@
 // RUN: not %clang -cc1 -triple riscv64-unknown-elf -target-feature +e 2>&1 | 
FileCheck %s -check-prefix=RV64-WITH-E
 
 // RV64-WITH-E: error: invalid feature combination: standard user-level 
extension 'e' requires 'rv32'
+
+// RUN: not %clang -c --target=riscv64-linux-gnu -gsplit-dwarf %s 2>&1 | 
FileCheck %s --check-prefix=ERR-SPLIT-DWARF
+// RUN: not %clang -c --target=riscv64 -gsplit-dwarf=single %s 2>&1 | 
FileCheck %s --check-prefix=ERR-SPLIT-DWARF
+// RUN: %clang -### -c --target=riscv64 -mno-relax -g -gsplit-dwarf %s 2>&1 | 
FileCheck %s --check-prefix=SPLIT-DWARF
+
+// ERR-SPLIT-DWARF: error: -gsplit-dwarf{{.*}} is unsupported with RISC-V 
linker relaxation (-mrelax)
+// SPLIT-DWARF: "-split-dwarf-file"
Index: clang/lib/Driver/ToolChains/Clang.h
===
--- clang/lib/Driver/ToolChains/Clang.h
+++ clang/lib/Driver/ToolChains/Clang.h
@@ -198,6 +198,12 @@
 const char *LinkingOutput) const override;
 };
 
+enum class DwarfFissionKind { None, Split, Single };
+
+DwarfFissionKind getDebugFissionKind(const Driver ,
+ const llvm::opt::ArgList ,
+ llvm::opt::Arg *);
+
 } // end namespace tools
 
 } // end namespace driver
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4034,9 +4034,7 @@
  options::OPT_fno_spell_checking);
 }
 
-enum class DwarfFissionKind { None, Split, Single };
-
-static DwarfFissionKind getDebugFissionKind(const Driver ,
+DwarfFissionKind tools::getDebugFissionKind(const Driver ,
 const ArgList , Arg *) {
   Arg = Args.getLastArg(options::OPT_gsplit_dwarf, 
options::OPT_gsplit_dwarf_EQ,
 options::OPT_gno_split_dwarf);
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "RISCV.h"
+#include "../Clang.h"
 #include "ToolChains/CommonArgs.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Driver/Driver.h"
@@ -137,10 +138,17 @@
 Features.push_back("+reserve-x31");
 
   // -mrelax is default, unless -mno-relax is specified.
-  if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
+  if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) {
 Features.push_back("+relax");
-  else
+// -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing
+// into .debug_addr, which is currently not implemented.
+Arg *A;
+if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None)
+  D.Diag(clang::diag::err_drv_riscv_unsupported_with_linker_relaxation)
+  << A->getAsString(Args);
+  } else {
 Features.push_back("-relax");
+  }
 
   // GCC Compatibility: -mno-save-restore is default, unless -msave-restore is
   // specified.
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -682,4 +682,7 @@
 def warn_drv_sarif_format_unstable : Warning<
   "diagnostic formatting in SARIF mode is currently unstable">,
   InGroup>;
+
+def err_drv_riscv_unsupported_with_linker_relaxation : Error<
+  "%0 is unsupported with RISC-V linker relaxation (-mrelax)">;
 }


Index: clang/test/Driver/riscv-features.c
===
--- clang/test/Driver/riscv-features.c
+++ clang/test/Driver/riscv-features.c
@@ -35,3 +35,10 @@
 // RUN: not %clang -cc1 -triple riscv64-unknown-elf -target-feature +e 2>&1 | FileCheck %s -check-prefix=RV64-WITH-E
 
 // RV64-WITH-E: error: 

[clang] 80a4e6f - [Driver] Error for -gsplit-dwarf with RISC-V linker relaxation

2022-07-22 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-07-22T17:16:41-07:00
New Revision: 80a4e6fd31a06143b83947785ea3bd5c04344ea6

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

LOG: [Driver] Error for -gsplit-dwarf with RISC-V linker relaxation

-gsplit-dwarf produces a .dwo file which will not be processed by the linker. If
.dwo files contain relocations, they will not be resolved. Therefore the
practice is that .dwo files do not contain relocations.

Address ranges and location description need to use forms/entry kinds indexing
into .debug_addr (DW_FORM_addrx/DW_RLE_startx_endx/etc), which is currently not
implemented.

There is a difficult-to-read MC error with -gsplit-dwarf with RISC-V for both 
-mrelax and -mno-relax.
```
% clang --target=riscv64-linux-gnu -g -gsplit-dwarf -c a.c
error: A dwo section may not contain relocations
```

We expect to fix -mno-relax soon, so report a driver error for -mrelax for now.

Link: https://github.com/llvm/llvm-project/issues/56642

Reviewed By: compnerd, kito-cheng

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Clang.h
clang/test/Driver/riscv-features.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 3c5f7e087de85..2f600d28fea0c 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -682,4 +682,7 @@ def err_drv_invalid_empty_dxil_validator_version : Error<
 def warn_drv_sarif_format_unstable : Warning<
   "diagnostic formatting in SARIF mode is currently unstable">,
   InGroup>;
+
+def err_drv_riscv_unsupported_with_linker_relaxation : Error<
+  "%0 is unsupported with RISC-V linker relaxation (-mrelax)">;
 }

diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 8a8ed20986c57..de6e045a9447f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "RISCV.h"
+#include "../Clang.h"
 #include "ToolChains/CommonArgs.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Driver/Driver.h"
@@ -137,10 +138,17 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("+reserve-x31");
 
   // -mrelax is default, unless -mno-relax is specified.
-  if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
+  if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) {
 Features.push_back("+relax");
-  else
+// -gsplit-dwarf -mrelax requires DW_AT_high_pc/DW_AT_ranges/... indexing
+// into .debug_addr, which is currently not implemented.
+Arg *A;
+if (getDebugFissionKind(D, Args, A) != DwarfFissionKind::None)
+  D.Diag(clang::diag::err_drv_riscv_unsupported_with_linker_relaxation)
+  << A->getAsString(Args);
+  } else {
 Features.push_back("-relax");
+  }
 
   // GCC Compatibility: -mno-save-restore is default, unless -msave-restore is
   // specified.

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 33e3fe267c239..3044c2d92d21f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4034,9 +4034,7 @@ static void RenderDiagnosticsOptions(const Driver , 
const ArgList ,
  options::OPT_fno_spell_checking);
 }
 
-enum class DwarfFissionKind { None, Split, Single };
-
-static DwarfFissionKind getDebugFissionKind(const Driver ,
+DwarfFissionKind tools::getDebugFissionKind(const Driver ,
 const ArgList , Arg *) {
   Arg = Args.getLastArg(options::OPT_gsplit_dwarf, 
options::OPT_gsplit_dwarf_EQ,
 options::OPT_gno_split_dwarf);

diff  --git a/clang/lib/Driver/ToolChains/Clang.h 
b/clang/lib/Driver/ToolChains/Clang.h
index 37263efd57a5e..5209c6687599b 100644
--- a/clang/lib/Driver/ToolChains/Clang.h
+++ b/clang/lib/Driver/ToolChains/Clang.h
@@ -198,6 +198,12 @@ class LLVM_LIBRARY_VISIBILITY LinkerWrapper final : public 
Tool {
 const char *LinkingOutput) const override;
 };
 
+enum class DwarfFissionKind { None, Split, Single };
+
+DwarfFissionKind getDebugFissionKind(const Driver ,
+ const llvm::opt::ArgList ,
+ llvm::opt::Arg *);
+
 } // end namespace tools
 
 } // end namespace driver

diff  --git a/clang/test/Driver/riscv-features.c 

[PATCH] D130308: WIP: [clang] extend getCommonSugaredType to merge sugar nodes

2022-07-22 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked 3 inline comments as done.
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:12670
+  return QualType();
+// FIXME: The modified types can be different as well.
+// FIXME: It's inneficient to have to unify the modified types.

mizvekov wrote:
> rsmith wrote:
> > Should we bail out if this happens, as we do in the other cases above?
> I think this means what we are trying to merge is unrelated, so yes. I just 
> didn't come up with a test case yet :)
I added the handling for those being different here, but I don't think it 
matters for any existing type attribute that I could find.



Comment at: clang/lib/AST/ASTContext.cpp:12698-12699
+return Ctx.getAutoType(Underlying, AX->getKeyword(),
+   AX->isInstantiationDependentType(),
+   AX->containsUnexpandedParameterPack(), CD, As);
+  }

rsmith wrote:
> Instantiation-dependence and "contains unexpanded parameter pack" can depend 
> on which sugar we choose to preserve. I think you strictly-speaking would 
> need to recompute these based on the sugar we end up with rather than 
> inheriting them from `AX`.
I think in this case, a dependent Auto will never be sugar, and a non-dependent 
auto can't have a pack either, so we can just pass in false for both.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130308/new/

https://reviews.llvm.org/D130308

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


[PATCH] D130308: WIP: [clang] extend getCommonSugaredType to merge sugar nodes

2022-07-22 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 447009.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130308/new/

https://reviews.llvm.org/D130308

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/sugar-common-types.cpp

Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix -triple i686-pc-win32
 
 enum class N {};
 
@@ -38,3 +38,77 @@
 N t7 = X4() + Y4(); // expected-error {{rvalue of type 'B4'}}
 N t8 = X4() * Y4(); // expected-error {{rvalue of type 'B4'}}
 N t9 = X5() * Y5(); // expected-error {{rvalue of type 'A4 __attribute__((matrix_type(3, 3)))'}}
+
+template  struct S1 {
+  template  struct S2 {};
+};
+
+N t10 = 0 ? S1() : S1(); // expected-error {{from 'S1' (aka 'S1')}}
+N t11 = 0 ? S1::S2() : S1::S2(); // expected-error {{from 'S1::S2' (aka 'S2')}}
+
+template  using Al = S1;
+
+N t12 = 0 ? Al() : Al(); // expected-error {{from 'Al' (aka 'S1')}}
+
+#define AS1 __attribute__((address_space(1)))
+#define AS2 __attribute__((address_space(1)))
+using AS1X1 = AS1 B1;
+using AS1Y1 = AS1 B1;
+using AS2Y1 = AS2 B1;
+N t13 = 0 ? (AS1X1){} : (AS1Y1){}; // expected-error {{rvalue of type 'AS1 B1' (aka '__attribute__((address_space(1))) int')}}
+N t14 = 0 ? (AS1X1){} : (AS2Y1){}; // expected-error {{rvalue of type '__attribute__((address_space(1))) B1' (aka '__attribute__((address_space(1))) int')}}
+
+using FX1 = X1 ();
+using FY1 = Y1 ();
+N t15 = 0 ? (FX1*){} : (FY1*){}; // expected-error {{rvalue of type 'B1 (*)()' (aka 'int (*)()')}}
+
+struct SS1 {};
+using SB1 = SS1;
+using SX1 = SB1;
+using SY1 = SB1;
+
+using MFX1 = X1 SX1::*();
+using MFY1 = Y1 SY1::*();
+
+N t16 = 0 ? (MFX1*){} : (MFY1*){}; // expected-error {{rvalue of type 'B1 SB1::*(*)()'}}
+
+N t17 = 0 ? (FX1 SX1::*){} : (FY1 SY1::*){}; // expected-error {{rvalue of type 'B1 (SB1::*)() __attribute__((thiscall))'}}
+
+N t18 = 0 ? (__typeof(X1*)){} : (__typeof(Y1*)){}; // expected-error {{rvalue of type 'typeof(B1 *)' (aka 'int *')}}
+
+struct Enums {
+  enum X : B1;
+  enum Y : ::B1;
+};
+using EnumsB = Enums;
+using EnumsX = EnumsB;
+using EnumsY = EnumsB;
+
+N t19 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::Y)){};
+// expected-error@-1 {{rvalue of type 'B1' (aka 'int')}}
+
+N t20 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::X)){};
+// expected-error@-1 {{rvalue of type '__underlying_type(Enums::X)' (aka 'int')}}
+
+using SBTF1 = SS1 [[clang::btf_type_tag("1")]];
+using SBTF2 = ::SS1 [[clang::btf_type_tag("1")]];
+using SBTF3 = ::SS1 [[clang::btf_type_tag("2")]];
+
+N t21 = 0 ? (SBTF1){} : (SBTF3){}; // expected-error {{from 'SS1'}}
+N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 btf_type_tag(1)' (aka 'SS1')}}
+
+using QX = const SB1 *;
+using QY = const ::SB1 *;
+N t23 = 0 ? (QX){} : (QY){}; // expected-error {{rvalue of type 'const SB1 *' (aka 'const SS1 *')}}
+
+template  using Alias = short;
+N t24 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'Alias' (aka 'short')}}
+N t25 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'short'}}
+
+template  concept C1 = true;
+template  concept C2 = true;
+C1 auto t26_1 = (SB1){};
+C1 auto t26_2 = (::SB1){};
+C2 auto t26_3 = (::SB1){};
+N t26 = 0 ? t26_1 : t26_2; // expected-error {{from 'SB1' (aka 'SS1')}}
+N t27 = 0 ? t26_1 : t26_3; // expected-error {{from 'SB1' (aka 'SS1')}}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3776,13 +3776,11 @@
 //   - If A is an array type, the pointer type produced by the
 // array-to-pointer standard conversion (4.2) is used in place of
 // A for type deduction; otherwise,
-if (ArgType->isArrayType())
-  ArgType = S.Context.getArrayDecayedType(ArgType);
 //   - If A is a function type, the pointer type produced by the
 // function-to-pointer standard conversion (4.3) is used in place
 // of A for type deduction; otherwise,
-else if (ArgType->isFunctionType())
-  ArgType = S.Context.getPointerType(ArgType);
+if (ArgType->canDecayToPointerType())
+  ArgType = S.Context.getDecayedType(ArgType);
 else {
   // - If A is a cv-qualified type, the top level cv-qualifiers of A's
   //   type are ignored for type deduction.
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -3329,6 

[PATCH] D130398: [clang][dataflow] Add DataflowEnvironment::dump()

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb5414b566a5a: [clang][dataflow] Add 
DataflowEnvironment::dump() (authored by gribozavr).

Changed prior to commit:
  https://reviews.llvm.org/D130398?vs=446992=447006#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130398/new/

https://reviews.llvm.org/D130398

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -188,6 +188,31 @@
   StrEq(Expected));
 }
 
+TEST(ConstraintSetDebugStringTest, Empty) {
+  llvm::DenseSet Constraints;
+  EXPECT_THAT(debugString(Constraints), StrEq(""));
+}
+
+TEST(ConstraintSetDebugStringTest, Simple) {
+  ConstraintContext Ctx;
+  llvm::DenseSet Constraints;
+  auto X = cast(Ctx.atom());
+  auto Y = cast(Ctx.atom());
+  Constraints.insert(Ctx.disj(X, Y));
+  Constraints.insert(Ctx.disj(X, Ctx.neg(Y)));
+
+  auto Expected = R"((or
+X
+(not
+Y))
+(or
+X
+Y)
+)";
+  EXPECT_THAT(debugString(Constraints, {{X, "X"}, {Y, "Y"}}),
+  StrEq(Expected));
+}
+
 Solver::Result CheckSAT(std::vector Constraints) {
   llvm::DenseSet ConstraintsSet(Constraints.begin(),
  Constraints.end());
Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -17,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/Solver.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -102,6 +103,22 @@
 return formatv("{0}", fmt_pad(S, Indent, 0));
   }
 
+  std::string debugString(const llvm::DenseSet ) {
+std::vector ConstraintsStrings;
+ConstraintsStrings.reserve(Constraints.size());
+for (BoolValue *Constraint : Constraints) {
+  ConstraintsStrings.push_back(debugString(*Constraint));
+}
+llvm::sort(ConstraintsStrings);
+
+std::string Result;
+for (const std::string  : ConstraintsStrings) {
+  Result += S;
+  Result += '\n';
+}
+return Result;
+  }
+
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
   std::string debugString(ArrayRef ,
@@ -151,7 +168,7 @@
   clang::dataflow::debugString(AtomAssignment.second));
   Lines.push_back(Line);
 }
-llvm::sort(Lines.begin(), Lines.end());
+llvm::sort(Lines);
 
 return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
   }
@@ -182,6 +199,12 @@
   return DebugStringGenerator(std::move(AtomNames)).debugString(B);
 }
 
+std::string
+debugString(const llvm::DenseSet ,
+llvm::DenseMap AtomNames) {
+  return DebugStringGenerator(std::move(AtomNames)).debugString(Constraints);
+}
+
 std::string
 debugString(ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames) {
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -15,10 +15,8 @@
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
-#include "clang/AST/ExprCXX.h"
 #include "clang/AST/Type.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
-#include "clang/Analysis/FlowSensitive/StorageLocation.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
@@ -512,5 +510,9 @@
   return DACtx->flowConditionImplies(*FlowConditionToken, Val);
 }
 
+void Environment::dump() const {
+  DACtx->dumpFlowCondition(*FlowConditionToken);
+}
+
 } // namespace dataflow
 } // namespace clang
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- 

[clang] b5414b5 - [clang][dataflow] Add DataflowEnvironment::dump()

2022-07-22 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2022-07-23T01:31:53+02:00
New Revision: b5414b566a5aedd90e41f01dd2b7b632afc5d5b7

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

LOG: [clang][dataflow] Add DataflowEnvironment::dump()

Start by dumping the flow condition.

Reviewed By: ymandel

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index 358ace0430f62..abc3183e1b0b5 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -23,6 +23,7 @@
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/Support/Compiler.h"
 #include 
 #include 
 #include 
@@ -251,6 +252,8 @@ class DataflowAnalysisContext {
   /// `Val2` imposed by the flow condition.
   bool equivalentBoolValues(BoolValue , BoolValue );
 
+  LLVM_DUMP_METHOD void dumpFlowCondition(AtomicBoolValue );
+
 private:
   struct NullableQualTypeDenseMapInfo : private llvm::DenseMapInfo {
 static QualType getEmptyKey() {

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index ce195f0662f53..f17df36f6a4a3 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -19,7 +19,6 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Type.h"
-#include "clang/AST/TypeOrdering.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
@@ -325,6 +324,8 @@ class Environment {
   /// imply that `Val` is true.
   bool flowConditionImplies(BoolValue ) const;
 
+  LLVM_DUMP_METHOD void dump() const;
+
 private:
   /// Creates a value appropriate for `Type`, if `Type` is supported, otherwise
   /// return null.

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h 
b/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
index 74367d29b2a0f..b8efdeb61d280 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -42,6 +42,20 @@ std::string debugString(
 const BoolValue ,
 llvm::DenseMap AtomNames = {{}});
 
+/// Returns a string representation for `Constraints` - a collection of boolean
+/// formulas.
+///
+/// Atomic booleans appearing in the boolean value `Constraints` are assigned 
to
+/// labels either specified in `AtomNames` or created by default rules as B0,
+/// B1, ...
+///
+/// Requirements:
+///
+///   Names assigned to atoms should not be repeated in `AtomNames`.
+std::string debugString(
+const llvm::DenseSet ,
+llvm::DenseMap AtomNames = {{}});
+
 /// Returns a string representation for `Constraints` - a collection of boolean
 /// formulas and the `Result` of satisfiability checking.
 ///

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index cd87e87a6acab..5105999741e6a 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -14,7 +14,9 @@
 
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
+#include "llvm/Support/Debug.h"
 #include 
 #include 
 #include 
@@ -293,6 +295,17 @@ BoolValue 
::buildAndSubstituteFlowConditionWithCache(
   return substituteBoolValue(*ConstraintsIT->second, SubstitutionsCache);
 }
 
+void DataflowAnalysisContext::dumpFlowCondition(AtomicBoolValue ) {
+  llvm::DenseSet Constraints = {};
+  llvm::DenseSet VisitedTokens;
+  addTransitiveFlowConditionConstraints(Token, Constraints, VisitedTokens);
+
+  llvm::DenseMap AtomNames = {
+  {(false), "False"},
+  {(true), "True"}};
+  llvm::dbgs() << 

[PATCH] D130377: Move "clang/Basic/TokenKinds.h" into a separate top-level module.

2022-07-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for the reviews!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130377/new/

https://reviews.llvm.org/D130377

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


[PATCH] D130377: Move "clang/Basic/TokenKinds.h" into a separate top-level module.

2022-07-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e4478bbea72: Move clang/Basic/TokenKinds.h into 
a separate top-level module. (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130377/new/

https://reviews.llvm.org/D130377

Files:
  clang/include/clang/module.modulemap


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -71,10 +71,17 @@
   textual header "Basic/RISCVVTypes.def"
   textual header "Basic/Sanitizers.def"
   textual header "Basic/TargetCXXABI.def"
-  textual header "Basic/TokenKinds.def"
 
   module * { export * }
 }
+module Clang_Basic_TokenKinds {
+  requires cplusplus
+
+  header "Basic/TokenKinds.h"
+  textual header "Basic/TokenKinds.def"
+
+  export *
+}
 
 module Clang_CodeGen { requires cplusplus umbrella "CodeGen" module * { export 
* } }
 module Clang_Config { requires cplusplus umbrella "Config" module * { export * 
} }


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -71,10 +71,17 @@
   textual header "Basic/RISCVVTypes.def"
   textual header "Basic/Sanitizers.def"
   textual header "Basic/TargetCXXABI.def"
-  textual header "Basic/TokenKinds.def"
 
   module * { export * }
 }
+module Clang_Basic_TokenKinds {
+  requires cplusplus
+
+  header "Basic/TokenKinds.h"
+  textual header "Basic/TokenKinds.def"
+
+  export *
+}
 
 module Clang_CodeGen { requires cplusplus umbrella "CodeGen" module * { export * } }
 module Clang_Config { requires cplusplus umbrella "Config" module * { export * } }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1e4478b - Move "clang/Basic/TokenKinds.h" into a separate top-level module.

2022-07-22 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2022-07-22T16:26:27-07:00
New Revision: 1e4478bbea727dbbffb1023eedfc24eae7185782

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

LOG: Move "clang/Basic/TokenKinds.h" into a separate top-level module.

Fixes modular build for clangPseudoGrammar from clang-tools-extra.

Starting from https://reviews.llvm.org/D126731 clangPseudoGrammar
doesn't depend on generated .inc headers but still depends on
"Basic/TokenKinds.h". It means clangPseudoGrammar depends on module
'Clang_Basic' which does depend on generated .inc headers. To avoid
these coarse dependencies and extra build steps, extract
"clang/Basic/TokenKinds.h" into a top-level module 'Clang_Basic_TokenKinds'.

rdar://97387951

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

Added: 


Modified: 
clang/include/clang/module.modulemap

Removed: 




diff  --git a/clang/include/clang/module.modulemap 
b/clang/include/clang/module.modulemap
index aca4d5ab919a..56c40ab0b001 100644
--- a/clang/include/clang/module.modulemap
+++ b/clang/include/clang/module.modulemap
@@ -71,10 +71,17 @@ module Clang_Basic {
   textual header "Basic/RISCVVTypes.def"
   textual header "Basic/Sanitizers.def"
   textual header "Basic/TargetCXXABI.def"
-  textual header "Basic/TokenKinds.def"
 
   module * { export * }
 }
+module Clang_Basic_TokenKinds {
+  requires cplusplus
+
+  header "Basic/TokenKinds.h"
+  textual header "Basic/TokenKinds.def"
+
+  export *
+}
 
 module Clang_CodeGen { requires cplusplus umbrella "CodeGen" module * { export 
* } }
 module Clang_Config { requires cplusplus umbrella "Config" module * { export * 
} }



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


[PATCH] D130399: [clang][dataflow] Expose stringification functions for SAT solver enums

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee6aba85aa48: [clang][dataflow] Expose stringification 
functions for SAT solver enums (authored by gribozavr).

Changed prior to commit:
  https://reviews.llvm.org/D130399?vs=446991=447002#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130399/new/

https://reviews.llvm.org/D130399

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp


Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -30,6 +30,28 @@
 using llvm::fmt_pad;
 using llvm::formatv;
 
+std::string debugString(Solver::Result::Assignment Assignment) {
+  switch (Assignment) {
+  case Solver::Result::Assignment::AssignedFalse:
+return "False";
+  case Solver::Result::Assignment::AssignedTrue:
+return "True";
+  }
+  llvm_unreachable("Booleans can only be assigned true/false");
+}
+
+std::string debugString(Solver::Result::Status Status) {
+  switch (Status) {
+  case Solver::Result::Status::Satisfiable:
+return "Satisfiable";
+  case Solver::Result::Status::Unsatisfiable:
+return "Unsatisfiable";
+  case Solver::Result::Status::TimedOut:
+return "TimedOut";
+  }
+  llvm_unreachable("Unhandled SAT check result status");
+}
+
 namespace {
 
 class DebugStringGenerator {
@@ -101,7 +123,7 @@
   ConstraintsStrings.push_back(debugString(*Constraint));
 }
 
-auto StatusString = debugString(Result.getStatus());
+auto StatusString = clang::dataflow::debugString(Result.getStatus());
 auto Solution = Result.getSolution();
 auto SolutionString = Solution ? "\n" + debugString(Solution.value()) : "";
 
@@ -126,7 +148,7 @@
   auto Line = formatv("{0} = {1}",
   fmt_align(getAtomName(AtomAssignment.first),
 AlignStyle::Left, MaxNameLength),
-  debugString(AtomAssignment.second));
+  clang::dataflow::debugString(AtomAssignment.second));
   Lines.push_back(Line);
 }
 llvm::sort(Lines.begin(), Lines.end());
@@ -134,30 +156,6 @@
 return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
   }
 
-  /// Returns a string representation of a boolean assignment to true or false.
-  std::string debugString(Solver::Result::Assignment Assignment) {
-switch (Assignment) {
-case Solver::Result::Assignment::AssignedFalse:
-  return "False";
-case Solver::Result::Assignment::AssignedTrue:
-  return "True";
-}
-llvm_unreachable("Booleans can only be assigned true/false");
-  }
-
-  /// Returns a string representation of the result status of a SAT check.
-  std::string debugString(Solver::Result::Status Status) {
-switch (Status) {
-case Solver::Result::Status::Satisfiable:
-  return "Satisfiable";
-case Solver::Result::Status::Unsatisfiable:
-  return "Unsatisfiable";
-case Solver::Result::Status::TimedOut:
-  return "TimedOut";
-}
-llvm_unreachable("Unhandled SAT check result status");
-  }
-
   /// Returns the name assigned to `Atom`, either user-specified or created by
   /// default rules (B0, B1, ...).
   std::string getAtomName(const AtomicBoolValue *Atom) {
Index: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
===
--- clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -23,6 +23,13 @@
 
 namespace clang {
 namespace dataflow {
+
+/// Returns a string representation of a boolean assignment to true or false.
+std::string debugString(Solver::Result::Assignment Assignment);
+
+/// Returns a string representation of the result status of a SAT check.
+std::string debugString(Solver::Result::Status Status);
+
 /// Returns a string representation for the boolean value `B`.
 ///
 /// Atomic booleans appearing in the boolean value `B` are assigned to labels


Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -30,6 +30,28 @@
 using llvm::fmt_pad;
 using llvm::formatv;
 
+std::string debugString(Solver::Result::Assignment Assignment) {
+  switch (Assignment) {
+  case Solver::Result::Assignment::AssignedFalse:
+return "False";
+  case Solver::Result::Assignment::AssignedTrue:
+return "True";
+  }
+  llvm_unreachable("Booleans can only be assigned true/false");
+}
+
+std::string debugString(Solver::Result::Status Status) {
+  switch (Status) {
+  case 

[clang] ee6aba8 - [clang][dataflow] Expose stringification functions for SAT solver enums

2022-07-22 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2022-07-23T01:21:20+02:00
New Revision: ee6aba85aa48d03a931ba989ea2c1584b468588a

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

LOG: [clang][dataflow] Expose stringification functions for SAT solver enums

Reviewed By: ymandel

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h 
b/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
index 3b854850907b..74367d29b2a0 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -23,6 +23,13 @@
 
 namespace clang {
 namespace dataflow {
+
+/// Returns a string representation of a boolean assignment to true or false.
+std::string debugString(Solver::Result::Assignment Assignment);
+
+/// Returns a string representation of the result status of a SAT check.
+std::string debugString(Solver::Result::Status Status);
+
 /// Returns a string representation for the boolean value `B`.
 ///
 /// Atomic booleans appearing in the boolean value `B` are assigned to labels

diff  --git a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp 
b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
index 1d699a9c9804..f4217fd04c49 100644
--- a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -30,6 +30,28 @@ using llvm::AlignStyle;
 using llvm::fmt_pad;
 using llvm::formatv;
 
+std::string debugString(Solver::Result::Assignment Assignment) {
+  switch (Assignment) {
+  case Solver::Result::Assignment::AssignedFalse:
+return "False";
+  case Solver::Result::Assignment::AssignedTrue:
+return "True";
+  }
+  llvm_unreachable("Booleans can only be assigned true/false");
+}
+
+std::string debugString(Solver::Result::Status Status) {
+  switch (Status) {
+  case Solver::Result::Status::Satisfiable:
+return "Satisfiable";
+  case Solver::Result::Status::Unsatisfiable:
+return "Unsatisfiable";
+  case Solver::Result::Status::TimedOut:
+return "TimedOut";
+  }
+  llvm_unreachable("Unhandled SAT check result status");
+}
+
 namespace {
 
 class DebugStringGenerator {
@@ -101,7 +123,7 @@ Constraints
   ConstraintsStrings.push_back(debugString(*Constraint));
 }
 
-auto StatusString = debugString(Result.getStatus());
+auto StatusString = clang::dataflow::debugString(Result.getStatus());
 auto Solution = Result.getSolution();
 auto SolutionString = Solution ? "\n" + debugString(Solution.value()) : "";
 
@@ -126,7 +148,7 @@ Constraints
   auto Line = formatv("{0} = {1}",
   fmt_align(getAtomName(AtomAssignment.first),
 AlignStyle::Left, MaxNameLength),
-  debugString(AtomAssignment.second));
+  clang::dataflow::debugString(AtomAssignment.second));
   Lines.push_back(Line);
 }
 llvm::sort(Lines.begin(), Lines.end());
@@ -134,30 +156,6 @@ Constraints
 return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
   }
 
-  /// Returns a string representation of a boolean assignment to true or false.
-  std::string debugString(Solver::Result::Assignment Assignment) {
-switch (Assignment) {
-case Solver::Result::Assignment::AssignedFalse:
-  return "False";
-case Solver::Result::Assignment::AssignedTrue:
-  return "True";
-}
-llvm_unreachable("Booleans can only be assigned true/false");
-  }
-
-  /// Returns a string representation of the result status of a SAT check.
-  std::string debugString(Solver::Result::Status Status) {
-switch (Status) {
-case Solver::Result::Status::Satisfiable:
-  return "Satisfiable";
-case Solver::Result::Status::Unsatisfiable:
-  return "Unsatisfiable";
-case Solver::Result::Status::TimedOut:
-  return "TimedOut";
-}
-llvm_unreachable("Unhandled SAT check result status");
-  }
-
   /// Returns the name assigned to `Atom`, either user-specified or created by
   /// default rules (B0, B1, ...).
   std::string getAtomName(const AtomicBoolValue *Atom) {



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


[PATCH] D130400: [clang][dataflow] ArrayRef'ize debugString()

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG589ddd7fe8e4: [clang][dataflow] ArrayRefize 
debugString() (authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130400/new/

https://reviews.llvm.org/D130400

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp


Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -82,7 +82,7 @@
 
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
-  std::string debugString(const std::vector ,
+  std::string debugString(ArrayRef ,
   const Solver::Result ) {
 auto Template = R"(
 Constraints
@@ -185,8 +185,7 @@
 }
 
 std::string
-debugString(const std::vector ,
-const Solver::Result ,
+debugString(ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames) {
   return DebugStringGenerator(std::move(AtomNames))
   .debugString(Constraints, Result);
Index: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
===
--- clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -46,7 +46,7 @@
 ///
 ///   Names assigned to atoms should not be repeated in `AtomNames`.
 std::string debugString(
-const std::vector , const Solver::Result ,
+ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames = {{}});
 inline std::string debugString(
 const llvm::DenseSet ,


Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -82,7 +82,7 @@
 
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
-  std::string debugString(const std::vector ,
+  std::string debugString(ArrayRef ,
   const Solver::Result ) {
 auto Template = R"(
 Constraints
@@ -185,8 +185,7 @@
 }
 
 std::string
-debugString(const std::vector ,
-const Solver::Result ,
+debugString(ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames) {
   return DebugStringGenerator(std::move(AtomNames))
   .debugString(Constraints, Result);
Index: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
===
--- clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -46,7 +46,7 @@
 ///
 ///   Names assigned to atoms should not be repeated in `AtomNames`.
 std::string debugString(
-const std::vector , const Solver::Result ,
+ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames = {{}});
 inline std::string debugString(
 const llvm::DenseSet ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 589ddd7 - [clang][dataflow] ArrayRef'ize debugString()

2022-07-22 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2022-07-23T01:16:31+02:00
New Revision: 589ddd7fe8e4dcf3323dd0b8f6af3ae953ed6037

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

LOG: [clang][dataflow] ArrayRef'ize debugString()

Reviewed By: ymandel

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
clang/lib/Analysis/FlowSensitive/DebugSupport.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h 
b/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
index ef903d807e12f..3b854850907b5 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -46,7 +46,7 @@ std::string debugString(
 ///
 ///   Names assigned to atoms should not be repeated in `AtomNames`.
 std::string debugString(
-const std::vector , const Solver::Result ,
+ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames = {{}});
 inline std::string debugString(
 const llvm::DenseSet ,

diff  --git a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp 
b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
index a2895d0197b1d..1d699a9c98040 100644
--- a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -82,7 +82,7 @@ class DebugStringGenerator {
 
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
-  std::string debugString(const std::vector ,
+  std::string debugString(ArrayRef ,
   const Solver::Result ) {
 auto Template = R"(
 Constraints
@@ -185,8 +185,7 @@ debugString(const BoolValue ,
 }
 
 std::string
-debugString(const std::vector ,
-const Solver::Result ,
+debugString(ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames) {
   return DebugStringGenerator(std::move(AtomNames))
   .debugString(Constraints, Result);



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


[PATCH] D119296: KCFI sanitizer

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

(Will read new updates.)

Note that release/15.x is branching soon 
(https://discourse.llvm.org/t/llvm-15-0-0-release-schedule/63495): 2022-07-26.
It seems that we can miss the branch to have more time mature the feature and 
have it for 16.0.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119296/new/

https://reviews.llvm.org/D119296

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


[PATCH] D130078: [flang][nfc] Rename `AddOtherOptions` as `ForwardOptions`

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D130078#3669072 , @awarzynski 
wrote:

> In D130078#3667188 , @MaskRay wrote:
>
>> `forwardOptions` will be better if you are renaming it anyway.
>
> I'd rather create a separate patch and update all other methods to follow 
> LLVM's style. Any idea why the style is not followed in Clang.h 
> ?

Clang is traditionally unfortunately very inconsistent in the code style 
When you add new functions, you don't necessarily follow the Clang tradition ;-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130078/new/

https://reviews.llvm.org/D130078

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


[PATCH] D119296: KCFI sanitizer

2022-07-22 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen planned changes to this revision.
samitolvanen added a comment.

Based on the recent LKML discussions about X86 retbleed mitigations 
(https://lore.kernel.org/lkml/20220716230344.239749...@linutronix.de/), we're 
going to need some changes to the code generated for X86.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119296/new/

https://reviews.llvm.org/D119296

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


[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-22 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp:10
+enum class EBool : bool { a = 1 } e3;
+enum EEmpty {};
 

erichkeane wrote:
> can you do a test on:
> 
> `enum ENeg { a = -1 }`
> ?
> 
> That should ALSO have only a single bit.
Added this test and it indeed only has one bit.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130301/new/

https://reviews.llvm.org/D130301

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


[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-22 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 446997.
shafik marked 4 inline comments as done.
shafik added a comment.

- Addressed style comments
- Changed to use initializer_list version of std::max
- Added test to cover enum with -1 as sole enumerator value


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130301/new/

https://reviews.llvm.org/D130301

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/pr12251.cpp
  compiler-rt/test/ubsan/TestCases/Misc/enum.cpp

Index: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
===
--- compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
+++ compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
@@ -1,21 +1,33 @@
-// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PLAIN
-// RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E" %s -O3 -o %t && %run %t
-// RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E : bool" %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-BOOL
+// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
 
 // FIXME: UBSan fails to add the correct instrumentation code for some reason on
 // Windows.
 // XFAIL: windows-msvc
 
-enum E { a = 1 } e;
-#undef E
+enum E { a = 1 };
+enum class EClass { a = 1 };
+enum class EBool : bool { a = 1 } e3;
+enum EEmpty {};
+enum EMinus { em = -1 };
 
 int main(int argc, char **argv) {
-  // memset(, 0xff, sizeof(e));
-  for (unsigned char *p = (unsigned char*) p != (unsigned char*)( + 1); ++p)
+  E e1 = static_cast(0x);
+  EClass e2 = static_cast(0x);
+  EEmpty e4 = static_cast(1);
+  EEmpty e5 = static_cast(2);
+  EMinus e6 = static_cast(1);
+  EMinus e7 = static_cast(2);
+
+  for (unsigned char *p = (unsigned char *) p != (unsigned char *)( + 1);
+   ++p)
 *p = 0xff;
 
-  // CHECK-PLAIN: error: load of value 4294967295, which is not a valid value for type 'enum E'
-  // FIXME: Support marshalling and display of enum class values.
-  // CHECK-BOOL: error: load of value , which is not a valid value for type 'enum E'
-  return (int)e != -1;
+  // CHECK: error: load of value 4294967295, which is not a valid value for type 'E'
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value , which is not a valid value for type 'enum EBool'
+ ((int)e3 != -1) & ((int)e4 == 1) &
+ // CHECK: error: load of value 2, which is not a valid value for type 'EEmpty'
+ ((int)e5 == 2) & ((int)e6 == 1) &
+ // CHECK: error: load of value 2, which is not a valid value for type 'EMinus'
+ ((int)e7 == 2);
 }
Index: clang/test/CodeGenCXX/pr12251.cpp
===
--- clang/test/CodeGenCXX/pr12251.cpp
+++ clang/test/CodeGenCXX/pr12251.cpp
@@ -18,14 +18,14 @@
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g1P2e1
-// CHECK: ret i32 0
+// CHECK: ret i32 %0
 
 enum e2 { e2_a = 0 };
 e2 g2(e2 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g2P2e2
-// CHECK: ret i32 0
+// CHECK: ret i32 %0
 
 enum e3 { e3_a = 16 };
 e3 g3(e3 *x) {
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -18878,14 +18878,24 @@
 const llvm::APSInt  = ECD->getInitVal();
 
 // Keep track of the size of positive and negative values.
-if (InitVal.isUnsigned() || InitVal.isNonNegative())
-  NumPositiveBits = std::max(NumPositiveBits,
- (unsigned)InitVal.getActiveBits());
-else
+if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
+  // If the enumerator is zero that should still be counted as a positive
+  // bit since we need a bit to store the value zero
+  const unsigned ActiveBits = InitVal.getActiveBits();
+  NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
+} else {
   NumNegativeBits = std::max(NumNegativeBits,
  (unsigned)InitVal.getMinSignedBits());
+}
   }
 
+  // If we have have a empty set of enumerators we still need one bit.
+  // From [dcl.enum]p8
+  // If the enumerator-list is empty, the values of the enumeration are as if
+  // the enumeration had a single enumerator with value 0
+  if (!NumPositiveBits && !NumNegativeBits)
+NumPositiveBits = 1;
+
   // Figure out the type that should be used for this enum.
   QualType BestType;
   unsigned BestWidth;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-22 Thread Med Ismail Bennani via Phabricator via cfe-commits
mib added a comment.

In D129377#3673204 , @mstorsjo wrote:

> This broke building of Clang, when it's set up by symlinking 
> `llvm-project/clang` into `llvm-project/llvm/tools`. In that case, cmake 
> configure errors out like this:
>
>   -- Configuring done 
>   CMake Error in tools/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt:
> Target "clangHandleCXX" INTERFACE_INCLUDE_DIRECTORIES property contains
> path:
>
>   
> "/home/martin/code/llvm-project/llvm/tools/clang/tools/clang-fuzzer/handle-cxx/."
>  
>   
> which is prefixed in the source directory.
>
> See e.g. 
> https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source
>  for some discussion on the issue.
>
> Can we revert this commit until this has been sorted out?

@mstorsjo I reverted Chelsea's patch in b797834748f1 
, since 
she's offline now. Do you have a link to a bot failure that would help us 
investigate the issue ?

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129377/new/

https://reviews.llvm.org/D129377

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


[PATCH] D130145: [AArch64] Simplify BTI/PAC-RET module flags

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: llvm/lib/IR/AutoUpgrade.cpp:4415-4430
-// Upgrade branch protection and return address signing module flags. The
-// module flag behavior for these fields were Error and now they are Min.
-if (ID->getString() == "branch-target-enforcement" ||
-ID->getString().startswith("sign-return-address")) {
-  if (auto *Behavior =
-  mdconst::dyn_extract_or_null(Op->getOperand(0))) {
-if (Behavior->getLimitedValue() == Module::Error) {

danielkiss wrote:
> In a full LTO build the linker will complain about the mis match between the 
> flags if one of the objects compiled with an older compiler that emitted 
> `Module:Error` for these flags.
The new approach doesnot emit a flag for 0 value, so there won't be an error 
even with old bitcode files using `Error`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130145/new/

https://reviews.llvm.org/D130145

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


[clang] d959324 - Revert "[lldb/Fuzzer] Add fuzzer for expression evaluator"

2022-07-22 Thread Med Ismail Bennani via cfe-commits

Author: Med Ismail Bennani
Date: 2022-07-22T15:24:40-07:00
New Revision: d959324e1efec12c3924c17b7d90db0b37eb84c3

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

LOG: Revert "[lldb/Fuzzer] Add fuzzer for expression evaluator"

This reverts commit b797834748f1954950880bf50fb78abedd4494e6, since it
breaks building Clang: https://reviews.llvm.org/D129377

Added: 


Modified: 
clang/cmake/modules/ProtobufMutator.cmake
clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
lldb/tools/lldb-fuzzer/CMakeLists.txt

Removed: 
lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp



diff  --git a/clang/cmake/modules/ProtobufMutator.cmake 
b/clang/cmake/modules/ProtobufMutator.cmake
index 071f11bc343de..15fe95ed6e8e9 100644
--- a/clang/cmake/modules/ProtobufMutator.cmake
+++ b/clang/cmake/modules/ProtobufMutator.cmake
@@ -1,9 +1,5 @@
 include(ExternalProject)
-
-if (NOT PBM_PREFIX)
-  set (PBM_PREFIX protobuf_mutator)
-endif()
-
+set(PBM_PREFIX protobuf_mutator)
 set(PBM_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PBM_PREFIX}/src/${PBM_PREFIX})
 set(PBM_LIB_PATH ${PBM_PATH}-build/src/libprotobuf-mutator.a)
 set(PBM_FUZZ_LIB_PATH 
${PBM_PATH}-build/src/libfuzzer/libprotobuf-mutator-libfuzzer.a)

diff  --git a/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt 
b/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
index 469b88cb7de29..6d62421d9a69a 100644
--- a/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
+++ b/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
@@ -11,5 +11,3 @@ add_clang_library(clangHandleCXX
   clangSerialization
   clangTooling
   )
-
-target_include_directories(clangHandleCXX PUBLIC .)

diff  --git a/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt 
b/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
index 45f51c9d8b54d..339959b81af0c 100644
--- a/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
+++ b/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
@@ -14,8 +14,6 @@ add_clang_library(clangLoopProtoToCXX loop_proto_to_cxx.cpp
   DEPENDS clangCXXLoopProto
   LINK_LIBS clangCXXLoopProto ${PROTOBUF_LIBRARIES}
   )
-target_include_directories(clangProtoToCXX PUBLIC .)
-target_include_directories(clangLoopProtoToCXX PUBLIC .)
 
 add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
 add_clang_executable(clang-loop-proto-to-cxx loop_proto_to_cxx_main.cpp)

diff  --git a/lldb/tools/lldb-fuzzer/CMakeLists.txt 
b/lldb/tools/lldb-fuzzer/CMakeLists.txt
index 4c081a9de53e2..867a41961c13c 100644
--- a/lldb/tools/lldb-fuzzer/CMakeLists.txt
+++ b/lldb/tools/lldb-fuzzer/CMakeLists.txt
@@ -1,4 +1,3 @@
 add_subdirectory(lldb-commandinterpreter-fuzzer)
-add_subdirectory(lldb-expression-fuzzer)
 add_subdirectory(lldb-target-fuzzer)
 add_subdirectory(utils)

diff  --git a/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt 
b/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
deleted file mode 100644
index 40606f10cc711..0
--- a/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
+++ /dev/null
@@ -1,57 +0,0 @@
-if(CLANG_ENABLE_PROTO_FUZZER)
-  set(LLVM_LINK_COMPONENTS
-Support
-)
-
-  add_llvm_fuzzer(lldb-expression-fuzzer
-EXCLUDE_FROM_ALL
-lldb-expression-fuzzer.cpp
-)
-
-  if(TARGET lldb-expression-fuzzer)
-target_include_directories(lldb-expression-fuzzer PRIVATE ..)
-find_package(Protobuf REQUIRED)
-add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI)
-include_directories(${PROTOBUF_INCLUDE_DIRS})
-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../../clang/tools/clang-fuzzer
 PRIVATE ..)
-
-set(CLANG_CMAKE_MODULE_PATH
-  ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/cmake/modules)
-
-set(CMAKE_MODULE_PATH
-  ${CMAKE_MODULE_PATH}
-  ${CLANG_CMAKE_MODULE_PATH})
-
-
-set (PBM_PREFIX lldb_protobuf_mutator)
-include(ProtobufMutator)
-include_directories(${ProtobufMutator_INCLUDE_DIRS})
-
-target_link_libraries(lldb-expression-fuzzer
-  PRIVATE
-  ${ProtobufMutator_LIBRARIES}
-  ${LLVM_LIB_FUZZING_ENGINE}
-  clangHandleCXX
-  clangCXXProto
-  clangProtoToCXX
-  liblldb
-  )
-
-add_custom_command(TARGET lldb-expression-fuzzer PRE_BUILD
-  COMMAND ${CMAKE_COMMAND} -E make_directory 
${CMAKE_BINARY_DIR}/fuzzer-artifacts/expression-artifacts
-  # Create and compile a simple C program using the command line. This is
-  # needed because LLDB's expression evaluator needs a legitmate target
-  # instead of a dummy target
-  COMMAND echo 'int main (int argc, char** argv) { return 0\; }' | clang 
-o main.out -xc -
-  )

[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-22 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

This broke building of Clang, when it's set up by symlinking 
`llvm-project/clang` into `llvm-project/llvm/tools`. In that case, cmake 
configure errors out like this:

  -- Configuring done 
  CMake Error in tools/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt:
Target "clangHandleCXX" INTERFACE_INCLUDE_DIRECTORIES property contains
path:
   
  
"/home/martin/code/llvm-project/llvm/tools/clang/tools/clang-fuzzer/handle-cxx/."
 
  
which is prefixed in the source directory.

See e.g. 
https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source
 for some discussion on the issue.

Can we revert this commit until this has been sorted out?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129377/new/

https://reviews.llvm.org/D129377

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


[PATCH] D116070: [X86] Enable ibt-seal optimization when LTO is used in Kernel

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.
Herald added subscribers: jsji, StephenFan.
Herald added a project: All.

The module flags metadata usage "Override" was wrong. I fixed it by using "Min".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116070/new/

https://reviews.llvm.org/D116070

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


[PATCH] D130398: [clang][dataflow] Add Environment::dump()

2022-07-22 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:117-120
+for (const std::string  : ConstraintsStrings) {
+  Result += S;
+  Result += '\n';
+}

I thought there's join-strings function somewhere...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130398/new/

https://reviews.llvm.org/D130398

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


[clang] 8f0c901 - [Driver] Report -Wunused-command-line-argument for unimplemented -mtune=

2022-07-22 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-07-22T15:07:28-07:00
New Revision: 8f0c901c1a172313a32bc06a1fcface76cd1220f

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

LOG: [Driver] Report -Wunused-command-line-argument for unimplemented -mtune=

Most common architectures (aarch64,riscv,s390x,x86,etc) have implemented 
-mtune=.
Don't ignore -mtune= in generic code.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 092566211ed0..33e3fe267c23 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5392,9 +5392,6 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
 
   TC.addClangTargetOptions(Args, CmdArgs, JA.getOffloadingDeviceKind());
 
-  // FIXME: Handle -mtune=.
-  (void)Args.hasArg(options::OPT_mtune_EQ);
-
   if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
 StringRef CM = A->getValue();
 if (CM == "small" || CM == "kernel" || CM == "medium" || CM == "large" ||



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


[PATCH] D130398: [clang][dataflow] Add Environment::dump()

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 446992.
gribozavr added a comment.

Reverted more changes broken out to separate revisions


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130398/new/

https://reviews.llvm.org/D130398

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -188,6 +188,31 @@
   StrEq(Expected));
 }
 
+TEST(ConstraintSetDebugStringTest, Empty) {
+  llvm::DenseSet Constraints;
+  EXPECT_THAT(debugString(Constraints), StrEq(""));
+}
+
+TEST(ConstraintSetDebugStringTest, Simple) {
+  ConstraintContext Ctx;
+  llvm::DenseSet Constraints;
+  auto X = cast(Ctx.atom());
+  auto Y = cast(Ctx.atom());
+  Constraints.insert(Ctx.disj(X, Y));
+  Constraints.insert(Ctx.disj(X, Ctx.neg(Y)));
+
+  auto Expected = R"((or
+X
+(not
+Y))
+(or
+X
+Y)
+)";
+  EXPECT_THAT(debugString(Constraints, {{X, "X"}, {Y, "Y"}}),
+  StrEq(Expected));
+}
+
 Solver::Result CheckSAT(std::vector Constraints) {
   llvm::DenseSet ConstraintsSet(Constraints.begin(),
  Constraints.end());
Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -17,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/Solver.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -80,6 +81,22 @@
 return formatv("{0}", fmt_pad(S, Indent, 0));
   }
 
+  std::string debugString(const llvm::DenseSet ) {
+std::vector ConstraintsStrings;
+ConstraintsStrings.reserve(Constraints.size());
+for (BoolValue *Constraint : Constraints) {
+  ConstraintsStrings.push_back(debugString(*Constraint));
+}
+llvm::sort(ConstraintsStrings);
+
+std::string Result;
+for (const std::string  : ConstraintsStrings) {
+  Result += S;
+  Result += '\n';
+}
+return Result;
+  }
+
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
   std::string debugString(const std::vector ,
@@ -129,7 +146,7 @@
   debugString(AtomAssignment.second));
   Lines.push_back(Line);
 }
-llvm::sort(Lines.begin(), Lines.end());
+llvm::sort(Lines);
 
 return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
   }
@@ -184,6 +201,12 @@
   return DebugStringGenerator(std::move(AtomNames)).debugString(B);
 }
 
+std::string
+debugString(const llvm::DenseSet ,
+llvm::DenseMap AtomNames) {
+  return DebugStringGenerator(std::move(AtomNames)).debugString(Constraints);
+}
+
 std::string
 debugString(const std::vector ,
 const Solver::Result ,
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -15,10 +15,8 @@
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
-#include "clang/AST/ExprCXX.h"
 #include "clang/AST/Type.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
-#include "clang/Analysis/FlowSensitive/StorageLocation.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
@@ -512,5 +510,9 @@
   return DACtx->flowConditionImplies(*FlowConditionToken, Val);
 }
 
+void Environment::dump() const {
+  DACtx->dumpFlowCondition(*FlowConditionToken);
+}
+
 } // namespace dataflow
 } // namespace clang
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -14,7 +14,9 @@
 
 #include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
 #include "clang/AST/ExprCXX.h"
+#include 

[clang] 1f02ba4 - [Driver][SystemZ] Simplify -mtune

2022-07-22 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-07-22T14:54:27-07:00
New Revision: 1f02ba4843a519606a3bdfd7e7a289f3d8c1c14b

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

LOG: [Driver][SystemZ] Simplify -mtune

Similar to AArch64.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a0b6422e51e2..092566211ed0 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2209,19 +2209,12 @@ void Clang::AddSparcTargetArgs(const ArgList ,
 
 void Clang::AddSystemZTargetArgs(const ArgList ,
  ArgStringList ) const {
-  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
-StringRef Name = A->getValue();
-
-std::string TuneCPU;
-if (Name == "native")
-  TuneCPU = std::string(llvm::sys::getHostCPUName());
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
 else
-  TuneCPU = std::string(Name);
-
-if (!TuneCPU.empty()) {
-  CmdArgs.push_back("-tune-cpu");
-  CmdArgs.push_back(Args.MakeArgString(TuneCPU));
-}
+  CmdArgs.push_back(A->getValue());
   }
 
   bool HasBackchain =



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


[PATCH] D130399: [clang][dataflow] Expose stringification functions for SAT solver enums

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 446991.
gribozavr added a comment.

Fix the build


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130399/new/

https://reviews.llvm.org/D130399

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp

Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -30,6 +30,30 @@
 using llvm::fmt_pad;
 using llvm::formatv;
 
+/// Returns a string representation of a boolean assignment to true or false.
+std::string debugString(Solver::Result::Assignment Assignment) {
+  switch (Assignment) {
+  case Solver::Result::Assignment::AssignedFalse:
+return "False";
+  case Solver::Result::Assignment::AssignedTrue:
+return "True";
+  }
+  llvm_unreachable("Booleans can only be assigned true/false");
+}
+
+/// Returns a string representation of the result status of a SAT check.
+std::string debugString(Solver::Result::Status Status) {
+  switch (Status) {
+  case Solver::Result::Status::Satisfiable:
+return "Satisfiable";
+  case Solver::Result::Status::Unsatisfiable:
+return "Unsatisfiable";
+  case Solver::Result::Status::TimedOut:
+return "TimedOut";
+  }
+  llvm_unreachable("Unhandled SAT check result status");
+}
+
 namespace {
 
 class DebugStringGenerator {
@@ -101,7 +125,7 @@
   ConstraintsStrings.push_back(debugString(*Constraint));
 }
 
-auto StatusString = debugString(Result.getStatus());
+auto StatusString = clang::dataflow::debugString(Result.getStatus());
 auto Solution = Result.getSolution();
 auto SolutionString = Solution ? "\n" + debugString(Solution.value()) : "";
 
@@ -126,7 +150,7 @@
   auto Line = formatv("{0} = {1}",
   fmt_align(getAtomName(AtomAssignment.first),
 AlignStyle::Left, MaxNameLength),
-  debugString(AtomAssignment.second));
+  clang::dataflow::debugString(AtomAssignment.second));
   Lines.push_back(Line);
 }
 llvm::sort(Lines.begin(), Lines.end());
@@ -134,30 +158,6 @@
 return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
   }
 
-  /// Returns a string representation of a boolean assignment to true or false.
-  std::string debugString(Solver::Result::Assignment Assignment) {
-switch (Assignment) {
-case Solver::Result::Assignment::AssignedFalse:
-  return "False";
-case Solver::Result::Assignment::AssignedTrue:
-  return "True";
-}
-llvm_unreachable("Booleans can only be assigned true/false");
-  }
-
-  /// Returns a string representation of the result status of a SAT check.
-  std::string debugString(Solver::Result::Status Status) {
-switch (Status) {
-case Solver::Result::Status::Satisfiable:
-  return "Satisfiable";
-case Solver::Result::Status::Unsatisfiable:
-  return "Unsatisfiable";
-case Solver::Result::Status::TimedOut:
-  return "TimedOut";
-}
-llvm_unreachable("Unhandled SAT check result status");
-  }
-
   /// Returns the name assigned to `Atom`, either user-specified or created by
   /// default rules (B0, B1, ...).
   std::string getAtomName(const AtomicBoolValue *Atom) {
Index: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
===
--- clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -23,6 +23,13 @@
 
 namespace clang {
 namespace dataflow {
+
+/// Returns a string representation of a boolean assignment to true or false.
+std::string debugString(Solver::Result::Assignment Assignment);
+
+/// Returns a string representation of the result status of a SAT check.
+std::string debugString(Solver::Result::Status Status);
+
 /// Returns a string representation for the boolean value `B`.
 ///
 /// Atomic booleans appearing in the boolean value `B` are assigned to labels
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a4df2da - [Driver][RISCV] Simplify -mtune

2022-07-22 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-07-22T14:51:07-07:00
New Revision: a4df2da173ba3907d652d24c9b4d8bb7d2ff447c

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

LOG: [Driver][RISCV] Simplify -mtune

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 4cf4bc817144..a0b6422e51e2 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2181,18 +2181,11 @@ void Clang::AddRISCVTargetArgs(const ArgList ,
 
   SetRISCVSmallDataLimit(getToolChain(), Args, CmdArgs);
 
-  std::string TuneCPU;
-
-  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
-StringRef Name = A->getValue();
-
-Name = llvm::RISCV::resolveTuneCPUAlias(Name, Triple.isArch64Bit());
-TuneCPU = std::string(Name);
-  }
-
-  if (!TuneCPU.empty()) {
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+StringRef Name =
+llvm::RISCV::resolveTuneCPUAlias(A->getValue(), Triple.isArch64Bit());
 CmdArgs.push_back("-tune-cpu");
-CmdArgs.push_back(Args.MakeArgString(TuneCPU));
+CmdArgs.push_back(Name.data());
   }
 }
 



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


[PATCH] D130400: [clang][dataflow] ArrayRef'ize debugString()

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
gribozavr requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130400

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp


Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -82,7 +82,7 @@
 
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
-  std::string debugString(const std::vector ,
+  std::string debugString(ArrayRef ,
   const Solver::Result ) {
 auto Template = R"(
 Constraints
@@ -185,8 +185,7 @@
 }
 
 std::string
-debugString(const std::vector ,
-const Solver::Result ,
+debugString(ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames) {
   return DebugStringGenerator(std::move(AtomNames))
   .debugString(Constraints, Result);
Index: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
===
--- clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -46,7 +46,7 @@
 ///
 ///   Names assigned to atoms should not be repeated in `AtomNames`.
 std::string debugString(
-const std::vector , const Solver::Result ,
+ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames = {{}});
 inline std::string debugString(
 const llvm::DenseSet ,


Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -82,7 +82,7 @@
 
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
-  std::string debugString(const std::vector ,
+  std::string debugString(ArrayRef ,
   const Solver::Result ) {
 auto Template = R"(
 Constraints
@@ -185,8 +185,7 @@
 }
 
 std::string
-debugString(const std::vector ,
-const Solver::Result ,
+debugString(ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames) {
   return DebugStringGenerator(std::move(AtomNames))
   .debugString(Constraints, Result);
Index: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
===
--- clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -46,7 +46,7 @@
 ///
 ///   Names assigned to atoms should not be repeated in `AtomNames`.
 std::string debugString(
-const std::vector , const Solver::Result ,
+ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames = {{}});
 inline std::string debugString(
 const llvm::DenseSet ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130398: [clang][dataflow] Add Environment::dump()

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 446988.
gribozavr added a comment.

Moved some changes to a different revision


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130398/new/

https://reviews.llvm.org/D130398

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -188,6 +188,31 @@
   StrEq(Expected));
 }
 
+TEST(ConstraintSetDebugStringTest, Empty) {
+  llvm::DenseSet Constraints;
+  EXPECT_THAT(debugString(Constraints), StrEq(""));
+}
+
+TEST(ConstraintSetDebugStringTest, Simple) {
+  ConstraintContext Ctx;
+  llvm::DenseSet Constraints;
+  auto X = cast(Ctx.atom());
+  auto Y = cast(Ctx.atom());
+  Constraints.insert(Ctx.disj(X, Y));
+  Constraints.insert(Ctx.disj(X, Ctx.neg(Y)));
+
+  auto Expected = R"((or
+X
+(not
+Y))
+(or
+X
+Y)
+)";
+  EXPECT_THAT(debugString(Constraints, {{X, "X"}, {Y, "Y"}}),
+  StrEq(Expected));
+}
+
 Solver::Result CheckSAT(std::vector Constraints) {
   llvm::DenseSet ConstraintsSet(Constraints.begin(),
  Constraints.end());
Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -17,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/Solver.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -80,9 +81,25 @@
 return formatv("{0}", fmt_pad(S, Indent, 0));
   }
 
+  std::string debugString(const llvm::DenseSet ) {
+std::vector ConstraintsStrings;
+ConstraintsStrings.reserve(Constraints.size());
+for (BoolValue *Constraint : Constraints) {
+  ConstraintsStrings.push_back(debugString(*Constraint));
+}
+llvm::sort(ConstraintsStrings);
+
+std::string Result;
+for (const std::string  : ConstraintsStrings) {
+  Result += S;
+  Result += '\n';
+}
+return Result;
+  }
+
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
-  std::string debugString(const std::vector ,
+  std::string debugString(ArrayRef Constraints,
   const Solver::Result ) {
 auto Template = R"(
 Constraints
@@ -101,7 +118,7 @@
   ConstraintsStrings.push_back(debugString(*Constraint));
 }
 
-auto StatusString = debugString(Result.getStatus());
+auto StatusString = clang::dataflow::debugString(Result.getStatus());
 auto Solution = Result.getSolution();
 auto SolutionString = Solution ? "\n" + debugString(Solution.value()) : "";
 
@@ -126,10 +143,10 @@
   auto Line = formatv("{0} = {1}",
   fmt_align(getAtomName(AtomAssignment.first),
 AlignStyle::Left, MaxNameLength),
-  debugString(AtomAssignment.second));
+  clang::dataflow::debugString(AtomAssignment.second));
   Lines.push_back(Line);
 }
-llvm::sort(Lines.begin(), Lines.end());
+llvm::sort(Lines);
 
 return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
   }
@@ -185,8 +202,13 @@
 }
 
 std::string
-debugString(const std::vector ,
-const Solver::Result ,
+debugString(const llvm::DenseSet ,
+llvm::DenseMap AtomNames) {
+  return DebugStringGenerator(std::move(AtomNames)).debugString(Constraints);
+}
+
+std::string
+debugString(ArrayRef Constraints, const Solver::Result ,
 llvm::DenseMap AtomNames) {
   return DebugStringGenerator(std::move(AtomNames))
   .debugString(Constraints, Result);
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -15,10 +15,8 @@
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
-#include "clang/AST/ExprCXX.h"
 #include "clang/AST/Type.h"
 #include 

[PATCH] D128142: [MemProf] Memprof profile matching and annotation

2022-07-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: clang/test/CodeGen/memprof.cpp:15
+// # Collect memory profile:
+// $ clang++ -fuse-ld=lld -Wl,-no-pie -Wl,--no-rosegment -gmlt \
+//  -fdebug-info-for-profiling -mno-omit-leaf-frame-pointer \

snehasish wrote:
> Just `-no-pie` is better (details: https://reviews.llvm.org/rG103b28902fd6)
Fixed, here and elsewhere



Comment at: llvm/include/llvm/ProfileData/InstrProfReader.h:333
 
+  bool hasMemoryProfile() const override {
+return (Version & VARIANT_MASK_MEMPROF) != 0;

snehasish wrote:
> The RawInstrProfReader shouldn't have the memprof mask set. We have a 
> separate  raw binary format which is independent. So this should always 
> return false. Also maybe add a comment to document the fact?
Also added an assert.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128142/new/

https://reviews.llvm.org/D128142

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


[PATCH] D128142: [MemProf] Memprof profile matching and annotation

2022-07-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 446986.
tejohnson marked 3 inline comments as done.
tejohnson added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128142/new/

https://reviews.llvm.org/D128142

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/Inputs/memprof.exe
  clang/test/CodeGen/Inputs/memprof.memprofraw
  clang/test/CodeGen/memprof.cpp
  llvm/include/llvm/Analysis/MemoryBuiltins.h
  llvm/include/llvm/ProfileData/InstrProfReader.h
  llvm/lib/Analysis/MemoryBuiltins.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Transforms/PGOProfile/Inputs/memprof.exe
  llvm/test/Transforms/PGOProfile/Inputs/memprof.memprofraw
  llvm/test/Transforms/PGOProfile/Inputs/memprof_pgo.profraw
  llvm/test/Transforms/PGOProfile/memprof.ll
  llvm/test/Transforms/PGOProfile/memprofmissingfunc.ll

Index: llvm/test/Transforms/PGOProfile/memprofmissingfunc.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/memprofmissingfunc.ll
@@ -0,0 +1,25 @@
+;; Tests that we get a missing memprof error for a function not in profile when
+;; using -pgo-warn-missing-function.
+
+;; TODO: Use text profile inputs once that is available for memprof.
+
+;; The raw profiles have been generated from the source used for the memprof.ll
+;; test (see comments at the top of that file).
+
+; RUN: llvm-profdata merge %S/Inputs/memprof.memprofraw --profiled-binary %S/Inputs/memprof.exe -o %t.memprofdata
+
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.memprofdata -pgo-warn-missing-function -S 2>&1 | FileCheck %s
+
+; CHECK: memprof record not found for function hash 10477964663628735180 _Z16funcnotinprofilev
+
+; ModuleID = 'memprofmissingfunc.cc'
+source_filename = "memprofmissingfunc.cc"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: mustprogress noinline nounwind optnone uwtable
+define dso_local void @_Z16funcnotinprofilev() {
+entry:
+  ret void
+}
+
Index: llvm/test/Transforms/PGOProfile/memprof.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/memprof.ll
@@ -0,0 +1,493 @@
+;; Tests memprof profile matching (with and without instrumentation profiles).
+
+;; TODO: Use text profile inputs once that is available for memprof.
+
+;; The input IR and raw profiles have been generated from the following source:
+;;
+;; #include 
+;; #include 
+;; #include 
+;; char *foo() {
+;;   return new char[10];
+;; }
+;; char *foo2() {
+;;   return foo();
+;; }
+;; char *bar() {
+;;   return foo2();
+;; }
+;; char *baz() {
+;;   return foo2();
+;; }
+;; char *recurse(unsigned n) {
+;;   if (!n)
+;; return foo();
+;;   return recurse(n-1);
+;; }
+;; int main(int argc, char **argv) {
+;;   // Test allocations with different combinations of stack contexts and
+;;   // coldness (based on lifetime, since they are all accessed a single time
+;;   // per byte via the memset).
+;;   char *a = new char[10];
+;;   char *b = new char[10];
+;;   char *c = foo();
+;;   char *d = foo();
+;;   char *e = bar();
+;;   char *f = baz();
+;;   memset(a, 0, 10);
+;;   memset(b, 0, 10);
+;;   memset(c, 0, 10);
+;;   memset(d, 0, 10);
+;;   memset(e, 0, 10);
+;;   memset(f, 0, 10);
+;;   // a and c have short lifetimes
+;;   delete[] a;
+;;   delete[] c;
+;;   // b, d, e, and f have long lifetimes and will be detected as cold by default.
+;;   sleep(200);
+;;   delete[] b;
+;;   delete[] d;
+;;   delete[] e;
+;;   delete[] f;
+;;   // Loop ensures the two calls to recurse have stack contexts that only differ
+;;   // in one level of recursion. Tests recursion collapsing during matching, and
+;;   // subsequent handling of identical stack contexts but differing allocation
+;;   // behavior (since the first has a very long lifetime and the second has a
+;;   // short lifetime).
+;;   for (unsigned i = 0; i < 2; i++) {
+;; char *g = recurse(i + 3);
+;; memset(g, 0, 10);
+;; if (!i)
+;;   sleep(200);
+;; delete[] g;
+;;   }
+;;   return 0;
+;; }
+;;
+;; The following commands were used to compile the source to instrumented
+;; executables and collect raw binary format profiles:
+;;
+;; # Collect memory profile:
+;; $ clang++ -fuse-ld=lld -no-pie -Wl,--no-rosegment -gmlt \
+;; 	-fdebug-info-for-profiling -mno-omit-leaf-frame-pointer \
+;;	-fno-omit-frame-pointer -fno-optimize-sibling-calls -m64 -Wl,-build-id \
+;; 	memprof.cc -o memprof.exe -fmemory-profile
+;; $ env MEMPROF_OPTIONS=log_path=stdout ./memprof.exe > memprof.memprofraw
+;;
+;; # Collect IR PGO profile:
+;; $ clang++ -fuse-ld=lld -no-pie -Wl,--no-rosegment -gmlt \
+;; 	-fdebug-info-for-profiling -mno-omit-leaf-frame-pointer \
+;;	-fno-omit-frame-pointer -fno-optimize-sibling-calls -m64 -Wl,-build-id \
+;; 	

[PATCH] D130399: [clang][dataflow] Expose stringification functions for SAT solver enums

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
gribozavr requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130399

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp


Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -30,6 +30,30 @@
 using llvm::fmt_pad;
 using llvm::formatv;
 
+/// Returns a string representation of a boolean assignment to true or false.
+std::string debugString(Solver::Result::Assignment Assignment) {
+  switch (Assignment) {
+  case Solver::Result::Assignment::AssignedFalse:
+return "False";
+  case Solver::Result::Assignment::AssignedTrue:
+return "True";
+  }
+  llvm_unreachable("Booleans can only be assigned true/false");
+}
+
+/// Returns a string representation of the result status of a SAT check.
+std::string debugString(Solver::Result::Status Status) {
+  switch (Status) {
+  case Solver::Result::Status::Satisfiable:
+return "Satisfiable";
+  case Solver::Result::Status::Unsatisfiable:
+return "Unsatisfiable";
+  case Solver::Result::Status::TimedOut:
+return "TimedOut";
+  }
+  llvm_unreachable("Unhandled SAT check result status");
+}
+
 namespace {
 
 class DebugStringGenerator {
@@ -134,30 +158,6 @@
 return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
   }
 
-  /// Returns a string representation of a boolean assignment to true or false.
-  std::string debugString(Solver::Result::Assignment Assignment) {
-switch (Assignment) {
-case Solver::Result::Assignment::AssignedFalse:
-  return "False";
-case Solver::Result::Assignment::AssignedTrue:
-  return "True";
-}
-llvm_unreachable("Booleans can only be assigned true/false");
-  }
-
-  /// Returns a string representation of the result status of a SAT check.
-  std::string debugString(Solver::Result::Status Status) {
-switch (Status) {
-case Solver::Result::Status::Satisfiable:
-  return "Satisfiable";
-case Solver::Result::Status::Unsatisfiable:
-  return "Unsatisfiable";
-case Solver::Result::Status::TimedOut:
-  return "TimedOut";
-}
-llvm_unreachable("Unhandled SAT check result status");
-  }
-
   /// Returns the name assigned to `Atom`, either user-specified or created by
   /// default rules (B0, B1, ...).
   std::string getAtomName(const AtomicBoolValue *Atom) {
Index: clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
===
--- clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
+++ clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
@@ -23,6 +23,13 @@
 
 namespace clang {
 namespace dataflow {
+
+/// Returns a string representation of a boolean assignment to true or false.
+std::string debugString(Solver::Result::Assignment Assignment);
+
+/// Returns a string representation of the result status of a SAT check.
+std::string debugString(Solver::Result::Status Status);
+
 /// Returns a string representation for the boolean value `B`.
 ///
 /// Atomic booleans appearing in the boolean value `B` are assigned to labels


Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -30,6 +30,30 @@
 using llvm::fmt_pad;
 using llvm::formatv;
 
+/// Returns a string representation of a boolean assignment to true or false.
+std::string debugString(Solver::Result::Assignment Assignment) {
+  switch (Assignment) {
+  case Solver::Result::Assignment::AssignedFalse:
+return "False";
+  case Solver::Result::Assignment::AssignedTrue:
+return "True";
+  }
+  llvm_unreachable("Booleans can only be assigned true/false");
+}
+
+/// Returns a string representation of the result status of a SAT check.
+std::string debugString(Solver::Result::Status Status) {
+  switch (Status) {
+  case Solver::Result::Status::Satisfiable:
+return "Satisfiable";
+  case Solver::Result::Status::Unsatisfiable:
+return "Unsatisfiable";
+  case Solver::Result::Status::TimedOut:
+return "TimedOut";
+  }
+  llvm_unreachable("Unhandled SAT check result status");
+}
+
 namespace {
 
 class DebugStringGenerator {
@@ -134,30 +158,6 @@
 return formatv("{0:$[\n]}", llvm::make_range(Lines.begin(), Lines.end()));
   }
 
-  /// Returns a string representation of a boolean assignment to true or false.
-  std::string debugString(Solver::Result::Assignment Assignment) {
-switch (Assignment) {
-case 

[clang] 12fbd2d - [Driver][test] Clean up and improve some -mtune tests

2022-07-22 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-07-22T14:37:58-07:00
New Revision: 12fbd2d377e396ad61bce56d71c98a1eb1bebfa9

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

LOG: [Driver][test] Clean up and improve some -mtune tests

Note: we should test CHECK-NOT: "-tune-cpu" instead of CHECK-NOT: "-tune-cpu" 
"generic"

Added: 


Modified: 
clang/test/Driver/aarch64-march.c
clang/test/Driver/aarch64-mtune.c
clang/test/Driver/x86-mtune.c

Removed: 




diff  --git a/clang/test/Driver/aarch64-march.c 
b/clang/test/Driver/aarch64-march.c
index 3a278be6ce976..59be5836b39dc 100644
--- a/clang/test/Driver/aarch64-march.c
+++ b/clang/test/Driver/aarch64-march.c
@@ -1,31 +1,31 @@
-// RUN: %clang -target aarch64 -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-V8A %s
-// RUN: %clang -target aarch64 -march=armv8-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-V8A %s
+// RUN: %clang --target=aarch64 -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-V8A %s
+// RUN: %clang --target=aarch64 -march=armv8-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-V8A %s
 // GENERIC-V8A: "-cc1"{{.*}} "-triple" "aarch64{{(--)?}}"{{.*}} "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v8a"
 
-// RUN: %clang -target aarch64 -march=armv8-r -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-V8R %s
+// RUN: %clang --target=aarch64 -march=armv8-r -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERIC-V8R %s
 // GENERIC-V8R: "-cc1"{{.*}} "-triple" "aarch64{{(--)?}}"{{.*}} "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v8r"
 
-// RUN: %clang -target aarch64 -march=armv9a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV9A %s
-// RUN: %clang -target aarch64 -march=armv9-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV9A %s
-// RUN: %clang -target aarch64 -mlittle-endian -march=armv9a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV9A %s
-// RUN: %clang -target aarch64 -mlittle-endian -march=armv9-a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV9A %s
-// RUN: %clang -target aarch64_be -mlittle-endian -march=armv9a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV9A %s
-// RUN: %clang -target aarch64_be -mlittle-endian -march=armv9-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV9A %s
+// RUN: %clang --target=aarch64 -march=armv9a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV9A %s
+// RUN: %clang --target=aarch64 -march=armv9-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV9A %s
+// RUN: %clang --target=aarch64 -mlittle-endian -march=armv9a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV9A %s
+// RUN: %clang --target=aarch64 -mlittle-endian -march=armv9-a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV9A %s
+// RUN: %clang --target=aarch64_be -mlittle-endian -march=armv9a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV9A %s
+// RUN: %clang --target=aarch64_be -mlittle-endian -march=armv9-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV9A %s
 // GENERICV9A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+neon" "-target-feature" "+v9a" "-target-feature" "+sve" 
"-target-feature" "+sve2"
 
-// RUN: %clang -target aarch64_be -march=armv9a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV9A-BE %s
-// RUN: %clang -target aarch64_be -march=armv9-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV9A-BE %s
-// RUN: %clang -target aarch64 -mbig-endian -march=armv9a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV9A-BE %s
-// RUN: %clang -target aarch64 -mbig-endian -march=armv9-a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV9A-BE %s
-// RUN: %clang -target aarch64_be -mbig-endian -march=armv9a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV9A-BE %s
-// RUN: %clang -target aarch64_be -mbig-endian -march=armv9-a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV9A-BE %s
+// RUN: %clang --target=aarch64_be -march=armv9a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV9A-BE %s
+// RUN: %clang --target=aarch64_be -march=armv9-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV9A-BE %s
+// RUN: %clang --target=aarch64 -mbig-endian -march=armv9a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV9A-BE %s
+// RUN: %clang --target=aarch64 -mbig-endian -march=armv9-a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV9A-BE %s
+// RUN: %clang --target=aarch64_be -mbig-endian -march=armv9a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV9A-BE %s
+// RUN: %clang --target=aarch64_be -mbig-endian -march=armv9-a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV9A-BE %s
 // GENERICV9A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+neon" "-target-feature" "+v9a" "-target-feature" 
"+sve" "-target-feature" "+sve2"
 
 // == 

[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D130306#3671852 , @samestep wrote:

> In D130306#3670259 , @xazax.hun 
> wrote:
>
>> 
>
> Yes, we considered a summary-based approach, but we decided not to use it 
> because (as you mentioned) it would be much more difficult to implement, 
> especially for callees with nontrivial CFGs, which would result in a 
> nontrivial flow condition instead of just `Value`s in the `Environment`.

Thanks! I think this is a major design decision, and I'd love to see a 
discussion about the alternatives considered before jumping to an 
implementation. Specifically, I'd like to know if summaries are out of scope or 
something you would consider in the future. Knowing this is useful because this 
can influence how the code should be reviewed. E.g., if you plan to have 
multiple ways to do context sensitive analysis in the future, we should make 
sure that the current code will not lock us in in the inline substitution 
approach. If summaries are not planned at all, this is not a concern.

> Could you elaborate on what specific scalability problems you are concerned 
> about?

The Clang Static Analyzer is using this approach and it was a long way to iron 
out all the corner cases where the performance was bad. It has many cuts 
including maximum number of visits for a basic block, maximum call stack depth, 
not inlining functions after a certain size threshold and so on. Basically, it 
took some time to get the right performance and precision. But overall, the 
inline substitution approach will never scale to large call stacks/long calling 
contexts. On the other hand, a summary-based approach can potentially find bugs 
across a really large number of function calls with reasonable costs. Mainly 
because the same function is not reanalyzed for every context.

> To clarify, the main reason we want context-sensitive analysis is to allow us 
> to simplify our definitions of some models, such as the `optional` checker 
> model. The goal is to provide the analysis a mock implementation of an 
> `optional` type, and then use context-sensitive analysis (probably just one 
> or two layers deep) to model the constructors and methods.

Thanks, this is also useful context!

>> Some other related questions:
>>
>> - Why call noop analysis?
>
> The alternative in this case would be to use the same analysis for the callee 
> that is already being used for the caller? I agree that would be nicer to 
> serve a broader category of use cases. I didn't do that in this patch for a 
> couple reasons:
>
> 1. In the short term, that would require threading more information through 
> to the builtin transfer function, while this patch was meant to just be a 
> minimum viable product.
> 2. In the longer term, we probably don't need that for our specific goals 
> (just modeling simple fields of mock classes) mentioned above.

I see. This was not clear to me from the description of the patch notes. It 
seems to me that the goal here is to simplify the modeling of certain types, 
not general context-sensitive analysis. I reviewed this patch with the wrong 
idea in mind. If that is the goal, the current approach makes sense. But I 
think the comments should make clear what the intended use case and the 
limitations of the current approach is.

>> - Currently, it looks like the framework assumes functions that cannot be 
>> inlined are not doing anything. This is an unsound assumption, and I wonder 
>> if we should change that before we try to settle on the best values for the 
>> tunable parameters.
>
> Agreed, this assumption is unsound. However, the framework already makes many 
> other unsound assumptions in a similar spirit, so this one doesn't 
> immediately strike me as one that needs to change. I'll defer to people with 
> more context.

The main reason I wanted to call this out because it increasingly seems to be 
whenever a decision needs to be made, the framework is getting less and less 
sound. Basically, many design decisions here are very similar to what the Clang 
Static Analyzer is doing. Basically, since Clang already has an analysis 
framework for unsound analysis, I wanted to avoid you reinventing the wheel and 
doing something similar to CSA instead of providing something new for the use 
cases that cannot be covered by the CSA.

>> - I think the environment currently is not really up to context-sensitive 
>> evaluation. Consider a recursive function:
>
> Yes, I mentioned this in the patch description and in a comment in the 
> `pushCall` implementation: we plan to do this by modifying the set of fields 
> in the `DataflowAnalysisContext` class. I plan to do this in my next patch, 
> once this one is landed.

Oh, my bad! I somehow blinked and totally skipped that comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130306/new/

https://reviews.llvm.org/D130306


[PATCH] D130398: [clang][dataflow] Add Environment::dump()

2022-07-22 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: martong, tschuett, mgrang, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
gribozavr requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Start by dumping the flow condition.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130398

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -188,6 +188,31 @@
   StrEq(Expected));
 }
 
+TEST(ConstraintSetDebugStringTest, Empty) {
+  llvm::DenseSet Constraints;
+  EXPECT_THAT(debugString(Constraints), StrEq(""));
+}
+
+TEST(ConstraintSetDebugStringTest, Simple) {
+  ConstraintContext Ctx;
+  llvm::DenseSet Constraints;
+  auto X = cast(Ctx.atom());
+  auto Y = cast(Ctx.atom());
+  Constraints.insert(Ctx.disj(X, Y));
+  Constraints.insert(Ctx.disj(X, Ctx.neg(Y)));
+
+  auto Expected = R"((or
+X
+(not
+Y))
+(or
+X
+Y)
+)";
+  EXPECT_THAT(debugString(Constraints, {{X, "X"}, {Y, "Y"}}),
+  StrEq(Expected));
+}
+
 Solver::Result CheckSAT(std::vector Constraints) {
   llvm::DenseSet ConstraintsSet(Constraints.begin(),
  Constraints.end());
Index: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
===
--- clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -17,6 +17,7 @@
 #include "clang/Analysis/FlowSensitive/Solver.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -30,6 +31,30 @@
 using llvm::fmt_pad;
 using llvm::formatv;
 
+/// Returns a string representation of a boolean assignment to true or false.
+std::string debugString(Solver::Result::Assignment Assignment) {
+  switch (Assignment) {
+  case Solver::Result::Assignment::AssignedFalse:
+return "False";
+  case Solver::Result::Assignment::AssignedTrue:
+return "True";
+  }
+  llvm_unreachable("Booleans can only be assigned true/false");
+}
+
+/// Returns a string representation of the result status of a SAT check.
+std::string debugString(Solver::Result::Status Status) {
+  switch (Status) {
+  case Solver::Result::Status::Satisfiable:
+return "Satisfiable";
+  case Solver::Result::Status::Unsatisfiable:
+return "Unsatisfiable";
+  case Solver::Result::Status::TimedOut:
+return "TimedOut";
+  }
+  llvm_unreachable("Unhandled SAT check result status");
+}
+
 namespace {
 
 class DebugStringGenerator {
@@ -80,9 +105,25 @@
 return formatv("{0}", fmt_pad(S, Indent, 0));
   }
 
+  std::string debugString(const llvm::DenseSet ) {
+std::vector ConstraintsStrings;
+ConstraintsStrings.reserve(Constraints.size());
+for (BoolValue *Constraint : Constraints) {
+  ConstraintsStrings.push_back(debugString(*Constraint));
+}
+llvm::sort(ConstraintsStrings);
+
+std::string Result;
+for (const std::string  : ConstraintsStrings) {
+  Result += S;
+  Result += '\n';
+}
+return Result;
+  }
+
   /// Returns a string representation of a set of boolean `Constraints` and the
   /// `Result` of satisfiability checking on the `Constraints`.
-  std::string debugString(const std::vector ,
+  std::string debugString(ArrayRef Constraints,
   const Solver::Result ) {
 auto Template = R"(
 Constraints
@@ -101,7 +142,7 @@
   ConstraintsStrings.push_back(debugString(*Constraint));
 }
 
-auto StatusString = debugString(Result.getStatus());
+auto StatusString = clang::dataflow::debugString(Result.getStatus());
 auto Solution = Result.getSolution();
 auto SolutionString = Solution ? "\n" + debugString(Solution.value()) : "";
 
@@ -126,38 +167,14 @@
   auto Line = formatv("{0} = {1}",
   fmt_align(getAtomName(AtomAssignment.first),
 AlignStyle::Left, MaxNameLength),
-  debugString(AtomAssignment.second));
+  clang::dataflow::debugString(AtomAssignment.second));
   Lines.push_back(Line);
 }
-llvm::sort(Lines.begin(), 

[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-22 Thread Chelsea Cassanova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb797834748f1: [lldb/Fuzzer] Add fuzzer for expression 
evaluator (authored by cassanova).

Changed prior to commit:
  https://reviews.llvm.org/D129377?vs=444761=446982#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129377/new/

https://reviews.llvm.org/D129377

Files:
  clang/cmake/modules/ProtobufMutator.cmake
  clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
  clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  lldb/tools/lldb-fuzzer/CMakeLists.txt
  lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
  lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp

Index: lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
===
--- /dev/null
+++ lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
@@ -0,0 +1,73 @@
+//===-- lldb-expression-fuzzer.cpp ---===//
+//
+// 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
+//
+//===-===//
+//
+// \file
+// This file is a fuzzer for LLDB's expression evaluator. It uses protobufs
+// and the libprotobuf-mutator to create valid C-like inputs for the
+// expression evaluator.
+//
+//===-===//
+
+#include 
+
+#include "cxx_proto.pb.h"
+#include "handle_cxx.h"
+#include "lldb/API/SBBreakpoint.h"
+#include "lldb/API/SBDebugger.h"
+#include "lldb/API/SBError.h"
+#include "lldb/API/SBLaunchInfo.h"
+#include "lldb/API/SBProcess.h"
+#include "lldb/API/SBTarget.h"
+#include "proto_to_cxx.h"
+#include "src/libfuzzer/libfuzzer_macro.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+
+using namespace lldb;
+using namespace llvm;
+using namespace clang_fuzzer;
+
+char **originalargv;
+
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
+  SBDebugger::Initialize();
+
+  // The path for a simple compiled program is needed to create a
+  // target for the debugger and that path is passed in through argv
+  originalargv = *argv;
+  return 0;
+}
+
+DEFINE_BINARY_PROTO_FUZZER(const clang_fuzzer::Function ) {
+  auto input_string = clang_fuzzer::FunctionToString(input);
+
+  // Get the second argument from argv and strip the '--' from it.
+  // This will be used as the path for the object file to create a target from
+  std::string raw_path = originalargv[2];
+  StringRef obj_path = raw_path.erase(0, 2);
+
+  // Create a debugger and a target
+  SBDebugger debugger = SBDebugger::Create(false);
+  SBTarget target = debugger.CreateTarget(obj_path.str().c_str());
+
+  // Create a breakpoint on the only line in the program
+  SBBreakpoint breakpoint = target.BreakpointCreateByLocation(obj_path.str().c_str(), 1);
+
+  // Create launch info and error for launching the process
+  SBLaunchInfo launch_info = target.GetLaunchInfo();
+  SBError error;
+
+  // Launch the process and evaluate the fuzzer's input data
+  // as an expression
+  SBProcess process = target.Launch(launch_info, error);
+  target.EvaluateExpression(input_string.c_str());
+
+  debugger.DeleteTarget(target);
+  SBDebugger::Destroy(debugger);
+  SBModule::GarbageCollectAllocatedModules();
+}
Index: lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
===
--- /dev/null
+++ lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
@@ -0,0 +1,57 @@
+if(CLANG_ENABLE_PROTO_FUZZER)
+  set(LLVM_LINK_COMPONENTS
+Support
+)
+
+  add_llvm_fuzzer(lldb-expression-fuzzer
+EXCLUDE_FROM_ALL
+lldb-expression-fuzzer.cpp
+)
+
+  if(TARGET lldb-expression-fuzzer)
+target_include_directories(lldb-expression-fuzzer PRIVATE ..)
+find_package(Protobuf REQUIRED)
+add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI)
+include_directories(${PROTOBUF_INCLUDE_DIRS})
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../../clang/tools/clang-fuzzer PRIVATE ..)
+
+set(CLANG_CMAKE_MODULE_PATH
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/cmake/modules)
+
+set(CMAKE_MODULE_PATH
+  ${CMAKE_MODULE_PATH}
+  ${CLANG_CMAKE_MODULE_PATH})
+
+
+set (PBM_PREFIX lldb_protobuf_mutator)
+include(ProtobufMutator)
+include_directories(${ProtobufMutator_INCLUDE_DIRS})
+
+target_link_libraries(lldb-expression-fuzzer
+  PRIVATE
+  ${ProtobufMutator_LIBRARIES}
+  ${LLVM_LIB_FUZZING_ENGINE}
+  clangHandleCXX
+  clangCXXProto
+  clangProtoToCXX
+  liblldb
+  )
+
+add_custom_command(TARGET lldb-expression-fuzzer PRE_BUILD
+  COMMAND ${CMAKE_COMMAND} -E make_directory 

[clang] b797834 - [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-22 Thread Chelsea Cassanova via cfe-commits

Author: Chelsea Cassanova
Date: 2022-07-22T17:32:00-04:00
New Revision: b797834748f1954950880bf50fb78abedd4494e6

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

LOG: [lldb/Fuzzer] Add fuzzer for expression evaluator

This commit adds a fuzzer for LLDB's expression evaluator.
The fuzzer takes a different approach than the current fuzzers
present, and uses an approach that is currently being used for
clang fuzzers.

Instead of fuzzing the evaluator with randomly mutated
characters, protobufs are used to generate a subset of C++. This
is then converted to valid C++ code and sent to the expression
evaluator. In addition, libprotobuf_mutator is used to mutate
the fuzzer's inputs from valid C++ code to valid C++ code, rather
than mutating from valid code to total nonsense.

Differential revision: https://reviews.llvm.org/D129377

Added: 
lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp

Modified: 
clang/cmake/modules/ProtobufMutator.cmake
clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
lldb/tools/lldb-fuzzer/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/ProtobufMutator.cmake 
b/clang/cmake/modules/ProtobufMutator.cmake
index 15fe95ed6e8e9..071f11bc343de 100644
--- a/clang/cmake/modules/ProtobufMutator.cmake
+++ b/clang/cmake/modules/ProtobufMutator.cmake
@@ -1,5 +1,9 @@
 include(ExternalProject)
-set(PBM_PREFIX protobuf_mutator)
+
+if (NOT PBM_PREFIX)
+  set (PBM_PREFIX protobuf_mutator)
+endif()
+
 set(PBM_PATH ${CMAKE_CURRENT_BINARY_DIR}/${PBM_PREFIX}/src/${PBM_PREFIX})
 set(PBM_LIB_PATH ${PBM_PATH}-build/src/libprotobuf-mutator.a)
 set(PBM_FUZZ_LIB_PATH 
${PBM_PATH}-build/src/libfuzzer/libprotobuf-mutator-libfuzzer.a)

diff  --git a/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt 
b/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
index 6d62421d9a69a..469b88cb7de29 100644
--- a/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
+++ b/clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
@@ -11,3 +11,5 @@ add_clang_library(clangHandleCXX
   clangSerialization
   clangTooling
   )
+
+target_include_directories(clangHandleCXX PUBLIC .)

diff  --git a/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt 
b/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
index 339959b81af0c..45f51c9d8b54d 100644
--- a/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
+++ b/clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
@@ -14,6 +14,8 @@ add_clang_library(clangLoopProtoToCXX loop_proto_to_cxx.cpp
   DEPENDS clangCXXLoopProto
   LINK_LIBS clangCXXLoopProto ${PROTOBUF_LIBRARIES}
   )
+target_include_directories(clangProtoToCXX PUBLIC .)
+target_include_directories(clangLoopProtoToCXX PUBLIC .)
 
 add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
 add_clang_executable(clang-loop-proto-to-cxx loop_proto_to_cxx_main.cpp)

diff  --git a/lldb/tools/lldb-fuzzer/CMakeLists.txt 
b/lldb/tools/lldb-fuzzer/CMakeLists.txt
index 867a41961c13c..4c081a9de53e2 100644
--- a/lldb/tools/lldb-fuzzer/CMakeLists.txt
+++ b/lldb/tools/lldb-fuzzer/CMakeLists.txt
@@ -1,3 +1,4 @@
 add_subdirectory(lldb-commandinterpreter-fuzzer)
+add_subdirectory(lldb-expression-fuzzer)
 add_subdirectory(lldb-target-fuzzer)
 add_subdirectory(utils)

diff  --git a/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt 
b/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
new file mode 100644
index 0..40606f10cc711
--- /dev/null
+++ b/lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
@@ -0,0 +1,57 @@
+if(CLANG_ENABLE_PROTO_FUZZER)
+  set(LLVM_LINK_COMPONENTS
+Support
+)
+
+  add_llvm_fuzzer(lldb-expression-fuzzer
+EXCLUDE_FROM_ALL
+lldb-expression-fuzzer.cpp
+)
+
+  if(TARGET lldb-expression-fuzzer)
+target_include_directories(lldb-expression-fuzzer PRIVATE ..)
+find_package(Protobuf REQUIRED)
+add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI)
+include_directories(${PROTOBUF_INCLUDE_DIRS})
+
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../../clang/tools/clang-fuzzer
 PRIVATE ..)
+
+set(CLANG_CMAKE_MODULE_PATH
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/cmake/modules)
+
+set(CMAKE_MODULE_PATH
+  ${CMAKE_MODULE_PATH}
+  ${CLANG_CMAKE_MODULE_PATH})
+
+
+set (PBM_PREFIX lldb_protobuf_mutator)
+include(ProtobufMutator)
+include_directories(${ProtobufMutator_INCLUDE_DIRS})
+
+target_link_libraries(lldb-expression-fuzzer
+  PRIVATE
+  ${ProtobufMutator_LIBRARIES}
+  ${LLVM_LIB_FUZZING_ENGINE}
+  clangHandleCXX
+  clangCXXProto
+  clangProtoToCXX
+  liblldb
+   

[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-07-22 Thread Danny Mösch via Phabricator via cfe-commits
SimplyDanny added a comment.

Thank you for the review! Before I push the change into main I may add an entry 
to `clang/docs/ReleaseNotes.rst`, right?

And do you agree that the test failures are unrelated to my change? It looks 
like they are all located in `libomptarget` caused by a linker error.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129973/new/

https://reviews.llvm.org/D129973

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


[PATCH] D130273: [clang][Driver] Handle SPARC -mcpu=native etc.

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/ToolChains/Arch/Sparc.cpp:121
+StringRef CPUName = A->getValue();
+
+if (CPUName == "native") {

delete blank line



Comment at: clang/lib/Driver/ToolChains/Arch/Sparc.cpp:135
+return "v9";
+  else
+return "";

The common style omits `else` here



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2226
+
+std::string TuneCPU;
+if (Name == "native")

ro wrote:
> MaskRay wrote:
> > ```
> > std::string TuneCPU(Name == "native" ? ... : ...)
> > if (!TuneCPU.empty()) {
> >   ...
> > ```
> I'm not sure about this: I tried that variant, but I don't really think it's 
> clearer than what I have now:
> ```
> std::string TuneCPU(Name == "native"
> ? std::string(llvm::sys::getHostCPUName()
> : std::string(Name)));
> ```
> My code was taken from `AddSystemZTargetArgs` directly below and it would 
> seem a bit weird if they differ in style.
OK, but I think AddSystemZTargetArgs somewhat deviates from common styles.

Since `llvm::sys::getHostCPUName()` cannot be empty, and `-mtune=` (empty 
value) should be an error (but only aarch64 seems to emit an error), I'd omit 
the `if (!TuneCPU.empty()) ` test. For aarch64, I made such a simplification: 
475e526d85003404ba521e15f8acef1b439fb910

I don't mind whether sparc emits an error for `-mtune=` or not.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130273/new/

https://reviews.llvm.org/D130273

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


[clang] 475e526 - [Driver][AArch64] Simplify -mtune

2022-07-22 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-07-22T14:19:27-07:00
New Revision: 475e526d85003404ba521e15f8acef1b439fb910

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

LOG: [Driver][AArch64] Simplify -mtune

llvm::sys::getHostCPUName()'s return value is not empty. `-mtune=` (empty value)
has caused a driver error. So we can omit `!TuneCPU.empty()` check.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3ad08ad7e11d1..4cf4bc8171442 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1923,18 +1923,11 @@ void Clang::AddAArch64TargetArgs(const ArgList ,
   AddAAPCSVolatileBitfieldArgs(Args, CmdArgs);
 
   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
-StringRef Name = A->getValue();
-
-std::string TuneCPU;
-if (Name == "native")
-  TuneCPU = std::string(llvm::sys::getHostCPUName());
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
 else
-  TuneCPU = std::string(Name);
-
-if (!TuneCPU.empty()) {
-  CmdArgs.push_back("-tune-cpu");
-  CmdArgs.push_back(Args.MakeArgString(TuneCPU));
-}
+  CmdArgs.push_back(A->getValue());
   }
 
   AddUnalignedAccessWarning(CmdArgs);



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


[PATCH] D126731: [pseudo] Eliminate dependencies from clang-pseudo-gen. NFC

2022-07-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D126731#3672666 , @vsapsai wrote:

> In D126731#3670896 , @sammccall 
> wrote:
>
>> Hmm, I also don't know.
>> The idea here is that we specifically depend only on the TokenKind enum from 
>> TokenKinds.h (which doesn't need any generated headers), not on other 
>> headers from clang/include/Basic (which might), and not on building/linking 
>> clangBasic itself.
>> In a modules world, maybe that means we need TokenKinds.h to be its own 
>> module, or a non-modular header, or something?
>
> I went with the approach of putting TokenKinds.h (and TokenKinds.def) into 
> its own module D130377 .
>
> In D126731#3670896 , @sammccall 
> wrote:
>
>> I'm also not sure on the support status of the modules build: I can't find a 
>> buildbot covering it or docs. Is this something I need to fix, or is it an 
>> experimental build like GN/Bazel?
>
> I know at least about https://green.lab.llvm.org/green/job/lldb-cmake/ 
> building with modules. I agree it's not a common configuration on buildbots 
> but it's not experimental like GN/Bazel. As for the fixing the issue, it is 
> covered by https://llvm.org/docs/DeveloperPolicy.html#quality , i.e., it is 
> the author's responsibility but the reporter is responsible for making sure 
> the author is equipped to do so (or fix themselves if they cannot help the 
> author).

Thank you! I had forgotten about the greendragon bots.
And thanks for the module fix, if it's not that simple I'm happy to re-add the 
dep while i try to work something out.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126731/new/

https://reviews.llvm.org/D126731

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


[PATCH] D130377: Move "clang/Basic/TokenKinds.h" into a separate top-level module.

2022-07-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thank you!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130377/new/

https://reviews.llvm.org/D130377

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


[PATCH] D130387: [CUDA/SPIR-V] Force passing aggregate type byval

2022-07-22 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

It's OK. If something comes up you can address it in a follow-up patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130387/new/

https://reviews.llvm.org/D130387

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


[PATCH] D130387: [CUDA/SPIR-V] Force passing aggregate type byval

2022-07-22 Thread Shangwu Yao via Phabricator via cfe-commits
shangwuyao added a comment.

In D130387#3672969 , @tra wrote:

> In D130387#3672961 , @shangwuyao 
> wrote:
>
>> Accidentally submitted early...
>
> The landed revision seems to have my comments addressed. Was there something 
> missing?

No, just want to wait a bit longer to see if someone else has comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130387/new/

https://reviews.llvm.org/D130387

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


[PATCH] D130387: [CUDA/SPIR-V] Force passing aggregate type byval

2022-07-22 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D130387#3672961 , @shangwuyao 
wrote:

> Accidentally submitted early...

The landed revision seems to have my comments addressed. Was there something 
missing?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130387/new/

https://reviews.llvm.org/D130387

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


[PATCH] D130387: [CUDA/SPIR-V] Force passing aggregate type byval

2022-07-22 Thread Shangwu Yao via Phabricator via cfe-commits
shangwuyao added a comment.

Accidentally submitted early...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130387/new/

https://reviews.llvm.org/D130387

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


[clang] 6a1ccf6 - Revert "[NFC] Add some additional features to MultiLevelTemplateArgumentList"

2022-07-22 Thread Nuno Lopes via cfe-commits

Author: Nuno Lopes
Date: 2022-07-22T21:33:22+01:00
New Revision: 6a1ccf61cdf80c793f9c699ada33af5d85263b30

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

LOG: Revert "[NFC] Add some additional features to 
MultiLevelTemplateArgumentList"

This reverts commit 0b36a62d5f3505e21692ae0abf25ef00836329e3.

It breaks the assertion build

Added: 


Modified: 
clang/include/clang/Sema/Template.h

Removed: 




diff  --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 49bcb5798..5dcde77b5dd37 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -75,8 +75,6 @@ enum class TemplateSubstitutionKind : char {
   class MultiLevelTemplateArgumentList {
 /// The template argument list at a certain template depth
 using ArgList = ArrayRef;
-using ArgListsIterator = SmallVector::iterator;
-using ConstArgListsIterator = SmallVector::const_iterator;
 
 /// The template argument lists, stored from the innermost template
 /// argument list (first) to the outermost template argument list (last).
@@ -123,12 +121,6 @@ enum class TemplateSubstitutionKind : char {
   return TemplateArgumentLists.size();
 }
 
-// Determine the number of substituted args at 'Depth'.
-unsigned getNumSubsitutedArgs(unsigned Depth) const {
-  assert(NumretainedOuterLevels <= Depth && Depth < getNumLevels());
-  return TemplateArgumentLists[getNumLevels() - Depth - 1].size();
-}
-
 unsigned getNumRetainedOuterLevels() const {
   return NumRetainedOuterLevels;
 }
@@ -166,14 +158,6 @@ enum class TemplateSubstitutionKind : char {
   return !(*this)(Depth, Index).isNull();
 }
 
-bool isAnyArgInstantiationDependent() const {
-  for (ArgList List : TemplateArgumentLists)
-for (const TemplateArgument  : List)
-  if (TA.isInstantiationDependent())
-return true;
-  return false;
-}
-
 /// Clear out a specific template argument.
 void setArgument(unsigned Depth, unsigned Index,
  TemplateArgument Arg) {
@@ -199,14 +183,6 @@ enum class TemplateSubstitutionKind : char {
   TemplateArgumentLists.push_back(Args);
 }
 
-/// Replaces the current 'innermost' level with the provided argument list.
-/// This is useful for type deduction cases where we need to get the entire
-/// list from the AST, but then add the deduced innermost list.
-void replaceInnermostTemplateArguments(ArgList Args) {
-  assert(TemplateArgumentLists.size() > 0 && "Replacing in an empty 
list?");
-  TemplateArgumentLists[0] = Args;
-}
-
 /// Add an outermost level that we are not substituting. We have no
 /// arguments at this level, and do not remove it from the depth of inner
 /// template parameters that we instantiate.
@@ -221,16 +197,6 @@ enum class TemplateSubstitutionKind : char {
 const ArgList () const {
   return TemplateArgumentLists.front();
 }
-/// Retrieve the outermost template argument list.
-const ArgList () const {
-  return TemplateArgumentLists.back();
-}
-ArgListsIterator begin() { return TemplateArgumentLists.begin(); }
-ConstArgListsIterator begin() const {
-  return TemplateArgumentLists.begin();
-}
-ArgListsIterator end() { return TemplateArgumentLists.end(); }
-ConstArgListsIterator end() const { return TemplateArgumentLists.end(); }
   };
 
   /// The context in which partial ordering of function templates occurs.



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


[PATCH] D130387: [CUDA/SPIR-V] Force passing aggregate type byval

2022-07-22 Thread Shangwu Yao via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG31d8dbd1e5b4: [CUDA/SPIR-V] Force passing aggregate type 
byval (authored by shangwuyao).

Changed prior to commit:
  https://reviews.llvm.org/D130387?vs=446934=446966#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130387/new/

https://reviews.llvm.org/D130387

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu


Index: clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
@@ -0,0 +1,25 @@
+// Tests CUDA kernel arguments get copied by value when targeting SPIR-V, even 
with
+// destructor, copy constructor or move constructor defined by user.
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only 
--offload=spirv32 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only 
--offload=spirv64 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+class GpuData {
+ public:
+  __attribute__((host)) __attribute__((device)) GpuData(int* src) {}
+  __attribute__((host)) __attribute__((device)) ~GpuData() {}
+  __attribute__((host)) __attribute__((device)) GpuData(const GpuData& other) 
{}
+  __attribute__((host)) __attribute__((device)) GpuData(GpuData&& other) {}
+};
+
+// CHECK: define
+// CHECK-SAME: spir_kernel void @_Z6kernel7GpuData(%class.GpuData* noundef 
byval(%class.GpuData) align
+
+__attribute__((global)) void kernel(GpuData output) {}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10449,6 +10449,15 @@
   LTy = llvm::PointerType::getWithSamePointeeType(PtrTy, GlobalAS);
   return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
 }
+
+// Force copying aggregate type in kernel arguments by value when
+// compiling CUDA targeting SPIR-V. This is required for the object
+// copied to be valid on the device.
+// This behavior follows the CUDA spec
+// 
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-function-argument-processing,
+// and matches the NVPTX implementation.
+if (isAggregateTypeForABI(Ty))
+  return getNaturalAlignIndirect(Ty, /* byval */ true);
   }
   return classifyArgumentType(Ty);
 }


Index: clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
@@ -0,0 +1,25 @@
+// Tests CUDA kernel arguments get copied by value when targeting SPIR-V, even with
+// destructor, copy constructor or move constructor defined by user.
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only --offload=spirv32 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only --offload=spirv64 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+class GpuData {
+ public:
+  __attribute__((host)) __attribute__((device)) GpuData(int* src) {}
+  __attribute__((host)) __attribute__((device)) ~GpuData() {}
+  __attribute__((host)) __attribute__((device)) GpuData(const GpuData& other) {}
+  __attribute__((host)) __attribute__((device)) GpuData(GpuData&& other) {}
+};
+
+// CHECK: define
+// CHECK-SAME: spir_kernel void @_Z6kernel7GpuData(%class.GpuData* noundef byval(%class.GpuData) align
+
+__attribute__((global)) void kernel(GpuData output) {}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10449,6 +10449,15 @@
   LTy = llvm::PointerType::getWithSamePointeeType(PtrTy, GlobalAS);
   return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
 }
+
+// Force copying aggregate type in kernel arguments by value when
+// compiling CUDA targeting SPIR-V. This is required for the object
+// copied to be valid on the device.
+// This behavior follows the CUDA spec
+// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-function-argument-processing,
+// and matches the NVPTX implementation.
+if (isAggregateTypeForABI(Ty))
+  return getNaturalAlignIndirect(Ty, /* byval */ true);
   }
   return classifyArgumentType(Ty);
 }

[clang] 31d8dbd - [CUDA/SPIR-V] Force passing aggregate type byval

2022-07-22 Thread Shangwu Yao via cfe-commits

Author: Shangwu Yao
Date: 2022-07-22T20:30:15Z
New Revision: 31d8dbd1e5b4ee0fd04bfeb3a64d8f9f33260905

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

LOG: [CUDA/SPIR-V] Force passing aggregate type byval

This patch forces copying aggregate type in kernel arguments by value when
compiling CUDA targeting SPIR-V. The original behavior is not passing by value
when there is any of destructor, copy constructor and move constructor defined
by user. This patch makes the behavior of SPIR-V generated from CUDA follow
the CUDA spec
(https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-function-argument-processing),
and matches the NVPTX
implementation (
https://github.com/llvm/llvm-project/blob/41958f76d8a2c47484fa176cba1de565cfe84de7/clang/lib/CodeGen/TargetInfo.cpp#L7241).

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

Added: 
clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu

Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index e8ee5533104ca..fc0952e68a667 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -10449,6 +10449,15 @@ ABIArgInfo 
SPIRVABIInfo::classifyKernelArgumentType(QualType Ty) const {
   LTy = llvm::PointerType::getWithSamePointeeType(PtrTy, GlobalAS);
   return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
 }
+
+// Force copying aggregate type in kernel arguments by value when
+// compiling CUDA targeting SPIR-V. This is required for the object
+// copied to be valid on the device.
+// This behavior follows the CUDA spec
+// 
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-function-argument-processing,
+// and matches the NVPTX implementation.
+if (isAggregateTypeForABI(Ty))
+  return getNaturalAlignIndirect(Ty, /* byval */ true);
   }
   return classifyArgumentType(Ty);
 }

diff  --git a/clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu 
b/clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
new file mode 100644
index 0..bceca4d4ee5d6
--- /dev/null
+++ b/clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
@@ -0,0 +1,25 @@
+// Tests CUDA kernel arguments get copied by value when targeting SPIR-V, even 
with
+// destructor, copy constructor or move constructor defined by user.
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only 
--offload=spirv32 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only 
--offload=spirv64 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+class GpuData {
+ public:
+  __attribute__((host)) __attribute__((device)) GpuData(int* src) {}
+  __attribute__((host)) __attribute__((device)) ~GpuData() {}
+  __attribute__((host)) __attribute__((device)) GpuData(const GpuData& other) 
{}
+  __attribute__((host)) __attribute__((device)) GpuData(GpuData&& other) {}
+};
+
+// CHECK: define
+// CHECK-SAME: spir_kernel void @_Z6kernel7GpuData(%class.GpuData* noundef 
byval(%class.GpuData) align
+
+__attribute__((global)) void kernel(GpuData output) {}



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


[PATCH] D130362: Fix one stray `{LLVM -> CLANG}_TOOLS_INSTALL_DIR`

2022-07-22 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D130362#3672886 , @mstorsjo wrote:

> I don't find any existing instances of `CLANG_TOOLS_INSTALL_DIR` anywhere in 
> the current monorepo - that doesn't seem right?

(I looked in a slightly outdated working dir that I hadn't updated in a couple 
days - sorry for the noise!)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130362/new/

https://reviews.llvm.org/D130362

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


[PATCH] D130387: [CUDA/SPIR-V] Force passing aggregate type byval

2022-07-22 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM with a couple of nits.




Comment at: clang/lib/CodeGen/TargetInfo.cpp:10450
+
+if (isAggregateTypeForABI(Ty)) {
+  return getNaturalAlignIndirect(Ty, /* byval */ true);

I would add a comment that this is a CUDA-specific behavior with the pointer to 
the relevant CUDA doc explaining what's going on.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10450
+
+if (isAggregateTypeForABI(Ty)) {
+  return getNaturalAlignIndirect(Ty, /* byval */ true);

tra wrote:
> I would add a comment that this is a CUDA-specific behavior with the pointer 
> to the relevant CUDA doc explaining what's going on.
Style nit: LLVM does not use braces for single-statement body. 
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130387/new/

https://reviews.llvm.org/D130387

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


[PATCH] D130362: Fix one stray `{LLVM -> CLANG}_TOOLS_INSTALL_DIR`

2022-07-22 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130362/new/

https://reviews.llvm.org/D130362

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


[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-22 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 446958.
samestep added a comment.

Appease -Wmissing-field-initializers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130306/new/

https://reviews.llvm.org/D130306

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Transfer.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -39,14 +39,14 @@
 
 template 
 void runDataflow(llvm::StringRef Code, Matcher Match,
-  LangStandard::Kind Std = LangStandard::lang_cxx17,
-  bool ApplyBuiltinTransfer = true,
-  llvm::StringRef TargetFun = "target") {
+ DataflowAnalysisOptions Options,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ llvm::StringRef TargetFun = "target") {
   ASSERT_THAT_ERROR(
   test::checkDataflow(
   Code, TargetFun,
-  [ApplyBuiltinTransfer](ASTContext , Environment &) {
-return NoopAnalysis(C, ApplyBuiltinTransfer);
+  [Options](ASTContext , Environment &) {
+return NoopAnalysis(C, Options);
   },
   [](
   llvm::ArrayRef<
@@ -54,12 +54,19 @@
   Results,
   ASTContext ) { Match(Results, ASTCtx); },
   {"-fsyntax-only", "-fno-delayed-template-parsing",
-"-std=" +
-std::string(
-LangStandard::getLangStandardForKind(Std).getName())}),
+   "-std=" + std::string(
+ LangStandard::getLangStandardForKind(Std).getName())}),
   llvm::Succeeded());
 }
 
+template 
+void runDataflow(llvm::StringRef Code, Matcher Match,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ bool ApplyBuiltinTransfer = true,
+ llvm::StringRef TargetFun = "target") {
+  runDataflow(Code, Match, {ApplyBuiltinTransfer, {}}, Std, TargetFun);
+}
+
 TEST(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) {
   std::string Code = R"(
 void target() {
@@ -3862,4 +3869,95 @@
   });
 }
 
+TEST(TransferTest, ContextSensitiveOptionDisabled) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = true; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment  = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto  =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/false}});
+}
+
+TEST(TransferTest, ContextSensitiveSetTrue) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = true; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment  = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto  =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveSetFalse) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = false; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+   

[PATCH] D130362: Fix one stray `{LLVM -> CLANG}_TOOLS_INSTALL_DIR`

2022-07-22 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

I don't find any existing instances of `CLANG_TOOLS_INSTALL_DIR` anywhere in 
the current monorepo - that doesn't seem right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130362/new/

https://reviews.llvm.org/D130362

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


[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-22 Thread Sam Estep via Phabricator via cfe-commits
samestep added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h:64
   TypeErasedDataflowAnalysis(bool ApplyBuiltinTransfer)
   : Options({ApplyBuiltinTransfer}) {}
 

li.zhe.hua wrote:
> Nit: `-Wmissing-field-initializers` is apparently enabled, and starts warning 
> on this.
Ah thanks, will fix.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:42
 void runDataflow(llvm::StringRef Code, Matcher Match,
-  LangStandard::Kind Std = LangStandard::lang_cxx17,
-  bool ApplyBuiltinTransfer = true,
-  llvm::StringRef TargetFun = "target") {
+ DataflowAnalysisOptions Options,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,

li.zhe.hua wrote:
> For the purposes of the test, there's really only 3 states:
> 
>   # No built-in transfer
>   # Built-in transfer, no context-sensitive
>   # Built-in transfer, with context-sensitive
> 
> It may be more readable for tests to have a 3-state enum, that `runDataFlow` 
> will then use to produce the corresponding `DataflowAnalysisOptions`. As is, 
> a snippet like
> 
> ```
>   {/*.ApplyBuiltinTransfer=*/true,
>/*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/false}});
> ```
> 
> is rough to read. Good enum names with good comments would probably make this 
> much better. WDYT?
I agree that there are only 3 states, but I also think that conceptually this 
really is a multi-layered thing; either we apply the built-in transfer or not, 
and then if we do apply the builtin transfer, there's some set of options we 
pass to it. Thus, it doesn't seem right to just collapse it into a flat enum; 
I'm not sure though.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:67
+ llvm::StringRef TargetFun = "target") {
+  runDataflow(Code, Match, {ApplyBuiltinTransfer}, Std, TargetFun);
+}

li.zhe.hua wrote:
> Nit: `-Wmissing-field-initializers` is apparently enabled, and starts warning 
> on this.
Same here; thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130306/new/

https://reviews.llvm.org/D130306

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


[PATCH] D130394: [clang][CodeGen] Factor out Swift ABI hooks

2022-07-22 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 446953.
barannikov88 added a comment.

Reword commit message.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130394/new/

https://reviews.llvm.org/D130394

Files:
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/SwiftCallingConv.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h

Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -38,6 +38,7 @@
 class CallArgList;
 class CodeGenFunction;
 class CGBlockInfo;
+class SwiftABIInfo;
 
 /// TargetCodeGenInfo - This class organizes various target-specific
 /// codegeneration issues, like target-specific attributes, builtins and so
@@ -45,6 +46,12 @@
 class TargetCodeGenInfo {
   std::unique_ptr Info;
 
+protected:
+  // Target hooks supporting Swift calling conventions. The target must
+  // initialize this field if it claims to support these calling conventions
+  // by returning true from TargetInfo::checkCallingConvention for them.
+  std::unique_ptr SwiftInfo;
+
 public:
   TargetCodeGenInfo(std::unique_ptr Info);
   virtual ~TargetCodeGenInfo();
@@ -52,6 +59,9 @@
   /// getABIInfo() - Returns ABI info helper for the target.
   const ABIInfo () const { return *Info; }
 
+  /// Returns Swift ABI info helper for the target.
+  const SwiftABIInfo () const { return *SwiftInfo; }
+
   /// setTargetAttributes - Provides a convenient hook to handle extra
   /// target-specific attributes for the given global.
   virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -23,7 +23,6 @@
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
-#include "clang/CodeGen/SwiftCallingConv.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -117,7 +116,9 @@
   return false;
 }
 
-ABIInfo::~ABIInfo() {}
+ABIInfo::~ABIInfo() = default;
+
+SwiftABIInfo::~SwiftABIInfo() = default;
 
 /// Does the given lowering require more than the given number of
 /// registers when expanded?
@@ -151,12 +152,16 @@
   return (intCount + fpCount > maxAllRegisters);
 }
 
-bool SwiftABIInfo::isLegalVectorTypeForSwift(CharUnits vectorSize,
- llvm::Type *eltTy,
- unsigned numElts) const {
+bool SwiftABIInfo::shouldPassIndirectly(ArrayRef ComponentTys,
+bool AsReturnValue) const {
+  return occupiesMoreThan(CGT, ComponentTys, /*total=*/4);
+}
+
+bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
+ unsigned NumElts) const {
   // The default implementation of this assumes that the target guarantees
   // 128-bit SIMD support but nothing more.
-  return (vectorSize.getQuantity() > 8 && vectorSize.getQuantity() <= 16);
+  return (VectorSize.getQuantity() > 8 && VectorSize.getQuantity() <= 16);
 }
 
 static CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT,
@@ -814,7 +819,7 @@
 // This is a very simple ABI that relies a lot on DefaultABIInfo.
 //===--===//
 
-class WebAssemblyABIInfo final : public SwiftABIInfo {
+class WebAssemblyABIInfo final : public ABIInfo {
 public:
   enum ABIKind {
 MVP = 0,
@@ -827,7 +832,7 @@
 
 public:
   explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes , ABIKind Kind)
-  : SwiftABIInfo(CGT), defaultInfo(CGT), Kind(Kind) {}
+  : ABIInfo(CGT), defaultInfo(CGT), Kind(Kind) {}
 
 private:
   ABIArgInfo classifyReturnType(QualType RetTy) const;
@@ -845,22 +850,16 @@
 
   Address EmitVAArg(CodeGenFunction , Address VAListAddr,
 QualType Ty) const override;
-
-  bool shouldPassIndirectlyForSwift(ArrayRef scalars,
-bool asReturnValue) const override {
-return occupiesMoreThan(CGT, scalars, /*total*/ 4);
-  }
-
-  bool isSwiftErrorInRegister() const override {
-return false;
-  }
 };
 
 class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
 public:
   explicit WebAssemblyTargetCodeGenInfo(CodeGen::CodeGenTypes ,
 WebAssemblyABIInfo::ABIKind K)
-  : TargetCodeGenInfo(std::make_unique(CGT, K)) {}
+  : TargetCodeGenInfo(std::make_unique(CGT, K)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule ) const override {
@@ -1136,7 +1135,7 @@
 };
 
 /// X86_32ABIInfo - The 

[clang] 0b36a62 - [NFC] Add some additional features to MultiLevelTemplateArgumentList

2022-07-22 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-07-22T13:05:42-07:00
New Revision: 0b36a62d5f3505e21692ae0abf25ef00836329e3

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

LOG: [NFC] Add some additional features to MultiLevelTemplateArgumentList

These are useful when dealing with multi-depth instantiation in deferred
concepts, so this is split off of that patch.

Added: 


Modified: 
clang/include/clang/Sema/Template.h

Removed: 




diff  --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 5dcde77b5dd3..49bcb579 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -75,6 +75,8 @@ enum class TemplateSubstitutionKind : char {
   class MultiLevelTemplateArgumentList {
 /// The template argument list at a certain template depth
 using ArgList = ArrayRef;
+using ArgListsIterator = SmallVector::iterator;
+using ConstArgListsIterator = SmallVector::const_iterator;
 
 /// The template argument lists, stored from the innermost template
 /// argument list (first) to the outermost template argument list (last).
@@ -121,6 +123,12 @@ enum class TemplateSubstitutionKind : char {
   return TemplateArgumentLists.size();
 }
 
+// Determine the number of substituted args at 'Depth'.
+unsigned getNumSubsitutedArgs(unsigned Depth) const {
+  assert(NumretainedOuterLevels <= Depth && Depth < getNumLevels());
+  return TemplateArgumentLists[getNumLevels() - Depth - 1].size();
+}
+
 unsigned getNumRetainedOuterLevels() const {
   return NumRetainedOuterLevels;
 }
@@ -158,6 +166,14 @@ enum class TemplateSubstitutionKind : char {
   return !(*this)(Depth, Index).isNull();
 }
 
+bool isAnyArgInstantiationDependent() const {
+  for (ArgList List : TemplateArgumentLists)
+for (const TemplateArgument  : List)
+  if (TA.isInstantiationDependent())
+return true;
+  return false;
+}
+
 /// Clear out a specific template argument.
 void setArgument(unsigned Depth, unsigned Index,
  TemplateArgument Arg) {
@@ -183,6 +199,14 @@ enum class TemplateSubstitutionKind : char {
   TemplateArgumentLists.push_back(Args);
 }
 
+/// Replaces the current 'innermost' level with the provided argument list.
+/// This is useful for type deduction cases where we need to get the entire
+/// list from the AST, but then add the deduced innermost list.
+void replaceInnermostTemplateArguments(ArgList Args) {
+  assert(TemplateArgumentLists.size() > 0 && "Replacing in an empty 
list?");
+  TemplateArgumentLists[0] = Args;
+}
+
 /// Add an outermost level that we are not substituting. We have no
 /// arguments at this level, and do not remove it from the depth of inner
 /// template parameters that we instantiate.
@@ -197,6 +221,16 @@ enum class TemplateSubstitutionKind : char {
 const ArgList () const {
   return TemplateArgumentLists.front();
 }
+/// Retrieve the outermost template argument list.
+const ArgList () const {
+  return TemplateArgumentLists.back();
+}
+ArgListsIterator begin() { return TemplateArgumentLists.begin(); }
+ConstArgListsIterator begin() const {
+  return TemplateArgumentLists.begin();
+}
+ArgListsIterator end() { return TemplateArgumentLists.end(); }
+ConstArgListsIterator end() const { return TemplateArgumentLists.end(); }
   };
 
   /// The context in which partial ordering of function templates occurs.



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


[PATCH] D130394: [clang][CodeGen] Factor out Swift ABI hooks

2022-07-22 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added a subscriber: dschuff.
Herald added a project: All.
barannikov88 requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

Swift calling conventions stands out in the way that they are lowered in
mostly target-independent manner, with very few customization points.
As such, swift-related methods of ABIInfo do not reference the rest of
ABIInfo and vice versa.
This change follows interface segregation principle; it factors out
swift-related stuff into separate class -- SwiftABIInfo -- which
targets must implement if they support Swift calling conventions.

Almost all targets implemented `shouldPassIndirectly` the same way. This
de-facto default implementation has been moved into the base class.

`isSwiftErrorInRegister` used to be virtual, now it is not. It didn't
accept any arguments which could have an effect on the returned value.
This is now a static property of the target ABI.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130394

Files:
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/SwiftCallingConv.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h

Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -38,6 +38,7 @@
 class CallArgList;
 class CodeGenFunction;
 class CGBlockInfo;
+class SwiftABIInfo;
 
 /// TargetCodeGenInfo - This class organizes various target-specific
 /// codegeneration issues, like target-specific attributes, builtins and so
@@ -45,6 +46,12 @@
 class TargetCodeGenInfo {
   std::unique_ptr Info;
 
+protected:
+  // Target hooks supporting Swift calling conventions. The target must
+  // initialize this field if it claims to support these calling conventions
+  // by returning true from TargetInfo::checkCallingConvention for them.
+  std::unique_ptr SwiftInfo;
+
 public:
   TargetCodeGenInfo(std::unique_ptr Info);
   virtual ~TargetCodeGenInfo();
@@ -52,6 +59,9 @@
   /// getABIInfo() - Returns ABI info helper for the target.
   const ABIInfo () const { return *Info; }
 
+  /// Returns Swift ABI info helper for the target.
+  const SwiftABIInfo () const { return *SwiftInfo; }
+
   /// setTargetAttributes - Provides a convenient hook to handle extra
   /// target-specific attributes for the given global.
   virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -23,7 +23,6 @@
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
-#include "clang/CodeGen/SwiftCallingConv.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -117,7 +116,9 @@
   return false;
 }
 
-ABIInfo::~ABIInfo() {}
+ABIInfo::~ABIInfo() = default;
+
+SwiftABIInfo::~SwiftABIInfo() = default;
 
 /// Does the given lowering require more than the given number of
 /// registers when expanded?
@@ -151,12 +152,16 @@
   return (intCount + fpCount > maxAllRegisters);
 }
 
-bool SwiftABIInfo::isLegalVectorTypeForSwift(CharUnits vectorSize,
- llvm::Type *eltTy,
- unsigned numElts) const {
+bool SwiftABIInfo::shouldPassIndirectly(ArrayRef ComponentTys,
+bool AsReturnValue) const {
+  return occupiesMoreThan(CGT, ComponentTys, /*total=*/4);
+}
+
+bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
+ unsigned NumElts) const {
   // The default implementation of this assumes that the target guarantees
   // 128-bit SIMD support but nothing more.
-  return (vectorSize.getQuantity() > 8 && vectorSize.getQuantity() <= 16);
+  return (VectorSize.getQuantity() > 8 && VectorSize.getQuantity() <= 16);
 }
 
 static CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT,
@@ -814,7 +819,7 @@
 // This is a very simple ABI that relies a lot on DefaultABIInfo.
 //===--===//
 
-class WebAssemblyABIInfo final : public SwiftABIInfo {
+class WebAssemblyABIInfo final : public ABIInfo {
 public:
   enum ABIKind {
 MVP = 0,
@@ -827,7 +832,7 @@
 
 public:
   explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes , ABIKind Kind)
-  : SwiftABIInfo(CGT), defaultInfo(CGT), Kind(Kind) {}
+  : ABIInfo(CGT), defaultInfo(CGT), Kind(Kind) {}
 
 private:
   ABIArgInfo classifyReturnType(QualType RetTy) const;
@@ -845,22 +850,16 @@
 
   Address EmitVAArg(CodeGenFunction , Address VAListAddr,
 QualType Ty) const override;
-
-  bool shouldPassIndirectlyForSwift(ArrayRef 

[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-22 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h:64
   TypeErasedDataflowAnalysis(bool ApplyBuiltinTransfer)
   : Options({ApplyBuiltinTransfer}) {}
 

Nit: `-Wmissing-field-initializers` is apparently enabled, and starts warning 
on this.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:42
 void runDataflow(llvm::StringRef Code, Matcher Match,
-  LangStandard::Kind Std = LangStandard::lang_cxx17,
-  bool ApplyBuiltinTransfer = true,
-  llvm::StringRef TargetFun = "target") {
+ DataflowAnalysisOptions Options,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,

For the purposes of the test, there's really only 3 states:

  # No built-in transfer
  # Built-in transfer, no context-sensitive
  # Built-in transfer, with context-sensitive

It may be more readable for tests to have a 3-state enum, that `runDataFlow` 
will then use to produce the corresponding `DataflowAnalysisOptions`. As is, a 
snippet like

```
  {/*.ApplyBuiltinTransfer=*/true,
   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/false}});
```

is rough to read. Good enum names with good comments would probably make this 
much better. WDYT?



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:67
+ llvm::StringRef TargetFun = "target") {
+  runDataflow(Code, Match, {ApplyBuiltinTransfer}, Std, TargetFun);
+}

Nit: `-Wmissing-field-initializers` is apparently enabled, and starts warning 
on this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130306/new/

https://reviews.llvm.org/D130306

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


[clang] 70c62f4 - [NFC] give getParentFunctionOrMethod a 'Lexical' parameter

2022-07-22 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-07-22T12:52:26-07:00
New Revision: 70c62f4cadbec132c4ab5f939648d10ca6338b15

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

LOG: [NFC] give getParentFunctionOrMethod a 'Lexical' parameter

Split up from the deferred concepts implementation, this function is
useful for determining the containing function of a different function.
However, in some cases it is valuable to instead get the lexical parent.
This adds a parameter to the existing function to allow a 'Lexical'
parameter to instead select the lexical parent.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/AST/DeclBase.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 52fe8dd6b1e5..d1193161fd75 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -920,10 +920,12 @@ class alignas(8) Decl {
 
   /// If this decl is defined inside a function/method/block it returns
   /// the corresponding DeclContext, otherwise it returns null.
-  const DeclContext *getParentFunctionOrMethod() const;
-  DeclContext *getParentFunctionOrMethod() {
-return const_cast(
-const_cast(this)->getParentFunctionOrMethod());
+  const DeclContext *
+  getParentFunctionOrMethod(bool LexicalParent = false) const;
+  DeclContext *getParentFunctionOrMethod(bool LexicalParent = false) {
+return const_cast(
+const_cast(this)->getParentFunctionOrMethod(
+LexicalParent));
   }
 
   /// Retrieves the "canonical" declaration of the given declaration.

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 13dd6da3f24f..d12330de1500 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -283,8 +283,9 @@ unsigned Decl::getTemplateDepth() const {
   return cast(DC)->getTemplateDepth();
 }
 
-const DeclContext *Decl::getParentFunctionOrMethod() const {
-  for (const DeclContext *DC = getDeclContext();
+const DeclContext *Decl::getParentFunctionOrMethod(bool LexicalParent) const {
+  for (const DeclContext *DC = LexicalParent ? getLexicalDeclContext()
+ : getDeclContext();
DC && !DC->isTranslationUnit() && !DC->isNamespace();
DC = DC->getParent())
 if (DC->isFunctionOrMethod())



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


[clang] 3ff86f9 - [NFC] Start saving InstantiatedFromDecl in non-template functions

2022-07-22 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-07-22T12:37:14-07:00
New Revision: 3ff86f961094306d1a3f219a44614e9cfd1dbd6b

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

LOG: [NFC] Start saving InstantiatedFromDecl in non-template functions

In cases where a non-template function is defined inside a function
template, we don't have information about the original uninstantiated
version.  In the case of concepts instantiation, we will need the
ability to get back to the original template.  This patch splits a piece
of the deferred concepts instantaition patch off to accomplish the
storage of this, with minor runtime overhead, and zero additional
storage.

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 66fab94b45b8..fb87a75a1241 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1890,7 +1890,10 @@ class FunctionDecl : public DeclaratorDecl,
 TK_FunctionTemplateSpecialization,
 // A function template specialization that hasn't yet been resolved to a
 // particular specialized function template.
-TK_DependentFunctionTemplateSpecialization
+TK_DependentFunctionTemplateSpecialization,
+// A non-template function which is in a dependent scope.
+TK_DependentNonTemplate
+
   };
 
   /// Stashed information about a defaulted function definition whose body has
@@ -1939,20 +1942,21 @@ class FunctionDecl : public DeclaratorDecl,
   /// The template or declaration that this declaration
   /// describes or was instantiated from, respectively.
   ///
-  /// For non-templates, this value will be NULL. For function
-  /// declarations that describe a function template, this will be a
-  /// pointer to a FunctionTemplateDecl. For member functions
-  /// of class template specializations, this will be a 
MemberSpecializationInfo
+  /// For non-templates this value will be NULL, unless this declaration was
+  /// declared directly inside of a function template, in which case it will
+  /// have a pointer to a FunctionDecl, stored in the NamedDecl. For function
+  /// declarations that describe a function template, this will be a pointer to
+  /// a FunctionTemplateDecl, stored in the NamedDecl. For member functions of
+  /// class template specializations, this will be a MemberSpecializationInfo
   /// pointer containing information about the specialization.
   /// For function template specializations, this will be a
   /// FunctionTemplateSpecializationInfo, which contains information about
   /// the template being specialized and the template arguments involved in
   /// that specialization.
-  llvm::PointerUnion
-TemplateOrSpecialization;
+  TemplateOrSpecialization;
 
   /// Provides source/type location info for the declaration name embedded in
   /// the DeclaratorDecl base class.
@@ -2695,6 +2699,13 @@ class FunctionDecl : public DeclaratorDecl,
 setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
   }
 
+  /// Specify that this function declaration was instantiated from a
+  /// FunctionDecl FD. This is only used if this is a function declaration
+  /// declared locally inside of a function template.
+  void setInstantiatedFromDecl(FunctionDecl *FD);
+
+  FunctionDecl *getInstantiatedFromDecl() const;
+
   /// Retrieves the function template that is described by this
   /// function declaration.
   ///

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 73c3f02e67a8..f7e7b73d1218 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -3109,6 +3109,11 @@ Error ASTNodeImporter::ImportTemplateInformation(
   case FunctionDecl::TK_FunctionTemplate:
 return Error::success();
 
+  case FunctionDecl::TK_DependentNonTemplate:
+if (Expected InstFDOrErr =
+import(FromFD->getInstantiatedFromDecl()))
+  ToFD->setInstantiatedFromDecl(*InstFDOrErr);
+return Error::success();
   case FunctionDecl::TK_MemberSpecialization: {
 TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind();
 

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5e5101203e6c..f88a2e3fa268 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3732,8 +3732,13 @@ const IdentifierInfo 
*FunctionDecl::getLiteralIdentifier() const {
 FunctionDecl::TemplatedKind FunctionDecl::getTemplatedKind() const {
   if (TemplateOrSpecialization.isNull())
 return TK_NonTemplate;
-  if 

[PATCH] D129873: [clang-offload-bundler] Library-ize ClangOffloadBundler

2022-07-22 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j updated this revision to Diff 446946.
lamb-j added a comment.

Fixing header typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129873/new/

https://reviews.llvm.org/D129873

Files:
  clang/include/clang/Driver/OffloadBundler.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/CMakeLists.txt
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/CMakeLists.txt
===
--- clang/tools/clang-offload-bundler/CMakeLists.txt
+++ clang/tools/clang-offload-bundler/CMakeLists.txt
@@ -2,15 +2,16 @@
 
 add_clang_tool(clang-offload-bundler
   ClangOffloadBundler.cpp
-  
+
   DEPENDS
   intrinsics_gen
   )
 
 set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
   clangBasic
+  clangDriver
   )
-  
+
 add_dependencies(clang clang-offload-bundler)
 
 clang_target_link_libraries(clang-offload-bundler
Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -7,15 +7,14 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements a stand-alone clang-offload-bundler tool using the
+/// OffloadBundler API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -55,38 +54,45 @@
 
 using namespace llvm;
 using namespace llvm::object;
+using namespace clang;
 
-static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+static void PrintVersion(raw_ostream ) {
+  OS << clang::getClangToolFullVersion("clang-offload-bundler") << '\n';
+}
+
+int main(int argc, const char **argv) {
+
+  cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
 
-// Mark all our options with this category, everything else (except for -version
-// and -help) will be hidden.
-static cl::OptionCategory
+  // Mark all our options with this category, everything else (except for
+  // -version and -help) will be hidden.
+  cl::OptionCategory
 ClangOffloadBundlerCategory("clang-offload-bundler options");
-static cl::list
+  cl::list
 InputFileNames("input",
cl::desc("Input file."
 " Can be specified multiple times "
 "for multiple input files."),
cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 InputFileNamesDeprecatedOpt("inputs", cl::CommaSeparated,
 cl::desc("[,...] (deprecated)"),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 OutputFileNames("output",
 cl::desc("Output file."
  " Can be specified multiple times "
  "for multiple output files."),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 OutputFileNamesDeprecatedOpt("outputs", cl::CommaSeparated,
  cl::desc("[,...] (deprecated)"),
  cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 TargetNames("targets", cl::CommaSeparated,
 cl::desc("[-,...]"),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::opt
+  cl::opt
 FilesType("type", cl::Required,
   cl::desc("Type of the files to be bundled/unbundled.\n"
"Current supported types are:\n"
@@ -102,1265 +108,34 @@
"  gch - precompiled-header\n"
"  ast - clang AST file"),
   cl::cat(ClangOffloadBundlerCategory));
-static cl::opt
+  cl::opt
 Unbundle("unbundle",
  cl::desc("Unbundle bundled file into several output files.\n"),
  cl::init(false), cl::cat(ClangOffloadBundlerCategory));
-
-static cl::opt
+  cl::opt
 ListBundleIDs("list", cl::desc("List bundle IDs in the bundled file.\n"),
   cl::init(false), cl::cat(ClangOffloadBundlerCategory));
-
-static cl::opt PrintExternalCommands(
+  cl::opt PrintExternalCommands(
 "###",
 cl::desc("Print any external commands that are to be executed "
  "instead of actually executing them - for testing purposes.\n"),
  

[PATCH] D129873: [clang-offload-bundler] Library-ize ClangOffloadBundler

2022-07-22 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j updated this revision to Diff 446945.
lamb-j added a comment.

Switching pointers to references, adding namespace comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129873/new/

https://reviews.llvm.org/D129873

Files:
  clang/include/clang/Driver/OffloadBundler.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/CMakeLists.txt
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/CMakeLists.txt
===
--- clang/tools/clang-offload-bundler/CMakeLists.txt
+++ clang/tools/clang-offload-bundler/CMakeLists.txt
@@ -2,15 +2,16 @@
 
 add_clang_tool(clang-offload-bundler
   ClangOffloadBundler.cpp
-  
+
   DEPENDS
   intrinsics_gen
   )
 
 set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
   clangBasic
+  clangDriver
   )
-  
+
 add_dependencies(clang clang-offload-bundler)
 
 clang_target_link_libraries(clang-offload-bundler
Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -7,15 +7,14 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements a stand-alone clang-offload-bundler tool using the
+/// OffloadBundler API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -55,38 +54,45 @@
 
 using namespace llvm;
 using namespace llvm::object;
+using namespace clang;
 
-static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+static void PrintVersion(raw_ostream ) {
+  OS << clang::getClangToolFullVersion("clang-offload-bundler") << '\n';
+}
+
+int main(int argc, const char **argv) {
+
+  cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
 
-// Mark all our options with this category, everything else (except for -version
-// and -help) will be hidden.
-static cl::OptionCategory
+  // Mark all our options with this category, everything else (except for
+  // -version and -help) will be hidden.
+  cl::OptionCategory
 ClangOffloadBundlerCategory("clang-offload-bundler options");
-static cl::list
+  cl::list
 InputFileNames("input",
cl::desc("Input file."
 " Can be specified multiple times "
 "for multiple input files."),
cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 InputFileNamesDeprecatedOpt("inputs", cl::CommaSeparated,
 cl::desc("[,...] (deprecated)"),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 OutputFileNames("output",
 cl::desc("Output file."
  " Can be specified multiple times "
  "for multiple output files."),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 OutputFileNamesDeprecatedOpt("outputs", cl::CommaSeparated,
  cl::desc("[,...] (deprecated)"),
  cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 TargetNames("targets", cl::CommaSeparated,
 cl::desc("[-,...]"),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::opt
+  cl::opt
 FilesType("type", cl::Required,
   cl::desc("Type of the files to be bundled/unbundled.\n"
"Current supported types are:\n"
@@ -102,1265 +108,34 @@
"  gch - precompiled-header\n"
"  ast - clang AST file"),
   cl::cat(ClangOffloadBundlerCategory));
-static cl::opt
+  cl::opt
 Unbundle("unbundle",
  cl::desc("Unbundle bundled file into several output files.\n"),
  cl::init(false), cl::cat(ClangOffloadBundlerCategory));
-
-static cl::opt
+  cl::opt
 ListBundleIDs("list", cl::desc("List bundle IDs in the bundled file.\n"),
   cl::init(false), cl::cat(ClangOffloadBundlerCategory));
-
-static cl::opt PrintExternalCommands(
+  cl::opt PrintExternalCommands(
 "###",
 cl::desc("Print any external commands that are to be executed "
  "instead of actually 

[PATCH] D129881: [C] Strengthen -Wint-conversion to default to an error

2022-07-22 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7068aa98412a: Strengthen -Wint-conversion to default to an 
error (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129881/new/

https://reviews.llvm.org/D129881

Files:
  clang-tools-extra/test/clang-tidy/checkers/bugprone/no-escape.m
  clang-tools-extra/test/clang-tidy/checkers/performance/no-int-to-ptr.c
  clang/bindings/python/tests/cindex/test_diagnostics.py
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/test/Analysis/ObjCProperties.m
  clang/test/Analysis/bsd-string.c
  clang/test/Analysis/novoidtypecrash.c
  clang/test/Analysis/null-deref-ps.c
  clang/test/Analysis/number-object-conversion.c
  clang/test/Analysis/number-object-conversion.m
  clang/test/Analysis/pr22954.c
  clang/test/C/drs/dr0xx.c
  clang/test/C/drs/dr2xx.c
  clang/test/CodeGen/2008-03-05-syncPtr.c
  clang/test/CodeGen/2008-07-31-promotion-of-compound-pointer-arithmetic.c
  clang/test/CodeGen/aarch64-mops.c
  clang/test/CodeGen/address-space-cast.c
  clang/test/CodeGen/const-init.c
  clang/test/CodeGen/pointer-arithmetic.c
  clang/test/CodeGen/pointer-to-int.c
  clang/test/CodeGen/statements.c
  clang/test/CodeGen/struct-init.c
  clang/test/CodeGen/vla.c
  clang/test/CodeGenObjC/block-ptr-type-crash.m
  clang/test/CodeGenOpenCL/builtins-generic-amdgcn.cl
  clang/test/FixIt/dereference-addressof.c
  clang/test/FixIt/selector-fixit.m
  clang/test/Misc/serialized-diags.c
  clang/test/Misc/tabstop.c
  clang/test/Modules/config_macros.m
  clang/test/PCH/objc_exprs.m
  clang/test/Parser/implicit-casts.c
  clang/test/Sema/array-init.c
  clang/test/Sema/atomic-ops.c
  clang/test/Sema/block-return.c
  clang/test/Sema/builtin-alloca-with-align.c
  clang/test/Sema/builtin-assume-aligned.c
  clang/test/Sema/builtin-dump-struct.c
  clang/test/Sema/builtins-bpf.c
  clang/test/Sema/builtins.c
  clang/test/Sema/compound-literal.c
  clang/test/Sema/conditional-expr.c
  clang/test/Sema/enum.c
  clang/test/Sema/extern-redecl.c
  clang/test/Sema/format-strings.c
  clang/test/Sema/function-redecl.c
  clang/test/Sema/function.c
  clang/test/Sema/i-c-e.c
  clang/test/Sema/indirect-goto.c
  clang/test/Sema/matrix-type-builtins.c
  clang/test/Sema/nullability.c
  clang/test/SemaObjC/argument-checking.m
  clang/test/SemaObjC/comptypes-7.m
  clang/test/SemaObjC/ivar-lookup-resolution-builtin.m
  clang/test/SemaObjC/message.m
  clang/test/SemaObjC/method-lookup-5.m
  clang/test/SemaObjC/nullability.m
  clang/test/SemaObjC/objc-container-subscripting-3.m
  clang/test/SemaObjC/objc-literal-fixit.m
  clang/test/SemaObjC/signed-char-bool-conversion.m
  clang/test/SemaOpenCL/atomic-ops.cl
  clang/test/SemaOpenCL/builtins-amdgcn-error.cl
  clang/test/VFS/Inputs/external-names.h
  clang/test/VFS/external-names.c
  compiler-rt/test/dfsan/gep.c
  compiler-rt/test/dfsan/sigaction.c

Index: compiler-rt/test/dfsan/sigaction.c
===
--- compiler-rt/test/dfsan/sigaction.c
+++ compiler-rt/test/dfsan/sigaction.c
@@ -1,5 +1,5 @@
-// RUN: %clang_dfsan -DUSE_SIGNAL_ACTION %s -o %t && %run %t
-// RUN: %clang_dfsan %s -o %t && %run %t
+// RUN: %clang_dfsan -DUSE_SIGNAL_ACTION -Wno-error=int-conversion %s -o %t && %run %t
+// RUN: %clang_dfsan -Wno-error=int-conversion %s -o %t && %run %t
 //
 // REQUIRES: x86_64-target-arch
 
Index: compiler-rt/test/dfsan/gep.c
===
--- compiler-rt/test/dfsan/gep.c
+++ compiler-rt/test/dfsan/gep.c
@@ -1,5 +1,5 @@
-// RUN: %clang_dfsan %s -mllvm -dfsan-combine-offset-labels-on-gep=false -o %t && %run %t
-// RUN: %clang_dfsan %s -DPROP_OFFSET_LABELS -o %t && %run %t
+// RUN: %clang_dfsan %s -mllvm -dfsan-combine-offset-labels-on-gep=false -Wno-error=int-conversion -o %t && %run %t
+// RUN: %clang_dfsan %s -DPROP_OFFSET_LABELS -Wno-error=int-conversion -o %t && %run %t
 //
 // REQUIRES: x86_64-target-arch
 
Index: clang/test/VFS/external-names.c
===
--- clang/test/VFS/external-names.c
+++ clang/test/VFS/external-names.c
@@ -21,7 +21,7 @@
 // Diagnostics:
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.external.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-DIAG-EXTERNAL %s
-// CHECK-DIAG-EXTERNAL: {{.*}}Inputs{{..?}}external-names.h:{{[0-9]*:[0-9]*}}: warning: incompatible pointer
+// CHECK-DIAG-EXTERNAL: {{.*}}Inputs{{..?}}external-names.h:{{[0-9]*:[0-9]*}}: warning: initializing 'const char **'
 
 // RUN: %clang_cc1 -I %t -ivfsoverlay %t.yaml -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-DIAG %s
 // CHECK-DIAG-NOT: Inputs
Index: clang/test/VFS/Inputs/external-names.h
===
--- clang/test/VFS/Inputs/external-names.h
+++ clang/test/VFS/Inputs/external-names.h
@@ -1,4 +1,4 @@
 void 

[clang-tools-extra] 7068aa9 - Strengthen -Wint-conversion to default to an error

2022-07-22 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-07-22T15:24:54-04:00
New Revision: 7068aa98412ade19a34b7ed126f4669f581b2311

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

LOG: Strengthen -Wint-conversion to default to an error

Clang has traditionally allowed C programs to implicitly convert
integers to pointers and pointers to integers, despite it not being
valid to do so except under special circumstances (like converting the
integer 0, which is the null pointer constant, to a pointer). In C89,
this would result in undefined behavior per 3.3.4, and in C99 this rule
was strengthened to be a constraint violation instead. Constraint
violations are most often handled as an error.

This patch changes the warning to default to an error in all C modes
(it is already an error in C++). This gives us better security posture
by calling out potential programmer mistakes in code but still allows
users who need this behavior to use -Wno-error=int-conversion to retain
the warning behavior, or -Wno-int-conversion to silence the diagnostic
entirely.

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/no-escape.m
clang-tools-extra/test/clang-tidy/checkers/performance/no-int-to-ptr.c
clang/bindings/python/tests/cindex/test_diagnostics.py
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/Analysis/ObjCProperties.m
clang/test/Analysis/bsd-string.c
clang/test/Analysis/novoidtypecrash.c
clang/test/Analysis/null-deref-ps.c
clang/test/Analysis/number-object-conversion.c
clang/test/Analysis/number-object-conversion.m
clang/test/Analysis/pr22954.c
clang/test/C/drs/dr0xx.c
clang/test/C/drs/dr2xx.c
clang/test/CodeGen/2008-03-05-syncPtr.c
clang/test/CodeGen/2008-07-31-promotion-of-compound-pointer-arithmetic.c
clang/test/CodeGen/aarch64-mops.c
clang/test/CodeGen/address-space-cast.c
clang/test/CodeGen/const-init.c
clang/test/CodeGen/pointer-arithmetic.c
clang/test/CodeGen/pointer-to-int.c
clang/test/CodeGen/statements.c
clang/test/CodeGen/struct-init.c
clang/test/CodeGen/vla.c
clang/test/CodeGenObjC/block-ptr-type-crash.m
clang/test/CodeGenOpenCL/builtins-generic-amdgcn.cl
clang/test/FixIt/dereference-addressof.c
clang/test/FixIt/selector-fixit.m
clang/test/Misc/serialized-diags.c
clang/test/Misc/tabstop.c
clang/test/Modules/config_macros.m
clang/test/PCH/objc_exprs.m
clang/test/Parser/implicit-casts.c
clang/test/Sema/array-init.c
clang/test/Sema/atomic-ops.c
clang/test/Sema/block-return.c
clang/test/Sema/builtin-alloca-with-align.c
clang/test/Sema/builtin-assume-aligned.c
clang/test/Sema/builtin-dump-struct.c
clang/test/Sema/builtins-bpf.c
clang/test/Sema/builtins.c
clang/test/Sema/compound-literal.c
clang/test/Sema/conditional-expr.c
clang/test/Sema/enum.c
clang/test/Sema/extern-redecl.c
clang/test/Sema/format-strings.c
clang/test/Sema/function-redecl.c
clang/test/Sema/function.c
clang/test/Sema/i-c-e.c
clang/test/Sema/indirect-goto.c
clang/test/Sema/matrix-type-builtins.c
clang/test/Sema/nullability.c
clang/test/SemaObjC/argument-checking.m
clang/test/SemaObjC/comptypes-7.m
clang/test/SemaObjC/ivar-lookup-resolution-builtin.m
clang/test/SemaObjC/message.m
clang/test/SemaObjC/method-lookup-5.m
clang/test/SemaObjC/nullability.m
clang/test/SemaObjC/objc-container-subscripting-3.m
clang/test/SemaObjC/objc-literal-fixit.m
clang/test/SemaObjC/signed-char-bool-conversion.m
clang/test/SemaOpenCL/atomic-ops.cl
clang/test/SemaOpenCL/builtins-amdgcn-error.cl
clang/test/VFS/Inputs/external-names.h
clang/test/VFS/external-names.c
compiler-rt/test/dfsan/gep.c
compiler-rt/test/dfsan/sigaction.c

Removed: 




diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/no-escape.m 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/no-escape.m
index 11dba3345fa1a..8545065f15526 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/no-escape.m
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/no-escape.m
@@ -1,5 +1,5 @@
-// RUN: %check_clang_tidy %s bugprone-no-escape %t
-// RUN: %check_clang_tidy %s -assume-filename=bugprone-no-escape.c 
bugprone-no-escape %t -- -- -fblocks
+// RUN: %check_clang_tidy %s bugprone-no-escape %t -- -- -Wno-int-conversion
+// RUN: %check_clang_tidy %s -assume-filename=bugprone-no-escape.c 
bugprone-no-escape %t -- -- -fblocks -Wno-int-conversion
 
 typedef struct dispatch_queue_s *dispatch_queue_t;
 typedef struct dispatch_time_s *dispatch_time_t;

diff  --git 

[PATCH] D129891: [test-suite] Update the test suite for changes to -Wint-conversion

2022-07-22 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rT1c09bf48b36b: Update the test suite for changes to 
-Wint-conversion (authored by aaron.ballman).

Repository:
  rT test-suite

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129891/new/

https://reviews.llvm.org/D129891

Files:
  MultiSource/Applications/Burg/CMakeLists.txt
  MultiSource/Applications/Burg/Makefile
  MultiSource/Benchmarks/Prolangs-C/assembler/CMakeLists.txt
  MultiSource/Benchmarks/Prolangs-C/assembler/Makefile
  MultiSource/Benchmarks/Prolangs-C/bison/CMakeLists.txt
  MultiSource/Benchmarks/Prolangs-C/bison/Makefile
  MultiSource/Benchmarks/Prolangs-C/football/CMakeLists.txt
  MultiSource/Benchmarks/Prolangs-C/football/Makefile
  MultiSource/Benchmarks/Prolangs-C/unix-smail/CMakeLists.txt
  MultiSource/Benchmarks/Prolangs-C/unix-smail/Makefile
  MultiSource/Benchmarks/TSVC/Recurrences-flt/CMakeLists.txt
  MultiSource/Benchmarks/TSVC/Recurrences-flt/Makefile
  MultiSource/Benchmarks/VersaBench/beamformer/CMakeLists.txt
  MultiSource/Benchmarks/VersaBench/beamformer/Makefile
  SingleSource/Regression/C/gcc-c-torture/execute/CMakeLists.txt

Index: SingleSource/Regression/C/gcc-c-torture/execute/CMakeLists.txt
===
--- SingleSource/Regression/C/gcc-c-torture/execute/CMakeLists.txt
+++ SingleSource/Regression/C/gcc-c-torture/execute/CMakeLists.txt
@@ -1,7 +1,7 @@
 add_subdirectory(ieee)
 
 # GCC C Torture Suite is conventionally run without warnings
-list(APPEND CFLAGS -Wno-implicit-int -Wno-implicit-function-declaration -w)
+list(APPEND CFLAGS -Wno-implicit-int -Wno-int-conversion -Wno-implicit-function-declaration -w)
 
 set(TestsToSkip)
 
Index: MultiSource/Benchmarks/VersaBench/beamformer/Makefile
===
--- MultiSource/Benchmarks/VersaBench/beamformer/Makefile
+++ MultiSource/Benchmarks/VersaBench/beamformer/Makefile
@@ -1,6 +1,6 @@
 LEVEL = ../../../..
 LDFLAGS += -lm
-CFLAGS += -DFP_ABSTOLERANCE=1e-5
+CFLAGS += -DFP_ABSTOLERANCE=1e-5 -Wno-int-conversion
 
 PROG = beamformer
 ifdef LARGE_PROBLEM_SIZE
Index: MultiSource/Benchmarks/VersaBench/beamformer/CMakeLists.txt
===
--- MultiSource/Benchmarks/VersaBench/beamformer/CMakeLists.txt
+++ MultiSource/Benchmarks/VersaBench/beamformer/CMakeLists.txt
@@ -1,3 +1,4 @@
+list(APPEND CFLAGS -Wno-int-conversion)
 list(APPEND LDFLAGS -lm)
 if(LARGE_PROBLEM_SIZE)
   set(RUN_OPTIONS -i 400)
Index: MultiSource/Benchmarks/TSVC/Recurrences-flt/Makefile
===
--- MultiSource/Benchmarks/TSVC/Recurrences-flt/Makefile
+++ MultiSource/Benchmarks/TSVC/Recurrences-flt/Makefile
@@ -2,7 +2,7 @@
 
 PROG = Recurrences-flt
 LDFLAGS  = -lm
-CFLAGS += -std=gnu99
+CFLAGS += -std=gnu99 -Wno-int-conversion
 RUN_OPTIONS = 2 5
 include $(LEVEL)/MultiSource/Makefile.multisrc
 
Index: MultiSource/Benchmarks/TSVC/Recurrences-flt/CMakeLists.txt
===
--- MultiSource/Benchmarks/TSVC/Recurrences-flt/CMakeLists.txt
+++ MultiSource/Benchmarks/TSVC/Recurrences-flt/CMakeLists.txt
@@ -1,4 +1,4 @@
 list(APPEND LDFLAGS -lm)
-list(APPEND CFLAGS -std=gnu99)
+list(APPEND CFLAGS -std=gnu99 -Wno-int-conversion)
 set(RUN_OPTIONS 2 5)
 llvm_multisource(Recurrences-flt)
Index: MultiSource/Benchmarks/Prolangs-C/unix-smail/Makefile
===
--- MultiSource/Benchmarks/Prolangs-C/unix-smail/Makefile
+++ MultiSource/Benchmarks/Prolangs-C/unix-smail/Makefile
@@ -1,6 +1,7 @@
 LEVEL = ../../../..
 
 PROG = unix-smail
+CFLAGS += -Wno-int-conversion
 RUN_OPTIONS = -v ALL
 STDIN_FILENAME = $(PROJ_SRC_DIR)/main.c
 
Index: MultiSource/Benchmarks/Prolangs-C/unix-smail/CMakeLists.txt
===
--- MultiSource/Benchmarks/Prolangs-C/unix-smail/CMakeLists.txt
+++ MultiSource/Benchmarks/Prolangs-C/unix-smail/CMakeLists.txt
@@ -1,3 +1,4 @@
+list(APPEND CFLAGS -Wno-int-conversion)
 set(RUN_OPTIONS -v ALL < main.c)
 llvm_multisource(unix-smail)
 llvm_test_data(unix-smail main.c)
Index: MultiSource/Benchmarks/Prolangs-C/football/Makefile
===
--- MultiSource/Benchmarks/Prolangs-C/football/Makefile
+++ MultiSource/Benchmarks/Prolangs-C/football/Makefile
@@ -1,5 +1,6 @@
 LEVEL = ../../../..
 
 PROG = football
+CFLAGS += -Wno-int-conversion
 include $(LEVEL)/MultiSource/Makefile.multisrc
 
Index: MultiSource/Benchmarks/Prolangs-C/football/CMakeLists.txt
===
--- MultiSource/Benchmarks/Prolangs-C/football/CMakeLists.txt
+++ MultiSource/Benchmarks/Prolangs-C/football/CMakeLists.txt
@@ -1 +1,2 @@
+list(APPEND CFLAGS -Wno-int-conversion)
 

[PATCH] D130387: [CUDA/SPIR-V] Force passing aggregate type byval

2022-07-22 Thread Shangwu Yao via Phabricator via cfe-commits
shangwuyao created this revision.
shangwuyao added reviewers: jlebar, mkuper, tra, yaxunl.
Herald added subscribers: mattd, ThomasRaoux.
Herald added a project: All.
shangwuyao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch forces copying aggregate type in kernel arguments by value when
compiling CUDA targeting SPIR-V. The original behavior is not passing by value
when there is any of destructor, copy constructor and move constructor defined
by user. This patch makes the behavior of SPIR-V generated from CUDA follow
the CUDA spec
(https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-function-argument-processing),
and matches the NVPTX
implementation (
https://github.com/llvm/llvm-project/blob/41958f76d8a2c47484fa176cba1de565cfe84de7/clang/lib/CodeGen/TargetInfo.cpp#L7241).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130387

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu


Index: clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
@@ -0,0 +1,25 @@
+// Tests CUDA kernel arguments get copied by value when targeting SPIR-V, even 
with
+// destructor, copy constructor or move constructor defined by user.
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only 
--offload=spirv32 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only 
--offload=spirv64 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+class GpuData {
+ public:
+  __attribute__((host)) __attribute__((device)) GpuData(int* src) {}
+  __attribute__((host)) __attribute__((device)) ~GpuData() {}
+  __attribute__((host)) __attribute__((device)) GpuData(const GpuData& other) 
{}
+  __attribute__((host)) __attribute__((device)) GpuData(GpuData&& other) {}
+};
+
+// CHECK: define
+// CHECK-SAME: spir_kernel void @_Z6kernel7GpuData(%class.GpuData* noundef 
byval(%class.GpuData) align
+
+__attribute__((global)) void kernel(GpuData output) {}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10446,6 +10446,10 @@
   LTy = llvm::PointerType::getWithSamePointeeType(PtrTy, GlobalAS);
   return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
 }
+
+if (isAggregateTypeForABI(Ty)) {
+  return getNaturalAlignIndirect(Ty, /* byval */ true);
+}
   }
   return classifyArgumentType(Ty);
 }


Index: clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDASPIRV/copy-aggregate-byval.cu
@@ -0,0 +1,25 @@
+// Tests CUDA kernel arguments get copied by value when targeting SPIR-V, even with
+// destructor, copy constructor or move constructor defined by user.
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only --offload=spirv32 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+// RUN: %clang -Xclang -no-opaque-pointers -emit-llvm --cuda-device-only --offload=spirv64 \
+// RUN:   -nocudalib -nocudainc %s -o %t.bc -c 2>&1
+// RUN: llvm-dis %t.bc -o %t.ll
+// RUN: FileCheck %s --input-file=%t.ll
+
+class GpuData {
+ public:
+  __attribute__((host)) __attribute__((device)) GpuData(int* src) {}
+  __attribute__((host)) __attribute__((device)) ~GpuData() {}
+  __attribute__((host)) __attribute__((device)) GpuData(const GpuData& other) {}
+  __attribute__((host)) __attribute__((device)) GpuData(GpuData&& other) {}
+};
+
+// CHECK: define
+// CHECK-SAME: spir_kernel void @_Z6kernel7GpuData(%class.GpuData* noundef byval(%class.GpuData) align
+
+__attribute__((global)) void kernel(GpuData output) {}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -10446,6 +10446,10 @@
   LTy = llvm::PointerType::getWithSamePointeeType(PtrTy, GlobalAS);
   return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
 }
+
+if (isAggregateTypeForABI(Ty)) {
+  return getNaturalAlignIndirect(Ty, /* byval */ true);
+}
   }
   return classifyArgumentType(Ty);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129881: [C] Strengthen -Wint-conversion to default to an error

2022-07-22 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision as: efriedma.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129881/new/

https://reviews.llvm.org/D129881

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


[PATCH] D126731: [pseudo] Eliminate dependencies from clang-pseudo-gen. NFC

2022-07-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In D126731#3670896 , @sammccall wrote:

> Hmm, I also don't know.
> The idea here is that we specifically depend only on the TokenKind enum from 
> TokenKinds.h (which doesn't need any generated headers), not on other headers 
> from clang/include/Basic (which might), and not on building/linking 
> clangBasic itself.
> In a modules world, maybe that means we need TokenKinds.h to be its own 
> module, or a non-modular header, or something?

I went with the approach of putting TokenKinds.h (and TokenKinds.def) into its 
own module D130377 .

In D126731#3670896 , @sammccall wrote:

> I'm also not sure on the support status of the modules build: I can't find a 
> buildbot covering it or docs. Is this something I need to fix, or is it an 
> experimental build like GN/Bazel?

I know at least about https://green.lab.llvm.org/green/job/lldb-cmake/ building 
with modules. I agree it's not a common configuration on buildbots but it's not 
experimental like GN/Bazel. As for the fixing the issue, it is covered by 
https://llvm.org/docs/DeveloperPolicy.html#quality , i.e., it is the author's 
responsibility but the reporter is responsible for making sure the author is 
equipped to do so (or fix themselves if they cannot help the author).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126731/new/

https://reviews.llvm.org/D126731

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


[PATCH] D129891: [test-suite] Update the test suite for changes to -Wint-conversion

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: StephenFan.

Thanks! This is similar to D123241 


Repository:
  rT test-suite

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129891/new/

https://reviews.llvm.org/D129891

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


[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-07-22 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/test/Index/annotate-operator-call-expr.cpp:21
+// CHECK1: Punctuation: "(" [7:6 - 7:7] CallExpr=operator():3:7
+// CHECK1: Punctuation: ")" [7:7 - 7:8] CallExpr=operator():3:7
 // CHECK1: Punctuation: ";" [7:8 - 7:9] CompoundStmt=

SimplyDanny wrote:
> I updated the test expectation without actually knowing whether the test 
> references are correct(er) now. There seems to be some loss of information 
> and some `CallExpr`s are now seen as `DeclRefExpr`s. Please tell me if these 
> changes are okay. I rather made them to have a basis for discussions.
`DeclRerExpr`  to `CallExpr` looks right.



Comment at: clang/test/Index/cursor-ref-names.cpp:36
 // CHECK: cursor-ref-names.cpp:18:5: DeclRefExpr=inst:17:9 Extent=[18:5 - 18:9]
-// CHECK: cursor-ref-names.cpp:19:5: CallExpr=operator[]:4:9 
SingleRefName=[19:9 - 19:12] RefName=[19:9 - 19:10] RefName=[19:11 - 19:12] 
Extent=[19:5 - 19:12]
+// CHECK: cursor-ref-names.cpp:19:5: CallExpr=operator[]:4:9 Extent=[19:5 - 
19:12] 
 // CHECK: cursor-ref-names.cpp:19:5: DeclRefExpr=inst:17:9 Extent=[19:5 - 19:9]

It looks like we lost some information here but I am not sure if that is 
expected or not. 

AFAIK CIndex is supported on a best effort basis, I think this is ok.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129973/new/

https://reviews.llvm.org/D129973

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


[PATCH] D129891: [test-suite] Update the test suite for changes to -Wint-conversion

2022-07-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ping


Repository:
  rT test-suite

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129891/new/

https://reviews.llvm.org/D129891

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


[PATCH] D129881: [C] Strengthen -Wint-conversion to default to an error

2022-07-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129881/new/

https://reviews.llvm.org/D129881

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


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-22 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added a comment.

In D128465#3672515 , @MaskRay wrote:

> I am still seeing the
>
>   zstdConfig.cmake
>   zstd-config.cmake
>
> warning. @ckissane @phosek will you fix it? :)

I've quieted the warnings in 
https://github.com/llvm/llvm-project/commit/a71a01bc10d509bd4e746e7d277c4613ef886875,
 though I'm just now seeing @phosek's suggestion to use `CONFIG` I'm not sure 
what that does


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D130377: Move "clang/Basic/TokenKinds.h" into a separate top-level module.

2022-07-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: sammccall, aprantl, jansvoboda11, iana.
Herald added a subscriber: ributzka.
Herald added a project: All.
vsapsai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes modular build for clangPseudoGrammar from clang-tools-extra.

Starting from https://reviews.llvm.org/D126731 clangPseudoGrammar
doesn't depend on generated .inc headers but still depends on
"Basic/TokenKinds.h". It means clangPseudoGrammar depends on module
'Clang_Basic' which does depend on generated .inc headers. To avoid
these coarse dependencies and extra build steps, extract
"clang/Basic/TokenKinds.h" into a top-level module 'Clang_Basic_TokenKinds'.

rdar://97387951


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130377

Files:
  clang/include/clang/module.modulemap


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -71,10 +71,17 @@
   textual header "Basic/RISCVVTypes.def"
   textual header "Basic/Sanitizers.def"
   textual header "Basic/TargetCXXABI.def"
-  textual header "Basic/TokenKinds.def"
 
   module * { export * }
 }
+module Clang_Basic_TokenKinds {
+  requires cplusplus
+
+  header "Basic/TokenKinds.h"
+  textual header "Basic/TokenKinds.def"
+
+  export *
+}
 
 module Clang_CodeGen { requires cplusplus umbrella "CodeGen" module * { export 
* } }
 module Clang_Config { requires cplusplus umbrella "Config" module * { export * 
} }


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -71,10 +71,17 @@
   textual header "Basic/RISCVVTypes.def"
   textual header "Basic/Sanitizers.def"
   textual header "Basic/TargetCXXABI.def"
-  textual header "Basic/TokenKinds.def"
 
   module * { export * }
 }
+module Clang_Basic_TokenKinds {
+  requires cplusplus
+
+  header "Basic/TokenKinds.h"
+  textual header "Basic/TokenKinds.def"
+
+  export *
+}
 
 module Clang_CodeGen { requires cplusplus umbrella "CodeGen" module * { export * } }
 module Clang_Config { requires cplusplus umbrella "Config" module * { export * } }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I am still seeing the

  zstdConfig.cmake
  zstd-config.cmake

warning. @ckissane @phosek will you fix it? :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128465/new/

https://reviews.llvm.org/D128465

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


[PATCH] D130299: [clang-format] FIX: Misformatting lambdas with trailing return type 'auto' in braced lists

2022-07-22 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 446916.
denis-fatkulin added a comment.

> Could you please add full git context?

I updated the patch with properly git context. Thanks!

> Was the problem due to misannotation of auto? If so, could you add an 
> annotator test?

I'm not sure about the questions. I will try to explain my patch purpose. 
Actually there was two problems:

1. `auto` wasn't detected as properly type keyword in lambda's trailing return 
type. So, formatting was completely wrong for this case (fixed in 
`clang/lib/Format/UnwrappedLineParser.cpp`)
2. The keyword `auto` and left brace `{` was interpreted as declaration 
`auto{}`. So, formatting delete a space symbol between them. (fixed in 
`clang/lib/Format/TokenAnnotator.cpp`)

Both cases are checked in changes at `clang/unittests/Format/FormatTest.cpp` 
and I think the unit test is sufficient.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130299/new/

https://reviews.llvm.org/D130299

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,13 @@
   verifyFormat("auto lambda = [ = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, LambdaWithTrailingAutoInBracedList) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("auto list = {[]() -> auto { return Val; }};", Style);
+  verifyFormat("auto list = {[]() -> auto * { return Ptr; }};", Style);
+  verifyFormat("auto list = {[]() -> auto & { return Ref; }};", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,10 @@
 }
   }
 
+  // Lambda with trailing return type 'auto': []() -> auto { return T; }
+  if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace)
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,13 @@
   verifyFormat("auto lambda = [ = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, LambdaWithTrailingAutoInBracedList) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("auto list = {[]() -> auto { return Val; }};", Style);
+  verifyFormat("auto list = {[]() -> auto * { return Ptr; }};", Style);
+  verifyFormat("auto list = {[]() -> auto & { return Ref; }};", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,10 @@
 }
   }
 
+  // Lambda with trailing return type 'auto': []() -> auto { return T; }
+  if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace)
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-22 Thread krishna chaitanya sankisa via Phabricator via cfe-commits
skc7 updated this revision to Diff 446919.
skc7 added a comment.

Fixes as per review comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130224/new/

https://reviews.llvm.org/D130224

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-maybeundef.c
  clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -83,6 +83,7 @@
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
+// CHECK-NEXT: MayBeUndef (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: MinSize (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: MinVectorWidth (SubjectMatchRule_function)
Index: clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
===
--- /dev/null
+++ clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -no-opaque-pointers -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip -fcuda-is-device -emit-llvm  %s \
+// RUN:   -o - | FileCheck %s
+
+#define __global__ __attribute__((global))
+#define __device__ __attribute__((device))
+#define __maybe_undef __attribute__((maybe_undef))
+#define WARP_SIZE 64
+
+static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE;
+
+__device__ static inline unsigned int __lane_id() {
+return  __builtin_amdgcn_mbcnt_hi(
+-1, __builtin_amdgcn_mbcnt_lo(-1, 0));
+}
+
+__device__
+inline
+int __shfl_sync(int __maybe_undef var, int src_lane, int width = warpSize) {
+int self = __lane_id();
+int index = src_lane + (self & ~(width-1));
+return __builtin_amdgcn_ds_bpermute(index<<2, var);
+}
+
+__global__ void
+shufflekernel()
+{
+int t;
+int res;
+res = __shfl_sync(t, WARP_SIZE, 0);
+}
+
+// CHECK: define dso_local amdgpu_kernel void @_Z13shufflekernelv()
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[TMP2:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[TMP3:%.*]] = addrspacecast i32 addrspace(5)* [[TMP1:%.*]] to i32*
+// CHECK-NEXT:[[TMP4:%.*]] = addrspacecast i32 addrspace(5)* [[TMP2:%.*]] to i32*
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, i32* [[TMP3:%.*]], align 4
+// CHECK-NEXT:[[TMP6:%.*]] = freeze i32 [[TMP5:%.*]]
+// CHECK-NEXT:%call = call noundef i32 @_Z11__shfl_synciii(i32 noundef [[TMP6:%.*]], i32 noundef 64, i32 noundef 0) #4
+// CHECK-NEXT:store i32 %call, i32* [[TMP4:%.*]], align 4
+// CHECK-NEXT:  ret void
+
+// CHECK: define linkonce_odr noundef i32 @_Z11__shfl_synciii(i32 noundef %var, i32 noundef %src_lane, i32 noundef %width)
Index: clang/test/CodeGen/attr-maybeundef.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-maybeundef.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - | FileCheck %s
+
+#define __maybe_undef __attribute__((maybe_undef))
+
+// CHECK: define dso_local void @t1(i32 noundef %param1, i32 noundef %param2, float noundef %param3) #[[attr1:[0-9]+]]
+void t1(int param1, int __maybe_undef param2, float param3) {}
+
+// CHECK: define dso_local void @t2(i32 noundef %param1, i32 noundef %param2, float noundef %param3)
+// CHECK: [[TMP1:%.*]] = freeze i32 [[TMP2:%.*]]
+// CHECK: call void @t1(i32 noundef %0, i32 noundef [[TMP1:%.*]], float noundef %2)
+// expected-error {{'maybe_undef' attribute only applies to parameters [-Wignored-attributes]}}
+void __maybe_undef t2(int param1, int param2, float param3) {
+t1(param1, param2, param3);
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8634,6 +8634,9 @@
   case ParsedAttr::AT_NoEscape:
 handleNoEscapeAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_MayBeUndef:
+handleSimpleAttribute(S, D, AL);
+break;
   case ParsedAttr::AT_AssumeAligned:
 handleAssumeAlignedAttr(S, D, AL);
 break;
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2046,6 +2046,25 @@
   return false;
 }
 
+/// Check if the argument of a function has maybe_undef attribute.
+static bool IsArgumentMayBeUndef(const Decl *TargetDecl, unsigned ArgNo) {
+  if 

[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-22 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 446915.
samestep added a comment.

Update comment about default parameters


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130306/new/

https://reviews.llvm.org/D130306

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Transfer.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -39,14 +39,14 @@
 
 template 
 void runDataflow(llvm::StringRef Code, Matcher Match,
-  LangStandard::Kind Std = LangStandard::lang_cxx17,
-  bool ApplyBuiltinTransfer = true,
-  llvm::StringRef TargetFun = "target") {
+ DataflowAnalysisOptions Options,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ llvm::StringRef TargetFun = "target") {
   ASSERT_THAT_ERROR(
   test::checkDataflow(
   Code, TargetFun,
-  [ApplyBuiltinTransfer](ASTContext , Environment &) {
-return NoopAnalysis(C, ApplyBuiltinTransfer);
+  [Options](ASTContext , Environment &) {
+return NoopAnalysis(C, Options);
   },
   [](
   llvm::ArrayRef<
@@ -54,12 +54,19 @@
   Results,
   ASTContext ) { Match(Results, ASTCtx); },
   {"-fsyntax-only", "-fno-delayed-template-parsing",
-"-std=" +
-std::string(
-LangStandard::getLangStandardForKind(Std).getName())}),
+   "-std=" + std::string(
+ LangStandard::getLangStandardForKind(Std).getName())}),
   llvm::Succeeded());
 }
 
+template 
+void runDataflow(llvm::StringRef Code, Matcher Match,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ bool ApplyBuiltinTransfer = true,
+ llvm::StringRef TargetFun = "target") {
+  runDataflow(Code, Match, {ApplyBuiltinTransfer}, Std, TargetFun);
+}
+
 TEST(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) {
   std::string Code = R"(
 void target() {
@@ -3862,4 +3869,95 @@
   });
 }
 
+TEST(TransferTest, ContextSensitiveOptionDisabled) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = true; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment  = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto  =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/false}});
+}
+
+TEST(TransferTest, ContextSensitiveSetTrue) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = true; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment  = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto  =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveSetFalse) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = false; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+

[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-22 Thread Sam Estep via Phabricator via cfe-commits
samestep added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:220
+  assert(Body != nullptr);
+  initGlobalVars(*Body, Env);
+

ymandel wrote:
> samestep wrote:
> > ymandel wrote:
> > > samestep wrote:
> > > > ymandel wrote:
> > > > > I wonder how this will work between caller and callee. Do we need 
> > > > > separate global var state in the frame? If so, maybe mention that as 
> > > > > well in the FIXME above.
> > > > Could you clarify what you mean? Perhaps I just don't understand 
> > > > exactly what is meant by "global vars" here.
> > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp#L131-L135
> > > 
> > > ```
> > > /// Initializes global storage values that are declared or referenced from
> > > /// sub-statements of `S`.
> > > // FIXME: Add support for resetting globals after function calls to enable
> > > // the implementation of sound analyses.
> > > ```
> > > Since this already mentions a need to reset after function calls, seemed 
> > > relevant here.
> > Hmm, OK. I pretty much just pattern-matched from the `Environment` 
> > constructor right above this method implementation. Would it be better for 
> > me to instead just remove this `initGlobalVars` call for now and replace it 
> > with a `FIXME` saying that we'll probably need to call this but it's 
> > unclear how exactly to do so?
> SGTM. We can note this constraint on models' reference implementations. 
> Specifically, that they cannot reference globals.
Done.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:231
+  // parameters still need to be given `StorageLocation`s anyway, so this code
+  // will need to be generalized later.
+  for (; ArgIt != ArgEnd; ++ParamIt, ++ArgIt) {

gribozavr2 wrote:
> The Clang AST includes argument expressions for defaulted arguments, so I 
> believe there shouldn't be anything left to do here, it should just work.
Oh nice! I'm updating this comment, thanks.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:3896
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+  },

gribozavr2 wrote:
> 
Good idea, done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130306/new/

https://reviews.llvm.org/D130306

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


[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-22 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 446914.
samestep added a comment.

Don't allow globals


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130306/new/

https://reviews.llvm.org/D130306

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Transfer.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -39,14 +39,14 @@
 
 template 
 void runDataflow(llvm::StringRef Code, Matcher Match,
-  LangStandard::Kind Std = LangStandard::lang_cxx17,
-  bool ApplyBuiltinTransfer = true,
-  llvm::StringRef TargetFun = "target") {
+ DataflowAnalysisOptions Options,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ llvm::StringRef TargetFun = "target") {
   ASSERT_THAT_ERROR(
   test::checkDataflow(
   Code, TargetFun,
-  [ApplyBuiltinTransfer](ASTContext , Environment &) {
-return NoopAnalysis(C, ApplyBuiltinTransfer);
+  [Options](ASTContext , Environment &) {
+return NoopAnalysis(C, Options);
   },
   [](
   llvm::ArrayRef<
@@ -54,12 +54,19 @@
   Results,
   ASTContext ) { Match(Results, ASTCtx); },
   {"-fsyntax-only", "-fno-delayed-template-parsing",
-"-std=" +
-std::string(
-LangStandard::getLangStandardForKind(Std).getName())}),
+   "-std=" + std::string(
+ LangStandard::getLangStandardForKind(Std).getName())}),
   llvm::Succeeded());
 }
 
+template 
+void runDataflow(llvm::StringRef Code, Matcher Match,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ bool ApplyBuiltinTransfer = true,
+ llvm::StringRef TargetFun = "target") {
+  runDataflow(Code, Match, {ApplyBuiltinTransfer}, Std, TargetFun);
+}
+
 TEST(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) {
   std::string Code = R"(
 void target() {
@@ -3862,4 +3869,95 @@
   });
 }
 
+TEST(TransferTest, ContextSensitiveOptionDisabled) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = true; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment  = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto  =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+EXPECT_FALSE(Env.flowConditionImplies(Env.makeNot(FooVal)));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/false}});
+}
+
+TEST(TransferTest, ContextSensitiveSetTrue) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = true; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment  = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto  =
+*cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {/*.ApplyBuiltinTransfer=*/true,
+   /*.BuiltinTransferOptions=*/{/*.ContextSensitive=*/true}});
+}
+
+TEST(TransferTest, ContextSensitiveSetFalse) {
+  std::string Code = R"(
+bool GiveBool();
+void SetBool(bool ) { Var = false; }
+
+void target() {
+  bool Foo = GiveBool();
+  SetBool(Foo);
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ 

[PATCH] D129872: [clang][OpenMP] Fix runtime crash in the call to __kmp_alloc.

2022-07-22 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D129872#3672332 , @jyu2 wrote:

> In D129872#3671847 , @ABataev wrote:
>
>> Why does it get truncated if the type must be integer? Probably, something 
>> incorrect in sema.
>
> This is only failed with C.  But not for C++.  So I don't think we have 
> problem for Seam.  I may missing something...
> The different is in reprehensive of enum type between c vs c++:
> For C:
>
> | -EnumDecl 0x1193f838  line:18:14 
> omp_allocator_handle_t |
> | 
>   | -EnumConstantDecl 0x1193f940  col:3 referenced 
> omp_null_allocator 'int'|
> | 
>   | `-ConstantExpr 0x1193f920  'int'  
> |
> | 
>   |   
> | -value: Int 0 |
> | 
>   | `-IntegerLiteral 0x1193f900  'int' 0  
> |
> | 
>   | -EnumConstantDecl 0x1193f9d0  col:7 referenced 
> omp_default_mem_alloc 'int' |
> | 
>   | `-ConstantExpr 0x1193f9b0  'int'  
> |
> | 
>   |   
> | -value: Int 1 |
> | 
>   | `-IntegerLiteral 0x1193f990  'int' 1  
> |
> |
>
> for C++:
>
> | -EnumDecl 0x11b31d88  line:18:14 
> omp_allocator_handle_t |
> | 
>   | -EnumConstantDecl 0x11b31e90  col:3 referenced 
> omp_null_allocator 'omp_allocator_handle_t'|
> | 
>   | `-ImplicitCastExpr 0x11b4b770  'unsigned long'  
>|
> | 
>   | `-ConstantExpr 0x11b31e70  'int'  
>|
> | 
>   |   
>| -value: Int 0 |
> | 
>   | `-IntegerLiteral 0x11b31e50  'int' 0  
>|
> | 
>   | -EnumConstantDecl 0x11b31f20  col:7 referenced 
> omp_default_mem_alloc 'omp_allocator_handle_t' |
> | 
>   | `-ImplicitCastExpr 0x11b4b788  'unsigned long'  
>|
> | 
>   | `-ConstantExpr 0x11b31f00  'int'  
>|
> | 
>   |   
>| -value: Int 1 |
> | 
>   | `-IntegerLiteral 0x11b31ee0  'int' 1  
>|
> |

If the type does not match, we have a problem with casting. Need to add an 
explicit cast to int-like type rather than avoid implicit casts.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129872/new/

https://reviews.llvm.org/D129872

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


[PATCH] D130322: [clang][CodeGen] Only include ABIInfo.h where required (NFC)

2022-07-22 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

In D130322#3672362 , @MaskRay wrote:

> Testing and will push in one minute

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130322/new/

https://reviews.llvm.org/D130322

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


[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-22 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

My concern with the 'num positive bits' is really that `enum EEmpty{};`, `enum 
EZero{ A =0 };`, and `enum ENeg {A = -1};` should all have 1 total bit of 
'values'.  So as long as THAT is true, I would expect this to be ok.

I fear that sticking to the 'non-negative' definition of `NumPositiveBits` 
might cause some oddball annoyances when trying to add this rule as a 
side-effect.




Comment at: clang/lib/Sema/SemaDecl.cpp:18886
+  InitVal.getActiveBits() ? InitVal.getActiveBits() : 1;
+  NumPositiveBits = std::max(NumPositiveBits, ActiveBits);
+} else

shafik wrote:
> erichkeane wrote:
> > What about:
> > 
> > `std::max({NumPositiveBits, ActiveBits, 1})` (which uses the init-list 
> > version of std::max).
> > 
> > Also, not completely following this: BUT we don't need a positive bit IF we 
> > have a negative bit, right?  So this is only necessary if BOTH 
> > NumPositiveBits and NumNegativeBits would have been 0?
> Good call on the `std::max` alternative, I completely forgot about it.
> 
> If we look at the description of `getNumPositiveBits()` in `Decl.h` it says:
> 
> > Returns the width in bits required to store all the non-negative 
> > enumerators of this enum.
> 
> So since `0` is non-negative we should update the positive bits. Make sense?
Hmm... ok then.  As long as my test below ends up with the right values (that 
is, a value range of -1, 0 in the 1 case, and 0, 1 in the other).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130301/new/

https://reviews.llvm.org/D130301

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


[PATCH] D130322: [clang][CodeGen] Only include ABIInfo.h where required (NFC)

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37502e042ff0: [clang][CodeGen] Only include ABIInfo.h where 
required (NFC) (authored by barannikov88, committed by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D130322?vs=446685=446901#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130322/new/

https://reviews.llvm.org/D130322

Files:
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.h
  clang/lib/CodeGen/CGObjCRuntime.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/SwiftCallingConv.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h

Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -43,10 +43,10 @@
 /// codegeneration issues, like target-specific attributes, builtins and so
 /// on.
 class TargetCodeGenInfo {
-  std::unique_ptr Info = nullptr;
+  std::unique_ptr Info;
 
 public:
-  TargetCodeGenInfo(std::unique_ptr Info) : Info(std::move(Info)) {}
+  TargetCodeGenInfo(std::unique_ptr Info);
   virtual ~TargetCodeGenInfo();
 
   /// getABIInfo() - Returns ABI info helper for the target.
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -443,6 +443,9 @@
   return Address(PHI, Addr1.getElementType(), Align);
 }
 
+TargetCodeGenInfo::TargetCodeGenInfo(std::unique_ptr Info)
+: Info(std::move(Info)) {}
+
 TargetCodeGenInfo::~TargetCodeGenInfo() = default;
 
 // If someone can figure out a general rule for this, that would be great.
Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -11,9 +11,10 @@
 //===--===//
 
 #include "clang/CodeGen/SwiftCallingConv.h"
-#include "clang/Basic/TargetInfo.h"
+#include "ABIInfo.h"
 #include "CodeGenModule.h"
 #include "TargetInfo.h"
+#include "clang/Basic/TargetInfo.h"
 
 using namespace clang;
 using namespace CodeGen;
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "CodeGenModule.h"
+#include "ABIInfo.h"
 #include "CGBlocks.h"
 #include "CGCUDARuntime.h"
 #include "CGCXXABI.h"
@@ -32,7 +33,6 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Mangle.h"
-#include "clang/AST/RecordLayout.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/Builtins.h"
Index: clang/lib/CodeGen/CGObjCRuntime.h
===
--- clang/lib/CodeGen/CGObjCRuntime.h
+++ clang/lib/CodeGen/CGObjCRuntime.h
@@ -34,7 +34,8 @@
 
 namespace clang {
 namespace CodeGen {
-  class CodeGenFunction;
+class CGFunctionInfo;
+class CodeGenFunction;
 }
 
   class FieldDecl;
Index: clang/lib/CodeGen/CGCall.h
===
--- clang/lib/CodeGen/CGCall.h
+++ clang/lib/CodeGen/CGCall.h
@@ -22,9 +22,6 @@
 #include "clang/AST/Type.h"
 #include "llvm/IR/Value.h"
 
-// FIXME: Restructure so we don't have to expose so much stuff.
-#include "ABIInfo.h"
-
 namespace llvm {
 class Type;
 class Value;
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -10,6 +10,7 @@
 //
 //===--===//
 
+#include "ABIInfo.h"
 #include "CGCUDARuntime.h"
 #include "CGCXXABI.h"
 #include "CGObjCRuntime.h"
Index: clang/lib/CodeGen/ABIInfo.h
===
--- clang/lib/CodeGen/ABIInfo.h
+++ clang/lib/CodeGen/ABIInfo.h
@@ -35,10 +35,6 @@
   class CodeGenTypes;
   class SwiftABIInfo;
 
-namespace swiftcall {
-  class SwiftAggLowering;
-}
-
   // FIXME: All of this stuff should be part of the target interface
   // somehow. It is currently here because it is not clear how to factor
   // the targets to support this, since the Targets currently live in a
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 37502e0 - [clang][CodeGen] Only include ABIInfo.h where required (NFC)

2022-07-22 Thread Fangrui Song via cfe-commits

Author: Sergei Barannikov
Date: 2022-07-22T10:45:02-07:00
New Revision: 37502e042ff007972db0a03dd8c5e293c3219de3

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

LOG: [clang][CodeGen] Only include ABIInfo.h where required (NFC)

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/CodeGen/ABIInfo.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.h
clang/lib/CodeGen/CGObjCRuntime.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/SwiftCallingConv.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h

Removed: 




diff  --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h
index 6214148adab93..fe6cc7a2b1c75 100644
--- a/clang/lib/CodeGen/ABIInfo.h
+++ b/clang/lib/CodeGen/ABIInfo.h
@@ -35,10 +35,6 @@ namespace CodeGen {
   class CodeGenTypes;
   class SwiftABIInfo;
 
-namespace swiftcall {
-  class SwiftAggLowering;
-}
-
   // FIXME: All of this stuff should be part of the target interface
   // somehow. It is currently here because it is not clear how to factor
   // the targets to support this, since the Targets currently live in a

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8c7ee6b078f2e..113c629bf9edc 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10,6 +10,7 @@
 //
 
//===--===//
 
+#include "ABIInfo.h"
 #include "CGCUDARuntime.h"
 #include "CGCXXABI.h"
 #include "CGObjCRuntime.h"

diff  --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index af63e1bddd2d6..59c3f304f59b9 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -22,9 +22,6 @@
 #include "clang/AST/Type.h"
 #include "llvm/IR/Value.h"
 
-// FIXME: Restructure so we don't have to expose so much stuff.
-#include "ABIInfo.h"
-
 namespace llvm {
 class Type;
 class Value;

diff  --git a/clang/lib/CodeGen/CGObjCRuntime.h 
b/clang/lib/CodeGen/CGObjCRuntime.h
index bb27c38db2045..3bd981256f475 100644
--- a/clang/lib/CodeGen/CGObjCRuntime.h
+++ b/clang/lib/CodeGen/CGObjCRuntime.h
@@ -34,7 +34,8 @@ namespace llvm {
 
 namespace clang {
 namespace CodeGen {
-  class CodeGenFunction;
+class CGFunctionInfo;
+class CodeGenFunction;
 }
 
   class FieldDecl;

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 7bc79630d67f0..a8b008b11435c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "CodeGenModule.h"
+#include "ABIInfo.h"
 #include "CGBlocks.h"
 #include "CGCUDARuntime.h"
 #include "CGCXXABI.h"
@@ -32,7 +33,6 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Mangle.h"
-#include "clang/AST/RecordLayout.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/Builtins.h"

diff  --git a/clang/lib/CodeGen/SwiftCallingConv.cpp 
b/clang/lib/CodeGen/SwiftCallingConv.cpp
index 1d712f4fde3cf..8fb24fcecf53c 100644
--- a/clang/lib/CodeGen/SwiftCallingConv.cpp
+++ b/clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -11,9 +11,10 @@
 
//===--===//
 
 #include "clang/CodeGen/SwiftCallingConv.h"
-#include "clang/Basic/TargetInfo.h"
+#include "ABIInfo.h"
 #include "CodeGenModule.h"
 #include "TargetInfo.h"
+#include "clang/Basic/TargetInfo.h"
 
 using namespace clang;
 using namespace CodeGen;

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 8eaed1db8e7d4..e8ee5533104ca 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -443,6 +443,9 @@ static Address emitMergePHI(CodeGenFunction ,
   return Address(PHI, Addr1.getElementType(), Align);
 }
 
+TargetCodeGenInfo::TargetCodeGenInfo(std::unique_ptr Info)
+: Info(std::move(Info)) {}
+
 TargetCodeGenInfo::~TargetCodeGenInfo() = default;
 
 // If someone can figure out a general rule for this, that would be great.

diff  --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index bdd64977b4754..30421612015b6 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -43,10 +43,10 @@ class CGBlockInfo;
 /// codegeneration issues, like target-specific attributes, builtins and so
 /// on.
 class TargetCodeGenInfo {
-  std::unique_ptr Info = nullptr;
+  std::unique_ptr Info;
 
 public:
-  TargetCodeGenInfo(std::unique_ptr Info) : Info(std::move(Info)) {}
+  TargetCodeGenInfo(std::unique_ptr Info);
   virtual ~TargetCodeGenInfo();
 

[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Generating freeze seems an option, just not sure we can easily get all 
locations with this approach.
Anyway, some code comments below.




Comment at: clang/lib/CodeGen/CGCall.cpp:2061
+}
+  }
+  return ArgHasMayBeUndefAttr;

Early exists please.

if (!TargetDecl)
  return false

no ArgHasMayBeUndefAttr is needed, just return true/false, etc.



Comment at: clang/lib/CodeGen/CGCall.cpp:4899
+  val = Builder.CreateFreeze(Addr.getPointer());
+IRCallArgs[FirstIRArg] = val;
 

Style: `Val`, also below.



Comment at: clang/test/CodeGenHIP/maybe_undef-attr-verify.hip:33
+res = __shfl_sync(t, WARP_SIZE, 0);
+}

Note, not necessarily to address: I would have preferred auto generated check 
lines, should not be many and it's easier to see what's going on, IMHO. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130224/new/

https://reviews.llvm.org/D130224

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


[PATCH] D130168: [CUDA] remove duplicate condition

2022-07-22 Thread VitalyR via Phabricator via cfe-commits
VitalyR added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130168/new/

https://reviews.llvm.org/D130168

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


[PATCH] D130322: [clang][CodeGen] Only include ABIInfo.h where required (NFC)

2022-07-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Testing and will push in one minute




Comment at: clang/lib/CodeGen/CGObjCRuntime.h:37
 namespace CodeGen {
+  class CGFunctionInfo;
   class CodeGenFunction;

The style is to remove indentation. I'll fix it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130322/new/

https://reviews.llvm.org/D130322

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


[PATCH] D130279: [clang-doc] Add check for pointer validity

2022-07-22 Thread Paul Kirth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30360d88d422: [clang-doc] Add check for pointer validity 
(authored by paulkirth).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130279/new/

https://reviews.llvm.org/D130279

Files:
  clang-tools-extra/clang-doc/Representation.cpp


Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -33,7 +33,7 @@
 template 
 llvm::Expected>
 reduce(std::vector> ) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no value to reduce");
   std::unique_ptr Merged = std::make_unique(Values[0]->USR);
@@ -95,7 +95,7 @@
 // Dispatch function.
 llvm::Expected>
 mergeInfos(std::vector> ) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no info values to merge");
 


Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -33,7 +33,7 @@
 template 
 llvm::Expected>
 reduce(std::vector> ) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no value to reduce");
   std::unique_ptr Merged = std::make_unique(Values[0]->USR);
@@ -95,7 +95,7 @@
 // Dispatch function.
 llvm::Expected>
 mergeInfos(std::vector> ) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no info values to merge");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 30360d8 - [clang-doc] Add check for pointer validity

2022-07-22 Thread Paul Kirth via cfe-commits

Author: Paul Kirth
Date: 2022-07-22T17:36:30Z
New Revision: 30360d88d42214e75215145c4e73a74aaf93ddfd

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

LOG: [clang-doc] Add check for pointer validity

clang-doc would SEGV when running over the Fuchsia code base.
This patch adds a check to avoid dereferencing potentially null pointers
in the Values vector. These pointers were either never valid or had been
invalidated when the underlying pointer in std::unique_ptr was moved from,
hence making it nullptr within the vector.

Reviewed By: phosek

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

Added: 


Modified: 
clang-tools-extra/clang-doc/Representation.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Representation.cpp 
b/clang-tools-extra/clang-doc/Representation.cpp
index 8c619d2a09632..0a78d8c190db9 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -33,7 +33,7 @@ const SymbolID EmptySID = SymbolID();
 template 
 llvm::Expected>
 reduce(std::vector> ) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no value to reduce");
   std::unique_ptr Merged = std::make_unique(Values[0]->USR);
@@ -95,7 +95,7 @@ void reduceChildren(std::vector ,
 // Dispatch function.
 llvm::Expected>
 mergeInfos(std::vector> ) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no info values to merge");
 



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


  1   2   3   >