[PATCH] D123126: [cmake] Remove LLVM_ENABLE_NEW_PASS_MANAGER cmake option

2022-04-06 Thread Nikita Popov 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 rGed4e6e03981a: [cmake] Remove LLVM_ENABLE_NEW_PASS_MANAGER 
cmake option (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D123126?vs=420484&id=420730#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123126

Files:
  clang/include/clang/Driver/Options.td
  clang/test/CMakeLists.txt
  clang/test/lit.cfg.py
  clang/test/lit.site.cfg.py.in
  clang/unittests/Frontend/CompilerInvocationTest.cpp
  lld/COFF/Driver.cpp
  lld/ELF/Driver.cpp
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/wasm/Driver.cpp
  llvm/CMakeLists.txt
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/docs/NewPassManager.rst
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/opt/opt.cpp
  llvm/utils/gn/secondary/clang/test/BUILD.gn
  llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
  utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -97,9 +97,6 @@
 /* Define to 1 if you have the  header file. */
 #cmakedefine HAVE_SYSEXITS_H ${HAVE_SYSEXITS_H}
 
-/* Define to 1 to enable the experimental new pass manager by default */
-#cmakedefine01 LLVM_ENABLE_NEW_PASS_MANAGER
-
 /* Define if the xar_open() function is supported on this platform. */
 #cmakedefine LLVM_HAVE_LIBXAR ${LLVM_HAVE_LIBXAR}
 
Index: utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h
===
--- utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h
+++ utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/llvm-config.h
@@ -105,9 +105,6 @@
 /* Define to 1 if you have the  header file. */
 /* HAVE_SYSEXITS_H defined in Bazel */
 
-/* Define to 1 to enable the experimental new pass manager by default */
-#define LLVM_ENABLE_NEW_PASS_MANAGER 0
-
 /* Define if the xar_open() function is supported this platform. */
 /* #undef HAVE_LIBXAR */
 
Index: llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -335,7 +335,6 @@
 "LLVM_BUILD_SHARED_LIBS=",
 "LLVM_DEFAULT_TARGET_TRIPLE=$llvm_target_triple",
 "LLVM_ENABLE_DUMP=",
-"LLVM_ENABLE_NEW_PASS_MANAGER=1",
 "LLVM_FORCE_ENABLE_STATS=",
 "LLVM_FORCE_USE_OLD_TOOLCHAIN=",
 "LLVM_HAS_ATOMICS=1",
Index: llvm/utils/gn/secondary/clang/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang/test/BUILD.gn
@@ -60,7 +60,6 @@
 "CMAKE_CXX_COMPILER=c++",
 "CMAKE_C_COMPILER=cc",
 "ENABLE_BACKTRACES=1",
-"LLVM_ENABLE_NEW_PASS_MANAGER=1",
 "LLVM_EXTERNAL_LIT=",
 "LLVM_HOST_TRIPLE=$llvm_current_triple",
 "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -75,7 +75,7 @@
 cl::desc("Enable the new pass manager, translating "
  "'opt -foo' to 'opt -passes=foo'. This is strictly for the new PM "
  "migration, use '-passes=' when possible."),
-cl::init(LLVM_ENABLE_NEW_PASS_MANAGER));
+cl::init(true));
 
 // This flag specifies a textual description of the optimization pass pipeline
 // to run over the module. This flag switches opt to use the new pass manager
Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -146,7 +146,7 @@
 static cl::opt
 UseNewPM("use-new-pm",
  cl::desc("Run LTO passes using the new pass manager"),
- cl::init(LLVM_ENABLE_NEW_PASS_MANAGER), cl::Hidden);
+ cl::init(true), cl::Hidden);
 
 static cl::opt
 DebugPassManager("debug-pass-manager", cl::init(false), cl::Hidden,
Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -256,9 +256,10 @@
 cl::desc("Inst

[PATCH] D123144: FileManager: std::map => BumpPtrAllocator + DenseMap of pointers

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/Basic/FileManager.cpp:318
   FileEntryRef ReturnedRef(*NamedFileEnt);
-  if (UFE.isValid()) { // Already have an entry with this inode, return it.
+  if (ReusingEntry) { // Already have an entry with this inode, return it.
 

dexonsmith wrote:
> I'm trying to figure out why `ReusingEntry` was necessary. It looks to me 
> like you could just call `UFE->isValid()` here and avoid introducing that 
> `bool`... or am I missing something?
You're right, but I think we can get rid of isValid, and plan to send a patch.

A FileEntry handed out by FileManager always has isValid = true. It's not 
possible to create a useful FileEntry outside FileManager (and this is never 
done outside FileManagerTest). So the concept of validity isn't needed.

(IMO the main cost of having the isValid flag is conceptual complexity - lots 
of places check it, which means people must be thinking about how to handle 
this case)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123144

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


[PATCH] D122285: [analyzer] Add path note tags to standard library function summaries.

2022-04-06 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:872-883
+if (NewState && NewState != State) {
+  StringRef Note = Case.getNote();
+  const NoteTag *Tag = C.getNoteTag(
+  // Sorry couldn't help myself.
+  [Node, Note]() {
+// Don't emit "Assuming..." note when we ended up
+// knowing in advance which branch is taken.

I thought we mostly have one or two cases. If we have two cases, then the 
constraint should be the opposite of the other one.

If this is the case, when does `NewState && NewState != State` not imply 
`Node->succ_size() > 1` given that `Summary.getCases().size() >= 2`?



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1326-1330
   // The locale-specific range.
   .Case({ArgumentCondition(0U, WithinRange, {{128, UCharRangeMax}})})
   // Is not an unsigned char.
   .Case({ArgumentCondition(0U, OutOfRange, Range(0, UCharRangeMax)),
  ReturnValueCondition(WithinRange, SingleValue(0))}));

Why don't we have notes for these cases?



Comment at: clang/test/Analysis/std-c-library-functions-path-notes.c:3
+// RUN: -analyzer-checker=core,apiModeling \
+// RUN: -analyzer-config assume-controlled-environment=false \
+// RUN: -analyzer-output=text

This is the default value. What's the benefit of passing this?


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

https://reviews.llvm.org/D122285

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


[PATCH] D122841: [analyzer] Consider all addrspaces in null dereference check

2022-04-06 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D122841#3431617 , @NoQ wrote:

> I looked up the history. I believe this refers to 
> https://clang.llvm.org/docs/LanguageExtensions.html#memory-references-to-specified-segments:
>
>> Annotating a pointer with address space #256 causes it to be code generated 
>> relative to the X86 GS segment register, address space #257 causes it to be 
>> relative to the X86 FS segment, and address space #258 causes it to be 
>> relative to the X86 SS segment. Note that this is a very very low-level 
>> feature that should only be used if you know what you’re doing (for example 
>> in an OS kernel).
>
> So basically `((void *__attribute__((address_space(256))) *)0)` is a valid 
> pointer that can be safely dereferenced.

Well, it seems like, on Windows, the `FS` register points to the `Win32 Thread 
Environment Block - TEB` (wiki 
). And at offset 
`0x0`, resides the pointer to the `Current Structured Exception Handling (SEH) 
frame`, making it perfectly valid to load and dereference `FS:[0]`. Using `FS` 
and `GS` registers are frequently used for implementing anti-debug tricks 

 in practice, but I think it's fairly safe to say that they are not our primary 
audience.

> I'm not aware of other situations of this kind. Probably this address space 
> range can be hardcoded, and/or a run-time checker option can be provided to 
> enable/disable this behavior.

That being said, I think it might deserve a //user-facing// analyzer config 
option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

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


[PATCH] D123070: [Driver][NFC] Simplify handling of flags in Options.td

2022-04-06 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D123070#3429519 , @hans wrote:

> I worry that the closing comments on '}'s might rot since there's no tooling 
> to maintain them though.

I share your concern. However, from my experience these `let` statements rarely 
change (i.e. this file is fairly stable), so the risk is not that high. 
Personally, I find them very helpful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123070

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


[PATCH] D123197: Remove a few effectively-unused FileEntry APIs. NFC

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: dexonsmith, kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- isValid: FileManager only ever returns valid FileEntries (see next point)
- construction from outside FileManager (also DirectoryEntry). It's not 
possible to create a useful FileEntry this way, there are no setters. This was 
only used in FileEntryTest.
- operator< (hypothetical callers who want to sort FileEntry*s by UID should 
probably be explicit about it).

The ugly part here:

- FileEntryTest was constructing dummy FileEntrys to wrap in FileEntryRef
- I changed this to use a FileManager as a factory
- but FileManager hands out *const* FileEntry*s
- so I needed to change FileEntryRef to wrap *const* FileEntry&

Fortunately this doesn't change the public APIs around FileEntryRef.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123197

Files:
  clang/include/clang/Basic/DirectoryEntry.h
  clang/include/clang/Basic/FileEntry.h
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Frontend/LogDiagnosticPrinter.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/unittests/Basic/FileEntryTest.cpp
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -165,7 +165,6 @@
 
   auto file = manager.getFile("/tmp/test");
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   EXPECT_EQ("/tmp/test", (*file)->getName());
 
   const DirectoryEntry *dir = (*file)->getDir();
@@ -190,7 +189,6 @@
   manager.getVirtualFile("virtual/dir/bar.h", 100, 0);
   auto file = manager.getFile("virtual/dir/bar.h");
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   EXPECT_EQ("virtual/dir/bar.h", (*file)->getName());
 
   const DirectoryEntry *dir = (*file)->getDir();
@@ -212,9 +210,7 @@
   auto fileFoo = manager.getFile("foo.cpp");
   auto fileBar = manager.getFile("bar.cpp");
   ASSERT_TRUE(fileFoo);
-  ASSERT_TRUE((*fileFoo)->isValid());
   ASSERT_TRUE(fileBar);
-  ASSERT_TRUE((*fileBar)->isValid());
   EXPECT_NE(*fileFoo, *fileBar);
 }
 
@@ -341,9 +337,6 @@
   statCache->InjectFile("abc/bar.cpp", 42);
   manager.setStatCache(std::move(statCache));
 
-  ASSERT_TRUE(manager.getVirtualFile("abc/foo.cpp", 100, 0)->isValid());
-  ASSERT_TRUE(manager.getVirtualFile("abc/bar.cpp", 200, 0)->isValid());
-
   auto f1 = manager.getFile("abc/foo.cpp");
   auto f2 = manager.getFile("abc/bar.cpp");
 
@@ -418,14 +411,12 @@
   // Inject the virtual file:
   const FileEntry *file1 = manager.getVirtualFile("c:\\tmp\\test", 123, 1);
   ASSERT_TRUE(file1 != nullptr);
-  ASSERT_TRUE(file1->isValid());
   EXPECT_EQ(43U, file1->getUniqueID().getFile());
   EXPECT_EQ(123, file1->getSize());
 
   // Lookup the virtual file with a different name:
   auto file2 = manager.getFile("c:/tmp/test", 100, 1);
   ASSERT_TRUE(file2);
-  ASSERT_TRUE((*file2)->isValid());
   // Check that it's the same UFE:
   EXPECT_EQ(file1, *file2);
   EXPECT_EQ(43U, (*file2)->getUniqueID().getFile());
@@ -487,7 +478,6 @@
   // Check for real path.
   const FileEntry *file = Manager.getVirtualFile("/tmp/test", 123, 1);
   ASSERT_TRUE(file != nullptr);
-  ASSERT_TRUE(file->isValid());
   SmallString<64> ExpectedResult = CustomWorkingDir;
 
   llvm::sys::path::append(ExpectedResult, "tmp", "test");
@@ -515,7 +505,6 @@
   // Check for real path.
   auto file = Manager.getFile("/tmp/test", /*OpenFile=*/false);
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   SmallString<64> ExpectedResult = CustomWorkingDir;
 
   llvm::sys::path::append(ExpectedResult, "tmp", "test");
@@ -548,7 +537,6 @@
   const FileEntry *File = Manager.getVirtualFile("/tmp/test", /*Size=*/10, 0);
   ASSERT_TRUE(File);
   const FileEntry &FE = *File;
-  EXPECT_TRUE(FE.isValid());
   EXPECT_EQ(FE.getSize(), 10);
 
   // Calling a second time should not affect the UID or size.
@@ -564,7 +552,6 @@
   llvm::Optional BypassRef =
   Manager.getBypassFile(File->getLastRef());
   ASSERT_TRUE(BypassRef);
-  EXPECT_TRUE(BypassRef->isValid());
   EXPECT_EQ("/tmp/test", BypassRef->getName());
 
   // Check that it's different in the right ways.
Index: clang/unittests/Basic/FileEntryTest.cpp
===
--- clang/unittests/Basic/FileEntryTest.cpp
+++ clang/unittests/Basic/FileEntryTest.cpp
@@ -7,8 +7,11 @@
 //===--===//
 
 #include "clang/Basic/FileEntry.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -1

[PATCH] D122285: [analyzer] Add path note tags to standard library function summaries.

2022-04-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:400
+  /// then the return value is 0
+  /// and the note may say "Assuming the character is non-alphabetical".
+  class SummaryCase {

It would be good to test how this looks in doxygen output. If it is for 
generated documentation formatting tags can be used, otherwise this can be a 
`//` comment.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:879
+// knowing in advance which branch is taken.
+return (Node->succ_size() > 1) ? Note.str() : "";
+  },

Can other checkers not add successor nodes (that make this check not always 
correct)?



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:879
+// knowing in advance which branch is taken.
+return (Node->succ_size() > 1) ? Note.str() : "";
+  },

balazske wrote:
> Can other checkers not add successor nodes (that make this check not always 
> correct)?
Is there a reason against add the note without the word "Assuming" instead of 
no note?


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

https://reviews.llvm.org/D122285

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


[PATCH] D121375: [clang] NFC, move the utility function CompilerInvocation::setLangDefaults to LangOptions.h

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:519-521
+void setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
+ std::vector &Includes,
+ LangStandard::Kind LangStd);

dexonsmith wrote:
> sammccall wrote:
> > dexonsmith wrote:
> > > I think this would be cleaner as:
> > > ```
> > > lang=c++
> > > class LangOpts {
> > > // ...
> > >   void setDefaults(Language Lang, const llvm::Triple &T, ...);
> > > };
> > > ```
> > > Or `setLangDefaults` or `setDefaultsFor` (I don't care about the name, 
> > > just feel like it makes more sense as a member function if we're updating 
> > > all the callers anyway).
> > > 
> > > Also, you should include a default for `LangStd` or it'll be hard to 
> > > migrate over callers.
> > I kind of like the idea that this logic is "layered above" the langopts 
> > struct itself. On the other hand making it a member makes it more 
> > discoverable and less surprising that LangOptions is actually an inout 
> > param (e.g. IncludeDefaultHeader). Either way is fine with me.
> > I kind of like the idea that this logic is "layered above" the langopts 
> > struct itself. 
> 
> @sammccall, I'm curious if you have reasoning for the preference to layer it 
> above; is it because it takes the `Triple`, or is it something more general? 
> (If it's because of the triple, I agree that makes the layering a bit odd.)
> 
> > On the other hand making it a member makes it more discoverable and less 
> > surprising that LangOptions is actually an inout param (e.g. 
> > IncludeDefaultHeader).
> 
> Maybe it's better to return by value in either case to remove the inout, 
> since it seems unnecessary:
> ```
> lang=c++
> class LangOpts {
> // ...
>   static LangOpts getDefaults(Language Lang, const llvm::Triple &T, ...);
> };
> ```
> 
> If you still prefer a free function, I'd be happy enough with something like 
> this:
> ```
> lang=c++
> namespace clang {
> LangOpts getLangDefaults(Language Lang, const llvm::Triple &T, ...);
> }
> ```
> (I'm probably almost indifferent at this point, after thinking about the 
> triple, ...)
> @sammccall, I'm curious if you have reasoning for the preference to layer it 
> above; is it because it takes the Triple, or is it something more general?

It's more about compiler defaults being an application-level concern where 
LangOptions is more of a dumb struct. But that's also an argument for keeping 
it in Frontend, and we don't want that for practical reasons (it's nice to use 
the lexer on real code without Frontend!). So I'm not sure I have a coherent 
argument here, I'm happy with any option.

Return by value sounds great, unfortunately the existing code in Frontend calls 
this in the *middle* of initializing LangOpts from various sources, so it would 
imply some bigger/riskier changes I guess.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121375

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


[PATCH] D122885: [clang] Draft: Implement P1703R1

2022-04-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

FWIW probably these 5 patches are pretty independent of changes to the 
preprocessor...
...  the first four of those are extremely unlikely to clash - since they are 
concerned with the driver.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122885

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


[PATCH] D122119: [C++20][Modules] Adjust handling of exports of namespaces and using-decls.

2022-04-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

@dblaikie - is the explanation for the change in diagnostics at the same time 
OK? (if not I can split the patch, but either way I'd like to land what is 
acceptable soonish).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122119

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


[PATCH] D122981: [Clang] Diagnose incomplete return/param types only when function is not deleted

2022-04-06 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 420764.
rZhBoYao marked 2 inline comments as done.
rZhBoYao added a reviewer: erichkeane.
rZhBoYao added a comment.

I think an extra parameter is inevitable without complicating things too much.


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

https://reviews.llvm.org/D122981

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p2.cpp

Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p2.cpp
===
--- /dev/null
+++ clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p2.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct Incomplete; // expected-note 4{{forward declaration of 'Incomplete'}}
+Incomplete f(Incomplete) = delete; // well-formed
+Incomplete g(Incomplete) {}// expected-error{{incomplete result type 'Incomplete' in function definition}}\
+// expected-error{{variable has incomplete type 'Incomplete'}}
+
+struct C {
+  Incomplete f(Incomplete) = delete; // well-formed
+  Incomplete g(Incomplete) {}// expected-error{{incomplete result type 'Incomplete' in function definition}}\
+  // expected-error{{variable has incomplete type 'Incomplete'}}
+};
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14185,7 +14185,7 @@
 Decl *
 Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D,
   MultiTemplateParamsArg TemplateParameterLists,
-  SkipBodyInfo *SkipBody) {
+  SkipBodyInfo *SkipBody, bool FnDeleted) {
   assert(getCurFunctionDecl() == nullptr && "Function parsing confused");
   assert(D.isFunctionDeclarator() && "Not a function declarator!");
   Scope *ParentScope = FnBodyScope->getParent();
@@ -14204,7 +14204,7 @@
 
   D.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
   Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists);
-  Decl *Dcl = ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody);
+  Decl *Dcl = ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody, FnDeleted);
 
   if (!Bases.empty())
 ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(Dcl, Bases);
@@ -14380,7 +14380,7 @@
 }
 
 Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,
-SkipBodyInfo *SkipBody) {
+SkipBodyInfo *SkipBody, bool FnDeleted) {
   if (!D) {
 // Parsing the function declaration failed in some way. Push on a fake scope
 // anyway so we can try to parse the function body.
@@ -14470,10 +14470,11 @@
   }
 
   // The return type of a function definition must be complete
-  // (C99 6.9.1p3, C++ [dcl.fct]p6).
+  // unless the function is deleted
+  // (C99 6.9.1p3, C++ [dcl.fct.def.general]p2).
   QualType ResultType = FD->getReturnType();
   if (!ResultType->isDependentType() && !ResultType->isVoidType() &&
-  !FD->isInvalidDecl() &&
+  !FD->isInvalidDecl() && !FnDeleted &&
   RequireCompleteType(FD->getLocation(), ResultType,
   diag::err_func_def_incomplete_result))
 FD->setInvalidDecl();
@@ -14482,8 +14483,9 @@
 PushDeclContext(FnBodyScope, FD);
 
   // Check the validity of our function parameters
-  CheckParmsForFunctionDef(FD->parameters(),
-   /*CheckParameterNames=*/true);
+  if (!FnDeleted)
+CheckParmsForFunctionDef(FD->parameters(),
+ /*CheckParameterNames=*/true);
 
   // Add non-parameter declarations already in the function to the current
   // scope.
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -1302,11 +1302,13 @@
   // Tell the actions module that we have entered a function definition with the
   // specified Declarator for the function.
   Sema::SkipBodyInfo SkipBody;
+  bool Delete =
+  Tok.is(tok::equal) && NextToken().is(tok::kw_delete) ? true : false;
   Decl *Res = Actions.ActOnStartOfFunctionDef(getCurScope(), D,
   TemplateInfo.TemplateParams
   ? *TemplateInfo.TemplateParams
   : MultiTemplateParamsArg(),
-  &SkipBody);
+  &SkipBody, Delete);
 
   if (SkipBody.ShouldSkip) {
 SkipFunctionBody();
@@ -1332,7 +1334,6 @@
   if (TryConsumeToken(tok::equal)) {
 assert(getLangOpts().CPlusPlus && "Only C++ function definitions have '='");
 
-bool Delete = false;
 SourceLocation KWLoc;
 if (TryConsumeToken(tok::kw_d

[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420770.
dang added a comment.

Manage PatchComponents stack manipulation using RAII to avoid forgetting to pop
the stack when returning early from `serializeAPIRecord`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123045

Files:
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/enum.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/language.c
  clang/test/ExtractAPI/macro_undefined.c
  clang/test/ExtractAPI/macros.c
  clang/test/ExtractAPI/objc_interface.m
  clang/test/ExtractAPI/objc_protocol.m
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -48,7 +48,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "memberOf",
   "source": "c:@S@Color@FI@Red",
@@ -72,6 +72,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -112,8 +113,10 @@
 "identifier": "c.struct"
   },
   "location": {
-"character": 8,
-"line": 2,
+"position": {
+  "character": 8,
+  "line": 2
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -124,9 +127,13 @@
   }
 ],
 "title": "Color"
-  }
+  },
+  "pathComponents": [
+"Color"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -151,8 +158,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 3,
+"position": {
+  "character": 12,
+  "line": 3
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -163,9 +172,14 @@
   }
 ],
 "title": "Red"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Red"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -190,8 +204,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 4,
+"position": {
+  "character": 12,
+  "line": 4
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -202,9 +218,14 @@
   }
 ],
 "title": "Green"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Green"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -229,8 +250,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 5,
+"position": {
+  "character": 12,
+  "line": 5
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -241,9 +264,14 @@
   }
 ],
 "title": "Blue"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Blue"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -285,8 +313,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 7,
+"position": {
+  "character": 12,
+  "line": 7
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -297,7 +327,11 @@
   }
 ],
 "title": "Alpha"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Alpha"
+  ]
 }
   ]
 }
Index: clang/test/ExtractAPI/objc_protocol.m
===
--- clang/test/ExtractAPI/objc_protocol.m
+++ clang/test/ExtractAPI/objc_protocol.m
@@ -45,7 +45,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "conformsTo",
   "source": "c:objc(pl)AnotherProtocol",
@@ -54,6 +54,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -77,8 +78,10 @@
 "identifier": "objective-c.protocol"
   },
   "location": {
-"character": 11,
-"line": 1,
+"position": {
+  "character": 11,
+  "line": 1
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -89,9 +92,13 @@
   }
 ],
 "title": "Protocol"
-  }
+ 

[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked an inline comment as done.
dang added inline comments.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:510
   Symbols.emplace_back(std::move(*Obj));
+  PathComponentContext.pop_back();
 }

QuietMisdreavus wrote:
> dang wrote:
> > dang wrote:
> > > zixuw wrote:
> > > > zixuw wrote:
> > > > > QuietMisdreavus wrote:
> > > > > > zixuw wrote:
> > > > > > > What's the cost/would it worth it to wrap the `emplace_back`s and 
> > > > > > > `pop_back`s of `PathComponentContext` in meaningful APIs like 
> > > > > > > `enterPathComponentContext` and `exitPathComponentContext`?
> > > > > > > That way the code is more self-explanatory and easier to read. It 
> > > > > > > took me some time and mental resources to figure out why the 
> > > > > > > `pop_back` is placed here.
> > > > > > What's the use of having the `emplace_back` call inside 
> > > > > > `serializeAPIRecord` but to pop it outside? It seems like it's 
> > > > > > easier to mess up for new kinds of records.
> > > > > The reason to `emplace_back` the path component inside 
> > > > > `serializeAPIRecord` is that the `pathComponent` field of the 
> > > > > `Record` is serialized in there so you want to include the name of 
> > > > > the symbol itself in the path component list.
> > > > > The `pop_back` is delayed til all other additional serialization for 
> > > > > a specific kind of record, for example `serializeEnumRecord` handles 
> > > > > all the enum cases after processing the enum record itself using 
> > > > > `serializeAPIRecord`. So in order to correctly include the enum name 
> > > > > in the path components of all the enum cases, the enum name has to 
> > > > > stay in `PathComponentContext` until all members are serialized.
> > > > > 
> > > > > This is exactly the reason why I wanted a clearer API to make it 
> > > > > easier to see.
> > > > Hmm now that I thought about this, it seems that it would be easier to 
> > > > understand and avoid bugs if we lift 
> > > > `PathComponentContext.emplace_back`/`enterPathComponentContext` out of 
> > > > `serializeAPIRecord`, because we have access to the record name before 
> > > > that anyway.
> > > > 
> > > > So we establish a pre-condition of `serializeAPIRecord` that the 
> > > > correct path components would be set up in `PathComponentContext` 
> > > > before the call so we could still serialize the field inside that 
> > > > method. And in specific `serialize*Record` methods we push the record 
> > > > name, and pop out at the end.
> > > > 
> > > > This way the push and pop operations would appear in pairs in a single 
> > > > block, saving the confusion and mental work of jumping across functions 
> > > > to see how `PathComponentContext` is evolving.
> > > If you think we should have a specialized API I am happy to do this. I 
> > > figured it was self-explanatory by the name of `PathComponentContext` but 
> > > it clearly isn't so needs addressing. I put the `emplace_back` call in 
> > > `serializeAPIRecord` since all the specific serialization methods call 
> > > it. I thought it would make it impossible to forget to add them. @zixuw 
> > > is correct in the reason why the pop is outside we don't want to pop 
> > > before we have serialized the sub records by agree it is ugly and 
> > > potentially error prone. I can see three ways forward for improving the 
> > > ergonomics of this since this seems to be problematic:
> > > - Provide `serializeAPIRecord` a continuation to serialize the sub 
> > > records or additional fields, that way we can move the pop inside 
> > > `serializeAPIRecord` I am not a fan personally because we get into JS 
> > > style closure hell if we start doing this...
> > > - Use a visitor pattern where the visitor would be responsible for 
> > > managing `PathComponentContext` and do the appropriate push/pops in the 
> > > `visit` methods. We would need to add a APIRecordVisitor type, and 
> > > appropriate visit methods for each APIRecord. This would make sense 
> > > because the records should really know how to visit themselves.
> > > - Just add a specialized API although it seems it would really easy to 
> > > forget to remove path components.
> > > 
> > > Let me know what you think is the way forward.
> > Unless we go with the last option, I think this should be a follow up patch 
> > since it would a structural change.
> I'm most a fan of the `APIRecordVisitor` option, but you're right in that 
> that would be a rather involved change. Now that you've said that the 
> arrangement is for encoding sub-records, it makes sense to me. As an 
> alternative, i think moving the `emplace_back` outside of 
> `serializeAPIRecord` is actually my other preferred arrangement; without some 
> other way of calculating the path components on-the-fly (e.g. walking up 
> DeclContexts) simply having `serializeAPIRecord` look at what's there and 
> have the wrapper calls deal with setting up its state sounds the most 
>

