[PATCH] D147176: [clang-format] NFC ensure Style operator== remains sorted for ease of editing

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added subscribers: sammccall, klimek.
MyDeveloperDay added a comment.

In D147176#4231952 , @rymiel wrote:

>> didn't go via the normal clang-format reviewers
>
> Is there a reason for this? This isn't the only case either, for example:
> https://reviews.llvm.org/D143070 https://reviews.llvm.org/D144170 
> https://reviews.llvm.org/D88299 https://reviews.llvm.org/D135356
>
> I don't have a lot of experience here, so maybe I'm missing "historical" 
> context, but this confuses me a lot...

@klimek was one of the original clang-format creators, and @sammccall I believe 
works on clangd among many other things, which might well be consuming 
libFormat.

Honestly these developers are pretty much 'OGs' , I'm happy to tidy up after 
them if they don't quite follow our current conventions.  Obviously at any 
point you can add yourself to a review and add the appropriate tags.

Phabractor does support automatically assigned code reviewers via the "Owners" 
package, and via Herald rules. I could see if I can add one to at least auto 
assign the clang-format tag, that should bring it onto our radar


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147176

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-03-30 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D146922: [clang-tidy] Fix false positve for defaulted move constructor in performance-noexcept-move-constructor

2023-03-30 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Looks ok, would be good to run this on some code base.




Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp:22
+  cxxMethodDecl(anyOf(cxxConstructorDecl(isMoveConstructor()),
+  hasOverloadedOperatorName("=")),
 unless(isImplicit()), unless(isDeleted()))

use isMoveAssignmentOperator instead of hasOverloadedOperatorName



Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp:23
+  hasOverloadedOperatorName("=")),
 unless(isImplicit()), unless(isDeleted()))
   .bind("decl"),

move those 2 to begining...



Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp:30
 const MatchFinder::MatchResult &Result) {
   if (const auto *Decl = Result.Nodes.getNodeAs("decl")) {
 bool IsConstructor = false;

invert this if to reduce nesting.
```
const auto *Decl = Result.Nodes.getNodeAs("decl")
if (!Decl)
return;
```



Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp:32-36
 if (const auto *Ctor = dyn_cast(Decl)) {
-  if (!Ctor->isMoveConstructor())
-return;
   IsConstructor = true;
 } else if (!Decl->isMoveAssignmentOperator()) {
   return;
 }

IsConstructor = CXXConstructorDecl::classof(Decl);



Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp:39
+if (SpecAnalyzer.analyze(Decl) !=
+utils::ExceptionSpecAnalyzer::State::Throwing) {
   return;

remove {}, leave just
```  
if (SpecAnalyzer.analyze(Decl) != 
utils::ExceptionSpecAnalyzer::State::Throwing) return;
```



Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp:45-49
+const auto *ProtoType = Decl->getType()->castAs();
+const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
+if (NoexceptExpr) {
+  NoexceptExpr = NoexceptExpr->IgnoreImplicit();
+  if (!isa(NoexceptExpr)) {

woudn't getExceptionSpecInfo() != EST_NoexceptFalse do a trick here ?



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:32
+  // Check if the function has already been analyzed and reuse that result.
+  if (FunctionCache.count(FuncDecl) == 0) {
+State = analyzeImpl(FuncDecl);

use FunctionCache.find to avoid double search in line 32 and 38 (and reuse 
result)



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:36
+// Cache the result of the analysis.
+FunctionCache.insert(std::make_pair(FuncDecl, State));
+  } else

try_emplace ?



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:44
+ExceptionSpecAnalyzer::State
+ExceptionSpecAnalyzer::analyzeUnresolvedOrDefaulted(
+const FunctionDecl *FuncDecl) {

pass FunctionProtoType also to this function



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:50-52
+  const auto *MethodDecl = cast(FuncDecl);
+  if (!MethodDecl)
+return State::Unknown;

technically you could change this class to operator on CXXMethodDecl since 
begining



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:76
+
+  // FIXME: There may still be a way to figure out if the field can throw or 
not
+  return State::Unknown;

check if this is trivial type, if its trivial type then cannot throw...
FDecl->getType()->isTrivialType(FDecl->getAstContext());



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:95
+ DefaultableMemberKind Kind,
+ SkipMethods SkipMethods) {
+  if (!RecordDecl)

Can we hit some endless recursion here ?
Maybe so protection against checking Record that we currently checking.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:108-114
+  BasesToVisit Bases = isConstructor(Kind)
+   ? BasesToVisit::VisitPotentiallyConstructedBases
+   : BasesToVisit::VisitAllBases;
+
+  if (Bases == BasesToVisit::VisitPotentiallyConstructedBases)
+Bases = RecordDecl->isAbstract() ? BasesToVisit::VisitNonVirtualBases
+ : BasesToVisit::VisitAllBases;

I'm not sure if we need to be so picky...
In short we could check all bases.
Virtual, Abstract or not...



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:155
+ExceptionSpecAnalyzer::State
+ExceptionSpecAnalyzer::analyzeFunctionE

[PATCH] D147176: [clang-format] NFC ensure Style operator== remains sorted for ease of editing

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I can auto add us as all as reviewers if you'd like?  This means if the title 
contains `[clang-format]` or it impacts a file path of /clang/lib/Format it 
should in theory run this rule

F26945275: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147176

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


[PATCH] D146101: [clang-format] Add DesignatedInitializerIndentWidth option.

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1665-1669
+  const auto DesignatedInitializerIndentWidth =
+  Style.DesignatedInitializerIndentWidth < 0
+  ? Style.ContinuationIndentWidth
+  : Style.DesignatedInitializerIndentWidth;
+  NewIndent = CurrentState.LastSpace + DesignatedInitializerIndentWidth;

rymiel wrote:
> owenpan wrote:
> > jp4a50 wrote:
> > > HazardyKnusperkeks wrote:
> > > > owenpan wrote:
> > > > > jp4a50 wrote:
> > > > > > HazardyKnusperkeks wrote:
> > > > > > > owenpan wrote:
> > > > > > > > jp4a50 wrote:
> > > > > > > > > owenpan wrote:
> > > > > > > > > > owenpan wrote:
> > > > > > > > > > > Using -1 to mean `ContinuationIndentWidth` is unnecessary 
> > > > > > > > > > > and somewhat confusing IMO.
> > > > > > > > > > Please disregard my comment above.
> > > > > > > > > Just to make sure we are on the same page, does this mean 
> > > > > > > > > that you are happy with the approach of using `-1` as a 
> > > > > > > > > default value to indicate that `ContinuationIndentWidth` 
> > > > > > > > > should be used?
> > > > > > > > > 
> > > > > > > > > I did initially consider using `std::optional` and 
> > > > > > > > > using empty optional to indicate that 
> > > > > > > > > `ContinuationIndentWidth` should be used but I saw that 
> > > > > > > > > `PPIndentWidth` was using `-1` to default to using 
> > > > > > > > > `IndentWidth` so I followed that precedent.
> > > > > > > > Yep! I would prefer the `optional`, but as you pointed out, we 
> > > > > > > > already got `PPIndentWidth`using `-1`.
> > > > > > > From the C++ side I totally agree. One could use `value_or()`, 
> > > > > > > which would make the code much more readable.
> > > > > > > And just because `PPIndentWidth` is using -1 is no reason to 
> > > > > > > repeat that, we could just as easily change `PPIndentWidht` to an 
> > > > > > > optional.
> > > > > > > 
> > > > > > > But how would it look in yaml?
> > > > > > In YAML we wouldn't need to support empty optional being 
> > > > > > *explicitly* specified - it would just be the default.
> > > > > > 
> > > > > > So specifying `DesignatedInitializerIndentWidth: 4` would set the 
> > > > > > `std::optional` to `4` but if 
> > > > > > `DesignatedInitializerIndentWidth` was omitted from the YAML then 
> > > > > > the optional would simply not be set during parsing.
> > > > > > 
> > > > > > Of course, if we were to change `PPIndentWidth` to work that way 
> > > > > > too, it would technically be a breaking change because users may 
> > > > > > have *explicitly* specified `-1` in their YAML.
> > > > > > And just because `PPIndentWidth` is using -1 is no reason to repeat 
> > > > > > that, we could just as easily change `PPIndentWidht` to an optional.
> > > > > 
> > > > > We would have to deal with backward compatibility to avoid 
> > > > > regressions though.
> > > > > In YAML we wouldn't need to support empty optional being *explicitly* 
> > > > > specified - it would just be the default.
> > > > > 
> > > > > So specifying `DesignatedInitializerIndentWidth: 4` would set the 
> > > > > `std::optional` to `4` but if 
> > > > > `DesignatedInitializerIndentWidth` was omitted from the YAML then the 
> > > > > optional would simply not be set during parsing.
> > > > > 
> > > > > Of course, if we were to change `PPIndentWidth` to work that way too, 
> > > > > it would technically be a breaking change because users may have 
> > > > > *explicitly* specified `-1` in their YAML.
> > > > 
> > > > You need an explicit entry, because you need to be able to write the 
> > > > empty optional on `--dump-config`.
> > > > > In YAML we wouldn't need to support empty optional being *explicitly* 
> > > > > specified - it would just be the default.
> > > > > 
> > > > > So specifying `DesignatedInitializerIndentWidth: 4` would set the 
> > > > > `std::optional` to `4` but if 
> > > > > `DesignatedInitializerIndentWidth` was omitted from the YAML then the 
> > > > > optional would simply not be set during parsing.
> > > > > 
> > > > > Of course, if we were to change `PPIndentWidth` to work that way too, 
> > > > > it would technically be a breaking change because users may have 
> > > > > *explicitly* specified `-1` in their YAML.
> > > > 
> > > > You need an explicit entry, because you need to be able to write the 
> > > > empty optional on `--dump-config`.
> > > 
> > > It looks like the YAML IO logic just does the right thing (TM) with 
> > > `std::optional`s. When calling `IO.mapOptional()` on output, it simply 
> > > doesn't write the key out if the value is an empty optional. So I don't 
> > > think this is an issue.
> > > 
> > > As @owenpan says, though, there is still the issue of backward 
> > > compatibility with `PPIndentWidth`.
> > > 
> > > I don't feel strongly about which way to go so I'll leave it to you two 
> > > to decide!
> > > As @owenpan says, though, there is still th

[PATCH] D147176: [clang-format] NFC ensure Style operator== remains sorted for ease of editing

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Also I've added  a couple of other rules

F26945535: image.png 

This should in theory, automatically add a comment to a clang-format review 
that contains a Format.h change but not a ClangFormatStyleOption.rst change and 
vice versa


Herald added a comment.

Your review contains a change to clang/include/clang/Format/Format.h but does 
not contain an update to ClangFormatStyleOptions.rst

ClangFormatStyleOptions.rst is generated via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  @mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147176

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


[PATCH] D147209: [clang][lit] Make LIT aware of env CLANG_CRASH_DIAGNOSTICS_DIR.

2023-03-30 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli created this revision.
fpetrogalli added a reviewer: mizvekov.
Herald added a project: All.
fpetrogalli requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is useful for retriving crash reports of LIT runs when the
temporary folder is not accessible.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147209

Files:
  clang/test/lit.cfg.py


Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -284,6 +284,10 @@
 config.substitutions.append(('llvm-nm', 'env OBJECT_MODE=any llvm-nm'))
 config.substitutions.append(('llvm-ar', 'env OBJECT_MODE=any llvm-ar'))
 
+# Pass the crash diagnostic dir set in the os environment to LIT.
+if 'CLANG_CRASH_DIAGNOSTICS_DIR' in os.environ:
+config.environment['CLANG_CRASH_DIAGNOSTICS_DIR'] = 
os.environ['CLANG_CRASH_DIAGNOSTICS_DIR']
+
 # It is not realistically possible to account for all options that could
 # possibly be present in system and user configuration files, so disable
 # default configs for the test runs.


Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -284,6 +284,10 @@
 config.substitutions.append(('llvm-nm', 'env OBJECT_MODE=any llvm-nm'))
 config.substitutions.append(('llvm-ar', 'env OBJECT_MODE=any llvm-ar'))
 
+# Pass the crash diagnostic dir set in the os environment to LIT.
+if 'CLANG_CRASH_DIAGNOSTICS_DIR' in os.environ:
+config.environment['CLANG_CRASH_DIAGNOSTICS_DIR'] = os.environ['CLANG_CRASH_DIAGNOSTICS_DIR']
+
 # It is not realistically possible to account for all options that could
 # possibly be present in system and user configuration files, so disable
 # default configs for the test runs.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147176: [clang-format] NFC ensure Style operator== remains sorted for ease of editing

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

...test comment which should fire an automated, you don't have any unit 
tests...comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147176

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


[PATCH] D147176: [clang-format] NFC ensure Style operator== remains sorted for ease of editing

2023-03-30 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

I apologize for not tagging appropriately - is that process documented 
somewhere?


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add you unit tests in `clang/unittests/Format` and build `ninja FormatTests` we 
recommend using the `verifyFormat(xxx)` format of unit tests rather than 
`EXPECT_EQ` as this will ensure you change is tolerant to random whitespace 
changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147176

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


[PATCH] D147176: [clang-format] NFC ensure Style operator== remains sorted for ease of editing

2023-03-30 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

And thanks a lot for cleaning up, really appreciate it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147176

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


[PATCH] D146412: [NFC] Fix potential for use-after-free in DumpModuleInfoAction

2023-03-30 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 509580.
Fznamznon added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146412

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,11 @@
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+// Pass empty deleter to not attempt to free memory that was allocated
+// outside of the current scope, possibly statically.
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
-   llvm::sys::fs::OF_TextWithCRLF));
-OutputStream = OutFile.get();
+OutputStream.reset(new llvm::raw_fd_ostream(
+OutputFileName.str(), EC, llvm::sys::fs::OF_TextWithCRLF));
   }
   llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs();
 
Index: clang/include/clang/Frontend/FrontendActions.h
===
--- clang/include/clang/Frontend/FrontendActions.h
+++ clang/include/clang/Frontend/FrontendActions.h
@@ -177,9 +177,8 @@
 /// Dump information about the given module file, to be used for
 /// basic debugging and discovery.
 class DumpModuleInfoAction : public ASTFrontendAction {
-public:
   // Allow other tools (ex lldb) to direct output for their use.
-  llvm::raw_ostream *OutputStream = nullptr;
+  std::shared_ptr OutputStream;
 
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
@@ -188,6 +187,9 @@
   void ExecuteAction() override;
 
 public:
+  DumpModuleInfoAction() = default;
+  explicit DumpModuleInfoAction(std::shared_ptr Out)
+  : OutputStream(Out) {}
   bool hasPCHSupport() const override { return false; }
   bool hasASTFileSupport() const override { return true; }
   bool hasIRSupport() const override { return false; }


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,11 @@
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+// Pass empty deleter to not attempt to free memory that was allocated
+// outside of the current scope, possibly statically.
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
-   llvm::sys::fs::OF_TextWithCRLF));
-OutputStream = OutFile.get();
+OutputStream.reset(new l

[PATCH] D136103: OpenMP asynchronous memory copy support

2023-03-30 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr updated this revision to Diff 509581.
jplehr added a comment.

Fix bug to corectly support the maximally supported dimensions as required by 
the spec.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136103

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/src/api.cpp
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/private.h
  openmp/libomptarget/test/api/omp_target_memcpy_async1.c
  openmp/libomptarget/test/api/omp_target_memcpy_async2.c
  openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
  openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c

Index: openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c
===
--- /dev/null
+++ openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c
@@ -0,0 +1,89 @@
+// RUN: %libomptarget-compile-and-run-generic
+
+#include 
+#include 
+
+#define NUM_DIMS 3
+
+int main() {
+  int d = omp_get_default_device();
+  int id = omp_get_initial_device();
+  int a[128], b[64], c[128], e[16], q[128], i;
+  void *p;
+
+  if (d < 0 || d >= omp_get_num_devices())
+d = id;
+
+  p = omp_target_alloc(130 * sizeof(int), d);
+  if (p == NULL)
+return 0;
+
+  for (i = 0; i < 128; i++)
+q[i] = 0;
+  if (omp_target_memcpy(p, q, 128 * sizeof(int), 0, 0, d, id) != 0)
+abort();
+
+  size_t volume[NUM_DIMS] = {2, 2, 3};
+  size_t dst_offsets[NUM_DIMS] = {0, 0, 0};
+  size_t src_offsets[NUM_DIMS] = {0, 0, 0};
+  size_t dst_dimensions[NUM_DIMS] = {3, 4, 5};
+  size_t src_dimensions[NUM_DIMS] = {2, 3, 4};
+
+  for (i = 0; i < 128; i++)
+a[i] = 42;
+  for (i = 0; i < 64; i++)
+b[i] = 24;
+  for (i = 0; i < 128; i++)
+c[i] = 0;
+  for (i = 0; i < 16; i++)
+e[i] = 77;
+
+  omp_depend_t obj[2];
+
+#pragma omp parallel num_threads(5)
+#pragma omp single
+  {
+#pragma omp task depend(out : p)
+omp_target_memcpy(p, a, 128 * sizeof(int), 0, 0, d, id);
+
+#pragma omp task depend(inout : p)
+omp_target_memcpy(p, b, 64 * sizeof(int), 0, 0, d, id);
+
+#pragma omp task depend(out : c)
+for (i = 0; i < 128; i++)
+  c[i] = i + 1;
+
+#pragma omp depobj(obj[0]) depend(inout : p)
+#pragma omp depobj(obj[1]) depend(in : c)
+
+/*  This produces: 1 2 3 - - 5 6 7 - - at positions 0..9 and
+13 14 15 - - 17 18 19 - - at positions 20..29.  */
+omp_target_memcpy_rect_async(p, c, sizeof(int), NUM_DIMS, volume,
+ dst_offsets, src_offsets, dst_dimensions,
+ src_dimensions, d, id, 2, obj);
+
+#pragma omp task depend(in : p)
+omp_target_memcpy(p, e, 16 * sizeof(int), 0, 0, d, id);
+  }
+
+#pragma omp taskwait
+
+  if (omp_target_memcpy(q, p, 128 * sizeof(int), 0, 0, id, d) != 0)
+abort();
+
+  for (i = 0; i < 16; ++i)
+if (q[i] != 77)
+  abort();
+  if (q[20] != 13 || q[21] != 14 || q[22] != 15 || q[25] != 17 || q[26] != 18 ||
+  q[27] != 19)
+abort();
+  for (i = 28; i < 64; ++i)
+if (q[i] != 24)
+  abort();
+  for (i = 64; i < 128; ++i)
+if (q[i] != 42)
+  abort();
+
+  omp_target_free(p, d);
+  return 0;
+}
Index: openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
===
--- /dev/null
+++ openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
@@ -0,0 +1,66 @@
+// RUN: %libomptarget-compile-and-run-generic
+
+#include 
+#include 
+#include 
+
+#define NUM_DIMS 3
+
+int main() {
+  int d = omp_get_default_device();
+  int id = omp_get_initial_device();
+  int q[128], q2[128], i;
+  void *p;
+
+  if (d < 0 || d >= omp_get_num_devices())
+d = id;
+
+  p = omp_target_alloc(130 * sizeof(int), d);
+  if (p == NULL)
+return 0;
+
+  if (omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+   NULL, d, id, 0, NULL) < 3 ||
+  omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+   NULL, id, d, 0, NULL) < 3 ||
+  omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+   NULL, id, id, 0, NULL) < 3)
+abort();
+
+  for (i = 0; i < 128; i++)
+q[i] = 0;
+  if (omp_target_memcpy(p, q, 128 * sizeof(int), 0, 0, d, id) != 0)
+abort();
+
+  for (i = 0; i < 128; i++)
+q[i] = i + 1;
+
+  size_t volume[NUM_DIMS] = {1, 2, 3};
+  size_t dst_offsets[NUM_DIMS] = {0, 0, 0};
+  size_t src_offsets[NUM_DIMS] = {0, 0, 0};
+  size_t dst_dimensions[NUM_DIMS] = {3, 4, 5};
+  size_t src_dimensions[NUM_DIMS] = {2, 3, 4};
+
+  if (omp_target_memcpy_rect_async(p, q, sizeof(int), NUM_DIMS, volume,
+   dst_offsets, src_offsets, dst_dimensions,
+   src_dimensions, d, id, 0, NULL) != 0)
+abort();
+
+#pragma omp taskwait
+
+  for (i = 0; i < 128; i++)
+q2[i] = 0;
+  if 

[PATCH] D136103: OpenMP asynchronous memory copy support

2023-03-30 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr updated this revision to Diff 509583.
jplehr added a comment.

Removed accidentally added code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136103

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/src/api.cpp
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/private.h
  openmp/libomptarget/test/api/omp_target_memcpy_async1.c
  openmp/libomptarget/test/api/omp_target_memcpy_async2.c
  openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
  openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c

Index: openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c
===
--- /dev/null
+++ openmp/libomptarget/test/api/omp_target_memcpy_rect_async2.c
@@ -0,0 +1,89 @@
+// RUN: %libomptarget-compile-and-run-generic
+
+#include 
+#include 
+
+#define NUM_DIMS 3
+
+int main() {
+  int d = omp_get_default_device();
+  int id = omp_get_initial_device();
+  int a[128], b[64], c[128], e[16], q[128], i;
+  void *p;
+
+  if (d < 0 || d >= omp_get_num_devices())
+d = id;
+
+  p = omp_target_alloc(130 * sizeof(int), d);
+  if (p == NULL)
+return 0;
+
+  for (i = 0; i < 128; i++)
+q[i] = 0;
+  if (omp_target_memcpy(p, q, 128 * sizeof(int), 0, 0, d, id) != 0)
+abort();
+
+  size_t volume[NUM_DIMS] = {2, 2, 3};
+  size_t dst_offsets[NUM_DIMS] = {0, 0, 0};
+  size_t src_offsets[NUM_DIMS] = {0, 0, 0};
+  size_t dst_dimensions[NUM_DIMS] = {3, 4, 5};
+  size_t src_dimensions[NUM_DIMS] = {2, 3, 4};
+
+  for (i = 0; i < 128; i++)
+a[i] = 42;
+  for (i = 0; i < 64; i++)
+b[i] = 24;
+  for (i = 0; i < 128; i++)
+c[i] = 0;
+  for (i = 0; i < 16; i++)
+e[i] = 77;
+
+  omp_depend_t obj[2];
+
+#pragma omp parallel num_threads(5)
+#pragma omp single
+  {
+#pragma omp task depend(out : p)
+omp_target_memcpy(p, a, 128 * sizeof(int), 0, 0, d, id);
+
+#pragma omp task depend(inout : p)
+omp_target_memcpy(p, b, 64 * sizeof(int), 0, 0, d, id);
+
+#pragma omp task depend(out : c)
+for (i = 0; i < 128; i++)
+  c[i] = i + 1;
+
+#pragma omp depobj(obj[0]) depend(inout : p)
+#pragma omp depobj(obj[1]) depend(in : c)
+
+/*  This produces: 1 2 3 - - 5 6 7 - - at positions 0..9 and
+13 14 15 - - 17 18 19 - - at positions 20..29.  */
+omp_target_memcpy_rect_async(p, c, sizeof(int), NUM_DIMS, volume,
+ dst_offsets, src_offsets, dst_dimensions,
+ src_dimensions, d, id, 2, obj);
+
+#pragma omp task depend(in : p)
+omp_target_memcpy(p, e, 16 * sizeof(int), 0, 0, d, id);
+  }
+
+#pragma omp taskwait
+
+  if (omp_target_memcpy(q, p, 128 * sizeof(int), 0, 0, id, d) != 0)
+abort();
+
+  for (i = 0; i < 16; ++i)
+if (q[i] != 77)
+  abort();
+  if (q[20] != 13 || q[21] != 14 || q[22] != 15 || q[25] != 17 || q[26] != 18 ||
+  q[27] != 19)
+abort();
+  for (i = 28; i < 64; ++i)
+if (q[i] != 24)
+  abort();
+  for (i = 64; i < 128; ++i)
+if (q[i] != 42)
+  abort();
+
+  omp_target_free(p, d);
+  return 0;
+}
Index: openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
===
--- /dev/null
+++ openmp/libomptarget/test/api/omp_target_memcpy_rect_async1.c
@@ -0,0 +1,66 @@
+// RUN: %libomptarget-compile-and-run-generic
+
+#include 
+#include 
+#include 
+
+#define NUM_DIMS 3
+
+int main() {
+  int d = omp_get_default_device();
+  int id = omp_get_initial_device();
+  int q[128], q2[128], i;
+  void *p;
+
+  if (d < 0 || d >= omp_get_num_devices())
+d = id;
+
+  p = omp_target_alloc(130 * sizeof(int), d);
+  if (p == NULL)
+return 0;
+
+  if (omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+   NULL, d, id, 0, NULL) < 3 ||
+  omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+   NULL, id, d, 0, NULL) < 3 ||
+  omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
+   NULL, id, id, 0, NULL) < 3)
+abort();
+
+  for (i = 0; i < 128; i++)
+q[i] = 0;
+  if (omp_target_memcpy(p, q, 128 * sizeof(int), 0, 0, d, id) != 0)
+abort();
+
+  for (i = 0; i < 128; i++)
+q[i] = i + 1;
+
+  size_t volume[NUM_DIMS] = {1, 2, 3};
+  size_t dst_offsets[NUM_DIMS] = {0, 0, 0};
+  size_t src_offsets[NUM_DIMS] = {0, 0, 0};
+  size_t dst_dimensions[NUM_DIMS] = {3, 4, 5};
+  size_t src_dimensions[NUM_DIMS] = {2, 3, 4};
+
+  if (omp_target_memcpy_rect_async(p, q, sizeof(int), NUM_DIMS, volume,
+   dst_offsets, src_offsets, dst_dimensions,
+   src_dimensions, d, id, 0, NULL) != 0)
+abort();
+
+#pragma omp taskwait
+
+  for (i = 0; i < 128; i++)
+q2[i] = 0;
+  if (omp_target_memcpy(q2, p, 128 * sizeof(int), 0, 0, id, d)

[PATCH] D147197: [llvm-docs] Added documentation for the 'neg' operation

2023-03-30 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added a comment.

Thank you oyalesalami. It looks like these instructions don't actually exist 
anymore so shouldn't be documented.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147197

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


[PATCH] D146412: [NFC] Fix potential for use-after-free in DumpModuleInfoAction

2023-03-30 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The test fail is unrelated, seem to be broken by 
https://reviews.llvm.org/D146811 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146412

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


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-30 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 509589.
Krishna-13-cyber edited the summary of this revision.
Krishna-13-cyber added a comment.

This patch aims to remove some redundant cases of static assert messages where 
the expansions are particularly unhelpful. In this particular patch, we have 
ignored the printing of diagnostic warnings for binary operators with logical 
OR operations.
This is done to prioritise and prefer to emit longer diagnostic warnings for 
more important concerns elsewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
 
+  static_assert(true && false, ""); // expected-error {{failed}}
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != 
BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
 
+  static_assert(true && false, ""); // expected-error {{failed}}
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] f3a815a - [clangd] Map references from include'd files to directives

