[PATCH] D94844: [VFS] Add support to RedirectingFileSystem for mapping a virtual directory to one in the external FS.

2021-01-21 Thread Nathan Hawes via Phabricator via cfe-commits
nathawes planned changes to this revision.
nathawes added a comment.

Thanks for reviewing @dexonsmith!

> I don't see a test for a case where the mapped directory already exists in 
> the external FS ... Unless I just missed it, can you add one?

I believe the `clang/test/VFS/directory.c` regression test covers that case. In 
that one the real file system is initially set up as follows:

  %t/Underlying/
  C.h
  B.h
  %t/Middle
  C.h
  %t/Overlay
  C.h

And it then sets up vfs overlay yaml files with fallthrough set true that 
redirect Underlying -> Overlay, or Underlying -> Middle and Middle -> Overlay, 
as specified on the numbered lines in the test (e.g. `// 1) Underlying -> 
Overlay`).

> My intuition is we'd want to overlay the directory contents, not replace them

I think it behaves as you expect (as an overlay, rather than replacement) when 
fallthrough is set to true. You can see that happening in first case in the 
same test (`clang/test/VFS/directory.c`). It has the real file system set up as 
above and creates a vfs yaml file that maps `%t/Underlying` to `%t/Overlay` in 
the external/real file system with fallthrough set true. It invokes clang 
passing that overlay file, an include path of `%t/Underlying`, and a source 
file that includes both C.h and B.h,  and checks that it finds the C.h from 
Overlay (after redirecting Underlying -> Overlay) and B.h from Underlying 
(after redirecting Underlying -> Overlay, not finding it, and falling back to 
the original path in the underlying file system).

I really should have a unit test showing the directory iterator output 
directly, though. That makes the overlay behavior much more obvious.


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

https://reviews.llvm.org/D94844

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


[PATCH] D94786: [clang][ASTImporter] Add support for importing CXXFoldExpr.

2021-01-21 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:642-649
+const internal::VariadicDynCastAllOfMatcher cxxFoldExpr;
+
+AST_MATCHER_P(CXXFoldExpr, hasOperator, BinaryOperatorKind, Op) {
+  return Node.getOperator() == Op;
+}
+AST_MATCHER(CXXFoldExpr, hasInit) { return Node.getInit(); }
+AST_MATCHER(CXXFoldExpr, isRightFold) { return Node.isRightFold(); }

balazske wrote:
> martong wrote:
> > Perhaps we could add this directly to ASTMatchers.h ?
> It would make sense, `CXXFoldExpr` could be needed by other users.
But I plan to commit this as is, there are other matchers in this file that 
could be put into **ASTMatchers.h**, it should be checked why these are not 
there and which ones to put into the header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94786

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


[PATCH] D95168: Add InsertBraces option

2021-01-21 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

True, I was aware of the presence of some of these options, thank you for 
indicating others. I'm not yet entirely convinced, especially that clang-tidy 
behaviour would be possibly different.

Anyway, a few comments just from the first glance.




Comment at: clang/docs/ClangFormatStyleOptions.rst:2254
+
+  * ``BIS_WrapLikely`` (in configuration: ``WrapLikely``)
+Insert braces if wrapping is likely

Shouldn't it be consistent with clang-tidy? So instead of an enum, this option 
might take a number of lines that will trigger brace insertion? None may be sth 
like -1. "Likely" is very vague.



Comment at: clang/lib/Format/Format.cpp:1680
+
+  // Get first token that is not a comment
+  const FormatToken *FirstTok = Line->First;

Nit: put full stop at the end of the comments.



Comment at: clang/lib/Format/Format.cpp:1694
+
+  // if the previous line starte a ctrl flow block and this line does not
+  // start with curly

And make the comments full phrases, starting with a capital letter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2021-01-21 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet added a comment.

> I may be over-reacting to the way the patch seemed to be touching on the C++ 
> ABI in multiple places.  My understanding is that `ms_abi` is just a 
> calling-convention attribute; it's basically "use the (default) calling 
> convention that MSVC would use for this function".  If that's all you want, 
> then this is reasonable, although I am worried about creating a new attribute 
> for every system that Wine chooses to target.

I literally based this patch on how ms_abi was implemented. It's unfortunately 
more than just teaching clang to change the calling convention on LLVM IR 
functions. The fact that ABI implementations are spread all over the place 
between various places in LLVM is, as far as I remember, a known problem 
discussed many times on llvm-dev, and looks like a hard one to fix.

> About "darwin": technically, every Apple platform has a different ABI.  Our 
> current ARM64 platforms do all agree about things like the calling 
> convention, at least if you count newer watches (which use a 32-on-64 ABI in 
> userspace) as not ARM64.  That is not true of other architectures, most 
> notably on ARM32, where the 32-bit iOS ABI is very different from the armv7k 
> Apple Watch ABI; and it is certainly conceivable that Apple might release a 
> new ARM64 platform in the future with a different calling convention.  The 
> more technically correct and future-proof thing would be to use the OS name 
> (or maybe even the triple!) in the attribute, probably as an argument to the 
> attribute, like `__attribute__((target_abi("arm64-apple-ios")))`.

I'm a bit afraid that `__attribute__((target_abi(XX)))` would conflict with the 
existing `__attribute__((ms_abi))`. Maybe, not to conflict with the MS ABI 
implementation, we could introduce `__attribute__((darwin_abi("arm64-ios")))` 
(and arm64-tvos, arm64-osx, ...)?

About Apple that would create as much ABIs as products, I guess we have a 
living example: is the ABI for OSX/ARM64 different than the ABI for iOS/ARM64? 
I can't seem find any official documentation about this :/ (only talking about 
arm64 here, but I get your points about armv7 targets).

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[PATCH] D95206: [clangd][SwapIndex] ensure that the old index is alive while we are using it via the function returned by `SwapIndex::indexedFiles()` call

2021-01-21 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX created this revision.
ArcsinX added reviewers: sammccall, kadircet.
Herald added subscribers: usaxena95, arphaman.
ArcsinX requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Without this patch the old index could be freed, but there still could be tries 
to access it via the function returned by `SwapIndex::indexedFiles()` call.
This leads to hard to reproduce clangd crashes at code completion.
This patch keeps the old index alive until the function returned by 
`SwapIndex::indexedFiles()` call is alive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95206

Files:
  clang-tools-extra/clangd/index/Index.cpp
  clang-tools-extra/clangd/index/Merge.cpp


Index: clang-tools-extra/clangd/index/Merge.cpp
===
--- clang-tools-extra/clangd/index/Merge.cpp
+++ clang-tools-extra/clangd/index/Merge.cpp
@@ -44,21 +44,23 @@
   SymbolSlab Dyn = std::move(DynB).build();
 
   llvm::DenseSet SeenDynamicSymbols;
-  auto DynamicContainsFile = Dynamic->indexedFiles();
-  More |= Static->fuzzyFind(Req, [&](const Symbol ) {
-// We expect the definition to see the canonical declaration, so it seems
-// to be enough to check only the definition if it exists.
-if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
- : S.CanonicalDeclaration.FileURI))
-  return;
-auto DynS = Dyn.find(S.ID);
-++StaticCount;
-if (DynS == Dyn.end())
-  return Callback(S);
-++MergedCount;
-SeenDynamicSymbols.insert(S.ID);
-Callback(mergeSymbol(*DynS, S));
-  });
+  {
+auto DynamicContainsFile = Dynamic->indexedFiles();
+More |= Static->fuzzyFind(Req, [&](const Symbol ) {
+  // We expect the definition to see the canonical declaration, so it seems
+  // to be enough to check only the definition if it exists.
+  if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
+   : S.CanonicalDeclaration.FileURI))
+return;
+  auto DynS = Dyn.find(S.ID);
+  ++StaticCount;
+  if (DynS == Dyn.end())
+return Callback(S);
+  ++MergedCount;
+  SeenDynamicSymbols.insert(S.ID);
+  Callback(mergeSymbol(*DynS, S));
+});
+  }
   SPAN_ATTACH(Tracer, "dynamic", DynamicCount);
   SPAN_ATTACH(Tracer, "static", StaticCount);
   SPAN_ATTACH(Tracer, "merged", MergedCount);
@@ -77,20 +79,22 @@
   Dynamic->lookup(Req, [&](const Symbol ) { B.insert(S); });
 
   auto RemainingIDs = Req.IDs;
-  auto DynamicContainsFile = Dynamic->indexedFiles();
-  Static->lookup(Req, [&](const Symbol ) {
-// We expect the definition to see the canonical declaration, so it seems
-// to be enough to check only the definition if it exists.
-if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
- : S.CanonicalDeclaration.FileURI))
-  return;
-const Symbol *Sym = B.find(S.ID);
-RemainingIDs.erase(S.ID);
-if (!Sym)
-  Callback(S);
-else
-  Callback(mergeSymbol(*Sym, S));
-  });
+  {
+auto DynamicContainsFile = Dynamic->indexedFiles();
+Static->lookup(Req, [&](const Symbol ) {
+  // We expect the definition to see the canonical declaration, so it seems
+  // to be enough to check only the definition if it exists.
+  if (DynamicContainsFile(S.Definition ? S.Definition.FileURI
+   : S.CanonicalDeclaration.FileURI))
+return;
+  const Symbol *Sym = B.find(S.ID);
+  RemainingIDs.erase(S.ID);
+  if (!Sym)
+Callback(S);
+  else
+Callback(mergeSymbol(*Sym, S));
+});
+  }
   for (const auto  : RemainingIDs)
 if (const Symbol *Sym = B.find(ID))
   Callback(*Sym);