[PATCH] D122874: [clang] Add GNU spelling for no_unqiue_address attribute

2022-04-06 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon resigned from this revision.
RKSimon added a comment.

Sorry but this is not an area I know enough about to review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122874

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


[clang] 77c74fd - [OpenCL] Remove argument names from math builtins

2022-04-06 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-04-06T11:43:59+01:00
New Revision: 77c74fd877b27418171693f187b8db865567b8dc

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

LOG: [OpenCL] Remove argument names from math builtins

This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" the argument name identifiers.

Continues the direction set out in D119560.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 71b0fbb3a691e..cee3c680aff2e 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -6362,7 +6362,7 @@ uint __ovld __cnfn get_work_dim(void);
  * dimindx, get_global_size() returns 1.
  * For clEnqueueTask, this always returns 1.
  */
-size_t __ovld __cnfn get_global_size(uint dimindx);
+size_t __ovld __cnfn get_global_size(uint);
 
 /**
  * Returns the unique global work-item ID value for
@@ -6373,7 +6373,7 @@ size_t __ovld __cnfn get_global_size(uint dimindx);
  * other values of dimindx, get_global_id() returns 0.
  * For clEnqueueTask, this returns 0.
  */
-size_t __ovld __cnfn get_global_id(uint dimindx);
+size_t __ovld __cnfn get_global_id(uint);
 
 /**
  * Returns the number of local work-items specified in
@@ -6387,7 +6387,7 @@ size_t __ovld __cnfn get_global_id(uint dimindx);
  * get_local_size() returns 1.
  * For clEnqueueTask, this always returns 1.
  */
-size_t __ovld __cnfn get_local_size(uint dimindx);
+size_t __ovld __cnfn get_local_size(uint);
 
 /**
  * Returns the unique local work-item ID i.e. a work-item
@@ -6397,7 +6397,7 @@ size_t __ovld __cnfn get_local_size(uint dimindx);
  * get_local_id() returns 0.
  * For clEnqueueTask, this returns 0.
  */
-size_t __ovld __cnfn get_local_id(uint dimindx);
+size_t __ovld __cnfn get_local_id(uint);
 
 /**
  * Returns the number of work-groups that will execute a
@@ -6406,7 +6406,7 @@ size_t __ovld __cnfn get_local_id(uint dimindx);
  * For other values of dimindx, get_num_groups() returns 1.
  * For clEnqueueTask, this always returns 1.
  */
-size_t __ovld __cnfn get_num_groups(uint dimindx);
+size_t __ovld __cnfn get_num_groups(uint);
 
 /**
  * get_group_id returns the work-group ID which is a
@@ -6415,7 +6415,7 @@ size_t __ovld __cnfn get_num_groups(uint dimindx);
  * For other values, get_group_id() returns 0.
  * For clEnqueueTask, this returns 0.
  */
-size_t __ovld __cnfn get_group_id(uint dimindx);
+size_t __ovld __cnfn get_group_id(uint);
 
 /**
  * get_global_offset returns the offset values specified in
@@ -6425,10 +6425,10 @@ size_t __ovld __cnfn get_group_id(uint dimindx);
  * For other values, get_global_offset() returns 0.
  * For clEnqueueTask, this returns 0.
  */
-size_t __ovld __cnfn get_global_offset(uint dimindx);
+size_t __ovld __cnfn get_global_offset(uint);
 
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
-size_t __ovld get_enqueued_local_size(uint dimindx);
+size_t __ovld get_enqueued_local_size(uint);
 size_t __ovld get_global_linear_id(void);
 size_t __ovld get_local_linear_id(void);
 #endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
@@ -6594,27 +6594,27 @@ half16 __ovld __cnfn asinpi(half16);
 /**
  * Arc tangent function.
  */
-float __ovld __cnfn atan(float y_over_x);
-float2 __ovld __cnfn atan(float2 y_over_x);
-float3 __ovld __cnfn atan(float3 y_over_x);
-float4 __ovld __cnfn atan(float4 y_over_x);
-float8 __ovld __cnfn atan(float8 y_over_x);
-float16 __ovld __cnfn atan(float16 y_over_x);
+float __ovld __cnfn atan(float);
+float2 __ovld __cnfn atan(float2);
+float3 __ovld __cnfn atan(float3);
+float4 __ovld __cnfn atan(float4);
+float8 __ovld __cnfn atan(float8);
+float16 __ovld __cnfn atan(float16);
 #ifdef cl_khr_fp64
-double __ovld __cnfn atan(double y_over_x);
-double2 __ovld __cnfn atan(double2 y_over_x);
-double3 __ovld __cnfn atan(double3 y_over_x);
-double4 __ovld __cnfn atan(double4 y_over_x);
-double8 __ovld __cnfn atan(double8 y_over_x);
-double16 __ovld __cnfn atan(double16 y_over_x);
+double __ovld __cnfn atan(double);
+double2 __ovld __cnfn atan(double2);
+double3 __ovld __cnfn atan(double3);
+double4 __ovld __cnfn atan(double4);
+double8 __ovld __cnfn atan(double8);
+double16 __ovld __cnfn atan(double16);
 #endif //cl_khr_fp64
 #ifdef cl_khr_fp16
-half __ovld __cnfn atan(half y_over_x);
-half2 __ovld __cnfn atan(half2 y_over_x);
-half3 __ovld __cnfn atan(half3 y_over_x);
-half4 __ovld __cnfn atan(half4 y_over_x);
-half8 __ovld __cnfn atan(half8 y_over_x);
-half16 __ovld __cnfn atan(half16 y_over_x);
+half __ovld __cnfn atan(half);
+half2 __ovld __cnfn atan(half2);
+half3 __ovld __cnfn atan(half3);
+half4 __ovld __cnfn atan(half4);
+hal

[PATCH] D119409: [C++20] [Modules] Remain dynamic initializing internal-linkage variables in module interface unit

2022-04-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D119409#3410893 , @ChuanqiXu wrote:

> In D119409#3410868 , @iains wrote:
>
>> In D119409#3410474 , @ChuanqiXu 
>> wrote:
>>
>>> In D119409#3409806 , @iains wrote:
>>>
 I think that this problem might well be a consequence of the bug which is 
 fixed by D122413 .

 We have been generating code with module internal entities (always) given 
 the special ModuleInternalLinkage (which means that, although the linkage 
 is formally 'internal', the entities are made global when emitted.  We 
 should only be doing this for fmodules-ts, not for regular standard 
 modules.

 If you apply D122413  (which I hope to 
 land soon), then I would expect that iostream should work as expected 
 (with one internal instance of std::__ioinit in each TU that includes 
 iostream).

 IFF (after applying D122413  ) you add 
 to the command line -fmodules-ts, then the patch here (D119409 
 ) would, presumably, be needed to work 
 around multiple instances of the globalised std::__ioinit.
>>>
>>> Sadly it wouldn't work after D122413  
>>> applied. Since the  is lived in GlobalModuleFragment, the 
>>> calculated linkage wouldn't affect them. So I met the same segfault as 
>>> before.
>>
>> Is this because we are not creating an initialiser for a static entity in 
>> the GMF ?
>>
>> - I did a quick test and that seemed to be the case.
>
> I think we need this one finally, It would create the initialiser after the 
> patch applied. And I think we couldn't do that without the patch. Since from 
> the code we could see that the static variable wouldn't be generated in the 
> current strategies.
>
>> (module initialisers need quite some work, it seems)
>
> The initialiser above I said is the initialiser in that TU. What you mean 
> `module initializer` ? Do you mean the one module could have only module 
> initializer?
>
 addendum: note we still have work to do on the module initialisers - those 
 are not correct yet (so probably some nesting of modules might not work).
>>>
>>> What does the nesting of modules mean?
>>
>> If we have an import of a module that imports another - then we should be 
>> running the module initializers for the imported stack (in the correct 
>> order) .. at present, we do not do this.
>> As noted above, we have some work to do here.
>
> I am not familiar with the history here. But I found 
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1874r1.html#solution.
>  It says clang already has a simple fix. So I am wondering if this one is 
> already fixed or we are not talking about the same thing?

Sorry for slow response - was hoping to have a patch to show by now
... I am currently finishing off an implementation for 1874 + elision of unused 
GMF decls.  The "simple fix" in clang actually pulls all the initialisers into 
one list in the top-level module (which is slightly different from the intent 
of the paper, as implemented in GCC) - that implementation also does not fix 
the issue of a module interface where there is no explicit "import" for the 
sub-modules.

The patch in progress will build a per module initialiser (which will handle 
sub-module initialisers and calling module initialisers for direct imports).  I 
think that will fix the iostreams problem (it is a motivating example from the 
paper).


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

https://reviews.llvm.org/D119409

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


[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

2022-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 420771.
hokein marked 12 inline comments as done.
hokein added a comment.

address review comments;
rename methods;
fix templatename::print and add a test;
add a fixme for qualified template name;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123127

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-using-template.cpp
  clang/test/SemaTemplate/qualified-id.cpp
  clang/tools/libclang/CIndex.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -890,6 +890,18 @@
  functionDecl(hasDescendant(usingDecl(hasName("bar");
 }
 
+TEST_P(ImportDecl, ImportUsingTemplate) {
+  MatchVerifier Verifier;
+  testImport("namespace ns { template  struct S {}; }"
+ "template  class T> class X {};"
+ "void declToImport() {"
+ "using ns::S;  X xi; }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ functionDecl(
+ hasDescendant(varDecl(hasTypeLoc(templateSpecializationTypeLoc(
+ hasAnyTemplateArgumentLoc(templateArgumentLoc(;
+}
+
 TEST_P(ImportDecl, ImportUsingEnumDecl) {
   MatchVerifier Verifier;
   testImport("namespace foo { enum bar { baz, toto, quux }; }"
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1472,6 +1472,9 @@
 return Visit(MakeCursorTemplateRef(
 Name.getAsSubstTemplateTemplateParmPack()->getParameterPack(), Loc,
 TU));
+  case TemplateName::UsingTemplate:
+return VisitTemplateName(
+Name.getAsUsingTemplateName()->getUnderlyingTemplate(), Loc);
   }
 
   llvm_unreachable("Invalid TemplateName::Kind!");
Index: clang/test/SemaTemplate/qualified-id.cpp
===
--- clang/test/SemaTemplate/qualified-id.cpp
+++ clang/test/SemaTemplate/qualified-id.cpp
@@ -31,6 +31,17 @@
   };
 }
 
+namespace test3 {
+namespace ns {
+template class S { S(T); }; // expected-note3{{candidate constructor}}
+}
+namespace ns2 {
+using ns::S;
+}
+// Verify we print the right name for the using template name.
+ns2::S s; // expected-error{{no matching constructor for initialization of 'ns2::S'}}
+}
+
 namespace PR6063 {
   template  void f(T, T);
   
Index: clang/test/AST/ast-dump-using-template.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-using-template.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -ast-dump %s | FileCheck -strict-whitespace %s
+
+// Tests to verify we construct correct using template names.
+// TemplateNames are not dumped, so the sugar here isn't obvious. However
+// the "using" on the TemplateSpecializationTypes shows that the
+// UsingTemplateName is present.
+namespace ns {
+template class S {
+ public:
+   S(T);
+};
+}
+using ns::S;
+
+// TemplateName in TemplateSpecializationType.
+template
+using A = S;
+// CHECK:  TypeAliasDecl
+// CHECK-NEXT: `-TemplateSpecializationType {{.*}} 'S' dependent using S
+
+// TemplateName in TemplateArgument.
+template  class T> class X {};
+using B = X;
+// CHECK:  TypeAliasDecl
+// CHECK-NEXT: `-TemplateSpecializationType {{.*}} 'X' sugar X
+// CHECK-NEXT:   |-TemplateArgument using template S
+// CHECK-NEXT: `-RecordType {{.*}} 'X'
+// CHECK-NEXT:   `-ClassTemplateSpecialization {{.*}} 'X'
+
+// TemplateName in DeducedTemplateSpecializationType.
+S DeducedTemplateSpecializationT(123);
+using C = decltype(DeducedTemplateSpecializationT);
+// CHECK:  DecltypeType {{.*}}
+// CHECK-NEXT:  |-DeclRefExpr {{.*}}
+// CHECK-NEXT:  `-DeducedTemplateSpecializationType {{.*}} 'ns::S' sugar using
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -16,6 +16,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateName.h"
 

[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

2022-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D123127#3429589 , @sammccall wrote:

> This looks pretty good!
> The tests in clang are sadly indirect.

This is mostly due to the fact that `TemplateName` is not dumped. This patch 
extend the `NodeDumper` to print a `using` indicator, I think it is relatively 
obvious in the AST.

> I think adding support to clangd's FindTarget would be a small change and 
> would allow a fairly direct test, but maybe it will affect a bunch of 
> existing tests or possibly have a blast radius. Up to you.

Adding support in clangd `FindTarget` is my next step, it would be a followup 
patch. I feel like the FindTarget tests are more related to the application 
logic of the new `TemplateName`, and are less direct compared with the tests in 
this patch.




Comment at: clang/include/clang/AST/TemplateName.h:446
   /// that this qualified name refers to.
   TemplateDecl *Template;
 

sammccall wrote:
> It seems really unfortunate that this is a `TemplateDecl*` instead of a 
> `TemplateName`.
> 
> for:
> ```
> template  class x;
> namespace a { using ::x; }
> a::x<0>;
> ```
> we want `a::x` to include both a QualifiedTemplateName (modelling the a:: 
> qualifier) and a UsingTemplateName (modelling the UsingShadowDecl that was 
> found).
> 
> I'd guess we can change `Template` to be a `TemplateName` internally, and add 
> `getTemplate()` while keeping the existing `get[Template]Decl` APIs on top of 
> `TemplateName::getAsTemplateDecl()`.
> I suppose this could be a separate change (though it'd be nice to know 
> whether it's going to work...)
> 
> Of course if that changed there's a natural followon to take the qualifier 
> out of DependentTemplateName and turn it into a QualifiedTemplateName 
> wrapping a DependentTemplateName. (Definitely out of scope for this patch, 
> not sure if it's reasonable to expect you to do it at all)
> we want a::x to include both a QualifiedTemplateName (modelling the a:: 
> qualifier) and a UsingTemplateName (modelling the UsingShadowDecl that was 
> found).

> I'd guess we can change Template to be a TemplateName internally, and add 
> getTemplate() while keeping the existing get[Template]Decl APIs on top of 
> TemplateName::getAsTemplateDecl().
> I suppose this could be a separate change (though it'd be nice to know 
> whether it's going to work...)

Agree, I think this is the right solution, but would require more work (a 
followup patch).

There are two options, 1) leave the qualified template name out, and support it 
in a followup patch, 2) workaround it -- we wrap the qualified template name 
with a using template name, though it doesn't quite match our mental model, I 
think it is probably ok. (I added a FIXME in `SemaTemplate.cpp`).

Let me know what you think, also happy to switch to 1).



Comment at: clang/lib/AST/ASTContext.cpp:6176
   }
+  case TemplateName::UsingTemplate:
+return getCanonicalTemplateName(

sammccall wrote:
> you could also handle this in the QualifiedTemplate/Template case, since the 
> decl is guaranteed to be present.
yeah, but I think the current version is clearer.



Comment at: clang/lib/AST/TemplateName.cpp:273
+  } else if (auto *U = getAsUsingTemplateName()) {
+U->getUnderlying().print(OS, Policy);
   } else {

sammccall wrote:
> Why is this correct, rather than potentially printing the wrong sugar?
> 
> If the reasoning is that that the underlying TemplateName has the same name 
> and can't have any unwanted sugar, that seems subtle and deserves a comment.
> 
> I think just printing the unqualified name directly would be clearer.
> 
good point, you're right, this will print duplicated nested specifiers. Change 
it to print unqualified name only, and added a test.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11026
   Context.hasSameTemplateName(SpecifiedName, GuidedTemplate);
-  if (SpecifiedName.getKind() == TemplateName::Template && TemplateMatches)
+  if ((SpecifiedName.getKind() == TemplateName::Template ||
+   SpecifiedName.getKind() == TemplateName::UsingTemplate) &&

sammccall wrote:
> I don't think it can be valid to find the template name via a 
> usingshadowdecl, because the deduction guide must be declared in the same 
> scope as the template. (err_deduction_guide_wrong_scope).
> 
> Is this to prevent an unneccesary second diagnostic? (And if so, I wonder 
> whether we should also include QualifiedTemplate, maybe as a separate 
> change). It may deserve a comment
yeah, it prevents a bogus diagnostic introduced by this patch.

```
 namespace N {
template struct NamedNS1 {}; // expected-note {{here}}
  }
  using N::NamedNS1;
  NamedNS1(int) -> NamedNS1; // expected-error {{deduction guide must be 
declared in the same scope as template}}
```

With this patch without the change here, we emit an extra diagnostic `deduce

[PATCH] D123200: [compiler-rt][AVR] Add initial support of target AVR

2022-04-06 Thread Ben Shi via Phabricator via cfe-commits
benshi001 created this revision.
benshi001 added reviewers: MaskRay, ddunbar, howard.hinnant, samsonov, aykevl.
Herald added subscribers: StephenFan, Jim, mgorny, dberris, dylanmckay.
Herald added a project: All.
benshi001 requested review of this revision.
Herald added subscribers: Sanitizers, cfe-commits, jacquesguan, aheejin.
Herald added projects: clang, Sanitizers.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123200

Files:
  clang/lib/Basic/Targets/AVR.cpp
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake
  compiler-rt/cmake/base-config-ix.cmake
  compiler-rt/cmake/builtin-config-ix.cmake
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/builtins/CMakeLists.txt

Index: compiler-rt/lib/builtins/CMakeLists.txt
===
--- compiler-rt/lib/builtins/CMakeLists.txt
+++ compiler-rt/lib/builtins/CMakeLists.txt
@@ -668,6 +668,11 @@
   ${GENERIC_TF_SOURCES}
   ${GENERIC_SOURCES})
 
+set(avr_SOURCES
+  ${GENERIC_TF_SOURCES}
+  ${GENERIC_SOURCES}
+)
+
 add_custom_target(builtins)
 set_target_properties(builtins PROPERTIES FOLDER "Compiler-RT Misc")
 
Index: compiler-rt/cmake/config-ix.cmake
===
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -203,8 +203,10 @@
 
 # Detect whether the current target platform is 32-bit or 64-bit, and setup
 # the correct commandline flags needed to attempt to target 32-bit and 64-bit.
+# AVR and MSP430 are omitted since they have 16-bit pointers.
 if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
-NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
+NOT CMAKE_SIZEOF_VOID_P EQUAL 8 AND
+NOT ${arch} MATCHES "avr|msp430")
   message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.")
 endif()
 
Index: compiler-rt/cmake/builtin-config-ix.cmake
===
--- compiler-rt/cmake/builtin-config-ix.cmake
+++ compiler-rt/cmake/builtin-config-ix.cmake
@@ -52,6 +52,7 @@
 set(WASM32 wasm32)
 set(WASM64 wasm64)
 set(VE ve)
+set(AVR avr)
 
 if(APPLE)
   set(ARM64 arm64 arm64e)
@@ -63,7 +64,7 @@
   ${X86} ${X86_64} ${ARM32} ${ARM64}
   ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC32} ${PPC64}
   ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9}
-  ${WASM32} ${WASM64} ${VE})
+  ${WASM32} ${WASM64} ${VE} ${AVR})
 
 include(CompilerRTUtils)
 include(CompilerRTDarwinUtils)
Index: compiler-rt/cmake/base-config-ix.cmake
===
--- compiler-rt/cmake/base-config-ix.cmake
+++ compiler-rt/cmake/base-config-ix.cmake
@@ -248,6 +248,8 @@
   test_target_arch(wasm64 "" "--target=wasm64-unknown-unknown")
 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "ve")
   test_target_arch(ve "__ve__" "--target=ve-unknown-none")
+elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "avr")
+  test_target_arch(avr "__avr__" "--target=avr")
 endif()
 set(COMPILER_RT_OS_SUFFIX "")
   endif()
Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake
===
--- compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -168,6 +168,7 @@
   check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32)
   check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64)
   check_symbol_exists(__ve__ "" __VE)
+  check_symbol_exists(__avr__ "" __AVR)
   if(__ARM)
 add_default_target_arch(arm)
   elseif(__AARCH64)
@@ -212,6 +213,8 @@
 add_default_target_arch(wasm64)
   elseif(__VE)
 add_default_target_arch(ve)
+  elseif(__AVR)
+add_default_target_arch(avr)
   endif()
 endmacro()
 
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -377,7 +377,9 @@
  MacroBuilder &Builder) const {
   Builder.defineMacro("AVR");
   Builder.defineMacro("__AVR");
+  Builder.defineMacro("__avr");
   Builder.defineMacro("__AVR__");
+  Builder.defineMacro("__avr__");
   Builder.defineMacro("__ELF__");
 
   if (!this->CPU.empty()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123200: [compiler-rt][AVR] Add initial support of target AVR

2022-04-06 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

Build `libclang_rt.builtins-avr.a` which contains math functions, such as 
`mulsi3`, `divmodsi4`, `mulsf3`, ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123200

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


[PATCH] D123019: [clang][extract-api] Add support for typedefs

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420773.
dang added a comment.

Address code review feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123019

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h
  clang/test/ExtractAPI/typedef.c
  clang/test/ExtractAPI/typedef_anonymous_record.c
  clang/test/ExtractAPI/typedef_chain.c

Index: clang/test/ExtractAPI/typedef_chain.c
===
--- /dev/null
+++ clang/test/ExtractAPI/typedef_chain.c
@@ -0,0 +1,193 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api --product-name=TypedefChain -target arm64-apple-macosx \
+// RUN: -x objective-c-header %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+typedef int MyInt;
+typedef MyInt MyIntInt;
+typedef MyIntInt MyIntIntInt;
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "TypedefChain",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyInt"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:input.h@T@MyInt"
+  },
+  "kind": {
+"displayName": "Type Alias",
+"identifier": "objective-c.typealias"
+  },
+  "location": {
+"character": 13,
+"line": 1,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyInt"
+  }
+],
+"title": "MyInt"
+  },
+  "type": "c:I"
+},
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:input.h@T@MyInt",
+  "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyIntInt"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:input.h@T@MyIntInt"
+  },
+  "kind": {
+"displayName": "Type Alias",
+"identifier": "objective-c.typealias"
+  },
+  "location": {
+"character": 15,
+"line": 2,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyIntInt"
+  }
+],
+"title": "MyIntInt"
+  },
+  "type": "c:input.h@T@MyInt"
+},
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:input.h@T@MyIntInt",
+  "spelling": "MyIntInt"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyIntIntInt"
+}

[clang] ba4482f - [clang][NFC] Add specificity to compatibility hack

2022-04-06 Thread Nathan Sidwell via cfe-commits

Author: Nathan Sidwell
Date: 2022-04-06T03:57:36-07:00
New Revision: ba4482f481991799a922d5cf124a56bea5866254

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

LOG: [clang][NFC] Add specificity to compatibility hack

Add specific dates and versions to note about source_location handling.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6c2447dc4420f..93950ac5341ba 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8838,10 +8838,11 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
   E->getType()->getPointeeType());
   // 1. We'll allow it in std::allocator::allocate, and anything which that
   //calls.
-  // 2. We'll allow it in the body of std::source_location:current.  This 
is
-  //necessary for libstdc++'s , which gave its
-  //parameter the type void*, and cast from that back to `const 
__impl*`
-  //in the body. (Fixed for new versions in gcc.gnu.org/PR104602).
+  // 2. HACK 2022-03-28: Work around an issue with libstdc++'s
+  // header. Fixed in GCC 12 and later (2022-04-??).
+  //We'll allow it in the body of std::source_location::current.  GCC's
+  //implementation had a parameter of type `void*`, and casts from
+  //that back to `const __impl*` in its body.
   if (VoidPtrCastMaybeOK &&
   (Info.getStdAllocatorCaller("allocate") ||
IsDeclSourceLocationCurrent(Info.CurrentCall->Callee))) {



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


[PATCH] D123119: [clang][NFC] Add specificity to compatibility hack

2022-04-06 Thread Nathan Sidwell 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 rGba4482f48199: [clang][NFC] Add specificity to compatibility 
hack (authored by urnathan).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123119

Files:
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8838,10 +8838,11 @@
   E->getType()->getPointeeType());
   // 1. We'll allow it in std::allocator::allocate, and anything which that
   //calls.
-  // 2. We'll allow it in the body of std::source_location:current.  This 
is
-  //necessary for libstdc++'s , which gave its
-  //parameter the type void*, and cast from that back to `const 
__impl*`
-  //in the body. (Fixed for new versions in gcc.gnu.org/PR104602).
+  // 2. HACK 2022-03-28: Work around an issue with libstdc++'s
+  // header. Fixed in GCC 12 and later (2022-04-??).
+  //We'll allow it in the body of std::source_location::current.  GCC's
+  //implementation had a parameter of type `void*`, and casts from
+  //that back to `const __impl*` in its body.
   if (VoidPtrCastMaybeOK &&
   (Info.getStdAllocatorCaller("allocate") ||
IsDeclSourceLocationCurrent(Info.CurrentCall->Callee))) {


Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8838,10 +8838,11 @@
   E->getType()->getPointeeType());
   // 1. We'll allow it in std::allocator::allocate, and anything which that
   //calls.
-  // 2. We'll allow it in the body of std::source_location:current.  This is
-  //necessary for libstdc++'s , which gave its
-  //parameter the type void*, and cast from that back to `const __impl*`
-  //in the body. (Fixed for new versions in gcc.gnu.org/PR104602).
+  // 2. HACK 2022-03-28: Work around an issue with libstdc++'s
+  // header. Fixed in GCC 12 and later (2022-04-??).
+  //We'll allow it in the body of std::source_location::current.  GCC's
+  //implementation had a parameter of type `void*`, and casts from
+  //that back to `const __impl*` in its body.
   if (VoidPtrCastMaybeOK &&
   (Info.getStdAllocatorCaller("allocate") ||
IsDeclSourceLocationCurrent(Info.CurrentCall->Callee))) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks, I think this is just about ready to go.
Only substantive issue is I think we should address the 
QualifiedTemplate/UsingTemplate interaction in a more principled way.




Comment at: clang/include/clang/AST/PropertiesBase.td:625
+let Class = PropertyTypeCase in {
+  def : Property<"usingShadowDecl", UsingShadowDeclRef> {
+let Read = [{ node.getAsUsingTemplateName()->getFoundDecl() }];

rename these properties too?



Comment at: clang/include/clang/AST/TemplateName.h:446
   /// that this qualified name refers to.
   TemplateDecl *Template;
 

hokein wrote:
> sammccall wrote:
> > It seems really unfortunate that this is a `TemplateDecl*` instead of a 
> > `TemplateName`.
> > 
> > for:
> > ```
> > template  class x;
> > namespace a { using ::x; }
> > a::x<0>;
> > ```
> > we want `a::x` to include both a QualifiedTemplateName (modelling the a:: 
> > qualifier) and a UsingTemplateName (modelling the UsingShadowDecl that was 
> > found).
> > 
> > I'd guess we can change `Template` to be a `TemplateName` internally, and 
> > add `getTemplate()` while keeping the existing `get[Template]Decl` APIs on 
> > top of `TemplateName::getAsTemplateDecl()`.
> > I suppose this could be a separate change (though it'd be nice to know 
> > whether it's going to work...)
> > 
> > Of course if that changed there's a natural followon to take the qualifier 
> > out of DependentTemplateName and turn it into a QualifiedTemplateName 
> > wrapping a DependentTemplateName. (Definitely out of scope for this patch, 
> > not sure if it's reasonable to expect you to do it at all)
> > we want a::x to include both a QualifiedTemplateName (modelling the a:: 
> > qualifier) and a UsingTemplateName (modelling the UsingShadowDecl that was 
> > found).
> 
> > I'd guess we can change Template to be a TemplateName internally, and add 
> > getTemplate() while keeping the existing get[Template]Decl APIs on top of 
> > TemplateName::getAsTemplateDecl().
> > I suppose this could be a separate change (though it'd be nice to know 
> > whether it's going to work...)
> 
> Agree, I think this is the right solution, but would require more work (a 
> followup patch).
> 
> There are two options, 1) leave the qualified template name out, and support 
> it in a followup patch, 2) workaround it -- we wrap the qualified template 
> name with a using template name, though it doesn't quite match our mental 
> model, I think it is probably ok. (I added a FIXME in `SemaTemplate.cpp`).
> 
> Let me know what you think, also happy to switch to 1).
I don't like 2), it adds code in order to introduce an incorrect "inside-out" 
AST in a surprising way that will lead to subtle bugs, and we'll need to undo 
this later. To me this seems probably worse than dropping one of the sugar 
nodes and never fixing it, which is already pretty bad.

I think we should do 1) instead - I think it's actually simpler to land the 
QualifiedTemplate-holds-TemplateName patch *first*, but either order seems fine.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11026
   Context.hasSameTemplateName(SpecifiedName, GuidedTemplate);
-  if (SpecifiedName.getKind() == TemplateName::Template && TemplateMatches)
+  if ((SpecifiedName.getKind() == TemplateName::Template ||
+   SpecifiedName.getKind() == TemplateName::UsingTemplate) &&

hokein wrote:
> sammccall wrote:
> > I don't think it can be valid to find the template name via a 
> > usingshadowdecl, because the deduction guide must be declared in the same 
> > scope as the template. (err_deduction_guide_wrong_scope).
> > 
> > Is this to prevent an unneccesary second diagnostic? (And if so, I wonder 
> > whether we should also include QualifiedTemplate, maybe as a separate 
> > change). It may deserve a comment
> yeah, it prevents a bogus diagnostic introduced by this patch.
> 
> ```
>  namespace N {
> template struct NamedNS1 {}; // expected-note {{here}}
>   }
>   using N::NamedNS1;
>   NamedNS1(int) -> NamedNS1; // expected-error {{deduction guide must be 
> declared in the same scope as template}}
> ```
> 
> With this patch without the change here, we emit an extra diagnostic `deduced 
> type 'NamedNS1' of deduction guide is not written as a specialization of 
> template 'NamedNS1'`. 
> 
> And this part of code might have another issue where it emits a wrong 
> `err_deduction_guide_defines_function` for a correct code, (this is something 
> I plan to take a look but not in this patch) .
That makes sense, though it seems to me inconsistent to suppress the secondary 
diagnostic for UsingTemplate but emit it for QualifiedTemplate - it's equally 
bogus/valid in both cases.

Can we either suppress both, or suppress neither for now and suppress them in a 
subsequent patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.

[PATCH] D123197: Remove a few effectively-unused FileEntry APIs. NFC

2022-04-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! I would still be looking out for build bot statuses in case there 
are OS specific code paths that were using isvalid. it might also be worthwhile 
to send out `operator<` change in a separate commit, just to give downstream 
users an opportunity to handle fixes for the two in isolation (or reverts if 
need be).




Comment at: clang/lib/Basic/FileManager.cpp:462
   UFE->Dir = &DirInfo->getDirEntry();
-  UFE->UID = NextFileUID++;
-  UFE->IsValid = true;
+  UFE->UID = NextFileUID++;
   UFE->File.reset();

nit: revert formatting



Comment at: clang/unittests/Basic/FileEntryTest.cpp:45
 return DirectoryEntryRef(
 *Dirs.insert({Name, const_cast(Base.getDirEntry())})
  .first);

no need for const_cast here anymore, right?



Comment at: clang/unittests/Basic/FileEntryTest.cpp:60
  {Name, FileEntryRef::MapValue(
 const_cast(Base.getFileEntry()), DR)})
  .first);

similarly we can drop the const_cast here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123197

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


[PATCH] D122748: [Sema] Don't check bounds for function pointer

2022-04-06 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

Friendly ping.

In D122748#3417500 , @erichkeane 
wrote:

> would still like to see the feedback from the original submitter here to see 
> if there is more work to do in here that would be valuable.

Unsure, maybe we can process without him? It seems his last activity here was 
more than six months ago.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122748

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


[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

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

address remaining comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123127

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-using-template.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/test/SemaTemplate/qualified-id.cpp
  clang/tools/libclang/CIndex.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -890,6 +890,18 @@
  functionDecl(hasDescendant(usingDecl(hasName("bar");
 }
 
+TEST_P(ImportDecl, ImportUsingTemplate) {
+  MatchVerifier Verifier;
+  testImport("namespace ns { template  struct S {}; }"
+ "template  class T> class X {};"
+ "void declToImport() {"
+ "using ns::S;  X xi; }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ functionDecl(
+ hasDescendant(varDecl(hasTypeLoc(templateSpecializationTypeLoc(
+ hasAnyTemplateArgumentLoc(templateArgumentLoc(;
+}
+
 TEST_P(ImportDecl, ImportUsingEnumDecl) {
   MatchVerifier Verifier;
   testImport("namespace foo { enum bar { baz, toto, quux }; }"
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1472,6 +1472,9 @@
 return Visit(MakeCursorTemplateRef(
 Name.getAsSubstTemplateTemplateParmPack()->getParameterPack(), Loc,
 TU));
+  case TemplateName::UsingTemplate:
+return VisitTemplateName(
+Name.getAsUsingTemplateName()->getUnderlyingTemplate(), Loc);
   }
 
   llvm_unreachable("Invalid TemplateName::Kind!");
Index: clang/test/SemaTemplate/qualified-id.cpp
===
--- clang/test/SemaTemplate/qualified-id.cpp
+++ clang/test/SemaTemplate/qualified-id.cpp
@@ -31,6 +31,17 @@
   };
 }
 
+namespace test3 {
+namespace ns {
+template class S { S(T); }; // expected-note3{{candidate constructor}}
+}
+namespace ns2 {
+using ns::S;
+}
+// Verify we print the right name for the using template name.
+ns2::S s; // expected-error{{no matching constructor for initialization of 'ns2::S'}}
+}
+
 namespace PR6063 {
   template  void f(T, T);
   
Index: clang/test/CXX/temp/temp.deduct.guide/p3.cpp
===
--- clang/test/CXX/temp/temp.deduct.guide/p3.cpp
+++ clang/test/CXX/temp/temp.deduct.guide/p3.cpp
@@ -55,6 +55,9 @@
   }
   using N::NamedNS1;
   NamedNS1(int) -> NamedNS1; // expected-error {{deduction guide must be declared in the same scope as template}}
+  // FIXME: remove the following bogus diagnostic
+  // expected-error@-2{{deduction guide is not written as a specialization of template 'NamedNS1'}}
+
   using namespace N;
   NamedNS2(int) -> NamedNS2; // expected-error {{deduction guide must be declared in the same scope as template}}
   struct ClassMemberA {
Index: clang/test/AST/ast-dump-using-template.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-using-template.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -ast-dump %s | FileCheck -strict-whitespace %s
+
+// Tests to verify we construct correct using template names.
+// TemplateNames are not dumped, so the sugar here isn't obvious. However
+// the "using" on the TemplateSpecializationTypes shows that the
+// UsingTemplateName is present.
+namespace ns {
+template class S {
+ public:
+   S(T);
+};
+}
+using ns::S;
+
+// TemplateName in TemplateSpecializationType.
+template
+using A = S;
+// CHECK:  TypeAliasDecl
+// CHECK-NEXT: `-TemplateSpecializationType {{.*}} 'S' dependent using S
+
+// TemplateName in TemplateArgument.
+template  class T> class X {};
+using B = X;
+// CHECK:  TypeAliasDecl
+// CHECK-NEXT: `-TemplateSpecializationType {{.*}} 'X' sugar X
+// CHECK-NEXT:   |-TemplateArgument using template S
+// CHECK-NEXT: `-RecordType {{.*}} 'X'
+// CHECK-NEXT:   `-ClassTemplateSpecialization {{.*}} 'X

[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

2022-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/AST/TemplateName.h:446
   /// that this qualified name refers to.
   TemplateDecl *Template;
 

sammccall wrote:
> hokein wrote:
> > sammccall wrote:
> > > It seems really unfortunate that this is a `TemplateDecl*` instead of a 
> > > `TemplateName`.
> > > 
> > > for:
> > > ```
> > > template  class x;
> > > namespace a { using ::x; }
> > > a::x<0>;
> > > ```
> > > we want `a::x` to include both a QualifiedTemplateName (modelling the a:: 
> > > qualifier) and a UsingTemplateName (modelling the UsingShadowDecl that 
> > > was found).
> > > 
> > > I'd guess we can change `Template` to be a `TemplateName` internally, and 
> > > add `getTemplate()` while keeping the existing `get[Template]Decl` APIs 
> > > on top of `TemplateName::getAsTemplateDecl()`.
> > > I suppose this could be a separate change (though it'd be nice to know 
> > > whether it's going to work...)
> > > 
> > > Of course if that changed there's a natural followon to take the 
> > > qualifier out of DependentTemplateName and turn it into a 
> > > QualifiedTemplateName wrapping a DependentTemplateName. (Definitely out 
> > > of scope for this patch, not sure if it's reasonable to expect you to do 
> > > it at all)
> > > we want a::x to include both a QualifiedTemplateName (modelling the a:: 
> > > qualifier) and a UsingTemplateName (modelling the UsingShadowDecl that 
> > > was found).
> > 
> > > I'd guess we can change Template to be a TemplateName internally, and add 
> > > getTemplate() while keeping the existing get[Template]Decl APIs on top of 
> > > TemplateName::getAsTemplateDecl().
> > > I suppose this could be a separate change (though it'd be nice to know 
> > > whether it's going to work...)
> > 
> > Agree, I think this is the right solution, but would require more work (a 
> > followup patch).
> > 
> > There are two options, 1) leave the qualified template name out, and 
> > support it in a followup patch, 2) workaround it -- we wrap the qualified 
> > template name with a using template name, though it doesn't quite match our 
> > mental model, I think it is probably ok. (I added a FIXME in 
> > `SemaTemplate.cpp`).
> > 
> > Let me know what you think, also happy to switch to 1).
> I don't like 2), it adds code in order to introduce an incorrect "inside-out" 
> AST in a surprising way that will lead to subtle bugs, and we'll need to undo 
> this later. To me this seems probably worse than dropping one of the sugar 
> nodes and never fixing it, which is already pretty bad.
> 
> I think we should do 1) instead - I think it's actually simpler to land the 
> QualifiedTemplate-holds-TemplateName patch *first*, but either order seems 
> fine.
ok, faire enough, switched to 1).



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11026
   Context.hasSameTemplateName(SpecifiedName, GuidedTemplate);
-  if (SpecifiedName.getKind() == TemplateName::Template && TemplateMatches)
+  if ((SpecifiedName.getKind() == TemplateName::Template ||
+   SpecifiedName.getKind() == TemplateName::UsingTemplate) &&

sammccall wrote:
> hokein wrote:
> > sammccall wrote:
> > > I don't think it can be valid to find the template name via a 
> > > usingshadowdecl, because the deduction guide must be declared in the same 
> > > scope as the template. (err_deduction_guide_wrong_scope).
> > > 
> > > Is this to prevent an unneccesary second diagnostic? (And if so, I wonder 
> > > whether we should also include QualifiedTemplate, maybe as a separate 
> > > change). It may deserve a comment
> > yeah, it prevents a bogus diagnostic introduced by this patch.
> > 
> > ```
> >  namespace N {
> > template struct NamedNS1 {}; // expected-note {{here}}
> >   }
> >   using N::NamedNS1;
> >   NamedNS1(int) -> NamedNS1; // expected-error {{deduction guide must 
> > be declared in the same scope as template}}
> > ```
> > 
> > With this patch without the change here, we emit an extra diagnostic 
> > `deduced type 'NamedNS1' of deduction guide is not written as a 
> > specialization of template 'NamedNS1'`. 
> > 
> > And this part of code might have another issue where it emits a wrong 
> > `err_deduction_guide_defines_function` for a correct code, (this is 
> > something I plan to take a look but not in this patch) .
> That makes sense, though it seems to me inconsistent to suppress the 
> secondary diagnostic for UsingTemplate but emit it for QualifiedTemplate - 
> it's equally bogus/valid in both cases.
> 
> Can we either suppress both, or suppress neither for now and suppress them in 
> a subsequent patch?
ok, let's not do it for now, and add a FIXME for the newly-introduced 
diagnostic in the existing test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123127

___
cfe-commits mailing list
cfe-commits@li

[PATCH] D123211: [flang][driver] Add support for generating LLVM bytecode files

2022-04-06 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
Herald added a subscriber: mgorny.
Herald added projects: Flang, All.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added a project: clang.

Support for generating LLVM BC files is added in Flang's compiler and
frontend drivers. This requires the `BitcodeWriterPass` pass to be run
on the input LLVM IR module and is implemented as a dedicated frontend
aciton. The new functionality as seen by the user (compiler driver):

  flang-new -c -emit-llvm file.90

or (frontend driver):

  flang-new -fc1 -emit-llvm-bc file.f90

The new behaviour is consistent with `clang` and `clang -cc1`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123211

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/driver-help.f90

Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -71,6 +71,7 @@
 ! HELP-FC1-NEXT:OPTIONS:
 ! HELP-FC1-NEXT: -cpp   Enable predefined and command line preprocessor macros
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-FC1-NEXT: -emit-llvm-bc  Build ASTs then convert to LLVM, emit .bc file
 ! HELP-FC1-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
 ! HELP-FC1-NEXT: -emit-mlir Build the parse tree, then lower it to MLIR
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
Index: flang/test/CMakeLists.txt
===
--- flang/test/CMakeLists.txt
+++ flang/test/CMakeLists.txt
@@ -55,6 +55,7 @@
   fir-opt
   tco
   bbc
+  llvm-dis
   llvm-objdump
   split-file
 )
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -37,6 +37,8 @@
 return std::make_unique();
   case EmitLLVM:
 return std::make_unique();
+  case EmitLLVMBitcode:
+return std::make_unique();
   case EmitObj:
 return std::make_unique(
 BackendAction::BackendActionTy::Backend_EmitObj);
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -33,6 +33,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/Bitcode/BitcodeWriterPass.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -472,6 +473,50 @@
   llvmModule->print(*os, /*AssemblyAnnotationWriter=*/nullptr);
 }
 
+void EmitLLVMBitcodeAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+  // Generate an LLVM module if it's not already present (it will already be
+  // present if the input file is an LLVM IR/BC file).
+  if (!llvmModule)
+GenerateLLVMIR();
+
+  llvm::ModulePassManager MPM;
+  llvm::ModuleAnalysisManager MAM;
+
+  // Create and configure `Target`
+  std::string error;
+  std::string theTriple = llvmModule->getTargetTriple();
+  const llvm::Target *theTarget =
+  llvm::TargetRegistry::lookupTarget(theTriple, error);
+  assert(theTarget && "Failed to create Target");
+
+  // Create and configure `TargetMachine`
+  std::unique_ptr TM;
+
+  TM.reset(theTarget->createTargetMachine(theTriple, /*CPU=*/"",
+  /*Features=*/"", llvm::TargetOptions(), llvm::None));
+  llvmModule->setDataLayout(TM->createDataLayout());
+  assert(TM && "Failed to create TargetMachine");
+
+  // Generate an output file
+  std::unique_ptr os = ci.CreateDefaultOutputFile(
+  /*Binary=*/true, /*InFile=*/GetCurrentFileOrBufferName(), "bc");
+  if (!os) {
+unsigned diagID = ci.diagnostics().getCustomDiagID(
+clang::DiagnosticsEngine::Error, "failed to create the output file");
+ci.diagnostics().Report(diagID);
+return;
+  }
+
+  // Set-up the pass manager
+  llvm::PassBuilder PB(TM.get());
+  PB.registerModuleAnalyses(MAM);
+  MPM.addPass(llvm::BitcodeWriterPass(*os));
+
+  // Run the passes
+  MPM.run(*llvmModule, MAM);
+}
+
 void EmitMLIRAction::ExecuteAction() {
   CompilerInstance &ci = this->instance();
 
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -150,6 +150,9 @@
 case clang::driver::options::OPT_e

[PATCH] D123212: [clangd] Handle the new UsingTemplateName.

2022-04-06 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Add supports in FindTarget and IncludeCleaner. This would
improve AST-based features on a tempalte which is found via a using
declaration. For example, go-to-def on `vect^or v;` gives us the
location of `using std::vector`, which was not previously.

Base on https://reviews.llvm.org/D123127


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123212

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

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -78,9 +78,17 @@
   "using namespace ns;",
   },
   {
+  // Refs from UsingTypeLoc and implicit constructor!
   "struct ^A {}; using B = A; using ^C = B;",
   "C a;",
   },
+  {"namespace ns { template class A {}; } using ns::^A;",
+   "A* a;"},
+  {"namespace ns { template class A {}; } using ns::^A;",
+   "template  class T> class X {}; X x;"},
+  {"namespace ns { template struct ^A { ^A(T); }; } using "
+   "ns::^A;",
+   "A x(123);"},
   {
   "typedef bool ^Y; template  struct ^X {};",
   "X x;",
@@ -226,6 +234,7 @@
 TU.Code = T.MainCode;
 Annotations Header(T.HeaderCode);
 TU.HeaderCode = Header.code().str();
+TU.ExtraArgs.push_back("-std=c++17");
 auto AST = TU.build();
 
 std::vector Points;
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -229,6 +229,44 @@
 )cpp";
   EXPECT_DECLS("UnresolvedUsingValueDecl", {"using Base::waldo", Rel::Alias},
{"void waldo()"});
+
+  Code = R"cpp(
+namespace ns {
+template class S {};
+}
+
+using ns::S;
+
+template
+using A = [[S]];
+  )cpp";
+  EXPECT_DECLS("TemplateSpecializationTypeLoc", {"using ns::S", Rel::Alias},
+   {"template  class S"});
+
+  Code = R"cpp(
+namespace ns {
+template class S {};
+}
+
+using ns::S;
+template  class T> class X {};
+using B = X<[[S]]>;
+  )cpp";
+  EXPECT_DECLS("TemplateArgumentLoc", {"using ns::S", Rel::Alias},
+   {"template  class S"});
+
+  Code = R"cpp(
+namespace ns {
+template class S { public: S(T); };
+}
+
+using ns::S;
+[[S]] s(123);
+  )cpp";
+  Flags.push_back("-std=c++17"); // For CTAD feature.
+  EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc",
+   {"using ns::S", Rel::Alias}, {"template  class S"},
+   {"class S", Rel::TemplatePattern});
 }
 
 TEST_F(TargetDeclTest, BaseSpecifier) {
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -73,11 +73,23 @@
   }
 
   bool VisitTemplateSpecializationType(TemplateSpecializationType *TST) {
+if (const auto *UTN = TST->getTemplateName().getAsUsingTemplateName()) {
+  add(UTN->getFoundDecl());
+  return true;
+}
 add(TST->getTemplateName().getAsTemplateDecl()); // Primary template.
 add(TST->getAsCXXRecordDecl());  // Specialization
 return true;
   }
 
+  // There is no VisitTemplateName in RAV, thus we override the Traverse version
+  // to handle the UsingTemplateName case.
+  bool TraverseTemplateName(TemplateName TN) {
+if (const auto *UTN = TN.getAsUsingTemplateName())
+  add(UTN->getFoundDecl());
+return Base::TraverseTemplateName(TN);
+  }
+
   bool VisitUsingType(UsingType *UT) {
 add(UT->getFoundDecl());
 return true;
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -384,11 +384,14 @@
   }
   void VisitDeducedTemplateSpecializationType(
   const DeducedTemplateSpecializationType *DTST) {
+if (const auto *UTN = DTST->getTemplateName().getAsUsingTemplateName())
+  Outer.add(UTN->getFoundDecl(), Flags);
+
 // FIXME: This is a workaround for https://llvm.org/PR42914,
 // which is causing DTST->getDeducedType() to be empty. We
 // fall back to the template pattern and miss the in

[PATCH] D123197: Remove a few effectively-unused FileEntry APIs. NFC

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 420808.
sammccall marked 2 inline comments as done.
sammccall added a comment.

Remove obsolete const_casts


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123197

Files:
  clang/include/clang/Basic/DirectoryEntry.h
  clang/include/clang/Basic/FileEntry.h
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Frontend/LogDiagnosticPrinter.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/unittests/Basic/FileEntryTest.cpp
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -165,7 +165,6 @@
 
   auto file = manager.getFile("/tmp/test");
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   EXPECT_EQ("/tmp/test", (*file)->getName());
 
   const DirectoryEntry *dir = (*file)->getDir();
@@ -190,7 +189,6 @@
   manager.getVirtualFile("virtual/dir/bar.h", 100, 0);
   auto file = manager.getFile("virtual/dir/bar.h");
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   EXPECT_EQ("virtual/dir/bar.h", (*file)->getName());
 
   const DirectoryEntry *dir = (*file)->getDir();
@@ -212,9 +210,7 @@
   auto fileFoo = manager.getFile("foo.cpp");
   auto fileBar = manager.getFile("bar.cpp");
   ASSERT_TRUE(fileFoo);
-  ASSERT_TRUE((*fileFoo)->isValid());
   ASSERT_TRUE(fileBar);
-  ASSERT_TRUE((*fileBar)->isValid());
   EXPECT_NE(*fileFoo, *fileBar);
 }
 
@@ -341,9 +337,6 @@
   statCache->InjectFile("abc/bar.cpp", 42);
   manager.setStatCache(std::move(statCache));
 
-  ASSERT_TRUE(manager.getVirtualFile("abc/foo.cpp", 100, 0)->isValid());
-  ASSERT_TRUE(manager.getVirtualFile("abc/bar.cpp", 200, 0)->isValid());
-
   auto f1 = manager.getFile("abc/foo.cpp");
   auto f2 = manager.getFile("abc/bar.cpp");
 
@@ -418,14 +411,12 @@
   // Inject the virtual file:
   const FileEntry *file1 = manager.getVirtualFile("c:\\tmp\\test", 123, 1);
   ASSERT_TRUE(file1 != nullptr);
-  ASSERT_TRUE(file1->isValid());
   EXPECT_EQ(43U, file1->getUniqueID().getFile());
   EXPECT_EQ(123, file1->getSize());
 
   // Lookup the virtual file with a different name:
   auto file2 = manager.getFile("c:/tmp/test", 100, 1);
   ASSERT_TRUE(file2);
-  ASSERT_TRUE((*file2)->isValid());
   // Check that it's the same UFE:
   EXPECT_EQ(file1, *file2);
   EXPECT_EQ(43U, (*file2)->getUniqueID().getFile());
@@ -487,7 +478,6 @@
   // Check for real path.
   const FileEntry *file = Manager.getVirtualFile("/tmp/test", 123, 1);
   ASSERT_TRUE(file != nullptr);
-  ASSERT_TRUE(file->isValid());
   SmallString<64> ExpectedResult = CustomWorkingDir;
 
   llvm::sys::path::append(ExpectedResult, "tmp", "test");
@@ -515,7 +505,6 @@
   // Check for real path.
   auto file = Manager.getFile("/tmp/test", /*OpenFile=*/false);
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   SmallString<64> ExpectedResult = CustomWorkingDir;
 
   llvm::sys::path::append(ExpectedResult, "tmp", "test");
@@ -548,7 +537,6 @@
   const FileEntry *File = Manager.getVirtualFile("/tmp/test", /*Size=*/10, 0);
   ASSERT_TRUE(File);
   const FileEntry &FE = *File;
-  EXPECT_TRUE(FE.isValid());
   EXPECT_EQ(FE.getSize(), 10);
 
   // Calling a second time should not affect the UID or size.
@@ -564,7 +552,6 @@
   llvm::Optional BypassRef =
   Manager.getBypassFile(File->getLastRef());
   ASSERT_TRUE(BypassRef);
-  EXPECT_TRUE(BypassRef->isValid());
   EXPECT_EQ("/tmp/test", BypassRef->getName());
 
   // Check that it's different in the right ways.
Index: clang/unittests/Basic/FileEntryTest.cpp
===
--- clang/unittests/Basic/FileEntryTest.cpp
+++ clang/unittests/Basic/FileEntryTest.cpp
@@ -7,8 +7,11 @@
 //===--===//
 
 #include "clang/Basic/FileEntry.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -17,55 +20,44 @@
 namespace {
 
 using FileMap = StringMap>;
-using DirMap = StringMap>;
+using DirMap = StringMap>;
 
 struct RefMaps {
+  FileManager FM; // Used only to create FileEntry/DirectoryEntry.
+  unsigned UniqueNameCounter = 0;
   FileMap Files;
   DirMap Dirs;
 
-  SmallVector, 5> FEs;
-  SmallVector, 5> DEs;
   DirectoryEntryRef DR;
 
-  RefMaps() : DR(addDirectory("dir")) {}
+  RefMaps()
+  : FM(FileSystemOptions(), std::make_unique()),
+DR(addDirectory("dir")) {}
 
   DirectoryEntryRef addDirectory(StringRef Name) {
-DEs.push_back(std::make_unique());
-return DirectoryEntryRef(*Dirs.insert({Name, *DEs.back()}).first);
+const DirectoryEntry *DE =
+FM.getVi

[PATCH] D123197: Remove a few effectively-unused FileEntry APIs. NFC

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D123197#3432386 , @kadircet wrote:

> thanks lgtm! I would still be looking out for build bot statuses in case 
> there are OS specific code paths that were using isvalid.

Will do!

> it might also be worthwhile to send out `operator<` change in a separate 
> commit, just to give downstream users an opportunity to handle fixes for the 
> two in isolation (or reverts if need be).

I think it's so unlikely to be used as to not be worth it.

- It's not possible to put FileEntrys as values in a container, so some code 
would have to be explicitly comparing them (rather than std::sort or so).
- Ordering file entries by UID doesn't seem terribly useful - it's neither the 
cheapest ordering (pointers) nor the most natural.
- Empirically, there are zero uses in llvm-project and zero in google's 
downstream repo, which is one of the heavier user of clang APIs. I'd bet there 
are none anywhere.




Comment at: clang/lib/Basic/FileManager.cpp:462
   UFE->Dir = &DirInfo->getDirEntry();
-  UFE->UID = NextFileUID++;
-  UFE->IsValid = true;
+  UFE->UID = NextFileUID++;
   UFE->File.reset();

kadircet wrote:
> nit: revert formatting
`arc` insists on this change here, because it's in the blast radius of the next 
line and clang-format isn't configured to allow this formatting.

Unless you feel strongly I'd rather not fight the linter when it's not really 
wrong.
(Happy to reformat the other lines to match though)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123197

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


[PATCH] D123197: Remove a few effectively-unused FileEntry APIs. NFC

2022-04-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/lib/Basic/FileManager.cpp:462
   UFE->Dir = &DirInfo->getDirEntry();
-  UFE->UID = NextFileUID++;
-  UFE->IsValid = true;
+  UFE->UID = NextFileUID++;
   UFE->File.reset();

sammccall wrote:
> kadircet wrote:
> > nit: revert formatting
> `arc` insists on this change here, because it's in the blast radius of the 
> next line and clang-format isn't configured to allow this formatting.
> 
> Unless you feel strongly I'd rather not fight the linter when it's not really 
> wrong.
> (Happy to reformat the other lines to match though)
> Unless you feel strongly I'd rather not fight the linter when it's not really 
> wrong.
> (Happy to reformat the other lines to match though)

I was suggesting this for preserving history purposes, in theory all of this is 
old code with intricate semantics so it would be nice to not add more commits 
to the history chain here. I think it should be possible to just `arc diff 
--nolint` (or push without updating the diff in phabricator, which you already 
probably know, but just in case).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123197

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


[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension

2022-04-06 Thread Daniil Dudkin via Phabricator via cfe-commits
unterumarmung added a comment.

@ekieri, hello! Thank you for the comment, it is really helpful!
It turns out that I've researched the issue poorly.

Actually, `nvfortran` compiler forbids to use `INTENT` attribute on local 
variables, even though a "mod" file can be generated. It generates a severe 
error like the one below and there's no way to ignore the severe errors, if I 
understand correctly.

  NVFORTRAN-S-0134-Illegal attribute - intent specified for nondummy argument 
bar2 (test.f90: 3)

But the reason why I filed the patch was that `nvfortran` allows to use any 
kind of `INTENT` attribute for a local variable that marked as `RESULT` one for 
a function:

  function foo() result(bar)
  integer, intent(out) :: bar
  end function foo

`nvfortran` does not generate any message for this code, not even a warning. 
So, it looks like a bug in the compiler, not a feature or extension and this 
should not be supported in flang, I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123113

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


[PATCH] D123212: [clangd] Handle the new UsingTemplateName.

2022-04-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks a lot for doing this! some drive-by comments




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:87
+  // to handle the UsingTemplateName case.
+  bool TraverseTemplateName(TemplateName TN) {
+if (const auto *UTN = TN.getAsUsingTemplateName())

what's the reason for not doing this in base method instead?



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:89
+   "template  class T> class X {}; X x;"},
+  {"namespace ns { template struct ^A { ^A(T); }; } using "
+   "ns::^A;",

a note for future:
we probably don't want to consider references to constructor and the underlying 
decl when figuring out missing includes. as it would imply insertion of 
underlying header, which might be annoying.
as an example, code patterns in the wild look like:
`foo.h`:
```
#include 
namespace famous_library_name {
using std::optional;
}
```

foo.cc
```
#include "foo.h"
void foo() {
  famous_library_name::optional x(3); // we were getting complaints around 
saying `foo.h` is unused, i bet we'll get similar complaints if we said you 
should insert ``.
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123212

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


[PATCH] D122841: [analyzer] Consider all addrspaces in null dereference check

2022-04-06 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Ahhh, I see - thanks for the references and discussion. I'll craft a patch to 
comprehend the use case and user-facing option, and post for review. We'll see 
how it goes :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

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


[PATCH] D123211: [flang][driver] Add support for generating LLVM bytecode files

2022-04-06 Thread Diana Picus via Phabricator via cfe-commits
rovka added a comment.

Why not use the BackendAction for this? There seems to be a lot of shared code, 
up until the point where you create and use the pass manager (and in the 
future, when the backend switches to the new pass manager, there will be even 
more shared code).




Comment at: flang/lib/Frontend/FrontendActions.cpp:483
+
+  llvm::ModulePassManager MPM;
+  llvm::ModuleAnalysisManager MAM;

Nit: I think you can move these closer to their first use.



Comment at: flang/test/CMakeLists.txt:58
   bbc
+  llvm-dis
   llvm-objdump

Were you going to add a test that uses this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123211

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


[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/AST/TemplateName.h:404
+
+  TemplateName UnderlyingTN;
+  UsingShadowDecl *USD = nullptr;

(Per offline discussion)

The UnderlyingTN here seems like it would refer to the TemplateDecl pointed to 
by the UsingShadowDecl, with sugar from the RHS of the UsingDecl.

The only sugar possible is a namespace [alias] qualifier, so the only 
TemplateNames possible are Qualified and Ordinary. And the code isn't actually 
creating Qualified names here when it would be applicable.

So we should either:
 - change this to be a TemplateDecl* instead
 - start creating the Qualified names where appropriate

Arguments in favor of having the sugar qualified names:
 - it's a more complete AST
 - it's more consistent with sugar types

Arguments against the sugar qualified names
 - performance: it avoids adding a second level of indirection, extra storage 
etc
 - it avoids confusing callers into handling *all* TemplateName cases here
 - the sugar is still available: USD->getUsingDecl()->getQualifier()

I think we should not provide sugared names here, and change the type to 
TemplateDecl*



Comment at: clang/include/clang/AST/TemplateName.h:404
+
+  TemplateName UnderlyingTN;
+  UsingShadowDecl *USD = nullptr;

sammccall wrote:
> (Per offline discussion)
> 
> The UnderlyingTN here seems like it would refer to the TemplateDecl pointed 
> to by the UsingShadowDecl, with sugar from the RHS of the UsingDecl.
> 
> The only sugar possible is a namespace [alias] qualifier, so the only 
> TemplateNames possible are Qualified and Ordinary. And the code isn't 
> actually creating Qualified names here when it would be applicable.
> 
> So we should either:
>  - change this to be a TemplateDecl* instead
>  - start creating the Qualified names where appropriate
> 
> Arguments in favor of having the sugar qualified names:
>  - it's a more complete AST
>  - it's more consistent with sugar types
> 
> Arguments against the sugar qualified names
>  - performance: it avoids adding a second level of indirection, extra storage 
> etc
>  - it avoids confusing callers into handling *all* TemplateName cases here
>  - the sugar is still available: USD->getUsingDecl()->getQualifier()
> 
> I think we should not provide sugared names here, and change the type to 
> TemplateDecl*
If we change the type to TemplateDecl, do we actually need to store it? Or can 
we just `cast(USD->getTargetDecl())`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123127

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


[PATCH] D122981: [Clang] Diagnose incomplete return/param types only when function is not deleted

2022-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:2906
+SkipBodyInfo *SkipBody = nullptr,
+bool FnDeleted = false);
   Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D,

I tend to prefer not doing bool params, and instead some type of 'enum class', 
as that makes it more clear at the call site.



Comment at: clang/lib/Parse/Parser.cpp:1306
+  bool Delete =
+  Tok.is(tok::equal) && NextToken().is(tok::kw_delete) ? true : false;
   Decl *Res = Actions.ActOnStartOfFunctionDef(getCurScope(), D,

I'm not sure about doing this 'look ahead' here, this feels dangerous to me.  
First, does this work with comments?  Second, it seems we wouldn't normally 
look at 'deleted' if SkipBody.ShouldSkip (see below with the early exit)?

Next I'm not a fan of double-parsing these tokens with this lookahead.  I 
wonder, if we should move hte logic from ~1334 and 1338 up here and calculate 
the 'deleted'/'defaulted' 'earlier', before we 'actOnStartOfFunctionDef`.  

This would result in us being able to instead change the signature of 
ActOnStartOfFunctionDef to take some enum as to whether it is 
deleted/defaulted, AND create the function decl as deleted/defaulted 'in place' 
(or, at least, call SetDeclDeleted or SetDeclDefaulted immediately).







Comment at: clang/lib/Sema/SemaDecl.cpp:14461
   if (!ResultType->isDependentType() && !ResultType->isVoidType() &&
-  !FD->isInvalidDecl() &&
+  !FD->isInvalidDecl() && !FnDeleted &&
   RequireCompleteType(FD->getLocation(), ResultType,

ChuanqiXu wrote:
> rZhBoYao wrote:
> > ChuanqiXu wrote:
> > > I think we could remove the use of `FnDeleted` by the use of 
> > > `FD->isDeleted()`. Also we should constrain the behavior only if std >= 
> > > 11.
> > I tried `FD->isDeleted()` at first only to find out it always returns 
> > `false`. Looks like it's not handled until [[ 
> > https://github.com/llvm/llvm-project/blob/634bf829a8d289371d5b5a50b787596124228898/clang/lib/Parse/Parser.cpp#L1342
> >  | Parser.cpp:1342 ]]
> > 
> > Also, looks like deleted functions are implemented as an extension. A 
> > warning is issued at [[ 
> > https://github.com/llvm/llvm-project/blob/634bf829a8d289371d5b5a50b787596124228898/clang/lib/Parse/Parser.cpp#L1338-L1341
> >  | Parser.cpp:1338 ]] if language mode < C++11
> I see. My suggestion might be to defer the diagnose message after we set 
> `FD->setDeletedAsWritten()`. I understand it might be harder. But the current 
> implementation looks a little bit not good... (redundant variables and 
> passing information by argument)
I disagree on doing this for C++11 mode.  As we allow them as an extension, we 
want this to work in the extension mode as well.


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

https://reviews.llvm.org/D122981

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


[PATCH] D123211: [flang][driver] Add support for generating LLVM bytecode files

2022-04-06 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 420821.
awarzynski added a comment.
Herald added a reviewer: sscalpone.

Add missing test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123211

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/driver-help.f90
  flang/test/Driver/emit-llvm-bc.f90

Index: flang/test/Driver/emit-llvm-bc.f90
===
--- /dev/null
+++ flang/test/Driver/emit-llvm-bc.f90
@@ -0,0 +1,8 @@
+! RUN: %flang -emit-llvm -c %s -o - | llvm-dis -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-llvm-bc %s -o - | llvm-dis -o - | FileCheck %s
+
+! CHECK: define void @_QQmain()
+! CHECK-NEXT:  ret void
+! CHECK-NEXT: }
+
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -71,6 +71,7 @@
 ! HELP-FC1-NEXT:OPTIONS:
 ! HELP-FC1-NEXT: -cpp   Enable predefined and command line preprocessor macros
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-FC1-NEXT: -emit-llvm-bc  Build ASTs then convert to LLVM, emit .bc file
 ! HELP-FC1-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
 ! HELP-FC1-NEXT: -emit-mlir Build the parse tree, then lower it to MLIR
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
Index: flang/test/CMakeLists.txt
===
--- flang/test/CMakeLists.txt
+++ flang/test/CMakeLists.txt
@@ -55,6 +55,7 @@
   fir-opt
   tco
   bbc
+  llvm-dis
   llvm-objdump
   split-file
 )
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -37,6 +37,8 @@
 return std::make_unique();
   case EmitLLVM:
 return std::make_unique();
+  case EmitLLVMBitcode:
+return std::make_unique();
   case EmitObj:
 return std::make_unique(
 BackendAction::BackendActionTy::Backend_EmitObj);
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -33,6 +33,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/Bitcode/BitcodeWriterPass.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -472,6 +473,50 @@
   llvmModule->print(*os, /*AssemblyAnnotationWriter=*/nullptr);
 }
 
+void EmitLLVMBitcodeAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+  // Generate an LLVM module if it's not already present (it will already be
+  // present if the input file is an LLVM IR/BC file).
+  if (!llvmModule)
+GenerateLLVMIR();
+
+  llvm::ModulePassManager MPM;
+  llvm::ModuleAnalysisManager MAM;
+
+  // Create and configure `Target`
+  std::string error;
+  std::string theTriple = llvmModule->getTargetTriple();
+  const llvm::Target *theTarget =
+  llvm::TargetRegistry::lookupTarget(theTriple, error);
+  assert(theTarget && "Failed to create Target");
+
+  // Create and configure `TargetMachine`
+  std::unique_ptr TM;
+
+  TM.reset(theTarget->createTargetMachine(theTriple, /*CPU=*/"",
+  /*Features=*/"", llvm::TargetOptions(), llvm::None));
+  llvmModule->setDataLayout(TM->createDataLayout());
+  assert(TM && "Failed to create TargetMachine");
+
+  // Generate an output file
+  std::unique_ptr os = ci.CreateDefaultOutputFile(
+  /*Binary=*/true, /*InFile=*/GetCurrentFileOrBufferName(), "bc");
+  if (!os) {
+unsigned diagID = ci.diagnostics().getCustomDiagID(
+clang::DiagnosticsEngine::Error, "failed to create the output file");
+ci.diagnostics().Report(diagID);
+return;
+  }
+
+  // Set-up the pass manager
+  llvm::PassBuilder PB(TM.get());
+  PB.registerModuleAnalyses(MAM);
+  MPM.addPass(llvm::BitcodeWriterPass(*os));
+
+  // Run the passes
+  MPM.run(*llvmModule, MAM);
+}
+
 void EmitMLIRAction::ExecuteAction() {
   CompilerInstance &ci = this->instance();
 
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -150,6 +150,9 @@
 case clang::driver::options::OPT_emit_llvm:
   opts.programA

[PATCH] D123212: [clangd] Handle the new UsingTemplateName.

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:446
   Outer.add(RD, Flags); // add(Decl) will despecialize if needed.
+else if (const auto *UTN =
+ TST->getTemplateName().getAsUsingTemplateName())

I don't think this really belongs in the else-if chain, if the previous catch 
matches (known class specialization) then we still want to recognize the alias.

I suspect this probably belongs right at the top, outside the chain



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:76
   bool VisitTemplateSpecializationType(TemplateSpecializationType *TST) {
+if (const auto *UTN = TST->getTemplateName().getAsUsingTemplateName()) {
+  add(UTN->getFoundDecl());

TraverseTemplateSpecializationType calls TraverseTemplateName, isn't this 
redundant with below?



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:89
+   "template  class T> class X {}; X x;"},
+  {"namespace ns { template struct ^A { ^A(T); }; } using "
+   "ns::^A;",

kadircet wrote:
> a note for future:
> we probably don't want to consider references to constructor and the 
> underlying decl when figuring out missing includes. as it would imply 
> insertion of underlying header, which might be annoying.
> as an example, code patterns in the wild look like:
> `foo.h`:
> ```
> #include 
> namespace famous_library_name {
> using std::optional;
> }
> ```
> 
> foo.cc
> ```
> #include "foo.h"
> void foo() {
>   famous_library_name::optional x(3); // we were getting complaints around 
> saying `foo.h` is unused, i bet we'll get similar complaints if we said you 
> should insert ``.
> }
> ```
this wrapping is weird, and the amount of code on one line is hard to read, 
switch to raw-string?



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:89
+   "template  class T> class X {}; X x;"},
+  {"namespace ns { template struct ^A { ^A(T); }; } using "
+   "ns::^A;",

sammccall wrote:
> kadircet wrote:
> > a note for future:
> > we probably don't want to consider references to constructor and the 
> > underlying decl when figuring out missing includes. as it would imply 
> > insertion of underlying header, which might be annoying.
> > as an example, code patterns in the wild look like:
> > `foo.h`:
> > ```
> > #include 
> > namespace famous_library_name {
> > using std::optional;
> > }
> > ```
> > 
> > foo.cc
> > ```
> > #include "foo.h"
> > void foo() {
> >   famous_library_name::optional x(3); // we were getting complaints around 
> > saying `foo.h` is unused, i bet we'll get similar complaints if we said you 
> > should insert ``.
> > }
> > ```
> this wrapping is weird, and the amount of code on one line is hard to read, 
> switch to raw-string?
> we probably don't want to consider references

Yeah, this is "do member accesses count as references" which we've identified 
as an important policy knob to add to IWYU-as-a-library

> imply insertion

we'll probably replace this impl with said library before starting to offer 
insertions.

(and for now, the behavior in this test matches the way we currently treat 
constructors elsewhere)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123212

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


[PATCH] D119544: Deferred Concept Instantiation Implementation

2022-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:60-61
 const NamedDecl *D, const TemplateArgumentList *Innermost,
-bool RelativeToPrimary, const FunctionDecl *Pattern) {
+bool RelativeToPrimary, const FunctionDecl *Pattern, bool LookBeyondLambda,
+bool IncludeContainingStructArgs) {
   // Accumulate the set of template argument lists in this structure.

ChuanqiXu wrote:
> Would you elaborate more for `LookBeyondLambda` and 
> `IncludeContainingStructArgs`? It confuses me since I couldn't find `Lambda` 
> or `Struct` from the context of use point.
Sure!  

So this function is typically used for 'getting the template instantiation 
args' of the current Declaration (D) for a variety of reasons.  In all of those 
cases previously, it would 'stop' looking when it hit a lambda generic call 
operator (see line 157).  This would block our ability to get the full 
instantiation tree.

Similarly, it would stop at a containing class-template (as most instantiations 
are done against the parent class template).  Unfortunately this is sufficient, 
so the IncludeContainingStructArgs (see line 185) ALSO includes those 
arguments, as they are necessary  (since they haven't been instantiated in the 
constraint yet).


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

https://reviews.llvm.org/D119544

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


[PATCH] D122535: [clang-tidy] Never consider assignments as equivalent in `misc-redundant-expression` check

2022-04-06 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

FWIW, False negatives are more tolerable than false positives in clang tidy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122535

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


[PATCH] D123182: [Concepts] Fix issue #53640

2022-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Can you improve the commit-message?  Title in particular, but more details 
would be greatly appreciated.




Comment at: clang/lib/Sema/SemaOverload.cpp:2955
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
 /// for equality of their argument types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are different,





Comment at: clang/lib/Sema/SemaOverload.cpp:2958
 /// ArgPos will have the parameter index of the first different parameter.
+/// If `Reversed` is true, exactly one of FT1 and FT2 is an overload
+/// candidate with a reversed parameter order.

I don't really get what you mean for 'Reversed', can you better clarify?  Both 
in comments, and here?



Comment at: clang/lib/Sema/SemaOverload.cpp:2970
+   E = OldType->param_type_end();
+   O && (O != E); ++O, (Reversed ? --N : ++N)) {
 // Ignore address spaces in pointee type. This is to disallow overloading

Now I REALLY don't get it :) 



Comment at: clang/lib/Sema/SemaOverload.cpp:9829
+  bool CanCompareConstraints = false;
+  if (Cand1.Function && Cand2.Function && Cand1.Function->hasPrototype() &&
+  Cand2.Function->hasPrototype()) {

Since the point of this is to just calculate the CanCompareConstraints, I think 
it should be a separate function called below where it is used.  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

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


[clang] 31c9711 - [PS4] clang-format PS4CPU.cpp/.h

2022-04-06 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-04-06T06:52:29-07:00
New Revision: 31c971145f5eef53e443fe7e9b137db6b5b6319d

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

LOG: [PS4] clang-format PS4CPU.cpp/.h

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/lib/Driver/ToolChains/PS4CPU.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index bcf9147833ddf..c73edf1adac2e 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -7,8 +7,8 @@
 
//===--===//
 
 #include "PS4CPU.h"
-#include "FreeBSD.h"
 #include "CommonArgs.h"
+#include "FreeBSD.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -125,7 +125,7 @@ void tools::PS4cpu::Link::ConstructJob(Compilation &C, 
const JobAction &JA,
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if(!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 AddPS4SanitizerArgs(ToolChain, Args, CmdArgs);
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
@@ -149,8 +149,7 @@ void tools::PS4cpu::Link::ConstructJob(Compilation &C, 
const JobAction &JA,
 << "-fuse-ld" << getToolChain().getTriple().str();
   }
 
-  const char *Exec =
-  Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld"));
+  const char *Exec = Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld"));
 
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileUTF8(),

diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.h 
b/clang/lib/Driver/ToolChains/PS4CPU.h
index 4bedabaf267c0..86731b8f9649b 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.h
+++ b/clang/lib/Driver/ToolChains/PS4CPU.h
@@ -33,8 +33,7 @@ class LLVM_LIBRARY_VISIBILITY Assemble : public Tool {
   bool hasIntegratedCPP() const override { return false; }
 
   void ConstructJob(Compilation &C, const JobAction &JA,
-const InputInfo &Output,
-const InputInfoList &Inputs,
+const InputInfo &Output, const InputInfoList &Inputs,
 const llvm::opt::ArgList &TCArgs,
 const char *LinkingOutput) const override;
 };
@@ -47,8 +46,7 @@ class LLVM_LIBRARY_VISIBILITY Link : public Tool {
   bool isLinkJob() const override { return true; }
 
   void ConstructJob(Compilation &C, const JobAction &JA,
-const InputInfo &Output,
-const InputInfoList &Inputs,
+const InputInfo &Output, const InputInfoList &Inputs,
 const llvm::opt::ArgList &TCArgs,
 const char *LinkingOutput) const override;
 };
@@ -63,12 +61,12 @@ class LLVM_LIBRARY_VISIBILITY PS4CPU : public Generic_ELF {
  const llvm::opt::ArgList &Args);
 
   // No support for finding a C++ standard library yet.
-  void addLibCxxIncludePaths(
-  const llvm::opt::ArgList &DriverArgs,
-  llvm::opt::ArgStringList &CC1Args) const override {}
-  void addLibStdCxxIncludePaths(
-  const llvm::opt::ArgList &DriverArgs,
-  llvm::opt::ArgStringList &CC1Args) const override {}
+  void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override 
{
+  }
+  void
+  addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
+   llvm::opt::ArgStringList &CC1Args) const override {}
 
   bool IsMathErrnoDefault() const override { return false; }
   bool IsObjCNonFragileABIDefault() const override { return true; }
@@ -92,9 +90,8 @@ class LLVM_LIBRARY_VISIBILITY PS4CPU : public Generic_ELF {
   bool canSplitThinLTOUnit() const override { return false; }
 
   void addClangTargetOptions(
-const llvm::opt::ArgList &DriverArgs,
-llvm::opt::ArgStringList &CC1Args,
-Action::OffloadKind DeviceOffloadingKind) const override;
+  const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
+  Action::OffloadKind DeviceOffloadingKind) const override;
 
   llvm::DenormalMode getDefaultDenormalModeForType(
   const llvm::opt::ArgList &DriverArgs, const JobAction &JA,



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


[PATCH] D123197: Remove a few effectively-unused FileEntry APIs. NFC

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 420832.
sammccall added a comment.

revert clang-format changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123197

Files:
  clang/include/clang/Basic/DirectoryEntry.h
  clang/include/clang/Basic/FileEntry.h
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp
  clang/lib/Frontend/LogDiagnosticPrinter.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/unittests/Basic/FileEntryTest.cpp
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -165,7 +165,6 @@
 
   auto file = manager.getFile("/tmp/test");
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   EXPECT_EQ("/tmp/test", (*file)->getName());
 
   const DirectoryEntry *dir = (*file)->getDir();
@@ -190,7 +189,6 @@
   manager.getVirtualFile("virtual/dir/bar.h", 100, 0);
   auto file = manager.getFile("virtual/dir/bar.h");
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   EXPECT_EQ("virtual/dir/bar.h", (*file)->getName());
 
   const DirectoryEntry *dir = (*file)->getDir();
@@ -212,9 +210,7 @@
   auto fileFoo = manager.getFile("foo.cpp");
   auto fileBar = manager.getFile("bar.cpp");
   ASSERT_TRUE(fileFoo);
-  ASSERT_TRUE((*fileFoo)->isValid());
   ASSERT_TRUE(fileBar);
-  ASSERT_TRUE((*fileBar)->isValid());
   EXPECT_NE(*fileFoo, *fileBar);
 }
 
@@ -341,9 +337,6 @@
   statCache->InjectFile("abc/bar.cpp", 42);
   manager.setStatCache(std::move(statCache));
 
-  ASSERT_TRUE(manager.getVirtualFile("abc/foo.cpp", 100, 0)->isValid());
-  ASSERT_TRUE(manager.getVirtualFile("abc/bar.cpp", 200, 0)->isValid());
-
   auto f1 = manager.getFile("abc/foo.cpp");
   auto f2 = manager.getFile("abc/bar.cpp");
 
@@ -418,14 +411,12 @@
   // Inject the virtual file:
   const FileEntry *file1 = manager.getVirtualFile("c:\\tmp\\test", 123, 1);
   ASSERT_TRUE(file1 != nullptr);
-  ASSERT_TRUE(file1->isValid());
   EXPECT_EQ(43U, file1->getUniqueID().getFile());
   EXPECT_EQ(123, file1->getSize());
 
   // Lookup the virtual file with a different name:
   auto file2 = manager.getFile("c:/tmp/test", 100, 1);
   ASSERT_TRUE(file2);
-  ASSERT_TRUE((*file2)->isValid());
   // Check that it's the same UFE:
   EXPECT_EQ(file1, *file2);
   EXPECT_EQ(43U, (*file2)->getUniqueID().getFile());
@@ -487,7 +478,6 @@
   // Check for real path.
   const FileEntry *file = Manager.getVirtualFile("/tmp/test", 123, 1);
   ASSERT_TRUE(file != nullptr);
-  ASSERT_TRUE(file->isValid());
   SmallString<64> ExpectedResult = CustomWorkingDir;
 
   llvm::sys::path::append(ExpectedResult, "tmp", "test");
@@ -515,7 +505,6 @@
   // Check for real path.
   auto file = Manager.getFile("/tmp/test", /*OpenFile=*/false);
   ASSERT_TRUE(file);
-  ASSERT_TRUE((*file)->isValid());
   SmallString<64> ExpectedResult = CustomWorkingDir;
 
   llvm::sys::path::append(ExpectedResult, "tmp", "test");
@@ -548,7 +537,6 @@
   const FileEntry *File = Manager.getVirtualFile("/tmp/test", /*Size=*/10, 0);
   ASSERT_TRUE(File);
   const FileEntry &FE = *File;
-  EXPECT_TRUE(FE.isValid());
   EXPECT_EQ(FE.getSize(), 10);
 
   // Calling a second time should not affect the UID or size.
@@ -564,7 +552,6 @@
   llvm::Optional BypassRef =
   Manager.getBypassFile(File->getLastRef());
   ASSERT_TRUE(BypassRef);
-  EXPECT_TRUE(BypassRef->isValid());
   EXPECT_EQ("/tmp/test", BypassRef->getName());
 
   // Check that it's different in the right ways.
Index: clang/unittests/Basic/FileEntryTest.cpp
===
--- clang/unittests/Basic/FileEntryTest.cpp
+++ clang/unittests/Basic/FileEntryTest.cpp
@@ -7,8 +7,11 @@
 //===--===//
 
 #include "clang/Basic/FileEntry.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -17,55 +20,44 @@
 namespace {
 
 using FileMap = StringMap>;
-using DirMap = StringMap>;
+using DirMap = StringMap>;
 
 struct RefMaps {
+  FileManager FM; // Used only to create FileEntry/DirectoryEntry.
+  unsigned UniqueNameCounter = 0;
   FileMap Files;
   DirMap Dirs;
 
-  SmallVector, 5> FEs;
-  SmallVector, 5> DEs;
   DirectoryEntryRef DR;
 
-  RefMaps() : DR(addDirectory("dir")) {}
+  RefMaps()
+  : FM(FileSystemOptions(), std::make_unique()),
+DR(addDirectory("dir")) {}
 
   DirectoryEntryRef addDirectory(StringRef Name) {
-DEs.push_back(std::make_unique());
-return DirectoryEntryRef(*Dirs.insert({Name, *DEs.back()}).first);
+const DirectoryEntry *DE =
+FM.getVirtualFile(std::to_string(UniqueNameCounter++

[PATCH] D123197: Remove a few effectively-unused FileEntry APIs. NFC

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 2 inline comments as done.
sammccall added inline comments.



Comment at: clang/lib/Basic/FileManager.cpp:462
   UFE->Dir = &DirInfo->getDirEntry();
-  UFE->UID = NextFileUID++;
-  UFE->IsValid = true;
+  UFE->UID = NextFileUID++;
   UFE->File.reset();

kadircet wrote:
> sammccall wrote:
> > kadircet wrote:
> > > nit: revert formatting
> > `arc` insists on this change here, because it's in the blast radius of the 
> > next line and clang-format isn't configured to allow this formatting.
> > 
> > Unless you feel strongly I'd rather not fight the linter when it's not 
> > really wrong.
> > (Happy to reformat the other lines to match though)
> > Unless you feel strongly I'd rather not fight the linter when it's not 
> > really wrong.
> > (Happy to reformat the other lines to match though)
> 
> I was suggesting this for preserving history purposes, in theory all of this 
> is old code with intricate semantics so it would be nice to not add more 
> commits to the history chain here. I think it should be possible to just `arc 
> diff --nolint` (or push without updating the diff in phabricator, which you 
> already probably know, but just in case).
Sure, fair enough


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123197

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


[PATCH] D123026: [clang][NFC] Extract the EmitAssemblyHelper::shouldEmitLTOSummary method

2022-04-06 Thread Pavel Samolysov via Phabricator via cfe-commits
psamolysov-intel updated this revision to Diff 420831.
psamolysov-intel retitled this revision from "[clang][NFC] Extract the 
EmitAssemblyHelper::emitLTOSummary method" to "[clang][NFC] Extract the 
EmitAssemblyHelper::shouldEmitLTOSummary method".
psamolysov-intel edited the summary of this revision.
psamolysov-intel added a comment.

@tejohnson Thank you for your opinion. I've renamed the function member into 
`shouldEmitLTOSummary` and extract the condition only. The code that changes 
the module flags is still inlined. The patch description was also edited to 
reflect these changes.


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

https://reviews.llvm.org/D123026

Files:
  clang/lib/CodeGen/BackendUtil.cpp


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -164,6 +164,16 @@
   std::unique_ptr &OS,
   std::unique_ptr &DwoOS);
 
+  /// Check whether we should emit a module summary.
+  /// The module summary should be emitted by default for Regular LTO
+  /// except for ld64 targets.
+  ///
+  /// \return True if the module summary should be emitted.
+  bool shouldEmitLTOSummary() const {
+return CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
+   TargetTriple.getVendor() != llvm::Triple::Apple;
+  }
+
 public:
   EmitAssemblyHelper(DiagnosticsEngine &_Diags,
  const HeaderSearchOptions &HeaderSearchOpts,
@@ -1054,9 +1064,7 @@
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
-  bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   TargetTriple.getVendor() != llvm::Triple::Apple);
+  bool EmitLTOSummary = shouldEmitLTOSummary();
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
@@ -1064,7 +1072,6 @@
   TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
uint32_t(1));
   }
-
   PerModulePasses.add(createBitcodeWriterPass(
   *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
 }
@@ -1470,9 +1477,7 @@
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
-  bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   TargetTriple.getVendor() != llvm::Triple::Apple);
+  bool EmitLTOSummary = shouldEmitLTOSummary();
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -164,6 +164,16 @@
   std::unique_ptr &OS,
   std::unique_ptr &DwoOS);
 
+  /// Check whether we should emit a module summary.
+  /// The module summary should be emitted by default for Regular LTO
+  /// except for ld64 targets.
+  ///
+  /// \return True if the module summary should be emitted.
+  bool shouldEmitLTOSummary() const {
+return CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
+   TargetTriple.getVendor() != llvm::Triple::Apple;
+  }
+
 public:
   EmitAssemblyHelper(DiagnosticsEngine &_Diags,
  const HeaderSearchOptions &HeaderSearchOpts,
@@ -1054,9 +1064,7 @@
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
-  bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   TargetTriple.getVendor() != llvm::Triple::Apple);
+  bool EmitLTOSummary = shouldEmitLTOSummary();
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
@@ -1064,7 +1072,6 @@
   TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
uint32_t(1));
   }
-
   PerModulePasses.add(createBitcodeWriterPass(
   *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
 }
@@ -1470,9 +1477,7 @@
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
-  bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   TargetTriple.getVendor() != llvm::Triple::Apple);
+  bool EmitLTOSummary = shouldEmitLTOSummary();
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));

[clang-tools-extra] 68eac9a - [clangd] Code action to declare missing move/copy constructor/assignment

2022-04-06 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-04-06T16:14:42+02:00
New Revision: 68eac9a6e7a10eba8081bab340fda8be13a7840e

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

LOG: [clangd] Code action to declare missing move/copy constructor/assignment

Fixes https://github.com/clangd/clangd/issues/973

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

Added: 
clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp

Modified: 
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/ParsedAST.h
clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 295418c8434ab..77cc4569ae712 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -629,6 +629,8 @@ const ASTContext &ParsedAST::getASTContext() const {
   return Clang->getASTContext();
 }
 
+Sema &ParsedAST::getSema() { return Clang->getSema(); }
+
 Preprocessor &ParsedAST::getPreprocessor() { return Clang->getPreprocessor(); }
 
 std::shared_ptr ParsedAST::getPreprocessorPtr() {

diff  --git a/clang-tools-extra/clangd/ParsedAST.h 
b/clang-tools-extra/clangd/ParsedAST.h
index 72ba2a9938c27..425a411ec9c3f 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -37,6 +37,7 @@
 #include 
 
 namespace clang {
+class Sema;
 namespace clangd {
 class HeuristicResolver;
 
@@ -63,6 +64,8 @@ class ParsedAST {
   ASTContext &getASTContext();
   const ASTContext &getASTContext() const;
 
+  Sema &getSema();
+
   Preprocessor &getPreprocessor();
   std::shared_ptr getPreprocessorPtr();
   const Preprocessor &getPreprocessor() const;

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt 
b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
index ae279781a6f52..0b968ee2a66c1 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
+++ b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangDaemonTweaks OBJECT
   PopulateSwitch.cpp
   RawStringLiteral.cpp
   RemoveUsingNamespace.cpp
+  SpecialMembers.cpp
   SwapIfBranches.cpp
 
   LINK_LIBS

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
new file mode 100644
index 0..70604c0c630cf
--- /dev/null
+++ b/clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
@@ -0,0 +1,153 @@
+//===--- SpecialMembers.cpp - Generate C++ special member functions 
---===//
+//
+// 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
+//
+//===--===//
+#include "ParsedAST.h"
+#include "refactor/InsertionPoint.h"
+#include "refactor/Tweak.h"
+#include "support/Logger.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+// Returns code to declare missing copy/move constructors/assignment operators.
+// They will be deleted or defaulted to match the class's current state.
+std::string buildSpecialMemberDeclarations(const CXXRecordDecl &Class) {
+  struct Members {
+const CXXMethodDecl *Copy = nullptr;
+const CXXMethodDecl *Move = nullptr;
+  } Ctor, Assign;
+
+  for (const auto &M : Class.methods()) {
+if (M->isCopyAssignmentOperator())
+  Assign.Copy = M;
+else if (M->isMoveAssignmentOperator())
+  Assign.Move = M;
+if (const auto *C = llvm::dyn_cast(M)) {
+  if (C->isCopyConstructor())
+Ctor.Copy = C;
+  else if (C->isMoveConstructor())
+Ctor.Move = C;
+}
+  }
+
+  std::string S;
+  llvm::raw_string_ostream OS(S);
+
+  auto PrintMember = [&](const CXXMethodDecl *D, const char *MemberPattern,
+ const char *ParmPattern) {
+if (D && !D->isImplicit())
+  return;
+bool Delete = !D || D->isDeleted();
+OS << llvm::formatv(
+"{0} = {1};\n",
+llvm::formatv(MemberPattern, Class.getName(),
+  llvm::formatv(ParmPattern, Class.getName())),
+Delete ? "delete" : "default");
+  };
+  auto PrintMembers = [&](const Members &M, const char *MemberPattern) {
+PrintMember(M.Copy, MemberPattern, /*ParmPattern=*/"const {0}&");
+PrintMember

[PATCH] D116490: [clangd] Code action to declare missing move/copy constructor/assignment

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG68eac9a6e7a1: [clangd] Code action to declare missing 
move/copy constructor/assignment (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116490

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
  clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/tweaks/SpecialMembersTests.cpp
@@ -0,0 +1,47 @@
+//===-- SpecialMembersTests.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TweakTesting.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TWEAK_TEST(SpecialMembers);
+
+TEST_F(SpecialMembersTest, Test) {
+  EXPECT_AVAILABLE("struct ^S {};");
+  EXPECT_UNAVAILABLE("struct S { ^ };");
+  EXPECT_UNAVAILABLE("union ^U {};");
+  EXPECT_AVAILABLE("struct ^S { S(const S&); S(S&&); };");
+  EXPECT_UNAVAILABLE("struct ^S {"
+ "S(const S&); S(S&&);"
+ "S &operator=(S&&); S &operator=(const S&);"
+ "};");
+
+  const char *Output = R"cpp(struct S{S(const S &) = default;
+  S(S &&) = default;
+  S &operator=(const S &) = default;
+  S &operator=(S &&) = default;
+};)cpp";
+  EXPECT_EQ(apply("struct ^S{};"), Output);
+
+  Output = R"cpp(struct S{S(const S &) = default;
+S(S &&) = default;
+S &operator=(const S &) = delete;
+S &operator=(S &&) = delete;
+int& ref;};)cpp";
+  EXPECT_EQ(apply("struct ^S{int& ref;};"), Output);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/refactor/tweaks/SpecialMembers.cpp
@@ -0,0 +1,153 @@
+//===--- SpecialMembers.cpp - Generate C++ special member functions ---===//
+//
+// 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
+//
+//===--===//
+#include "ParsedAST.h"
+#include "refactor/InsertionPoint.h"
+#include "refactor/Tweak.h"
+#include "support/Logger.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+// Returns code to declare missing copy/move constructors/assignment operators.
+// They will be deleted or defaulted to match the class's current state.
+std::string buildSpecialMemberDeclarations(const CXXRecordDecl &Class) {
+  struct Members {
+const CXXMethodDecl *Copy = nullptr;
+const CXXMethodDecl *Move = nullptr;
+  } Ctor, Assign;
+
+  for (const auto &M : Class.methods()) {
+if (M->isCopyAssignmentOperator())
+  Assign.Copy = M;
+else if (M->isMoveAssignmentOperator())
+  Assign.Move = M;
+if (const auto *C = llvm::dyn_cast(M)) {
+  if (C->isCopyConstructor())
+Ctor.Copy = C;
+  else if (C->isMoveConstructor())
+Ctor.Move = C;
+}
+  }
+
+  std::string S;
+  llvm::raw_string_ostream OS(S);
+
+  auto PrintMember = [&](const CXXMethodDecl *D, const char *MemberPattern,
+ const char *ParmPattern) {
+if (D && !D->isImplicit())
+  return;
+bool Delete = !D || D->isDeleted();
+OS << llvm::formatv(
+"{0} = {1};\n",
+llvm::formatv(MemberPattern, Class.getName(),
+  llvm::formatv(ParmPattern, Class.getName())),
+Delete ? "delete" : "default");
+  };
+  auto PrintMembers = [&](const Members &M, const char *MemberPattern) {
+PrintMember(M.Copy, MemberPattern, /*ParmPattern=*/"const {0}&");
+PrintMember(M.Move, MemberPattern, /*ParmPattern=*/"{0}&&");
+  };
+  PrintMembers(Ctor, /*MemberPattern=*/"{0}({1})");
+  PrintMembers(Assign, /*MemberPattern=*/"{0} &operator=({1})");
+
+  return S;
+}
+
+// A tweak that adds missing declara

[PATCH] D116514: [clangd] Add code action to generate a constructor for a C++ class

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D116514#3230255 , @njames93 wrote:

> Shouldn't the constructors that need `std::move` also ensure the `` 
> header is also included, or at least transitively included. We don't want to 
> generate constructors that wont compile.

I've added this just as a FIXME for now, because we're missing "framework" 
support for adding includes and composing separate edits in tweaks.
I think this is probably only a small obstacle in practice, it seems pretty 
rare to write `std::move` and need to add the `#include` for it to compile.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116514

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


[clang-tools-extra] afa9430 - [clangd] Add code action to generate a constructor for a C++ class

2022-04-06 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-04-06T16:23:50+02:00
New Revision: afa94306a8c197e346d3234e5ac5292ab90eae73

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

LOG: [clangd] Add code action to generate a constructor for a C++ class

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

Added: 
clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp

Modified: 
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/AST.h
clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
clang-tools-extra/clangd/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index 660c7187c2268..70d98d0e0bb40 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -349,7 +349,8 @@ SymbolID getSymbolID(const llvm::StringRef MacroName, const 
MacroInfo *MI,
   return SymbolID(USR);
 }
 
-std::string printType(const QualType QT, const DeclContext &CurContext) {
+std::string printType(const QualType QT, const DeclContext &CurContext,
+  const llvm::StringRef Placeholder) {
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   PrintingPolicy PP(CurContext.getParentASTContext().getPrintingPolicy());
@@ -370,7 +371,7 @@ std::string printType(const QualType QT, const DeclContext 
&CurContext) {
   PrintCB PCB(&CurContext);
   PP.Callbacks = &PCB;
 
-  QT.print(OS, PP);
+  QT.print(OS, PP, Placeholder);
   return OS.str();
 }
 

diff  --git a/clang-tools-extra/clangd/AST.h b/clang-tools-extra/clangd/AST.h
index 523e1d9a9a5f4..c903a34e728fa 100644
--- a/clang-tools-extra/clangd/AST.h
+++ b/clang-tools-extra/clangd/AST.h
@@ -95,7 +95,8 @@ SymbolID getSymbolID(const llvm::StringRef MacroName, const 
MacroInfo *MI,
 
 /// Returns a QualType as string. The result doesn't contain unwritten scopes
 /// like anonymous/inline namespace.
-std::string printType(const QualType QT, const DeclContext &CurContext);
+std::string printType(const QualType QT, const DeclContext &CurContext,
+  llvm::StringRef Placeholder = "");
 
 /// Indicates if \p D is a template instantiation implicitly generated by the
 /// compiler, e.g.

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt 
b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
index 0b968ee2a66c1..a68e7157a5af0 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
+++ b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
@@ -21,6 +21,7 @@ add_clang_library(clangDaemonTweaks OBJECT
   ExpandMacro.cpp
   ExtractFunction.cpp
   ExtractVariable.cpp
+  MemberwiseConstructor.cpp
   ObjCLocalizeStringLiteral.cpp
   ObjCMemberwiseInitializer.cpp
   PopulateSwitch.cpp

diff  --git 
a/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
new file mode 100644
index 0..a00b778e7dd79
--- /dev/null
+++ b/clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
@@ -0,0 +1,267 @@
+//===--- MemberwiseConstructor.cpp - Generate C++ constructor 
-===//
+//
+// 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
+//
+//===--===//
+#include "AST.h"
+#include "ParsedAST.h"
+#include "refactor/InsertionPoint.h"
+#include "refactor/Tweak.h"
+#include "support/Logger.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/TypeVisitor.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+// A tweak that adds a C++ constructor which initializes each member.
+//
+// Given:
+//   struct S{ int x; unique_ptr y; };
+// the tweak inserts the constructor:
+//   S(int x, unique_ptr y) : x(x), y(std::move(y)) {}
+//
+// We place the constructor inline, other tweaks are available to outline it.
+class MemberwiseConstructor : public Tweak {
+public:
+  const char *id() const override final;
+  llvm::StringLiteral kind() const override {
+return CodeAction::REFACTOR_KIND;
+  }
+  std::string title() const override {
+return llvm::formatv("Define constructor");
+  }
+
+  bool prepare(const Selection &Inputs) override {
+// This tweak assumes move semantics.
+if (!Inputs.AST->getLangOpts().CPlusPlus11)
+  return false;
+
+// Trigger only on class definitions.
+if (auto *N = Inp

[PATCH] D116514: [clangd] Add code action to generate a constructor for a C++ class

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGafa94306a8c1: [clangd] Add code action to generate a 
constructor for a C++ class (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D116514?vs=419225&id=420840#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116514

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/tweaks/MemberwiseConstructorTests.cpp
@@ -0,0 +1,99 @@
+//===-- MemberwiseConstructorTests.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TweakTesting.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+using testing::AllOf;
+using testing::Eq;
+using testing::HasSubstr;
+using testing::Not;
+
+TWEAK_TEST(MemberwiseConstructor);
+
+TEST_F(MemberwiseConstructorTest, Availability) {
+  EXPECT_AVAILABLE("^struct ^S ^{ int x, y; };");
+  EXPECT_UNAVAILABLE("struct S { ^int ^x, y; }; struct ^S;");
+  EXPECT_UNAVAILABLE("struct ^S {};");
+  EXPECT_UNAVAILABLE("union ^S { int x; };");
+  EXPECT_UNAVAILABLE("struct ^S { int x = 0; };");
+  EXPECT_UNAVAILABLE("struct ^S { struct { int x; }; };");
+  EXPECT_UNAVAILABLE("struct ^{ int x; } e;");
+}
+
+TEST_F(MemberwiseConstructorTest, Edits) {
+  Header = R"cpp(
+struct Move {
+  Move(Move&&) = default;
+  Move(const Move&) = delete;
+};
+struct Copy {
+  Copy(Copy&&) = delete;
+  Copy(const Copy&);
+};
+  )cpp";
+  EXPECT_EQ(apply("struct ^S{Move M; Copy C; int I; int J=4;};"),
+"struct S{"
+"S(Move M, const Copy &C, int I) : M(std::move(M)), C(C), I(I) {}\n"
+"Move M; Copy C; int I; int J=4;};");
+}
+
+TEST_F(MemberwiseConstructorTest, FieldTreatment) {
+  Header = R"cpp(
+struct MoveOnly {
+  MoveOnly(MoveOnly&&) = default;
+  MoveOnly(const MoveOnly&) = delete;
+};
+struct CopyOnly {
+  CopyOnly(CopyOnly&&) = delete;
+  CopyOnly(const CopyOnly&);
+};
+struct CopyTrivial {
+  CopyTrivial(CopyTrivial&&) = default;
+  CopyTrivial(const CopyTrivial&) = default;
+};
+struct Immovable {
+  Immovable(Immovable&&) = delete;
+  Immovable(const Immovable&) = delete;
+};
+template 
+struct Traits { using Type = typename T::Type; };
+using IntAlias = int;
+  )cpp";
+
+  auto Fail = Eq("unavailable");
+  auto Move = HasSubstr(": Member(std::move(Member))");
+  auto CopyRef = AllOf(HasSubstr("S(const "), HasSubstr(": Member(Member)"));
+  auto Copy = AllOf(Not(HasSubstr("S(const ")), HasSubstr(": Member(Member)"));
+  auto With = [](llvm::StringRef Type) {
+return ("struct ^S { " + Type + " Member; };").str();
+  };
+
+  EXPECT_THAT(apply(With("Immovable")), Fail);
+  EXPECT_THAT(apply(With("MoveOnly")), Move);
+  EXPECT_THAT(apply(With("CopyOnly")), CopyRef);
+  EXPECT_THAT(apply(With("CopyTrivial")), Copy);
+  EXPECT_THAT(apply(With("int")), Copy);
+  EXPECT_THAT(apply(With("IntAlias")), Copy);
+  EXPECT_THAT(apply(With("Immovable*")), Copy);
+  EXPECT_THAT(apply(With("Immovable&")), Copy);
+
+  EXPECT_THAT(apply("template " + With("T")), Move);
+  EXPECT_THAT(apply("template " + With("typename Traits::Type")),
+  Move);
+  EXPECT_THAT(apply("template " + With("T*")), Copy);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -117,6 +117,7 @@
   tweaks/ExpandMacroTests.cpp
   tweaks/ExtractFunctionTests.cpp
   tweaks/ExtractVariableTests.cpp
+  tweaks/MemberwiseConstructorTests.cpp
   tweaks/ObjCLocalizeStringLiteralTests.cpp
   tweaks/ObjCMemberwiseInitializerTests.cpp
   tweaks/PopulateSwitchTests.cpp
Index: clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/refactor/tweaks/MemberwiseConstructor.cpp
@@ -0,0 +1,267 @@

[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension

2022-04-06 Thread Emil Kieri via Phabricator via cfe-commits
ekieri added a comment.

Ok, good. Then please abandon this revision (Add Action... down by the comment 
box), so that its status is clear to everybody. Cheers!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123113

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


[PATCH] D122525: [clang][ASTImporter] Fix an import error handling related bug.

2022-04-06 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8792-8794
+if (!isa(FromDi))
+  if (auto *FromDiDC = dyn_cast(FromDi))
+if (FromDiDC->containsDecl(PrevFromDi))

martong wrote:
> We should elevate this logic and the one in `ImportDeclContext` that uses 
> `consumeError` into a common abstraction. I.e. making them closer to each 
> other in a class.
> Something like (draft, did not test it, might not compile):
> ```
> class ErrorHandlingStrategy {
>   static bool accumulateChildErrors(DeclContext*);
>   static bool accumulateChildErrors(Decl *FromDi, Decl* Parent); // Use this 
> one when traversing through the import path!
> public:
>   static Error handleDeclContextError(Error Err, DeclContext* FromDC) {
> Error ChildErrors = Error::success();
> if (Err && accumulateChildErrors(FromDC))
>   ChildErrors =  joinErrors(std::move(ChildErrors), 
> std::move(Err));
> else
>   consumeError(std::move(Err));
>  return ChildErrors
>   }
>   
> };
> ```
The `AccumulateChildErrors` value looks the only common thing. It can mean: 
Accumulate errors (or not) for declarations that are in child-relationship with 
the parent. The value is only dependent on the parent, true if it is a 
`TagDecl`. This value can be extracted into a function that is used in 
`importDeclContext` and at `Import(Decl *)`. At `importDeclContext` we should 
accumulate or discard errors for every child node. But not for possible other 
nodes that are imported but are not a child node (probably no such exists now 
but theoretically it is possible, and when using the error handling strategy 
for non-namespace-like nodes).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122525

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


[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2022-04-06 Thread Augie Fackler via Phabricator via cfe-commits
durin42 edited the summary of this revision.
durin42 updated this revision to Diff 420854.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-structors.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-structors.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-structors.cpp
@@ -57,7 +57,7 @@
 //
 // DTORS:  [[CALL_DELETE_LABEL]]
 // DTORS-NEXT:   %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
-// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
+// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[THIS_AS_VOID]])
 // DTORS-NEXT:   br label %[[CONTINUE_LABEL]]
 //
 // DTORS:  [[CONTINUE_LABEL]]
@@ -119,7 +119,7 @@
 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
 // CHECK-NEXT:   %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
 // CHECK-NEXT:   %[[CALL:.*]] = call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* {{[^,]*}} %[[OBJ_PTR_VALUE]], i32 0)
-// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[CALL]])
+// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[CALL]])
 // CHECK:  ret void
 }
 
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -37,7 +37,7 @@
 // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
 // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 5)
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(5);
   }
 
@@ -48,7 +48,7 @@
 // CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
 // CHECK:  invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 [[FOO]])
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 extern int foo();
 return new A(foo());
   }
@@ -74,7 +74,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B().x);
   }
 
@@ -102,7 +102,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B());
   }
 
@@ -128,7 +128,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B(), B());
   }
   A *f() {
@@ -165,7 +165,7 @@
 // CHECK:  ret [[A]]* [[RET]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 A *x;
 return (x = new A(makeB()), makeB(), x);
   }
@@ -458,7 +458,7 @@
   }
   // CHECK: define{{.*}} {{%.*}}* @_ZN5test94testEv
   // CHECK: [[TEST9_NEW:%.*]] = call noalias nonnull i8* @_Znam
-  // CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
+  // CHECK: call void @_ZdaPv(i8* allocptr [[TEST9_NEW]])
 }
 
 // In a destructor with a function-try-block, a return statement in a
Index: clang/test/CodeGenCXX/delete.cpp
===
--- clang/test/CodeGenCXX/delete.cpp
+++ clang/test/CodeGenCXX/delete.cpp
@@ -100,7 +100,7 @@
 // CHECK-NEXT: call void @_ZN5test11AD1Ev([[A]]* {{[^,]*}} [[CUR]])
 // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]]
 // CHECK-NEXT: br i1 [[ISDONE]]
-// CHECK:  call void @_ZdaPv(i8* noundef [[ALLOC]])
+// CHECK:  call void @_ZdaPv(i8* allocptr noundef [[ALLOC]])
   }
 }
 
@@ -146,7 +146,7 @@
 // CHECK-NEXT: [[DTOR:%.*]] = load void ([[X]]*)*, void ([[X]]*)** [[T0]]
 // CHECK-NEXT: call void [[DTOR]]([[X]]* {{[^,]*}} [[OBJ:%.*]])
 //   Call the global operator delete.
-// CHECK-NEXT: call void @_Z

[PATCH] D123211: [flang][driver] Add support for generating LLVM bytecode files

2022-04-06 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 420862.
awarzynski added a comment.

Move code a bit, add comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123211

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/driver-help.f90
  flang/test/Driver/emit-llvm-bc.f90

Index: flang/test/Driver/emit-llvm-bc.f90
===
--- /dev/null
+++ flang/test/Driver/emit-llvm-bc.f90
@@ -0,0 +1,19 @@
+! Test the options for generating LLVM byte-code `-emit-llvm-bc` option
+
+!-
+! RUN COMMANDS
+!-
+! RUN: %flang -emit-llvm -c %s -o - | llvm-dis -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-llvm-bc %s -o - | llvm-dis -o - | FileCheck %s
+
+!
+! EXPECTED OUTPUT
+!
+! CHECK: define void @_QQmain()
+! CHECK-NEXT:  ret void
+! CHECK-NEXT: }
+
+!--
+! INPUT
+!--
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -71,6 +71,7 @@
 ! HELP-FC1-NEXT:OPTIONS:
 ! HELP-FC1-NEXT: -cpp   Enable predefined and command line preprocessor macros
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-FC1-NEXT: -emit-llvm-bc  Build ASTs then convert to LLVM, emit .bc file
 ! HELP-FC1-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
 ! HELP-FC1-NEXT: -emit-mlir Build the parse tree, then lower it to MLIR
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
Index: flang/test/CMakeLists.txt
===
--- flang/test/CMakeLists.txt
+++ flang/test/CMakeLists.txt
@@ -55,6 +55,7 @@
   fir-opt
   tco
   bbc
+  llvm-dis
   llvm-objdump
   split-file
 )
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -37,6 +37,8 @@
 return std::make_unique();
   case EmitLLVM:
 return std::make_unique();
+  case EmitLLVMBitcode:
+return std::make_unique();
   case EmitObj:
 return std::make_unique(
 BackendAction::BackendActionTy::Backend_EmitObj);
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -33,6 +33,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/Bitcode/BitcodeWriterPass.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -472,6 +473,49 @@
   llvmModule->print(*os, /*AssemblyAnnotationWriter=*/nullptr);
 }
 
+void EmitLLVMBitcodeAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+  // Generate an LLVM module if it's not already present (it will already be
+  // present if the input file is an LLVM IR/BC file).
+  if (!llvmModule)
+GenerateLLVMIR();
+
+  // Create and configure `Target`
+  std::string error;
+  std::string theTriple = llvmModule->getTargetTriple();
+  const llvm::Target *theTarget =
+  llvm::TargetRegistry::lookupTarget(theTriple, error);
+  assert(theTarget && "Failed to create Target");
+
+  // Create and configure `TargetMachine`
+  std::unique_ptr TM;
+
+  TM.reset(theTarget->createTargetMachine(theTriple, /*CPU=*/"",
+  /*Features=*/"", llvm::TargetOptions(), llvm::None));
+  assert(TM && "Failed to create TargetMachine");
+  llvmModule->setDataLayout(TM->createDataLayout());
+
+  // Generate an output file
+  std::unique_ptr os = ci.CreateDefaultOutputFile(
+  /*Binary=*/true, /*InFile=*/GetCurrentFileOrBufferName(), "bc");
+  if (!os) {
+unsigned diagID = ci.diagnostics().getCustomDiagID(
+clang::DiagnosticsEngine::Error, "failed to create the output file");
+ci.diagnostics().Report(diagID);
+return;
+  }
+
+  // Set-up the pass manager
+  llvm::ModulePassManager MPM;
+  llvm::ModuleAnalysisManager MAM;
+  llvm::PassBuilder PB(TM.get());
+  PB.registerModuleAnalyses(MAM);
+  MPM.addPass(llvm::BitcodeWriterPass(*os));
+
+  // Run the passes
+  MPM.run(*llvmModule, MAM);
+}
+
 void EmitMLIRAction::ExecuteAction() {
   CompilerInstance &ci = this->instance();
 
Index: flang/lib/Frontend/CompilerInvocation.cpp
==

[PATCH] D123211: [flang][driver] Add support for generating LLVM bytecode files

2022-04-06 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/lib/Frontend/FrontendActions.cpp:483
+
+  llvm::ModulePassManager MPM;
+  llvm::ModuleAnalysisManager MAM;

rovka wrote:
> Nit: I think you can move these closer to their first use.
Thanks, I thought that I _did_ move it :)



