[PATCH] D121045: [analyzer][NFC] Merge similar conditional paths

2022-03-07 Thread Balázs Benics via Phabricator via cfe-commits
steakhal requested changes to this revision.
steakhal added a comment.
This revision now requires changes to proceed.

Shadowing potential names is not a good idea.
BTW OpCodes are often abbreviated to `Op` in variable names in this context.




Comment at: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp:110-111
   break;
-if (BO->getOpcode() == BO_Assign) {
-  Ex = BO->getRHS();
-  continue;
-}
-if (BO->getOpcode() == BO_Comma) {
+BinaryOperatorKind BO_AssignOrComma = BO->getOpcode();
+if (BO_AssignOrComma == BO_Assign || BO_AssignOrComma == BO_Comma) {
   Ex = BO->getRHS();




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121045

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


[PATCH] D119172: [pseudo] Implement LRGraph

2022-03-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h:96
+  uint8_t DotPos = 0;
+  uint8_t RuleLength = 0; // the length of rule body.
+};

alextsao1999 wrote:
> Can we add LookaheadSymbol here to implement LR(1)?
we could do that. However, we don't have a plan to implement an `LR(1)` yet, we 
use `SLR(1)`. (though LR(1) is more powerful than SLR(1), the typical 
deterministic LR(1) parser cannot handle the C++ grammar, we need a "general" 
parser GLR which can be able to handle arbitrary context-free grammars).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119172

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


[PATCH] D121089: [pseudo] empty parameter-declaration should be allowed in lambda declarator.

2022-03-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: alextsao1999.
Herald added a project: clang.

This was an oversight, as we did a avoild-nullable modication to
parameter-declaration-clause.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121089

Files:
  clang/lib/Tooling/Syntax/Pseudo/cxx.bnf


Index: clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
===
--- clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
+++ clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
@@ -69,7 +69,7 @@
 lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
 lambda-expression := lambda-introducer < template-parameter-list > 
requires-clause_opt lambda-declarator_opt compound-statement
 lambda-introducer := [ lambda-capture_opt ]
-lambda-declarator := ( parameter-declaration-clause ) decl-specifier-seq_opt 
noexcept-specifier_opt trailing-return-type_opt requires-clause_opt
+lambda-declarator := ( parameter-declaration-clause_opt ) 
decl-specifier-seq_opt noexcept-specifier_opt trailing-return-type_opt 
requires-clause_opt
 lambda-capture := capture-default
 lambda-capture := capture-list
 lambda-capture := capture-default , capture-list


Index: clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
===
--- clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
+++ clang/lib/Tooling/Syntax/Pseudo/cxx.bnf
@@ -69,7 +69,7 @@
 lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
 lambda-expression := lambda-introducer < template-parameter-list > requires-clause_opt lambda-declarator_opt compound-statement
 lambda-introducer := [ lambda-capture_opt ]
-lambda-declarator := ( parameter-declaration-clause ) decl-specifier-seq_opt noexcept-specifier_opt trailing-return-type_opt requires-clause_opt
+lambda-declarator := ( parameter-declaration-clause_opt ) decl-specifier-seq_opt noexcept-specifier_opt trailing-return-type_opt requires-clause_opt
 lambda-capture := capture-default
 lambda-capture := capture-list
 lambda-capture := capture-default , capture-list
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120307: [X86] Add helper enum for ternary intrinsics

2022-03-07 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120307

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


[clang] 242b24c - [clang][modules] NFC: Simplify and clarify test

2022-03-07 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-03-07T10:47:46+01:00
New Revision: 242b24c1849165bedb73fb14c8012d1d63ffd344

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

LOG: [clang][modules] NFC: Simplify and clarify test

This patch simplifies a test that checks only used module map files are 
reported as input files in PCM files.

Instead of using opaque `diff`, this patch uses `clang -module-file-info` and 
`FileCheck` to verify this.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/test/Modules/add-remove-irrelevant-module-map.m

Removed: 
clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap



diff  --git 
a/clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap 
b/clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
deleted file mode 100644
index bf7200f93745b..0
--- a/clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
+++ /dev/null
@@ -1 +0,0 @@
-module a { }

diff  --git 
a/clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap 
b/clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
deleted file mode 100644
index f22b754a9950d..0
--- a/clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
+++ /dev/null
@@ -1 +0,0 @@
-module b { }

diff  --git a/clang/test/Modules/add-remove-irrelevant-module-map.m 
b/clang/test/Modules/add-remove-irrelevant-module-map.m
index 3341d89e6067b..c7ee07763bbb0 100644
--- a/clang/test/Modules/add-remove-irrelevant-module-map.m
+++ b/clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -1,16 +1,30 @@
-// RUN: rm -rf %t
-// RUN: rm -rf %t.mcp
-// RUN: mkdir -p %t
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
 
-// Build without b.modulemap
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t.mcp -fdisable-module-hash 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
-// RUN: cp %t.mcp/a.pcm %t/a.pcm
+//--- a.modulemap
+module a {}
 
-// Build with b.modulemap
-// RUN: rm -rf %t.mcp
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t.mcp -fdisable-module-hash 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
-// RUN: not 
diff  %t.mcp/a.pcm %t/a.pcm
+//--- b.modulemap
+module b {}
 
+//--- test-simple.m
 // expected-no-diagnostics
-
 @import a;
+
+// Build without b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap %t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-without-b
+
+// Build with b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap 
%t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-with-b
+
+// Neither PCM file considers 'b.modulemap' an input:
+//
+// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s
+// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s
+// CHECK-NOT: Input file: {{.*}}/b.modulemap



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


[clang] b45888e - [clang][modules] Report module maps affecting `no_undeclared_includes` modules

2022-03-07 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-03-07T10:47:46+01:00
New Revision: b45888e959ad2d6562b8d321166e6387facdd412

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

LOG: [clang][modules] Report module maps affecting `no_undeclared_includes` 
modules

Since D106876, PCM files don't report module maps as input files unless they 
contributed to the compilation.

Reporting only module maps of (transitively) imported modules is not enough, 
though. For modules marked with `[no_undeclared_includes]`, other module maps 
affect the compilation by introducing anti-dependencies.

This patch makes sure such module maps are being reported as input files.

Depends on D120463.

Reviewed By: dexonsmith

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

Added: 


Modified: 
clang/include/clang/Basic/Module.h
clang/lib/Basic/Module.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/Modules/add-remove-irrelevant-module-map.m

Removed: 




diff  --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 5b97044524553..3d1af45c48f3d 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -371,6 +371,10 @@ class Module {
   /// The set of use declarations that have yet to be resolved.
   SmallVector UnresolvedDirectUses;
 
+  /// When \c NoUndeclaredIncludes is true, the set of modules this module 
tried
+  /// to import but didn't because they are not direct uses.
+  llvm::SmallSetVector UndeclaredUses;
+
   /// A library or framework to link against when an entity from this
   /// module is used.
   struct LinkLibrary {
@@ -601,7 +605,7 @@ class Module {
 
   /// Determine whether this module has declared its intention to
   /// directly use another module.
-  bool directlyUses(const Module *Requested) const;
+  bool directlyUses(const Module *Requested);
 
   /// Add the given feature requirement to the list of features
   /// required by this module.

diff  --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 09bd3251fea0c..17b83184abb66 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -267,7 +267,7 @@ ArrayRef 
Module::getTopHeaders(FileManager &FileMgr) {
   return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
 }
 
-bool Module::directlyUses(const Module *Requested) const {
+bool Module::directlyUses(const Module *Requested) {
   auto *Top = getTopLevelModule();
 
   // A top-level module implicitly uses itself.
@@ -282,6 +282,9 @@ bool Module::directlyUses(const Module *Requested) const {
   if (!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t")
 return true;
 
+  if (NoUndeclaredIncludes)
+UndeclaredUses.insert(Requested);
+
   return false;
 }
 

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index f0ecfe413c31a..63fcc1eaa5509 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -164,8 +164,8 @@ namespace {
 std::set GetAllModuleMaps(const HeaderSearch &HS,
  Module *RootModule) {
   std::set ModuleMaps{};
-  std::set ProcessedModules;
-  SmallVector ModulesToProcess{RootModule};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
 
   SmallVector FilesByUID;
   HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
@@ -209,6 +209,11 @@ std::set GetAllModuleMaps(const 
HeaderSearch &HS,
   }
   ModulesToProcess.push_back(ImportedModule);
 }
+
+for (const Module *UndeclaredModule : CurrentModule->UndeclaredUses)
+  if (UndeclaredModule &&
+  ProcessedModules.find(UndeclaredModule) == ProcessedModules.end())
+ModulesToProcess.push_back(UndeclaredModule);
   }
 
   return ModuleMaps;
@@ -2861,6 +2866,8 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
 // Might be unnecessary as use declarations are only used to build the
 // module itself.
 
+// TODO: Consider serializing undeclared uses of modules.
+
 // Emit the link libraries.
 for (const auto &LL : Mod->LinkLibraries) {
   RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY,

diff  --git a/clang/test/Modules/add-remove-irrelevant-module-map.m 
b/clang/test/Modules/add-remove-irrelevant-module-map.m
index c7ee07763bbb0..c0b081d8b52d0 100644
--- a/clang/test/Modules/add-remove-irrelevant-module-map.m
+++ b/clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -25,6 +25,34 @@
 
 // Neither PCM file considers 'b.modulemap' an input:
 //
-// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s
-// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s
-// CHECK-NOT: Input file: {{.*}}/b.modulemap
+// RUN: %clang_cc1 -mod

[PATCH] D120463: [clang][modules] NFC: Simplify and clarify test

2022-03-07 Thread Jan Svoboda 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 rG242b24c18491: [clang][modules] NFC: Simplify and clarify 
test (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120463

Files:
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-module-map.m


Index: clang/test/Modules/add-remove-irrelevant-module-map.m
===
--- clang/test/Modules/add-remove-irrelevant-module-map.m
+++ clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -1,16 +1,30 @@
-// RUN: rm -rf %t
-// RUN: rm -rf %t.mcp
-// RUN: mkdir -p %t
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
 
-// Build without b.modulemap
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t.mcp -fdisable-module-hash 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
-// RUN: cp %t.mcp/a.pcm %t/a.pcm
+//--- a.modulemap
+module a {}
 
-// Build with b.modulemap
-// RUN: rm -rf %t.mcp
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t.mcp -fdisable-module-hash 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap 
-fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
-// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+//--- b.modulemap
+module b {}
 
+//--- test-simple.m
 // expected-no-diagnostics
-
 @import a;
+
+// Build without b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap %t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-without-b
+
+// Build with b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap 
%t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-with-b
+
+// Neither PCM file considers 'b.modulemap' an input:
+//
+// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s
+// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s
+// CHECK-NOT: Input file: {{.*}}/b.modulemap
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
+++ /dev/null
@@ -1 +0,0 @@
-module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
+++ /dev/null
@@ -1 +0,0 @@
-module a { }


Index: clang/test/Modules/add-remove-irrelevant-module-map.m
===
--- clang/test/Modules/add-remove-irrelevant-module-map.m
+++ clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -1,16 +1,30 @@
-// RUN: rm -rf %t
-// RUN: rm -rf %t.mcp
-// RUN: mkdir -p %t
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
 
-// Build without b.modulemap
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
-// RUN: cp %t.mcp/a.pcm %t/a.pcm
+//--- a.modulemap
+module a {}
 
-// Build with b.modulemap
-// RUN: rm -rf %t.mcp
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
-// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+//--- b.modulemap
+module b {}
 
+//--- test-simple.m
 // expected-no-diagnostics
-
 @import a;
+
+// Build without b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap %t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-without-b
+
+// Build with b.modulemap:
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap %t/test-simple.m -verify
+// RUN: mv %t/cache %t/cache-with-b
+
+// Neither PCM file considers 'b.modulemap' an input:
+//
+// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s
+// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s
+// CHECK-NOT: Input file: {{.*}}/b.modulemap
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
=

[PATCH] D120464: [clang][modules] Report module maps affecting `no_undeclared_includes` modules

2022-03-07 Thread Jan Svoboda 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 rGb45888e959ad: [clang][modules] Report module maps affecting 
`no_undeclared_includes` modules (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120464

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/Basic/Module.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/add-remove-irrelevant-module-map.m

Index: clang/test/Modules/add-remove-irrelevant-module-map.m
===
--- clang/test/Modules/add-remove-irrelevant-module-map.m
+++ clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -25,6 +25,34 @@
 
 // Neither PCM file considers 'b.modulemap' an input:
 //
-// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s
-// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s
-// CHECK-NOT: Input file: {{.*}}/b.modulemap
+// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s --check-prefix=CHECK-B
+// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s --check-prefix=CHECK-B
+// CHECK-B-NOT: Input file: {{.*}}/b.modulemap
+
+//--- c.modulemap
+module c [no_undeclared_includes] { header "c.h" }
+
+//--- c.h
+#if __has_include("d.h") // This should use 'd.modulemap' in order to determine that 'd.h'
+ // doesn't exist for 'c' because of its '[no_undeclared_includes]'.
+#endif
+
+//--- d.modulemap
+module d { header "d.h" }
+
+//--- d.h
+// empty
+
+//--- test-no-undeclared-includes.m
+// expected-no-diagnostics
+@import c;
+
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fdisable-module-hash \
+// RUN:   -fmodule-map-file=%t/c.modulemap -fmodule-map-file=%t/d.modulemap \
+// RUN:   %t/test-no-undeclared-includes.m -verify
+
+// The PCM file considers 'd.modulemap' an input because it affects the compilation,
+// although it doesn't describe the built module or its imports.
+//
+// RUN: %clang_cc1 -module-file-info %t/cache/c.pcm | FileCheck %s --check-prefix=CHECK-D -DDIR=%t
+// CHECK-D: Input file: [[DIR]]/d.modulemap
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -164,8 +164,8 @@
 std::set GetAllModuleMaps(const HeaderSearch &HS,
  Module *RootModule) {
   std::set ModuleMaps{};
-  std::set ProcessedModules;
-  SmallVector ModulesToProcess{RootModule};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
 
   SmallVector FilesByUID;
   HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
@@ -209,6 +209,11 @@
   }
   ModulesToProcess.push_back(ImportedModule);
 }
+
+for (const Module *UndeclaredModule : CurrentModule->UndeclaredUses)
+  if (UndeclaredModule &&
+  ProcessedModules.find(UndeclaredModule) == ProcessedModules.end())
+ModulesToProcess.push_back(UndeclaredModule);
   }
 
   return ModuleMaps;
@@ -2861,6 +2866,8 @@
 // Might be unnecessary as use declarations are only used to build the
 // module itself.
 
+// TODO: Consider serializing undeclared uses of modules.
+
 // Emit the link libraries.
 for (const auto &LL : Mod->LinkLibraries) {
   RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY,
Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -267,7 +267,7 @@
   return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
 }
 
-bool Module::directlyUses(const Module *Requested) const {
+bool Module::directlyUses(const Module *Requested) {
   auto *Top = getTopLevelModule();
 
   // A top-level module implicitly uses itself.
@@ -282,6 +282,9 @@
   if (!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t")
 return true;
 
+  if (NoUndeclaredIncludes)
+UndeclaredUses.insert(Requested);
+
   return false;
 }
 
Index: clang/include/clang/Basic/Module.h
===
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -371,6 +371,10 @@
   /// The set of use declarations that have yet to be resolved.
   SmallVector UnresolvedDirectUses;
 
+  /// When \c NoUndeclaredIncludes is true, the set of modules this module tried
+  /// to import but didn't because they are not direct uses.
+  llvm::SmallSetVector UndeclaredUses;
+
   /// A library or framework to link against when an entity from this
   /// module is used.
   struct LinkLibrary {
@@ -601,7 +605,7 @@
 
   /// Determine whether this module has declared its intention to
   /// directly use another module.

[PATCH] D120902: [clang-format] Fix assertion failure/crash with `AllowShortFunctionsOnASingleLine: Inline/InlineOnly`.

2022-03-07 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius updated this revision to Diff 413380.
curdeius added a comment.

Safer condition.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120902

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12639,6 +12639,13 @@
"};",
MergeInlineOnly);
   verifyFormat("int f() {}", MergeInlineOnly);
+  // https://llvm.org/PR54147
+  verifyFormat("auto lambda = []() {\n"
+   "  // comment\n"
+   "  f();\n"
+   "  g();\n"
+   "};",
+   MergeInlineOnly);
 
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -310,6 +310,8 @@
   for (; J != AnnotatedLines.begin(); --J)
 if ((*J)->Level < TheLine->Level)
   break;
+  if ((*J)->Level >= TheLine->Level)
+return false;
 
   // Check if the found line starts a record.
   const FormatToken *LastNonComment = (*J)->Last;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12639,6 +12639,13 @@
"};",
MergeInlineOnly);
   verifyFormat("int f() {}", MergeInlineOnly);
+  // https://llvm.org/PR54147
+  verifyFormat("auto lambda = []() {\n"
+   "  // comment\n"
+   "  f();\n"
+   "  g();\n"
+   "};",
+   MergeInlineOnly);
 
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -310,6 +310,8 @@
   for (; J != AnnotatedLines.begin(); --J)
 if ((*J)->Level < TheLine->Level)
   break;
+  if ((*J)->Level >= TheLine->Level)
+return false;
 
   // Check if the found line starts a record.
   const FormatToken *LastNonComment = (*J)->Last;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121092: [pseudo] Strip comments for TokenStream.

2022-03-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: alextsao1999.
Herald added a project: clang.

Add a utility function to strip comments from a "raw" tokenstream. The
derived stream will be fed to the GLR parser (for early testing).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121092

Files:
  clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
  clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
  clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp


Index: clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
===
--- clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
+++ clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
@@ -23,11 +23,16 @@
 
 using testing::_;
 using testing::ElementsAre;
+using testing::ElementsAreArray;
 using testing::Matcher;
 using testing::Pair;
 using testing::StrEq;
 using Chunk = PPStructure::Chunk;
 
+MATCHER_P2(token, Text, Kind, "") {
+  return arg.Kind == Kind && arg.text() == Text;
+}
+
 MATCHER_P2(tokensAre, TS, Tokens, "tokens are " + std::string(Tokens)) {
   std::vector Texts;
   for (const Token &Tok : TS.tokens(arg.Tokens))
@@ -146,6 +151,22 @@
   EXPECT_EQ(0u, X.End.Tokens.size());
 }
 
+TEST(Preprocessor, StripComments) {
+  LangOptions Opts;
+  std::string Code = R"cpp(
+  // comment
+  int;
+)cpp";
+  TokenStream Raw = cook(lex(Code, Opts), Opts);
+  TokenStream Stripped = stripComments(Raw);
+  EXPECT_THAT(Raw.tokens(), ElementsAreArray({token("// comment", 
tok::comment),
+  token("int", tok::kw_int),
+  token(";", tok::semi)}));
+
+  EXPECT_THAT(Stripped.tokens(), ElementsAreArray({token("int", tok::kw_int),
+   token(";", tok::semi)}));
+}
+
 } // namespace
 } // namespace pseudo
 } // namespace syntax
Index: clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
===
--- clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
+++ clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
@@ -201,6 +201,17 @@
 OSTREAM_DUMP(PPStructure::Code)
 #undef OSTREAM_DUMP
 
+TokenStream stripComments(const TokenStream &Input) {
+  TokenStream Out;
+  for (const Token &T : Input.tokens()) {
+if (T.Kind == tok::comment)
+  continue;
+Out.push(T);
+  }
+  Out.finalize();
+  return Out;
+}
+
 } // namespace pseudo
 } // namespace syntax
 } // namespace clang
Index: clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
===
--- clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
+++ clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
@@ -141,6 +141,9 @@
   llvm::Optional ConditionalVariant;
 };
 
+/// Drops comment tokens.
+TokenStream stripComments(const TokenStream &);
+
 } // namespace pseudo
 } // namespace syntax
 } // namespace clang


Index: clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
===
--- clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
+++ clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
@@ -23,11 +23,16 @@
 
 using testing::_;
 using testing::ElementsAre;
+using testing::ElementsAreArray;
 using testing::Matcher;
 using testing::Pair;
 using testing::StrEq;
 using Chunk = PPStructure::Chunk;
 
+MATCHER_P2(token, Text, Kind, "") {
+  return arg.Kind == Kind && arg.text() == Text;
+}
+
 MATCHER_P2(tokensAre, TS, Tokens, "tokens are " + std::string(Tokens)) {
   std::vector Texts;
   for (const Token &Tok : TS.tokens(arg.Tokens))
@@ -146,6 +151,22 @@
   EXPECT_EQ(0u, X.End.Tokens.size());
 }
 
+TEST(Preprocessor, StripComments) {
+  LangOptions Opts;
+  std::string Code = R"cpp(
+  // comment
+  int;
+)cpp";
+  TokenStream Raw = cook(lex(Code, Opts), Opts);
+  TokenStream Stripped = stripComments(Raw);
+  EXPECT_THAT(Raw.tokens(), ElementsAreArray({token("// comment", tok::comment),
+  token("int", tok::kw_int),
+  token(";", tok::semi)}));
+
+  EXPECT_THAT(Stripped.tokens(), ElementsAreArray({token("int", tok::kw_int),
+   token(";", tok::semi)}));
+}
+
 } // namespace
 } // namespace pseudo
 } // namespace syntax
Index: clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
===
--- clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
+++ clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
@@ -201,6 +201,17 @@
 OSTREAM_DUMP(PPStructure::Code)
 #undef OSTREAM_DUMP
 
