[PATCH] D120540: [Driver] Enable to use C++20 modules standalone by -fcxx-modules

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

@aprantl Thanks for the reverting. I never image `-fcxx-modules` would refer to 
Clang C++ modules. So the problem becomes more complicated.

In D120540#3551169 , @iains wrote:

> I guess Chuanqi's TZ is in sleep mode at the moment, so the revert makes 
> sense.
>
> Please let's not use -fmodules-ts to mean anything - we want to phase it out 
> and make it a NOP (we are implementing the standardised modules; I do not see 
> anyone putting effort into finishing the ts implementation).
>
> my suggestion is to introduce `-fmodules={cxx20, clang, etc. etc}` where 
> `-fmodules` is mapped in the driver to `-fmodules=clang` ... and to introduce 
> an enumeration in the options that is visible in the FE so that we can be 
> explicit in checking **which** kind of modules we mean at each stage.
>
> unfortunately, right now I cannot volunteer to implement the suggestion ...

Now I feel your proposal looks better. Given the current complexity we saw,  I 
feel it might be better to disambiguate the meaning of modules in clang first 
and I filed an issue: https://github.com/llvm/llvm-project/issues/55891. So 
that we could avoid discussing the same problem again and again in different 
review pages.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120540

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


[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable (1/3)

2022-06-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

In D125291#3535196 , @nhaehnle wrote:

> You can use the "Edit Related Revisions" option in the right-hand side menu 
> of Phabricator to link this revision with the others of the series.

I forgot to reply this one. It is intended to not add related revisions. Since 
these revisions don't depend on each other from the perspective of codes. We 
could commit them in either order.

In D125291#3548671 , @jyknight wrote:

> So, I've been spending some significant time looking into this. I found that 
> I couldn't really review this change for correctness, because I find it 
> basically impossible to figure out whether the intrinsic calls have actually 
> been added to all the right places in Clang or not. (And my intuition said 
> "not", but then couldn't tell me where it's wrong.)

Thanks for spending the time! To answer the question "Whether the intrinsic 
calls have actually been added to all the right places in Clang or not", I 
insert a verify pass in the beginning of the middle end pipeline to verify if 
all the uses of TLS variable is wrapped by the intrinsic. And my conclusion is 
NO. Not all the places is guarded by the intrinsic. Concretely, the dynamic 
initializer of TLS variable. See https://www.godbolt.org/z/a4bK8v67o. I am not 
sure if this is the RIGHT place you said.

> So, I started hacking up a prototype of a change to make the type of a TLS 
> global variable be `token` instead of `ptr`. This allows missing calls to 
> manifest as IR construction errors.
>
> So far the biggest missing piece that identified in this review is 
> function-local thread_locals (although I haven't actually gotten something 
> fully working). Sadly, the handling of function-local statics in Clang is 
> really rather hairy, what with objc blocks and openmp support both doing 
> things that seem rather ill-advised to me. I'm toying with some cleanups 
> there, to see if it can be simplified a bit. I don't have a full idea, yet, 
> what changes need to be made to this review.

Thanks for pointing this out! I also spent significant time to try to handle 
function-local thread locals in the last few days. And I have't found a 
solution yet. It is more complex indeed.

> Anyhow -- I think the prototype I'm fiddling with is also along the path to 
> the ideal long-term state, but pushing it beyond a prototype seems like it'll 
> be a pain in the ass due to the bitcode compatibility requirement. (The 
> bitcode upgrader would need to know how to transform all constant expressions 
> using a TLS global into non-constant IR instructions, starting with a call to 
> llvm.threadlocal.address -- in every function where the "constant" is 
> referenced. For uses outside a function body, it transforms to an arbitrary 
> address (e.g. null), instead.)

Oh, I never heard about the IR upgrader before. This is missed indeed.

---

Summarize things up. Here are 3 problems we found:
(1) The use in the dynamic initializer of TLS variable.
(2) Function local thread locals.
(3) IR Upgrader.

From my perspective, only the second problem (2) is the problem we must solve. 
The first problem looks fine to me in practice. And I am wondering if it is 
problem for the third problem. Since if I understand the problem correctly, it 
means that the newer compiler couldn't compile the IR from older compiler. And 
I think it wouldn't be that case after the patch landed. Do I misunderstand it?


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

https://reviews.llvm.org/D125291

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


[PATCH] D112661: [clangd] reuse preambles from other files when possible

2022-06-06 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

@qchateau How should I interpret the abandoning of this patch -- did you run 
into a problem with the approach, or just don't have the time / interest to 
pursue it further?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112661

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


[PATCH] D127005: [clang-format][NFC] Clean up the unwrapped line parser

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

LGTM


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

https://reviews.llvm.org/D127005

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


[PATCH] D126845: [clang-format] Handle Verilog numbers and operators

2022-06-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/FormatToken.h:1417
   // Workaround for hashes and backticks in Verilog.
   IdentifierInfo *verilogHash;
   IdentifierInfo *verilogHashHash;

maybe `kw_verilogHash` and `kw_verilogHashHash` and `kw_quote` for clarity when 
using isOneOf



Comment at: clang/lib/Format/FormatToken.h:1421
+  // Symbols in Verilog that don't exist in C++.
+  IdentifierInfo *quote;
+

HazardyKnusperkeks wrote:
> apostrophe
kw_apostrophe?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126845

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


[PATCH] D127054: [clang-format] Handle attributes for for/while loops

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

nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127054

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


[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

2022-06-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In D126364#3556943 , @efriedma wrote:

> Given we have getEffectiveRoundingMode(), I think the calls to 
> setRoundingModeOverride shouldn't be necessary?  And if we drop those calls, 
> we can also drop the IsRoundingModeSet variable.

In the block:

  {
  #pragma STDC FENV_ACCESS ON
  fesetround(x);
  ...
  }

floating point operations must have rounding mode `dynamic`. If handler of 
FENV_ACCESS does not set it, the rounding mode remains FE_TONEAREST, which is 
incorrect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[PATCH] D126959: [C++20][Modules] Introduce an implementation module.

2022-06-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains planned changes to this revision.
iains added a comment.

thanks for the reviews, I need to figure out why the implementation passes 
clang tests but gives fails for clangd.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126959

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


[PATCH] D118034: [C++20] [Modules] Don't complain about duplicated default template argument across modules

2022-06-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 434411.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D118034

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/Modules/Inputs/redundant-template-default-arg/foo.cppm
  clang/test/Modules/Inputs/redundant-template-default-arg/foo.h
  clang/test/Modules/Inputs/redundant-template-default-arg2/foo.cppm
  clang/test/Modules/Inputs/redundant-template-default-arg3/foo.cppm
  clang/test/Modules/Inputs/redundant-template-default-arg3/foo.h
  clang/test/Modules/Inputs/redundant-template-default-arg3/foo_bad.h
  clang/test/Modules/redundant-template-default-arg.cpp
  clang/test/Modules/redundant-template-default-arg2.cpp
  clang/test/Modules/redundant-template-default-arg3.cpp

Index: clang/test/Modules/redundant-template-default-arg3.cpp
===
--- /dev/null
+++ clang/test/Modules/redundant-template-default-arg3.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: %clang_cc1  -std=c++20 %S/Inputs/redundant-template-default-arg3/foo.cppm -I%S/Inputs/redundant-template-default-arg3/. -emit-module-interface -o %t/foo.pcm
+// RUN: %clang_cc1  -fprebuilt-module-path=%t -std=c++20 %s -I%S/Inputs/redundant-template-default-arg3/. -fsyntax-only -verify
+
+import foo;
+#include "foo_bad.h"
+
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:1 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:1 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:4 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:4 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:10 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:10 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:17 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:13 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:23 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:16 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:27 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:20 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:31 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:24 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:34 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:27 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:40 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:33 {{previous default template argument defined in module foo.}}
Index: clang/test/Modules/redundant-template-default-arg2.cpp
===
--- /dev/null
+++ clang/test/Modules/redundant-template-default-arg2.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: %clang_cc1  -std=c++20 %S/Inputs/redundant-template-default-arg2/foo.cppm -I%S/Inputs/redundant-template-default-arg2/. -emit-module-interface -o %t/foo.pcm
+// RUN: %clang_cc1  -fprebuilt-module-path=%t -std=c++20 %s -fsyntax-only -verify
+import foo;
+template 
+T v; // expected-error {{declaration of 'v' in the global module follows declaration in module foo}}
+ // expected-note@Inputs/redundant-template-default-arg2/foo.cppm:3 {{previous declaration is here}}
+
+template 
+int v2; // expected-error {{declaration of 'v2' in the global module follows declaration in module foo}}
+// expected-note@Inputs/redundant-template-default-arg2/foo.cppm:6 {{previous declaration is 

[PATCH] D127093: [clang][pseudo] Add missing Support lib to cxx

2022-06-06 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett created this revision.
Herald added subscribers: jsji, pengfei, mgorny.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

Without this the following build config fails.

cmake ../llvm-project/llvm -DCMAKE_BUILD_TYPE=Debug \

  -DLLVM_TARGETS_TO_BUILD=X86 -DBUILD_SHARED_LIBS=ON \
  -DLLVM_APPEND_VC_REV=OFF 
-DLLVM_ENABLE_PROJECTS="lldb;clang;clang-tools-extra" \
  -G Ninja

With:
ld.lld: error: undefined symbol: llvm::EnableABIBreakingChecks

>>> referenced by CXX.cpp
>>>
>>>   
>>> tools/clang/tools/extra/pseudo/lib/cxx/CMakeFiles/obj.clangPseudoCXX.dir/CXX.cpp.o:(llvm::VerifyEnableABIBreakingChecks)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127093

Files:
  clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt


Index: clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
===
--- clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
+++ clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(LLVM_LINK_COMPONENTS Support)
+
 add_clang_library(clangPseudoCXX
   CXX.cpp
 


Index: clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
===
--- clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
+++ clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(LLVM_LINK_COMPONENTS Support)
+
 add_clang_library(clangPseudoCXX
   CXX.cpp
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127093: [clang][pseudo] Add missing Support lib to cxx

2022-06-06 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added reviewers: sammccall, MaskRay.
DavidSpickett added a comment.
Herald added a subscriber: StephenFan.

I'm basing this on what `psuedo/lib/grammar` does, so I'm not totally sure this 
is the place to fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127093

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


[PATCH] D127093: [clang][pseudo] Add missing Support lib to cxx

2022-06-06 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

`DBUILD_SHARED_LIBS` being the key setting in the config that causes the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127093

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


[PATCH] D118034: [C++20] [Modules] Don't complain about duplicated default template argument across modules

2022-06-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked 10 inline comments as done.
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:2762
 SawDefaultArgument = true;
-RedundantDefaultArg = true;
+if (!OldTypeParm->getImportedOwningModule())
+  RedundantDefaultArg = true;

rsmith wrote:
> This is the wrong thing to check -- whether the owning module is imported 
> (from an AST file) is irrelevant. We might parse multiple translation units 
> in the same compilation, and we might split a single translation unit into 
> multiple compilations (eg with a precompiled preamble) resulting in some of 
> the same translation unit being in an AST file. What matters is whether the 
> declaration is in the current translation unit or a different translation 
> unit.
> 
> I'm not sure what the best way to detect that is currently. You might be able 
> to just compare `getOwningModule()` of the two declarations, but I don't 
> think that will properly handle cases in the global module fragment, or cases 
> where one template is in the primary module interface unit and another is in 
> a module implementation unit of the same module.
> 
> Ideally I would like for us to create one `TranslationUnitDecl` per 
> translation unit, rather than shoving all imported code into the translation 
> unit of the importer, but that's a moderately large change, which I'd like to 
> not block this change on if we can avoid it. But I think that's the right 
> longer-term approach. Then here we would just need to find the 
> lexically-enclosing `TranslationUnitDecl` for each template parameter and see 
> if they're the same.
I found we could determine whether the declaration is in the current TU or not 
by using `Sema::ModuleScopes`, which contains the modules we're currently 
parsing.


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

https://reviews.llvm.org/D118034

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


[PATCH] D118034: [C++20] [Modules] Don't complain about duplicated default template argument across modules

2022-06-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 434415.
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

Remove unused header ODRHash.h


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

https://reviews.llvm.org/D118034

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/Modules/Inputs/redundant-template-default-arg/foo.cppm
  clang/test/Modules/Inputs/redundant-template-default-arg/foo.h
  clang/test/Modules/Inputs/redundant-template-default-arg2/foo.cppm
  clang/test/Modules/Inputs/redundant-template-default-arg3/foo.cppm
  clang/test/Modules/Inputs/redundant-template-default-arg3/foo.h
  clang/test/Modules/Inputs/redundant-template-default-arg3/foo_bad.h
  clang/test/Modules/redundant-template-default-arg.cpp
  clang/test/Modules/redundant-template-default-arg2.cpp
  clang/test/Modules/redundant-template-default-arg3.cpp

Index: clang/test/Modules/redundant-template-default-arg3.cpp
===
--- /dev/null
+++ clang/test/Modules/redundant-template-default-arg3.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: %clang_cc1  -std=c++20 %S/Inputs/redundant-template-default-arg3/foo.cppm -I%S/Inputs/redundant-template-default-arg3/. -emit-module-interface -o %t/foo.pcm
+// RUN: %clang_cc1  -fprebuilt-module-path=%t -std=c++20 %s -I%S/Inputs/redundant-template-default-arg3/. -fsyntax-only -verify
+
+import foo;
+#include "foo_bad.h"
+
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:1 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:1 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:4 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:4 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:10 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:10 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:17 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:13 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:23 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:16 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:27 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:20 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:31 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:24 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:34 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:27 {{previous default template argument defined in module foo.}}
+// expected-error@Inputs/redundant-template-default-arg3/foo_bad.h:40 {{template parameter default argument is inconsistent with previous definition}}
+// expected-note@Inputs/redundant-template-default-arg3/foo.h:33 {{previous default template argument defined in module foo.}}
Index: clang/test/Modules/redundant-template-default-arg2.cpp
===
--- /dev/null
+++ clang/test/Modules/redundant-template-default-arg2.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: %clang_cc1  -std=c++20 %S/Inputs/redundant-template-default-arg2/foo.cppm -I%S/Inputs/redundant-template-default-arg2/. -emit-module-interface -o %t/foo.pcm
+// RUN: %clang_cc1  -fprebuilt-module-path=%t -std=c++20 %s -fsyntax-only -verify
+import foo;
+template 
+T v; // expected-error {{declaration of 'v' in the global module follows declaration in module foo}}
+ // expected-note@Inputs/redundant-template-default-arg2/foo.cppm:3 {{previous declaration is here}}
+
+template 
+int v2; // expected-error {{declaration of 'v2' in the global module follows declaration in module foo}}
+// expected-note@Inputs/redundant-te

[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

2022-06-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 434417.
iains added a comment.
Herald added a reviewer: aaron.ballman.

this is a re-write - please see additional comments on the revised direction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126694

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp

Index: clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
===
--- clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
+++ clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
@@ -29,8 +29,7 @@
 #endif
 
 void test_early() {
-  in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
-  // expected-note@*{{not visible}}
+  in_header = 1; // expected-error {{use of undeclared identifier 'in_header'}}
 
   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
   // expected-n...@p2.cpp:16 {{not visible}}
@@ -54,8 +53,7 @@
 #endif
 
 void test_late() {
-  in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
-  // expected-note@*{{not visible}}
+  in_header = 1; // expected-error {{use of undeclared identifier 'in_header'}}
 
   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
   // expected-n...@p2.cpp:16 {{not visible}}
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -312,6 +312,7 @@
   Record.push_back(D->isTopLevelDeclInObjCContainer());
   Record.push_back(D->getAccess());
   Record.push_back(D->isModulePrivate());
+  Record.push_back(D->isModuleUnreachable());
   Record.push_back(Writer.getSubmoduleID(D->getOwningModule()));
 
   // If this declaration injected a name into a context different from its
@@ -394,6 +395,7 @@
   !D->isInvalidDecl() &&
   !D->isTopLevelDeclInObjCContainer() &&
   !D->isModulePrivate() &&
+  !D->isModuleUnreachable() &&
   !needsAnonymousDeclarationNumber(D) &&
   D->getDeclName().getNameKind() == DeclarationName::Identifier)
 AbbrevToUse = Writer.getDeclTypedefAbbrev();
@@ -464,6 +466,7 @@
   !D->isTopLevelDeclInObjCContainer() &&
   D->getAccess() == AS_none &&
   !D->isModulePrivate() &&
+  !D->isModuleUnreachable() &&
   !CXXRecordDecl::classofKind(D->getKind()) &&
   !D->getIntegerTypeSourceInfo() &&
   !D->getMemberSpecializationInfo() &&
@@ -501,6 +504,7 @@
   !D->isTopLevelDeclInObjCContainer() &&
   D->getAccess() == AS_none &&
   !D->isModulePrivate() &&
+  !D->isModuleUnreachable() &&
   !CXXRecordDecl::classofKind(D->getKind()) &&
   !needsAnonymousDeclarationNumber(D) &&
   D->getDeclName().getNameKind() == DeclarationName::Identifier)
@@ -803,6 +807,7 @@
   !D->isInvalidDecl() &&
   !D->isReferenced() &&
   !D->isModulePrivate() &&
+  !D->isModuleUnreachable() &&
   !D->getBitWidth() &&
   !D->hasExtInfo() &&
   D->getDeclName())
@@ -938,6 +943,7 @@
   !D->isReferenced() &&
   !D->isTopLevelDeclInObjCContainer() &&
   !D->isModulePrivate() &&
+  !D->isModuleUnreachable() &&
   !D->getBitWidth() &&
   !D->hasInClassInitializer() &&
   !D->hasCapturedVLAType() &&
@@ -1069,6 +1075,7 @@
   !D->isTopLevelDeclInObjCContainer() &&
   D->getAccess() == AS_none &&
   !D->isModulePrivate() &&
+  !D->isModuleUnreachable() &&
   !needsAnonymousDeclarationNumber(D) &&
   D->getDeclName().getNameKind() == DeclarationName::Identifier &&
   !D->hasExtInfo() &&
@@ -1117,6 +1124,7 @@
   !D->isReferenced() &&
   D->getAccess() == AS_none &&
   !D->isModulePrivate() &&
+  !D->isModuleUnreachable() &&
   D->getStorageClass() == 0 &&
   D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
   D->getFunctionScopeDepth() == 0 &&
@@ -1929,6 +1937,7 @@
   Abv->Add(BitCodeAbbrevOp(0));   // TopLevelDeclInObjCContainer
   Abv->Add(BitCodeAbbrevOp(

[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

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

@chuanqiXu, thanks for reviewing - but it seems I need to find the right 
direction before dealing with the details.

@rsmith - So here is a revised strategy - it is incomplete, and the code 
contains debug - so I am posting only for a review of the direction 
taken.

I first tried your suggested  `ReachableIfUsed` directly - but that became 
somewhat tangled because,  as you noted,  `used` is not sufficient - we mark 
things as used outside of the module purview.

So.

I added `ModuleUnreachable` which is set to be the default module ownership for 
the GMF.

When we are in module purview and we mark a decl as used or referenced we reset 
that ownership to visible.
So Sema now has thin wrappers over setIsUsed/markUsed/setReferenced that then 
handle the case that the decl is marked as `ModuleUnreachable`.

Then comes the **horrible** bit;  AFAICT we then have to walk the decl we just 
marked to determine if that makes other decls similarly visible - I've made a 
partial implementation of this (it just covers function decls - which is enough 
to run the example from the standard).
^^^ this is what I need review of direction-wise .. I cannot at present see a 
simpler way to do it - or even a reasonable way to cache used-ness dependencies 
in the GMF.

Any present, I've elected to stream the `ModuleUnreachable` state which is then 
used to ignore decls in lookup.
It seems harder than I'd expected to 'just not stream` those decls

- although that would be what I'd assume to be the motivation for this facility 
- reducing the size of PCMs for cases like:

  module;
  #include 
  module Foo;
  

suggestions most welcome - if the direction is OK, then the 
`markReachableGMFDecls` function needs to be completed before reviewing the 
details.




Comment at: clang/lib/Sema/Sema.cpp:1154-1155
+
+  for (auto *D : WorkList)
+DC->removeDecl(D);
+}

rsmith wrote:
> rsmith wrote:
> > Please don't remove the declarations from the `DeclContext`; `removeDecl`  
> > is inefficient, not well-tested, and not really compatible with the Clang 
> > philosophy of AST fidelity. For example, this will be very problematic for 
> > tooling that wants to inspect the translation unit after compilation.
> > 
> > As an alternative that should also fix the issue with checking `isUsed`, 
> > how would you feel about this:
> > 
> > * Create a new `ModuleOwnershipKind`, say `ReachableIfUsed`, and set that 
> > as the ownership kind for the TU when parsing the global module fragment so 
> > it gets inherited into everything we parse in that region. This'll mean 
> > that `NextInContextAndBits` needs an extra bit for the ownership field, but 
> > I think `Decl` is 8-byte-aligned so that seems fine.
> > * When a declaration is being marked as used, check if its ownership kind 
> > is `ReachableIfUsed` and if so change it to `ModulePrivate`.
> > 
> > That should be enough to get the desired semantic effect, and would allow 
> > us to get the improved diagnostic experience that @ChuanqiXu asked about. 
> > As a potentially separate step,  we can teach the ASTWriter code to 
> > (optionally) skip declarations that are `ReachableIfUsed` (and similarly 
> > for internal linkage declarations in module interfaces, function bodies for 
> > non-inline functions, and anything else we're allowed to omit).
> > When a declaration is being marked as used, check if its ownership kind is 
> > ReachableIfUsed and if so change it to ModulePrivate.
> 
> We'd need something a little more subtle, such as checking whether the module 
> ownership kind of the translation unit is no longer `ReachableIfUsed`,  to 
> detect whether we've already left the global module fragment at the point of 
> use. Maybe there's somewhere in `Sema` that marks declarations as used that 
> we can put this logic in instead?
> > When a declaration is being marked as used, check if its ownership kind is 
> > ReachableIfUsed and if so change it to ModulePrivate.
> 
> We'd need something a little more subtle, such as checking whether the module 
> ownership kind of the translation unit is no longer `ReachableIfUsed`,  to 
> detect whether we've already left the global module fragment at the point of 
> use. Maybe there's somewhere in `Sema` that marks declarations as used that 
> we can put this logic in instead?

Yes, what I was doing was way too simplistic - please see the top-level comment 
now on the revised direction.





Comment at: clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp:32
 void test_early() {
-  in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' 
must be declared before it is used}}
-  // expected-note@*{{not visible}}
+  in_header = 1; // expected-error {{use of undeclared identifier 'in_header'}}
 

ChuanqiXu wrote:
> This error message looks worse. I image I could hear users complaining this. 
> (I doesn't say it is your 

[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

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

Given it touches ModuleOwnershipKind too and some codes looks similar to me (I 
haven't look into the it yet), I want to know if it is possible to make D113545 
 a parent revision of this one? I feel like 
reachability might be more important than this one. Since reachability helps 
developers to use something but this functionality prevent developers to use 
something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126694

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


[PATCH] D126479: [Clang] Allow 'Complex float __attribute__((mode(HC)))'

2022-06-06 Thread Jolanta Jensen via Phabricator via cfe-commits
jolanta.jensen added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:60
+  Ibm128,
+  Half
 };

tahonermann wrote:
> The existing enumerators were ordered according to precision. Consider moving 
> `Half` to before `Float` if doing so doesn't cause any problems (I would hope 
> there is no dependence on the assigned enumerator values anywhere; if there 
> is, then it would be helpful to add a comment about that here).
In clang/test/CodeGenObjC/fpret.m, IR for i386-apple-darwin9 and 
x86_64-apple-darwin10 differ for long double after the move of Half to before 
Float:
--
Half added last to the FloatModeKind enum (test PASS) generates:

; Function Attrs: noinline nounwind optnone
define void @t0() #0 {
entry: 
  %0 = load i8*, i8** @OBJC_SELECTOR_REFERENCES_, align 4
  %call = call float bitcast (double (i8*, i8*, ...)* @objc_msgSend_fpret to 
float (i8*, i8*)*)(i8* noundef null, i8* noundef %0)
  %1 = load i8*, i8** @OBJC_SELECTOR_REFERENCES_.2, align 4
  %call1 = call double bitcast (double (i8*, i8*, ...)* @objc_msgSend_fpret to 
double (i8*, i8*)*)(i8* noundef null, i8* noundef %1)
  %2 = load i8*, i8** @OBJC_SELECTOR_REFERENCES_.4, align 4
  %call2 = call x86_fp80 bitcast (double (i8*, i8*, ...)* @objc_msgSend_fpret 
to x86_fp80 (i8*, i8*)*)(i8* noundef null, i8* noundef %2)
  ret void
}

declare double @objc_msgSend_fpret(i8*, i8*, ...)

attributes #0 = { noinline nounwind optnone "frame-pointer"="none" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="+cx8,+x87" }

---
While Half added before Float to the FloatModeKind enum (test FAIL) generates:

; Function Attrs: noinline nounwind optnone
define void @t0() #0 {
entry: 
  %0 = load i8*, i8** @OBJC_SELECTOR_REFERENCES_, align 4
  %call = call float bitcast (double (i8*, i8*, ...)* @objc_msgSend_fpret to 
float (i8*, i8*)*)(i8* noundef null, i8* noundef %0)
  %1 = load i8*, i8** @OBJC_SELECTOR_REFERENCES_.2, align 4
  %call1 = call double bitcast (double (i8*, i8*, ...)* @objc_msgSend_fpret to 
double (i8*, i8*)*)(i8* noundef null, i8* noundef %1)
  %2 = load i8*, i8** @OBJC_SELECTOR_REFERENCES_.4, align 4
  %call2 = call x86_fp80 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to 
x86_fp80 (i8*, i8*)*)(i8* noundef null, i8* noundef %2)
  ret void
}

declare double @objc_msgSend_fpret(i8*, i8*, ...)

; Function Attrs: nonlazybind
declare i8* @objc_msgSend(i8*, i8*, ...) #1

attributes #0 = { noinline nounwind optnone "frame-pointer"="none" 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-features"="+cx8,+x87" }
attributes #1 = { nonlazybind }


There is a similar failure in CodeGenObjC/metadata-symbols-64.m for 
x86_64-apple-darwin10 where @objc_msgSend_fpret is replaced by @objc_msgSend.

It looks like there are dependencies on the FloatModeKind enum values in 
clang/lib/Basic/Targets/X86.h and in clang/include/clang/Basic/TargetInfo.h
If I shift the initial value of RealTypeUsesObjCFPRet one bit to the left the 
tests above will PASS, i.e this together seems to work:
---

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 57bf4278251a..32e163b9cf38 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -52,12 +52,12 @@ namespace Builtin { struct Info; }

 enum class FloatModeKind {
   NoFloat = 255,
-  Float = 0,
+  Half = 0,
+  Float,
   Double,
   LongDouble,
   Float128,
-  Ibm128,
-  Half
+  Ibm128
 };

 /// Fields controlling how types are laid out in memory; these may need to
@@ -219,7 +219,7 @@ protected:
   mutable VersionTuple PlatformMinVersion;

   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRet : 3;
+  unsigned RealTypeUsesObjCFPRet : 6;
   unsigned ComplexLongDoubleUsesFP2Ret : 1;

   unsigned HasBuiltinMSVaList : 1;

Is the solution, i.e. shifting the initial value of the RealTypeUsesObjCFPRet 
to 6, acceptable or is it too hacky?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126479

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


[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

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

on the serialisation-front; maybe it would be better just to stream the 3 bits 
of the ownership and then we only need to check on deserialisation that the 
owning module exists for anything other than !owned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126694

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


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: llvm/test/lit.cfg.py:142
 tools = [
+ToolSubst('%llvm', FindTool('llvm')),
 ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),

This causes `llvm-lit: 
/Users/thakis/src/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: Did 
not find llvm in /Users/thakis/src/llvm-build-2/bin` if llvm-driver isn't 
enabled (which it isn't by default). Any reason not to add this one only `if 
config.have_llvm_driver`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

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


[clang] 881125a - Allow use of an elaborated type specifier in a _Generic association in C++

2022-06-06 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-06-06T07:17:35-04:00
New Revision: 881125ad9178120acef186f579e36ced0888dfdb

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

LOG: Allow use of an elaborated type specifier in a _Generic association in C++

Currently, Clang accepts this code in C mode (where the tag is required
to be used) but rejects it in C++ mode thinking that the association is
defining a new type.

void foo(void) {
  struct S { int a; };
  _Generic(something, struct S : 1);
}
Clang thinks this in C++ because it sees struct S : when parsing the
class specifier and decides that must be a type definition (because the
colon signifies the presence of a base class type). This patch adds a
new declarator context to represent a _Generic association so that we
can distinguish these situations properly.

Fixes #55562

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/DeclSpec.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Sema/generic-selection.c
clang/test/SemaCXX/generic-selection.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c377738401474..57519787ecc47 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -163,6 +163,9 @@ Bug Fixes
 - Unscoped and scoped enumeration types can no longer be initialized from a
   brace-init-list containing a single element of a 
diff erent scoped enumeration
   type.
+- Allow use of an elaborated type specifier as a ``_Generic`` selection
+  association in C++ mode. This fixes
+  `Issue 55562 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index a20866e410aa4..5bf7b276c328d 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2195,7 +2195,8 @@ class Parser : public CodeCompletionHandler {
 DSC_template_param, // template parameter context
 DSC_template_type_arg, // template type argument context
 DSC_objc_method_result, // ObjC method result context, enables 
'instancetype'
-DSC_condition // condition declaration context
+DSC_condition, // condition declaration context
+DSC_association // A _Generic selection expression's type association
   };
 
   /// Is this a context in which we are parsing just a type-specifier (or
@@ -2214,6 +2215,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_type_specifier:
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_alias_declaration:
+case DeclSpecContext::DSC_association:
   return true;
 }
 llvm_unreachable("Missing DeclSpecContext case");
@@ -2238,7 +2240,7 @@ class Parser : public CodeCompletionHandler {
   /// so permit class and enum definitions in addition to non-defining class 
and
   /// enum elaborated-type-specifiers)?
   static AllowDefiningTypeSpec
-  isDefiningTypeSpecifierContext(DeclSpecContext DSC) {
+  isDefiningTypeSpecifierContext(DeclSpecContext DSC, bool IsCPlusPlus) {
 switch (DSC) {
 case DeclSpecContext::DSC_normal:
 case DeclSpecContext::DSC_class:
@@ -2255,6 +2257,10 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_type_specifier:
   return AllowDefiningTypeSpec::NoButErrorRecovery;
 
+case DeclSpecContext::DSC_association:
+  return IsCPlusPlus ? AllowDefiningTypeSpec::NoButErrorRecovery
+ : AllowDefiningTypeSpec::Yes;
+
 case DeclSpecContext::DSC_trailing:
   return AllowDefiningTypeSpec::No;
 }
@@ -2276,6 +2282,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_template_type_arg:
 case DeclSpecContext::DSC_type_specifier:
 case DeclSpecContext::DSC_trailing:
+case DeclSpecContext::DSC_association:
   return false;
 }
 llvm_unreachable("Missing DeclSpecContext case");
@@ -2291,6 +2298,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_top_level:
 case DeclSpecContext::DSC_condition:
 case DeclSpecContext::DSC_type_specifier:
+case DeclSpecContext::DSC_association:
   return true;
 
 case DeclSpecContext::DSC_objc_method_result:

diff  --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index c03ead9c79b34..dc1fbf098a8ac 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -1786,7 +1786,8 @@ enum class DeclaratorContext

[PATCH] D126969: Allow use of an elaborated type specifier in a _Generic association in C++

2022-06-06 Thread Aaron Ballman 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 rG881125ad9178: Allow use of an elaborated type specifier in a 
_Generic association in C++ (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126969

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/generic-selection.c
  clang/test/SemaCXX/generic-selection.cpp

Index: clang/test/SemaCXX/generic-selection.cpp
===
--- clang/test/SemaCXX/generic-selection.cpp
+++ clang/test/SemaCXX/generic-selection.cpp
@@ -69,3 +69,24 @@
   default : 3
 ) == 2, "we had better pick const Test, not Test!"); // C++-specific result
 }
+
+namespace GH55562 {
+struct S { // expected-note {{declared here}}
+  int i;
+};
+
+void func(struct S s) {
+  // We would previously reject this because the parser thought 'struct S :'
+  // was the start of a definition (with a base class specifier); it's not, it
+  // is an elaborated type specifier followed by the association's value and
+  // it should work the same as in C.
+  (void)_Generic(s, struct S : 1);
+
+  // The rest of these cases test that we still produce a reasonable diagnostic
+  // when referencing an unknown type or trying to define a type in other ways.
+  (void)_Generic(s, struct T : 1);// expected-error {{type 'struct T' in generic association incomplete}}
+  (void)_Generic(s, struct U { int a; } : 1); // expected-error {{'U' cannot be defined in a type specifier}}
+  (void)_Generic(s, struct V : S);// expected-error {{'S' does not refer to a value}}
+  (void)_Generic(s, struct W : S { int b; } : 1); // expected-error {{expected '(' for function-style cast or type construction}}
+}
+} // namespace GH55562
Index: clang/test/Sema/generic-selection.c
===
--- clang/test/Sema/generic-selection.c
+++ clang/test/Sema/generic-selection.c
@@ -78,3 +78,11 @@
   default : 3
 ) == 1, "we had better pick struct Test, not const struct Test!"); // C-specific result
 }
+
+void GH55562(void) {
+  // Ensure that you can still define a type within a generic selection
+  // association (despite it not being particularly useful).
+  (void)_Generic(1, struct S { int a; } : 0, default : 0); // ext-warning {{'_Generic' is a C11 extension}}
+  struct S s = { 0 };
+  int i = s.a;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -3538,6 +3538,7 @@
 break; // auto(x)
   LLVM_FALLTHROUGH;
 case DeclaratorContext::TypeName:
+case DeclaratorContext::Association:
   Error = 15; // Generic
   break;
 case DeclaratorContext::File:
@@ -3648,6 +3649,7 @@
 case DeclaratorContext::ObjCCatch:
 case DeclaratorContext::TemplateArg:
 case DeclaratorContext::TemplateTypeArg:
+case DeclaratorContext::Association:
   DiagID = diag::err_type_defined_in_type_specifier;
   break;
 case DeclaratorContext::Prototype:
@@ -4735,6 +4737,7 @@
 case DeclaratorContext::TypeName:
 case DeclaratorContext::FunctionalCast:
 case DeclaratorContext::RequiresExpr:
+case DeclaratorContext::Association:
   // Don't infer in these contexts.
   break;
 }
@@ -5777,6 +5780,7 @@
 case DeclaratorContext::TrailingReturnVar:
 case DeclaratorContext::TemplateArg:
 case DeclaratorContext::TemplateTypeArg:
+case DeclaratorContext::Association:
   // FIXME: We may want to allow parameter packs in block-literal contexts
   // in the future.
   S.Diag(D.getEllipsisLoc(),
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3276,7 +3276,7 @@
   Ty = nullptr;
 } else {
   ColonProtectionRAIIObject X(*this);
-  TypeResult TR = ParseTypeName();
+  TypeResult TR = ParseTypeName(nullptr, DeclaratorContext::Association);
   if (TR.isInvalid()) {
 SkipUntil(tok::r_paren, StopAtSemi);
 return ExprError();
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1752,13 +1752,15 @@
 
   const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
   Sema::TagUseKind TUK;
-  if (isDefiningTypeSpecifierContext(DSC) == AllowDefiningTypeSpec::No ||
+  if (isDefiningTypeSpecifierContext(DSC, getLangO

[clang] cc30d43 - Fix a -Wlogical-op-parentheses warning; NFC

2022-06-06 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-06-06T07:52:12-04:00
New Revision: cc30d43ce49c253e0274ca2679d42c2f706bfc3b

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

LOG: Fix a -Wlogical-op-parentheses warning; NFC

This should address bot failures like:
https://lab.llvm.org/buildbot/#/builders/77/builds/18317

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index b5874e28786a..1afe1995237a 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1758,9 +1758,9 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
 TUK = Sema::TUK_Reference;
   else if (Tok.is(tok::l_brace) ||
(DSC != DeclSpecContext::DSC_association &&
-(getLangOpts().CPlusPlus && Tok.is(tok::colon)) ||
-(isClassCompatibleKeyword() &&
- (NextToken().is(tok::l_brace) || NextToken().is(tok::colon) {
+getLangOpts().CPlusPlus && Tok.is(tok::colon)) ||
+   (isClassCompatibleKeyword() &&
+(NextToken().is(tok::l_brace) || NextToken().is(tok::colon {
 if (DS.isFriendSpecified()) {
   // C++ [class.friend]p2:
   //   A class shall not be defined in a friend declaration.



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


[PATCH] D127066: [clang] Remove some `U+00AD`s in `__cpp_multidimensional_subscript`

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

It took me a moment, but this actually removes a 0xC2AD and not a 0x00AD. It's 
still correct, but I was wondering why no character was printed in the text -- 
0xC2AD is not a defined Unicode character.

LGTM, but can you correct the patch title + summary when committing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127066

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


[PATCH] D126377: [clang][AArch64][SVE] Improve diagnostics for SVE operators

2022-06-06 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes accepted this revision.
c-rhodes 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/D126377/new/

https://reviews.llvm.org/D126377

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


[PATCH] D119646: [clang] Allow consteval functions in default arguments

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

LGTM with some small fixes to the release note. Thanks @ChuanqiXu!




Comment at: clang/docs/ReleaseNotes.rst:166
   type.
+- Clang will allow constexpr function in default argument. This fixes
+  `Issue 48230 `_.

Minor corrections


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

https://reviews.llvm.org/D119646

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


[PATCH] D126380: [clang][AArch64][SVE] Implicit conversions for vector-scalar operations

2022-06-06 Thread David Truby via Phabricator via cfe-commits
DavidTruby added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:13582
+// Need the original target type for vector type checks
+const Type *OriginalTarget = S.Context.getCanonicalType(T).getTypePtr();
+// Handle conversion from scalable to fixed when msve-vector-bits is

c-rhodes wrote:
> this is the same as `Target` defined on line 13473
The control flow in this function is a little odd, but it isn't necessarily the 
same target; we could have entered one or more of the if statements above that 
modify the target, and we need to inspect the original target here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126380

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


[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

2022-06-06 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: martong, steakhal, NoQ.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A crash was seen in CastValueChecker due to a null pointer dereference
when analyzing proprietary source code. A suitably small and obfuscated
reproducer cannot be provided at this time, but a description of the
problem seen can be provided. The crash seen is as follows, with debug
information dump following.

The fix seeks to simply avoid the null pointer dereference, thus
preventing the crash.

Program received signal SIGSEGV, Segmentation fault.
0x09c2d380 in clang::DeclarationName::getAsString[abi:cxx11]()
const (this=0x28)

  at ../../clang/lib/AST/DeclarationName.cpp:238

238   OS << *this;
(gdb) bt
clang::DeclarationName::getAsString[abi:cxx11]() const (this=0x28)

  at ../../clang/lib/AST/DeclarationName.cpp:238

const (this=0x0)

  at ../../clang/include/clang/AST/Decl.h:290

Object=0x1c11af18,

  CastSucceeds=true, IsKnownCast=false)
  at ../../clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:111

State=..., C=..., IsInstanceOf=true)

  at ../../clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:319

namespace)::CastValueChecker::evalIsa (this=0x10cdf140, Call=...,

  DV=..., C=...) at

../../clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:437
...

(gdb) frame 2
Object=0x1c11af18,

  CastSucceeds=true, IsKnownCast=false)
  at ../../clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:111

111:
CastToTy->getPointeeCXXRecordDecl()->getNameAsString();

(gdb) p CastToTy
$1 = {Value = {Value = 312725088}}

(gdb) p CastToTy->getPointeeCXXRecordDecl()
$2 = (const clang::CXXRecordDecl *) 0x0

(gdb) p CastToTy.dump()
LValueReferenceType 0x12a3ce60 'class llvm::ReplaceableMetadataImpl *&'
`-PointerType 0x129971b0 'class llvm::ReplaceableMetadataImpl *'

  `-RecordType 0x128afce0 'class llvm::ReplaceableMetadataImpl'
`-CXXRecord 0x128ff160 'ReplaceableMetadataImpl'

(gdb) frame 16
(this=0x7fff9208, currStmt=0x1f026978, Pred=0x22cf76f0)

  at ../../clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:783

783Visit(currStmt, I, DstI);

(gdb) p currStmt
$1 = (const clang::Stmt *) 0x1f026978

(gdb) p currStmt->dump()
CallExpr 0x1f026978 '_Bool'

| -ImplicitCastExpr 0x1f026960 '_Bool (*)(const class |
|

llvm::PointerUnion &)' 

| `-DeclRefExpr 0x1f026908 '_Bool (const class llvm::PointerUnion &)' lvalue Function
0x1f007e58 'isa' '_Bool (const class llvm::PointerUnion &)' (FunctionTemplate
0x11c5df38 'isa')
`-UnaryOperator 0x1f026738 'const class llvm::PointerUnion' lvalue prefix '*' cannot
overflow

  `-CXXThisExpr 0x1f026728 'const class llvm::PointerUnion *' this
$2 = void


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127105

Files:
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -108,7 +108,9 @@
  bool CastSucceeds, bool IsKnownCast) {
   std::string CastToName =
   CastInfo ? CastInfo->to()->getAsCXXRecordDecl()->getNameAsString()
-   : CastToTy->getPointeeCXXRecordDecl()->getNameAsString();
+  : (CastToTy->getPointeeCXXRecordDecl() != nullptr)
+  ? CastToTy->getPointeeCXXRecordDecl()->getNameAsString()
+  : "(nil)";
   Object = Object->IgnoreParenImpCasts();
 
   return C.getNoteTag(
@@ -163,9 +165,11 @@
 bool First = true;
 for (QualType CastToTy: CastToTyVec) {
   std::string CastToName =
-CastToTy->getAsCXXRecordDecl() ?
-CastToTy->getAsCXXRecordDecl()->getNameAsString() :
-CastToTy->getPointeeCXXRecordDecl()->getNameAsString();
+  CastToTy->getAsCXXRecordDecl()
+  ? CastToTy->getAsCXXRecordDecl()->getNameAsString()
+  : (CastToTy->getPointeeCXXRecordDecl() != nullptr)
+  ? CastToTy->getPointeeCXXRecordDecl()->getNameAsString()
+  : "(nil)";
   Out << ' ' << ((CastToTyVec.size() == 1) ? "not" :
  (First ? "neither" : "nor")) << " a '" << CastToName
   << '\'';


Index: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -108,7 +108,9 @@
  bool CastSucceeds, bool IsKnownCast) {
   std::string CastToName =
   CastInfo ? CastInfo->to

[PATCH] D126380: [clang][AArch64][SVE] Implicit conversions for vector-scalar operations

2022-06-06 Thread David Truby via Phabricator via cfe-commits
DavidTruby updated this revision to Diff 434445.
DavidTruby added a comment.

Clean up code based on review comments
Move additional tests to existing file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126380

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-arith-ops.c
  clang/test/Sema/aarch64-sve-vector-arith-ops.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -213,23 +213,6 @@
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
 
-  local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 / 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 % 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 == 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 != 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 > 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 && 0; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
-  local_int8 || 0; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
-
   if (local_int8) { // expected-error {{not contextually convertible to 'bool'}}
   }
   while (local_int8) { // expected-error {{not contextually convertible to 'bool'}}
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -201,23 +201,6 @@
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}}
 
-  local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 / 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 % 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 == 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 != 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 > 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 && 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 || 0; // expected-error {{invalid operands to binary expression}}
-
   if (local_int8) { // expected-error {{statement requires expression of scalar type}}
   }
   while (local_int8) { // expected-error {{statement requires expression of scalar type}}
Index: clang/test/Sema/aarch64-sve-vector-arith-ops.c
===
--- clang/test/Sema/aarch64-sve-vector-arith-ops.c
+++ clang/test/Sema/aarch64-sve-vector-arith-ops.c
@@ -643,3 +643,11 @@
   (void)(f64 % f16); // expected-error{{invalid operands to binary expression}}
   (void)(f64 % f32); // expected-error{{invalid operands to binary expression}}
 }
+
+svint8_t svi8(svint8_t a) {
+  return a + 256; // expected-error{{cannot convert between scalar type 'int' and vector type 'svint8_t' (aka '__SVInt8_t') as implicit conversion would c

[PATCH] D126183: Implement soft reset of the diagnostics engine.

2022-06-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

This looks good to me, modulo the inline comment.

Let's wait for @rsmith's green light.




Comment at: clang/lib/Interpreter/IncrementalParser.cpp:201
 // FIXME: Do not reset the pragma handlers.
-Diags.Reset();
+Diags.Reset(true);
 return llvm::make_error("Parsing failed.",

```
Diags.Reset(/*soft=*/true);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126183

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


[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.h:1506
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;

Would it make sense to make the RAII a friend to avoid adding the accessors of 
various structures?



Comment at: clang/lib/CodeGen/ModuleBuilder.cpp:138
+  {
+CodeGenModule::KeepLazyEmiitedSymRAII RAIIKeeper(Builder);
+M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), 
C));

Maybe we could move this call into `Initialize`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

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


[PATCH] D88780: Allow interfaces to operate on in-memory buffers with no source location info.

2022-06-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

This looks reasonable to me...

@shafik, @teemperor  what do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88780

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


[PATCH] D126719: [clang-cl] Add support for /kernel

2022-06-06 Thread Stephen Long via Phabricator via cfe-commits
steplong updated this revision to Diff 434459.
steplong added a comment.

- Clang-formatted patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126719

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-zc.cpp

Index: clang/test/Driver/cl-zc.cpp
===
--- clang/test/Driver/cl-zc.cpp
+++ clang/test/Driver/cl-zc.cpp
@@ -24,6 +24,33 @@
 // RUN: %clang_cl /c /std:c++17 -### /Zc:alignedNew- -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-OFF %s
 // ALIGNED-NEW-OFF-NOT: "-faligned-allocation"
 
+// RUN: %clang_cl /c -### /kernel -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-NO-RTTI,KERNEL-NO-EXCEPTIONS %s
+// KERNEL-NO-RTTI: "-fno-rtti"
+// KERNEL-NO-EXCEPTIONS-NOT: "-fcxx-exceptions" "-fexceptions"
+
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:SSE -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-SSE %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:SSE2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-SSE2 %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX2 %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX512 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX512 %s
+// KERNEL-SSE: error: invalid argument '/arch:SSE' not allowed with '/kernel'
+// KERNEL-SSE2: error: invalid argument '/arch:SSE2' not allowed with '/kernel'
+// KERNEL-AVX: error: invalid argument '/arch:AVX' not allowed with '/kernel'
+// KERNEL-AVX2: error: invalid argument '/arch:AVX2' not allowed with '/kernel'
+// KERNEL-AVX512: error: invalid argument '/arch:AVX512' not allowed with '/kernel'
+
+// RUN: %clang_cl /c -### /kernel /EHsc -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-EHSC %s
+// RUN: %clang_cl /c -### /kernel /GR -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-GR %s
+// KERNEL-EHSC-NOT: "-fcxx-exceptions" "-fexceptions"
+// KERNEL-GR: error: invalid argument '/GR' not allowed with '/kernel'
+
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX %s
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX2 %s
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX512 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX512 %s
+// KERNEL-X64-AVX: error: invalid argument '/arch:AVX' not allowed with '/kernel'
+// KERNEL-X64-AVX2: error: invalid argument '/arch:AVX2' not allowed with '/kernel'
+// KERNEL-X64-AVX512: error: invalid argument '/arch:AVX512' not allowed with '/kernel'
+
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=STRICTSTRINGS-DEFAULT %s
 // STRICTSTRINGS-DEFAULT-NOT: -Werror=c++11-compat-deprecated-writable-strings
 // RUN: %clang_cl /c -### /Zc:strictStrings -- %s 2>&1 | FileCheck -check-prefix=STRICTSTRINGS-ON %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -38,6 +38,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "clang/Driver/Types.h"
 #include "clang/Driver/XRayArgs.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Option/ArgList.h"
@@ -7458,6 +7459,12 @@
 EH.NoUnwindC = true;
   }
 
+  if (Args.hasArg(options::OPT__SLASH_kernel)) {
+EH.Synch = false;
+EH.NoUnwindC = false;
+EH.Asynch = false;
+  }
+
   return EH;
 }
 
@@ -7602,6 +7609,27 @@
CmdArgs.push_back("-fno-wchar");
  }
 
+ if (Args.hasArg(options::OPT__SLASH_kernel)) {
+   llvm::Triple::ArchType Arch = getToolChain().getArch();
+   std::vector Values =
+   Args.getAllArgValues(options::OPT__SLASH_arch);
+   if (!Values.empty()) {
+ llvm::SmallSet SupportedArches;
+ if (Arch == llvm::Triple::x86)
+   SupportedArches.insert("IA32");
+
+ for (auto &V : Values)
+   if (!SupportedArches.contains(V))
+ D.Diag(diag::err_drv_argument_not_allowed_with)
+ << std::string("/arch:").append(V) << "/kernel";
+   }
+
+   CmdArgs.push_back("-fno-rtti");
+   if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_, false))
+ D.Diag(diag::err_drv_argument_not_allowed_with) << "/GR"
+ << "/kernel";
+ }
+
   Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
   Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
   if (MostGeneralArg && BestCaseAr

[PATCH] D126984: [clang] Add initial support for gcc's optimize function attribute

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



Comment at: clang/include/clang/Basic/Attr.td:2265
+  let Spellings = [GCC<"optimize">];
+  let Args = [StringArgument<"Level">];
+  let Subjects = SubjectList<[Function]>;

Something along these lines adds a "fake" argument to the attribute. This means 
the parsed attribute doesn't care about this argument (so users don't supply it 
when writing the attribute themselves), but the semantic attribute 
(`OptimizeAttr`) will have a member to track the fake argument value and will 
require extra information when creating the attribute.

This effectively will add:
```
enum OptLevelKind {
  O0,
  O1,
  O2,
  O3,
  O4
} OptLevel;
```
to the semantic attribute.



Comment at: clang/include/clang/Basic/Attr.td:2267
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
+}

You should add some rudimentary documentation for this, and probably point to 
the GCC docs for further information.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3019-3020
   "%0 attribute takes at least %1 argument%s1">;
+def err_attribute_only_allowed_with_argument : Error <
+  "argument to '%0' should be %1">;
 def err_attribute_invalid_vector_type : Error<"invalid vector element type 
%0">;

I'm not 100% in love with the list of valid options in my suggested wording (I 
had originally listed the valid values manually and that was not much better).

One thing I think is important is that this be a warning rather than an error. 
Users will pass "-f" strings here which are supported by GCC; they should just 
be able to ignore the warning in Clang as being harmless, but if it's an error, 
the user has to change the function signatures in ways that are kind of 
annoying.



Comment at: clang/lib/CodeGen/CGCall.cpp:2169
+HasOptnone = TargetDecl->hasAttr() ||
+ (TargetDecl->hasAttr() &&
+  TargetDecl->getAttr()->getLevel() == "0");

steplong wrote:
> I don't think this is the most ergonomic way. Let me know if you have a 
> better idea of doing this
I'll sprinkle some comments around about how I'd investigate handling this.

Based on those suggestions, here you would be able to ask for 
`OptimizeAttr->getOptLevel()` and it will return the mapped enumeration value, 
which should clean this code up to not require string checking.

Btw, `hasAttr()` followed by `getAttr()` is generally a code smell (same smell 
as `isa` followed by `cast`). You should switch to logic more like:
```
if (const auto *OA = TargetDecl->getAttr()) {

}
```
so that we only have to traverse the list of attributes once instead of twice.



Comment at: clang/lib/CodeGen/CGCall.cpp:2171-2172
+  TargetDecl->getAttr()->getLevel() == "0");
+HasOptsize = TargetDecl->hasAttr() &&
+ TargetDecl->getAttr()->getLevel() == "s";
 if (auto *AllocSize = TargetDecl->getAttr()) {

I think we also need to check for `-Ofast`, `-Oz`, and `-Og` 
(https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/CompilerInvocation.cpp#L575)



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4841-4850
+  StringRef Level;
+  // Check if argument is prefixed with "-O" or "O"
+  if (Arg.str().rfind("-O", 0) == 0)
+Level = Arg.substr(2);
+  else if (Arg.str().rfind("O", 0) == 0)
+Level = Arg.substr(1);
+  else

Then, in here, you can parse the `-O` the user passed as a string, 
and convert it to an `OptimizeAttr::OptLevelKind` enumerator and store that in 
the semantic attribute.

This allows you to map things like `-Og` to whatever -O level that actually 
represents, or do any other kind of mapping that works for you.

One question we should probably figure out is whether we also want to support 
clang-cl optimization strings or not. e.g., `__attribute__((optimize("/O0")))` 
with a slash instead of a dash. Since we're already going to be doing parsing 
from here anyway, I feel like it might not be a bad idea to also support those. 
FWIW, here's the list from the user's manual:
```
  /O0 Disable optimization
  /O1 Optimize for size  (same as /Og /Os /Oy /Ob2 /GF 
/Gy)
  /O2 Optimize for speed (same as /Og /Oi /Ot /Oy /Ob2 /GF 
/Gy)
  /Ob0Disable function inlining
  /Ob1Only inline functions which are (explicitly or 
implicitly) marked inline
  /Ob2Inline functions as deemed beneficial by the compiler
  /Od Disable optimization
  /Og No effect
  /Oi-Disable use of builtin functions
  /Oi Enable use of builtin functions
  /Os Optimize for size
  /Ot Optimize for speed
  /Ox Deprecated (same as /Og

[PATCH] D109977: LLVM Driver Multicall tool

2022-06-06 Thread Alex Brachet via Phabricator via cfe-commits
abrachet marked an inline comment as done.
abrachet added inline comments.



Comment at: llvm/test/lit.cfg.py:142
 tools = [
+ToolSubst('%llvm', FindTool('llvm')),
 ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),

thakis wrote:
> This causes `llvm-lit: 
> /Users/thakis/src/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: 
> Did not find llvm in /Users/thakis/src/llvm-build-2/bin` if llvm-driver isn't 
> enabled (which it isn't by default). Any reason not to add this one only `if 
> config.have_llvm_driver`?
Fixed in rG553c2af5360b993376d3c000cf53850605940307


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

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


[PATCH] D32199: [TySan] A Type Sanitizer (Clang)

2022-06-06 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 434471.
fhahn added a comment.

Rebase & address comments, thanks! Also update the code to link tysan runtime 
with static linking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D32199

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTBAA.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/CodeGen/sanitize-type-attr.cpp
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -247,6 +247,18 @@
 // CHECK-ASAN-MYRIAD-NOT: "-lc"
 // CHECK-ASAN-MYRIAD: libclang_rt.asan-sparcel.a"
 
+// RUN: %clangxx %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
+// RUN: -fsanitize=type \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TYSAN-LINUX-CXX %s
+//
+// CHECK-TYSAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-TYSAN-LINUX-CXX-NOT: stdc++
+// CHECK-TYSAN-LINUX-CXX: "--whole-archive" "{{.*}}libclang_rt.tysan{{[^.]*}}.a" "--no-whole-archive"
+// CHECK-TYSAN-LINUX-CXX: stdc++
+
 // RUN: %clangxx -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
 // RUN: -fsanitize=thread \
Index: clang/test/CodeGen/sanitize-type-attr.cpp
===
--- /dev/null
+++ clang/test/CodeGen/sanitize-type-attr.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type | FileCheck -check-prefix=TYSAN %s
+// RUN: echo "src:%s" | sed -e 's/\\//g' > %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s
+
+// The sanitize_type attribute should be attached to functions
+// when TypeSanitizer is enabled, unless no_sanitize("type") attribute
+// is present.
+
+// WITHOUT:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type"))) int NoTYSAN1(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN2{{.*}}) [[NOATTR]]
+// BL:  NoTYSAN2{{.*}}) [[NOATTR]]
+// TYSAN:  NoTYSAN2{{.*}}) [[NOATTR]]
+__attribute__((no_sanitize("type"))) int NoTYSAN2(int *a);
+int NoTYSAN2(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type"))) int NoTYSAN3(int *a) { return *a; }
+
+// WITHOUT:  TYSANOk{{.*}}) [[NOATTR]]
+// BL:  TYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TYSANOk{{.*}}) [[WITH:#[0-9]+]]
+int TYSANOk(int *a) { return *a; }
+
+// WITHOUT:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// BL:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TemplateTYSANOk{{.*}}) [[WITH]]
+template 
+int TemplateTYSANOk() { return i; }
+
+// WITHOUT:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// BL:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// TYSAN: TemplateNoTYSAN{{.*}}) [[NOATTR]]
+template 
+__attribute__((no_sanitize("type"))) int TemplateNoTYSAN() { return i; }
+
+int force_instance = TemplateTYSANOk<42>() + TemplateNoTYSAN<42>();
+
+// Check that __cxx_global_var_init* get the sanitize_type attribute.
+int global1 = 0;
+int global2 = *(int *)((char *)&global1 + 1);
+// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// BL: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// TYSAN: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
+
+// Make sure that we don't add globals to the list for which we don't have a
+// specific type description.
+struct SX {
+  int a, b;
+};
+SX sx;
+
+// WITHOUT: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+
+// BL: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+
+// TYSAN: attributes [[NOATTR]] = { mustprogress noinline nounwind{{.*}} }
+// TYSAN: attributes [[WITH]] = { noinline nounwind sanitize_type{{.*}} }
+
+// TYSAN-DAG: !llvm.tysan.globals = !{[[G1MD:![0-9]+]], [[G2MD:![0-9]+]], [[G3MD:![0-9]+]]}
+// TYSAN-DAG: [[G1MD]] = !{i32* @force_instance, [[INTMD:![0-9]+]]}
+// TYSAN-DAG: [[INTMD]] = !{!"int",
+// TYSAN-DAG: [[G2MD]] = !{i32* @

[PATCH] D127114: new clang-tidy checker for assignments within condition clause of if statement

2022-06-06 Thread dodohand via Phabricator via cfe-commits
dodohand created this revision.
Herald added subscribers: carlosgalvezp, mgorny.
Herald added a project: All.
dodohand requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

new clang-tidy checker for assignments with the condition clause of an 'if' 
statement.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127114

Files:
  clang-tools-extra/clang-tidy/misc/AssignmentInIfClauseCheck.cpp
  clang-tools-extra/clang-tidy/misc/AssignmentInIfClauseCheck.h
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-assignment-in-if-clause.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-assignment-in-if-clause.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc-assignment-in-if-clause.cpp
@@ -0,0 +1,122 @@
+// RUN: %check_clang_tidy %s misc-assignment-in-if-clause %t
+
+// Add something that triggers the check here.
+void f(int arg)
+{
+  int f = 3;
+  if(( f = arg ) || ( f == (arg + 1)))
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: Assignment detected within if statement. Fix to equality check if this was accidental. Consider moving out of if statement if intentional. [misc-assignment-in-if-clause] 
+  {
+f = 5;
+  }
+}
+
+void f1(int arg)
+{
+  int f = 3;
+  if(( f == arg ) || ( f = (arg + 1)))
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: Assignment detected within if statement. Fix to equality check if this was accidental. Consider moving out of if statement if intentional. [misc-assignment-in-if-clause] 
+  {
+f = 5;
+  }
+}
+
+void f2(int arg)
+{
+  int f = 3;
+  if( f = arg )
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Assignment detected within if statement. Fix to equality check if this was accidental. Consider moving out of if statement if intentional. [misc-assignment-in-if-clause] 
+  {
+f = 5;
+  }
+}
+
+volatile int v = 32;
+
+void f3(int arg)
+{
+  int f = 3;
+  if(( f == arg ) || (( arg + 6 < f ) && ( f = v )))  
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: Assignment detected within if statement. Fix to equality check if this was accidental. Consider moving out of if statement if intentional. [misc-assignment-in-if-clause] 
+  {
+f = 5;
+  }
+}
+
+void f4(int arg)
+{
+  int f = 3;
+  if(( f == arg ) || (( arg + 6 < f ) && (( f = v ) || (f < 8  
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: Assignment detected within if statement. Fix to equality check if this was accidental. Consider moving out of if statement if intentional. [misc-assignment-in-if-clause] 
+  {
+f = 5;
+  }
+  else if(( arg + 8 < f ) && ((f = v) || (f < 8)))
+// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: Assignment detected within if statement. Fix to equality check if this was accidental. Consider moving out of if statement if intentional. [misc-assignment-in-if-clause] 
+  {
+f = 6;
+  }
+}
+
+class BrokenOperator
+{
+public:
+int d = 0;
+int operator = (const int &val)
+{
+	d = val + 1;
+	return d;
+}
+};
+
+void f5(int arg)
+{
+BrokenOperator bo;
+int f = 3;
+bo = f;
+if(bo.d == 3)
+{
+f = 6;
+}
+if(bo = 3)
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: Assignment detected within if statement. Fix to equality check if this was accidental. Consider moving out of if statement if intentional. [misc-assignment-in-if-clause] 
+{
+f = 7;
+}
+if((arg == 3) || (bo = 6))
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: Assignment detected within if statement. Fix to equality check if this was accidental. Consider moving out of if statement if intentional. [misc-assignment-in-if-clause] 
+{
+	f = 8;
+}
+v = f;
+}
+
+// Add something that doesn't trigger the check here.
+void awesome_f2(int arg)
+{
+  int f = 3;
+  if(( f == arg ) || ( f == (arg + 1)))
+  {
+f = 5;
+  }
+}
+
+void awesome_f3(int arg)
+{
+  int f = 3;
+  if( f == arg )
+  {
+f = 5;
+  }
+}
+
+void awesome_f4(int arg)
+{
+  int f = 3;
+  if(( f == arg ) || (( arg + 6 < f ) && (( f == v ) || (f < 8  
+  {
+f = 5;
+  }
+}
+
+
Index: clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst
@@ -0,0 +1,27 @@
+.. title:: clang-tidy - misc-assignment-in-if-clause
+
+misc-assignment-in-if-clause
+
+
+Finds assignments within the condition of `if` statements. 
+Allows automatic identification of assignments which may have been intended as equality tests. 
+Finds these assignments even within multiple sets of parenthese

[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 434473.
junaire added a comment.

friend class comes to the rescue!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,13 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
-  M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
-  Initialize(*Ctx);
+
+  {
+CodeGenModule::KeepLazyEmiitedSymRAII RAIIKeeper(Builder);
+M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), 
C));
+Initialize(*Ctx);
+  }
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,44 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  friend struct KeepLazyEmiitedSymRAII;
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;
+std::unique_ptr &Self;
+
+explicit KeepLazyEmiitedSymRAII(std::unique_ptr &Builder)
+: Self(Builder) {
+  OldBuilder.swap(Self);
+}
+
+~KeepLazyEmiitedSymRAII() {
+  assert(OldBuilder->tDeferredDeclsToEmit.empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Self->tDeferredDecls.empty() &&
+ "Newly created module should not have deferred decls");
+
+  std::swap(Self->DeferredDecls, OldBuilder->DeferredDecls);
+
+  assert(Self->DeferredVTables.empty() &&
+ "Newly created module should not have deferred vtables");
+
+  std::swap(Self->DeferredVTables, OldBuilder->DeferredVTables);
+
+  assert(Self->MangledDeclNames.empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(Self->Manglings.empty() &&
+ "Newly created module should not have manglings");
+
+  Self->Manglings = std::move(OldBuilder->Manglings);
+
+  assert(OldBuilder->WeakRefReferences.empty() &&
+ "Not all WeakRefRefs have been applied");
+
+  std::swap(Self->TBAA, OldBuilder->TBAA);
+}
+  };
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,13 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
-  M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
-  Initialize(*Ctx);
+
+  {
+CodeGenModule::KeepLazyEmiitedSymRAII RAIIKeeper(Builder);
+M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+Initialize(*Ctx);
+  }
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,44 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  friend struct KeepLazyEmiitedSymRAII;
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;
+std::unique_ptr &Self;
+
+explicit KeepLazyEmiitedSymRAII(std::unique_ptr &Builder)
+: Self(Builder) {
+  OldBuilder.swap(Self);
+}
+
+~KeepLazyEmiitedSymRAII() {
+  assert(OldBuilder->tDeferredDeclsToEmit.empty() &&
+ "Sho

[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 434474.
junaire marked an inline comment as done.
junaire added a comment.

fix a typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,13 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
-  M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
-  Initialize(*Ctx);
+
+  {
+CodeGenModule::KeepLazyEmiitedSymRAII RAIIKeeper(Builder);
+M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), 
C));
+Initialize(*Ctx);
+  }
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,44 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  friend struct KeepLazyEmiitedSymRAII;
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;
+std::unique_ptr &Self;
+
+explicit KeepLazyEmiitedSymRAII(std::unique_ptr &Builder)
+: Self(Builder) {
+  OldBuilder.swap(Self);
+}
+
+~KeepLazyEmiitedSymRAII() {
+  assert(OldBuilder->DeferredDeclsToEmit.empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Self->DeferredDecls.empty() &&
+ "Newly created module should not have deferred decls");
+
+  std::swap(Self->DeferredDecls, OldBuilder->DeferredDecls);
+
+  assert(Self->DeferredVTables.empty() &&
+ "Newly created module should not have deferred vtables");
+
+  std::swap(Self->DeferredVTables, OldBuilder->DeferredVTables);
+
+  assert(Self->MangledDeclNames.empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(Self->Manglings.empty() &&
+ "Newly created module should not have manglings");
+
+  Self->Manglings = std::move(OldBuilder->Manglings);
+
+  assert(OldBuilder->WeakRefReferences.empty() &&
+ "Not all WeakRefRefs have been applied");
+
+  std::swap(Self->TBAA, OldBuilder->TBAA);
+}
+  };
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,13 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
-  M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
-  Initialize(*Ctx);
+
+  {
+CodeGenModule::KeepLazyEmiitedSymRAII RAIIKeeper(Builder);
+M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+Initialize(*Ctx);
+  }
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,44 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  friend struct KeepLazyEmiitedSymRAII;
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;
+std::unique_ptr &Self;
+
+explicit KeepLazyEmiitedSymRAII(std::unique_ptr &Builder)
+: Self(Builder) {
+  OldBuilder.swap(Self);
+}
+
+~KeepLazyEmiitedSymRAII() {
+  assert(OldBuilder->DeferredDeclsToEmit.empty() &&
+ 

[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/lib/CodeGen/ModuleBuilder.cpp:138
+  {
+CodeGenModule::KeepLazyEmiitedSymRAII RAIIKeeper(Builder);
+M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), 
C));

v.g.vassilev wrote:
> Maybe we could move this call into `Initialize`.
I don't know why but moving this to `Initialize` causes a crash...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

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


[PATCH] D127114: new clang-tidy checker for assignments within condition clause of if statement

2022-06-06 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:9
+Finds these assignments even within multiple sets of parentheses which is 
often appropriate to structure multi-part condition statements.
+Finds these assignments even within multiple sets of paretheses which disables 
the compiler -Wparentheses check which one would otherwise like to rely on to 
find accidental assignment.
+The identified assignments violate BARR group "Rule 8.2.c". See: 
https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard/statement-rules/if-else-statements

Why not improve `-Wparentheses` to catch these cases too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127114

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


[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 434479.
junaire added a comment.

Remove extra brackets


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,6 +133,8 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
+
+  CodeGenModule::KeepLazyEmiitedSymRAII RAIIKeeper(Builder);
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
   Initialize(*Ctx);
   return M.get();
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,44 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  friend struct KeepLazyEmiitedSymRAII;
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;
+std::unique_ptr &Self;
+
+explicit KeepLazyEmiitedSymRAII(std::unique_ptr &Builder)
+: Self(Builder) {
+  OldBuilder.swap(Self);
+}
+
+~KeepLazyEmiitedSymRAII() {
+  assert(OldBuilder->DeferredDeclsToEmit.empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Self->DeferredDecls.empty() &&
+ "Newly created module should not have deferred decls");
+
+  std::swap(Self->DeferredDecls, OldBuilder->DeferredDecls);
+
+  assert(Self->DeferredVTables.empty() &&
+ "Newly created module should not have deferred vtables");
+
+  std::swap(Self->DeferredVTables, OldBuilder->DeferredVTables);
+
+  assert(Self->MangledDeclNames.empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(Self->Manglings.empty() &&
+ "Newly created module should not have manglings");
+
+  Self->Manglings = std::move(OldBuilder->Manglings);
+
+  assert(OldBuilder->WeakRefReferences.empty() &&
+ "Not all WeakRefRefs have been applied");
+
+  std::swap(Self->TBAA, OldBuilder->TBAA);
+}
+  };
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,6 +133,8 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
+
+  CodeGenModule::KeepLazyEmiitedSymRAII RAIIKeeper(Builder);
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
   Initialize(*Ctx);
   return M.get();
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,44 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  friend struct KeepLazyEmiitedSymRAII;
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;
+std::unique_ptr &Self;
+
+explicit KeepLazyEmiitedSymRAII(std::unique_ptr &Builder)
+: Self(Builder) {
+  OldBuilder.swap(Self);
+}
+
+~KeepLazyEmiitedSymRAII() {
+  assert(OldBuilder->DeferredDeclsToEmit.empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Self->DeferredDecls.empty() &&
+ "Newly created module should not have deferred decls");
+
+  std::swap(Self->DeferredDecls, OldBuilder->DeferredDecls);
+
+  assert(Self->DeferredVTables.empty() &&
+ "New

[PATCH] D127116: [clangd] Add flags to symbol requests to restrict to ObjC symbols

2022-06-06 Thread David Goldman via Phabricator via cfe-commits
dgoldman created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
dgoldman requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

clangd will set this flag for files with ObjC language flag enabled. This can 
be used to only include ObjC symbols when searching for symbols.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127116

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/Index.h

Index: clang-tools-extra/clangd/index/Index.h
===
--- clang-tools-extra/clangd/index/Index.h
+++ clang-tools-extra/clangd/index/Index.h
@@ -47,13 +47,15 @@
   std::vector ProximityPaths;
   /// Preferred types of symbols. These are raw representation of `OpaqueType`.
   std::vector PreferredTypes;
+  /// Whether Objective-C symbols should be included in the search.
+  bool IncludeObjC = false;
 
   bool operator==(const FuzzyFindRequest &Req) const {
 return std::tie(Query, Scopes, Limit, RestrictForCodeCompletion,
-ProximityPaths, PreferredTypes) ==
+ProximityPaths, PreferredTypes, IncludeObjC) ==
std::tie(Req.Query, Req.Scopes, Req.Limit,
 Req.RestrictForCodeCompletion, Req.ProximityPaths,
-Req.PreferredTypes);
+Req.PreferredTypes, Req.IncludeObjC);
   }
   bool operator!=(const FuzzyFindRequest &Req) const { return !(*this == Req); }
 };
@@ -63,6 +65,8 @@
 
 struct LookupRequest {
   llvm::DenseSet IDs;
+  /// Whether Objective-C symbols should be included in the lookup.
+  bool IncludeObjC = false;
 };
 
 struct RefsRequest {
@@ -75,6 +79,8 @@
   /// If set, populates the container of the reference.
   /// Index implementations may chose to populate containers no matter what.
   bool WantContainer = false;
+  /// Whether Objective-C code should be included in the search.
+  bool IncludeObjC = false;
 };
 
 struct RelationsRequest {
@@ -82,6 +88,8 @@
   RelationKind Predicate;
   /// If set, limit the number of relations returned from the index.
   llvm::Optional Limit;
+  /// Whether Objective-C code should be included in the search.
+  bool IncludeObjC = false;
 };
 
 /// Describes what data is covered by an index.
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -455,6 +455,7 @@
   // Now query the index for all Symbol IDs we found in the AST.
   if (Index && !ResultIndex.empty()) {
 LookupRequest QueryRequest;
+QueryRequest.IncludeObjC = AST.getLangOpts().ObjC;
 for (auto It : ResultIndex)
   QueryRequest.IDs.insert(It.first);
 std::string Scratch;
@@ -588,6 +589,7 @@
   // too much data, while still likely having enough for 3 results to remain
   // after additional filtering.
   Req.Limit = 10;
+  Req.IncludeObjC = AST.getLangOpts().ObjC;
   bool TooMany = false;
   using ScoredLocatedSymbol = std::pair;
   std::vector ScoredResults;
@@ -1397,6 +1399,7 @@
 }
 
 RelationsRequest OverriddenBy;
+OverriddenBy.IncludeObjC = AST.getLangOpts().ObjC;
 if (Index) {
   OverriddenBy.Predicate = RelationKind::OverriddenBy;
   for (const NamedDecl *ND : Decls) {
@@ -1472,6 +1475,7 @@
   return;
 RefsRequest Req;
 Req.IDs = std::move(IDs);
+Req.IncludeObjC = AST.getLangOpts().ObjC;
 if (Limit) {
   if (Limit < Results.References.size()) {
 // We've already filled our quota, still check the index to correctly
Index: clang-tools-extra/clangd/IncludeFixer.h
===
--- clang-tools-extra/clangd/IncludeFixer.h
+++ clang-tools-extra/clangd/IncludeFixer.h
@@ -61,6 +61,9 @@
 std::string Name;   // E.g. "X" in foo::X.
 SourceLocation Loc; // Start location of the unresolved name.
 std::vector Scopes; // Namespace scopes we should search in.
+/// Whether Objective-C symbols should be included in the search for this
+/// name.
+bool IncludeObjC = false;
   };
 
   /// Records the last unresolved name seen by Sema.
Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -511,6 +511,7 @@
 UnresolvedName Unresolved;
 Unresolved.Name = Extracted->Name;
 Unresolved.Loc = Typo.getBeginLoc();
+Unresolved.IncludeObjC = SemaPtr->getLangOpts().ObjC;
 if (!Extracted->ResolvedScope && !S) // Give up if no scope a

[PATCH] D127114: new clang-tidy checker for assignments within condition clause of if statement

2022-06-06 Thread dodohand via Phabricator via cfe-commits
dodohand added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:9
+Finds these assignments even within multiple sets of parentheses which is 
often appropriate to structure multi-part condition statements.
+Finds these assignments even within multiple sets of paretheses which disables 
the compiler -Wparentheses check which one would otherwise like to rely on to 
find accidental assignment.
+The identified assignments violate BARR group "Rule 8.2.c". See: 
https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard/statement-rules/if-else-statements

gribozavr2 wrote:
> Why not improve `-Wparentheses` to catch these cases too?
IMHO, `-Wparentheses` isn't broken. Its "disable warning by an extra set of 
parentheses" behavior has been around for a long time and is common across gcc 
and clang... it just isn't what is called for when trying to ensure that 
accidental assignments aren't occurring in even slightly complicated condition 
statements, or when trying to comply with BARR-group coding standard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127114

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


[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.h:1482
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;

I think a RAII object is an odd way to express this API; there's not really a 
natural reason you would scope this.  It would be better to just have a method 
on `CodeGenModule` that steals the internal lazy-emission state from a 
different instance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

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


[PATCH] D125742: Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

2022-06-06 Thread Paul Pluzhnikov via Phabricator via cfe-commits
ppluzhnikov added a comment.

Ping x2?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125742

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


[PATCH] D121733: Clean pathnames in FileManager.

2022-06-06 Thread Paul Pluzhnikov via Phabricator via cfe-commits
ppluzhnikov abandoned this revision.
ppluzhnikov added a comment.

This proved to be too hard :-(
A smaller change: https://reviews.llvm.org/D126396 fixed one aspect of this 
problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121733

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


[PATCH] D127114: new clang-tidy checker for assignments within condition clause of if statement

2022-06-06 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/AssignmentInIfClauseCheck.cpp:39
+  diag(MatchedDecl->getBeginLoc(),
+   "Assignment detected within if statement. Fix to equality check if this 
"
+   "was accidental. Consider moving out of if statement if intentional.");

Please follow Clang's message style. The message should start with a lowercase 
letter and should not end with a period. Suggested fixes (since there are 
multiple) should be in notes.

warning: an assignment within an 'if' condition is bug-prone
note: if it should be an assignment, move it out of the 'if' condition
note: if it is meant to be an equality check, change '=' to '=='

Also consider adding a fixit to the second note.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:3
+
+misc-assignment-in-if-clause
+

WDYT about `bugprone-assignment-in-if-condition`?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:6-9
+Finds assignments within the condition of `if` statements. 
+Allows automatic identification of assignments which may have been intended as 
equality tests. 
+Finds these assignments even within multiple sets of parentheses which is 
often appropriate to structure multi-part condition statements.
+Finds these assignments even within multiple sets of paretheses which disables 
the compiler -Wparentheses check which one would otherwise like to rely on to 
find accidental assignment.





Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:9
+Finds these assignments even within multiple sets of parentheses which is 
often appropriate to structure multi-part condition statements.
+Finds these assignments even within multiple sets of paretheses which disables 
the compiler -Wparentheses check which one would otherwise like to rely on to 
find accidental assignment.
+The identified assignments violate BARR group "Rule 8.2.c". See: 
https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard/statement-rules/if-else-statements

dodohand wrote:
> gribozavr2 wrote:
> > Why not improve `-Wparentheses` to catch these cases too?
> IMHO, `-Wparentheses` isn't broken. Its "disable warning by an extra set of 
> parentheses" behavior has been around for a long time and is common across 
> gcc and clang... it just isn't what is called for when trying to ensure that 
> accidental assignments aren't occurring in even slightly complicated 
> condition statements, or when trying to comply with BARR-group coding 
> standard.
Oh, I see -- it wasn't clear to me that the silencing through the extra set of 
parens was specifically not desirable for you.

I suggested some edits to the documentation to directly highlight the 
difference.

I also suggest changing the example below to explicitly mention what 
assignments are flagged by `-Wparentheses` and which are flagged by this check.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:10
+Finds these assignments even within multiple sets of paretheses which disables 
the compiler -Wparentheses check which one would otherwise like to rely on to 
find accidental assignment.
+The identified assignments violate BARR group "Rule 8.2.c". See: 
https://barrgroup.com/embedded-systems/books/embedded-c-coding-standard/statement-rules/if-else-statements
+





Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:17
+
+   static volatile int f = 3;
+   if( f = 4 ) // This is identified - should it have been: `if ( f == 4 )` ?

The "static volatile" part is not relevant to the example, and it might 
distract the reader, suggesting that something is special about such variables.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-assignment-in-if-clause.cpp:68
+   d = val + 1;
+   return d;
+}

Please clang-format the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127114

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


[PATCH] D125919: Drop qualifiers from return types in C (DR423)

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

In D125919#3556754 , @rsmith wrote:

> In D125919#3556418 , @aaron.ballman 
> wrote:
>
>> In D125919#3556319 , @rjmccall 
>> wrote:
>>
>>> Now, the standard has chosen not to talk about `_Atomic` as a qualifier, I 
>>> assume because there's a fair number of rules in the standard that assume 
>>> that qualifiers can be freely added to pointers and don't change layout and 
>>> so on, none of which apply to `_Atomic`.  But those rules also don't apply 
>>> to a large number of other extended qualifiers, like address spaces and the 
>>> ARC ownership qualifiers and `__ptrauth`.  The committee should probably 
>>> just come to terms with the fact that it's the relatively easy-come-easy-go 
>>> nature of the CVR qualifiers which is the special case.  I've thought for 
>>> awhile that Clang should really be representing `_Atomic` as a qualifier 
>>> instead of having to treat `AtomicType` as a special case in a million 
>>> places.
>>
>> I'm not certain if we can get away with that. IIRC, Microsoft uses embedded 
>> locks on Windows in some circumstances. However, cl doesn't support 
>> `_Atomic` and so maybe we can get away with it on the assumption we have no 
>> other targets where the size/alignment would be different for an atomic type 
>> vs a non-atomic type?
>
> That assumption does not hold. Given `struct A { char c[3]; };`, `struct A` 
> has size 3 and align 1, but `_Atomic struct A` has size 4 and align 4 across 
> many (perhaps all?) of our targets. (This is an ABI divergence between GCC 
> and Clang, which as far as I know the psABI owners have so far not succeeded 
> in resolving.)

Good point!

> I saw some talk in WG14 of separating `_Atomic(T)` and `_Atomic T` so that 
> `_Atomic T` would be a qualifier that doesn't affect size or alignment, only 
> what code is generated to access the value, and `_Atomic(T)` would be a 
> distinct type with potentially a different representation in order to support 
> lock-free atomic access. Did that go anywhere? (I'd assume not, it seems to 
> be at least a decade too late for such an idea.)

So far that's just been talk (and I'm not convinced it'll be possible to change 
the semantics there without silently breaking code).

In D125919#3558062 , @rjmccall wrote:

>> I disagree with the assessment that _Atomic behaves exactly like a 
>> qualifier. It *should* (IMHO), but it doesn't. C allows the size and 
>> alignment of an atomic type be *different* from its unqualified version, to 
>> allow for embedded locks and such. Because the size and alignment can be 
>> different, to my mind, _Atomic int and int are different types in the same 
>> way as _Complex float and float -- the object representations can (must, in 
>> the case of _Complex) be different, so they're different types. The same is 
>> not true for const, volatile, or restrict qualifiers -- those are required 
>> to have the same size and alignment as the unqualified type.
>
> I think our apparent disagreement here is rooted in something quite simple: 
> you seem to be assuming that a qualified type by definition cannot have a 
> different size and alignment from the unqualified type, and I think that's a 
> property that's *guaranteed* for the CVR qualifiers and merely *happens to be 
> true* for our current set of extended qualifiers, and only really because we 
> don't represent `_Atomic` as a qualifier.

I think you're right about the root of our disagreement. Any qualifiers other 
than CVR, _Atomic, and address spaces are fully implementation-defined and can 
do whatever they want, thus aren't really relevant to how standard qualifiers 
behave. Address spaces are covered by TR 18037 (which states they're extending 
the list of CVR qualifiers in C, thus I'd expect would follow the same rules as 
CVR despite predating DR423). We treat all standards-based qualifiers as a 
`Qualifier` in Clang, except for `_Atomic`, which I believe we treat 
differently because it behaves as a distinct type. I think we *want* that 
behavior -- these are not valid redeclarations: `void func(int a); void 
func(_Atomic int a);` while these are valid (and have utility): `void func(int 
a); void func(const int a);`.

> Many of our extended qualifiers completely change the ABI of the type they 
> qualify, and they can change the basic semantic properties of types they're 
> nested within.  I don't see why we'd draw a line around type layout for what 
> counts as a qualifier and what doesn't.  For example, ObjC ARC happens to 
> implement `__weak` references without using extra inline storage, but it 
> would certainly be a reasonable ABI choice to make them larger than just a 
> pointer — Swift does with its native weak references, for example.  That ABI 
> choice wouldn't make `__weak` suddenly not a qualifier.  Type constr

[PATCH] D127114: new clang-tidy checker for assignments within condition clause of if statement

2022-06-06 Thread dodohand via Phabricator via cfe-commits
dodohand added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/AssignmentInIfClauseCheck.cpp:39
+  diag(MatchedDecl->getBeginLoc(),
+   "Assignment detected within if statement. Fix to equality check if this 
"
+   "was accidental. Consider moving out of if statement if intentional.");

gribozavr2 wrote:
> Please follow Clang's message style. The message should start with a 
> lowercase letter and should not end with a period. Suggested fixes (since 
> there are multiple) should be in notes.
> 
> warning: an assignment within an 'if' condition is bug-prone
> note: if it should be an assignment, move it out of the 'if' condition
> note: if it is meant to be an equality check, change '=' to '=='
> 
> Also consider adding a fixit to the second note.
Will adjust the messages.

I'm specifically reluctant to add a fixit to this, as I'm not sure how I can 
tell an intended assignment (for which the fix would be moving the assignment 
out of the if clause) apart from an accidental assignment (for which the fix is 
changing '=' to '=='). Thoughts?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst:3
+
+misc-assignment-in-if-clause
+

gribozavr2 wrote:
> WDYT about `bugprone-assignment-in-if-condition`?
I'm in favor of that categorization - it reflects how I feel about having 
assignments within an 'if' condition. I'll change it accordingly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127114

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


[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.h:1482
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;

rjmccall wrote:
> I think a RAII object is an odd way to express this API; there's not really a 
> natural reason you would scope this.  It would be better to just have a 
> method on `CodeGenModule` that steals the internal lazy-emission state from a 
> different instance.
I don't have a better way to do this in mind, We need to restore the states 
after resetting the `Builder` right? So I guess RAII should be fine? Can you 
please provide some hints about how to do this more elegantly? Thx!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

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


[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-06-06 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz added a comment.

To elaborate on known situation where expansion isn't available:

1. expansion doesn't work on site of #define
2. expansion doesn't work for _Pragma(...) and alike
3. expansion doesn't work with builtin macro
4. expansion doesn't work for macros as arguments of function-like macro

Basically, anywhere the same code action isn't available. Need this be 
documented somewhere?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

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


[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.h:1482
+
+  struct KeepLazyEmiitedSymRAII {
+std::unique_ptr OldBuilder;

junaire wrote:
> rjmccall wrote:
> > I think a RAII object is an odd way to express this API; there's not really 
> > a natural reason you would scope this.  It would be better to just have a 
> > method on `CodeGenModule` that steals the internal lazy-emission state from 
> > a different instance.
> I don't have a better way to do this in mind, We need to restore the states 
> after resetting the `Builder` right? So I guess RAII should be fine? Can you 
> please provide some hints about how to do this more elegantly? Thx!
I don't know what you mean.  You're not restoring any old state, you're moving 
state into the new CGM.  The whole thing is an imperative operation, it's just 
being done in a destructor for no particular reason.

```
std::unique_ptr newBuilder(new CodeGenModule(...));
Builder->moveLazyEmissionStateInto(newBuilder.get());
Builder = newBuilder;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

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


[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

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

In D126694#3559818 , @ChuanqiXu wrote:

> Given it touches ModuleOwnershipKind too and some codes looks similar to me 
> (I haven't look into the it yet), I want to know if it is possible to make 
> D113545  a parent revision of this one? I 
> feel like reachability might be more important than this one. Since 
> reachability helps developers to use something but this functionality prevent 
> developers to use something.

I will look at this - it is indeed a problem that currently we do not 
differentiate reachability from visibility - which means either some 
work-around, or making some thing artificially visible,
this patch would address your

  /// FIXME: Implement discarding declarations actually in global module
  /// fragment. See [module.global.frag]p3,4 for details.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126694

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


[PATCH] D127125: [clangd] Improve ObjC protocol suggestions from the index

2022-06-06 Thread David Goldman via Phabricator via cfe-commits
dgoldman created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
dgoldman requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

When querying the index during an ObjC protocol name lookup for code
completion, we should only suggest ObjC protocols.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127125

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/TestIndex.cpp
  clang-tools-extra/clangd/unittests/TestIndex.h

Index: clang-tools-extra/clangd/unittests/TestIndex.h
===
--- clang-tools-extra/clangd/unittests/TestIndex.h
+++ clang-tools-extra/clangd/unittests/TestIndex.h
@@ -34,6 +34,14 @@
 // Create a C++20 concept symbol.
 Symbol conceptSym(llvm::StringRef Name);
 
+// Create an Objective-C symbol.
+Symbol objcSym(llvm::StringRef Name, index::SymbolKind Kind,
+   llvm::StringRef USRPrefix);
+// Create an @interface or @implementation.
+Symbol objcClass(llvm::StringRef Name);
+// Create an @protocol.
+Symbol objcProtocol(llvm::StringRef Name);
+
 // Create a slab of symbols with the given qualified names as IDs and names.
 SymbolSlab generateSymbols(std::vector QualifiedNames);
 
Index: clang-tools-extra/clangd/unittests/TestIndex.cpp
===
--- clang-tools-extra/clangd/unittests/TestIndex.cpp
+++ clang-tools-extra/clangd/unittests/TestIndex.cpp
@@ -81,6 +81,28 @@
   return sym(Name, index::SymbolKind::Concept, "@CT@\\0");
 }
 
+Symbol objcSym(llvm::StringRef Name, index::SymbolKind Kind,
+   llvm::StringRef USRPrefix) {
+  Symbol Sym;
+  std::string USR = USRPrefix.str() + Name.str();
+  Sym.Name = Name;
+  Sym.Scope = "";
+  Sym.ID = SymbolID(USR);
+  Sym.SymInfo.Kind = Kind;
+  Sym.SymInfo.Lang = index::SymbolLanguage::ObjC;
+  Sym.Flags |= Symbol::IndexedForCodeCompletion;
+  Sym.Origin = SymbolOrigin::Static;
+  return Sym;
+}
+
+Symbol objcClass(llvm::StringRef Name) {
+  return objcSym(Name, index::SymbolKind::Class, "objc(cs)");
+}
+
+Symbol objcProtocol(llvm::StringRef Name) {
+  return objcSym(Name, index::SymbolKind::Protocol, "objc(pl)");
+}
+
 SymbolSlab generateSymbols(std::vector QualifiedNames) {
   SymbolSlab::Builder Slab;
   for (llvm::StringRef QName : QualifiedNames)
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3150,6 +3150,20 @@
   EXPECT_THAT(C, ElementsAre(signature("(id)object")));
 }
 
+TEST(CompletionTest, ObjectiveCProtocolFromIndex) {
+  Symbol FoodClass = objcClass("FoodClass");
+  Symbol SymFood = objcProtocol("Food");
+  Symbol SymFooey = objcProtocol("Fooey");
+  auto Results = completions(R"objc(
+  id
+)objc",
+ {SymFood, FoodClass, SymFooey},
+ /*Opts=*/{}, "Foo.m");
+
+  auto C = Results.Completions;
+  EXPECT_THAT(C, UnorderedElementsAre(named("Food"), named("Fooey")));
+}
+
 TEST(CompletionTest, CursorInSnippets) {
   clangd::CodeCompleteOptions Options;
   Options.EnableSnippets = true;
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -1677,6 +1677,14 @@
 return Output;
   }
 
+  bool includeSymbolFromIndex(const Symbol &Sym) {
+if (CCContextKind == CodeCompletionContext::CCC_ObjCProtocolName) {
+  return Sym.SymInfo.Lang == index::SymbolLanguage::ObjC &&
+  Sym.SymInfo.Kind == index::SymbolKind::Protocol;
+}
+return true;
+  }
+
   SymbolSlab queryIndex() {
 trace::Span Tracer("Query index");
 SPAN_ATTACH(Tracer, "limit", int64_t(Opts.Limit));
@@ -1711,8 +1719,10 @@
 
 // Run the query against the index.
 SymbolSlab::Builder ResultsBuilder;
-if (Opts.Index->fuzzyFind(
-Req, [&](const Symbol &Sym) { ResultsBuilder.insert(Sym); }))
+if (Opts.Index->fuzzyFind(Req, [&](const Symbol &Sym) {
+  if (includeSymbolFromIndex(Sym))
+ResultsBuilder.insert(Sym);
+}))
   Incomplete = true;
 return std::move(ResultsBuilder).build();
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126183: Implement soft reset of the diagnostics engine.

2022-06-06 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:200
 
 // FIXME: Do not reset the pragma handlers.
+Diags.Reset(true);

We should remove this fixme, too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126183

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


[PATCH] D127075: [clang] P2266: apply move elision rules on throw expr nested in function prototypes

2022-06-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:848
 (Scope::FnScope | Scope::ClassScope | Scope::BlockScope |
- Scope::FunctionPrototypeScope | Scope::ObjCMethodScope |
- Scope::TryScope))
+ Scope::ObjCMethodScope | Scope::TryScope))
   break;

Many of the remaining scope checks here also seem incorrect per the wording.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127075

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


[PATCH] D126871: [clang] [MinGW] Use SEH for unwind info on ARM by default

2022-06-06 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126871

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


[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

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

Shouldn't the rounding mode be FE_DYNAMIC by default?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[PATCH] D126871: [clang] [MinGW] Use SEH for unwind info on ARM by default

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

Oh, just remembered, we should probably release-note this.  (You can post that 
as a followup.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126871

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


[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

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

I'm going to try rebasing my GMF elision code on top of this.

the test-suite changes could be made easier to read by using the file-split 
stuff we've been using for recent changes (I guess this is an older patch)?




Comment at: clang/include/clang/AST/DeclBase.h:234-236
 /// lookups that occur within that module.
+/// The discarded declarations in global module fragment belongs
+/// to this group too.

that is not going to be sufficient to exclude them - see D126694, we introduce 
a new category "ModuleUnreachable".



Comment at: clang/include/clang/AST/DeclBase.h:636-637
+
+  /// FIXME: Implement discarding declarations actually in global module
+  /// fragment. See [module.global.frag]p3,4 for details.
+  bool isDiscardedInGlobalModuleFragment() const { return false; }

see D126694.




Comment at: clang/lib/Sema/SemaLookup.cpp:1947
+  // DeclModule if it isn't (transitively) imported.
+  if (DeclModule->getTopLevelModule()->isModuleInterfaceUnit())
+return true;

I think isModuleInterfaceUnit needs to include implementation partition units, 
since they also have a BMI  (is `isInterfaceOrPartition()` the right thing to 
use here?



Comment at: clang/lib/Sema/SemaLookup.cpp:1958
+  // additional translation unit is not considered as reachable for 
portability.
+  return SemaRef.getLangOpts().AllAdditionalTUReachable;
+}

could we separate this part of the change into a separate patch (along with the 
command line switch etc.) ?
it is not needed for standard compliance, right?




Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:1931
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));  // AccessSpecifier
-  Abv->Add(BitCodeAbbrevOp(0));   // ModulePrivate
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3));  // ModulePrivate
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID

ModuleOwnershipKind? (and several cases below)



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

https://reviews.llvm.org/D113545

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


[PATCH] D126651: [clang-diff] Fix getStmtValue when dealing with wide chars

2022-06-06 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes requested changes to this revision.
johannes added a comment.
This revision now requires changes to proceed.

I've suggested some more refactorings but otherwise this should be good to go




Comment at: clang/lib/Tooling/ASTDiff/ASTDiff.cpp:497
+  return str;
+}
 return std::string(String->getString());

Sorry for the delay. Looks pretty good already.

 think there's a bit of redundancy now, I tried to simplify it, WDYT?
I used uppercase variable names as this is the local convention. I'm not sure 
what's the global one.
`String->getByteLength() / String->getCharByteWidth();` adds an unnecessary 
division, we can just use getLength().

```
if (String->isWide() || String->isUTF16() || String->isUTF32()) {
  std::string UTF8Str;
  unsigned int NumChars = String->getLength();
  const char *Bytes = String->getBytes().data();
  if (String->isWide()) {
const auto *Chars = reinterpret_cast(Bytes);
if (!convertWideToUTF8({Chars, NumChars}, UTF8Str))
  return "";
  } else if (String->isUTF16()) {
const auto *Chars = reinterpret_cast(Bytes);
if (!convertUTF16ToUTF8String({Chars, NumChars}, UTF8Str))
  return "";
  } else {
assert(String->isUTF32() && "Unsupported string encoding.");
const auto *Chars = reinterpret_cast(Bytes);
if (!convertUTF32ToUTF8String({Chars, NumChars}, UTF8Str))
  return "";
  }
  return UTF8Str;
}
```



Comment at: clang/test/Tooling/clang-diff-ast.cpp:74
+  return U"foo";
+// CHECK-NOT: ImplicitCastExpr
+return 0;

I think two lines per encoding should be enough, so how about doing this right 
next to the existing string literal?

```
  const char *foo(int i) {
if (i == 0)
  // CHECK: StringLiteral: foo(
  return "foo";
// CHECK: StringLiteral: wide(
(void)L"wide";
// CHECK: StringLiteral: utf-16(
(void)u"utf-16";
// CHECK: StringLiteral: utf-32(
(void)U"utf-32";
// CHECK-NOT: ImplicitCastExpr
return 0;
  }
```


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

https://reviews.llvm.org/D126651

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


[PATCH] D125695: [clang][DebugInfo] Allow function-local type-like entities to be scoped within a lexical block (5/5)

2022-06-06 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 434541.
krisb marked an inline comment as done.
krisb added a comment.

Applied review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125695

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGenCXX/debug-info-local-types.cpp

Index: clang/test/CodeGenCXX/debug-info-local-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-local-types.cpp
@@ -0,0 +1,101 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=CHECK,LIMITED
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=unused-types -debugger-tuning=gdb %s -o - | FileCheck %s --check-prefixes=UNUSED_TYPES
+
+void test() {
+  {
+struct S { int a; };
+class C { int b; };
+S s;
+{
+  C c;
+}
+  }
+
+  {
+typedef char Char;
+using Int = int;
+Char c;
+{
+  Int i;
+}
+  }
+
+  {
+enum E { a, b, c };
+enum class T { aa, bb, cc };
+E e = E::a;
+{
+  T t = T::aa;
+}
+  }
+
+  {
+union U { int i; char c; };
+U u = { 256 };
+  }
+}
+
+// LIMITED: distinct !DICompileUnit
+// LIMITED-NOT: retainedTypes:
+
+// CHECK: !DILocalVariable(name: "s", scope: [[LBSCOPE_1:![0-9]+]]
+// CHECK-SAME:type: [[STRUCT:![0-9]+]]
+// CHECK: [[LBSCOPE_1]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB1_DECLS:![0-9]+]]
+// CHECK: [[LB1_DECLS]] = !{[[STRUCT]], [[CLASS:![0-9]+]]}
+// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", scope: [[LBSCOPE_1]]
+// CHECK: [[CLASS]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", scope: [[LBSCOPE_1]]
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_11:![0-9]+]]
+// CHECK-SAME:type: [[CLASS]]
+// CHECK: [[LBSCOPE_11]] = distinct !DILexicalBlock(scope: [[LBSCOPE_1]]
+//
+// CHECK: !DILocalVariable(name: "c", scope: [[LBSCOPE_2:![0-9]+]]
+// CHECK-SAME:type: [[TYPEDEF:![0-9]+]]
+// CHECK: [[LBSCOPE_2]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB2_DECLS:![0-9]+]]
+// CHECK: [[LB2_DECLS]] = !{[[TYPEDEF]], [[USING:![0-9]+]]}
+// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Char", scope: [[LBSCOPE_2]]
+// CHECK: [[USING]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Int", scope: [[LBSCOPE_2]]
+// CHECK: !DILocalVariable(name: "i", scope: [[LBSCOPE_21:![0-9]+]]
+// CHECK-SAME:type: [[USING]]
+// CHECK: [[LBSCOPE_21]] = distinct !DILexicalBlock(scope: [[LBSCOPE_2]]
+//
+// CHECK: !DILocalVariable(name: "e", scope: [[LBSCOPE_3:![0-9]+]]
+// CHECK-SAME:type: [[ENUM:![0-9]+]]
+// CHECK: [[LBSCOPE_3]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB3_DECLS:![0-9]+]]
+// CHECK: [[LB3_DECLS]] = !{[[ENUM]], [[ENUM_CLASS:![0-9]+]]}
+// CHECK: [[ENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "E", scope: [[LBSCOPE_3]]
+// CHECK: [[ENUM_CLASS]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "T", scope: [[LBSCOPE_3]]
+// CHECK: !DILocalVariable(name: "t", scope: [[LBSCOPE_31:![0-9]+]]
+// CHECK-SAME:type: [[ENUM_CLASS]]
+// CHECK: [[LBSCOPE_31]] = distinct !DILexicalBlock(scope: [[LBSCOPE_3]]
+//
+// CHECK: !DILocalVariable(name: "u", scope: [[LBSCOPE_4:![0-9]+]]
+// CHECK-SAME:type: [[UNION:![0-9]+]]
+// CHECK: [[LBSCOPE_4]] = distinct !DILexicalBlock({{.*}}, localDecls: [[LB4_DECLS:![0-9]+]]
+// CHECK: [[LB4_DECLS]] = !{[[UNION]]}
+// CHECK: [[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "U", scope: [[LBSCOPE_4]]
+
+void test_unused() {
+  {
+struct X {};
+typedef int Y; // typedef doesn't go to retainedTypes.
+enum Z { z };
+  }
+}
+
+// UNUSED_TYPES: distinct !DICompileUnit
+// UNUSED_TYPES-SAME: retainedTypes: [[RETAINED_TYPES:![0-9]+]]
+//
+// struct, class, char, int, enum, enum class, union, unused struct, unused enum, ::F
+// UNUSED_TYPES: [[RETAINED_TYPES]] = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, [[UNUSED_STRUCT:![0-9]+]], [[UNUSED_ENUM:![0-9]+]], !{{.*}}}
+// UNUSED_TYPES: [[UNUSED_STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[UNUSED_LB:![0-9]+]]
+// UNUSED_TYPES: [[UNUSED_LB]] = distinct !DILexicalBlock({{.*}}, localDecls: [[UNUSED_LB_DECLS:![0-9]+]]
+// UNUSED_TYPES: [[UNUSED_LB_DECLS]] = !{[[UNUSED_STRUCT]], [[UNUSED_ENUM]]}
+// UNUSED_TYPES: [[UNUSED_ENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Z", scope: [[UNUSED_LB]]
+
+void test_lambda() {
+  auto t = []() { struct F {}; return F(); };
+  auto v = t();
+}
+
+// TODO: ::F doesn't have its scope specified.

[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

2022-06-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In D126364#3560877 , @efriedma wrote:

> Shouldn't the rounding mode be FE_DYNAMIC by default?

According to the standard it must be FE_TONEAREST:

  F.8.3p1:
  At program startup the dynamic floating-point environment is initialized as 
prescribed by IEC 60559:
  ...
  - The dynamic rounding direction mode is rounding to nearest.
  ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

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

In D126364#3560984 , @sepavloff wrote:

> In D126364#3560877 , @efriedma 
> wrote:
>
>> Shouldn't the rounding mode be FE_DYNAMIC by default?
>
> According to the standard it must be FE_TONEAREST:
>
>   F.8.3p1:
>   At program startup the dynamic floating-point environment is initialized as 
> prescribed by IEC 60559:
>   ...
>   - The dynamic rounding direction mode is rounding to nearest.
>   ...

When I say the default should be FE_DYNAMIC, I'm talking about the default 
FENV_ROUND state.  That's talking about the initial state of the floating-point 
registers at runtime (on entry to main()).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

2022-06-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In D126364#3560997 , @efriedma wrote:

> In D126364#3560984 , @sepavloff 
> wrote:
>
>> In D126364#3560877 , @efriedma 
>> wrote:
>>
>>> Shouldn't the rounding mode be FE_DYNAMIC by default?
>>
>> According to the standard it must be FE_TONEAREST:
>>
>>   F.8.3p1:
>>   At program startup the dynamic floating-point environment is initialized 
>> as prescribed by IEC 60559:
>>   ...
>>   - The dynamic rounding direction mode is rounding to nearest.
>>   ...
>
> When I say the default should be FE_DYNAMIC, I'm talking about the default 
> FENV_ROUND state.  That's talking about the initial state of the 
> floating-point registers at runtime (on entry to main()).

The cited excerpt from the standard is just about floating point environment at 
program startup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[PATCH] D126929: Add sanitizer metadata attributes to clang IR gen.

2022-06-06 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 434546.
hctim added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126929

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp

Index: clang/test/CodeGen/sanitize-init-order.cpp
===
--- clang/test/CodeGen/sanitize-init-order.cpp
+++ clang/test/CodeGen/sanitize-init-order.cpp
@@ -36,12 +36,29 @@
 
 // Check that ASan init-order checking ignores structs with trivial default
 // constructor.
+
+// CHECK: @s1 = global
+// CHECK-NOT: sanitize_address_dyninit
+// CHECK: @s2 = global
+// CHECK-NOT: sanitize_address_dyninit
+// CHECK: @s3 = global {{.*}}, sanitize_address_dyninit
+// CHECK: @{{.*}}array{{.*}} = global {{.*}}, sanitize_address_dyninit
+
 // CHECK: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], ![[GLOB_3:[0-9]+]], ![[GLOB_4:[0-9]+]]
 // CHECK: ![[GLOB_1]] = !{%struct.PODStruct* {{.*}}, i1 false, i1 false}
 // CHECK: ![[GLOB_2]] = !{%struct.PODWithDtor* {{.*}}, i1 false, i1 false}
 // CHECK: ![[GLOB_3]] = !{%struct.PODWithCtorAndDtor* {{.*}}, i1 true, i1 false}
 // CHECK: ![[GLOB_4]] = !{{{.*}}class.NS::PODWithCtor{{.*}}, i1 true, i1 false}
 
+// IGNORELIST: @s1 = global
+// IGNORELIST-NOT: sanitize_address_dyninit
+// IGNORELIST: @s2 = global
+// IGNORELIST-NOT: sanitize_address_dyninit
+// IGNORELIST: @s3 = global
+// IGNORELIST-NOT: sanitize_address_dyninit
+// IGNORELIST: @{{.*}}array{{.*}} = global
+// IGNORELIST-NOT: sanitize_address_dyninit
+
 // IGNORELIST: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], ![[GLOB_3:[0-9]+]], ![[GLOB_4:[0-9]+]]}
 // IGNORELIST: ![[GLOB_1]] = !{%struct.PODStruct* {{.*}}, i1 false, i1 false}
 // IGNORELIST: ![[GLOB_2]] = !{%struct.PODWithDtor* {{.*}}, i1 false, i1 false}
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -23,6 +23,9 @@
   const char *literal = "Hello, world!";
 }
 
+// ASAN: @dyn_init_global = global {{.*}}, sanitize_address_dyninit
+// KASAN: @dyn_init_global = global {{.*}}, sanitize_address_dyninit
+
 // ASAN: sectioned_global{{.*}} global { i32, [28 x i8] }{{.*}}, align 32
 // KASAN: sectioned_global{{.*}} global i32
 // ASAN: @__special_global{{.*}} global { i32, [28 x i8] }{{.*}}, align 32
Index: clang/lib/CodeGen/SanitizerMetadata.h
===
--- clang/lib/CodeGen/SanitizerMetadata.h
+++ clang/lib/CodeGen/SanitizerMetadata.h
@@ -14,13 +14,15 @@
 
 #include "clang/AST/Type.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/SourceLocation.h"
 
+#include "llvm/IR/GlobalVariable.h"
+
 namespace llvm {
-class GlobalVariable;
 class Instruction;
 class MDNode;
-}
+} // namespace llvm
 
 namespace clang {
 class VarDecl;
@@ -34,19 +36,24 @@
   void operator=(const SanitizerMetadata &) = delete;
 
   CodeGenModule &CGM;
+
 public:
   SanitizerMetadata(CodeGenModule &CGM);
-  void reportGlobalToASan(llvm::GlobalVariable *GV, const VarDecl &D,
-  bool IsDynInit = false);
-  void reportGlobalToASan(llvm::GlobalVariable *GV, SourceLocation Loc,
-  StringRef Name, QualType Ty, bool IsDynInit = false,
-  bool IsExcluded = false);
+  void reportGlobal(llvm::GlobalVariable *GV, const VarDecl &D,
+bool IsDynInit = false);
+  void reportGlobal(llvm::GlobalVariable *GV, SourceLocation Loc,
+StringRef Name, QualType Ty, bool IsDynInit = false,
+SanitizerMask NoSanitizeMask = {});
   void disableSanitizerForGlobal(llvm::GlobalVariable *GV);
   void disableSanitizerForInstruction(llvm::Instruction *I);
+
 private:
   llvm::MDNode *getLocationMetadata(SourceLocation Loc);
+  void setASanSpecificMetadata(llvm::GlobalVariable::SanitizerMetadata &Meta,
+   llvm::GlobalVariable *GV, SourceLocation Loc,
+   QualType Ty, bool IsDynInit = false);
 };
-}  // end namespace CodeGen
-}  // end namespace clang
+} // end namespace CodeGen
+} // end namespace clang
 
 #endif
Index: clang/lib/CodeGen/SanitizerMetadata.cpp
===
--- clang/lib/CodeGen/SanitizerMetadata.cpp
+++ clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -17,29 +17,90 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/IR/Constants.h"
 
+using GlobalVariable = llvm::GlobalVariable;
+using GVSanitizerMetadata = GlobalVariable::SanitizerMetadata;
+
 using namespace clang;
 using namespace CodeGen;
 
 SanitizerMe

[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

2022-06-06 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers planned changes to this revision.
vabridgers added a comment.

I know this will need a reproducer, and I'm working on that. That work is still 
in progress.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127105

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


[PATCH] D126871: [clang] [MinGW] Use SEH for unwind info on ARM by default

2022-06-06 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D126871#3560924 , @efriedma wrote:

> Oh, just remembered, we should probably release-note this.  (You can post 
> that as a followup.)

Sure, can do.

Btw, thanks a lot for your reviews, you've spent a lot of time on them! They 
did improve the end result a lot, and your pointers to e.g. specific passes 
that do things was very valuable - that's something that is hard to figure ouy 
by just grepping around in the code.

Also regarding announcing completion - at this point, the unwind info 
generation is complete, and itanium style unwinding works. But for MSVC style 
(C++ exceptions and `__try`/`__catch`) there's still a couple backend things 
that need to be implemented. Do you happen to know roughly how much effort that 
is? I've essentially achieved what I wanted here, but it would be nice just for 
completeness to have those parts implemented too, but it's a lower priority for 
me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126871

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


[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

2022-06-06 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:622
 setFPContractMode(LangOptions::FPM_Off);
 setRoundingMode(static_cast(LangOptions::FPR_ToNearest));
 setFPExceptionMode(LangOptions::FPE_Ignore);

I'm suggesting this should be `setRoundingMode(llvm::RoundingMode::Dynamic)`.

If FENV_ACCESS is off, getEffectiveRoundingMode() converts that to "nearest".  
If FENV_ACCESS is turned on, the mode is treated as dynamic.  This is exactly 
what we want.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

2022-06-06 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:622
 setFPContractMode(LangOptions::FPM_Off);
 setRoundingMode(static_cast(LangOptions::FPR_ToNearest));
 setFPExceptionMode(LangOptions::FPE_Ignore);

efriedma wrote:
> I'm suggesting this should be `setRoundingMode(llvm::RoundingMode::Dynamic)`.
> 
> If FENV_ACCESS is off, getEffectiveRoundingMode() converts that to "nearest". 
>  If FENV_ACCESS is turned on, the mode is treated as dynamic.  This is 
> exactly what we want.
It would change semantics. In particular, it would make impossible to use FP 
arithmetic in constexpr functions. An expression like `1.0 / 3.0` cannot be 
evaluated with dynamic rounding mode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[PATCH] D127142: [HIP] Link with clang_rt.builtins

2022-06-06 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: MaskRay.

HIP supports _Float16 by default in host programs, which
may cause calls of conversion functions for _Float16
emitted e.g. `__truncdfhf2`. These functions are not
available in libgcc but in libclang_rt.builtins. Therefore
--hip-link needs to link with libclang_rt.builtins by
default.

By default clang already has -L for libclang_rt.builtins.
Therefore only -lclang_rt.builtins needs to be added.


https://reviews.llvm.org/D127142

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/hip-runtime-libs-linux.hip
  clang/test/Driver/hip-runtime-libs-msvc.hip


Index: clang/test/Driver/hip-runtime-libs-msvc.hip
===
--- clang/test/Driver/hip-runtime-libs-msvc.hip
+++ clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -7,4 +7,6 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck %s
 
+// CHECK: "-libpath:{{.*lib.*windows}}"
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
+// CHECK: "clang_rt.builtins-x86_64.lib"
Index: clang/test/Driver/hip-runtime-libs-linux.hip
===
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -5,12 +5,12 @@
 // Test HIP runtime lib args specified by --rocm-path.
 // RUN: %clang -### --hip-link -target x86_64-linux-gnu \
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+// RUN:   | FileCheck -check-prefixes=ROCM-PATH,COMMON %s
 
 // Test HIP runtime lib args specified by environment variable ROCM_PATH.
 // RUN: env ROCM_PATH=%S/Inputs/rocm %clang -### --hip-link \
 // RUN:   -target x86_64-linux-gnu %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+// RUN:   | FileCheck -check-prefixes=ROCM-PATH,COMMON %s
 
 // Test detecting latest /opt/rocm-{release} directory.
 // RUN: rm -rf %T/opt
@@ -19,7 +19,7 @@
 // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.10.0
 // RUN: %clang -### --hip-link -target x86_64-linux-gnu \
 // RUN:   --sysroot=%T %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-REL %s
+// RUN:   | FileCheck -check-prefixes=ROCM-REL,COMMON %s
 
 // Test HIP runtime lib is not linked without --hip-link.
 // RUN: %clang -### -target x86_64-linux-gnu \
@@ -36,8 +36,11 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
+// COMMON: "-L{{.*}}lib/x86_64-unknown-linux-gnu"
 // ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" 
"-lamdhip64"
 // ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-rpath" "[[HIPRT]]" 
"-lamdhip64"
+// COMMON: "-lclang_rt.builtins-x86_64"
 // NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-lamdhip64"
+// NOHIPRT-NOT: "-lclang_rt.builtins-x86_64"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -482,6 +482,8 @@
   CmdArgs.append({Args.MakeArgString(StringRef("-libpath:") +
  RocmInstallation.getLibPath()),
   "amdhip64.lib"});
+  CmdArgs.push_back(Args.MakeArgString("clang_rt.builtins-" +
+   getTriple().getArchName() + ".lib"));
 }
 
 void MSVCToolChain::printVerboseInfo(raw_ostream &OS) const {
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -686,6 +686,8 @@
"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
 
   CmdArgs.push_back("-lamdhip64");
+  CmdArgs.push_back(
+  Args.MakeArgString("-lclang_rt.builtins-" + getTriple().getArchName()));
 }
 
 void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,


Index: clang/test/Driver/hip-runtime-libs-msvc.hip
===
--- clang/test/Driver/hip-runtime-libs-msvc.hip
+++ clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -7,4 +7,6 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck %s
 
+// CHECK: "-libpath:{{.*lib.*windows}}"
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
+// CHECK: "clang_rt.builtins-x86_64.lib"
Index: clang/test/Driver/hip-runtime-libs-linux.hip
===
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -5,12 +5,12 @@
 // Test HIP runtime lib args specified by --rocm-path.
 // RUN: %clang -### --hip-link -target x86_64-linux-gnu \
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>

[PATCH] D126364: Fix interaction of pragma FENV_ACCESS with other pragmas

2022-06-06 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:622
 setFPContractMode(LangOptions::FPM_Off);
 setRoundingMode(static_cast(LangOptions::FPR_ToNearest));
 setFPExceptionMode(LangOptions::FPE_Ignore);

sepavloff wrote:
> efriedma wrote:
> > I'm suggesting this should be 
> > `setRoundingMode(llvm::RoundingMode::Dynamic)`.
> > 
> > If FENV_ACCESS is off, getEffectiveRoundingMode() converts that to 
> > "nearest".  If FENV_ACCESS is turned on, the mode is treated as dynamic.  
> > This is exactly what we want.
> It would change semantics. In particular, it would make impossible to use FP 
> arithmetic in constexpr functions. An expression like `1.0 / 3.0` cannot be 
> evaluated with dynamic rounding mode.
Can we just change the relevant code in ExprConstant to call 
getEffectiveRoundingMode()?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126364

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


[PATCH] D127142: [HIP] Link with clang_rt.builtins

2022-06-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:485
   "amdhip64.lib"});
+  CmdArgs.push_back(Args.MakeArgString("clang_rt.builtins-" +
+   getTriple().getArchName() + ".lib"));

Note that the path is different with LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on. See 
D107799


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

https://reviews.llvm.org/D127142

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


[PATCH] D126871: [clang] [MinGW] Use SEH for unwind info on ARM by default

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

> Btw, thanks a lot for your reviews, you've spent a lot of time on them!

You're welcome.

> But for MSVC style (C++ exceptions and __try/__except) there's still a couple 
> backend things that need to be implemented. Do you happen to know roughly how 
> much effort that is?

Getting funclets working is a significant amount of code; see D51524 
 .

Beyond that, it's not that much work, I think?  There's probably some random 
little bits I'm not remembering, but most of the code is shared across 
x64/aarch64/arm, I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126871

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


[PATCH] D126871: [clang] [MinGW] Use SEH for unwind info on ARM by default

2022-06-06 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D126871#3561243 , @efriedma wrote:

>> But for MSVC style (C++ exceptions and __try/__except) there's still a 
>> couple backend things that need to be implemented. Do you happen to know 
>> roughly how much effort that is?
>
> Getting funclets working is a significant amount of code; see D51524 
>  .

Yikes - ok, thanks, that's good to know. Are funclets also needed for 
`__try`/`__except`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126871

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


[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

2022-06-06 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 434563.
iains added a comment.

reworked to use D113545  as a parent revision

which resolves the issue of needing to make module ownership 'visible' to 
satisfy lookup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126694

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp

Index: clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
===
--- clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
+++ clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
@@ -29,8 +29,7 @@
 #endif
 
 void test_early() {
-  in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
-  // expected-note@* {{not visible}}
+  in_header = 1; // expected-error {{use of undeclared identifier 'in_header'}}
 
   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
   // expected-n...@p2.cpp:16 {{not visible}}
@@ -57,8 +56,7 @@
 #endif
 
 void test_late() {
-  in_header = 1; // expected-error {{missing '#include "foo.h"'; 'in_header' must be declared before it is used}}
-  // expected-note@* {{not visible}}
+  in_header = 1; // expected-error {{use of undeclared identifier 'in_header'}}
 
   global_module_fragment = 1; // expected-error {{missing '#include'; 'global_module_fragment' must be declared before it is used}}
   // expected-n...@p2.cpp:16 {{not visible}}
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -621,6 +621,7 @@
 case Decl::ModuleOwnershipKind::VisibleWhenImported:
 case Decl::ModuleOwnershipKind::ReachableWhenImported:
 case Decl::ModuleOwnershipKind::ModulePrivate:
+case Decl::ModuleOwnershipKind::ModuleUnreachable:
   break;
 
 default:
@@ -631,9 +632,10 @@
 // Store the owning submodule ID in the declaration.
 D->setOwningModuleID(SubmoduleID);
 
-if (ModulePrivate) {
-  // Module-private declarations are never visible, so there is no work to
-  // do.
+if (ModulePrivate ||
+ModuleOwnership == Decl::ModuleOwnershipKind::ModuleUnreachable) {
+  // Module-private and unreachable declarations are never visible, so
+  // there is no work to do.
 } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) {
   // If local visibility is being tracked, this declaration will become
   // hidden and visible as the owning module does.
@@ -644,6 +646,8 @@
   else
 Reader.HiddenNamesMap[Owner].push_back(D);
 }
+  } else if (ModuleOwnership == Decl::ModuleOwnershipKind::ModuleUnreachable) {
+D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModuleUnreachable);
   } else if (ModulePrivate) {
 D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate);
   }
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1004,7 +1004,7 @@
 SemaRef.inferGslPointerAttribute(Typedef);
 
   Typedef->setAccess(D->getAccess());
-  Typedef->setReferenced(D->isReferenced());
+  SemaRef.setDeclReferenced(Typedef, D->isReferenced());
 
   return Typedef;
 }
@@ -1069,7 +1069,7 @@
 Decl *TemplateDeclInstantiator::VisitBindingDecl(BindingDecl *D) {
   auto *NewBD = BindingDecl::Create(SemaRef.Context, Owner, D->getLocation(),
 D->getIdentifier());
-  NewBD->setReferenced(D->isReferenced());
+  SemaRef.setDeclReferenced(NewBD, D->isReferenced());
   SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, NewBD);
   return NewBD;
 }
@@ -5210,8 +5210,8 @@
 
   if (!OldVar->isStaticDataMember()) {
 if (OldVar->isUsed(false))
-  NewVar->setIsUsed();
-NewVar->setReferenced(OldVar->isReferenced());
+  setDeclIsUsed(NewVar);
+setDeclReferenced(static_cast(NewVar), OldVar->isReferenced());
   }
 
   InstantiateAttrs(TemplateArgs, OldVar, NewVar, LateAttrs, StartingScope);
Index: clang/lib/Sema/SemaStmtAsm.cpp

[PATCH] D126871: [clang] [MinGW] Use SEH for unwind info on ARM by default

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

Funclets are necessary for both C++ and SEH exception handling, yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126871

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


[PATCH] D126694: [C++20][Modules] Initial implementation of GMF decl elision.

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

so standard 10.4 ex 2 gives the expected output with this patch stack 
note that there's a query to core about whether that example is fully correct 
(but that does not affect the skeleton of these implements - only the detail of 
what is included / excluded in the `markReachableGMFDecls()` evaluation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126694

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


[PATCH] D127142: [HIP] Link with clang_rt.builtins

2022-06-06 Thread Artem Belevich via Phabricator via cfe-commits
tra added a reviewer: MaskRay.
tra added a comment.
Herald added a subscriber: StephenFan.

Looks OK syntax-wise.  Library path should probably be fixed, though it appears 
to be a somewhat separate  issue and could be done in its own patch, if the 
required change is not trivial.




Comment at: clang/lib/Driver/ToolChains/Linux.cpp:684-690
   CmdArgs.append(
   {Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()),
"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
 
   CmdArgs.push_back("-lamdhip64");
+  CmdArgs.push_back(
+  Args.MakeArgString("-lclang_rt.builtins-" + getTriple().getArchName()));

Nit: Collapse all of these into a single `append()`



Comment at: clang/test/Driver/hip-runtime-libs-msvc.hip:10
 
+// CHECK: "-libpath:{{.*lib.*windows}}"
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"

What are we matching here? A more verbose pattern or some comments would be 
helpful.



Comment at: clang/test/Driver/hip-runtime-libs-msvc.hip:12
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
+// CHECK: "clang_rt.builtins-x86_64.lib"

`CHECK-SAME`?


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

https://reviews.llvm.org/D127142

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


[clang] d1346e2 - [gmodules] Skip CXXDeductionGuideDecls when visiting FunctionDecls in

2022-06-06 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2022-06-06T12:51:36-07:00
New Revision: d1346e2ee2741919a8cc1b1ffe41e76a6d06

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

LOG: [gmodules] Skip CXXDeductionGuideDecls when visiting FunctionDecls in
DebugTypeVisitor

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

Added: 
clang/test/Modules/Inputs/gmodules-deduction-guide.h
clang/test/Modules/gmodules-deduction-guide.cpp

Modified: 
clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp 
b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
index 9fe7e5d1f5c31..d03e5bd508731 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -96,6 +96,10 @@ class PCHContainerGenerator : public ASTConsumer {
 }
 
 bool VisitFunctionDecl(FunctionDecl *D) {
+  // Skip deduction guides.
+  if (isa(D))
+return true;
+
   if (isa(D))
 // This is not yet supported. Constructing the `this' argument
 // mandates a CodeGenFunction.

diff  --git a/clang/test/Modules/Inputs/gmodules-deduction-guide.h 
b/clang/test/Modules/Inputs/gmodules-deduction-guide.h
new file mode 100644
index 0..47b5931083af1
--- /dev/null
+++ b/clang/test/Modules/Inputs/gmodules-deduction-guide.h
@@ -0,0 +1,11 @@
+struct A {
+};
+
+template 
+struct S{
+  S(const A &);
+};
+
+S(const A&) -> S;
+
+typedef decltype(S(A())) Type0;

diff  --git a/clang/test/Modules/gmodules-deduction-guide.cpp 
b/clang/test/Modules/gmodules-deduction-guide.cpp
new file mode 100644
index 0..1017b76c82875
--- /dev/null
+++ b/clang/test/Modules/gmodules-deduction-guide.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++2b -x c++-header -emit-pch -fmodule-format=obj -I 
%S/Inputs \
+// RUN:   -o %t.pch %S/Inputs/gmodules-deduction-guide.h \
+// RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
+// RUN: cat %t-pch.ll | FileCheck %s
+
+// CHECK: ![[V0:.*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "S",
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "Type0",{{.*}}, baseType: 
![[V0]])



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


[PATCH] D125839: [gmodules] Skip CXXDeductionGuideDecls when visiting FunctionDecls in DebugTypeVisitor

2022-06-06 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 rGd1346e2ee274: [gmodules] Skip CXXDeductionGuideDecls when 
visiting FunctionDecls in (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125839

Files:
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/test/Modules/Inputs/gmodules-deduction-guide.h
  clang/test/Modules/gmodules-deduction-guide.cpp


Index: clang/test/Modules/gmodules-deduction-guide.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-deduction-guide.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++2b -x c++-header -emit-pch -fmodule-format=obj -I 
%S/Inputs \
+// RUN:   -o %t.pch %S/Inputs/gmodules-deduction-guide.h \
+// RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
+// RUN: cat %t-pch.ll | FileCheck %s
+
+// CHECK: ![[V0:.*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "S",
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "Type0",{{.*}}, baseType: 
![[V0]])
Index: clang/test/Modules/Inputs/gmodules-deduction-guide.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/gmodules-deduction-guide.h
@@ -0,0 +1,11 @@
+struct A {
+};
+
+template 
+struct S{
+  S(const A &);
+};
+
+S(const A&) -> S;
+
+typedef decltype(S(A())) Type0;
Index: clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
===
--- clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -96,6 +96,10 @@
 }
 
 bool VisitFunctionDecl(FunctionDecl *D) {
+  // Skip deduction guides.
+  if (isa(D))
+return true;
+
   if (isa(D))
 // This is not yet supported. Constructing the `this' argument
 // mandates a CodeGenFunction.


Index: clang/test/Modules/gmodules-deduction-guide.cpp
===
--- /dev/null
+++ clang/test/Modules/gmodules-deduction-guide.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++2b -x c++-header -emit-pch -fmodule-format=obj -I %S/Inputs \
+// RUN:   -o %t.pch %S/Inputs/gmodules-deduction-guide.h \
+// RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
+// RUN: cat %t-pch.ll | FileCheck %s
+
+// CHECK: ![[V0:.*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S",
+// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "Type0",{{.*}}, baseType: ![[V0]])
Index: clang/test/Modules/Inputs/gmodules-deduction-guide.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/gmodules-deduction-guide.h
@@ -0,0 +1,11 @@
+struct A {
+};
+
+template 
+struct S{
+  S(const A &);
+};
+
+S(const A&) -> S;
+
+typedef decltype(S(A())) Type0;
Index: clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
===
--- clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
+++ clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
@@ -96,6 +96,10 @@
 }
 
 bool VisitFunctionDecl(FunctionDecl *D) {
+  // Skip deduction guides.
+  if (isa(D))
+return true;
+
   if (isa(D))
 // This is not yet supported. Constructing the `this' argument
 // mandates a CodeGenFunction.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127145: [Driver] add -lresolv for all but Android.

2022-06-06 Thread Kevin Athey via Phabricator via cfe-commits
kda created this revision.
kda added reviewers: vitalybuka, eugenis.
Herald added subscribers: Enna1, danielkiss.
Herald added a project: All.
kda requested review of this revision.
Herald added subscribers: Sanitizers, cfe-commits, MaskRay.
Herald added projects: clang, Sanitizers.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127145

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/test/msan/Linux/b64.cpp
  compiler-rt/test/msan/Linux/dn_expand.cpp
  compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
  compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp


Index: compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
===
--- compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
@@ -1,7 +1,4 @@
-// RUN: %clangxx %s -o %t -lresolv && %run %t %p
-
-// -lresolv fails on Android.
-// UNSUPPORTED: android
+// RUN: %clangxx %s -o %t && %run %t %p
 
 #include 
 #include 
Index: compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
===
--- compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
@@ -1,7 +1,4 @@
-// RUN: %clangxx %s -o %t -lresolv && %run %t %p
-
-// -lresolv fails on Android.
-// UNSUPPORTED: android
+// RUN: %clangxx %s -o %t && %run %t %p
 
 #include 
 #include 
Index: compiler-rt/test/msan/Linux/dn_expand.cpp
===
--- compiler-rt/test/msan/Linux/dn_expand.cpp
+++ compiler-rt/test/msan/Linux/dn_expand.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_msan -O0 %s -o %t -lresolv && %run %t
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
 
 #include 
 #include 
Index: compiler-rt/test/msan/Linux/b64.cpp
===
--- compiler-rt/test/msan/Linux/b64.cpp
+++ compiler-rt/test/msan/Linux/b64.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_msan -O0 %s -o %t -lresolv && %run %t
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
 // RUN: not %run %t NTOP_READ 2>&1 | FileCheck %s --check-prefix=NTOP_READ
 // RUN: not %run %t PTON_READ 2>&1 | FileCheck %s --check-prefix=PTON_READ
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -838,6 +838,10 @@
   TC.getTriple().isOSNetBSD() ||
   TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lexecinfo");
+  // There is no libresolv on Android.
+  if (!TC.getTriple().isAndroid()) {
+CmdArgs.push_back("-lresolv");
+  }
 }
 
 static void


Index: compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
===
--- compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/dn_expand.cpp
@@ -1,7 +1,4 @@
-// RUN: %clangxx %s -o %t -lresolv && %run %t %p
-
-// -lresolv fails on Android.
-// UNSUPPORTED: android
+// RUN: %clangxx %s -o %t && %run %t %p
 
 #include 
 #include 
Index: compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
===
--- compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/b64.cpp
@@ -1,7 +1,4 @@
-// RUN: %clangxx %s -o %t -lresolv && %run %t %p
-
-// -lresolv fails on Android.
-// UNSUPPORTED: android
+// RUN: %clangxx %s -o %t && %run %t %p
 
 #include 
 #include 
Index: compiler-rt/test/msan/Linux/dn_expand.cpp
===
--- compiler-rt/test/msan/Linux/dn_expand.cpp
+++ compiler-rt/test/msan/Linux/dn_expand.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_msan -O0 %s -o %t -lresolv && %run %t
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
 
 #include 
 #include 
Index: compiler-rt/test/msan/Linux/b64.cpp
===
--- compiler-rt/test/msan/Linux/b64.cpp
+++ compiler-rt/test/msan/Linux/b64.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_msan -O0 %s -o %t -lresolv && %run %t
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t
 // RUN: not %run %t NTOP_READ 2>&1 | FileCheck %s --check-prefix=NTOP_READ
 // RUN: not %run %t PTON_READ 2>&1 | FileCheck %s --check-prefix=PTON_READ
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -838,6 +838,10 @@
   TC.getTriple().isOSNetBSD() ||
   TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lexecinfo");
+  // There is no libresolv on Android.
+  if (!TC.getTriple().isAndroid()) {
+CmdArgs.push_

[PATCH] D127145: [Driver] add -lresolv for all but Android.

2022-06-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

The description needs to mention the motivation. Is this meant for `isOSLinux() 
&& isGNUEnvironment()` targets?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127145

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


[clang] 2293d46 - [clang] [Headers] Check __SEH__, when checking if ARM EHABI is implied

2022-06-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-06-06T23:21:05+03:00
New Revision: 2293d46a01752e312a0796d044a25a49b2fd17f5

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

LOG: [clang] [Headers] Check __SEH__, when checking if ARM EHABI is implied

ARM EHABI isn't signalled by any specific compiler builtin define,
but is implied by the lack of defines specifying any other
exception handling mechanism, `__USING_SJLJ_EXCEPTIONS__` or
`__ARM_DWARF_EH__`.

As Windows SEH also can be used for unwinding, check for the
`__SEH__` define too, in the same way.

This is the same change as 4a3722a2c3dff1fe885cc38bf43d3c095c9851e7 /
D126866, applied on the clang headers.

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

Added: 


Modified: 
clang/lib/Headers/unwind.h

Removed: 




diff  --git a/clang/lib/Headers/unwind.h b/clang/lib/Headers/unwind.h
index 6e069798f02d6..971a62da0d212 100644
--- a/clang/lib/Headers/unwind.h
+++ b/clang/lib/Headers/unwind.h
@@ -62,7 +62,8 @@ typedef intptr_t _sleb128_t;
 typedef uintptr_t _uleb128_t;
 
 struct _Unwind_Context;
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 struct _Unwind_Control_Block;
 typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
 #else
@@ -72,7 +73,7 @@ typedef struct _Unwind_Exception _Unwind_Exception;
 typedef enum {
   _URC_NO_REASON = 0,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_OK = 0, /* used by ARM EHABI */
 #endif
   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
@@ -86,7 +87,7 @@ typedef enum {
   _URC_INSTALL_CONTEXT = 7,
   _URC_CONTINUE_UNWIND = 8,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_FAILURE = 9 /* used by ARM EHABI */
 #endif
 } _Unwind_Reason_Code;
@@ -103,7 +104,8 @@ typedef enum {
 typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
  _Unwind_Exception *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef struct _Unwind_Control_Block _Unwind_Control_Block;
 typedef uint32_t _Unwind_EHT_Header;
 
@@ -167,7 +169,8 @@ typedef _Unwind_Personality_Fn __personality_routine;
 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
 void *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) ||
\
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef enum {
   _UVRSC_CORE = 0,/* integer register */
   _UVRSC_VFP = 1, /* vfp */



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


[libunwind] 7c0e93c - [libunwind] Fix SEH unwinding on ARM

2022-06-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-06-06T23:23:35+03:00
New Revision: 7c0e93cb89e6aa74881411213abf83faae7c58ee

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

LOG: [libunwind] Fix SEH unwinding on ARM

Check `__SEH__` when checking if ARM EHABI should be implied,
similarly to 4a3722a2c3dff1fe885cc38bf43d3c095c9851e7 / D126866.

Fix a warning by using the right format specifier (PRIxPTR instead
of PRIx64), and add a double->float cast in a codepath that hasn't
been built so far.

This is enough to make SEH unwinding of itanium ABI exceptions on
ARM mostly work - one specific issue is fixed in a separate follow-up
patch.

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

Added: 


Modified: 
libunwind/include/__libunwind_config.h
libunwind/include/libunwind.h
libunwind/src/Unwind-seh.cpp
libunwind/src/UnwindCursor.hpp

Removed: 




diff  --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index e626567d4e594..5e9de90f649fd 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -12,7 +12,7 @@
 #define _LIBUNWIND_VERSION 15000
 
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
 #define _LIBUNWIND_ARM_EHABI
 #endif
 

diff  --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index 3d8fd2146ebbd..f878b46f03484 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -81,7 +81,7 @@ typedef struct unw_addr_space *unw_addr_space_t;
 
 typedef int unw_regnum_t;
 typedef uintptr_t unw_word_t;
-#if defined(__arm__) && !defined(__ARM_DWARF_EH__)
+#if defined(__arm__) && !defined(__ARM_DWARF_EH__) && !defined(__SEH__)
 typedef uint64_t unw_fpreg_t;
 #else
 typedef double unw_fpreg_t;

diff  --git a/libunwind/src/Unwind-seh.cpp b/libunwind/src/Unwind-seh.cpp
index f00bc4721ba43..64aaf0a383b86 100644
--- a/libunwind/src/Unwind-seh.cpp
+++ b/libunwind/src/Unwind-seh.cpp
@@ -255,8 +255,8 @@ unwind_phase2_forced(unw_context_t *uc,
   (frameInfo.start_ip + offset > frameInfo.end_ip))
 functionName = ".anonymous.";
   _LIBUNWIND_TRACE_UNWINDING(
-  "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIx64
-  ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64,
+  "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIxPTR
+  ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR,
   (void *)exception_object, frameInfo.start_ip, functionName,
   frameInfo.lsda, frameInfo.handler);
 }

diff  --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 6e8fc45ebfa8f..dc334edbe3857 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -863,7 +863,7 @@ void UnwindCursor::setFloatReg(int regNum, 
unw_fpreg_t value) {
   uint32_t w;
   float f;
 } d;
-d.f = value;
+d.f = (float)value;
 _msContext.S[regNum - UNW_ARM_S0] = d.w;
   }
   if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {



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


[libunwind] 64778c0 - [libunwind] Remove unused ARM SEH placeholder code

2022-06-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-06-06T23:24:22+03:00
New Revision: 64778c002a77046e15a7ce7a7206f5c15355fc26

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

LOG: [libunwind] Remove unused ARM SEH placeholder code

There's no such corresponding code for ARM64 (which has been working
in production for years). The SEH version of the Unwind functions
(e.g. `_Unwind_GetLanguageSpecificData`) doesn't use these fields.

The `_Unwind_ForcedUnwind` function would need these bits though,
but that's not used in normal C++ exception unwinding.

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

Added: 


Modified: 
libunwind/src/UnwindCursor.hpp

Removed: 




diff  --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index dc334edbe385..a46bbfbccdb5 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -1965,10 +1965,6 @@ bool UnwindCursor::getInfoFromSEH(pint_t pc) {
   _info.handler = 0;
 }
   }
-#elif defined(_LIBUNWIND_TARGET_ARM)
-  _info.end_ip = _info.start_ip + unwindEntry->FunctionLength;
-  _info.lsda = 0; // FIXME
-  _info.handler = 0; // FIXME
 #endif
   setLastPC(pc);
   return true;



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


[PATCH] D126865: [clang] [Headers] Check __SEH__, when checking if ARM EHABI is implied

2022-06-06 Thread Martin Storsjö 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 rG2293d46a0175: [clang] [Headers] Check __SEH__, when checking 
if ARM EHABI is implied (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126865

Files:
  clang/lib/Headers/unwind.h


Index: clang/lib/Headers/unwind.h
===
--- clang/lib/Headers/unwind.h
+++ clang/lib/Headers/unwind.h
@@ -62,7 +62,8 @@
 typedef uintptr_t _uleb128_t;
 
 struct _Unwind_Context;
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 struct _Unwind_Control_Block;
 typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
 #else
@@ -72,7 +73,7 @@
 typedef enum {
   _URC_NO_REASON = 0,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_OK = 0, /* used by ARM EHABI */
 #endif
   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
@@ -86,7 +87,7 @@
   _URC_INSTALL_CONTEXT = 7,
   _URC_CONTINUE_UNWIND = 8,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_FAILURE = 9 /* used by ARM EHABI */
 #endif
 } _Unwind_Reason_Code;
@@ -103,7 +104,8 @@
 typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
  _Unwind_Exception *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef struct _Unwind_Control_Block _Unwind_Control_Block;
 typedef uint32_t _Unwind_EHT_Header;
 
@@ -167,7 +169,8 @@
 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
 void *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || 
defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) ||
\
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef enum {
   _UVRSC_CORE = 0,/* integer register */
   _UVRSC_VFP = 1, /* vfp */


Index: clang/lib/Headers/unwind.h
===
--- clang/lib/Headers/unwind.h
+++ clang/lib/Headers/unwind.h
@@ -62,7 +62,8 @@
 typedef uintptr_t _uleb128_t;
 
 struct _Unwind_Context;
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 struct _Unwind_Control_Block;
 typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
 #else
@@ -72,7 +73,7 @@
 typedef enum {
   _URC_NO_REASON = 0,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_OK = 0, /* used by ARM EHABI */
 #endif
   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
@@ -86,7 +87,7 @@
   _URC_INSTALL_CONTEXT = 7,
   _URC_CONTINUE_UNWIND = 8,
 #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \
-!defined(__ARM_DWARF_EH__)
+!defined(__ARM_DWARF_EH__) && !defined(__SEH__)
   _URC_FAILURE = 9 /* used by ARM EHABI */
 #endif
 } _Unwind_Reason_Code;
@@ -103,7 +104,8 @@
 typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
  _Unwind_Exception *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || \
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef struct _Unwind_Control_Block _Unwind_Control_Block;
 typedef uint32_t _Unwind_EHT_Header;
 
@@ -167,7 +169,8 @@
 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
 void *);
 
-#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__))
+#if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) ||\
+  defined(__ARM_DWARF_EH__) || defined(__SEH__))
 typedef enum {
   _UVRSC_CORE = 0,/* integer register */
   _UVRSC_VFP = 1, /* vfp */
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] 08d30c6 - [libunwind] Don't store a predecremented PC when using SEH

2022-06-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-06-06T23:25:24+03:00
New Revision: 08d30c602bcf3bc25a02938f2663a1b9e96a7cbe

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

LOG: [libunwind] Don't store a predecremented PC when using SEH

This fixes unwinding in boundary cases on ARM with SEH.

In the case of ARM/Thumb, disp->ControlPc points at the following
instruction, with the thumb bit set. Thus by decrementing 1,
it still points at the next instruction. To achieve the desired
effect of pointing at the previous instruction, one first has to strip
out the thumb bit, then do the decrement by 1 to reach the previous
instruction.

When libcxxabi looks for call site ranges, it already does
`_Unwind_GetIP(context) - 1` (in `scan_eh_tab` in
libcxxabi/src/cxa_personality.cpp), so we shouldn't do the
corresponding `- 1` multiple times.

In the case of libcxxabi on Thumb, `funcStart` (still in `scan_eh_tab`)
may have the thumb bit set. If the program counter address is
decremented both in libunwind (first removing the thumb bit, then
decremented), and then libcxxabi decrements it further, and compares
with a `funcStart` with the thumb bit set, it could point to one byte
before the start of the call site.

Thus: This modification makes libunwind with SEH work with libcxxabi
on Thumb, in settings where libunwind and libcxxabi worked fine with
Dwarf before.

For existing cases with libunwind with SEH (on x86_64 and aarch64),
this modification doesn't break any of my testcases.

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

Added: 


Modified: 
libunwind/src/Unwind-seh.cpp
libunwind/src/UnwindCursor.hpp

Removed: 




diff  --git a/libunwind/src/Unwind-seh.cpp b/libunwind/src/Unwind-seh.cpp
index 64aaf0a383b8..c2c31045a37b 100644
--- a/libunwind/src/Unwind-seh.cpp
+++ b/libunwind/src/Unwind-seh.cpp
@@ -104,7 +104,7 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID 
frame, PCONTEXT ms_ctx,
   if (!ctx) {
 __unw_init_seh(&cursor, disp->ContextRecord);
 __unw_seh_set_disp_ctx(&cursor, disp);
-__unw_set_reg(&cursor, UNW_REG_IP, disp->ControlPc - 1);
+__unw_set_reg(&cursor, UNW_REG_IP, disp->ControlPc);
 ctx = (struct _Unwind_Context *)&cursor;
 
 if (!IS_UNWINDING(ms_exc->ExceptionFlags)) {

diff  --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index a46bbfbccdb5..e363f9e59c9a 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -518,6 +518,14 @@ class UnwindCursor : public AbstractUnwindCursor {
   pint_t getLastPC() const { return _dispContext.ControlPc; }
   void setLastPC(pint_t pc) { _dispContext.ControlPc = pc; }
   RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {
+#ifdef __arm__
+// Remove the thumb bit; FunctionEntry ranges don't include the thumb bit.
+pc &= ~1U;
+#endif
+// If pc points exactly at the end of the range, we might resolve the
+// next function instead. Decrement pc by 1 to fit inside the current
+// function.
+pc -= 1;
 _dispContext.FunctionEntry = RtlLookupFunctionEntry(pc,
 
&_dispContext.ImageBase,
 
_dispContext.HistoryTable);



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


[clang] fcb784d - [clang] [MinGW] Default to WinEH (SEH) exception handling instead of Dwarf

2022-06-06 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-06-06T23:27:31+03:00
New Revision: fcb784db496137fa29a11b7e106efe89c7550e11

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

LOG: [clang] [MinGW] Default to WinEH (SEH) exception handling instead of Dwarf

The relevant runtime libraries have been updated to support this
now.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/MinGW.cpp
clang/test/Driver/windows-exceptions.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index ceeaa79bc2021..43466ef2b40f5 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -478,8 +478,8 @@ bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList 
&Args) const {
   if (ExceptionArg &&
   ExceptionArg->getOption().matches(options::OPT_fseh_exceptions))
 return true;
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
+  return getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
+ getArch() == llvm::Triple::thumb || getArch() == 
llvm::Triple::aarch64;
 }
 
 bool toolchains::MinGW::isPICDefault() const {
@@ -495,7 +495,8 @@ bool toolchains::MinGW::isPICDefaultForced() const { return 
true; }
 
 llvm::ExceptionHandling
 toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
-  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64)
+  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 
||
+  getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb)
 return llvm::ExceptionHandling::WinEH;
   return llvm::ExceptionHandling::DwarfCFI;
 }

diff  --git a/clang/test/Driver/windows-exceptions.cpp 
b/clang/test/Driver/windows-exceptions.cpp
index 244c3b9479549..ffca80fdfa550 100644
--- a/clang/test/Driver/windows-exceptions.cpp
+++ b/clang/test/Driver/windows-exceptions.cpp
@@ -4,6 +4,8 @@
 // RUN: %clang -target aarch64-windows-msvc -c %s -### 2>&1 | FileCheck 
-check-prefix=MSVC -check-prefix=MSVC-SEH %s
 // RUN: %clang -target i686-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-DWARF %s
 // RUN: %clang -target x86_64-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
+// RUN: %clang -target armv7-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 | 
FileCheck -check-prefix=MINGW-DWARF %s
+// RUN: %clang -target armv7-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
 // RUN: %clang -target aarch64-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 
| FileCheck -check-prefix=MINGW-DWARF %s
 // RUN: %clang -target aarch64-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
 



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


[PATCH] D126871: [clang] [MinGW] Use SEH for unwind info on ARM by default

2022-06-06 Thread Martin Storsjö 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 rGfcb784db4961: [clang] [MinGW] Default to WinEH (SEH) 
exception handling instead of Dwarf (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D126871?vs=433706&id=434589#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126871

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/windows-exceptions.cpp


Index: clang/test/Driver/windows-exceptions.cpp
===
--- clang/test/Driver/windows-exceptions.cpp
+++ clang/test/Driver/windows-exceptions.cpp
@@ -4,6 +4,8 @@
 // RUN: %clang -target aarch64-windows-msvc -c %s -### 2>&1 | FileCheck 
-check-prefix=MSVC -check-prefix=MSVC-SEH %s
 // RUN: %clang -target i686-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-DWARF %s
 // RUN: %clang -target x86_64-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
+// RUN: %clang -target armv7-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 | 
FileCheck -check-prefix=MINGW-DWARF %s
+// RUN: %clang -target armv7-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
 // RUN: %clang -target aarch64-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 
| FileCheck -check-prefix=MINGW-DWARF %s
 // RUN: %clang -target aarch64-windows-gnu -c %s -### 2>&1 | FileCheck 
-check-prefix=MINGW-SEH %s
 
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -478,8 +478,8 @@
   if (ExceptionArg &&
   ExceptionArg->getOption().matches(options::OPT_fseh_exceptions))
 return true;
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
+  return getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
+ getArch() == llvm::Triple::thumb || getArch() == 
llvm::Triple::aarch64;
 }
 
 bool toolchains::MinGW::isPICDefault() const {
@@ -495,7 +495,8 @@
 
 llvm::ExceptionHandling
 toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
-  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64)
+  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 
||
+  getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb)
 return llvm::ExceptionHandling::WinEH;
   return llvm::ExceptionHandling::DwarfCFI;
 }


Index: clang/test/Driver/windows-exceptions.cpp
===
--- clang/test/Driver/windows-exceptions.cpp
+++ clang/test/Driver/windows-exceptions.cpp
@@ -4,6 +4,8 @@
 // RUN: %clang -target aarch64-windows-msvc -c %s -### 2>&1 | FileCheck -check-prefix=MSVC -check-prefix=MSVC-SEH %s
 // RUN: %clang -target i686-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-DWARF %s
 // RUN: %clang -target x86_64-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-SEH %s
+// RUN: %clang -target armv7-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-DWARF %s
+// RUN: %clang -target armv7-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-SEH %s
 // RUN: %clang -target aarch64-windows-gnu -fdwarf-exceptions -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-DWARF %s
 // RUN: %clang -target aarch64-windows-gnu -c %s -### 2>&1 | FileCheck -check-prefix=MINGW-SEH %s
 
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -478,8 +478,8 @@
   if (ExceptionArg &&
   ExceptionArg->getOption().matches(options::OPT_fseh_exceptions))
 return true;
-  return getArch() == llvm::Triple::x86_64 ||
- getArch() == llvm::Triple::aarch64;
+  return getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::arm ||
+ getArch() == llvm::Triple::thumb || getArch() == llvm::Triple::aarch64;
 }
 
 bool toolchains::MinGW::isPICDefault() const {
@@ -495,7 +495,8 @@
 
 llvm::ExceptionHandling
 toolchains::MinGW::GetExceptionModel(const ArgList &Args) const {
-  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64)
+  if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 ||
+  getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb)
 return llvm::ExceptionHandling::WinEH;
   return llvm::ExceptionHandling::DwarfCFI;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127145: [Driver] add -lresolv for all but Android.

2022-06-06 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

yes, however I have no idea if we need !TC.getTriple().isOSFreeBSD()
!TC.getTriple().isOSNetBSD() !TC.getTriple().isOSOpenBSD()) etc.
I guess if make mistake it will be noticed and fixed.

Please update clang/test/Driver/sanitizer-ld.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127145

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


[PATCH] D127145: [Driver] add -lresolv for all but Android.

2022-06-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.
Herald added a subscriber: StephenFan.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:843
+  if (!TC.getTriple().isAndroid()) {
+CmdArgs.push_back("-lresolv");
+  }

Omit brace for simple single-line body.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127145

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


[PATCH] D127150: [doc] Add release notes about SEH unwind information on ARM

2022-06-06 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: efriedma, MaskRay.
Herald added subscribers: StephenFan, kristof.beyls.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127150

Files:
  clang/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -102,6 +102,8 @@
   versions.
 * Added a pass to workaround Cortex-A57 Erratum 1742098 and Cortex-A72
   Erratum 1655431. This is enabled by default when targeting either CPU.
+* Implemented generation of Windows SEH unwind information.
+* Switched the MinGW target to use SEH instead of Dwarf for unwind information.
 
 Changes to the AVR Backend
 --
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -351,6 +351,11 @@
   JustMyCode feature. Note, you may need to manually add ``/JMC`` as additional
   compile options in the Visual Studio since it currently assumes clang-cl 
does not support ``/JMC``.
 
+- Implemented generation of SEH unwind information on ARM. (C++ exception
+  handling in MSVC mode is still unimplemented though.)
+
+- Switched MinGW mode on ARM to use SEH instead of Dwarf for unwind 
information.
+
 AIX Support
 ---
 


Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -102,6 +102,8 @@
   versions.
 * Added a pass to workaround Cortex-A57 Erratum 1742098 and Cortex-A72
   Erratum 1655431. This is enabled by default when targeting either CPU.
+* Implemented generation of Windows SEH unwind information.
+* Switched the MinGW target to use SEH instead of Dwarf for unwind information.
 
 Changes to the AVR Backend
 --
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -351,6 +351,11 @@
   JustMyCode feature. Note, you may need to manually add ``/JMC`` as additional
   compile options in the Visual Studio since it currently assumes clang-cl does not support ``/JMC``.
 
+- Implemented generation of SEH unwind information on ARM. (C++ exception
+  handling in MSVC mode is still unimplemented though.)
+
+- Switched MinGW mode on ARM to use SEH instead of Dwarf for unwind information.
+
 AIX Support
 ---
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127145: [Driver] add -lresolv for all but Android.

2022-06-06 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

The interceptor (dn_expand) is only defined on linux && !android, while this 
code links libresolv on *bsd and others, too. I think it's ok, as long as all 
platforms with the interceptor are covered.

It would be great to mention the actual reason we do this in the commit 
message: because otherwise link tests in ./configure scripts may be confused by 
the presence of the dn_expand symbol even without -lresolv (because of the 
interceptor) and get a runtime error later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127145

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


[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling

2022-06-06 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 updated this revision to Diff 434605.
sbc100 added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75277

Files:
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CodeGenModule.cpp


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -554,10 +554,8 @@
 CodeGenFunction(*this).EmitCfiCheckStub();
   }
   emitAtAvailableLinkGuard();
-  if (Context.getTargetInfo().getTriple().isWasm() &&
-  !Context.getTargetInfo().getTriple().isOSEmscripten()) {
+  if (Context.getTargetInfo().getTriple().isWasm())
 EmitMainVoidAlias();
-  }
 
   if (getTriple().isAMDGPU()) {
 // Emit reference of __amdgpu_device_library_preserve_asan_functions to
@@ -6352,8 +6350,10 @@
   // new-style no-argument main is in used.
   if (llvm::Function *F = getModule().getFunction("main")) {
 if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() &&
-F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth()))
-  addUsedGlobal(llvm::GlobalAlias::create("__main_void", F));
+
F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) {
+  auto *GA = llvm::GlobalAlias::create("__main_void", F);
+  GA->setVisibility(llvm::GlobalValue::HiddenVisibility);
+}
   }
 }
 
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -70,9 +70,7 @@
 
   // On wasm, the argc/argv form of "main" is renamed so that the startup code
   // can call it with the correct function signature.
