[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:12
+SYMBOL(consume_header, std::, ) // declared
+SYMBOL(consume_header, std::, )  // defined
+SYMBOL(generate_header, std::, )

i feel like cppreference is wrong here (at least per libstdc++-12, and 
https://eel.is/c++draft/locale.syn#header:%3clocale%3e)

```
#include 
auto x = std::consume_header;
```

same for generate_header and little_endian.

it might be worth changing these into:
```
SYMBOL(consume_header, std::, )
// cppreference mentions this header as an alternative, but it isn't in 
practice.
// SYMBOL(consume_header, std::, ) 
```



Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:19
+SYMBOL(mbstate_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )

can we actually use the ordering from standard: `[cstddef.syn], [cstdlib.syn], 
[cstring.syn], [cwchar.syn], [cuchar.syn], [ctime.syn], [cstdio.syn]` 
[(1)](https://eel.is/c++draft/libraryindex#:~:text=size_%C2%ADt%2C%20%5Bexpr.sizeof%5D%2C%20%5Bcstddef.syn%5D%2C%20%5Bcstdlib.syn%5D%2C%20%5Bcstring.syn%5D%2C%20%5Bcwchar.syn%5D%2C%20%5Bcuchar.syn%5D%2C%20%5Bctime.syn%5D%2C%20%5Bcstdio.syn%5D)



Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:26
+SYMBOL(size_t, std::, )
+// C++ [meta.trans.other 21.3.8.7]:
+// In addition to being available via inclusion of the  header,

nit: i don't think we need the comments here, both headers are also mentioned 
in cppreference pages.
i am afraid these might get out of date (or only seldom mentioned) as future 
editors of this mapping might not be delicate enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

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


[PATCH] D142871: [clangd] Semantic highlighting for constrained-parameter

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:1047
 
+  bool TraverseTypeConstraint(const TypeConstraint *TC) {
+Out(ReferenceLoc{TC->getNestedNameSpecifierLoc(),

can you also add a comment like `// We actually want to handle all 
ConceptReferences but RAV doesn't traverse it polymorphically. So handle the 
ones inside TypeConstraints specially here.`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142871

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


[PATCH] D142871: [clangd] Semantic highlighting for constrained-parameter

2023-02-06 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 495015.
nridge added a comment.

address review comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142871

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1022,7 +1022,7 @@
 class $Class_def[[Z]] {};
 template $Bracket[[<]]typename, typename$Bracket[[>]]
 concept $Concept_decl[[C2]] = true;
-template $Bracket[[<]]C2$Bracket[[<]]int$Bracket[[>]] 
$TemplateParameter_def[[A]]$Bracket[[>]]
+template $Bracket[[<]]$Concept[[C2]]$Bracket[[<]]int$Bracket[[>]] 
$TemplateParameter_def[[A]]$Bracket[[>]]
 class $Class_def[[B]] {};
   )cpp",
   // no crash
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -1044,6 +1044,17 @@
 return RecursiveASTVisitor::TraverseConstructorInitializer(Init);
   }
 
+  bool TraverseTypeConstraint(const TypeConstraint *TC) {
+// We want to handle all ConceptReferences but RAV is missing a
+// polymorphic Visit or Traverse method for it, so we handle
+// TypeConstraints specially here.
+Out(ReferenceLoc{TC->getNestedNameSpecifierLoc(),
+ TC->getConceptNameLoc(),
+ /*IsDecl=*/false,
+ {TC->getNamedConcept()}});
+return RecursiveASTVisitor::TraverseTypeConstraint(TC);
+  }
+
 private:
   /// Obtain information about a reference directly defined in \p N. Does not
   /// recurse into child nodes, e.g. do not expect references for constructor


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1022,7 +1022,7 @@
 class $Class_def[[Z]] {};
 template $Bracket[[<]]typename, typename$Bracket[[>]]
 concept $Concept_decl[[C2]] = true;
-template $Bracket[[<]]C2$Bracket[[<]]int$Bracket[[>]] $TemplateParameter_def[[A]]$Bracket[[>]]
+template $Bracket[[<]]$Concept[[C2]]$Bracket[[<]]int$Bracket[[>]] $TemplateParameter_def[[A]]$Bracket[[>]]
 class $Class_def[[B]] {};
   )cpp",
   // no crash
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -1044,6 +1044,17 @@
 return RecursiveASTVisitor::TraverseConstructorInitializer(Init);
   }
 
+  bool TraverseTypeConstraint(const TypeConstraint *TC) {
+// We want to handle all ConceptReferences but RAV is missing a
+// polymorphic Visit or Traverse method for it, so we handle
+// TypeConstraints specially here.
+Out(ReferenceLoc{TC->getNestedNameSpecifierLoc(),
+ TC->getConceptNameLoc(),
+ /*IsDecl=*/false,
+ {TC->getNamedConcept()}});
+return RecursiveASTVisitor::TraverseTypeConstraint(TC);
+  }
+
 private:
   /// Obtain information about a reference directly defined in \p N. Does not
   /// recurse into child nodes, e.g. do not expect references for constructor
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140915: [clangd] Fix getQueryScopes for using-directive with inline namespace

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!




Comment at: clang-tools-extra/clangd/CodeComplete.cpp:675
+std::vector EnclosingAtFront;
+if (EnclosingNamespace.has_value()) {
+  EnclosingAtFront.push_back(*EnclosingNamespace);

nit: you can drop the braces



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1719
+  });
+llvm::copy_if(SpecifiedScopes.scopesForQualification(),
+  std::back_inserter(AccessibleScopes),

tom-anders wrote:
> kadircet wrote:
> > `AccessibleScopes` doesn't need any particular ordering. we can use 
> > `scopesForQualification` as-is.
> Might as well just make it a std::set instead of std::vector? 
let's leave it as-is for now. i feel like this part can benefit from a bigger 
refactoring going forward and thinking about vectors is easier then having a 
bunch of references or sets.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140915

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


[clang-tools-extra] 6c46913 - [clangd] Semantic highlighting for constrained-parameter

2023-02-06 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-02-06T03:44:36-05:00
New Revision: 6c4691391419814d0fd8fcd92c99026813c35b47

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

LOG: [clangd] Semantic highlighting for constrained-parameter

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

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index f76bedee03515..1caf70183fdb6 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1044,6 +1044,17 @@ class ExplicitReferenceCollector
 return RecursiveASTVisitor::TraverseConstructorInitializer(Init);
   }
 
+  bool TraverseTypeConstraint(const TypeConstraint *TC) {
+// We want to handle all ConceptReferences but RAV is missing a
+// polymorphic Visit or Traverse method for it, so we handle
+// TypeConstraints specially here.
+Out(ReferenceLoc{TC->getNestedNameSpecifierLoc(),
+ TC->getConceptNameLoc(),
+ /*IsDecl=*/false,
+ {TC->getNamedConcept()}});
+return RecursiveASTVisitor::TraverseTypeConstraint(TC);
+  }
+
 private:
   /// Obtain information about a reference directly defined in \p N. Does not
   /// recurse into child nodes, e.g. do not expect references for constructor

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 08d94537f4d29..f5174979a8d6e 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1022,7 +1022,7 @@ sizeof...($TemplateParameter[[Elements]]);
 class $Class_def[[Z]] {};
 template $Bracket[[<]]typename, typename$Bracket[[>]]
 concept $Concept_decl[[C2]] = true;
-template $Bracket[[<]]C2$Bracket[[<]]int$Bracket[[>]] 
$TemplateParameter_def[[A]]$Bracket[[>]]
+template $Bracket[[<]]$Concept[[C2]]$Bracket[[<]]int$Bracket[[>]] 
$TemplateParameter_def[[A]]$Bracket[[>]]
 class $Class_def[[B]] {};
   )cpp",
   // no crash



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


[PATCH] D142871: [clangd] Semantic highlighting for constrained-parameter

2023-02-06 Thread Nathan Ridge 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 rG6c4691391419: [clangd] Semantic highlighting for 
constrained-parameter (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142871

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1022,7 +1022,7 @@
 class $Class_def[[Z]] {};
 template $Bracket[[<]]typename, typename$Bracket[[>]]
 concept $Concept_decl[[C2]] = true;
-template $Bracket[[<]]C2$Bracket[[<]]int$Bracket[[>]] 
$TemplateParameter_def[[A]]$Bracket[[>]]
+template $Bracket[[<]]$Concept[[C2]]$Bracket[[<]]int$Bracket[[>]] 
$TemplateParameter_def[[A]]$Bracket[[>]]
 class $Class_def[[B]] {};
   )cpp",
   // no crash
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -1044,6 +1044,17 @@
 return RecursiveASTVisitor::TraverseConstructorInitializer(Init);
   }
 
+  bool TraverseTypeConstraint(const TypeConstraint *TC) {
+// We want to handle all ConceptReferences but RAV is missing a
+// polymorphic Visit or Traverse method for it, so we handle
+// TypeConstraints specially here.
+Out(ReferenceLoc{TC->getNestedNameSpecifierLoc(),
+ TC->getConceptNameLoc(),
+ /*IsDecl=*/false,
+ {TC->getNamedConcept()}});
+return RecursiveASTVisitor::TraverseTypeConstraint(TC);
+  }
+
 private:
   /// Obtain information about a reference directly defined in \p N. Does not
   /// recurse into child nodes, e.g. do not expect references for constructor


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1022,7 +1022,7 @@
 class $Class_def[[Z]] {};
 template $Bracket[[<]]typename, typename$Bracket[[>]]
 concept $Concept_decl[[C2]] = true;
-template $Bracket[[<]]C2$Bracket[[<]]int$Bracket[[>]] $TemplateParameter_def[[A]]$Bracket[[>]]
+template $Bracket[[<]]$Concept[[C2]]$Bracket[[<]]int$Bracket[[>]] $TemplateParameter_def[[A]]$Bracket[[>]]
 class $Class_def[[B]] {};
   )cpp",
   // no crash
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -1044,6 +1044,17 @@
 return RecursiveASTVisitor::TraverseConstructorInitializer(Init);
   }
 
+  bool TraverseTypeConstraint(const TypeConstraint *TC) {
+// We want to handle all ConceptReferences but RAV is missing a
+// polymorphic Visit or Traverse method for it, so we handle
+// TypeConstraints specially here.
+Out(ReferenceLoc{TC->getNestedNameSpecifierLoc(),
+ TC->getConceptNameLoc(),
+ /*IsDecl=*/false,
+ {TC->getNamedConcept()}});
+return RecursiveASTVisitor::TraverseTypeConstraint(TC);
+  }
+
 private:
   /// Obtain information about a reference directly defined in \p N. Does not
   /// recurse into child nodes, e.g. do not expect references for constructor
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:1
+//===-- CXXSymbolMap.inc *- C++ 
-*-===//
+//

also maybe rename this to, `AlternativeHeaderMap.inc` ?



Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:3
+//
+// Unlike the generated StdSymbolMap.inc, this file contains a hand-cruted list
+// of symbols (which are hard to handle by the generator script). It intends

i'd rather say `This is a hand-curated list for symbols provided by multiple 
headers, to address the short comings of cppreference or automated extraction 
logic. All entries for a symbol name provide the same declaration (hence these 
are not overloads/variants like std::remove from algorithm vs cstdio).`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-06 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the fix! Might be good to wait a few days for other reviewers 
to have a look or give suggestions on how to improve the issue of having to do 
one parameter at a time.


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

https://reviews.llvm.org/D143342

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


[clang] 7c97c57 - [Modules] Recreate file manager for ftime-trace when compiling a module

2023-02-06 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-02-06T17:17:09+08:00
New Revision: 7c97c574cc795705737cd0b73daf6867406fe624

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

LOG: [Modules] Recreate file manager for ftime-trace when compiling a module

Close https://github.com/llvm/llvm-project/issues/60544.

The root cause for the issue is that when we compile a module unit, the
file manager (and proprocessor and source manager) are owned by AST
instead of the compilaton instance. So the file manager may be invalid
when we want to create a time-report file for -ftime-trace when we are
compiling a module unit.

This patch tries to recreate the file manager for -ftime-trace if we
find the file manager is not valid.

Added: 
clang/test/Modules/ftime-trace.cppm

Modified: 
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/FrontendAction.cpp
clang/tools/driver/cc1_main.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index ecc1c4cf51c18..9c79e856dad4f 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -851,6 +851,9 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
   // relative to that.
   std::optional> AbsPath;
   if (OutputPath != "-" && !llvm::sys::path::is_absolute(OutputPath)) {
+assert(hasFileManager() &&
+   "File Manager is required to fix up relative path.\n");
+
 AbsPath.emplace(OutputPath);
 FileMgr->FixupRelativePath(*AbsPath);
 OutputPath = *AbsPath;

diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 1e276642016d1..3551967106c5a 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -1117,6 +1117,9 @@ void FrontendAction::EndSourceFile() {
   // FrontendAction.
   CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles());
 
+  // The resources are owned by AST when the current file is AST.
+  // So we reset the resources here to avoid users accessing it
+  // accidently.
   if (isCurrentFileAST()) {
 if (DisableFree) {
   CI.resetAndLeakPreprocessor();

diff  --git a/clang/test/Modules/ftime-trace.cppm 
b/clang/test/Modules/ftime-trace.cppm
new file mode 100644
index 0..48cd4113ec782
--- /dev/null
+++ b/clang/test/Modules/ftime-trace.cppm
@@ -0,0 +1,13 @@
+// Tests that we can use modules and ftime-trace together.
+// Address https://github.com/llvm/llvm-project/issues/60544
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/a.pcm -ftime-trace=%t/a.json -o -
+// RUN: ls %t | grep "a.json"
+
+//--- a.cppm
+export module a;

diff  --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index c79306b6f7d59..cb33692cd2623 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -266,6 +266,19 @@ int cc1_main(ArrayRef Argv, const char 
*Argv0, void *MainAddr) {
 llvm::sys::path::append(TracePath, llvm::sys::path::filename(Path));
   Path.assign(TracePath);
 }
+
+// It is possible that the compiler instance doesn't own a file manager 
here
+// if we're compiling a module unit. Since the file manager are owned by 
AST
+// when we're compiling a module unit. So the file manager may be invalid
+// here.
+//
+// It should be fine to create file manager here since the file system
+// options are stored in the compiler invocation and we can recreate the 
VFS
+// from the compiler invocation.
+if (!Clang->hasFileManager())
+  Clang->createFileManager(createVFSFromCompilerInvocation(
+  Clang->getInvocation(), Clang->getDiagnostics()));
+
 if (auto profilerOutput = Clang->createOutputFile(
 Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {



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


[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.cpp:736
 void CanonicalIncludes::addSystemHeadersMapping(const LangOptions &Language) {
   if (Language.CPlusPlus) {
+static const auto *Symbols = []() {

what about getting rid of `StdSymbolMapping` completely and changing 
`CanonicalIncludes::mapSymbol` to use `tooling::stdlib` ?
only call site is through `SymbolCollector`, which has access to `LangOptions`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

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


[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495032.
hokein marked an inline comment as done.
hokein edited the summary of this revision.
hokein added a comment.

address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

Files:
  clang/include/clang/Tooling/Inclusions/StdAlternativeHeaderMap.inc

Index: clang/include/clang/Tooling/Inclusions/StdAlternativeHeaderMap.inc
===
--- /dev/null
+++ clang/include/clang/Tooling/Inclusions/StdAlternativeHeaderMap.inc
@@ -0,0 +1,207 @@
+//===-- StdAlternativeHeaderMap.inc -*- C++ -*-===//
+//
+// This is a hand-curated list for C++ symbols (e.g. provided by multiple
+// headers), to address the short comings of cppreference or automated
+// extraction logic. All headers for a symbol name provide the same declaration
+// (hence these are not overloads/variants like std::remove from algorithm vs
+// cstdio).
+//
+//===--===//
+
+// Symbols that can be provided by any of the headers, ordered by the header
+// preference.
+// cppreference mentions the  header is an alternative for these symbols,
+// but they are not per the standard.
+SYMBOL(consume_header, std::, )
+SYMBOL(generate_header, std::, )
+SYMBOL(little_endian, std::, )
+
+SYMBOL(mbstate_t, std::, )
+SYMBOL(mbstate_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(unwrap_ref_decay, std::, )
+SYMBOL(unwrap_ref_decay, std::, )
+SYMBOL(unwrap_reference, std::, )
+SYMBOL(unwrap_reference, std::, )
+SYMBOL(unwrap_ref_decay_t, std::, )
+SYMBOL(unwrap_ref_decay_t, std::, )
+SYMBOL(wint_t, std::, )
+SYMBOL(wint_t, std::, )
+// C++ [iterator.range 25.7]: In addition to being available via inclusion of
+// the  header, the function templates in [iterator.range] are
+// available when any of the following headers are included: , ,
+// , ... and .
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(r

[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:1
+//===-- CXXSymbolMap.inc *- C++ 
-*-===//
+//

kadircet wrote:
> also maybe rename this to, `AlternativeHeaderMap.inc` ?
Renamed it to `StdAlternativeHeaderMap.inc`, to align with the existing 
`StdSymbolMap.inc` name pattern for C++ symbols.



Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:12
+SYMBOL(consume_header, std::, ) // declared
+SYMBOL(consume_header, std::, )  // defined
+SYMBOL(generate_header, std::, )

kadircet wrote:
> i feel like cppreference is wrong here (at least per libstdc++-12, and 
> https://eel.is/c++draft/locale.syn#header:%3clocale%3e)
> 
> ```
> #include 
> auto x = std::consume_header;
> ```
> 
> same for generate_header and little_endian.
> 
> it might be worth changing these into:
> ```
> SYMBOL(consume_header, std::, )
> // cppreference mentions this header as an alternative, but it isn't in 
> practice.
> // SYMBOL(consume_header, std::, ) 
> ```
Right, thanks for checking it! You're right. I also have checked the C++11, 
C++17 standard, I don't find any relevant text about the header "" 
contains the these symbol definition.
I'd rather delete this entry, and only keep ``. 




Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:19
+SYMBOL(mbstate_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )

kadircet wrote:
> can we actually use the ordering from standard: `[cstddef.syn], 
> [cstdlib.syn], [cstring.syn], [cwchar.syn], [cuchar.syn], [ctime.syn], 
> [cstdio.syn]` 
> [(1)](https://eel.is/c++draft/libraryindex#:~:text=size_%C2%ADt%2C%20%5Bexpr.sizeof%5D%2C%20%5Bcstddef.syn%5D%2C%20%5Bcstdlib.syn%5D%2C%20%5Bcstring.syn%5D%2C%20%5Bcwchar.syn%5D%2C%20%5Bcuchar.syn%5D%2C%20%5Bctime.syn%5D%2C%20%5Bcstdio.syn%5D)
Sure. 



Comment at: clang/include/clang/Tooling/Inclusions/CXXSymbolMap.inc:26
+SYMBOL(size_t, std::, )
+// C++ [meta.trans.other 21.3.8.7]:
+// In addition to being available via inclusion of the  header,

kadircet wrote:
> nit: i don't think we need the comments here, both headers are also mentioned 
> in cppreference pages.
> i am afraid these might get out of date (or only seldom mentioned) as future 
> editors of this mapping might not be delicate enough.
Removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

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


[PATCH] D143280: [include-mapping] Better #includes support for std input/output symbols

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/tools/include-mapping/gen_std.py:160
+  headers = [sym_header]
+  if symbol.name in iosfwd_symbols:
+headers.append("")

i think putting `iostream` before `iosfwd` in the alternative list makes more 
sense. WDYT?



Comment at: clang/tools/include-mapping/gen_std.py:212
   # SYMBOL(unqualified_name, namespace, header)
-  print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
-symbol.headers[0]))
+  for header in AdditionalHeadersForIOSymbols(symbol):
+print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,

what about changing this to:
```
symbol.headers.extend(AdditionalHeadersForIOSymbols(symbol))
for header in symbol.headers:
  
```

(and also changing `AdditionalHeadersForIOSymbols` to only return additional 
headers and an empty list if there's none)

that way it'll be easier to augment symbol headers later on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143280

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


[PATCH] D107290: [RISCV] Add support for the vscale_range attribute

2023-02-06 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck abandoned this revision.
frasercrmck added a comment.
Herald added a subscriber: luke.

Superseded by D139873  amongst others


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107290

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-06 Thread Nathan James via Phabricator via cfe-commits
njames93 requested changes to this revision.
njames93 added inline comments.
This revision now requires changes to proceed.



Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp:186-187
+  traverse(TK_AsIs,
+   callExpr(anyOf(callee(functionDecl(hasName("::std::print"))),
+  callee(functionDecl(hasName("::std::format",
+hasAnyArgument(materializeTemporaryExpr(





Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp:188
+  callee(functionDecl(hasName("::std::format",
+hasAnyArgument(materializeTemporaryExpr(
+has(StringCStrCallExpr),

The limitation about only transforming the first argument can be alleviated by 
using the `forEachArgumentWithParam` matcher



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:129-131
+  arguments to ``std::print`` and ``std::format``. Note that only the first
+  such argument is currently reported so it may be necessary to run the
+  check multiple times to fix all of them.

Please address this needless restriction, see above comment



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp:336
+  // Ideally we'd fix both the second and fourth parameters here, but that 
doesn't work.
+  auto r2 = std::format("One:{} Two:{} Three:{}\n", s1.c_str(), s2, 
s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: redundant call to 'c_str' 
[readability-redundant-string-cstr]

Again this test case would need updating to handle applying all fixes


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

https://reviews.llvm.org/D143342

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


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/tools/include-mapping/gen_std.py:107-108
   symbols = cppreference_parser.GetSymbols(parse_pages)
-  
+  # C++ form of the C standard headers.
+  c_style_headers = {
+"",





Comment at: clang/tools/include-mapping/gen_std.py:162
 symbol.headers[0]))
+  # Handle C-compatibility symbols.
+  if symbol.headers[0] in c_style_headers:

what about having this logic as:
```
augmented_symbols = [symbol]
augmented_symbols.extend(GetCCompatibilitySymbols(symbol))
for s in augmented_symbols:
  ...