2023-03-30 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-03-30T12:06:22+02:00
New Revision: f3a815aa776f42c4f4b80fc8d19a69ff1b359906

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

LOG: [clangd] Map references from include'd files to directives

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

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index fb245593b2f94..ee645efa6e6e1 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -51,9 +51,11 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -266,7 +268,6 @@ std::vector generateUnusedIncludeDiagnostics(
 }
 } // namespace
 
-
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
@@ -398,6 +399,10 @@ IncludeCleanerFindings 
computeIncludeCleanerFindings(ParsedAST &AST) {
 // FIXME: Use presumed locations to map such usages back to patched
 // locations safely.
 auto Loc = SM.getFileLoc(Ref.RefLocation);
+// File locations can be outside of the main file if macro is expanded
+// through an #include.
+while (SM.getFileID(Loc) != SM.getMainFileID())
+  Loc = SM.getIncludeLoc(SM.getFileID(Loc));
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
 MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
 Providers};

diff  --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp 
b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index de45da02bfe87..c0c15cd0db8e5 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -384,6 +384,35 @@ TEST(IncludeCleaner, UmbrellaUsesPrivate) {
   EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, MacroExpandedThroughIncludes) {
+  Annotations MainFile(R"cpp(
+  #include "all.h"
+  #define FOO(X) const Foo *X
+  void foo() {
+  #include [["expander.inc"]]
+  }
+)cpp");
+
+  TestTU TU;
+  TU.AdditionalFiles["expander.inc"] = guard("FOO(f1);FOO(f2);");
+  TU.AdditionalFiles["foo.h"] = guard("struct Foo {};");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+
+  TU.Code = MainFile.code();
+  ParsedAST AST = TU.build();
+
+  auto Findings = computeIncludeCleanerFindings(AST).MissingIncludes;
+  // FIXME: Deduplicate references resulting from expansion of the same macro 
in
+  // multiple places.
+  EXPECT_THAT(Findings, testing::SizeIs(2));
+  auto RefRange = Findings.front().SymRefRange;
+  auto &SM = AST.getSourceManager();
+  EXPECT_EQ(RefRange.file(), SM.getMainFileID());
+  // FIXME: Point at the spelling location, rather than the include.
+  EXPECT_EQ(halfOpenToRange(SM, RefRange.toCharRange(SM)), MainFile.range());
+  EXPECT_EQ(RefRange, Findings[1].SymRefRange);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang



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


[PATCH] D147139: [clangd] Map references from include'd files to directives

2023-03-30 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf3a815aa776f: [clangd] Map references from include'd 
files to directives (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147139

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -384,6 +384,35 @@
   EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, MacroExpandedThroughIncludes) {
+  Annotations MainFile(R"cpp(
+  #include "all.h"
+  #define FOO(X) const Foo *X
+  void foo() {
+  #include [["expander.inc"]]
+  }
+)cpp");
+
+  TestTU TU;
+  TU.AdditionalFiles["expander.inc"] = guard("FOO(f1);FOO(f2);");
+  TU.AdditionalFiles["foo.h"] = guard("struct Foo {};");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+
+  TU.Code = MainFile.code();
+  ParsedAST AST = TU.build();
+
+  auto Findings = computeIncludeCleanerFindings(AST).MissingIncludes;
+  // FIXME: Deduplicate references resulting from expansion of the same macro 
in
+  // multiple places.
+  EXPECT_THAT(Findings, testing::SizeIs(2));
+  auto RefRange = Findings.front().SymRefRange;
+  auto &SM = AST.getSourceManager();
+  EXPECT_EQ(RefRange.file(), SM.getMainFileID());
+  // FIXME: Point at the spelling location, rather than the include.
+  EXPECT_EQ(halfOpenToRange(SM, RefRange.toCharRange(SM)), MainFile.range());
+  EXPECT_EQ(RefRange, Findings[1].SymRefRange);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -51,9 +51,11 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -266,7 +268,6 @@
 }
 } // namespace
 
-
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
@@ -398,6 +399,10 @@
 // FIXME: Use presumed locations to map such usages back to patched
 // locations safely.
 auto Loc = SM.getFileLoc(Ref.RefLocation);
+// File locations can be outside of the main file if macro is expanded
+// through an #include.
+while (SM.getFileID(Loc) != SM.getMainFileID())
+  Loc = SM.getIncludeLoc(SM.getFileID(Loc));
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
 MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
 Providers};


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -384,6 +384,35 @@
   EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, MacroExpandedThroughIncludes) {
+  Annotations MainFile(R"cpp(
+  #include "all.h"
+  #define FOO(X) const Foo *X
+  void foo() {
+  #include [["expander.inc"]]
+  }
+)cpp");
+
+  TestTU TU;
+  TU.AdditionalFiles["expander.inc"] = guard("FOO(f1);FOO(f2);");
+  TU.AdditionalFiles["foo.h"] = guard("struct Foo {};");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+
+  TU.Code = MainFile.code();
+  ParsedAST AST = TU.build();
+
+  auto Findings = computeIncludeCleanerFindings(AST).MissingIncludes;
+  // FIXME: Deduplicate references resulting from expansion of the same macro in
+  // multiple places.
+  EXPECT_THAT(Findings, testing::SizeIs(2));
+  auto RefRange = Findings.front().SymRefRange;
+  auto &SM = AST.getSourceManager();
+  EXPECT_EQ(RefRange.file(), SM.getMainFileID());
+  // FIXME: Point at the spelling location, rather than the include.
+  EXPECT_EQ(halfOpenToRange(SM, RefRange.toCharRange(SM)), MainFile.range());
+  EXPECT_EQ(RefRange, Findings[1].SymRefRange);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -51,9 +51,11 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -266,7 +268,6 @@
 }
 } // namespace
 
-
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   c

[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-03-30 Thread Roman via Phabricator via cfe-commits
kekcheburec added a comment.

In D70401#4226597 , @pcwang-thead 
wrote:

> In D70401#4226549 , @recallmenot 
> wrote:
>
>> In D70401#4205333 , @pcwang-thead 
>> wrote:
>>
>>> In D70401#4204511 , @recallmenot 
>>> wrote:
>>>
 Hi, I'm working on CH32V003 for rust and it uses RV32EC core.
 I tried replacing my distros llvm and clang with a patched version of this 
 like this:

   git clone https://aur.archlinux.org/llvm-git.git
   cd llvm-git
   mkdir src
   cd src
   git clone https://github.com/llvm/llvm-project.git
   cd llvm-project
   arc patch D70401
   cd ../..
   mv llvm-config.h src/
   makepkg -es
   sudo pacman -Rd --nodeps clang llvm
   makepkg -eid

 but that bricked my xfce-wayland-manjaro DE (one screen black)
 And in config.toml if I put

   [build]
   target = "riscv32i-unknown-none-elf"
   rustflags = [
"-C", "target-feature=+e,+c"
   ]

 then build with cargo build
 LLVM still complains it doesn't implement CodeGen for RV32E yet
 What am I doing wrong?
 Ended up reverting to repository llvm and clang, desktop now works again 
 but CodeGen is obviously missing.
>>>
>>> I don't see any obvious problem here.
>>> I am not familiar with rust. Is `riscv32i-unknown-none-elf` a valid target 
>>> for `rustc`, it should be something like `riscv32-unknown-elf` in LLVM I 
>>> think. And is `target-feature=+e,+c` the right way to specify features?
>>> Can you please provide the whole command/arguments passed to LLVM?
>>
>> Yeah so I looked at the at the target files of rustc, telling rustc to do 
>> RV32I will indeed result in RV32 and the way to enable the E and C features 
>> seems to be correct, BUT:
>> rust uses their own "special sauce" version of llvm and rustc needs to be 
>> built against that to enable the new features. I tried to apply (patch) the 
>> diff directly to rusts llvm branch but there were many errors, and I 
>> couldn't figure out how to apply them manually since some things are 
>> different.
>> I'm stuck, this is all way beyond my understanding. Sorry I can't test it 
>> for you guys.
>> What I did was:
>>
>>   git clone https://github.com/rust-lang/rust.git
>>   cd rust
>>   nvim config.toml
>>
>>   [llvm]
>>   download-ci-llvm = false
>>
>> then I started building with
>>
>>   ./x.py build
>>
>> and as soon as the rust-llvm source was downloaded completely I aborted 
>> (CTRL+C).
>>
>> then downloaded the raw diff from this page (button top right) into the rust 
>> llvm dir, opened a terminal in that dir and tried to patch with
>>
>>   patch -p1 < D70401.diff
>>
>> but that gives lots of errors
>> resolving them manually seems way beyond me, especially since patch seems to 
>> already use fuzzy matching
>
> So it seems that rust uses its own llvm branch based on released llvm branch, 
> so I think you may download old version of this patch which is near the 
> baseline of rust llvm branch and try again. :-)

I made a fork with a fix (until the recent rebase with the addition of rv64e) 
https://github.com/kekcheburec/llvm-project/tree/5cf27e03900c06c0f374a8f3a6e65a817ce70607

In this case, you need to use a fork https://github.com/rust-lang/llvm-project 
because this is the latest version of LLVM that has not yet been switched to. 
For older versions of LLVM, you can also use pure LLVM.

Do you have any news about adding rv32e/rv64e to LLD? At the moment, you need 
to use GCC for linking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[PATCH] D147176: [clang-format] NFC ensure Style operator== remains sorted for ease of editing

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D147176#4232808 , @klimek wrote:

> I apologize for not tagging appropriately - is that process documented 
> somewhere?

I've implemented it via Phabricator Herald rules now, so we should be good 
going forward, @klimek you get a free pass as far as I'm concerns, I'll always 
be happy to tidy up after you given the opportunity you gave me in the past.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147176

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