-  // On Emscripten, users may be exporting "main" and expecting to call it
-  // themselves, so we can't mangle it.
-  if (Triple.isWasm() && !Triple.isOSEmscripten())
+  if (Triple.isWasm())
 if (const FunctionDecl *FD = dyn_cast(ND))
   if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2)
 return CCM_WasmMainArgcArgv;


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -554,10 +554,8 @@
 CodeGenFunction(*this).EmitCfiCheckStub();
   }
   emitAtAvailableLinkGuard();
-  if (Context.getTargetInfo().getTriple().isWasm() &&
-  !Context.getTargetInfo().getTriple().isOSEmscripten()) {
+  if (Context.getTargetInfo().getTriple().isWasm())
 EmitMainVoidAlias();
-  }
 
   if (getTriple().isAMDGPU()) {
 // Emit reference of __amdgpu_device_library_preserve_asan_functions to
@@ -6352,8 +6350,10 @@
   // new-style no-argument main is in used.
   if (llvm::Function *F = getModule().getFunction("main")) {
 if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() &&
-F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth()))
-  addUsedGlobal(llvm::GlobalAlias::create("__main_void", F));
+F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) {
+  auto *GA = llvm::GlobalAlias::create("__main_void", F);
+  GA->setVisibility(llvm::GlobalValue::HiddenVisibility);
+}
   }
 }
 
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -70,9 +70,7 @@
 
   // On wasm, the argc/argv form of "main" is renamed so that the startup code
   // can call it with the correct function signature.