+TokenStream stripComments(const TokenStream &Input) {
+  TokenStream Out;
+  for (const Token &T : Input.tokens()) {
+if (T.Kind == tok::comment)
+  continue;
+ 

[PATCH] D120857: WIP [randstruct] Create basis for unit test module

2022-03-07 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 413383.
void added a comment.

Don't warn on multiple attributes. Instead, use the last one to indicate 
whether to randomize the layout or not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120857

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/Randstruct.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Randstruct.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/RandstructTest.cpp

Index: clang/unittests/AST/RandstructTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/RandstructTest.cpp
@@ -0,0 +1,435 @@
+//===- unittest/AST/RandstructTest.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
+//
+//===--===//
+//
+// This file contains tests for Clang's structure field layout randomization.
+//
+//===--===//
+
+/*
+ * Build this test suite by running `make ASTTests` in the build folder.
+ *
+ * Run this test suite by running the following in the build folder:
+ * ` ./tools/clang/unittests/AST/ASTTests
+ * --gtest_filter=StructureLayoutRandomization*`
+ */
+
+#include "clang/AST/Randstruct.h"
+#include "gtest/gtest.h"
+
+#include "DeclMatcher.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Testing/CommandLineArgs.h"
+#include "clang/Tooling/Tooling.h"
+
+#include 
+
+using namespace clang::randstruct;
+
+namespace clang {
+namespace ast_matchers {
+
+static std::unique_ptr makeAST(const std::string &SourceCode,
+TestLanguage Lang) {
+  std::vector Args = getCommandLineArgsForTesting(Lang);
+  Args.push_back("-frandstruct-seed=1234567890abcdef");
+  auto AST = tooling::buildASTFromCodeWithArgs(SourceCode, Args, "input.cc");
+  return AST;
+}
+
+static RecordDecl *getRecordDeclFromAST(const ASTContext &C,
+const std::string &Name) {
+  return FirstDeclMatcher().match(C.getTranslationUnitDecl(),
+  recordDecl(hasName(Name)));
+}
+
+static std::vector getFieldNamesFromRecord(const RecordDecl *RD) {
+  std::vector Fields;
+  Fields.reserve(8);
+  for (auto *Field : RD->fields())
+Fields.push_back(Field->getNameAsString());
+  return Fields;
+}
+
+static bool isSubsequence(const std::vector &Seq,
+  const std::vector &Subseq) {
+  const auto SeqLen = Seq.size();
+  const auto SubLen = Subseq.size();
+
+  auto IsSubseq = false;
+  for (auto I = 0u; I < SeqLen; ++I) {
+if (Seq[I] == Subseq[0]) {
+  IsSubseq = true;
+  for (auto J = 0u; J + I < SeqLen && J < SubLen; ++J) {
+if (Seq[J + I] != Subseq[J]) {
+  IsSubseq = false;
+  break;
+}
+  }
+}
+  }
+  return IsSubseq;
+}
+
+#define RANDSTRUCT_TEST_SUITE_TEST StructureLayoutRandomizationTestSuiteTest
+
+TEST(RANDSTRUCT_TEST_SUITE_TEST, CanDetermineIfSubsequenceExists) {
+  const std::vector S0 = {"a", "b", "c", "d"};
+  ASSERT_TRUE(isSubsequence(S0, {"b", "c"}));
+  ASSERT_TRUE(isSubsequence(S0, {"a", "b", "c", "d"}));
+  ASSERT_TRUE(isSubsequence(S0, {"b", "c", "d"}));
+  ASSERT_TRUE(isSubsequence(S0, {"a"}));
+  ASSERT_FALSE(isSubsequence(S0, {"a", "d"}));
+}
+
+#define RANDSTRUCT_TEST StructureLayoutRandomization
+
+TEST(RANDSTRUCT_TEST, UnmarkedStructuresAreNotRandomized) {
+  std::string Code =
+  R"(
+struct dont_randomize_me {
+int potato;
+float tomato;
+long cabbage;
+};
+)";
+
+  const auto AST = makeAST(Code, Lang_C99);
+  const auto *RD =
+  getRecordDeclFromAST(AST->getASTContext(), "dont_randomize_me");
+  const std::vector Expected = {"potato", "tomato", "cabbage"};
+  const std::vector Actual = getFieldNamesFromRecord(RD);
+
+  ASSERT_EQ(Expected, Actual);
+}
+
+TEST(RANDSTRUCT_TEST, StructuresCanBeMarkedWithRandomizeLayoutAttr) {
+  std::string Code =
+  

[PATCH] D120465: [clang][deps] Generate necessary "-fmodule-map-file=" arguments, disable implicit module maps

2022-03-07 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 413384.
jansvoboda11 added a comment.

Review feedback (add TODO & rename function)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120465

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-inferred.m
  clang/test/ClangScanDeps/modules-no-undeclared-includes.c
  clang/test/ClangScanDeps/modules-pch.c

Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -26,6 +26,7 @@
 // CHECK-PCH-NEXT: "-cc1"
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModCommon1"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -43,6 +44,7 @@
 // CHECK-PCH-NEXT: "-cc1"
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModCommon2"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -66,6 +68,7 @@
 // CHECK-PCH:  "-emit-module"
 // CHECK-PCH:  "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_2]]/ModCommon2-{{.*}}.pcm"
 // CHECK-PCH:  "-fmodules"
+// CHECK-PCH-NOT:  "-fimplicit-module-maps"
 // CHECK-PCH:  "-fmodule-name=ModPCH"
 // CHECK-PCH:  "-fno-implicit-modules"
 // CHECK-PCH:],
@@ -139,6 +142,7 @@
 // CHECK-TU-NEXT:   "command-line": [
 // CHECK-TU-NEXT: "-cc1",
 // CHECK-TU:  "-emit-module",
+// CHECK-TU-NOT:  "-fimplicit-module-maps",
 // CHECK-TU:  "-fmodule-name=ModTU",
 // CHECK-TU:  "-fno-implicit-modules",
 // CHECK-TU:],
@@ -202,6 +206,7 @@
 // CHECK-TU-WITH-COMMON-NEXT: "-cc1",
 // CHECK-TU-WITH-COMMON:  "-emit-module",
 // CHECK-TU-WITH-COMMON:  "-fmodule-file=[[PREFIX]]/build/{{.*}}/ModCommon1-{{.*}}.pcm",
+// CHECK-TU-WITH-COMMON-NOT:  "-fimplicit-module-maps",
 // CHECK-TU-WITH-COMMON:  "-fmodule-name=ModTUWithCommon",
 // CHECK-TU-WITH-COMMON:  "-fno-implicit-modules",
 // CHECK-TU-WITH-COMMON:],
Index: clang/test/ClangScanDeps/modules-no-undeclared-includes.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-no-undeclared-includes.c
@@ -0,0 +1,72 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: split-file %s %t
+
+//--- undeclared/module.modulemap
+module Undeclared { header "undeclared.h" }
+
+//--- undeclared/undeclared.h
+
+//--- module.modulemap
+module User [no_undeclared_includes] { header "user.h" }
+
+//--- user.h
+#if __has_include("undeclared.h")
+#error Unreachable. Undeclared comes from a module that's not 'use'd, meaning the compiler should pretend it doesn't exist.
+#endif
+
+//--- test.c
+#include "user.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -IDIR/undeclared -c DIR/test.c -o DIR/test.o",
+  "file": "DIR/test.c"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
+// RUN:   -generate-modules-path-args -module-files-dir %t/build > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%t
+
+// CHECK:{
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/undeclared/module.modulemap"
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT: "[[PREFIX]]/undeclared/module.modulemap",
+// CHECK-NEXT: "[[PREFIX]]/user.h"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "name": "User"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}"
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}"
+// CHECK-NEXT:   "module-name": "User"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "comman

[PATCH] D118915: [clang][deps] Generate '-fmodule-file=' only for direct dependencies

2022-03-07 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 413386.
jansvoboda11 added a comment.
Herald added a project: All.

Rebase on top of D120465 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118915

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules-pch.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -298,10 +298,7 @@
 
 ID.CommandLine = GenerateModulesPathArgs
  ? FD.getCommandLine(
-   [&](ModuleID MID) { return lookupPCMPath(MID); },
-   [&](ModuleID MID) -> const ModuleDeps & {
- return lookupModuleDeps(MID);
-   })
+   [&](ModuleID MID) { return lookupPCMPath(MID); })
  : FD.getCommandLineWithoutModulePaths();
 
 Inputs.push_back(std::move(ID));
@@ -336,10 +333,7 @@
   {"command-line",
GenerateModulesPathArgs
? MD.getCanonicalCommandLine(
- [&](ModuleID MID) { return lookupPCMPath(MID); },
- [&](ModuleID MID) -> const ModuleDeps & {
-   return lookupModuleDeps(MID);
- })
+ [&](ModuleID MID) { return lookupPCMPath(MID); })
: MD.getCanonicalCommandLineWithoutModulePaths()},
   };
   OutModules.push_back(std::move(O));
@@ -369,12 +363,16 @@
   StringRef lookupPCMPath(ModuleID MID) {
 auto PCMPath = PCMPaths.insert({MID, ""});
 if (PCMPath.second)
-  PCMPath.first->second = constructPCMPath(lookupModuleDeps(MID));
+  PCMPath.first->second = constructPCMPath(MID);
 return PCMPath.first->second;
   }
 
   /// Construct a path for the explicitly built PCM.
-  std::string constructPCMPath(const ModuleDeps &MD) const {
+  std::string constructPCMPath(ModuleID MID) const {
+auto MDIt = Modules.find(IndexedModuleID{MID, 0});
+assert(MDIt != Modules.end());
+const ModuleDeps &MD = MDIt->second;
+
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
 
 SmallString<256> ExplicitPCMPath(
@@ -385,12 +383,6 @@
 return std::string(ExplicitPCMPath);
   }
 
-  const ModuleDeps &lookupModuleDeps(ModuleID MID) {
-auto I = Modules.find(IndexedModuleID{MID, 0});
-assert(I != Modules.end());
-return I->second;
-  };
-
   struct IndexedModuleID {
 ModuleID ID;
 mutable size_t InputIndex;
Index: clang/test/ClangScanDeps/modules-pch.c
===
--- clang/test/ClangScanDeps/modules-pch.c
+++ clang/test/ClangScanDeps/modules-pch.c
@@ -97,7 +97,6 @@
 // CHECK-PCH:  "-fno-implicit-modules",
 // CHECK-PCH-NEXT: "-fno-implicit-module-maps",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_1]]/ModCommon1-{{.*}}.pcm",
-// CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_COMMON_2]]/ModCommon2-{{.*}}.pcm",
 // CHECK-PCH-NEXT: "-fmodule-file=[[PREFIX]]/build/[[HASH_MOD_PCH]]/ModPCH-{{.*}}.pcm"
 // CHECK-PCH-NEXT:   ],
 // CHECK-PCH-NEXT:   "file-deps": [
Index: clang/test/ClangScanDeps/modules-full.cpp
===
--- clang/test/ClangScanDeps/modules-full.cpp
+++ clang/test/ClangScanDeps/modules-full.cpp
@@ -169,9 +169,7 @@
 // CHECK:  "-fno-implicit-modules"
 // CHECK-NEXT: "-fno-implicit-module-maps"
 // CHECK-NO-ABS-NOT:   "-fmodule-file={{.*}}"
-// CHECK-ABS-NEXT: "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[HASH_H2_DINCLUDE]]/header2-{{[A-Z0-9]+}}.pcm"
 // CHECK-ABS-NEXT: "-fmodule-file=[[PREFIX]]/module-cache{{(_clangcl)?}}/[[HASH_H1_DINCLUDE]]/header1-{{[A-Z0-9]+}}.pcm"
-// CHECK-CUSTOM-NEXT:  "-fmodule-file=[[PREFIX]]/custom/[[HASH_H2_DINCLUDE]]/header2-{{[A-Z0-9]+}}.pcm"
 // CHECK-CUSTOM-NEXT:  "-fmodule-file=[[PREFIX]]/custom/[[HASH_H1_DINCLUDE]]/header1-{{[A-Z0-9]+}}.pcm"
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "file-deps": [
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -87,8 +87,7 @@
 }
 
 std::vecto

[PATCH] D120474: [clang][deps] Remove '-fmodules-cache-path=' arguments

2022-03-07 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 413387.
jansvoboda11 added a comment.

Update TODO instead of removing it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120474

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-inferred-explicit-build.m
  clang/tools/clang-scan-deps/ClangScanDeps.cpp


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -374,11 +374,11 @@
 const ModuleDeps &MD = MDIt->second;
 
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
+StringRef ModuleCachePath = llvm::sys::path::parent_path(
+llvm::sys::path::parent_path(MD.ImplicitModulePCMPath));
 
-SmallString<256> ExplicitPCMPath(
-!ModuleFilesDir.empty()
-? ModuleFilesDir
-: MD.BuildInvocation.getHeaderSearchOpts().ModuleCachePath);
+SmallString<256> ExplicitPCMPath(!ModuleFilesDir.empty() ? ModuleFilesDir
+ : 
ModuleCachePath);
 llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
 return std::string(ExplicitPCMPath);
   }
Index: clang/test/ClangScanDeps/modules-inferred-explicit-build.m
===
--- clang/test/ClangScanDeps/modules-inferred-explicit-build.m
+++ clang/test/ClangScanDeps/modules-inferred-explicit-build.m
@@ -12,7 +12,7 @@
 // RUN: %python %S/../../utils/module-deps-to-rsp.py %t.db --tu-index=0 > 
%t.tu.rsp
 // RUN: %clang @%t.inferred.cc1.rsp -pedantic -Werror
 // RUN: %clang @%t.system.cc1.rsp -pedantic -Werror
-// RUN: %clang @%t.tu.rsp -pedantic -Werror -Wno-unused-command-line-argument
+// RUN: %clang @%t.tu.rsp -pedantic -Werror
 
 #include 
 #include 
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -51,6 +51,7 @@
 
   CI.getLangOpts()->ImplicitModules = false;
   CI.getHeaderSearchOpts().ImplicitModuleMaps = false;
+  CI.getHeaderSearchOpts().ModuleCachePath.clear();
 
   // Report the prebuilt modules this module uses.
   for (const auto &PrebuiltModule : Deps.PrebuiltModuleDeps)
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -31,7 +31,13 @@
   getAdditionalArgsWithoutModulePaths();
   Args.insert(Args.end(), AdditionalArgs.begin(), AdditionalArgs.end());
 
-  // TODO: Filter out implicit modules leftovers (e.g. 
"-fmodules-cache-path=").
+  // This argument is unused in explicit compiles.
+  llvm::erase_if(Args, [](const std::string &Arg) {
+return Arg.find("-fmodules-cache-path=") == 0;
+  });
+
+  // TODO: Filter out the remaining implicit modules leftovers
+  // (e.g. "-fmodules-prune-interval=" or "-fmodules-prune-after=").
 
   return Args;
 }


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -374,11 +374,11 @@
 const ModuleDeps &MD = MDIt->second;
 
 StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
+StringRef ModuleCachePath = llvm::sys::path::parent_path(
+llvm::sys::path::parent_path(MD.ImplicitModulePCMPath));
 
-SmallString<256> ExplicitPCMPath(
-!ModuleFilesDir.empty()
-? ModuleFilesDir
-: MD.BuildInvocation.getHeaderSearchOpts().ModuleCachePath);
+SmallString<256> ExplicitPCMPath(!ModuleFilesDir.empty() ? ModuleFilesDir
+ : ModuleCachePath);
 llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
 return std::string(ExplicitPCMPath);
   }
Index: clang/test/ClangScanDeps/modules-inferred-explicit-build.m
===
--- clang/test/ClangScanDeps/modules-inferred-explicit-build.m
+++ clang/test/ClangScanDeps/modules-inferred-explicit-build.m
@@ -12,7 +12,7 @@
 // RUN: %python %S/../../utils/module-deps-to-rsp.py %t.db --tu-index=0 > %t.tu.rsp
 // RUN: %clang @%t.inferred.cc1.rsp -pedantic -Werror
 // RUN: %clang @%t.system.cc1.rsp -pedantic -Werror
-// RUN: %clang @%t.tu.rsp -pedantic -Werror -Wno-unused-command-line-argument
+// RUN: %clang @%t.tu.rsp -pedan

[PATCH] D114382: [clang] Fix wrong -Wunused-local-typedef warning within a template function

2022-03-07 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.
Herald added a project: All.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


[PATCH] D120369: [analyzer] Add more propagations to Taint analysis

2022-03-07 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 413388.
gamesh411 added a comment.
Herald added a project: All.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120369

Files:
  clang/docs/analyzer/checkers.rst
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/test/Analysis/taint-generic.c

Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -1,20 +1,26 @@
-// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast -verify %s \
+// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
+// RUN:   -Wno-incompatible-library-redeclaration -verify %s \
 // RUN:   -analyzer-checker=alpha.security.taint \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=alpha.security.ArrayBoundV2 \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
 
-// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast -verify %s \
+// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
+// RUN:   -Wno-incompatible-library-redeclaration -verify %s \
 // RUN:   -DFILE_IS_STRUCT \
 // RUN:   -analyzer-checker=alpha.security.taint \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=alpha.security.ArrayBoundV2 \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
 
-// RUN: not %clang_analyze_cc1 -Wno-pointer-to-int-cast -verify %s \
+// RUN: not %clang_analyze_cc1 -Wno-pointer-to-int-cast \
+// RUN:   -Wno-incompatible-library-redeclaration -verify %s \
 // RUN:   -analyzer-checker=alpha.security.taint \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=justguessit \
 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-FILE
@@ -24,8 +30,10 @@
 // CHECK-INVALID-FILE-SAME:that expects a valid filename instead of
 // CHECK-INVALID-FILE-SAME:'justguessit'
 
-// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN: not %clang_analyze_cc1 -Wno-incompatible-library-redeclaration \
+// RUN:   -verify %s \
 // RUN:   -analyzer-checker=alpha.security.taint \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-ill-formed.yaml \
 // RUN:   2>&1 | FileCheck -DMSG=%errc_EINVAL %s -check-prefix=CHECK-ILL-FORMED
@@ -34,8 +42,10 @@
 // CHECK-ILL-FORMED-SAME:'alpha.security.taint.TaintPropagation:Config',
 // CHECK-ILL-FORMED-SAME:that expects a valid yaml file: [[MSG]]
 
-// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN: not %clang_analyze_cc1 -Wno-incompatible-library-redeclaration \
+// RUN:   -verify %s \
 // RUN:   -analyzer-checker=alpha.security.taint \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-invalid-arg.yaml \
 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-ARG
@@ -46,6 +56,9 @@
 // CHECK-INVALID-ARG-SAME:rules greater or equal to -1
 
 typedef long long rsize_t;
+void clang_analyzer_isTainted_char(char);
+void clang_analyzer_isTainted_charp(char*);
+void clang_analyzer_isTainted_int(int);
 
 int scanf(const char *restrict format, ...);
 char *gets(char *str);
@@ -60,13 +73,18 @@
 #endif
 
 #define bool _Bool
+#define NULL (void*)0
 
 char *getenv(const char *name);
+
+FILE *fopen(const char *name, const char *mode);
+
 int fscanf(FILE *restrict stream, const char *restrict format, ...);
 int sprintf(char *str, const char *format, ...);
 void setproctitle(const char *fmt, ...);
 void setproctitle_init(int argc, char *argv[], char *envp[]);
 typedef __typeof(sizeof(int)) size_t;
+typedef signed long long ssize_t;
 
 // Define string functions. Use builtin for some of them. They all default to
 // the processing in the taint checker.
@@ -388,7 +406,6 @@
   return system(c); // expected-warning {{Untrusted data is passed to a system call}}
 }
 
-typedef signed long long ssize_t;
 ssize_t readlink(const char *path, char *buf, size_t bufsiz);
 int testReadlink(char *path, char *buf, size_t bufsiz) {
   ssize_t s = readlink(path, buf, bufsiz);
@@ -463,6 +480,510 @@
   return system(buf); // expected-warning {{Untrusted data is passed to a system call}}
 }
 
+int fscanf_s(FILE *stream, const char *format, ...);
+void testFscanf_s(const char *fname, int *d) {
+  FILE *f = fopen(fname, "r");
+  fscanf_s(f, "%d", d);
+  clang_analyzer_isTainted_int(*d); // expected-warning {{YES}}
+}
+
+int fr

[clang] 2d26f16 - [clang][modules] Fix failing test

2022-03-07 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-03-07T11:21:21+01:00
New Revision: 2d26f163f60ea4a466584a2347ccc09fc1595c76

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

LOG: [clang][modules] Fix failing test

This test started failing on Windows after 
b45888e959ad2d6562b8d321166e6387facdd412 due to path separators not matching up.

Added: 


Modified: 
clang/test/Modules/add-remove-irrelevant-module-map.m

Removed: 




diff  --git a/clang/test/Modules/add-remove-irrelevant-module-map.m 
b/clang/test/Modules/add-remove-irrelevant-module-map.m
index c0b081d8b52d0..25c45a4cd6eb9 100644
--- a/clang/test/Modules/add-remove-irrelevant-module-map.m
+++ b/clang/test/Modules/add-remove-irrelevant-module-map.m
@@ -27,7 +27,7 @@
 //
 // RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s 
--check-prefix=CHECK-B
 // RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s 
--check-prefix=CHECK-B
-// CHECK-B-NOT: Input file: {{.*}}/b.modulemap
+// CHECK-B-NOT: Input file: {{.*}}b.modulemap
 
 //--- c.modulemap
 module c [no_undeclared_includes] { header "c.h" }
@@ -54,5 +54,5 @@
 // The PCM file considers 'd.modulemap' an input because it affects the 
compilation,
 // although it doesn't describe the built module or its imports.
 //
-// RUN: %clang_cc1 -module-file-info %t/cache/c.pcm | FileCheck %s 
--check-prefix=CHECK-D -DDIR=%t
-// CHECK-D: Input file: [[DIR]]/d.modulemap
+// RUN: %clang_cc1 -module-file-info %t/cache/c.pcm | FileCheck %s 
--check-prefix=CHECK-D
+// CHECK-D: Input file: {{.*}}d.modulemap



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


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 created this revision.
tyb0807 added reviewers: dmgreen, lenary, tmatheson, simon_tatham, fhahn.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
tyb0807 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is the continuation of https://reviews.llvm.org/D120875, where
aarch64-cpus-2.c is further splitted and renamed to better reflect the
tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121093

Files:
  clang/test/Driver/aarch64-archs.c
  clang/test/Driver/aarch64-bf16.c
  clang/test/Driver/aarch64-cpus-1.c
  clang/test/Driver/aarch64-cpus-2.c
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/aarch64-fp16.c
  clang/test/Driver/aarch64-i8mm.c
  clang/test/Driver/aarch64-ls64.c
  clang/test/Driver/aarch64-ras.c
  clang/test/Driver/aarch64-sve.c
  clang/test/Driver/aarch64-sve2.c

Index: clang/test/Driver/aarch64-sve2.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-sve2.c
@@ -0,0 +1,8 @@
+// SVE2 is enabled by default on Armv9-A but it can be disabled
+// RUN: %clang -target aarch64 -march=armv9a+nosve2 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV9A-NOSVE2 %s
+// RUN: %clang -target aarch64 -march=armv9-a+nosve2 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV9A-NOSVE2 %s
+// RUN: %clang -target aarch64 -mlittle-endian -march=armv9a+nosve2 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV9A-NOSVE2 %s
+// RUN: %clang -target aarch64 -mlittle-endian -march=armv9-a+nosve2 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV9A-NOSVE2 %s
+// RUN: %clang -target aarch64_be -mlittle-endian -march=armv9a+nosve2 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV9A-NOSVE2 %s
+// RUN: %clang -target aarch64_be -mlittle-endian -march=armv9-a+nosve2 -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV9A-NOSVE2 %s
+// GENERICV9A-NOSVE2: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v9a" "-target-feature" "+sve" "-target-feature" "-sve2"
Index: clang/test/Driver/aarch64-sve.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-sve.c
@@ -0,0 +1,27 @@
+// The SVE extension is an optional extension for Armv8-A.
+// RUN: %clang -target aarch64 -march=armv8a+sve -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV8A-SVE %s
+// RUN: %clang -target aarch64 -march=armv8.6a+sve -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV8A-SVE %s
+// GENERICV8A-SVE: "-target-feature" "+sve"
+// RUN: %clang -target aarch64 -march=armv8a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV8A-NOSVE %s
+// RUN: %clang -target aarch64 -march=armv8.6a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV8A-NOSVE %s
+// GENERICV8A-NOSVE-NOT: "-target-feature" "+sve"
+
+// The 32-bit floating point matrix multiply extension is enabled by default
+// for armv8.6-a targets (or later) with SVE, and can optionally be enabled for
+// any target from armv8.2a onwards (we don't enforce not using it with earlier
+// targets).
+// RUN: %clang -target aarch64 -march=armv8.6a   -### -c %s 2>&1 | FileCheck -check-prefix=NO-F32MM %s
+// RUN: %clang -target aarch64 -march=armv8.6a+sve   -### -c %s 2>&1 | FileCheck -check-prefix=F32MM %s
+// RUN: %clang -target aarch64 -march=armv8.5a+f32mm -### -c %s 2>&1 | FileCheck -check-prefix=F32MM %s
+// NO-F32MM-NOT: "-target-feature" "+f32mm"
+// F32MM: "-target-feature" "+f32mm"
+
+// The 64-bit floating point matrix multiply extension is not currently enabled
+// by default for any targets, because it requires an SVE vector length >= 256
+// bits. When we add a CPU which has that, then it can be enabled by default,
+// but for now it can only be used by adding the +f64mm feature.
+// RUN: %clang -target aarch64 -march=armv8.6a   -### -c %s 2>&1 | FileCheck -check-prefix=NO-F64MM %s
+// RUN: %clang -target aarch64 -march=armv8.6a+sve   -### -c %s 2>&1 | FileCheck -check-prefix=NO-F64MM %s
+// RUN: %clang -target aarch64 -march=armv8.6a+f64mm -### -c %s 2>&1 | FileCheck -check-prefix=F64MM %s
+// NO-F64MM-NOT: "-target-feature" "+f64mm"
+// F64MM: "-target-feature" "+f64mm"
Index: clang/test/Driver/aarch64-ras.c
===
--- clang/test/Driver/aarch64-ras.c
+++ clang/test/Driver/aarch64-ras.c
@@ -1,4 +1,6 @@
+// RAS is off by default for v8a, but can be enabled by +ras (this is not architecturally valid)
 // RUN: %clang -target aarch64-none-none-eabi -march=armv8a+ras -### -c %s 2>&1 | FileCheck --check-prefix=CHECK-RAS %s
+// RUN: %clang -target aarch64-none-none-eabi -march=armv8-a+ras -### -c %s 2>&1 | FileCheck --check-prefix=CHECK-RAS %s
 // RUN: %clang -target aarch64-none-none-eabi -mcpu=generic+ras -### -c %s 2>&1 | FileCheck --check-prefix=CHECK-RAS %s
 // RUN: %clang -target aarch64-none-none-eabi -mcpu=cortex-a75 -### -c %s 2>&1 | FileCheck --chec

[PATCH] D120464: [clang][modules] Report module maps affecting `no_undeclared_includes` modules

2022-03-07 Thread Orlando Cazalet-Hyams via Phabricator via cfe-commits
Orlando added a comment.

Hi, the test `add-remove-irrelevant-module-map.m` starts failing with this 
commit on the `llvm-clang-x86_64-sie-win` builder: 
https://lab.llvm.org/buildbot/#/builders/216/builds/929. Please can you take a 
look when you get the chance?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120464

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


[PATCH] D121100: [clang][DebugInfo] clang should not generate DW_TAG_subprogram entry without DW_AT_name

2022-03-07 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: aprantl, djtodoro, jini.susan.
alok added a project: debug-info.
Herald added a project: All.
alok requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently Clang is generating subprograms without DW_AT_name. which is fine for 
LLDB but other debuggers (GNU gdb) can not be forced to accept such DWARF due 
to DWARF standard mandating DW_AT_name attribute for subprograms.

As per DWARF standard Subroutine must have DW_AT_name attribute.
Please consider below lines from DWARF(5) document

  3.3.1 General Subroutine and Entry Point Information
   The subroutine or entry point entry has a DW_AT_name attribute whose value is
   a null-terminated string containing the subroutine or entry point name. It 
may
   also have a DW_AT_linkage_name attribute as described in Section 2.22 on
   page 56.

Current behavior of Clang prevents gdb to show variables in shared/private 
clause of Openmp task construct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121100

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/constructor-attribute.c
  clang/test/CodeGen/debug-info-oslog.c
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
  clang/test/CodeGenCXX/debug-info-blocks.cpp
  clang/test/CodeGenCXX/debug-info-thunk.cpp
  clang/test/CodeGenCXX/difile_entry.cpp
  clang/test/CodeGenCXX/globalinit-loc.cpp
  clang/test/CodeGenObjC/block-byref-debuginfo.m
  clang/test/CodeGenObjC/debug-info-block-helper.m
  clang/test/CodeGenObjC/debug-info-blocks.m
  clang/test/CodeGenObjC/nontrivial-c-struct-exception.m
  clang/test/OpenMP/master_taskloop_reduction_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_reduction_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_reduction_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_reduction_codegen.cpp
  clang/test/OpenMP/simd_codegen.cpp
  clang/test/OpenMP/taskgroup_task_reduction_codegen.cpp
  clang/test/OpenMP/taskloop_reduction_codegen.cpp
  clang/test/OpenMP/taskloop_simd_reduction_codegen.cpp