[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I don't like using additional variables in unit tests, if someone changes 25400 
multiple tests could break, each test should be stand alone in my view


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to ClangFormatStyleOptions.rst but not a change 
to clang/include/clang/Format/Format.h

ClangFormatStyleOptions.rst is auto generated from Format.h via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html




Comment at: clang/unittests/Format/FormatTest.cpp:25410-25415
+  verifyFormat("int function1(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3);\n"
+   "int function2();\n",
+   Code, Style);




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Can you show your example from a implementation case and not just a declaration 
i.e. what happens with

`int function1(int param1) {}`




Comment at: clang/lib/Format/TokenAnnotator.cpp:4789
+  if (Left.is(tok::l_paren) && Style.AlwaysBreakBeforeFunctionParameters &&
+  !Right.is(tok::r_paren) && Left.Previous &&
+  Left.Previous->is(TT_FunctionDeclarationName)) {

can you test the `()` case in your tests please with 
`AlwaysBreakBeforeFunctionParameters` set to true


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:1374
+**AlwaysBreakBeforeFunctionParameters** (``Boolean``) 
:versionbadge:`clang-format 16.0` :ref:`¶ `
+  If ``true``, always break before function parameters in a declaration.
+

here you say declaration but don't we want the same in definition too? 
otherewise should it be `AlwaysBreakBeforeFunctionDefinitionParameters` if you 
are expecting something else?



Comment at: clang/docs/ClangFormatStyleOptions.rst:1380
+  Example uses
+  ``AlwaysBreakAfterReturnType`` set to ``All``.
+

This isn't relevant is it? `AlwaysBreakAfterReturnType`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-03-30 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik updated this revision to Diff 509598.
philnik added a comment.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Try to fix CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147175

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/RecordLayout.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/RecordLayout.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  libcxx/include/__algorithm/equal.h
  libcxx/include/__string/constexpr_c_functions.h
  libcxx/include/__type_traits/is_equality_comparable.h
  libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp

Index: libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
===
--- libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
+++ libcxx/test/libcxx/type_traits/is_trivially_comparable.compile.pass.cpp
@@ -13,32 +13,32 @@
 enum Enum : int {};
 enum class EnumClass : int {};
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 struct S {
   char c;
@@ -51,8 +51,8 @@
 struct VirtualBase : virtual S {};
 struct NonVirtualBase : S, S2 {};
 
-static_assert(!std::__is_trivially_equality_comparable::value, "");
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
 
 // This is trivially_equality_comparable, but we can't detect it currently
-static_assert(!std::__is_trivially_equality_comparable::value, "");
+static_assert(!std::__libcpp_is_trivially_equality_comparable::value, "");
Index: libcxx/include/__type_traits/is_equality_comparable.h
===
--- libcxx/include/__type_traits/is_equality_comparable.h
+++ libcxx/include/__type_traits/is_equality_comparable.h
@@ -43,14 +43,14 @@
 //   always compared.
 
 template 
-struct __is_trivially

[PATCH] D146412: [NFC] Fix potential for use-after-free in DumpModuleInfoAction

2023-03-30 Thread Mariya Podchishchaeva 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 rG42ae055b4c92: [NFC] Fix potential for use-after-free in 
DumpModuleInfoAction (authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146412

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,11 @@
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+// Pass empty deleter to not attempt to free memory that was allocated
+// outside of the current scope, possibly statically.
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
-   llvm::sys::fs::OF_TextWithCRLF));
-OutputStream = OutFile.get();
+OutputStream.reset(new llvm::raw_fd_ostream(
+OutputFileName.str(), EC, llvm::sys::fs::OF_TextWithCRLF));
   }
   llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs();
 
Index: clang/include/clang/Frontend/FrontendActions.h
===
--- clang/include/clang/Frontend/FrontendActions.h
+++ clang/include/clang/Frontend/FrontendActions.h
@@ -177,9 +177,8 @@
 /// Dump information about the given module file, to be used for
 /// basic debugging and discovery.
 class DumpModuleInfoAction : public ASTFrontendAction {
-public:
   // Allow other tools (ex lldb) to direct output for their use.
-  llvm::raw_ostream *OutputStream = nullptr;
+  std::shared_ptr OutputStream;
 
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
@@ -188,6 +187,9 @@
   void ExecuteAction() override;
 
 public:
+  DumpModuleInfoAction() = default;
+  explicit DumpModuleInfoAction(std::shared_ptr Out)
+  : OutputStream(Out) {}
   bool hasPCHSupport() const override { return false; }
   bool hasASTFileSupport() const override { return true; }
   bool hasIRSupport() const override { return false; }


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,11 @@
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+// Pass empty deleter to not attempt to free memory that was allocated
+// outside of the current scope, possibly statically.
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(O

[clang] 42ae055 - [NFC] Fix potential for use-after-free in DumpModuleInfoAction

2023-03-30 Thread Mariya Podchishchaeva via cfe-commits

Author: Mariya Podchishchaeva
Date: 2023-03-30T06:44:23-04:00
New Revision: 42ae055b4c9282050636dd11198cad500424adf2

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

LOG: [NFC] Fix potential for use-after-free in DumpModuleInfoAction

Since each `DumpModuleInfoAction` can now contain a pointer to a
`raw_ostream`, saving there a poiter that owned by a local `unique_ptr`
may cause use-after-free. Clarify ownership and save a `shared_ptr`
inside of `DumpModuleInfoAction` instead.
Found by static analyzer.

Reviewed By: tahonermann, aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Frontend/FrontendActions.h
clang/lib/Frontend/FrontendActions.cpp
lldb/source/Commands/CommandObjectTarget.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/FrontendActions.h 
b/clang/include/clang/Frontend/FrontendActions.h
index 9e6ed1ace190..3940e00eeb8d 100644
--- a/clang/include/clang/Frontend/FrontendActions.h
+++ b/clang/include/clang/Frontend/FrontendActions.h
@@ -177,9 +177,8 @@ class SyntaxOnlyAction : public ASTFrontendAction {
 /// Dump information about the given module file, to be used for
 /// basic debugging and discovery.
 class DumpModuleInfoAction : public ASTFrontendAction {
-public:
   // Allow other tools (ex lldb) to direct output for their use.
-  llvm::raw_ostream *OutputStream = nullptr;
+  std::shared_ptr OutputStream;
 
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
@@ -188,6 +187,9 @@ class DumpModuleInfoAction : public ASTFrontendAction {
   void ExecuteAction() override;
 
 public:
+  DumpModuleInfoAction() = default;
+  explicit DumpModuleInfoAction(std::shared_ptr Out)
+  : OutputStream(Out) {}
   bool hasPCHSupport() const override { return false; }
   bool hasASTFileSupport() const override { return true; }
   bool hasIRSupport() const override { return false; }

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index 05d9fc8208b2..0349e769595d 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@ static StringRef ModuleKindName(Module::ModuleKind MK) {
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
-   llvm::sys::fs::OF_TextWithCRLF));
-OutputStream = OutFile.get();
+OutputStream.reset(new llvm::raw_fd_ostream(
+OutputFileName.str(), EC, llvm::sys::fs::OF_TextWithCRLF));
   }
   llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs();
 

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index 5874453bca23..aecdf595ee5b 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,11 @@ class CommandObjectTargetModulesDumpClangPCMInfo : 
public CommandObjectParsed {
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+// Pass empty deleter to not attempt to free memory that was allocated
+// outside of the current scope, possibly statically.
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());



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


[PATCH] D147213: [include-cleaner] Ignore builtin symbols in the WalkAST.

2023-03-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

There is no need to add headers for builtin symbols.

Additionally, there is a bonus benefit which help eliminate some bugs -- builtin
functions are modeled as implicit FunctionDecls in the clang AST, which results 
in
them being treated as normal FunctionDecls in the implementation of the 
include-cleaner
(going through the path: ast-node -> decl -> source location -> header).
And, the source location of these built-in symbols' AST nodes is not precise 
(e.g. points to the first call site),
which leads to subtle behavior that inserts a header of the call site.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147213

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -322,5 +322,11 @@
   testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
+TEST(WalkAST, BuiltinSymbols) {
+  testWalk(R"cpp(
+extern "C" int __builtin_popcount(unsigned int) noexcept;
+  )cpp", "int x = ^__builtin_popcount(1);");
+}
+
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -34,6 +35,9 @@
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
   return;
+// Don't report builtin symbols.
+if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0)
+  return;
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -322,5 +322,11 @@
   testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
+TEST(WalkAST, BuiltinSymbols) {
+  testWalk(R"cpp(
+extern "C" int __builtin_popcount(unsigned int) noexcept;
+  )cpp", "int x = ^__builtin_popcount(1);");
+}
+
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -34,6 +35,9 @@
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
   return;
+// Don't report builtin symbols.
+if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0)
+  return;
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] ed61d6a - [libc++] Use the stdlib= Lit feature instead of use_system_cxx_lib

2023-03-30 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2023-03-30T06:57:56-04:00
New Revision: ed61d6a46611cfb144b260e0dd0fb1b5783562d9

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

LOG: [libc++] Use the stdlib= Lit feature instead of use_system_cxx_lib

The use_system_cxx_lib Lit feature was only used for back-deployment
testing. However, one immense hole in that setup was that we didn't
have a proper way to test Apple's own libc++ outside of back-deployment,
which was embodied by the fact that we needed to define 
_LIBCPP_DISABLE_AVAILABILITY
when testing (see change in libcxx/utils/libcxx/test/params.py).

This led to the apple-system testing configuration not checking for
availability markup, which is obviously quite bad since the library
we ship actually has availability markup.

Using stdlib=-libc++ instead to encode back-deployment restrictions
on tests is simpler and it makes it possible to naturally support tests
such as availability markup checking even in the tip-of-trunk Apple-libc++
configuration.

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

Added: 


Modified: 
libcxx/test/libcxx/language.support/cxa_deleted_virtual.pass.cpp
libcxx/test/libcxx/strings/basic.string/string.capacity/PR53170.pass.cpp
libcxx/test/libcxx/strings/string.view/assert.ctor.length.pass.cpp

libcxx/test/libcxx/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp

libcxx/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp

libcxx/test/libcxx/thread/thread.threads/thread.thread.this/sleep_for.signals.pass.cpp
libcxx/test/std/depr/depr.c.headers/stdlib_h.aligned_alloc.compile.pass.cpp

libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/generic_category.pass.cpp

libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.objects/system_category.pass.cpp

libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.mods/refresh.pass.cpp

libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp

libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp

libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/last_write_time.pass.cpp

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directories/create_directories.pass.cpp

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_directory/create_directory_with_attributes.pass.cpp

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.file_size/file_size.pass.cpp

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp

libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.remove_all/toctou.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/bool.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/double.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/float.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/int.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_double.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/long_long.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/pointer.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/short.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_int.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_long_long.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream.formatted.arithmetic/unsigned_short.pass.cpp

libcxx/test/std/input.output/iostream.format/input.streams/istream.formatted/istream_extractors/streambuf.pass.cpp

libcxx/test/std/input.outp

[clang] 243b355 - [clang][Interp] Support destructors

2023-03-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-30T13:17:04+02:00
New Revision: 243b355ee0f063cff4988f061215839020c2175b

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

LOG: [clang][Interp] Support destructors

Emit destructors for non-primitive (array) variables on scope ends.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.h
clang/test/AST/Interp/cxx20.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 0056da191765b..fff2425bedf42 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -26,10 +26,10 @@ namespace clang {
 namespace interp {
 
 /// Scope used to handle temporaries in toplevel variable declarations.
-template  class DeclScope final : public LocalScope {
+template  class DeclScope final : public VariableScope 
{
 public:
   DeclScope(ByteCodeExprGen *Ctx, const ValueDecl *VD)
-  : LocalScope(Ctx), Scope(Ctx->P, VD) {}
+  : VariableScope(Ctx), Scope(Ctx->P, VD) {}
 
   void addExtended(const Scope::Local &Local) override {
 return this->addLocal(Local);
@@ -1857,6 +1857,80 @@ void ByteCodeExprGen::emitCleanup() {
 C->emitDestruction();
 }
 
+/// When calling this, we have a pointer of the local-to-destroy
+/// on the stack.
+/// Emit destruction of record types (or arrays of record types).
+/// FIXME: Handle virtual destructors.
+template 
+bool ByteCodeExprGen::emitRecordDestruction(const Descriptor *Desc) {
+  assert(Desc);
+  assert(!Desc->isPrimitive());
+  assert(!Desc->isPrimitiveArray());
+
+  // Arrays.
+  if (Desc->isArray()) {
+const Descriptor *ElemDesc = Desc->ElemDesc;
+const Record *ElemRecord = ElemDesc->ElemRecord;
+assert(ElemRecord); // This is not a primitive array.
+
+if (const CXXDestructorDecl *Dtor = ElemRecord->getDestructor();
+Dtor && !Dtor->isTrivial()) {
+  for (ssize_t I = Desc->getNumElems() - 1; I >= 0; --I) {
+if (!this->emitConstUint64(I, SourceInfo{}))
+  return false;
+if (!this->emitArrayElemPtrUint64(SourceInfo{}))
+  return false;
+if (!this->emitRecordDestruction(Desc->ElemDesc))
+  return false;
+  }
+}
+return this->emitPopPtr(SourceInfo{});
+  }
+
+  const Record *R = Desc->ElemRecord;
+  assert(R);
+  // First, destroy all fields.
+  for (const Record::Field &Field : llvm::reverse(R->fields())) {
+const Descriptor *D = Field.Desc;
+if (!D->isPrimitive() && !D->isPrimitiveArray()) {
+  if (!this->emitDupPtr(SourceInfo{}))
+return false;
+  if (!this->emitGetPtrField(Field.Offset, SourceInfo{}))
+return false;
+  if (!this->emitRecordDestruction(D))
+return false;
+}
+  }
+
+  // FIXME: Unions need to be handled 
diff erently here. We don't want to
+  //   call the destructor of its members.
+
+  // Now emit the destructor and recurse into base classes.
+  if (const CXXDestructorDecl *Dtor = R->getDestructor();
+  Dtor && !Dtor->isTrivial()) {
+const Function *DtorFunc = getFunction(Dtor);
+if (DtorFunc && DtorFunc->isConstexpr()) {
+  assert(DtorFunc->hasThisPointer());
+  assert(DtorFunc->getNumParams() == 1);
+  if (!this->emitDupPtr(SourceInfo{}))
+return false;
+  if (!this->emitCall(DtorFunc, SourceInfo{}))
+return false;
+}
+  }
+
+  for (const Record::Base &Base : llvm::reverse(R->bases())) {
+if (!this->emitGetPtrBase(Base.Offset, SourceInfo{}))
+  return false;
+if (!this->emitRecordDestruction(Base.Desc))
+  return false;
+  }
+  // FIXME: Virtual bases.
+
+  // Remove the instance pointer.
+  return this->emitPopPtr(SourceInfo{});
+}
+
 namespace clang {
 namespace interp {
 

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 231f39ff8bd6d..03d2eb87b5e1c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -29,6 +29,7 @@ class QualType;
 namespace interp {
 
 template  class LocalScope;
+template  class DestructorScope;
 template  class RecordScope;
 template  class VariableScope;
 template  class DeclScope;
@@ -189,6 +190,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 private:
   friend class VariableScope;
   friend class LocalScope;
+  friend class DestructorScope;
   friend class RecordScope;
   friend class DeclScope;
   friend class OptionScope;
@@ -256,6 +258,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 return FPO.getRoundingMode();
   }
 
+  bool emitR

[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

2023-03-30 Thread Timm Bäder 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 rG243b355ee0f0: [clang][Interp] Support destructors (authored 
by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D145545?vs=509281&id=509608#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145545

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/test/AST/Interp/cxx20.cpp

Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -271,3 +271,250 @@
// ref-error {{must have constant destruction}} \
// ref-note {{in call to}}
 };
+
+namespace Destructors {
+
+  class Inc final {
+  public:
+int &I;
+constexpr Inc(int &I) : I(I) {}
+constexpr ~Inc() {
+  I++;
+}
+  };
+
+  class Dec final {
+  public:
+int &I;
+constexpr Dec(int &I) : I(I) {}
+constexpr ~Dec() {
+  I--;
+}
+  };
+
+
+
+  constexpr int m() {
+int i = 0;
+{
+  Inc f1(i);
+  Inc f2(i);
+  Inc f3(i);
+}
+return i;
+  }
+  static_assert(m() == 3, "");
+
+
+  constexpr int C() {
+int i = 0;
+
+while (i < 10) {
+  Inc inc(i);
+  continue;
+  Dec dec(i);
+}
+return i;
+  }
+  static_assert(C() == 10, "");
+
+
+  constexpr int D() {
+int i = 0;
+
+{
+  Inc i1(i);
+  {
+Inc i2(i);
+return i;
+  }
+}
+
+return i;
+  }
+  static_assert(D() == 0, "");
+
+  constexpr int E() {
+int i = 0;
+
+for(;;) {
+  Inc i1(i);
+  break;
+}
+return i;
+  }
+  static_assert(E() == 1, "");
+
+
+  /// FIXME: This should be rejected, since we call the destructor
+  ///   twice. However, GCC doesn't care either.
+  constexpr int ManualDtor() {
+int i = 0;
+{
+  Inc I(i); // ref-note {{destroying object 'I' whose lifetime has already ended}}
+  I.~Inc();
+}
+return i;
+  }
+  static_assert(ManualDtor() == 1, ""); // expected-error {{static assertion failed}} \
+// expected-note {{evaluates to '2 == 1'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'ManualDtor()'}}
+
+  constexpr void doInc(int &i) {
+Inc I(i);
+return;
+  }
+  constexpr int testInc() {
+int i = 0;
+doInc(i);
+return i;
+  }
+  static_assert(testInc() == 1, "");
+  constexpr void doInc2(int &i) {
+Inc I(i);
+// No return statement.
+  }
+   constexpr int testInc2() {
+int i = 0;
+doInc2(i);
+return i;
+  }
+  static_assert(testInc2() == 1, "");
+
+
+  namespace DtorOrder {
+class A {
+  public:
+  int &I;
+  constexpr A(int &I) : I(I) {}
+  constexpr ~A() {
+I = 1337;
+  }
+};
+
+class B : public A {
+  public:
+  constexpr B(int &I) : A(I) {}
+  constexpr ~B() {
+I = 42;
+  }
+};
+
+constexpr int foo() {
+  int i = 0;
+  {
+B b(i);
+  }
+  return i;
+}
+
+static_assert(foo() == 1337);
+  }
+
+  class FieldDtor1 {
+  public:
+Inc I1;
+Inc I2;
+constexpr FieldDtor1(int &I) : I1(I), I2(I){}
+  };
+
+  constexpr int foo2() {
+int i = 0;
+{
+  FieldDtor1 FD1(i);
+}
+return i;
+  }
+
+  static_assert(foo2() == 2);
+
+  class FieldDtor2 {
+  public:
+Inc Incs[3];
+constexpr FieldDtor2(int &I)  : Incs{Inc(I), Inc(I), Inc(I)} {}
+  };
+
+  constexpr int foo3() {
+int i = 0;
+{
+  FieldDtor2 FD2(i);
+}
+return i;
+  }
+
+  static_assert(foo3() == 3);
+
+  struct ArrD {
+int index;
+int *arr;
+int &p;
+constexpr ~ArrD() {
+  arr[p] = index;
+  ++p;
+}
+  };
+  constexpr bool ArrayOrder() {
+int order[3] = {0, 0, 0};
+int p = 0;
+{
+  ArrD ds[3] = {
+{1, order, p},
+{2, order, p},
+{3, order, p},
+  };
+  // ds will be destroyed.
+}
+return order[0] == 3 && order[1] == 2 && order[2] == 1;
+  }
+  static_assert(ArrayOrder());
+
+
+  // Static members aren't destroyed.
+  class Dec2 {
+  public:
+int A = 0;
+constexpr ~Dec2() {
+  A++;
+}
+  };
+  class Foo {
+  public:
+static constexpr Dec2 a;
+static Dec2 b;
+  };
+  static_assert(Foo::a.A == 0);
+  constexpr bool f() {
+Foo f;
+return true;
+  }
+  static_assert(Foo::a.A == 0);
+  static_assert(f());
+  static_assert(Foo::a.A == 0);
+
+
+  struct NotConstexpr {
+NotConstexpr() {}
+~NotConstexpr() {}
+  };
+
+  struct Outer {
+  

[PATCH] D147217: [OpenMP][OMPIRBuilder] OpenMPIRBuilder support for requires directive

2023-03-30 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak created this revision.
skatrak added reviewers: dpalermo, jsjodin, domada, agozillon.
Herald added subscribers: sunshaoce, guansong, hiraditya, yaxunl.
Herald added a project: All.
skatrak requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added projects: clang, LLVM.

This patch updates the `OpenMPIRBuilderConfig` structure to hold all
available 'requires' clauses, and it moves part of the code
generation for the 'requires' registration function from clang to the
`OMPIRBuilder`, to be shared with flang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147217

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -5731,7 +5731,8 @@
 
 TEST_F(OpenMPIRBuilderTest, OffloadEntriesInfoManager) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.setConfig(OpenMPIRBuilderConfig(true, false, false, false));
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(true, false, false, false, false, false, false));
   OffloadEntriesInfoManager &InfoManager = OMPBuilder.OffloadInfoManager;
   TargetRegionEntryInfo EntryInfo("parent", 1, 2, 4, 0);
   InfoManager.initializeTargetRegionEntryInfo(EntryInfo, 0);
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -21,10 +21,12 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/MDBuilder.h"
@@ -328,6 +330,104 @@
   return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
 }
 
+//===--===//
+// OpenMPIRBuilderConfig
+//===--===//
+
+namespace {
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+/// Values for bit flags for marking which requires clauses have been used.
+enum OpenMPOffloadingRequiresDirFlags {
+  /// flag undefined.
+  OMP_REQ_UNDEFINED = 0x000,
+  /// no requires directive present.
+  OMP_REQ_NONE = 0x001,
+  /// reverse_offload clause.
+  OMP_REQ_REVERSE_OFFLOAD = 0x002,
+  /// unified_address clause.
+  OMP_REQ_UNIFIED_ADDRESS = 0x004,
+  /// unified_shared_memory clause.
+  OMP_REQ_UNIFIED_SHARED_MEMORY = 0x008,
+  /// dynamic_allocators clause.
+  OMP_REQ_DYNAMIC_ALLOCATORS = 0x010,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/OMP_REQ_DYNAMIC_ALLOCATORS)
+};
+
+} // anonymous namespace
+
+OpenMPIRBuilderConfig::OpenMPIRBuilderConfig()
+: RequiresFlags(OMP_REQ_UNDEFINED) {}
+
+OpenMPIRBuilderConfig::OpenMPIRBuilderConfig(
+bool IsEmbedded, bool IsTargetCodegen, bool OpenMPOffloadMandatory,
+bool HasRequiresReverseOffload, bool HasRequiresUnifiedAddress,
+bool HasRequiresUnifiedSharedMemory, bool HasRequiresDynamicAllocators)
+: RequiresFlags(OMP_REQ_UNDEFINED), IsEmbedded(IsEmbedded),
+  IsTargetCodegen(IsTargetCodegen),
+  OpenMPOffloadMandatory(OpenMPOffloadMandatory) {
+  if (HasRequiresReverseOffload)
+RequiresFlags |= OMP_REQ_REVERSE_OFFLOAD;
+  if (HasRequiresUnifiedAddress)
+RequiresFlags |= OMP_REQ_UNIFIED_ADDRESS;
+  if (HasRequiresUnifiedSharedMemory)
+RequiresFlags |= OMP_REQ_UNIFIED_SHARED_MEMORY;
+  if (HasRequiresDynamicAllocators)
+RequiresFlags |= OMP_REQ_DYNAMIC_ALLOCATORS;
+}
+
+bool OpenMPIRBuilderConfig::hasRequiresReverseOffload() const {
+  return RequiresFlags & OMP_REQ_REVERSE_OFFLOAD;
+}
+
+bool OpenMPIRBuilderConfig::hasRequiresUnifiedAddress() const {
+  return RequiresFlags & OMP_REQ_UNIFIED_ADDRESS;
+}
+
+bool OpenMPIRBuilderConfig::hasRequiresUnifiedSharedMemory() const {
+  return RequiresFlags & OMP_REQ_UNIFIED_SHARED_MEMORY;
+}
+
+bool OpenMPIRBuilderConfig::hasRequiresDynamicAllocators() const {
+  return RequiresFlags & OMP_REQ_DYNAMIC_ALLOCATORS;
+}
+
+int64_t OpenMPIRBuilderConfig::getRequiresFlags() const {
+  return hasRequiresFlags() ? RequiresFlags
+: static_cast(OMP_REQ_NONE);
+}
+
+void OpenMPIRBuilderConfig::setHasRequiresReverseOffload(bool Value) {
+  if (Value)
+RequiresFlags |= OMP_REQ_REVERSE_OFFLOAD;
+  else
+RequiresFlags &= ~OMP_REQ_REVERS

[PATCH] D147121: [hwasan] remove requirment for PIE

2023-03-30 Thread Mingjie Xu via Phabricator via cfe-commits
Enna1 updated this revision to Diff 509611.
Enna1 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147121

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/sanitizer-ld.c


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -961,7 +961,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-HWASAN-X86-64-LINUX %s
 //
 // CHECK-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.a"
 // CHECK-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
@@ -979,7 +978,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-X86-64-LINUX %s
 //
 // CHECK-SHARED-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SHARED-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
 // CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
@@ -996,7 +994,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-DSO-SHARED-HWASAN-X86-64-LINUX %s
 //
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: 
"{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-DSO_SHARED-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
@@ -1013,7 +1010,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-HWASAN-AARCH64-LINUX %s
 //
 // CHECK-HWASAN-AARCH64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-HWASAN-AARCH64-LINUX: "-pie"
 // CHECK-HWASAN-AARCH64-LINUX-NOT: "-lc"
 // CHECK-HWASAN-AARCH64-LINUX: libclang_rt.hwasan-aarch64.a"
 // CHECK-HWASAN-AARCH64-LINUX-NOT: "--export-dynamic"
@@ -1032,7 +1028,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-AARCH64-LINUX %s
 //
 // CHECK-SHARED-HWASAN-AARCH64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SHARED-HWASAN-AARCH64-LINUX: "-pie"
 // CHECK-SHARED-HWASAN-AARCH64-LINUX-NOT: "-lc"
 // CHECK-SHARED-HWASAN-AARCH64-LINUX: libclang_rt.hwasan-aarch64.so"
 // CHECK-SHARED-HWASAN-AARCH64-LINUX-NOT: "-lpthread"
@@ -1049,7 +1044,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX %s
 //
 // CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX: 
"{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-DSO_SHARED-HWASAN-AARCH64-LINUX: "-pie"
 // CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX-NOT: "-lc"
 // CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX: libclang_rt.hwasan-aarch64.so"
 // CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX-NOT: "-lpthread"
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -38,8 +38,7 @@
 static const SanitizerMask NotAllowedWithMinimalRuntime =
 SanitizerKind::Function | SanitizerKind::Vptr;
 static const SanitizerMask RequiresPIE =
-SanitizerKind::DataFlow | SanitizerKind::HWAddress | SanitizerKind::Scudo |
-SanitizerKind::KCFI;
+SanitizerKind::DataFlow | SanitizerKind::Scudo | SanitizerKind::KCFI;
 static const SanitizerMask NeedsUnwindTables =
 SanitizerKind::Address | SanitizerKind::HWAddress | SanitizerKind::Thread |
 SanitizerKind::Memory | SanitizerKind::DataFlow;


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -961,7 +961,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-HWASAN-X86-64-LINUX %s
 //
 // CHECK-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.a"
 // CHECK-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
@@ -979,7 +978,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-X86-64-LINUX %s
 //
 // CHECK-SHARED-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SHARED-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
 // CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
@@ -996,7 +994,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-DSO-SHARED-HWASAN-X86-64-LINUX %s
 //
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-DSO_SHARED-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
@@ -1013,7 +1010,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-HWASAN-AARCH64-LINUX %s
 //
 // C

Re: [PATCH] D143967: [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF

2023-03-30 Thread Jose E. Marchesi via cfe-commits

> eddyz87 added a subscriber: anakryiko.
> eddyz87 added a comment.
>
> In D143967#4231746 , @jemarch wrote:
>
>>> eddyz87 added a comment.
>>> ...
>>> If we consider type tag a qualifier, conceptually it would be simpler
>>> if ordering would not matter for it as well, so that the following
>>> have identical meaning:
>>>
>>> - `__tag volatile int`
>>> - `volatile __tag int`
>>
>> Makes sense.
>>
>> But then I think we should allow the tags to be anywhere in the chain in
>> the DWARF, and not necessarily in the qualified type.  For example
>> given:
>>
>>   typedef const int bar;
>>   volatile bar __tag1 foo;
>>
>> The resulting DWARF type chain is:
>>
>>   volatile -> typedef (bar) -> const -> int
>>
>> IMO we should allow __tag1 to be a child of any of the elements of the
>> chain, like:
>>
>>   volatile -> typedef (bar) -> const -> int
>>|
>>  __tag1
>>
>> or
>>
>>   volatile -> typedef (bar) -> const -> int
>>  |
>>   __tag1
>>
>> or
>>
>>   volatile -> typedef (bar) -> const -> int
>>  |
>>   __tag1
>>
>> or
>>
>>   volatile -> typedef (bar) -> const -> int
>>  |
>>__tag1
>>
>> would be all accepted and equivalent.  Also Faust noted that GCC
>> sometimes optimizes out the typedef nodes, so we need to be able to
>> place the tags (in the internal representatinos) in the typedef'ed type
>> instead.
>
> Well, it's a logical consequence, I guess.
> In practice I'm going to emit it like below:
>
>   volatile -> const -> int
> |
>  __tag1
>
> But please remember that in BTF it would have to be encoded like this:
>
>   __tag1 -> volatile -> const -> int
>
> (that's how kernel expects it, we can change the kernel but will loose
> backwards compatibility).

Thinking about typedef, some C cases may be problematic if we adopt the
flexible rule we are discussing:

  typedef int bar;
  const bar __tag1 var1;
  bar var2;

  DWARF:

  var1 -> const -> typedef (bar) -> int
   |   ^
  __tag1   |
   |
  var2 +

If we would allow __tag1 to be "moved" to either the typedef DWARF node
or the node for int like this:

  DWARF:

  var1 -> const -> typedef (bar) -> int
   ^ |
   |  __tag1
  var2 +

Then the __tag1 would also apply to var2's type.  But I would say in the
C snippet above __tag1 should apply to the type of var1, but not
to the type of var2.

This makes me think we shouldn't allow tags to "jump" over typedef
nodes, in neither DWARF nor BTF.

PS: I am a bit concerned with the fact that the kernel's interpretation
of BTF is so rigit in this case as to assume C's type system
semantics when it comes to type qualifiers.  Other languages may be
coming to the BPF world (Rust, for example) and in these languages
the ordering of type qualifiers may actually matter.  There is a
reason why DWARF encodes qualifiers as explicit nodes in the type
chain rather than as attributes of the type nodes.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147213: [include-cleaner] Ignore builtin symbols in the WalkAST.

2023-03-30 Thread Haojian Wu 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 rG83546221af43: [include-cleaner] Ignore builtin symbols in 
the WalkAST. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147213

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -322,5 +322,11 @@
   testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
+TEST(WalkAST, BuiltinSymbols) {
+  testWalk(R"cpp(
+extern "C" int __builtin_popcount(unsigned int) noexcept;
+  )cpp", "int x = ^__builtin_popcount(1);");
+}
+
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -34,6 +35,9 @@
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
   return;
+// Don't report builtin symbols.
+if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0)
+  return;
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -322,5 +322,11 @@
   testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
+TEST(WalkAST, BuiltinSymbols) {
+  testWalk(R"cpp(
+extern "C" int __builtin_popcount(unsigned int) noexcept;
+  )cpp", "int x = ^__builtin_popcount(1);");
+}
+
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -34,6 +35,9 @@
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
   return;
+// Don't report builtin symbols.
+if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0)
+  return;
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 8354622 - [include-cleaner] Ignore builtin symbols in the WalkAST.

2023-03-30 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-03-30T13:46:41+02:00
New Revision: 83546221af43ca347f8e1b1197a9df54810244e0

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

LOG: [include-cleaner] Ignore builtin symbols in the WalkAST.

There is no need to add headers for builtin symbols.

Additionally, there is a bonus benefit which help eliminate some bugs -- builtin
functions are modeled as implicit FunctionDecls in the clang AST, which results 
in
them being treated as normal FunctionDecls in the implementation of the 
include-cleaner
(going through the path: ast-node -> decl -> source location -> header).
And, the source location of these built-in symbols' AST nodes is not precise 
(e.g. points to the first call site),
which leads to subtle behavior that inserts a header of the call site.

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index 0db1f2bec8e6b..b10c722b6653a 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -34,6 +35,9 @@ class ASTWalker : public RecursiveASTVisitor {
   RefType RT = RefType::Explicit) {
 if (!ND || Loc.isInvalid())
   return;
+// Don't report builtin symbols.
+if (const auto *II = ND->getIdentifier(); II && II->getBuiltinID() > 0)
+  return;
 Callback(Loc, *cast(ND->getCanonicalDecl()), RT);
   }
 

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index 8ce556f5fbf1f..fd6c6da9d5509 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -322,5 +322,11 @@ TEST(WalkAST, Enums) {
   testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
+TEST(WalkAST, BuiltinSymbols) {
+  testWalk(R"cpp(
+extern "C" int __builtin_popcount(unsigned int) noexcept;
+  )cpp", "int x = ^__builtin_popcount(1);");
+}
+
 } // namespace
 } // namespace clang::include_cleaner



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


[PATCH] D121584: [clang-format] Correctly recognize arrays in template parameter list.

2023-03-30 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.
Herald added a project: clang-format.

In D121584#3404704 , @curdeius wrote:

> Yes, let's revert this. I should have a fix soon though.

@curdeius Did you manage to find a fix suitable for both use cases?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121584

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


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaCXX/static-assert.cpp:262
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+

+1 -- please spell out more of the diagnostic wording (I see you're following a 
pattern elsewhere in the file, but we should have enough diagnostic wording to 
know what the diagnostic is.)

It's hard for me to tell from this review because the patch was not uploaded 
with context (next time, please use `-U` when making the patch diff so that 
this context exists), but is there test coverage showing what happens when the 
operators are chained together? e.g.,
```
static_assert(inverted(true) || invert(true) || false, "");
static_assert((true && invert(true)) || false, "");
static_assert(true && inverted(false) && inverted(true), "");
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

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


[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-03-30 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:1338
+
+auto ReferencedInclude = convertIncludes(SM, Inc);
+include_cleaner::walkUsed(

can we put the rest into a separate function (I know this function is already 
quite long, but I think we shouldn't make it worse, and probably refactor 
soon). I believe something like below should work?
```
std::vector getIncludeUsages(const ParsedAST &AST, const Inclusion 
&Include);
```



Comment at: clang-tools-extra/clangd/XRefs.cpp:1347
+
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  for (const auto &H : Providers) {

nit: no need to calculate the file location, if we're not going to emit a 
reference. so maybe move this into the place where we're going to use the `Loc`.



Comment at: clang-tools-extra/clangd/XRefs.cpp:1347
+
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  for (const auto &H : Providers) {

kadircet wrote:
> nit: no need to calculate the file location, if we're not going to emit a 
> reference. so maybe move this into the place where we're going to use the 
> `Loc`.
this file location might fall outside of the main file when they get expanded 
through `#include` directives, so we need something like 
https://reviews.llvm.org/D147139



Comment at: clang-tools-extra/clangd/XRefs.cpp:1348
+  auto Loc = SM.getFileLoc(Ref.RefLocation);
+  for (const auto &H : Providers) {
+auto MatchingIncludes = ConvertedMainFileIncludes.match(H);

we're implementing and testing this logic twice now, once in here and once in 
hover. can we instead have a helper in `IncludeCleaner.h` that looks like:
```
std::optional firstSatisfiedProvider(const 
include_cleaner::Includes& Includes, llvm::ArrayRef 
Providers);
// I'd actually return the matching `std::vector` (the highest 
ranked provider that matched some includes in main file), and check if the 
include of interest is part of that set for rest of the operations.
// Since it represents both the provider and the include in the main file. 
whereas the provider on it's own doesn't say anything about which include in 
main file triggered satisfaction.
```
and turn these call sites into
```
auto Provider = firstSatisfiedProvider(ConvertedMainFileIncludes, Providers);
if(!Provider || ReferencedInclude.match(Provider).empty())
  return;
// Include in question provides the symbol, do magic.
```



Comment at: clang-tools-extra/clangd/XRefs.cpp:1358
+  auto TokLen =
+  Lexer::MeasureTokenLength(Loc, SM, AST.getLangOpts());
+  Result.Loc.range =

no need to re-run the lexer, these references are inside the main file for 
sure, so you can use token buffer instead.



Comment at: clang-tools-extra/clangd/XRefs.cpp:1381
+Result.Loc.uri = URIMainFile;
+Results.References.push_back(std::move(Result));
+  }

we can return Results directly here, no need to run rest of the logic



Comment at: clang-tools-extra/clangd/XRefs.cpp:2004
 
-// Given a type targeted by the cursor, return one or more types that are more 
interesting
-// to target.
-static void unwrapFindType(
-QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
+// Given a type targeted by the cursor, return one or more types that are more
+// interesting to target.

can you revert changes below? I feel like they're unrelated formatting changes



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:1909
   TU.ExtraArgs.push_back("-std=c++20");
+  TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+#define BAR 5

rather than introducing these into all tests, can we have our own TestTU and 
whatnot in the relevant test? something like MainFileReferencesOnly test



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:2322
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+int fstBar = [[bar1]]();

can you also have a second include header that provides some other symbols and 
make sure references of those don't get highlighted?



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:2329
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;

we don't really need rest of these tests, they're testing the "symbol is 
provided by first provider included in the main file" logic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

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


[PATCH] D145264: [OpenMP][MLIR] Lower and apply RTLModuleFlagsAttr

2023-03-30 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 509626.
agozillon added a comment.

- [Flang][Driver][Test] Move flang-omp.f90 tests into 
omp-frontend-forwarding.f90


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/LangOptions.def
  flang/include/flang/Tools/CrossToolHelpers.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/omp-frontend-forwarding.f90
  flang/test/Lower/OpenMP/rtl-flags.f90
  flang/tools/bbc/CMakeLists.txt
  flang/tools/bbc/bbc.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1542,6 +1542,38 @@
   return bodyGenStatus;
 }
 
+/// Lowers the FlagsAttr which is applied to the module on the device
+/// pass when offloading, this attribute contains OpenMP RTL globals that can
+/// be passed as flags to the frontend, otherwise they are set to default
+LogicalResult convertFlagsAttr(Operation *op, mlir::omp::FlagsAttr attribute,
+   LLVM::ModuleTranslation &moduleTranslation) {
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+
+  ompBuilder->createGlobalFlag(
+  attribute.getDebugKind() /*LangOpts().OpenMPTargetDebug*/,
+  "__omp_rtl_debug_kind");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeTeamsOversubscription() /*LangOpts().OpenMPTeamSubscription*/
+  ,
+  "__omp_rtl_assume_teams_oversubscription");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeThreadsOversubscription() /*LangOpts().OpenMPThreadSubscription*/
+  ,
+  "__omp_rtl_assume_threads_oversubscription");
+  ompBuilder->createGlobalFlag(
+  attribute.getAssumeNoThreadState() /*LangOpts().OpenMPNoThreadState*/,
+  "__omp_rtl_assume_no_thread_state");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeNoNestedParallelism() /*LangOpts().OpenMPNoNestedParallelism*/
+  ,
+  "__omp_rtl_assume_no_nested_parallelism");
+
+  return success();
+}
+
 namespace {
 
 /// Implementation of the dialect interface that converts operations belonging
@@ -1556,10 +1588,34 @@
   LogicalResult
   convertOperation(Operation *op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) const final;
+
+  LogicalResult
+  amendOperation(Operation *op, NamedAttribute attribute,
+ LLVM::ModuleTranslation &moduleTranslation) const final;
 };
 
 } // namespace
 
+/// Given an OpenMP MLIR attribute, create the corresponding LLVM-IR, runtime
+/// calls, or operation amendments
+LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
+Operation *op, NamedAttribute attribute,
+LLVM::ModuleTranslation &moduleTranslation) const {
+
+  return llvm::TypeSwitch(attribute.getValue())
+  .Case([&](mlir::omp::FlagsAttr rtlAttr) {
+return convertFlagsAttr(op, rtlAttr, moduleTranslation);
+  })
+  .Default([&](Attribute attr) {
+// fall through for omp attributes that do not require lowering and/or
+// have no concrete definition and thus no type to define a case on
+// e.g. omp.is_device
+return success();
+  });
+
+  return failure();
+}
+
 /// Given an OpenMP MLIR operation, create the corresponding LLVM IR
 /// (including OpenMP runtime calls).
 LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation(
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -16,6 +16,7 @@
 
 #include "flang/Common/Fortran-features.h"
 #include "flang/Common/default-kinds.h"
+#include "flang/Frontend/LangOptions.h"
 #include "flang/Lower/Bridge.h"
 #include "flang/Lower/PFTBuilder.h"
 #include "flang/Lower/Support/Verifier.h"
@@ -129,6 +130,39 @@
llvm::cl::desc("enable openmp device compilation"),
llvm::cl::init(false));
 
+// A simplified subset of the OpenMP RTL Flags from Flang, only the primary
+// positive options are available, no negative options e.g. fopen_assume* vs
+// fno_open_assume*
+static llvm::cl::opt setOpenMPTargetDebug(
+"fopenmp-target-debug",
+llvm::cl::desc("Enable debugging in the OpenMP offloading device RTL"),
+llvm::cl::init(0));
+
+static llvm::cl::opt
+setOpenMPThreadSubscription(
+"fopenmp-assume-threads-oversubscription",
+llvm::cl::desc("Assume work-shared loops do not hav

[PATCH] D145264: [OpenMP][MLIR] Lower and apply RTLModuleFlagsAttr

2023-03-30 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 509628.
agozillon added a comment.

- [Flang][Driver][Test] Move flang-omp.f90 tests into 
omp-frontend-forwarding.f90


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/LangOptions.def
  flang/include/flang/Tools/CrossToolHelpers.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/omp-frontend-forwarding.f90
  flang/test/Lower/OpenMP/rtl-flags.f90
  flang/tools/bbc/CMakeLists.txt
  flang/tools/bbc/bbc.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1542,6 +1542,38 @@
   return bodyGenStatus;
 }
 
+/// Lowers the FlagsAttr which is applied to the module on the device
+/// pass when offloading, this attribute contains OpenMP RTL globals that can
+/// be passed as flags to the frontend, otherwise they are set to default
+LogicalResult convertFlagsAttr(Operation *op, mlir::omp::FlagsAttr attribute,
+   LLVM::ModuleTranslation &moduleTranslation) {
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+
+  ompBuilder->createGlobalFlag(
+  attribute.getDebugKind() /*LangOpts().OpenMPTargetDebug*/,
+  "__omp_rtl_debug_kind");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeTeamsOversubscription() /*LangOpts().OpenMPTeamSubscription*/
+  ,
+  "__omp_rtl_assume_teams_oversubscription");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeThreadsOversubscription() /*LangOpts().OpenMPThreadSubscription*/
+  ,
+  "__omp_rtl_assume_threads_oversubscription");
+  ompBuilder->createGlobalFlag(
+  attribute.getAssumeNoThreadState() /*LangOpts().OpenMPNoThreadState*/,
+  "__omp_rtl_assume_no_thread_state");
+  ompBuilder->createGlobalFlag(
+  attribute
+  .getAssumeNoNestedParallelism() /*LangOpts().OpenMPNoNestedParallelism*/
+  ,
+  "__omp_rtl_assume_no_nested_parallelism");
+
+  return success();
+}
+
 namespace {
 
 /// Implementation of the dialect interface that converts operations belonging
@@ -1556,10 +1588,34 @@
   LogicalResult
   convertOperation(Operation *op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) const final;
+
+  LogicalResult
+  amendOperation(Operation *op, NamedAttribute attribute,
+ LLVM::ModuleTranslation &moduleTranslation) const final;
 };
 
 } // namespace
 