Comment at: flang/test/CMakeLists.txt:58
   bbc
+  llvm-dis
   llvm-objdump

rovka wrote:
> Were you going to add a test that uses this?
Sorry, forgot to add in the original revision. Should be there now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123211

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


[PATCH] D121838: [WIP] Generalize "check-all" umbrella targets, use for check-clang-tools

2022-04-06 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

I think this is no longer [WIP] but rather review-ready, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121838

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


[PATCH] D121838: [WIP] Generalize "check-all" umbrella targets, use for check-clang-tools

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Ran into problems caused by check-clang-tools not running clangd tests again, 
probably worth

In D121838#3433022 , @kbobyrev wrote:

> I think this is no longer [WIP] but rather review-ready, right?

It's both WIP and review-ready :-)
There are some mechanical cleanups left to do as mentioned in the comment 
above, but there's no point doing them if the idea is wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121838

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


[PATCH] D123026: [clang][NFC] Extract the EmitAssemblyHelper::shouldEmitLTOSummary method

2022-04-06 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

lgtm with a couple of small changes noted below.




Comment at: clang/lib/CodeGen/BackendUtil.cpp:167
 
+  /// Check whether we should emit a module summary.
+  /// The module summary should be emitted by default for Regular LTO

Add "for regular LTO" (this check is not appropriate for ThinLTO). I'd prefer 
to make the name "shouldEmitRegularLTOSummary" to be explicit about this too.


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