-  // On Emscripten, users may be exporting "main" and expecting to call it
-  // themselves, so we can't mangle it.
-  if (Triple.isWasm() && !Triple.isOSEmscripten())
+  if (Triple.isWasm())
 if (const FunctionDecl *FD = dyn_cast(ND))
   if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2)
 return CCM_WasmMainArgcArgv;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127150: [doc] Add release notes about SEH unwind information on ARM

2022-06-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:357
+
+- Switched MinGW mode on ARM to use SEH instead of Dwarf for unwind 
information.
+

The official spelling is `DWARF`. The official way to name the version is 
`DWARF version 5`. If abbreviation is intended, `DWARF v5`.



Comment at: llvm/docs/ReleaseNotes.rst:106
+* Implemented generation of Windows SEH unwind information.
+* Switched the MinGW target to use SEH instead of Dwarf for unwind information.
 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127150

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


[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling

2022-06-06 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6360
+  auto *GA = llvm::GlobalAlias::create("__main_void", F);
+  GA->setVisibility(F->getVisibility());
+}

sbc100 wrote:
> sunfish wrote:
> > sbc100 wrote:
> > > sunfish wrote:
> > > > Can this use `GA->setVisibility(GlobalValue::HiddenVisibility)`? 
> > > > `__main_void` is an implementation detail, so in theory users shouldn't 
> > > > be setting interesting visibility attributes on it.
> > > The caller main / __main_void could live in different shared library the 
> > > main function itself.  
> > > 
> > > IIRC the caller of `main` is normally something like crt1.o and it should 
> > > be able to see `__main_void` if, and only if, it can see `main`.  i.e. if 
> > > should have the same visibility as main itself, no?
> > Typically crt1.o is linked into the same exe/dso as `main`, so it needs 
> > `main` to have external linkage, but it doesn't need `main` to have any 
> > particular visibility.
> > 
> > In Emscripten, is `main` being called from a different dso, or from JS 
> > following visibility rules for different dsos?
> No, emscirpten is not different that respect.   Typically main lives in the 
> same DSO as crt1.o.   
> 
> But it doesn't have to, and we have a few tests that check it can be in a 
> separate dso.
Actually I think verified that setting this to hidden works for emscripten (at 
least the tests pass).