Index: clang/test/OpenMP/taskloop_simd_reduction_codegen.cpp
===
--- clang/test/OpenMP/taskloop_simd_reduction_codegen.cpp
+++ clang/test/OpenMP/taskloop_simd_reduction_codegen.cpp
@@ -213,12 +213,12 @@
 // CHECK: store float %{{.+}}, float* %
 // CHECK: ret void
 
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT1]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB1]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_FINI2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT3]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB3]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT4]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB4]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT1]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB1]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_FINI2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT3]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB3]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT4]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB4]]"
Index: clang/test/OpenMP/taskloop_reduction_codegen.cpp
===
--- clang/test/OpenMP/taskloop_reduction_codegen.cpp
+++ clang/test/OpenMP/taskloop_reduction_codegen.cpp
@@ -220,13 +220,13 @@
 // CHECK: call i8* @__kmpc_task_reduction_get_th_data(
 // CHECK: call i8* @__kmpc_task_reduction_get_th_data(
 
-// CHECK-DAG: distinct !DISubprogram(linkageName: "[[TASK]]", scope: !
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT1]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB1]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_FINI2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB2]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT3]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB3]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT4]]"
-// CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB4]]"
+// CHECK-DAG: distinct !DISubprogram(name: "[[TASK]]", scope: !
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT1]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB1]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_FINI2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB2]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT3]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB3]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_INIT4]]"
+// CHECK-DAG: !DISubprogram(name: "[[RED_COMB4]]"
Index: clang/test/OpenMP/taskgroup_task_reduction_codegen.cpp

[PATCH] D120464: [clang][modules] Report module maps affecting `no_undeclared_includes` modules

2022-03-07 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D120464#3363258 , @Orlando wrote:

> Hi, the test `add-remove-irrelevant-module-map.m` starts failing with this 
> commit on the `llvm-clang-x86_64-sie-win` builder: 
> https://lab.llvm.org/buildbot/#/builders/216/builds/929. Please can you take 
> a look when you get the chance?

Hi, it's already fixed in 
https://lab.llvm.org/buildbot/#/builders/216/builds/932.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120464

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


[PATCH] D120464: [clang][modules] Report module maps affecting `no_undeclared_includes` modules

2022-03-07 Thread Orlando Cazalet-Hyams via Phabricator via cfe-commits
Orlando added a comment.

In D120464#3363274 , @jansvoboda11 
wrote:

> In D120464#3363258 , @Orlando wrote:
>
>> Hi, the test `add-remove-irrelevant-module-map.m` starts failing with this 
>> commit on the `llvm-clang-x86_64-sie-win` builder: 
>> https://lab.llvm.org/buildbot/#/builders/216/builds/929. Please can you take 
>> a look when you get the chance?
>
> Hi, it's already fixed in 
> https://lab.llvm.org/buildbot/#/builders/216/builds/932.

Aha, sorry for the noise, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120464

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


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added inline comments.



Comment at: clang/test/Driver/aarch64-cpus.c:2
+// Check target CPUs are correctly passed.
+// TODO: The files should be split up by categories, e.g. by architecture 
versions, to avoid excessive test
 // times for large single test files.

Tiniest nit ever: what files is this comment talking about?

(In the previous version, it followed on from a previous comment that gave the 
name of the file containing other half of the tests in question. Now it 
doesn't, so the wording is no longer clear.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[PATCH] D121045: [analyzer][NFC] Merge similar conditional paths

2022-03-07 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets updated this revision to Diff 413402.
phyBrackets added a comment.

used the correct name for Opcodes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121045

Files:
  clang/docs/DataFlowAnalysisIntro.md
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -107,11 +107,8 @@
   dyn_cast(Ex->IgnoreParenCasts());
 if (!BO)
   break;
-if (BO->getOpcode() == BO_Assign) {
-  Ex = BO->getRHS();
-  continue;
-}
-if (BO->getOpcode() == BO_Comma) {
+BinaryOperatorKind Op = BO->getOpcode();
+if (Op == BO_Assign || Op == BO_Comma) {
   Ex = BO->getRHS();
   continue;
 }
Index: clang/docs/DataFlowAnalysisIntro.md
===
--- clang/docs/DataFlowAnalysisIntro.md
+++ clang/docs/DataFlowAnalysisIntro.md
@@ -287,7 +287,7 @@
 
 (Note that there are other ways to write this equation that produce higher
 precision analysis results. The trick is to keep exploring the execution paths
-separately and delay joining until later. Hoowever, we won't discuss those
+separately and delay joining until later. However, we won't discuss those
 variations here.)
 
 To make a conclusion about all paths through the program, we repeat this


Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -107,11 +107,8 @@
   dyn_cast(Ex->IgnoreParenCasts());
 if (!BO)
   break;
-if (BO->getOpcode() == BO_Assign) {
-  Ex = BO->getRHS();
-  continue;
-}
-if (BO->getOpcode() == BO_Comma) {
+BinaryOperatorKind Op = BO->getOpcode();
+if (Op == BO_Assign || Op == BO_Comma) {
   Ex = BO->getRHS();
   continue;
 }
Index: clang/docs/DataFlowAnalysisIntro.md
===
--- clang/docs/DataFlowAnalysisIntro.md
+++ clang/docs/DataFlowAnalysisIntro.md
@@ -287,7 +287,7 @@
 
 (Note that there are other ways to write this equation that produce higher
 precision analysis results. The trick is to keep exploring the execution paths
-separately and delay joining until later. Hoowever, we won't discuss those
+separately and delay joining until later. However, we won't discuss those
 variations here.)
 
 To make a conclusion about all paths through the program, we repeat this
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 marked an inline comment as done.
tyb0807 added inline comments.



Comment at: clang/test/Driver/aarch64-cpus.c:2
+// Check target CPUs are correctly passed.
+// TODO: The files should be split up by categories, e.g. by architecture 
versions, to avoid excessive test
 // times for large single test files.

simon_tatham wrote:
> Tiniest nit ever: what files is this comment talking about?
> 
> (In the previous version, it followed on from a previous comment that gave 
> the name of the file containing other half of the tests in question. Now it 
> doesn't, so the wording is no longer clear.)
This is for just in case we want to split up this file (aarch64-cpus.c) 
further, into smaller files such as aarch64-cortex-a53.c, aarch64-cortex-a57.c, 
etc. Do you think we still need to do this, or this file looks ok to you in its 
current state?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson accepted this revision.
tmatheson added a comment.
This revision is now accepted and ready to land.

Thanks for picking this up, LGTM




Comment at: clang/test/Driver/aarch64-archs.c:296
-// NO-LS64-NOT: "-target-feature" "+ls64"
-// LS64: "-target-feature" "+ls64"
-

Looks like these were duplicate tests? Besides `armv8.7a` vs `armv8.7-a`



Comment at: clang/test/Driver/aarch64-cpus.c:2
+// Check target CPUs are correctly passed.
+// TODO: The files should be split up by categories, e.g. by architecture 
versions, to avoid excessive test
 // times for large single test files.

tyb0807 wrote:
> simon_tatham wrote:
> > Tiniest nit ever: what files is this comment talking about?
> > 
> > (In the previous version, it followed on from a previous comment that gave 
> > the name of the file containing other half of the tests in question. Now it 
> > doesn't, so the wording is no longer clear.)
> This is for just in case we want to split up this file (aarch64-cpus.c) 
> further, into smaller files such as aarch64-cortex-a53.c, 
> aarch64-cortex-a57.c, etc. Do you think we still need to do this, or this 
> file looks ok to you in its current state?




Comment at: clang/test/Driver/aarch64-ras.c:14
+// RAS is on by default for v8.2a, but can be disabled by +noras
+// FIXME: in the current implementation, RAS is not on by default at all for 
v8.2a (the test says it all...)
+// RUN: %clang -target aarch64 -march=armv8.2a  -### -c %s 2>&1 | FileCheck 
-check-prefix=V82ARAS %s

The RAS test changes are the only functional change to this review, which is 
otherwise moving lines around and changing comments. I would keep the original 
tests even if they're wrong, so that the history remains clearer. Alternatively 
describe the RAS changes in the commit message and description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[PATCH] D121101: [clang] Fix OpenMP critical hint parameter check

2022-03-07 Thread Peixin Qiao via Phabricator via cfe-commits
peixin created this revision.
peixin added a reviewer: ABataev.
peixin added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
peixin requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

The paramemter of hint clause in OpenMP critical hint should be
non-negative. The omp_lock_hint_none is 0 in omp.h.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121101

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/critical_messages.cpp


Index: clang/test/OpenMP/critical_messages.cpp
===
--- clang/test/OpenMP/critical_messages.cpp
+++ clang/test/OpenMP/critical_messages.cpp
@@ -67,10 +67,14 @@
   foo();
   #pragma omp critical (name2) hint(argc) // expected-error {{integral 
constant expression}} expected-note 0+{{constant expression}}
   foo();
-  #pragma omp critical (name) hint(N) // expected-error {{argument to 'hint' 
clause must be a strictly positive integer value}} expected-error {{constructs 
with the same name must have a 'hint' clause with the same value}} 
expected-note {{'hint' clause with value '4'}}
+  #pragma omp critical (name) hint(N) // expected-error {{argument to 'hint' 
clause must be a non-negative integer value}} expected-error {{constructs with 
the same name must have a 'hint' clause with the same value}} expected-note 
{{'hint' clause with value '4'}}
   foo();
   #pragma omp critical hint(N) // expected-error {{the name of the construct 
must be specified in presence of 'hint' clause}}
   foo();
+
+  const int omp_lock_hint_none = 0;
+  #pragma omp critical (name3) hint(omp_lock_hint_none)
+  foo();
   return 0;
 }
 
@@ -132,7 +136,7 @@
   foo();
   #pragma omp critical (name) hint(23) // expected-note {{previous 'hint' 
clause with value '23'}}
   foo();
-  #pragma omp critical hint(-5) // expected-error {{argument to 'hint' clause 
must be a strictly positive integer value}}
+  #pragma omp critical hint(-5) // expected-error {{argument to 'hint' clause 
must be a non-negative integer value}}
   foo();
   #pragma omp critical hint(1) // expected-error {{the name of the construct 
must be specified in presence of 'hint' clause}}
   foo();
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -21402,7 +21402,8 @@
   // OpenMP [2.13.2, critical construct, Description]
   // ... where hint-expression is an integer constant expression that evaluates
   // to a valid lock hint.
-  ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint);
+  ExprResult HintExpr =
+  VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint, false);
   if (HintExpr.isInvalid())
 return nullptr;
   return new (Context)


Index: clang/test/OpenMP/critical_messages.cpp
===
--- clang/test/OpenMP/critical_messages.cpp
+++ clang/test/OpenMP/critical_messages.cpp
@@ -67,10 +67,14 @@
   foo();
   #pragma omp critical (name2) hint(argc) // expected-error {{integral constant expression}} expected-note 0+{{constant expression}}
   foo();
-  #pragma omp critical (name) hint(N) // expected-error {{argument to 'hint' clause must be a strictly positive integer value}} expected-error {{constructs with the same name must have a 'hint' clause with the same value}} expected-note {{'hint' clause with value '4'}}
+  #pragma omp critical (name) hint(N) // expected-error {{argument to 'hint' clause must be a non-negative integer value}} expected-error {{constructs with the same name must have a 'hint' clause with the same value}} expected-note {{'hint' clause with value '4'}}
   foo();
   #pragma omp critical hint(N) // expected-error {{the name of the construct must be specified in presence of 'hint' clause}}
   foo();
+
+  const int omp_lock_hint_none = 0;
+  #pragma omp critical (name3) hint(omp_lock_hint_none)
+  foo();
   return 0;
 }
 
@@ -132,7 +136,7 @@
   foo();
   #pragma omp critical (name) hint(23) // expected-note {{previous 'hint' clause with value '23'}}
   foo();
-  #pragma omp critical hint(-5) // expected-error {{argument to 'hint' clause must be a strictly positive integer value}}
+  #pragma omp critical hint(-5) // expected-error {{argument to 'hint' clause must be a non-negative integer value}}
   foo();
   #pragma omp critical hint(1) // expected-error {{the name of the construct must be specified in presence of 'hint' clause}}
   foo();
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -21402,7 +21402,8 @@
   // OpenMP [2.13.2, critical construct, Description]
   // ... where hint-expression is an integer constant expression that evaluates
   // to a va

[PATCH] D121103: [clang] Adjust LookupTest for UsingTypeLocs

2022-03-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We no longer traverse the underlying RecordTypeLoc directly, but rather
visit the UsingTypeLoc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121103

Files:
  clang/unittests/Tooling/LookupTest.cpp


Index: clang/unittests/Tooling/LookupTest.cpp
===
--- clang/unittests/Tooling/LookupTest.cpp
+++ clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(), 
Visitor.DeclStack.back()->getDeclContext(),
-FD, ReplacementString);
+nullptr, Loc, Visitor.DeclStack.back()->getDeclContext(), ND,
+ReplacementString);
   };
 
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("x::Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+  EXPECT_EQ("x::Bar", replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(),
+ "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b {\n"
@@ -201,12 +210,13 @@
   "namespace c { Foo f();; }\n"
   "} }\n");
 