https://reviews.llvm.org/D123026

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


[PATCH] D123211: [flang][driver] Add support for generating LLVM bytecode files

2022-04-06 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Thanks for taking a look Diana!

> Why not use the BackendAction for this?

This action only requires the middle-end in LLVM :) The `BackendAction` will 
use the backend, but that's not needed here.

> There seems to be a lot of shared code, up until the point where you create 
> and use the pass manager

This is the bit that's shared:

  CompilerInstance &ci = this->instance();
  // Generate an LLVM module if it's not already present (it will already be
  // present if the input file is an LLVM IR/BC file).
  if (!llvmModule)
GenerateLLVMIR();
  
  // Create and configure `Target`
  std::string error;
  std::string theTriple = llvmModule->getTargetTriple();
  const llvm::Target *theTarget =
  llvm::TargetRegistry::lookupTarget(theTriple, error);
  assert(theTarget && "Failed to create Target");
  
  // Create and configure `TargetMachine`
  std::unique_ptr TM;
  
  TM.reset(theTarget->createTargetMachine(theTriple, /*CPU=*/"",
  /*Features=*/"", llvm::TargetOptions(), llvm::None));
  assert(TM && "Failed to create TargetMachine");
  llvmModule->setDataLayout(TM->createDataLayout());

I wouldn't say it's "a lot", but probably enough for a dedicated method. I've 
been conservative with regard to sharing code as I anticipate things to change 
in the future (I expect `-O{0|1|2|3|s|z}` to complicate the logic a bit).