@sunfish.. do you know if you were relying on this symbols being marked as 
"used"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75277

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


[clang] 47039a1 - [WebAssembly] Remove restriction on main name mangling

2022-06-06 Thread Sam Clegg via cfe-commits

Author: Sam Clegg
Date: 2022-06-06T14:04:27-07:00
New Revision: 47039a1a4b299c01dfa0ec531fbc0d24718bb8eb

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

LOG: [WebAssembly] Remove restriction on main name mangling

Summary: Emscripten now handles/supports this new mode.

Subscribers: dschuff, jgravelle-google, aheejin, sunfish, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/AST/Mangle.cpp
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index 984da9909ce23..c1a345390091b 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -70,9 +70,7 @@ static CCMangling getCallingConvMangling(const ASTContext 
&Context,
 
   // On wasm, the argc/argv form of "main" is renamed so that the startup code
   // can call it with the correct function signature.
-  // On Emscripten, users may be exporting "main" and expecting to call it
-  // themselves, so we can't mangle it.
-  if (Triple.isWasm() && !Triple.isOSEmscripten())
+  if (Triple.isWasm())
 if (const FunctionDecl *FD = dyn_cast(ND))
   if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2)
 return CCM_WasmMainArgcArgv;

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index afb28c1e5cc97..c3507fad0d79d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -554,10 +554,8 @@ void CodeGenModule::Release() {
 CodeGenFunction(*this).EmitCfiCheckStub();
   }
   emitAtAvailableLinkGuard();