-  Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
+  Visitor.OnUsingTypeLoc = [&](UsingTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 // `a::b::Foo` in using shadow decl is not `TypeLoc`.
-if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+auto *TD = Type.getFoundDecl()->getTargetDecl();
+if (TD->getQualifiedNameAsString() == "a::b::Foo") {
+  EXPECT_EQ("Bar", replaceTypeLoc(TD, Type.getBeginLoc(), "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b { class Foo {}; } }\n"
@@ -218,7 +228,8 @@
   // it's not visible at [0].
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 if (Type.getDecl()->getQualifiedNameAsString() == "x::y::Old") {
-  EXPECT_EQ("Foo", replaceRecordTypeLoc(Type, "::x::Foo"));
+  EXPECT_EQ("Foo",
+replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(), 
"::x::Foo"));
 }
   };
   Visitor.runOver(R"(


Index: clang/unittests/Tooling/LookupTest.cpp
===
--- clang/unittests/Tooling/LookupTest.cpp
+++ clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(), Visitor.DeclStack.back()->get

[PATCH] D119040: Fix LookupTest where it was missing an assertion

2022-03-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Thanks for the change, but the test is actually checking for rename in presence 
of using-decls. I beleive https://reviews.llvm.org/D121103 is the proper fix 
here.


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

https://reviews.llvm.org/D119040

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


[PATCH] D121101: [clang] Fix OpenMP critical hint parameter check

2022-03-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121101

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


[PATCH] D121077: Simplify OpenMP Lambda use

2022-03-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121077

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


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham accepted this revision.
simon_tatham added inline comments.



Comment at: clang/test/Driver/aarch64-cpus.c:2
+// Check target CPUs are correctly passed.
+// TODO: The files should be split up by categories, e.g. by architecture 
versions, to avoid excessive test
 // times for large single test files.

tmatheson wrote:
> tyb0807 wrote:
> > simon_tatham wrote:
> > > Tiniest nit ever: what files is this comment talking about?
> > > 
> > > (In the previous version, it followed on from a previous comment that 
> > > gave the name of the file containing other half of the tests in question. 
> > > Now it doesn't, so the wording is no longer clear.)
> > This is for just in case we want to split up this file (aarch64-cpus.c) 
> > further, into smaller files such as aarch64-cortex-a53.c, 
> > aarch64-cortex-a57.c, etc. Do you think we still need to do this, or this 
> > file looks ok to you in its current state?
> 
I do quite like the idea of a whole set of aarch64-cortex-.c files, for 
the same reason I mentioned in D120875: it means that when someone is 
implementing support for the next CPU, they'll look at the existing test 
collection and naturally add a new file alongside all the others, instead of 
naturally appending another stanza to this file which will eventually grow too 
big again.

But like the previous patch, I won't block you making this much improvement 
just because you haven't made even more improvement :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[clang] 4fd6c6e - [analyzer] Add more propagations to Taint analysis

2022-03-07 Thread Endre Fülöp via cfe-commits

Author: Endre Fülöp
Date: 2022-03-07T13:18:54+01:00
New Revision: 4fd6c6e65ab59f82284d8272aa3bec8d5084511e

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

LOG: [analyzer] Add more propagations to Taint analysis

Add more functions as taint propators to GenericTaintChecker.

Reviewed By: steakhal

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

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
clang/test/Analysis/taint-generic.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index bc42b80d166c7..6e42544c05808 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2358,7 +2358,7 @@ Default sources defined by ``GenericTaintChecker``:
  ``_IO_getc``, ``fdopen``, ``fopen``, ``freopen``, ``get_current_dir_name``, 
``getch``, ``getchar``, ``getchar_unlocked``, ``getwd``, ``getcwd``, 
``getgroups``, ``gethostname``, ``getlogin``, ``getlogin_r``, ``getnameinfo``, 
``gets``, ``gets_s``, ``getseuserbyname``, ``readlink``, ``readlinkat``, 
``scanf``, ``scanf_s``, ``socket``, ``wgetch``
 
 Default propagations defined by ``GenericTaintChecker``:
-``atoi``, ``atol``, ``atoll``, ``fgetc``, ``fgetln``, ``fgets``, ``fscanf``, 
``sscanf``, ``getc``, ``getc_unlocked``, ``getdelim``, ``getline``, ``getw``, 
``pread``, ``read``, ``strchr``, ``strrchr``, ``tolower``, ``toupper``
+``atoi``, ``atol``, ``atoll``, ``basename``, ``dirname``, ``fgetc``, 
``fgetln``, ``fgets``, ``fnmatch``, ``fread``, ``fscanf``, ``fscanf_s``, 
``index``, ``inflate``, ``isalnum``, ``isalpha``, ``isascii``, ``isblank``, 
``iscntrl``, ``isdigit``, ``isgraph``, ``islower``, ``isprint``, ``ispunct``, 
``isspace``, ``isupper``, ``isxdigit``, ``memchr``, ``memrchr``, ``sscanf``, 
``getc``, ``getc_unlocked``, ``getdelim``, ``getline``, ``getw``, ``memcmp``, 
``memcpy``, ``memmem``, ``memmove``, ``mbtowc``, ``pread``, ``qsort``, 
``qsort_r``, ``rawmemchr``, ``read``, ``recv``, ``recvfrom``, ``rindex``, 
``strcasestr``, ``strchr``, ``strchrnul``, ``strcasecmp``, ``strcmp``, 
``strcspn``, ``strlen``, ``strncasecmp``, ``strncmp``, ``strndup``, 
``strndupa``, ``strnlen``, ``strpbrk``, ``strrchr``, ``strsep``, ``strspn``, 
``strstr``, ``strtol``, ``strtoll``, ``strtoul``, ``strtoull``, ``tolower``, 
``toupper``, ``ttyname``, ``ttyname_r``, ``wctomb``, ``wcwidth``
 
 Default sinks defined in ``GenericTaintChecker``:
 ``printf``, ``setproctitle``, ``system``, ``popen``, ``execl``, ``execle``, 
``execlp``, ``execv``, ``execvp``, ``execvP``, ``execve``, ``dlopen``, 
``memcpy``, ``memmove``, ``strncpy``, ``strndup``, ``malloc``, ``calloc``, 
``alloca``, ``memccpy``, ``realloc``, ``bcopy``

diff  --git a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
index 1100f215cb5d9..518a4eb4d7759 100644
--- a/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -580,7 +580,9 @@ void GenericTaintChecker::initTaintRules(CheckerContext &C) 
const {
   {{"fgetln"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
   {{"fgets"}, TR::Prop({{2}}, {{0, ReturnValueIndex}})},
   {{"fscanf"}, TR::Prop({{0}}, {{}, 2})},
+  {{"fscanf_s"}, TR::Prop({{0}}, {{}, {2}})},
   {{"sscanf"}, TR::Prop({{0}}, {{}, 2})},
+
   {{"getc"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
   {{"getc_unlocked"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
   {{"getdelim"}, TR::Prop({{3}}, {{0}})},
@@ -592,6 +594,78 @@ void GenericTaintChecker::initTaintRules(CheckerContext 
&C) const {
   {{"strrchr"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
   {{"tolower"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
   {{"toupper"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
+  {{"fread"}, TR::Prop({{3}}, {{0, ReturnValueIndex}})},
+  {{"recv"}, TR::Prop({{0}}, {{1, ReturnValueIndex}})},
+  {{"recvfrom"}, TR::Prop({{0}}, {{1, ReturnValueIndex}})},
+
+  {{"ttyname"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
+  {{"ttyname_r"}, TR::Prop({{0}}, {{1, ReturnValueIndex}})},
+
+  {{"basename"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
+  {{"dirname"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
+  {{"fnmatch"}, TR::Prop({{1}}, {{ReturnValueIndex}})},
+  {{"memchr"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
+  {{"memrchr"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
+  {{"rawmemchr"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
+
+  {{"mbtowc"}, TR::Prop({{1}}, {{0, ReturnValueIndex}})},
+  {{"wctomb"}, TR::Prop({{1}}, {{0, ReturnValueIndex}})},
+  {{"wcwidth"}, TR::Prop({{0}}, {{ReturnValueIndex}})},
+
+  {{"memcmp"}, TR::Prop({{0, 1}}, {{Re

[PATCH] D120369: [analyzer] Add more propagations to Taint analysis

2022-03-07 Thread Endre Fülöp via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4fd6c6e65ab5: [analyzer] Add more propagations to Taint 
analysis (authored by gamesh411).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120369

Files:
  clang/docs/analyzer/checkers.rst
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/test/Analysis/taint-generic.c

Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -1,20 +1,26 @@
-// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast -verify %s \
+// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
+// RUN:   -Wno-incompatible-library-redeclaration -verify %s \
 // RUN:   -analyzer-checker=alpha.security.taint \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=alpha.security.ArrayBoundV2 \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
 
-// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast -verify %s \
+// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
+// RUN:   -Wno-incompatible-library-redeclaration -verify %s \
 // RUN:   -DFILE_IS_STRUCT \
 // RUN:   -analyzer-checker=alpha.security.taint \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=alpha.security.ArrayBoundV2 \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
 
-// RUN: not %clang_analyze_cc1 -Wno-pointer-to-int-cast -verify %s \
+// RUN: not %clang_analyze_cc1 -Wno-pointer-to-int-cast \
+// RUN:   -Wno-incompatible-library-redeclaration -verify %s \
 // RUN:   -analyzer-checker=alpha.security.taint \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=justguessit \
 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-FILE
@@ -24,8 +30,10 @@
 // CHECK-INVALID-FILE-SAME:that expects a valid filename instead of
 // CHECK-INVALID-FILE-SAME:'justguessit'
 
-// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN: not %clang_analyze_cc1 -Wno-incompatible-library-redeclaration \
+// RUN:   -verify %s \
 // RUN:   -analyzer-checker=alpha.security.taint \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-ill-formed.yaml \
 // RUN:   2>&1 | FileCheck -DMSG=%errc_EINVAL %s -check-prefix=CHECK-ILL-FORMED
@@ -34,8 +42,10 @@
 // CHECK-ILL-FORMED-SAME:'alpha.security.taint.TaintPropagation:Config',
 // CHECK-ILL-FORMED-SAME:that expects a valid yaml file: [[MSG]]
 
-// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN: not %clang_analyze_cc1 -Wno-incompatible-library-redeclaration \
+// RUN:   -verify %s \
 // RUN:   -analyzer-checker=alpha.security.taint \
+// RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
 // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-invalid-arg.yaml \
 // RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-ARG
@@ -46,6 +56,9 @@
 // CHECK-INVALID-ARG-SAME:rules greater or equal to -1
 
 typedef long long rsize_t;
+void clang_analyzer_isTainted_char(char);
+void clang_analyzer_isTainted_charp(char*);
+void clang_analyzer_isTainted_int(int);
 
 int scanf(const char *restrict format, ...);
 char *gets(char *str);
@@ -60,13 +73,18 @@
 #endif
 
 #define bool _Bool
+#define NULL (void*)0
 
 char *getenv(const char *name);
+
+FILE *fopen(const char *name, const char *mode);
+
 int fscanf(FILE *restrict stream, const char *restrict format, ...);
 int sprintf(char *str, const char *format, ...);
 void setproctitle(const char *fmt, ...);
 void setproctitle_init(int argc, char *argv[], char *envp[]);
 typedef __typeof(sizeof(int)) size_t;
+typedef signed long long ssize_t;
 
 // Define string functions. Use builtin for some of them. They all default to
 // the processing in the taint checker.
@@ -388,7 +406,6 @@
   return system(c); // expected-warning {{Untrusted data is passed to a system call}}
 }
 
-typedef signed long long ssize_t;
 ssize_t readlink(const char *path, char *buf, size_t bufsiz);
 int testReadlink(char *path, char *buf, size_t bufsiz) {
   ssize_t s = readlink(path, buf, bufsiz);
@@ -463,6 +480,510 @@
   return system(buf); // expected-warning {{Untrusted data is passed to a system call}}
 }
 
+int fscanf_s(FILE *stream, const char *format, ...);
+void testFscanf_s(const char *fname, int *d) {
+  FILE *f = fopen(fname, "r");
+  fscanf_s(f, "%d", d);
+  cla

[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

Thanks!




Comment at: clang/test/Driver/aarch64-cpus.c:2
+// Check target CPUs are correctly passed.
+// TODO: The files should be split up by categories, e.g. by architecture 
versions, to avoid excessive test
 // times for large single test files.

simon_tatham wrote:
> tmatheson wrote:
> > tyb0807 wrote:
> > > simon_tatham wrote:
> > > > Tiniest nit ever: what files is this comment talking about?
> > > > 
> > > > (In the previous version, it followed on from a previous comment that 
> > > > gave the name of the file containing other half of the tests in 
> > > > question. Now it doesn't, so the wording is no longer clear.)
> > > This is for just in case we want to split up this file (aarch64-cpus.c) 
> > > further, into smaller files such as aarch64-cortex-a53.c, 
> > > aarch64-cortex-a57.c, etc. Do you think we still need to do this, or this 
> > > file looks ok to you in its current state?
> > 
> I do quite like the idea of a whole set of aarch64-cortex-.c files, for 
> the same reason I mentioned in D120875: it means that when someone is 
> implementing support for the next CPU, they'll look at the existing test 
> collection and naturally add a new file alongside all the others, instead of 
> naturally appending another stanza to this file which will eventually grow 
> too big again.
> 
> But like the previous patch, I won't block you making this much improvement 
> just because you haven't made even more improvement :-)
> I do quite like the idea of a whole set of aarch64-cortex-.c files

Yeah that sounds good. Maybe ` aarch64-cortex-cpus.c` might be a good start, to 
avoid having too many small files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[PATCH] D120984: [clang][dataflow] Extend flow conditions from block terminators

2022-03-07 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 413426.
sgatev marked 5 inline comments as done.
sgatev added a comment.

Address reviewers' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120984

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.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
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -336,7 +336,8 @@
   }
 
   bool compareEquivalent(QualType Type, const Value &Val1,
- const Value &Val2) final {
+ const Environment &Env1, const Value &Val2,
+ const Environment &Env2) final {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
@@ -346,8 +347,9 @@
cast(&Val2)->getProperty("has_value");
   }
 
-  bool merge(QualType Type, const Value &Val1, const Value &Val2,
- Value &MergedVal, Environment &Env) final {
+  bool merge(QualType Type, const Value &Val1, const Environment &Env1,
+ const Value &Val2, const Environment &Env2, Value &MergedVal,
+ Environment &MergedEnv) final {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
@@ -559,4 +561,319 @@
   });
 }
 
+class FlowConditionTest : public Test {
+protected:
+  template 
+  void runDataflow(llvm::StringRef Code, Matcher Match) {
+ASSERT_THAT_ERROR(
+test::checkDataflow(
+Code, "target",
+[](ASTContext &Context, Environment &Env) {
+  return NoopAnalysis(Context, true);
+},
+[&Match](
+llvm::ArrayRef<
+std::pair>>
+Results,
+ASTContext &ASTCtx) { Match(Results, ASTCtx); },
+{"-fsyntax-only", "-std=c++17"}),
+llvm::Succeeded());
+  }
+};
+
+TEST_F(FlowConditionTest, IfStmtSingleVar) {
+  std::string Code = R"(
+void target(bool Foo) {
+  if (Foo) {
+(void)0;
+/*[[p1]]*/
+  } else {
+(void)1;
+/*[[p2]]*/
+  }
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+ASSERT_THAT(Results, ElementsAre(Pair("p2", _), Pair("p1", _)));
+
+const Environment &Env1 = Results[1].second.Env;
+auto *FooVal1 =
+cast(Env1.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env1.flowConditionImplies(*FooVal1));
+
+const Environment &Env2 = Results[0].second.Env;
+auto *FooVal2 =
+cast(Env2.getValue(*FooDecl, SkipPast::None));
+EXPECT_FALSE(Env2.flowConditionImplies(*FooVal2));
+  });
+}
+
+TEST_F(FlowConditionTest, IfStmtSingleNegatedVar) {
+  std::string Code = R"(
+void target(bool Foo) {
+  if (!Foo) {
+(void)0;
+/*[[p1]]*/
+  } else {
+(void)1;
+/*[[p2]]*/
+  }
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+ASSERT_THAT(Results, ElementsAre(Pair("p2", _), Pair("p1", _)));
+
+const Environment &Env1 = Results[1].second.Env;
+auto *FooVal1 =
+cast(Env1.getValue(*FooDecl, SkipPast::None));
+EXPECT_FALSE(Env1.flowConditionImplies(*FooVal1));
+
+const Environment &Env2 = Results[0].second.Env;
+auto *FooVal2 =
+cast(Env2.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env2.flowConditionImplies(*FooVal2));
+  });
+}
+
+TEST_F(FlowConditionTest, WhileStmt) {
+  std::string Code = R"(
+void target(bool Foo) {
+  while (Foo) {
+

[PATCH] D120984: [clang][dataflow] Extend flow conditions from block terminators

2022-03-07 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h:99
+   const Environment &Env2, Value &MergedVal,
+   Environment &Env) {
   return false;

xazax.hun wrote:
> `MergedEnv`? Also, the documentation above gives a short description of the 
> relationship between `Val1`, `Val2`, and `MergedVal`. But it gives little 
> pointers what are we supposed to do with the `Environment`. 
Updated the name and added some pointers in the documentation.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:154
+
+  // `X v (X ^ Y ^ ...)` is logically equivalent to `X`. The common conditions
+  // have already been added to the result so we don't have to do anything here

ymandel wrote:
> The current comment gets at the big picture, but focusing on the actual 
> disjunction that is being guarded (that is, just the remaining, unshared 
> clauses) may be better. So, maybe instead point out that "True v (X ^ ...)"  
> is equivalent to "True", since if either val is nullptr it represents "true"?
I added a general comment at the top and modified the comment here to target 
the specific case.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:112
+
+// The condition must be inversed in one of the successors.
+if (BlockSuccIdx == 1)

ymandel wrote:
> Can we be more specific? I'd think we need to invert for specifically the 
> successor corresponding to "else" or what not.
Yup. Updated the comment to be more specific.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120984

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


[PATCH] D120774: [clang-format] Handle builtins in constraint expression

2022-03-07 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 413430.
HazardyKnusperkeks marked 3 inline comments as done.

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

https://reviews.llvm.org/D120774

Files:
  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
@@ -23743,6 +23743,18 @@
   verifyFormat("template \n"
"concept Node = std::is_object_v;");
 
+  verifyFormat("template \n"
+   "concept integral = __is_integral(T);");
+
+  verifyFormat("template \n"
+   "concept is2D = __array_extent(T, 1) == 2;");
+
+  verifyFormat("template \n"
+   "concept isRhs = __is_rvalue_expr(std::declval() + 2)");
+
+  verifyFormat("template \n"
+   "concept Same = __is_same_as;");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3085,30 +3085,6 @@
 return;
   break;
 
-case tok::identifier:
-  // We need to differentiate identifiers for a template deduction guide,
-  // variables, or function return types (the constraint expression has
-  // ended before that), and basically all other cases. But it's easier to
-  // check the other way around.
-  assert(FormatTok->Previous);
-  switch (FormatTok->Previous->Tok.getKind()) {
-  case tok::coloncolon:  // Nested identifier.
-  case tok::ampamp:  // Start of a function or variable for the
-  case tok::pipepipe:// constraint expression.
-  case tok::kw_requires: // Initial identifier of a requires clause.
-  case tok::equal:   // Initial identifier of a concept declaration.
-break;
-  default:
-return;
-  }
-
-  // Read identifier with optional template declaration.
-  nextToken();
-  if (FormatTok->is(tok::less))
-parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-/*ClosingBraceKind=*/tok::greater);
-  break;
-
 case tok::kw_const:
 case tok::semi:
 case tok::kw_class:
@@ -3184,8 +3160,33 @@
   parseParens();
   break;
 
+case tok::identifier:
 default:
-  return;
+  if (!FormatTok->Tok.getIdentifierInfo())
+return;
+
+  // We need to differentiate identifiers for a template deduction guide,
+  // variables, or function return types (the constraint expression has
+  // ended before that), and basically all other cases. But it's easier to
+  // check the other way around.
+  assert(FormatTok->Previous);
+  switch (FormatTok->Previous->Tok.getKind()) {
+  case tok::coloncolon:  // Nested identifier.
+  case tok::ampamp:  // Start of a function or variable for the
+  case tok::pipepipe:// constraint expression.
+  case tok::kw_requires: // Initial identifier of a requires clause.
+  case tok::equal:   // Initial identifier of a concept declaration.
+break;
+  default:
+return;
+  }
+
+  // Read identifier with optional template declaration.
+  nextToken();
+  if (FormatTok->is(tok::less))
+parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
+/*ClosingBraceKind=*/tok::greater);
+  break;
 }
   } while (!eof());
 }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23743,6 +23743,18 @@
   verifyFormat("template \n"
"concept Node = std::is_object_v;");
 
+  verifyFormat("template \n"
+   "concept integral = __is_integral(T);");
+
+  verifyFormat("template \n"
+   "concept is2D = __array_extent(T, 1) == 2;");
+
+  verifyFormat("template \n"
+   "concept isRhs = __is_rvalue_expr(std::declval() + 2)");
+
+  verifyFormat("template \n"
+   "concept Same = __is_same_as;");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3085,30 +3085,6 @@
 return;
   break;
 
-case tok::identifier:
-  // We need to differentiate identifiers for a template deduction guide,
-  // variables, or function return types (the constraint expression has
-  // ended before that), and basically all other cases. 

[PATCH] D120774: [clang-format] Handle builtins in constraint expression

2022-03-07 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:3090-3093
+#define TYPE_TRAIT(N, I, K) case tok::kw_##I:
+#define ARRAY_TYPE_TRAIT(I, E, K) case tok::kw_##I:
+#define EXPRESSION_TRAIT(I, E, K) case tok::kw_##I:
+#include "clang/Basic/TokenKinds.def"

owenpan wrote:
> Instead, you can fold `case tok::identifier:` below into `default:` like this:
> ```
> default:
>   if (!FormatTok->Tok.getIdentifierInfo())
> return;
> 
>   // We need to differentiate identifiers for a template deduction guide,
>   ...
> ```
Thanks.


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

https://reviews.llvm.org/D120774

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


[PATCH] D121095: [C++20][Modules][HU 1/5] Introduce header units as a module type.

2022-03-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
Herald added subscribers: dexonsmith, dang.
Herald added a project: All.
iains added reviewers: rsmith, urnathan, ChuanqiXu.
iains added a subscriber: clang-modules.
iains edited the summary of this revision.
iains added a comment.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a small patch set  that implements the initial front end changes to 
support C++20 importable modules.
A second path series will follow that makes the driver changes to drive the 
fronted support.

This implementation makes the user-facing names, command line options and 
behaviour match the existing GCC implementation.  There is no apparent 
engineering reason for divergence and this strategy minimises user learning 
curves and tooling differences.

1/5 - introduces the module type and build actions to compile them
2/5 - allows the user to specify that a header unit should be found from either 
the user or system search paths in force.  In particular this avoids the user 
having to know the install path for system headers.
3/5 - handles emitting macros that are live at the end of the header unit TU, 
as required.
4/5 - handles pre-processed header unit sources
5/5 - introduces "-fdirectives-only" that can be combined with -E to produce 
pre-processor output that can be consumed as a second job to build an 
importable header (it can also be used to provide a scannable preprocesed file 
that has actioned any directives).


iains added a comment.

please see first comment for a description of the patch series.


This is the first in a series of patches that introduce C++20 importable
header units.

These differ from clang header modules in that:
 (a) they are identifiable by an internal name
 (b) they represent the top level source for a single header - although  that 
one might include or import other headers.

We name importable header units with the path by which they are specified
(although that need not be the absolute path for the file).

So "foo/bar.h" would have a name "foo/bar.h".  Header units are made a
separate module type so that we can deal with diagnosing places where they
are permitted but a named module is not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121095

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Lex/ModuleMap.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-hu-01.cpp

Index: clang/test/Modules/cxx20-hu-01.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-01.cpp
@@ -0,0 +1,104 @@
+// Test generation and import of simple C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header %t/hu-01.h \
+// RUN:  -o %t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info %t/hu-01.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/imp-hu-01.cpp \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/B.pcm -Rmodule-import 2>&1  | \
+// RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/imp-hu-02.cpp \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/C.pcm -Rmodule-import 2>&1  | \
+// RUN: FileCheck --check-prefix=CHECK-GMF-IMP %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header %t/hu-02.h \
+// RUN:  -o %t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/imp-hu-03.cpp \
+// RUN:  -fmodule-file=%t/hu-01.pcm -fmodule-file=%t/hu-02.pcm -o %t/D.pcm \
+// RUN: -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-BOTH %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header %t/hu-03.h \
+// RUN: -fmodule-file=%t/hu-01.pcm  -o %t/hu-03.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info %t/hu-03.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU-HU %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/imp-hu-04.cpp \
+// RUN:  -fmodule-file=%t/hu-03.pcm -o %t/E.pcm -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-NESTED %s -DTDIR=%t
+
+//--- hu-01.h
+int foo(int);
+
+// CHECK-HU:  == C++20 Module structure ==
+// CHECK-HU-NEXT:  Header Unit '[[TDIR]]/hu-01.h' is the Primary Module at index #1
+
+//--- imp-hu-01.cpp
+export module B;
+import "hu-01.h";
+
+int bar(int x) {
+  

[PATCH] D121096: [C++20][Modules][HU 2/5] Support searching Header Units in user or system search paths.

2022-03-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
Herald added a project: All.
iains added reviewers: rsmith, urnathan, ChuanqiXu.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is support for the user-facing options to create importable header units
from headers in the user or system search paths (or to be given an absolute 
path).

This means that an incomplete header path will be passed by the driver and the
lookup carried out using the search paths present when the front end is run.

To support this, we introduce file fypes for 
c++-{user,system,header-unit}-header.
These terms are the same as the ones used by GCC, to minimise the differences 
for
tooling (and users).

The preprocessor checks for headers before issuing a warning for
"#pragma once" in a header build.  We ensure that the importable header units
are recognised as headers in order to avoid such warnings.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121096

Files:
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/test/Modules/cxx20-hu-02.cpp
  clang/test/Modules/cxx20-hu-03.cpp

Index: clang/test/Modules/cxx20-hu-03.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-03.cpp
@@ -0,0 +1,58 @@
+// Test check that processing headers as C++20 units allows #pragma once.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-01.h \
+// RUN: -Werror -o hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \
+// RUN: -fmodule-file=%t/hu-01.pcm -o hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only imports-01.cpp \
+// RUN: -fmodule-file=%t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only imports-02.cpp \
+// RUN: -fmodule-file=%t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only imports-03.cpp \
+// RUN: -fmodule-file=%t/hu-02.pcm
+
+//--- hu-01.h
+#pragma once
+#define FORTYTWO 42
+struct HU {
+  int a;
+};
+// expected-no-diagnostics
+
+//--- hu-02.h
+export import "hu-01.h";
+// expected-no-diagnostics
+
+//--- imports-01.cpp
+import "hu-01.h";
+
+HU foo(int x) {
+  return {FORTYTWO};
+}
+// expected-no-diagnostics
+
+//--- imports-02.cpp
+import "hu-02.h";
+
+HU foo(int x) {
+  return {FORTYTWO};
+}
+// expected-no-diagnostics
+
+//--- imports-03.cpp
+import "hu-01.h";
+import "hu-02.h";
+
+HU foo(int x) {
+  return {FORTYTWO};
+}
+// expected-no-diagnostics
Index: clang/test/Modules/cxx20-hu-02.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-02.cpp
@@ -0,0 +1,77 @@
+// Test generation and import of user and system C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// check user path
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -I user \
+// RUN: -xc++-user-header hu-01.h -o hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-01.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface imp-hu-01.cpp \
+// RUN:  -I user -fmodule-file=hu-01.pcm -o B.pcm -Rmodule-import \
+// RUN: 2>&1  | FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
+
+// check system path
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -isystem system \
+// RUN: -xc++-system-header hu-02.h -o hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-02.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU2 %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface imp-hu-02.cpp \
+// RUN:  -isystem system -fmodule-file=hu-02.pcm -o C.pcm \
+// RUN: -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-SYS-IMP %s -DTDIR=%t
+
+// check absolute path
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit  \
+// RUN: -xc++-header-unit-header %t/hu-03.h -o hu-03.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-03.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU3 %s -DTDIR=%t
+
+//--- user/hu-01.h
+int foo(int);
+
+// CHECK-HU:  == C++20 Module structure ==
+// CHECK-HU-NEXT:  Header Unit 'user/hu-01.h' is the Primary Module at index #1
+
+//--- imp-hu-01.cpp
+export module B;
+import "hu-01.h";
+
+int bar(int x) {
+  return foo(x);
+}
+// CHECK-IMP: remark: importing module 'user/hu-01.h' from 'hu-01.pcm'
+// expected-no-diagnostics
+
+//--- system/hu-02.h
+int baz(int);
+
+// CHECK-HU2:  == C++20 Module structure ==
+// CHECK-HU2-NEXT:  Header Unit 'system/hu-02.h' is the Primary Module at index #1
+
+//--- imp-hu-02.cpp
+module;
+import ;
+
+export module C;
+
+int bar(int x) {
+  return baz(x);
+}
+// CHECK-SYS-IMP: remark: importing module 'system/hu-02.h' from 'hu-02.pcm'
+// expected-no-diagnostics
+
+//--- hu-03.h
+int curly(int);
+
+// CHECK-HU3:  == 

[PATCH] D121097: [C++20][Modules][HU 3/5] Emit module macros for header units.

2022-03-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
Herald added a project: All.
iains added reviewers: rsmith, urnathan, ChuanqiXu.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For header units we build the top level module directly from the header
that it represents and macros defined in this TU need to be emitted (when
such a definition is live at the end of the TU).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121097

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/cxx20-hu-04.cpp

Index: clang/test/Modules/cxx20-hu-04.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-04.cpp
@@ -0,0 +1,105 @@
+// Test macro preservation in C++20 Header Units.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-01.h \
+// RUN: -o hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-01.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \
+// RUN: -DFOO -fmodule-file=hu-01.pcm -o hu-02.pcm  -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -module-file-info hu-02.pcm | \
+// RUN: FileCheck --check-prefix=CHECK-HU2 %s -DTDIR=%t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface importer-01.cpp \
+// RUN:  -fmodule-file=hu-02.pcm -o B.pcm -DTDIR=%t -verify
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface importer-02.cpp \
+// RUN:  -fmodule-file=hu-02.pcm -o C.pcm -DTDIR=%t -Rmodule-import 2>&1 | \
+// RUN:  FileCheck --check-prefix=CHECK-IMP-HU2 %s -DTDIR=%t
+
+//--- hu-01.h
+#ifndef __GUARD
+#define __GUARD
+
+int baz(int);
+#define FORTYTWO 42
+
+#define SHOULD_NOT_BE_DEFINED -1
+#undef SHOULD_NOT_BE_DEFINED
+
+#endif // __GUARD
+// expected-no-diagnostics
+
+// CHECK-HU:  == C++20 Module structure ==
+// CHECK-HU-NEXT:  Header Unit './hu-01.h' is the Primary Module at index #1
+
+//--- hu-02.h
+export import "hu-01.h";
+#if !defined(FORTYTWO) || FORTYTWO != 42
+#error FORTYTWO missing in hu-02
+#endif
+
+#ifndef __GUARD
+#error __GUARD missing in hu-02
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED
+#error SHOULD_NOT_BE_DEFINED is visible
+#endif
+
+#define KAP 6174
+
+#ifdef FOO
+#define FOO_BRANCH(X) (X) + 1
+inline int foo(int x) {
+  if (x == FORTYTWO)
+return FOO_BRANCH(x);
+  return FORTYTWO;
+}
+#else
+#define BAR_BRANCH(X) (X) + 2
+inline int bar(int x) {
+  if (x == FORTYTWO)
+return BAR_BRANCH(x);
+  return FORTYTWO;
+}
+#endif
+
+// CHECK-IMP: remark: importing module './hu-01.h' from 'hu-01.pcm'
+// CHECK-HU2:  == C++20 Module structure ==
+// CHECK-HU2-NEXT:  Header Unit './hu-02.h' is the Primary Module at index #2
+// CHECK-HU2-NEXT:   Exports:
+// CHECK-HU2-NEXT:Header Unit './hu-01.h' is at index #1
+// expected-no-diagnostics
+
+//--- importer-01.cpp
+export module B;
+import "hu-02.h";
+
+int success(int x) {
+  return foo(FORTYTWO + x + KAP);
+}
+
+int fail(int x) {
+  return bar(FORTYTWO + x + KAP); // expected-error {{use of undeclared identifier 'bar'}}
+  // expected-note@* {{'baz' declared here}}
+}
+
+//--- importer-02.cpp
+export module C;
+import "hu-02.h";
+
+int success(int x) {
+  return foo(FORTYTWO + x + KAP);
+}
+
+// CHECK-IMP-HU2: remark: importing module './hu-02.h' from 'hu-02.pcm'
+// CHECK-IMP-HU2: remark: importing module './hu-01.h' into './hu-02.h' from '[[TDIR]]/hu-01.pcm'
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -2279,7 +2279,8 @@
 
 /// Writes the block containing the serialized form of the
 /// preprocessor.
-void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
+void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule,
+  Module *Mod) {
   uint64_t MacroOffsetsBase = Stream.GetCurrentBitNo();
 
   PreprocessingRecord *PPRec = PP.getPreprocessingRecord();
@@ -2345,16 +2346,19 @@
   // identifier they belong to.
   for (const IdentifierInfo *Name : MacroIdentifiers) {
 MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name);
+MacroInfo *MI = MD->getMacroInfo();
 uint64_t StartOffset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
 assert((StartOffset >> 32) == 0 && "Macro identifiers offset too large");
 
-// Emit the macro directives in reverse source order.
-for (; MD; MD = MD->getPrevious()) {
-  // Once we hit an ignored macro, we're done: the rest of the chain
-  // will all be ignored macros.
-  if (shouldIgnoreMacro(MD, IsModule, PP))
-break;
-
+// Write out any exported module macros.
+bool Emi

[PATCH] D121098: [C++20][Modules][HU 4/5] Handle pre-processed header units.

2022-03-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
Herald added a project: All.
iains added reviewers: rsmith, urnathan, ChuanqiXu.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We wish to support emitting a pre-processed output for an importable
header unit, that can be consumed to produce the same header units as
the original source.

This means that ee need to find the original filename used to produce
the re-preprocessed output, so that it can be assigned as the module
name.  This is peeked from the first line of the pre-processed source
when the action sets up the files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121098

Files:
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Sema/SemaModule.cpp


Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -109,10 +109,18 @@
 const_cast(getLangOpts()).CurrentModule = HUName.str();
   }
 
-  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
   // TODO: Make the C++20 header lookup independent.
-  Module::Header H{getLangOpts().CurrentModule, getLangOpts().CurrentModule,
-   SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())};
+  // When the input is pre-processed source, we need a file ref to the original
+  // file for the header map.
+  auto F = SourceMgr.getFileManager().getFile(HUName);
+  // For the sake of error recovery (if someone has moved the original header
+  // after creating the pre-processed output) fall back to obtaining the file
+  // ref for the input file, which must be present.
+  if (!F)
+F = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
+  assert(F && "failed to find the header unit source?");
+  Module::Header H{HUName.str(), HUName.str(), *F};
+  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
   Module *Mod = Map.createHeaderUnit(StartOfTU, HUName, H);
   assert(Mod && "module creation should not fail");
   ModuleScopes.push_back({}); // No GMF
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -843,6 +843,21 @@
   if (!CI.InitializeSourceManager(Input))
 return false;
 
+  if (CI.getLangOpts().CPlusPlusModules && Input.getKind().isHeaderUnit() &&
+  Input.getKind().isPreprocessed() && !usesPreprocessorOnly()) {
+// We have an input filename like foo.iih, but we want to find the right
+// module name (and original file, to build the map entry).
+// Check if the first line specifies the original source file name with a
+// linemarker.
+std::string PresumedInputFile = std::string(getCurrentFileOrBufferName());
+ReadOriginalFileName(CI, PresumedInputFile);
+// Unless the user overrides this, the module name is the name by which the
+// original file was known.
+if (CI.getLangOpts().ModuleName.empty())
+  CI.getLangOpts().ModuleName = std::string(PresumedInputFile);
+CI.getLangOpts().CurrentModule = CI.getLangOpts().ModuleName;
+  }
+
   // For module map files, we first parse the module map and synthesize a
   // "" buffer before more conventional processing.
   if (Input.getKind().getFormat() == InputKind::ModuleMap) {


Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -109,10 +109,18 @@
 const_cast(getLangOpts()).CurrentModule = HUName.str();
   }
 
-  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
   // TODO: Make the C++20 header lookup independent.
-  Module::Header H{getLangOpts().CurrentModule, getLangOpts().CurrentModule,
-   SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())};
+  // When the input is pre-processed source, we need a file ref to the original
+  // file for the header map.
+  auto F = SourceMgr.getFileManager().getFile(HUName);
+  // For the sake of error recovery (if someone has moved the original header
+  // after creating the pre-processed output) fall back to obtaining the file
+  // ref for the input file, which must be present.
+  if (!F)
+F = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
+  assert(F && "failed to find the header unit source?");
+  Module::Header H{HUName.str(), HUName.str(), *F};
+  auto &Map = PP.getHeaderSearchInfo().getModuleMap();
   Module *Mod = Map.createHeaderUnit(StartOfTU, HUName, H);
   assert(Mod && "module creation should not fail");
   ModuleScopes.push_back({}); // No GMF
Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -843,6 +843,21 @@
   if (!CI.InitializeSourceManager(Input))
 return false;
 
+  if (CI.getLangOpts().C

[PATCH] D121099: [C++20][Modules][HU 5/5] Add fdirectives-only mode for preprocessing output.

2022-03-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains created this revision.
Herald added a subscriber: dang.
Herald added a project: All.
iains added reviewers: rsmith, urnathan, ChuanqiXu.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When the -fdirectives-only option is used together with -E, the preprocessor
output reflects evaluation of if/then/else directives.

As such, it preserves defines and undefs of macros that are still live after
such processing.  The intent is that this output could be consumed as input
to generate considered a C++20 header unit.

We strip out any (unused) defines that come from built-in, built-in-file or
command line; these are re-added when the preprocessed source is consumed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121099

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/PreprocessorOutputOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/test/Modules/cxx20-hu-05.cpp

Index: clang/test/Modules/cxx20-hu-05.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-hu-05.cpp
@@ -0,0 +1,68 @@
+// Test check that consuming -E -fdirectives-only output produces the expected
+// header unit.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -E -fdirectives-only -xc++-user-header hu-01.h \
+// RUN: -o hu-01.iih
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit \
+// RUN: -xc++-user-header-cpp-output hu-01.iih -o hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header hu-02.h \
+// RUN: -DFOO -fmodule-file=hu-01.pcm -o hu-02.pcm -Rmodule-import 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-IMP %s -DTDIR=%t
+
+//--- hu-01.h
+#ifndef __GUARD
+#define __GUARD
+
+int baz(int);
+#define FORTYTWO 42
+
+#define SHOULD_NOT_BE_DEFINED -1
+#undef SHOULD_NOT_BE_DEFINED
+
+#endif // __GUARD
+// expected-no-diagnostics
+
+//--- hu-02.h
+export import "hu-01.h";
+#if !defined(FORTYTWO) || FORTYTWO != 42
+#error FORTYTWO missing in hu-02
+#endif
+
+#ifndef __GUARD
+#error __GUARD missing in hu-02
+#endif
+
+#ifdef SHOULD_NOT_BE_DEFINED
+#error SHOULD_NOT_BE_DEFINED is visible
+#endif
+
+// Make sure that we have not discarded macros from the builtin file.
+#ifndef __cplusplus
+#error we dropped a defined macro
+#endif
+
+#define KAP 6174
+
+#ifdef FOO
+#define FOO_BRANCH(X) (X) + 1
+inline int foo(int x) {
+  if (x == FORTYTWO)
+return FOO_BRANCH(x);
+  return FORTYTWO;
+}
+#else
+#define BAR_BRANCH(X) (X) + 2
+inline int bar(int x) {
+  if (x == FORTYTWO)
+return BAR_BRANCH(x);
+  return FORTYTWO;
+}
+#endif
+// CHECK-IMP: remark: importing module './hu-01.h' from 'hu-01.pcm'
Index: clang/lib/Frontend/PrintPreprocessedOutput.cpp
===
--- clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -96,6 +96,7 @@
   bool UseLineDirectives;
   bool IsFirstFileEntered;
   bool MinimizeWhitespace;
+  bool DirectivesOnly;
 
   Token PrevTok;
   Token PrevPrevTok;
@@ -103,12 +104,13 @@
 public:
   PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers,
bool defines, bool DumpIncludeDirectives,
-   bool UseLineDirectives, bool MinimizeWhitespace)
+   bool UseLineDirectives, bool MinimizeWhitespace,
+   bool DirectivesOnly)
   : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os),
 DisableLineMarkers(lineMarkers), DumpDefines(defines),
 DumpIncludeDirectives(DumpIncludeDirectives),
 UseLineDirectives(UseLineDirectives),
-MinimizeWhitespace(MinimizeWhitespace) {
+MinimizeWhitespace(MinimizeWhitespace), DirectivesOnly(DirectivesOnly) {
 CurLine = 0;
 CurFilename += "";
 EmittedTokensOnThisLine = false;
@@ -467,12 +469,21 @@
 void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
 const MacroDirective *MD) {
   const MacroInfo *MI = MD->getMacroInfo();
-  // Only print out macro definitions in -dD mode.
-  if (!DumpDefines ||
+  // Print out macro definitions in -dD mode and when we have -fdirectives-only
+  // for C++20 header units.
+  if ((!DumpDefines && !DirectivesOnly) ||
   // Ignore __FILE__ etc.
-  MI->isBuiltinMacro()) return;
+  MI->isBuiltinMacro())
+return;
 
-  MoveToLine(MI->getDefinitionLoc(), /*RequireStartOfLine=*/true);
+  SourceLocation DefLoc = MI->getDefinitionLoc();
+  if (DirectivesOnly && !MI->isUsed()) {
+SourceManager &SM = PP.getSourceManager();
+if (SM.isWrittenInBuiltinFile(DefLoc) ||
+SM.isWrittenInCommandLineFile(DefLoc))
+  return;
+  }
+  MoveToLine(DefLoc, /*RequireStartOfLine=*/true);
   PrintMacroDefinition

[PATCH] D121108: [pseudo] Add readme

2022-03-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121108

Files:
  clang/lib/Tooling/Syntax/Pseudo/README.md


Index: clang/lib/Tooling/Syntax/Pseudo/README.md
===
--- /dev/null
+++ clang/lib/Tooling/Syntax/Pseudo/README.md
@@ -0,0 +1,37 @@
+# clang pseudoparser
+
+This directory implements an approximate heuristic parser for C++, based on the
+clang lexer, the C++ grammar, and the GLR parsing algorithm.
+
+It parses a file in isolation, without reading its included headers.
+The result is a strict syntactic tree whose structure follows the C++ grammar.
+There is no syntactic analysis, apart from guesses to disambiguate the parse.
+Disambiguation can optionally be guided by an AST or a symbol index.
+
+For now, the best reference on intended scope is the [design proposal],
+with further discussion on the [RFC].
+
+## Dependencies between pseudoparser and clang
+
+Dependencies are limited because they don't make sense, but also to avoid
+placing a burden on clang mantainers.
+
+The pseudoparser reuses the clang lexer (clangLex and clangBasic libraries) but
+not the higher-level libraries (Parse, Sema, AST, Frontend...).
+
+When the pseudoparser should be used together with an AST (e.g. to guide
+disambiguation), this is a separate "bridge" library that depends on both.
+
+Clang does not depend on the pseudoparser at all. If this seems useful in 
future
+it should be discussed by RFC.
+
+## Parity between pseudoparser and clang
+
+The pseudoparser aims to understand real-world code, and particularly the
+languages and extensions supported by Clang.
+
+However we don't try to keep these in lockstep: there's no expectation that
+Clang parser changes are accompanied by pseudoparser changes or vice versa.
+
+[design proposal]: 
https://docs.google.com/document/d/1eGkTOsFja63wsv8v0vd5JdoTonj-NlN3ujGF0T7xDbM/edit
+[RFC]: https://discourse.llvm.org/t/rfc-a-c-pseudo-parser-for-tooling/59217/49


Index: clang/lib/Tooling/Syntax/Pseudo/README.md
===
--- /dev/null
+++ clang/lib/Tooling/Syntax/Pseudo/README.md
@@ -0,0 +1,37 @@
+# clang pseudoparser
+
+This directory implements an approximate heuristic parser for C++, based on the
+clang lexer, the C++ grammar, and the GLR parsing algorithm.
+
+It parses a file in isolation, without reading its included headers.
+The result is a strict syntactic tree whose structure follows the C++ grammar.
+There is no syntactic analysis, apart from guesses to disambiguate the parse.
+Disambiguation can optionally be guided by an AST or a symbol index.
+
+For now, the best reference on intended scope is the [design proposal],
+with further discussion on the [RFC].
+
+## Dependencies between pseudoparser and clang
+
+Dependencies are limited because they don't make sense, but also to avoid
+placing a burden on clang mantainers.
+
+The pseudoparser reuses the clang lexer (clangLex and clangBasic libraries) but
+not the higher-level libraries (Parse, Sema, AST, Frontend...).
+
+When the pseudoparser should be used together with an AST (e.g. to guide
+disambiguation), this is a separate "bridge" library that depends on both.
+
+Clang does not depend on the pseudoparser at all. If this seems useful in future
+it should be discussed by RFC.
+
+## Parity between pseudoparser and clang
+
+The pseudoparser aims to understand real-world code, and particularly the
+languages and extensions supported by Clang.
+
+However we don't try to keep these in lockstep: there's no expectation that
+Clang parser changes are accompanied by pseudoparser changes or vice versa.
+
+[design proposal]: https://docs.google.com/document/d/1eGkTOsFja63wsv8v0vd5JdoTonj-NlN3ujGF0T7xDbM/edit
+[RFC]: https://discourse.llvm.org/t/rfc-a-c-pseudo-parser-for-tooling/59217/49
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121092: [pseudo] Strip comments for TokenStream.

2022-03-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h:144
 
+/// Drops comment tokens.
+TokenStream stripComments(const TokenStream &);

I think this fits more naturally into Token.h next to cook().

It produces and consumes a token stream, and its implementation is a trivial 
use of those APIs.

While formally we might see comment stripping as part of the preprocessor, this 
file is more to do with directive structure. (Maybe it should be renamed?)



Comment at: clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp:158
+  // comment
+  int;
+)cpp";

also include a `/*comment*/` between int and ;?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121092

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


[PATCH] D121108: [pseudo] Add readme

2022-03-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks!




Comment at: clang/lib/Tooling/Syntax/Pseudo/README.md:8
+The result is a strict syntactic tree whose structure follows the C++ grammar.
+There is no syntactic analysis, apart from guesses to disambiguate the parse.
+Disambiguation can optionally be guided by an AST or a symbol index.

syntactic => semantic I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121108

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


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 marked 2 inline comments as done.
tyb0807 added inline comments.



Comment at: clang/test/Driver/aarch64-archs.c:296
-// NO-LS64-NOT: "-target-feature" "+ls64"
-// LS64: "-target-feature" "+ls64"
-

tmatheson wrote:
> Looks like these were duplicate tests? Besides `armv8.7a` vs `armv8.7-a`
Hmm, the first one tests that LS64 is not on by default on `armv8.7a`, and the 
second tests that `armv8.7a+ls64` enables it. Why these are duplicates?

If you mean L276/277, I guess the intent is to test both syntaxes that we 
support



Comment at: clang/test/Driver/aarch64-ras.c:14
+// RAS is on by default for v8.2a, but can be disabled by +noras
+// FIXME: in the current implementation, RAS is not on by default at all for 
v8.2a (the test says it all...)
+// RUN: %clang -target aarch64 -march=armv8.2a  -### -c %s 2>&1 | FileCheck 
-check-prefix=V82ARAS %s

tmatheson wrote:
> The RAS test changes are the only functional change to this review, which is 
> otherwise moving lines around and changing comments. I would keep the 
> original tests even if they're wrong, so that the history remains clearer. 
> Alternatively describe the RAS changes in the commit message and description.
Actually, I added the FIXME because I don't want to fix the test in this 
commit. There's no functional change to this review I think


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[PATCH] D121092: [pseudo] Strip comments for TokenStream.

2022-03-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h:144
 
+/// Drops comment tokens.
+TokenStream stripComments(const TokenStream &);

sammccall wrote:
> I think this fits more naturally into Token.h next to cook().
> 
> It produces and consumes a token stream, and its implementation is a trivial 
> use of those APIs.
> 
> While formally we might see comment stripping as part of the preprocessor, 
> this file is more to do with directive structure. (Maybe it should be 
> renamed?)
moving to Token.h sounds good to me -- I'd treat this is a trivial 
implementation (I just wrote it to test the GLR parser). And yeah, stripping 
comment is just part of preprocessing the code. 

> Maybe it should be renamed?

The current `Preprocess.h` file name indicates that everything about  
preprocessing of TokenStream should live in it.

Since this file defines PPStructure, just call it `PPStructure.h/cpp` for 
better fine grained granularity?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121092

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


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 added a comment.

> Yeah that sounds good. Maybe  aarch64-cortex-cpus.c might be a good start, to 
> avoid having too many small files.

Oops, I went ahead and split to many small cortex test files. Not really sure 
what would be better. What do you think @simon_tatham  @fhahn @tmatheson ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[PATCH] D121093: [Driver][AArch64] Split up aarch64-cpus.c test further

2022-03-07 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added a comment.

I like this version! This definitely says to me "nobody is going to just 
thoughtlessly append to an existing file".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121093

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


[PATCH] D119172: [pseudo] Implement LRGraph

2022-03-07 Thread Alex Tsao via Phabricator via cfe-commits
alextsao1999 added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h:96
+  uint8_t DotPos = 0;
+  uint8_t RuleLength = 0; // the length of rule body.
+};

hokein wrote:
> alextsao1999 wrote:
> > Can we add LookaheadSymbol here to implement LR(1)?
> we could do that. However, we don't have a plan to implement an `LR(1)` yet, 
> we use `SLR(1)`. (though LR(1) is more powerful than SLR(1), the typical 
> deterministic LR(1) parser cannot handle the C++ grammar, we need a "general" 
> parser GLR which can be able to handle arbitrary context-free grammars).
Thanks for your answering! Oh, I know some `GLR` parsers are based on `LR(1)` 
or `LALR`, so I think our `GLR` parser is based on `LR(1)` as well. I'm trying 
to keep up with your train of thought :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119172

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


[clang] bfc40b1 - [analyzer] Fix buildbot failure for D120369

2022-03-07 Thread Endre Fülöp via cfe-commits

Author: Endre Fülöp
Date: 2022-03-07T14:56:04+01:00
New Revision: bfc40b1a1a2c6149e2ebcdc47ffac7d018e2b78d

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

LOG: [analyzer] Fix buildbot failure for D120369

Fix test case for GenericTaintChecker.
Redefinition of types is a C11 feature, and it broke a buildbot.
Commit amended: 4fd6c6e65ab59f82284d8272aa3bec8d5084511e.

Added: 


Modified: 
clang/test/Analysis/taint-generic.c

Removed: 




diff  --git a/clang/test/Analysis/taint-generic.c 
b/clang/test/Analysis/taint-generic.c
index 0fdd05493172e..626e01e39d158 100644
--- a/clang/test/Analysis/taint-generic.c
+++ b/clang/test/Analysis/taint-generic.c
@@ -105,6 +105,13 @@ void *malloc(size_t);
 void *calloc(size_t nmemb, size_t size);
 void bcopy(void *s1, void *s2, size_t n);
 
+typedef size_t socklen_t;
+
+struct sockaddr {
+  unsigned short sa_family;
+  char sa_data[14];
+};
+
 #define BUFSIZE 10
 
 int Buffer[BUFSIZE];
@@ -437,8 +444,6 @@ int testGethostname(char *name, size_t len) {
   return system(name); // expected-warning {{Untrusted data is passed to a 
system call}}
 }
 
-struct sockaddr;
-typedef size_t socklen_t;
 int getnameinfo(const struct sockaddr *restrict addr, socklen_t addrlen,
 char *restrict host, socklen_t hostlen,
 char *restrict serv, socklen_t servlen, int flags);
@@ -506,13 +511,6 @@ void testRecv(int *buf, size_t len, int flags) {
   clang_analyzer_isTainted_int(read); // expected-warning {{YES}}
 }
 
-typedef size_t socklen_t;
-
-struct sockaddr {
-  unsigned short sa_family;
-  char sa_data[14];
-};
-
 ssize_t recvfrom(int sockfd, void *restrict buf, size_t len, int flags,
  struct sockaddr *restrict src_addr,
  socklen_t *restrict addrlen);



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


[PATCH] D118259: [AArch64] Adjust aarch64-neon-intrinsics-constrained test and un-XFAIL

2022-03-07 Thread John Brawn via Phabricator via cfe-commits
john.brawn added a comment.
Herald added a project: All.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118259

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


[PATCH] D121063: [AST] Make the last element in the linked list null

2022-03-07 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan resigned from this revision.
urnathan added a comment.

Huh? this web interface is confusing.  How did this ever work -- doesn't the 
decl's ctor set this to null?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121063

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


[PATCH] D121092: [pseudo] Strip comments for TokenStream.

2022-03-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 413446.
hokein marked an inline comment as done.
hokein added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121092

Files:
  clang/include/clang/Tooling/Syntax/Pseudo/Token.h
  clang/lib/Tooling/Syntax/Pseudo/Token.cpp
  clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp


Index: clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
===
--- clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
+++ clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
@@ -172,6 +172,23 @@
 }));
 }
 
+TEST(TokenTest, DropComments) {
+  LangOptions Opts;
+  std::string Code = R"cpp(
+  // comment
+  int /*abc*/;
+)cpp";
+  TokenStream Raw = cook(lex(Code, Opts), Opts);
+  TokenStream Stripped = stripComments(Raw);
+  EXPECT_THAT(Raw.tokens(),
+  ElementsAreArray(
+  {token("// comment", tok::comment), token("int", 
tok::kw_int),
+   token("/*abc*/", tok::comment), token(";", tok::semi)}));
+
+  EXPECT_THAT(Stripped.tokens(), ElementsAreArray({token("int", tok::kw_int),
+   token(";", tok::semi)}));
+}
+
 } // namespace
 } // namespace pseudo
 } // namespace syntax
Index: clang/lib/Tooling/Syntax/Pseudo/Token.cpp
===
--- clang/lib/Tooling/Syntax/Pseudo/Token.cpp
+++ clang/lib/Tooling/Syntax/Pseudo/Token.cpp
@@ -93,6 +93,17 @@
 OS << '\n';
 }
 
+TokenStream stripComments(const TokenStream &Input) {
+  TokenStream Out;
+  for (const Token &T : Input.tokens()) {
+if (T.Kind == tok::comment)
+  continue;
+Out.push(T);
+  }
+  Out.finalize();
+  return Out;
+}
+
 } // namespace pseudo
 } // namespace syntax
 } // namespace clang
Index: clang/include/clang/Tooling/Syntax/Pseudo/Token.h
===
--- clang/include/clang/Tooling/Syntax/Pseudo/Token.h
+++ clang/include/clang/Tooling/Syntax/Pseudo/Token.h
@@ -195,6 +195,9 @@
 /// (And having cooked token kinds in PP-disabled sections is useful for us).
 TokenStream cook(const TokenStream &, const clang::LangOptions &);
 
+/// Drops comment tokens.
+TokenStream stripComments(const TokenStream &);
+
 } // namespace pseudo
 } // namespace syntax
 } // namespace clang


Index: clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
===
--- clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
+++ clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
@@ -172,6 +172,23 @@
 }));
 }
 
+TEST(TokenTest, DropComments) {
+  LangOptions Opts;
+  std::string Code = R"cpp(
+  // comment
+  int /*abc*/;
+)cpp";
+  TokenStream Raw = cook(lex(Code, Opts), Opts);
+  TokenStream Stripped = stripComments(Raw);
+  EXPECT_THAT(Raw.tokens(),
+  ElementsAreArray(
+  {token("// comment", tok::comment), token("int", tok::kw_int),
+   token("/*abc*/", tok::comment), token(";", tok::semi)}));
+
+  EXPECT_THAT(Stripped.tokens(), ElementsAreArray({token("int", tok::kw_int),
+   token(";", tok::semi)}));
+}
+
 } // namespace
 } // namespace pseudo
 } // namespace syntax
Index: clang/lib/Tooling/Syntax/Pseudo/Token.cpp
===
--- clang/lib/Tooling/Syntax/Pseudo/Token.cpp
+++ clang/lib/Tooling/Syntax/Pseudo/Token.cpp
@@ -93,6 +93,17 @@
 OS << '\n';
 }
 
+TokenStream stripComments(const TokenStream &Input) {
+  TokenStream Out;
+  for (const Token &T : Input.tokens()) {
+if (T.Kind == tok::comment)
+  continue;
+Out.push(T);
+  }
+  Out.finalize();
+  return Out;
+}
+
 } // namespace pseudo
 } // namespace syntax
 } // namespace clang