> (and in the future, when the backend switches to the new pass manager, there 
> will be even more shared code).

I'm not sure about the timelines for this. And even then, the logic might be 
quite different (again, middle-end vs back-end).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123211

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


[PATCH] D122981: [Clang] Diagnose incomplete return/param types only when function is not deleted

2022-04-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D122981#3432233 , @rZhBoYao wrote:

> I think an extra parameter is inevitable without complicating things too much.

My thought is that it might not be worth to fix the problem for the workaround. 
I feel like the problem is less countered. Let's try to fix it in a cleaner way.


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

https://reviews.llvm.org/D122981

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


[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-06 Thread Victoria Mitchell via Phabricator via cfe-commits
QuietMisdreavus accepted this revision.
QuietMisdreavus added a comment.
This revision is now accepted and ready to land.

I like the idea of using the RAII context/guard to manage the path components 
stack. I have one non-blocking comment about the rest of the patch now.




Comment at: 
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h:125
   /// containing common symbol information of \p Record.
-  Optional serializeAPIRecord(const APIRecord &Record) const;
+  Optional serializeAPIRecord(const APIRecord &Record);
 

Now that the path components are being manipulated outside of 
`serializeAPIRecord`, can this function become `const` again?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123045

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


[PATCH] D122734: [HIP] Fix mangling number for local struct

2022-04-06 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

ping


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

https://reviews.llvm.org/D122734

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


[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420875.
dang marked 2 inline comments as done.
dang added a comment.

Address code review feedback:

- Remove unnecessary code
- Add a test to validate that everything works in the presence of header maps
- Simplify existing test
- Fix small nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123148

Files:
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/known_files_only.c
  clang/test/ExtractAPI/known_files_only_hmap.c

Index: clang/test/ExtractAPI/known_files_only_hmap.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only_hmap.c
@@ -0,0 +1,152 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/known_files_only.hmap.json.in >> \
+// RUN: %t/known_files_only.hmap.json
+// RUN: %hmaptool write %t/known_files_only.hmap.json %t/known_files_only.hmap
+// RUN: %clang -extract-api --product-name=KnownFilesOnlyHmap -target arm64-apple-macosx \
+// RUN: -I%t/known_files_only.hmap -I%t/subdir %t/subdir/subdir1/input.h \
+// RUN: %t/subdir/subdir2/known_file.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+//--- known_files_only.hmap.json.in
+{
+  "mappings" :
+{
+ "subdir2/known_file.h" : "INPUT_DIR/subdir/subdir3/unknown.h"
+}
+}
+
+//--- subdir/subdir1/input.h
+int num;
+#include "subdir2/known_file.h"
+
+//--- subdir/subdir2/known_file.h
+int known_num;
+
+//--- subdir/subdir3/unknown.h
+// Ensure that these symbols are not emitted in the Symbol Graph.
+#ifndef INPUT4_H
+#define INPUT4_H
+
+#define HELLO 1
+char not_emitted;
+void foo(int);
+struct Foo { int a; };
+
+#endif
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "KnownFilesOnlyHmap",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"character": 5,
+"line": 1,
+"uri": "file://INPUT_DIR/subdir/subdir1/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "num"
+  }
+],
+"title": "num"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "known_num"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@known_num"
+  },
+  "kind": {
+"displayName": "Global Variable",
+"identifier": "c.var"
+  },
+  "location": {
+"character": 5,
+"line": 1,
+"uri": "file://INPUT_DIR/subdir/subdir2/known_file.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "known_num"
+  }
+],
+"title": "known_num"
+  }
+}
+  ]
+}
Index: clang/test/ExtractAPI/known_files_only.c
===
--- /dev/null
+++ clang/test/ExtractAPI/known_files_only.c
@@ -0,0 +1,94 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api --product-name=GlobalRecord -target arm64-apple-macosx \
+// RUN: %t/input1.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Gener

[PATCH] D123148: [clang][extract-api] Process only APIs declared in inputs

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 2 inline comments as done.
dang added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:72
+// primarily to resolve headers found via headermaps, as they remap
+// locations.
+const auto *FileInfo = PP.getHeaderSearchInfo().getExistingFileInfo(File);

cishida wrote:
> How is this searching by the way the header was included? It looks like 
> comparisons are based on file locations as `KnownIncludes` stores file paths. 
Upon second thought and further testing all this stuff isn't needed because we 
always construct the input buffer using `#include "ABSOLUTE_PATH"`. I have 
added a test to validate that this works when using a header map. If we ever 
move to relative includes, then we should change how this to use only include 
string comparisons (potentially caching the FileEntries as a performance 
optimization).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123148

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


[clang-tools-extra] af89e47 - [pseudo] Add crude heuristics to choose taken preprocessor branches.

2022-04-06 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-04-06T17:22:35+02:00
New Revision: af89e4792d23779969c70284dcf6cfafa411637c

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

LOG: [pseudo] Add crude heuristics to choose taken preprocessor branches.

In files where different preprocessing paths are possible, our goal is to
choose a preprocessed token sequence which we can parse that pins down as much
of the grammatical structure as possible.
This forms the "primary parse", and the not-taken branches get parsed later,
and are constrained to be compatible with the primary parse.

Concretely:
  int x =
#ifdef // TAKEN
  2 + 2 + 2 // determined during primary parse to be an expression
#else
  2 // constrained to be an expression during a secondary parse
#endif
;

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

Added: 


Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h
clang-tools-extra/pseudo/include/clang-pseudo/Token.h
clang-tools-extra/pseudo/lib/DirectiveMap.cpp
clang-tools-extra/pseudo/test/lex.c
clang-tools-extra/pseudo/tool/ClangPseudo.cpp
clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h
index 14c752d29040a..67e815e67efdb 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h
@@ -78,6 +78,11 @@ struct DirectiveMap {
 std::vector> Branches;
 /// The directive terminating the conditional, should be #endif.
 Directive End;
+/// The index of the conditional branch we chose as active.
+/// None indicates no branch was taken (e.g. #if 0 ... #endif).
+/// The initial map from of `parse()` has no branches marked as taken.
+/// See `chooseConditionalBranches()`.
+llvm::Optional Taken;
   };
 
   /// Some piece of the file. {One of Code, Directive, Conditional}.
@@ -87,7 +92,6 @@ struct DirectiveMap {
   /// Extract preprocessor structure by examining the raw tokens.
   static DirectiveMap parse(const TokenStream &);
 
-  // FIXME: add heuristically selection of conditional branches.
   // FIXME: allow deriving a preprocessed stream
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DirectiveMap &);
@@ -98,6 +102,24 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &,
 llvm::raw_ostream &operator<<(llvm::raw_ostream &,
   const DirectiveMap::Conditional &);
 
+/// Selects a "taken" branch for each conditional directive in the file.
+///
+/// The choice is somewhat arbitrary, but aims to produce a useful parse:
+///  - idioms like `#if 0` are respected
+///  - we avoid paths that reach `#error`
+///  - we try to maximize the amount of code seen
+/// The choice may also be "no branch taken".
+///
+/// Choices are also made for conditionals themselves inside not-taken 
branches:
+///   #if 1 // taken!
+///   #else // not taken
+///  #if 1 // taken!
+///  #endif
+///   #endif
+///
+/// The choices are stored in Conditional::Taken nodes.
+void chooseConditionalBranches(DirectiveMap &, const TokenStream &Code);
+
 // FIXME: This approximates std::variant.
 // Switch once we can use C++17.
 class DirectiveMap::Chunk {

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Token.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
index 4563477b2c4fe..2bbd598736e6d 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Token.h
@@ -74,6 +74,20 @@ struct Token {
 Flags |= uint8_t{static_cast>(Mask)};
   }
 
+  /// Returns the next token in the stream. this may not be a sentinel.
+  const Token &next() const {
+assert(Kind != tok::eof);
+return *(this + 1);
+  }
+  /// Returns the next token in the stream, skipping over comments.
+  const Token &nextNC() const {
+const Token *T = this;
+do
+  T = &T->next();
+while (T->Kind == tok::comment);
+return *T;
+  }
+
   /// The type of token as determined by clang's lexer.
   clang::tok::TokenKind Kind = clang::tok::unknown;
 };

diff  --git a/clang-tools-extra/pseudo/lib/DirectiveMap.cpp 
b/clang-tools-extra/pseudo/lib/DirectiveMap.cpp
index 6e66708818954..f25231c9b7f28 100644
--- a/clang-tools-extra/pseudo/lib/DirectiveMap.cpp
+++ b/clang-tools-extra/pseudo/lib/DirectiveMap.cpp
@@ -151,10 +151,11 @@ DirectiveMap DirectiveMap::parse(const TokenStream &Code) 
{
 
 static void dump(llvm::raw_ostream &OS, const DirectiveMap &, unsigned Indent);
 static void dump(llvm::raw_ostream &OS,
- const DirectiveMap::Directive &Directive, unsigned Indent) {
- 

[PATCH] D121165: [pseudo] Add crude heuristics to choose taken preprocessor branches.

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/pseudo/lib/DirectiveMap.cpp:329
+const auto &Tokens = Code.tokens(Dir.Tokens);
+if (Tokens.empty() || Tokens.front().Kind != tok::hash)
+  return llvm::None;

hokein wrote:
> I thought the first token of the `Directive` should always be `tok::hash`, 
> isn't it?
Yeah, this was defensive against parsing recovery, but we're sufficiently close 
to the parser that we don't need to be.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121165

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


[PATCH] D121165: [pseudo] Add crude heuristics to choose taken preprocessor branches.

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rGaf89e4792d23: [pseudo] Add crude heuristics to choose taken 
preprocessor branches. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D121165?vs=419142&id=420878#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121165

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h
  clang-tools-extra/pseudo/include/clang-pseudo/Token.h
  clang-tools-extra/pseudo/lib/DirectiveMap.cpp
  clang-tools-extra/pseudo/test/lex.c
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp
  clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp

Index: clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp
===
--- clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp
+++ clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp
@@ -145,6 +145,162 @@
   EXPECT_EQ(0u, X.End.Tokens.size());
 }
 
+TEST(DirectiveMap, ChooseBranches) {
+  LangOptions Opts;
+  const std::string Cases[] = {
+  R"cpp(
+// Branches with no alternatives are taken
+#if COND // TAKEN
+int x;
+#endif
+  )cpp",
+
+  R"cpp(
+// Empty branches are better than nothing
+#if COND // TAKEN
+#endif
+  )cpp",
+
+  R"cpp(
+// Trivially false branches are not taken, even with no alternatives.
+#if 0
+int x;
+#endif
+  )cpp",
+
+  R"cpp(
+// Longer branches are preferred over shorter branches
+#if COND // TAKEN
+int x = 1;
+#else
+int x;
+#endif
+
+#if COND
+int x;
+#else // TAKEN
+int x = 1;
+#endif
+  )cpp",
+
+  R"cpp(
+// Trivially true branches are taken if previous branches are trivial.
+#if 1 // TAKEN
+#else
+  int x = 1;
+#endif
+
+#if 0
+  int x = 1;
+#elif 0
+  int x = 2;
+#elif 1 // TAKEN
+  int x;
+#endif
+
+#if 0
+  int x = 1;
+#elif FOO // TAKEN
+  int x = 2;
+#elif 1
+  int x;
+#endif
+  )cpp",
+
+  R"cpp(
+// #else is a trivially true branch
+#if 0
+  int x = 1;
+#elif 0
+  int x = 2;
+#else // TAKEN
+  int x;
+#endif
+  )cpp",
+
+  R"cpp(
+// Directives break ties, but nondirective text is more important.
+#if FOO
+  #define A 1 2 3
+#else // TAKEN
+  #define B 4 5 6
+  #define C 7 8 9
+#endif
+
+#if FOO // TAKEN
+  ;
+  #define A 1 2 3
+#else
+  #define B 4 5 6
+  #define C 7 8 9
+#endif
+  )cpp",
+
+  R"cpp(
+// Avoid #error directives.
+#if FOO
+  int x = 42;
+  #error This branch is no good
+#else // TAKEN
+#endif
+
+#if FOO
+  // All paths here lead to errors.
+  int x = 42;
+  #if 1 // TAKEN
+#if COND // TAKEN
+  #error This branch is no good
+#else
+  #error This one is no good either
+#endif
+  #endif
+#else // TAKEN
+#endif
+  )cpp",
+
+  R"cpp(
+// Populate taken branches recursively.
+#if FOO // TAKEN
+  int x = 42;
+  #if BAR
+;
+  #else // TAKEN
+int y = 43;
+  #endif
+#else
+  int x;
+  #if BAR // TAKEN
+int y;
+  #else
+;
+  #endif
+#endif
+  )cpp",
+  };
+  for (const auto &Code : Cases) {
+TokenStream S = cook(lex(Code, Opts), Opts);
+
+std::function Verify =
+[&](const DirectiveMap &M) {
+  for (const auto &C : M.Chunks) {
+if (C.kind() != DirectiveMap::Chunk::K_Conditional)
+  continue;
+const DirectiveMap::Conditional &Cond(C);
+for (unsigned I = 0; I < Cond.Branches.size(); ++I) {
+  auto Directive = S.tokens(Cond.Branches[I].first.Tokens);
+  EXPECT_EQ(I == Cond.Taken, Directive.back().text() == "// TAKEN")
+  << "At line " << Directive.front().Line << " of: " << Code;
+  Verify(Cond.Branches[I].second);
+}
+  }
+};
+
+DirectiveMap Map = DirectiveMap::parse(S);
+chooseConditionalBranches(Map, S);
+Verify(Map);
+  }
+}
+
 } // namespace
 } // namespace pseudo
 } // namespace clang
Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/Cla

[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420883.
dang marked an inline comment as done.
dang added a comment.

Make `SymbolGraphSerializer::serializeAPIRecord` const again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123045

Files:
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/enum.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/language.c
  clang/test/ExtractAPI/macro_undefined.c
  clang/test/ExtractAPI/macros.c
  clang/test/ExtractAPI/objc_interface.m
  clang/test/ExtractAPI/objc_protocol.m
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -48,7 +48,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "memberOf",
   "source": "c:@S@Color@FI@Red",
@@ -72,6 +72,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -112,8 +113,10 @@
 "identifier": "c.struct"
   },
   "location": {
-"character": 8,
-"line": 2,
+"position": {
+  "character": 8,
+  "line": 2
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -124,9 +127,13 @@
   }
 ],
 "title": "Color"
-  }
+  },
+  "pathComponents": [
+"Color"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -151,8 +158,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 3,
+"position": {
+  "character": 12,
+  "line": 3
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -163,9 +172,14 @@
   }
 ],
 "title": "Red"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Red"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -190,8 +204,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 4,
+"position": {
+  "character": 12,
+  "line": 4
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -202,9 +218,14 @@
   }
 ],
 "title": "Green"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Green"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -229,8 +250,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 5,
+"position": {
+  "character": 12,
+  "line": 5
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -241,9 +264,14 @@
   }
 ],
 "title": "Blue"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Blue"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -285,8 +313,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 7,
+"position": {
+  "character": 12,
+  "line": 7
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -297,7 +327,11 @@
   }
 ],
 "title": "Alpha"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Alpha"
+  ]
 }
   ]
 }
Index: clang/test/ExtractAPI/objc_protocol.m
===
--- clang/test/ExtractAPI/objc_protocol.m
+++ clang/test/ExtractAPI/objc_protocol.m
@@ -45,7 +45,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "conformsTo",
   "source": "c:objc(pl)AnotherProtocol",
@@ -54,6 +54,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -77,8 +78,10 @@
 "identifier": "objective-c.protocol"
   },
   "location": {
-"character": 11,
-"line": 1,
+"position": {
+  "character": 11,
+  "line": 1
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -89,9 +92,13 @@
   }
 ],
 "title": "Protocol"
-  }
+  },
+  "pathComponents": [
+ 

[PATCH] D123026: [clang][NFC] Extract EmitAssemblyHelper::shouldEmitRegularLTOSummary

2022-04-06 Thread Pavel Samolysov via Phabricator via cfe-commits
psamolysov-intel updated this revision to Diff 420888.
psamolysov-intel retitled this revision from "[clang][NFC] Extract the 
EmitAssemblyHelper::shouldEmitLTOSummary method" to "[clang][NFC] Extract 
EmitAssemblyHelper::shouldEmitRegularLTOSummary".
psamolysov-intel edited the summary of this revision.
psamolysov-intel added a comment.

Thank you @tejohnson I've applied the suggested changes.


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

https://reviews.llvm.org/D123026

Files:
  clang/lib/CodeGen/BackendUtil.cpp


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -164,6 +164,16 @@
   std::unique_ptr &OS,
   std::unique_ptr &DwoOS);
 