+/// Given an OpenMP MLIR attribute, create the corresponding LLVM-IR, runtime
+/// calls, or operation amendments
+LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
+Operation *op, NamedAttribute attribute,
+LLVM::ModuleTranslation &moduleTranslation) const {
+
+  return llvm::TypeSwitch(attribute.getValue())
+  .Case([&](mlir::omp::FlagsAttr rtlAttr) {
+return convertFlagsAttr(op, rtlAttr, moduleTranslation);
+  })
+  .Default([&](Attribute attr) {
+// fall through for omp attributes that do not require lowering and/or
+// have no concrete definition and thus no type to define a case on
+// e.g. omp.is_device
+return success();
+  });
+
+  return failure();
+}
+
 /// Given an OpenMP MLIR operation, create the corresponding LLVM IR
 /// (including OpenMP runtime calls).
 LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation(
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -16,6 +16,7 @@
 
 #include "flang/Common/Fortran-features.h"
 #include "flang/Common/default-kinds.h"
+#include "flang/Frontend/LangOptions.h"
 #include "flang/Lower/Bridge.h"
 #include "flang/Lower/PFTBuilder.h"
 #include "flang/Lower/Support/Verifier.h"
@@ -129,6 +130,39 @@
llvm::cl::desc("enable openmp device compilation"),
llvm::cl::init(false));
 
+// A simplified subset of the OpenMP RTL Flags from Flang, only the primary
+// positive options are available, no negative options e.g. fopen_assume* vs
+// fno_open_assume*
+static llvm::cl::opt setOpenMPTargetDebug(
+"fopenmp-target-debug",
+llvm::cl::desc("Enable debugging in the OpenMP offloading device RTL"),
+llvm::cl::init(0));
+
+static llvm::cl::opt
+setOpenMPThreadSubscription(
+"fopenmp-assume-threads-oversubscription",
+llvm::cl::desc("Assume work-shared loops do not hav

[PATCH] D145264: [OpenMP][MLIR] Lower and apply RTLModuleFlagsAttr

2023-03-30 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

Recent update(s) moved flag/driver testing of the flags from Clang to Flang's 
omp-frontend-forwarding.f90 aligning it with previous tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[PATCH] D137327: [clang-format] Handle object instansiation in if-statements

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

because of https://github.com/llvm/llvm-project/issues/61785 should this really 
be reverted?  is basically saying `X * Y {`  must be `X *Y{`  but that 
obviously not the case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137327

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


[PATCH] D144862: Implement code lense for used symbols.

2023-03-30 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 509633.
VitaNuo added a comment.

Use custom command.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144862

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/test/fixits-command.test
  clang-tools-extra/clangd/test/initialize-params.test

Index: clang-tools-extra/clangd/test/initialize-params.test
===
--- clang-tools-extra/clangd/test/initialize-params.test
+++ clang-tools-extra/clangd/test/initialize-params.test
@@ -9,6 +9,7 @@
 # CHECK-NEXT:  "callHierarchyProvider": true,
 # CHECK-NEXT:  "clangdInlayHintsProvider": true,
 # CHECK-NEXT:  "codeActionProvider": true,
+# CHECK-NEXT:  "codeLensProvider": true,
 # CHECK-NEXT:  "compilationDatabase": {
 # CHECK-NEXT:"automaticReload": true
 # CHECK-NEXT:  },
Index: clang-tools-extra/clangd/test/fixits-command.test
===
--- clang-tools-extra/clangd/test/fixits-command.test
+++ clang-tools-extra/clangd/test/fixits-command.test
@@ -63,7 +63,8 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:]
 # CHECK-NEXT:  }
-# CHECK-NEXT:}
+# CHECK-NEXT:},
+# CHECK-NEXT:null
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  "command": "clangd.applyFix",
 # CHECK-NEXT:  "title": "Apply fix: place parentheses around the assignment to silence this warning"
@@ -88,7 +89,8 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:]
 # CHECK-NEXT:  }
-# CHECK-NEXT:}
+# CHECK-NEXT:},
+# CHECK-NEXT:null
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  "command": "clangd.applyFix",
 # CHECK-NEXT:  "title": "Apply fix: use '==' to turn this assignment into an equality comparison"
@@ -133,7 +135,8 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:]
 # CHECK-NEXT:  }
-# CHECK-NEXT:}
+# CHECK-NEXT:},
+# CHECK-NEXT:null
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  "command": "clangd.applyFix",
 # CHECK-NEXT:  "title": "Apply fix: place parentheses around the assignment to silence this warning"
@@ -158,7 +161,8 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:]
 # CHECK-NEXT:  }
-# CHECK-NEXT:}
+# CHECK-NEXT:},
+# CHECK-NEXT:null
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  "command": "clangd.applyFix",
 # CHECK-NEXT:  "title": "Apply fix: use '==' to turn this assignment into an equality comparison"