Index: clang/include/clang/Tooling/Syntax/Pseudo/Token.h
===
--- clang/include/clang/Tooling/Syntax/Pseudo/Token.h
+++ clang/include/clang/Tooling/Syntax/Pseudo/Token.h
@@ -195,6 +195,9 @@
 /// (And having cooked token kinds in PP-disabled sections is useful for us).
 TokenStream cook(const TokenStream &, const clang::LangOptions &);
 
+/// Drops comment tokens.
+TokenStream stripComments(const TokenStream &);
+
 } // namespace pseudo
 } // namespace syntax
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119407: [PowerPC] [Clang] Add SSE4 and BMI compatible intrinsics implementation for PowerPC

2022-03-07 Thread Jinsong Ji via Phabricator via cfe-commits
jsji accepted this revision as: jsji.
jsji added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119407

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


[PATCH] D121112: [clang-format] Fix namespace end comments in ObjC++ files too

2022-03-07 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added reviewers: MyDeveloperDay, zequanwu.
Herald added a project: All.
thakis requested review of this revision.

See also d96ae867351ec.


https://reviews.llvm.org/D121112

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp


Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -416,6 +416,19 @@
 "// unrelated"));
 }
 
+TEST_F(NamespaceEndCommentsFixerTest, WorksForObjCpp) {
+  FormatStyle ObjCppStyle = getLLVMStyle();
+  ObjCppStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ("namespace {\n"
+"int i;\n"
+"int j;\n"
+"}// namespace",
+fixNamespaceEndComments("namespace {\n"
+"int i;\n"
+"int j;\n"
+"}", ObjCppStyle));
+}
+
 TEST_F(NamespaceEndCommentsFixerTest, AddsMacroEndComment) {
   FormatStyle Style = getLLVMStyle();
   Style.NamespaceMacros.push_back("TESTSUITE");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23340,7 +23340,7 @@
 }
 
 TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
-  // These tests are not in NamespaceFixer because that doesn't
+  // These tests are not in NamespaceEndCommentsFixerTest because that doesn't
   // test its interaction with line wrapping
   FormatStyle Style = getLLVMStyleWithColumns(80);
   verifyFormat("namespace {\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3190,7 +3190,7 @@
   return BracesRemover(Env, Expanded).process();
 });
 