```

that way we can also encapsulate the rest of c-compat related logic into a more 
isolated place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

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


[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495036.
hokein marked an inline comment as done.
hokein added a comment.

address review comment: remove StdSymbolMapping in the CanonicalIncluedes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp

Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -36,8 +36,8 @@
   Language.C11 = true;
   CI.addSystemHeadersMapping(Language);
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("printf"));
-  EXPECT_EQ("", CI.mapSymbol("unknown_symbol"));
+  EXPECT_EQ("", CI.mapSymbol("printf", Language));
+  EXPECT_EQ("", CI.mapSymbol("unknown_symbol", Language));
 }
 
 TEST(CanonicalIncludesTest, CXXStandardLibrary) {
@@ -47,14 +47,14 @@
   CI.addSystemHeadersMapping(Language);
 
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("std::vector"));
-  EXPECT_EQ("", CI.mapSymbol("std::printf"));
+  EXPECT_EQ("", CI.mapSymbol("std::vector", Language));
+  EXPECT_EQ("", CI.mapSymbol("std::printf", Language));
   // std::move is ambiguous, currently always mapped to 
-  EXPECT_EQ("", CI.mapSymbol("std::move"));
+  EXPECT_EQ("", CI.mapSymbol("std::move", Language));
   // Unknown std symbols aren't mapped.
-  EXPECT_EQ("", CI.mapSymbol("std::notathing"));
+  EXPECT_EQ("", CI.mapSymbol("std::notathing", Language));
   // iosfwd declares some symbols it doesn't own.
-  EXPECT_EQ("", CI.mapSymbol("std::ostream"));
+  EXPECT_EQ("", CI.mapSymbol("std::ostream", Language));
   // And (for now) we assume it owns the others.
   auto InMemFS = llvm::makeIntrusiveRefCnt();
   FileManager Files(FileSystemOptions(), InMemFS);
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -837,7 +837,7 @@
   if (Opts.Includes) {
 QName = S->Scope;
 QName.append(S->Name);
-IncludeHeader = Opts.Includes->mapSymbol(QName);
+IncludeHeader = Opts.Includes->mapSymbol(QName, ASTCtx->getLangOpts());
 if (!IncludeHeader.empty()) {
   if (IncludeHeader.front() != '"' && IncludeHeader.front() != '<')
 IncludeHeader = HeaderFileURIs->toURI(IncludeHeader);
Index: clang-tools-extra/clangd/index/StdLib.cpp
===
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -67,7 +68,7 @@
 }
 
 std::string buildUmbrella(llvm::StringLiteral Mandatory,
-  std::vector Headers) {
+  llvm::ArrayRef Headers) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
 
@@ -80,13 +81,11 @@
   "#endif\n",
   Mandatory);
 
-  llvm::sort(Headers);
-  auto Last = std::unique(Headers.begin(), Headers.end());
-  for (auto Header = Headers.begin(); Header != Last; ++Header) {
+  for (auto Header : Headers) {
 OS << llvm::formatv("#if __has_include({0})\n"
 "#include {0}\n"
 "#endif\n",
-*Header);
+Header);
   }
   OS.flush();
   return Result;
@@ -102,20 +101,14 @@
   Lang L = langFromOpts(LO);
   switch (L) {
   case CXX:
-static std::string *UmbrellaCXX =
-new std::string(buildUmbrella(mandatoryHeader(L), {
-#define SYMBOL(Name, NameSpace, Header) #Header,
-#include "clang/Tooling/Inclusions/StdSymbolMap.inc"
-#undef SYMBOL
-  }));
+static std::string *UmbrellaCXX = new std::string(buildUmbrella(
+mandatoryHeader(L),
+tooling::stdlib::Header::all(tooling::stdlib::Lang::CXX)));
 return *UmbrellaCXX;
   case C:
-static std::string *UmbrellaC =
-new std::string(buildUmbrella(mandatoryHeader(L), {
-#define SYMBOL(Name, NameSpace, Header) #Header,
-#include "clang/Tooling/Inclusions/CSymbolMap.inc"
-#undef SYMBOL
-  }));
+st

[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.cpp:736
 void CanonicalIncludes::addSystemHeadersMapping(const LangOptions &Language) {
   if (Language.CPlusPlus) {
+static const auto *Symbols = []() {

kadircet wrote:
> what about getting rid of `StdSymbolMapping` completely and changing 
> `CanonicalIncludes::mapSymbol` to use `tooling::stdlib` ?
> only call site is through `SymbolCollector`, which has access to 
> `LangOptions`.
Yeah, good idea. This simplifies the code further, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

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


[PATCH] D143375: clang-tidy: Count template constructors in modernize-use-default-member-init

2023-02-06 Thread Marco Falke via Phabricator via cfe-commits
MarcoFalke created this revision.
MarcoFalke added a project: clang-tools-extra.
Herald added a subscriber: carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
MarcoFalke requested review of this revision.
Herald added a subscriber: cfe-commits.

The check should bomb out when there are multiple constructors. However, it 
didn't count template constructors.

Add a negative test case `TwoConstructorsTpl` and make it pass.

Also, add more test cases with templates that were already passing on `main`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143375

Files:
  clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
@@ -60,6 +60,20 @@
 int i;
 };
 
+struct TwoConstructorsTpl {
+  TwoConstructorsTpl() : i{7} {}
+  template  TwoConstructorsTpl(T, int) : i(8) {}
+  int i;
+};
+
+struct PositiveConstructorTpl {
+  template  PositiveConstructorTpl(T, int) : i(8) {}
+  // CHECK-FIXES: PositiveConstructorTpl(T, int)  {}
+  int i;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer 
for 'i'
+  // CHECK-FIXES: int i{8};
+};
+
 struct PositiveNotDefaultOOLInt {
   PositiveNotDefaultOOLInt(int);
   int i;
@@ -237,6 +251,14 @@
 NegativeTemplate nti;
 NegativeTemplate ntd;
 
+template  struct PositiveTemplate {
+  PositiveTemplate() : i(9) {}
+  // CHECK-FIXES: PositiveTemplate()  {}
+  int i;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer 
for 'i'
+  // CHECK-FIXES: int i{9};
+};
+
 struct NegativeDefaultMember {
   NegativeDefaultMember() {}
   int i = 2;
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -246,8 +246,12 @@
   // Check whether we have multiple hand-written constructors and bomb out, as
   // it is hard to reconcile their sets of member initializers.
   const auto *ClassDecl = cast(Field->getParent());
-  if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
-return !Ctor->isCopyOrMoveConstructor();
+  if (llvm::count_if(ClassDecl->decls(), [](const Decl *D) {
+if (const auto *Ctor = dyn_cast(D))
+  return !Ctor->isCopyOrMoveConstructor();
+if (const auto *FTD = dyn_cast(D))
+  return isa(FTD->getTemplatedDecl());
+return false;
   }) > 1)
 return;
 


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
@@ -60,6 +60,20 @@
 int i;
 };
 
+struct TwoConstructorsTpl {
+  TwoConstructorsTpl() : i{7} {}
+  template  TwoConstructorsTpl(T, int) : i(8) {}
+  int i;
+};
+
+struct PositiveConstructorTpl {
+  template  PositiveConstructorTpl(T, int) : i(8) {}
+  // CHECK-FIXES: PositiveConstructorTpl(T, int)  {}
+  int i;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
+  // CHECK-FIXES: int i{8};
+};
+
 struct PositiveNotDefaultOOLInt {
   PositiveNotDefaultOOLInt(int);
   int i;
@@ -237,6 +251,14 @@
 NegativeTemplate nti;
 NegativeTemplate ntd;
 
+template  struct PositiveTemplate {
+  PositiveTemplate() : i(9) {}
+  // CHECK-FIXES: PositiveTemplate()  {}
+  int i;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'i'
+  // CHECK-FIXES: int i{9};
+};
+
 struct NegativeDefaultMember {
   NegativeDefaultMember() {}
   int i = 2;
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -246,8 +246,12 @@
   // Check whether we have multiple hand-written constructors and bomb out, as
   // it is hard to reconcile their sets of member initializers.
   const auto *ClassDecl = cast(Field->getParent());
-  if (llvm::count_if(ClassDecl->ctors(), [](const CXXConstructorDecl *Ctor) {
-return !Ctor->isCopyOrMoveConstructor();
+  if (llvm::count_if(ClassDecl->decls(), [](const Decl *D) {
+if (const auto *Ctor = dyn_cast(D))
+  return !Ctor->isCopyOrMoveConstructor();
+if (const auto

[PATCH] D143194: [clang][analyzer] Make messages of StdCLibraryFunctionsChecker user-friendly

2023-02-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 495042.
balazske added a comment.

Replaced "of function" with "to" in checker messages.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143194

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
  clang/test/Analysis/stream-note.c
  clang/test/Analysis/stream-stdlibraryfunctionargs.c

Index: clang/test/Analysis/stream-stdlibraryfunctionargs.c
===
--- clang/test/Analysis/stream-stdlibraryfunctionargs.c
+++ clang/test/Analysis/stream-stdlibraryfunctionargs.c
@@ -18,37 +18,31 @@
 void test_fopen(void) {
   FILE *fp = fopen("path", "r");
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}} any-warning{{FALSE}}
-  fclose(fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
-  // stdargs-note{{The 1st argument should not be NULL}}
+  fclose(fp); // stdargs-warning{{should not be NULL}}
 }
 
 void test_tmpfile(void) {
   FILE *fp = tmpfile();
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}} any-warning{{FALSE}}
-  fclose(fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
-  // stdargs-note{{The 1st argument should not be NULL}}
+  fclose(fp); // stdargs-warning{{should not be NULL}}
 }
 
 void test_fclose(void) {
   FILE *fp = tmpfile();
-  fclose(fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
-  // stdargs-note{{The 1st argument should not be NULL}}
+  fclose(fp); // stdargs-warning{{should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
 }
 
 void test_freopen(void) {
   FILE *fp = tmpfile();
-  fp = freopen("file", "w", fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
- // stdargs-note{{The 3rd argument should not be NULL}}
-  fclose(fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
-  // stdargs-note{{The 1st argument should not be NULL}}
+  fp = freopen("file", "w", fp); // stdargs-warning{{should not be NULL}}
+  fclose(fp); // stdargs-warning{{should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
 }
 
 void test_fread(void) {
   FILE *fp = tmpfile();
-  size_t ret = fread(buf, size, n, fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
-// stdargs-note{{The 4th argument should not be NULL}}
+  size_t ret = fread(buf, size, n, fp); // stdargs-warning{{The 4th argument to 'fread' should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
   clang_analyzer_eval(ret <= n); // any-warning{{TRUE}}
   clang_analyzer_eval(ret == n); // any-warning{{TRUE}} any-warning{{FALSE}}
@@ -58,8 +52,7 @@
 
 void test_fwrite(void) {
   FILE *fp = tmpfile();
-  size_t ret = fwrite(buf, size, n, fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
-// stdargs-note{{The 4th argument should not be NULL}}
+  size_t ret = fwrite(buf, size, n, fp); // stdargs-warning{{The 4th argument to 'fwrite' should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
   clang_analyzer_eval(ret <= n); // any-warning{{TRUE}}
   clang_analyzer_eval(ret == n); // any-warning{{TRUE}} any-warning{{FALSE}}
@@ -69,24 +62,21 @@
 
 void test_fseek(void) {
   FILE *fp = tmpfile();
-  fseek(fp, 0, 0); // stdargs-warning{{Function argument constraint is not satisfied}} \
-   // stdargs-note{{The 1st argument should not be NULL}}
+  fseek(fp, 0, 0); // stdargs-warning{{should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
   fclose(fp);
 }
 
 void test_ftell(void) {
   FILE *fp = tmpfile();
-  ftell(fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
- // stdargs-note{{The 1st argument should not be NULL}}
+  ftell(fp); // stdargs-warning{{should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
   fclose(fp);
 }
 
 void test_rewind(void) {
   FILE *fp = tmpfile();
-  rewind(fp); // stdargs-warning{{Function argument constraint is not satisfied}} \
-  // stdargs-note{{The 1st argument should not be NULL}}
+  rewind(fp); // stdargs-warning{{should not be NULL}}
   clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}
   fclose(fp);
 }
@@ -94,8 +84,7 @@
 void test_fgetpos(void) {
   FILE *fp = tmpfile();
   fpos_t pos;
-  fgetpos(fp, &pos); // stdargs-warning

[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/include/clang/Tooling/Inclusions/StdAlternativeHeaderMap.inc:3
+//
+// This is a hand-curated list for C++ symbols (e.g. provided by multiple
+// headers), to address the short comings of cppreference or automated

`This is a hand-curated list for C++ symbols` reads like we're planning to put 
all special C++ symbols into this file, rather than just the ones that are 
provided by alternative headers. that's the reason why i mentioned it as `This 
is a hand-curated list for symbols provided by multiple headers` specifically.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

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


[PATCH] D143280: [include-mapping] Better #includes support for std input/output symbols

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495047.
hokein marked 2 inline comments as done.
hokein added a comment.

address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143280

Files:
  clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
  clang/tools/include-mapping/gen_std.py

Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -40,6 +40,7 @@
 import os
 import sys
 
+
 CODE_PREFIX = """\
 //===-- gen_std.py generated file ---*- C++ -*-===//
 //
@@ -66,6 +67,108 @@
   required=True) 
   return parser.parse_args()
 
+def AdditionalHeadersForIOSymbols(symbol):
+  # IO-related symbols declared in the  header, per C++
+  # [iosfwd.syn 31.3.1]:
+  iosfwd_symbols = [
+  'basic_ios',
+  'basic_streambuf',
+  'basic_istream',
+  'basic_ostream',
+  'basic_iostream',
+
+  'basic_stringbuf',
+  'basic_istringstream',
+  'basic_ostringstream',
+  'basic_stringstream',
+
+  'basic_spanbuf',
+  'basic_ispanstream',
+  'basic_ospanstream',
+  'basic_spanstream',
+
+  'basic_filebuf',
+  'basic_ifstream',
+  'basic_ofstream',
+  'basic_fstream',
+
+  'basic_syncbuf',
+  'basic_osyncstream',
+
+  'istreambuf_iterator',
+  'ostreambuf_iterator',
+
+  'ios',
+  'wios',
+
+  'streambuf',
+  'istream',
+  'ostream',
+  'iostream',
+
+  'stringbuf',
+  'istringstream',
+  'ostringstream',
+  'stringstream',
+
+  'spanbuf',
+  'ispanstream',
+  'ospanstream',
+  'spanstream',
+
+  'filebuf',
+  'ifstream',
+  'ofstream',
+  'fstream',
+
+  'syncbuf',
+  'osyncstream',
+
+  'wstreambuf',
+  'wistream',
+  'wostream',
+  'wiostream',
+
+  'wstringbuf',
+  'wistringstream',
+  'wostringstream',
+  'wstringstream',
+
+  'wspanbuf',
+  'wispanstream',
+  'wospanstream',
+  'wspanstream',
+
+  'wfilebuf',
+  'wifstream',
+  'wofstream',
+  'wfstream',
+
+  'wsyncbuf',
+  'wosyncstream',
+
+  'fpos',
+  'streampos',
+  'wstreampos',
+  'u8streampos',
+  'u16streampos',
+  'u32streampos',
+  ]
+  assert(len(symbol.headers) == 1)
+  sym_header = symbol.headers[0]
+  headers = []
+  #  is preferred than 
+
+  #  is an alternative of , , , .
+  # per C++ [iostream.syn 31.4.1]
+  if sym_header in ["", "", "", ""]:
+headers.append("")
+
+  if symbol.name in iosfwd_symbols:
+headers.append("")
+
+  return headers
+
 
 def main():
   args = ParseArg()
@@ -109,8 +212,10 @@
   for symbol in symbols:
 if len(symbol.headers) == 1:
   # SYMBOL(unqualified_name, namespace, header)
-  print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
-symbol.headers[0]))
+  symbol.headers.extend(AdditionalHeadersForIOSymbols(symbol))
+  for header in symbol.headers:
+print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
+  header))
 elif len(symbol.headers) == 0:
   sys.stderr.write("No header found for symbol %s\n" % symbol.name)
 else:
Index: clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
===
--- clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
+++ clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
@@ -149,32 +149,56 @@
 SYMBOL(barrier, std::, )
 SYMBOL(basic_common_reference, std::, )
 SYMBOL(basic_filebuf, std::, )
+SYMBOL(basic_filebuf, std::, )
 SYMBOL(basic_format_arg, std::, )
 SYMBOL(basic_format_args, std::, )
 SYMBOL(basic_format_context, std::, )
 SYMBOL(basic_format_parse_context, std::, )
 SYMBOL(basic_fstream, std::, )
+SYMBOL(basic_fstream, std::, )
 SYMBOL(basic_ifstream, std::, )
+SYMBOL(basic_ifstream, std::, )
 SYMBOL(basic_ios, std::, )
+SYMBOL(basic_ios, std::, )
+SYMBOL(basic_ios, std::, )
 SYMBOL(basic_iostream, std::, )
+SYMBOL(basic_iostream, std::, )
+SYMBOL(basic_iostream, std::, )
 SYMBOL(basic_ispanstream, std::, )
+SYMBOL(basic_ispanstream, std::, )
 SYMBOL(basic_istream, std::, )
+SYMBOL(basic_istream, std::, )
+SYMBOL(basic_istream, std::, )
 SYMBOL(basic_istringstream, std::, )
+SYMBOL(basic_istringstream, std::, )
 SYMBOL(basic_ofstream, std::, )
+SYMBOL(basic_ofstream, std::, )
 SYMBOL(basic_ospanstream, std::, )
+SYMBOL(basic_ospanstream, std::, )
 SYMBOL(basic_ostream, std::, )
+SYMBOL(basic_ostream, std::, )
+SYMBOL(basic_ostream, std::, )
 SYMBOL(basic_ostringstream, std::, )
+SYMBOL(basic_ostringstream, std::, )
 SYMBOL(basic_osyncstream, std::, )
+SYMBOL(basic_osyncstream, std::, )
 SYMBOL(basic_regex, std::, )
 SYMBOL(basic_spanbuf, std::, )
+SYMBOL(

[PATCH] D143280: [include-mapping] Better #includes support for std input/output symbols

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/tools/include-mapping/gen_std.py:160
+  headers = [sym_header]
+  if symbol.name in iosfwd_symbols:
+headers.append("")

kadircet wrote:
> i think putting `iostream` before `iosfwd` in the alternative list makes more 
> sense. WDYT?
sounds good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143280

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


[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.cpp:711
+return "";
+  // There are multiple headers for size_t, pick one.
+  if (QName == "std::size_t")

i think the comment is misleading. as if we had some alternatives in the 
tooling::stdlib, it would already pick one for us. the issue is we don't have 
it in the mapping at all.



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.cpp:717
+  Scope, Name,
+  L.CPlusPlus ? tooling::stdlib::Lang::CXX : tooling::stdlib::Lang::C))
+return StdSym->header().name();

this is a slight behaviour change. we'd actually return `""` whenever the 
language isn't CPlusPlus or C11. could you retain that behaviour?



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:840
 QName.append(S->Name);
-IncludeHeader = Opts.Includes->mapSymbol(QName);
+IncludeHeader = Opts.Includes->mapSymbol(QName, ASTCtx->getLangOpts());
 if (!IncludeHeader.empty()) {

nit: rather than creating a new copy of the symbol name everytime, i'd also 
update the `mapSymbol` interface to take in `StringRef Scope, StringRef Name` 
instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

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


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495056.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

Files:
  clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
  clang/tools/include-mapping/gen_std.py

Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -41,6 +41,7 @@
 import datetime
 import os
 import sys
+import re
 
 CODE_PREFIX = """\
 //===-- gen_std.py generated file ---*- C++ -*-===//
@@ -68,6 +69,64 @@
   required=True) 
   return parser.parse_args()
 
+def GetCCompatibilitySymbols(symbol):
+   # C++ form of the C standard headers.
+  c_compat_headers = {
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+  }
+  # C++ [support.c.headers.other] 17.14.7
+  #..., behaves as if each name placed in the standard library namespace by
+  #the corresponding  header is placed within the global namespace
+  #scope, except for the functions described in [sf.cmath], the
+  #std​::​lerp function overloads ([c.math.lerp]), the declaration of
+  #std​::​byte ([cstddef.syn]), and the functions and function templates
+  #described in [support.types.byteops].
+  exception_symbols = {
+"(assoc_)?laguerre[f|l]?",
+"(assoc_|sph_)?legendre[f|l]?",
+"beta[f|l]?",
+"(comp_)?ellint_[1-3][f|l]?",
+"(cyl_|sph_)?bessel_[i-k][f|l]?",
+"(cyl_|sph_)?neumann[f|l]?",
+"expint[f|l]?",
+"hermite[f|l]?",
+"riemann_zeta[f|l]?",
+"lerp",
+"byte",
+  }
+  assert(len(symbol.headers) == 1)
+  results = []
+  header = symbol.headers[0]
+  if header in c_compat_headers:
+#  => 
+c_header = "<" + header[2:-1] +  ".h>"
+if not any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+  if symbol.namespace != None:
+# avoid printing duplicated entries, for C macros!
+results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
+# print("SYMBOL(%s, None, %s)" % (symbol.name, symbol.headers[0]))
+  results.append(cppreference_parser.Symbol(symbol.name, None, [c_header]))
+  return results
 
 def main():
   args = ParseArg()
@@ -88,6 +147,7 @@
   (symbol_index_root, "pmr.html", "std::pmr::"),
   (symbol_index_root, "regex_constants.html", "std::regex_constants::"),
   (symbol_index_root, "this_thread.html", "std::this_thread::"),
+  (symbol_index_root, "macro.html", None),
 ]
   elif args.symbols == 'cpp_removed':
 page_root = os.path.join(args.cppreference, "en", "cpp")
@@ -111,9 +171,12 @@
   print(CODE_PREFIX % (args.symbols.upper(), cppreference_modified_date))
   for symbol in symbols:
 if len(symbol.headers) == 1:
-  # SYMBOL(unqualified_name, namespace, header)
-  print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
-symbol.headers[0]))
+  augmented_symbols = [symbol]
+  augmented_symbols.extend(GetCCompatibilitySymbols(symbol))
+  for s in augmented_symbols:
+# SYMBOL(unqualified_name, namespace, header)
+print("SYMBOL(%s, %s, %s)" % (s.name, s.namespace,
+  s.headers[0]))
 elif len(symbol.headers) == 0:
   sys.stderr.write("No header found for symbol %s\n" % symbol.name)
 else:
Index: clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
===
--- clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
+++ clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
@@ -10,14 +10,30 @@
 //===--===//
 
 SYMBOL(FILE, std::, )
+SYMBOL(FILE, None, )
+SYMBOL(FILE, None, )
 SYMBOL(_Exit, std::, )
+SYMBOL(_Exit, None, )
+SYMBOL(_Exit, None, )
 SYMBOL(accumulate, std::, )
 SYMBOL(acos, std::, )
+SYMBOL(acos, None, )
+SYMBOL(acos, None, )
 SYMBOL(acosf, std::, )
+SYMBOL(acosf, None, )
+SYMBOL(acosf, None, )
 SYMBOL(acosh, std::, )
+SYMBOL(acosh, None, )
+SYMBOL(acosh, None, )
 SYMBOL(acoshf, std::, )
+SYMBOL(acoshf, None, )
+SYMBOL(acoshf, None, )
 SYMBOL(acoshl, std::, )
+SYMBOL(acoshl, None, )
+SYMBOL(acoshl, None, )
 SYMBOL(acosl, std::, )
+SYMBOL(acosl, None, )
+SYMBOL(acosl, None, )
 SYMBOL(add_const, std::, )
 SYMBOL(add_const_t, std::, )
 SYMBOL(add_cv, std::, )
@@ -39,6 +55,8 @@
 SYMBOL(align, std::, )
 SYMBOL(align_val_t, std::, )
 SYMBOL(aligned_alloc, std::, )
+SYMBOL(aligned_alloc, None, )
+SYMBOL(aligned_alloc, None, )
 SYMBOL(aligned_storage, std::, )
 SYMBOL(aligned_storage_t, std::, )
 SYMBOL(aligned_union, std::, )

[PATCH] D142014: [clangd] fix wrong CalleeArgInfo in the hover

2023-02-06 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry added a comment.

Thanks for the review! @kadircet

Would you mind having a look at if there're any concerns about the current code 
change, @nridge, @tom-anders, and @adamcz? Thanks a lot!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142014

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


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

2023-02-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

> Member pointers (for functions or for data) are weird in that they're not the 
> typical pointer width. They're actually a pointer and between one-to-three 
> other fields in a trenchcoat, depending on the circumstances. You generally 
> need the function pointer, but you also may need various offsets (to this, to 
> the vtable, etc). There's some more information about how it's done in MSVC 
> (which is different from Itanium ABI, but we can do what we want for the 
> constant expression interpreter): https://rants.vastheman.com/2021/09/21/msvc/
>
> I don't think there's a problem with `FunctionPointer` per se, I'm more 
> wondering are you planning to also add a `MemberPointer` type or are you 
> planning to reuse `FunctionPointer` to handle function members (and 
> presumably something else for data members)?
>
> As for virtual functions in general, the standard has rules: 
> http://eel.is/c++draft/expr.const#5.6 and http://eel.is/c++draft/expr.const#7

I was thinking that the `dynamicDispatch` in https://godbolt.org/z/rf9Ks77Wo 
would be a good reproducer since the actual function to call is only known when 
calling `dynamicDispatch()`, but that example already works when doing a few 
changes to `classify()` the right types and adding a `if (BO->isPtrMemOP()) { 
return visit(RHS); }` to `VisitBinaryOperator()`.


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

https://reviews.llvm.org/D141472

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


[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-06 Thread serge via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6fa2abf90886: Lazyly initialize uncommon toolchain detector 
(authored by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D142606?vs=494927&id=495058#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142606

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/lib/Driver/ToolChains/LazyDetector.h
  clang/lib/Driver/ToolChains/Linux.cpp

Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -681,23 +681,23 @@
 
 void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
-  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
+  CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
 }
 
 void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs,
   ArgStringList &CC1Args) const {
-  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
+  RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
 void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
   CmdArgs.push_back(
-  Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()));
+  Args.MakeArgString(StringRef("-L") + RocmInstallation->getLibPath()));
 
   if (Args.hasFlag(options::OPT_offload_add_rpath,
options::OPT_no_offload_add_rpath, false))
 CmdArgs.append(
-{"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
+{"-rpath", Args.MakeArgString(RocmInstallation->getLibPath())});
 
   CmdArgs.push_back("-lamdhip64");
 }
Index: clang/lib/Driver/ToolChains/LazyDetector.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/LazyDetector.h
@@ -0,0 +1,45 @@
+//===--- LazyDetector.h - Lazy ToolChain Detection --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+#include 
+
+namespace clang {
+
+/// Simple wrapper for toolchain detector with costly initialization. This
+/// delays the creation of the actual detector until its first usage.
+
+template  class LazyDetector {
+  const driver::Driver &D;
+  const llvm::Triple &Triple;
+  const llvm::opt::ArgList &Args;
+
+  std::optional Detector;
+
+public:
+  LazyDetector(const driver::Driver &D, const llvm::Triple &Triple,
+   const llvm::opt::ArgList &Args)
+  : D(D), Triple(Triple), Args(Args) {}
+  T *operator->() {
+if (!Detector)
+  Detector.emplace(D, Triple, Args);
+return &*Detector;
+  }
+  const T *operator->() const {
+return const_cast(
+const_cast(*this).operator->());
+  }
+};
+
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -314,7 +314,7 @@
 
 void HIPAMDToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
 ArgStringList &CC1Args) const {
-  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
+  RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
 SanitizerMask HIPAMDToolChain::getSupportedSanitizers() const {
@@ -343,7 +343,7 @@
   ArgStringList LibraryPaths;
 
   // Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
-  for (StringRef Path : RocmInstallation.getRocmDeviceLibPathArg())
+  for (StringRef Path : RocmInstallation->getRocmDeviceLibPathArg())
 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
 
   addDirectoryList(DriverArgs, LibraryPaths, "", "HIP_DEVICE_LIB_PATH");
@@ -365,7 +365,7 @@
   getDriver().Diag(diag::err_drv_no_such_file) << BCName;
 });
   } else {
-if (!RocmInstallation.hasDeviceLibrary()) {
+if (!RocmInstallation->hasDeviceLibrary()) {
   getDriver().Diag(diag::err_drv_no_ro

[clang] 6fa2abf - Lazyly initialize uncommon toolchain detector

2023-02-06 Thread via cfe-commits

Author: serge-sans-paille
Date: 2023-02-06T12:03:00+01:00
New Revision: 6fa2abf90886f18472c87bc9bffbcdf4f73c465e

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

LOG: Lazyly initialize uncommon toolchain detector

Cuda and rocm toolchain detectors are currently run unconditionally,
while their result may not be used at all. Make their initialization
lazy so that the discovery code is not run in common cases.

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

Added: 
clang/lib/Driver/ToolChains/LazyDetector.h

Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Gnu.h
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/lib/Driver/ToolChains/Linux.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 52021901b9bf8..a25bea951388c 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -701,7 +701,7 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList 
&DriverArgs,
 ROCMToolChain::ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
  const ArgList &Args)
 : AMDGPUToolChain(D, Triple, Args) {
-  RocmInstallation.detectDeviceLibrary();
+  RocmInstallation->detectDeviceLibrary();
 }
 
 void AMDGPUToolChain::addClangTargetOptions(
@@ -790,11 +790,11 @@ void ROCMToolChain::addClangTargetOptions(
   const StringRef GpuArch = getGPUArch(DriverArgs);
   auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
   const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
-  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
+  StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
   auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
-  if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
-   ABIVer))
+  if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
+ABIVer))
 return;
 
   bool Wave64 = isWave64(DriverArgs, Kind);
@@ -813,10 +813,10 @@ void ROCMToolChain::addClangTargetOptions(
 
   // Add the OpenCL specific bitcode library.
   llvm::SmallVector BCLibs;
-  BCLibs.push_back(RocmInstallation.getOpenCLPath().str());
+  BCLibs.push_back(RocmInstallation->getOpenCLPath().str());
 
   // Add the generic set of libraries.
-  BCLibs.append(RocmInstallation.getCommonBitcodeLibs(
+  BCLibs.append(RocmInstallation->getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, false));
 
@@ -875,11 +875,11 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   auto Kind = llvm::AMDGPU::parseArchAMDGCN(GPUArch);
   const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
 
-  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
+  StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
   auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
-  if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
-   ABIVer))
+  if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
+ABIVer))
 return {};
 
   // If --hip-device-lib is not set, add the default bitcode libraries.
@@ -900,7 +900,7 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt, true);
   bool Wave64 = isWave64(DriverArgs, Kind);
 
-  return RocmInstallation.getCommonBitcodeLibs(
+  return RocmInstallation->getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }

diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 68d351af22603..b012b7cb72937 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -160,7 +160,7 @@ AMDGPUOpenMPToolChain::getDeviceLibs(const 
llvm::opt::ArgList &Args) const {
   if (Args.hasArg(options::OPT_nogpulib))
 return {};
 
-  if (!RocmInstallation.hasDeviceLibrary()) {
+  if (!RocmInstallation->hasDeviceLibrary()) {
 getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 0;
 return {};
   }

diff  --git a/c

[PATCH] D143144: [clang][lex] Add TryGrowLexerBuffer/SourceFileGrower

2023-02-06 Thread Sunho Kim via Phabricator via cfe-commits
sunho created this revision.
Herald added a project: All.
sunho retitled this revision from "asdfasdf" to "[clang][lex] Add 
TryExpandBuffer callback".
sunho edited the summary of this revision.
sunho updated this revision to Diff 494978.
sunho added a comment.
sunho updated this revision to Diff 495037.
sunho updated this revision to Diff 495039.
sunho retitled this revision from "[clang][lex] Add TryExpandBuffer callback" 
to "[clang][lex] Add TryGrowLexerBuffer/SourceFileGrower".
sunho edited the summary of this revision.
sunho edited the summary of this revision.
sunho edited the summary of this revision.
sunho edited the summary of this revision.
sunho published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update


sunho added a comment.

Update


sunho added a comment.

Update


Add TryGrowLexerBuffer to Lexer and SourceFileGrower to Preprocessor that can 
be used to grow the source code buffer when Lexer reaches the eof of the buffer.

Since clang-repl receive source code incrementally line by line, we need to 
grow source code buffer. This change adds the interfaces to Lexer/Preprocessor 
in order to accommodate this need. If SourceFileGrower interface is registered 
to Preprocessor, it will call TryGrowFile method when Lexer reached eof. Inside 
this method, the user can grow the file and return true to request Lexer to 
continue the lexing from the last point.

When Lexer reaches eof it will call TryGrowLexerBuffer callback specified in 
the constructor to try growing buffer and if it got new buffer, it will 
continue the lexing from the last point. Preprocessor registers 
TryGrowLexerBuffer callback in order to implement handling of SourceFileGrower.

Note that practically all the code changes will not affect the AOT clang world 
since they are all disabled when Preprocessor doesn't have SourceFileGrower 
instance.

NOTE: This is part 2 and 3 of 
https://discourse.llvm.org/t/rfc-flexible-lexer-buffering-for-handling-incomplete-input-in-interactive-c-c/64180


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143144

Files:
  clang/include/clang/Lex/Lexer.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/unittests/Lex/LexerTest.cpp

Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -26,9 +26,12 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
+#include 
 #include 
 
 namespace {
@@ -49,12 +52,7 @@
 Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
   }
 
-  std::unique_ptr CreatePP(StringRef Source,
- TrivialModuleLoader &ModLoader) {
-std::unique_ptr Buf =
-llvm::MemoryBuffer::getMemBuffer(Source);
-SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
-
+  std::unique_ptr CreatePP(TrivialModuleLoader &ModLoader) {
 HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
 Diags, LangOpts, Target.get());
 std::unique_ptr PP = std::make_unique(
@@ -63,6 +61,14 @@
 /*IILookup =*/nullptr,
 /*OwnsHeaderSearch =*/false);
 PP->Initialize(*Target);
+return PP;
+  }
+
+  std::unique_ptr CreatePP(StringRef Source, TrivialModuleLoader &ModLoader) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(Source);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+std::unique_ptr PP = CreatePP(ModLoader);
 PP->EnterMainSourceFile();
 return PP;
   }
@@ -660,4 +666,59 @@
   }
   EXPECT_TRUE(ToksView.empty());
 }
+
+TEST_F(LexerTest, BasicSourceFileGrower) {
+  std::deque SourceLines = {
+"int main() {",
+"  return 0;",
+"}"
+  };
+
+  TrivialModuleLoader ModLoader;
+  PP = CreatePP(ModLoader);
+  auto &SM = PP->getSourceManager();
+
+  struct FileGrower : public SourceFileGrower {
+FileGrower(SourceManager& SM, std::deque SourceLines) : SM(SM), SourceLines(SourceLines) {
+  FE = SM.getFileManager().getVirtualFile("main.cpp", 1024, 0);
+  CurFileID = SM.createFileID(FE, SourceLocation(), SrcMgr::C_User);
+  SM.overrideFileContents(FE, llvm::MemoryBufferRef("", ""));
+}
+~FileGrower() = default;
+
+bool TryGrowFile(FileID FileID) override {
+  if (FileID != CurFileID)
+return false;
+  if (SourceLines.empty())
+return false;
+  CurStr += SourceLines.front();
+  CurStr.push_back('\n');
+  SourceLines.pop_front();
+  CurBuf = llvm::MemoryBuffer::getMemBuffer(CurStr);
+  SM.overrideFileContents(FE, CurBuf->getMemBufferRef());
+  return true;
+}
+SourceManager& SM;
+std

[PATCH] D143148: [clang-repl] Add basic multiline input support

2023-02-06 Thread Sunho Kim via Phabricator via cfe-commits
sunho created this revision.
Herald added a project: All.
sunho retitled this revision from "Add multiline support in clang-repl" to 
"[clang-repl] Add basic multiline support".
sunho edited the summary of this revision.
sunho updated this revision to Diff 494983.
sunho added a comment.
sunho updated this revision to Diff 494985.
sunho added a comment.
sunho updated this revision to Diff 495041.
sunho added a comment.
sunho updated this revision to Diff 495043.
sunho updated this revision to Diff 495044.
sunho updated this revision to Diff 495054.
sunho retitled this revision from "[clang-repl] Add basic multiline support" to 
"[clang-repl] Add basic multiline input support".
sunho edited the summary of this revision.
sunho published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update


sunho added a comment.

Update


sunho added a comment.

Update


sunho added a comment.

Update


Add basic multi-line input support to clang-repl by using newly available 
SourceFileGrower interface of Preprocessor.

Compared to cling, this change uses fully fledged clang preprocessor (not 
MetaLexer) so it supports very complicated macro expressions.

NOTE: this is the related to 
https://discourse.llvm.org/t/rfc-flexible-lexer-buffering-for-handling-incomplete-input-in-interactive-c-c/64180


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143148

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/multiline-func-macro-brace-error.cpp
  clang/test/Interpreter/multiline-func-macro-brace.cpp
  clang/test/Interpreter/multiline-func.cpp
  clang/test/Interpreter/multiline-ifdef.cpp
  clang/tools/clang-repl/ClangRepl.cpp

Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -124,7 +124,8 @@
 continue;
   }
 
-  if (auto Err = Interp->ParseAndExecute(*Line)) {
+  if (auto Err =
+  Interp->ParseAndExecute(*Line, [&]() { return LE.readLine(); })) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
 HasError = true;
   }
Index: clang/test/Interpreter/multiline-ifdef.cpp
===
--- /dev/null
+++ clang/test/Interpreter/multiline-ifdef.cpp
@@ -0,0 +1,43 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl 2>&1 | FileCheck %s
+// Check if complex multiline ifdef directive is working.
+extern "C" int printf(const char *, ...);
+
+#define ___DEFINED_SYMBOL
+
+#ifdef ___DEFINED_SYMBOL
+int test_ifdef_one() {
+  printf("Simple multiline ifdef\n");
+}
+#endif
+// CHECK: Simple multiline ifdef
+
+#ifdef ___DEFINED_SYMBOL
+#ifndef ___DEFINED_SYMBOL
+int test_ifdef_two() {
+  printf("Wrong\n");
+}
+#endif
+#ifdef ___DEFINED_SYMBOL
+int test_ifdef_two() {
+  printf("Multiline ifdef two stack\n");
+}
+#endif
+#endif
+// CHECK-NEXT: Multiline ifdef two stack
+
+#ifdef ___DEFINED_SYMBOL
+#ifdef ___DEFINED_SYMBOL
+#ifdef ___DEFINED_SYMBOL
+#ifdef ___DEFINED_SYMBOL
+int test_ifdef_four() {
+  printf("Multiline ifdef four stack\n");
+}
+#endif
+#endif
+#endif
+#endif
+// CHECK-NEXT: Multiline ifdef four stack
+
+%quit
\ No newline at end of file
Index: clang/test/Interpreter/multiline-func.cpp
===
--- /dev/null
+++ clang/test/Interpreter/multiline-func.cpp
@@ -0,0 +1,16 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// Check a multiline function is parsed and executed correctly.
+extern "C" int printf(const char *, ...);
+int test_multiline_function() {
+  printf("Multiline\n");
+  printf("Function\n");
+  return 0;
+}
+
+auto r1 = test_multiline_function();
+// CHECK: Multiline
+// CHECK-NEXT: Function
+
+% quit
\ No newline at end of file
Index: clang/test/Interpreter/multiline-func-macro-brace.cpp
===
--- /dev/null
+++ clang/test/Interpreter/multiline-func-macro-brace.cpp
@@ -0,0 +1,53 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// Check a brace counting is not broken by introduction of macro directives.
+// Brace counting is done to support multiline functions.
+extern "C" int printf(const char *, ...);
+
+#define ___DEFINED_SYMBOL
+
+int test_multiline_brace_count_simple() {
+#ifdef ___UNDEFINED_SYMBOL
+  {
+#else
+  printf("Simple multiline brace count\n");
+#endif
+return 0;
+  }
+  auto r1 = test_multiline_brace_count_simple();
+  // CHECK: Simple multiline brace count
+
+  int test_multiline_brace_count_defined() {
+#ifdef ___DEFINED_SYMBOL
+printf(

[PATCH] D142630: [clang][Interp] Implement virtual function calls

2023-02-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 495059.

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

https://reviews.llvm.org/D142630

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Context.h
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpState.h
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 // RUN: %clang_cc1 -verify=ref -std=c++14 %s
+// RUN: %clang_cc1 -verify=ref -std=c++20 %s
 // RUN: %clang_cc1 -verify=ref -triple i686 %s
 
 struct BoolPair {
@@ -286,6 +288,7 @@
 };
 
 namespace DeriveFailures {
+#if __cplusplus < 202002L
   struct Base { // ref-note 2{{declared here}}
 int Val;
   };
@@ -301,10 +304,12 @@
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
// expected-error {{must be initialized by a constant expression}}
+
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
  // ref-note {{initializer of 'D' is not a constant expression}} \
  // expected-error {{not an integral constant expression}} \
  // expected-note {{read of object outside its lifetime}}
+#endif
 
   struct AnotherBase {
 int Val;
@@ -354,3 +359,82 @@
   static_assert(getS(true).a == 12, "");
   static_assert(getS(false).a == 13, "");
 };
+
+#if __cplusplus >= 202002L
+namespace VirtualCalls {
+namespace Obvious {
+
+  class A {
+  public:
+constexpr A(){}
+constexpr virtual int foo() {
+  return 3;
+}
+  };
+  class B : public A {
+  public:
+constexpr int foo() override {
+  return 6;
+}
+  };
+
+  constexpr int getFooB(bool b) {
+A *a;
+A myA;
+B myB;
+
+if (b)
+  a = &myA;
+else
+  a = &myB;
+
+return a->foo();
+  }
+  static_assert(getFooB(true) == 3, "");
+  static_assert(getFooB(false) == 6, "");
+}
+
+namespace MultipleBases {
+  class A {
+  public:
+constexpr virtual int getInt() const { return 10; }
+  };
+  class B {
+  public:
+  };
+  class C : public A, public B {
+  public:
+constexpr int getInt() const override { return 20; }
+  };
+
+  constexpr int callGetInt(const A& a) { return a.getInt(); }
+  static_assert(callGetInt(C()) == 20, "");
+  static_assert(callGetInt(A()) == 10, "");
+}
+
+namespace Destructors {
+  class Base {
+  public:
+int i;
+constexpr Base(int &i) : i(i) {i++;}
+constexpr virtual ~Base() {i--;}
+  };
+
+  class Derived : public Base {
+  public:
+constexpr Derived(int &i) : Base(i) {}
+constexpr virtual ~Derived() {i--;}
+  };
+
+  constexpr int test() {
+int i = 0;
+Derived d(i);
+return i;
+  }
+  static_assert(test() == 1);
+}
+
+
+
+};
+#endif
Index: clang/lib/AST/Interp/InterpState.h
===
--- clang/lib/AST/Interp/InterpState.h
+++ clang/lib/AST/Interp/InterpState.h
@@ -86,6 +86,8 @@
 return M ? M->getSource(F, PC) : F->getSource(PC);
   }
 
+  Context &getContext() const { return Ctx; }
+
 private:
   /// AST Walker state.
   State &Parent;
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1509,6 +1509,22 @@
 
 if (S.checkingPotentialConstantExpression())
   return false;
+
+// For a virtual call, we need to get the right function here.
+if (Func->isVirtual()) {
+  // Our ThisPtr has the decl of the right type at this point,
+  // so we just need to find the function to call.
+  const CXXRecordDecl *DynamicDecl =
+  ThisPtr.getDeclDesc()->getType()->getAsCXXRecordDecl();
+  const CXXRecordDecl *StaticDecl =
+  cast(Func->getParentDecl());
+  const CXXMethodDecl *InitialFunction =
+  cast(Func->getDecl());
+  const CXXMethodDecl *Overrider = S.getContext().getOverridingFunction(
+  DynamicDecl, StaticDecl, InitialFunction);
+  if (Overrider != InitialFunction)
+Func = S.P.getFunction(Overrider);
+}
   }
 
   if (!CheckCallable(S, PC, Func))
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Fu

[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495065.
hokein marked 2 inline comments as done.
hokein added a comment.

address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp

Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -36,8 +36,8 @@
   Language.C11 = true;
   CI.addSystemHeadersMapping(Language);
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("printf"));
-  EXPECT_EQ("", CI.mapSymbol("unknown_symbol"));
+  EXPECT_EQ("", CI.mapSymbol("", "printf", Language));
+  EXPECT_EQ("", CI.mapSymbol("", "unknown_symbol", Language));
 }
 
 TEST(CanonicalIncludesTest, CXXStandardLibrary) {
@@ -47,14 +47,14 @@
   CI.addSystemHeadersMapping(Language);
 
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("std::vector"));
-  EXPECT_EQ("", CI.mapSymbol("std::printf"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "vector", Language));
+  EXPECT_EQ("", CI.mapSymbol("std::", "printf", Language));
   // std::move is ambiguous, currently always mapped to 
-  EXPECT_EQ("", CI.mapSymbol("std::move"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "move", Language));
   // Unknown std symbols aren't mapped.
-  EXPECT_EQ("", CI.mapSymbol("std::notathing"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "notathing", Language));
   // iosfwd declares some symbols it doesn't own.
-  EXPECT_EQ("", CI.mapSymbol("std::ostream"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "ostream", Language));
   // And (for now) we assume it owns the others.
   auto InMemFS = llvm::makeIntrusiveRefCnt();
   FileManager Files(FileSystemOptions(), InMemFS);
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -829,20 +829,18 @@
   llvm::DenseMap FileToContainsImportsOrObjC;
   // Fill in IncludeHeaders.
   // We delay this until end of TU so header guards are all resolved.
-  llvm::SmallString<128> QName;
   for (const auto &[SID, FID] : IncludeFiles) {
 if (const Symbol *S = Symbols.find(SID)) {
   llvm::StringRef IncludeHeader;
   // Look for an overridden include header for this symbol specifically.
   if (Opts.Includes) {
-QName = S->Scope;
-QName.append(S->Name);
-IncludeHeader = Opts.Includes->mapSymbol(QName);
+IncludeHeader =
+Opts.Includes->mapSymbol(S->Scope, S->Name, ASTCtx->getLangOpts());
 if (!IncludeHeader.empty()) {
   if (IncludeHeader.front() != '"' && IncludeHeader.front() != '<')
 IncludeHeader = HeaderFileURIs->toURI(IncludeHeader);
-  else if (IncludeHeader == "" && QName == "std::move" &&
-   S->Signature.contains(','))
+  else if (IncludeHeader == "" && S->Scope == "std::" &&
+   S->Name == "move" && S->Signature.contains(','))
 IncludeHeader = "";
 }
   }
Index: clang-tools-extra/clangd/index/StdLib.cpp
===
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -67,7 +68,7 @@
 }
 
 std::string buildUmbrella(llvm::StringLiteral Mandatory,
-  std::vector Headers) {
+  llvm::ArrayRef Headers) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
 
@@ -80,13 +81,11 @@
   "#endif\n",
   Mandatory);
 
-  llvm::sort(Headers);
-  auto Last = std::unique(Headers.begin(), Headers.end());
-  for (auto Header = Headers.begin(); Header != Last; ++Header) {
+  for (auto Header : Headers) {
 OS << llvm::formatv("#if __has_include({0})\n"
 "#include {0}\n"
 "#endif\n",
-*Header);
+Header);
   }
   OS.flush();
   return Result;
@@ -102,20 +101,14 @@
   Lang L = langFromOpts(LO);
   switch (L) {
   case CXX:
-static std::string *UmbrellaCXX =
-new std::string(buildUmbr

[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495066.
hokein added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp

Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -36,8 +36,8 @@
   Language.C11 = true;
   CI.addSystemHeadersMapping(Language);
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("printf"));
-  EXPECT_EQ("", CI.mapSymbol("unknown_symbol"));
+  EXPECT_EQ("", CI.mapSymbol("", "printf", Language));
+  EXPECT_EQ("", CI.mapSymbol("", "unknown_symbol", Language));
 }
 
 TEST(CanonicalIncludesTest, CXXStandardLibrary) {
@@ -47,14 +47,14 @@
   CI.addSystemHeadersMapping(Language);
 
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("std::vector"));
-  EXPECT_EQ("", CI.mapSymbol("std::printf"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "vector", Language));
+  EXPECT_EQ("", CI.mapSymbol("std::", "printf", Language));
   // std::move is ambiguous, currently always mapped to 
-  EXPECT_EQ("", CI.mapSymbol("std::move"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "move", Language));
   // Unknown std symbols aren't mapped.
-  EXPECT_EQ("", CI.mapSymbol("std::notathing"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "notathing", Language));
   // iosfwd declares some symbols it doesn't own.
-  EXPECT_EQ("", CI.mapSymbol("std::ostream"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "ostream", Language));
   // And (for now) we assume it owns the others.
   auto InMemFS = llvm::makeIntrusiveRefCnt();
   FileManager Files(FileSystemOptions(), InMemFS);
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -829,20 +829,18 @@
   llvm::DenseMap FileToContainsImportsOrObjC;
   // Fill in IncludeHeaders.
   // We delay this until end of TU so header guards are all resolved.
-  llvm::SmallString<128> QName;
   for (const auto &[SID, FID] : IncludeFiles) {
 if (const Symbol *S = Symbols.find(SID)) {
   llvm::StringRef IncludeHeader;
   // Look for an overridden include header for this symbol specifically.
   if (Opts.Includes) {
-QName = S->Scope;
-QName.append(S->Name);
-IncludeHeader = Opts.Includes->mapSymbol(QName);
+IncludeHeader =
+Opts.Includes->mapSymbol(S->Scope, S->Name, ASTCtx->getLangOpts());
 if (!IncludeHeader.empty()) {
   if (IncludeHeader.front() != '"' && IncludeHeader.front() != '<')
 IncludeHeader = HeaderFileURIs->toURI(IncludeHeader);
-  else if (IncludeHeader == "" && QName == "std::move" &&
-   S->Signature.contains(','))
+  else if (IncludeHeader == "" && S->Scope == "std::" &&
+   S->Name == "move" && S->Signature.contains(','))
 IncludeHeader = "";
 }
   }
Index: clang-tools-extra/clangd/index/StdLib.cpp
===
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -67,7 +68,7 @@
 }
 
 std::string buildUmbrella(llvm::StringLiteral Mandatory,
-  std::vector Headers) {
+  llvm::ArrayRef Headers) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
 
@@ -80,13 +81,11 @@
   "#endif\n",
   Mandatory);
 
-  llvm::sort(Headers);
-  auto Last = std::unique(Headers.begin(), Headers.end());
-  for (auto Header = Headers.begin(); Header != Last; ++Header) {
+  for (auto Header : Headers) {
 OS << llvm::formatv("#if __has_include({0})\n"
 "#include {0}\n"
 "#endif\n",
-*Header);
+Header);
   }
   OS.flush();
   return Result;
@@ -102,20 +101,14 @@
   Lang L = langFromOpts(LO);
   switch (L) {
   case CXX:
-static std::string *UmbrellaCXX =
-new std::string(buildUmbrella(mandatoryHeader(L), {
-#define SYMBOL(Name, NameSpace

[PATCH] D141098: [clang-format][NFC] Set LineEnding to LF in config files

2023-02-06 Thread Sunho Kim via Phabricator via cfe-commits
sunho added a comment.

This seems to be causing builtbot lint script error: 
https://buildkite.com/llvm-project/premerge-checks/builds/134501#01862630-8fa9-487c-99b1-9addbe6257d0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141098

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


[PATCH] D142878: Add testing for Fuchsia multilib

2023-02-06 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings abandoned this revision.
michaelplatings added a comment.

> A more scalable approach would be to check only the minimal set of 
> combination necessary to achieve full coverage.

In that case the testing you've already got in place in 
`clang/test/Driver/fuchsia.cpp` is adequate. There was a potential bug here so 
I was being extra cautious, but in practice the test added in this change 
didn't pick up anything that wasn't also caught by the existing tests. I'll 
abandon this change and remove it from the stack. The change stack now begins 
at D142893 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142878

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


[clang] 9166842 - [clang][NFC] Fix a documentation typo

2023-02-06 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-02-06T12:37:36+01:00
New Revision: 9166842bc6fbd9c9b45134aa09a44b68ad1d7f02

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

LOG: [clang][NFC] Fix a documentation typo

Added: 


Modified: 
clang/include/clang/AST/Expr.h

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 485278917994..df2573324b75 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -665,8 +665,8 @@ class Expr : public ValueStmt {
SideEffectsKind AllowSideEffects = SE_NoSideEffects,
bool InConstantContext = false) const;
 
-  /// EvaluateAsFloat - Return true if this is a constant which we can fold and
-  /// convert to a fixed point value.
+  /// EvaluateAsFixedPoint - Return true if this is a constant which we can 
fold
+  /// and convert to a fixed point value.
   bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx,
 SideEffectsKind AllowSideEffects = 
SE_NoSideEffects,
 bool InConstantContext = false) const;



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


[PATCH] D142905: Change multilib selection algorithm

2023-02-06 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 495070.
michaelplatings added a comment.

Set both fexceptions and fno-exceptions flags for Fuchsia multilib. Previously 
that tweak had slipped into D142878 , which 
is now abandoned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142905

Files:
  clang/include/clang/Driver/Multilib.h
  clang/include/clang/Driver/MultilibBuilder.h
  clang/lib/Driver/Multilib.cpp
  clang/lib/Driver/MultilibBuilder.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/unittests/Driver/MultilibBuilderTest.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -33,14 +33,14 @@
 }
 
 TEST(MultilibTest, OpEqReflexivity3) {
-  Multilib M1({}, {}, {}, 0, {"+foo"});
-  Multilib M2({}, {}, {}, 0, {"+foo"});
+  Multilib M1({}, {}, {}, {"+foo"});
+  Multilib M2({}, {}, {}, {"+foo"});
   ASSERT_TRUE(M1 == M2) << "Multilibs with the same flag should be the same";
 }
 
 TEST(MultilibTest, OpEqInequivalence1) {
-  Multilib M1({}, {}, {}, 0, {"+foo"});
-  Multilib M2({}, {}, {}, 0, {"-foo"});
+  Multilib M1({}, {}, {}, {"+foo"});
+  Multilib M2({}, {}, {}, {"-foo"});
   ASSERT_FALSE(M1 == M2) << "Multilibs with conflicting flags are not the same";
   ASSERT_FALSE(M2 == M1)
   << "Multilibs with conflicting flags are not the same (commuted)";
@@ -48,7 +48,7 @@
 
 TEST(MultilibTest, OpEqInequivalence2) {
   Multilib M1;
-  Multilib M2({}, {}, {}, 0, {"+foo"});
+  Multilib M2({}, {}, {}, {"+foo"});
   ASSERT_FALSE(M1 == M2) << "Flags make Multilibs different";
 }
 
@@ -124,7 +124,7 @@
 }
 
 TEST(MultilibTest, Construction3) {
-  Multilib M({}, {}, {}, 0, {"+f1", "+f2", "-f3"});
+  Multilib M({}, {}, {}, {"+f1", "+f2", "-f3"});
   for (Multilib::flags_list::const_iterator I = M.flags().begin(),
 E = M.flags().end();
I != E; ++I) {
@@ -149,8 +149,8 @@
 
 TEST(MultilibTest, SetPriority) {
   MultilibSet MS({
-  Multilib("/foo", {}, {}, 1, {"+foo"}),
-  Multilib("/bar", {}, {}, 2, {"+bar"}),
+  Multilib("/foo", {}, {}, {"+foo"}),
+  Multilib("/bar", {}, {}, {"+bar"}),
   });
   Multilib::flags_list Flags1 = {"+foo", "-bar"};
   Multilib Selection1;
@@ -166,3 +166,24 @@
   ASSERT_TRUE(Selection2.gccSuffix() == "/bar")
   << "Selection picked " << Selection2 << " which was not expected";
 }
+
+TEST(MultilibTest, SelectMultiple) {
+  MultilibSet MS({
+  Multilib("/a", {}, {}, {"x"}),
+  Multilib("/b", {}, {}, {"y"}),
+  });
+  std::vector Selection;
+
+  Selection = MS.select({"x"});
+  ASSERT_EQ(1u, Selection.size());
+  EXPECT_EQ("/a", Selection[0].gccSuffix());
+
+  Selection = MS.select({"y"});
+  ASSERT_EQ(1u, Selection.size());
+  EXPECT_EQ("/b", Selection[0].gccSuffix());
+
+  Selection = MS.select({"y", "x"});
+  ASSERT_EQ(2u, Selection.size());
+  EXPECT_EQ("/a", Selection[0].gccSuffix());
+  EXPECT_EQ("/b", Selection[1].gccSuffix());
+}
Index: clang/unittests/Driver/MultilibBuilderTest.cpp
===
--- clang/unittests/Driver/MultilibBuilderTest.cpp
+++ clang/unittests/Driver/MultilibBuilderTest.cpp
@@ -7,7 +7,7 @@
 //
 //===--===//
 //
-// Unit tests for Multilib and MultilibBuilder
+// Unit tests for MultilibBuilderVariant and MultilibBuilder
 //
 //===--===//
 
@@ -185,14 +185,14 @@
 bool IsSF = I & 0x2;
 Multilib::flags_list Flags;
 if (IsEL)
-  Flags.push_back("+EL");
+  Flags.insert("+EL");
 else
-  Flags.push_back("-EL");
+  Flags.insert("-EL");
 
 if (IsSF)
-  Flags.push_back("+SF");
+  Flags.insert("+SF");
 else
-  Flags.push_back("-SF");
+  Flags.insert("-SF");
 
 Multilib Selection;
 ASSERT_TRUE(MS2.select(Flags, Selection))
@@ -209,3 +209,11 @@
 << "Selection picked " << Selection << " which was not expected ";
   }
 }
+
+TEST(MultilibBuilderTest, PrintArgs) {
+  MultilibBuilderVariant MBV =
+  MultilibBuilderVariant().flag("+x").flag("-y").flag("+a").flag("-b").flag(
+  "+c");
+  auto M = MBV.makeMultilib();
+  ASSERT_EQ(Multilib::arg_list({"-x", "-a", "-c"}), M.getPrintArgs());
+}
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -263,33 +263,33 @@
 
   Multilibs.push_back(Multilib());
   // Use the noexcept variant with -fno-exceptions to avoid the extra overhead.
-  Multilibs.push_back(MultilibBuilderVariant("noe

[PATCH] D143059: [NFC] Enable selecting multiple multilibs

2023-02-06 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 495072.
michaelplatings added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143059

Files:
  clang/include/clang/Driver/Multilib.h
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/Multilib.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/CSKYToolChain.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/Hurd.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/MipsLinux.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/test/Driver/fuchsia.cpp
  clang/unittests/Driver/MultilibBuilderTest.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -153,18 +153,18 @@
   Multilib("/bar", {}, {}, {"+bar"}),
   });
   Multilib::flags_list Flags1 = {"+foo", "-bar"};
-  Multilib Selection1;
+  llvm::SmallVector Selection1;
   ASSERT_TRUE(MS.select(Flags1, Selection1))
   << "Flag set was {\"+foo\"}, but selection not found";
-  ASSERT_TRUE(Selection1.gccSuffix() == "/foo")
-  << "Selection picked " << Selection1 << " which was not expected";
+  ASSERT_TRUE(Selection1.back().gccSuffix() == "/foo")
+  << "Selection picked " << Selection1.back() << " which was not expected";
 
   Multilib::flags_list Flags2 = {"+foo", "+bar"};
-  Multilib Selection2;
+  llvm::SmallVector Selection2;
   ASSERT_TRUE(MS.select(Flags2, Selection2))
   << "Flag set was {\"+bar\"}, but selection not found";
-  ASSERT_TRUE(Selection2.gccSuffix() == "/bar")
-  << "Selection picked " << Selection2 << " which was not expected";
+  ASSERT_TRUE(Selection2.back().gccSuffix() == "/bar")
+  << "Selection picked " << Selection2.back() << " which was not expected";
 }
 
 TEST(MultilibTest, SelectMultiple) {
@@ -172,17 +172,17 @@
   Multilib("/a", {}, {}, {"x"}),
   Multilib("/b", {}, {}, {"y"}),
   });
-  std::vector Selection;
+  llvm::SmallVector Selection;
 
-  Selection = MS.select({"x"});
+  ASSERT_TRUE(MS.select({"x"}, Selection));
   ASSERT_EQ(1u, Selection.size());
   EXPECT_EQ("/a", Selection[0].gccSuffix());
 
-  Selection = MS.select({"y"});
+  ASSERT_TRUE(MS.select({"y"}, Selection));
   ASSERT_EQ(1u, Selection.size());
   EXPECT_EQ("/b", Selection[0].gccSuffix());
 
-  Selection = MS.select({"y", "x"});
+  ASSERT_TRUE(MS.select({"y", "x"}, Selection));
   ASSERT_EQ(2u, Selection.size());
   EXPECT_EQ("/a", Selection[0].gccSuffix());
   EXPECT_EQ("/b", Selection[1].gccSuffix());
@@ -314,7 +314,7 @@
 
 TEST(MultilibTest, SelectSoft) {
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parse(MS, R"(
 variants:
 - dir: s
@@ -333,7 +333,7 @@
 
 TEST(MultilibTest, SelectSoftFP) {
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parse(MS, R"(
 variants:
 - dir: f
@@ -349,7 +349,7 @@
   // If hard float is all that's available then select that only if compiling
   // with hard float.
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parse(MS, R"(
 variants:
 - dir: h
@@ -363,7 +363,7 @@
 
 TEST(MultilibTest, SelectFloatABI) {
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parse(MS, R"(
 variants:
 - dir: s
@@ -384,18 +384,18 @@
   noMatchFlags: [hasfp]
 )"));
   MS.select({"mfloat-abi=soft"}, Selected);
-  EXPECT_EQ("/s", Selected.gccSuffix());
+  EXPECT_EQ("/s", Selected.back().gccSuffix());
   MS.select({"mfloat-abi=softfp"}, Selected);
-  EXPECT_EQ("/f", Selected.gccSuffix());
+  EXPECT_EQ("/f", Selected.back().gccSuffix());
   MS.select({"mfloat-abi=hard"}, Selected);
-  EXPECT_EQ("/h", Selected.gccSuffix());
+  EXPECT_EQ("/h", Selected.back().gccSuffix());
 }
 
 TEST(MultilibTest, SelectFloatABIReversed) {
   // If soft is specified after softfp then softfp will never be
   // selected because soft is compatible with softfp and last wins.
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parse(MS, R"(
 variants:
 - dir: h
@@ -416,11 +416,11 @@
   noMatchFlags: [hasfp]
 )"));
   MS.select({"mfloat-abi=soft"}, Selected);
-  EXPECT_EQ("/s", Selected.gccSuffix());
+  EXPECT_EQ("/s", Selected.back().gccSuffix());
   MS.select({"mfloat-abi=softfp"}, Selected);
-  EXPECT_EQ("/s", Selected.gccSuffix());
+  EXPECT_EQ("/s", Selected.back().gccSuffix());
   MS.select({"mfloat-abi=hard"}, Selected);
-  EXPECT_EQ("/h", Selected.gccSuffix());
+  EXPECT_EQ("/h", Selected.back().gccSuffix());
 }
 
 TEST(MultilibTest, SelectMClas

[PATCH] D142617: [clang][Interp] Check This pointer without creating InterpFrame

2023-02-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142617

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


[PATCH] D141098: [clang-format][NFC] Set LineEnding to LF in config files

2023-02-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I guess we'll need to revert this until the buildbots are updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141098

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


[PATCH] D143178: Add new clang-format alignment option

2023-02-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay requested changes to this revision.
MyDeveloperDay added a comment.
This revision now requires changes to proceed.

Please add the unit tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143178

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


[PATCH] D143178: Add new clang-format alignment option

2023-02-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Can you please do a full context diff  see 
(https://llvm.org/docs/Contributing.html)




Comment at: clang/include/clang/Format/Format.h:225
 bool AlignCompound;
+// TODO
+bool AcrossParameterDeclarations;

Ok you have to give us the example at least


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143178

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


[PATCH] D143178: Add new clang-format alignment option

2023-02-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

please point to a github issue which outlines what you are fixing and why




Comment at: clang/lib/Format/Format.cpp:35
 #include "clang/Basic/SourceManager.h"
+#include "clang/Format/Format.h"
 #include "clang/Lex/Lexer.h"

why moving?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143178

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


[PATCH] D143178: Add new clang-format alignment option

2023-02-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

" just to get feedback whether this
option would get accepted or not."

Honestly I can't tell from the code what problem you are trying to fix. The 
github issue and unit tests are vital for us to understand what you are trying 
to achieve (and to ensure you are not breaking anything)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143178

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


[PATCH] D140415: [flang] stack arrays pass

2023-02-06 Thread Tom Eccles via Phabricator via cfe-commits
tblah updated this revision to Diff 495073.
tblah added a comment.

Changes: inline mlir::blockIsInLoop


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140415

Files:
  clang/docs/tools/clang-formatted-files.txt
  flang/include/flang/Optimizer/Builder/MutableBox.h
  flang/include/flang/Optimizer/Dialect/FIRAttr.h
  flang/include/flang/Optimizer/Transforms/Passes.h
  flang/include/flang/Optimizer/Transforms/Passes.td
  flang/lib/Lower/Allocatable.cpp
  flang/lib/Optimizer/Builder/MutableBox.cpp
  flang/lib/Optimizer/Transforms/CMakeLists.txt
  flang/lib/Optimizer/Transforms/StackArrays.cpp
  flang/test/Lower/HLFIR/allocatable-and-pointer-status-change.f90
  flang/test/Lower/Intrinsics/c_loc.f90
  flang/test/Lower/Intrinsics/system_clock.f90
  flang/test/Transforms/stack-arrays.f90
  flang/test/Transforms/stack-arrays.fir

Index: flang/test/Transforms/stack-arrays.fir
===
--- /dev/null
+++ flang/test/Transforms/stack-arrays.fir
@@ -0,0 +1,309 @@
+// RUN: fir-opt --stack-arrays %s | FileCheck %s
+
+// Simplest transformation
+func.func @simple() {
+  %0 = fir.allocmem !fir.array<42xi32>
+  fir.freemem %0 : !fir.heap>
+  return
+}
+// CHECK: func.func @simple() {
+// CHECK-NEXT: fir.alloca !fir.array<42xi32>
+// CHECK-NEXT: return
+// CHECK-NEXT: }
+
+// Check fir.must_be_heap allocations are not moved
+func.func @must_be_heap() {
+  %0 = fir.allocmem !fir.array<42xi32> {fir.must_be_heap = true}
+  fir.freemem %0 : !fir.heap>
+  return
+}
+// CHECK:  func.func @must_be_heap() {
+// CHECK-NEXT:   %[[ALLOC:.*]] = fir.allocmem !fir.array<42xi32> {fir.must_be_heap = true}
+// CHECK-NEXT:   fir.freemem %[[ALLOC]] : !fir.heap>
+// CHECK-NEXT:   return
+// CHECK-NEXT: }
+
+// Check the data-flow-analysis can detect cases where we aren't sure if memory
+// is freed by the end of the function
+func.func @dfa1(%arg0: !fir.ref> {fir.bindc_name = "cond"}) {
+  %7 = arith.constant 42 : index
+  %8 = fir.allocmem !fir.array, %7 {uniq_name = "_QFdfa1Earr.alloc"}
+  %9 = fir.load %arg0 : !fir.ref>
+  %10 = fir.convert %9 : (!fir.logical<4>) -> i1
+  fir.if %10 {
+fir.freemem %8 : !fir.heap>
+  } else {
+  }
+  return
+}
+// CHECK:  func.func @dfa1(%arg0: !fir.ref> {fir.bindc_name = "cond"}) {
+// CHECK-NEXT:   %[[C42:.*]] = arith.constant 42 : index
+// CHECK-NEXT:   %[[MEM:.*]] = fir.allocmem !fir.array, %[[C42]] {uniq_name = "_QFdfa1Earr.alloc"}
+// CHECK-NEXT:   %[[LOGICAL:.*]] = fir.load %arg0 : !fir.ref>
+// CHECK-NEXT:   %[[BOOL:.*]] = fir.convert %[[LOGICAL]] : (!fir.logical<4>) -> i1
+// CHECK-NEXT:   fir.if %[[BOOL]] {
+// CHECK-NEXT: fir.freemem %[[MEM]] : !fir.heap>
+// CHECK-NEXT:   } else {
+// CHECK-NEXT:   }
+// CHECK-NEXT:   return
+// CHECK-NEXT: }
+
+// Check scf.if (fir.if is not considered a branch operation)
+func.func @dfa2(%arg0: i1) {
+  %a = fir.allocmem !fir.array<1xi8>
+  scf.if %arg0 {
+fir.freemem %a : !fir.heap>
+  } else {
+  }
+  return
+}
+// CHECK: func.func @dfa2(%arg0: i1) {
+// CHECK-NEXT:  %[[MEM:.*]] = fir.allocmem !fir.array<1xi8>
+// CHECK-NEXT:  scf.if %arg0 {
+// CHECK-NEXT:fir.freemem %[[MEM]] : !fir.heap>
+// CHECK-NEXT:  } else {
+// CHECK-NEXT:  }
+// CHECK-NEXT:  return
+// CHECK-NEXT:  }
+
+// check the alloca is placed after all operands become available
+func.func @placement1() {
+  // do some stuff with other ssa values
+  %1 = arith.constant 1 : index
+  %2 = arith.constant 2 : index
+  %3 = arith.addi %1, %2 : index
+  // operand is now available
+  %4 = fir.allocmem !fir.array, %3
+  // ...
+  fir.freemem %4 : !fir.heap>
+  return
+}
+// CHECK:  func.func @placement1() {
+// CHECK-NEXT:   %[[ONE:.*]] = arith.constant 1 : index
+// CHECK-NEXT:   %[[TWO:.*]] = arith.constant 2 : index
+// CHECK-NEXT:   %[[ARG:.*]] = arith.addi %[[ONE]], %[[TWO]] : index
+// CHECK-NEXT:   %[[MEM:.*]] = fir.alloca !fir.array, %[[ARG]]
+// CHECK-NEXT:   return
+// CHECK-NEXT: }
+
+// check that if there are no operands, then the alloca is placed early
+func.func @placement2() {
+  // do some stuff with other ssa values
+  %1 = arith.constant 1 : index
+  %2 = arith.constant 2 : index
+  %3 = arith.addi %1, %2 : index
+  %4 = fir.allocmem !fir.array<42xi32>
+  // ...
+  fir.freemem %4 : !fir.heap>
+  return
+}
+// CHECK:  func.func @placement2() {
+// CHECK-NEXT:   %[[MEM:.*]] = fir.alloca !fir.array<42xi32>
+// CHECK-NEXT:   %[[ONE:.*]] = arith.constant 1 : index
+// CHECK-NEXT:   %[[TWO:.*]] = arith.constant 2 : index
+// CHECK-NEXT:   %[[SUM:.*]] = arith.addi %[[ONE]], %[[TWO]] : index
+// CHECK-NEXT:   return
+// CHECK-NEXT: }
+
+// check that stack allocations which must be placed in loops use stacksave
+func.func @placement3() {
+  %c1 = arith.constant 1 : index
+  %c1_i32 = fir.convert %c1 : (index) -> i32
+  %c2 = arith.constant 2 : index
+  %c10 = arith.constant 10 : index
+  %0:2 = fir.do_loop %arg0 = 

[clang] c24cdd5 - [clang-format] PackConstructorInitializers support PCIS_OnlyNextLine

2023-02-06 Thread via cfe-commits

Author: Backl1ght
Date: 2023-02-06T19:39:05+08:00
New Revision: c24cdd58a1445e9741d89137f18f1ec9c89ecead

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

LOG: [clang-format] PackConstructorInitializers support PCIS_OnlyNextLine

fixes https://github.com/llvm/llvm-project/issues/60241

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ea4fe179eddce..fd8f2bbb54322 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3888,6 +3888,23 @@ the configuration (without a prefix: ``Auto``).
  (),
  ()
 
+  * ``PCIS_NextLineOnly`` (in configuration: ``NextLineOnly``)
+Put all constructor initializers on the next line if they fit.
+Otherwise, put each one on its own line.
+
+.. code-block:: c++
+
+   Constructor()
+   : a(), b()
+
+   Constructor()
+   : (), (), d()
+
+   Constructor()
+   : (),
+ (),
+ ()
+
 
 
 .. _PenaltyBreakAssignment:

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4463f03174543..50c647a4faaf7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,11 @@ AST Matchers
 clang-format
 
 
+- Add ``NextLineOnly`` style to option ``PackConstructorInitializers``.
+  Compared to ``NextLine`` style, ``NextLineOnly`` style will not try to
+  put the initializers on the current line first, instead, it will try to
+  put the initializers on the next line only.
+
 clang-extdef-mapping
 
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index b5f9b8b955a76..0d57d7996525a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2929,6 +2929,21 @@ struct FormatStyle {
 ///  ()
 /// \endcode
 PCIS_NextLine,
+/// Put all constructor initializers on the next line if they fit.
+/// Otherwise, put each one on its own line.
+/// \code
+///Constructor()
+///: a(), b()
+///
+///Constructor()
+///: (), (), 
d()
+///
+///Constructor()
+///: (),
+///  (),
+///  ()
+/// \endcode
+PCIS_NextLineOnly,
   };
 
   /// The pack constructor initializers style to use.

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 412c57b850b51..d82ea43c1c34f 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1053,13 +1053,16 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState &State,
 bool PreviousIsBreakingCtorInitializerColon =
 PreviousNonComment && PreviousNonComment->is(TT_CtorInitializerColon) 
&&
 Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon;
+bool AllowAllConstructorInitializersOnNextLine =
+Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine ||
+Style.PackConstructorInitializers == FormatStyle::PCIS_NextLineOnly;
 if (!(Previous.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) ||
   PreviousIsBreakingCtorInitializerColon) ||
 (!Style.AllowAllParametersOfDeclarationOnNextLine &&
  State.Line->MustBeDeclaration) ||
 (!Style.AllowAllArgumentsOnNextLine &&
  !State.Line->MustBeDeclaration) ||
-(Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine &&
+(!AllowAllConstructorInitializersOnNextLine &&
  PreviousIsBreakingCtorInitializerColon) ||
 Previous.is(TT_DictLiteral)) {
   CurrentState.BreakBeforeParameter = true;
@@ -1069,7 +1072,7 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState &State,
 // and we allow all arguments on the next line, we should not break
 // before the next parameter.
 if (PreviousIsBreakingCtorInitializerColon &&
-Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine) {
+

[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_NextLineOnly

2023-02-06 Thread Zhikai Zeng 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 rGc24cdd58a144: [clang-format] PackConstructorInitializers 
support PCIS_OnlyNextLine (authored by Backl1ght).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143091

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7289,6 +7289,19 @@
  Style);
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a)\n"
+ ", b(b)\n"
+ ", cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor()\n"
@@ -7301,6 +7314,19 @@
  "  b(b) {}",
  Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a),\n"
+ "  b(b),\n"
+ "  cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor() :\n"
@@ -7312,6 +7338,19 @@
  "aa(a),\n"
  "b(b) {}",
  Style);
+
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor() :\n"
+ "aa(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "(a),\n"
+ "b(b),\n"
+ "cc(c) {}",
+ Style);
   }
 
   // Test interactions between AllowAllParametersOfDeclarationOnNextLine and
@@ -7319,6 +7358,7 @@
   // BreakConstructorInitializers modes
   Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
   Style.AllowAllParametersOfDeclarationOnNextLine = true;
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
"int , int b)\n"
": (a)\n"
@@ -7333,6 +7373,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7359,6 +7407,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllPa

[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/Tooling/Inclusions/StdAlternativeHeaderMap.inc:3
+//
+// This is a hand-curated list for C++ symbols (e.g. provided by multiple
+// headers), to address the short comings of cppreference or automated

kadircet wrote:
> `This is a hand-curated list for C++ symbols` reads like we're planning to 
> put all special C++ symbols into this file, rather than just the ones that 
> are provided by alternative headers. that's the reason why i mentioned it as 
> `This is a hand-curated list for symbols provided by multiple headers` 
> specifically.
Restricting the file only to multiple-header symbols seems a bit narrow (and 
the `consume_header` symbol only has one header which doesn't fit into this 
bucket nicely).

My take of this file is - we'll put all special C++ symbols that are not able 
to handle by the cppreference generator, multiple-header symbols are the most 
critical ones.

What do you think?





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

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


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/tools/include-mapping/gen_std.py:123
+c_header = "<" + header[2:-1] +  ".h>"
+if not any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+  if symbol.namespace != None:

nit: early exits

```
if header not in c_compat_headers:
  return []