Index: clang-tools-extra/clangd/test/code-action-request.test
===
--- clang-tools-extra/clangd/test/code-action-request.test
+++ clang-tools-extra/clangd/test/code-action-request.test
@@ -44,7 +44,8 @@
 # CHECK-NEXT:}
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "tweakID": "ExpandDeducedType"
-# CHECK-NEXT:}
+# CHECK-NEXT:},
+# CHECK-NEXT:null
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  "command": "clangd.applyTweak",
 # CHECK-NEXT:  "title": "Replace with deduced type"
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -32,6 +32,8 @@
 namespace clangd {
 class ParsedAST;
 
+std::vector findCodeLens(ParsedAST &AST);
+
 // Describes where a symbol is declared and defined (as far as clangd knows).
 // There are three cases:
 //  - a declaration only, no definition is known (e.g. only header seen)
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -10,12 +10,15 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -51,6 +54,7 @@
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallSet.h"
@@ -61,6 +65,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#includ

[PATCH] D146376: Update static_assert message for redundant cases

2023-03-30 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 509632.
Krishna-13-cyber added a comment.
Herald added subscribers: llvm-commits, kadircet, arphaman.
Herald added a project: LLVM.

- Updated patch
- Added testcases for chained operators




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn


Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -23,6 +23,7 @@
 "//clang/lib/Lex",
 "//clang/lib/Sema",
 "//clang/lib/Serialization",
+"//clang/lib/Testing",
 "//clang/lib/Tooling",
 "//clang/lib/Tooling/Core",
 "//clang/lib/Tooling/Inclusions",
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{failed}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error 
{{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error 
{{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error 
{{failed}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != 
BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 


Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -23,6 +23,7 @@
 "//clang/lib/Lex",
 "//clang/lib/Sema",
 "//clang/lib/Serialization",
+"//clang/lib/Testing",
 "//clang/lib/Tooling",
 "//clang/lib/Tooling/Core",
 "//clang/lib/Tooling/Inclusions",
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{failed}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error {{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error {{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error {{failed}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144862: Implement code lense for used symbols.

2023-03-30 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 509636.
VitaNuo added a comment.

Improve argument handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144862

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/test/initialize-params.test

Index: clang-tools-extra/clangd/test/initialize-params.test
===
--- clang-tools-extra/clangd/test/initialize-params.test
+++ clang-tools-extra/clangd/test/initialize-params.test
@@ -9,6 +9,7 @@
 # CHECK-NEXT:  "callHierarchyProvider": true,
 # CHECK-NEXT:  "clangdInlayHintsProvider": true,
 # CHECK-NEXT:  "codeActionProvider": true,
+# CHECK-NEXT:  "codeLensProvider": true,
 # CHECK-NEXT:  "compilationDatabase": {
 # CHECK-NEXT:"automaticReload": true
 # CHECK-NEXT:  },
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -32,6 +32,8 @@
 namespace clangd {
 class ParsedAST;
 
+std::vector findCodeLens(ParsedAST &AST);
+
 // Describes where a symbol is declared and defined (as far as clangd knows).
 // There are three cases:
 //  - a declaration only, no definition is known (e.g. only header seen)
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -10,12 +10,15 @@
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -51,6 +54,7 @@
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallSet.h"
@@ -61,6 +65,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1312,6 +1317,63 @@
 }
 } // namespace
 
+std::vector findCodeLens(ParsedAST &AST) {
+  const auto &SM = AST.getSourceManager();
+  std::vector Result;
+  auto Includes = AST.getIncludeStructure().MainFileIncludes;
+  auto ConvertedMainFileIncludes = convertIncludes(SM, Includes);
+  for (auto &Inc : Includes) {
+llvm::DenseSet UsedSyms;
+auto AnalyzedInclude = convertIncludes(SM, Inc);
+include_cleaner::walkUsed(
+AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
+AST.getPragmaIncludes(), SM,
+[&](const include_cleaner::SymbolReference &Ref,
+llvm::ArrayRef Providers) {
+  if (Ref.RT != include_cleaner::RefType::Explicit)
+return;
+
+  for (const auto &H : Providers) {
+auto MatchingIncludes = ConvertedMainFileIncludes.match(H);
+// No match for this provider in the main file.
+if (MatchingIncludes.empty())
+  continue;
+
+// Check if the referenced include matches this provider.
+if (!AnalyzedInclude.match(H).empty()) {
+  UsedSyms.insert(Ref.Target);
+}
+
+// Don't look for rest of the providers once we've found a match
+// in the main file.
+break;
+  }
+});
+
+// Compute the length of the #include line
+auto IncludeLen =
+std::string{"#include"}.length() + Inc.Written.length() + 1;
+CodeLens Lens;
+Lens.range = clangd::Range{Position{Inc.HashLine, 0},
+   Position{Inc.HashLine, (int)IncludeLen}};
+
+Command Cmd;
+Cmd.title = std::to_string(UsedSyms.size()) + " used symbols";
+Cmd.command = "clangd/findReferences";
+
+auto MainFilePath = AST.tuPath();
+auto URIMainFile = URIForFile::canonicalize(MainFilePath, MainFilePath);
+   
+Cmd.argument = URIMainFile;
+Position P = sourceLocToPosition(SM, SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset));
+Cmd.argument2 = P;
+Lens.command = Cmd;
+Result.push_back(Lens);  
+  }
+  
+  return Result;
+}
+
 ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
 const SymbolIndex *Index, bool AddContext) {
   ReferencesResult Results;
@@ -1324,6 

[PATCH] D147227: [clangd] Support Config in TestTU.

2023-03-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Add a config as a filed in TestTU, for each TestTU::build, we set the
config. And make the Config copyable.

This is needed for enabling the unused-include feature by default.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147227

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -19,6 +19,7 @@
 
 #include "../TidyProvider.h"
 #include "Compiler.h"
+#include "Config.h"
 #include "FeatureModule.h"
 #include "ParsedAST.h"
 #include "TestFS.h"
@@ -45,6 +46,8 @@
 return TU;
   }
 
+  TestTU();
+
   // The code to be compiled.
   std::string Code;
   std::string Filename = "TestTU.cpp";
@@ -59,6 +62,8 @@
   // Extra arguments for the compiler invocation.
   std::vector ExtraArgs;
 
+  Config Cfg;
+
   // Predefine macros such as __UINTPTR_TYPE__.
   bool PredefineMacros = false;
 
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -9,6 +9,7 @@
 #include "TestTU.h"
 #include "CompileCommands.h"
 #include "Compiler.h"
+#include "Config.h"
 #include "Diagnostics.h"
 #include "TestFS.h"
 #include "index/FileIndex.h"
@@ -23,6 +24,12 @@
 namespace clang {
 namespace clangd {
 
+TestTU::TestTU() {
+  // Disable the clangd-specific diagnostics by default.
+  Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::None;
+  Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::None;
+}
+
 ParseInputs TestTU::inputs(MockFS &FS) const {
   std::string FullFilename = testPath(Filename),
   FullHeaderName = testPath(HeaderFilename),
@@ -122,7 +129,7 @@
 initializeModuleCache(*CI);
   auto ModuleCacheDeleter = llvm::make_scope_exit(
   std::bind(deleteModuleCache, CI->getHeaderSearchOpts().ModuleCachePath));
-
+  WithContextValue Ctx(Config::Key, Cfg);
   auto Preamble = clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
/*StoreInMemory=*/true,
/*PreambleCallback=*/nullptr);
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -473,9 +473,8 @@
   ElementsAre(Diag(Main.range(), "use of undeclared identifier 'unknown'"),
   Diag(Main.range("ret"),
"void function 'x' should not return a value")));
-  Config Cfg;
-  Cfg.Diagnostics.Suppress.insert("return-type");
-  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  TU.Cfg.Diagnostics.Suppress.insert("return-type");
   EXPECT_THAT(*TU.build().getDiagnostics(),
   ElementsAre(Diag(Main.range(),
"use of undeclared identifier 'unknown'")));
@@ -490,9 +489,7 @@
   )cpp");
   auto TU = TestTU::withCode(Main.code());
   TU.AdditionalFiles["header.hpp"] = std::string(Header.code());
-  Config Cfg;
-  Cfg.Diagnostics.Suppress.insert("init_conversion_failed");
-  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+  TU.Cfg.Diagnostics.Suppress.insert("init_conversion_failed");
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
 }
 
@@ -1899,12 +1896,10 @@
   TU.ExtraArgs = {"-isystem" + testPath("system")};
   // Off by default.
   EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
-  Config Cfg;
-  Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
+  TU.Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
   // Set filtering.
-  Cfg.Diagnostics.Includes.IgnoreHeader.emplace_back(
+  TU.Cfg.Diagnostics.Includes.IgnoreHeader.emplace_back(
   [](llvm::StringRef Header) { return Header.endswith("ignore.h"); });
-  WithContextValue WithCfg(Config::Key, std::move(Cfg));
   auto AST = TU.build();
   EXPECT_THAT(
   *AST.getDiagnostics(),
@@ -1916,12 +1911,10 @@
   auto &Diag = AST.getDiagnostics()->front();
   EXPECT_EQ(getDiagnosticDocURI(Diag.Source, Diag.ID, Diag.Name),
 std::string("https://clangd.llvm.org/guides/include-cleaner";));
-  Cfg.Diagnostics.SuppressAll = true;
-  WithContextValue SuppressAllWithCfg(Config::Key, std::move(Cfg));
+  TU.Cfg.Diagnostics.SuppressAll = true;
   EXPECT_THAT(*T

[PATCH] D145264: [OpenMP][MLIR][Flang][Driver][bbc] Lower and apply Module FlagsAttr

2023-03-30 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

Unfortunately I do not believe an mlir-translate test that tests if the 
OffloadModuleInterface is accessible when directly utilizing mlir-translate is 
possible for this patch... I forgot I removed the is device check as it is 
already done at the initial creation of the attribute. However, I do have a 
future patch that it will be utilised in and when @jsjodin's initial TargetOp 
work is in I can likely create a test around that functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[PATCH] D145264: [OpenMP][MLIR][Flang][Driver][bbc] Lower and apply Module FlagsAttr

2023-03-30 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

The driver plumbing looks good to me. I will defer reviewing the OpenMP changes 
to experts. Thanks for working on this!




Comment at: clang/include/clang/Driver/Options.td:2692
 def fno_openmp_assume_teams_oversubscription : Flag<["-"], 
"fno-openmp-assume-teams-oversubscription">,
-  Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
+  Group, Flags<[CC1Option, FC1Option, NoArgumentUnused, HelpHidden]>;
 def fno_openmp_assume_threads_oversubscription : Flag<["-"], 
"fno-openmp-assume-threads-oversubscription">,

Many of these options have identical flags. While not really needed for this 
change, it would still be nice to re-organise them a bit. This file could 
really benefit from some love :) Here's an example of what I have in mind: 
https://github.com/llvm/llvm-project/blob/cf60d3f1a688671c8eb7859bf0572c403c3c0cca/clang/include/clang/Driver/Options.td#L6575-L6600



Comment at: flang/tools/bbc/CMakeLists.txt:29
 FortranLower
+flangFrontendTool
 )

This a frontend driver library and so far `bbc` and `flang-new -fc1` have been 
entirely separate. Could this dependency be avoided?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[clang] 18fe663 - Correct deferred concepts with NTTP placeholder constraints

2023-03-30 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-03-30T06:15:02-07:00
New Revision: 18fe66396906178872dd933a39e38779a5a3c722

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

LOG: Correct deferred concepts with NTTP placeholder constraints

Seemingly we never tested this, but the constraint on a NTTP was being
swtiched to the 'instantiated' version, but constraints need to be
relative to the 'top level', so this was causing us to not be able to
check the constraint on final use.

This patch corrects the issue by making the constraint created with the
un-instantiated version in the case of dependent constraint attachment.

Fixes: #61777

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/concepts.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9f7d58a4a3cd6..a5a784027636f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8123,7 +8123,8 @@ class Sema final {
 SourceLocation EllipsisLoc);
 
   bool AttachTypeConstraint(AutoTypeLoc TL,
-NonTypeTemplateParmDecl *ConstrainedParameter,
+NonTypeTemplateParmDecl *NewConstrainedParm,
+NonTypeTemplateParmDecl *OrigConstrainedParm,
 SourceLocation EllipsisLoc);
 
   bool RequireStructuralType(QualType T, SourceLocation Loc);

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index befc1e73c4f35..f1de491f1cd33 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1251,35 +1251,41 @@ bool Sema::AttachTypeConstraint(NestedNameSpecifierLoc 
NS,
   return false;
 }
 
-bool Sema::AttachTypeConstraint(AutoTypeLoc TL, NonTypeTemplateParmDecl *NTTP,
+bool Sema::AttachTypeConstraint(AutoTypeLoc TL,
+NonTypeTemplateParmDecl *NewConstrainedParm,
+NonTypeTemplateParmDecl *OrigConstrainedParm,
 SourceLocation EllipsisLoc) {
-  if (NTTP->getType() != TL.getType() ||
+  if (NewConstrainedParm->getType() != TL.getType() ||
   TL.getAutoKeyword() != AutoTypeKeyword::Auto) {
-Diag(NTTP->getTypeSourceInfo()->getTypeLoc().getBeginLoc(),
+Diag(NewConstrainedParm->getTypeSourceInfo()->getTypeLoc().getBeginLoc(),
  diag::err_unsupported_placeholder_constraint)
-   << NTTP->getTypeSourceInfo()->getTypeLoc().getSourceRange();
+<< NewConstrainedParm->getTypeSourceInfo()
+   ->getTypeLoc()
+   .getSourceRange();
 return true;
   }
   // FIXME: Concepts: This should be the type of the placeholder, but this is
   // unclear in the wording right now.
   DeclRefExpr *Ref =
-  BuildDeclRefExpr(NTTP, NTTP->getType(), VK_PRValue, NTTP->getLocation());
+  BuildDeclRefExpr(OrigConstrainedParm, OrigConstrainedParm->getType(),
+   VK_PRValue, OrigConstrainedParm->getLocation());
   if (!Ref)
 return true;
   ExprResult ImmediatelyDeclaredConstraint = formImmediatelyDeclaredConstraint(
   *this, TL.getNestedNameSpecifierLoc(), TL.getConceptNameInfo(),
   TL.getNamedConcept(), TL.getLAngleLoc(), TL.getRAngleLoc(),
-  BuildDecltypeType(Ref), NTTP->getLocation(),
+  BuildDecltypeType(Ref), OrigConstrainedParm->getLocation(),
   [&](TemplateArgumentListInfo &ConstraintArgs) {
 for (unsigned I = 0, C = TL.getNumArgs(); I != C; ++I)
   ConstraintArgs.addArgument(TL.getArgLoc(I));
   },
   EllipsisLoc);
   if (ImmediatelyDeclaredConstraint.isInvalid() ||
- !ImmediatelyDeclaredConstraint.isUsable())
+  !ImmediatelyDeclaredConstraint.isUsable())
 return true;
 
-  NTTP->setPlaceholderTypeConstraint(ImmediatelyDeclaredConstraint.get());
+  NewConstrainedParm->setPlaceholderTypeConstraint(
+  ImmediatelyDeclaredConstraint.get());
   return false;
 }
 
@@ -1559,7 +1565,7 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, 
Declarator &D,
 
   if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc())
 if (TL.isConstrained())
-  if (AttachTypeConstraint(TL, Param, D.getEllipsisLoc()))
+  if (AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
 Invalid = true;
 
   if (Invalid)

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index bf82ffb52a26e..ce461b18978c4 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3008,8 +3008,10 @@ Decl 
*TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(

Re: [PATCH] D143967: [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF

2023-03-30 Thread Jose E. Marchesi via cfe-commits

> eddyz87 added a comment.
>
> In D143967#4232089 , @jemarch wrote:
>
>> Thinking about typedef, some C cases may be problematic if we adopt the
>> flexible rule we are discussing:
>>
>>   typedef int bar;
>>   const bar __tag1 var1;
>>   bar var2;
>>   
>>   DWARF:
>>   
>>   var1 -> const -> typedef (bar) -> int
>>|   ^
>>   __tag1   |
>>|
>>   var2 +
>>
>> If we would allow __tag1 to be "moved" to either the typedef DWARF node
>> or the node for int like this:
>>
>>   DWARF:
>>   
>>   var1 -> const -> typedef (bar) -> int
>>^ |
>>|  __tag1
>>   var2 +
>>
>> Then the __tag1 would also apply to var2's type.  But I would say in the
>> C snippet above __tag1 should apply to the type of var1, but not
>> to the type of var2.
>
> I'm not sure I understand, the DWARF #2 is not a valid representation
> of the program for all the reasons you write.  Current LLVM
> implementation should generate DWARF #1 in this case.

Yes that was my point: tags can cross qualifiers and still keep C
language semantics, but not (all) typedefs.

> If some tooling applies such tags movement it should also apply
> appropriate copying of tags, e.g. it should transform DWARF like this:
>
>   var1 -> const -> typedef (bar) -> int
>  |
>   __tag1
>   
>   var2 --> typedef (bar) -> int
>
> (and it is what needs to be implemented in pahole to get BTF
> qualifiers ordering expected by kernel, but the move is in the
> opposite direction).

So the kernel expects tags to precede typedefs as well as qualifiers?
i.e. given this DWARF:

   var1 -> const -> typedef (bar) -> int
^ |
|   __tag1
|
   var2 +


We have to transform to these two BTF type chains:

var1 -> __tag1 -> const -> typedef (bar) -> int
^
|
var2 -> __tag1 -+

Correct?

>> PS: I am a bit concerned with the fact that the kernel's interpretation
>>
>>   of BTF is so rigit in this case as to assume C's type system
>>   semantics when it comes to type qualifiers.  Other languages may be
>>   coming to the BPF world (Rust, for example) and in these languages
>>   the ordering of type qualifiers may actually matter.  There is a
>>   reason why DWARF encodes qualifiers as explicit nodes in the type
>>   chain rather than as attributes of the type nodes.
>
> Need to read a bit about Rust, can't comment right now.
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D143967/new/
>
> https://reviews.llvm.org/D143967
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147179: [RISCV] Bump I, F, D, and A extension versions to 20191214 spec version

2023-03-30 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

I've added a couple of inline comments, but otherwise this seems fine to me. 
I'd suggest updating the patch description to reference Philip's documentation 
patch (which was posted soon after this), and also to explain why there are no 
codegen changes (I think "Either changes to the specification required no 
codegen changes, or LLVM was written against a newer version of the 
specification than it claimed" is vague but accurate).




Comment at: llvm/lib/Support/RISCVISAInfo.cpp:625
   case 'g':
 // g = imafd
 if (Arch.size() > 5 && isdigit(Arch[5]))

Perhaps update to `// g expands to extensions in RISCVGImplications.` or delete 
altogether.



Comment at: llvm/unittests/Support/RISCVISAInfoTest.cpp:253
 TEST(ParseArchString, AcceptsVersionInLongOrShortForm) {
-  for (StringRef Input : {"rv64i2", "rv64i2p0"}) {
-auto MaybeISAInfo = RISCVISAInfo::parseArchString(Input, true);

Why is this test dropped? It's not redundant as there's a slightly separate 
path for parsing the version on the base ISA vs other extensions (this could 
perhaps be refactored).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147179

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


[PATCH] D145264: [OpenMP][MLIR][Flang][Driver][bbc] Lower and apply Module FlagsAttr

2023-03-30 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added inline comments.



Comment at: clang/include/clang/Driver/Options.td:2692
 def fno_openmp_assume_teams_oversubscription : Flag<["-"], 
"fno-openmp-assume-teams-oversubscription">,
-  Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
+  Group, Flags<[CC1Option, FC1Option, NoArgumentUnused, HelpHidden]>;
 def fno_openmp_assume_threads_oversubscription : Flag<["-"], 
"fno-openmp-assume-threads-oversubscription">,

awarzynski wrote:
> Many of these options have identical flags. While not really needed for this 
> change, it would still be nice to re-organise them a bit. This file could 
> really benefit from some love :) Here's an example of what I have in mind: 
> https://github.com/llvm/llvm-project/blob/cf60d3f1a688671c8eb7859bf0572c403c3c0cca/clang/include/clang/Driver/Options.td#L6575-L6600
I can have a look into doing this in this patch :-)



Comment at: flang/tools/bbc/CMakeLists.txt:29
 FortranLower
+flangFrontendTool
 )

awarzynski wrote:
> This a frontend driver library and so far `bbc` and `flang-new -fc1` have 
> been entirely separate. Could this dependency be avoided?
I had hoped to share LangOpts so that the setOffloadModuleInterfaceAttributes 
function wouldn't turn into a monolithic set of arguments whenever it's invoked 
if more arguments are added, but the dependency isn't ideal I agree!

I could perhaps look into making some sort of shared data structure to be put 
inside of CrossToolHelpers that might remove the dependency and be similarly 
useable to how LangOpts works at the moment. If that doesn't work, I can revert 
the change to just be a regular argument list and we can revisit the topic if 
new options are ever added? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[PATCH] D147233: [clangd] Enable unused-include diagnostic by default.

2023-03-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Based on https://reviews.llvm.org/D147227.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147233

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -171,11 +171,6 @@
 }
 
 TEST(IncludeCleaner, GenerateMissingHeaderDiags) {
-  Config Cfg;
-  Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict;
-  Cfg.Diagnostics.Includes.IgnoreHeader = {
-  [](llvm::StringRef Header) { return Header.ends_with("buzz.h"); }};
-  WithContextValue Ctx(Config::Key, std::move(Cfg));
   Annotations MainFile(R"cpp(
 #include "a.h"
 #include "all.h"
@@ -247,6 +242,12 @@
   TU.Code = MainFile.code();
   ParsedAST AST = TU.build();
 
+  Config Cfg;
+  Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::None;
+  Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict;
+  Cfg.Diagnostics.Includes.IgnoreHeader = {
+  [](llvm::StringRef Header) { return Header.ends_with("buzz.h"); }};
+  WithContextValue Ctx(Config::Key, std::move(Cfg));
   std::vector Diags =
   issueIncludeCleanerDiagnostics(AST, TU.Code);
   EXPECT_THAT(
@@ -308,9 +309,7 @@
 // IWYU pragma: private, include "public.h"
 void foo() {}
   )cpp");
-  Config Cfg;
-  Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
-  WithContextValue Ctx(Config::Key, std::move(Cfg));
+  TU.Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
   ParsedAST AST = TU.build();
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
   IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
@@ -356,11 +355,8 @@
   )cpp";
   TU.ExtraArgs.emplace_back("-xobjective-c");
 
-  Config Cfg;
-
-  Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
-  Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict;
-  WithContextValue Ctx(Config::Key, std::move(Cfg));
+  TU.Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
+  TU.Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict;
   ParsedAST AST = TU.build();
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
 }
@@ -375,9 +371,7 @@
 void foo() {}
   )cpp");
   TU.Filename = "public.h";
-  Config Cfg;
-  Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
-  WithContextValue Ctx(Config::Key, std::move(Cfg));
+  TU.Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
   ParsedAST AST = TU.build();
   EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
   IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -246,10 +246,9 @@
 }
 
 TEST_F(ConfigCompileTests, DiagnosticsIncludeCleaner) {
-  // Defaults to None.
   EXPECT_TRUE(compileAndApply());
   EXPECT_EQ(Conf.Diagnostics.UnusedIncludes,
-Config::IncludesPolicy::None);
+Config::IncludesPolicy::Strict);
 
   Frag = {};
   Frag.Diagnostics.UnusedIncludes.emplace("None");
Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -106,7 +106,7 @@
 /// Enable emitting diagnostics using stale preambles.
 bool AllowStalePreamble = false;
 
-IncludesPolicy UnusedIncludes = IncludesPolicy::None;
+IncludesPolicy UnusedIncludes = IncludesPolicy::Strict;
 IncludesPolicy MissingIncludes = IncludesPolicy::None;
 
 /// IncludeCleaner will not diagnose usages of these headers matched by


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -171,11 +171,6 @@
 }
 
 TEST(IncludeCleaner, GenerateMissingHeaderDiags) {
-  Config Cfg;
-  Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict;
-  Cfg.Diagnostics.Includes.IgnoreHeader = {
-  [](llvm::StringRef Header) { return Header.ends_with("buzz.h"); }};
-  WithContextValue Ctx(Config::Key, std::move(Cfg));
   Annotations MainFile(R"cpp(
 #include "a.h"
 #include "all.h

[clang] 3ad1673 - [clang][Interp] Implement function pointers

2023-03-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-30T15:37:49+02:00
New Revision: 3ad167329aafde02e70b0327c0488602111a81ee

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

LOG: [clang][Interp] Implement function pointers

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

Added: 
clang/lib/AST/Interp/FunctionPointer.h

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpStack.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/PrimType.cpp
clang/lib/AST/Interp/PrimType.h
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index fff2425bedf42..c6cf7f7c99a59 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -131,6 +131,11 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 return this->emitCastFloatingIntegral(*ToT, CE);
   }
 
+  case CK_NullToPointer:
+if (DiscardResult)
+  return true;
+return this->emitNull(classifyPrim(CE->getType()), CE);
+
   case CK_ArrayToPointerDecay:
   case CK_AtomicToNonAtomic:
   case CK_ConstructorConversion:
@@ -138,7 +143,6 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
   case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_UserDefinedConversion:
-  case CK_NullToPointer:
 return this->visit(SubExpr);
 
   case CK_IntegralToBoolean:
@@ -400,10 +404,7 @@ bool 
ByteCodeExprGen::VisitImplicitValueInitExpr(const ImplicitValueIni
   if (!T)
 return false;
 
-  if (E->getType()->isPointerType())
-return this->emitNullPtr(E);
-
-  return this->emitZero(*T, E);
+  return this->visitZeroInitializer(*T, E);
 }
 
 template 
@@ -950,6 +951,8 @@ bool 
ByteCodeExprGen::visitZeroInitializer(PrimType T, const Expr *E) {
 return this->emitZeroUint64(E);
   case PT_Ptr:
 return this->emitNullPtr(E);
+  case PT_FnPtr:
+return this->emitNullFnPtr(E);
   case PT_Float:
 assert(false);
   }
@@ -1116,6 +1119,7 @@ bool ByteCodeExprGen::emitConst(T Value, const 
Expr *E) {
   case PT_Bool:
 return this->emitConstBool(Value, E);
   case PT_Ptr:
+  case PT_FnPtr:
   case PT_Float:
 llvm_unreachable("Invalid integral type");
 break;
@@ -1606,8 +1610,27 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
   if (E->getBuiltinCallee())
 return VisitBuiltinCallExpr(E);
 
-  const Decl *Callee = E->getCalleeDecl();
-  if (const auto *FuncDecl = dyn_cast_if_present(Callee)) {
+  QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
+  std::optional T = classify(ReturnType);
+  bool HasRVO = !ReturnType->isVoidType() && !T;
+
+  if (HasRVO && DiscardResult) {
+// If we need to discard the return value but the function returns its
+// value via an RVO pointer, we need to create one such pointer just
+// for this call.
+if (std::optional LocalIndex = allocateLocal(E)) {
+  if (!this->emitGetPtrLocal(*LocalIndex, E))
+return false;
+}
+  }
+
+  // Put arguments on the stack.
+  for (const auto *Arg : E->arguments()) {
+if (!this->visit(Arg))
+  return false;
+  }
+
+  if (const FunctionDecl *FuncDecl = E->getDirectCallee()) {
 const Function *Func = getFunction(FuncDecl);
 if (!Func)
   return false;
@@ -1619,24 +1642,7 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
 if (Func->isFullyCompiled() && !Func->isConstexpr())
   return false;
 
-QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
-std::optional T = classify(ReturnType);
-
-if (Func->hasRVO() && DiscardResult) {
-  // If we need to discard the return value but the function returns its
-  // value via an RVO pointer, we need to create one such pointer just
-  // for this call.
-  if (std::optional LocalIndex = allocateLocal(E)) {
-if (!this->emitGetPtrLocal(*LocalIndex, E))
-  return false;
-  }
-}
-
-// Put arguments on the stack.
-for (const auto *Arg : E->arguments()) {
-  if (!this->visit(Arg))
-return false;
-}
+assert(HasRVO == Func->hasRVO());
 
 // In any case call the function. The return value will end up on the stack
 // and if the function has RVO, we already have the pointer on the stack to
@@ -1644,15 +1650,22 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
 if (!this->emitCall(Func, E))
   return false;
 
-if (DiscardResult && !ReturnType->isVoidType() && T)
-  return this->emitPop(*T, E);
-
-return true;
   } else {
-assert(false && "We don't support non-FunctionDecl callees right now.");
+// I

[PATCH] D141472: [clang][Interp] Add function pointers

2023-03-30 Thread Timm Bäder 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 rG3ad167329aaf: [clang][Interp] Implement function pointers 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D141472?vs=507966&id=509655#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141472

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/FunctionPointer.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.cpp
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/functions.cpp

Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -99,3 +99,66 @@
   huh(); // expected-error {{use of undeclared identifier}} \
  // ref-error {{use of undeclared identifier}}
 }
+
+namespace FunctionPointers {
+  constexpr int add(int a, int b) {
+return a + b;
+  }
+
+  struct S { int a; };
+  constexpr S getS() {
+return S{12};
+  }
+
+  constexpr int applyBinOp(int a, int b, int (*op)(int, int)) {
+return op(a, b);
+  }
+  static_assert(applyBinOp(1, 2, add) == 3, "");
+
+  constexpr int ignoreReturnValue() {
+int (*foo)(int, int) = add;
+
+foo(1, 2);
+return 1;
+  }
+  static_assert(ignoreReturnValue() == 1, "");
+
+  constexpr int createS(S (*gimme)()) {
+gimme(); // Ignored return value
+return gimme().a;
+  }
+  static_assert(createS(getS) == 12, "");
+
+namespace FunctionReturnType {
+  typedef int (*ptr)(int*);
+  typedef ptr (*pm)();
+
+  constexpr int fun1(int* y) {
+  return *y + 10;
+  }
+  constexpr ptr fun() {
+  return &fun1;
+  }
+  static_assert(fun() == nullptr, ""); // expected-error {{static assertion failed}} \
+   // ref-error {{static assertion failed}}
+
+  constexpr int foo() {
+int (*f)(int *) = fun();
+int m = 0;
+
+m = f(&m);
+
+return m;
+  }
+  static_assert(foo() == 10);
+
+  struct S {
+int i;
+void (*fp)();
+  };
+
+  constexpr S s{ 12 };
+  static_assert(s.fp == nullptr); // zero-initialized function pointer.
+}
+
+}
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -24,6 +24,7 @@
 class Pointer;
 class Boolean;
 class Floating;
+class FunctionPointer;
 
 /// Enumeration of the primitive types of the VM.
 enum PrimType : unsigned {
@@ -38,6 +39,7 @@
   PT_Bool,
   PT_Float,
   PT_Ptr,
+  PT_FnPtr,
 };
 
 /// Mapping from primitive types to their representation.
@@ -53,6 +55,9 @@
 template <> struct PrimConv { using T = Floating; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
+template <> struct PrimConv {
+  using T = FunctionPointer;
+};
 
 /// Returns the size of a primitive type in bytes.
 size_t primSize(PrimType Type);
@@ -90,6 +95,7 @@
   TYPE_SWITCH_CASE(PT_Float, B)\
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
+  TYPE_SWITCH_CASE(PT_FnPtr, B)\
 }  \
   } while (0)
 #define COMPOSITE_TYPE_SWITCH(Expr, B, D)  \
Index: clang/lib/AST/Interp/PrimType.cpp
===
--- clang/lib/AST/Interp/PrimType.cpp
+++ clang/lib/AST/Interp/PrimType.cpp
@@ -9,6 +9,7 @@
 #include "PrimType.h"
 #include "Boolean.h"
 #include "Floating.h"
+#include "FunctionPointer.h"
 #include "Pointer.h"
 
 using namespace clang;
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -27,6 +27,7 @@
 def Uint64 : Type;
 def Float : Type;
 def Ptr : Type;
+def FnPtr : Type;
 
 //===--===//
 // Types transferred to the interpreter.
@@ -77,7 +78,7 @@
 }
 
 def PtrTypeClass : TypeClass {
-  let Types = [Ptr];
+  let Types = [Ptr, FnPtr];
 }
 
 def BoolTypeClass : TypeClass {
@@ -187,6 +188,12 @@
   let ChangesPC = 1;
 }
 
+def CallPtr : Opcode {
+  let Args = [];
+  let Types = [];
+  let ChangesPC = 1;
+}
+
 //===--===//
 // Frame management
 //===--

[PATCH] D146376: Update static_assert message for redundant cases

2023-03-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16718
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != 
BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();

This line is over 80 colums now, remember to format it: 
https://llvm.org/docs/Contributing.html#format-patches


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

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


[clang] 3930e33 - [clang][Interp] Add missing static_assert messages

2023-03-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-03-30T15:43:43+02:00
New Revision: 3930e3331e7173bbacb7181015d8f7ca93f4aaef

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

LOG: [clang][Interp] Add missing static_assert messages

This broke builders, e.g.
https://lab.llvm.org/buildbot/#builders/139/builds/38250

Added: 


Modified: 
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 48862d399722..9c0d51686581 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -150,7 +150,7 @@ namespace FunctionReturnType {
 
 return m;
   }
-  static_assert(foo() == 10);
+  static_assert(foo() == 10, "");
 
   struct S {
 int i;
@@ -158,7 +158,7 @@ namespace FunctionReturnType {
   };
 
   constexpr S s{ 12 };
-  static_assert(s.fp == nullptr); // zero-initialized function pointer.
+  static_assert(s.fp == nullptr, ""); // zero-initialized function pointer.
 }
 
 }



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


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaCXX/static-assert.cpp:266-268
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error 
{{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error 
{{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error 
{{failed}}

We really need to see more of the diagnostic to know whether the behavior is 
reasonable or not.

I was thinking we'd have given a note as to why the failure occurred, but I see 
now that the current behavior doesn't give a note either. Not that I think this 
is related to your patch, but the current behavior seems a bit surprising: 
https://godbolt.org/z/erPGdsanK  Note how the last diagnostic points to exactly 
where the failure comes from but the first two use the entire expression as the 
failure.



Comment at: 
llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn:26
 "//clang/lib/Serialization",
+"//clang/lib/Testing",
 "//clang/lib/Tooling",

This seems like an unrelated change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

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


[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-03-30 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this! The changes should also come with a release note 
in `clang/docs/ReleaseNotes.rst` to note the improvement.




Comment at: clang/lib/AST/ExprConstant.cpp:2357-2361
+if (SubobjectDecl) {
+  Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << 
SubobjectDecl;
+  Info.Note(SubobjectDecl->getLocation(),
+diag::note_constexpr_subobject_declared_here);
+}

Hmm, this breaks one of the contracts of our constexpr evaluation engine, 
doesn't it? My understanding is that if constexpr evaluation fails, we will 
have emitted a note diagnostic for why it failed. But if the caller doesn't 
pass a nonnull `SubobjectDecl`, we'll return `false` but we won't issue a 
diagnostic.

I'm surprised no tests lost notes as a result of this change, that suggests 
we're missing test coverage for the cases where nullptr is passed in explicitly 
to this function.


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

https://reviews.llvm.org/D146358

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


[PATCH] D147234: [clang][ExtractAPI] Reland ExtractAPI for libclang improvements

2023-03-30 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added reviewers: hctim, zixuw.
Herald added subscribers: ChuanqiXu, arphaman.
Herald added a reviewer: ributzka.
Herald added a project: All.
dang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This relands the changes that were originally introduced by:

- https://reviews.llvm.org/D146656
- https://reviews.llvm.org/D147138

This also fixes the leak that led to these changes being reverted


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147234

Files:
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/TypedefUnderlyingTypeResolver.h
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h
  clang/test/Index/extract-api-cursor.m
  clang/test/Index/extract-api-usr.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CXExtractAPI.cpp

Index: clang/tools/libclang/CXExtractAPI.cpp
===
--- clang/tools/libclang/CXExtractAPI.cpp
+++ clang/tools/libclang/CXExtractAPI.cpp
@@ -18,6 +18,7 @@
 #include "clang-c/Index.h"
 #include "clang-c/Platform.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/ExtractAPIVisitor.h"
@@ -34,13 +35,73 @@
 using namespace clang;
 using namespace clang::extractapi;
 
+namespace {
+struct LibClangExtractAPIVisitor
+: ExtractAPIVisitor {
+  using Base = ExtractAPIVisitor;
+
+  LibClangExtractAPIVisitor(ASTContext &Context, APISet &API)
+  : ExtractAPIVisitor(Context, API) {}
+
+  const RawComment *fetchRawCommentForDecl(const Decl *D) const {
+return Context.getRawCommentForAnyRedecl(D);
+  }
+
+  // We need to visit implementations as well to ensure that when a user clicks
+  // on a method defined only within the implementation that we can still
+  // provide a symbol graph for it.
+  bool VisitObjCImplementationDecl(const ObjCImplementationDecl *Decl) {
+if (!shouldDeclBeIncluded(Decl))
+  return true;
+
+const ObjCInterfaceDecl *Interface = Decl->getClassInterface();
+StringRef Name = Interface->getName();
+StringRef USR = API.recordUSR(Decl);
+PresumedLoc Loc =
+Context.getSourceManager().getPresumedLoc(Decl->getLocation());
+LinkageInfo Linkage = Decl->getLinkageAndVisibility();
+DocComment Comment;
+if (auto *RawComment = fetchRawCommentForDecl(Interface))
+  Comment = RawComment->getFormattedLines(Context.getSourceManager(),
+  Context.getDiagnostics());
+
+// Build declaration fragments and sub-heading by generating them for the
+// interface.
+DeclarationFragments Declaration =
+DeclarationFragmentsBuilder::getFragmentsForObjCInterface(Interface);
+DeclarationFragments SubHeading =
+DeclarationFragmentsBuilder::getSubHeading(Decl);
+
+// Collect super class information.
+SymbolReference SuperClass;
+if (const auto *SuperClassDecl = Decl->getSuperClass()) {
+  SuperClass.Name = SuperClassDecl->getObjCRuntimeNameAsString();
+  SuperClass.USR = API.recordUSR(SuperClassDecl);
+}
+
+ObjCInterfaceRecord *ObjCInterfaceRecord = API.addObjCInterface(
+Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment, Declaration,
+SubHeading, SuperClass, isInSystemHeader(Decl));
+
+// Record all methods (selectors). This doesn't include automatically
+// synthesized property methods.
+recordObjCMethods(ObjCInterfaceRecord, Decl->methods());
+recordObjCProperties(ObjCInterfaceRecord, Decl->properties());
+recordObjCInstanceVariables(ObjCInterfaceRecord, Decl->ivars());
+
+return true;
+  }
+};
+} // namespace
+
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(APISet, CXAPISet)
 
-static void WalkupFromMostDerivedType(ExtractAPIVisitor &Visitor, Decl *D);
+static void WalkupFromMostDerivedType(LibClangExtractAPIVisitor &Visitor,
+  Decl *D);
 
 template 
 static bool WalkupParentContext(DeclContext *Parent,
-ExtractAPIVisitor &Visitor) {
+LibClangExtractAPIVisitor &Visitor) {
   if (auto *D = dyn_cast(Parent)) {
 WalkupFromMostDerivedType(Visitor, D);
 return true;
@@ -48,7 +109,8 @@
   return false;
 }
 
-static void WalkupFromMostDerivedType(ExtractAPIVisitor &Visitor, Decl *D) {
+static void WalkupFromMostDerivedType(LibClangExtractAPIVisitor &Visitor,
+  Decl *D) {
   switch (D->getKind()) {
 #define ABSTRACT_DECL(DECL)
 #define DECL(CLASS, BASE)

[PATCH] D146101: [clang-format] Add DesignatedInitializerIndentWidth option.

2023-03-30 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

So at the risk of adding to the number of decisions we need to come to a 
consensus on, I was about to update the KJ style guide to explicitly call out 
the difference in indentation for designated initializers when I realized that 
we (both KJ code authors and clang-format contributors) should consider whether 
users should have the option to configure other similar types of indentation 
following opening braces.

I chatted to the owner of the KJ style guide and, whilst he did not have 
extremely strong opinions one way or another, he and I agreed that it probably 
makes more sense for such a config option to apply to other types of braced 
init lists.

Broadly speaking, these include aggregate initialization and list 
initialization (possibly direct initialization with braces too). See the 
initialization  
cppref article for links to all these.

As such, I would propose to actually rename `DesignatedInitializerIndentWidth` 
to `BracedInitializerIndentWidth` (but open to suggestiosn on exact naming) and 
have it apply to all the above types of initialization.

What does everyone think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D147234: [clang][ExtractAPI] Reland ExtractAPI for libclang improvements

2023-03-30 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/tools/c-index-test/c-index-test.c:4898
+
+  clang_disposeString(SGFData);
+}

The previous version didn't free the string here which was the source of the 
leak @hctim 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147234

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


[PATCH] D137327: [clang-format] Handle object instansiation in if-statements

2023-03-30 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

In D137327#4233290 , @MyDeveloperDay 
wrote:

> because of https://github.com/llvm/llvm-project/issues/61785 should this 
> really be reverted?  is basically saying `X * Y {`  must be `X *Y{`  but that 
> obviously not the case

Tricky one. Any ideas on how we could differentiate those two cases? Maybe 
impossible? Not sure what the normal way to handle ambiguous things like that 
in clang-format is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137327

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


[clang] abf4a8c - [Clang] Improve diagnostics when using a concept as template argument

2023-03-30 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-03-30T16:30:23+02:00
New Revision: abf4a8cb15d4faf04ee0da14e37d7349d3bde9a1

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

LOG: [Clang] Improve diagnostics when using a concept as template argument

When using the name of a template variable or concept in places
where an expression was expected, Clang would drop the cxxscope token
preceeding it, if any.

This leads to subpar diagnostics - complaining about the
identifier being undeclared as clang would not know to look into a
non-global scope.

We make sure the scope is preserved.

When encountering `ns::Concept foo x;`, Clang would also fail
to provide the same quality as it does at global scope.

Reviewed By: aaron.ballman, erichkeane

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

Added: 
clang/test/Parser/cxx-template-template-recovery.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/Parser.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44ffca26f26a2..fdbe640f704f8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -253,6 +253,8 @@ Bug Fixes in This Version
   to limit non-defined/non-member functions as well. Additionally, we now 
diagnose
   requires on lambdas when not allowed, which we previously missed.
   (`#61748 `_)
+- Fix confusing diagnostic for incorrect use of qualified concepts names.
+
 
 Bug Fixes to Compiler Builtins
 ^^
@@ -300,7 +302,7 @@ AMDGPU Support
   undefined symbols in the created module to be a linker error. To prevent 
this,
   pass ``-Wl,--undefined`` if compiling directly, or ``-Xoffload-linker
   --undefined`` if using an offloading language.
-- The deprecated ``-mcode-object-v3`` and ``-mno-code-object-v3`` command-line 
+- The deprecated ``-mcode-object-v3`` and ``-mno-code-object-v3`` command-line
   options have been removed.
 
 X86 Support

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 2b5829ba0ef0e..91376cf6a34e4 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3448,12 +3448,12 @@ void Parser::ParseDeclarationSpecifiers(
 continue;
   }
 
-  if (TemplateId && TemplateId->Kind == TNK_Concept_template &&
-  GetLookAheadToken(2).isOneOf(tok::kw_auto, tok::kw_decltype)) {
+  if (TemplateId && TemplateId->Kind == TNK_Concept_template) {
 DS.getTypeSpecScope() = SS;
-// This is a qualified placeholder-specifier, e.g., ::C auto ...
-// Consume the scope annotation and continue to consume the template-id
-// as a placeholder-specifier.
+// This is probably a qualified placeholder-specifier, e.g., ::C
+// auto ... Consume the scope annotation and continue to consume the
+// template-id as a placeholder-specifier. Let the next iteration
+// diagnose a missing auto.
 ConsumeAnnotationToken();
 continue;
   }

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index e6b1d3fdf70bf..c0f4556d743b2 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1883,31 +1883,25 @@ Parser::TryAnnotateName(CorrectionCandidateCallback 
*CCC,
   return ANK_TemplateName;
 }
 [[fallthrough]];
+  case Sema::NC_Concept:
   case Sema::NC_VarTemplate:
   case Sema::NC_FunctionTemplate:
   case Sema::NC_UndeclaredTemplate: {
-// We have a type, variable or function template followed by '<'.
-ConsumeToken();
-UnqualifiedId Id;
-Id.setIdentifier(Name, NameLoc);
-if (AnnotateTemplateIdToken(
-TemplateTy::make(Classification.getTemplateName()),
-Classification.getTemplateNameKind(), SS, SourceLocation(), Id))
-  return ANK_Error;
-return ANK_Success;
-  }
-  case Sema::NC_Concept: {
-UnqualifiedId Id;
-Id.setIdentifier(Name, NameLoc);
+bool IsConceptName = Classification.getKind() == Sema::NC_Concept;
+// We have a template name followed by '<'. Consume the identifier token so
+// we reach the '<' and annotate it.
 if (Next.is(tok::less))
-  // We have a concept name followed by '<'. Consume the identifier token 
so
-  // we reach the '<' and annotate it.
   ConsumeToken();
+UnqualifiedId Id;
+Id.setIdentifier(Name, NameLoc);
 if (AnnotateTemplateIdToken(
 TemplateTy::make(Classification.getTemplateName()),
 Classification.getTemplateNameKind(), SS, SourceLocation(), Id,
-/*AllowTypeAnnotation=*/false, /*TypeConstraint=*/true))
+/*AllowTypeAnnotation=*/!IsConceptName,
+/*TypeConstraint=*/IsCo

[PATCH] D146719: [Clang] Improve diagnostics when using a concept as template argument

2023-03-30 Thread Corentin Jabot 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 rGabf4a8cb15d4: [Clang] Improve diagnostics when using a 
concept as template argument (authored by cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D146719?vs=508299&id=509675#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146719

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx-template-template-recovery.cpp

Index: clang/test/Parser/cxx-template-template-recovery.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-template-template-recovery.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only %s
+
+namespace a {
+  template 
+  concept C1 = true; // #C1
+
+  template 
+  auto V1 = true; // #V1
+
+  namespace b {
+template 
+concept C2 = true; // #C2
+template 
+auto V2 = true; // #V2
+  }
+}
+
+template 
+concept C3 = true; // #C3
+template 
+auto V3 = true; // #V3
+template  typename C>
+constexpr bool test = true;
+
+static_assert(test); // expected-error {{too few template arguments for concept 'C1'}} \
+// expected-note@#C1 {{here}}
+static_assert(test); // expected-error {{too few template arguments for concept 'C2'}} \
+   // expected-note@#C2 {{here}}
+static_assert(test); // expected-error {{too few template arguments for concept 'C3'}} \
+ // expected-note@#C3 {{here}}
+
+static_assert(test); // expected-error {{use of variable template 'V1' requires template arguments}} \
+// expected-note@#V1 {{here}}
+static_assert(test); // expected-error {{use of variable template 'V2' requires template arguments}} \
+// expected-note@#V2 {{here}}
+static_assert(test); // expected-error {{use of variable template 'V3' requires template arguments}} \
+ // expected-note@#V3 {{here}}
+
+
+void f() {
+C3 t1 = 0;  // expected-error {{expected 'auto' or 'decltype(auto)' after concept name}}
+a::C1 t2 = 0; // expected-error {{expected 'auto' or 'decltype(auto)' after concept name}}
+a::b::C2 t3 = 0; // expected-error {{expected 'auto' or 'decltype(auto)' after concept name}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -1883,31 +1883,25 @@
   return ANK_TemplateName;
 }
 [[fallthrough]];
+  case Sema::NC_Concept:
   case Sema::NC_VarTemplate:
   case Sema::NC_FunctionTemplate:
   case Sema::NC_UndeclaredTemplate: {
-// We have a type, variable or function template followed by '<'.
-ConsumeToken();
-UnqualifiedId Id;
-Id.setIdentifier(Name, NameLoc);
-if (AnnotateTemplateIdToken(
-TemplateTy::make(Classification.getTemplateName()),
-Classification.getTemplateNameKind(), SS, SourceLocation(), Id))
-  return ANK_Error;
-return ANK_Success;
-  }
-  case Sema::NC_Concept: {
-UnqualifiedId Id;
-Id.setIdentifier(Name, NameLoc);
+bool IsConceptName = Classification.getKind() == Sema::NC_Concept;
+// We have a template name followed by '<'. Consume the identifier token so
+// we reach the '<' and annotate it.
 if (Next.is(tok::less))
-  // We have a concept name followed by '<'. Consume the identifier token so
-  // we reach the '<' and annotate it.
   ConsumeToken();
+UnqualifiedId Id;
+Id.setIdentifier(Name, NameLoc);
 if (AnnotateTemplateIdToken(
 TemplateTy::make(Classification.getTemplateName()),
 Classification.getTemplateNameKind(), SS, SourceLocation(), Id,
-/*AllowTypeAnnotation=*/false, /*TypeConstraint=*/true))
+/*AllowTypeAnnotation=*/!IsConceptName,
+/*TypeConstraint=*/IsConceptName))
   return ANK_Error;
+if (SS.isNotEmpty())
+  AnnotateScopeToken(SS, !WasScopeAnnotation);
 return ANK_Success;
   }
   }
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3448,12 +3448,12 @@
 continue;
   }
 
-  if (TemplateId && TemplateId->Kind == TNK_Concept_template &&
-  GetLookAheadToken(2).isOneOf(tok::kw_auto, tok::kw_decltype)) {
+  if (TemplateId && TemplateId->Kind == TNK_Concept_template) {
 DS.getTypeSpecScope() = SS;
-// This is a qualified placeholder-specifier, e.g., ::C auto ...
-// Consume the scope annotation and continue to consume the template-id
-// as a placeholder-specifier.
+// This is probably a qualified placeholder-spec

[PATCH] D143099: [clang][lex] Expose findBeginningOfLine()

2023-03-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@KyleFromKitware oups, this fell under the cracks. I think I'm happy with is 
as-is, do you need help landing it?


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

https://reviews.llvm.org/D143099

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


[PATCH] D146922: [clang-tidy] Fix false positve for defaulted move constructor in performance-noexcept-move-constructor

2023-03-30 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:260
 
+- Fixed an issue in :doc:`performance-noexcept-move-constructor
+  ` which resulted in 
false

Please keep alphabetical order (by check name) in this section.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146922

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


[PATCH] D143099: [clang][lex] Expose findBeginningOfLine()

2023-03-30 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware added a comment.

In D143099#4233623 , @cor3ntin wrote:

> @KyleFromKitware oups, this fell under the cracks. I think I'm happy with is 
> as-is, do you need help landing it?

Yes, please.


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

https://reviews.llvm.org/D143099

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


[PATCH] D143099: [clang][lex] Expose findBeginningOfLine()

2023-03-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D143099#4233633 , @KyleFromKitware 
wrote:

> In D143099#4233623 , @cor3ntin 
> wrote:
>
>> @KyleFromKitware oups, this fell under the cracks. I think I'm happy with is 
>> as-is, do you need help landing it?
>
> Yes, please.

Sure.  Let me know what name and email address you would like used for the 
patch attribution! Thanks


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

https://reviews.llvm.org/D143099

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


[PATCH] D137327: [clang-format] Handle object instansiation in if-statements

2023-03-30 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D137327#4233551 , @thieta wrote:

> In D137327#4233290 , 
> @MyDeveloperDay wrote:
>
>> because of https://github.com/llvm/llvm-project/issues/61785 should this 
>> really be reverted?  is basically saying `X * Y {`  must be `X *Y{`  but 
>> that obviously not the case
>
> Tricky one. Any ideas on how we could differentiate those two cases? Maybe 
> impossible? Not sure what the normal way to handle ambiguous things like that 
> in clang-format is.

I would prefer we avoid the regression that this issue caused, even if both are 
equally viable. because otherwise we get blamed for "changing defaults" 
@owenpan, @HazardyKnusperkeks what are your thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137327

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


[PATCH] D143099: [clang][lex] Expose findBeginningOfLine()

2023-03-30 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware added a comment.

In D143099#4233651 , @cor3ntin wrote:

> Sure.  Let me know what name and email address you would like used for the 
> patch attribution! Thanks

Kyle Edwards 

Is there some way I can set this in my profile settings so that this name and 
address is always used?


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

https://reviews.llvm.org/D143099

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


[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-03-30 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

@aaron.ballman 
Thanks for the review! I'll add a release note.




Comment at: clang/lib/AST/ExprConstant.cpp:2357-2361
+if (SubobjectDecl) {
+  Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << 
SubobjectDecl;
+  Info.Note(SubobjectDecl->getLocation(),
+diag::note_constexpr_subobject_declared_here);
+}

aaron.ballman wrote:
> Hmm, this breaks one of the contracts of our constexpr evaluation engine, 
> doesn't it? My understanding is that if constexpr evaluation fails, we will 
> have emitted a note diagnostic for why it failed. But if the caller doesn't 
> pass a nonnull `SubobjectDecl`, we'll return `false` but we won't issue a 
> diagnostic.
> 
> I'm surprised no tests lost notes as a result of this change, that suggests 
> we're missing test coverage for the cases where nullptr is passed in 
> explicitly to this function.
Yeah, I was looking into when `SubobjectDecl` can be null here. I `assert`ed 
the non-nullness of `SubobjectDecl` before and found that there exists two 
lines of code 
(https://github.com/llvm/llvm-project/blob/22a3f974d35da89247c0396594f2e4cd592742eb/clang/test/SemaCXX/attr-weak.cpp#L49
 and 
https://github.com/llvm/llvm-project/blob/abf4a8cb15d4faf04ee0da14e37d7349d3bde9a1/clang/test/CodeGenCXX/weak-external.cpp#L97)
 in the test codes that nulls here.
It seems they are doing the same thing, doing comparison against a pointer to a 
`[[gnu::weak]]` member. A simple reproducing code is here: 
https://godbolt.org/z/qn997n85n
As you can see from the compiler explorer, there's no note emitted here before 
the patch.
I inserted some `printf` into the code before this patch  and confirmed 
`Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << true << Type` was 
actually called when compiling the reproducing code and that somehow it is 
ignored. FWIW, `SubobjectLoc.isValid()` was `false` here.


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

https://reviews.llvm.org/D146358

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


[clang] cc8237d - [documentation] Fix some typos

2023-03-30 Thread Samuel Tebbs via cfe-commits

Author: Ayushi Shukla
Date: 2023-03-30T15:58:02+01:00
New Revision: cc8237d9d727b864fe65d2c9d620f3332f4235ca

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

LOG: [documentation] Fix some typos

This patch fixes https://github.com/llvm/llvm-project/issues/56747

Patch-By: ayushi-8102

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

Added: 


Modified: 
clang/docs/AutomaticReferenceCounting.rst
clang/docs/ConstantInterpreter.rst
clang/docs/CrossCompilation.rst
clang/docs/DataFlowAnalysisIntro.md
clang/docs/DebuggingCoroutines.rst
clang/docs/analyzer/developer-docs/nullability.rst
clang/include/clang/AST/CXXInheritance.h
clang/include/clang/AST/CommentSema.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/AST/DeclarationName.h
clang/include/clang/AST/Expr.h
clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
clang/include/clang/Analysis/Analyses/Consumed.h

Removed: 




diff  --git a/clang/docs/AutomaticReferenceCounting.rst 
b/clang/docs/AutomaticReferenceCounting.rst
index 5e40fa837b1aa..640f3f7dec390 100644
--- a/clang/docs/AutomaticReferenceCounting.rst
+++ b/clang/docs/AutomaticReferenceCounting.rst
@@ -635,7 +635,7 @@ retain-agnostic, the conversion is treated as a 
``__bridge`` cast.
 
   For loads from ``const`` global variables of :ref:`C retainable pointer type
   `, it is reasonable to assume that global system
-  constants were initialitzed with true constants (e.g. string literals), but
+  constants were initialized with true constants (e.g. string literals), but
   user constants might have been initialized with something dynamically
   allocated, using a global initializer.
 

diff  --git a/clang/docs/ConstantInterpreter.rst 
b/clang/docs/ConstantInterpreter.rst
index eba637585b8f0..0c5b09c73ee30 100644
--- a/clang/docs/ConstantInterpreter.rst
+++ b/clang/docs/ConstantInterpreter.rst
@@ -81,7 +81,7 @@ Primitive Types
 
 * ``PT_VoidPtr``
 
-  Void pointer type, can be used for rount-trip casts. Represented as
+  Void pointer type, can be used for round-trip casts. Represented as
   the union of all pointers which can be cast to void.
   Defined in ``"VoidPointer.h"``.
 

diff  --git a/clang/docs/CrossCompilation.rst b/clang/docs/CrossCompilation.rst
index 3578eb3e4db01..48f0f72477544 100644
--- a/clang/docs/CrossCompilation.rst
+++ b/clang/docs/CrossCompilation.rst
@@ -97,7 +97,7 @@ choose ``unknown`` and the defaults will be used. If you 
choose a parameter
 that Clang doesn't know, like ``blerg``, it'll ignore and assume
 ``unknown``, which is not always desired, so be careful.
 
-Finally, the env (enviornment) option is something that will pick default
+Finally, the env (environment) option is something that will pick default
 CPU/FPU, define the specific behaviour of your code (PCS, extensions),
 and also choose the correct library calls, etc.
 

diff  --git a/clang/docs/DataFlowAnalysisIntro.md 
b/clang/docs/DataFlowAnalysisIntro.md
index 8bfecd24906cb..67faae0cd9e72 100644
--- a/clang/docs/DataFlowAnalysisIntro.md
+++ b/clang/docs/DataFlowAnalysisIntro.md
@@ -219,7 +219,7 @@ the function:
 this fact as `⊤`.
 
 *   When two control flow paths join, we compute the set union of incoming
-values (limiting the number of elements to 3, representig larger sets as
+values (limiting the number of elements to 3, representing larger sets as
 `⊤`).
 
 The sets of possible values are influenced by:
@@ -332,7 +332,7 @@ void PrintAbs(int x) {
 We can't say what specific value gets printed, but we know that it is either 
`x`
 or `-x`.
 
-Dataflow analysis is an istance of abstract interpretation, and does not 
dictate
+Dataflow analysis is an instance of abstract interpretation, and does not 
dictate
 how exactly the lattice and transfer functions should be designed, beyond the
 necessary conditions for the analysis to converge. Nevertheless, we can use
 symbolic execution ideas to guide our design of the lattice and transfer
@@ -634,7 +634,7 @@ void Uninit() {
 
 For this purpose we can use lattice in a form of a mapping from variable
 declarations to initialization states; each initialization state is represented
-by the followingn lattice:
+by the following lattice:
 
 ![Lattice for definitive initialization 
analysis](DataFlowAnalysisIntroImages/DefinitiveInitializationLattice.svg)
 

diff  --git a/clang/docs/DebuggingCoroutines.rst 
b/clang/docs/DebuggingCoroutines.rst
index ae5359117775b..591d2eadabe53 100644
--- a/clang/docs/DebuggingCoroutines.rst
+++ b/clang/docs/DebuggingCoroutines.rst
@@ -620,7 +620,7 @@ Then let's run:
 
   $ clang++ -std=c++20 -g debugging-example.cpp -o debugging-example
   $ gdb ./de

[PATCH] D146892: [documentation] Fix some typos

2023-03-30 Thread Sam Tebbs via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc8237d9d727: [documentation] Fix some typos (authored by 
ayushi-8102, committed by samtebbs).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146892

Files:
  clang/docs/AutomaticReferenceCounting.rst
  clang/docs/ConstantInterpreter.rst
  clang/docs/CrossCompilation.rst
  clang/docs/DataFlowAnalysisIntro.md
  clang/docs/DebuggingCoroutines.rst
  clang/docs/analyzer/developer-docs/nullability.rst
  clang/include/clang/AST/CXXInheritance.h
  clang/include/clang/AST/CommentSema.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
  clang/include/clang/Analysis/Analyses/Consumed.h

Index: clang/include/clang/Analysis/Analyses/Consumed.h
===
--- clang/include/clang/Analysis/Analyses/Consumed.h
+++ clang/include/clang/Analysis/Analyses/Consumed.h
@@ -258,7 +258,7 @@
 /// Check a function's CFG for consumed violations.
 ///
 /// We traverse the blocks in the CFG, keeping track of the state of each
-/// value who's type has uniquness annotations.  If methods are invoked in
+/// value who's type has uniqueness annotations.  If methods are invoked in
 /// the wrong state a warning is issued.  Each block in the CFG is traversed
 /// exactly once.
 void run(AnalysisDeclContext &AC);
Index: clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
===
--- clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
+++ clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
@@ -28,7 +28,7 @@
 /// \enum IfThen -- then branch of the if statement has no call.
 /// \enum IfElse -- else branch of the if statement has no call.
 /// \enum Switch -- one of the switch cases doesn't have a call.
-/// \enum SwitchSkipped -- there is no call if none of the cases appies.
+/// \enum SwitchSkipped -- there is no call if none of the cases applies.
 /// \enum LoopEntered -- no call when the loop is entered.
 /// \enum LoopSkipped -- no call when the loop is not entered.
 /// \enum FallbackReason -- fallback case when we were not able to figure out
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -135,8 +135,8 @@
   void setDependence(ExprDependence Deps) {
 ExprBits.Dependent = static_cast(Deps);
   }
-  friend class ASTImporter; // Sets dependence dircetly.
-  friend class ASTStmtReader; // Sets dependence dircetly.
+  friend class ASTImporter;   // Sets dependence directly.
+  friend class ASTStmtReader; // Sets dependence directly.
 
 public:
   QualType getType() const { return TR; }
@@ -171,7 +171,7 @@
   }
 
   /// Determines whether the type of this expression depends on
-  ///   - a template paramter (C++ [temp.dep.expr], which means that its type
+  ///   - a template parameter (C++ [temp.dep.expr], which means that its type
   /// could change from one template instantiation to the next)
   ///   - or an error
   ///
@@ -820,7 +820,7 @@
   /// member expression.
   static QualType findBoundMemberType(const Expr *expr);
 
-  /// Skip past any invisble AST nodes which might surround this
+  /// Skip past any invisible AST nodes which might surround this
   /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes,
   /// but also injected CXXMemberExpr and CXXConstructExpr which represent
   /// implicit conversions.
@@ -924,7 +924,7 @@
 return const_cast(this)->IgnoreParenLValueCasts();
   }
 
-  /// Skip past any parenthese and casts which do not change the value
+  /// Skip past any parentheses and casts which do not change the value
   /// (including ptr->int casts of the same size) until reaching a fixed point.
   /// Skips:
   /// * What IgnoreParens() skips
@@ -2815,7 +2815,7 @@
   /// The number of arguments in the call expression.
   unsigned NumArgs;
 
-  /// The location of the right parenthese. This has a different meaning for
+  /// The location of the right parentheses. This has a different meaning for
   /// the derived classes of CallExpr.
   SourceLocation RParenLoc;
 
Index: clang/include/clang/AST/DeclarationName.h
===
--- clang/include/clang/AST/DeclarationName.h
+++ clang/include/clang/AST/DeclarationName.h
@@ -763,7 +763,7 @@
 };
 
 /// DeclarationNameInfo - A collector data type for bundling together
-/// a DeclarationName and the correspnding source/type location info.
+/// a DeclarationName and the corresponding source/type location info.
 struct DeclarationNameInfo {
 priva

[PATCH] D137740: [clang-tidy][NFC] Fix namespace comments in AvoidThrowingObjCExceptionCheck.cpp 🧹

2023-03-30 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore abandoned this revision.
stephanemoore added a comment.

Abandoned this revision and folded the changes into another revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137740

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


[PATCH] D143967: [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF

2023-03-30 Thread Eduard Zingerman via Phabricator via cfe-commits
eddyz87 added a comment.

In D143967#4233414 , @jemarch wrote:

>> If some tooling applies such tags movement it should also apply
>> appropriate copying of tags, e.g. it should transform DWARF like this:
>>
>>   var1 -> const -> typedef (bar) -> int
>>  |
>>   __tag1
>>   
>>   var2 --> typedef (bar) -> int
>>
>> (and it is what needs to be implemented in pahole to get BTF
>> qualifiers ordering expected by kernel, but the move is in the
>> opposite direction).
>
> So the kernel expects tags to precede typedefs as well as qualifiers?
> i.e. given this DWARF:
>
>   var1 -> const -> typedef (bar) -> int
>^ |
>|   __tag1
>|
>   var2 +
>
> We have to transform to these two BTF type chains:
>
>   var1 -> __tag1 -> const -> typedef (bar) -> int
>   ^
>   |
>   var2 -> __tag1 -+
>
> Correct?

This is controlled by the following code (btf.c:btf_check_type_tags()):

https://elixir.bootlin.com/linux/latest/source/kernel/bpf/btf.c#L5349

It uses `btf_type_is_modifier()` utility function, which treats typedef as a 
modifier.

So, in theory the transformation moving tags past typedef is necessary. On the 
other hand, such transformation is not applied now, and this does not cause 
issues. Which suggests that there are no cases in practice where type tag 
follows typedef (and thus, this is not required for backwards compatibility).

Moving type tags cross typedef feels wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143967

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


[PATCH] D145264: [OpenMP][MLIR][Flang][Driver][bbc] Lower and apply Module FlagsAttr

2023-03-30 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added inline comments.



Comment at: flang/tools/bbc/CMakeLists.txt:29
 FortranLower
+flangFrontendTool
 )

agozillon wrote:
> awarzynski wrote:
> > This a frontend driver library and so far `bbc` and `flang-new -fc1` have 
> > been entirely separate. Could this dependency be avoided?
> I had hoped to share LangOpts so that the setOffloadModuleInterfaceAttributes 
> function wouldn't turn into a monolithic set of arguments whenever it's 
> invoked if more arguments are added, but the dependency isn't ideal I agree!
> 
> I could perhaps look into making some sort of shared data structure to be put 
> inside of CrossToolHelpers that might remove the dependency and be similarly 
> useable to how LangOpts works at the moment. If that doesn't work, I can 
> revert the change to just be a regular argument list and we can revisit the 
> topic if new options are ever added? 
Although looking at @domada's https://reviews.llvm.org/D146612 patch it reminds 
me that they could just be separate functions shared across tools (I perhaps 
got a little fixated on the idea of it being similar to a driver function 
handling all the options). Please do tell me whichever you'd prefer :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145264

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


[PATCH] D143967: [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF

2023-03-30 Thread Eduard Zingerman via Phabricator via cfe-commits
eddyz87 added a comment.

Moving type tags past typedefs would also make C code reconstruction from BTF 
incomplete. Such reconstruction is used now by e.g. bpftool to create a 
vmlinux.h header with all kernel type definitions. So, I think type tags should 
not be moved past typedefs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143967

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


[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-03-30 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 509686.
hazohelet added a comment.

Added release note


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

https://reviews.llvm.org/D146358

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -761,7 +761,7 @@
 };
 
 S s1; // expected-error {{call to consteval function 'NamespaceScopeConsteval::S::S' is not a constant expression}} \
- expected-note {{subobject of type 'int' is not initialized}}
+ expected-note {{subobject 'Val' is not initialized}}
 
 template 
 struct T {
@@ -770,7 +770,7 @@
 };
 
 T t; // expected-error {{call to consteval function 'NamespaceScopeConsteval::T::T' is not a constant expression}} \
- expected-note {{subobject of type 'int' is not initialized}}
+ expected-note {{subobject 'Val' is not initialized}}
 
 } // namespace NamespaceScopeConsteval
 
Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -409,12 +409,12 @@
 b.a.x = 2;
 return b;
   }
-  constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject 'y' is not initialized}}
   static_assert(return_uninit().a.x == 2);
   constexpr A return_uninit_struct() {
 B b = {.b = 1};
 b.a.x = 2;
-return b.a; // expected-note {{in call to 'A(b.a)'}} expected-note {{subobject of type 'int' is not initialized}}
+return b.a; // expected-note {{in call to 'A(b.a)'}} expected-note {{subobject 'y' is not initialized}}
   }
   // Note that this is rejected even though return_uninit() is accepted, and
   // return_uninit() copies the same stuff wrapped in a union.
@@ -558,7 +558,7 @@
 }
   };
   constinit X x1(true);
-  constinit X x2(false); // expected-error {{constant initializer}} expected-note {{constinit}} expected-note {{subobject of type 'int' is not initialized}}
+  constinit X x2(false); // expected-error {{constant initializer}} expected-note {{constinit}} expected-note {{subobject 'n' is not initialized}}
 
   struct Y {
 struct Z { int n; }; // expected-note {{here}}
@@ -577,7 +577,7 @@
   };
   // FIXME: This is working around clang not implementing DR2026. With that
   // fixed, we should be able to test this without the injected copy.
-  constexpr Y copy(Y y) { return y; } // expected-note {{in call to 'Y(y)'}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr Y copy(Y y) { return y; } // expected-note {{in call to 'Y(y)'}} expected-note {{subobject 'n' is not initialized}}
   constexpr Y y1 = copy(Y());
   static_assert(y1.z1.n == 1 && y1.z2.n == 2 && y1.z3.n == 3);
 
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
@@ -359,7 +359,7 @@
   // The constructor is still 'constexpr' here, but the result is not intended
   // to be a constant expression. The standard is not clear on how this should
   // work.
-  constexpr V v; // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr V v; // expected-error {{constant expression}} expected-note {{subobject 'y' is not initialized}}
 
   constexpr int k = V().x; // FIXME: ok?
 }
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -143,9 +143,9 @@
 constexpr A() {}
   };
   constexpr A a; // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{subobject of type 'int' is not initialized}} \
+ // expected-note {{subobject 'a' is not initialized}} \
  // ref-error {{must be initialized by a constant expression}} \
- // ref-note {{subobject of type 'int' is not initialized}}
+ // ref-note {{subobject 'a' is not initialized}}
 
 
   class Base {
@@ -161,18 +161,18 @@
 constexpr Derived() : Base() {}   };
 
   constexpr Derived D; // expected-error {{must be initialized by a constant expression}} \
-   

[clang] 43aa293 - [AArch64] Basic target(+crypto) handling

2023-03-30 Thread David Green via cfe-commits

Author: David Green
Date: 2023-03-30T16:46:47+01:00
New Revision: 43aa293aeaf04e8da50c3c53169c0311e0c5

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

LOG: [AArch64] Basic target(+crypto) handling

This adds some basic handling for target(+crypto) attributes. In this patch it
just enabled aes and sha2 regardless of the architecture revision, which
matches gccs implementation (and keeps the patch simple).

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

Added: 
clang/test/CodeGen/aarch64-targetattr-crypto.c

Modified: 
llvm/include/llvm/TargetParser/AArch64TargetParser.h

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-targetattr-crypto.c 
b/clang/test/CodeGen/aarch64-targetattr-crypto.c
new file mode 100644
index 0..d3609240fbd55
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-targetattr-crypto.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +v8a -verify -S %s -o -
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+__attribute__((target("+crypto")))
+void test_crypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("crypto")))
+void test_pluscrypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("arch=armv8.2-a+crypto")))
+void test_archcrypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+// FIXME: This shouldn't need +crypto to be consistent with -mcpu options.
+__attribute__((target("cpu=cortex-a55+crypto")))
+void test_a55crypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("cpu=cortex-a510+crypto")))
+void test_a510crypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("+sha2+aes")))
+void test_sha2aes(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+void test_errors(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key); // expected-error {{always_inline function 'vaeseq_u8' 
requires target feature 'aes'}}
+  vsha1su1q_u32(data, key); // expected-error {{always_inline function 
'vsha1su1q_u32' requires target feature 'sha2'}}
+}

diff  --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 9cba6b4b19599..a6379297a26d7 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -184,7 +184,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"brbe", AArch64::AEK_BRBE, "+brbe", "-brbe", FEAT_MAX, "", 0},
 {"bti", AArch64::AEK_NONE, {}, {}, FEAT_BTI, "+bti", 510},
 {"crc", AArch64::AEK_CRC, "+crc", "-crc", FEAT_CRC, "+crc", 110},