-  if (Context.getTargetInfo().getTriple().isWasm() &&
-  !Context.getTargetInfo().getTriple().isOSEmscripten()) {
+  if (Context.getTargetInfo().getTriple().isWasm())
 EmitMainVoidAlias();
-  }
 
   if (getTriple().isAMDGPU()) {
 // Emit reference of __amdgpu_device_library_preserve_asan_functions to
@@ -6352,8 +6350,10 @@ void CodeGenModule::EmitMainVoidAlias() {
   // new-style no-argument main is in used.
   if (llvm::Function *F = getModule().getFunction("main")) {
 if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() &&
-F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth()))
-  addUsedGlobal(llvm::GlobalAlias::create("__main_void", F));
+
F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) {
+  auto *GA = llvm::GlobalAlias::create("__main_void", F);
+  GA->setVisibility(llvm::GlobalValue::HiddenVisibility);
+}
   }
 }
 



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


[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling

2022-06-06 Thread Sam Clegg 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 rG47039a1a4b29: [WebAssembly] Remove restriction on main name 
mangling (authored by sbc100).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75277

Files:
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CodeGenModule.cpp


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -554,10 +554,8 @@
 CodeGenFunction(*this).EmitCfiCheckStub();
   }
   emitAtAvailableLinkGuard();