+  /// Check whether we should emit a module summary for regular LTO.
+  /// The module summary should be emitted by default for regular LTO
+  /// except for ld64 targets.
+  ///
+  /// \return True if the module summary should be emitted.
+  bool shouldEmitRegularLTOSummary() const {
+return CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
+   TargetTriple.getVendor() != llvm::Triple::Apple;
+  }
+
 public:
   EmitAssemblyHelper(DiagnosticsEngine &_Diags,
  const HeaderSearchOptions &HeaderSearchOpts,
@@ -1054,9 +1064,7 @@
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
-  bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   TargetTriple.getVendor() != llvm::Triple::Apple);
+  bool EmitLTOSummary = shouldEmitRegularLTOSummary();
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
@@ -1064,7 +1072,6 @@
   TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
uint32_t(1));
   }
-
   PerModulePasses.add(createBitcodeWriterPass(
   *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
 }
@@ -1470,9 +1477,7 @@
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
-  bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   TargetTriple.getVendor() != llvm::Triple::Apple);
+  bool EmitLTOSummary = shouldEmitRegularLTOSummary();
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));


Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -164,6 +164,16 @@
   std::unique_ptr &OS,
   std::unique_ptr &DwoOS);
 
+  /// Check whether we should emit a module summary for regular LTO.
+  /// The module summary should be emitted by default for regular LTO
+  /// except for ld64 targets.
+  ///
+  /// \return True if the module summary should be emitted.
+  bool shouldEmitRegularLTOSummary() const {
+return CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
+   TargetTriple.getVendor() != llvm::Triple::Apple;
+  }
+
 public:
   EmitAssemblyHelper(DiagnosticsEngine &_Diags,
  const HeaderSearchOptions &HeaderSearchOpts,
@@ -1054,9 +1064,7 @@
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
-  bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   TargetTriple.getVendor() != llvm::Triple::Apple);
+  bool EmitLTOSummary = shouldEmitRegularLTOSummary();
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
@@ -1064,7 +1072,6 @@
   TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
uint32_t(1));
   }
-
   PerModulePasses.add(createBitcodeWriterPass(
   *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
 }
@@ -1470,9 +1477,7 @@
 } else {
   // Emit a module summary by default for Regular LTO except for ld64
   // targets
-  bool EmitLTOSummary =
-  (CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
-   TargetTriple.getVendor() != llvm::Triple::Apple);
+  bool EmitLTOSummary = shouldEmitRegularLTOSummary();
   if (EmitLTOSummary) {
 if (!TheModule->getModuleFlag("ThinLTO"))
   TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/

[PATCH] D122808: [clang] Fix warnings when `-Wdeprecated-enum-enum-conversion` is enabled

2022-04-06 Thread Antonio Frighetto via Phabricator via cfe-commits
antoniofrighetto updated this revision to Diff 420894.

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

https://reviews.llvm.org/D122808

Files:
  clang/include/clang/AST/DeclarationName.h
  llvm/include/llvm/ADT/STLExtras.h
  llvm/unittests/ADT/STLExtrasTest.cpp

Index: llvm/unittests/ADT/STLExtrasTest.cpp
===
--- llvm/unittests/ADT/STLExtrasTest.cpp
+++ llvm/unittests/ADT/STLExtrasTest.cpp
@@ -989,4 +989,26 @@
   static_assert(!is_contained({1, 2, 3, 4}, 5), "It's not there :(");
 }
 
+TEST(STLExtrasTest, addEnumValues) {
+  enum A { Zero = 0, One = 1 };
+  enum B { IntMax = INT_MAX, ULongLongMax = ULLONG_MAX };
+  enum class C : unsigned { Two = 2 };
+
+  // Non-fixed underlying types, with same underlying types
+  static_assert(addEnumValues(Zero, One) == 1);
+  static_assert(addEnumValues(IntMax, ULongLongMax) ==
+INT_MAX + static_cast(ULLONG_MAX));
+  // Non-fixed underlying types, with different underlying types
+  static_assert(addEnumValues(Zero, IntMax) == INT_MAX);
+  static_assert(addEnumValues(One, ULongLongMax) ==
+1 + static_cast(ULLONG_MAX));
+  // Non-fixed underlying type enum and fixed underlying type enum, with same
+  // underlying types
+  static_assert(addEnumValues(One, C::Two) == 3);
+  // Non-fixed underlying type enum and fixed underlying type enum, with
+  // different underlying types
+  static_assert(addEnumValues(ULongLongMax, C::Two) ==
+static_cast(ULLONG_MAX) + 2);
+}
+
 } // namespace
Index: llvm/include/llvm/ADT/STLExtras.h
===
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -203,6 +203,17 @@
 template 
 using TypeAtIndex = std::tuple_element_t>;
 
+/// Helper which adds two underlying types of enumeration type.
+/// Implicit conversion to a common type is accepted.
+template ::value,
+  std::underlying_type_t>,
+  typename UT2 = std::enable_if_t::value,
+  std::underlying_type_t>>
+constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS) {
+  return static_cast(LHS) + static_cast(RHS);
+}
+
 //===--===//
 // Extra additions to 
 //===--===//
Index: clang/include/clang/AST/DeclarationName.h
===
--- clang/include/clang/AST/DeclarationName.h
+++ clang/include/clang/AST/DeclarationName.h
@@ -21,6 +21,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include 
@@ -192,6 +193,13 @@
 "The various classes that DeclarationName::Ptr can point to"
 " must be at least aligned to 8 bytes!");
 
+  static_assert(
+  std::is_same,
+   std::underlying_type_t<
+   detail::DeclarationNameExtra::ExtraKind>>::value,
+  "The various enums used to compute values for NameKind should "
+  "all have the same underlying type");
+
 public:
   /// The kind of the name stored in this DeclarationName.
   /// The first 7 enumeration values are stored inline and correspond
@@ -205,15 +213,18 @@
 CXXDestructorName = StoredCXXDestructorName,
 CXXConversionFunctionName = StoredCXXConversionFunctionName,
 CXXOperatorName = StoredCXXOperatorName,
-CXXDeductionGuideName = UncommonNameKindOffset +
-detail::DeclarationNameExtra::CXXDeductionGuideName,
-CXXLiteralOperatorName =
-UncommonNameKindOffset +
-detail::DeclarationNameExtra::CXXLiteralOperatorName,
-CXXUsingDirective = UncommonNameKindOffset +
-detail::DeclarationNameExtra::CXXUsingDirective,
-ObjCMultiArgSelector = UncommonNameKindOffset +
-   detail::DeclarationNameExtra::ObjCMultiArgSelector
+CXXDeductionGuideName = llvm::addEnumValues(
+UncommonNameKindOffset,
+detail::DeclarationNameExtra::CXXDeductionGuideName),
+CXXLiteralOperatorName = llvm::addEnumValues(
+UncommonNameKindOffset,
+detail::DeclarationNameExtra::CXXLiteralOperatorName),
+CXXUsingDirective =
+llvm::addEnumValues(UncommonNameKindOffset,
+detail::DeclarationNameExtra::CXXUsingDirective),
+ObjCMultiArgSelector =
+llvm::addEnumValues(UncommonNameKindOffset,
+detail::DeclarationNameExtra::ObjCMultiArgSelector),
   };
 
 private:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122808: [clang] Fix warnings when `-Wdeprecated-enum-enum-conversion` is enabled

2022-04-06 Thread Antonio Frighetto via Phabricator via cfe-commits
antoniofrighetto added a comment.

Fixed the change, and added a new test. Hope the coverage is at a fairly good 
level now!


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

https://reviews.llvm.org/D122808

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


[PATCH] D123229: [clang][deps] Ensure deterministic file names on case-insensitive filesystems

2022-04-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman, akyrtzi.
Herald added a subscriber: mgrang.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The dependency scanner can reuse single FileManager instance across multiple 
translation units. This may lead to non-deterministic output depending on which 
TU gets processed first.

The root cause is the fact that Clang is using DirectoryEntry::getName in the 
header search algorithm. This function returns the path that was first used to 
construct the (shared) entry in FileManager. Using DirectoryEntryRef::getName 
instead preserves the case as it was spelled out for the current "get directory 
entry" request.

rdar://90647508


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123229

Files:
  clang/include/clang/Lex/DirectoryLookup.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/ClangScanDeps/header-search-case-sensitivity.c


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format make -j 
1 | FileCheck %s
+
+// In the reversed case, Clang starts by scanning "t2.c". When looking up the 
"arm/lower.h" header,
+// the string is appended to "DIR/dir2". That file ("DIR/dir2/arm/lower.h") 
doesn't exist, but when
+// learning so, the FileManager stats and caches the parent directory 
("DIR/dir2/arm"), using the
+// UID as the key.
+// When scanning "t1.c" later on, the "DIR/dir2/ARM" search directory is 
assigned the **same**
+// directory entry (with lowercase "arm"), since they share the UID on 
case-insensitive filesystems.
+// To preserve the correct case throughout the compiler for any file within 
that directory, it's
+// important to use the spelling actually used, not just the cached one.
+// RUN: clang-scan-deps -compilation-database=%t/cdb-rev.json -format make -j 
1 | FileCheck %s
+
+// CHECK: ARM/upper.h
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -436,10 +436,10 @@
   SmallString<1024> TmpDir;
   if (isNormalDir()) {
 // Concatenate the requested file onto the directory.
-TmpDir = getDir()->getName();
+TmpDir = getDirRef()->getName();
 llvm::sys::path::append(TmpDir, Filename);
 if (SearchPath) {
-  StringRef SearchPathRef(getDir()->getName());
+  StringRef SearchPathRef(getDirRef()->getName());
   SearchPath->clear();
   SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
 }
Index: clang/include/clang/Lex/DirectoryLookup.h
===
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -91,6 +91,10 @@
 return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
   }
 
+  Optional getDirRef() const {
+return isNormalDir() ? Optional(u.Dir) : None;
+  }
+
   /// getFrameworkDir - Return the directory that this framework refers to.
   ///
   const DirectoryEntry *getFrameworkDir() const {


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json

[PATCH] D123229: [clang][deps] Ensure deterministic file names on case-insensitive filesystems

2022-04-06 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 420905.
jansvoboda11 added a comment.

Finish test description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123229

Files:
  clang/include/clang/Lex/DirectoryLookup.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/ClangScanDeps/header-search-case-sensitivity.c


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that reusing FileManager produces deterministic results on 
case-insensitive filesystems.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format make -j 
1 | FileCheck %s
+
+// In the reversed case, Clang starts by scanning "t2.c". When looking up the 
"arm/lower.h" header,
+// the string is appended to "DIR/dir2". That file ("DIR/dir2/arm/lower.h") 
doesn't exist, but when
+// learning so, the FileManager stats and caches the parent directory 
("DIR/dir2/arm"), using the
+// UID as the key.
+// When scanning "t1.c" later on, the "DIR/dir2/ARM" search directory is 
assigned the **same**
+// directory entry (with lowercase "arm"), since they share the UID on 
case-insensitive filesystems.
+// To preserve the correct case throughout the compiler for any file within 
that directory, it's
+// important to use the spelling actually used, not just the cached one.
+// RUN: clang-scan-deps -compilation-database=%t/cdb-rev.json -format make -j 
1 | FileCheck %s
+
+// CHECK: ARM/upper.h
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -436,10 +436,10 @@
   SmallString<1024> TmpDir;
   if (isNormalDir()) {
 // Concatenate the requested file onto the directory.
-TmpDir = getDir()->getName();
+TmpDir = getDirRef()->getName();
 llvm::sys::path::append(TmpDir, Filename);
 if (SearchPath) {
-  StringRef SearchPathRef(getDir()->getName());
+  StringRef SearchPathRef(getDirRef()->getName());
   SearchPath->clear();
   SearchPath->append(SearchPathRef.begin(), SearchPathRef.end());
 }
Index: clang/include/clang/Lex/DirectoryLookup.h
===
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -91,6 +91,10 @@
 return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
   }
 
+  Optional getDirRef() const {
+return isNormalDir() ? Optional(u.Dir) : None;
+  }
+
   /// getFrameworkDir - Return the directory that this framework refers to.
   ///
   const DirectoryEntry *getFrameworkDir() const {


Index: clang/test/ClangScanDeps/header-search-case-sensitivity.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/header-search-case-sensitivity.c
@@ -0,0 +1,50 @@
+// This test checks that reusing FileManager produces deterministic results on case-insensitive filesystems.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- dir1/arm/lower.h
+//--- dir2/ARM/upper.h
+//--- t1.c
+#include "upper.h"
+//--- t2.c
+#include "arm/lower.h"
+
+//--- cdb.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+}]
+
+//--- cdb-rev.json.template
+[{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t2.c -I DIR/dir2 -I DIR/dir1",
+  "file": "DIR/t2.c"
+},{
+  "directory": "DIR",
+  "command": "clang -fsyntax-only DIR/t1.c -I DIR/dir2/ARM -I DIR/dir1",
+  "file": "DIR/t1.c"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb-rev.json.template > %t/cdb-rev.json
+
+// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format make -j 

[PATCH] D121838: Generalize "check-all" umbrella targets, use for check-clang-tools

2022-04-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> In D121838#3433022 , @kbobyrev 
> wrote:
>
>> I think this is no longer [WIP] but rather review-ready, right?
>
> It's both WIP and review-ready :-)
> There are some mechanical cleanups left to do as mentioned in the comment 
> above, but there's no point doing them if the idea is wrong.

I edited the title to remove the WIP bit so reviewers know. :-)

Can you rebase the patch so that precommit CI can go through the paces?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121838

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


[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2022-04-06 Thread Augie Fackler via Phabricator via cfe-commits
durin42 updated this revision to Diff 420915.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/delete.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/microsoft-abi-structors.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-structors.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-structors.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-structors.cpp
@@ -57,7 +57,7 @@
 //
 // DTORS:  [[CALL_DELETE_LABEL]]
 // DTORS-NEXT:   %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
-// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
+// DTORS-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[THIS_AS_VOID]])
 // DTORS-NEXT:   br label %[[CONTINUE_LABEL]]
 //
 // DTORS:  [[CONTINUE_LABEL]]
@@ -119,7 +119,7 @@
 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
 // CHECK-NEXT:   %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)*, i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
 // CHECK-NEXT:   %[[CALL:.*]] = call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* {{[^,]*}} %[[OBJ_PTR_VALUE]], i32 0)
-// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* %[[CALL]])
+// CHECK-NEXT:   call void @"??3@YAXPAX@Z"(i8* allocptr %[[CALL]])
 // CHECK:  ret void
 }
 
Index: clang/test/CodeGenCXX/exceptions.cpp
===
--- clang/test/CodeGenCXX/exceptions.cpp
+++ clang/test/CodeGenCXX/exceptions.cpp
@@ -37,7 +37,7 @@
 // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
 // CHECK-NEXT: invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 5)
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(5);
   }
 
@@ -48,7 +48,7 @@
 // CHECK-NEXT: [[FOO:%.*]] = invoke i32 @_ZN5test13fooEv()
 // CHECK:  invoke void @_ZN5test11AC1Ei([[A]]* {{[^,]*}} [[CAST]], i32 [[FOO]])
 // CHECK:  ret [[A]]* [[CAST]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 extern int foo();
 return new A(foo());
   }
@@ -74,7 +74,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B().x);
   }
 
@@ -102,7 +102,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B());
   }
 
@@ -128,7 +128,7 @@
 // CHECK:  ret [[A]]* [[CAST]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 return new A(B(), B());
   }
   A *f() {
@@ -165,7 +165,7 @@
 // CHECK:  ret [[A]]* [[RET]]
 // CHECK:  [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
 // CHECK-NEXT: br i1 [[ISACTIVE]]
-// CHECK:  call void @_ZdlPv(i8* [[NEW]])
+// CHECK:  call void @_ZdlPv(i8* allocptr [[NEW]])
 A *x;
 return (x = new A(makeB()), makeB(), x);
   }
@@ -458,7 +458,7 @@
   }
   // CHECK: define{{.*}} {{%.*}}* @_ZN5test94testEv
   // CHECK: [[TEST9_NEW:%.*]] = call noalias nonnull i8* @_Znam
-  // CHECK: call void @_ZdaPv(i8* [[TEST9_NEW]])
+  // CHECK: call void @_ZdaPv(i8* allocptr [[TEST9_NEW]])
 }
 
 // In a destructor with a function-try-block, a return statement in a
Index: clang/test/CodeGenCXX/delete.cpp
===
--- clang/test/CodeGenCXX/delete.cpp
+++ clang/test/CodeGenCXX/delete.cpp
@@ -100,7 +100,7 @@
 // CHECK-NEXT: call void @_ZN5test11AD1Ev([[A]]* {{[^,]*}} [[CUR]])
 // CHECK-NEXT: [[ISDONE:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]]
 // CHECK-NEXT: br i1 [[ISDONE]]
-// CHECK:  call void @_ZdaPv(i8* noundef [[ALLOC]])
+// CHECK:  call void @_ZdaPv(i8* allocptr noundef [[ALLOC]])
   }
 }
 
@@ -146,7 +146,7 @@
 // CHECK-NEXT: [[DTOR:%.*]] = load void ([[X]]*)*, void ([[X]]*)** [[T0]]
 // CHECK-NEXT: call void [[DTOR]]([[X]]* {{[^,]*}} [[OBJ:%.*]])
 //   Call the global operator delete.
-// CHECK-NEXT: call void @_ZdlPv(i8* noundef [[ALLOCATED]]) [[NUW:#[0-9]+

[PATCH] D121838: Generalize "check-all" umbrella targets, use for check-clang-tools

2022-04-06 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

Can you elaborate more on the problem this is solving?  Also, what are the user 
visible changes?  Will check-all and check-clang run the same set of tests as 
before?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121838

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


[PATCH] D121838: Generalize "check-all" umbrella targets, use for check-clang-tools

2022-04-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D121838#3433472 , @tstellar wrote:

> Can you elaborate more on the problem this is solving? Also, what are the 
> user visible changes?

Most directly, check-clang-tools does not currently run clangd or clang-pseudo 
tests, but does after this patch.

More generally, it removes the requirement to intermingle the layout of 
projects (e.g. those under clang-tools-extra) that we want a single `check-*` 
target to cover.

Lit is a monolithic runner that expects to see all tests, manage parallelism 
and failures, and display interactive output.
This means if you want to run all tests in a subdirectory via e.g. ninja, you 
need to define a `check-mydir` target that knows about each lit test suite 
involved.

Examples of this pattern are:

- `check-clang-tools` for `llvm-project/clang-tools-extra/`, today we force the 
tests of each project in this directory into a single test suite directory. 
(`clangd/` and `pseudo/` do not follow this, and so their tests are not run by 
`check-clang-tools`).
- `check-all` for the `llvm-project/` root, today we use global variables to 
keep track of all test suites. This is the mechanism this patch attempts to 
generalize.

> Will check-all and check-clang run the same set of tests as before?

Yes, only check-clang-tools is intended to change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121838

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