-{"crypto", AArch64::AEK_CRYPTO, "+crypto", "-crypto", FEAT_MAX, "", 0},
+{"crypto", AArch64::AEK_CRYPTO, "+crypto", "-crypto", FEAT_MAX, 
"+aes,+sha2", 0},
 {"cssc", AArch64::AEK_CSSC, "+cssc", "-cssc", FEAT_MAX, "", 0},
 {"d128", AArch64::AEK_D128, "+d128", "-d128", FEAT_MAX, "", 0},
 {"dgh", AArch64::AEK_NONE, {}, {}, FEAT_DGH, "", 260},



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


[PATCH] D142135: [AArch64] Basic target("+crypto") handling

2023-03-30 Thread Dave Green 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 rG43aa293aeaf0: [AArch64] Basic target(+crypto) handling 
(authored by dmgreen).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142135

Files:
  clang/test/CodeGen/aarch64-targetattr-crypto.c
  llvm/include/llvm/TargetParser/AArch64TargetParser.h


Index: llvm/include/llvm/TargetParser/AArch64TargetParser.h
===
--- llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -184,7 +184,7 @@
 {"brbe", AArch64::AEK_BRBE, "+brbe", "-brbe", FEAT_MAX, "", 0},
 {"bti", AArch64::AEK_NONE, {}, {}, FEAT_BTI, "+bti", 510},
 {"crc", AArch64::AEK_CRC, "+crc", "-crc", FEAT_CRC, "+crc", 110},