-  if (Context.getTargetInfo().getTriple().isWasm() &&
-  !Context.getTargetInfo().getTriple().isOSEmscripten()) {
+  if (Context.getTargetInfo().getTriple().isWasm())
 EmitMainVoidAlias();
-  }
 
   if (getTriple().isAMDGPU()) {
 // Emit reference of __amdgpu_device_library_preserve_asan_functions to
@@ -6352,8 +6350,10 @@
   // new-style no-argument main is in used.
   if (llvm::Function *F = getModule().getFunction("main")) {
 if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() &&
-F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth()))
-  addUsedGlobal(llvm::GlobalAlias::create("__main_void", F));
+
F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) {
+  auto *GA = llvm::GlobalAlias::create("__main_void", F);
+  GA->setVisibility(llvm::GlobalValue::HiddenVisibility);
+}
   }
 }
 
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -70,9 +70,7 @@
 
   // On wasm, the argc/argv form of "main" is renamed so that the startup code
   // can call it with the correct function signature.
-  // On Emscripten, users may be exporting "main" and expecting to call it
-  // themselves, so we can't mangle it.
-  if (Triple.isWasm() && !Triple.isOSEmscripten())
+  if (Triple.isWasm())
 if (const FunctionDecl *FD = dyn_cast(ND))
   if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2)
 return CCM_WasmMainArgcArgv;


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -554,10 +554,8 @@
 CodeGenFunction(*this).EmitCfiCheckStub();
   }
   emitAtAvailableLinkGuard();