if any(re.fullmatch(x, symbol.name) for x in exception_symbols)::
  return []
...
```



Comment at: clang/tools/include-mapping/gen_std.py:124
+if not any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+  if symbol.namespace != None:
+# avoid printing duplicated entries, for C macros!

maybe add a comment like: `Introduce two more entries, both in the global 
namespace, one using the C++-compat header and another using the C header`.



Comment at: clang/tools/include-mapping/gen_std.py:127
+results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
+# print("SYMBOL(%s, None, %s)" % (symbol.name, symbol.headers[0]))
+  results.append(cppreference_parser.Symbol(symbol.name, None, [c_header]))

i think it might be better to delete this line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

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


[PATCH] D143386: Add function pointer alignment to DataLayout

2023-02-06 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet created this revision.
gchatelet added a reviewer: efriedma.
Herald added subscribers: luke, kosarev, mattd, gchakrabarti, pmatos, asb, 
asavonic, frasercrmck, kerbowa, luismarques, apazos, sameer.abuasal, s.egerton, 
Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, atanasyan, 
edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, 
fedor.sergeev, kbarton, jgravelle-google, sbc100, jvesely, nemanjai, sdardis, 
dylanmckay, jyknight, dschuff.
Herald added a project: All.
gchatelet requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay, aheejin, 
jholewinski.
Herald added a project: clang.

This is to follow up on https://reviews.llvm.org/D57335.
The patch should not be submitted as-is, the tests are completely broken, but 
before having a look at them I want to make sure this patch makes sense.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143386

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/ARC.h
  clang/lib/Basic/Targets/AVR.h
  clang/lib/Basic/Targets/BPF.h
  clang/lib/Basic/Targets/CSKY.h
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/Hexagon.h
  clang/lib/Basic/Targets/Lanai.h
  clang/lib/Basic/Targets/Le64.h
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/MSP430.h
  clang/lib/Basic/Targets/Mips.h
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/Sparc.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/VE.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Basic/Targets/XCore.h

Index: clang/lib/Basic/Targets/XCore.h
===
--- clang/lib/Basic/Targets/XCore.h
+++ clang/lib/Basic/Targets/XCore.h
@@ -36,7 +36,7 @@
 WCharType = UnsignedChar;
 WIntType = UnsignedInt;
 UseZeroLengthBitfieldAlignment = true;
-resetDataLayout("e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32"
+resetDataLayout("e-m:e-Fi32-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32"
 "-f64:32-a:0:32-n32");
   }
 
Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -536,8 +536,10 @@
   UseSignedCharForObjCBool = false;
 SizeType = UnsignedLong;
 IntPtrType = SignedLong;
-resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
-"f80:128-n8:16:32-S128", "_");
+resetDataLayout(
+"e-m:o-p:32:32-Fn32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
+"f80:128-n8:16:32-S128",
+"_");
 HasAlignMac68kSupport = true;
   }
 
@@ -564,7 +566,7 @@
 getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
 bool IsMSVC = getTriple().isWindowsMSVCEnvironment();
 std::string Layout = IsWinCOFF ? "e-m:x" : "e-m:e";
-Layout += "-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-";
+Layout += "-p:32:32-Fn32-p270:32:32-p271:32:32-p272:64:64-i64:64-";
 Layout += IsMSVC ? "f80:128" : "f80:32";
 Layout += "-n8:16:32-a:0:32-S32";
 resetDataLayout(Layout, IsWinCOFF ? "_" : "");
@@ -615,9 +617,10 @@
   : X86_32TargetInfo(Triple, Opts) {
 this->WCharType = TargetInfo::UnsignedShort;
 DoubleAlign = LongLongAlign = 64;
-resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:"
-"32-n8:16:32-a:0:32-S32",
-"_");
+resetDataLayout(
+"e-m:x-p:32:32-Fn32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:"
+"32-n8:16:32-a:0:32-S32",
+"_");
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -654,8 +657,9 @@
   : X86_32TargetInfo(Triple, Opts) {
 LongDoubleWidth = 64;
 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
-resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-f64:"
-"32-f128:32-n8:16:32-a:0:32-S32");
+resetDataLayout(
+"e-m:e-p:32:32-Fn32-p270:32:32-p271:32:32-p272:64:64-i64:32-f64:"
+"32-f128:32-n8:16:32-a:0:32-S32");
 WIntType = UnsignedInt;
   }
 
@@ -714,12 +718,13 @@
 RegParmMax = 6;
 
 // Pointers are 32-bit in x32.
-resetDataLayout(IsX32 ? "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
-"i64:64-f80:128-n8:16:32:64-S128"
-  : IsWinCOFF ? "e-m:w-p270:32:32-p271:32:32-p272:64:"
-"64-i64:64-f80:128-n8:16:32:64-S128"
-  : "e-m:e-p270:32:32-p271:32:32-p272:64:"
-"64-i64:64-f80:128-n8:16:32:64-S128");
+resetDataLayout(

[clang] 8323d2a - [CodeGen] Remove some not needed includes in BackendUtil.cpp

2023-02-06 Thread Bjorn Pettersson via cfe-commits

Author: Bjorn Pettersson
Date: 2023-02-06T13:38:57+01:00
New Revision: 8323d2a66575ef5f891ec917f163c1737ade4187

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

LOG: [CodeGen] Remove some not needed includes in BackendUtil.cpp

Getting rid of some include dependencies that seem to be outdated.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 2b43d0e38bf7..5ccf1a665a6c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -20,7 +20,6 @@
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/GlobalsModRef.h"
-#include "llvm/Analysis/StackSafetyAnalysis.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeReader.h"
@@ -56,12 +55,6 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
-#include "llvm/Transforms/Coroutines/CoroCleanup.h"
-#include "llvm/Transforms/Coroutines/CoroEarly.h"
-#include "llvm/Transforms/Coroutines/CoroElide.h"
-#include "llvm/Transforms/Coroutines/CoroSplit.h"
-#include "llvm/Transforms/IPO.h"
-#include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/LowerTypeTests.h"
 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
 #include "llvm/Transforms/InstCombine/InstCombine.h"
@@ -80,18 +73,12 @@
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
 #include "llvm/Transforms/ObjCARC.h"
-#include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
-#include "llvm/Transforms/Scalar/LowerMatrixIntrinsics.h"
-#include "llvm/Transforms/Utils.h"
-#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
-#include "llvm/Transforms/Utils/NameAnonGlobals.h"
-#include "llvm/Transforms/Utils/SymbolRewriter.h"
 #include 
 #include 
 using namespace clang;



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


[PATCH] D143214: [include-mapping] Add C-compatibility symbol entries.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495089.
hokein marked 3 inline comments as done.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143214

Files:
  clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
  clang/tools/include-mapping/gen_std.py

Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -41,6 +41,7 @@
 import datetime
 import os
 import sys
+import re
 
 CODE_PREFIX = """\
 //===-- gen_std.py generated file ---*- C++ -*-===//
@@ -69,6 +70,69 @@
   return parser.parse_args()
 
 
+def GetCCompatibilitySymbols(symbol):
+   # C++ form of the C standard headers.
+  c_compat_headers = {
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+"",
+  }
+  # C++ [support.c.headers.other] 17.14.7
+  #..., behaves as if each name placed in the standard library namespace by
+  #the corresponding  header is placed within the global namespace
+  #scope, except for the functions described in [sf.cmath], the
+  #std​::​lerp function overloads ([c.math.lerp]), the declaration of
+  #std​::​byte ([cstddef.syn]), and the functions and function templates
+  #described in [support.types.byteops].
+  exception_symbols = {
+"(assoc_)?laguerre[f|l]?",
+"(assoc_|sph_)?legendre[f|l]?",
+"beta[f|l]?",
+"(comp_)?ellint_[1-3][f|l]?",
+"(cyl_|sph_)?bessel_[i-k][f|l]?",
+"(cyl_|sph_)?neumann[f|l]?",
+"expint[f|l]?",
+"hermite[f|l]?",
+"riemann_zeta[f|l]?",
+"lerp",
+"byte",
+  }
+  assert(len(symbol.headers) == 1)
+  header = symbol.headers[0]
+  if header not in c_compat_headers:
+return []
+  if any(re.fullmatch(x, symbol.name) for x in exception_symbols):
+return []
+
+  # Introduce two more entries, both in the global namespace, one using the
+  # C++-compat header and another using the C header.
+  results = []
+  if symbol.namespace != None:
+# avoid printing duplicated entries, for C macros!
+results.append(cppreference_parser.Symbol(symbol.name, None, [header]))
+  c_header = "<" + header[2:-1] +  ".h>" #  => 
+  results.append(cppreference_parser.Symbol(symbol.name, None, [c_header]))
+  return results
+
+
 def main():
   args = ParseArg()
   if args.symbols == 'cpp':
@@ -88,6 +152,7 @@
   (symbol_index_root, "pmr.html", "std::pmr::"),
   (symbol_index_root, "regex_constants.html", "std::regex_constants::"),
   (symbol_index_root, "this_thread.html", "std::this_thread::"),
+  (symbol_index_root, "macro.html", None),
 ]
   elif args.symbols == 'cpp_removed':
 page_root = os.path.join(args.cppreference, "en", "cpp")
@@ -111,9 +176,12 @@
   print(CODE_PREFIX % (args.symbols.upper(), cppreference_modified_date))
   for symbol in symbols:
 if len(symbol.headers) == 1:
-  # SYMBOL(unqualified_name, namespace, header)
-  print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
-symbol.headers[0]))
+  augmented_symbols = [symbol]
+  augmented_symbols.extend(GetCCompatibilitySymbols(symbol))
+  for s in augmented_symbols:
+# SYMBOL(unqualified_name, namespace, header)
+print("SYMBOL(%s, %s, %s)" % (s.name, s.namespace,
+  s.headers[0]))
 elif len(symbol.headers) == 0:
   sys.stderr.write("No header found for symbol %s\n" % symbol.name)
 else:
Index: clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
===
--- clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
+++ clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
@@ -10,14 +10,30 @@
 //===--===//
 
 SYMBOL(FILE, std::, )
+SYMBOL(FILE, None, )
+SYMBOL(FILE, None, )
 SYMBOL(_Exit, std::, )
+SYMBOL(_Exit, None, )
+SYMBOL(_Exit, None, )
 SYMBOL(accumulate, std::, )
 SYMBOL(acos, std::, )
+SYMBOL(acos, None, )
+SYMBOL(acos, None, )
 SYMBOL(acosf, std::, )
+SYMBOL(acosf, None, )
+SYMBOL(acosf, None, )
 SYMBOL(acosh, std::, )
+SYMBOL(acosh, None, )
+SYMBOL(acosh, None, )
 SYMBOL(acoshf, std::, )
+SYMBOL(acoshf, None, )
+SYMBOL(acoshf, None, )
 SYMBOL(acoshl, std::, )
+SYMBOL(acoshl, None, )
+SYMBOL(acoshl, None, )
 SYMBOL(acosl, std::, )
+SYMBOL(acosl, None, )
+SYMBOL(acosl, None, )
 SYMBOL(add_const, std::, )
 SYMBOL(add_const_t, std::, )
 SYMBOL(add_cv, std::, )
@@ -39,6 +55,8 @@
 SYMBOL(align, std::, )
 SYMBOL(align_val_t, std::, )
 SYMBOL(aligned_alloc, std::, )
+SYMBOL(aligned_alloc, None, )
+SYMBOL(aligned_alloc, None, )
 SYMBOL(aligned_storage, std::, )
 SYMBOL(ali

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-02-06 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

Please add more description to the summary regarding the scope of this patch. 
If it is only able to lower specific llvm-dialect types, please call out that. 
Please also explain the split in work between mlir::Translation and 
OpenMPIRbuilder. You can also consider splitting this into two patches. One 
that just adds the changes to OpenMPIRBuilder and the child version of the 
patch adding the translation in MLIR.




Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:1342-1382
+/// Create a constant string location from the MLIR Location information.
+static llvm::Constant *
+createSourceLocStrFromLocation(Location loc, llvm::OpenMPIRBuilder &builder,
+   StringRef name, uint32_t &strLen) {
+  if (auto fileLoc = loc.dyn_cast()) {
+StringRef fileName = fileLoc.getFilename();
+unsigned lineNo = fileLoc.getLine();

TIFitis wrote:
> clementval wrote:
> > TIFitis wrote:
> > > clementval wrote:
> > > > TIFitis wrote:
> > > > > clementval wrote:
> > > > > > TIFitis wrote:
> > > > > > > clementval wrote:
> > > > > > > > TIFitis wrote:
> > > > > > > > > clementval wrote:
> > > > > > > > > > kiranchandramohan wrote:
> > > > > > > > > > > clementval wrote:
> > > > > > > > > > > > Instead of copy pasting this from 
> > > > > > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > > > > > > >  can you extract it and put it in a common shared file 
> > > > > > > > > > > > so bith translation can use the same code without 
> > > > > > > > > > > > duplication?
> > > > > > > > > > > @raghavendhra put up a patch some time back and he faced 
> > > > > > > > > > > some issues. It might be good to check with him or may be 
> > > > > > > > > > > he can comment here.
> > > > > > > > > > > https://reviews.llvm.org/D127037
> > > > > > > > > > > https://discourse.llvm.org/t/rfc-for-refactoring-common-code-for-openacc-and-openmp/63833
> > > > > > > > > > Just moving the three functions should be trivial. I'm not 
> > > > > > > > > > talking about the processMapOperand.
> > > > > > > > > I've moved `getSizeInBytes`.
> > > > > > > > > 
> > > > > > > > > The other two functions make use of `mlir::Location` and thus 
> > > > > > > > > can't be moved trivially.
> > > > > > > > > 
> > > > > > > > > I can still try to move them by individually passing the 
> > > > > > > > > elements of `mlir::Location` but that might not be ideal. Is 
> > > > > > > > > that what you'd like?
> > > > > > > > What about a new header file in 
> > > > > > > > `mlir/include/mlir/Target/LLVMIR/Dialect/**` shared by 
> > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > > >  and 
> > > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`.
> > > > > > > >  That should be doable. 
> > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp`
> > > > > > >  and 
> > > > > > > `mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp`
> > > > > > >  already have access to the common `mlir::Location` type.
> > > > > > > 
> > > > > > > Problem is that `OMPIRBuilder.cpp` is the only common file 
> > > > > > > between them  where I can move the two functions to. Currently 
> > > > > > > there are no `mlir/**` include files in `OMPIRBuilder.cpp` and it 
> > > > > > > seems to me like a strict design choice to have it that way.
> > > > > > The functions can be header only. Why do you need to put them in 
> > > > > > the OMPIRBuilder.cpp? I think it is better than duplicate the exact 
> > > > > > same code over. 
> > > > > Sorry, I misunderstood you earlier.
> > > > > I've added a new header file 
> > > > > `mlir/include/mlir/Target/LLVMIR/Dialect/Utils.h`, this is my first 
> > > > > attempt at adding a new header file, please let me know if you find 
> > > > > any issues.
> > > > Thanks! That's what I had in mind. We might want to check with MLIR 
> > > > folks if `mlir::utils` is suited for that. I don't mind if it is 
> > > > `mlir::omp::builder` or smth similar since it is related to the 
> > > > OMPIRBuilder.
> > > Since the utils file is common to all the dialects I kept it as 
> > > `mlir::utils`.
> > > 
> > > How do I get the opinion from people working in MLIR on this, can you 
> > > suggest some reviewers whom I can add?
> > It's only valid for translation to the `llvmir` dialect so that why 
> > `mlir::utils` seems to generic to me. 
> > 
> > Maybe @ftynse has some thoughts on this. 
> I agree with you on that, would perhaps renaming it to something like 
> `mlir::dialect-utils` be a better option?
You can post in MLIR discourse MLIR section 
(https://discourse.llvm.org/c/mlir/31) to get an opinion.

open-directive-utils , ompbuilder-utils are other options. Simialr names could 
be considered for the file name as well.






Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST 

[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks a lot. since this is the last (and only) upstream user of the raw 
mappings. can you also move them into `clang/lib/Tooling/Inclusions/Stdlib/` as 
part of this patch?




Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.h:43
+  /// Returns the overridden include for a qualified symbol with, or "".
+  llvm::StringRef mapSymbol(llvm::StringRef /*std::*/ Scope,
+llvm::StringRef /*vector*/ Name,