-{"crypto", AArch64::AEK_CRYPTO, "+crypto", "-crypto", FEAT_MAX, "", 0},
+{"crypto", AArch64::AEK_CRYPTO, "+crypto", "-crypto", FEAT_MAX, 
"+aes,+sha2", 0},
 {"cssc", AArch64::AEK_CSSC, "+cssc", "-cssc", FEAT_MAX, "", 0},
 {"d128", AArch64::AEK_D128, "+d128", "-d128", FEAT_MAX, "", 0},
 {"dgh", AArch64::AEK_NONE, {}, {}, FEAT_DGH, "", 260},
Index: clang/test/CodeGen/aarch64-targetattr-crypto.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-targetattr-crypto.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +v8a -verify -S %s -o -
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+__attribute__((target("+crypto")))
+void test_crypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("crypto")))
+void test_pluscrypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("arch=armv8.2-a+crypto")))
+void test_archcrypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+// FIXME: This shouldn't need +crypto to be consistent with -mcpu options.
+__attribute__((target("cpu=cortex-a55+crypto")))
+void test_a55crypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("cpu=cortex-a510+crypto")))
+void test_a510crypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("+sha2+aes")))
+void test_sha2aes(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+void test_errors(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key); // expected-error {{always_inline function 'vaeseq_u8' 
requires target feature 'aes'}}
+  vsha1su1q_u32(data, key); // expected-error {{always_inline function 
'vsha1su1q_u32' requires target feature 'sha2'}}
+}


Index: llvm/include/llvm/TargetParser/AArch64TargetParser.h
===
--- llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -184,7 +184,7 @@
 {"brbe", AArch64::AEK_BRBE, "+brbe", "-brbe", FEAT_MAX, "", 0},
 {"bti", AArch64::AEK_NONE, {}, {}, FEAT_BTI, "+bti", 510},
 {"crc", AArch64::AEK_CRC, "+crc", "-crc", FEAT_CRC, "+crc", 110},
-{"crypto", AArch64::AEK_CRYPTO, "+crypto", "-crypto", FEAT_MAX, "", 0},
+{"crypto", AArch64::AEK_CRYPTO, "+crypto", "-crypto", FEAT_MAX, "+aes,+sha2", 0},
 {"cssc", AArch64::AEK_CSSC, "+cssc", "-cssc", FEAT_MAX, "", 0},
 {"d128", AArch64::AEK_D128, "+d128", "-d128", FEAT_MAX, "", 0},
 {"dgh", AArch64::AEK_NONE, {}, {}, FEAT_DGH, "", 260},
Index: clang/test/CodeGen/aarch64-targetattr-crypto.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-targetattr-crypto.c
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +v8a -verify -S %s -o -
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+__attribute__((target("+crypto")))
+void test_crypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("crypto")))
+void test_pluscrypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("arch=armv8.2-a+crypto")))
+void test_archcrypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+// FIXME: This shouldn't need +crypto to be consistent with -mcpu options.
+__attribute__((target("cpu=cortex-a55+crypto")))
+void test_a55crypto(uint8x16_t data, uint8x16_t key)
+{
+  vaeseq_u8(data, key);
+  vsha1su1q_u32(data, key);
+}
+
+__attribute__((target("cpu=cortex-a510+crypto")))
+void test_a510crypto(ui

[PATCH] D147194: [clang-tidy] fix concat-nest-namespace fix hint remove the macro

2023-03-30 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp:70
+  File.data() + LocInfo.second, File.end());
+  L.SetCommentRetentionState(WithComment);
+  // Find the token.

This part of code copy from `Lexer::findNextToken` except this line. Should I 
refactor `Lexer::findNextToken` for example add a parameter to control it?
But `Lexer::findNextToken` is involved with lots of code. Maybe use another 
patch to do it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147194

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


[PATCH] D143099: [clang][lex] Expose findBeginningOfLine()

2023-03-30 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.

Sorry for the delayed response. I managed to miss seeing this review request.




Comment at: clang/include/clang/Lex/Lexer.h:598-599
 
+  /// Returns the pointer that points to the beginning of line that contains
+  /// the given offset, or null if the offset if invalid.
+  static const char *findBeginningOfLine(StringRef Buffer, unsigned Offset);





Comment at: clang/lib/Lex/Lexer.cpp:493-494
 
 /// Returns the pointer that points to the beginning of line that contains
 /// the given offset, or null if the offset if invalid.
+const char *Lexer::findBeginningOfLine(StringRef Buffer, unsigned Offset) {

KyleFromKitware wrote:
> cor3ntin wrote:
> > Should we remove the comment here?
> Other `Lexer` methods follow a similar pattern of having doc comments both in 
> the header and in the implementation. I think we can leave it.




Comment at: clang/unittests/Lex/LexerTest.cpp:673
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 13), 13);
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 12), 13);
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 11), 0);

I find this case interesting. I'm assuming it is intentional that an offset 
that corresponds to an EOL character indicates that the offset of the character 
following it be returned. That suggests some additional cases to test:
EXPECT_EQ(FindBeginningOfLineOffset("int func1();\n\n", 12), 13);
EXPECT_EQ(FindBeginningOfLineOffset("int func1();\n", 12), 13);  // 13? Or 
perhaps invalid?

My intuition is that an offset corresponding to an EOL character would result 
in the offset of the line containing the EOL character being returned.


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

https://reviews.llvm.org/D143099

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


[PATCH] D146922: [clang-tidy] Fix false positve for defaulted move constructor in performance-noexcept-move-constructor

2023-03-30 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 509695.
AMS21 marked 15 inline comments as done.
AMS21 added a comment.

Implement review suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146922

Files:
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor-fix.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp
@@ -1,10 +1,17 @@
-// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t
+// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t -- -- -fexceptions
+
+struct Empty
+{};
+
+struct IntWrapper {
+  int value;
+};
 
 class A {
   A(A &&);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [performance-noexcept-move-constructor]
   A &operator=(A &&);
-  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should be marked noexcept [performance-noexcept-move-constructor]
 };
 
 struct B {
@@ -13,6 +20,135 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]
 };
 