Index: clang-tools-extra/clangd/index/Index.cpp
===
--- clang-tools-extra/clangd/index/Index.cpp
+++ clang-tools-extra/clangd/index/Index.cpp
@@ -78,7 +78,10 @@
 
 llvm::unique_function
 SwapIndex::indexedFiles() const {
-  return snapshot()->indexedFiles();
+  return [ KeepAlive = snapshot(),
+   IndexedFiles = snapshot()->indexedFiles() ](llvm::StringRef File) {
+return IndexedFiles(File);
+  };
 }
 
 size_t SwapIndex::estimateMemoryUsage() const {


Index: clang-tools-extra/clangd/index/Merge.cpp
===
--- clang-tools-extra/clangd/index/Merge.cpp
+++ clang-tools-extra/clangd/index/Merge.cpp
@@ -44,21 +44,23 @@
   SymbolSlab Dyn = std::move(DynB).build();
 
   llvm::DenseSet SeenDynamicSymbols;
-  auto DynamicContainsFile = Dynamic->indexedFiles();
-  More |= Static->fuzzyFind(Req, [&](const Symbol ) {
-// We expect the definition to see the canonical declaration, so it seems
-// to be enough to check only the definition if it exists.
-if 

[PATCH] D95204: [lld-macho] switch default to new Darwin port

2021-01-21 Thread Greg McGary via Phabricator via cfe-commits
gkm created this revision.
gkm added a reviewer: lld-macho.
Herald added subscribers: pengfei, steven_wu, hiraditya, kristof.beyls, mgorny.
gkm requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, aheejin.
Herald added projects: clang, LLVM.

In advance of the LLVM 12 branch cut, replace the old Darwin port with the new.

We have achieved self-hosting for the X86_64 target, where all tests pass when 
building lld with itself on macOS.

The ARM64 target has not yet self-hostable and is in the debugging phase.

See annoucement email:
[llvm-dev] Making ld64.lld default to the new Mach-O port
https://lists.llvm.org/pipermail/llvm-dev/2021-January/147665.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95204

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/darwin-ld-demangle-lld.c
  clang/test/Driver/darwin-ld-platform-version-ios.c
  clang/test/Driver/darwin-ld-platform-version-macos.c
  clang/test/Driver/darwin-ld-platform-version-tvos.c
  clang/test/Driver/darwin-ld-platform-version-watchos.c
  lld/test/MachO/invalid/stub-link.s
  lld/test/MachO/lit.local.cfg
  lld/test/MachO/search-paths-darwin.test
  lld/test/MachO/syslibroot.test
  lld/test/darwin/cmdline-lto_library.objtxt
  lld/test/darwin/cmdline-objc_gc.objtxt
  lld/test/darwin/cmdline-objc_gc_compaction.objtxt
  lld/test/darwin/cmdline-objc_gc_only.objtxt
  lld/test/darwin/native-and-mach-o.objtxt
  lld/test/mach-o/Inputs/swift-version-1.yaml
  lld/test/mach-o/Inputs/wrong-arch-error.yaml
  lld/test/mach-o/PIE.yaml
  lld/test/mach-o/align_text.yaml
  lld/test/mach-o/arm-interworking-movw.yaml
  lld/test/mach-o/arm-interworking.yaml
  lld/test/mach-o/arm-shims.yaml
  lld/test/mach-o/arm-subsections-via-symbols.yaml
  lld/test/mach-o/arm64-reloc-negDelta32-fixup.yaml
  lld/test/mach-o/arm64-relocs-errors-delta64-offset.yaml
  lld/test/mach-o/arm64-section-order.yaml
  lld/test/mach-o/bind-opcodes.yaml
  lld/test/mach-o/cstring-sections.yaml
  lld/test/mach-o/data-in-code-load-command.yaml
  lld/test/mach-o/data-only-dylib.yaml
  lld/test/mach-o/dead-strip-globals.yaml
  lld/test/mach-o/debug-syms.yaml
  lld/test/mach-o/demangle.yaml
  lld/test/mach-o/dependency_info.yaml
  lld/test/mach-o/do-not-emit-unwind-fde-arm64.yaml
  lld/test/mach-o/dso_handle.yaml
  lld/test/mach-o/dylib-install-names.yaml
  lld/test/mach-o/eh-frame-relocs-arm64.yaml
  lld/test/mach-o/empty-sections.yaml
  lld/test/mach-o/error-simulator-vs-macosx.yaml
  lld/test/mach-o/exe-offsets.yaml
  lld/test/mach-o/exe-segment-overlap.yaml
  lld/test/mach-o/executable-exports.yaml
  lld/test/mach-o/export-trie-order.yaml
  lld/test/mach-o/exported_symbols_list-dylib.yaml
  lld/test/mach-o/exported_symbols_list-obj.yaml
  lld/test/mach-o/exported_symbols_list-undef.yaml
  lld/test/mach-o/fat-archive.yaml
  lld/test/mach-o/filelist.yaml
  lld/test/mach-o/flat_namespace_undef_error.yaml
  lld/test/mach-o/flat_namespace_undef_suppress.yaml
  lld/test/mach-o/force_load-dylib.yaml
  lld/test/mach-o/force_load-x86_64.yaml
  lld/test/mach-o/framework-user-paths.yaml
  lld/test/mach-o/function-starts-load-command.yaml
  lld/test/mach-o/gcc_except_tab-got-arm64.yaml
  lld/test/mach-o/got-order.yaml
  lld/test/mach-o/hello-world-arm64.yaml
  lld/test/mach-o/hello-world-armv6.yaml
  lld/test/mach-o/hello-world-armv7.yaml
  lld/test/mach-o/hello-world-x86.yaml
  lld/test/mach-o/hello-world-x86_64.yaml
  lld/test/mach-o/image-base.yaml
  lld/test/mach-o/infer-arch.yaml
  lld/test/mach-o/interposing-section.yaml
  lld/test/mach-o/keep_private_externs.yaml
  lld/test/mach-o/lazy-bind-x86_64.yaml
  lld/test/mach-o/lc_segment_filesize.yaml
  lld/test/mach-o/lib-search-paths.yaml
  lld/test/mach-o/library-order.yaml
  lld/test/mach-o/library-rescan.yaml
  lld/test/mach-o/libresolve-bizarre-root-override.yaml
  lld/test/mach-o/libresolve-multiple-syslibroots.yaml
  lld/test/mach-o/libresolve-one-syslibroot.yaml
  lld/test/mach-o/libresolve-simple.yaml
  lld/test/mach-o/libresolve-user-paths.yaml
  lld/test/mach-o/libresolve-z.yaml
  lld/test/mach-o/load-commands-size.yaml
  lld/test/mach-o/mach_header-cpusubtype.yaml
  lld/test/mach-o/mh_bundle_header.yaml
  lld/test/mach-o/mh_dylib_header.yaml
  lld/test/mach-o/objc-category-list-atom.yaml
  lld/test/mach-o/objc-image-info-host-vs-simulator.yaml
  lld/test/mach-o/objc-image-info-invalid-size.yaml
  lld/test/mach-o/objc-image-info-invalid-version.yaml
  lld/test/mach-o/objc-image-info-mismatched-swift-version.yaml
  lld/test/mach-o/objc-image-info-pass-output.yaml
  lld/test/mach-o/objc-image-info-simulator-vs-host.yaml
  lld/test/mach-o/objc-image-info-unsupported-gc.yaml
  lld/test/mach-o/objc_export_list.yaml
  lld/test/mach-o/order_file-basic.yaml
  lld/test/mach-o/parse-aliases.yaml
  lld/test/mach-o/parse-arm-relocs.yaml
  lld/test/mach-o/parse-cfstring32.yaml
  lld/test/mach-o/parse-cfstring64.yaml
  lld/test/mach-o/parse-compact-unwind32.yaml
  

[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-01-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 318420.
nullptr.cpp added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1203,6 +1203,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+  More implicit moves
+  https://wg21.link/p1825r0;>P1825R0 (DR)
+  Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,12 +1,17 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
 
 // definitions for std::move
 namespace std {
 inline namespace foo {
 template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
 
 template  typename remove_reference::type &(T &);
 } // namespace foo
@@ -76,11 +81,8 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
-Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+  Derived d3;
+  return d3; // ok
 }
 ConstructFromBase test4() {
 Derived d4;
@@ -153,10 +155,7 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
 }
 ConstructFromDerived testParam3(Derived d) {
-return d;  // e7-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
+  return d; // ok
 }
 ConstructFromBase testParam4(Derived d) {
 return d;  // e8
@@ -218,8 +217,10 @@
 // But if the return type is a reference type, then moving would be wrong.
 Derived& testRetRef1(Derived&& d) { return d; }
 Base& testRetRef2(Derived&& d) { return d; }
+#if __cplusplus >= 201402L
 auto&& testRetRef3(Derived&& d) { return d; }
 decltype(auto) testRetRef4(Derived&& d) { return (d); }
+#endif
 
 // As long as we're checking parentheses, make sure parentheses don't disable the warning.
 Base testParens1() {
@@ -230,14 +231,10 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
 }
 ConstructFromDerived testParens2() {
-Derived d;
-return (d);  // e18-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
+  Derived d;
+  return (d); // ok
 }
 
-
 // If the target is a catch-handler parameter, do apply the diagnostic.
 void throw_derived();
 Derived testEParam1() {
@@ -339,7 +336,7 @@
 namespace test_delete {
 struct Base {
   Base();
-  Base(Base &&) = delete;
+  Base(Base &&) = delete; // cxx20-note {{'Base' has been explicitly marked deleted here}}
   Base(Base const &);
 };
 
@@ -347,6 +344,6 @@
 
 Base 

[PATCH] D95202: ADT: Use 'using' to inherit assign and append in SmallString

2021-01-21 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith created this revision.
dexonsmith added a reviewer: dblaikie.
Herald added subscribers: ributzka, hiraditya.
dexonsmith requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

Rather than reimplement, use a `using` declaration to bring in
`SmallVectorImpl`'s assign and append implementations in
`SmallString`.

The `SmallString` versions were missing reference invalidation
assertions from `SmallVector`. This patch also fixes a bug in
`llvm::FileCollector::addFileImpl`, which was a copy/paste from
`clang::ModuleDependencyCollector::copyToRoot`, both caught by the
no-longer-skipped assertions.

As a drive-by, this also sinks the `const SmallVectorImpl&` versions of
these methods down into `SmallVectorImpl`, since I imagine they'd be
useful elsewhere.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95202

Files:
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  llvm/include/llvm/ADT/SmallString.h
  llvm/include/llvm/ADT/SmallVector.h
  llvm/lib/Support/FileCollector.cpp
  llvm/unittests/ADT/SmallVectorTest.cpp

Index: llvm/unittests/ADT/SmallVectorTest.cpp
===
--- llvm/unittests/ADT/SmallVectorTest.cpp
+++ llvm/unittests/ADT/SmallVectorTest.cpp
@@ -485,6 +485,15 @@
   this->assertValuesInOrder(this->theVector, 3u, 1, 7, 7);
 }
 
+TYPED_TEST(SmallVectorTest, AppendSmallVector) {
+  SCOPED_TRACE("AppendSmallVector");
+
+  SmallVector otherVector = { 7, 7 };
+  this->theVector.push_back(Constructable(1));
+  this->theVector.append(otherVector);
+  this->assertValuesInOrder(this->theVector, 3u, 1, 7, 7);
+}
+
 // Assign test
 TYPED_TEST(SmallVectorTest, AssignTest) {
   SCOPED_TRACE("AssignTest");
@@ -513,6 +522,15 @@
   this->assertValuesInOrder(this->theVector, 2u, 7, 7);
 }
 
+TYPED_TEST(SmallVectorTest, AssignSmallVector) {
+  SCOPED_TRACE("AssignSmallVector");
+
+  SmallVector otherVector = { 7, 7 };
+  this->theVector.push_back(Constructable(1));
+  this->theVector.assign(otherVector);
+  this->assertValuesInOrder(this->theVector, 2u, 7, 7);
+}
+
 // Move-assign test
 TYPED_TEST(SmallVectorTest, MoveAssignTest) {
   SCOPED_TRACE("MoveAssignTest");
Index: llvm/lib/Support/FileCollector.cpp
===
--- llvm/lib/Support/FileCollector.cpp
+++ llvm/lib/Support/FileCollector.cpp
@@ -86,7 +86,11 @@
   sys::path::native(AbsoluteSrc);
 
   // Remove redundant leading "./" pieces and consecutive separators.
-  AbsoluteSrc = sys::path::remove_leading_dotslash(AbsoluteSrc);
+  {
+StringRef DroppedDotSlash = sys::path::remove_leading_dotslash(AbsoluteSrc);
+if (DroppedDotSlash.begin() != AbsoluteSrc.begin())
+  AbsoluteSrc.erase(AbsoluteSrc.begin(), DroppedDotSlash.begin());
+  }
 
   // Canonicalize the source path by removing "..", "." components.
   SmallString<256> VirtualPath = AbsoluteSrc;
Index: llvm/include/llvm/ADT/SmallVector.h
===
--- llvm/include/llvm/ADT/SmallVector.h
+++ llvm/include/llvm/ADT/SmallVector.h
@@ -664,6 +664,8 @@
 append(IL.begin(), IL.end());
   }
 
+  void append(const SmallVectorImpl ) { append(RHS.begin(), RHS.end()); }
+
   void assign(size_type NumElts, ValueParamT Elt) {
 // Note that Elt could be an internal reference.
 if (NumElts > this->capacity()) {
@@ -698,6 +700,8 @@
 append(IL);
   }
 
+  void assign(const SmallVectorImpl ) { assign(RHS.begin(), RHS.end()); }
+
   iterator erase(const_iterator CI) {
 // Just cast away constness because this is a non-const member function.
 iterator I = const_cast(CI);
Index: llvm/include/llvm/ADT/SmallString.h
===
--- llvm/include/llvm/ADT/SmallString.h
+++ llvm/include/llvm/ADT/SmallString.h
@@ -40,35 +40,15 @@
   template
   SmallString(ItTy S, ItTy E) : SmallVector(S, E) {}
 
-  // Note that in order to add new overloads for append & assign, we have to
-  // duplicate the inherited versions so as not to inadvertently hide them.
-
   /// @}
   /// @name String Assignment
   /// @{
 
-  /// Assign from a repeated element.
-  void assign(size_t NumElts, char Elt) {
-this->SmallVectorImpl::assign(NumElts, Elt);
-  }
-
-  /// Assign from an iterator pair.
-  template
-  void assign(in_iter S, in_iter E) {
-this->clear();
-SmallVectorImpl::append(S, E);
-  }
+  using SmallVector::assign;
 
   /// Assign from a StringRef.
   void assign(StringRef RHS) {
-this->clear();
-SmallVectorImpl::append(RHS.begin(), RHS.end());
-  }
-
-  /// Assign from a SmallVector.
-  void assign(const SmallVectorImpl ) {
-this->clear();
-SmallVectorImpl::append(RHS.begin(), RHS.end());
+SmallVectorImpl::assign(RHS.begin(), RHS.end());
   }
 
   /// Assign from a list of StringRefs.
@@ -81,26 +61,13 @@
   /// @name String Concatenation
   /// @{
 
-  /// Append from an 

[clang] b0e8990 - [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-01-21 Thread Argyrios Kyrtzidis via cfe-commits

Author: Argyrios Kyrtzidis
Date: 2021-01-21T20:45:54-08:00
New Revision: b0e89906f5b7e505a1ea315ab4ff612b1607fda8

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

LOG: [ASTReader] Allow controlling separately whether validation should be 
disabled for a PCH vs a module file

This addresses an issue with how the PCH preable works, specifically:

1. When using a PCH/preamble the module hash changes and a different cache 
directory is used
2. When the preamble is used, PCH & PCM validation is disabled.

Due to combination of #1 and #2, reparsing with preamble enabled can end up 
loading a stale module file before a header change and using it without 
updating it because validation is disabled and it doesn’t check that the header 
has changed and the module file is out-of-date.

rdar://72611253

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

Added: 
clang/test/Index/Inputs/preamble-reparse-changed-module/head.h
clang/test/Index/Inputs/preamble-reparse-changed-module/module.modulemap
clang/test/Index/Inputs/preamble-reparse-changed-module/new-head.h
clang/test/Index/preamble-reparse-changed-module.m

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/CompilerInstance.h
clang/include/clang/Lex/PreprocessorOptions.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/ChainedIncludesSource.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Frontend/PrecompiledPreamble.cpp
clang/lib/Serialization/ASTReader.cpp
clang/tools/c-index-test/c-index-test.c
clang/tools/c-index-test/core_main.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 500022c2c99b..a2800381be0e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5121,7 +5121,8 @@ def fhalf_no_semantic_interposition : Flag<["-"], 
"fhalf-no-semantic-interpositi
   MarshallingInfoFlag>;
 def fno_validate_pch : Flag<["-"], "fno-validate-pch">,
   HelpText<"Disable validation of precompiled headers">,
-  MarshallingInfoFlag>;
+  MarshallingInfoFlag, 
"DisableValidationForModuleKind::None">,
+  Normalizer<"makeFlagToValueNormalizer(DisableValidationForModuleKind::All)">;
 def fallow_pcm_with_errors : Flag<["-"], "fallow-pcm-with-compiler-errors">,
   HelpText<"Accept a PCM file that was created with compiler errors">,
   MarshallingInfoFlag>;

diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 4fc002c6f383..15f6ed2df885 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -50,6 +50,7 @@ class Preprocessor;
 class Sema;
 class SourceManager;
 class TargetInfo;
+enum class DisableValidationForModuleKind;
 
 /// CompilerInstance - Helper class for managing a single instance of the Clang
 /// compiler.
@@ -659,16 +660,17 @@ class CompilerInstance : public ModuleLoader {
 
   /// Create an external AST source to read a PCH file and attach it to the AST
   /// context.
-  void createPCHExternalASTSource(StringRef Path, bool DisablePCHValidation,
-  bool AllowPCHWithCompilerErrors,
-  void *DeserializationListener,
-  bool OwnDeserializationListener);
+  void createPCHExternalASTSource(
+  StringRef Path, DisableValidationForModuleKind DisableValidation,
+  bool AllowPCHWithCompilerErrors, void *DeserializationListener,
+  bool OwnDeserializationListener);
 
   /// Create an external AST source to read a PCH file.
   ///
   /// \return - The new object on success, or null on failure.
   static IntrusiveRefCntPtr createPCHExternalASTSource(
-  StringRef Path, StringRef Sysroot, bool DisablePCHValidation,
+  StringRef Path, StringRef Sysroot,
+  DisableValidationForModuleKind DisableValidation,
   bool AllowPCHWithCompilerErrors, Preprocessor ,
   InMemoryModuleCache , ASTContext ,
   const PCHContainerReader ,

diff  --git a/clang/include/clang/Lex/PreprocessorOptions.h 
b/clang/include/clang/Lex/PreprocessorOptions.h
index c551f87e0d7b..7f024989bf9b 100644
--- a/clang/include/clang/Lex/PreprocessorOptions.h
+++ b/clang/include/clang/Lex/PreprocessorOptions.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
 #define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
 
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h"
 #include "llvm/ADT/StringRef.h"
@@ -40,6 +41,24 

[PATCH] D95159: [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-01-21 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0e89906f5b7: [ASTReader] Allow controlling separately 
whether validation should be disabled… (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95159

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/CompilerInstance.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/ChainedIncludesSource.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Index/Inputs/preamble-reparse-changed-module/head.h
  clang/test/Index/Inputs/preamble-reparse-changed-module/module.modulemap
  clang/test/Index/Inputs/preamble-reparse-changed-module/new-head.h
  clang/test/Index/preamble-reparse-changed-module.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/c-index-test/core_main.cpp

Index: clang/tools/c-index-test/core_main.cpp
===
--- clang/tools/c-index-test/core_main.cpp
+++ clang/tools/c-index-test/core_main.cpp
@@ -13,22 +13,25 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexingAction.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/PrettyStackTrace.h"
 
 using namespace clang;
 using namespace clang::index;
 using namespace llvm;
 
 extern "C" int indextest_core_main(int argc, const char **argv);
+extern "C" int indextest_perform_shell_execution(const char *command_line);
 
 namespace {
 
@@ -359,3 +362,21 @@
 
   return 0;
 }
+
+//===--===//
+// Utility functions
+//===--===//
+
+int indextest_perform_shell_execution(const char *command_line) {
+  BumpPtrAllocator Alloc;
+  llvm::StringSaver Saver(Alloc);
+  SmallVector Args;
+  llvm::cl::TokenizeGNUCommandLine(command_line, Saver, Args);
+  auto Program = llvm::sys::findProgramByName(Args[0]);
+  if (std::error_code ec = Program.getError()) {
+llvm::errs() << "command not found: " << Args[0] << "\n";
+return ec.value();
+  }
+  SmallVector execArgs(Args.begin(), Args.end());
+  return llvm::sys::ExecuteAndWait(*Program, execArgs);
+}
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -24,6 +24,7 @@
 #endif
 
 extern int indextest_core_main(int argc, const char **argv);
+extern int indextest_perform_shell_execution(const char *command_line);
 
 /**/
 /* Utility functions. */
@@ -2095,6 +2096,8 @@
   enum CXErrorCode Err;
   int result, i;
   int trial;
+  int execute_after_trial = 0;
+  const char *execute_command = NULL;
   int remap_after_trial = 0;
   char *endptr = 0;
   
@@ -2133,12 +2136,26 @@
   if (checkForErrors(TU) != 0)
 return -1;
 
+  if (getenv("CINDEXTEST_EXECUTE_COMMAND")) {
+execute_command = getenv("CINDEXTEST_EXECUTE_COMMAND");
+  }
+  if (getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL")) {
+execute_after_trial =
+strtol(getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL"), , 10);
+  }
+
   if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
 remap_after_trial =
 strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), , 10);
   }
 
   for (trial = 0; trial < trials; ++trial) {
+if (execute_command && trial == execute_after_trial) {
+  result = indextest_perform_shell_execution(execute_command);
+  if (result != 0)
+return result;
+}
+
 free_remapped_files(unsaved_files, num_unsaved_files);
 if (parse_remapped_files_with_try(trial, argc, argv, 0,
   _files, _unsaved_files)) {
Index: clang/test/Index/preamble-reparse-changed-module.m
===
--- /dev/null
+++ clang/test/Index/preamble-reparse-changed-module.m
@@ -0,0 +1,18 @@
+// REQUIRES: shell
+
+// RUN: mkdir -p %t/mod
+// RUN: 

[PATCH] D94986: Remove requirement for -maltivec to be used when using -mabi=vec-extabi or -mabi=vec-default when not using vector code

2021-01-21 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4669
   << A->getSpelling() << RawTriple.str();
-if (!Args.hasArg(options::OPT_maltivec))
-  D.Diag(diag::err_aix_altivec);
+if (Args.hasArg(options::OPT_mabi_EQ_vec_default))
+  D.Diag(diag::err_aix_default_altivec_abi);

Only generate the message when the option is active.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94986

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


[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-01-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp updated this revision to Diff 318406.
nullptr.cpp added a comment.

Add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
  clang/test/SemaCXX/P1155.cpp
  clang/test/SemaCXX/warn-return-std-move.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1203,6 +1203,11 @@
   https://wg21.link/p0593r6;>P0593R6 (DR)
   Clang 11
 
+
+  More implicit moves
+  https://wg21.link/p1825r0;>P1825R0 (DR)
+  Clang 12
+
 
 
 
Index: clang/test/SemaCXX/warn-return-std-move.cpp
===
--- clang/test/SemaCXX/warn-return-std-move.cpp
+++ clang/test/SemaCXX/warn-return-std-move.cpp
@@ -1,12 +1,17 @@
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -Wreturn-std-move-in-c++11 -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=expected %s
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
+// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK
 
 // definitions for std::move
 namespace std {
 inline namespace foo {
 template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
-template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
 
 template  typename remove_reference::type &(T &);
 } // namespace foo
@@ -76,11 +81,8 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
 }
 ConstructFromDerived test3() {
-Derived d3;
-return d3;  // e2-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+  Derived d3;
+  return d3; // ok
 }
 ConstructFromBase test4() {
 Derived d4;
@@ -153,10 +155,7 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
 }
 ConstructFromDerived testParam3(Derived d) {
-return d;  // e7-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying on older compilers}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)"
+  return d; // ok
 }
 ConstructFromBase testParam4(Derived d) {
 return d;  // e8
@@ -218,8 +217,10 @@
 // But if the return type is a reference type, then moving would be wrong.
 Derived& testRetRef1(Derived&& d) { return d; }
 Base& testRetRef2(Derived&& d) { return d; }
+#if __cplusplus >= 201402L
 auto&& testRetRef3(Derived&& d) { return d; }
 decltype(auto) testRetRef4(Derived&& d) { return (d); }
+#endif
 
 // As long as we're checking parentheses, make sure parentheses don't disable the warning.
 Base testParens1() {
@@ -230,14 +231,10 @@
 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
 }
 ConstructFromDerived testParens2() {
-Derived d;
-return (d);  // e18-cxx11
-// expected-warning@-1{{would have been copied despite being returned by name}}
-// expected-note@-2{{to avoid copying}}
-// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)"
+  Derived d;
+  return (d); // ok
 }
 
-
 // If the target is a catch-handler parameter, do apply the diagnostic.
 void throw_derived();
 Derived testEParam1() {
@@ -339,7 +336,7 @@
 namespace test_delete {
 struct Base {
   Base();
-  Base(Base &&) = delete;
+  Base(Base &&) = delete; // cxx20-note {{'Base' has been explicitly marked deleted here}}
   Base(Base const &);
 };
 
@@ -347,6 +344,6 @@
 
 Base 

[PATCH] D88220: [C++20] P1825R0: More implicit moves

2021-01-21 Thread Yang Fan via Phabricator via cfe-commits
nullptr.cpp added a comment.

In D88220#2495071 , @Quuxplusone wrote:

> I notice a lack of any explicitly `co_return`-related tests and/or code in 
> this patch. I'm just going to assume that is fine.

`co_return` related implicit move is implemented by @aaronpuchert in D68845 
. I think it's a good idea to split that from 
this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88220

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


[PATCH] D94583: [RISCV] Update V extension to v1.0-draft 08a0b464.

2021-01-21 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

@jrtc27 just let you know I have same concern too, that's one major reason why 
we don't upstream those extension on GNU toolchain... we are intend to 
introduce an internal revision number on ELF attribute in near future, e.g. 
v-ext 0.9.1 / v0p9p1 to prevent compatible issue here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94583

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


[PATCH] D94583: [RISCV] Update V extension to v1.0-draft 08a0b464.

2021-01-21 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

(Their problem stems from having 1.0 drafts before they've resolved all the 
outstanding issues and frozen the instruction set; if they didn't jump the gun 
then things would be saner for people implementing it)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94583

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


[PATCH] D94583: [RISCV] Update V extension to v1.0-draft 08a0b464.

2021-01-21 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D94583#2513915 , @HsiangKai wrote:

> In D94583#2513070 , @jrtc27 wrote:
>
>> There are a lot of "Resolve for v1.0" issues open against the spec still. 
>> Are we sure we want to brand this as 1.0? It will end up as such in the ELF 
>> attributes and thus be deemed compatible with future "real" 1.0 binaries.
>
> We could keep the version number as v0.9 or do you think it is better to keep 
> it as v1.020201218.

You don't want it to be higher than 1.0 either as that would be newer than the 
future actual 1.0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94583

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


[PATCH] D94745: [OpenMP][WIP] Build the deviceRTLs with OpenMP instead of target dependent language - NOT FOR REVIEW

2021-01-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 318398.
tianshilei1992 added a comment.

Droped the forward declaration and rewrote CUDA intrinsics with LLVM instrinsics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94745

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  openmp/libomptarget/deviceRTLs/common/allocator.h
  openmp/libomptarget/deviceRTLs/common/omptarget.h
  openmp/libomptarget/deviceRTLs/common/src/libcall.cu
  openmp/libomptarget/deviceRTLs/common/src/omp_data.cu
  openmp/libomptarget/deviceRTLs/common/src/reduction.cu
  openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
  openmp/libomptarget/deviceRTLs/nvptx/src/nvptx_interface.h
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h

Index: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
===
--- openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
+++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
@@ -13,18 +13,16 @@
 #define _TARGET_IMPL_H_
 
 #include 
-#include 
 #include 
 #include 
 #include 
 
 #include "nvptx_interface.h"
 
-#define DEVICE __device__
-#define INLINE __forceinline__ DEVICE
-#define NOINLINE __noinline__ DEVICE
-#define SHARED __shared__
-#define ALIGN(N) __align__(N)
+#define DEVICE
+#define INLINE inline __attribute__((always_inline))
+#define NOINLINE __attribute__((noinline))
+#define ALIGN(N) __attribute__((aligned(N)))
 
 
 // Kernel options
@@ -61,6 +59,7 @@
 #elif __CUDA_ARCH__ >= 600
 #define MAX_SM 56
 #else
+#error "Wrong number!"
 #define MAX_SM 16
 #endif
 #endif
Index: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
===
--- openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
+++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
@@ -14,25 +14,6 @@
 #include "target_impl.h"
 #include "common/debug.h"
 
-#include 
-
-// Forward declaration of CUDA primitives which will be evetually transformed
-// into LLVM intrinsics.
-extern "C" {
-unsigned int __activemask();
-unsigned int __ballot(unsigned);
-// The default argument here is based on NVIDIA's website
-// https://developer.nvidia.com/blog/using-cuda-warp-level-primitives/
-int __shfl_sync(unsigned mask, int val, int src_line, int width = WARPSIZE);
-int __shfl(int val, int src_line, int width = WARPSIZE);
-int __shfl_down(int var, unsigned detla, int width);
-int __shfl_down_sync(unsigned mask, int var, unsigned detla, int width);
-void __syncwarp(int mask);
-void __threadfence();
-void __threadfence_block();
-void __threadfence_system();
-}
-
 DEVICE void __kmpc_impl_unpack(uint64_t val, uint32_t , uint32_t ) {
   asm volatile("mov.b64 {%0,%1}, %2;" : "=r"(lo), "=r"(hi) : "l"(val));
 }
@@ -74,10 +55,12 @@
 
 // In Cuda 9.0, __ballot(1) from Cuda 8.0 is replaced with __activemask().
 DEVICE __kmpc_impl_lanemask_t __kmpc_impl_activemask() {
-#if CUDA_VERSION >= 9000
-  return __activemask();
+#if CUDA_VERSION < 9020
+  return __nvvm_vote_ballot(1);
 #else
-  return __ballot(1);
+  unsigned int mask;
+  asm volatile("activemask.b32 %0;" : "=r"(mask));
+  return mask;
 #endif
 }
 
@@ -85,9 +68,9 @@
 DEVICE int32_t __kmpc_impl_shfl_sync(__kmpc_impl_lanemask_t Mask, int32_t Var,
  int32_t SrcLane) {
 #if CUDA_VERSION >= 9000
-  return __shfl_sync(Mask, Var, SrcLane);
+  return __nvvm_shfl_sync_idx_i32(Mask, Var, SrcLane, 0x1f);
 #else
-  return __shfl(Var, SrcLane);
+  return __nvvm_shfl_idx_i32(Var, SrcLane, 0x1f);
 #endif // CUDA_VERSION
 }
 
@@ -95,9 +78,10 @@
   int32_t Var, uint32_t Delta,
   int32_t Width) {
 #if CUDA_VERSION >= 9000
-  return __shfl_down_sync(Mask, Var, Delta, Width);
+  return __nvvm_shfl_sync_down_i32(Mask, Var, Delta,
+   ((WARPSIZE - Width) << 8) | 0x1f);
 #else
-  return __shfl_down(Var, Delta, Width);
+  return __nvvm_shfl_down_i32(Var, Delta, ((WARPSIZE - Width) << 8) | 0x1f);
 #endif // CUDA_VERSION
 }
 
@@ -105,7 +89,7 @@
 
 DEVICE void __kmpc_impl_syncwarp(__kmpc_impl_lanemask_t Mask) {
 #if CUDA_VERSION >= 9000
-  __syncwarp(Mask);
+  __nvvm_bar_warp_sync(Mask);
 #else
   // In Cuda < 9.0 no need to sync threads in warps.
 #endif // CUDA_VERSION
@@ -126,9 +110,9 @@
: "memory");
 }
 
-DEVICE void __kmpc_impl_threadfence() { __threadfence(); }
-DEVICE void __kmpc_impl_threadfence_block() { __threadfence_block(); }
-DEVICE void __kmpc_impl_threadfence_system() { __threadfence_system(); }
+DEVICE void __kmpc_impl_threadfence() { __nvvm_membar_gl(); }
+DEVICE void __kmpc_impl_threadfence_block() { __nvvm_membar_cta(); }
+DEVICE void __kmpc_impl_threadfence_system() { __nvvm_membar_sys(); 

[PATCH] D70701: Fix more VFS tests on Windows

2021-01-21 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Thanks for the quick and detailed response!

Your explanation of hybrid behaviour on Windows was especially helpful, as I 
didn't fully understand how that worked before.

One thing I see, but wasn't obvious from your description, is that the 
mixed/hybrid separator behaviour only happens for `defined(_WIN_32)`. E.g., 
from Path.cpp:

  bool is_separator(char value, Style style) {
if (value == '/')
  return true;
if (real_style(style) == Style::windows)
  return value == '\\';
return false;
  }



In D70701#2514143 , @amccarth wrote:

>> - The path style is detected when reading the YAML file (as now).
>
> Which path's style?  The virtual one that's going to be redirected or the
> actual one it's redirected at?

Both, but you've mostly convinced me not to go down this route.

> - Paths in the YAML file are canonicalized to native at parse time.
>
> If we canonicalize the virtual path, VFS would no longer be valuable for
> creating platform-agnostic tests.

This is a good point I hadn't considered.

> In LLDB, we have the additional wrinkle of remote debugging, where the
> debugger may be running on a Windows machine while the program being
> debugged is running on a Linux box.  You always have to know whether a path
> will be used on the debugger host or the debuggee host.  And there are
> similar concerns for post-mortem debugging from a crash collected on a
> different type of host.

Ah, interesting.

> Honestly, I'm not sure we have a good definition of what makeAbsolute
> should do.

Perhaps the name isn't ideal -- 
`prependRelativePathsWithCurrentWorkingDirectory()` would be more precise -- 
but otherwise I'm not sure I fully agree. Regardless, I acknowledge your point 
that the two worlds are awkwardly different.

I'm going to think about other options; thanks again for your feedback. I am 
still leaning toward `FileSystem::makeAbsolute()` not being virtual / 
overridden, but I have a better idea of how to approach that. One idea is for 
the `RedirectingFileSystem` to keep track of where different styles were used 
when parsing I'm not sure if that'll pan out though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70701

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


[PATCH] D94745: [OpenMP][WIP] Build the deviceRTLs with OpenMP instead of target dependent language - NOT FOR REVIEW

2021-01-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 318377.
tianshilei1992 added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Added changes in the driver


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94745

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  openmp/libomptarget/deviceRTLs/common/allocator.h
  openmp/libomptarget/deviceRTLs/common/omptarget.h
  openmp/libomptarget/deviceRTLs/common/src/libcall.cu
  openmp/libomptarget/deviceRTLs/common/src/omp_data.cu
  openmp/libomptarget/deviceRTLs/common/src/reduction.cu
  openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
  openmp/libomptarget/deviceRTLs/nvptx/src/nvptx_interface.h
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h

Index: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
===
--- openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
+++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
@@ -13,18 +13,16 @@
 #define _TARGET_IMPL_H_
 
 #include 
-#include 
 #include 
 #include 
 #include 
 
 #include "nvptx_interface.h"
 
-#define DEVICE __device__
-#define INLINE __forceinline__ DEVICE
-#define NOINLINE __noinline__ DEVICE
-#define SHARED __shared__
-#define ALIGN(N) __align__(N)
+#define DEVICE
+#define INLINE inline __attribute__((always_inline))
+#define NOINLINE __attribute__((noinline))
+#define ALIGN(N) __attribute__((aligned(N)))
 
 
 // Kernel options
@@ -61,6 +59,7 @@
 #elif __CUDA_ARCH__ >= 600
 #define MAX_SM 56
 #else
+#error "Wrong number!"
 #define MAX_SM 16
 #endif
 #endif
Index: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
===
--- openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
+++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
@@ -14,8 +14,6 @@
 #include "target_impl.h"
 #include "common/debug.h"
 
-#include 
-
 // Forward declaration of CUDA primitives which will be evetually transformed
 // into LLVM intrinsics.
 extern "C" {
Index: openmp/libomptarget/deviceRTLs/nvptx/src/nvptx_interface.h
===
--- openmp/libomptarget/deviceRTLs/nvptx/src/nvptx_interface.h
+++ openmp/libomptarget/deviceRTLs/nvptx/src/nvptx_interface.h
@@ -11,7 +11,8 @@
 
 #include 
 
-#define EXTERN extern "C" __device__
+#define EXTERN extern "C"
+
 typedef uint32_t __kmpc_impl_lanemask_t;
 typedef uint32_t omp_lock_t; /* arbitrary type of the right length */
 
Index: openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
===
--- openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
+++ openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
@@ -10,6 +10,21 @@
 #
 ##===--===##
 
+# TODO: This part needs to be refined when libomptarget is going to support
+# Windows!
+# TODO: This part can also be removed if we can change the clang driver to make
+# it support device only compilation.
+if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
+  set(aux_triple x86_64-unknown-linux-gnu)
+elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "ppc64le")
+  set(aux_triple powerpc64le-unknown-linux-gnu)
+elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
+  set(aux_triple aarch64-unknown-linux-gnu)
+else()
+  libomptarget_say("Not building CUDA offloading device RTL: unknown host arch: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
+  return()
+endif()
+
 get_filename_component(devicertl_base_directory
   ${CMAKE_CURRENT_SOURCE_DIR}
   DIRECTORY)
@@ -79,61 +94,83 @@
 )
 
 # Set flags for LLVM Bitcode compilation.
-set(bc_flags ${LIBOMPTARGET_NVPTX_SELECTED_CUDA_COMPILER_FLAGS}
+set(bc_flags -S -x c++
+ -target nvptx64
+ -Xclang -emit-llvm-bc
+ -Xclang -aux-triple -Xclang ${aux_triple}
+ -fopenmp -Xclang -fopenmp-is-device
+ -D__CUDACC__
+ -fdeclspec
  -I${devicertl_base_directory}
  -I${devicertl_nvptx_directory}/src)
 
 if(${LIBOMPTARGET_NVPTX_DEBUG})
-  set(bc_flags ${bc_flags} -DOMPTARGET_NVPTX_DEBUG=-1)
+  list(APPEND bc_flags -DOMPTARGET_NVPTX_DEBUG=-1)
 else()
-  set(bc_flags ${bc_flags} -DOMPTARGET_NVPTX_DEBUG=0)
+  list(APPEND bc_flags -DOMPTARGET_NVPTX_DEBUG=0)
 endif()
 
 # Create target to build all Bitcode libraries.
 add_custom_target(omptarget-nvptx-bc)
 
-# Generate a Bitcode library for all the compute capabilities the user requested.
+# This correlation is from clang/lib/Driver/ToolChains/Cuda.cpp.
+# The last element is the default case.
+set(cuda_version_list 110 102 101 100 

[PATCH] D94355: [SimplifyCFG] Add relative switch lookup tables

2021-01-21 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem updated this revision to Diff 318372.
gulfem added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

1. Apply relative lookup table generation in fPIC mode
2. Add a test case for single value case
3. Remove hard-coding 64 bit pointers
4. Improve implementation and test coverage


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94355

Files:
  clang/test/CodeGen/switch-to-lookup-table.c
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/X86/switch_to_relative_lookup_table.ll

Index: llvm/test/Transforms/SimplifyCFG/X86/switch_to_relative_lookup_table.ll
===
--- /dev/null
+++ llvm/test/Transforms/SimplifyCFG/X86/switch_to_relative_lookup_table.ll
@@ -0,0 +1,239 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -simplifycfg -switch-to-lookup=true -keep-loops=false -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+; RUN: opt < %s -passes='simplify-cfg' -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@.str = private unnamed_addr constant [5 x i8] c"zero\00", align 1
+@.str.1 = private unnamed_addr constant [4 x i8] c"one\00", align 1
+@.str.2 = private unnamed_addr constant [4 x i8] c"two\00", align 1
+@.str.3 = private unnamed_addr constant [6 x i8] c"three\00", align 1
+@.str.4 = private unnamed_addr constant [5 x i8] c"four\00", align 1
+@.str.5 = private unnamed_addr constant [5 x i8] c"five\00", align 1
+@.str.6 = private unnamed_addr constant [4 x i8] c"six\00", align 1
+@.str.7 = private unnamed_addr constant [6 x i8] c"seven\00", align 1
+@.str.8 = private unnamed_addr constant [6 x i8] c"eight\00", align 1
+@.str.9 = private unnamed_addr constant [8 x i8] c"default\00", align 1
+@.str.10 = private unnamed_addr constant [12 x i8] c"singlevalue\00", align 1
+@.str.11 = private unnamed_addr constant [9 x i8] c"default1\00", align 1
+@.str.12 = private unnamed_addr constant [9 x i8] c"default2\00", align 1
+; Relative string table lookup
+; CHECK: @switch.reltable.string_table = private unnamed_addr constant [9 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.8 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table to i64)) to i32)], align 4
+
+; Relative string table lookup that holes are filled with relative offset to default values
+; CHECK: @switch.reltable.string_table_holes = private unnamed_addr constant [9 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table_holes to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.9 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table_holes to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table_holes to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table_holes to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table_holes to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table_holes to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.9 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table_holes to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([9 x i32]* @switch.reltable.string_table_holes to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* 

[PATCH] D94844: [VFS] Add support to RedirectingFileSystem for mapping a virtual directory to one in the external FS.

2021-01-21 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

I don't see a test for a case where the mapped directory already exists in the 
external FS, something like:

  # external fs
  /d1/f1
  /d2/f2
  
  # redirect fs from yaml (fallthrough: true)
  /d1 -> /d2

Unless I just missed it, can you add one?

My intuition is we'd want to overlay the directory contents, not replace them:

  # overlayed contents (my intuition for fallthrough: true)
  /d1/f1
  /d1/f2
  /d2/f2
  
  # replaced contents (I think unexpected)
  /d1/f2
  /d2/f2

If you agree, it might be good to test that the recursive directory iterator 
does the right thing.

Might also be valuable to test the non-fallthrough case, which I assume should 
give this view:

  # fallthrough: false
  /d1/f2

@JDevlieghere, I'm hoping you can help review the details of the code here, as 
I don't know the iteration code well. Also, are these API changes okay for LLDB 
(I seem to remember LLDB subclassing this...)?




Comment at: llvm/include/llvm/Support/VirtualFileSystem.h:608-610
+  /// A file or directory in the vfs that is mapped to a file or directory in
+  /// the external filesystem.
+  class RemapEntry : public Entry {

Is it easy to move this declaration after `DirectoryEntry`? If so, I think 
that'd reduce the diff a bit, and make it more clear what parts of this were 
being used verbatim from the old `FileEntry`. Up to you though.



Comment at: llvm/include/llvm/Support/VirtualFileSystem.h:776-778
   /// Looks up \p Path in \c Roots.
-  ErrorOr lookupPath(const Twine ) const;
+  ErrorOr lookupPath(const Twine ,
+  SmallVectorImpl ) const;

It's not entirely clear what the extra parameters do / when they're filled in / 
etc; can you add a bit more documentation?

Also, I see that the public caller ignores the `ExternalRedirect` parameter. I 
wonder if this should be renamed to `lookupPathWithName` or `lookupPathImpl`, 
leaving behind a `lookupPath` wrapper that creates the ignored buffer for the 
public interface... no strong opinion though.



Comment at: llvm/lib/Support/VirtualFileSystem.cpp:1831
+  // directory's external contents path plus any remaining path components.
+  auto SetExtRedirect = [&](RedirectingFileSystem::Entry *E) {
+auto *DRE = dyn_cast(From);

Could this return `E`, and then the callers `return SetExtRedirect(...)`? Not 
sure if it'd actually be cleaner, up to you.



Comment at: llvm/lib/Support/VirtualFileSystem.cpp:2039
 }
-return;
+  } else if (Kind == RedirectingFileSystem::EK_RemapDirectory) {
+auto *DR = dyn_cast(SrcE);

Nit: please keep the early return.



Comment at: llvm/lib/Support/VirtualFileSystem.cpp:2047
+YAMLVFSEntry(VPath.c_str(), DR->getExternalContentsPath()));
+  } else {
+assert(Kind == RedirectingFileSystem::EK_File && "Must be a EK_File");

Nit: please use an early return here to avoid unnecessary indentation (I think 
the rest of this diff goes away...).



Comment at: llvm/lib/Support/VirtualFileSystem.cpp:2068-2070
+  SmallString<256> ExternalRedirect;
+  ErrorOr RootE =
+  VFS->lookupPath("/", ExternalRedirect);

This seems a bit unfortunate to have to change, but not a big deal...


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

https://reviews.llvm.org/D94844

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


[PATCH] D95181: [CodeGen][ObjC] Fix broken IR generated when there is a nil receiver check

2021-01-21 Thread Akira Hatanaka 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 rG3d349ed7e110: [CodeGen][ObjC] Fix broken IR generated when 
there is a nil receiver (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95181

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/ns_consume_null_check.m

Index: clang/test/CodeGenObjC/ns_consume_null_check.m
===
--- clang/test/CodeGenObjC/ns_consume_null_check.m
+++ clang/test/CodeGenObjC/ns_consume_null_check.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-dispatch-method=mixed -fobjc-runtime-has-weak -fexceptions -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-dispatch-method=mixed -fobjc-runtime-has-weak -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
 
 @interface NSObject
 - (id) new;
@@ -7,6 +7,7 @@
 @interface MyObject : NSObject
 - (char)isEqual:(id) __attribute__((ns_consumed)) object;
 - (_Complex float) asComplexWithArg: (id) __attribute__((ns_consumed)) object;
++(instancetype)m0:(id) __attribute__((ns_consumed)) object;
 @end
 
 MyObject *x;
@@ -82,4 +83,27 @@
 // CHECK:  landingpad
 // CHECK:  call void @llvm.objc.destroyWeak(i8** [[WEAKOBJ]]) [[NUW]]
 
+void test2(id a) {
+  id obj = [MyObject m0:a];
+}
+
+// CHECK-LABEL: define{{.*}} void @test2(
+// CHECK: %[[CALL:.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
+// CHECK-NEXT: %[[V6:.*]] = {{.*}}call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
+
+// CHECK: phi i8* [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
+
+void test3(id a) {
+  @try {
+id obj = [MyObject m0:a];
+  } @catch (id x) {
+  }
+}
+
+// CHECK-LABEL: define{{.*}} void @test3(
+// CHECK: %[[CALL:.*]] = invoke i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
+// CHECK: %[[V6:.*]] = {{.*}}call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
+
+// CHECK: phi i8* [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
+
 // CHECK: attributes [[NUW]] = { nounwind }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2894,45 +2894,57 @@
   ValueTransform;
 
 /// Insert code immediately after a call.
+
+// FIXME: We should find a way to emit the runtime call immediately
+// after the call is emitted to eliminate the need for this function.
 static llvm::Value *emitARCOperationAfterCall(CodeGenFunction ,
   llvm::Value *value,
   ValueTransform doAfterCall,
   ValueTransform doFallback) {
-  if (llvm::CallInst *call = dyn_cast(value)) {
-CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
+  CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
 
+  if (llvm::CallInst *call = dyn_cast(value)) {
 // Place the retain immediately following the call.
 CGF.Builder.SetInsertPoint(call->getParent(),
++llvm::BasicBlock::iterator(call));
 value = doAfterCall(CGF, value);
-
-CGF.Builder.restoreIP(ip);
-return value;
   } else if (llvm::InvokeInst *invoke = dyn_cast(value)) {
-CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
-
 // Place the retain at the beginning of the normal destination block.
 llvm::BasicBlock *BB = invoke->getNormalDest();
 CGF.Builder.SetInsertPoint(BB, BB->begin());
 value = doAfterCall(CGF, value);
 
-CGF.Builder.restoreIP(ip);
-return value;
-
   // Bitcasts can arise because of related-result returns.  Rewrite
   // the operand.
   } else if (llvm::BitCastInst *bitcast = dyn_cast(value)) {
+// Change the insert point to avoid emitting the fall-back call after the
+// bitcast.
+CGF.Builder.SetInsertPoint(bitcast->getParent(), bitcast->getIterator());
 llvm::Value *operand = bitcast->getOperand(0);
 operand = emitARCOperationAfterCall(CGF, operand, doAfterCall, doFallback);
 bitcast->setOperand(0, operand);
-return bitcast;
-
-  // Generic fall-back case.
+value = bitcast;
   } else {
-// Retain using the non-block variant: we never need to do a copy
-// of a block that's been returned to us.
-return doFallback(CGF, value);
+auto *phi = dyn_cast(value);
+if (phi && phi->getNumIncomingValues() == 2 &&
+isa(phi->getIncomingValue(1)) &&
+isa(phi->getIncomingValue(0))) {
+  // Handle phi instructions that are generated when it's necessary to check
+  // whether the receiver of a message is null.
+  llvm::Value *inVal = phi->getIncomingValue(0);
+  inVal = emitARCOperationAfterCall(CGF, inVal, doAfterCall, doFallback);
+  

[clang] 3d349ed - [CodeGen][ObjC] Fix broken IR generated when there is a nil receiver

2021-01-21 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2021-01-21T17:38:46-08:00
New Revision: 3d349ed7e1108686271a09314dafaa356df4006d

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

LOG: [CodeGen][ObjC] Fix broken IR generated when there is a nil receiver
check

This patch fixes a bug in emitARCOperationAfterCall where it inserts the
fall-back call after a bitcast instruction and then replaces the
bitcast's operand with the result of the fall-back call. The generated
IR without this patch looks like this:

msgSend.call: ; preds = %entry
  %call = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
  br label %msgSend.cont

msgSend.null-receiver:; preds = %entry
  call void @llvm.objc.release(i8* %4)
  br label %msgSend.cont

msgSend.cont:
  %8 = phi i8* [ %call, %msgSend.call ], [ null, %msgSend.null-receiver ]
  %9 = bitcast i8* %10 to %0*
  %10 = call i8* @llvm.objc.retain(i8* %8)

Notice that `%9 = bitcast i8* %10` to %0* is taking operand %10 which is
defined after it.

To fix the bug, this patch modifies the insert point to point to the
bitcast instruction so that the fall-back call is inserted before the
bitcast. In addition, it teaches the function to look at phi
instructions that are generated when there is a check for a null
receiver and insert the retainRV/claimRV instruction right after the
call instead of inserting a fall-back call right after the phi
instruction.

rdar://73360225

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

Added: 


Modified: 
clang/lib/CodeGen/CGObjC.cpp
clang/test/CodeGenObjC/ns_consume_null_check.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index bdb9f4002f3c..3f930c76fe0a 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -2894,45 +2894,57 @@ typedef llvm::function_ref(value)) {
-CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
+  CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
 
+  if (llvm::CallInst *call = dyn_cast(value)) {
 // Place the retain immediately following the call.
 CGF.Builder.SetInsertPoint(call->getParent(),
++llvm::BasicBlock::iterator(call));
 value = doAfterCall(CGF, value);
-
-CGF.Builder.restoreIP(ip);
-return value;
   } else if (llvm::InvokeInst *invoke = dyn_cast(value)) {
-CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
-
 // Place the retain at the beginning of the normal destination block.
 llvm::BasicBlock *BB = invoke->getNormalDest();
 CGF.Builder.SetInsertPoint(BB, BB->begin());
 value = doAfterCall(CGF, value);
 
-CGF.Builder.restoreIP(ip);
-return value;
-
   // Bitcasts can arise because of related-result returns.  Rewrite
   // the operand.
   } else if (llvm::BitCastInst *bitcast = dyn_cast(value)) {
+// Change the insert point to avoid emitting the fall-back call after the
+// bitcast.
+CGF.Builder.SetInsertPoint(bitcast->getParent(), bitcast->getIterator());
 llvm::Value *operand = bitcast->getOperand(0);
 operand = emitARCOperationAfterCall(CGF, operand, doAfterCall, doFallback);
 bitcast->setOperand(0, operand);
-return bitcast;
-
-  // Generic fall-back case.
+value = bitcast;
   } else {
-// Retain using the non-block variant: we never need to do a copy
-// of a block that's been returned to us.
-return doFallback(CGF, value);
+auto *phi = dyn_cast(value);
+if (phi && phi->getNumIncomingValues() == 2 &&
+isa(phi->getIncomingValue(1)) &&
+isa(phi->getIncomingValue(0))) {
+  // Handle phi instructions that are generated when it's necessary to 
check
+  // whether the receiver of a message is null.
+  llvm::Value *inVal = phi->getIncomingValue(0);
+  inVal = emitARCOperationAfterCall(CGF, inVal, doAfterCall, doFallback);
+  phi->setIncomingValue(0, inVal);
+  value = phi;
+} else {
+  // Generic fall-back case.
+  // Retain using the non-block variant: we never need to do a copy
+  // of a block that's been returned to us.
+  value = doFallback(CGF, value);
+}
   }
+
+  CGF.Builder.restoreIP(ip);
+  return value;
 }
 
 /// Given that the given expression is some sort of call (which does

diff  --git a/clang/test/CodeGenObjC/ns_consume_null_check.m 
b/clang/test/CodeGenObjC/ns_consume_null_check.m
index 3a0aa6f7c596..e02654d4e21b 100644
--- a/clang/test/CodeGenObjC/ns_consume_null_check.m
+++ b/clang/test/CodeGenObjC/ns_consume_null_check.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc 
-fobjc-dispatch-method=mixed -fobjc-runtime-has-weak -fexceptions -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 

[PATCH] D95181: [CodeGen][ObjC] Fix broken IR generated when there is a nil receiver check

2021-01-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 318366.
ahatanak added a comment.

Add a test for invoke and a FIXME for eliminating the need for 
emitARCOperationAfterCall.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95181

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/ns_consume_null_check.m

Index: clang/test/CodeGenObjC/ns_consume_null_check.m
===
--- clang/test/CodeGenObjC/ns_consume_null_check.m
+++ clang/test/CodeGenObjC/ns_consume_null_check.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-dispatch-method=mixed -fobjc-runtime-has-weak -fexceptions -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-dispatch-method=mixed -fobjc-runtime-has-weak -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
 
 @interface NSObject
 - (id) new;
@@ -7,6 +7,7 @@
 @interface MyObject : NSObject
 - (char)isEqual:(id) __attribute__((ns_consumed)) object;
 - (_Complex float) asComplexWithArg: (id) __attribute__((ns_consumed)) object;
++(instancetype)m0:(id) __attribute__((ns_consumed)) object;
 @end
 
 MyObject *x;
@@ -82,4 +83,27 @@
 // CHECK:  landingpad
 // CHECK:  call void @llvm.objc.destroyWeak(i8** [[WEAKOBJ]]) [[NUW]]
 
+void test2(id a) {
+  id obj = [MyObject m0:a];
+}
+
+// CHECK-LABEL: define{{.*}} void @test2(
+// CHECK: %[[CALL:.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
+// CHECK-NEXT: %[[V6:.*]] = {{.*}}call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
+
+// CHECK: phi i8* [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
+
+void test3(id a) {
+  @try {
+id obj = [MyObject m0:a];
+  } @catch (id x) {
+  }
+}
+
+// CHECK-LABEL: define{{.*}} void @test3(
+// CHECK: %[[CALL:.*]] = invoke i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
+// CHECK: %[[V6:.*]] = {{.*}}call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
+
+// CHECK: phi i8* [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
+
 // CHECK: attributes [[NUW]] = { nounwind }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2894,45 +2894,57 @@
   ValueTransform;
 
 /// Insert code immediately after a call.
+
+// FIXME: We should find a way to emit the runtime call immediately
+// after the call is emitted to eliminate the need for this function.
 static llvm::Value *emitARCOperationAfterCall(CodeGenFunction ,
   llvm::Value *value,
   ValueTransform doAfterCall,
   ValueTransform doFallback) {
-  if (llvm::CallInst *call = dyn_cast(value)) {
-CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
+  CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
 
+  if (llvm::CallInst *call = dyn_cast(value)) {
 // Place the retain immediately following the call.
 CGF.Builder.SetInsertPoint(call->getParent(),
++llvm::BasicBlock::iterator(call));
 value = doAfterCall(CGF, value);
-
-CGF.Builder.restoreIP(ip);
-return value;
   } else if (llvm::InvokeInst *invoke = dyn_cast(value)) {
-CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
-
 // Place the retain at the beginning of the normal destination block.
 llvm::BasicBlock *BB = invoke->getNormalDest();
 CGF.Builder.SetInsertPoint(BB, BB->begin());
 value = doAfterCall(CGF, value);
 
-CGF.Builder.restoreIP(ip);
-return value;
-
   // Bitcasts can arise because of related-result returns.  Rewrite
   // the operand.
   } else if (llvm::BitCastInst *bitcast = dyn_cast(value)) {
+// Change the insert point to avoid emitting the fall-back call after the
+// bitcast.
+CGF.Builder.SetInsertPoint(bitcast->getParent(), bitcast->getIterator());
 llvm::Value *operand = bitcast->getOperand(0);
 operand = emitARCOperationAfterCall(CGF, operand, doAfterCall, doFallback);
 bitcast->setOperand(0, operand);
-return bitcast;
-
-  // Generic fall-back case.
+value = bitcast;
   } else {
-// Retain using the non-block variant: we never need to do a copy
-// of a block that's been returned to us.
-return doFallback(CGF, value);
+auto *phi = dyn_cast(value);
+if (phi && phi->getNumIncomingValues() == 2 &&
+isa(phi->getIncomingValue(1)) &&
+isa(phi->getIncomingValue(0))) {
+  // Handle phi instructions that are generated when it's necessary to check
+  // whether the receiver of a message is null.
+  llvm::Value *inVal = phi->getIncomingValue(0);
+  inVal = emitARCOperationAfterCall(CGF, inVal, doAfterCall, doFallback);
+  phi->setIncomingValue(0, inVal);
+  value = phi;
+} else {
+  // Generic fall-back case.
+  

Re: [PATCH] D70701: Fix more VFS tests on Windows

2021-01-21 Thread Adrian McCarthy via cfe-commits
 I didn't design VFS.  I just fixed a bunch of portability bugs that
prevented us from running most of the VFS tests on Windows.  If I were
designing it, I (hope) I wouldn't have done it this way.  But the horse is
already out of the barn.

Here's my background with VFS (and, specifically, the redirecting
filesystem):

VFS is used in many tests to map a path in an arbitrary (usually Posix)
style to another path, possibly in a different filesystem.  This allows the
test to be platform agnostic.  For example, the test can refer to
`/foo/bar.h` if it uses the redirecting filesystem to map `/foo` to an
actual directory on the host.  If it's a Windows machine, that target might
be something like `C:\foo`, in which case the actual file would be
`C:\foo\bar.h`, which LLVM thinks of as `C:\foo/bar.h`.  That's inherently
a path with hybrid style.  There are other cases, too, e.g., where the host
is Windows, but the target filesystem is an LLVM in-memory one (which uses
only Posix style).

When I first tried to tackle the portability bugs, I tried various
normalization/canonicalization strategies, but always encountered a
blocker.  That's when rnk pointed out to me that clang generally doesn't do
any path normalization; it just treats paths as strings that can be
concatenated.  With that in mind, I tried accepting the fact that hybrid
path styles are a fact of life in VFS, and suddenly nearly all of the
portability problems became relatively easy to solve.

Note that lots of LLVM and Clang tests were using VFS, but the VFS tests
themselves couldn't run on Windows.  All those tests were built upon
functionality that wasn't being tested.

I think that we probably could do something simpler, but it would force a
breaking change in the design of the redirecting filesystem.  The most
obvious victim of that break would be various LLVM and clang tests that
exclusively use Posix-style paths and rely on VFS to make it work on
non-Posix OSes.  I'm not sure how significant the break would be for others.

Looking specifically at your proposal:

> - The path style is detected when reading the YAML file (as now).

Which path's style?  The virtual one that's going to be redirected or the
actual one it's redirected at?

- Paths in the YAML file are canonicalized to native at parse time.

If we canonicalize the virtual path, VFS would no longer be valuable for
creating platform-agnostic tests.

I don't remember the details, but canonicalizing the target paths caused
problems.  Do we need to be careful about multiple redirections (e.g.,
`/foo` directs to `/zerz` which directs to `C:\bumble`)?  I seem to recall
there was a good reason why the redirecting filesystem waits to the last
moment to convert a virtual path to an actual host path.

> - The nodes in-memory all use native paths so the non-native style isn't
needed after construction is complete.

I'm guessing that would affect how paths are displayed (e.g., in diagnostic
messages).  At a minimum, we'd have to fix some tests.  I don't know all
the contexts this might occur and how that might affect things.  For
example, paths may be written into debug info metadata.

- `makeAbsolute()` doesn't need to be overridden / special.

Honestly, I'm not sure we have a good definition of what `makeAbsolute`
should do.  Sure, on Posix, it's well understood.  But is `\foo` an
absolute path on Windows?  Is `D:bar.h` an absolute path on Windows?  If
not, how should those be made absolute?  LLVM assumes that there's a well
defined mapping between Posix filesystem concepts and the host filesystem.
But I haven't seen any documentation on how a Posix->Windows mapping should
work (let alone the inverse), and I certainly don't have an intuitive
understanding of how that mapping should work.

In LLDB, we have the additional wrinkle of remote debugging, where the
debugger may be running on a Windows machine while the program being
debugged is running on a Linux box.  You always have to know whether a path
will be used on the debugger host or the debuggee host.  And there are
similar concerns for post-mortem debugging from a crash collected on a
different type of host.

I'm not opposed to making this better, but I don't think I understand your
proposal well enough to discuss it in detail.  I'm pretty sure anything
that eliminates hybrid paths is going to cause some breaking changes.  That
might be as simple as fixing up a bunch of tests, but it might have wider
impact.

Adrian.

On Thu, Jan 21, 2021 at 4:26 PM Duncan P. N. Exon Smith via Phabricator <
revi...@reviews.llvm.org> wrote:

> dexonsmith added a comment.
>
> @rnk / @amccarth, I've been looking at the history of `makeAbsolute` being
> virtual, since it's a bit awkward that `RedirectingFileSystem` behaves
> differently from the others. I'm hoping you can give me a bit more context.
>
> I'm wondering about an alternative implementation where:
>
> - The path style is detected when reading the YAML file (as now).
> - Paths in the YAML file are 

[PATCH] D93668: [clang] Override the Fuchsia platform ABI using the triple environment

2021-01-21 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr added a comment.

I am also a C++ programmer working on C++ ABI support.  I'm glad to be working 
on a platform that made many intentional design decisions to enable keeping the 
C++ ABI out of the platform ABI.  It makes it vastly easier to do interesting 
work on C++ ABIs such as what Leo is doing.  It also makes it significantly 
easier to do interesting work on platform ABIs, which I also do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93668

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


[PATCH] D95187: [DebugInfo][CodeView] Use as the display name for lambdas.

2021-01-21 Thread Amy Huang via Phabricator via cfe-commits
akhuang created this revision.
akhuang added reviewers: rnk, dblaikie.
akhuang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently (for codeview) lambdas have a string like `` in
their mangled name, and don't have any display name. This change uses the
`` as the display name, which helps distinguish between lambdas
in -gline-tables-only, since there are no linkage names there. 
It also changes how we display lambda names; previously we used
``; now it will show ``.

I added a function to the mangling context code to create this string;
for Itanium it just returns an empty string.

Bug: https://bugs.llvm.org/show_bug.cgi?id=48432


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95187

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Index: clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
===
--- clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -10,6 +10,8 @@
 void f() {}
 }
 
+auto lambda1 = []() { return 1; };
+
 NS::C c;
 
 void test() {
@@ -27,4 +29,10 @@
   // CHECK-NOT: identifier
   // CHECK: ![[MTYPE]] = !DISubroutineType(types: !{{.*}})
   c.m();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1:[0-9]+]]
+  // CHECK: ![[LAMBDA1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:name: ""
+  // CHECK-SAME:flags: DIFlagFwdDecl
+  lambda1();
 }
Index: clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
===
--- clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
+++ clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
@@ -100,7 +100,7 @@
   // MSVC-SAME:  )
   // MSVC:   [[TYPE_OF_FOUR]] = distinct !DICompositeType
   // MSVC-SAME:  tag: DW_TAG_class_type
-  // MSVC-NOT:   name:
+  // MSVC-SAME:  name: ""
   // MSVC-SAME:  identifier: ".?AV@?0??main@@9@"
   // MSVC-SAME:  )
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -342,6 +342,12 @@
 // associate typedef mangled in if they have one.
 Name = TND->getName();
 
+  // Give lambdas a display name based on their name mangling.
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+if (CXXRD->isLambda())
+  return internString(
+  CGM.getCXXABI().getMangleContext().getLambdaString(CXXRD));
+
   if (!Name.empty()) {
 SmallString<256> UnnamedType("isLambda() && "RD must be a lambda!");
+llvm::SmallString<10> Name("getLambdaContextDecl();
+unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
+unsigned LambdaId;
+const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
+const FunctionDecl *Func =
+Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+if (Func) {
+  unsigned DefaultArgNo =
+  Func->getNumParams() - Parm->getFunctionScopeIndex();
+  Name += llvm::utostr(DefaultArgNo);
+  Name += "_";
+}
+
+if (LambdaManglingNumber)
+  LambdaId = LambdaManglingNumber;
+else
+  LambdaId = getLambdaId(Lambda);
+
+Name += llvm::utostr(LambdaId);
+Name += ">";
+return StringRef(Name);
+  }
+
   unsigned getLambdaId(const CXXRecordDecl *RD) {
 assert(RD->isLambda() && "RD must be a lambda!");
 assert(!RD->isExternallyVisible() && "RD must not be visible!");
@@ -972,32 +1000,10 @@
 
   if (const CXXRecordDecl *Record = dyn_cast(TD)) {
 if (Record->isLambda()) {
-  llvm::SmallString<10> Name("getLambdaContextDecl();
   unsigned LambdaManglingNumber = Record->getLambdaManglingNumber();
-  unsigned LambdaId;
-  const ParmVarDecl *Parm =
-  dyn_cast_or_null(LambdaContextDecl);
-  const FunctionDecl *Func =
-  Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
-
-  if (Func) {
-unsigned DefaultArgNo =
-Func->getNumParams() - Parm->getFunctionScopeIndex();
-Name += llvm::utostr(DefaultArgNo);
-Name += "_";
-  }
-
-  if (LambdaManglingNumber)
-LambdaId = LambdaManglingNumber;
-  else
-LambdaId = Context.getLambdaId(Record);
-
-  Name += llvm::utostr(LambdaId);
-  Name += ">";
-
-  mangleSourceName(Name);
+  Decl *LambdaContextDecl = Record->getLambdaContextDecl();
 
   // If the context is a variable or a 

[PATCH] D70701: Fix more VFS tests on Windows

2021-01-21 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

@rnk / @amccarth, I've been looking at the history of `makeAbsolute` being 
virtual, since it's a bit awkward that `RedirectingFileSystem` behaves 
differently from the others. I'm hoping you can give me a bit more context.

I'm wondering about an alternative implementation where:

- The path style is detected when reading the YAML file (as now).
- Paths in the YAML file are canonicalized to native at parse time.
- The nodes in-memory all use native paths so the non-native style isn't needed 
after construction is complete.
- `makeAbsolute()` doesn't need to be overridden / special.

Was this considered? If so, why was it rejected? (If it doesn't work, why not?)

If we could limit the scope the special version of `makeAbsolute()` to 
"construction time" it would simplify the mental model. As it stands it's a bit 
difficult to reason about `makeAbsolute`, and whether it's safe/correct to send 
a `makeAbsolute`-d path into `ExternalFS`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70701

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


[PATCH] D80421: [Mips] use correct ld.so for musl soft float

2021-01-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Such driver tests are in `clang/test/Driver/`. You may want to read a few 
existing mips driver tests and musl tests to figure out whether reusing an 
existing file or creating a new file makes more sense.

You can run a test with `$build/bin/llvm-lit -vv test.c`. `check-clang-driver` 
runs all test/Driver tests. Before uploading a patch, `check-clang-driver` or 
`check-clang` (the latter if you suspect other components can be affected). For 
driver, `check-clang-driver` is usually sufficient.


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

https://reviews.llvm.org/D80421

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


[PATCH] D95161: [Clang][OpenMP][NVPTX] Replace `libomptarget-nvptx-path` with `libomptarget-nvptx-bc-path`

2021-01-21 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95161

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


[PATCH] D80421: [Mips] use correct ld.so for musl soft float

2021-01-21 Thread Joe Holden via Phabricator via cfe-commits
joewholden updated this revision to Diff 318346.

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

https://reviews.llvm.org/D80421

Files:
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -426,6 +426,7 @@
   if (Triple.isMusl()) {
 std::string ArchName;
 bool IsArm = false;
+bool IsMips = false;
 
 switch (Arch) {
 case llvm::Triple::arm:
@@ -438,14 +439,25 @@
   ArchName = "armeb";
   IsArm = true;
   break;
+case llvm::Triple::mips:
+case llvm::Triple::mipsel:
+case llvm::Triple::mips64:
+case llvm::Triple::mips64el:
+  IsMips = true;
+  ArchName = Triple.getArchName().str();
+  break;
 default:
   ArchName = Triple.getArchName().str();
 }
+
 if (IsArm &&
 (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
  tools::arm::getARMFloatABI(*this, Args) == 
tools::arm::FloatABI::Hard))
   ArchName += "hf";
 
+if (IsMips && tools::mips::getMipsFloatABI(getDriver(), Args, getTriple()) 
== tools::mips::FloatABI::Soft)
+  ArchName += "-sf";
+
 return "/lib/ld-musl-" + ArchName + ".so.1";
   }
 


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -426,6 +426,7 @@
   if (Triple.isMusl()) {
 std::string ArchName;
 bool IsArm = false;
+bool IsMips = false;
 
 switch (Arch) {
 case llvm::Triple::arm:
@@ -438,14 +439,25 @@
   ArchName = "armeb";
   IsArm = true;
   break;
+case llvm::Triple::mips:
+case llvm::Triple::mipsel:
+case llvm::Triple::mips64:
+case llvm::Triple::mips64el:
+  IsMips = true;
+  ArchName = Triple.getArchName().str();
+  break;
 default:
   ArchName = Triple.getArchName().str();
 }
+
 if (IsArm &&
 (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
  tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard))
   ArchName += "hf";
 
+if (IsMips && tools::mips::getMipsFloatABI(getDriver(), Args, getTriple()) == tools::mips::FloatABI::Soft)
+  ArchName += "-sf";
+
 return "/lib/ld-musl-" + ArchName + ".so.1";
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80421: [Mips] use correct ld.so for musl soft float

2021-01-21 Thread Joe Holden via Phabricator via cfe-commits
joewholden updated this revision to Diff 318343.
joewholden added a comment.

I think this is better (we've been using it for a while successfully), I 
haven't had time to understand the tests enough to add some yet, but I'll take 
a look as soon as I can


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

https://reviews.llvm.org/D80421

Files:
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -519,6 +519,7 @@
   if (Triple.isMusl()) {
 std::string ArchName;
 bool IsArm = false;
+bool IsMips = false;
 
 switch (Arch) {
 case llvm::Triple::arm:
@@ -531,14 +532,25 @@
   ArchName = "armeb";
   IsArm = true;
   break;
+case llvm::Triple::mips:
+case llvm::Triple::mipsel:
+case llvm::Triple::mips64:
+case llvm::Triple::mips64el:
+  IsMips = true;
+  ArchName = Triple.getArchName().str();
+  break;
 default:
   ArchName = Triple.getArchName().str();
 }
+
 if (IsArm &&
 (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
  tools::arm::getARMFloatABI(*this, Args) == 
tools::arm::FloatABI::Hard))
   ArchName += "hf";
 
+if (IsMips && tools::mips::getMipsFloatABI(getDriver(), Args, getTriple()) 
== tools::mips::FloatABI::Soft)
+  ArchName += "-sf";
+
 return "/lib/ld-musl-" + ArchName + ".so.1";
   }
 


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -519,6 +519,7 @@
   if (Triple.isMusl()) {
 std::string ArchName;
 bool IsArm = false;
+bool IsMips = false;
 
 switch (Arch) {
 case llvm::Triple::arm:
@@ -531,14 +532,25 @@
   ArchName = "armeb";
   IsArm = true;
   break;
+case llvm::Triple::mips:
+case llvm::Triple::mipsel:
+case llvm::Triple::mips64:
+case llvm::Triple::mips64el:
+  IsMips = true;
+  ArchName = Triple.getArchName().str();
+  break;
 default:
   ArchName = Triple.getArchName().str();
 }
+
 if (IsArm &&
 (Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
  tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard))
   ArchName += "hf";
 
+if (IsMips && tools::mips::getMipsFloatABI(getDriver(), Args, getTriple()) == tools::mips::FloatABI::Soft)
+  ArchName += "-sf";
+
 return "/lib/ld-musl-" + ArchName + ".so.1";
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95182: [clang][Fuchsia] Turn on Relative VTables for Fuchsia

2021-01-21 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr.
leonardchan added a project: clang.
Herald added a reviewer: jansvoboda11.
leonardchan requested review of this revision.

And also remove `-fexperimental-relative-c++-abi-vtables` from tests that 
already have fuchsia as the target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95182

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/available_externally-vtable.cpp
  
clang/test/CodeGenCXX/RelativeVTablesABI/child-inheritted-from-parent-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/child-vtable-in-comdat.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-1.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/cross-translation-unit-2.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/diamond-virtual-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/dynamic-cast.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/inheritted-virtual-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/inlined-key-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/member-function-pointer.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/multiple-inheritance.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/no-alias-when-dso-local.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/override-pure-virtual-method.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/overriden-virtual-function.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/relative-vtables-flag.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/thunk-mangling.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/type-info.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/virtual-function-call.cpp
  clang/test/CodeGenCXX/RelativeVTablesABI/vtable-hidden-when-in-comdat.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
  clang/test/Lexer/has_feature_cxx_abi_relative_vtable.cpp

Index: clang/test/Lexer/has_feature_cxx_abi_relative_vtable.cpp
===
--- clang/test/Lexer/has_feature_cxx_abi_relative_vtable.cpp
+++ clang/test/Lexer/has_feature_cxx_abi_relative_vtable.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -E %s -triple x86_64-linux-gnu -x c++ -fexperimental-relative-c++-abi-vtables -o - | FileCheck %s --check-prefix=RELATIVE-VTABLE
 // RUN: %clang_cc1 -E %s -triple x86_64-linux-gnu -x c++ -fno-experimental-relative-c++-abi-vtables -o - | FileCheck %s --check-prefix=NO-RELATIVE-VTABLE
 // RUN: %clang_cc1 -E %s -triple x86_64-linux-gnu -x c -fexperimental-relative-c++-abi-vtables -o - | FileCheck %s --check-prefix=NO-RELATIVE-VTABLE
+// RUN: %clang_cc1 -E %s -triple x86_64-unknown-fuchsia -x c++ -o - | FileCheck %s --check-prefix=RELATIVE-VTABLE
 
 #if __has_feature(cxx_abi_relative_vtable)
 int has_relative_vtable();
Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
===
--- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
+++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
@@ -3,8 +3,12 @@
 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-apple-ios5.0 -target-abi apcs-gnu | FileCheck --check-prefix=CHECKIOS5 %s
 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=wasm32-unknown-unknown \
 //RUN:   | FileCheck --check-prefix=CHECKARM %s
-//RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
-//RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
+//RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefixes=CHECKFUCHSIA,CHECKFUCHSIA-RELVTABLE %s
+//RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefixes=CHECKFUCHSIA,CHECKFUCHSIA-RELVTABLE %s
+//RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia -fno-experimental-relative-c++-abi-vtables \
+//RUN:   | FileCheck --check-prefixes=CHECKFUCHSIA,CHECKFUCHSIA-NORELVTABLE %s
+//RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia -fno-experimental-relative-c++-abi-vtables \
+//RUN:   | FileCheck --check-prefixes=CHECKFUCHSIA,CHECKFUCHSIA-NORELVTABLE %s
 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s
 // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32
 
@@ -151,8 +155,10 @@
 
 // Verify that virtual calls to destructors are not marked with a 'returned'
 // this parameter at the call site...
-// CHECKARM,CHECKFUCHSIA: [[VFN:%.*]] = getelementptr inbounds %class.E* (%class.E*)*, %class.E* (%class.E*)**
-// CHECKARM,CHECKFUCHSIA: [[THUNK:%.*]] = load %class.E* (%class.E*)*, %class.E* (%class.E*)** [[VFN]]
+// 

[PATCH] D94583: [RISCV] Update V extension to v1.0-draft 08a0b464.

2021-01-21 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

In D94583#2513070 , @jrtc27 wrote:

> There are a lot of "Resolve for v1.0" issues open against the spec still. Are 
> we sure we want to brand this as 1.0? It will end up as such in the ELF 
> attributes and thus be deemed compatible with future "real" 1.0 binaries.

We could keep the version number as v0.9 or do you think it is better to keep 
it as v1.020201218.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94583

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


[PATCH] D95159: [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-01-21 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 318335.
akyrtzi edited the summary of this revision.
akyrtzi added a comment.

Fix typo in commit message, 'state' -> 'stale'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95159

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/CompilerInstance.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/ChainedIncludesSource.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Index/Inputs/preamble-reparse-changed-module/head.h
  clang/test/Index/Inputs/preamble-reparse-changed-module/module.modulemap
  clang/test/Index/Inputs/preamble-reparse-changed-module/new-head.h
  clang/test/Index/preamble-reparse-changed-module.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/c-index-test/core_main.cpp

Index: clang/tools/c-index-test/core_main.cpp
===
--- clang/tools/c-index-test/core_main.cpp
+++ clang/tools/c-index-test/core_main.cpp
@@ -13,22 +13,25 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexingAction.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/PrettyStackTrace.h"
 
 using namespace clang;
 using namespace clang::index;
 using namespace llvm;
 
 extern "C" int indextest_core_main(int argc, const char **argv);
+extern "C" int indextest_perform_shell_execution(const char *command_line);
 
 namespace {
 
@@ -359,3 +362,21 @@
 
   return 0;
 }
+
+//===--===//
+// Utility functions
+//===--===//
+
+int indextest_perform_shell_execution(const char *command_line) {
+  BumpPtrAllocator Alloc;
+  llvm::StringSaver Saver(Alloc);
+  SmallVector Args;
+  llvm::cl::TokenizeGNUCommandLine(command_line, Saver, Args);
+  auto Program = llvm::sys::findProgramByName(Args[0]);
+  if (std::error_code ec = Program.getError()) {
+llvm::errs() << "command not found: " << Args[0] << "\n";
+return ec.value();
+  }
+  SmallVector execArgs(Args.begin(), Args.end());
+  return llvm::sys::ExecuteAndWait(*Program, execArgs);
+}
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -24,6 +24,7 @@
 #endif
 
 extern int indextest_core_main(int argc, const char **argv);
+extern int indextest_perform_shell_execution(const char *command_line);
 
 /**/
 /* Utility functions. */
@@ -2095,6 +2096,8 @@
   enum CXErrorCode Err;
   int result, i;
   int trial;
+  int execute_after_trial = 0;
+  const char *execute_command = NULL;
   int remap_after_trial = 0;
   char *endptr = 0;
   
@@ -2133,12 +2136,26 @@
   if (checkForErrors(TU) != 0)
 return -1;
 
+  if (getenv("CINDEXTEST_EXECUTE_COMMAND")) {
+execute_command = getenv("CINDEXTEST_EXECUTE_COMMAND");
+  }
+  if (getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL")) {
+execute_after_trial =
+strtol(getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL"), , 10);
+  }
+
   if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
 remap_after_trial =
 strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), , 10);
   }
 
   for (trial = 0; trial < trials; ++trial) {
+if (execute_command && trial == execute_after_trial) {
+  result = indextest_perform_shell_execution(execute_command);
+  if (result != 0)
+return result;
+}
+
 free_remapped_files(unsaved_files, num_unsaved_files);
 if (parse_remapped_files_with_try(trial, argc, argv, 0,
   _files, _unsaved_files)) {
Index: clang/test/Index/preamble-reparse-changed-module.m
===
--- /dev/null
+++ clang/test/Index/preamble-reparse-changed-module.m
@@ -0,0 +1,18 @@
+// REQUIRES: shell
+
+// RUN: mkdir -p %t/mod
+// RUN: touch %t/empty.h
+// RUN: cp 

[PATCH] D95159: [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-01-21 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 318333.
akyrtzi added a comment.

Use `getValueOr`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95159

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/CompilerInstance.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/ChainedIncludesSource.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Index/Inputs/preamble-reparse-changed-module/head.h
  clang/test/Index/Inputs/preamble-reparse-changed-module/module.modulemap
  clang/test/Index/Inputs/preamble-reparse-changed-module/new-head.h
  clang/test/Index/preamble-reparse-changed-module.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/c-index-test/core_main.cpp

Index: clang/tools/c-index-test/core_main.cpp
===
--- clang/tools/c-index-test/core_main.cpp
+++ clang/tools/c-index-test/core_main.cpp
@@ -13,22 +13,25 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexingAction.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/PrettyStackTrace.h"
 
 using namespace clang;
 using namespace clang::index;
 using namespace llvm;
 
 extern "C" int indextest_core_main(int argc, const char **argv);
+extern "C" int indextest_perform_shell_execution(const char *command_line);
 
 namespace {
 
@@ -359,3 +362,21 @@
 
   return 0;
 }
+
+//===--===//
+// Utility functions
+//===--===//
+
+int indextest_perform_shell_execution(const char *command_line) {
+  BumpPtrAllocator Alloc;
+  llvm::StringSaver Saver(Alloc);
+  SmallVector Args;
+  llvm::cl::TokenizeGNUCommandLine(command_line, Saver, Args);
+  auto Program = llvm::sys::findProgramByName(Args[0]);
+  if (std::error_code ec = Program.getError()) {
+llvm::errs() << "command not found: " << Args[0] << "\n";
+return ec.value();
+  }
+  SmallVector execArgs(Args.begin(), Args.end());
+  return llvm::sys::ExecuteAndWait(*Program, execArgs);
+}
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -24,6 +24,7 @@
 #endif
 
 extern int indextest_core_main(int argc, const char **argv);
+extern int indextest_perform_shell_execution(const char *command_line);
 
 /**/
 /* Utility functions. */
@@ -2095,6 +2096,8 @@
   enum CXErrorCode Err;
   int result, i;
   int trial;
+  int execute_after_trial = 0;
+  const char *execute_command = NULL;
   int remap_after_trial = 0;
   char *endptr = 0;
   
@@ -2133,12 +2136,26 @@
   if (checkForErrors(TU) != 0)
 return -1;
 
+  if (getenv("CINDEXTEST_EXECUTE_COMMAND")) {
+execute_command = getenv("CINDEXTEST_EXECUTE_COMMAND");
+  }
+  if (getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL")) {
+execute_after_trial =
+strtol(getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL"), , 10);
+  }
+
   if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
 remap_after_trial =
 strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), , 10);
   }
 
   for (trial = 0; trial < trials; ++trial) {
+if (execute_command && trial == execute_after_trial) {
+  result = indextest_perform_shell_execution(execute_command);
+  if (result != 0)
+return result;
+}
+
 free_remapped_files(unsaved_files, num_unsaved_files);
 if (parse_remapped_files_with_try(trial, argc, argv, 0,
   _files, _unsaved_files)) {
Index: clang/test/Index/preamble-reparse-changed-module.m
===
--- /dev/null
+++ clang/test/Index/preamble-reparse-changed-module.m
@@ -0,0 +1,18 @@
+// REQUIRES: shell
+
+// RUN: mkdir -p %t/mod
+// RUN: touch %t/empty.h
+// RUN: cp %S/Inputs/preamble-reparse-changed-module/module.modulemap %t/mod
+// RUN: cp 

[PATCH] D95168: Add InsertBraces option

2021-01-21 Thread Tiago Macarios via Phabricator via cfe-commits
tiagoma added a comment.

Some background might be useful. I work at Microsoft (Office to be precise). We 
have our own fork of LLVM internally and I am starting to upstream some of the 
changes in our fork.

> There's a clang-tidy check for it.

Yes - readability-braces-around-statements. I would argue that clang-tidy is a 
heavyweight tool for this.

> And clang-format should not, IMO, add not remove tokens but only handle 
> whitespace.

I don't think token operations are novel, see the `InsertTrailingCommas`, 
`JavaScriptQuotes`, `SortUsingDeclarations`, `FixNamespaceComments` options. 
Also, keep in mind that this option is fairly self contained (it happens before 
the `Formatter` pass) and it is off by default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D95181: [CodeGen][ObjC] Fix broken IR generated when there is a nil receiver check

2021-01-21 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

This looks good, but in the long term it would be great if we could eliminate 
the need for `emitARCOperationAfterCall` and just emit the call properly in the 
first place.

Please add a test where we have a null check around an `invoke`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95181

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


[PATCH] D94333: [Inliner] Change inline remark format and update ReplayInlineAdvisor to use it

2021-01-21 Thread Di Mo via Phabricator via cfe-commits
modimo added inline comments.



Comment at: llvm/lib/Analysis/InlineAdvisor.cpp:412
+
+  Remark << ";";
 }

wenlei wrote:
> modimo wrote:
> > wenlei wrote:
> > > nit: any special reason for adding this? doesn't seem consistent with 
> > > other remarks we have.
> > If you grab the remark outputs via `-Rpass=inline` you'll get additional 
> > suffix information:
> > ```
> > inline.cpp:8:12: remark: _Z3foov inlined into main with (cost=0, 
> > threshold=375) at callsite main:2:12; [-Rpass=inline]
> > return foo();
> > ```
> > 
> > The semicolon is to separate the remark from any additional output at the 
> > end so when replaying we can match the correct callsite. Something like 
> > this would be unneeded for yaml replay but for the current implementation 
> > it's necessary for correctness.
> > 
> By correctness, did you mean the fact that you rely on `split(";")` in 
> parsing, or something else?
> 
> This is not a big deal, but if no other remarks end with `;`, it would be 
> good to be consistent. Using `split(";")` for parsing is just one way of 
> implementing it, and IMO could be changed to favor consistency in remarks 
> output.
> By correctness, did you mean the fact that you rely on `split(";")` in 
> parsing, or something else?

Yeah, without that we would store the callsite from remarks as `main:2:12 
[-Rpass=inline]` which would not match the actual callsite string `main:2:12` 
that we query the map with which causes replay to never inline.

> This is not a big deal, but if no other remarks end with `;`, it would be 
> good to be consistent. Using `split(";")` for parsing is just one way of 
> implementing it, and IMO could be changed to favor consistency in remarks 
> output.

Doing a search query for `OptimizationRemarkAnalysis` I see vectorizer ORE uses 
"." for their terminator so switching to that is better consistency. I'll make 
the change in an upcoming patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94333

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


[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2021-01-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2342
+attrs = attrs.addAttribute(CGF.getLLVMContext(),
+   llvm::AttributeList::ReturnIndex, "rv_marker");
+callBase->setAttributes(attrs);

ahatanak wrote:
> rjmccall wrote:
> > It's weird that these attributes use two different capitalization styles.  
> > Also, why are they both needed?  Did you consider making the role 
> > (retain/claim) be the value of the attribute rather than a separate 
> > attribute?
> > 
> > Should the attribute be namespaced, like `clang.arc.rv_marker`?
> > 
> > Let's go ahead and add globals for these strings so we can refer to them 
> > symbolically, like you did with `retainRVMarkerKey`.  Is there an LLVM 
> > header for ARC optimization we could reasonably pull them from, or are we 
> > doomed to repeat ourselves across projects?
> I think you are asking why both `retain/claim` and `rv_marker` are needed? Or 
> are you asking why both 'retain' and 'claim' are needed?
> 
> We could do without `clang.arc.rv_marker` and just use 
> `clang.arc.rv=retain/claim` since the middle-end and backend passes can 
> easily determine whether a marker is needed or not. The only drawback to 
> using only `clang.arc.rv` I can think of is that it's no longer possible to 
> tell whether an instruction is implicitly followed by marker+retain/claimRV 
> or just the marker, which makes `Instruction::mayWriteToMemory` return a 
> conservative answer if the function call is read-only. A read-only call 
> cannot be treated as read-only if it's followed by marker+retain/claimRV, but 
> it is still read-only if it is followed just by the marker.
> 
> Note that ARC contract pass emits the retain/claimRV instruction into the IR 
> and drops the corresponding `clang.arc.rv` attribute but doesn't remove the 
> `clang.arc.rv_marker` attribute. So if we used only `clang.arc.rv`, a call 
> annotated with the attribute would be implicitly followed by 
> marker+retain/claimRV before ARC contract, while it would be followed by just 
> the marker after ARC contract, but `Instruction::mayWriteToMemory` wouldn't' 
> be able to tell the difference.
> I think you are asking why both retain/claim and rv_marker are needed?

Yes.

> We could do without clang.arc.rv_marker and just use 
> clang.arc.rv=retain/claim since the middle-end and backend passes can easily 
> determine whether a marker is needed or not. The only drawback to using only 
> clang.arc.rv I can think of is that it's no longer possible to tell whether 
> an instruction is implicitly followed by marker+retain/claimRV or just the 
> marker, which makes Instruction::mayWriteToMemory return a conservative 
> answer if the function call is read-only. A read-only call cannot be treated 
> as read-only if it's followed by marker+retain/claimRV, but it is still 
> read-only if it is followed just by the marker.

Is there a situation where we emit the marker but not a following call?  Or is 
that just in the places where we've already made the following call explicit in 
IR?  Because in the latter case, presumably the following call will still act 
as a barrier to anything that's querying `mayWriteToMemory`, right?  (That is: 
in general, I expect that nobody just asks whether a specific instruction can 
write to memory, they ask if any of the instructions in a region can write to 
memory, and since the following call can...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

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


[PATCH] D95181: [CodeGen][ObjC] Fix broken IR generated when there is a nil receiver check

2021-01-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
ahatanak added a project: clang.
Herald added subscribers: ributzka, jkorous.
ahatanak requested review of this revision.

This patch fixes a bug in `emitARCOperationAfterCall` where it inserts the 
fall-back call after a bitcast instruction and then replaces the bitcast's 
operand with the result of the fall-back call. The generated IR without this 
patch looks like this:

  msgSend.call: ; preds = %entry
%call = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, 
i8*, i8*)*)(i8* %6, i8* %5, i8* %4) #4, !clang.arc.no_objc_arc_exceptions !11
br label %msgSend.cont
  
  msgSend.null-receiver:; preds = %entry
call void @llvm.objc.release(i8* %4) #1, !clang.imprecise_release !11
br label %msgSend.cont
  
  msgSend.cont: ; preds = 
%msgSend.null-receiver, %msgSend.call
%8 = phi i8* [ %call, %msgSend.call ], [ null, %msgSend.null-receiver ]
%9 = bitcast i8* %10 to %0*
%10 = call i8* @llvm.objc.retain(i8* %8) #1

Notice that `%9 = bitcast i8* %10 to %0*` is taking operand `%10` which is 
defined after it.

To fix the bug, this patch modifies the insert point to point to the bitcast 
instruction so that the fall-back call is inserted before the bitcast. In 
addition, it teaches the function to look at phi instructions that are 
generated when there is a check for a null receiver and insert the 
retainRV/claimRV instruction right after the call instead of inserting a 
fall-back call right after the phi instruction.

rdar://73360225


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95181

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/ns_consume_null_check.m


Index: clang/test/CodeGenObjC/ns_consume_null_check.m
===
--- clang/test/CodeGenObjC/ns_consume_null_check.m
+++ clang/test/CodeGenObjC/ns_consume_null_check.m
@@ -7,6 +7,7 @@
 @interface MyObject : NSObject
 - (char)isEqual:(id) __attribute__((ns_consumed)) object;
 - (_Complex float) asComplexWithArg: (id) __attribute__((ns_consumed)) object;
++(instancetype)m0:(id) __attribute__((ns_consumed)) object;
 @end
 
 MyObject *x;
@@ -82,4 +83,15 @@
 // CHECK:  landingpad
 // CHECK:  call void @llvm.objc.destroyWeak(i8** [[WEAKOBJ]]) [[NUW]]
 
+void test2(id a) {
+  id obj = [MyObject m0:a];
+}
+
+// CHECK: define{{.*}} void @test2(i8* %[[A:.*]]) #0 {
+// CHECK: %[[CALL:.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
+// CHECK-NEXT: %[[V6:.*]] = {{.*}}call i8* 
@llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
+
+// CHECK: phi i8* [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
+
+
 // CHECK: attributes [[NUW]] = { nounwind }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2898,41 +2898,50 @@
   llvm::Value *value,
   ValueTransform doAfterCall,
   ValueTransform doFallback) {
-  if (llvm::CallInst *call = dyn_cast(value)) {
-CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
+  CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
 
+  if (llvm::CallInst *call = dyn_cast(value)) {
 // Place the retain immediately following the call.
 CGF.Builder.SetInsertPoint(call->getParent(),
++llvm::BasicBlock::iterator(call));
 value = doAfterCall(CGF, value);
-
-CGF.Builder.restoreIP(ip);
-return value;
   } else if (llvm::InvokeInst *invoke = dyn_cast(value)) {
-CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
-
 // Place the retain at the beginning of the normal destination block.
 llvm::BasicBlock *BB = invoke->getNormalDest();
 CGF.Builder.SetInsertPoint(BB, BB->begin());
 value = doAfterCall(CGF, value);
 
-CGF.Builder.restoreIP(ip);
-return value;
-
   // Bitcasts can arise because of related-result returns.  Rewrite
   // the operand.
   } else if (llvm::BitCastInst *bitcast = dyn_cast(value)) {
+// Change the insert point to avoid emitting the fall-back call after the
+// bitcast.
+CGF.Builder.SetInsertPoint(bitcast->getParent(), bitcast->getIterator());
 llvm::Value *operand = bitcast->getOperand(0);
 operand = emitARCOperationAfterCall(CGF, operand, doAfterCall, doFallback);
 bitcast->setOperand(0, operand);
-return bitcast;
-
-  // Generic fall-back case.
+value = bitcast;
   } else {
-// Retain using the non-block variant: we never need to do a copy
-// of a block that's been returned to us.
-return doFallback(CGF, value);
+auto *phi = dyn_cast(value);
+if (phi && phi->getNumIncomingValues() == 2 &&
+isa(phi->getIncomingValue(1)) &&
+

[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2021-01-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2342
+attrs = attrs.addAttribute(CGF.getLLVMContext(),
+   llvm::AttributeList::ReturnIndex, "rv_marker");
+callBase->setAttributes(attrs);

rjmccall wrote:
> It's weird that these attributes use two different capitalization styles.  
> Also, why are they both needed?  Did you consider making the role 
> (retain/claim) be the value of the attribute rather than a separate attribute?
> 
> Should the attribute be namespaced, like `clang.arc.rv_marker`?
> 
> Let's go ahead and add globals for these strings so we can refer to them 
> symbolically, like you did with `retainRVMarkerKey`.  Is there an LLVM header 
> for ARC optimization we could reasonably pull them from, or are we doomed to 
> repeat ourselves across projects?
I think you are asking why both `retain/claim` and `rv_marker` are needed? Or 
are you asking why both 'retain' and 'claim' are needed?

We could do without `clang.arc.rv_marker` and just use 
`clang.arc.rv=retain/claim` since the middle-end and backend passes can easily 
determine whether a marker is needed or not. The only drawback to using only 
`clang.arc.rv` I can think of is that it's no longer possible to tell whether 
an instruction is implicitly followed by marker+retain/claimRV or just the 
marker, which makes `Instruction::mayWriteToMemory` return a conservative 
answer if the function call is read-only. A read-only call cannot be treated as 
read-only if it's followed by marker+retain/claimRV, but it is still read-only 
if it is followed just by the marker.

Note that ARC contract pass emits the retain/claimRV instruction into the IR 
and drops the corresponding `clang.arc.rv` attribute but doesn't remove the 
`clang.arc.rv_marker` attribute. So if we used only `clang.arc.rv`, a call 
annotated with the attribute would be implicitly followed by 
marker+retain/claimRV before ARC contract, while it would be followed by just 
the marker after ARC contract, but `Instruction::mayWriteToMemory` wouldn't' be 
able to tell the difference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

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


[PATCH] D95017: [clang-format] add case aware include sorting

2021-01-21 Thread Kent Sommer via Phabricator via cfe-commits
kentsommer added a comment.

I do not have commit access.

Full Name: Kent Sommer
Email: w...@kentsommer.com


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95017

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


[clang] 1deee5c - Fix crash when emitting NullReturn guards for functions returning BOOL

2021-01-21 Thread Jon Roelofs via cfe-commits

Author: Jon Roelofs
Date: 2021-01-21T14:29:36-08:00
New Revision: 1deee5cacbb76578367186d7ff2937b6fa79b827

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

LOG: Fix crash when emitting NullReturn guards for functions returning BOOL

CodeGenModule::EmitNullConstant() creates constants with their "in memory"
type, not their "in vregs" type. The one place where this difference matters is
when the type is _Bool, as that is an i1 when in vregs and an i8 in memory.

Fixes: rdar://73361264

Added: 
clang/test/CodeGenObjC/null-check-bool-ret.m

Modified: 
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 465d2c5449d5..4c4a316308ce 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1800,7 +1800,8 @@ struct NullReturnState {
 // If we've got a scalar return, build a phi.
 if (result.isScalar()) {
   // Derive the null-initialization value.
-  llvm::Constant *null = CGF.CGM.EmitNullConstant(resultType);
+  llvm::Value *null =
+  CGF.EmitFromMemory(CGF.CGM.EmitNullConstant(resultType), resultType);
 
   // If no join is necessary, just flow out.
   if (!contBB) return RValue::get(null);

diff  --git a/clang/test/CodeGenObjC/null-check-bool-ret.m 
b/clang/test/CodeGenObjC/null-check-bool-ret.m
new file mode 100644
index ..db9b40efec1b
--- /dev/null
+++ b/clang/test/CodeGenObjC/null-check-bool-ret.m
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple arm64e-apple-ios15.0.0 -emit-llvm-bc -fobjc-arc 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
+
+// rdar://73361264
+
+@protocol NSObject
+@end
+
+@interface NSObject 
+@end
+
+@interface WidgetTester : NSObject
+@end
+
+@implementation WidgetTester
+
+typedef struct {
+NSObject* impl;
+} widget_t;
+
+- (_Bool)withWidget:(widget_t)widget {
+return 0;
+}
+
+- (_Bool)testWidget:(widget_t)widget {
+return [self withWidget:widget];
+}
+
+@end
+
+// CHECK-LABEL: msgSend.call:
+// CHECK: [[CALL:%[^ ]+]] = call i1 bitcast (i8* (i8*, i8*, ...)* 
@objc_msgSend to
+// CHECK-NEXT: br label %msgSend.cont
+
+// CHECK-LABEL: msgSend.null-receiver:
+// CHECK: br label %msgSend.cont
+
+// CHECK-LABEL: msgSend.cont:
+// CHECK-NEXT: {{%[^ ]+}} = phi i1 [ [[CALL]], %msgSend.call ], [ false, 
%msgSend.null-receiver ]



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


[PATCH] D95081: [clang-format] [NFC] Restructure getLineCommentIndentPrefix

2021-01-21 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

Just an assert is ok IMO. We may fix it when LLVM will be compiled with C++20 
but this code may change before it happens.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95081

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


[PATCH] D95128: [clang-format] [NFC] Remove unsued arguments

2021-01-21 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks for tidying up!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95128

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


[PATCH] D95168: Add InsertBraces option

2021-01-21 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

There's a clang-tidy check for it.
And clang-format should not, IMO, add not remove tokens but only handle 
whitespace.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D94942: [clangd] Add tweak for implementing abstract class

2021-01-21 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ImplementAbstract.cpp:38-40
+  // If we have any pure virtual methods declared in the root (The class
+  // this tweak was invoked on), assume the user probably doesn't want to
+  // implement all abstract methods as the class will still be astract.

Is this a good behaviour, or should we still offer the tweak, even knowing that 
applying it will still result in the class being marked as abstract?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94942

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


[PATCH] D94942: [clangd] Add tweak for implementing abstract class

2021-01-21 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 318315.
njames93 added a comment.

Split up the code a little more. Fix a few malformed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94942

Files:
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ImplementAbstract.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/tweaks/ImplementAbstractTests.cpp
@@ -0,0 +1,349 @@
+//===-- ImplementAbstractTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestTU.h"
+#include "TweakTesting.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using ::testing::Not;
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TWEAK_TEST(ImplementAbstract);
+
+TEST_F(ImplementAbstractTest, TestUnavailable) {
+
+  StringRef Cases[]{
+  // Not a pure virtual method.
+  R"cpp(
+  class A {
+virtual void Foo();
+  };
+  class ^B : public A {};
+)cpp",
+  // Pure virtual method overridden in class.
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+void Foo() override;
+  };
+)cpp",
+  // Pure virtual method overridden in class with virtual keyword
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+virtual void Foo() override;
+  };
+)cpp",
+  // Pure virtual method overridden in class without override keyword
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class ^B : public A {
+void Foo();
+  };
+)cpp",
+  // Pure virtual method overriden in base class.
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };
+  class B : public A {
+void Foo() override;
+  };
+  class ^C : public B {
+  };
+)cpp"};
+  for (const auto  : Cases) {
+EXPECT_THAT(Case, Not(isAvailable()));
+  }
+}
+
+TEST_F(ImplementAbstractTest, NormalAvailable) {
+  struct Case {
+llvm::StringRef TestHeader;
+llvm::StringRef TestSource;
+llvm::StringRef ExpectedSource;
+  };
+
+  Case Cases[]{
+  {
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };)cpp",
+  R"cpp(
+  class B : public A {^};
+)cpp",
+  R"cpp(
+  class B : public A {
+void Foo() override;
+};
+)cpp",
+  },
+  {
+  R"cpp(
+  class A {
+public:
+virtual void Foo() = 0;
+  };)cpp",
+  R"cpp(
+  class ^B : public A {};
+)cpp",
+  R"cpp(
+  class B : public A {
+public:
+
+void Foo() override;
+};
+)cpp",
+  },
+  {
+  R"cpp(
+  class A {
+virtual void Foo(int Param) = 0;
+  };)cpp",
+  R"cpp(
+  class ^B : public A {};
+)cpp",
+  R"cpp(
+  class B : public A {
+void Foo(int Param) override;
+};
+)cpp",
+  },
+  {
+  R"cpp(
+  class A {
+virtual void Foo(int Param) = 0;
+  };)cpp",
+  R"cpp(
+  struct ^B : public A {};
+)cpp",
+  R"cpp(
+  struct B : public A {
+private:
+
+void Foo(int Param) override;
+};
+)cpp",
+  },
+  {
+  R"cpp(
+  class A {
+virtual void Foo(int Param) const volatile = 0;
+public:
+virtual void Bar(int Param) = 0;
+  };)cpp",
+  R"cpp(
+  class ^B : public A {
+void Foo(int Param) const volatile override;
+  };
+)cpp",
+  R"cpp(
+  class B : public A {
+void Foo(int Param) const volatile override;
+  
+public:
+
+void Bar(int Param) override;
+};
+)cpp",
+  },
+  {
+  R"cpp(
+   class A {
+virtual void Foo() = 0;
+virtual void Bar() = 0;
+  };
+  class B : public A {
+void Foo() override;
+  };
+)cpp",
+  R"cpp(
+  class ^C : public B {
+virtual void Baz();
+  };
+)cpp",
+  R"cpp(
+  class C : public B {
+virtual void Baz();
+void Bar() override;
+
+  };
+)cpp",
+  },
+  {
+  R"cpp(
+  class A {
+virtual void Foo() = 0;
+  };)cpp",
+  R"cpp(
+  class ^B : public A {
+~B();
+  

[PATCH] D95159: [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-01-21 Thread Ben Barham via Phabricator via cfe-commits
bnbarham accepted this revision.
bnbarham added a comment.
This revision is now accepted and ready to land.

LGTM, just the one minor comment




Comment at: clang/lib/Serialization/ASTReader.cpp:2221-
+  // validation for the PCH and the modules it loads.
+  ModuleKind K = CurrentDeserializingModuleKind.hasValue() ?
+ CurrentDeserializingModuleKind.getValue() : M.Kind;
+

There's a `getValueOr` method that you could use instead (ie. 
`CurrentDeserializingModuleKind.getValueOr(M.Kind)`).



Comment at: clang/test/Index/preamble-reparse-changed-module.m:8
+
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_EXECUTE_COMMAND="cp 
%S/Inputs/preamble-reparse-changed-module/new-head.h %t/mod/head.h" 
CINDEXTEST_EXECUTE_AFTER_TRIAL=1 \
+// RUN: c-index-test -test-load-source-reparse 3 local %s -I %t -I %t/mod 
-fmodules -fmodules-cache-path=%t/mcp 2>&1 | FileCheck %s

For some reason I was expecting the trial's to be 1 based, not 0. I'm not sure 
why though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95159

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


LLVM buildmaster will be restarted tonight

2021-01-21 Thread Galina Kistanova via cfe-commits
 Hello everyone,

LLVM buildmaster will be restarted at 6PM PST today.

Thanks

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


[PATCH] D95159: [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-01-21 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 318314.
akyrtzi added a comment.

clang-format changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95159

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/CompilerInstance.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/ChainedIncludesSource.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Index/Inputs/preamble-reparse-changed-module/head.h
  clang/test/Index/Inputs/preamble-reparse-changed-module/module.modulemap
  clang/test/Index/Inputs/preamble-reparse-changed-module/new-head.h
  clang/test/Index/preamble-reparse-changed-module.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/c-index-test/core_main.cpp

Index: clang/tools/c-index-test/core_main.cpp
===
--- clang/tools/c-index-test/core_main.cpp
+++ clang/tools/c-index-test/core_main.cpp
@@ -13,22 +13,25 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexingAction.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/PrettyStackTrace.h"
 
 using namespace clang;
 using namespace clang::index;
 using namespace llvm;
 
 extern "C" int indextest_core_main(int argc, const char **argv);
+extern "C" int indextest_perform_shell_execution(const char *command_line);
 
 namespace {
 
@@ -359,3 +362,21 @@
 
   return 0;
 }
+
+//===--===//
+// Utility functions
+//===--===//
+
+int indextest_perform_shell_execution(const char *command_line) {
+  BumpPtrAllocator Alloc;
+  llvm::StringSaver Saver(Alloc);
+  SmallVector Args;
+  llvm::cl::TokenizeGNUCommandLine(command_line, Saver, Args);
+  auto Program = llvm::sys::findProgramByName(Args[0]);
+  if (std::error_code ec = Program.getError()) {
+llvm::errs() << "command not found: " << Args[0] << "\n";
+return ec.value();
+  }
+  SmallVector execArgs(Args.begin(), Args.end());
+  return llvm::sys::ExecuteAndWait(*Program, execArgs);
+}
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -24,6 +24,7 @@
 #endif
 
 extern int indextest_core_main(int argc, const char **argv);
+extern int indextest_perform_shell_execution(const char *command_line);
 
 /**/
 /* Utility functions. */
@@ -2095,6 +2096,8 @@
   enum CXErrorCode Err;
   int result, i;
   int trial;
+  int execute_after_trial = 0;
+  const char *execute_command = NULL;
   int remap_after_trial = 0;
   char *endptr = 0;
   
@@ -2133,12 +2136,26 @@
   if (checkForErrors(TU) != 0)
 return -1;
 
+  if (getenv("CINDEXTEST_EXECUTE_COMMAND")) {
+execute_command = getenv("CINDEXTEST_EXECUTE_COMMAND");
+  }
+  if (getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL")) {
+execute_after_trial =
+strtol(getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL"), , 10);
+  }
+
   if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
 remap_after_trial =
 strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), , 10);
   }
 
   for (trial = 0; trial < trials; ++trial) {
+if (execute_command && trial == execute_after_trial) {
+  result = indextest_perform_shell_execution(execute_command);
+  if (result != 0)
+return result;
+}
+
 free_remapped_files(unsaved_files, num_unsaved_files);
 if (parse_remapped_files_with_try(trial, argc, argv, 0,
   _files, _unsaved_files)) {
Index: clang/test/Index/preamble-reparse-changed-module.m
===
--- /dev/null
+++ clang/test/Index/preamble-reparse-changed-module.m
@@ -0,0 +1,18 @@
+// REQUIRES: shell
+
+// RUN: mkdir -p %t/mod
+// RUN: touch %t/empty.h
+// RUN: cp %S/Inputs/preamble-reparse-changed-module/module.modulemap %t/mod
+// RUN: cp 

[PATCH] D95154: [WIP][clang][Fuchsia] Add the *-fuchsia-gnu arch and multilibs

2021-01-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/cmake/caches/Fuchsia-stage2.cmake:148
+
+  foreach(name i386;x86_64;aarch64;riscv64;x86_64_gnu;aarch64_gnu)
+if(${name} MATCHES ".*_gnu$")

I'd just iterate over full triples rather than doing the `.*_gnu` replacement, 
see above what we do for Linux. The same below.



Comment at: clang/cmake/caches/Fuchsia-stage2.cmake:219-236
+set(RUNTIMES_${target}+noexcept_LLVM_BUILD_COMPILER_RT OFF CACHE BOOL "")
+set(RUNTIMES_${target}+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL 
"")
+set(RUNTIMES_${target}+noexcept_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
+
+set(RUNTIMES_${target}+asan+noexcept_LLVM_BUILD_COMPILER_RT OFF CACHE BOOL 
"")
+set(RUNTIMES_${target}+asan+noexcept_LLVM_USE_SANITIZER "Address" CACHE 
STRING "")
+
set(RUNTIMES_${target}+asan+noexcept_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS 
OFF CACHE BOOL "")

I'd break this off into a separate `foreach` loop and only do it for the 
non-GNU variant.



Comment at: clang/test/Driver/fuchsia.cpp:104-119
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTIARCH-X86-GNU
+// RUN: %clangxx %s -### --target=x86_64-fuchsia-gnu -fsanitize=address \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s 
-check-prefixes=CHECK-MULTIARCH-X86-GNU,CHECK-MULTIARCH-ASAN-X86-GNU
+// RUN: %clangxx %s -### --target=x86_64-fuchsia-gnu -fno-exceptions \

I don't think we need these multilibs for the GNU variant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95154

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


[PATCH] D93668: [clang] Override the Fuchsia platform ABI using the triple environment

2021-01-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek 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/D93668/new/

https://reviews.llvm.org/D93668

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


[PATCH] D93668: [clang] Override the Fuchsia platform ABI using the triple environment

2021-01-21 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I guess the spelling -fc++-abi= is intuitive, discoverable, and easy to use. 
I'd be OK going back to that, as long as the compiler knows which ABIs work on 
which targets and rejects the unsupported configurations.

Regarding the idea of separating the platform ABI from the C++ ABI, I can't say 
I really believe in the idea of language neutral platform ABIs. The platform 
ABI always incorporates aspects of the most widely used source languages, 
typically C. This is where LLVM gets into trouble when non-C frontends want to 
pass _Complex values or structs as arguments, for example. Whether you think of 
C++ features as being part of the platform or not probably depends on your view 
on whether C++ support is a critical part of the platform. I tend to think of 
C++ as pretty critical, but I'm a C++ programmer working on C++ ABI support, so 
that's my view.

Regarding reducing global ABI switches, yes, I would like to minimize them. We 
have many, and they have costs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93668

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


[PATCH] D95070: Fix crash when emitting NullReturn guards for functions returning BOOL

2021-01-21 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Oops.  LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95070

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


[PATCH] D95099: [clang-scan-deps] : Support -- in clang command lines.

2021-01-21 Thread Sylvain Audi via Phabricator via cfe-commits
saudi added inline comments.



Comment at: clang/test/ClangScanDeps/Inputs/regular_cdb.json:12-16
 {
   "directory": "DIR",
-  "command": "clang -E DIR/regular_cdb_input.cpp -IInputs -o adena.o",
+  "command": "clang -E -IInputs -o adena.o -- DIR/regular_cdb_input.cpp",
   "file": "DIR/regular_cdb_input.cpp"
 }

dexonsmith wrote:
> It's not obvious to me how this exercises the new `-resource-dir` logic. Can 
> you walk me through it?
clang tools like `clang-scan-deps` may edit the provided clang command line, 
especially to override the resource directory with their own default value in 
case it is not found as an argument.

This patch avoids inserting new arguments after `--`, since they would be 
wrongly interpreted as extra input files.

By adding `--` in this test, we broadly verify that no argument inserted by 
`clang-scan-deps` is treated as an extra input file. `-resource-dir` is merely 
one possible case. 

Note that `-resource-dir` case is a bit special: `clang-scan-deps` will first 
try to force its value using the result of `clang -print-resource-dir`  (see 
`ClangScanDeps.cpp`).
Yet, this heuristic may fail (and it does in this clang-scan-deps test, where 
the clang command is not given as an absolute path). In that case `ClangTool` 
will also try to add `-resource-dir` (see `Tooling.cpp`).





Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:480
 }
+AdjustedArgs.insert(AdjustedArgs.end(), ArgsEnd, Args.end());
 return AdjustedArgs;

dexonsmith wrote:
> Can we use `AdjustedArgs.append(LastFlag, Args.end())` here?
`AdjustedArgs` is of type `tooling::CommandLineArguments` which inherits from 
`std::vector`, it doesn't have `append()`.


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

https://reviews.llvm.org/D95099

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


[PATCH] D95099: [clang-scan-deps] : Support -- in clang command lines.

2021-01-21 Thread Sylvain Audi via Phabricator via cfe-commits
saudi updated this revision to Diff 318304.
saudi marked 5 inline comments as done.
saudi added a comment.

Updated for suggested modifications


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

https://reviews.llvm.org/D95099

Files:
  clang/lib/Tooling/Tooling.cpp
  clang/test/ClangScanDeps/Inputs/regular_cdb.json
  clang/tools/clang-scan-deps/ClangScanDeps.cpp


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -421,14 +421,18 @@
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
+auto FlagsEnd = llvm::find(Args, "--");
+
 // We need to find the last -o value.
-if (!Args.empty()) {
-  std::size_t Idx = Args.size() - 1;
-  for (auto It = Args.rbegin(); It != Args.rend(); ++It) {
-StringRef Arg = Args[Idx];
+if (FlagsEnd != Args.begin()) {
+  // Reverse scan, starting at the end or at the element before "--".
+  for (auto RB = llvm::make_reverse_iterator(FlagsEnd), RI = RB,
+RE = Args.rend();
+   RI != RE; ++RI) {
+StringRef Arg = *RI;
 if (LastO.empty()) {
-  if (Arg == "-o" && It != Args.rbegin())
-LastO = Args[Idx + 1];
+  if (Arg == "-o" && RI != RB)
+LastO = RI[-1]; // Next argument (reverse iterator)
   else if (Arg.startswith("-o"))
 LastO = Arg.drop_front(2).str();
 }
@@ -440,12 +444,11 @@
   HasMD = true;
 if (Arg == "-resource-dir")
   HasResourceDir = true;
---Idx;
   }
 }
 // If there's no -MT/-MQ Driver would add -MT with the value of the 
last
 // -o option.
-tooling::CommandLineArguments AdjustedArgs = Args;
+tooling::CommandLineArguments AdjustedArgs(Args.begin(), FlagsEnd);
 AdjustedArgs.push_back("-o");
 AdjustedArgs.push_back("/dev/null");
 if (!HasMT && !HasMQ) {
@@ -475,6 +478,7 @@
 AdjustedArgs.push_back(std::string(ResourceDir));
   }
 }
+AdjustedArgs.insert(AdjustedArgs.end(), FlagsEnd, Args.end());
 return AdjustedArgs;
   });
   AdjustingCompilations->appendArgumentsAdjuster(
Index: clang/test/ClangScanDeps/Inputs/regular_cdb.json
===
--- clang/test/ClangScanDeps/Inputs/regular_cdb.json
+++ clang/test/ClangScanDeps/Inputs/regular_cdb.json
@@ -11,7 +11,7 @@
 },
 {
   "directory": "DIR",
-  "command": "clang -E DIR/regular_cdb_input.cpp -IInputs -o adena.o",
+  "command": "clang -E -IInputs -o adena.o -- DIR/regular_cdb_input.cpp",
   "file": "DIR/regular_cdb_input.cpp"
 }
 ]
Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -435,13 +435,22 @@
 static void injectResourceDir(CommandLineArguments , const char *Argv0,
   void *MainAddr) {
   // Allow users to override the resource dir.
-  for (StringRef Arg : Args)
+  // Don't search/inject past "--", as the subsequent arguments are only file
+  // names.
+  auto FlagsEnd = Args.end();
+  for (auto B = Args.begin(), I = B, E = Args.end(); I != E; ++I) {
+StringRef Arg = *I;
+if (Arg == "--") {
+  FlagsEnd = I;
+  break;
+}
 if (Arg.startswith("-resource-dir"))
   return;
+  }
 
   // If there's no override in place add our resource dir.
-  Args.push_back("-resource-dir=" +
- CompilerInvocation::GetResourcesPath(Argv0, MainAddr));
+  Args.insert(FlagsEnd, "-resource-dir=" + 
CompilerInvocation::GetResourcesPath(
+   Argv0, MainAddr));
 }
 
 int ClangTool::run(ToolAction *Action) {


Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -421,14 +421,18 @@
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
+auto FlagsEnd = llvm::find(Args, "--");
+
 // We need to find the last -o value.
-if (!Args.empty()) {
-  std::size_t Idx = Args.size() - 1;
-  for (auto It = Args.rbegin(); It != Args.rend(); ++It) {
-StringRef Arg = Args[Idx];
+if (FlagsEnd != Args.begin()) {
+  // Reverse scan, starting at the end or at the element before "--".
+  for (auto RB = llvm::make_reverse_iterator(FlagsEnd), RI = RB,
+RE = Args.rend();
+   RI != RE; ++RI) {
+StringRef Arg = *RI;
 if 

[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2021-01-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Okay, so it's important that we emit both attributes?  I'll take your word for 
it.




Comment at: llvm/include/llvm/Analysis/ObjCARCRVAttr.h:56
+  if (hasRetainRVOrClaimRVAttr(CB))
+CB->removeAttribute(llvm::AttributeList::ReturnIndex, getRVAttrKeyStr());
+

This is just doing the lookup twice, right?  You can just unconditionally 
remove the attribute, here and below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

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


[PATCH] D95007: [CUDA][HIP] Add -fuse-cuid

2021-01-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:2307
+  // Only alphanumeric and underscore is allowed in -cuid option.
+  if (auto *A = Args.getLastArg(OPT_cuid_EQ)) {
+const char *V = A->getValue();

tra wrote:
> JonChesterfield wrote:
> > Why this limitation? In particular I can imagine people using an id based 
> > on a filesystem location, which introduces /\:. and possibly other 
> > characters.
> I guess one of the reasons is that CUID is used to create unique externally 
> visible symbol names, so the charset is sort of the lowest common denominator 
> that could be directly used in the symbol name.
> 
> We could work around that by accepting an arbitrary string as a CUID and then 
> using its hash to create unique stable suffix.
will remove the check and use hash for suffix.


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

https://reviews.llvm.org/D95007

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


[PATCH] D92136: [clang] Enhanced test for --relocatable-pch, and corresponding fixes for Windows

2021-01-21 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Seems reasonable




Comment at: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp:534
 
+#ifdef _WIN32
+// Support special case of Windows absolute file paths

rnk wrote:
> I think looking for a slash after the colon is a bit more robust, and worth 
> doing. `[a-zA-Z]:[/\\]`
I'm trying to imagine a use case where the user might be validating diagnostics 
generated with a Windows style virtual filesystem, but I can't think of how 
that could happen.

In any case, I think we should drop the ifdef, and just do the special case on 
all platforms, especially if you tighten it up with the slash check.



Comment at: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp:534-537
+#ifdef _WIN32
+// Support special case of Windows absolute file paths
+if (Filename.size() == 1 && isLetter(Filename.front()) &&
+PH.Search(":")) {

I think looking for a slash after the colon is a bit more robust, and worth 
doing. `[a-zA-Z]:[/\\]`



Comment at: llvm/unittests/Support/Path.cpp:1477
 
+TEST(Support, StartsWith) {
+  EXPECT_FALSE(starts_with("/foo/bar", "/bar", path::Style::posix));

Thank you for adding unit tests!


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

https://reviews.llvm.org/D92136

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


[PATCH] D95168: Add InsertBraces option

2021-01-21 Thread Tiago Macarios via Phabricator via cfe-commits
tiagoma created this revision.
tiagoma requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

InsertBraces will insert braces for single line control flow statements 
(currently if/else/for).
It currently accepts the following options:

- Never - Keeps the current behavior and never add braces (also default value)
- Always - Always add braces to single lines after the control flow statement
- WrapLikely - If the line after the control flow statement is not braced and 
likely to wrap, braces will be  added


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95168

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -14749,6 +14749,12 @@
   CHECK_PARSE("IndentExternBlock: false", IndentExternBlock,
   FormatStyle::IEBS_NoIndent);
 
+  Style.InsertBraces = FormatStyle::BIS_Never;
+  CHECK_PARSE("InsertBraces: Always", InsertBraces, FormatStyle::BIS_Always);
+  CHECK_PARSE("InsertBraces: WrapLikely", InsertBraces,
+  FormatStyle::BIS_WrapLikely);
+  CHECK_PARSE("InsertBraces: Never", InsertBraces, FormatStyle::BIS_Never);
+
   Style.BitFieldColonSpacing = FormatStyle::BFCS_None;
   CHECK_PARSE("BitFieldColonSpacing: Both", BitFieldColonSpacing,
   FormatStyle::BFCS_Both);
@@ -17890,6 +17896,105 @@
 "}",
 format(Source, Style));
 }
+
+TEST_F(FormatTest, InsertBraces) {
+  FormatStyle Style = getLLVMStyle();
+  StringRef IfSourceShort = "if (condition)\n"
+"  call_function(arg, arg);";
+  EXPECT_EQ(IfSourceShort, format(IfSourceShort, Style));
+
+  StringRef IfSourceLong = "if (condition)\n"
+   "  call_function(arg, arg, arg, arg, arg, arg);";
+  EXPECT_EQ(IfSourceLong, format(IfSourceLong, Style));
+
+  StringRef IfElseSourceShort = "if (condition)\n"
+"  a_function(arg, arg);\n"
+"else\n"
+"  another_function(arg, arg);";
+  EXPECT_EQ(IfElseSourceShort, format(IfElseSourceShort, Style));
+
+  StringRef IfElseSourceLong =
+  "if (condition)\n"
+  "  a_function(arg, arg, arg, arg, arg, arg);\n"
+  "else\n"
+  "  another_function(arg, arg, arg, arg, arg, arg);";
+  EXPECT_EQ(IfElseSourceLong, format(IfElseSourceLong, Style));
+
+  StringRef ForSourceShort = "for (auto val : container)\n"
+ "  call_function(arg, arg);";
+  EXPECT_EQ(ForSourceShort, format(ForSourceShort, Style));
+
+  StringRef ForSourceLong = "for (auto val : container)\n"
+"  call_function(arg, arg, arg, arg, arg, arg);";
+  EXPECT_EQ(ForSourceLong, format(ForSourceLong, Style));
+
+  Style.InsertBraces = FormatStyle::BIS_Always;
+
+  EXPECT_EQ("if (condition) {\n"
+"  call_function(arg, arg);\n"
+"}",
+format(IfSourceShort, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  call_function(arg, arg, arg, arg, arg, arg);\n"
+"}",
+format(IfSourceLong, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  a_function(arg, arg);\n"
+"} else {\n"
+"  another_function(arg, arg);\n"
+"}",
+format(IfElseSourceShort, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  a_function(arg, arg, arg, arg, arg, arg);\n"
+"} else {\n"
+"  another_function(arg, arg, arg, arg, arg, arg);\n"
+"}",
+format(IfElseSourceLong, Style));
+
+  EXPECT_EQ("for (auto val : container) {\n"
+"  call_function(arg, arg);\n"
+"}",
+format(ForSourceShort, Style));
+
+  EXPECT_EQ("for (auto val : container) {\n"
+"  call_function(arg, arg, arg, arg, arg, arg);\n"
+"}",
+format(ForSourceLong, Style));
+
+  Style.InsertBraces = FormatStyle::BIS_WrapLikely;
+  Style.ColumnLimit = 35;
+
+  EXPECT_EQ(IfSourceShort, format(IfSourceShort, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  call_function(arg, arg, arg, arg,\n"
+"arg, arg);\n"
+"}",
+format(IfSourceLong, Style));
+
+  EXPECT_EQ(IfElseSourceShort, format(IfElseSourceShort, Style));
+
+  EXPECT_EQ("if (condition) {\n"
+"  a_function(arg, arg, arg, arg,\n"
+" arg, arg);\n"
+"} else {\n"
+"  another_function(arg, arg, arg,\n"
+"   arg, arg, arg);\n"
+"}",
+format(IfElseSourceLong, Style));
+
+  EXPECT_EQ(ForSourceShort, format(ForSourceShort, Style));
+
+  

[PATCH] D95166: Disable rosegment for old Android versions.

2021-01-21 Thread Dan Albert via Phabricator via cfe-commits
danalbert created this revision.
danalbert added a reviewer: srhines.
danalbert added a project: clang.
danalbert requested review of this revision.

The unwinder used by the crash handler on versions of Android prior to
API 29 did not correctly handle binaries built with rosegment, which is
enabled by default for LLD. Android only supports LLD, so it's not an
issue that this flag is not accepted by other linkers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95166

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/linux-ld.c


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1089,6 +1089,20 @@
 // CHECK-ANDROID-HASH-STYLE-M: "{{.*}}ld{{(.exe)?}}"
 // CHECK-ANDROID-HASH-STYLE-M: "--hash-style=gnu"
 
+// Check that we pass --no-rosegment for pre-29 Android versions and do not for
+// 29+.
+// RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-linux-android28 \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-ROSEGMENT-28 %s
+// CHECK-ANDROID-ROSEGMENT-28: "{{.*}}ld{{(.exe)?}}"
+// CHECK-ANDROID-ROSEGMENT-28: "--no-rosegment"
+//
+// RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-linux-android29 \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-ROSEGMENT-29 %s
+// CHECK-ANDROID-ROSEGMENT-29: "{{.*}}ld{{(.exe)?}}"
+// CHECK-ANDROID-ROSEGMENT-29-NOT: "--no-rosegment"
+
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=armv7-linux-android21 \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NOEXECSTACK %s
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -236,6 +236,15 @@
 ExtraOpts.push_back("relro");
   }
 
+  if (Triple.isAndroid() && Triple.isAndroidVersionLT(29)) {
+// https://github.com/android/ndk/issues/1196
+// The unwinder used by the crash handler on versions of Android prior to
+// API 29 did not correctly handle binaries built with rosegment, which is
+// enabled by default for LLD. Android only supports LLD, so it's not an
+// issue that this flag is not accepted by other linkers.
+ExtraOpts.push_back("--no-rosegment");
+  }
+
   // Android ARM/AArch64 use max-page-size=4096 to reduce VMA usage. Note, lld
   // from 11 onwards default max-page-size to 65536 for both ARM and AArch64.
   if ((Triple.isARM() || Triple.isAArch64()) && Triple.isAndroid()) {


Index: clang/test/Driver/linux-ld.c
===
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -1089,6 +1089,20 @@
 // CHECK-ANDROID-HASH-STYLE-M: "{{.*}}ld{{(.exe)?}}"
 // CHECK-ANDROID-HASH-STYLE-M: "--hash-style=gnu"
 
+// Check that we pass --no-rosegment for pre-29 Android versions and do not for
+// 29+.
+// RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-linux-android28 \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-ROSEGMENT-28 %s
+// CHECK-ANDROID-ROSEGMENT-28: "{{.*}}ld{{(.exe)?}}"
+// CHECK-ANDROID-ROSEGMENT-28: "--no-rosegment"
+//
+// RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-linux-android29 \
+// RUN:   | FileCheck --check-prefix=CHECK-ANDROID-ROSEGMENT-29 %s
+// CHECK-ANDROID-ROSEGMENT-29: "{{.*}}ld{{(.exe)?}}"
+// CHECK-ANDROID-ROSEGMENT-29-NOT: "--no-rosegment"
+
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=armv7-linux-android21 \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NOEXECSTACK %s
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -236,6 +236,15 @@
 ExtraOpts.push_back("relro");
   }
 
+  if (Triple.isAndroid() && Triple.isAndroidVersionLT(29)) {
+// https://github.com/android/ndk/issues/1196
+// The unwinder used by the crash handler on versions of Android prior to
+// API 29 did not correctly handle binaries built with rosegment, which is
+// enabled by default for LLD. Android only supports LLD, so it's not an
+// issue that this flag is not accepted by other linkers.
+ExtraOpts.push_back("--no-rosegment");
+  }
+
   // Android ARM/AArch64 use max-page-size=4096 to reduce VMA usage. Note, lld
   // from 11 onwards default max-page-size to 65536 for both ARM and AArch64.
   if ((Triple.isARM() || Triple.isAArch64()) && Triple.isAndroid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94919: [clangd] Fix a crash when indexing invalid ObjC method declaration

2021-01-21 Thread David Goldman via Phabricator via cfe-commits
dgoldman added inline comments.



Comment at: 
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:1807-1811
+@interface Foo
+- (void)fun:(bool)foo
+  bar:(bool)bar,
+  baz:(bool)baz;
+@end

It's hard to tell what Clang makes of this, I think instead we should test out 
the root cause of this crash, IIUC, are the legacy C style parameters:

```
@interface Foo
- (void)func:(bool)foo, bool bar;
@end
```



Comment at: 
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:1816-1819
+  // We mostly care about not crashing, but verify that we didn't insert 
garbage
+  // about X too.
+  EXPECT_THAT(TU.headerSymbols(), Not(Contains(QName("X";
+}

We should verify the method name is exactly as expected but comment we mostly 
care about not crashing.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:3519
   PEnd = Method->param_end();
  P != PEnd; (void)++P, ++Idx) {
   if (Idx > 0) {

I think it might be simpler just to check the index:

```
unsigned NumSelectorArgs = Sel.getNumArgs();

P != PEnd && Idx < NumSelectorArgs
```

and note that we need to check this due to legacy use of C-style parameters in 
Objective-C method declarations which in practice only occurs due to typos



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94919

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


[PATCH] D95147: [clang][cli] Port visibility LangOptions to marshalling system

2021-01-21 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith 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/D95147/new/

https://reviews.llvm.org/D95147

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


[PATCH] D95161: [Clang][OpenMP][NVPTX] Replace `libomptarget-nvptx-path` with `libomptarget-nvptx-bc-path`

2021-01-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, JonChesterfield, ABataev.
Herald added subscribers: dang, guansong, yaxunl.
Herald added a reviewer: jansvoboda11.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

D94700  removed the static library so we no 
longer need to pass
`-llibomptarget-nvptx` to `nvlink`. Since the bitcode library is the only device
runtime for now, instead of emitting a warning when it is not found, an error
should be raised.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95161

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/openmp-offload-gpu.c

Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -34,22 +34,6 @@
 
 /// ###
 
-/// Check that -lomptarget-nvptx is passed to nvlink.
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp \
-// RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHK-NVLINK %s
-/// Check that the value of --libomptarget-nvptx-path is forwarded to nvlink.
-// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp \
-// RUN:  --libomptarget-nvptx-path=/path/to/libomptarget/ \
-// RUN:  -fopenmp-targets=nvptx64-nvidia-cuda %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=CHK-NVLINK,CHK-LIBOMPTARGET-NVPTX-PATH %s
-
-// CHK-NVLINK: nvlink
-// CHK-LIBOMPTARGET-NVPTX-PATH-SAME: "-L/path/to/libomptarget/"
-// CHK-NVLINK-SAME: "-lomptarget-nvptx"
-
-/// ###
-
 /// Check cubin file generation and usage by nvlink
 // RUN:   %clang -### -no-canonical-prefixes -target powerpc64le-unknown-linux-gnu -fopenmp=libomp \
 // RUN:  -fopenmp-targets=nvptx64-nvidia-cuda -save-temps %s 2>&1 \
@@ -173,13 +157,14 @@
 // RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
-/// The user can override default detection using --libomptarget-nvptx-path=.
-// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda --libomptarget-nvptx-path=%S/Inputs/libomptarget \
+/// The user can override default detection using --libomptarget-nvptx-bc-path=.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   --libomptarget-nvptx-bc-path=%S/Inputs/libomptarget/libomptarget-nvptx-sm_20.bc \
 // RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB %s
 
-// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}libomptarget-nvptx-sm_20.bc
+// CHK-BCLIB: clang{{.*}}-triple{{.*}}nvptx64-nvidia-cuda{{.*}}-mlink-builtin-bitcode{{.*}}/Inputs/libomptarget/libomptarget-nvptx-sm_20.bc
 // CHK-BCLIB-NOT: {{error:|warning:}}
 
 /// ###
@@ -191,7 +176,18 @@
 // RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHK-BCLIB-WARN %s
 
-// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Expect degraded performance due to no inlining of runtime functions on target devices.
+// CHK-BCLIB-WARN: No library 'libomptarget-nvptx-sm_20.bc' found in the default clang lib directory or in LIBRARY_PATH. Please use --libomptarget-nvptx-bc-path to specify nvptx bitcode library.
+
+/// ###
+
+/// Check that the error is thrown when the libomptarget bitcode library does not exist.
+// RUN:   %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda \
+// RUN:   -Xopenmp-target -march=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   --libomptarget-nvptx-bc-path=not-exist.bc \
+// RUN:   -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHK-BCLIB-ERROR %s
+
+// CHK-BCLIB-ERROR: Bitcode library 'not-exist.bc' does not exist.
 
 /// Check that debug info is emitted in dwarf-2
 // RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O1 --no-cuda-noopt-device-debug 2>&1 \
Index: clang/lib/Driver/ToolChains/Cuda.cpp

[PATCH] D95145: [clang] Fix a nullptr dereference bug on invalid code

2021-01-21 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp:2
+// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify
+#include 
+

A common practice is to avoid depending on STL in tests. I think we need to 
pull out (even simplify?) std::result_of implementation if it is needed for 
reproducing the crash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95145

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


[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2021-01-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 318278.
ahatanak added a comment.

Update patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjC/arc-rv-attr.m
  clang/test/CodeGenObjC/arc-unsafeclaim.m
  llvm/include/llvm/Analysis/ObjCARCRVAttr.h
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
  llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
  llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARC.h
  llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.h
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/CodeGen/AArch64/call-rv-marker.ll
  llvm/test/Transforms/DeadArgElim/deadretval.ll
  llvm/test/Transforms/Inline/inline-retainRV-call.ll
  llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
  llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
  llvm/test/Transforms/ObjCARC/rv.ll

Index: llvm/test/Transforms/ObjCARC/rv.ll
===
--- llvm/test/Transforms/ObjCARC/rv.ll
+++ llvm/test/Transforms/ObjCARC/rv.ll
@@ -452,6 +452,28 @@
   ret i8* %v3
 }
 
+; Remove attributes and the autoreleaseRV call if the call is a tail call.
+
+; CHECK-LABEL: define i8* @test31(
+; CHECK: %[[CALL:.*]] = tail call i8* @returner()
+; CHECK: ret i8* %[[CALL]]
+
+define i8* @test31() {
+  %call = tail call "clang.arc.rv"="retain" "clang.arc.rv_marker" i8* @returner()
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
+; CHECK-LABEL: define i8* @test32(
+; CHECK: %[[CALL:.*]] = call "clang.arc.rv"="retain" "clang.arc.rv_marker" i8* @returner()
+; CHECK: call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[CALL]])
+
+define i8* @test32() {
+  %call = call "clang.arc.rv"="retain" "clang.arc.rv_marker" i8* @returner()
+  %1 = call i8* @llvm.objc.autoreleaseReturnValue(i8* %call)
+  ret i8* %1
+}
+
 !0 = !{}
 
 ; CHECK: attributes [[NUW]] = { nounwind }
Index: llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
===
--- /dev/null
+++ llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
@@ -0,0 +1,63 @@
+; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
+; RUN: opt -passes=objc-arc-contract -S < %s | FileCheck %s
+
+; CHECK-LABEL: define void @test0() {
+; CHECK: %[[CALL:.*]] = notail call "clang.arc.rv_marker" i8* @foo()
+; CHECK: call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
+
+define void @test0() {
+  %call1 = call "clang.arc.rv"="retain" "clang.arc.rv_marker" i8* @foo()
+  ret void
+}
+
+; CHECK-LABEL: define void @test1() {
+; CHECK: %[[CALL:.*]] = notail call "clang.arc.rv_marker" i8* @foo()
+; CHECK: call i8* @llvm.objc.unsafeClaimAutoreleasedReturnValue(i8* %[[CALL]])
+
+define void @test1() {
+  %call1 = call "clang.arc.rv"="claim" "clang.arc.rv_marker" i8* @foo()
+  ret void
+}
+
+; CHECK-LABEL:define i8* @test2(
+; CHECK: %[[CALL1:.*]] = invoke "clang.arc.rv_marker" i8* @foo()
+
+; CHECK: %[[V0:.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL1]])
+; CHECK-NEXT: br
+
+; CHECK: %[[CALL3:.*]] = invoke "clang.arc.rv_marker" i8* @foo()
+
+; CHECK: %[[V2:.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL3]])
+; CHECK-NEXT: br
+
+; CHECK: %[[RETVAL:.*]] = phi i8* [ %[[V0]], {{.*}} ], [ %[[V2]], {{.*}} ]
+; CHECK: ret i8* %[[RETVAL]]
+
+define i8* @test2(i1 zeroext %b) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+  br i1 %b, label %if.then, label %if.end
+
+if.then:
+  %call1 = invoke "clang.arc.rv"="retain" "clang.arc.rv_marker" i8* @foo()
+  to label %cleanup unwind label %lpad
+
+lpad:
+  %0 = landingpad { i8*, i32 }
+  cleanup
+  resume { i8*, i32 } undef
+
+if.end:
+  %call3 = invoke "clang.arc.rv"="retain" "clang.arc.rv_marker" i8* @foo()
+  to label %cleanup unwind label %lpad
+
+cleanup:
+  %retval.0 = phi i8* [ %call1, %if.then ], [ %call3, %if.end ]
+  ret i8* %retval.0
+}
+
+declare i8* @foo()
+declare i32 @__gxx_personality_v0(...)
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"clang.arc.retainAutoreleasedReturnValueMarker", !"mov\09fp, fp\09\09// marker for objc_retainAutoreleaseReturnValue"}
Index: llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
===
--- llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
+++ llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
@@ -10,6 +10,16 @@
 ;   }
 ; }
 
+; CHECK-LABEL: define void @"\01?g@@YAXXZ"()
+; CHECK-LABEL: catch
+; CHECK: call void asm sideeffect "movl{{.*}}%ebp, %ebp{{.*}}", ""() [ "funclet"(token %1) ]
+
+; CHECK-LABEL: 

[PATCH] D93922: Mangle `__alignof__` differently than `alignof`.

2021-01-21 Thread James Y Knight via Phabricator via cfe-commits
jyknight updated this revision to Diff 318277.
jyknight marked 8 inline comments as done.
jyknight added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93922

Files:
  clang/lib/AST/ItaniumMangle.cpp
  clang/test/CodeGenCXX/mangle-alignof.cpp
  clang/test/CodeGenCXX/microsoft-uuidof-mangling.cpp
  libcxxabi/src/demangle/ItaniumDemangle.h
  libcxxabi/test/test_demangle.pass.cpp
  llvm/include/llvm/Demangle/ItaniumDemangle.h

Index: llvm/include/llvm/Demangle/ItaniumDemangle.h
===
--- llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -96,7 +96,6 @@
 X(InitListExpr) \
 X(FoldExpr) \
 X(ThrowExpr) \
-X(UUIDOfExpr) \
 X(BoolExpr) \
 X(StringLiteral) \
 X(LambdaExpr) \
@@ -2035,21 +2034,6 @@
   }
 };
 
-// MSVC __uuidof extension, generated by clang in -fms-extensions mode.
-class UUIDOfExpr : public Node {
-  Node *Operand;
-public:
-  UUIDOfExpr(Node *Operand_) : Node(KUUIDOfExpr), Operand(Operand_) {}
-
-  template void match(Fn F) const { F(Operand); }
-
-  void printLeft(OutputStream ) const override {
-S << "__uuidof(";
-Operand->print(S);
-S << ")";
-  }
-};
-
 class BoolExpr : public Node {
   bool Value;
 
@@ -5013,6 +4997,43 @@
 }
 }
 return nullptr;
+  case 'u': {
+++First;
+Node *Name = getDerived().parseSourceName(/*NameState=*/nullptr);
+if (!Name)
+  return nullptr;
+// Special case legacy __uuidof mangling. The 't' and 'z' appear where the
+// standard encoding expects a , and would be otherwise be
+// interpreted as  node 'short' or 'ellipsis'. However, neither
+// __uuidof(short) nor __uuidof(...) can actually appear, so there is no
+// actual conflict here.
+if (Name->getBaseName() == "__uuidof") {
+  if (numLeft() < 2)
+return nullptr;
+  if (*First == 't') {
+++First;
+Node *Ty = getDerived().parseType();
+if (!Ty)
+  return nullptr;
+return make(Name, makeNodeArray(,  + 1));
+  }
+  if (*First == 'z') {
+++First;
+Node *Ex = getDerived().parseExpr();
+if (!Ex)
+  return nullptr;
+return make(Name, makeNodeArray(,  + 1));
+  }
+}
+size_t ExprsBegin = Names.size();
+while (!consumeIf('E')) {
+  Node *E = getDerived().parseTemplateArg();
+  if (E == nullptr)
+return E;
+  Names.push_back(E);
+}
+return make(Name, popTrailingNodeArray(ExprsBegin));
+  }
   case '1':
   case '2':
   case '3':
@@ -5024,21 +5045,6 @@
   case '9':
 return getDerived().parseUnresolvedName();
   }
-
-  if (consumeIf("u8__uuidoft")) {
-Node *Ty = getDerived().parseType();
-if (!Ty)
-  return nullptr;
-return make(Ty);
-  }
-
-  if (consumeIf("u8__uuidofz")) {
-Node *Ex = getDerived().parseExpr();
-if (!Ex)
-  return nullptr;
-return make(Ex);
-  }
-
   return nullptr;
 }
 
Index: libcxxabi/src/demangle/ItaniumDemangle.h
===
--- libcxxabi/src/demangle/ItaniumDemangle.h
+++ libcxxabi/src/demangle/ItaniumDemangle.h
@@ -96,7 +96,6 @@
 X(InitListExpr) \
 X(FoldExpr) \
 X(ThrowExpr) \
-X(UUIDOfExpr) \
 X(BoolExpr) \
 X(StringLiteral) \
 X(LambdaExpr) \
@@ -2035,21 +2034,6 @@
   }
 };
 
-// MSVC __uuidof extension, generated by clang in -fms-extensions mode.
-class UUIDOfExpr : public Node {
-  Node *Operand;
-public:
-  UUIDOfExpr(Node *Operand_) : Node(KUUIDOfExpr), Operand(Operand_) {}
-
-  template void match(Fn F) const { F(Operand); }
-
-  void printLeft(OutputStream ) const override {
-S << "__uuidof(";
-Operand->print(S);
-S << ")";
-  }
-};
-
 class BoolExpr : public Node {
   bool Value;
 
@@ -5013,6 +4997,43 @@
 }
 }
 return nullptr;
+  case 'u': {
+++First;
+Node *Name = getDerived().parseSourceName(/*NameState=*/nullptr);
+if (!Name)
+  return nullptr;
+// Special case legacy __uuidof mangling. The 't' and 'z' appear where the
+// standard encoding expects a , and would be otherwise be
+// interpreted as  node 'short' or 'ellipsis'. However, neither
+// __uuidof(short) nor __uuidof(...) can actually appear, so there is no
+// actual conflict here.
+if (Name->getBaseName() == "__uuidof") {
+  if (numLeft() < 2)
+return nullptr;
+  if (*First == 't') {
+++First;
+Node *Ty = getDerived().parseType();
+if (!Ty)
+  return nullptr;
+return make(Name, makeNodeArray(,  + 1));
+  }
+  if (*First == 'z') {
+++First;
+Node *Ex = getDerived().parseExpr();
+if (!Ex)
+  return nullptr;
+return make(Name, makeNodeArray(,  + 1));
+  }
+}
+size_t ExprsBegin = 

[PATCH] D93922: Mangle `__alignof__` differently than `alignof`.

2021-01-21 Thread James Y Knight via Phabricator via cfe-commits
jyknight added inline comments.



Comment at: clang/lib/AST/ItaniumMangle.cpp:4010
+if (Context.getASTContext().getLangOpts().getClangABICompat() >=
+LangOptions::ClangABI::Ver11) {
+  Out << "u8__uuidof";

rsmith wrote:
> Should this be `>= Ver12` / `> Ver11` (given that we already released version 
> 11 and it didn't do this)?
Oops, indeed, done, and adjusted the test as well to test against ABI 11.



Comment at: clang/lib/AST/ItaniumMangle.cpp:4025
+QualType UuidT = UE->getTypeOperand(Context.getASTContext());
+Out << 't';
+mangleType(UuidT);

rsmith wrote:
> It looks like we've lost the `u8__uuidof` prefix on this side. Did you intend 
> to emit that unconditionally above?
Whoops, indeed.



Comment at: clang/lib/AST/ItaniumMangle.cpp:4032
+  }
 }
 break;

rjmccall wrote:
> The old case doesn't seem to be adding the `u8__uuidof` prefix anymore.
> 
> Your patch description does not say anything about changing the mangling of 
> `__uuidof`, and that should be treated separately, not just lumped in to try 
> to make manglings more consistent.
The original description didn't, but I updated it a while ago. ("Additionally, 
fix the mangling of __uuidof to use the new extension syntax, instead of its 
previous nonstandard special-case.")

Not sure if your comment predates that or is asking for something more?



Comment at: clang/lib/AST/ItaniumMangle.cpp:4349
+  if (Context.getASTContext().getLangOpts().getClangABICompat() >=
+  LangOptions::ClangABI::Ver11) {
+Out << "u11__alignof__";

rsmith wrote:
> Presumably this should be `> Ver11`, as above.
Done.



Comment at: clang/lib/AST/ItaniumMangle.cpp:4356
+  mangleExpression(SAE->getArgumentExpr());
+  Out << 'E';
+}

rjmccall wrote:
> This isn't a correct mangling of `template-arg` for expressions; simple 
> expressions should not be surrounded by `X`...`E`.  Please call 
> `mangleTemplateArg`.
> 
> Although... `mangleTemplateArg` doesn't look like it consistently does the 
> right thing when you pass it a `TemplateArgument` constructed with an 
> arbitrary expression, because it seems to be relying on certain expressions 
> having been folded to their canonical representations during template 
> argument checking.  So really we need to have some code that mangles an 
> expression as if it were a template argument, which is to say, recognizing 
> simple expressions that fit into `expr-primary`.
> 
> This would break ABI for any existing place that calls `mangleTemplateArg` 
> with an arbitrary expression, but it looks like the only place that does that 
> is dependent matrix types, where I think wee can justify the break as a bug 
> fix since matrix types are such a new feature.  Pinging Florian.
Yep, made the first part of the change (although, annoyingly, using a 
const_cast -- TemplateArg's constructor requires a non-const `Expr*`, and that 
doesn't look easy to change, since it exposes it via a getter, and other 
callers require a non-const `Expr*` result from that getter).

I'll work on fixing mangleTemplateArg separately.

I'll note that non-instantiation-dependent `__alignof__` gets mangled as a 
integer literal already, even when in a dependent expression. So I //think// 
it's not possible to get this bug to exhibit for alignof -- I don't see how you 
could end up with something that should mangle as expr-primary there.

For `__uuidof`, it can only be applied to expressions of struct type, so, most 
of the things that fit in expr-primary would be an error there. However, `L _Z 
encoding E` is possible here, e.g. `template  void 
test_uuidofExpr(decltype(T{}, __uuidof(HasMember::member)) arg) {}` gets 
mangled with my patch as 
`_Z15test_uuidofExprI11OtherStructEvDTcmtlT_Eu8__uuidofXL_ZN9HasMember6memberE`
 when it should've omitted the X/E on the arg to uuidof, as: 
`_Z15test_uuidofExprI11OtherStructEvDTcmtlT_Eu8__uuidofL_ZN9HasMember6member`.




Comment at: clang/test/CodeGenCXX/microsoft-uuidof-mangling.cpp:54
+// CHECK: call void @_Z15test_uuidofTypeI10TestStructEvDTu8__uuidofT_EE(
+// CHECK: call void 
@_Z15test_uuidofExprI9HasMemberEvDTu8__uuidofXsrT_6memberEEE(
 // CHECK: define linkonce_odr void 
@_ZN8UUIDTestI10TestStructL_Z42_GUID_eafa1952_66f8_438b_8fba_af1bbae42191EEC1Ev

rsmith wrote:
> Please consider adding test coverage for `-fclang-abi-compat` for `__uuidof` 
> too.
Indeed, that would've caught the bug in my code...done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93922

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


[PATCH] D92808: [ObjC][ARC] Annotate calls with attributes instead of emitting retainRV or claimRV calls in the IR

2021-01-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added a comment.

Add helper functions to ObjCARCRVAttr.h for adding, removing, or looking up 
attributes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

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


[PATCH] D95159: [ASTReader] Allow controlling separately whether validation should be disabled for a PCH vs a module file

2021-01-21 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added subscribers: dang, arphaman.
Herald added a reviewer: jansvoboda11.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This addresses an issue with how the PCH preable works, specifically:

1. When using a PCH/preamble the module hash changes and a different cache 
directory is used
2. When the preamble is used, PCH & PCM validation is disabled.

Due to combination of #1 and #2, reparsing with preamble enabled can end up 
loading a state module file before a header change and using it without 
updating it because validation is disabled and it doesn’t check that the header 
has changed and the module file is out-of-date.

rdar://72611253


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95159

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/CompilerInstance.h
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/ChainedIncludesSource.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/Index/Inputs/preamble-reparse-changed-module/head.h
  clang/test/Index/Inputs/preamble-reparse-changed-module/module.modulemap
  clang/test/Index/Inputs/preamble-reparse-changed-module/new-head.h
  clang/test/Index/preamble-reparse-changed-module.m
  clang/tools/c-index-test/c-index-test.c
  clang/tools/c-index-test/core_main.cpp

Index: clang/tools/c-index-test/core_main.cpp
===
--- clang/tools/c-index-test/core_main.cpp
+++ clang/tools/c-index-test/core_main.cpp
@@ -21,14 +21,17 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Program.h"
 
 using namespace clang;
 using namespace clang::index;
 using namespace llvm;
 
 extern "C" int indextest_core_main(int argc, const char **argv);
+extern "C" int indextest_perform_shell_execution(const char *command_line);
 
 namespace {
 
@@ -359,3 +362,21 @@
 
   return 0;
 }
+
+//===--===//
+// Utility functions
+//===--===//
+
+int indextest_perform_shell_execution(const char *command_line) {
+  BumpPtrAllocator Alloc;
+  llvm::StringSaver Saver(Alloc);
+  SmallVector Args;
+  llvm::cl::TokenizeGNUCommandLine(command_line, Saver, Args);
+  auto Program = llvm::sys::findProgramByName(Args[0]);
+  if (std::error_code ec = Program.getError()) {
+llvm::errs() << "command not found: " << Args[0] << "\n";
+return ec.value();
+  }
+  SmallVector execArgs(Args.begin(), Args.end());
+  return llvm::sys::ExecuteAndWait(*Program, execArgs);
+}
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -24,6 +24,7 @@
 #endif
 
 extern int indextest_core_main(int argc, const char **argv);
+extern int indextest_perform_shell_execution(const char *command_line);
 
 /**/
 /* Utility functions. */
@@ -2095,6 +2096,8 @@
   enum CXErrorCode Err;
   int result, i;
   int trial;
+  int execute_after_trial = 0;
+  const char *execute_command = NULL;
   int remap_after_trial = 0;
   char *endptr = 0;
   
@@ -2133,12 +2136,26 @@
   if (checkForErrors(TU) != 0)
 return -1;
 
+  if (getenv("CINDEXTEST_EXECUTE_COMMAND")) {
+execute_command = getenv("CINDEXTEST_EXECUTE_COMMAND");
+  }
+  if (getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL")) {
+execute_after_trial =
+strtol(getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL"), , 10);
+  }
+
   if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
 remap_after_trial =
 strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), , 10);
   }
 
   for (trial = 0; trial < trials; ++trial) {
+if (execute_command && trial == execute_after_trial) {
+  result = indextest_perform_shell_execution(execute_command);
+  if (result != 0)
+return result;
+}
+
 free_remapped_files(unsaved_files, num_unsaved_files);
 if (parse_remapped_files_with_try(trial, argc, argv, 0,
   _files, _unsaved_files)) {
Index: clang/test/Index/preamble-reparse-changed-module.m
===
--- /dev/null
+++ clang/test/Index/preamble-reparse-changed-module.m
@@ -0,0 +1,18 @@
+// 

[clang] 65fd034 - [FunctionAttrs] Infer willreturn for functions without loops

2021-01-21 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2021-01-21T20:29:33+01:00
New Revision: 65fd034b95d69fa0e634861ee165b502ceb92a12

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

LOG: [FunctionAttrs] Infer willreturn for functions without loops

If a function doesn't contain loops and does not call non-willreturn
functions, then it is willreturn. Loops are detected by checking
for backedges in the function. We don't attempt to handle finite
loops at this point.

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

Added: 


Modified: 
clang/test/CodeGenOpenCL/convergent.cl
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
llvm/test/CodeGen/AMDGPU/inline-attr.ll
llvm/test/Transforms/FunctionAttrs/atomic.ll
llvm/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll
llvm/test/Transforms/FunctionAttrs/nofree.ll
llvm/test/Transforms/FunctionAttrs/optnone.ll
llvm/test/Transforms/FunctionAttrs/willreturn.ll
llvm/test/Transforms/FunctionAttrs/writeonly.ll
llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/convergent.cl 
b/clang/test/CodeGenOpenCL/convergent.cl
index 5e4f6fad1b3a..25951a64c114 100644
--- a/clang/test/CodeGenOpenCL/convergent.cl
+++ b/clang/test/CodeGenOpenCL/convergent.cl
@@ -134,7 +134,7 @@ kernel void assume_convergent_asm()
   __asm__ volatile("s_barrier");
 }
 
-// CHECK: attributes #0 = { nofree noinline norecurse nounwind "
+// CHECK: attributes #0 = { nofree noinline norecurse nounwind willreturn "
 // CHECK: attributes #1 = { {{[^}]*}}convergent{{[^}]*}} }
 // CHECK: attributes #2 = { {{[^}]*}}convergent{{[^}]*}} }
 // CHECK: attributes #3 = { {{[^}]*}}convergent noduplicate{{[^}]*}} }

diff  --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp 
b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 210186a0550e..30a1f81ad0e1 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -22,6 +22,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/AssumptionCache.h"
 #include "llvm/Analysis/BasicAliasAnalysis.h"
+#include "llvm/Analysis/CFG.h"
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/CallGraphSCCPass.h"
@@ -1425,12 +1426,36 @@ static bool addNoReturnAttrs(const SCCNodeSet 
) {
   return Changed;
 }
 
+static bool functionWillReturn(const Function ) {
+  // Must-progress function without side-effects must return.
+  if (F.mustProgress() && F.onlyReadsMemory())
+return true;
+
+  // Can only analyze functions with a definition.
+  if (F.isDeclaration())
+return false;
+
+  // Functions with loops require more sophisticated analysis, as the loop
+  // may be infinite. For now, don't try to handle them.
+  SmallVector> Backedges;
+  FindFunctionBackedges(F, Backedges);
+  if (!Backedges.empty())
+return false;
+
+  // If there are no loops, then the function is willreturn if all calls in
+  // it are willreturn.
+  return all_of(instructions(F), [](const Instruction ) {
+const auto *CB = dyn_cast();
+return !CB || CB->hasFnAttr(Attribute::WillReturn);
+  });
+}
+
 // Set the willreturn function attribute if possible.
 static bool addWillReturn(const SCCNodeSet ) {
   bool Changed = false;
 
   for (Function *F : SCCNodes) {
-if (!F || !F->onlyReadsMemory() || !F->mustProgress() || F->willReturn())
+if (!F || F->willReturn() || !functionWillReturn(*F))
   continue;
 
 F->setWillReturn();

diff  --git a/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll 
b/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
index 95ac2525b4ad..5bbc86bb69ed 100644
--- a/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
+++ b/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
@@ -72,13 +72,13 @@ define i32 @test3_no(i8* %p) nounwind {
 declare void @callee(i32* %p) nounwind
 declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i1) nounwind
 
-; CHECK: attributes #0 = { norecurse nounwind readnone }
-; CHECK: attributes #1 = { nofree norecurse nounwind writeonly }
+; CHECK: attributes #0 = { norecurse nounwind readnone willreturn }
+; CHECK: attributes #1 = { nofree norecurse nounwind willreturn writeonly }
 ; CHECK: attributes #2 = { nounwind readonly }
 ; CHECK: attributes #3 = { nounwind }
-; CHECK: attributes #4 = { nounwind readnone }
-; CHECK: attributes #5 = { nofree nounwind }
-; CHECK: attributes #6 = { nofree norecurse nounwind }
+; CHECK: attributes #4 = { nounwind readnone willreturn }
+; CHECK: attributes #5 = { nofree nounwind willreturn }
+; CHECK: attributes #6 = { nofree norecurse nounwind willreturn }
 ; CHECK: attributes #7 = { argmemonly nofree nosync 

[PATCH] D94633: [FunctionAttrs] Infer willreturn for functions without loops

2021-01-21 Thread Nikita Popov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG65fd034b95d6: [FunctionAttrs] Infer willreturn for functions 
without loops (authored by nikic).
Herald added subscribers: cfe-commits, hiraditya.
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D94633?vs=316693=318272#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94633

Files:
  clang/test/CodeGenOpenCL/convergent.cl
  llvm/lib/Transforms/IPO/FunctionAttrs.cpp
  llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
  llvm/test/CodeGen/AMDGPU/inline-attr.ll
  llvm/test/Transforms/FunctionAttrs/atomic.ll
  llvm/test/Transforms/FunctionAttrs/incompatible_fn_attrs.ll
  llvm/test/Transforms/FunctionAttrs/nofree.ll
  llvm/test/Transforms/FunctionAttrs/optnone.ll
  llvm/test/Transforms/FunctionAttrs/willreturn.ll
  llvm/test/Transforms/FunctionAttrs/writeonly.ll
  llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll

Index: llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll
===
--- llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll
+++ llvm/test/Transforms/InferFunctionAttrs/norecurse_debug.ll
@@ -52,5 +52,5 @@
 !28 = !DILocation(line: 9, column: 18, scope: !2)
 !29 = !DILocation(line: 10, column: 1, scope: !2)
 
-; CHECK: attributes #0 = { nofree norecurse nounwind }
+; CHECK: attributes #0 = { nofree norecurse nounwind willreturn }
 ; CHECK-NOT: foo.coefficient1
Index: llvm/test/Transforms/FunctionAttrs/writeonly.ll
===
--- llvm/test/Transforms/FunctionAttrs/writeonly.ll
+++ llvm/test/Transforms/FunctionAttrs/writeonly.ll
@@ -25,6 +25,6 @@
   ret void
 }
 
-; CHECK: attributes #0 = { {{.*}} readnone }
-; CHECK: attributes #1 = { {{.*}} readonly }
+; CHECK: attributes #0 = { {{.*}} readnone {{.*}} }
+; CHECK: attributes #1 = { {{.*}} readonly {{.*}} }
 ; CHECK: attributes #2 = { {{.*}} writeonly }
Index: llvm/test/Transforms/FunctionAttrs/willreturn.ll
===
--- llvm/test/Transforms/FunctionAttrs/willreturn.ll
+++ llvm/test/Transforms/FunctionAttrs/willreturn.ll
@@ -71,9 +71,10 @@
   ret i64 0
 }
 
+; Function without loops or non-willreturn calls will return.
 define void @willreturn_no_loop(i1 %c, i32* %p) {
-; CHECK-NOT: Function Attrs: {{.*}}willreturn
-; CHECK: define void @willreturn_no_loop(
+; CHECK: Function Attrs: willreturn
+; CHECK-NEXT: define void @willreturn_no_loop(
 ;
   br i1 %c, label %if, label %else
 
@@ -90,6 +91,7 @@
   ret void
 }
 
+; Calls a function that is not guaranteed to return, not willreturn.
 define void @willreturn_non_returning_function(i1 %c, i32* %p) {
 ; CHECK-NOT: Function Attrs: {{.*}}willreturn
 ; CHECK: define void @willreturn_non_returning_function(
@@ -98,6 +100,7 @@
   ret void
 }
 
+; Infinite loop without mustprogress, will not return.
 define void @willreturn_loop() {
 ; CHECK-NOT: Function Attrs: {{.*}}willreturn
 ; CHECK: define void @willreturn_loop(
@@ -108,6 +111,8 @@
   br label %loop
 }
 
+; Finite loop. Could be willreturn but not detected.
+; FIXME
 define void @willreturn_finite_loop() {
 ; CHECK-NOT: Function Attrs: {{.*}}willreturn
 ; CHECK: define void @willreturn_finite_loop(
@@ -125,5 +130,28 @@
   ret void
 }
 
+; Infinite recursion without mustprogress, will not return.
+define void @willreturn_recursion() {
+; CHECK-NOT: Function Attrs: {{.*}}willreturn
+; CHECK: define void @willreturn_recursion(
+;
+  tail call void @willreturn_recursion()
+  ret void
+}
+
+; Irreducible infinite loop, will not return.
+define void @willreturn_irreducible(i1 %c) {
+; CHECK-NOT: Function Attrs: {{.*}}willreturn
+; CHECK: define void @willreturn_irreducible(
+;
+  br i1 %c, label %bb1, label %bb2
+
+bb1:
+  br label %bb2
+
+bb2:
+  br label %bb1
+}
+
 declare i64 @fn_noread() readnone
 declare void @fn_willreturn() willreturn
Index: llvm/test/Transforms/FunctionAttrs/optnone.ll
===
--- llvm/test/Transforms/FunctionAttrs/optnone.ll
+++ llvm/test/Transforms/FunctionAttrs/optnone.ll
@@ -20,6 +20,6 @@
 ; CHECK: (i8*) #1
 
 ; CHECK-LABEL: attributes #0
-; CHECK: = { norecurse nounwind readnone }
+; CHECK: = { norecurse nounwind readnone willreturn }
 ; CHECK-LABEL: attributes #1
 ; CHECK: = { noinline optnone }
Index: llvm/test/Transforms/FunctionAttrs/nofree.ll
===
--- llvm/test/Transforms/FunctionAttrs/nofree.ll
+++ llvm/test/Transforms/FunctionAttrs/nofree.ll
@@ -107,7 +107,7 @@
 ; CHECK: attributes #0 = { uwtable }
 ; CHECK: attributes #1 = { nounwind uwtable }
 ; CHECK: attributes #2 = { nounwind }
-; CHECK: attributes #3 = { norecurse nounwind readonly uwtable }
+; CHECK: attributes #3 = { norecurse 

[PATCH] D94979: [CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC

2021-01-21 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Clang has generally made a point of trying to be as neutral about `CHAR_BITS` 
as it can be, even though LLVM has not.  As the code owner of this code, I view 
this as a fix consistent with that, and I consider it acceptable to land.

Of course, if you are pursuing these patches out of an expectation that you'll 
eventually get Clang to support compiling targets with non-8-bit-addressing, 
you need to understand that (at least for most cases) that depends on LLVM 
supporting such targets, and so far the LLVM community has been pretty strongly 
opposed to that idea.  But Clang has *internally* already accepted the 
abstraction costs of `CharUnits`, and we should to be as consistent as possible 
about that in our own code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94979

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


[PATCH] D92191: [clang-scan-deps] Add support for clang-cl

2021-01-21 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D92191#2512960 , @saudi wrote:

> Removed the support for "--" command lines, it was extracted to patch D95099 
> .
> Applied suggested fixes.

Thanks!

@Bigcheese, since you reviewed the original patch, are you able to take a look 
at the updated version?


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

https://reviews.llvm.org/D92191

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


[PATCH] D95154: [WIP][clang][Fuchsia] Add the *-fuchsia-gnu arch and multilibs

2021-01-21 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr.
leonardchan added a project: clang.
Herald added subscribers: s.egerton, simoncook, mgorny.
leonardchan requested review of this revision.

Create libraries that are GCC compaitble.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95154

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  
clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia-gnu/c++/asan+noexcept/libc++.so
  
clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia-gnu/c++/asan/libc++.so
  
clang/test/Driver/Inputs/basic_fuchsia_tree/lib/x86_64-fuchsia-gnu/c++/noexcept/libc++.so
  clang/test/Driver/fuchsia.cpp

Index: clang/test/Driver/fuchsia.cpp
===
--- clang/test/Driver/fuchsia.cpp
+++ clang/test/Driver/fuchsia.cpp
@@ -96,10 +96,36 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN: -fuse-ld=lld 2>&1\
 // RUN: | FileCheck %s -check-prefixes=CHECK-MULTILIB-X86,CHECK-MULTILIB-RELATIVE-VTABLES-NOEXCEPT-X86
+
+// RUN: %clangxx %s -### --target=x86_64-fuchsia-gnu \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTIARCH-X86-GNU
+// RUN: %clangxx %s -### --target=x86_64-fuchsia-gnu -fsanitize=address \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTIARCH-X86-GNU,CHECK-MULTIARCH-ASAN-X86-GNU
+// RUN: %clangxx %s -### --target=x86_64-fuchsia-gnu -fno-exceptions \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTIARCH-X86-GNU,CHECK-MULTIARCH-NOEXCEPT-X86-GNU
+// RUN: %clangxx %s -### --target=x86_64-fuchsia-gnu -fsanitize=address -fno-exceptions \
+// RUN: -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fuse-ld=lld 2>&1\
+// RUN: | FileCheck %s -check-prefixes=CHECK-MULTIARCH-X86-GNU,CHECK-MULTIARCH-ASAN-NOEXCEPT-X86-GNU
+
 // CHECK-MULTILIB-X86: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-MULTILIB-ASAN-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}asan"
 // CHECK-MULTILIB-NOEXCEPT-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}noexcept"
 // CHECK-MULTILIB-ASAN-NOEXCEPT-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}asan+noexcept"
+// CHECK-MULTIARCH-ASAN-X86-GNU: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia-gnu{{/|}}c++{{/|}}asan"
+// CHECK-MULTIARCH-NOEXCEPT-X86-GNU: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia-gnu{{/|}}c++{{/|}}noexcept"
+// CHECK-MULTIARCH-ASAN-NOEXCEPT-X86-GNU: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia-gnu{{/|}}c++{{/|}}asan+noexcept"
+// CHECK-MULTIARCH-X86-GNU: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia-gnu{{/|}}c++"
 // CHECK-MULTILIB-RELATIVE-VTABLES-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}relative-vtables"
 // CHECK-MULTILIB-RELATIVE-VTABLES-NOEXCEPT-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++{{/|}}relative-vtables+noexcept"
 // CHECK-MULTILIB-X86: "-L{{.*}}{{/|}}..{{/|}}lib{{/|}}x86_64-fuchsia{{/|}}c++"
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -144,89 +144,105 @@
   set(FUCHSIA_i386_NAME x64)
   set(FUCHSIA_x86_64_NAME x64)
   set(FUCHSIA_riscv64_NAME riscv64)
-  foreach(target i386;x86_64;aarch64;riscv64)
-set(FUCHSIA_${target}_COMPILER_FLAGS "--target=${target}-unknown-fuchsia -I${FUCHSIA_SDK}/pkg/fdio/include")
-set(FUCHSIA_${target}_LINKER_FLAGS "-L${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/lib")
-set(FUCHSIA_${target}_SYSROOT "${FUCHSIA_SDK}/arch/${FUCHSIA_${target}_NAME}/sysroot")
+
+  foreach(name i386;x86_64;aarch64;riscv64;x86_64_gnu;aarch64_gnu)
+if(${name} MATCHES ".*_gnu$")
+  string(REGEX REPLACE "_gnu$" "" target ${name})
+  set(FUCHSIA_${name}_COMPILER_FLAGS "--target=${target}-unknown-fuchsia-gnu -I${FUCHSIA_SDK}/pkg/fdio/include")
+else()
+  set(target ${name})
+  set(FUCHSIA_${name}_COMPILER_FLAGS "--target=${target}-unknown-fuchsia -I${FUCHSIA_SDK}/pkg/fdio/include")
+endif()
+set(FUCHSIA_${name}_LINKER_FLAGS 

[PATCH] D95099: [clang-scan-deps] : Support -- in clang command lines.

2021-01-21 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Thanks for splitting this out! The looks good, just a few nits in line below. I 
also have a question about the test.




Comment at: clang/lib/Tooling/Tooling.cpp:440
+  // names.
+  auto ArgsEnd = Args.end();
+  for (auto I = Args.begin(), E = Args.end(); I != E; ++I) {

I think another name that doesn't sound like a synonym of `Args.end()` would be 
more clear. Maybe `LastFlag` or `FlagsEnd`?



Comment at: clang/test/ClangScanDeps/Inputs/regular_cdb.json:12-16
 {
   "directory": "DIR",
-  "command": "clang -E DIR/regular_cdb_input.cpp -IInputs -o adena.o",
+  "command": "clang -E -IInputs -o adena.o -- DIR/regular_cdb_input.cpp",
   "file": "DIR/regular_cdb_input.cpp"
 }

It's not obvious to me how this exercises the new `-resource-dir` logic. Can 
you walk me through it?



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:424
 bool HasResourceDir = false;
+auto ArgsEnd = llvm::find(Args, "--");
+

I think it'd be a bit clearer to name this `LastFlag` or `LastOption` or 
`FlagsEnd` or something, since this is not the last argument, just the last 
flag/option. Especially helpful on the last usage below when referencing the 
range from `ArgsEnd` to `Args.end()`.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:427
 // We need to find the last -o value.
 if (!Args.empty()) {
+  // Reverse scan, starting at the end or at the element before "--".

Should this condition be instead check for `LastFlag != Args.begin()`?



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:430
+  auto ArgsRBegin = llvm::make_reverse_iterator(ArgsEnd);
+  for (auto It = ArgsRBegin; It != Args.rend(); ++It) {
+StringRef Arg = *It;

Nit: since you're touching this line anyway, would be nice to update it to 
follow the usual LLVM style of calling `rend()` just once instead of on every 
iteration:
```
for (auto RB = llvm::make_reverse_iterator(LastFlag), RI = RB, RE = Args.rend();
 RI != RE; ++RI) {
```
Up to you, but I find the initialism `RI` a bit more indicative of a reverse 
iterator... this patch touches every use so you could rename it without pulling 
in any extra diff. If you prefer the names you have that's fine too though.

Also, if you narrow the scope of `RB` / `ArgsRBegin` you can probably reduce 
nesting by deleting the redundant `if`, but that'd be nice to commit separately 
(in a follow up?) to avoid cluttering up this patch with NFC indentation 
changes.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:434
+  if (Arg == "-o" && It != ArgsRBegin)
+LastO = *(It - 1); // Next argument (reverse iterator)
   else if (Arg.startswith("-o"))

Does `RI[-1]` work here? Personally I find `x[y]` more clear than `*(x + y)`.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:480
 }
+AdjustedArgs.insert(AdjustedArgs.end(), ArgsEnd, Args.end());
 return AdjustedArgs;

Can we use `AdjustedArgs.append(LastFlag, Args.end())` here?


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

https://reviews.llvm.org/D95099

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


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek marked an inline comment as done.
phosek added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:851
+return "csllvm";
+  default:
+llvm_unreachable("unknown instrumentation type");

vsk wrote:
> If we add an instrumentation kind, it may be more convenient to trigger a 
> -Wcovered-switch warning (by removing this default case) vs. seeing a crash 
> at runtime.
Done, I've also decided to move the helper function inside the `ProfileList` 
class to hide the detail of how `ProfileInstrKind` translates to section name.


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

https://reviews.llvm.org/D94820

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


[PATCH] D94583: [RISCV] Update V extension to v1.0-draft 08a0b464.

2021-01-21 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

There are a lot of "Resolve for v1.0" issues open against the spec still. Are 
we sure we want to brand this as 1.0? It will end up as such in the ELF 
attributes and thus be deemed compatible with future "real" 1.0 binaries.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94583

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


[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 318257.

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

https://reviews.llvm.org/D94820

Files:
  clang/docs/SourceBasedCodeCoverage.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/ProfileList.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/profile-filter.c
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLToken.h
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- /dev/null
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -0,0 +1,25 @@
+; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@i = dso_local global i32 0, align 4
+
+define i32 @test1() {
+entry:
+; CHECK: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %add = add i32 %0, 1
+  ret i32 %add
+}
+
+define i32 @test2() #0 {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  %0 = load i32, i32* @i, align 4
+  %sub = sub i32 %0, 1
+  ret i32 %sub
+}
+
+attributes #0 = { noprofile }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -974,6 +974,7 @@
   case Attribute::UWTable:
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 break;
   }
 
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1591,6 +1591,8 @@
   for (auto  : M) {
 if (F.isDeclaration())
   continue;
+if (F.hasFnAttribute(llvm::Attribute::NoProfile))
+  continue;
 auto  = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1639,6 +1639,7 @@
   case Attribute::StrictFP:
   case Attribute::NullPointerIsValid:
   case Attribute::MustProgress:
+  case Attribute::NoProfile:
 return true;
   default:
 break;
Index: llvm/lib/IR/Attributes.cpp
===
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -403,6 +403,8 @@
 return "nocf_check";
   if (hasAttribute(Attribute::NoRecurse))
 return "norecurse";
+  if (hasAttribute(Attribute::NoProfile))
+return "noprofile";
   if (hasAttribute(Attribute::NoUnwind))
 return "nounwind";
   if (hasAttribute(Attribute::OptForFuzzing))
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -680,6 +680,8 @@
 return bitc::ATTR_KIND_NOSYNC;
   case Attribute::NoCfCheck:
 return bitc::ATTR_KIND_NOCF_CHECK;
+  case Attribute::NoProfile:
+return bitc::ATTR_KIND_NO_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NullPointerIsValid:
Index: llvm/lib/AsmParser/LLToken.h
===
--- llvm/lib/AsmParser/LLToken.h
+++ llvm/lib/AsmParser/LLToken.h
@@ -210,6 +210,7 @@
   kw_nonlazybind,
   kw_nomerge,
   kw_nonnull,
+  kw_noprofile,
   kw_noredzone,
   kw_noreturn,
   kw_nosync,
Index: llvm/lib/AsmParser/LLParser.cpp
===
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -1368,6 +1368,7 @@
 case lltok::kw_noreturn: B.addAttribute(Attribute::NoReturn); break;
 case lltok::kw_nosync: B.addAttribute(Attribute::NoSync); break;
 case lltok::kw_nocf_check: B.addAttribute(Attribute::NoCfCheck); break;
+

[PATCH] D94732: [CUDA] Normalize handling of defauled dtor.

2021-01-21 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG127091bfd5ed: [CUDA] Normalize handling of defauled dtor. 
(authored by tra).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94732

Files:
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGenCUDA/usual-deallocators.cu
  clang/test/SemaCUDA/usual-deallocators.cu

Index: clang/test/SemaCUDA/usual-deallocators.cu
===
--- clang/test/SemaCUDA/usual-deallocators.cu
+++ clang/test/SemaCUDA/usual-deallocators.cu
@@ -93,3 +93,12 @@
   test_hd(t);
   test_hd(t);
 }
+
+// This should produce no errors.  Defaulted destructor should be treated as HD,
+// which allows referencing host-only `operator delete` with a deferred
+// diagnostics that would fire if we ever attempt to codegen it on device..
+struct H {
+  virtual ~H() = default;
+  static void operator delete(void *) {}
+};
+H h;
Index: clang/test/CodeGenCUDA/usual-deallocators.cu
===
--- clang/test/CodeGenCUDA/usual-deallocators.cu
+++ clang/test/CodeGenCUDA/usual-deallocators.cu
@@ -12,6 +12,19 @@
 extern "C" __device__ void dev_fn();
 extern "C" __host__ __device__ void hd_fn();
 
+// Destructors are handled a bit differently, compared to regular functions.
+// Make sure we do trigger kernel generation on the GPU side even if it's only
+// referenced by the destructor.
+template __global__ void f(T) {}
+template struct A {
+  ~A() { f<<<1, 1>>>(T()); }
+};
+
+// HOST-LABEL: @a
+A a;
+// HOST-LABEL: define linkonce_odr void @_ZN1AIiED1Ev
+// search further down for the deice-side checks for @_Z1fIiEvT_
+
 struct H1D1 {
   __host__ void operator delete(void *) { host_fn(); };
   __device__ void operator delete(void *) { dev_fn(); };
@@ -95,6 +108,9 @@
   test_hd(t);
 }
 
+// Make sure that we've generated the kernel used by A::~A.
+// DEVICE-LABEL: define dso_local void @_Z1fIiEvT_
+
 // Make sure we've picked deallocator for the correct side of compilation.
 
 // COMMON-LABEL: define  linkonce_odr void @_ZN4H1D1dlEPv(i8* %0)
@@ -131,3 +147,5 @@
 // COMMON-LABEL: define  linkonce_odr void @_ZN8H1H2D1D2dlEPv(i8* %0)
 // DEVICE: call void @dev_fn()
 // HOST: call void @host_fn()
+
+// DEVICE: !0 = !{void (i32)* @_Z1fIiEvT_, !"kernel", i32 1}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1527,9 +1527,24 @@
 bool Sema::isUsualDeallocationFunction(const CXXMethodDecl *Method) {
   // [CUDA] Ignore this function, if we can't call it.
   const FunctionDecl *Caller = dyn_cast(CurContext);
-  if (getLangOpts().CUDA &&
-  IdentifyCUDAPreference(Caller, Method) <= CFP_WrongSide)
-return false;
+  if (getLangOpts().CUDA) {
+auto CallPreference = IdentifyCUDAPreference(Caller, Method);
+// If it's not callable at all, it's not the right function.
+if (CallPreference < CFP_WrongSide)
+  return false;
+if (CallPreference == CFP_WrongSide) {
+  // Maybe. We have to check if there are better alternatives.
+  DeclContext::lookup_result R =
+  Method->getDeclContext()->lookup(Method->getDeclName());
+  for (const auto *D : R) {
+if (const auto *FD = dyn_cast(D)) {
+  if (IdentifyCUDAPreference(Caller, FD) > CFP_WrongSide)
+return false;
+}
+  }
+  // We've found no better variants.
+}
+  }
 
   SmallVector PreventedBy;
   bool Result = Method->isUsualDeallocationFunction(PreventedBy);
Index: clang/lib/Sema/SemaCUDA.cpp
===
--- clang/lib/Sema/SemaCUDA.cpp
+++ clang/lib/Sema/SemaCUDA.cpp
@@ -123,7 +123,8 @@
 return CFT_Device;
   } else if (hasAttr(D, IgnoreImplicitHDAttr)) {
 return CFT_Host;
-  } else if (D->isImplicit() && !IgnoreImplicitHDAttr) {
+  } else if ((D->isImplicit() || !D->isUserProvided()) &&
+ !IgnoreImplicitHDAttr) {
 // Some implicit declarations (like intrinsic functions) are not marked.
 // Set the most lenient target on them for maximal flexibility.
 return CFT_HostDevice;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 127091b - [CUDA] Normalize handling of defauled dtor.

2021-01-21 Thread Artem Belevich via cfe-commits

Author: Artem Belevich
Date: 2021-01-21T10:48:07-08:00
New Revision: 127091bfd5edf10495fee4724fd21c666e5d79c1

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

LOG: [CUDA] Normalize handling of defauled dtor.

Defaulted destructor was treated inconsistently, compared to other
compiler-generated functions.

When Sema::IdentifyCUDATarget() got called on just-created dtor which didn't
have implicit __host__ __device__ attributes applied yet, it would treat it as a
host function.  That happened to (sometimes) hide the error when dtor referred
to a host-only functions.

Even when we had identified defaulted dtor as a HD function, we still treated it
inconsistently during selection of usual deallocators, where we did not allow
referring to wrong-side functions, while it is allowed for other HD functions.

This change brings handling of defaulted dtors in line with other HD functions.

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

Added: 


Modified: 
clang/lib/Sema/SemaCUDA.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGenCUDA/usual-deallocators.cu
clang/test/SemaCUDA/usual-deallocators.cu

Removed: 




diff  --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index 0f06adf38f7a..ee91eb4c5deb 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -123,7 +123,8 @@ Sema::CUDAFunctionTarget Sema::IdentifyCUDATarget(const 
FunctionDecl *D,
 return CFT_Device;
   } else if (hasAttr(D, IgnoreImplicitHDAttr)) {
 return CFT_Host;
-  } else if (D->isImplicit() && !IgnoreImplicitHDAttr) {
+  } else if ((D->isImplicit() || !D->isUserProvided()) &&
+ !IgnoreImplicitHDAttr) {
 // Some implicit declarations (like intrinsic functions) are not marked.
 // Set the most lenient target on them for maximal flexibility.
 return CFT_HostDevice;

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 1ee52107c3da..d91db60f17a0 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1527,9 +1527,24 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
 bool Sema::isUsualDeallocationFunction(const CXXMethodDecl *Method) {
   // [CUDA] Ignore this function, if we can't call it.
   const FunctionDecl *Caller = dyn_cast(CurContext);
-  if (getLangOpts().CUDA &&
-  IdentifyCUDAPreference(Caller, Method) <= CFP_WrongSide)
-return false;
+  if (getLangOpts().CUDA) {
+auto CallPreference = IdentifyCUDAPreference(Caller, Method);
+// If it's not callable at all, it's not the right function.
+if (CallPreference < CFP_WrongSide)
+  return false;
+if (CallPreference == CFP_WrongSide) {
+  // Maybe. We have to check if there are better alternatives.
+  DeclContext::lookup_result R =
+  Method->getDeclContext()->lookup(Method->getDeclName());
+  for (const auto *D : R) {
+if (const auto *FD = dyn_cast(D)) {
+  if (IdentifyCUDAPreference(Caller, FD) > CFP_WrongSide)
+return false;
+}
+  }
+  // We've found no better variants.
+}
+  }
 
   SmallVector PreventedBy;
   bool Result = Method->isUsualDeallocationFunction(PreventedBy);

diff  --git a/clang/test/CodeGenCUDA/usual-deallocators.cu 
b/clang/test/CodeGenCUDA/usual-deallocators.cu
index 7e7752497f34..6f4cc267a23f 100644
--- a/clang/test/CodeGenCUDA/usual-deallocators.cu
+++ b/clang/test/CodeGenCUDA/usual-deallocators.cu
@@ -12,6 +12,19 @@ extern "C" __host__ void host_fn();
 extern "C" __device__ void dev_fn();
 extern "C" __host__ __device__ void hd_fn();
 
+// Destructors are handled a bit 
diff erently, compared to regular functions.
+// Make sure we do trigger kernel generation on the GPU side even if it's only
+// referenced by the destructor.
+template __global__ void f(T) {}
+template struct A {
+  ~A() { f<<<1, 1>>>(T()); }
+};
+
+// HOST-LABEL: @a
+A a;
+// HOST-LABEL: define linkonce_odr void @_ZN1AIiED1Ev
+// search further down for the deice-side checks for @_Z1fIiEvT_
+
 struct H1D1 {
   __host__ void operator delete(void *) { host_fn(); };
   __device__ void operator delete(void *) { dev_fn(); };
@@ -95,6 +108,9 @@ __host__ __device__ void tests_hd(void *t) {
   test_hd(t);
 }
 
+// Make sure that we've generated the kernel used by A::~A.
+// DEVICE-LABEL: define dso_local void @_Z1fIiEvT_
+
 // Make sure we've picked deallocator for the correct side of compilation.
 
 // COMMON-LABEL: define  linkonce_odr void @_ZN4H1D1dlEPv(i8* %0)
@@ -131,3 +147,5 @@ __host__ __device__ void tests_hd(void *t) {
 // COMMON-LABEL: define  linkonce_odr void @_ZN8H1H2D1D2dlEPv(i8* %0)
 // DEVICE: call void @dev_fn()
 // HOST: call void @host_fn()
+
+// DEVICE: !0 = !{void (i32)* @_Z1fIiEvT_, !"kernel", i32 1}

diff  --git 

[PATCH] D82862: [ThinLTO] Always parse module level inline asm with At dialect

2021-01-21 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D82862#2512908 , @uweigand wrote:

> So why do you want GNU inline asm for clang-cl anyway?   I thought the whole 
> point of clang-cl was to be compatible with the Microsoft Visual Studio 
> compiler, which I understand only supports the MS asm syntax?

We have users, in this case, I think it's V8, who would prefer to use gcc-style 
module level assembly if it is available. Their motivation is somewhat 
arbitrary, but generally, clang-cl supports a variety of extensions, some 
inherited from GCC, in all modes. Part of the point of switching compilers from 
MSVC to clang is to get access to those extensions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82862

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


[PATCH] D94583: [RISCV] Update V extension to v1.0-draft 08a0b464.

2021-01-21 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper 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/D94583/new/

https://reviews.llvm.org/D94583

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


[PATCH] D92191: [clang-scan-deps] Add support for clang-cl

2021-01-21 Thread Sylvain Audi via Phabricator via cfe-commits
saudi marked an inline comment as done.
saudi added inline comments.



Comment at: clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json:4-5
   "directory": "DIR",
-  "command": "clang --analyze DIR/static-analyzer.c",
-  "file": "DIR/static-analyzer.c"
+  "command": "clang --analyze -- DIR/static-analyzer_clang.c",
+  "file": "DIR/static-analyzer_clang.c"
+},

dexonsmith wrote:
> It's not clear why you made these changes. Can you clarify?
The added "--" was not necessary, I removed it.
The added "_clang" was because I added a `CHECK:` line for the `.c` file, but 
"static-analyzer.c" would cause false positives with %S.
  -> see the new comment in the static-analyzer.c


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

https://reviews.llvm.org/D92191

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


[PATCH] D94979: [CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC

2021-01-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

I don't particularly want/like to straight-up derail this,
but my opinion still hasn't changed, and it is not unsubstantiated,
see https://lists.llvm.org/pipermail/llvm-dev/2019-May/132080.html, 
https://lists.llvm.org/pipermail/llvm-dev/2019-October/136115.html, etc,

I think the fact that last *two* recent-ish RFC's on this didn't succeed
suggests that a third one might be in order, perhaps with better arguments
this time, or maybe the previous opponents will just not block this..

TBN, i don't dislike the feature per-se, at least without seeing the full 
impact of the cleanup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94979

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


[PATCH] D92191: [clang-scan-deps] Add support for clang-cl

2021-01-21 Thread Sylvain Audi via Phabricator via cfe-commits
saudi updated this revision to Diff 318248.
saudi edited the summary of this revision.
saudi added a comment.

Removed the support for "--" command lines, it was extracted to patch D95099 
.
Applied suggested fixes.


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

https://reviews.llvm.org/D92191

Files:
  clang/test/ClangScanDeps/Inputs/has_include_if_elif.json
  clang/test/ClangScanDeps/Inputs/header_stat_before_open_cdb.json
  clang/test/ClangScanDeps/Inputs/headerwithdirname.json
  clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
  clang/test/ClangScanDeps/Inputs/modules_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/no-werror.json
  clang/test/ClangScanDeps/Inputs/regular_cdb_clangcl.json
  clang/test/ClangScanDeps/Inputs/static-analyzer-cdb.json
  clang/test/ClangScanDeps/Inputs/strip_diag_serialize.json
  clang/test/ClangScanDeps/Inputs/target-filename-cdb.json
  clang/test/ClangScanDeps/Inputs/vfsoverlay_cdb.json
  clang/test/ClangScanDeps/error.cpp
  clang/test/ClangScanDeps/has_include_if_elif.cpp
  clang/test/ClangScanDeps/header_stat_before_open.m
  clang/test/ClangScanDeps/headerwithdirname.cpp
  clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/ClangScanDeps/modules.cpp
  clang/test/ClangScanDeps/no-werror.cpp
  clang/test/ClangScanDeps/regular_cdb.cpp
  clang/test/ClangScanDeps/static-analyzer.c
  clang/test/ClangScanDeps/strip_diag_serialize.cpp
  clang/test/ClangScanDeps/target-filename.cpp
  clang/test/ClangScanDeps/vfsoverlay.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -12,6 +12,8 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/InitLLVM.h"
@@ -49,7 +51,8 @@
   /// option and cache the results for reuse. \returns resource directory path
   /// associated with the given invocation command or empty string if the
   /// compiler path is NOT an absolute path.
-  StringRef findResourceDir(const tooling::CommandLineArguments ) {
+  StringRef findResourceDir(const tooling::CommandLineArguments ,
+bool ClangCLMode) {
 if (Args.size() < 1)
   return "";
 
@@ -65,8 +68,12 @@
 if (CachedResourceDir != Cache.end())
   return CachedResourceDir->second;
 
-std::vector PrintResourceDirArgs{ClangBinaryName,
-"-print-resource-dir"};
+std::vector PrintResourceDirArgs{ClangBinaryName};
+if (ClangCLMode)
+  PrintResourceDirArgs.push_back("/clang:-print-resource-dir");
+else
+  PrintResourceDirArgs.push_back("-print-resource-dir");
+
 llvm::SmallString<64> OutputFile, ErrorFile;
 llvm::sys::fs::createTemporaryFile("print-resource-dir-output",
"" /*no-suffix*/, OutputFile);
@@ -421,26 +428,54 @@
 bool HasMQ = false;
 bool HasMD = false;
 bool HasResourceDir = false;
+bool ClangCLMode = false;
 auto ArgsEnd = llvm::find(Args, "--");
 
 // We need to find the last -o value.
 if (!Args.empty()) {
+  ClangCLMode =
+  llvm::sys::path::stem(Args[0]).contains_lower("clang-cl") ||
+  llvm::is_contained(Args, "--driver-mode=cl");
+
   // Reverse scan, starting at the end or at the element before "--".
   auto ArgsRBegin = llvm::make_reverse_iterator(ArgsEnd);
   for (auto It = ArgsRBegin; It != Args.rend(); ++It) {
 StringRef Arg = *It;
-if (LastO.empty()) {
-  if (Arg == "-o" && It != ArgsRBegin)
-LastO = *(It - 1); // Next argument (reverse iterator)
-  else if (Arg.startswith("-o"))
-LastO = Arg.drop_front(2).str();
+if (ClangCLMode) {
+  if (LastO.empty()) {
+// With clang-cl, the output obj file can be specified with
+// "/opath", "/o path", "/Fopath", and the dash counterparts.
+// Also, clang-cl adds ".obj" extension if none is found.
+if ((Arg == "-o" || Arg == "/o") && It != ArgsRBegin)
+  LastO = *(It - 1); // Next argument (reverse iterator)
+else if (Arg.startswith("/Fo") || Arg.startswith("-Fo"))
+  LastO = Arg.drop_front(3).str();
+else if (Arg.startswith("/o") || Arg.startswith("-o"))
+  LastO = 

[PATCH] D94814: [HIP] Support `__managed__` attribute

2021-01-21 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D94814

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


[PATCH] D94979: [CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC

2021-01-21 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope added a comment.

@lebedev.ri : I think I need your blessing as well on this, considering your 
earlier concerns. Is it still just confusing? (I doubt that we want/can replace 
all uses of getCharWidth/getIntWidth etc in clang with integers)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94979

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


[PATCH] D82862: [ThinLTO] Always parse module level inline asm with At dialect

2021-01-21 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

In D82862#2500717 , @hans wrote:

>> In D82862#2498785 , @hans wrote:
>>
>>> The motivation for my change was really just to make ThinLTO compiles work 
>>> the same as non-ThinLTO ones.
>>>
>>> Maybe the fact that -x86-asm-syntax=intel doesn't affect inline asm is a 
>>> bug. I wasn't aware that Clang and GCC's -masm= flags behaved differently 
>>> in that way, but that certainly suggests there's a problem here.
>>
>> So I'm wondering, if I remove the above setAssemblerDialect line **and** 
>> revert this commit, we should have inline asm (both module-level and GNU 
>> function-leve) respect the target-selected asm dialect variant both for 
>> ThinLTO and non-ThinLTO, so they should match again.   Would that also solve 
>> the problem you were originally tracking?
>
> Not completely, because clang-cl sets -x86-asm-syntax=intel to enable 
> intel-style asm in assembly listing output. We'd have to find another way of 
> doing that without affecting the inline asm dialect.

So why do you want GNU inline asm for clang-cl anyway?   I thought the whole 
point of clang-cl was to be compatible with the Microsoft Visual Studio 
compiler, which I understand only supports the MS asm syntax?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82862

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


[PATCH] D94814: [HIP] Support `__managed__` attribute

2021-01-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 318243.
yaxunl marked an inline comment as done.
yaxunl added a comment.

revised by Artem's and Aaron's comments.


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

https://reviews.llvm.org/D94814

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CGCUDARuntime.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/Inputs/cuda.h
  clang/test/AST/ast-dump-managed-var.cu
  clang/test/CodeGenCUDA/Inputs/cuda.h
  clang/test/CodeGenCUDA/managed-var.cu
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCUDA/Inputs/cuda.h
  clang/test/SemaCUDA/bad-attributes.cu
  clang/test/SemaCUDA/device-var-init.cu
  clang/test/SemaCUDA/function-overload.cu
  clang/test/SemaCUDA/managed-var.cu
  clang/test/SemaCUDA/union-init.cu
  llvm/include/llvm/IR/ReplaceConstant.h
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/IR/ReplaceConstant.cpp
  llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp

Index: llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp
===
--- llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp
+++ llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp
@@ -21,6 +21,7 @@
 #include "llvm/IR/IntrinsicsXCore.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/NoFolder.h"
+#include "llvm/IR/ReplaceConstant.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/CommandLine.h"
@@ -74,57 +75,6 @@
   return ConstantArray::get(NewType, Elements);
 }
 
-static Instruction *
-createReplacementInstr(ConstantExpr *CE, Instruction *Instr) {
-  IRBuilder Builder(Instr);
-  unsigned OpCode = CE->getOpcode();
-  switch (OpCode) {
-case Instruction::GetElementPtr: {
-  SmallVector CEOpVec(CE->operands());
-  ArrayRef CEOps(CEOpVec);
-  return dyn_cast(Builder.CreateInBoundsGEP(
-  cast(CE)->getSourceElementType(), CEOps[0],
-  CEOps.slice(1)));
-}
-case Instruction::Add:
-case Instruction::Sub:
-case Instruction::Mul:
-case Instruction::UDiv:
-case Instruction::SDiv:
-case Instruction::FDiv:
-case Instruction::URem:
-case Instruction::SRem:
-case Instruction::FRem:
-case Instruction::Shl:
-case Instruction::LShr:
-case Instruction::AShr:
-case Instruction::And:
-case Instruction::Or:
-case Instruction::Xor:
-  return dyn_cast(
-  Builder.CreateBinOp((Instruction::BinaryOps)OpCode,
-  CE->getOperand(0), CE->getOperand(1),
-  CE->getName()));
-case Instruction::Trunc:
-case Instruction::ZExt:
-case Instruction::SExt:
-case Instruction::FPToUI:
-case Instruction::FPToSI:
-case Instruction::UIToFP:
-case Instruction::SIToFP:
-case Instruction::FPTrunc:
-case Instruction::FPExt:
-case Instruction::PtrToInt:
-case Instruction::IntToPtr:
-case Instruction::BitCast:
-  return dyn_cast(
-  Builder.CreateCast((Instruction::CastOps)OpCode,
- CE->getOperand(0), CE->getType(),
- CE->getName()));
-default:
-  llvm_unreachable("Unhandled constant expression!\n");
-  }
-}
 
 static bool replaceConstantExprOp(ConstantExpr *CE, Pass *P) {
   do {
Index: llvm/lib/IR/ReplaceConstant.cpp
===
--- /dev/null
+++ llvm/lib/IR/ReplaceConstant.cpp
@@ -0,0 +1,70 @@
+//===- ReplaceConstant.cpp - Replace LLVM constant expression--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements a utility function for replacing LLVM constant
+// expressions by instructions.
+//
+//===--===//
+
+#include "llvm/IR/ReplaceConstant.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/NoFolder.h"
+
+namespace llvm {
+// Replace a constant expression by instructions with equivalent operations at
+// a specified location.
+Instruction *createReplacementInstr(ConstantExpr *CE, Instruction *Instr) {
+  IRBuilder Builder(Instr);
+  unsigned OpCode = CE->getOpcode();
+  switch (OpCode) {
+  case Instruction::GetElementPtr: {
+SmallVector CEOpVec(CE->operands());
+ArrayRef CEOps(CEOpVec);
+return dyn_cast(
+Builder.CreateInBoundsGEP(cast(CE)->getSourceElementType(),
+  CEOps[0], CEOps.slice(1)));
+  }
+  case Instruction::Add:
+  case 

[PATCH] D94820: Support for instrumenting only selected files or functions

2021-01-21 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:851
+return "csllvm";
+  default:
+llvm_unreachable("unknown instrumentation type");

If we add an instrumentation kind, it may be more convenient to trigger a 
-Wcovered-switch warning (by removing this default case) vs. seeing a crash at 
runtime.


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

https://reviews.llvm.org/D94820

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


[PATCH] D95147: [clang][cli] Port visibility LangOptions to marshalling system

2021-01-21 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, Bigcheese.
Herald added a subscriber: dang.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch introduces Clang-specific MarshallingInfoVisibility TableGen class.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95147

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2061,24 +2061,6 @@
   Opts.DoubleSquareBracketAttributes = Opts.CPlusPlus11 || Opts.C2x;
 }
 
-/// Attempt to parse a visibility value out of the given argument.
-static Visibility parseVisibility(Arg *arg, ArgList ,
-  DiagnosticsEngine ) {
-  StringRef value = arg->getValue();
-  if (value == "default") {
-return DefaultVisibility;
-  } else if (value == "hidden" || value == "internal") {
-return HiddenVisibility;
-  } else if (value == "protected") {
-// FIXME: diagnose if target does not support protected visibility
-return ProtectedVisibility;
-  }
-
-  diags.Report(diag::err_drv_invalid_value)
-<< arg->getAsString(args) << value;
-  return DefaultVisibility;
-}
-
 /// Check if input file kind and language standard are compatible.
 static bool IsInputCompatibleWithStandard(InputKind IK,
   const LangStandard ) {
@@ -2366,45 +2348,6 @@
   Opts.GNUInline = 1;
   }
 
-  // The type-visibility mode defaults to the value-visibility mode.
-  if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) {
-Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags));
-  } else {
-Opts.setTypeVisibilityMode(Opts.getValueVisibilityMode());
-  }
-
-  if (Args.hasArg(OPT_fvisibility_from_dllstorageclass)) {
-Opts.VisibilityFromDLLStorageClass = 1;
-
-// Translate dllexport defintions to default visibility, by default.
-if (Arg *O = Args.getLastArg(OPT_fvisibility_dllexport_EQ))
-  Opts.setDLLExportVisibility(parseVisibility(O, Args, Diags));
-else
-  Opts.setDLLExportVisibility(DefaultVisibility);
-
-// Translate defintions without an explict DLL storage class to hidden
-// visibility, by default.
-if (Arg *O = Args.getLastArg(OPT_fvisibility_nodllstorageclass_EQ))
-  Opts.setNoDLLStorageClassVisibility(parseVisibility(O, Args, Diags));
-else
-  Opts.setNoDLLStorageClassVisibility(HiddenVisibility);
-
-// Translate dllimport external declarations to default visibility, by
-// default.
-if (Arg *O = Args.getLastArg(OPT_fvisibility_externs_dllimport_EQ))
-  Opts.setExternDeclDLLImportVisibility(parseVisibility(O, Args, Diags));
-else
-  Opts.setExternDeclDLLImportVisibility(DefaultVisibility);
-
-// Translate external declarations without an explicit DLL storage class
-// to hidden visibility, by default.
-if (Arg *O = Args.getLastArg(OPT_fvisibility_externs_nodllstorageclass_EQ))
-  Opts.setExternDeclNoDLLStorageClassVisibility(
-  parseVisibility(O, Args, Diags));
-else
-  Opts.setExternDeclNoDLLStorageClassVisibility(HiddenVisibility);
-  }
-
   if (Args.hasArg(OPT_ftrapv)) {
 Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping);
 // Set the handler, if one is specified.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -510,6 +510,14 @@
   Group;
 }
 
+// FIXME: Diagnose if target does not support protected visibility.
+class MarshallingInfoVisibility
+  : MarshallingInfoString,
+Values<"default,hidden,internal,protected">,
+NormalizedValues<["DefaultVisibility", "HiddenVisibility",
+  "HiddenVisibility", "ProtectedVisibility"]>,
+AutoNormalizeEnum {}
+
 // Key paths that are constant during parsing of options with the same key path prefix.
 defvar open_cl = LangOpts<"OpenCL">;
 
@@ -2482,15 +2490,26 @@
 def fverbose_asm : Flag<["-"], "fverbose-asm">, Group,
   HelpText<"Generate verbose assembly output">;
 def dA : Flag<["-"], "dA">, Alias;
-defm visibility_from_dllstorageclass : OptInFFlag<"visibility-from-dllstorageclass", "Set the visiblity of symbols in the generated code from their DLL storage class">;
+defm visibility_from_dllstorageclass : BoolFOption<"visibility-from-dllstorageclass",
+  LangOpts<"VisibilityFromDLLStorageClass">, DefaultsToFalse,
+  ChangedBy,
+  ResetBy>;
 def fvisibility_dllexport_EQ : Joined<["-"], "fvisibility-dllexport=">, Group, Flags<[CC1Option]>,
-  HelpText<"The visibility for dllexport defintions [-fvisibility-from-dllstorageclass]">, Values<"hidden,protected,default">;
+  

[PATCH] D94814: [HIP] Support `__managed__` attribute

2021-01-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 9 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7728
+  case ParsedAttr::AT_HIPManaged:
+handleSimpleAttributeWithExclusions(S, D,
+AL);

aaron.ballman wrote:
> aaron.ballman wrote:
> > tra wrote:
> > > The code changes in the patch appear to treat `__managed__` variable as a 
> > > superset of a `__device__` var. If that's indeed the case, adding an 
> > > implicit `__device__` attribute here would help to simplify the code. 
> > > This way the existing code can handle generic  `__device__` var 
> > > functionality without additional changes, and would use `__managed__` 
> > > checks for the cases specific for managed vars only.
> > > 
> > I think you're missing changes to the CUDA global attr to check for mutual 
> > exclusions with `__managed__` as well. Also, I think this won't do the 
> > right thing for redeclarations, like:
> > ```
> > __device__ extern int i;
> > __managed__ extern int i;
> > ```
> > This way the existing code can handle generic __device__ var functionality 
> > without additional changes, and would use __managed__ checks for the cases 
> > specific for managed vars only.
> 
> Another alternative to consider is to not create a new semantic attribute 
> named `HIPManagedAttr` but to instead add a new spelling to `CUDADevice` in 
> `Attr.td`, giving the class an `Accessor` to distinguish which spelling the 
> user wrote in code, and use that accessor for the specific cases for managed 
> vars.
I will add an implicit device attr for managed attr. I think this will have a 
more readable AST.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7728
+  case ParsedAttr::AT_HIPManaged:
+handleSimpleAttributeWithExclusions(S, D,
+AL);

yaxunl wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > tra wrote:
> > > > The code changes in the patch appear to treat `__managed__` variable as 
> > > > a superset of a `__device__` var. If that's indeed the case, adding an 
> > > > implicit `__device__` attribute here would help to simplify the code. 
> > > > This way the existing code can handle generic  `__device__` var 
> > > > functionality without additional changes, and would use `__managed__` 
> > > > checks for the cases specific for managed vars only.
> > > > 
> > > I think you're missing changes to the CUDA global attr to check for 
> > > mutual exclusions with `__managed__` as well. Also, I think this won't do 
> > > the right thing for redeclarations, like:
> > > ```
> > > __device__ extern int i;
> > > __managed__ extern int i;
> > > ```
> > > This way the existing code can handle generic __device__ var 
> > > functionality without additional changes, and would use __managed__ 
> > > checks for the cases specific for managed vars only.
> > 
> > Another alternative to consider is to not create a new semantic attribute 
> > named `HIPManagedAttr` but to instead add a new spelling to `CUDADevice` in 
> > `Attr.td`, giving the class an `Accessor` to distinguish which spelling the 
> > user wrote in code, and use that accessor for the specific cases for 
> > managed vars.
> I will add an implicit device attr for managed attr. I think this will have a 
> more readable AST.
Actually `__managed__` does not need exclude with `__global__` since 
`__global__` cannot be used with variable. However, `__managed__` need to 
exclude with `__constant__` and `__shared__`. I will add handling for that.

`__managed__` should behave the same as `__device__` regarding compatibility 
with `extern`. It is allowed to be with `extern`. Currently for `extern 
__device__` var, on device side, it is treated as a normal device variable with 
definition; on host side, the shadow variable is emitted with internal linkage. 
This is fine for the default -fno-gpu-rdc mode. However, this does not work for 
-fgpu-rdc mode. For -fgpu-rdc mode, both device variable and shadow variable 
should be declarations. Since this issue is orthogonal to `__managed__`, I will 
create a separate patch to fix it.


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

https://reviews.llvm.org/D94814

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


[PATCH] D95145: [clang] Fix a nullptr dereference bug on invalid code

2021-01-21 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: hokein.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When working with invalid code, we would try to dereference a nullptr
while deducing template arguments in some dependend code operating on a
lambda with invalid return type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95145

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp


Index: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify
+#include 
+
+template 
+auto Call(T x) -> typename std::result_of::type {} // 
expected-note{{candidate template ignored}}
+
+class Status {};
+
+void fun() {
+  // The Status() (instead of Status) here used to cause a crash.
+  Call([](auto x) -> Status() {}); // expected-error{{function cannot return 
function type 'Status ()}}
+  // expected-error@-1{{no matching function for call to 'Call'}}
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4189,6 +4189,9 @@
   for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams();
OldIdx != NumOldParams; ++OldIdx) {
 ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx);
+if (!OldParam)
+  return nullptr;
+
 LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope;
 
 Optional NumArgumentsInExpansion;


Index: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify
+#include 
+
+template 
+auto Call(T x) -> typename std::result_of::type {} // expected-note{{candidate template ignored}}
+
+class Status {};
+
+void fun() {
+  // The Status() (instead of Status) here used to cause a crash.
+  Call([](auto x) -> Status() {}); // expected-error{{function cannot return function type 'Status ()}}
+  // expected-error@-1{{no matching function for call to 'Call'}}
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4189,6 +4189,9 @@
   for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams();
OldIdx != NumOldParams; ++OldIdx) {
 ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx);
+if (!OldParam)
+  return nullptr;
+
 LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope;
 
 Optional NumArgumentsInExpansion;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76545: [clang-tidy] Add a new check group 'experimental-'

2021-01-21 Thread Whisperity via Phabricator via cfe-commits
whisperity abandoned this revision.
whisperity added a comment.

Obsolete. There was no community consensus, or even a large enough discussion 
about this. What's more, the only dependee of this patch has superseded in 
ellegance, dropping the need for this group.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76545

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


[PATCH] D75041: [clang-tidy] Approximate implicit conversion issues in 'experimental-cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type'

2021-01-21 Thread Whisperity via Phabricator via cfe-commits
whisperity planned changes to this revision.
whisperity added a comment.

This patch will be replaced with the refactoring of the base check.


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

https://reviews.llvm.org/D75041

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


[PATCH] D78652: [clang-tidy] Add "ignore related parameters" heuristics to 'experimental-cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type'

2021-01-21 Thread Whisperity via Phabricator via cfe-commits
whisperity planned changes to this revision.
whisperity added a comment.
Herald added a subscriber: shchenz.

This patch will be replaced with the refactoring of the base check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78652

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


[PATCH] D69560: [clang-tidy] Add 'bugprone-easily-swappable-parameters' check

2021-01-21 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 318220.
whisperity retitled this revision from "[clang-tidy] Add 
'experimental-cppcoreguidelines-avoid-adjacent-parameters-of-the-same-type' 
check" to "[clang-tidy] Add 'bugprone-easily-swappable-parameters' check".
whisperity edited the summary of this revision.
whisperity removed a reviewer: baloghadamsoftware.
whisperity set the repository for this revision to rG LLVM Github Monorepo.
whisperity removed a subscriber: o.gyorgy.
whisperity added a comment.

Refactored the check and rebased it against "current" `master`. This version 
now has the tests rewritten and fixed. In addition, this patch only introduces 
the **very basic** frame of the check (i.e. only //strict type equality//), 
nothing more. This is so that review can be done in a more digestible way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 3}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""} \
+// RUN:  ]}' --
+
+int add(int Left, int Right) { return Left + Right; } // NO-WARN: Only 2 parameters.
+
+int magic(int Left, int Right, int X, int Y) { return 0; }
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 4 adjacent parameters of 'magic' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
+// CHECK-MESSAGES: :[[@LINE-2]]:15: note: the first parameter in the range is 'Left'
+// CHECK-MESSAGES: :[[@LINE-3]]:43: note: the last parameter in the range is 'Y'
+
+void multipleDistinctTypes(int I, int J, int K,
+   long L, long M,
+   double D, double E, double F) {}
+// CHECK-MESSAGES: :[[@LINE-3]]:28: warning: 3 adjacent parameters of 'multipleDistinctTypes' of similar type ('int')
+// CHECK-MESSAGES: :[[@LINE-4]]:32: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-5]]:46: note: the last parameter in the range is 'K'
+// NO-WARN: The [long, long] range is length of 2.
+// CHECK-MESSAGES: :[[@LINE-5]]:28: warning: 3 adjacent parameters of 'multipleDistinctTypes' of similar type ('double')
+// CHECK-MESSAGES: :[[@LINE-6]]:35: note: the first parameter in the range is 'D'
+// CHECK-MESSAGES: :[[@LINE-7]]:55: note: the last parameter in the range is 'F'
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
@@ -0,0 +1,112 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: ""} \
+// RUN:  ]}' --
+
+#define assert(X)
+
+void declaration(int Param, int Other); // NO-WARN: No chance to change this function.
+
+struct S {};
+
+S *allocate() { return nullptr; }   // NO-WARN: 1 parameter.
+void allocate(S **Out) {}   // NO-WARN: 1 parameter.
+bool operator<(const S , const S ) { return true; } // NO-WARN: Operator.
+
+void redeclChain(int, int, int);
+void redeclChain(int I, int, int);
+void redeclChain(int, int J, int);
+void redeclChain(int I, int J, int K) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 3 adjacent parameters of 'redeclChain' of similar type ('int') are easily swapped by 

  1   2   >