[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-06 Thread Zixu Wang via Phabricator via cfe-commits
zixuw accepted this revision.
zixuw added a comment.

Unused include of declaration fragments in SymbolGraphSerializer. Otherwise 
LGTM!




Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:17
 #include "clang/ExtractAPI/API.h"
+#include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/Support/JSON.h"

zixuw wrote:
> Not needed
ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123045

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


[PATCH] D123019: [clang][extract-api] Add support for typedefs

2022-04-06 Thread Zixu Wang via Phabricator via cfe-commits
zixuw accepted this revision.
zixuw added a comment.
This revision is now accepted and ready to land.

LGTM! 🚢


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123019

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


[PATCH] D123235: atomic compare fail : Parser & AST support

2022-04-06 Thread Sunil K via Phabricator via cfe-commits
koops created this revision.
koops added reviewers: dreachem, soumitra, tianshilei1992, cchen.
Herald added a subscriber: arphaman.
Herald added a project: All.
koops requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This is a support for " #pragma atomic compare fail ". It has Parser & AST 
support for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123235

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/atomic_ast_print.cpp
  clang/test/OpenMP/atomic_messages.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -180,6 +180,7 @@
 def OMPC_Update : Clause<"update"> { let clangClass = "OMPUpdateClause"; }
 def OMPC_Capture : Clause<"capture"> { let clangClass = "OMPCaptureClause"; }
 def OMPC_Compare : Clause<"compare"> { let clangClass = "OMPCompareClause"; }
+def OMPC_Fail : Clause<"fail"> { let clangClass = "OMPFailClause"; }
 def OMPC_SeqCst : Clause<"seq_cst"> { let clangClass = "OMPSeqCstClause"; }
 def OMPC_AcqRel : Clause<"acq_rel"> { let clangClass = "OMPAcqRelClause"; }
 def OMPC_Acquire : Clause<"acquire"> { let clangClass = "OMPAcquireClause"; }
@@ -545,7 +546,8 @@
 VersionedClause,
 VersionedClause,
 VersionedClause,
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
 }
 def OMP_Target : Directive<"target"> {
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2281,6 +2281,8 @@
 
 void OMPClauseEnqueue::VisitOMPCompareClause(const OMPCompareClause *) {}
 
+void OMPClauseEnqueue::VisitOMPFailClause(const OMPFailClause *) {}
+
 void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
 
 void OMPClauseEnqueue::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -958,6 +958,24 @@
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
   { v = a; if (a > b) a = b; }
+// expected-error@+1 {{expected 'compare' clause with the 'fail' modifier}}
+#pragma omp atomic fail(seq_cst) 
+  if(v == a) { v = a; }
+// expected-error@+1 {{expected '(' after 'fail'}}
+#pragma omp atomic compare fail
+  if(v < a) { v = a; }
+// expected-error@+1 {{expected a memory order clause}}
+#pragma omp atomic compare fail(capture)
+  if(v < a) { v = a; }
+ // expected-error@+2 {{expected ')' after 'atomic compare fail'}} 
+ // expected-warning@+1 {{extra tokens at the end of '#pragma omp atomic' are ignored}}
+#pragma omp atomic compare fail(seq_cst | acquire)
+  if(v < a) { v = a; }
+// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'fail' clause}}
+#pragma omp atomic compare fail(relaxed) fail(seq_cst)
+  if(v < a) { v = a; }
+
+
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_ast_print.cpp
===
--- clang/test/OpenMP/atomic_ast_print.cpp
+++ clang/test/OpenMP/atomic_ast_print.cpp
@@ -226,6 +226,16 @@
   { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
+#pragma omp atomic compare fail(acq_rel)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare fail(acquire)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare fail(release)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare fail(relaxed)
+  { if (a < c) { a = c; } }
+#pragma omp atomic compare fail(seq_cst)
+  { if (a < c) { a = c; } }
 #endif
   return T();
 }
@@ -1099,6 +1109,16 @@
   { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
+#pragma omp atomic compare fail(acq_rel)
+  if(a < b) { a = b; }
+#pragma omp atomic compare fail(acquire)
+  if(a

[PATCH] D122766: [clang] Use forward slash as the path separator for Windows in __FILE__, __builtin_FILE(), and std::source_location

2022-04-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Normalizing to `\` seems better to me than normalizing to `/` too.

I abstractly like changing as little as necessary at every stage, which in this 
case would mean changing just the slashiness of slashes that clang itself adds, 
so I'm still weakly in favor of that. But I also won't insist on it.

In D122766#3431468 , @dexonsmith 
wrote:

> In D122766#3429552 , @hans wrote:
>
>>> My feeling is that the default behavior on Windows needs to be to use 
>>> backslashes and not forward slashes.
>>
>> Okay, how would folks feel about always canonicalizing `__FILE__` etc. to 
>> use //backslashes// when targeting Windows?
>
> FWIW (I have little Windows experience and no stake in this!), defaulting to 
> backslashes more sense to me. Also seems easy enough to add a preprocessor 
> option to configure this.
>
> I'm curious though, if you're building on POSIX (so the file starts out as 
> POSIX) and targeting Windows, does calling `make_preferred()` actually give 
> you something reasonable in the general case? Or should it be used *only* 
> when there's a hit in `LangOpts.remapPathPrefix()`? Sorry if this has been 
> discussed and rejected; I haven't followed the full thread; feel free to 
> ignore if it's not relevant; but it seems to me that when `-ffile-prefix-map` 
> is NOT being used, then `__FILE__` ought to correspond to the build 
> environment (if anything, it should use `Style::native`).

(We don't use `-ffile-prefix-map`. As 
https://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html 
explains, using it means your commandlines *must* be machine-dependent, which 
we don't want. So we use `-ffile-compilation-dir=.` instead which has the same 
effect but doesn't have that drawback.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122766

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


[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420938.
dang added a comment.

Remove unnecessary include.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123045

Files:
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/enum.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/language.c
  clang/test/ExtractAPI/macro_undefined.c
  clang/test/ExtractAPI/macros.c
  clang/test/ExtractAPI/objc_interface.m
  clang/test/ExtractAPI/objc_protocol.m
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -48,7 +48,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "memberOf",
   "source": "c:@S@Color@FI@Red",
@@ -72,6 +72,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -112,8 +113,10 @@
 "identifier": "c.struct"
   },
   "location": {
-"character": 8,
-"line": 2,
+"position": {
+  "character": 8,
+  "line": 2
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -124,9 +127,13 @@
   }
 ],
 "title": "Color"
-  }
+  },
+  "pathComponents": [
+"Color"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -151,8 +158,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 3,
+"position": {
+  "character": 12,
+  "line": 3
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -163,9 +172,14 @@
   }
 ],
 "title": "Red"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Red"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -190,8 +204,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 4,
+"position": {
+  "character": 12,
+  "line": 4
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -202,9 +218,14 @@
   }
 ],
 "title": "Green"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Green"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -229,8 +250,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 5,
+"position": {
+  "character": 12,
+  "line": 5
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -241,9 +264,14 @@
   }
 ],
 "title": "Blue"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Blue"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -285,8 +313,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 7,
+"position": {
+  "character": 12,
+  "line": 7
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -297,7 +327,11 @@
   }
 ],
 "title": "Alpha"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Alpha"
+  ]
 }
   ]
 }
Index: clang/test/ExtractAPI/objc_protocol.m
===
--- clang/test/ExtractAPI/objc_protocol.m
+++ clang/test/ExtractAPI/objc_protocol.m
@@ -45,7 +45,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "conformsTo",
   "source": "c:objc(pl)AnotherProtocol",
@@ -54,6 +54,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -77,8 +78,10 @@
 "identifier": "objective-c.protocol"
   },
   "location": {
-"character": 11,
-"line": 1,
+"position": {
+  "character": 11,
+  "line": 1
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -89,9 +92,13 @@
   }
 ],
 "title": "Protocol"
-  }
+  },
+  "pathComponents": [
+"Protocol"
+  ]
 },
 {
+  "accessLevel": "public",

[clang] 28d7931 - [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-06 Thread Daniel Grumberg via cfe-commits

Author: Daniel Grumberg
Date: 2022-04-06T18:42:55+01:00
New Revision: 28d793144f2a5c92b83df3cc3d2772ec4cab0ad3

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

LOG: [clang][extract-api] Fix small issues with SymbolGraphSerializer

This includes:
- replacing "relationhips" with "relationships"
- emitting the "pathComponents" property on symbols
- emitting the "accessLevel" property on symbols

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

Added: 


Modified: 
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/test/ExtractAPI/enum.c
clang/test/ExtractAPI/global_record.c
clang/test/ExtractAPI/global_record_multifile.c
clang/test/ExtractAPI/language.c
clang/test/ExtractAPI/macro_undefined.c
clang/test/ExtractAPI/macros.c
clang/test/ExtractAPI/objc_interface.m
clang/test/ExtractAPI/objc_protocol.m
clang/test/ExtractAPI/struct.c

Removed: 




diff  --git 
a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h 
b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
index 02ea9c2e92c83..7b55fd788f6d0 100644
--- a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
+++ b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
@@ -19,6 +19,7 @@
 
 #include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/Serialization/SerializerBase.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/raw_ostream.h"
@@ -45,6 +46,25 @@ class SymbolGraphSerializer : public APISerializer {
   /// The Symbol Graph format version used by this serializer.
   static const VersionTuple FormatVersion;
 
+  using PathComponentStack = llvm::SmallVector;
+  /// The current path component stack.
+  ///
+  /// Note: this is used to serialize the ``pathComponents`` field of symbols 
in
+  /// the Symbol Graph.
+  PathComponentStack PathComponents;
+
+  /// A helper type to manage PathComponents correctly using RAII.
+  struct PathComponentGuard {
+PathComponentGuard(PathComponentStack &PC, StringRef Component) : PC(PC) {
+  PC.emplace_back(Component);
+}
+
+~PathComponentGuard() { PC.pop_back(); }
+
+  private:
+PathComponentStack &PC;
+  };
+
 public:
   /// Serialize the APIs in \c APISet in the Symbol Graph format.
   ///
@@ -126,6 +146,13 @@ class SymbolGraphSerializer : public APISerializer {
   /// Serialize a macro defintion record.
   void serializeMacroDefinitionRecord(const MacroDefinitionRecord &Record);
 
+  /// Push a component to the current path components stack.
+  ///
+  /// \param Component The component to push onto the path components stack.
+  /// \return A PathComponentGuard responsible for removing the latest
+  /// component from the stack on scope exit.
+  LLVM_NODISCARD PathComponentGuard makePathComponentGuard(StringRef 
Component);
+
 public:
   SymbolGraphSerializer(const APISet &API, StringRef ProductName,
 APISerializerOption Options = {})

diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index bfd2c207c0918..1440ca358d4b5 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -90,27 +90,35 @@ Object serializePlatform(const Triple &T) {
   return Platform;
 }
 
+/// Serialize a source position.
+Object serializeSourcePosition(const PresumedLoc &Loc) {
+  assert(Loc.isValid() && "invalid source position");
+
+  Object SourcePosition;
+  SourcePosition["line"] = Loc.getLine();
+  SourcePosition["character"] = Loc.getColumn();
+
+  return SourcePosition;
+}
+
 /// Serialize a source location in file.
 ///
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourcePosition(const PresumedLoc &Loc,
+Object serializeSourceLocation(const PresumedLoc &Loc,
bool IncludeFileURI = false) {
-  assert(Loc.isValid() && "invalid source position");
-
-  Object SourcePosition;
-  SourcePosition["line"] = Loc.getLine();
-  SourcePosition["character"] = Loc.getColumn();
+  Object SourceLocation;
+  serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
 
   if (IncludeFileURI) {
 std::string FileURI = "file://";
 // Normalize file path to use forward slashes for the URI.
 FileURI += sys::path::convert_to_slash(Loc.getFilename());
-SourcePosition["uri"] = FileURI;
+SourceLocation["uri"] = FileURI;
   }
 
-  return SourcePosi

[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-06 Thread Daniel Grumberg 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 rG28d793144f2a: [clang][extract-api] Fix small issues with 
SymbolGraphSerializer (authored by dang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123045

Files:
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/enum.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/language.c
  clang/test/ExtractAPI/macro_undefined.c
  clang/test/ExtractAPI/macros.c
  clang/test/ExtractAPI/objc_interface.m
  clang/test/ExtractAPI/objc_protocol.m
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -48,7 +48,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "memberOf",
   "source": "c:@S@Color@FI@Red",
@@ -72,6 +72,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -112,8 +113,10 @@
 "identifier": "c.struct"
   },
   "location": {
-"character": 8,
-"line": 2,
+"position": {
+  "character": 8,
+  "line": 2
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -124,9 +127,13 @@
   }
 ],
 "title": "Color"
-  }
+  },
+  "pathComponents": [
+"Color"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -151,8 +158,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 3,
+"position": {
+  "character": 12,
+  "line": 3
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -163,9 +172,14 @@
   }
 ],
 "title": "Red"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Red"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -190,8 +204,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 4,
+"position": {
+  "character": 12,
+  "line": 4
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -202,9 +218,14 @@
   }
 ],
 "title": "Green"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Green"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -229,8 +250,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 5,
+"position": {
+  "character": 12,
+  "line": 5
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -241,9 +264,14 @@
   }
 ],
 "title": "Blue"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Blue"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -285,8 +313,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 7,
+"position": {
+  "character": 12,
+  "line": 7
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -297,7 +327,11 @@
   }
 ],
 "title": "Alpha"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Alpha"
+  ]
 }
   ]
 }
Index: clang/test/ExtractAPI/objc_protocol.m
===
--- clang/test/ExtractAPI/objc_protocol.m
+++ clang/test/ExtractAPI/objc_protocol.m
@@ -45,7 +45,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "conformsTo",
   "source": "c:objc(pl)AnotherProtocol",
@@ -54,6 +54,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -77,8 +78,10 @@
 "identifier": "objective-c.protocol"
   },
   "location": {
-"character": 11,
-"line": 1,
+"position": {
+  "character": 11,
+  "line": 1
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -89,9 +92,13 @@
   }

[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122983#3430706 , @erichkeane 
wrote:

> In D122983#3427518 , @xbolva00 
> wrote:
>
>> Could you please check that https://github.com/llvm/llvm-test-suite is 
>> buildable with your patch?
>
> Aaron wasn't able to get this working on his system, but I was.  I ended up 
> collecting the following errors (though, if the build ended early and my 
> workaround of adding the flag failed, i likely missed others):

Thank you for the help with this, Erich!

>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
> MultiSource/Applications/siod/CMakeFiles/siod.dir/slibu.c.o.time 
> /iusers/ekeane1/workspaces/llvm-project2/build/bin/clang -DNDEBUG  -O3   -w 
> -Werror=date-time -D__USE_MISC -D__USE_GNU -D__USE_SVID 
> -D__USE_XOPEN_EXTENDED -D__USE_XOPEN -Dunix -MD -MT 
> MultiSource/Applications/siod/CMakeFiles/siod.dir/slibu.c.o -MF 
> MultiSource/Applications/siod/CMakeFiles/siod.dir/slibu.c.o.d -o 
> MultiSource/Applications/siod/CMakeFiles/siod.dir/slibu.c.o   -c 
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Applications/siod/slibu.c
>   
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Applications/siod/slibu.c:1720:6:
>  error: implicit declaration of function 'strptime' is invalid in C99 and 
> later and unsupported in C2x [-Wimplicit-function-declaration]
>if (strptime(get_c_string(str),get_c_string(fmt),&tm))
>^
>   1 error generated.
>   
>   
>   
>   
>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
> MultiSource/Benchmarks/Prolangs-C/plot2fig/CMakeFiles/plot2fig.dir/fontname.c.o.time
>  /iusers/ekeane1/workspaces/llvm-project2/build/bin/clang -DNDEBUG  -O3   -w 
> -Werror=date-time -MD -MT 
> MultiSource/Benchmarks/Prolangs-C/plot2fig/CMakeFiles/plot2fig.dir/fontname.c.o
>  -MF 
> MultiSource/Benchmarks/Prolangs-C/plot2fig/CMakeFiles/plot2fig.dir/fontname.c.o.d
>  -o 
> MultiSource/Benchmarks/Prolangs-C/plot2fig/CMakeFiles/plot2fig.dir/fontname.c.o
>-c 
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/plot2fig/fontname.c
>   
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/plot2fig/fontname.c:98:18:
>  error: implicit declaration of function 're_comp' is invalid in C99 and 
> later and unsupported in C2x [-Wimplicit-function-declaration]
> res = (char *) re_comp (s);
>^
>   
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/plot2fig/fontname.c:106:7:
>  error: implicit declaration of function 're_exec' is invalid in C99 and 
> later and unsupported in C2x [-Wimplicit-function-declaration]
> if (re_exec("typewriter")
> ^
>   2 errors generated.
>   
>   
>   
>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
> MultiSource/Benchmarks/Prolangs-C/archie-client/CMakeFiles/archie.dir/dirsend.c.o.time
>  /iusers/ekeane1/workspaces/llvm-project2/build/bin/clang -DNDEBUG 
> -I/iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/archie-client
>  -O3   -w -Werror=date-time -MD -MT 
> MultiSource/Benchmarks/Prolangs-C/archie-client/CMakeFiles/archie.dir/dirsend.c.o
>  -MF 
> MultiSource/Benchmarks/Prolangs-C/archie-client/CMakeFiles/archie.dir/dirsend.c.o.d
>  -o 
> MultiSource/Benchmarks/Prolangs-C/archie-client/CMakeFiles/archie.dir/dirsend.c.o
>-c 
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/archie-client/dirsend.c
>   
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/archie-client/dirsend.c:298:17:
>  error: implicit declaration of function 'time' is invalid in C99 and later 
> and unsupported in C2x [-Wimplicit-function-declaration]
>   srand(getpid()+time(0)); /* XXX: arg ok, but not right type. */
>  ^
>   1 error generated.
>   
>   
>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
> MultiSource/Benchmarks/MiBench/office-ispell/CMakeFiles/office-ispell.dir/term.c.o.time
>  /iusers/ekeane1/workspaces/llvm-project2/build/bin/clang -DNDEBUG  -O3   -w 
> -Werror=date-time -Dconst= -MD -MT 
> MultiSource/Benchmarks/MiBench/office-ispell/CMakeFiles/office-ispell.dir/term.c.o
>  -MF 
> MultiSource/Benchmarks/MiBench/office-ispell/CMakeFiles/office-ispell.dir/term.c.o.d
>  -o 
> MultiSource/Benchmarks/MiBench/office-ispell/CMakeFiles/office-ispell.dir/term.c.o
>-c 
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/MiBench/office-ispell/term.c
>   
> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/MiBench/office-ispell/term.c:519:9:
>  error: implicit declaration of function 'wait' is invalid in C99 and later 
> and unsupported in C2x [-Wimplicit-function-declaration]
>   while (wait (&termstat) != i)
>  ^
>   1 error generated.
>   
>   
>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
> SingleSou

[PATCH] D115924: [ConstantFolding] Unify handling of load from uniform value

2022-04-06 Thread Cameron McInally via Phabricator via cfe-commits
cameron.mcinally added inline comments.
Herald added a project: All.



Comment at: llvm/lib/Analysis/ConstantFolding.cpp:722
+  (Ty->isIntOrIntVectorTy() || Ty->isFPOrFPVectorTy()))
+return Constant::getAllOnesValue(Ty);
+  return nullptr;

Sorry for the late comment, but is this legal to do if the src and dest types 
are different sizes? E.g.:

```
%xxx_cast = bitcast i8* %xxx to i1*
store i1 true, i1* %xxx_cast
%yyy = load i8, i8* %xxx
```

In this case, we'll be turning an i1 -1 into an i8 -1, which changes bits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115924

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


[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D122983#3433685 , @aaron.ballman 
wrote:

> In D122983#3430706 , @erichkeane 
> wrote:
>
>> In D122983#3427518 , @xbolva00 
>> wrote:
>>
>>> Could you please check that https://github.com/llvm/llvm-test-suite is 
>>> buildable with your patch?
>>
>> Aaron wasn't able to get this working on his system, but I was.  I ended up 
>> collecting the following errors (though, if the build ended early and my 
>> workaround of adding the flag failed, i likely missed others):
>
> Thank you for the help with this, Erich!
>
>>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
>> MultiSource/Applications/siod/CMakeFiles/siod.dir/slibu.c.o.time 
>> /iusers/ekeane1/workspaces/llvm-project2/build/bin/clang -DNDEBUG  -O3   -w 
>> -Werror=date-time -D__USE_MISC -D__USE_GNU -D__USE_SVID 
>> -D__USE_XOPEN_EXTENDED -D__USE_XOPEN -Dunix -MD -MT 
>> MultiSource/Applications/siod/CMakeFiles/siod.dir/slibu.c.o -MF 
>> MultiSource/Applications/siod/CMakeFiles/siod.dir/slibu.c.o.d -o 
>> MultiSource/Applications/siod/CMakeFiles/siod.dir/slibu.c.o   -c 
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Applications/siod/slibu.c
>>   
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Applications/siod/slibu.c:1720:6:
>>  error: implicit declaration of function 'strptime' is invalid in C99 and 
>> later and unsupported in C2x [-Wimplicit-function-declaration]
>>if (strptime(get_c_string(str),get_c_string(fmt),&tm))
>>^
>>   1 error generated.
>>   
>>   
>>   
>>   
>>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
>> MultiSource/Benchmarks/Prolangs-C/plot2fig/CMakeFiles/plot2fig.dir/fontname.c.o.time
>>  /iusers/ekeane1/workspaces/llvm-project2/build/bin/clang -DNDEBUG  -O3   -w 
>> -Werror=date-time -MD -MT 
>> MultiSource/Benchmarks/Prolangs-C/plot2fig/CMakeFiles/plot2fig.dir/fontname.c.o
>>  -MF 
>> MultiSource/Benchmarks/Prolangs-C/plot2fig/CMakeFiles/plot2fig.dir/fontname.c.o.d
>>  -o 
>> MultiSource/Benchmarks/Prolangs-C/plot2fig/CMakeFiles/plot2fig.dir/fontname.c.o
>>-c 
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/plot2fig/fontname.c
>>   
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/plot2fig/fontname.c:98:18:
>>  error: implicit declaration of function 're_comp' is invalid in C99 and 
>> later and unsupported in C2x [-Wimplicit-function-declaration]
>> res = (char *) re_comp (s);
>>^
>>   
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/plot2fig/fontname.c:106:7:
>>  error: implicit declaration of function 're_exec' is invalid in C99 and 
>> later and unsupported in C2x [-Wimplicit-function-declaration]
>> if (re_exec("typewriter")
>> ^
>>   2 errors generated.
>>   
>>   
>>   
>>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
>> MultiSource/Benchmarks/Prolangs-C/archie-client/CMakeFiles/archie.dir/dirsend.c.o.time
>>  /iusers/ekeane1/workspaces/llvm-project2/build/bin/clang -DNDEBUG 
>> -I/iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/archie-client
>>  -O3   -w -Werror=date-time -MD -MT 
>> MultiSource/Benchmarks/Prolangs-C/archie-client/CMakeFiles/archie.dir/dirsend.c.o
>>  -MF 
>> MultiSource/Benchmarks/Prolangs-C/archie-client/CMakeFiles/archie.dir/dirsend.c.o.d
>>  -o 
>> MultiSource/Benchmarks/Prolangs-C/archie-client/CMakeFiles/archie.dir/dirsend.c.o
>>-c 
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/archie-client/dirsend.c
>>   
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/Prolangs-C/archie-client/dirsend.c:298:17:
>>  error: implicit declaration of function 'time' is invalid in C99 and later 
>> and unsupported in C2x [-Wimplicit-function-declaration]
>>   srand(getpid()+time(0)); /* XXX: arg ok, but not right type. */
>>  ^
>>   1 error generated.
>>   
>>   
>>   /iusers/ekeane1/workspaces/test-suite-build/tools/timeit --summary 
>> MultiSource/Benchmarks/MiBench/office-ispell/CMakeFiles/office-ispell.dir/term.c.o.time
>>  /iusers/ekeane1/workspaces/llvm-project2/build/bin/clang -DNDEBUG  -O3   -w 
>> -Werror=date-time -Dconst= -MD -MT 
>> MultiSource/Benchmarks/MiBench/office-ispell/CMakeFiles/office-ispell.dir/term.c.o
>>  -MF 
>> MultiSource/Benchmarks/MiBench/office-ispell/CMakeFiles/office-ispell.dir/term.c.o.d
>>  -o 
>> MultiSource/Benchmarks/MiBench/office-ispell/CMakeFiles/office-ispell.dir/term.c.o
>>-c 
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/MiBench/office-ispell/term.c
>>   
>> /iusers/ekeane1/workspaces/test-suite/MultiSource/Benchmarks/MiBench/office-ispell/term.c:519:9:
>>  error: implicit declaration of function 'wait' is invalid in C99 and later 
>> and unsupported in C2x [-Wimplicit-function-declara

[PATCH] D123229: [clang][deps] Ensure deterministic file names on case-insensitive filesystems

2022-04-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a reviewer: benlangmuir.
dexonsmith added a subscriber: benlangmuir.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.

Once we've removed the last use of `DirectoryEntry::getName()`, we should drop 
`DirectoryEntry::getName()` to avoid picking up other users. Perhaps 
`DirectoryEntry` itself could be made private to the FileManager.

> The root cause is the fact that Clang is using DirectoryEntry::getName in the 
> header search algorithm. This function returns the path that was first used 
> to construct the (shared) entry in FileManager. Using 
> DirectoryEntryRef::getName instead preserves the case as it was spelled out 
> for the current "get directory entry" request.

For clarity, this is just one of various root causes of FileManager being 
unsound to reuse. Might be good to reword the commit message to avoid implying 
that it's the only one.

The obvious thing is that FileEntry is still used in a few places, especially 
in modules.

The non-obvious thing is that the "redirection hack" in 
`FileManager::getFileRef()`, which deals with a VFS remapping an external name, 
can cause future lookups to succeed that would previously have failed. 
@benlangmuir hit this recently when he was experimenting with NOT sharing the 
FileManager during implicit modules scanning; he can share the sequence of 
steps (I tried just now to remember them but I couldn't work it out).

IMO, we should turn off sharing the FileManager across multiple TUs (except as 
an experimental option) until we actually believe that it's sound. I'm not 
convinced there's a lot of benefit anyway:

- Stat failures need to be cleared between TUs
- Stat successes are cached by the dependency scanning filesystem
- The contents are (mostly? entirely?) bump-ptr allocated since 
https://reviews.llvm.org/D123144


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123229

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


[PATCH] D123144: FileManager: std::map => BumpPtrAllocator + DenseMap of pointers

2022-04-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/lib/Basic/FileManager.cpp:318
   FileEntryRef ReturnedRef(*NamedFileEnt);
-  if (UFE.isValid()) { // Already have an entry with this inode, return it.
+  if (ReusingEntry) { // Already have an entry with this inode, return it.
 

sammccall wrote:
> dexonsmith wrote:
> > I'm trying to figure out why `ReusingEntry` was necessary. It looks to me 
> > like you could just call `UFE->isValid()` here and avoid introducing that 
> > `bool`... or am I missing something?
> You're right, but I think we can get rid of isValid, and plan to send a patch.
> 
> A FileEntry handed out by FileManager always has isValid = true. It's not 
> possible to create a useful FileEntry outside FileManager (and this is never 
> done outside FileManagerTest). So the concept of validity isn't needed.
> 
> (IMO the main cost of having the isValid flag is conceptual complexity - lots 
> of places check it, which means people must be thinking about how to handle 
> this case)
Sure, SGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123144

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


[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122983#3433691 , @erichkeane 
wrote:

> In D122983#3433685 , @aaron.ballman 
> wrote:
>
>> The `-Wimplicit-function-declaration` already exists today, so I believe we 
>> can land the changes you have above to the test suite already today 
>> independent of this patch. Would you be interested in being nerd-sniped into 
>> doing that @erichkeane since you can actually run the tests? (I'm happy to 
>> support you in the work however I can, of course.)
>
> *GRUMBLE GRUMBLE GRUMBLE*.
> Sure, I can get on that in the next day or two.

:-D Thanks, I owe you Yet Another Beer!


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

https://reviews.llvm.org/D122983

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


[PATCH] D123064: [Clang][C++23][WIP] P2071 Named universal character escapes

2022-04-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 420946.
cor3ntin added a comment.

- Typo fixes for invalid code points

Add a method `NearestMatchesForCodepointName` that will return the N closest
valid codepoints, by edit distance.
This is used to detect typos in named escape sequences in literals.

- Address some of Tom's comments:
  - Add test for '\N{ABC'.
  - Handle loose matching of named ucns in identifiers with appropriate 
diagnostics.
  - Fix detection of the difference betwen empty and incomplete named escape 
sequences.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/ADT/StringExtras.h
  llvm/include/llvm/Support/ScopedPrinter.h
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/ScopedPrinter.cpp
  llvm/lib/Support/StringExtras.cpp
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D123155: [analyzer] Expose Taint.h to plugins

2022-04-06 Thread Tom Ritter via Phabricator via cfe-commits
tomrittervg added a comment.

Just a note - I was able to test this finally and it works for what I was 
trying to do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123155

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


[PATCH] D123085: CGExprCXX: emit allocptr attributes for operator delete

2022-04-06 Thread Augie Fackler via Phabricator via cfe-commits
durin42 planned changes to this revision.
durin42 added a comment.

I'll hold off on this one until the other LLVM patches are done, then mail out 
the clang work as its own logical unit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123085

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


[PATCH] D123019: [clang][extract-api] Add support for typedefs

2022-04-06 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420950.
dang added a comment.

Rebase on top of latest changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123019

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h
  clang/test/ExtractAPI/typedef.c
  clang/test/ExtractAPI/typedef_anonymous_record.c
  clang/test/ExtractAPI/typedef_chain.c

Index: clang/test/ExtractAPI/typedef_chain.c
===
--- /dev/null
+++ clang/test/ExtractAPI/typedef_chain.c
@@ -0,0 +1,211 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api --product-name=TypedefChain -target arm64-apple-macosx \
+// RUN: -x objective-c-header %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+typedef int MyInt;
+typedef MyInt MyIntInt;
+typedef MyIntInt MyIntIntInt;
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "TypedefChain",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyInt"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:input.h@T@MyInt"
+  },
+  "kind": {
+"displayName": "Type Alias",
+"identifier": "objective-c.typealias"
+  },
+  "location": {
+"position": {
+  "character": 13,
+  "line": 1
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyInt"
+  }
+],
+"title": "MyInt"
+  },
+  "pathComponents": [
+"MyInt"
+  ],
+  "type": "c:I"
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:input.h@T@MyInt",
+  "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyIntInt"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:input.h@T@MyIntInt"
+  },
+  "kind": {
+"displayName": "Type Alias",
+"identifier": "objective-c.typealias"
+  },
+  "location": {
+"position": {
+  "character": 15,
+  "line": 2
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyIntInt"
+  }
+],
+"title": "MyIntInt"
+  },
+  "pathComponents": [
+"MyIntInt"
+  ],
+  "type": "c:input.h@T@MyInt"
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "

[PATCH] D123197: Remove a few effectively-unused FileEntry APIs. NFC

2022-04-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

> The ugly part here:
>
> - FileEntryTest was constructing dummy FileEntrys to wrap in FileEntryRef
> - I changed this to use a FileManager as a factory

It's not clear *why* you changed this to use a FileManager as a factory. It 
seems unrelated to removing `FileEntry::isValid()` (but maybe I'm missing 
something obvious). It also doesn't seem like an improvement for the test, 
since FileManager is full of hacks and twisted logic that's hard to reason 
about, and it's useful to test FileEntry / FileEntryRef / etc. in isolation of 
that.

Depending on the goal, maybe instead we could abstract out some lower-level 
API, FileManagerBase or FileEntryFactory or something, which both FileEntryTest 
and FileManager use.




Comment at: clang/unittests/Basic/FileEntryTest.cpp:47-52
   FileEntryRef addFile(StringRef Name) {
-FEs.push_back(std::make_unique());
+const FileEntry *FE =
+FM.getVirtualFile(std::to_string(UniqueNameCounter++), 0, 0);
 return FileEntryRef(
-*Files.insert({Name, FileEntryRef::MapValue(*FEs.back().get(), DR)})
- .first);
+*Files.try_emplace(Name, FileEntryRef::MapValue(*FE, DR)).first);
   }

I don't love this from a layering perspective. FileEntryTest is testing the 
low-level pieces that are used inside FileManager... using FileManager to 
generate the FileEntries is awkward.

Maybe it'd be okay if `FileManager::getVirtualFile()` were trivial, but it's 
not.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123197

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


[PATCH] D122885: [clang] Draft: Implement P1703R1

2022-04-06 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan requested changes to this revision.
urnathan added a comment.
This revision now requires changes to proceed.

Either update this when you're ready, or abandon and create a new one for 1857.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122885

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


[clang] 482fad4 - [clang][DOC] Document module mangler changes

2022-04-06 Thread Nathan Sidwell via cfe-commits

Author: Nathan Sidwell
Date: 2022-04-06T11:13:32-07:00
New Revision: 482fad4a3fcb013aa19e97661e3d66583d026bb8

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

LOG: [clang][DOC] Document module mangler changes

Note that the mangling has changed and the demangler's learnt a new
trick.  Obviously dependent upon the mangler and demangler patches.

Reviewed By: bruno

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bf592329ac02a..df6a7d7539ee6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -201,6 +201,13 @@ C++20 Feature Support
 
 - Implemented `__builtin_source_location()` which enables library support for 
std::source_location.
 
+- The mangling scheme for C++20 modules has incompatibly changed. The
+  initial mangling was discovered not to be reversible, and the weak
+  ownership design decision did not give the backwards compatibility
+  that was hoped for. C++20 since added ``extern "C++"`` semantics
+  that can be used for such compatibility. The demangler now demangles
+  symbols with named module attachment.
+
 C++2b Feature Support
 ^
 



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


  1   2   >