+template 
+struct C
+{
+  C(C &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [performance-noexcept-move-constructor]
+  C& operator=(C &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should be marked noexcept [performance-noexcept-move-constructor]
+};
+
+struct D
+{
+  static constexpr bool kFalse = false;
+  D(D &&) noexcept(kFalse) = default;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]
+  D& operator=(D &&) noexcept(kFalse) = default;
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: noexcept specifier on the move assignment operator evaluates to 'false'
+};
+
+template 
+struct E
+{
+  static constexpr bool kFalse = false;
+  E(E &&) noexcept(kFalse);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]
+  E& operator=(E &&) noexcept(kFalse);
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: noexcept specifier on the move assignment operator evaluates to 'false'
+};
+
+template 
+struct F
+{
+  static constexpr bool kFalse = false;
+  F(F &&) noexcept(kFalse) = default;
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]
+  F& operator=(F &&) noexcept(kFalse) = default;
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: noexcept specifier on the move assignment operator evaluates to 'false'
+};
+
+struct Field
+{
+  Field() = default;
+  Field(Field&&) noexcept(false) {
+  }
+  Field& operator=(Field &&) noexcept(false) {
+return *this;
+  }
+};
+
+struct G {
+  G(G &&) = default;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept [performance-noexcept-move-constructor]
+  G& operator=(G &&) = default;
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should be marked noexcept [performance-noexcept-move-constructor]
+
+  Field field;
+};
+
+void throwing_function() noexcept(false) {}
+
+struct H {
+  H(H &&) noexcept(noexcept(throwing_function()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]
+  H &operator=(H &&) noexcept(noexcept(throwing_function()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: noexcept specifier on the move assignment operator evaluates to 'false'
+};
+
+template 
+struct I {
+  I(I &&) noexcept(noexcept(throwing_function()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [performance-noexcept-move-constructor]
+  I &operator=(I &&) noexcept(noexcept(throwing_function()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: noexcept specifier on the move assignment operator evaluates to 'false'
+};
+
+te

[PATCH] D146922: [clang-tidy] Fix false positve for defaulted move constructor in performance-noexcept-move-constructor

2023-03-30 Thread André Schackier via Phabricator via cfe-commits
AMS21 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp:45-49
+const auto *ProtoType = Decl->getType()->castAs();
+const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
+if (NoexceptExpr) {
+  NoexceptExpr = NoexceptExpr->IgnoreImplicit();
+  if (!isa(NoexceptExpr)) {

PiotrZSL wrote:
> woudn't getExceptionSpecInfo() != EST_NoexceptFalse do a trick here ?
I've tested it and it seem that a struct like this:

```
struct B {
  static constexpr bool kFalse = false;
  B(B &&) noexcept(kFalse);
};
```

Also has the the `ExceptionSpecType` set to `EST_NoexceptFalse`. So changing 
this would change the previous behavior.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:95
+ DefaultableMemberKind Kind,
+ SkipMethods SkipMethods) {
+  if (!RecordDecl)

PiotrZSL wrote:
> Can we hit some endless recursion here ?
> Maybe so protection against checking Record that we currently checking.
Yes we can hit an infinite recursion here.
Take this class:

```
struct A {
A(A &&) = default;
};
```

Since the move constructor is defaulted, we need to call 
`analyzeUnresolvedOrDefaulted`. There we determine the kind of defaulted member 
function which in this case is a move constructor.
Then we call `analyzeRecord`. Without setting `SkipMethods::Yes` we would try 
to check the move constructor of the class which in this case is `A`. We would 
call `analyze` on the move constructor of `A` which is exactly where we started 
and we'd have an infinite loop.

That is why I've added the `SkipMethods` parameter. While analyzing the 
defaulted move constructor of `A` we only want to look at its base classes and 
it's fields and determine if they are declared as throwing or not. While for 
their the base classes and fields of `A` we also want to check their move 
constructor (if they have any).

I hope my explanation was at least a bit helpful.

There might be a better solution to this, Before this I had essentially the 
same code twice for checking the bases and field and wanted to combine them.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:95
+ DefaultableMemberKind Kind,
+ SkipMethods SkipMethods) {
+  if (!RecordDecl)

AMS21 wrote:
> PiotrZSL wrote:
> > Can we hit some endless recursion here ?
> > Maybe so protection against checking Record that we currently checking.
> Yes we can hit an infinite recursion here.
> Take this class:
> 
> ```
> struct A {
> A(A &&) = default;
> };
> ```
> 
> Since the move constructor is defaulted, we need to call 
> `analyzeUnresolvedOrDefaulted`. There we determine the kind of defaulted 
> member function which in this case is a move constructor.
> Then we call `analyzeRecord`. Without setting `SkipMethods::Yes` we would try 
> to check the move constructor of the class which in this case is `A`. We 
> would call `analyze` on the move constructor of `A` which is exactly where we 
> started and we'd have an infinite loop.
> 
> That is why I've added the `SkipMethods` parameter. While analyzing the 
> defaulted move constructor of `A` we only want to look at its base classes 
> and it's fields and determine if they are declared as throwing or not. While 
> for their the base classes and fields of `A` we also want to check their move 
> constructor (if they have any).
> 
> I hope my explanation was at least a bit helpful.
> 
> There might be a better solution to this, Before this I had essentially the 
> same code twice for checking the bases and field and wanted to combine them.
Another way to defiantly have an infinite recursion is if to resolve a `struct 
A;` we needed to resolve `struct B;` and to resolve that we needed to resolve 
`struct A`.  You would need something like `A` inheriting from `B` and `B` 
inheriting from `A` or having the other type as a member variable. Same goes 
for a struct which contains itself.

But I'm currently unaware on how to create such a scenario with legal C++.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionSpecAnalyzer.cpp:108-114
+  BasesToVisit Bases = isConstructor(Kind)
+   ? BasesToVisit::VisitPotentiallyConstructedBases
+   : BasesToVisit::VisitAllBases;
+
+  if (Bases == BasesToVisit::VisitPotentiallyConstructedBases)
+Bases = RecordDecl->isAbstract() ? BasesToVisit::VisitNonVirtualBases
+ : BasesToVisit::VisitAllBases;

PiotrZSL wrote:
> I'm not sure if we need to be so picky...
> In short we could check all bases.
> Virtual, Abstract or not...
Honestly I not sure about it. I just tried to copy what `Sema` does when 
resolving noexcept.
Removing it de

[PATCH] D146922: [clang-tidy] Fix false positve for defaulted move constructor in performance-noexcept-move-constructor

2023-03-30 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

Overall looks good to me. Leave it open for few days, maybe someone else want 
to comment.




Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp:45-49
+const auto *ProtoType = Decl->getType()->castAs();
+const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
+if (NoexceptExpr) {
+  NoexceptExpr = NoexceptExpr->IgnoreImplicit();
+  if (!isa(NoexceptExpr)) {

AMS21 wrote:
> PiotrZSL wrote:
> > woudn't getExceptionSpecInfo() != EST_NoexceptFalse do a trick here ?
> I've tested it and it seem that a struct like this:
> 
> ```
> struct B {
>   static constexpr bool kFalse = false;
>   B(B &&) noexcept(kFalse);
> };
> ```
> 
> Also has the the `ExceptionSpecType` set to `EST_NoexceptFalse`. So changing 
> this would change the previous behavior.
And thats why I pointing this, we should treat this function in same way as it 
would have noexcept(false)

but functions that use templates like:
noexcept(T::value) should not fall into this



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:261-262
+- Fixed an issue in :doc:`performance-noexcept-move-constructor
+  ` which resulted in 
false
+  positives if the constructor was defaulted.
+

Maybe: Fixed an issue in the performance-noexcept-move-constructor checker that 
was causing false-positives when the move constructor or move assign operator 
were defaulted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146922

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


[PATCH] D146922: [clang-tidy] Fix false positve for defaulted move constructor in performance-noexcept-move-constructor

2023-03-30 Thread André Schackier via Phabricator via cfe-commits
AMS21 added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:260
 
+- Fixed an issue in :doc:`performance-noexcept-move-constructor
+  ` which resulted in 
false

Eugene.Zelenko wrote:
> Please keep alphabetical order (by check name) in this section.
Sure but I'm a bit confused. I assuming the check name is without the prefix so 
in this case `noexcept-move-constructor`. So it should be after 
`readability-avoid-underscore-in-googletest-name`. But why then is 
`use-after-move` sorted before `identifier-naming`. 
I'm probably missing something very obvious.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146922

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


[PATCH] D146922: [clang-tidy] Fix false positve for defaulted move constructor in performance-noexcept-move-constructor

2023-03-30 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:260
 
+- Fixed an issue in :doc:`performance-noexcept-move-constructor
+  ` which resulted in 
false

AMS21 wrote:
> Eugene.Zelenko wrote:
> > Please keep alphabetical order (by check name) in this section.
> Sure but I'm a bit confused. I assuming the check name is without the prefix 
> so in this case `noexcept-move-constructor`. So it should be after 
> `readability-avoid-underscore-in-googletest-name`. But why then is 
> `use-after-move` sorted before `identifier-naming`. 
> I'm probably missing something very obvious.
Full check name (i.e. `performance-noexcept-move-constructor`) should be 
accounted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146922

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 509698.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Changed how size is calculated. Updated tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -1,8 +1,6 @@
 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
 
-llvm.func @_QPopenmp_target_data() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+llvm.func @_QPopenmp_target_data(%1 : !llvm.ptr) {
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
 %2 = llvm.mlir.constant(99 : i32) : i32
 llvm.store %2, %1 : !llvm.ptr
@@ -12,43 +10,35 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
-// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
+// CHECK-LABEL: define void @_QPopenmp_target_data
+// CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: br label %[[VAL_2:.*]]
+// CHECK:   entry:; preds = %[[VAL_3:.*]]
+// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_4]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[ARG_0]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @

[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1357-1362
+int64_t getSizeInBytes(DataLayout &DL, const mlir::Type &type) {
+  if (isa(type))
+return DL.getTypeSize(cast(type).getElementType());
+
+  return -1;
+}

@jdoerfert Is this way of getting the size correct? It seems to work for basic 
types and arrays which is what we support for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D147179: [RISCV] Bump I, F, D, and A extension versions to 20191214 spec version

2023-03-30 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 509707.
craig.topper added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147179

Files:
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  lld/test/ELF/lto/riscv-attributes.ll
  lld/test/ELF/riscv-attributes.s
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/attribute-with-insts.s
  llvm/test/MC/RISCV/attribute-with-option.s
  llvm/test/MC/RISCV/attribute.s
  llvm/test/MC/RISCV/invalid-attribute.s
  llvm/test/tools/llvm-readobj/ELF/RISCV/attribute.s
  llvm/unittests/Support/RISCVISAInfoTest.cpp

Index: llvm/unittests/Support/RISCVISAInfoTest.cpp
===
--- llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -130,7 +130,7 @@
   RISCVISAInfo &InfoRV32I = **MaybeRV32I;
   RISCVISAInfo::OrderedExtensionMap ExtsRV32I = InfoRV32I.getExtensions();
   EXPECT_EQ(ExtsRV32I.size(), 1UL);
-  EXPECT_TRUE(ExtsRV32I.at("i") == (RISCVExtensionInfo{2, 0}));
+  EXPECT_TRUE(ExtsRV32I.at("i") == (RISCVExtensionInfo{2, 1}));
   EXPECT_EQ(InfoRV32I.getXLen(), 32U);
   EXPECT_EQ(InfoRV32I.getFLen(), 0U);
 
@@ -147,12 +147,14 @@
   ASSERT_THAT_EXPECTED(MaybeRV32G, Succeeded());
   RISCVISAInfo &InfoRV32G = **MaybeRV32G;
   RISCVISAInfo::OrderedExtensionMap ExtsRV32G = InfoRV32G.getExtensions();
-  EXPECT_EQ(ExtsRV32G.size(), 5UL);
-  EXPECT_TRUE(ExtsRV32G.at("i") == (RISCVExtensionInfo{2, 0}));
+  EXPECT_EQ(ExtsRV32G.size(), 7UL);
+  EXPECT_TRUE(ExtsRV32G.at("i") == (RISCVExtensionInfo{2, 1}));
   EXPECT_TRUE(ExtsRV32G.at("m") == (RISCVExtensionInfo{2, 0}));
-  EXPECT_TRUE(ExtsRV32G.at("a") == (RISCVExtensionInfo{2, 0}));
-  EXPECT_TRUE(ExtsRV32G.at("f") == (RISCVExtensionInfo{2, 0}));
-  EXPECT_TRUE(ExtsRV32G.at("d") == (RISCVExtensionInfo{2, 0}));
+  EXPECT_TRUE(ExtsRV32G.at("a") == (RISCVExtensionInfo{2, 1}));
+  EXPECT_TRUE(ExtsRV32G.at("f") == (RISCVExtensionInfo{2, 2}));
+  EXPECT_TRUE(ExtsRV32G.at("d") == (RISCVExtensionInfo{2, 2}));
+  EXPECT_TRUE(ExtsRV32G.at("zicsr") == (RISCVExtensionInfo{2, 0}));
+  EXPECT_TRUE(ExtsRV32G.at("zifencei") == (RISCVExtensionInfo{2, 0}));
   EXPECT_EQ(InfoRV32G.getXLen(), 32U);
   EXPECT_EQ(InfoRV32G.getFLen(), 64U);
 
@@ -161,7 +163,7 @@
   RISCVISAInfo &InfoRV64I = **MaybeRV64I;
   RISCVISAInfo::OrderedExtensionMap ExtsRV64I = InfoRV64I.getExtensions();
   EXPECT_EQ(ExtsRV64I.size(), 1UL);
-  EXPECT_TRUE(ExtsRV64I.at("i") == (RISCVExtensionInfo{2, 0}));
+  EXPECT_TRUE(ExtsRV64I.at("i") == (RISCVExtensionInfo{2, 1}));
   EXPECT_EQ(InfoRV64I.getXLen(), 64U);
   EXPECT_EQ(InfoRV64I.getFLen(), 0U);
 
@@ -178,12 +180,14 @@
   ASSERT_THAT_EXPECTED(MaybeRV64G, Succeeded());
   RISCVISAInfo &InfoRV64G = **MaybeRV64G;
   RISCVISAInfo::OrderedExtensionMap ExtsRV64G = InfoRV64G.getExtensions();
-  EXPECT_EQ(ExtsRV64G.size(), 5UL);
-  EXPECT_TRUE(ExtsRV64G.at("i") == (RISCVExtensionInfo{2, 0}));
+  EXPECT_EQ(ExtsRV64G.size(), 7UL);
+  EXPECT_TRUE(ExtsRV64G.at("i") == (RISCVExtensionInfo{2, 1}));
   EXPECT_TRUE(ExtsRV64G.at("m") == (RISCVExtensionInfo{2, 0}));
-  EXPECT_TRUE(ExtsRV64G.at("a") == (RISCVExtensionInfo{2, 0}));
-  EXPECT_TRUE(ExtsRV64G.at("f") == (RISCVExtensionInfo{2, 0}));
-  EXPECT_TRUE(ExtsRV64G.at("d") == (RISCVExtensionInfo{2, 0}));
+  EXPECT_TRUE(ExtsRV64G.at("a") == (RISCVExtensionInfo{2, 1}));
+  EXPECT_TRUE(ExtsRV64G.at("f") == (RISCVExtensionInfo{2, 2}));
+  EXPECT_TRUE(ExtsRV64G.at("d") == (RISCVExtensionInfo{2, 2}));
+  EXPECT_TRUE(ExtsRV64G.at("zicsr") == (RISCVExtensionInfo{2, 0}));
+  EXPECT_TRUE(ExtsRV64G.at("zifencei") == (RISCVExtensionInfo{2, 0}));
   EXPECT_EQ(InfoRV64G.getXLen(), 64U);
   EXPECT_EQ(InfoRV64G.getFLen(), 64U);
 }
@@ -237,7 +241,7 @@
 RISCVISAInfo &Info = **MaybeISAInfo;
 RISCVISAInfo::OrderedExtensionMap Exts = Info.getExtensions();
 EXPECT_EQ(Exts.size(), 1UL);
-EXPECT_TRUE(Exts.at("i") == (RISCVExtensionInfo{2, 0}));
+EXPECT_TRUE(Exts.at("i") == (RISCVExtensionInfo{2, 1}));
   }
 
   // Checks that supported extensions aren't incorrectly ignored when a
@@ -250,11 +254,11 @@
 }
 
 TEST(ParseArchString, AcceptsVersionInLongOrShortForm) {
-  for (StringRef Input : {"rv64i2", "rv64i2p0"}) {
+  for (StringRef Input : {"rv64i2p1"}) {
 auto MaybeISAInfo = RISCVISAInfo::parseArchString(Input, true);
 ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
 RISCVISAInfo::OrderedExtensionMap Exts = (*MaybeISAInfo)->getExtensions();
-EXPECT_TRUE(Exts.at("i") == (RISCVExtensionInfo{2, 0}));
+EXPECT_TRUE(Exts.at("i") == (RISCVExtensionInfo{2, 1}));
   }
   for (StringRef Input : {"rv32i_zfinx1", "rv32i_zfinx1p0"}) {
 auto MaybeISAInfo = RISC

[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-03-30 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1482
+if (prev_base) {
+  clang::CXXRecordDecl *prev_base_decl =
+  prev_base->getType()->getAsCXXRecordDecl();

Should we add a comment describing why this block is necessary?

Perhaps even putting it into its own helper function



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:1487
+assert(it != layout_info.base_offsets.end());
+if (it->second.getQuantity() == member_byte_offset) {
+  prev_base_decl->markEmpty();

The idea seem reasonable in general.

Though this wouldn't work for overlapping member offsets. E.g.,:

```
struct C
{
 long c,d;
};

struct D
{
};

struct B
{
  [[no_unique_address]] D x;
};

struct E
{
  [[no_unique_address]] D x;
};

struct Foo : B, E, C {

};
```

Here `B` and `C` have offset `0x0`, but `E` can have offset `0x1`. So we 
wouldn't attach the attribute for `E` and would still crash. Maybe we should 
check for overlapping offsets, not just equal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D147234: [clang][ExtractAPI] Reland ExtractAPI for libclang improvements

2023-03-30 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG142c3d9d1414: [clang][ExtractAPI] Reland ExtractAPI for 
libclang improvements (authored by dang).

Changed prior to commit:
  https://reviews.llvm.org/D147234?vs=509660&id=509714#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147234

Files:
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/include/clang/ExtractAPI/TypedefUnderlyingTypeResolver.h
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h
  clang/test/Index/extract-api-cursor.m
  clang/test/Index/extract-api-usr.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CXExtractAPI.cpp

Index: clang/tools/libclang/CXExtractAPI.cpp
===
--- clang/tools/libclang/CXExtractAPI.cpp
+++ clang/tools/libclang/CXExtractAPI.cpp
@@ -18,6 +18,7 @@
 #include "clang-c/Index.h"
 #include "clang-c/Platform.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/ExtractAPIVisitor.h"
@@ -34,13 +35,73 @@
 using namespace clang;
 using namespace clang::extractapi;
 
+namespace {
+struct LibClangExtractAPIVisitor
+: ExtractAPIVisitor {
+  using Base = ExtractAPIVisitor;
+
+  LibClangExtractAPIVisitor(ASTContext &Context, APISet &API)
+  : ExtractAPIVisitor(Context, API) {}
+
+  const RawComment *fetchRawCommentForDecl(const Decl *D) const {
+return Context.getRawCommentForAnyRedecl(D);
+  }
+
+  // We need to visit implementations as well to ensure that when a user clicks
+  // on a method defined only within the implementation that we can still
+  // provide a symbol graph for it.
+  bool VisitObjCImplementationDecl(const ObjCImplementationDecl *Decl) {
+if (!shouldDeclBeIncluded(Decl))
+  return true;
+
+const ObjCInterfaceDecl *Interface = Decl->getClassInterface();
+StringRef Name = Interface->getName();
+StringRef USR = API.recordUSR(Decl);
+PresumedLoc Loc =
+Context.getSourceManager().getPresumedLoc(Decl->getLocation());
+LinkageInfo Linkage = Decl->getLinkageAndVisibility();
+DocComment Comment;
+if (auto *RawComment = fetchRawCommentForDecl(Interface))
+  Comment = RawComment->getFormattedLines(Context.getSourceManager(),
+  Context.getDiagnostics());
+
+// Build declaration fragments and sub-heading by generating them for the
+// interface.
+DeclarationFragments Declaration =
+DeclarationFragmentsBuilder::getFragmentsForObjCInterface(Interface);
+DeclarationFragments SubHeading =
+DeclarationFragmentsBuilder::getSubHeading(Decl);
+
+// Collect super class information.
+SymbolReference SuperClass;
+if (const auto *SuperClassDecl = Decl->getSuperClass()) {
+  SuperClass.Name = SuperClassDecl->getObjCRuntimeNameAsString();
+  SuperClass.USR = API.recordUSR(SuperClassDecl);
+}
+
+ObjCInterfaceRecord *ObjCInterfaceRecord = API.addObjCInterface(
+Name, USR, Loc, AvailabilitySet(Decl), Linkage, Comment, Declaration,
+SubHeading, SuperClass, isInSystemHeader(Decl));
+
+// Record all methods (selectors). This doesn't include automatically
+// synthesized property methods.
+recordObjCMethods(ObjCInterfaceRecord, Decl->methods());
+recordObjCProperties(ObjCInterfaceRecord, Decl->properties());
+recordObjCInstanceVariables(ObjCInterfaceRecord, Decl->ivars());
+
+return true;
+  }
+};
+} // namespace
+
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(APISet, CXAPISet)
 
-static void WalkupFromMostDerivedType(ExtractAPIVisitor &Visitor, Decl *D);
+static void WalkupFromMostDerivedType(LibClangExtractAPIVisitor &Visitor,
+  Decl *D);
 
 template 
 static bool WalkupParentContext(DeclContext *Parent,
-ExtractAPIVisitor &Visitor) {
+LibClangExtractAPIVisitor &Visitor) {
   if (auto *D = dyn_cast(Parent)) {
 WalkupFromMostDerivedType(Visitor, D);
 return true;
@@ -48,7 +109,8 @@
   return false;
 }
 
-static void WalkupFromMostDerivedType(ExtractAPIVisitor &Visitor, Decl *D) {
+static void WalkupFromMostDerivedType(LibClangExtractAPIVisitor &Visitor,
+  Decl *D) {
   switch (D->getKind()) {
 #define ABSTRACT_DECL(DECL)
 #define DECL(CLASS, BASE)  \
@@ -84,8 +146,7 @@
   auto Lang = Unit->getInputKind().getLanguage();
   APISet *API = 

[clang] 142c3d9 - [clang][ExtractAPI] Reland ExtractAPI for libclang improvements

2023-03-30 Thread Daniel Grumberg via cfe-commits

Author: Daniel Grumberg
Date: 2023-03-30T18:13:58+01:00
New Revision: 142c3d9d1414847fd154c300ff12505283027505

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

LOG: [clang][ExtractAPI] Reland ExtractAPI for libclang improvements

This relands the changes that were originally introduced by:
- https://reviews.llvm.org/D146656
- https://reviews.llvm.org/D147138

This also fixes the leak that led to these changes being reverted

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

Added: 
clang/include/clang/ExtractAPI/TypedefUnderlyingTypeResolver.h

Modified: 
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/lib/ExtractAPI/CMakeLists.txt
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
clang/test/Index/extract-api-cursor.m
clang/test/Index/extract-api-usr.m
clang/tools/c-index-test/c-index-test.c
clang/tools/libclang/CXExtractAPI.cpp

Removed: 
clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h



diff  --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h 
b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index f6546fb4776a6..a31648b80195a 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -14,24 +14,27 @@
 #ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
 #define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
 
+#include "llvm/ADT/FunctionExtras.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/ExtractAPI/API.h"
-#include "llvm/ADT/FunctionExtras.h"
+#include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h"
+#include 
 
 namespace clang {
 namespace extractapi {
+namespace impl {
 
-/// The RecursiveASTVisitor to traverse symbol declarations and collect API
-/// information.
-class ExtractAPIVisitor : public RecursiveASTVisitor {
-public:
-  ExtractAPIVisitor(ASTContext &Context,
-llvm::unique_function 
LocationChecker,
-APISet &API)
-  : Context(Context), API(API),
-LocationChecker(std::move(LocationChecker)) {}
+template 
+class ExtractAPIVisitorBase : public RecursiveASTVisitor {
+protected:
+  ExtractAPIVisitorBase(ASTContext &Context, APISet &API)
+  : Context(Context), API(API) {}
 
+public:
   const APISet &getAPI() const { return API; }
 
   bool VisitVarDecl(const VarDecl *Decl);
@@ -50,7 +53,11 @@ class ExtractAPIVisitor : public 
RecursiveASTVisitor {
 
   bool VisitObjCCategoryDecl(const ObjCCategoryDecl *Decl);
 
-private:
+  bool shouldDeclBeIncluded(const Decl *Decl) const;
+
+  const RawComment *fetchRawCommentForDecl(const Decl *Decl) const;
+
+protected:
   /// Collect API information for the enum constants and associate with the
   /// parent enum.
   void recordEnumConstants(EnumRecord *EnumRecord,
@@ -77,9 +84,582 @@ class ExtractAPIVisitor : public 
RecursiveASTVisitor {
 
   void recordObjCProtocols(ObjCContainerRecord *Container,
ObjCInterfaceDecl::protocol_range Protocols);
+
   ASTContext &Context;
   APISet &API;
-  llvm::unique_function LocationChecker;
+
+  StringRef getTypedefName(const TagDecl *Decl) {
+if (const auto *TypedefDecl = Decl->getTypedefNameForAnonDecl())
+  return TypedefDecl->getName();
+
+return {};
+  }
+
+  bool isInSystemHeader(const Decl *D) {
+return Context.getSourceManager().isInSystemHeader(D->getLocation());
+  }
+
+private:
+  Derived &getDerivedExtractAPIVisitor() {
+return *static_cast(this);
+  }
+};
+
+template 
+bool ExtractAPIVisitorBase::VisitVarDecl(const VarDecl *Decl) {
+  // skip function parameters.
+  if (isa(Decl))
+return true;
+
+  // Skip non-global variables in records (struct/union/class).
+  if (Decl->getDeclContext()->isRecord())
+return true;
+
+  // Skip local variables inside function or method.
+  if (!Decl->isDefinedOutsideFunctionOrMethod())
+return true;
+
+  // If this is a template but not specialization or instantiation, skip.
+  if (Decl->getASTContext().getTemplateOrSpecializationInfo(Decl) &&
+  Decl->getTemplateSpecializationKind() == TSK_Undeclared)
+return true;
+
+  if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
+return true;
+
+  // Collect symbol information.
+  StringRef Name = Decl->getName();
+  StringRef USR = API.recordUSR(Decl);
+  PresumedLoc Loc =
+  Context.getSourceManager().getPresumedLoc(Decl->getLocation());
+  LinkageInfo Linkage = Decl->getLinkageAndVisibility();

[PATCH] D143099: [clang][lex] Expose findBeginningOfLine()

2023-03-30 Thread Kyle Edwards via Phabricator via cfe-commits
KyleFromKitware added inline comments.



Comment at: clang/unittests/Lex/LexerTest.cpp:673
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 13), 13);
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 12), 13);
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 11), 0);

tahonermann wrote:
> I find this case interesting. I'm assuming it is intentional that an offset 
> that corresponds to an EOL character indicates that the offset of the 
> character following it be returned. That suggests some additional cases to 
> test:
> EXPECT_EQ(FindBeginningOfLineOffset("int func1();\n\n", 12), 13);
> EXPECT_EQ(FindBeginningOfLineOffset("int func1();\n", 12), 13);  // 13? 
> Or perhaps invalid?
> 
> My intuition is that an offset corresponding to an EOL character would result 
> in the offset of the line containing the EOL character being returned.
I did my best to preserve the existing behavior of the function while fixing a 
corner case that was obviously wrong. Should this be fixed as well?


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

https://reviews.llvm.org/D143099

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


[PATCH] D143099: [clang][lex] Expose findBeginningOfLine()

2023-03-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/unittests/Lex/LexerTest.cpp:673
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 13), 13);
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 12), 13);
+  EXPECT_EQ(FindBeginningOfLineOffset("int func1();\nint func2();", 11), 0);

KyleFromKitware wrote:
> tahonermann wrote:
> > I find this case interesting. I'm assuming it is intentional that an offset 
> > that corresponds to an EOL character indicates that the offset of the 
> > character following it be returned. That suggests some additional cases to 
> > test:
> > EXPECT_EQ(FindBeginningOfLineOffset("int func1();\n\n", 12), 13);
> > EXPECT_EQ(FindBeginningOfLineOffset("int func1();\n", 12), 13);  // 13? 
> > Or perhaps invalid?
> > 
> > My intuition is that an offset corresponding to an EOL character would 
> > result in the offset of the line containing the EOL character being 
> > returned.
> I did my best to preserve the existing behavior of the function while fixing 
> a corner case that was obviously wrong. Should this be fixed as well?
@KyleFromKitware Try to fix it. If it doesn't cause test failures, i think we 
can do it as part of this PR. It it has wider ramifications we'll see.
But I agree with Tom that logically new lines should be part of the line they 
appear in rather than the next.


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

https://reviews.llvm.org/D143099

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-03-30 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 509725.
TIFitis added a comment.

Updated unit test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -1,8 +1,6 @@
 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
 
-llvm.func @_QPopenmp_target_data() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+llvm.func @_QPopenmp_target_data(%1 : !llvm.ptr) {
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
 %2 = llvm.mlir.constant(99 : i32) : i32
 llvm.store %2, %1 : !llvm.ptr
@@ -12,43 +10,35 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
-// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
+// CHECK-LABEL: define void @_QPopenmp_target_data
+// CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: br label %[[VAL_2:.*]]
+// CHECK:   entry:; preds = %[[VAL_3:.*]]
+// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_4]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[ARG_0]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr nu

[clang] 1fab236 - [CMake] Switch to -fPIE for Fuchsia Toolchain

2023-03-30 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2023-03-30T18:00:50Z
New Revision: 1fab236e6e4575d5af4f4722216df4dd6a872795

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

LOG: [CMake] Switch to -fPIE for Fuchsia Toolchain

This is a reland of D135471, save for dropping libLTO which was
already done in a separate change.

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 7778a7f84b051..c6debed5007b8 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -16,6 +16,7 @@ set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
 set(LLVM_ENABLE_LLD ON CACHE BOOL "")
 set(LLVM_ENABLE_LTO ON CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
+set(LLVM_ENABLE_PIC OFF CACHE BOOL "")
 set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -135,6 +136,7 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING 
"")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING 
"")
@@ -147,6 +149,7 @@ foreach(target 
aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unkn
 list(APPEND RUNTIME_TARGETS "${target}")
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING 
"")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING 
"")
@@ -197,6 +200,7 @@ if(FUCHSIA_SDK)
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
@@ -212,6 +216,7 @@ if(FUCHSIA_SDK)
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")



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


[PATCH] D147250: [CMake] Switch to -fPIE for Fuchsia Toolchain

2023-03-30 Thread Alex Brachet 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 rG1fab236e6e45: [CMake] Switch to -fPIE for Fuchsia Toolchain 
(authored by abrachet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147250

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -16,6 +16,7 @@
 set(LLVM_ENABLE_LLD ON CACHE BOOL "")
 set(LLVM_ENABLE_LTO ON CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
+set(LLVM_ENABLE_PIC OFF CACHE BOOL "")
 set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -135,6 +136,7 @@
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING 
"")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING 
"")
@@ -147,6 +149,7 @@
 list(APPEND RUNTIME_TARGETS "${target}")
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING 
"")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING 
"")
@@ -197,6 +200,7 @@
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
@@ -212,6 +216,7 @@
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS ${FUCHSIA_${target}_COMPILER_FLAGS} 
CACHE STRING "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -16,6 +16,7 @@
 set(LLVM_ENABLE_LLD ON CACHE BOOL "")
 set(LLVM_ENABLE_LTO ON CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
+set(LLVM_ENABLE_PIC OFF CACHE BOOL "")
 set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -135,6 +136,7 @@
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(BUILTINS_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(BUILTINS_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING "")
 set(BUILTINS_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING "")
@@ -147,6 +149,7 @@
 list(APPEND RUNTIME_TARGETS "${target}")
 set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Linux CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(RUNTIMES_${target}_CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
 set(RUNTIMES_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING "")
 set(RUNTIMES_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING "")
@@ -197,6 +200,7 @@
 list(APPEND BUILTIN_TARGETS "${target}")
 set(BUILTINS_${tar

[PATCH] D138247: PR58819: Correct linkage and mangling of lambdas in inline static member initializers

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138247

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


  1   2   3   >