these parameter comments are a little bit unconventional, maybe just mention 
that `Scope` should have trailing colons (e.g. std::) and name shouldn't have 
any (e.g. vector) ? also mention that `it should be empty ("") for global 
namespace`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

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


[PATCH] D143280: [include-mapping] Better #includes support for std input/output symbols

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm! as discussed offline, let's first move the raw header mappings to 
a private location first though and make sure all users are going through 
stdlib apis to ensure we don't see weird behaviour after such changes (since 
we're breaking the invariant of a qualified symbol name occurring only once)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143280

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


[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/include/clang/Tooling/Inclusions/StdAlternativeHeaderMap.inc:3
+//
+// This is a hand-curated list for C++ symbols (e.g. provided by multiple
+// headers), to address the short comings of cppreference or automated

hokein wrote:
> kadircet wrote:
> > `This is a hand-curated list for C++ symbols` reads like we're planning to 
> > put all special C++ symbols into this file, rather than just the ones that 
> > are provided by alternative headers. that's the reason why i mentioned it 
> > as `This is a hand-curated list for symbols provided by multiple headers` 
> > specifically.
> Restricting the file only to multiple-header symbols seems a bit narrow (and 
> the `consume_header` symbol only has one header which doesn't fit into this 
> bucket nicely).
> 
> My take of this file is - we'll put all special C++ symbols that are not able 
> to handle by the cppreference generator, multiple-header symbols are the most 
> critical ones.
> 
> What do you think?
> 
> 
> 
> (and the consume_header symbol only has one header which doesn't fit into 
> this bucket nicely).

Well, i'd say they deserve their own list in that case.


> My take of this file is - we'll put all special C++ symbols that are not able 
> to handle by the cppreference generator, multiple-header symbols are the most 
> critical ones.

I am afraid of that list getting too long and impossible to read manually any 
more.
but since these are going to be private files soon, we can always do that split 
once that's actually the case.

We need a different name for this file in that case though. As I thought we are 
only putting symbols with alternative headers into this file. What about 
`StdSpecialSymbolMap.inc` instead and update the file comment to:
```
This is a hand-curated list for C++ symbols that cannot be parsed/extracted via 
include-mapping tool.
```

and not talk about `All headers for a symbol name provide the same declaration 
(hence these are not overloads/variants like std::remove from algorithm vs 
cstdio).` as we're planning to add them to here as well. it's just we aren't 
adding them "right now".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

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


[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added a comment.

In D143274#4106449 , @kadircet wrote:

> thanks a lot. since this is the last (and only) upstream user of the raw 
> mappings. can you also move them into `clang/lib/Tooling/Inclusions/Stdlib/` 
> as part of this patch?

As discussed, I will address this in a followup patch.




Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.cpp:711
+return "";
+  // There are multiple headers for size_t, pick one.
+  if (QName == "std::size_t")

kadircet wrote:
> i think the comment is misleading. as if we had some alternatives in the 
> tooling::stdlib, it would already pick one for us. the issue is we don't have 
> it in the mapping at all.
yeah, this comment was moved from the old version. I removed it as it is 
covered by the above FIXME.



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.h:43
+  /// Returns the overridden include for a qualified symbol with, or "".
+  llvm::StringRef mapSymbol(llvm::StringRef /*std::*/ Scope,
+llvm::StringRef /*vector*/ Name,

kadircet wrote:
> these parameter comments are a little bit unconventional, maybe just mention 
> that `Scope` should have trailing colons (e.g. std::) and name shouldn't have 
> any (e.g. vector) ? also mention that `it should be empty ("") for global 
> namespace`?
Removed the parameter comments, and refined the doc comment of the function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

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


[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495096.
hokein marked an inline comment as done.
hokein added a comment.

refined the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp

Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -36,8 +36,8 @@
   Language.C11 = true;
   CI.addSystemHeadersMapping(Language);
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("printf"));
-  EXPECT_EQ("", CI.mapSymbol("unknown_symbol"));
+  EXPECT_EQ("", CI.mapSymbol("", "printf", Language));
+  EXPECT_EQ("", CI.mapSymbol("", "unknown_symbol", Language));
 }
 
 TEST(CanonicalIncludesTest, CXXStandardLibrary) {
@@ -47,14 +47,14 @@
   CI.addSystemHeadersMapping(Language);
 
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("std::vector"));
-  EXPECT_EQ("", CI.mapSymbol("std::printf"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "vector", Language));
+  EXPECT_EQ("", CI.mapSymbol("std::", "printf", Language));
   // std::move is ambiguous, currently always mapped to 
-  EXPECT_EQ("", CI.mapSymbol("std::move"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "move", Language));
   // Unknown std symbols aren't mapped.
-  EXPECT_EQ("", CI.mapSymbol("std::notathing"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "notathing", Language));
   // iosfwd declares some symbols it doesn't own.
-  EXPECT_EQ("", CI.mapSymbol("std::ostream"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "ostream", Language));
   // And (for now) we assume it owns the others.
   auto InMemFS = llvm::makeIntrusiveRefCnt();
   FileManager Files(FileSystemOptions(), InMemFS);
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -829,20 +829,18 @@
   llvm::DenseMap FileToContainsImportsOrObjC;
   // Fill in IncludeHeaders.
   // We delay this until end of TU so header guards are all resolved.
-  llvm::SmallString<128> QName;
   for (const auto &[SID, FID] : IncludeFiles) {
 if (const Symbol *S = Symbols.find(SID)) {
   llvm::StringRef IncludeHeader;
   // Look for an overridden include header for this symbol specifically.
   if (Opts.Includes) {
-QName = S->Scope;
-QName.append(S->Name);
-IncludeHeader = Opts.Includes->mapSymbol(QName);
+IncludeHeader =
+Opts.Includes->mapSymbol(S->Scope, S->Name, ASTCtx->getLangOpts());
 if (!IncludeHeader.empty()) {
   if (IncludeHeader.front() != '"' && IncludeHeader.front() != '<')
 IncludeHeader = HeaderFileURIs->toURI(IncludeHeader);
-  else if (IncludeHeader == "" && QName == "std::move" &&
-   S->Signature.contains(','))
+  else if (IncludeHeader == "" && S->Scope == "std::" &&
+   S->Name == "move" && S->Signature.contains(','))
 IncludeHeader = "";
 }
   }
Index: clang-tools-extra/clangd/index/StdLib.cpp
===
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -67,7 +68,7 @@
 }
 
 std::string buildUmbrella(llvm::StringLiteral Mandatory,
-  std::vector Headers) {
+  llvm::ArrayRef Headers) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
 
@@ -80,13 +81,11 @@
   "#endif\n",
   Mandatory);
 
-  llvm::sort(Headers);
-  auto Last = std::unique(Headers.begin(), Headers.end());
-  for (auto Header = Headers.begin(); Header != Last; ++Header) {
+  for (auto Header : Headers) {
 OS << llvm::formatv("#if __has_include({0})\n"
 "#include {0}\n"
 "#endif\n",
-*Header);
+Header);
   }
   OS.flush();
   return Result;
@@ -102,20 +101,14 @@
   Lang L = langFromOpts(LO);
   switch (L) {
   case CXX:
-static std::string *UmbrellaCXX =
-new std::string(buildUmbrell

[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.h:43
+  /// Returns the overridden include for a qualified symbol with, or "".
+  /// \p Scope and \p Name concatenation forms the full qualified name.
+  /// \p Scope is the qualifier with the trailing "::" (e.g. "std::") or empty

s/full/fully



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.h:45
+  /// \p Scope is the qualifier with the trailing "::" (e.g. "std::") or empty
+  /// (for global namespace symbol).
+  llvm::StringRef mapSymbol(llvm::StringRef Scope, llvm::StringRef Name,

s/for global namespace symbol/for global namespace/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

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


[PATCH] D143318: [Support] Move ItaniumManglingCanonicalizer and SymbolRemappingReader from Support to ProfileData

2023-02-06 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

This (moving to ProfileData) seems like a simple and pragmatic solution for a 
(perhaps not gigantic but) real problem. It feels fine to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143318

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


[clang] de31b5c - Update status of WG21 DR1042

2023-02-06 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-02-06T08:34:31-05:00
New Revision: de31b5cf0ae6b22ea7f71b4cbe1c21e543726020

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

LOG: Update status of WG21 DR1042

We've supported attributes on alias declarations at least as far back
as Clang 3.5 from my testing. This also updates the RUN lines to test
the newer language modes as well.

Added: 


Modified: 
clang/test/CXX/drs/dr10xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr10xx.cpp b/clang/test/CXX/drs/dr10xx.cpp
index f629280c3d981..4d49a1859c2f5 100644
--- a/clang/test/CXX/drs/dr10xx.cpp
+++ b/clang/test/CXX/drs/dr10xx.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++2b %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
 namespace std {
   __extension__ typedef __SIZE_TYPE__ size_t;
@@ -83,3 +85,16 @@ namespace dr1070 { // dr1070: 3.5
   C c = {};
 #endif
 }
+
+namespace dr1042 { // dr1042: 3.5
+#if __cplusplus >= 201402L
+  // C++14 added an attribute that we can test the semantics of.
+  using foo [[deprecated]] = int; // expected-note {{'foo' has been explicitly 
marked deprecated here}}
+  foo f = 12; // expected-warning {{'foo' is deprecated}}
+#elif __cplusplus >= 201103L
+  // C++11 did not have any attributes that could be applied to an alias
+  // declaration, so the best we can test is that we accept an empty attribute
+  // list in this mode.
+  using foo [[]] = int;
+#endif
+}

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index b54c65e034066..dbd4e34816f98 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -6059,7 +6059,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1042";>1042
 C++11
 Attributes in alias-declarations
-Unknown
+3.5
   
   
 https://wg21.link/cwg1043";>1043



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


[clang-tools-extra] 58927e9 - [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-02-06T14:41:52+01:00
New Revision: 58927e9931219387895b4ef67ebb50eafa2d9056

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

LOG: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

Replace them with the library APIs.

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

Added: 


Modified: 
clang-tools-extra/clangd/index/CanonicalIncludes.cpp
clang-tools-extra/clangd/index/CanonicalIncludes.h
clang-tools-extra/clangd/index/StdLib.cpp
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp 
b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index f123b029f9fb3..41d195f81298e 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -10,6 +10,7 @@
 #include "Headers.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Tooling/Inclusions/HeaderAnalysis.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem/UniqueID.h"
 #include "llvm/Support/Path.h"
@@ -700,8 +701,26 @@ llvm::StringRef CanonicalIncludes::mapHeader(FileEntryRef 
Header) const {
   return "";
 }
 
-llvm::StringRef CanonicalIncludes::mapSymbol(llvm::StringRef QName) const {
-  return StdSymbolMapping ? StdSymbolMapping->lookup(QName) : "";
+llvm::StringRef CanonicalIncludes::mapSymbol(llvm::StringRef Scope,
+ llvm::StringRef Name,
+ const LangOptions &L) const {
+  tooling::stdlib::Lang Lang;
+  if (L.CPlusPlus)
+Lang = tooling::stdlib::Lang::CXX;
+  else if (L.C11)
+Lang = tooling::stdlib::Lang::C;
+  else
+return "";
+  // FIXME: remove the following special cases when the tooling stdlib supports
+  // them.
+  // There are two std::move()s, this is by far the most common.
+  if (Scope == "std::" && Name == "move")
+return "";
+  if (Scope == "std::" && Name == "size_t")
+return "";
+  if (auto StdSym = tooling::stdlib::Symbol::named(Scope, Name, Lang))
+return StdSym->header().name();
+  return "";
 }
 
 std::unique_ptr
@@ -732,28 +751,6 @@ collectIWYUHeaderMaps(CanonicalIncludes *Includes) {
 }
 
 void CanonicalIncludes::addSystemHeadersMapping(const LangOptions &Language) {
-  if (Language.CPlusPlus) {
-static const auto *Symbols = new llvm::StringMap({
-#define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name, #Header},
-#include "clang/Tooling/Inclusions/StdSymbolMap.inc"
-// There are two std::move()s, this is by far the most common.
-SYMBOL(move, std::, )
-// There are multiple headers for size_t, pick one.
-SYMBOL(size_t, std::, )
-#undef SYMBOL
-});
-StdSymbolMapping = Symbols;
-  } else if (Language.C11) {
-static const auto *CSymbols = new llvm::StringMap({
-#define SYMBOL(Name, NameSpace, Header) {#Name, #Header},
-#include "clang/Tooling/Inclusions/CSymbolMap.inc"
-// There are multiple headers for size_t, pick one.
-SYMBOL(size_t, None, )
-#undef SYMBOL
-});
-StdSymbolMapping = CSymbols;
-  }
-
   // FIXME: remove the std header mapping once we support ambiguous symbols, 
now
   // it serves as a fallback to disambiguate:
   //   - symbols with multiple headers (e.g. std::move)

diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.h 
b/clang-tools-extra/clangd/index/CanonicalIncludes.h
index f6ac4a1fb271f..f1464885018e9 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.h
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.h
@@ -39,8 +39,12 @@ class CanonicalIncludes {
   /// Adds a file-to-string mapping from \p ID to \p CanonicalPath.
   void addMapping(FileEntryRef Header, llvm::StringRef CanonicalPath);
 
-  /// Returns the overridden include for symbol with \p QualifiedName, or "".
-  llvm::StringRef mapSymbol(llvm::StringRef QualifiedName) const;
+  /// Returns the overridden include for a qualified symbol with, or "".
+  /// \p Scope and \p Name concatenation forms the fully qualified name.
+  /// \p Scope is the qualifier with the trailing "::" (e.g. "std::") or empty
+  /// (for global namespace).
+  llvm::StringRef mapSymbol(llvm::StringRef Scope, llvm::StringRef Name,
+const LangOptions &L) const;
 
   /// Returns the overridden include for files in \p Header, or "".
   llvm::StringRef mapHeader(FileEntryRef Header) const;
@@ -61,9 +65,6 @@ class CanonicalIncludes {
   /// A map from a suffix (one or components of a path) to a canonical path.
   /// Used only for mapping standard headers.
   const llvm::StringMap *

[PATCH] D143274: [clangd] Remove the direct use of StdSymbolMapping.inc usage.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
hokein marked 2 inline comments as done.
Closed by commit rG58927e993121: [clangd] Remove the direct use of 
StdSymbolMapping.inc usage. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D143274?vs=495096&id=495098#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143274

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp

Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -36,8 +36,8 @@
   Language.C11 = true;
   CI.addSystemHeadersMapping(Language);
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("printf"));
-  EXPECT_EQ("", CI.mapSymbol("unknown_symbol"));
+  EXPECT_EQ("", CI.mapSymbol("", "printf", Language));
+  EXPECT_EQ("", CI.mapSymbol("", "unknown_symbol", Language));
 }
 
 TEST(CanonicalIncludesTest, CXXStandardLibrary) {
@@ -47,14 +47,14 @@
   CI.addSystemHeadersMapping(Language);
 
   // Usual standard library symbols are mapped correctly.
-  EXPECT_EQ("", CI.mapSymbol("std::vector"));
-  EXPECT_EQ("", CI.mapSymbol("std::printf"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "vector", Language));
+  EXPECT_EQ("", CI.mapSymbol("std::", "printf", Language));
   // std::move is ambiguous, currently always mapped to 
-  EXPECT_EQ("", CI.mapSymbol("std::move"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "move", Language));
   // Unknown std symbols aren't mapped.
-  EXPECT_EQ("", CI.mapSymbol("std::notathing"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "notathing", Language));
   // iosfwd declares some symbols it doesn't own.
-  EXPECT_EQ("", CI.mapSymbol("std::ostream"));
+  EXPECT_EQ("", CI.mapSymbol("std::", "ostream", Language));
   // And (for now) we assume it owns the others.
   auto InMemFS = llvm::makeIntrusiveRefCnt();
   FileManager Files(FileSystemOptions(), InMemFS);
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -829,20 +829,18 @@
   llvm::DenseMap FileToContainsImportsOrObjC;
   // Fill in IncludeHeaders.
   // We delay this until end of TU so header guards are all resolved.
-  llvm::SmallString<128> QName;
   for (const auto &[SID, FID] : IncludeFiles) {
 if (const Symbol *S = Symbols.find(SID)) {
   llvm::StringRef IncludeHeader;
   // Look for an overridden include header for this symbol specifically.
   if (Opts.Includes) {
-QName = S->Scope;
-QName.append(S->Name);
-IncludeHeader = Opts.Includes->mapSymbol(QName);
+IncludeHeader =
+Opts.Includes->mapSymbol(S->Scope, S->Name, ASTCtx->getLangOpts());
 if (!IncludeHeader.empty()) {
   if (IncludeHeader.front() != '"' && IncludeHeader.front() != '<')
 IncludeHeader = HeaderFileURIs->toURI(IncludeHeader);
-  else if (IncludeHeader == "" && QName == "std::move" &&
-   S->Signature.contains(','))
+  else if (IncludeHeader == "" && S->Scope == "std::" &&
+   S->Name == "move" && S->Signature.contains(','))
 IncludeHeader = "";
 }
   }
Index: clang-tools-extra/clangd/index/StdLib.cpp
===
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -67,7 +68,7 @@
 }
 
 std::string buildUmbrella(llvm::StringLiteral Mandatory,
-  std::vector Headers) {
+  llvm::ArrayRef Headers) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
 
@@ -80,13 +81,11 @@
   "#endif\n",
   Mandatory);
 
-  llvm::sort(Headers);
-  auto Last = std::unique(Headers.begin(), Headers.end());
-  for (auto Header = Headers.begin(); Header != Last; ++Header) {
+  for (auto Header : Headers) {
 OS << llvm::formatv("#if __has_include({0})\n"
 "#include {0}\n"
 "#endif\n",
-*Header);
+Header);
   }
   OS

[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495100.
hokein added a comment.

Rename the file name for more general purposes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

Files:
  clang/include/clang/Tooling/Inclusions/StdSpecialSymbolMap.inc

Index: clang/include/clang/Tooling/Inclusions/StdSpecialSymbolMap.inc
===
--- /dev/null
+++ clang/include/clang/Tooling/Inclusions/StdSpecialSymbolMap.inc
@@ -0,0 +1,204 @@
+//===-- StdSpecialSymbolMap.inc -*- C++ -*-===//
+//
+// This is a hand-curated list for C++ symbols that cannot be parsed/extracted
+// via the include-mapping tool (gen_std.py).
+//
+//===--===//
+
+// Symbols that can be provided by any of the headers, ordered by the header
+// preference.
+// cppreference mentions the  header is an alternative for these symbols,
+// but they are not per the standard.
+SYMBOL(consume_header, std::, )
+SYMBOL(generate_header, std::, )
+SYMBOL(little_endian, std::, )
+
+SYMBOL(mbstate_t, std::, )
+SYMBOL(mbstate_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(size_t, std::, )
+SYMBOL(unwrap_ref_decay, std::, )
+SYMBOL(unwrap_ref_decay, std::, )
+SYMBOL(unwrap_reference, std::, )
+SYMBOL(unwrap_reference, std::, )
+SYMBOL(unwrap_ref_decay_t, std::, )
+SYMBOL(unwrap_ref_decay_t, std::, )
+SYMBOL(wint_t, std::, )
+SYMBOL(wint_t, std::, )
+// C++ [iterator.range 25.7]: In addition to being available via inclusion of
+// the  header, the function templates in [iterator.range] are
+// available when any of the following headers are included: , ,
+// , ... and .
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(begin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cbegin, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(cend, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crbegin, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(crend, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(data, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(empty, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(end, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rbegin, std::, )
+SYMBOL(rend, std::, )
+SYMBOL(rend, std::, )
+SYMBOL(rend, std::, )
+SYMBO

[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/Tooling/Inclusions/StdAlternativeHeaderMap.inc:3
+//
+// This is a hand-curated list for C++ symbols (e.g. provided by multiple
+// headers), to address the short comings of cppreference or automated

kadircet wrote:
> hokein wrote:
> > kadircet wrote:
> > > `This is a hand-curated list for C++ symbols` reads like we're planning 
> > > to put all special C++ symbols into this file, rather than just the ones 
> > > that are provided by alternative headers. that's the reason why i 
> > > mentioned it as `This is a hand-curated list for symbols provided by 
> > > multiple headers` specifically.
> > Restricting the file only to multiple-header symbols seems a bit narrow 
> > (and the `consume_header` symbol only has one header which doesn't fit into 
> > this bucket nicely).
> > 
> > My take of this file is - we'll put all special C++ symbols that are not 
> > able to handle by the cppreference generator, multiple-header symbols are 
> > the most critical ones.
> > 
> > What do you think?
> > 
> > 
> > 
> > (and the consume_header symbol only has one header which doesn't fit into 
> > this bucket nicely).
> 
> Well, i'd say they deserve their own list in that case.
> 
> 
> > My take of this file is - we'll put all special C++ symbols that are not 
> > able to handle by the cppreference generator, multiple-header symbols are 
> > the most critical ones.
> 
> I am afraid of that list getting too long and impossible to read manually any 
> more.
> but since these are going to be private files soon, we can always do that 
> split once that's actually the case.
> 
> We need a different name for this file in that case though. As I thought we 
> are only putting symbols with alternative headers into this file. What about 
> `StdSpecialSymbolMap.inc` instead and update the file comment to:
> ```
> This is a hand-curated list for C++ symbols that cannot be parsed/extracted 
> via include-mapping tool.
> ```
> 
> and not talk about `All headers for a symbol name provide the same 
> declaration (hence these are not overloads/variants like std::remove from 
> algorithm vs cstdio).` as we're planning to add them to here as well. it's 
> just we aren't adding them "right now".
Yeah, this sounds good to me.

> Well, i'd say they deserve their own list in that case.

Yeah, this is an alternative (a mono file vs. muti files). I would start with a 
single file.
The list of these symbols is not that large now.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

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


[PATCH] D143160: [include-mapping] Introduce a human-edit CXXSymbolMapping file

2023-02-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143160

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-06 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

> The limitation about only transforming the first argument can be alleviated 
> by using the forEachArgumentWithParam matcher

I shall try to make that work. My initial attempts were not successful, but 
there's still more to try. If I can't make it work I'll ask for more help here.

Thanks.


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

https://reviews.llvm.org/D143342

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


[PATCH] D143343: Broken link to SourceWeb (aka CxxCodeBrowser) project in "External Clang Examples" #60142

2023-02-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you! I'll land this on your behalf.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143343

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


[clang] d041833 - Fix broken link to CxxCodeBrowser in External Clang Examples

2023-02-06 Thread Aaron Ballman via cfe-commits

Author: Pratik Sharma
Date: 2023-02-06T09:12:58-05:00
New Revision: d041833f55d91321670f2ccfc22d66a85c279905

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

LOG: Fix broken link to CxxCodeBrowser in External Clang Examples

Replaced the dead link with the correct link in ExternalClangExamples.rst

Differential Revision: https://reviews.llvm.org/D143343
Fixes https://github.com/llvm/llvm-project/issues/60142

Added: 


Modified: 
clang/docs/ExternalClangExamples.rst

Removed: 




diff  --git a/clang/docs/ExternalClangExamples.rst 
b/clang/docs/ExternalClangExamples.rst
index 080114740ddb..c119d8165561 100644
--- a/clang/docs/ExternalClangExamples.rst
+++ b/clang/docs/ExternalClangExamples.rst
@@ -33,7 +33,7 @@ List of projects and tools
a persistent in-memory database of references, symbolnames, completions
etc."
 
-``_
+``_
"A C/C++ source code indexer and navigator"
 
 ``_



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


[PATCH] D143343: Broken link to SourceWeb (aka CxxCodeBrowser) project in "External Clang Examples" #60142

2023-02-06 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd041833f55d9: Fix broken link to CxxCodeBrowser in External 
Clang Examples (authored by s-pratik, committed by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143343

Files:
  clang/docs/ExternalClangExamples.rst


Index: clang/docs/ExternalClangExamples.rst
===
--- clang/docs/ExternalClangExamples.rst
+++ clang/docs/ExternalClangExamples.rst
@@ -33,7 +33,7 @@
a persistent in-memory database of references, symbolnames, completions
etc."
 
-``_
+``_
"A C/C++ source code indexer and navigator"
 
 ``_


Index: clang/docs/ExternalClangExamples.rst
===
--- clang/docs/ExternalClangExamples.rst
+++ clang/docs/ExternalClangExamples.rst
@@ -33,7 +33,7 @@
a persistent in-memory database of references, symbolnames, completions
etc."
 
-``_
+``_
"A C/C++ source code indexer and navigator"
 
 ``_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143054: [include-mapping] Regenerate the mappings from the 20220730 html book.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks, it looks good.

One remaining suggestion is to merge the `StdRemovedSymbolMap.inc` to the 
`StdSymbolMap.inc` (it doesn't seem to add much value to maintain a separate 
file for zoombie symbols), I will address it and land the patch for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143054

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


[PATCH] D138453: [clang] Add serialization for loop hint annotation tokens

2023-02-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D138453#4105211 , @DHowett-MSFT 
wrote:

> In D138453#4105209 , @shafik wrote:
>
>> It looks like https://github.com/llvm/llvm-project/issues/60543 is hitting 
>> your added `llvm_unreachable("missing serialization code for annotation 
>> token");` is this expected.
>
> I believe it's expected that we hit this assertion - it's clearer than the 
> original message, and more directly indicates that `#pragma pack` cannot be 
> serialized.

Failed assertions or reaching code marked as unreachable is always a bug -- we 
should be failing gracefully with diagnostics and not crashing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138453

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


[clang] b5ee4f7 - Revert "Lazyly initialize uncommon toolchain detector"

2023-02-06 Thread Jonas Hahnfeld via cfe-commits

Author: Jonas Hahnfeld
Date: 2023-02-06T15:39:33+01:00
New Revision: b5ee4f755fcff56243f6ff0cea9e7a722259304a

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

LOG: Revert "Lazyly initialize uncommon toolchain detector"

clang/test/Driver/rocm-detect.hip is failing for a number of
configurations, for example:

clang-x86_64-debian-fast
https://lab.llvm.org/buildbot/#/builders/109/builds/57270

clang-debian-cpp20
https://lab.llvm.org/buildbot/#/builders/249/builds/310

clang-with-lto-ubuntu
https://lab.llvm.org/buildbot/#/builders/124/builds/6693

This reverts commit 6fa2abf90886f18472c87bc9bffbcdf4f73c465e.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Gnu.h
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/lib/Driver/ToolChains/Linux.cpp

Removed: 
clang/lib/Driver/ToolChains/LazyDetector.h



diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index a25bea951388c..52021901b9bf8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -701,7 +701,7 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList 
&DriverArgs,
 ROCMToolChain::ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
  const ArgList &Args)
 : AMDGPUToolChain(D, Triple, Args) {
-  RocmInstallation->detectDeviceLibrary();
+  RocmInstallation.detectDeviceLibrary();
 }
 
 void AMDGPUToolChain::addClangTargetOptions(
@@ -790,11 +790,11 @@ void ROCMToolChain::addClangTargetOptions(
   const StringRef GpuArch = getGPUArch(DriverArgs);
   auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
   const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
-  StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
+  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
   auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
-  if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
-ABIVer))
+  if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
+   ABIVer))
 return;
 
   bool Wave64 = isWave64(DriverArgs, Kind);
@@ -813,10 +813,10 @@ void ROCMToolChain::addClangTargetOptions(
 
   // Add the OpenCL specific bitcode library.
   llvm::SmallVector BCLibs;
-  BCLibs.push_back(RocmInstallation->getOpenCLPath().str());
+  BCLibs.push_back(RocmInstallation.getOpenCLPath().str());
 
   // Add the generic set of libraries.
-  BCLibs.append(RocmInstallation->getCommonBitcodeLibs(
+  BCLibs.append(RocmInstallation.getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, false));
 
@@ -875,11 +875,11 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   auto Kind = llvm::AMDGPU::parseArchAMDGCN(GPUArch);
   const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
 
-  StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
+  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
   auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
-  if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
-ABIVer))
+  if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
+   ABIVer))
 return {};
 
   // If --hip-device-lib is not set, add the default bitcode libraries.
@@ -900,7 +900,7 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt, true);
   bool Wave64 = isWave64(DriverArgs, Kind);
 
-  return RocmInstallation->getCommonBitcodeLibs(
+  return RocmInstallation.getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }

diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index b012b7cb72937..68d351af22603 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -160,7 +160,7 @@ AMDGPUOpenMPToolChain::getDeviceLibs(const 
llvm::opt::ArgList &Args) const {
   if (Args.hasArg(options::OPT_nogpulib))
 return {};
 
-  if (!RocmInstallation->hasDeviceLibrary()) {
+ 

[PATCH] D143054: [include-mapping] Regenerate the mappings from the 20220730 html book.

2023-02-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 495108.
hokein added a comment.

merge zoombie names to StdSymboMap.inc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143054

Files:
  clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
  clang/tools/include-mapping/cppreference_parser.py
  clang/tools/include-mapping/gen_std.py

Index: clang/tools/include-mapping/gen_std.py
===
--- clang/tools/include-mapping/gen_std.py
+++ clang/tools/include-mapping/gen_std.py
@@ -29,8 +29,6 @@
   4. Run the command:
// Generate C++ symbols
python3 gen_std.py -cppreference cppreference/reference -symbols=cpp > StdSymbolMap.inc
-   // Generate C++ removed symbols
-   python3 gen_std.py -cppreference cppreference/reference -symbols=cpp_removed > RemovedSymbolMap.inc
// Generate C symbols
python3 gen_std.py -cppreference cppreference/reference -symbols=c > CSymbolMap.inc
 """
@@ -88,11 +86,10 @@
   (symbol_index_root, "pmr.html", "std::pmr::"),
   (symbol_index_root, "regex_constants.html", "std::regex_constants::"),
   (symbol_index_root, "this_thread.html", "std::this_thread::"),
+  # Zombie symbols that were available from the Standard Library, but are
+  # removed in the following standards.
+  (symbol_index_root, "zombie_names.html", "std::"),
 ]
-  elif args.symbols == 'cpp_removed':
-page_root = os.path.join(args.cppreference, "en", "cpp")
-symbol_index_root = os.path.join(page_root, "symbol_index")
-parse_pages = [(symbol_index_root, "zombie_names.html", "std::")]
   elif args.symbols == 'c':
 page_root = os.path.join(args.cppreference, "en", "c")
 symbol_index_root = page_root
Index: clang/tools/include-mapping/cppreference_parser.py
===
--- clang/tools/include-mapping/cppreference_parser.py
+++ clang/tools/include-mapping/cppreference_parser.py
@@ -28,6 +28,11 @@
 # a list of corresponding headers
 self.headers = headers
 
+  def __lt__(self, other):
+if self.namespace != other.namespace:
+  return self.namespace < other.namespace
+return self.name < other.name
+
 
 def _HasClass(tag, *classes):
   for c in tag.get('class', []):
@@ -147,7 +152,7 @@
   pool.apply_async(_ReadSymbolPage, (path, symbol_name
   else:
 sys.stderr.write("Discarding information for symbol: %s. Page %s does not exist.\n" 
-  % (symbol_name, path))
+  % (symbol_name, path))
 
 # Build map from symbol name to a set of headers.
 symbol_headers = collections.defaultdict(set)
@@ -185,4 +190,5 @@
   finally:
 pool.terminate()
 pool.join()
-  return symbols
+
+  return sorted(symbols)
Index: clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
===
--- clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
+++ clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
@@ -6,45 +6,18 @@
 // This file was generated automatically by
 // clang/tools/include-mapping/gen_std.py, DO NOT EDIT!
 //
-// Generated from cppreference offline HTML book (modified on 2018-10-28).
+// Generated from cppreference offline HTML book (modified on 2022-07-30).
 //===--===//
 
-SYMBOL(Assignable, std::, )
-SYMBOL(Boolean, std::, )
-SYMBOL(Common, std::, )
-SYMBOL(CommonReference, std::, )
-SYMBOL(Constructible, std::, )
-SYMBOL(ConvertibleTo, std::, )
-SYMBOL(CopyConstructible, std::, )
-SYMBOL(Copyable, std::, )
-SYMBOL(DefaultConstructible, std::, )
-SYMBOL(DerivedFrom, std::, )
-SYMBOL(Destructible, std::, )
-SYMBOL(EqualityComparable, std::, )
-SYMBOL(EqualityComparableWith, std::, )
 SYMBOL(FILE, std::, )
-SYMBOL(Integral, std::, )
-SYMBOL(Invocable, std::, )
-SYMBOL(Movable, std::, )
-SYMBOL(MoveConstructible, std::, )
-SYMBOL(Predicate, std::, )
-SYMBOL(Regular, std::, )
-SYMBOL(RegularInvocable, std::, )
-SYMBOL(Relation, std::, )
-SYMBOL(Same, std::, )
-SYMBOL(Semiregular, std::, )
-SYMBOL(SignedIntegral, std::, )
-SYMBOL(StrictTotallyOrdered, std::, )
-SYMBOL(StrictTotallyOrderedWith, std::, )
-SYMBOL(StrictWeakOrder, std::, )
-SYMBOL(Swappable, std::, )
-SYMBOL(SwappableWith, std::, )
-SYMBOL(UniformRandomBitGenerator, std::, )
-SYMBOL(UnsignedIntegral, std::, )
 SYMBOL(_Exit, std::, )
 SYMBOL(accumulate, std::, )
 SYMBOL(acos, std::, )
+SYMBOL(acosf, std::, )
 SYMBOL(acosh, std::, )
+SYMBOL(acoshf, std::, )
+SYMBOL(acoshl, std::, )
+SYMBOL(acosl, std::, )
 SYMBOL(add_const, std::, )
 SYMBOL(add_const_t, std::, )
 SYMBOL(add_cv, std::, )
@@ -73,7 +46,10 @@
 SYMBOL(alignment_of, std::, )
 SYMBOL(alignment_of_v, std::, )
 SYMBOL(all_of, std::, )
+SYMBOL(allocate_at_least, std::, )
 SYMBOL(allocate_shared, std::, )
+SYMBOL(allocate_shared_

[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-06 Thread Tom Weaver via Phabricator via cfe-commits
TWeaver added a comment.

Hello all,

sorry to be a bother, but I believe this patch has caused a failure in this 
buildbot (and potentially others).

https://lab.llvm.org/buildbot/#/builders/109/builds/57277


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142606

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


[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-06 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld reopened this revision.
Hahnfeld added a comment.

This broke `clang/test/Driver/rocm-detect.hip` on a number of platforms 
(including the pre-merge checks on this PR), I've reverted for now in 
b5ee4f755fcff56243f6ff0cea9e7a722259304a 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142606

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


[PATCH] D141240: [SVE][Builtins] Add metadata to intrinsic calls for builtins that don't define the result of inactive lanes.

2023-02-06 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm abandoned this revision.
paulwalker-arm added a comment.

D141939  turned out to be the better approach.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141240

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


[clang] 77910ac - [clang] Reorder output of rocm-detect.hip test

2023-02-06 Thread via cfe-commits

Author: serge-sans-paille
Date: 2023-02-06T16:03:58+01:00
New Revision: 77910ac374656319ff114ef251fda358d4aa166a

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

LOG: [clang] Reorder output of rocm-detect.hip test

Since 6fa2abf90886f18472c87bc9bffbcdf4f73c465e the rocm driver is lazily
loaded, which impacts the output of the rocm-detect.hip test.

Added: 


Modified: 
clang/test/Driver/rocm-detect.hip

Removed: 




diff  --git a/clang/test/Driver/rocm-detect.hip 
b/clang/test/Driver/rocm-detect.hip
index c3ffd21a75b9b..01837bb45065c 100644
--- a/clang/test/Driver/rocm-detect.hip
+++ b/clang/test/Driver/rocm-detect.hip
@@ -80,12 +80,12 @@
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0
 
-// SPACK: ROCm installation search path (Spack 4.0.0): [[DIR:.*]]
+// SPACK: InstalledDir: 
[[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
+// SPACK: ROCm installation search path (Spack 4.0.0): [[DIR]]
 // SPACK: ROCm installation search path: [[CLANG:.*]]
 // SPACK: ROCm installation search path: 
[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z
 // SPACK: ROCm installation search path: 
[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/lib/clang
 // SPACK: ROCm installation search path: /opt/rocm
-// SPACK: InstalledDir: 
[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
 // SPACK: Found HIP installation: 
[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
 // SPACK: "-triple" "amdgcn-amd-amdhsa"
 // SPACK-SAME: "-mlink-builtin-bitcode" 
"[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"



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


[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-06 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 495116.
xgupta added a comment.

use function to avoid code duplication


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142609

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/test/C/drs/dr4xx.c
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp
  clang/test/Parser/cxx2a-concept-declaration.cpp
  clang/test/Sema/exprs.c
  clang/test/SemaCXX/expressions.cpp
  clang/test/SemaCXX/warn-unsequenced.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -43,7 +43,9 @@
 
 namespace PR7724 {
   template int myMethod()
-  { return 2 && sizeof(OT); }
+  { return 2 && sizeof(OT); } // expected-warning {{use of logical '&&' with constant operand}} \
+  // expected-note {{use '&' for a bitwise operation}} \
+  // expected-note {{remove constant to silence this warning}}
 }
 
 namespace test4 {
Index: clang/test/SemaCXX/warn-unsequenced.cpp
===
--- clang/test/SemaCXX/warn-unsequenced.cpp
+++ clang/test/SemaCXX/warn-unsequenced.cpp
@@ -76,15 +76,37 @@
 
   (xs[2] && (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
-  (0 && (a = 0)) + a; // ok
+
+  (0 && (a = 0)) + a; // cxx11-warning {{use of logical '&&' with constant operand}}
+  // cxx11-note@-1 {{use '&' for a bitwise operation}}
+  // cxx11-note@-2 {{remove constant to silence this warning}}
+  // cxx17-warning@-3 {{use of logical '&&' with constant operand}}
+  // cxx17-note@-4 {{use '&' for a bitwise operation}}
+  // cxx17-note@-5 {{remove constant to silence this warning}}
+
   (1 && (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+  // cxx11-warning@-2 {{use of logical '&&' with constant operand}}
+  // cxx11-note@-3 {{use '&' for a bitwise operation}}
+  // cxx11-note@-4 {{remove constant to silence this warning}}
+  // cxx17-warning@-5 {{use of logical '&&' with constant operand}}
+  // cxx17-note@-6 {{use '&' for a bitwise operation}}
+  // cxx17-note@-7 {{remove constant to silence this warning}}
+
 
   (xs[3] || (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
   (0 || (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
-  (1 || (a = 0)) + a; // ok
+  // cxx11-warning@-2 {{use of logical '||' with constant operand}}
+  // cxx11-note@-3 {{use '|' for a bitwise operation}}
+  // cxx17-warning@-4 {{use of logical '||' with constant operand}}
+  // cxx17-note@-5 {{use '|' for a bitwise operation}}
+  (1 || (a = 0)) + a; // cxx11-warning {{use of logical '||' with constant operand}}
+  // cxx11-note@-1 {{use '|' for a bitwise operation}}
+  // cxx17-warning@-2 {{use of logical '||' with constant operand}}
+  // cxx17-note@-3 {{use '|' for a bitwise operation}}
+
 
   (xs[4] ? a : ++a) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
  // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
Index: clang/test/SemaCXX/expressions.cpp
===
--- clang/test/SemaCXX/expressions.cpp
+++ clang/test/SemaCXX/expressions.cpp
@@ -44,6 +44,9 @@
   return x && 4; // expected-warning {{use of logical '&&' with constant operand}} \
// expected-note {{use '&' for a bitwise operation}} \
// expected-note {{remove constant to silence this warning}}
+  return 4 && x; // expected-warning {{use of logical '&&' with constant operand}} \
+   // expected-note {{use '&' for a bitwise operation}} \
+   // expected-note {{remove constant to silence this warning}}
 
   return x && sizeof(int) == 4;  // no warning, RHS is logical op.
   return x && true;
@@ -66,6 +69,8 @@
// expected-note {{use '|' for a bitwise operation}}
   return x || 5; // expected-warning {{use of logical '||'

[PATCH] D143399: [Tooling/Inclusion] Move the generated mapping .inc file to private places.

2023-02-06 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.

The .inc files are private now, clients should tooling::stdlib APIs instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143399

Files:
  clang/include/clang/Tooling/Inclusions/CSymbolMap.inc
  clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
  clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -1078,10 +1078,10 @@
 name = "tooling_inclusions",
 srcs = glob([
 "lib/Tooling/Inclusions/**/*.cpp",
+"lib/Tooling/Inclusions/**/*.inc",
 ]),
 hdrs = glob([
 "include/clang/Tooling/Inclusions/**/*.h",
-"include/clang/Tooling/Inclusions/**/*.inc",
 ]),
 deps = [
 ":ast",
Index: clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
===
--- /dev/null
+++ clang/include/clang/Tooling/Inclusions/StdSymbolMap.inc
@@ -1,1538 +0,0 @@
-//===-- gen_std.py generated file ---*- C++ -*-===//
-//
-// Used to build a lookup table (qualified names => include headers) for CPP
-// Standard Library symbols.
-//
-// This file was generated automatically by
-// clang/tools/include-mapping/gen_std.py, DO NOT EDIT!
-//
-// Generated from cppreference offline HTML book (modified on 2018-10-28).
-//===--===//
-
-SYMBOL(Assignable, std::, )
-SYMBOL(Boolean, std::, )
-SYMBOL(Common, std::, )
-SYMBOL(CommonReference, std::, )
-SYMBOL(Constructible, std::, )
-SYMBOL(ConvertibleTo, std::, )
-SYMBOL(CopyConstructible, std::, )
-SYMBOL(Copyable, std::, )
-SYMBOL(DefaultConstructible, std::, )
-SYMBOL(DerivedFrom, std::, )
-SYMBOL(Destructible, std::, )
-SYMBOL(EqualityComparable, std::, )
-SYMBOL(EqualityComparableWith, std::, )
-SYMBOL(FILE, std::, )
-SYMBOL(Integral, std::, )
-SYMBOL(Invocable, std::, )
-SYMBOL(Movable, std::, )
-SYMBOL(MoveConstructible, std::, )
-SYMBOL(Predicate, std::, )
-SYMBOL(Regular, std::, )
-SYMBOL(RegularInvocable, std::, )
-SYMBOL(Relation, std::, )
-SYMBOL(Same, std::, )
-SYMBOL(Semiregular, std::, )
-SYMBOL(SignedIntegral, std::, )
-SYMBOL(StrictTotallyOrdered, std::, )
-SYMBOL(StrictTotallyOrderedWith, std::, )
-SYMBOL(StrictWeakOrder, std::, )
-SYMBOL(Swappable, std::, )
-SYMBOL(SwappableWith, std::, )
-SYMBOL(UniformRandomBitGenerator, std::, )
-SYMBOL(UnsignedIntegral, std::, )
-SYMBOL(_Exit, std::, )
-SYMBOL(accumulate, std::, )
-SYMBOL(acos, std::, )
-SYMBOL(acosh, std::, )
-SYMBOL(add_const, std::, )
-SYMBOL(add_const_t, std::, )
-SYMBOL(add_cv, std::, )
-SYMBOL(add_cv_t, std::, )
-SYMBOL(add_lvalue_reference, std::, )
-SYMBOL(add_lvalue_reference_t, std::, )
-SYMBOL(add_pointer, std::, )
-SYMBOL(add_pointer_t, std::, )
-SYMBOL(add_rvalue_reference, std::, )
-SYMBOL(add_rvalue_reference_t, std::, )
-SYMBOL(add_volatile, std::, )
-SYMBOL(add_volatile_t, std::, )
-SYMBOL(addressof, std::, )
-SYMBOL(adjacent_difference, std::, )
-SYMBOL(adjacent_find, std::, )
-SYMBOL(adopt_lock, std::, )
-SYMBOL(adopt_lock_t, std::, )
-SYMBOL(advance, std::, )
-SYMBOL(align, std::, )
-SYMBOL(align_val_t, std::, )
-SYMBOL(aligned_alloc, std::, )
-SYMBOL(aligned_storage, std::, )
-SYMBOL(aligned_storage_t, std::, )
-SYMBOL(aligned_union, std::, )
-SYMBOL(aligned_union_t, std::, )
-SYMBOL(alignment_of, std::, )
-SYMBOL(alignment_of_v, std::, )
-SYMBOL(all_of, std::, )
-SYMBOL(allocate_shared, std::, )
-SYMBOL(allocator, std::, )
-SYMBOL(allocator_arg, std::, )
-SYMBOL(allocator_arg_t, std::, )
-SYMBOL(allocator_traits, std::, )
-SYMBOL(any, std::, )
-SYMBOL(any_of, std::, )
-SYMBOL(apply, std::, )
-SYMBOL(arg, std::, )
-SYMBOL(array, std::, )
-SYMBOL(as_const, std::, )
-SYMBOL(asctime, std::, )
-SYMBOL(asin, std::, )
-SYMBOL(asinh, std::, )
-SYMBOL(async, std::, )
-SYMBOL(at_quick_exit, std::, )
-SYMBOL(atan, std::, )
-SYMBOL(atan2, std::, )
-SYMBOL(atanh, std::, )
-SYMBOL(atexit, std::, )
-SYMBOL(atof, std::, )
-SYMBOL(atoi, std::, )
-SYMBOL(atol, std::, )
-SYMBOL(atoll, std::, )
-SYMBOL(atomic_compare_exchange_strong, std::, )
-SYMBOL(atomic_compare_exchange_strong_explicit, std::, )
-SYMBOL(atomic_compare_exchange_weak, std::, )
-SYMBOL(atomic_compare_exchange_weak_explicit, std::, )
-SYMBOL(atomic_exchange, std::, )
-SYMBOL(atomic_exchange_explicit, std::, )
-SYMBOL(atomic_fetch_add, std::, )
-SYMBOL(atomic_fetch_add_explicit, std::, )
-SYMBOL(atomic_fetch_and, std::, )
-SYMBOL(atomic_fetch_and_explicit, std::, 

[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant

2023-02-06 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 495122.
xgupta added a comment.

remove old code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142609

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/test/C/drs/dr4xx.c
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp
  clang/test/Parser/cxx2a-concept-declaration.cpp
  clang/test/Sema/exprs.c
  clang/test/SemaCXX/expressions.cpp
  clang/test/SemaCXX/warn-unsequenced.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -43,7 +43,9 @@
 
 namespace PR7724 {
   template int myMethod()
-  { return 2 && sizeof(OT); }
+  { return 2 && sizeof(OT); } // expected-warning {{use of logical '&&' with constant operand}} \
+  // expected-note {{use '&' for a bitwise operation}} \
+  // expected-note {{remove constant to silence this warning}}
 }
 
 namespace test4 {
Index: clang/test/SemaCXX/warn-unsequenced.cpp
===
--- clang/test/SemaCXX/warn-unsequenced.cpp
+++ clang/test/SemaCXX/warn-unsequenced.cpp
@@ -76,15 +76,37 @@
 
   (xs[2] && (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
-  (0 && (a = 0)) + a; // ok
+
+  (0 && (a = 0)) + a; // cxx11-warning {{use of logical '&&' with constant operand}}
+  // cxx11-note@-1 {{use '&' for a bitwise operation}}
+  // cxx11-note@-2 {{remove constant to silence this warning}}
+  // cxx17-warning@-3 {{use of logical '&&' with constant operand}}
+  // cxx17-note@-4 {{use '&' for a bitwise operation}}
+  // cxx17-note@-5 {{remove constant to silence this warning}}
+
   (1 && (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+  // cxx11-warning@-2 {{use of logical '&&' with constant operand}}
+  // cxx11-note@-3 {{use '&' for a bitwise operation}}
+  // cxx11-note@-4 {{remove constant to silence this warning}}
+  // cxx17-warning@-5 {{use of logical '&&' with constant operand}}
+  // cxx17-note@-6 {{use '&' for a bitwise operation}}
+  // cxx17-note@-7 {{remove constant to silence this warning}}
+
 
   (xs[3] || (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
   (0 || (a = 0)) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
-  (1 || (a = 0)) + a; // ok
+  // cxx11-warning@-2 {{use of logical '||' with constant operand}}
+  // cxx11-note@-3 {{use '|' for a bitwise operation}}
+  // cxx17-warning@-4 {{use of logical '||' with constant operand}}
+  // cxx17-note@-5 {{use '|' for a bitwise operation}}
+  (1 || (a = 0)) + a; // cxx11-warning {{use of logical '||' with constant operand}}
+  // cxx11-note@-1 {{use '|' for a bitwise operation}}
+  // cxx17-warning@-2 {{use of logical '||' with constant operand}}
+  // cxx17-note@-3 {{use '|' for a bitwise operation}}
+
 
   (xs[4] ? a : ++a) + a; // cxx11-warning {{unsequenced modification and access to 'a'}}
  // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
Index: clang/test/SemaCXX/expressions.cpp
===
--- clang/test/SemaCXX/expressions.cpp
+++ clang/test/SemaCXX/expressions.cpp
@@ -44,6 +44,9 @@
   return x && 4; // expected-warning {{use of logical '&&' with constant operand}} \
// expected-note {{use '&' for a bitwise operation}} \
// expected-note {{remove constant to silence this warning}}
+  return 4 && x; // expected-warning {{use of logical '&&' with constant operand}} \
+   // expected-note {{use '&' for a bitwise operation}} \
+   // expected-note {{remove constant to silence this warning}}
 
   return x && sizeof(int) == 4;  // no warning, RHS is logical op.
   return x && true;
@@ -66,6 +69,8 @@
// expected-note {{use '|' for a bitwise operation}}
   return x || 5; // expected-warning {{use of logical '||' with constant operand}

[PATCH] D142277: [clang][Interp] Clear metadata when destroying locals

2023-02-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/EvalEmitter.cpp:260-261
+// local variable is used after being destroyed.
+InlineDescriptor &ID = *reinterpret_cast(B->rawData());
+std::memset(&ID, 0, sizeof(InlineDescriptor));
   }

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > I'm not certain this is a good idea -- we've just deallocated `B` and 
> > > then we're saying "cool, now get me your raw data so I can muck about 
> > > with it".
> > > 
> > > The comments in `InterpState::deallocate()` say `// Free storage, if 
> > > necessary.`, so this looks a lot like a use-after-free. Am I missing 
> > > something?
> > `deallocate()` doesn't free the `Block`'s memory though, so we can still 
> > use it afterwards. That's why I had the problems with 
> > https://reviews.llvm.org/rG5b54cf1a2892767fe949826a32d7820732028a38 and 
> > neither a
> >  I could also move this code to `deallocate` directly.
> > 
> > This is just a security measure so we don't end up emitting a `load` 
> > instruction for a variable we've already emitted a `destroy` instruction 
> > for. So just for me, not for users.
> Ugh... so we have a function named `deallocate` that doesn't actually 
> deallocate? Should we rename that?
> 
> It's hard to consider it a security measure when it looks so much like a 
> use-after-free. Can we make whatever `Desc->DtorFn` resolves to do the 
> `memset` instead (so it's hidden within `deallocate()` rather than comes 
> after it)?
Doing it in `InterpBlock::invokeDtor()` would be a lot cleaner IMO, however, 
that is only for the data part, not the metadata. That is important for local 
variables that we reuse in loops; they get their metadata set once and that's 
it.

I'll just drop this patch since it had limited value anyway.


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

https://reviews.llvm.org/D142277

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


[clang] 993bce9 - [HIP] Support ASAN with malloc/free

2023-02-06 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-02-06T10:18:02-05:00
New Revision: 993bce9680c6a8f403a4a753fcbcb13ac7cddca3

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

LOG: [HIP] Support ASAN with malloc/free

Device side malloc/free needs special
implementation for ASAN.

Reviewed by: Artem Belevich, Matt Arsenault

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

Added: 


Modified: 
clang/lib/Headers/__clang_hip_runtime_wrapper.h
clang/test/Headers/hip-header.hip

Removed: 




diff  --git a/clang/lib/Headers/__clang_hip_runtime_wrapper.h 
b/clang/lib/Headers/__clang_hip_runtime_wrapper.h
index 0508731de1062..e8817073efdbc 100644
--- a/clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ b/clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -80,12 +80,25 @@ extern "C" {
 #if HIP_VERSION_MAJOR * 100 + HIP_VERSION_MINOR >= 405
 extern "C" __device__ unsigned long long __ockl_dm_alloc(unsigned long long 
__size);
 extern "C" __device__ void __ockl_dm_dealloc(unsigned long long __addr);
+#if __has_feature(address_sanitizer)
+extern "C" __device__ unsigned long long __asan_malloc_impl(unsigned long long 
__size, unsigned long long __pc);
+extern "C" __device__ void __asan_free_impl(unsigned long long __addr, 
unsigned long long __pc);
+__attribute__((noinline, weak)) __device__ void *malloc(__hip_size_t __size) {
+  unsigned long long __pc = (unsigned long long)__builtin_return_address(0);
+  return (void *)__asan_malloc_impl(__size, __pc);
+}
+__attribute__((noinline, weak)) __device__ void free(void *__ptr) {
+  unsigned long long __pc = (unsigned long long)__builtin_return_address(0);
+  __asan_free_impl((unsigned long long)__ptr, __pc);
+}
+#else
 __attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
   return (void *) __ockl_dm_alloc(__size);
 }
 __attribute__((weak)) inline __device__ void free(void *__ptr) {
   __ockl_dm_dealloc((unsigned long long)__ptr);
 }
+#endif // __has_feature(address_sanitizer)
 #else  // HIP version check
 #if __HIP_ENABLE_DEVICE_MALLOC__
 __device__ void *__hip_malloc(__hip_size_t __size);

diff  --git a/clang/test/Headers/hip-header.hip 
b/clang/test/Headers/hip-header.hip
index 84870584417ae..73fc075b23123 100644
--- a/clang/test/Headers/hip-header.hip
+++ b/clang/test/Headers/hip-header.hip
@@ -32,6 +32,14 @@
 // RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
 // RUN:   -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
 // RUN:   -D__HIPCC_RTC__ | FileCheck -check-prefixes=CHECK,MALLOC %s
+// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
+// RUN:   -internal-isystem %S/Inputs/include \
+// RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
+// RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
+// RUN:   -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
+// RUN:   -fsanitize=address -disable-llvm-passes -D__HIPCC_RTC__ \
+// RUN:   | FileCheck -check-prefixes=MALLOC-ASAN %s
 
 // expected-no-diagnostics
 
@@ -130,6 +138,9 @@ __device__ double test_isnan() {
 // CHECK-LABEL: define weak {{.*}}i8* @malloc(i64
 // MALLOC:  call i64 @__ockl_dm_alloc
 // NOMALLOC:  call void @llvm.trap
+// MALLOC-ASAN-LABEL: define weak {{.*}}i8* @malloc(i64
+// MALLOC-ASAN:  call i8* @llvm.returnaddress(i32 0)
+// MALLOC-ASAN:  call i64 @__asan_malloc_impl(i64 {{.*}}, i64 {{.*}})
 __device__ void test_malloc(void *a) {
   a = malloc(42);
 }
@@ -139,6 +150,9 @@ __device__ void test_malloc(void *a) {
 // CHECK-LABEL: define weak {{.*}}void @free(i8*
 // MALLOC:  call void @__ockl_dm_dealloc
 // NOMALLOC: call void @llvm.trap
+// MALLOC-ASAN-LABEL: define weak {{.*}}void @free(i8*
+// MALLOC-ASAN:  call i8* @llvm.returnaddress(i32 0)
+// MALLOC-ASAN:  call void @__asan_free_impl(i64 {{.*}}, i64 {{.*}})
 __device__ void test_free(void *a) {
   free(a);
 }



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


[PATCH] D143111: [HIP] Support ASAN with malloc/free

2023-02-06 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG993bce9680c6: [HIP] Support ASAN with malloc/free (authored 
by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143111

Files:
  clang/lib/Headers/__clang_hip_runtime_wrapper.h
  clang/test/Headers/hip-header.hip


Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -32,6 +32,14 @@
 // RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
 // RUN:   -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
 // RUN:   -D__HIPCC_RTC__ | FileCheck -check-prefixes=CHECK,MALLOC %s
+// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
+// RUN:   -internal-isystem %S/Inputs/include \
+// RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
+// RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
+// RUN:   -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
+// RUN:   -fsanitize=address -disable-llvm-passes -D__HIPCC_RTC__ \
+// RUN:   | FileCheck -check-prefixes=MALLOC-ASAN %s
 
 // expected-no-diagnostics
 
@@ -130,6 +138,9 @@
 // CHECK-LABEL: define weak {{.*}}i8* @malloc(i64
 // MALLOC:  call i64 @__ockl_dm_alloc
 // NOMALLOC:  call void @llvm.trap
+// MALLOC-ASAN-LABEL: define weak {{.*}}i8* @malloc(i64
+// MALLOC-ASAN:  call i8* @llvm.returnaddress(i32 0)
+// MALLOC-ASAN:  call i64 @__asan_malloc_impl(i64 {{.*}}, i64 {{.*}})
 __device__ void test_malloc(void *a) {
   a = malloc(42);
 }
@@ -139,6 +150,9 @@
 // CHECK-LABEL: define weak {{.*}}void @free(i8*
 // MALLOC:  call void @__ockl_dm_dealloc
 // NOMALLOC: call void @llvm.trap
+// MALLOC-ASAN-LABEL: define weak {{.*}}void @free(i8*
+// MALLOC-ASAN:  call i8* @llvm.returnaddress(i32 0)
+// MALLOC-ASAN:  call void @__asan_free_impl(i64 {{.*}}, i64 {{.*}})
 __device__ void test_free(void *a) {
   free(a);
 }
Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -80,12 +80,25 @@
 #if HIP_VERSION_MAJOR * 100 + HIP_VERSION_MINOR >= 405
 extern "C" __device__ unsigned long long __ockl_dm_alloc(unsigned long long 
__size);
 extern "C" __device__ void __ockl_dm_dealloc(unsigned long long __addr);
+#if __has_feature(address_sanitizer)
+extern "C" __device__ unsigned long long __asan_malloc_impl(unsigned long long 
__size, unsigned long long __pc);
+extern "C" __device__ void __asan_free_impl(unsigned long long __addr, 
unsigned long long __pc);
+__attribute__((noinline, weak)) __device__ void *malloc(__hip_size_t __size) {
+  unsigned long long __pc = (unsigned long long)__builtin_return_address(0);
+  return (void *)__asan_malloc_impl(__size, __pc);
+}
+__attribute__((noinline, weak)) __device__ void free(void *__ptr) {
+  unsigned long long __pc = (unsigned long long)__builtin_return_address(0);
+  __asan_free_impl((unsigned long long)__ptr, __pc);
+}
+#else
 __attribute__((weak)) inline __device__ void *malloc(__hip_size_t __size) {
   return (void *) __ockl_dm_alloc(__size);
 }
 __attribute__((weak)) inline __device__ void free(void *__ptr) {
   __ockl_dm_dealloc((unsigned long long)__ptr);
 }
+#endif // __has_feature(address_sanitizer)
 #else  // HIP version check
 #if __HIP_ENABLE_DEVICE_MALLOC__
 __device__ void *__hip_malloc(__hip_size_t __size);


Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -32,6 +32,14 @@
 // RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
 // RUN:   -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
 // RUN:   -D__HIPCC_RTC__ | FileCheck -check-prefixes=CHECK,MALLOC %s
+// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
+// RUN:   -internal-isystem %S/Inputs/include \
+// RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
+// RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
+// RUN:   -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
+// RUN:   -fsanitize=address -disable-llvm-passes -D__HIPCC_RTC__ \
+// RUN:   | FileCheck -check-prefixes=MALLOC-ASAN %s
 
 // expected-no-diagnostics
 
@@ -130,6 +138,9 @@
 // CHECK-LABEL: define weak {{.*}}i8* @malloc(i64
 // MALLOC:  call i64 @__ockl_dm_alloc
 // NOMALLOC:  call void @llvm.trap
+// MALLOC-ASAN-LABEL: define weak {{.*}}i8* @malloc(i64
+// MALLOC-ASAN:  call i8* @llvm.returnaddress(i32 0

[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

2023-02-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/Interp.cpp:264-270
+  const Function *Func = S.Current->getFunction();
+  if (Func && Func->isConstructor()) {
+// The This pointer is writable in constructors, even if
+// isConst() returns true.
+if (Ptr.block() == S.Current->getThis().block())
+  return true;
+  }

The same is true for destructors as well: https://godbolt.org/z/a49aEErz8


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136751

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


[clang] 0ffaffc - Reapply 6fa2abf90886f18472c87bc9bffbcdf4f73c465e

2023-02-06 Thread via cfe-commits

Author: serge-sans-paille
Date: 2023-02-06T16:44:11+01:00
New Revision: 0ffaffcaac97de31e1b0e7e80c4f7cab724eda20

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

LOG: Reapply 6fa2abf90886f18472c87bc9bffbcdf4f73c465e

Lazyly initialize uncommon toolchain detector

Cuda and rocm toolchain detectors are currently run unconditionally,
while their result may not be used at all. Make their initialization
lazy so that the discovery code is not run in common cases.

Reapplied since 77910ac374656319ff114ef251fda358d4aa166a landed and
fixes the test ordering issue.

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

Added: 
clang/lib/Driver/ToolChains/LazyDetector.h

Modified: 
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Gnu.h
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/lib/Driver/ToolChains/Linux.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 52021901b9bf8..a25bea951388c 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -701,7 +701,7 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList 
&DriverArgs,
 ROCMToolChain::ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
  const ArgList &Args)
 : AMDGPUToolChain(D, Triple, Args) {
-  RocmInstallation.detectDeviceLibrary();
+  RocmInstallation->detectDeviceLibrary();
 }
 
 void AMDGPUToolChain::addClangTargetOptions(
@@ -790,11 +790,11 @@ void ROCMToolChain::addClangTargetOptions(
   const StringRef GpuArch = getGPUArch(DriverArgs);
   auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
   const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
-  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
+  StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
   auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
-  if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
-   ABIVer))
+  if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
+ABIVer))
 return;
 
   bool Wave64 = isWave64(DriverArgs, Kind);
@@ -813,10 +813,10 @@ void ROCMToolChain::addClangTargetOptions(
 
   // Add the OpenCL specific bitcode library.
   llvm::SmallVector BCLibs;
-  BCLibs.push_back(RocmInstallation.getOpenCLPath().str());
+  BCLibs.push_back(RocmInstallation->getOpenCLPath().str());
 
   // Add the generic set of libraries.
-  BCLibs.append(RocmInstallation.getCommonBitcodeLibs(
+  BCLibs.append(RocmInstallation->getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, false));
 
@@ -875,11 +875,11 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   auto Kind = llvm::AMDGPU::parseArchAMDGCN(GPUArch);
   const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
 
-  StringRef LibDeviceFile = RocmInstallation.getLibDeviceFile(CanonArch);
+  StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
   auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
   getAMDGPUCodeObjectVersion(getDriver(), DriverArgs));
-  if (!RocmInstallation.checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
-   ABIVer))
+  if (!RocmInstallation->checkCommonBitcodeLibs(CanonArch, LibDeviceFile,
+ABIVer))
 return {};
 
   // If --hip-device-lib is not set, add the default bitcode libraries.
@@ -900,7 +900,7 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt, true);
   bool Wave64 = isWave64(DriverArgs, Kind);
 
-  return RocmInstallation.getCommonBitcodeLibs(
+  return RocmInstallation->getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
 }

diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 68d351af22603..b012b7cb72937 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -160,7 +160,7 @@ AMDGPUOpenMPToolChain::getDeviceLibs(const 
llvm::opt::ArgList &Args) const {
   if (Args.hasArg(options::OPT_nogpulib))
 return {};
 
-  if (!RocmInstallation.hasDeviceLibrary())

[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-06 Thread serge via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0ffaffcaac97: Reapply 
6fa2abf90886f18472c87bc9bffbcdf4f73c465e (authored by serge-sans-paille).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142606

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/lib/Driver/ToolChains/LazyDetector.h
  clang/lib/Driver/ToolChains/Linux.cpp

Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -681,23 +681,23 @@
 
 void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
-  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
+  CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
 }
 
 void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs,
   ArgStringList &CC1Args) const {
-  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
+  RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
 void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
   CmdArgs.push_back(
-  Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()));
+  Args.MakeArgString(StringRef("-L") + RocmInstallation->getLibPath()));
 
   if (Args.hasFlag(options::OPT_offload_add_rpath,
options::OPT_no_offload_add_rpath, false))
 CmdArgs.append(
-{"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
+{"-rpath", Args.MakeArgString(RocmInstallation->getLibPath())});
 
   CmdArgs.push_back("-lamdhip64");
 }
Index: clang/lib/Driver/ToolChains/LazyDetector.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/LazyDetector.h
@@ -0,0 +1,45 @@
+//===--- LazyDetector.h - Lazy ToolChain Detection --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+#include 
+
+namespace clang {
+
+/// Simple wrapper for toolchain detector with costly initialization. This
+/// delays the creation of the actual detector until its first usage.
+
+template  class LazyDetector {
+  const driver::Driver &D;
+  const llvm::Triple &Triple;
+  const llvm::opt::ArgList &Args;
+
+  std::optional Detector;
+
+public:
+  LazyDetector(const driver::Driver &D, const llvm::Triple &Triple,
+   const llvm::opt::ArgList &Args)
+  : D(D), Triple(Triple), Args(Args) {}
+  T *operator->() {
+if (!Detector)
+  Detector.emplace(D, Triple, Args);
+return &*Detector;
+  }
+  const T *operator->() const {
+return const_cast(
+const_cast(*this).operator->());
+  }
+};
+
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -314,7 +314,7 @@
 
 void HIPAMDToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
 ArgStringList &CC1Args) const {
-  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
+  RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
 SanitizerMask HIPAMDToolChain::getSupportedSanitizers() const {
@@ -343,7 +343,7 @@
   ArgStringList LibraryPaths;
 
   // Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
-  for (StringRef Path : RocmInstallation.getRocmDeviceLibPathArg())
+  for (StringRef Path : RocmInstallation->getRocmDeviceLibPathArg())
 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
 
   addDirectoryList(DriverArgs, LibraryPaths, "", "HIP_DEVICE_LIB_PATH");
@@ -365,7 +365,7 @@
   getDriver().Diag(diag::err_drv_no_such_file) << BCName;
 });
   } else {
-if (!RocmInstallation.hasDeviceLibrary()) {
+if (!RocmInstallation->hasDeviceLibrary()) {
   getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 0;
   return {};
 }
@@ -376,7 +376,7 @@
 if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize,

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

2023-02-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D141472#4106091 , @tbaeder wrote:

>> Member pointers (for functions or for data) are weird in that they're not 
>> the typical pointer width. They're actually a pointer and between 
>> one-to-three other fields in a trenchcoat, depending on the circumstances. 
>> You generally need the function pointer, but you also may need various 
>> offsets (to this, to the vtable, etc). There's some more information about 
>> how it's done in MSVC (which is different from Itanium ABI, but we can do 
>> what we want for the constant expression interpreter): 
>> https://rants.vastheman.com/2021/09/21/msvc/
>>
>> I don't think there's a problem with `FunctionPointer` per se, I'm more 
>> wondering are you planning to also add a `MemberPointer` type or are you 
>> planning to reuse `FunctionPointer` to handle function members (and 
>> presumably something else for data members)?
>>
>> As for virtual functions in general, the standard has rules: 
>> http://eel.is/c++draft/expr.const#5.6 and http://eel.is/c++draft/expr.const#7
>
> I was thinking that the `dynamicDispatch` in https://godbolt.org/z/rf9Ks77Wo 
> would be a good reproducer since the actual function to call is only known 
> when calling `dynamicDispatch()`, but that example already works when doing a 
> few changes to `classify()` the right types and adding a `if 
> (BO->isPtrMemOP()) { return visit(RHS); }` to `VisitBinaryOperator()`.

That is a reasonable test, but probably not sufficient as nothing is really 
testing the layout of those objects (the calls return a constant). How about a 
test like: https://godbolt.org/z/rhhhvxYxf where there are offsets to member 
variables involved?


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

https://reviews.llvm.org/D141472

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


[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

2023-02-06 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 495147.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D136751

Files:
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Pointer.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
@@ -201,3 +201,37 @@
// ref-note {{subobject of type 'bool' is not initialized}}
 #endif
 };
+
+namespace ConstThis {
+  class Foo {
+const int T = 12; // expected-note {{declared const here}} \
+  // ref-note {{declared const here}}
+int a;
+  public:
+constexpr Foo() {
+  this->a = 10;
+  T = 13; // expected-error {{cannot assign to non-static data member 'T' 
with const-qualified type}} \
+  // ref-error {{cannot assign to non-static data member 'T' with 
const-qualified type}}
+}
+  };
+  constexpr Foo F; // expected-error {{must be initialized by a constant 
expression}} \
+   // ref-error {{must be initialized by a constant 
expression}}
+
+
+  class FooDtor {
+int a;
+  public:
+constexpr FooDtor() {
+  this->a = 10;
+}
+constexpr ~FooDtor() {
+  this->a = 12;
+}
+  };
+
+  constexpr int foo() {
+const FooDtor f;
+return 0;
+  }
+  static_assert(foo() == 0);
+};
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -290,6 +290,8 @@
   /// Returns the number of elements.
   unsigned getNumElems() const { return getSize() / elemSize(); }
 
+  Block *block() const { return Pointee; }
+
   /// Returns the index into an array.
   int64_t getIndex() const {
 if (isElementPastEnd())
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -213,8 +213,15 @@
 
 bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
   assert(Ptr.isLive() && "Pointer is not live");
-  if (!Ptr.isConst()) {
+  if (!Ptr.isConst())
 return true;
+
+  // The This pointer is writable in constructors and destructors,
+  // even if isConst() returns true.
+  if (const Function *Func = S.Current->getFunction();
+  Func && (Func->isConstructor() || Func->isDestructor())) {
+if (Ptr.block() == S.Current->getThis().block())
+  return true;
   }
 
   const QualType Ty = Ptr.getType();
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -129,6 +129,8 @@
 
   /// Checks if the function is a constructor.
   bool isConstructor() const { return isa(F); }
+  /// Checks if the function is a destructor.
+  bool isDestructor() const { return isa(F); }
 
   /// Checks if the function is fully done compiling.
   bool isFullyCompiled() const { return IsFullyCompiled; }


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -201,3 +201,37 @@
// ref-note {{subobject of type 'bool' is not initialized}}
 #endif
 };
+
+namespace ConstThis {
+  class Foo {
+const int T = 12; // expected-note {{declared const here}} \
+  // ref-note {{declared const here}}
+int a;
+  public:
+constexpr Foo() {
+  this->a = 10;
+  T = 13; // expected-error {{cannot assign to non-static data member 'T' with const-qualified type}} \
+  // ref-error {{cannot assign to non-static data member 'T' with const-qualified type}}
+}
+  };
+  constexpr Foo F; // expected-error {{must be initialized by a constant expression}} \
+   // ref-error {{must be initialized by a constant expression}}
+
+
+  class FooDtor {
+int a;
+  public:
+constexpr FooDtor() {
+  this->a = 10;
+}
+constexpr ~FooDtor() {
+  this->a = 12;
+}
+  };
+
+  constexpr int foo() {
+const FooDtor f;
+return 0;
+  }
+  static_assert(foo() == 0);
+};
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -290,6 +290,8 @@
   /// Returns the number of elements.
   unsigned getNumElems() const { return getSize() / elemSize(); }
 
+  Block *block() const { return Pointee; }
+
   /// Returns the index into an array.
   int64_t getIndex() const {
 if (isElementPastEnd())
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
++

[PATCH] D136751: [clang][Interp] This pointers are writable in constructors

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



Comment at: clang/lib/AST/Interp/Interp.cpp:264-270
+  const Function *Func = S.Current->getFunction();
+  if (Func && Func->isConstructor()) {
+// The This pointer is writable in constructors, even if
+// isConst() returns true.
+if (Ptr.block() == S.Current->getThis().block())
+  return true;
+  }

aaron.ballman wrote:
> The same is true for destructors as well: https://godbolt.org/z/a49aEErz8
Oh, good catch, thanks.


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

https://reviews.llvm.org/D136751

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


[clang] d2b0b26 - [Coroutines] Pass size parameter for deallocation function when qualified

2023-02-06 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-02-07T00:22:22+08:00
New Revision: d2b0b26132ce5d3d9022edbf274f01e9de764673

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

LOG: [Coroutines] Pass size parameter for deallocation function when qualified

Close https://github.com/llvm/llvm-project/issues/60545.

Previously, we would only pass the size parameter to the deallocation
function if the type is completely the same. But it is good enough to
make them unqualified the smae.

Added: 


Modified: 
clang/lib/Sema/SemaCoroutine.cpp
clang/test/SemaCXX/coroutine-dealloc.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index 79c08adb8fab..9678e30699c8 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1562,7 +1562,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
   const auto *OpDeleteType =
   OpDeleteQualType.getTypePtr()->castAs();
   if (OpDeleteType->getNumParams() > DeleteArgs.size() &&
-  S.getASTContext().hasSameType(
+  S.getASTContext().hasSameUnqualifiedType(
   OpDeleteType->getParamType(DeleteArgs.size()), FrameSize->getType()))
 DeleteArgs.push_back(FrameSize);
 
@@ -1579,7 +1579,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
   // So we are not forced to pass alignment to the deallocation function.
   if (S.getLangOpts().CoroAlignedAllocation &&
   OpDeleteType->getNumParams() > DeleteArgs.size() &&
-  S.getASTContext().hasSameType(
+  S.getASTContext().hasSameUnqualifiedType(
   OpDeleteType->getParamType(DeleteArgs.size()),
   FrameAlignment->getType()))
 DeleteArgs.push_back(FrameAlignment);

diff  --git a/clang/test/SemaCXX/coroutine-dealloc.cpp 
b/clang/test/SemaCXX/coroutine-dealloc.cpp
index 6eca1e6f42f8..762a14465b29 100644
--- a/clang/test/SemaCXX/coroutine-dealloc.cpp
+++ b/clang/test/SemaCXX/coroutine-dealloc.cpp
@@ -25,3 +25,19 @@ struct task {
 task f() {
   co_return 43;
 }
+
+// From https://github.com/llvm/llvm-project/issues/60545
+struct generator {
+struct promise_type {
+generator get_return_object();
+std::suspend_always initial_suspend();
+std::suspend_always final_suspend() noexcept;
+void return_void();
+[[noreturn]] void unhandled_exception();
+
+static void* operator new(std::size_t size);
+static void operator delete(void* ptr, const std::size_t size);
+};
+};
+
+generator goo() { co_return; }



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


[PATCH] D143348: [Clang][Doc][OpenCL] Release 16 notes

2023-02-06 Thread Tom Stellard via Phabricator via cfe-commits
tstellar accepted this revision.
tstellar added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D143348

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


[PATCH] D138453: [clang] Add serialization for loop hint annotation tokens

2023-02-06 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

In D138453#410 , @aaron.ballman 
wrote:

> In D138453#4105211 , @DHowett-MSFT 
> wrote:
>
>> 



>> I believe it's expected that we hit this assertion - it's clearer than the 
>> original message, and more directly indicates that `#pragma pack` cannot be 
>> serialized.
>
> Failed assertions or reaching code marked as unreachable is always a bug -- 
> we should be failing gracefully with diagnostics and not crashing.

My intention is to go through all the pragmas and implement serialization for 
any that need it. If there are some that we don't want to do or if this takes a 
long time, I will do ahead and add a diagnostic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138453

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


[PATCH] D143411: [NFC][clang] Fix static analyzer concern about uninitialized variable

2023-02-06 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Fznamznon added reviewers: NoQ, xazax.hun, gribozavr, ymandel, sgatev.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, rnkovacs, baloghadamsoftware.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143411

Files:
  clang/lib/Sema/AnalysisBasedWarnings.cpp


Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -574,6 +574,7 @@
 D.diag_AlwaysFallThrough_HasNoReturn = 0;
 D.diag_AlwaysFallThrough_ReturnsNonVoid =
 diag::warn_falloff_nonvoid_coroutine;
+D.diag_NeverFallThroughOrReturn = 0;
 D.funMode = Coroutine;
 return D;
   }


Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -574,6 +574,7 @@
 D.diag_AlwaysFallThrough_HasNoReturn = 0;
 D.diag_AlwaysFallThrough_ReturnsNonVoid =
 diag::warn_falloff_nonvoid_coroutine;
+D.diag_NeverFallThroughOrReturn = 0;
 D.funMode = Coroutine;
 return D;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143412: [HIP] Update test hip-header.hip

2023-02-06 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, arsenm.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.

remove -no-opaque-pointers


https://reviews.llvm.org/D143412

Files:
  clang/test/Headers/hip-header.hip


Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -1,38 +1,38 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
 // RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
 // RUN:   -internal-isystem %S/Inputs/include \
 // RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
 // RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
 // RUN:   -D__HIPCC_RTC__ | FileCheck -check-prefixes=CHECK,NOMALLOC %s
-// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
 // RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
 // RUN:   -internal-isystem %S/Inputs/include \
 // RUN:   -include cmath \
 // RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
 // RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
 // RUN:   -D__HIPCC_RTC__ | FileCheck %s  -check-prefixes=AMD_BOOL_RETURN
-// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
 // RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
 // RUN:   -internal-isystem %S/Inputs/include \
 // RUN:   -include cmath \
 // RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
 // RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
 // RUN:   -D__HIPCC_RTC__ -DUSE_ISNAN_WITH_INT_RETURN | FileCheck %s 
-check-prefixes=AMD_INT_RETURN
-// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
 // RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
 // RUN:   -internal-isystem %S/Inputs/include \
 // RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
 // RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
 // RUN:   -D__HIPCC_RTC__ -std=c++14 | FileCheck -check-prefixes=CHECK,CXX14 %s
-// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
 // RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
 // RUN:   -internal-isystem %S/Inputs/include \
 // RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
 // RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -o - \
 // RUN:   -DHIP_VERSION_MAJOR=4 -DHIP_VERSION_MINOR=5 \
 // RUN:   -D__HIPCC_RTC__ | FileCheck -check-prefixes=CHECK,MALLOC %s
-// RUN: %clang_cc1 -no-opaque-pointers -include __clang_hip_runtime_wrapper.h \
+// RUN: %clang_cc1 -include __clang_hip_runtime_wrapper.h \
 // RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
 // RUN:   -internal-isystem %S/Inputs/include \
 // RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
@@ -60,8 +60,8 @@
 __device__ void test_vf() {
 derived d;
 }
-// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 
x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.derived*)* 
@_ZN7derived2pvEv to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to 
i8*)] }, comdat, align 8
-// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x 
i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (void ()* 
@__cxa_pure_virtual to i8*), i8* bitcast (void ()* @__cxa_deleted_virtual to 
i8*)] }, comdat, align 8
+// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 
x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN7derived2pvEv, ptr 
@__cxa_deleted_virtual] }, comdat, align 8
+// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x 
ptr] } { [4 x ptr] [ptr null, ptr null, ptr @__cxa_pure_virtual, ptr 
@__cxa_deleted_virtual] }, comdat, align 8
 
 // CHECK: define{{.*}}void @__cxa_pure_virtual()
 // CHECK: define{{.*}}void @__cxa_deleted_virtual()
@@ -134,24 +134,24 @@
 // Check that device malloc and free do not conflict with std headers.
 #include 
 // CHECK-LABEL: define{{.*}}@_Z11test_malloc
-// CHECK: call {{.*}}i8* @malloc(i64
-// CHECK-LABEL: define weak {{.*}}i8* @malloc(i64
+// CHECK: call {{.*}}ptr @malloc(i64
+// CHECK-LABEL: define weak {{.*}}ptr @malloc(i64
 // MALLOC:  call i64 @__ockl_dm_alloc
 // NOMALLOC:  call void @llvm.trap
-// MALLOC-ASAN-LABEL: define weak {{.*}}i8* @malloc(i64
-// MALLOC-ASAN:  call i8* @llvm.returnaddress(i32 0)
+// MALLOC-ASAN-LABEL: define weak {{.*}}ptr @malloc(i

[PATCH] D143300: [randstruct] Don't allow implicit forward decl to stop struct randomization

2023-02-06 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D143300#4104469 , @MaskRay wrote:

> `clang/test/CodeGen/init-randomized-struct-fwd-decl.c` passes without this 
> patch. Is it correct?

Perhaps related to my comment about RecordDecl vs EnumDecl...

or the tests might require a specific randomization seed?




Comment at: clang/lib/Sema/SemaDecl.cpp:18891
+// incomplete definition.
+if (const auto *RD = dyn_cast(D))
+  return !RD->isCompleteDefinition();

what about `EnumDecl`s? I suspect the shared common base `TagDecl` might be 
better to use?

If it is, can you add a test?  I'm guessing

```
struct foo {
  enum havent_seen_yet;
  enum havent_seen_yet2;
}
```
would be the test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143300

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


[PATCH] D143348: [Clang][Doc][OpenCL] Release 16 notes

2023-02-06 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:840
+  * Fixed conditional definition of the depth image and read_write image3d 
builtins.
+  * Added ``nounwind`` attribute to all builtin functions.
+

It's slightly more than that: clang adds `nounwind` not only for builtin 
functions, but for any OpenCL function call.


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

https://reviews.llvm.org/D143348

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


[PATCH] D143386: Add function pointer alignment to DataLayout

2023-02-06 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Almost all the specifications you're specifying are wrong.  Very few targets 
should be using "i".  Off the top of my head, 32-bit ARM, MIPS targets with 
MicroMIPS, and certain PowerPC targets should, but most common targets 
shouldn't.  ("i" means that either the target mangles the bottom bits of 
function pointers, or function pointers don't point directly at code.)  And the 
x86 doesn't specify 4-byte alignment.

For each target, we should try to handle the LLVM backend at the same time...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143386

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


[PATCH] D142893: [NFC] Class for building MultilibSet

2023-02-06 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

Looks good so far. Some stylistic suggestions.




Comment at: clang/include/clang/Driver/Multilib.h:25
 namespace driver {
 
 /// This corresponds to a single GCC Multilib, or a segment of one controlled

It took a bit of reading to work out what the relationship between Multilib, 
MultilibVariant, MultilibSet and MultilibVariantBuilder are and how they are 
expected to be used.

IIUC MultilibVariant and MultilibVariantBuilder are used to construct Multilib 
and MultilibSet, which are expected to be immutable post construction.

Will be worth either a comment describing the relation ship or potentially 
write up the design in the clang docs and reference it from here. 



Comment at: clang/include/clang/Driver/Multilib.h:40
 public:
   Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
+   StringRef IncludeSuffix = {}, int Priority = 0,

Could be worth documenting the requirement for the strings to start with a `/` 
or be empty as the constructor implementation in a different file will assert 
if they aren't?



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:32
 
-static Multilib makeMultilib(StringRef commonSuffix) {
-  return Multilib(commonSuffix, commonSuffix, commonSuffix);
+static MultilibBuilderVariant makeMultilib(StringRef commonSuffix) {
+  return MultilibBuilderVariant(commonSuffix, commonSuffix, commonSuffix);

Worth making this a lambda in findRISCVMultilibs? Purely subjective opinion 
here as there could be an attempt to limit changes.



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:44
   if (TargetTriple.isRISCV64()) {
-Multilib Imac = 
makeMultilib("").flag("+march=rv64imac").flag("+mabi=lp64");
-Multilib Imafdc = makeMultilib("/rv64imafdc/lp64d")
-  .flag("+march=rv64imafdc")
-  .flag("+mabi=lp64d");
+auto Imac = makeMultilib("").flag("+march=rv64imac").flag("+mabi=lp64");
+auto Imafdc = makeMultilib("/rv64imafdc/lp64d")

Wondering if we've lost information here by going to auto. We're really making 
a MultilibVariant here. Perhaps worth renaming makeMultilib to 
makeMultilibVariant?



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:1049
 
-static Multilib makeMultilib(StringRef commonSuffix) {
-  return Multilib(commonSuffix, commonSuffix, commonSuffix);
+static MultilibBuilderVariant makeMultilib(StringRef commonSuffix) {
+  return MultilibBuilderVariant(commonSuffix, commonSuffix, commonSuffix);

Similar comment to BareMetal, is it worth renaming to makeMultilibVariant



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:1737
   });
 
   Multilib::flags_list Flags;

Although I'm not too bothered myself, some people prefer to keep changes in 
whitespace to a separate NFC patch for the benefit of git annotate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142893

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


  1   2   3   >