-  if (Style.Language == FormatStyle::LK_Cpp) {
+  if (Style.isCpp()) {
 if (Style.FixNamespaceComments)
   Passes.emplace_back([&](const Environment &Env) {
 return NamespaceEndCommentsFixer(Env, Expanded).process();


Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -416,6 +416,19 @@
 "// unrelated"));
 }
 
+TEST_F(NamespaceEndCommentsFixerTest, WorksForObjCpp) {
+  FormatStyle ObjCppStyle = getLLVMStyle();
+  ObjCppStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ("namespace {\n"
+"int i;\n"
+"int j;\n"
+"}// namespace",
+fixNamespaceEndComments("namespace {\n"
+"int i;\n"
+"int j;\n"
+"}", ObjCppStyle));
+}
+
 TEST_F(NamespaceEndCommentsFixerTest, AddsMacroEndComment) {
   FormatStyle Style = getLLVMStyle();
   Style.NamespaceMacros.push_back("TESTSUITE");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23340,7 +23340,7 @@
 }
 
 TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {
-  // These tests are not in NamespaceFixer because that doesn't
+  // These tests are not in NamespaceEndCommentsFixerTest because that doesn't
   // test its interaction with line wrapping
   FormatStyle Style = getLLVMStyleWithColumns(80);
   verifyFormat("namespace {\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3190,7 +3190,7 @@
   return BracesRemover(Env, Expanded).process();
 });
 
-  if (Style.Language == FormatStyle::LK_Cpp) {
+  if (Style.isCpp()) {
 if (Style.FixNamespaceComments)
   Passes.emplace_back([&](const Environment &Env) {
 return NamespaceEndCommentsFixer(Env, Expanded).process();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119172: [pseudo] Implement LRGraph

2022-03-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h:96
+  uint8_t DotPos = 0;
+  uint8_t RuleLength = 0; // the length of rule body.
+};

alextsao1999 wrote:
> hokein wrote:
> > alextsao1999 wrote:
> > > Can we add LookaheadSymbol here to implement LR(1)?
> > we could do that. However, we don't have a plan to implement an `LR(1)` 
> > yet, we use `SLR(1)`. (though LR(1) is more powerful than SLR(1), the 
> > typical deterministic LR(1) parser cannot handle the C++ grammar, we need a 
> > "general" parser GLR which can be able to handle arbitrary context-free 
> > grammars).
> Thanks for your answering! Oh, I know some `GLR` parsers are based on `LR(1)` 
> or `LALR`, so I think our `GLR` parser is based on `LR(1)` as well. I'm 
> trying to keep up with your train of thought :)
Yeah, GLR changes the tradeoff between more sophisticated and simpler parsers 
(LR(1) > LALR > SLR(1) > LR(0)).

Normally the sophisticated parsers are able to handle grammars/languages that 
the simple ones can't, by avoiding action conflicts. So the value is very high.

However with GLR we can handle action conflicts by branching, so the value is 
"only" avoiding the performance hit of chasing branches that don't go anywhere.

So it didn't really seem worth the extra implementation complexity (or extra 
size of the in-memory grammar tables!) to use a more powerful parser than 
SLR(1). Maybe we should even have given LR(0) more thought :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119172

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


[PATCH] D121019: [clang-tools-extra] Document clang tidy unit tests target

2022-03-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!




Comment at: clang-tools-extra/docs/clang-tidy/Contributing.rst:369
+Test targets in LLVM and Clang are excluded from the "build all" style action 
of
+IDE based CMake generators, so you need to explicitly build the target for the 
unit
+tests to be built.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121019

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


[PATCH] D107141: [Inline-asm] Add structure type handling when they are tied in input and output constraints

2022-03-07 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 413453.
pengfei added a comment.
Herald added a project: All.

Refactor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107141

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/test/Sema/asm.c

Index: clang/test/Sema/asm.c
===
--- clang/test/Sema/asm.c
+++ clang/test/Sema/asm.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only
+// RUN: %clang_cc1 %s -Wno-private-extern -triple x86_64-pc-linux-gnu -verify -fsyntax-only -DTEST_X86_64
 
 
 void f(void) {
@@ -313,3 +314,69 @@
   asm ("jne %l0":::);
   asm goto ("jne %l0"lab);
 }
+
+typedef struct test19_a {
+  int a;
+  char b;
+} test19_a;
+
+typedef struct test19_b {
+  int a;
+  int b;
+  int c;
+} test19_b;
+
+typedef struct test19_c {
+  char a;
+  char b;
+} test19_c;
+
+typedef struct test19_d {
+  char a;
+  char b;
+  char c;
+  char d;
+} test19_d;
+
+typedef struct test19_e {
+  int a;
+  int b;
+  int c;
+  int d;
+} test19_e;
+
+#ifdef TEST_X86_64
+void test19(long long x)
+{
+  test19_a a;
+  test19_b b;
+  test19_c c;
+  test19_d d;
+  test19_e e;
+  asm ("" : "=rm" (a): "0" (1)); // no-error
+  asm ("" : "=rm" (d): "0" (1)); // no-error
+  asm ("" : "=rm" (c): "0" (x)); // no-error
+  asm ("" : "=rm" (x): "0" (a)); // no-error
+  asm ("" : "=rm" (a): "0" (d)); // no-error
+  asm ("" : "=rm" (b): "0" (1)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+  asm ("" : "=rm" (e): "0" (1)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+  asm ("" : "=rm" (x): "0" (e)); // no-error
+}
+#else
+void test19(long long x)
+{
+  test19_a a;
+  test19_b b;
+  test19_c c;
+  test19_d d;
+  test19_e e;
+  asm ("" : "=rm" (a): "0" (1)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+  asm ("" : "=rm" (d): "0" (1)); // no-error
+  asm ("" : "=rm" (c): "0" (x)); // no-error
+  asm ("" : "=rm" (x): "0" (a)); // no-error
+  asm ("" : "=rm" (a): "0" (d)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+  asm ("" : "=rm" (b): "0" (1)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+  asm ("" : "=rm" (e): "0" (1)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+  asm ("" : "=rm" (x): "0" (e)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+}
+#endif
Index: clang/lib/Sema/SemaStmtAsm.cpp
===
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -618,14 +618,16 @@
   AD_Int, AD_FP, AD_Other
 } InputDomain, OutputDomain;
 
-if (InTy->isIntegerType() || InTy->isPointerType())
+if (InTy->isIntegerType() || InTy->isPointerType() ||
+InTy->isStructureType() || InTy->isConstantArrayType())
   InputDomain = AD_Int;
 else if (InTy->isRealFloatingType())
   InputDomain = AD_FP;
 else
   InputDomain = AD_Other;
 
-if (OutTy->isIntegerType() || OutTy->isPointerType())
+if (OutTy->isIntegerType() || OutTy->isPointerType() ||
+OutTy->isStructureType() || OutTy->isConstantArrayType())
   OutputDomain = AD_Int;
 else if (OutTy->isRealFloatingType())
   OutputDomain = AD_FP;
@@ -667,8 +669,17 @@
 // output was a register, just extend the shorter one to the size of the
 // larger one.
 if (!SmallerValueMentioned && InputDomain != AD_Other &&
-OutputConstraintInfos[TiedTo].allowsRegister())
+OutputConstraintInfos[TiedTo].allowsRegister()) {
+  // FIXME: GCC supports the OutSize to be 128 at maximum. Currently codegen
+  // crash when the size larger than the register size. So we limit it here.
+  if (OutputDomain != AD_Int)
+continue;
+  if (OutSize < 8 || OutSize > Context.getTypeSize(Context.getSizeType()) ||
+  !llvm::isPowerOf2_32(OutSize))
+targetDiag(OutputExpr->getExprLoc(), diag::err_store_value_to_reg);
+
   continue;
+}
 
 // Either both of the operands were mentioned or the smaller one was
 // mentioned.  One more special case that we'll allow: if the tied input is
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2725,9 +2725,8 @@
   QualType Ty = getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
   if (Ty.isNull()) {
 const Expr *OutExpr = S.getOutputExpr(i);
-CGM.Error(
-OutExpr->getExprLoc(),
-"impossible constraint in asm: can't store value into a register");
+ 

[clang] 68b4e2d - [pseudo] Add readme

2022-03-07 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-03-07T15:54:00+01:00
New Revision: 68b4e2d703e3b89b44084825786106e32b456c9c

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

LOG: [pseudo] Add readme

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

Added: 
clang/lib/Tooling/Syntax/Pseudo/README.md

Modified: 


Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Pseudo/README.md 
b/clang/lib/Tooling/Syntax/Pseudo/README.md
new file mode 100644
index 0..0958f5d500e7f
--- /dev/null
+++ b/clang/lib/Tooling/Syntax/Pseudo/README.md
@@ -0,0 +1,37 @@
+# clang pseudoparser
+
+This directory implements an approximate heuristic parser for C++, based on the
+clang lexer, the C++ grammar, and the GLR parsing algorithm.
+
+It parses a file in isolation, without reading its included headers.
+The result is a strict syntactic tree whose structure follows the C++ grammar.
+There is no semantic analysis, apart from guesses to disambiguate the parse.
+Disambiguation can optionally be guided by an AST or a symbol index.
+
+For now, the best reference on intended scope is the [design proposal],
+with further discussion on the [RFC].
+
+## Dependencies between pseudoparser and clang
+
+Dependencies are limited because they don't make sense, but also to avoid
+placing a burden on clang mantainers.
+
+The pseudoparser reuses the clang lexer (clangLex and clangBasic libraries) but
+not the higher-level libraries (Parse, Sema, AST, Frontend...).
+
+When the pseudoparser should be used together with an AST (e.g. to guide
+disambiguation), this is a separate "bridge" library that depends on both.
+
+Clang does not depend on the pseudoparser at all. If this seems useful in 
future
+it should be discussed by RFC.
+
+## Parity between pseudoparser and clang
+
+The pseudoparser aims to understand real-world code, and particularly the
+languages and extensions supported by Clang.
+
+However we don't try to keep these in lockstep: there's no expectation that
+Clang parser changes are accompanied by pseudoparser changes or vice versa.
+
+[design proposal]: 
https://docs.google.com/document/d/1eGkTOsFja63wsv8v0vd5JdoTonj-NlN3ujGF0T7xDbM/edit
+[RFC]: https://discourse.llvm.org/t/rfc-a-c-pseudo-parser-for-tooling/59217/49



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


[PATCH] D121108: [pseudo] Add readme

2022-03-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG68b4e2d703e3: [pseudo] Add readme (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D121108?vs=413432&id=413456#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121108

Files:
  clang/lib/Tooling/Syntax/Pseudo/README.md


Index: clang/lib/Tooling/Syntax/Pseudo/README.md
===
--- /dev/null
+++ clang/lib/Tooling/Syntax/Pseudo/README.md
@@ -0,0 +1,37 @@
+# clang pseudoparser
+
+This directory implements an approximate heuristic parser for C++, based on the
+clang lexer, the C++ grammar, and the GLR parsing algorithm.
+
+It parses a file in isolation, without reading its included headers.
+The result is a strict syntactic tree whose structure follows the C++ grammar.
+There is no semantic analysis, apart from guesses to disambiguate the parse.
+Disambiguation can optionally be guided by an AST or a symbol index.
+
+For now, the best reference on intended scope is the [design proposal],
+with further discussion on the [RFC].
+
+## Dependencies between pseudoparser and clang
+
+Dependencies are limited because they don't make sense, but also to avoid
+placing a burden on clang mantainers.
+
+The pseudoparser reuses the clang lexer (clangLex and clangBasic libraries) but
+not the higher-level libraries (Parse, Sema, AST, Frontend...).
+
+When the pseudoparser should be used together with an AST (e.g. to guide
+disambiguation), this is a separate "bridge" library that depends on both.
+
+Clang does not depend on the pseudoparser at all. If this seems useful in 
future
+it should be discussed by RFC.
+
+## Parity between pseudoparser and clang
+
+The pseudoparser aims to understand real-world code, and particularly the
+languages and extensions supported by Clang.
+
+However we don't try to keep these in lockstep: there's no expectation that
+Clang parser changes are accompanied by pseudoparser changes or vice versa.
+
+[design proposal]: 
https://docs.google.com/document/d/1eGkTOsFja63wsv8v0vd5JdoTonj-NlN3ujGF0T7xDbM/edit
+[RFC]: https://discourse.llvm.org/t/rfc-a-c-pseudo-parser-for-tooling/59217/49


Index: clang/lib/Tooling/Syntax/Pseudo/README.md
===
--- /dev/null
+++ clang/lib/Tooling/Syntax/Pseudo/README.md
@@ -0,0 +1,37 @@
+# clang pseudoparser
+
+This directory implements an approximate heuristic parser for C++, based on the
+clang lexer, the C++ grammar, and the GLR parsing algorithm.
+
+It parses a file in isolation, without reading its included headers.
+The result is a strict syntactic tree whose structure follows the C++ grammar.
+There is no semantic analysis, apart from guesses to disambiguate the parse.
+Disambiguation can optionally be guided by an AST or a symbol index.
+
+For now, the best reference on intended scope is the [design proposal],
+with further discussion on the [RFC].
+
+## Dependencies between pseudoparser and clang
+
+Dependencies are limited because they don't make sense, but also to avoid
+placing a burden on clang mantainers.
+
+The pseudoparser reuses the clang lexer (clangLex and clangBasic libraries) but
+not the higher-level libraries (Parse, Sema, AST, Frontend...).
+
+When the pseudoparser should be used together with an AST (e.g. to guide
+disambiguation), this is a separate "bridge" library that depends on both.
+
+Clang does not depend on the pseudoparser at all. If this seems useful in future
+it should be discussed by RFC.
+
+## Parity between pseudoparser and clang
+
+The pseudoparser aims to understand real-world code, and particularly the
+languages and extensions supported by Clang.
+
+However we don't try to keep these in lockstep: there's no expectation that
+Clang parser changes are accompanied by pseudoparser changes or vice versa.
+
+[design proposal]: https://docs.google.com/document/d/1eGkTOsFja63wsv8v0vd5JdoTonj-NlN3ujGF0T7xDbM/edit
+[RFC]: https://discourse.llvm.org/t/rfc-a-c-pseudo-parser-for-tooling/59217/49
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121078: Replace links to archived mailing lists by links to Discourse forums

2022-03-07 Thread Louis Dionne via Phabricator via cfe-commits
ldionne requested changes to this revision.
ldionne added a comment.
This revision now requires changes to proceed.

Thanks for doing this! We need to fix a few undefined references, though.




Comment at: libcxx/docs/index.rst:223
 * `libcxx-commits Mailing List`_
 * `libcxx-dev Mailing List`_
 * `Browse libc++ Sources 
`_

I think this needs to be updated!



Comment at: libunwind/docs/index.rst:103
 * `cfe-commits Mailing List`_
 * `cfe-dev Mailing List`_
 * `Browse libunwind Sources 
`_

Probably this one too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121078

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


[PATCH] D121063: [AST] Make the last element in the linked list null

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

I suspect this works because we never really treated this as a LL, just as a 
pair of iterators.  Two things:

1- Can you produce some situation where this is valuable to do?
2- Can you switch this over so that the NextInContextAndBits initializes to 
nullptr/0 so that this line isn't necessary?  I can't imagine we ever re-call 
this on a decl and have the answer be different.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121063

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


[PATCH] D121019: [clang-tools-extra] Document clang tidy unit tests target

2022-03-07 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood updated this revision to Diff 413464.
LegalizeAdulthood added a comment.

Update from review comments


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

https://reviews.llvm.org/D121019

Files:
  clang-tools-extra/docs/clang-tidy/Contributing.rst


Index: clang-tools-extra/docs/clang-tidy/Contributing.rst
===
--- clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -364,6 +364,11 @@
 test.  The ``ASTMatchersTests`` target contains unit tests for the public AST 
matcher
 classes and is a good source of testing idioms for matchers.
 
+You can build the Clang-tidy unit tests by building the ``ClangTidyTests`` 
target.
+Test targets in LLVM and Clang are excluded from the "build all" style action 
of
+IDE-based CMake generators, so you need to explicitly build the target for the 
unit
+tests to be built.
+
 Making your check robust
 
 


Index: clang-tools-extra/docs/clang-tidy/Contributing.rst
===
--- clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -364,6 +364,11 @@
 test.  The ``ASTMatchersTests`` target contains unit tests for the public AST matcher
 classes and is a good source of testing idioms for matchers.
 
+You can build the Clang-tidy unit tests by building the ``ClangTidyTests`` target.
+Test targets in LLVM and Clang are excluded from the "build all" style action of
+IDE-based CMake generators, so you need to explicitly build the target for the unit
+tests to be built.
+
 Making your check robust
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121078: Replace links to archived mailing lists by links to Discourse forums

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

I think we need to retain *some* references to the existing mailing list 
archives. The migration to Discourse worked fairly well, but there were still 
data migration issues.  For example:

https://discourse.llvm.org/t/memory-barrier-problem/57493
https://lists.llvm.org/pipermail/llvm-dev/2021-January/148151.html

Also, the commits mailing lists are still hosted by mailman and remain relevant 
to the community for the foreseeable future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121078

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


[clang-tools-extra] de29719 - [clang-tools-extra] Document clang tidy unit tests target

2022-03-07 Thread via cfe-commits

Author: Richard
Date: 2022-03-07T08:24:08-07:00
New Revision: de29719af2c7d1772e14b45f8da75626735246e6

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

LOG: [clang-tools-extra] Document clang tidy unit tests target

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

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/Contributing.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst 
b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index b1771574950a8..5849353591cc2 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -364,6 +364,11 @@ other support classes by writing a unit test than by 
writing a ``FileCheck`` int
 test.  The ``ASTMatchersTests`` target contains unit tests for the public AST 
matcher
 classes and is a good source of testing idioms for matchers.
 
+You can build the Clang-tidy unit tests by building the ``ClangTidyTests`` 
target.
+Test targets in LLVM and Clang are excluded from the "build all" style action 
of
+IDE-based CMake generators, so you need to explicitly build the target for the 
unit
+tests to be built.
+
 Making your check robust
 
 



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


[clang] d65952b - [clang] Adjust LookupTest for UsingTypeLocs

2022-03-07 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-03-07T16:22:03+01:00
New Revision: d65952b9bd8099b7405a4168d501596256a49f87

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

LOG: [clang] Adjust LookupTest for UsingTypeLocs

We no longer traverse the underlying RecordTypeLoc directly, but rather
visit the UsingTypeLoc.

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

Added: 


Modified: 
clang/unittests/Tooling/LookupTest.cpp

Removed: 




diff  --git a/clang/unittests/Tooling/LookupTest.cpp 
b/clang/unittests/Tooling/LookupTest.cpp
index 05494cb42d904..2cf5ebb2a4cbd 100644
--- a/clang/unittests/Tooling/LookupTest.cpp
+++ b/clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@ struct GetDeclsVisitor : TestVisitor {
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@ TEST(LookupTest, replaceNestedFunctionName) {
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(), 
Visitor.DeclStack.back()->getDeclContext(),
-FD, ReplacementString);
+nullptr, Loc, Visitor.DeclStack.back()->getDeclContext(), ND,
+ReplacementString);
   };
 
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("x::Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+  EXPECT_EQ("x::Bar", replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(),
+ "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b {\n"
@@ -201,12 +210,13 @@ TEST(LookupTest, replaceNestedClassName) {
   "namespace c { Foo f();; }\n"
   "} }\n");
 
-  Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
+  Visitor.OnUsingTypeLoc = [&](UsingTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 // `a::b::Foo` in using shadow decl is not `TypeLoc`.
-if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+auto *TD = Type.getFoundDecl()->getTargetDecl();
+if (TD->getQualifiedNameAsString() == "a::b::Foo") {
+  EXPECT_EQ("Bar", replaceTypeLoc(TD, Type.getBeginLoc(), "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b { class Foo {}; } }\n"
@@ -218,7 +228,8 @@ TEST(LookupTest, replaceNestedClassName) {
   // it's not visible at [0].
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 if (Type.getDecl()->getQualifiedNameAsString() == "x::y::Old") {
-  EXPECT_EQ("Foo", replaceRecordTypeLoc(Type, "::x::Foo"));
+  EXPECT_EQ("Foo",
+replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(), 
"::x::Foo"));
 }
   };
   Visitor.runOver(R"(



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


[PATCH] D121019: [clang-tools-extra] Document clang tidy unit tests target

2022-03-07 Thread Richard 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 rGde29719af2c7: [clang-tools-extra] Document clang tidy unit 
tests target (authored by LegalizeAdulthood).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121019

Files:
  clang-tools-extra/docs/clang-tidy/Contributing.rst


Index: clang-tools-extra/docs/clang-tidy/Contributing.rst
===
--- clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -364,6 +364,11 @@
 test.  The ``ASTMatchersTests`` target contains unit tests for the public AST 
matcher
 classes and is a good source of testing idioms for matchers.
 
+You can build the Clang-tidy unit tests by building the ``ClangTidyTests`` 
target.
+Test targets in LLVM and Clang are excluded from the "build all" style action 
of
+IDE-based CMake generators, so you need to explicitly build the target for the 
unit
+tests to be built.
+
 Making your check robust
 
 


Index: clang-tools-extra/docs/clang-tidy/Contributing.rst
===
--- clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -364,6 +364,11 @@
 test.  The ``ASTMatchersTests`` target contains unit tests for the public AST matcher
 classes and is a good source of testing idioms for matchers.
 
+You can build the Clang-tidy unit tests by building the ``ClangTidyTests`` target.
+Test targets in LLVM and Clang are excluded from the "build all" style action of
+IDE-based CMake generators, so you need to explicitly build the target for the unit
+tests to be built.
+
 Making your check robust
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121103: [clang] Adjust LookupTest for UsingTypeLocs

2022-03-07 Thread Kadir Cetinkaya 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 rGd65952b9bd80: [clang] Adjust LookupTest for UsingTypeLocs 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121103

Files:
  clang/unittests/Tooling/LookupTest.cpp


Index: clang/unittests/Tooling/LookupTest.cpp
===
--- clang/unittests/Tooling/LookupTest.cpp
+++ clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(), 
Visitor.DeclStack.back()->getDeclContext(),
-FD, ReplacementString);
+nullptr, Loc, Visitor.DeclStack.back()->getDeclContext(), ND,
+ReplacementString);
   };
 
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("x::Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+  EXPECT_EQ("x::Bar", replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(),
+ "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b {\n"
@@ -201,12 +210,13 @@
   "namespace c { Foo f();; }\n"
   "} }\n");
 
-  Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
+  Visitor.OnUsingTypeLoc = [&](UsingTypeLoc Type) {
 // Filter Types by name since there are other `RecordTypeLoc` in the test
 // file.
 // `a::b::Foo` in using shadow decl is not `TypeLoc`.
-if (Type.getDecl()->getQualifiedNameAsString() == "a::b::Foo") {
-  EXPECT_EQ("Bar", replaceRecordTypeLoc(Type, "::a::x::Bar"));
+auto *TD = Type.getFoundDecl()->getTargetDecl();
+if (TD->getQualifiedNameAsString() == "a::b::Foo") {
+  EXPECT_EQ("Bar", replaceTypeLoc(TD, Type.getBeginLoc(), "::a::x::Bar"));
 }
   };
   Visitor.runOver("namespace a { namespace b { class Foo {}; } }\n"
@@ -218,7 +228,8 @@
   // it's not visible at [0].
   Visitor.OnRecordTypeLoc = [&](RecordTypeLoc Type) {
 if (Type.getDecl()->getQualifiedNameAsString() == "x::y::Old") {
-  EXPECT_EQ("Foo", replaceRecordTypeLoc(Type, "::x::Foo"));
+  EXPECT_EQ("Foo",
+replaceTypeLoc(Type.getDecl(), Type.getBeginLoc(), 
"::x::Foo"));
 }
   };
   Visitor.runOver(R"(


Index: clang/unittests/Tooling/LookupTest.cpp
===
--- clang/unittests/Tooling/LookupTest.cpp
+++ clang/unittests/Tooling/LookupTest.cpp
@@ -8,12 +8,15 @@
 
 #include "clang/Tooling/Refactoring/Lookup.h"
 #include "TestVisitor.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
 using namespace clang;
 
 namespace {
 struct GetDeclsVisitor : TestVisitor {
   std::function OnCall;
   std::function OnRecordTypeLoc;
+  std::function OnUsingTypeLoc;
   SmallVector DeclStack;
 
   bool VisitCallExpr(CallExpr *Expr) {
@@ -28,6 +31,12 @@
 return true;
   }
 
+  bool VisitUsingTypeLoc(UsingTypeLoc Loc) {
+if (OnUsingTypeLoc)
+  OnUsingTypeLoc(Loc);
+return true;
+  }
+
   bool TraverseDecl(Decl *D) {
 DeclStack.push_back(D);
 bool Ret = TestVisitor::TraverseDecl(D);
@@ -181,19 +190,19 @@
 TEST(LookupTest, replaceNestedClassName) {
   GetDeclsVisitor Visitor;
 
-  auto replaceRecordTypeLoc = [&](RecordTypeLoc TLoc,
-  StringRef ReplacementString) {
-const auto *FD = cast(TLoc.getDecl());
+  auto replaceTypeLoc = [&](const NamedDecl *ND, SourceLocation Loc,
+StringRef ReplacementString) {
 return tooling::replaceNestedName(
-nullptr, TLoc.getBeginLoc(), Visitor.DeclStack.back()->getDeclContext()

[PATCH] D120323: [clang][SVE] Add support for arithmetic operators on SVE types

2022-03-07 Thread David Truby via Phabricator via cfe-commits
DavidTruby updated this revision to Diff 413470.
DavidTruby added a comment.

Add tests for in-place operators


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120323

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-ops.c
  clang/test/Sema/aarch64-sve-vector-ops.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -211,11 +211,6 @@
   __real init_int8; // expected-error {{invalid type 'svint8_t'}}
   __imag init_int8; // expected-error {{invalid type 'svint8_t'}}
 
-  local_int8 + init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 - init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 *init_int8;   // expected-error {{invalid operands to binary expression}}
-  local_int8 / init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 % init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 &init_int8;   // expected-error {{invalid operands to binary expression}}
   local_int8 | init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 ^ init_int8;  // expected-error {{invalid operands to binary expression}}
@@ -230,11 +225,6 @@
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
 
-  local_int8 += init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 -= init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 *= init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 /= init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 %= init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 &= init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 |= init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 ^= init_int8;  // expected-error {{invalid operands to binary expression}}
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -199,11 +199,6 @@
   __real init_int8; // expected-error {{invalid type 'svint8_t'}}
   __imag init_int8; // expected-error {{invalid type 'svint8_t'}}
 
-  local_int8 + init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 - init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 *init_int8;   // expected-error {{invalid operands to binary expression}}
-  local_int8 / init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 % init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 &init_int8;   // expected-error {{invalid operands to binary expression}}
   local_int8 | init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 ^ init_int8;  // expected-error {{invalid operands to binary expression}}
@@ -218,11 +213,6 @@
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}}
 
-  local_int8 += init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 -= init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 *= init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 /= init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 %= init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 &= init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 |= init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 ^= init_int8;  // expected-error {{invalid operands to binary expression}}
Index: clang/test/Sema/aarch64-sve-vector-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-ops.c
@@ -0,0 +1,645 @@
+// RUN: %clang_cc1 -verify -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -fsyntax-only %s
+
+// REQUIRES: aarch64-registered-target || arm-registered-target
+
+#include 
+
+void add(svint8_t i8, svint16_t i16, svint32_t i32, svint

[PATCH] D120296: [Attr] Fix a btf_type_tag AST generation bug

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

I only looked at the 'new type' code, and it generally looks correct with the 
exception of the comments below.




Comment at: clang/include/clang/AST/Type.h:4793
+
+  QualType ModifiedType;
+  QualType EquivalentType;

I suspect both of these aren't necessary.  If the intent here is to just wrap a 
single type, I think we can have only 1.  Then the fields here are just the 
Tag, and the WrappedType.



Comment at: clang/include/clang/Serialization/ASTRecordReader.h:131
 
+  StringRef readStringRef() { return readString(); }
+

This is a bug.  readString returns a std::string temporary, which creating the 
StringRef to, it now no longer exists.



Comment at: clang/lib/Sema/SemaType.cpp:194
+std::pair;
+SmallVector AttrsForBTFTagTypes;
+bool AttrsForBTFTagTypesSorted = true;

This seems pretty absurdly expensive here... Should we instead have the 
BTFTagAttributedType store its Attr here?



Comment at: clang/lib/Sema/TreeTransform.h:6872
+  const BTFTagAttributedType *oldType = TL.getTypePtr();
+  StringRef Tag = oldType->getTag();
+  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());

Most of this tree-transform doesn't really do much, since this is a 'C' only 
type, but otherwise we'd probably want to allow the tag itself to be dependent. 
 

We still need this though, since there are other non-template tree-transforms.

You also might need to make this not contain a `StringRef` based on the 
serialization issues above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120296

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


[PATCH] D118352: [clang][ABI] New c++20 modules mangling scheme

2022-03-07 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan updated this revision to Diff 413472.
urnathan added a comment.

added partition tests


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

https://reviews.llvm.org/D118352

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
  clang/test/CXX/modules-ts/basic/basic.link/p3.cppm
  clang/test/CXX/modules-ts/codegen-basics.cppm
  clang/test/CodeGenCXX/Inputs/cxx20-module-impl-1a.cpp
  clang/test/CodeGenCXX/Inputs/cxx20-module-std-subst-2a.cpp
  clang/test/CodeGenCXX/cxx20-module-decomp-1.cpp
  clang/test/CodeGenCXX/cxx20-module-extern-1.cppm
  clang/test/CodeGenCXX/cxx20-module-impl-1a.cpp
  clang/test/CodeGenCXX/cxx20-module-nested-1.cppm
  clang/test/CodeGenCXX/cxx20-module-nested-2.cppm
  clang/test/CodeGenCXX/cxx20-module-part-1a.cpp
  clang/test/CodeGenCXX/cxx20-module-part-1b.cpp
  clang/test/CodeGenCXX/cxx20-module-part-1c.cpp
  clang/test/CodeGenCXX/cxx20-module-std-subst-1.cppm
  clang/test/CodeGenCXX/cxx20-module-std-subst-2b.cpp
  clang/test/CodeGenCXX/cxx20-module-std-subst-2c.cpp
  clang/test/CodeGenCXX/cxx20-module-sub-1a.cppm
  clang/test/CodeGenCXX/cxx20-module-sub-1b.cppm
  clang/test/CodeGenCXX/cxx20-module-tmpl-1.cppm

Index: clang/test/CodeGenCXX/cxx20-module-tmpl-1.cppm
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-tmpl-1.cppm
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s
+
+export module FOO;
+
+class One;
+class Two;
+
+export template struct TPL
+{
+void M (T *);
+template void N (T *, U*);
+};
+
+template
+void TPL::M (T *) {}
+
+template template void TPL::N (T *, U*) {}
+
+// CHECK-DAG: void @_ZNW3FOO3TPLIS_3OneE1MEPS1_(
+template void TPL::M (One *);
+// CHECK-DAG: void @_ZNW3FOO3TPLIS_3OneE1NIS_3TwoEEvPS1_PT_(
+template void TPL::N (One *, Two *);
+
+namespace NMS {
+class One;
+class Two;
+
+export template struct TPL
+{
+void M (T *);
+template void N (T *, U*);
+};
+
+template
+void TPL::M (T *) {}
+
+template template void TPL::N (T *, U*) {}
+
+// CHECK-DAG: void @_ZN3NMSW3FOO3TPLINS_S0_3OneEE1MEPS2_(
+template void TPL::M (One *);
+// CHECK-DAG: void @_ZN3NMSW3FOO3TPLINS_S0_3OneEE1NINS_S0_3TwoEEEvPS2_PT_
+template void TPL::N (One *, Two *);
+}
Index: clang/test/CodeGenCXX/cxx20-module-sub-1b.cppm
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-sub-1b.cppm
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 %S/cxx20-module-sub-1a.cppm -triple %itanium_abi_triple -emit-module-interface -o %t
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s
+
+export module FOO.BAZ;
+import FOO.BAR;
+
+namespace Bob {
+
+// CHECK-DAG: void @_ZN3BobW3FOOW3BAZ3FooEPS0_W3BAR1APNS_S2_1BE(
+void Foo (A *, B*) {
+}
+}
+
+// CHECK-DAG: void @_ZW3FOOW3BAZ3BarPS_W3BAR1APN3BobS1_1BE(
+void Bar (A *, Bob::B*) {
+}
Index: clang/test/CodeGenCXX/cxx20-module-sub-1a.cppm
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-sub-1a.cppm
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s
+
+export module FOO.BAR;
+export class A;
+namespace Bob {
+export class B;
+
+// CHECK-DAG: void @_ZN3BobW3FOOW3BAR3BarEPS1_1APNS_S1_1BE(
+export void Bar (A *, B*) {
+}
+}
+
+// CHECK-DAG: void @_ZW3FOOW3BAR3FooPS0_1APN3BobS0_1BE(
+export void Foo (A *, Bob::B*) {
+}
Index: clang/test/CodeGenCXX/cxx20-module-std-subst-2c.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-std-subst-2c.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++20 %S/Inputs/cxx20-module-std-subst-2a.cpp -triple %itanium_abi_triple -emit-module-interface -o %t
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s
+module;
+# 5 __FILE__ 1
+namespace std {
+template  struct char_traits {};
+} // namespace std
+# 9 "" 2
+export module Bar;
+import RenameString;
+
+// Use Ss as this is global-module std::char_traits
+// CHECK-DAG: void @_ZW3Bar1gRSs(
+void g(str> &s) {
+}
Index: clang/test/CodeGenCXX/cxx20-module-std-subst-2b.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-std-subst-2b.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++20 %S/Inputs/cxx20-module-std-subst-2a.cpp -triple %itanium_abi_triple -emit-module-interface -o %t
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s
+
+export module Foo;
+import RenameString;
+
+namespace std {
+template  s

[PATCH] D118352: [clang][ABI] New c++20 modules mangling scheme

2022-03-07 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added a comment.

In D118352#3362694 , @ChuanqiXu wrote:

> In D118352#3359626 , @urnathan 
> wrote:
>
>> 



>> Correct, it is not called as the global initializer pieces are not yet 
>> implemented.  Let's not hold up this patch for that nor remove piece that 
>> will become necessary at that point.
>
> It's odd to see unused functions. I just worry about that other people might 
> delete these functions as cleaning up (maybe there wouldn't be).

That's a risk I'm ok with.

> Although the general declarations in partitions wouldn't be mangled 
> specially, I think it would be better to add test case to show that.

good idea, added.


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

https://reviews.llvm.org/D118352

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


[PATCH] D121122: Set FLT_EVAL_METHOD to -1 when fast-math is enabled.

2022-03-07 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam created this revision.
zahiraam added reviewers: andrew.w.kaylor, aaron.ballman, thakis, rjmccall, 
fhahn.
Herald added a project: All.
zahiraam requested review of this revision.
Herald added a project: clang.

Currently the control of the eval-method is mixed with fast-math.  
FLT_EVAL_METHOD tells the user the precision at which, temporary results
are evaluated but when fast-math is enabled, the numeric values are not 
guaranteed to match the source semantics, so the eval-method is
meaningless.
For example, the expression `x + y + z` has as source semantics `(x + y) + z`. 
FLT_EVAL_METHOD is telling the user at which precision `(x + y)`
is evaluated. With fast-math enable the compiler may choose to evaluate the 
expression as `(y + z) + x`.

The correct behavior is to set the FLT_EVAL_METHOD to `-1`, to tell the user 
that the precision of the intermediate values is unknow. 
This patch is doing that.

This patch is also fixing a crash when the `pragma clang fp  eval-method` is 
given the wrong value (should be source, double, extended).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121122

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/test/CodeGen/eval-method-fast-math.c
  clang/test/Sema/fp-eval-pragma.cpp

Index: clang/test/Sema/fp-eval-pragma.cpp
===
--- clang/test/Sema/fp-eval-pragma.cpp
+++ clang/test/Sema/fp-eval-pragma.cpp
@@ -27,6 +27,16 @@
   return 0;
 }
 
+void apply_pragma_with_wrong_value() {
+ // expected-error@+1{{unexpected argument 'value' to '#pragma clang fp eval_method'; expected 'source' or 'double' or 'extended'}}
+#pragma clang fp eval_method(value)
+}
+
+int foo3() {
+  apply_pragma_with_wrong_value();
+  return 0;
+}
+
 void foo() {
   auto a = __FLT_EVAL_METHOD__;
   {
Index: clang/test/CodeGen/eval-method-fast-math.c
===
--- /dev/null
+++ clang/test/CodeGen/eval-method-fast-math.c
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fexperimental-strict-floating-point  \
+// RUN: -triple x86_64-linux-gnu -emit-llvm -o - %s  \
+// RUN: | FileCheck %s -check-prefixes=CHECK
+
+// RUN: %clang_cc1 -triple i386--linux -emit-llvm -o - %s \
+// RUN: | FileCheck %s -check-prefixes=CHECK-EXT
+
+// RUN: %clang_cc1 -fexperimental-strict-floating-point  \
+// RUN: -mreassociate -freciprocal-math -ffp-contract=fast \
+// RUN: -ffast-math -triple x86_64-linux-gnu \
+// RUN: -emit-llvm -o - %s \
+// RUN: | FileCheck %s -check-prefixes=CHECK-FAST
+
+// RUN: %clang_cc1 -triple i386--linux -mreassociate -freciprocal-math \
+// RUN: -ffp-contract=fast -ffast-math -emit-llvm -o - %s \
+// RUN: | FileCheck %s -check-prefixes=CHECK-FAST
+
+float res;
+int add(float a, float b, float c) {
+  // CHECK: fadd float
+  // CHECK: load float, float*
+  // CHECK: fadd float
+  // CHECK: store float
+  // CHECK-FAST: fadd fast float
+  // CHECK-FAST: load float, float*
+  // CHECK-FAST: fadd fast float
+  // CHECK: ret i32 0
+  // CHECK-EXT: ret i32 2
+  // CHECK-FAST: ret i32 -1
+  res = a + b + c;
+  return __FLT_EVAL_METHOD__;
+}
+
+int add_precise(float a, float b, float c) {
+#pragma float_control(precise, on)
+  // CHECK: fadd float
+  // CHECK: load float, float*
+  // CHECK: fadd float
+  // CHECK: store float
+  // CHECK: ret i32 0
+  // CHECK-FAST: ret i32 -1
+  res = a + b + c;
+  return __FLT_EVAL_METHOD__;
+}
+
+int add_not_precise(float a, float b, float c) {
+  // Fast-math is enabled with this pragma.
+#pragma float_control(precise, off)
+  // CHECK-FAST: fadd fast float
+  // CHECK-FAST: load float, float*
+  // CHECK-FAST: fadd fast float
+  // CHECK-FAST: ret i32 -1
+  res = a + b + c;
+  return __FLT_EVAL_METHOD__;
+}
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -517,6 +517,10 @@
 else
   NewFPFeatures.setFPPreciseEnabled(false);
 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
+// Fast-math is enabled.
+PP.setCurrentFPEvalMethod(
+Loc, LangOptions::FPEvalMethodKind::FEM_Indeterminable);
+PP.getCurrentFPEvalMethod();
 break;
   case PFC_Except:
 if (!isPreciseFPEnabled())
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -254,6 +254,9 @@
 PP.setCurrentFPEvalMethod(SourceLocation(),
   getLangOpts().getFPEvalMethod());
   CurFPFeatures.setFPEvalMethod(PP.getCurrentFPEvalMethod());
+  // Fast-math is enabled.
+  if (getLangOpts().AllowFPReassoc || getLangOpts().AllowRecip)
+PP.setCurrentFPEvalMethod(SourceLocation(), LangOptions::FEM_Indeterminable);
 }
 
 // Anchor Sema's type info to this TU.
Index: clang/lib/Lex/PPMa

[PATCH] D119609: [Clang][Sema] Don't act on ReturnStmt when parsing the lambda declarator.

2022-03-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4366
+def err_expr_statement_in_default_arg : Error<
+  "can't use expression statement in default argument">;
 

I'm not a fan of this text here(for 1, contractions aren't permitted I think), 
but I suspect Aaron is the best one to bikeshed.  Until then, I might suggest 
something like:

"expression statement not permitted in default argument".



Comment at: clang/lib/Parse/ParseDecl.cpp:7092
+  Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
+  SkipUntil(tok::comma, tok::r_paren, StopAtSemi | 
StopBeforeMatch);
+  return;

Can we have a test to make sure this properly captures everything/doesn't get 
confused with parens/braces inside the expression statement?



Comment at: clang/test/Sema/err-expr-stmt-in-default-arg.cpp:19
+  return bar(l);
+}

For completeness, I'd like to see an in-function-defined-struct-member-function 
test here as well.

As for the above question about the recovery, something like:

`void fn(int i, int j = ({ {},{},{,} }), int k = "");` I think checks all the 
issues I can think of.  We want to make sure that 'k' still diagnoses its error 
correctly (and that we have just skipped all of the expression statement stuff).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[clang] d03e342 - [clang-format] Fix assertion failure/crash with `AllowShortFunctionsOnASingleLine: Inline/InlineOnly`.

2022-03-07 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2022-03-07T16:54:08+01:00
New Revision: d03e342803df7a75fb86c5a5c07cd84f3683bef9

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

LOG: [clang-format] Fix assertion failure/crash with 
`AllowShortFunctionsOnASingleLine: Inline/InlineOnly`.

Fixes https://github.com/llvm/llvm-project/issues/54147.

When handling `AllowShortFunctionsOnASingleLine`, we were searching for the 
last line with a smaller level than the current line. The search was incorrect 
when the first line had the same level as the current one. This led to an 
unsatisfied assumption about the existence of a brace (non-comment token).

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index dbf1e4cbbf6a3..5b5439901b2f7 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -310,6 +310,8 @@ class LineJoiner {
   for (; J != AnnotatedLines.begin(); --J)
 if ((*J)->Level < TheLine->Level)
   break;
+  if ((*J)->Level >= TheLine->Level)
+return false;
 
   // Check if the found line starts a record.
   const FormatToken *LastNonComment = (*J)->Last;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8909acdae5dc3..1f8601d30857c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12669,6 +12669,13 @@ TEST_F(FormatTest, 
PullInlineFunctionDefinitionsIntoSingleLine) {
"};",
MergeInlineOnly);
   verifyFormat("int f() {}", MergeInlineOnly);
+  // https://llvm.org/PR54147
+  verifyFormat("auto lambda = []() {\n"
+   "  // comment\n"
+   "  f();\n"
+   "  g();\n"
+   "};",
+   MergeInlineOnly);
 
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;



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


[PATCH] D120902: [clang-format] Fix assertion failure/crash with `AllowShortFunctionsOnASingleLine: Inline/InlineOnly`.

2022-03-07 Thread Marek Kurdej via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd03e342803df: [clang-format] Fix assertion failure/crash 
with… (authored by curdeius).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120902

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12669,6 +12669,13 @@
"};",
MergeInlineOnly);
   verifyFormat("int f() {}", MergeInlineOnly);
+  // https://llvm.org/PR54147
+  verifyFormat("auto lambda = []() {\n"
+   "  // comment\n"
+   "  f();\n"
+   "  g();\n"
+   "};",
+   MergeInlineOnly);
 
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -310,6 +310,8 @@
   for (; J != AnnotatedLines.begin(); --J)
 if ((*J)->Level < TheLine->Level)
   break;
+  if ((*J)->Level >= TheLine->Level)
+return false;
 
   // Check if the found line starts a record.
   const FormatToken *LastNonComment = (*J)->Last;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12669,6 +12669,13 @@
"};",
MergeInlineOnly);
   verifyFormat("int f() {}", MergeInlineOnly);
+  // https://llvm.org/PR54147
+  verifyFormat("auto lambda = []() {\n"
+   "  // comment\n"
+   "  f();\n"
+   "  g();\n"
+   "};",
+   MergeInlineOnly);
 
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -310,6 +310,8 @@
   for (; J != AnnotatedLines.begin(); --J)
 if ((*J)->Level < TheLine->Level)
   break;
+  if ((*J)->Level >= TheLine->Level)
+return false;
 
   // Check if the found line starts a record.
   const FormatToken *LastNonComment = (*J)->Last;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120301: clang-tools-extra: Make test dependency on LLVMHello optional

2022-03-07 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.
Herald added a project: All.

@vtjnash  There hasn't been consensus on removing support for standalone builds 
yet, and I'm in favor of keeping  them as are some other distribution 
maintainers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120301

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


[PATCH] D118352: [clang][ABI] New c++20 modules mangling scheme

2022-03-07 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D118352#3363909 , @urnathan wrote:

> In D118352#3362694 , @ChuanqiXu 
> wrote:
>
>> In D118352#3359626 , @urnathan 
>> wrote:
>>
>>> 
>
>
>
>>> Correct, it is not called as the global initializer pieces are not yet 
>>> implemented.  Let's not hold up this patch for that nor remove piece that 
>>> will become necessary at that point.
>>
>> It's odd to see unused functions. I just worry about that other people might 
>> delete these functions as cleaning up (maybe there wouldn't be).
>
> That's a risk I'm ok with.

I agree - I think we already a fair amount of infrastructure in the compiler to 
handle module initialisers, ahead of a full implementation - so I do not see a 
reason for waiting longer to apply this because we cannot yet exercise it full.

>> Although the general declarations in partitions wouldn't be mangled 
>> specially, I think it would be better to add test case to show that.
>
> good idea, added.




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

https://reviews.llvm.org/D118352

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


[PATCH] D106184: [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics

2022-03-07 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.
Herald added a project: All.



Comment at: llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp:303
 CInfo.RecordAlignment =
 DL->getABITypeAlign(CInfo.Base->getType()->getPointerElementType());
 return true;

yonghong-song wrote:
> nikic wrote:
> > I noticed too late that this intrinsic also uses the element type to get 
> > the alignment. I'll have to follow up with the same change for this 
> > intrinsic.
> > 
> > Though I'm not completely sure if this is actually used, because no tests 
> > fail if I replace this with dummy values like 1 or 128.
> This is for llvm.preserve.union.access.index. It is used only if the union 
> member type is a bitfield and we don't have any usecase and test case for 
> that. That is why we didn't hit it.
> 
> It is okay for now. I probably will change to use getBaseElementType(Call) 
> later by myself.
I want to check back here on what we should do with this intrinsic. Should it 
be changed to use `elementtype` as well?

A possible alternative is to only add an `align` attribute to it, as it's the 
only part being actually used.


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

https://reviews.llvm.org/D106184

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


[PATCH] D114382: [clang] Fix wrong -Wunused-local-typedef warning within a template function

2022-03-07 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Seems like a progression :)

Do you have commit permissoins?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114382

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


[clang] 90a6e35 - [analyzer][NFC] Merge similar conditional paths

2022-03-07 Thread via cfe-commits

Author: phyBrackets
Date: 2022-03-07T22:05:27+05:30
New Revision: 90a6e3547863922ede7e2df1a1a650d1ef7d040a

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

LOG: [analyzer][NFC] Merge similar conditional paths

Reviewed By: aaron.ballman, steakhal

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

Added: 


Modified: 
clang/docs/DataFlowAnalysisIntro.md
clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp

Removed: 




diff  --git a/clang/docs/DataFlowAnalysisIntro.md 
b/clang/docs/DataFlowAnalysisIntro.md
index 9aee197d5746a..8bfecd24906cb 100644
--- a/clang/docs/DataFlowAnalysisIntro.md
+++ b/clang/docs/DataFlowAnalysisIntro.md
@@ -287,7 +287,7 @@ out = transfer(basic_block, join(in_1, in_2, ..., in_n))
 
 (Note that there are other ways to write this equation that produce higher
 precision analysis results. The trick is to keep exploring the execution paths
-separately and delay joining until later. Hoowever, we won't discuss those
+separately and delay joining until later. However, we won't discuss those
 variations here.)
 
 To make a conclusion about all paths through the program, we repeat this

diff  --git a/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
index 8070d869f6785..2102f9233bc10 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -107,11 +107,8 @@ LookThroughTransitiveAssignmentsAndCommaOperators(const 
Expr *Ex) {
   dyn_cast(Ex->IgnoreParenCasts());
 if (!BO)
   break;
-if (BO->getOpcode() == BO_Assign) {
-  Ex = BO->getRHS();
-  continue;
-}
-if (BO->getOpcode() == BO_Comma) {
+BinaryOperatorKind Op = BO->getOpcode();
+if (Op == BO_Assign || Op == BO_Comma) {
   Ex = BO->getRHS();
   continue;
 }



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


[PATCH] D121045: [analyzer][NFC] Merge similar conditional paths

2022-03-07 Thread Shivam Rajput via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90a6e3547863: [analyzer][NFC] Merge similar conditional 
paths (authored by phyBrackets).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121045

Files:
  clang/docs/DataFlowAnalysisIntro.md
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -107,11 +107,8 @@
   dyn_cast(Ex->IgnoreParenCasts());
 if (!BO)
   break;
-if (BO->getOpcode() == BO_Assign) {
-  Ex = BO->getRHS();
-  continue;
-}
-if (BO->getOpcode() == BO_Comma) {
+BinaryOperatorKind Op = BO->getOpcode();
+if (Op == BO_Assign || Op == BO_Comma) {
   Ex = BO->getRHS();
   continue;
 }
Index: clang/docs/DataFlowAnalysisIntro.md
===
--- clang/docs/DataFlowAnalysisIntro.md
+++ clang/docs/DataFlowAnalysisIntro.md
@@ -287,7 +287,7 @@
 
 (Note that there are other ways to write this equation that produce higher
 precision analysis results. The trick is to keep exploring the execution paths
-separately and delay joining until later. Hoowever, we won't discuss those
+separately and delay joining until later. However, we won't discuss those
 variations here.)
 
 To make a conclusion about all paths through the program, we repeat this


Index: clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -107,11 +107,8 @@
   dyn_cast(Ex->IgnoreParenCasts());
 if (!BO)
   break;
-if (BO->getOpcode() == BO_Assign) {
-  Ex = BO->getRHS();
-  continue;
-}
-if (BO->getOpcode() == BO_Comma) {
+BinaryOperatorKind Op = BO->getOpcode();
+if (Op == BO_Assign || Op == BO_Comma) {
   Ex = BO->getRHS();
   continue;
 }
Index: clang/docs/DataFlowAnalysisIntro.md
===
--- clang/docs/DataFlowAnalysisIntro.md
+++ clang/docs/DataFlowAnalysisIntro.md
@@ -287,7 +287,7 @@
 
 (Note that there are other ways to write this equation that produce higher
 precision analysis results. The trick is to keep exploring the execution paths
-separately and delay joining until later. Hoowever, we won't discuss those
+separately and delay joining until later. However, we won't discuss those
 variations here.)
 
 To make a conclusion about all paths through the program, we repeat this
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121045: [analyzer][NFC] Merge similar conditional paths

2022-03-07 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets added a comment.

Thanks @steakhal !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121045

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


[clang] 54d6b5b - [pseudo] Rename {Preprocess,PPStructure} -> DirectiveMap. NFC

2022-03-07 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-03-07T17:41:35+01:00
New Revision: 54d6b5b67fb3106eaf560261920df682eafa860f

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

LOG: [pseudo] Rename {Preprocess,PPStructure} -> DirectiveMap. NFC

More precisely describes what this file does.
Per comments on https://reviews.llvm.org/D121092

Added: 
clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h
clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp
clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp

Modified: 
clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
clang/test/Syntax/lex.c
clang/tools/clang-pseudo/ClangPseudo.cpp
clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt

Removed: 
clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp



diff  --git a/clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h 
b/clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h
similarity index 88%
rename from clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
rename to clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h
index 11a92042e7496..177302d9bae7a 100644
--- a/clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
+++ b/clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h
@@ -1,4 +1,4 @@
-//===--- Preprocess.h - Preprocess token streams -*- 
C++-*-===//
+//===--- DirectiveMap.h - Find and strip preprocessor directives -*- 
C++-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -56,7 +56,7 @@ namespace pseudo {
 ///
 /// Unlike the clang preprocessor, we model the full tree explicitly.
 /// This class does not recognize macro usage, only directives.
-struct PPStructure {
+struct DirectiveMap {
   /// A range of code (and possibly comments) containing no directives.
   struct Code {
 Token::Range Tokens;
@@ -76,7 +76,7 @@ struct PPStructure {
 ///
 /// The first branch will have an #if type directive.
 /// Subsequent branches will have #else type directives.
-std::vector> Branches;
+std::vector> Branches;
 /// The directive terminating the conditional, should be #endif.
 Directive End;
   };
@@ -86,22 +86,22 @@ struct PPStructure {
   std::vector Chunks;
 
   /// Extract preprocessor structure by examining the raw tokens.
-  static PPStructure parse(const TokenStream &);
+  static DirectiveMap parse(const TokenStream &);
 
   // FIXME: add heuristically selection of conditional branches.
   // FIXME: allow deriving a preprocessed stream
 };
-llvm::raw_ostream &operator<<(llvm::raw_ostream &, const PPStructure &);
-llvm::raw_ostream &operator<<(llvm::raw_ostream &, const PPStructure::Chunk &);
-llvm::raw_ostream &operator<<(llvm::raw_ostream &, const PPStructure::Code &);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DirectiveMap &);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DirectiveMap::Chunk 
&);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DirectiveMap::Code &);
 llvm::raw_ostream &operator<<(llvm::raw_ostream &,
-  const PPStructure::Directive &);
+  const DirectiveMap::Directive &);
 llvm::raw_ostream &operator<<(llvm::raw_ostream &,
-  const PPStructure::Conditional &);
+  const DirectiveMap::Conditional &);
 
 // FIXME: This approximates std::variant.
 // Switch once we can use C++17.
-class PPStructure::Chunk {
+class DirectiveMap::Chunk {
 public:
   enum Kind { K_Empty, K_Code, K_Directive, K_Conditional };
   Kind kind() const {

diff  --git a/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt 
b/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
index be75138e60c60..1e00905731c83 100644
--- a/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
+++ b/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
@@ -1,13 +1,13 @@
 set(LLVM_LINK_COMPONENTS Support)
 
 add_clang_library(clangToolingSyntaxPseudo
+  DirectiveMap.cpp
   Grammar.cpp
   GrammarBNF.cpp
   Lex.cpp
   LRGraph.cpp
   LRTable.cpp
   LRTableBuild.cpp
-  Preprocess.cpp
   Token.cpp
 
   LINK_LIBS

diff  --git a/clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp 
b/clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp
similarity index 72%
rename from clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
rename to clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp
index 3a6403a147c91..06a3b4400cf39 100644
--- a/clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
+++ b/clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp
@@ -1,4 +1,4 @@
-//===--- Preprocess.cpp - Preprocess token streams 
===//

[PATCH] D121076: [MLIR][Python] Add SCFIfOp Python binding

2022-03-07 Thread Hongzheng Chen via Phabricator via cfe-commits
chhzh123 updated this revision to Diff 413518.
chhzh123 added a comment.
Herald added subscribers: cfe-commits, llvm-commits, libc-commits, 
libcxx-commits, pcwang-thead, awarzynski, arjunp, luke957, abrachet, Groverkss, 
ormris, foad, mravishankar, frasercrmck, dexonsmith, ecnelises, ThomasRaoux, 
okura, jdoerfert, sstefan1, kuter, martong, phosek, kerbowa, csigg, 
luismarques, apazos, sameer.abuasal, pengfei, s.egerton, dmgreen, Jim, 
asbirlea, jocewei, PkmX, arphaman, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, MaskRay, jrtc27, niosHD, cryptoad, sabuasal, simoncook, 
johnrusso, rbar, asb, kbarton, aheejin, hiraditya, arichardson, mgorny, 
nhaehnle, jvesely, nemanjai, arsenm.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: jhenderson.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: antiagainst.
Herald added a reviewer: nicolasvasilache.
Herald added a reviewer: herhut.
Herald added a reviewer: rriddle.
Herald added a reviewer: aartbik.
Herald added a reviewer: sscalpone.
Herald added a reviewer: jpienaar.
Herald added a reviewer: baziotis.
Herald added a reviewer: aartbik.
Herald added a reviewer: aartbik.
Herald added a reviewer: awarzynski.
Herald added a reviewer: bondhugula.
Herald added projects: clang, libc++, libc-project, LLVM, clang-tools-extra, 
Flang.
Herald added a reviewer: libc++.

Fix signature and add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121076

Files:
  README.md
  clang-tools-extra/docs/clang-tidy/Contributing.rst
  clang/docs/ClangFormattedStatus.rst
  clang/docs/DataFlowAnalysisIntro.md
  clang/docs/analyzer/checkers.rst
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Basic/Module.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h
  clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
  clang/lib/Basic/Module.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
  clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp
  clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
  clang/lib/Tooling/Syntax/Pseudo/README.md
  clang/test/Analysis/taint-generic.c
  clang/test/CodeGen/PowerPC/builtins-ppc-fma.c
  clang/test/CodeGen/PowerPC/builtins-ppc-fpconstrained.c
  clang/test/CodeGen/PowerPC/builtins-ppc-vsx.c
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-math.c
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-module-map.m
  clang/test/OpenMP/irbuilder_nested_openmp_parallel_empty.c
  clang/test/OpenMP/irbuilder_nested_parallel_for.c
  clang/test/Syntax/lex.c
  clang/tools/clang-pseudo/ClangPseudo.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Tooling/LookupTest.cpp
  clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
  clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp
  clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
  flang/tools/bbc/bbc.cpp
  flang/tools/fir-opt/fir-opt.cpp
  flang/tools/tco/tco.cpp
  libc/loader/linux/x86_64/start.cpp
  libcxx/docs/ReleaseNotes.rst
  libcxx/include/CMakeLists.txt
  libcxx/include/__algorithm/ranges_max_element.h
  libcxx/include/__memory/unique_ptr.h
  libcxx/include/__ranges/access.h
  libcxx/include/algorithm
  libcxx/include/cuchar
  libcxx/include/module.modulemap
  libcxx/include/uchar.h
  libcxx/test/libcxx/clang_tidy.sh.cpp
  
libcxx/test/libcxx/diagnostics/detail.headers/algorithm/ranges_max_element.module.verify.cpp
  libcxx/test/libcxx/double_include.sh.cpp
  libcxx/test/libcxx/min_max_macros.compile.pass.cpp
  libcxx/test/libcxx/nasty_macros.compile.pass.cpp
  libcxx/test/libcxx/no_assert_include.compile.pass.cpp
  libcxx/test/libcxx/strings/c.strings/version_cuchar.pass.cpp
  libcxx/test/std/algorithms/alg.sorting/alg.min.max/ranges.max_element.pass.cpp
  libcxx/test/std/depr/depr.c.headers/uchar_h.compile.pass.cpp
  libcxx/test/std/depr/depr.c.headers/uchar_h.pass.cpp
  
libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp
  libcxx/test/std/ranges/range.access/begin.sizezero.pass.cpp
  libcxx/test/std/ranges/range.access/end.sizezero.pass.cpp
  libcxx/test/std/strings/c.strings/cuchar.compile.pass.cpp
  libcxx/test/std/strings/c.stri

[PATCH] D121076: [MLIR][Python] Add SCFIfOp Python binding

2022-03-07 Thread Hongzheng Chen via Phabricator via cfe-commits
chhzh123 added a comment.

Oh seems I made a wrong merge from the master branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121076

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


[PATCH] D117522: [clang-tidy] Add modernize-macro-to-enum check

2022-03-07 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.
Herald added a project: All.

Ping.  Another week waiting for reviews...


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

https://reviews.llvm.org/D117522

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


[PATCH] D120984: [clang][dataflow] Extend flow conditions from block terminators

2022-03-07 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.

Thanks, with the new comments it is much clearer what is going on!




Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:90
+  void VisitBinaryOperator(const BinaryOperator *S) {
+auto *LHS = S->getLHS()->IgnoreParenImpCasts();
+assert(LHS != nullptr);

We only expect `||` and `&&` to be terminators right? I wonder if we should add 
an assert so we get notified if the language gets extended with a new operator 
that we do not support yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120984

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


[PATCH] D121076: [MLIR][Python] Add SCFIfOp Python binding

2022-03-07 Thread Hongzheng Chen via Phabricator via cfe-commits
chhzh123 updated this revision to Diff 413520.
chhzh123 added a comment.

Revert


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121076

Files:
  mlir/python/mlir/dialects/_scf_ops_ext.py


Index: mlir/python/mlir/dialects/_scf_ops_ext.py
===
--- mlir/python/mlir/dialects/_scf_ops_ext.py
+++ mlir/python/mlir/dialects/_scf_ops_ext.py
@@ -64,3 +64,44 @@
 To obtain the loop-carried operands, use `iter_args`.
 """
 return self.body.arguments[1:]
+
+
+class IfOp:
+  """Specialization for the SCF if op class."""
+
+  def __init__(self,
+   results_,
+   cond,
+   withElseRegion=False,
+   *,
+   loc=None,
+   ip=None):
+"""Creates an SCF `if` operation.
+
+- `cond` is a boolean value to determine which regions of code will be 
executed.
+- `withElseRegion` determines whether the if operation has the else branch.
+"""
+operands = []
+operands.append(cond)
+results = []
+results.extend(results_)
+super().__init__(
+self.build_generic(
+regions=2,
+results=results,
+operands=operands,
+loc=loc,
+ip=ip))
+self.regions[0].blocks.append(*results)
+if withElseRegion:
+self.regions[1].blocks.append(*results)
+
+  @property
+  def then_block(self):
+"""Returns the then block of the if operation."""
+return self.regions[0].blocks[0]
+
+  @property
+  def else_block(self):
+"""Returns the else block of the if operation."""
+return self.regions[1].blocks[0]


Index: mlir/python/mlir/dialects/_scf_ops_ext.py
===
--- mlir/python/mlir/dialects/_scf_ops_ext.py
+++ mlir/python/mlir/dialects/_scf_ops_ext.py
@@ -64,3 +64,44 @@
 To obtain the loop-carried operands, use `iter_args`.
 """
 return self.body.arguments[1:]
+
+
+class IfOp:
+  """Specialization for the SCF if op class."""
+
+  def __init__(self,
+   results_,
+   cond,
+   withElseRegion=False,
+   *,
+   loc=None,
+   ip=None):
+"""Creates an SCF `if` operation.
+
+- `cond` is a boolean value to determine which regions of code will be executed.
+- `withElseRegion` determines whether the if operation has the else branch.
+"""
+operands = []
+operands.append(cond)
+results = []
+results.extend(results_)
+super().__init__(
+self.build_generic(
+regions=2,
+results=results,
+operands=operands,
+loc=loc,
+ip=ip))
+self.regions[0].blocks.append(*results)
+if withElseRegion:
+self.regions[1].blocks.append(*results)
+
+  @property
+  def then_block(self):
+"""Returns the then block of the if operation."""
+return self.regions[0].blocks[0]
+
+  @property
+  def else_block(self):
+"""Returns the else block of the if operation."""
+return self.regions[1].blocks[0]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121132: [clang-format] Handle C# 9 `init` accessor specifier.

2022-03-07 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
Herald added a project: All.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Before, the code:

  int Value { get; } = 0;
  int Value { init; } = 0;

was formatted incoherently:

  int Value { get; } = 0;
  int Value { init; }
  = 0;

because `init` was not recognised as an accessor specifier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121132

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -960,9 +960,11 @@
   verifyFormat("int Value { get; } = 0", Style);
   verifyFormat("int Value { set }", Style);
   verifyFormat("int Value { set; }", Style);
+  verifyFormat("int Value { init; }", Style);
   verifyFormat("int Value { internal set; }", Style);
   verifyFormat("int Value { set; } = 0", Style);
   verifyFormat("int Value { get; set }", Style);
+  verifyFormat("int Value { get; init; }", Style);
   verifyFormat("int Value { set; get }", Style);
   verifyFormat("int Value { get; private set; }", Style);
   verifyFormat("int Value { get; set; }", Style);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1839,14 +1839,14 @@
   // A trivial property accessor is of the form:
   // { [ACCESS_SPECIFIER] [get]; [ACCESS_SPECIFIER] [set] }
   // Track these as they do not require line breaks to be introduced.
-  bool HasGetOrSet = false;
+  bool HasAccessSpecifier = false;
   bool IsTrivialPropertyAccessor = true;
   while (!eof()) {
 if (Tok->isOneOf(tok::semi, tok::kw_public, tok::kw_private,
- tok::kw_protected, Keywords.kw_internal, Keywords.kw_get,
- Keywords.kw_set)) {
-  if (Tok->isOneOf(Keywords.kw_get, Keywords.kw_set))
-HasGetOrSet = true;
+ tok::kw_protected, Keywords.kw_internal, Keywords.kw_init,
+ Keywords.kw_get, Keywords.kw_set)) {
+  if (Tok->isOneOf(Keywords.kw_get, Keywords.kw_init, Keywords.kw_set))
+HasAccessSpecifier = true;
   Tok = Tokens->getNextToken();
   continue;
 }
@@ -1855,7 +1855,7 @@
 break;
   }
 
-  if (!HasGetOrSet) {
+  if (!HasAccessSpecifier) {
 Tokens->setPosition(StoredPosition);
 return false;
   }
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -954,6 +954,7 @@
 kw_event = &IdentTable.get("event");
 kw_fixed = &IdentTable.get("fixed");
 kw_foreach = &IdentTable.get("foreach");
+kw_init = &IdentTable.get("init");
 kw_implicit = &IdentTable.get("implicit");
 kw_internal = &IdentTable.get("internal");
 kw_lock = &IdentTable.get("lock");
@@ -986,11 +987,11 @@
 
 CSharpExtraKeywords = std::unordered_set(
 {kw_base, kw_byte, kw_checked, kw_decimal, kw_delegate, kw_event,
- kw_fixed, kw_foreach, kw_implicit, kw_in, kw_interface, kw_internal,
- kw_is, kw_lock, kw_null, kw_object, kw_out, kw_override, kw_params,
- kw_readonly, kw_ref, kw_string, kw_stackalloc, kw_sbyte, kw_sealed,
- kw_uint, kw_ulong, kw_unchecked, kw_unsafe, kw_ushort, kw_when,
- kw_where,
+ kw_fixed, kw_foreach, kw_implicit, kw_in, kw_init, kw_interface,
+ kw_internal, kw_is, kw_lock, kw_null, kw_object, kw_out, kw_override,
+ kw_params, kw_readonly, kw_ref, kw_string, kw_stackalloc, kw_sbyte,
+ kw_sealed, kw_uint, kw_ulong, kw_unchecked, kw_unsafe, kw_ushort,
+ kw_when, kw_where,
  // Keywords from the JavaScript section.
  kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
  kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly,
@@ -1078,6 +1079,7 @@
   IdentifierInfo *kw_fixed;
   IdentifierInfo *kw_foreach;
   IdentifierInfo *kw_implicit;
+  IdentifierInfo *kw_init;
   IdentifierInfo *kw_internal;
 
   IdentifierInfo *kw_lock;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -960,9 +960,11 @@
   verifyFormat("int Value { get; } = 0", Style);
   verifyFormat("int Value { set }", Style);
   verifyFormat("int Value { set; }", Style);
+  verifyFormat("int Value { init; }", Style);
   verifyFormat("int Value { internal set; }", Style);
   verifyFormat("int Value { set; } = 0", Sty

[PATCH] D120989: Support debug info for alias variable

2022-03-07 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D120989#3362912 , 
@kavitha-natarajan wrote:

> In D120989#3362491 , @dblaikie 
> wrote:
>
>> In D120989#3362490 , @dblaikie 
>> wrote:
>>
>>> Broad question about debug info for aliases: How's this proposed solution 
>>> compare/contrast to GCC's behavior?
>>
>> Aaand, I see that was described in thhe patch description. Sorry for not 
>> reading...
>>
>> Right, paging in all the context - this review hinges on whether gdb/lldb 
>> can handle/be made to handle this sort of debug info correctly.
>
> I have posted a gdb patch to handle this change for review:
> https://sourceware.org/pipermail/gdb-patches/2022-March/186329.html
>
> lldb can handle this debug info correctly.

Thanks for the details - can you ping this thread once the gdb thread has 
progressed/seems like it's moving in this direction?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120989

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


[PATCH] D120984: [clang][dataflow] Extend flow conditions from block terminators

2022-03-07 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 413523.
sgatev marked an inline comment as done.
sgatev added a comment.

Address reviewers' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120984

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.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
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -336,7 +336,8 @@
   }
 
   bool compareEquivalent(QualType Type, const Value &Val1,
- const Value &Val2) final {
+ const Environment &Env1, const Value &Val2,
+ const Environment &Env2) final {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
@@ -346,8 +347,9 @@
cast(&Val2)->getProperty("has_value");
   }
 
-  bool merge(QualType Type, const Value &Val1, const Value &Val2,
- Value &MergedVal, Environment &Env) final {
+  bool merge(QualType Type, const Value &Val1, const Environment &Env1,
+ const Value &Val2, const Environment &Env2, Value &MergedVal,
+ Environment &MergedEnv) final {
 // Nothing to say about a value that does not model an `OptionalInt`.
 if (!Type->isRecordType() ||
 Type->getAsCXXRecordDecl()->getQualifiedNameAsString() != "OptionalInt")
@@ -559,4 +561,319 @@
   });
 }
 
+class FlowConditionTest : public Test {
+protected:
+  template 
+  void runDataflow(llvm::StringRef Code, Matcher Match) {
+ASSERT_THAT_ERROR(
+test::checkDataflow(
+Code, "target",
+[](ASTContext &Context, Environment &Env) {
+  return NoopAnalysis(Context, true);
+},
+[&Match](
+llvm::ArrayRef<
+std::pair>>
+Results,
+ASTContext &ASTCtx) { Match(Results, ASTCtx); },
+{"-fsyntax-only", "-std=c++17"}),
+llvm::Succeeded());
+  }
+};
+
+TEST_F(FlowConditionTest, IfStmtSingleVar) {
+  std::string Code = R"(
+void target(bool Foo) {
+  if (Foo) {
+(void)0;
+/*[[p1]]*/
+  } else {
+(void)1;
+/*[[p2]]*/
+  }
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+ASSERT_THAT(Results, ElementsAre(Pair("p2", _), Pair("p1", _)));
+
+const Environment &Env1 = Results[1].second.Env;
+auto *FooVal1 =
+cast(Env1.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env1.flowConditionImplies(*FooVal1));
+
+const Environment &Env2 = Results[0].second.Env;
+auto *FooVal2 =
+cast(Env2.getValue(*FooDecl, SkipPast::None));
+EXPECT_FALSE(Env2.flowConditionImplies(*FooVal2));
+  });
+}
+
+TEST_F(FlowConditionTest, IfStmtSingleNegatedVar) {
+  std::string Code = R"(
+void target(bool Foo) {
+  if (!Foo) {
+(void)0;
+/*[[p1]]*/
+  } else {
+(void)1;
+/*[[p2]]*/
+  }
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+ASSERT_THAT(Results, ElementsAre(Pair("p2", _), Pair("p1", _)));
+
+const Environment &Env1 = Results[1].second.Env;
+auto *FooVal1 =
+cast(Env1.getValue(*FooDecl, SkipPast::None));
+EXPECT_FALSE(Env1.flowConditionImplies(*FooVal1));
+
+const Environment &Env2 = Results[0].second.Env;
+auto *FooVal2 =
+cast(Env2.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env2.flowConditionImplies(*FooVal2));
+  });
+}
+
+TEST_F(FlowConditionTest, WhileStmt) {
+  std::string Code = R"(
+void target(bool Foo) {
+  while (Foo) {
+

[PATCH] D120989: Support debug info for alias variable

2022-03-07 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added subscribers: JDevlieghere, aprantl.
dblaikie added a comment.

Maybe APple folks would want to move forward with this only when targeting 
lldb, though - which might unblock this patch. @aprantl @JDevlieghere ? What do 
you folks think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120989

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


[PATCH] D120984: [clang][dataflow] Extend flow conditions from block terminators

2022-03-07 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:90
+  void VisitBinaryOperator(const BinaryOperator *S) {
+auto *LHS = S->getLHS()->IgnoreParenImpCasts();
+assert(LHS != nullptr);

xazax.hun wrote:
> We only expect `||` and `&&` to be terminators right? I wonder if we should 
> add an assert so we get notified if the language gets extended with a new 
> operator that we do not support yet.
Right. Adding an assert here sounds good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120984

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


[PATCH] D121132: [clang-format] Handle C# 9 `init` accessor specifier.

2022-03-07 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius updated this revision to Diff 413525.
curdeius added a comment.

Rename.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121132

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -960,9 +960,11 @@
   verifyFormat("int Value { get; } = 0", Style);
   verifyFormat("int Value { set }", Style);
   verifyFormat("int Value { set; }", Style);
+  verifyFormat("int Value { init; }", Style);
   verifyFormat("int Value { internal set; }", Style);
   verifyFormat("int Value { set; } = 0", Style);
   verifyFormat("int Value { get; set }", Style);
+  verifyFormat("int Value { get; init; }", Style);
   verifyFormat("int Value { set; get }", Style);
   verifyFormat("int Value { get; private set; }", Style);
   verifyFormat("int Value { get; set; }", Style);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1837,16 +1837,16 @@
   FormatToken *Tok = Tokens->getNextToken();
 
   // A trivial property accessor is of the form:
-  // { [ACCESS_SPECIFIER] [get]; [ACCESS_SPECIFIER] [set] }
+  // { [ACCESS_SPECIFIER] [get]; [ACCESS_SPECIFIER] [set|init] }
   // Track these as they do not require line breaks to be introduced.
-  bool HasGetOrSet = false;
+  bool HasSpecialAccessor = false;
   bool IsTrivialPropertyAccessor = true;
   while (!eof()) {
 if (Tok->isOneOf(tok::semi, tok::kw_public, tok::kw_private,
- tok::kw_protected, Keywords.kw_internal, Keywords.kw_get,
- Keywords.kw_set)) {
-  if (Tok->isOneOf(Keywords.kw_get, Keywords.kw_set))
-HasGetOrSet = true;
+ tok::kw_protected, Keywords.kw_internal, Keywords.kw_init,
+ Keywords.kw_get, Keywords.kw_set)) {
+  if (Tok->isOneOf(Keywords.kw_get, Keywords.kw_init, Keywords.kw_set))
+HasSpecialAccessor = true;
   Tok = Tokens->getNextToken();
   continue;
 }
@@ -1855,7 +1855,7 @@
 break;
   }
 
-  if (!HasGetOrSet) {
+  if (!HasSpecialAccessor) {
 Tokens->setPosition(StoredPosition);
 return false;
   }
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -954,6 +954,7 @@
 kw_event = &IdentTable.get("event");
 kw_fixed = &IdentTable.get("fixed");
 kw_foreach = &IdentTable.get("foreach");
+kw_init = &IdentTable.get("init");
 kw_implicit = &IdentTable.get("implicit");
 kw_internal = &IdentTable.get("internal");
 kw_lock = &IdentTable.get("lock");
@@ -986,11 +987,11 @@
 
 CSharpExtraKeywords = std::unordered_set(
 {kw_base, kw_byte, kw_checked, kw_decimal, kw_delegate, kw_event,
- kw_fixed, kw_foreach, kw_implicit, kw_in, kw_interface, kw_internal,
- kw_is, kw_lock, kw_null, kw_object, kw_out, kw_override, kw_params,
- kw_readonly, kw_ref, kw_string, kw_stackalloc, kw_sbyte, kw_sealed,
- kw_uint, kw_ulong, kw_unchecked, kw_unsafe, kw_ushort, kw_when,
- kw_where,
+ kw_fixed, kw_foreach, kw_implicit, kw_in, kw_init, kw_interface,
+ kw_internal, kw_is, kw_lock, kw_null, kw_object, kw_out, kw_override,
+ kw_params, kw_readonly, kw_ref, kw_string, kw_stackalloc, kw_sbyte,
+ kw_sealed, kw_uint, kw_ulong, kw_unchecked, kw_unsafe, kw_ushort,
+ kw_when, kw_where,
  // Keywords from the JavaScript section.
  kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
  kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly,
@@ -1078,6 +1079,7 @@
   IdentifierInfo *kw_fixed;
   IdentifierInfo *kw_foreach;
   IdentifierInfo *kw_implicit;
+  IdentifierInfo *kw_init;
   IdentifierInfo *kw_internal;
 
   IdentifierInfo *kw_lock;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -960,9 +960,11 @@
   verifyFormat("int Value { get; } = 0", Style);
   verifyFormat("int Value { set }", Style);
   verifyFormat("int Value { set; }", Style);
+  verifyFormat("int Value { init; }", Style);
   verifyFormat("int Value { internal set; }", Style);
   verifyFormat("int Value { set; } = 0", Style);
   verifyFormat("int Value { get; set }", Style);
+  verifyFormat("int Value { get; init; }", Style);
   verifyFormat("int Value { set; get }", Style);
   verifyFormat("int Value { get; private set;

[PATCH] D119172: [pseudo] Implement LRGraph

2022-03-07 Thread Alex Tsao via Phabricator via cfe-commits
alextsao1999 added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h:96
+  uint8_t DotPos = 0;
+  uint8_t RuleLength = 0; // the length of rule body.
+};

sammccall wrote:
> alextsao1999 wrote:
> > hokein wrote:
> > > alextsao1999 wrote:
> > > > Can we add LookaheadSymbol here to implement LR(1)?
> > > we could do that. However, we don't have a plan to implement an `LR(1)` 
> > > yet, we use `SLR(1)`. (though LR(1) is more powerful than SLR(1), the 
> > > typical deterministic LR(1) parser cannot handle the C++ grammar, we need 
> > > a "general" parser GLR which can be able to handle arbitrary context-free 
> > > grammars).
> > Thanks for your answering! Oh, I know some `GLR` parsers are based on 
> > `LR(1)` or `LALR`, so I think our `GLR` parser is based on `LR(1)` as well. 
> > I'm trying to keep up with your train of thought :)
> Yeah, GLR changes the tradeoff between more sophisticated and simpler parsers 
> (LR(1) > LALR > SLR(1) > LR(0)).
> 
> Normally the sophisticated parsers are able to handle grammars/languages that 
> the simple ones can't, by avoiding action conflicts. So the value is very 
> high.
> 
> However with GLR we can handle action conflicts by branching, so the value is 
> "only" avoiding the performance hit of chasing branches that don't go 
> anywhere.
> 
> So it didn't really seem worth the extra implementation complexity (or extra 
> size of the in-memory grammar tables!) to use a more powerful parser than 
> SLR(1). Maybe we should even have given LR(0) more thought :-)
Yes, agree. `SLR` can reduce memory usage, but it can't handle operator 
precedence. With the help of GLR, we can resolve the problem of operator 
precedence by chosing one branch. Thanks, I got it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119172

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


  1   2   3   >