-  if (Context.getTargetInfo().getTriple().isWasm() &&
-  !Context.getTargetInfo().getTriple().isOSEmscripten()) {
+  if (Context.getTargetInfo().getTriple().isWasm())
 EmitMainVoidAlias();
-  }
 
   if (getTriple().isAMDGPU()) {
 // Emit reference of __amdgpu_device_library_preserve_asan_functions to
@@ -6352,8 +6350,10 @@
   // new-style no-argument main is in used.
   if (llvm::Function *F = getModule().getFunction("main")) {
 if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() &&
-F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth()))
-  addUsedGlobal(llvm::GlobalAlias::create("__main_void", F));
+F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) {
+  auto *GA = llvm::GlobalAlias::create("__main_void", F);
+  GA->setVisibility(llvm::GlobalValue::HiddenVisibility);
+}
   }
 }
 
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -70,9 +70,7 @@
 
   // On wasm, the argc/argv form of "main" is renamed so that the startup code
   // can call it with the correct function signature.
-  // On Emscripten, users may be exporting "main" and expecting to call it
-  // themselves, so we can't mangle it.
-  if (Triple.isWasm() && !Triple.isOSEmscripten())
+  if (Triple.isWasm())
 if (const FunctionDecl *FD = dyn_cast(ND))
   if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2)
 return CCM_WasmMainArgcArgv;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >