[PATCH] D149405: [Clang][Doc] Added an open project for improving command line docs

2023-04-27 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta created this revision.
xgupta added a reviewer: aaron.ballman.
Herald added a project: All.
xgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There seems to be a lot of documentation is missing
for different command line flags uses. 
This create confusion with same looking options, better to 
document clearly their uses.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149405

Files:
  clang/www/OpenProjects.html


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,10 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td;>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  improve existing and add missing documentation for
+  https://clang.llvm.org/docs/ClangCommandLineReference.html;>
+  clang command line flags, generated from https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td;>
+  clang/Driver/Options.td,
   help with completing other missing documentation.
 
 These projects are independent of each other.


Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -38,6 +38,10 @@
   documenting https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticDocs.td;>
   diagnostic group flags (adding code examples of what is diagnosed, or
   other relevant information), or
+  improve existing and add missing documentation for
+  https://clang.llvm.org/docs/ClangCommandLineReference.html;>
+  clang command line flags, generated from https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td;>
+  clang/Driver/Options.td,
   help with completing other missing documentation.
 
 These projects are independent of each other.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132819: [RISCV] Add MC support of RISCV zcmp Extension

2023-04-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:1048
+  static std::unique_ptr createRlist(unsigned RlistEncode,
+   SMLoc S, bool IsRV64) {
+auto Op = std::make_unique(KindTy::Rlist);

Drop IsRV64



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:1056
+  static std::unique_ptr createSpimm(unsigned Spimm, SMLoc S,
+   bool IsRV64) {
+auto Op = std::make_unique(KindTy::Spimm);

Drop IsRV64



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:1473
+ErrorLoc,
+"This stack adjustment is invalid for this instruction and register "
+"list, "

Drop the word "This" from the beginning. Drop the word "Please".

Something like

`stack adjustment is invalid for this instruction and register; refer to Zc 
spec for a detailed range of stack adjustment`



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2323
+  if (getLexer().isNot(AsmToken::LCurly)) {
+Error(getLoc(), "Rlist must start with '{'");
+return MatchOperand_ParseFail;

Rlist -> register list



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2323
+  if (getLexer().isNot(AsmToken::LCurly)) {
+Error(getLoc(), "Rlist must start with '{'");
+return MatchOperand_ParseFail;

craig.topper wrote:
> Rlist -> register list
General comment, error messages should not start with capitalized words.



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2352
+if (RegStart != RISCV::X8) {
+  Error(getLoc(), "Continuous registers list must start from 's0' or 
'x8'");
+  return MatchOperand_ParseFail;

registers -> register



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2369
+  Error(getLoc(),
+"Contiguous registers list of EABI only can be 's0-s1' or "
+"'x8-x9' pair");

This sentence is awkward.

Something like

"contiguous register list for EABI can only be 's0-1' or 'x8-x9'"



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2381
+Error(getLoc(),
+  "First contiguous registers pair of XRlist must be 'x8-x9'");
+return MatchOperand_ParseFail;

XRlist -> register list



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2395
+getLoc(),
+"Second contiguous registers pair of XRlist must start from 
'x18'");
+return MatchOperand_ParseFail;

XRList -> register list



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2425
+  if (getLexer().isNot(AsmToken::RCurly)) {
+Error(getLoc(), "Rlist must end with '}'");
+return MatchOperand_ParseFail;

Rlist -> register list



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2435
+  if (Encode == 16) {
+Error(S, "invalid Register list");
+return MatchOperand_ParseFail;

Don't capitalize Register


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132819

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2023-04-27 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev marked an inline comment as done.
v.g.vassilev added a comment.

In D127284#4303390 , @tahonermann 
wrote:

> This change appears to have negatively impacted some users that were 
> dependent on the previous `Preprocessing::enableIncrementalProcessing(true)` 
> behavior. See https://github.com/llvm/llvm-project/issues/62413.

Thank you for the ping. I’ve replied there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127284

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


[PATCH] D149389: [clang] Fix default initializers being ignored when initializing templated aggregate types

2023-04-27 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

Please also add a release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149389

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


[PATCH] D148274: [clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization

2023-04-27 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I need to look at this more carefully but can we add a release note in the 
meantime


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148274

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


[PATCH] D146269: MIPS: allow o32 abi with 64bit CPU and 64 abi with 32bit triple

2023-04-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/mips-cpu64abi32.c:1
+// Check handling the CPU is 64bit while ABI is O32.
+// when build for MIPS platforms.

Use `///` for non-CHECK non-RUN comments.



Comment at: clang/test/Driver/mips-cpu64abi32.c:5
+// abi-n32
+// RUN: %clang -c %s -target mips-linux-gnu -mabi=n32 -o - \
+// RUN:   | llvm-readelf -h - \

`-target ` is legacy. Use `--target=`.

Driver tests should not test code generation. Just check that `%clang ...` 
passes the right options to cc1.



Comment at: clang/test/Driver/mips-cpu64abi32.c:9
+// CHECK-ABI-N32: abi2
+//
+// abi-64

Don't add `^//$` lines. Just use a blank line.


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

https://reviews.llvm.org/D146269

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


[PATCH] D149401: [Clang][RISCV] Set native half type to legal when has zfh extension

2023-04-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Is this the same as https://reviews.llvm.org/D145071


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149401

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


[PATCH] D125272: [clang] Add -fcheck-new support

2023-04-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGenCXX/fcheck-new.cpp:7
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call noalias noundef ptr @_Znwm(i64 noundef 
4) #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret ptr [[CALL]]

` #[[ATTR2:[0-9]+]]` If ATTR2 is not checked, remove ` #[[ATTR2:[0-9]+]]`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125272

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


[PATCH] D125272: [clang] Add -fcheck-new support

2023-04-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGenCXX/fcheck-new.cpp:2
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -fcheck-new -triple x86_64-linux-gnu -S -disable-O0-optnone 
\
+// RUN: -emit-llvm -o - %s | opt -S -passes=mem2reg | FileCheck %s

heatd wrote:
> MaskRay wrote:
> > In this test, if I remove `-fcheck-new` , nothing will change. So this 
> > isn't a good test.
> > 
> > I think we need something like:
> > ```
> > struct A { A(); };
> > void *test0() { return A; }
> > ```
> It will change (the attributes of _Znwm).
> 
> From the test (with -fcheck-new):
> ```
> [[CALL:%.*]] = call noalias noundef ptr @_Znwm(i64 noundef 4) 
> #[[ATTR2:[0-9]+]]
> ```
> The same test (but without -fcheck-new, tested locally):
> 
> ```
>   %1 = tail call noalias noundef nonnull dereferenceable(4) ptr @_Znwm(i64 
> noundef 4) #2
> ```
> 
> As you'll see, the non-fcheck-new has nonnull attached to _Znwm, while 
> -fcheck-new doesn't. This is exactly the behavior we want to test for.
OK, you are right about `nonull`. I think my point still holds as with a 
constructor the effect will be more visible with a `new.notnull:` basic block.
You may want to add another function to do `A *test1() { return new A; }`

Also, with the simple IR, `opt -S -mem2reg ` is a no-op. You should remove it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125272

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


[PATCH] D149389: [clang] Fix default initializers being ignored when initializing templated aggregate types

2023-04-27 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

So the change makes sense but the original issue: 
https://github.com/llvm/llvm-project/issues/62266 it worked for the first once 
but not the second, it also worked for the non-paren aggregate init. So I feel 
like the explanation is missing some details.

It seems like the codegen test should be mimicing the test from the bug report 
more closely w/ two paren inits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149389

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


[PATCH] D149401: [Clang][RISCV] Set native half type to legal when has zfh extension

2023-04-27 Thread Yunze Zhu(Thead) via Phabricator via cfe-commits
Yunzezhu created this revision.
Yunzezhu added reviewers: asb, kito-cheng, craig.topper.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, 
arichardson.
Herald added a project: All.
Yunzezhu requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

Issue: When processing a f16 type value, a f16 value is extended to f32 after 
load and processed in f32 form, and truncated back to f16 before store, even 
when the target has zfh extension, which indicates the target has native half 
type float support, and such kind of extend/truncate actions are not necessary.

Some changes:
1.Set native half type to legal when has zfh extension, which prevent 
unnecessary promotion from f16 to f32, and unpromotion back to f16.
2.Add related test case to test generation of half type float.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149401

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/test/CodeGen/RISCV/_Float16-add.c


Index: clang/test/CodeGen/RISCV/_Float16-add.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/_Float16-add.c
@@ -0,0 +1,19 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zfh -emit-llvm %s -o - \
+// RUN:   | FileCheck %s
+
+_Float16 x;
+_Float16 y;
+_Float16 z;
+// CHECK-LABEL: @func(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load half, ptr @y, align 2
+// CHECK-NEXT:[[TMP1:%.*]] = load half, ptr @z, align 2
+// CHECK-NEXT:[[ADD:%.*]] = fadd half [[TMP0]], [[TMP1]]
+// CHECK-NEXT:store half [[ADD]], ptr @x, align 2
+// CHECK-NEXT:ret void
+//
+void func()
+{
+  x = y + z;
+}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -349,6 +349,11 @@
 ISAInfo = std::move(*ParseResult);
   }
 
+  // Turn on native half type support by set half type to legal.
+  if (ISAInfo->hasExtension("zfh")){
+HasLegalHalfType = true;
+  }
+
   if (ABI.empty())
 ABI = ISAInfo->computeDefaultABI().str();
 


Index: clang/test/CodeGen/RISCV/_Float16-add.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/_Float16-add.c
@@ -0,0 +1,19 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zfh -emit-llvm %s -o - \
+// RUN:   | FileCheck %s
+
+_Float16 x;
+_Float16 y;
+_Float16 z;
+// CHECK-LABEL: @func(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load half, ptr @y, align 2
+// CHECK-NEXT:[[TMP1:%.*]] = load half, ptr @z, align 2
+// CHECK-NEXT:[[ADD:%.*]] = fadd half [[TMP0]], [[TMP1]]
+// CHECK-NEXT:store half [[ADD]], ptr @x, align 2
+// CHECK-NEXT:ret void
+//
+void func()
+{
+  x = y + z;
+}
Index: clang/lib/Basic/Targets/RISCV.cpp
===
--- clang/lib/Basic/Targets/RISCV.cpp
+++ clang/lib/Basic/Targets/RISCV.cpp
@@ -349,6 +349,11 @@
 ISAInfo = std::move(*ParseResult);
   }
 
+  // Turn on native half type support by set half type to legal.
+  if (ISAInfo->hasExtension("zfh")){
+HasLegalHalfType = true;
+  }
+
   if (ABI.empty())
 ABI = ISAInfo->computeDefaultABI().str();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 876df74 - [flang][driver] Allow main program to be in an archive

2023-04-27 Thread Shao-Ce SUN via cfe-commits

Author: Shao-Ce SUN
Date: 2023-04-28T09:53:25+08:00
New Revision: 876df74dd47196a9ca3b4fff21ffb5441491a0a0

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

LOG: [flang][driver] Allow main program to be in an archive

Add --undefined=_QQmain to the link line, so that a Fortran main program
will be included in the link job even if it is in an archive (unless we
are building a shared object). For now, this is only applied to the Gnu
toolchain.

We also add a section on the linker invocation to docs/FlangDriver.md.

The new tests require llvm-ar to construct an archive we can include in
the link job. This is a new dependency for flang/test (which already
depends on similar tools such as llvm-objdump).

See discussions in
https://github.com/llvm/llvm-project/issues/54787
which this patch fixes.

Reviewed By: awarzynski

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

Added: 
flang/test/Driver/link-c-main.c
flang/test/Driver/link-f90-main.f90

Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
flang/docs/FlangDriver.md
flang/test/CMakeLists.txt
flang/test/Driver/linker-flags.f90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b0716322bc141..c4a276126b653 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -598,6 +598,14 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
   // these dependencies need to be listed before the C runtime below (i.e.
   // AddRuntTimeLibs).
   if (D.IsFlangMode()) {
+// A Fortran main program will be lowered to a function named _QQmain. Make
+// _QQmain an undefined symbol, so that it's correctly resolved even when
+// creating executable from archives. This is a workaround for how and 
where
+// Flang's `main` is defined. For more context, see:
+//   *  https://github.com/llvm/llvm-project/issues/54787
+if (!Args.hasArg(options::OPT_shared))
+  CmdArgs.push_back("--undefined=_QQmain");
+
 addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
 addFortranRuntimeLibs(ToolChain, CmdArgs);
 CmdArgs.push_back("-lm");

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index 6c2a473820634..9522e223b17b5 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -149,13 +149,6 @@ flang-new -ccc-print-phases -c file.f
 +- 3: backend, {2}, assembler
 4: assembler, {3}, object
 ```
-Note that currently Flang does not support code-generation and `flang-new` will
-fail during the second step above with the following error:
-```bash
-error: code-generation is not available yet
-```
-The other phases are printed nonetheless when using `-ccc-print-phases`, as
-that reflects what `clangDriver`, the library, will try to create and run.
 
 For actions specific to the frontend (e.g. preprocessing or code generation), a
 command to call the frontend driver is generated (more specifically, an
@@ -205,6 +198,41 @@ is `ParseSyntaxOnlyAction`, which corresponds to 
`-fsyntax-only`. In other
 words, `flang-new -fc1 ` is equivalent to `flang-new -fc1 
-fsyntax-only
 `.
 
+## Linker invocation
+> **_NOTE:_**  Linker invocation through the `flang-new` driver is so far
+> experimental. This section describes the currently intended design, and not
+> necessarily what is implemented.
+
+Calling
+```bash
+flang-new -flang-experimental-exec prog.f90
+```
+will, on a high level, do two things:
+* call the frontend driver, `flang-new -fc1`, to build the object file `prog.o`
+* call the system linker to build the executable `a.out`.
+
+In both invocations, `flang-new` will add default options to the frontend 
driver
+and the linker invocations. To see the exact invocations on your system, you 
can
+call
+```bash
+flang-new -### prog.f90
+```
+The link line will contain a fair number of options, which will depend on your
+system. Compared to when linking a C program with `clang`, the main additions
+are (on GNU/linux),
+* `--undefined=_QQmain`: A Fortran main program will appear in the 
corresponding
+  object file as a function called `_QQmain`. This flag makes sure that an
+  object file containing a Fortran main program (i.e., a symbol `_QQmain`) be
+  included in the linking also when it is bundled in an archive.
+* `-lFortran_main`: The Fortran_main archive is part of Flang's runtime. It
+  exports the symbol `main`, i.e., a c main function, which will make some
+  initial configuration before calling `_QQmain`, and clean up before 
returning.
+* `-lFortranRuntime`: Flang's Fortran runtime, containing, for example,
+  implementations of intrinsic functions.
+* `-lFortranDecimal`: Part of Flang's runtime, containing routines for parsing
+  and formatting decimal 

[PATCH] D134821: [flang][driver] Allow main program to be in an archive

2023-04-27 Thread Shao-Ce SUN 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 rG876df74dd471: [flang][driver] Allow main program to be in an 
archive (authored by sunshaoce).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134821

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  flang/docs/FlangDriver.md
  flang/test/CMakeLists.txt
  flang/test/Driver/link-c-main.c
  flang/test/Driver/link-f90-main.f90
  flang/test/Driver/linker-flags.f90

Index: flang/test/Driver/linker-flags.f90
===
--- flang/test/Driver/linker-flags.f90
+++ flang/test/Driver/linker-flags.f90
@@ -12,6 +12,14 @@
 !   Make sure they're not added.
 ! RUN: %flang -### -flang-experimental-exec -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames
 
+! Check linker invocation to generate shared object (only GNU toolchain for now)
+! Output should not contain any undefined reference to _QQmain since it is not
+! considered a valid entry point for shared objects, which are usually specified
+! using the bind attribute.
+! RUN: %flang -### -flang-experimental-exec -shared -target x86_64-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU-SHARED --implicit-check-not _QQmain
+! RUN: %flang -### -flang-experimental-exec -shared -target aarch64-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU-SHARED --implicit-check-not _QQmain
+! RUN: %flang -### -flang-experimental-exec -shared -target riscv64-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,GNU-SHARED --implicit-check-not _QQmain
+
 ! Compiler invocation to generate the object file
 ! CHECK-LABEL: {{.*}} "-emit-obj"
 ! CHECK-SAME:  "-o" "[[object_file:.*\.o]]" {{.*}}Inputs/hello.f90
@@ -23,6 +31,7 @@
 !   executable and may find the GNU linker from MinGW or Cygwin.
 ! GNU-LABEL:  "{{.*}}ld{{(\.exe)?}}"
 ! GNU-SAME: "[[object_file]]"
+! GNU-SAME: --undefined=_QQmain
 ! GNU-SAME: -lFortran_main
 ! GNU-SAME: -lFortranRuntime
 ! GNU-SAME: -lFortranDecimal
@@ -50,3 +59,9 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Linker invocation to generate a shared object
+! GNU-SHARED-LABEL:  "{{.*}}ld"
+! GNU-SHARED-SAME: "[[object_file]]"
+! GNU-SHARED-SAME: -lFortranRuntime
+! GNU-SHARED-SAME: -lFortranDecimal
Index: flang/test/Driver/link-f90-main.f90
===
--- /dev/null
+++ flang/test/Driver/link-f90-main.f90
@@ -0,0 +1,23 @@
+! Test that a fortran main program can be linked to an executable
+! by flang.
+!
+! For now, this test only covers the Gnu toolchain on linux.
+
+!REQUIRES: x86-registered-target || aarch64-registered-target || riscv64-registered-target
+!REQUIRES: system-linux
+
+! RUN: %flang_fc1 -emit-obj %s -o %t.o
+! RUN: %flang -target x86_64-unknown-linux-gnu %t.o -o %t.out -flang-experimental-exec
+! RUN: llvm-objdump --syms %t.out | FileCheck %s
+
+! Test that it also works if the program is bundled in an archive.
+
+! RUN: llvm-ar -r %t.a %t.o
+! RUN: %flang -target x86_64-unknown-linux-gnu %t.a -o %ta.out -flang-experimental-exec
+! RUN: llvm-objdump --syms %ta.out | FileCheck %s
+
+end program
+
+! CHECK-DAG: F .text {{[a-f0-9]+}} main
+! CHECK-DAG: F .text {{[a-f0-9]+}} _QQmain
+! CHECK-DAG: _FortranAProgramStart
Index: flang/test/Driver/link-c-main.c
===
--- /dev/null
+++ flang/test/Driver/link-c-main.c
@@ -0,0 +1,28 @@
+/*
+Test that an object file with a C main function can be linked to an executable
+by Flang.
+
+For now, this test only covers the Gnu toolchain on Linux.
+
+REQUIRES: x86-registered-target || aarch64-registered-target || riscv64-registered-target
+REQUIRES: system-linux, c-compiler
+
+RUN: %cc -c %s -o %t.o
+RUN: %flang -target x86_64-unknown-linux-gnu %t.o -o %t.out -flang-experimental-exec
+RUN: llvm-objdump --syms %t.out | FileCheck %s --implicit-check-not Fortran
+
+Test that it also works if the c-main is bundled in an archive.
+
+RUN: llvm-ar -r %t.a %t.o
+RUN: %flang -target x86_64-unknown-linux-gnu %t.a -o %ta.out -flang-experimental-exec
+RUN: llvm-objdump --syms %ta.out | FileCheck %s --implicit-check-not Fortran
+*/
+
+int main(void) {
+return 0;
+}
+
+/*
+CHECK-DAG: F .text {{[a-f0-9]+}} main
+CHECK-DAG: *UND* {{[a-f0-9]+}} _QQmain
+*/
Index: flang/test/CMakeLists.txt
===
--- flang/test/CMakeLists.txt
+++ flang/test/CMakeLists.txt
@@ -57,6 +57,7 @@
   fir-opt
   tco
   bbc
+  llvm-ar
   llvm-dis
   llvm-objdump
   llvm-readobj
Index: flang/docs/FlangDriver.md

[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[clang] ce861ec - [Clang][Sema] Add a temporary workaround in SemaConcept.cpp

2023-04-27 Thread Alexander Shaposhnikov via cfe-commits

Author: Alexander Shaposhnikov
Date: 2023-04-27T23:34:03Z
New Revision: ce861ec782ae3f41807b61e855512aaccf3c2149

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

LOG: [Clang][Sema] Add a temporary workaround in SemaConcept.cpp

This commit adds FIXME and a temporary workaround to repair
CUDA build bots after e3b1083e00e62f.

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f208cdbd1d87..a9335d6689ec 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -260,6 +260,11 @@ calculateConstraintSatisfaction(Sema , const Expr 
*ConstraintExpr,
 return SubstitutedAtomicExpr;
   }
 
+  // FIXME: Remove this workaround.
+  // It's necessary to investigate how we get here.
+  if (SubstitutedAtomicExpr.get()->isValueDependent())
+return SubstitutedAtomicExpr;
+
   EnterExpressionEvaluationContext ConstantEvaluated(
   S, Sema::ExpressionEvaluationContext::ConstantEvaluated);
   SmallVector EvaluationDiags;



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


[PATCH] D149389: [clang] Fix default initializers being ignored when initializing templated aggregate types

2023-04-27 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao created this revision.
Herald added a project: All.
ayzhao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It turns out that FieldDecl::getInClassInitializer() will return nullptr
for default member initializers if the field is part of a templated
class. The correct thing to do is to call hasInClassInitializer(), which
is what we do for braced init lists[0].

Fixes 62266

[0]: 
https://github.com/llvm/llvm-project/blob/be5f35e24f4c15caf3c4aeccddc54c52560c28a0/clang/lib/Sema/SemaInit.cpp#L685


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149389

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -90,6 +90,15 @@
   };
 }
 
+namespace gh62266 {
+  // CHECK-DAG: [[STRUCT_H:%.*H.*]] = type { i32, i32 }
+  template 
+  struct H {
+int i;
+int j = J;
+  };
+}
+
 // CHECK-DAG: [[A1:@.*a1.*]] = internal constant [[STRUCT_A]] { i8 3, double 
2.00e+00 }, align 8
 constexpr A a1(3.1, 2.0);
 // CHECK-DAG: [[A2:@.*a2.*]] = internal constant [[STRUCT_A]] { i8 99, double 
0.00e+00 }, align 8
@@ -421,3 +430,17 @@
 make2<0>();
   }
 }
+
+namespace gh62266 {
+  // CHECK: define {{.*}} void {{.*foo20.*}}
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: [[H:%.*h.*]] = alloca [[STRUCT_H]], align 4
+  // CHECK-NEXT: [[I:%.*i.*]] = getelementptr inbounds [[STRUCT_H]], ptr 
[[H]], i32 0, i32 0
+  // CHECK-NEXT: store i32 1, ptr [[I]], align 4
+  // CHECK-NEXT: [[J:%.*j.*]] = getelementptr inbounds [[STRUCT_H]], ptr 
[[H]], i32 0, i32 1
+  // CHECK-NEXT: store i32 2, ptr [[J]], align 4
+  // CHECK-NEXT: ret void
+  void foo20() {
+H<2> h(1);
+  }
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5377,14 +5377,16 @@
   //   The remaining elements are initialized with their default member
   //   initializers, if any
   auto *FD = cast(SubEntity.getDecl());
-  if (Expr *ICE = FD->getInClassInitializer(); ICE && !VerifyOnly) {
-ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
-if (DIE.isInvalid())
-  return false;
-S.checkInitializerLifetime(SubEntity, DIE.get());
-InitExprs.push_back(DIE.get());
+  if (FD->hasInClassInitializer()) {
+if (!VerifyOnly) {
+  ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), 
FD);
+  if (DIE.isInvalid())
+return false;
+  S.checkInitializerLifetime(SubEntity, DIE.get());
+  InitExprs.push_back(DIE.get());
+}
 continue;
-  };
+  }
 }
 // Remaining class elements without default member initializers and
 // array elements are value initialized:


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -90,6 +90,15 @@
   };
 }
 
+namespace gh62266 {
+  // CHECK-DAG: [[STRUCT_H:%.*H.*]] = type { i32, i32 }
+  template 
+  struct H {
+int i;
+int j = J;
+  };
+}
+
 // CHECK-DAG: [[A1:@.*a1.*]] = internal constant [[STRUCT_A]] { i8 3, double 2.00e+00 }, align 8
 constexpr A a1(3.1, 2.0);
 // CHECK-DAG: [[A2:@.*a2.*]] = internal constant [[STRUCT_A]] { i8 99, double 0.00e+00 }, align 8
@@ -421,3 +430,17 @@
 make2<0>();
   }
 }
+
+namespace gh62266 {
+  // CHECK: define {{.*}} void {{.*foo20.*}}
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: [[H:%.*h.*]] = alloca [[STRUCT_H]], align 4
+  // CHECK-NEXT: [[I:%.*i.*]] = getelementptr inbounds [[STRUCT_H]], ptr [[H]], i32 0, i32 0
+  // CHECK-NEXT: store i32 1, ptr [[I]], align 4
+  // CHECK-NEXT: [[J:%.*j.*]] = getelementptr inbounds [[STRUCT_H]], ptr [[H]], i32 0, i32 1
+  // CHECK-NEXT: store i32 2, ptr [[J]], align 4
+  // CHECK-NEXT: ret void
+  void foo20() {
+H<2> h(1);
+  }
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5377,14 +5377,16 @@
   //   The remaining elements are initialized with their default member
   //   initializers, if any
   auto *FD = cast(SubEntity.getDecl());
-  if (Expr *ICE = FD->getInClassInitializer(); ICE && !VerifyOnly) {
-ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
-if (DIE.isInvalid())
-  return false;
-S.checkInitializerLifetime(SubEntity, DIE.get());
-InitExprs.push_back(DIE.get());

[PATCH] D149364: [CUDA] Temporarily undefine __noinline__ when including bits/shared_ptr_base.h

2023-04-27 Thread Justin Lebar via Phabricator via cfe-commits
jlebar accepted this revision.
jlebar added a comment.
This revision is now accepted and ready to land.

wow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149364

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


[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-04-27 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 517734.
void added a comment.

Use the new memory location.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -61,6 +61,7 @@
 // CHECK-NEXT: DiagnoseAsBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: DisableSanitizerInstrumentation (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: DisableTailCalls (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: ElementCount (SubjectMatchRule_field)
 // CHECK-NEXT: EnableIf (SubjectMatchRule_function)
 // CHECK-NEXT: EnforceTCB (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: EnforceTCBLeaf (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8238,6 +8238,29 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleElementCountAttr(Sema , Decl *D, const ParsedAttr ) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  SmallVector Names;
+  SmallVector Ranges;
+  for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
+if (!AL.isArgIdent(ArgNo)) {
+  S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return;
+}
+
+IdentifierLoc *IL = AL.getArgAsIdent(ArgNo);
+Names.push_back(IL->Ident);
+Ranges.push_back(IL->Loc);
+  }
+
+  ElementCountAttr *ECA = ::new (S.Context) ElementCountAttr(S.Context, AL,
+ Names.data(),
+ Names.size());
+  ECA->addCountFieldSourceRange(Ranges);
+  D->addAttr(ECA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema , Decl *D,
const ParsedAttr ) {
   StringRef KindStr;
@@ -9142,6 +9165,9 @@
   case ParsedAttr::AT_FunctionReturnThunks:
 handleFunctionReturnThunksAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ElementCount:
+handleElementCountAttr(S, D, AL);
+break;
 
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17686,6 +17686,43 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))
+  if (const FieldDecl *FD = FindFieldWithElementCountAttr(SubRD))
+return FD;
+  }
+
+  return nullptr;
+}
+
+static bool CheckElementCountAttr(const RecordDecl *RD, const FieldDecl *FD,
+  SourceRange ) {
+  const ElementCountAttr *ECA = FD->getAttr();
+  unsigned Idx = 0;
+
+  for (const IdentifierInfo *II : ECA->elementCountFields()) {
+Loc = ECA->getCountFieldSourceRange(Idx++);
+
+auto DeclIter = llvm::find_if(
+RD->fields(), [&](const FieldDecl *FD){
+  return II->getName() == FD->getName();
+});
+
+if (DeclIter == RD->field_end())
+  return false;
+
+if (auto *SubRD = DeclIter->getType()->getAsRecordDecl())
+  RD = SubRD;
+  }
+
+  return true;
+}
+
 void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
 SourceRange BraceRange) {
   AdjustDeclIfTemplate(TagD);
@@ -17743,6 +17780,17 @@
  [](const FieldDecl *FD) { return FD->isBitField(); }))
   Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
   }
+
+  // Check the "element_count" attribute to ensure that the count field exists
+  // in the struct.
+  if (const RecordDecl *RD = dyn_cast(Tag)) {
+if (const FieldDecl *FD = FindFieldWithElementCountAttr(RD)) {
+  SourceRange SR;
+  if (!CheckElementCountAttr(RD, FD, SR))
+Diag(SR.getBegin(), diag::warn_element_count_placeholder)
+<< FD->getName() << SR;
+}
+  }
 }
 
 void 

[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2023-04-27 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

(I apologize it took me so long to get back to reviewing this.)


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

https://reviews.llvm.org/D137107

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2023-04-27 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.
Herald added subscribers: bd1976llvm, jplehr.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:520
+  getOpenMPRuntime().emitDeclareTargetVarDefinition(D, Addr, PerformInit))
+return;
+

efriedma wrote:
> I don't really like the copy-pasted bits here.
It would be nice it we could to unify EmitCXXCtorInit with 
EmitCXXGlobalVarDeclInitFunc a bit more.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5006
+if (NeedsGlobalCtor || NeedsGlobalDtor)
+  DelayedCXXInitPosition[D] = ~0U;
+  } else {

zahiraam wrote:
> efriedma wrote:
> > zahiraam wrote:
> > > efriedma wrote:
> > > > zahiraam wrote:
> > > > > efriedma wrote:
> > > > > > zahiraam wrote:
> > > > > > > efriedma wrote:
> > > > > > > > zahiraam wrote:
> > > > > > > > > Do you agree this should be done only when one of those flags 
> > > > > > > > > is on?
> > > > > > > > Yes, that's fine; I wasn't really paying close attention to the 
> > > > > > > > exact code.  Just wanted to make the point about the structure 
> > > > > > > > of the if statements, and code was the easiest way to explain 
> > > > > > > > it.
> > > > > > > > 
> > > > > > > > Maybe the outer if statement should actually be `if 
> > > > > > > > (isStaticInit(D, getLangOpts()) && NeedsGlobalCtor) {`.
> > > > > > > > 
> > > > > > > > On a related note, we might want to avoid the name "ctor", in 
> > > > > > > > case that accidentally conflicts with some user code; an 
> > > > > > > > "__"-prefixed name would be appropriate.
> > > > > > > >> Maybe the outer if statement should actually be if 
> > > > > > > >> (isStaticInit(D, getLangOpts()) && NeedsGlobalCtor) {
> > > > > > > Not sure about that! There are cases where (isStaticInit(D, 
> > > > > > > getLangOpts())) = true and NeedsGlobalCtor=false, but 
> > > > > > > NeedsGlobalDtor=true. In which case a __dtor needs to be emitted, 
> > > > > > > no?
> > > > > > > 
> > > > > > > Writing the condition as you are proposing would actually not get 
> > > > > > > me into the body to emit the __dtor. Is that what we want?
> > > > > > EmitCXXGlobalVarDeclInitFunc should be able to handle that case.
> > > > > > 
> > > > > > Looking again, I'm a little concerned that in the isStaticInit() 
> > > > > > case, we're skipping a bunch of the logic in 
> > > > > > EmitCXXGlobalVarDeclInitFunc. EmitCXXCtorInit handles the basic 
> > > > > > cases correctly, but there are a lot of special cases in 
> > > > > > EmitCXXGlobalVarDeclInitFunc.
> > > > > I have left the condition as it was to make sure no cases are left. 
> > > > > What other cases are you thinking of? 
> > > > > 
> > > > EmitCXXGlobalVarDeclInitFunc has special cases for CUDA, OpenMP, 
> > > > thread-local variables, the InitSeg attribute, and inline variables.
> > > Let me know if this works? I have added one additional LIT test. I 
> > > referred to 
> > > https://learn.microsoft.com/en-us/cpp/cpp/storage-classes-cpp?view=msvc-170#thread_local
> > >  for thread_local. 
> > > For the inline variables, I couldn't find much information about 
> > > initialization of inline variables. I tried to find a case that wouldn't 
> > > pass by the new code and wouldn't pass by EmitCXXGlobalVarDeclInitFunc, 
> > > but no success.
> > Inline variable example:
> > 
> > ```
> > __declspec(dllimport) extern int x;
> > inline int *y = 
> > int **z = 
> > ```
> > 
> > This should trigger your new codepath, I think?
> Yes. And the IR looks like this:
> 
>   @"?y@@3PEAHEA" = linkonce_odr dso_local global ptr null, comdat, align 8
>   @"?z@@3PEAPEAHEA" = dso_local global ptr @"?y@@3PEAHEA", align 8
>   @"?x@@3HA" = external dllimport global i32, align 4
>   @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, 
> ptr } { i32 201, ptr @__ctor, ptr null }]
> 
>   ; Function Attrs: noinline nounwind
>   define linkonce_odr dso_local void @__ctor() #0 comdat {
>   entry:
> store ptr @"?x@@3HA", ptr @"?y@@3PEAHEA", align 8
> ret void
>   }
> 
> I think this is correct. 
> Adding it to the LIT testing.
Without your patch, the IR looks significantly different; the constructor 
function is named ??__Ey@@YAXXZ, and there's a reference to the variable in 
llvm.global_ctors.  This is necessary to ensure we only construct the variable 
once.

In this particular case, I guess the harm of constructing the variable multiple 
times would be relatively minor, but it's still not a great idea.  And we 
definitely can't emit a linkonce_odr function and just name it "__ctor".



Comment at: clang/test/CodeGenCXX/constant-init.cpp:17
+
+// CHECK: define internal void @"??__Ft2@@YAXXZ"() #0 {
+// CHECK: entry:

zahiraam wrote:
> efriedma wrote:
> > This doesn't look like your new codepath is triggering?  If your code is 
> > working correctly, it should, I think?
> That's right. In all cases where 
> 
>   llvm::Constant *Initializer = 

[PATCH] D149364: [CUDA] Temporarily undefine __noinline__ when including bits/shared_ptr_base.h

2023-04-27 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Fun tidbit: https://github.com/NVIDIA/thrust/issues/1703#issuecomment-1526604000

> Indeed, I believe the nvcc frontend has special handling for that attribute 
> expansion. clang would need to emulate that "special" handling
>
> Right. The __attribute__((__attribute__((noinline void foo(); gets 
> magically transformed into __attribute((noinline)) void foo() by the time it 
> makes it to the final host compilation. 
>
> And the magic seems to work only for 
> __attribute__((__attribute__((noinline. Any other variants I tried error 
> out.
>
> So, it's been a known issue in the CUDA headers, deliberately worked around 
> in NVCC. And now the bug lives on and keeps giving...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149364

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


[PATCH] D149163: [NFC][CLANG] Fix coverity remarks about large copy by values

2023-04-27 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision.
tahonermann added a comment.
This revision is now accepted and ready to land.

These changes all look good to me. For the `DeclaratorChunk` case, I noted an 
additional removal of a comment that I think should be considered. Assuming I 
haven't misread the code, `DeclaratorChunk` does not look like a small value 
type (at least not any more).




Comment at: clang/lib/CodeGen/CGGPUBuiltin.cpp:128
 
-bool containsNonScalarVarargs(CodeGenFunction *CGF, CallArgList Args) {
+bool containsNonScalarVarargs(CodeGenFunction *CGF, const CallArgList ) {
   return llvm::any_of(llvm::drop_begin(Args), [&](const CallArg ) {

This looks like a good change; `CallArgList` derives from `SmallVector` and holds a few other `SmallVector` specializations as data members.



Comment at: clang/lib/CodeGen/CGNonTrivialStruct.cpp:326
 std::array 
Alignments,
-FunctionArgList Args,
+const FunctionArgList ,
 CodeGenFunction *CGF) {

This looks like a good change. `FunctionArgList` derives from 
`SmallVector`.



Comment at: clang/lib/CodeGen/CodeGenModule.h:1714
   /// the backend to LLVM.
-  void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts);
+  void EmitBackendOptionsMetadata(const CodeGenOptions );
 

This is definitely a good change; it seems likely that the omission of the `&` 
was not intentional.



Comment at: clang/lib/Sema/SemaType.cpp:4556
 
-static bool IsNoDerefableChunk(DeclaratorChunk Chunk) {
+static bool IsNoDerefableChunk(const DeclaratorChunk ) {
   return (Chunk.Kind == DeclaratorChunk::Pointer ||

The definition of `DeclaratorChunk` has this comment:
  /// This is intended to be a small value object.

However, it contains what looks likely to be a sizable anonymous union. See 
`clang/include/clang/Sema/DeclSpec.h` lines 1587-1595 and the definition of 
`FunctionTypeInfo` in that same file. I don't see other pass-by-value uses of 
this type. Perhaps the above comment should be removed.


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

https://reviews.llvm.org/D149163

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


[PATCH] D149361: [profiling] Improve error message for raw profile header mismatches

2023-04-27 Thread Jessica Paquette 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 rG17cfd2e025cb: [profiling] Improve error message for raw 
profile header mismatches (authored by paquette).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D149361?vs=517644=517723#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149361

Files:
  clang/lib/CodeGen/CodeGenPGO.cpp
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/InstrProfReader.cpp
  llvm/test/tools/llvm-profdata/mismatched-raw-profile-header.test
  llvm/tools/llvm-profdata/llvm-profdata.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp

Index: llvm/unittests/ProfileData/InstrProfTest.cpp
===
--- llvm/unittests/ProfileData/InstrProfTest.cpp
+++ llvm/unittests/ProfileData/InstrProfTest.cpp
@@ -869,7 +869,9 @@
   const uint64_t MaxEdgeCount = getInstrMaxCountValue();
 
   instrprof_error Result;
-  auto Err = [&](Error E) { Result = InstrProfError::take(std::move(E)); };
+  auto Err = [&](Error E) {
+Result = std::get<0>(InstrProfError::take(std::move(E)));
+  };
   Result = instrprof_error::success;
   Writer.addRecord({"foo", 0x1234, {1}}, Err);
   ASSERT_EQ(Result, instrprof_error::success);
Index: llvm/tools/llvm-profdata/llvm-profdata.cpp
===
--- llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -233,9 +233,10 @@
   auto ReaderOrErr = InstrProfReader::create(TestFilename, *FS);
   if (Error E = ReaderOrErr.takeError()) {
 // Skip the empty profiles by returning sliently.
-instrprof_error IPE = InstrProfError::take(std::move(E));
-if (IPE != instrprof_error::empty_raw_profile)
-  WC->Errors.emplace_back(make_error(IPE), TestFilename);
+auto [ErrorCode, Msg] = InstrProfError::take(std::move(E));
+if (ErrorCode != instrprof_error::empty_raw_profile)
+  WC->Errors.emplace_back(make_error(ErrorCode, Msg),
+  TestFilename);
 return;
   }
 
@@ -280,8 +281,9 @@
 }
 
 auto MemProfError = [&](Error E) {
-  instrprof_error IPE = InstrProfError::take(std::move(E));
-  WC->Errors.emplace_back(make_error(IPE), Filename);
+  auto [ErrorCode, Msg] = InstrProfError::take(std::move(E));
+  WC->Errors.emplace_back(make_error(ErrorCode, Msg),
+  Filename);
 };
 
 // Add the frame mappings into the writer context.
@@ -306,9 +308,10 @@
   auto ReaderOrErr = InstrProfReader::create(Input.Filename, *FS, Correlator);
   if (Error E = ReaderOrErr.takeError()) {
 // Skip the empty profiles by returning silently.
-instrprof_error IPE = InstrProfError::take(std::move(E));
-if (IPE != instrprof_error::empty_raw_profile)
-  WC->Errors.emplace_back(make_error(IPE), Filename);
+auto [ErrCode, Msg] = InstrProfError::take(std::move(E));
+if (ErrCode != instrprof_error::empty_raw_profile)
+  WC->Errors.emplace_back(make_error(ErrCode, Msg),
+  Filename);
 return;
   }
 
@@ -335,11 +338,11 @@
   }
   Reported = true;
   // Only show hint the first time an error occurs.
-  instrprof_error IPE = InstrProfError::take(std::move(E));
+  auto [ErrCode, Msg] = InstrProfError::take(std::move(E));
   std::unique_lock ErrGuard{WC->ErrLock};
-  bool firstTime = WC->WriterErrorCodes.insert(IPE).second;
-  handleMergeWriterError(make_error(IPE), Input.Filename,
- FuncName, firstTime);
+  bool firstTime = WC->WriterErrorCodes.insert(ErrCode).second;
+  handleMergeWriterError(make_error(ErrCode, Msg),
+ Input.Filename, FuncName, firstTime);
 });
   }
 
@@ -370,11 +373,11 @@
 exitWithError(std::move(E));
 
   Dst->Writer.mergeRecordsFromWriter(std::move(Src->Writer), [&](Error E) {
-instrprof_error IPE = InstrProfError::take(std::move(E));
+auto [ErrorCode, Msg] = InstrProfError::take(std::move(E));
 std::unique_lock ErrGuard{Dst->ErrLock};
-bool firstTime = Dst->WriterErrorCodes.insert(IPE).second;
+bool firstTime = Dst->WriterErrorCodes.insert(ErrorCode).second;
 if (firstTime)
-  warn(toString(make_error(IPE)));
+  warn(toString(make_error(ErrorCode, Msg)));
   });
 }
 
Index: llvm/test/tools/llvm-profdata/mismatched-raw-profile-header.test
===
--- /dev/null
+++ llvm/test/tools/llvm-profdata/mismatched-raw-profile-header.test
@@ -0,0 +1,19 @@
+// Magic
+RUN: printf '\377lprofr\201' > %t
+// Version
+RUN: printf 

[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

I certainly like the idea. I'll spend some time later looking at the 
implementation, but from a quick glance it looks good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


[clang] 17cfd2e - [profiling] Improve error message for raw profile header mismatches

2023-04-27 Thread Jessica Paquette via cfe-commits

Author: Jessica Paquette
Date: 2023-04-27T14:51:38-07:00
New Revision: 17cfd2e025cb3aa929ad219c6ed0974d6198bf5b

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

LOG: [profiling] Improve error message for raw profile header mismatches

When a user uses a mismatched clang + llvm-profdata, they didn't get a very
informative error message. It would just say "unsupported version".

As a result, users are often confused as to what they are supposed to do and
tend to assume that it's a bug in the profiling runtime.

This patch improves the error message by:

- Adding a new class of error (`raw_profile_version_mismatch`) to make it clear
  that, specifically, the *raw profile* version is unsupported because of a
  tool mismatch.

- Adding an error message that tells the user which raw profile version was
  encountered, which version was expected, and instructs them to align their
  tool versions.

To support this, this patch also updates `InstrProfError::take` to also
propagate the optional error message.

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

Added: 
llvm/test/tools/llvm-profdata/mismatched-raw-profile-header.test

Modified: 
clang/lib/CodeGen/CodeGenPGO.cpp
llvm/include/llvm/ProfileData/InstrProf.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/tools/llvm-profdata/llvm-profdata.cpp
llvm/unittests/ProfileData/InstrProfTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index 15a3d74666ca2..b80317529b72b 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1036,7 +1036,7 @@ void 
CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader,
   llvm::Expected RecordExpected =
   PGOReader->getInstrProfRecord(FuncName, FunctionHash);
   if (auto E = RecordExpected.takeError()) {
-auto IPE = llvm::InstrProfError::take(std::move(E));
+auto IPE = std::get<0>(llvm::InstrProfError::take(std::move(E)));
 if (IPE == llvm::instrprof_error::unknown_function)
   CGM.getPGOStats().addMissing(IsInMainFile);
 else if (IPE == llvm::instrprof_error::hash_mismatch)

diff  --git a/llvm/include/llvm/ProfileData/InstrProf.h 
b/llvm/include/llvm/ProfileData/InstrProf.h
index 2a9da23f4f02f..ef01070832dee 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -330,7 +330,8 @@ enum class instrprof_error {
   compress_failed,
   uncompress_failed,
   empty_raw_profile,
-  zlib_unavailable
+  zlib_unavailable,
+  raw_profile_version_mismatch
 };
 
 /// An ordered list of functions identified by their NameRef found in
@@ -362,15 +363,18 @@ class InstrProfError : public ErrorInfo {
   instrprof_error get() const { return Err; }
   const std::string () const { return Msg; }
 
-  /// Consume an Error and return the raw enum value contained within it. The
-  /// Error must either be a success value, or contain a single InstrProfError.
-  static instrprof_error take(Error E) {
+  /// Consume an Error and return the raw enum value contained within it, and
+  /// the optional error message. The Error must either be a success value, or
+  /// contain a single InstrProfError.
+  static std::pair take(Error E) {
 auto Err = instrprof_error::success;
-handleAllErrors(std::move(E), [](const InstrProfError ) {
+std::string Msg = "";
+handleAllErrors(std::move(E), [, ](const InstrProfError ) {
   assert(Err == instrprof_error::success && "Multiple errors encountered");
   Err = IPE.get();
+  Msg = IPE.getMessage();
 });
-return Err;
+return {Err, Msg};
   }
 
   static char ID;

diff  --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index d6aec276838e6..849ee80bfaa33 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -249,7 +249,7 @@ Error CoverageMapping::loadFunctionRecord(
   std::vector Counts;
   if (Error E = ProfileReader.getFunctionCounts(Record.FunctionName,
 Record.FunctionHash, Counts)) {
-instrprof_error IPE = InstrProfError::take(std::move(E));
+instrprof_error IPE = std::get<0>(InstrProfError::take(std::move(E)));
 if (IPE == instrprof_error::hash_mismatch) {
   FuncHashMismatches.emplace_back(std::string(Record.FunctionName),
   Record.FunctionHash);

diff  --git a/llvm/lib/ProfileData/InstrProf.cpp 
b/llvm/lib/ProfileData/InstrProf.cpp
index d8dbcf1ebbe9a..1dd1ce4b3e50a 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ 

[PATCH] D146386: [MS ABI] Fix mangling references to declarations.

2023-04-27 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1250
+  for (unsigned I = 1, IE = ID->getChainingSize(); I < IE; ++I)
+mangleSourceName("");
+

Weird indentation



Comment at: clang/lib/AST/MicrosoftMangle.cpp:1816
 
-  QualType T = Base.getType();
+  std::stack EntryTypeStack;
+  SmallVector, 2> EntryManglers;

Please just use SmallVector instead of std::stack.


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

https://reviews.llvm.org/D146386

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


[PATCH] D148975: -fdebug-prefix-map=: make the last win when multiple prefixes match

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D148975#4296895 , @MaskRay wrote:

> Thank you! I feel that specifying multiple `-fdebug-prefix-map=` is a very 
> uncommon situation, so a release note entry is likely overkill.
> I updated the HelpText, though.

The Yocto project and my WIP changes against FreeBSD both specify multiple 
`-fdebug-prefix-map=` options, but neither depend on the longest-match first 
semantics. They did at one point, but GCC behaved differently.

So, I suppose this LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148975

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-27 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe3b1083e00e6: [Clang][Sema] Fix comparison of constraint 
expressions (authored by alexander-shaposhnikov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Template.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/concepts-friends.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -816,3 +816,62 @@
 static_assert(Parent::TakesBinary::i == 0);
 }
 
+namespace TemplateInsideNonTemplateClass {
+template concept C = true;
+
+template auto L = [] U>() {};
+
+struct Q {
+  template U> friend constexpr auto decltype(L)::operator()() const;
+};
+} // namespace TemplateInsideNonTemplateClass
+
+namespace GH61959 {
+template 
+concept C = (sizeof(T0) >= 4);
+
+template
+struct Orig { };
+
+template
+struct Orig {
+  template requires C
+  void f() { }
+
+  template requires true
+  void f() { }
+};
+
+template  struct Mod {};
+
+template 
+struct Mod {
+  template  requires C
+  constexpr static int f() { return 1; }
+
+  template  requires C
+  constexpr static int f() { return 2; }
+};
+
+static_assert(Mod::f() == 1);
+static_assert(Mod::f() == 2);
+
+template
+struct Outer {
+  template
+  struct Inner {};
+
+  template
+  struct Inner {
+template
+void foo()  requires C && C && C{}
+template
+void foo()  requires true{}
+  };
+};
+
+void bar() {
+  Outer::Inner I;
+  I.foo();
+}
+}
Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -127,3 +127,220 @@
 static_assert(S::specialization("str") == SPECIALIZATION_REQUIRES);
 
 } // namespace multiple_template_parameter_lists
+
+static constexpr int CONSTRAINED_METHOD_1 = 1;
+static constexpr int CONSTRAINED_METHOD_2 = 2;
+
+namespace constrained_members {
+
+template 
+struct S {
+  template 
+  static constexpr int constrained_method();
+};
+
+template <>
+template 
+constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  template T4>
+  static constexpr int constrained_method();
+};
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained members
+
+namespace constrained_members_of_nested_types {
+
+template 
+struct S {
+  struct Inner0 {
+struct Inner1 {
+  template 
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template <>
+template 
+constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  struct Inner0 {
+struct Inner1 {
+  template T4>
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_members_of_nested_types
+
+namespace constrained_member_sfinae {
+
+template struct S {
+  template
+  static constexpr int constrained_method() requires 

[clang] e3b1083 - [Clang][Sema] Fix comparison of constraint expressions

2023-04-27 Thread Alexander Shaposhnikov via cfe-commits

Author: Alexander Shaposhnikov
Date: 2023-04-27T21:33:32Z
New Revision: e3b1083e00e62f5d157d15cb8c63a1c3dfdf12e2

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

LOG: [Clang][Sema] Fix comparison of constraint expressions

This diff switches the approach to comparison of constraint expressions
to the new one based on template args substitution.
It continues the effort to fix our handling of out-of-line definitions
of constrained templates.
This is a recommit of 60bee9ff5445.

Differential revision: https://reviews.llvm.org/D146178

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/Sema/Template.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaTemplate/concepts-friends.cpp
clang/test/SemaTemplate/concepts-out-of-line-def.cpp
clang/test/SemaTemplate/concepts.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 3677335fa176f..7cd505218f2b9 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -2309,9 +2309,15 @@ class ClassTemplateDecl : public 
RedeclarableTemplateDecl {
 return static_cast(RedeclarableTemplateDecl::getCommonPtr());
   }
 
+  void setCommonPtr(Common *C) {
+RedeclarableTemplateDecl::Common = C;
+  }
+
 public:
+
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
+  friend class TemplateDeclInstantiator;
 
   /// Load any lazily-loaded specializations from the external source.
   void LoadLazySpecializations() const;

diff  --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 48e8b78311e12..1de2cc6917b42 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -232,9 +232,21 @@ enum class TemplateSubstitutionKind : char {
 /// Replaces the current 'innermost' level with the provided argument list.
 /// This is useful for type deduction cases where we need to get the entire
 /// list from the AST, but then add the deduced innermost list.
-void replaceInnermostTemplateArguments(ArgList Args) {
-  assert(TemplateArgumentLists.size() > 0 && "Replacing in an empty 
list?");
-  TemplateArgumentLists[0].Args = Args;
+void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args) 
{
+  assert((!TemplateArgumentLists.empty() || NumRetainedOuterLevels) &&
+ "Replacing in an empty list?");
+
+  if (!TemplateArgumentLists.empty()) {
+assert((TemplateArgumentLists[0].AssociatedDeclAndFinal.getPointer() ||
+TemplateArgumentLists[0].AssociatedDeclAndFinal.getPointer() ==
+AssociatedDecl) &&
+   "Trying to change incorrect declaration?");
+TemplateArgumentLists[0].Args = Args;
+  } else {
+--NumRetainedOuterLevels;
+TemplateArgumentLists.push_back(
+{{AssociatedDecl, /*Final=*/false}, Args});
+  }
 }
 
 /// Add an outermost level that we are not substituting. We have no

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 328d66bf33afa..f208cdbd1d87d 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -721,7 +721,7 @@ CalculateTemplateDepthForConstraints(Sema , const 
NamedDecl *ND,
   ND, /*Final=*/false, /*Innermost=*/nullptr, /*RelativeToPrimary=*/true,
   /*Pattern=*/nullptr,
   /*ForConstraintInstantiation=*/true, SkipForSpecialization);
-  return MLTAL.getNumSubstitutedLevels();
+  return MLTAL.getNumLevels();
 }
 
 namespace {
@@ -752,27 +752,44 @@ namespace {
   };
 } // namespace
 
+static const Expr *SubstituteConstraintExpression(Sema , const NamedDecl *ND,
+  const Expr *ConstrExpr) {
+  MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
+  ND, /*Final=*/false, /*Innermost=*/nullptr,
+  /*RelativeToPrimary=*/true,
+  /*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true,
+  /*SkipForSpecialization*/ false);
+  if (MLTAL.getNumSubstitutedLevels() == 0)
+return ConstrExpr;
+
+  Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/false);
+  std::optional ThisScope;
+  if (auto *RD = dyn_cast(ND->getDeclContext()))
+ThisScope.emplace(S, const_cast(RD), Qualifiers());
+  ExprResult SubstConstr =
+  S.SubstConstraintExpr(const_cast(ConstrExpr), MLTAL);
+  if (SFINAE.hasErrorOccurred() || !SubstConstr.isUsable())
+return nullptr;
+  return SubstConstr.get();
+}
+
 bool 

[PATCH] D129951: adds `__disable_adl` attribute

2023-04-27 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

Gentle ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129951

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


[PATCH] D149098: [Clang] Add tests and mark as implemented WG14 N2728 (char16_t & char32_t string literals shall be UTF-16 & UTF-32)

2023-04-27 Thread Tom Honermann via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tahonermann marked 2 inline comments as done.
Closed by commit rGa68039c51e61: [Clang] Add tests and mark as implemented 
WG14-N2728 (authored by tahonermann).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149098

Files:
  clang/test/Lexer/char-literal.cpp
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -929,7 +929,7 @@
 
   char16_t & char32_t string literals shall be UTF-16 & UTF-32
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2728.htm;>N2728
-  Unknown
+  Yes
 
 
   IEC 60559 binding
Index: clang/test/Lexer/char-literal.cpp
===
--- clang/test/Lexer/char-literal.cpp
+++ clang/test/Lexer/char-literal.cpp
@@ -1,5 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -Wfour-char-constants -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -Wfour-char-constants -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -Wfour-char-constants -fsyntax-only -verify=cxx,expected %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++17 -Wfour-char-constants -fsyntax-only -verify=cxx,expected %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++20 -Wfour-char-constants -fsyntax-only -verify=cxx,expected %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c -Wfour-char-constants -fsyntax-only -verify=c,expected %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c -Wfour-char-constants -fsyntax-only -verify=c,expected %s
 
 #ifndef __cplusplus
 typedef __WCHAR_TYPE__ wchar_t;
@@ -38,3 +41,81 @@
 #ifdef __cplusplus
 // expected-error@-2 {{too long}}
 #endif
+
+// UTF-8 character literal code point ranges.
+#if __cplusplus >= 201703L || __STDC_VERSION__ >= 201710L
+_Static_assert(u8'\U' == 0x00, ""); // c-error {{universal character name refers to a control character}}
+_Static_assert(u8'\U007F' == 0x7F, ""); // c-error {{universal character name refers to a control character}}
+_Static_assert(u8'\U0080', ""); // c-error {{universal character name refers to a control character}}
+// cxx-error@-1 {{character too large for enclosing character literal type}}
+_Static_assert((unsigned char)u8'\xFF' == (unsigned char)0xFF, "");
+#endif
+
+// UTF-8 string literal code point ranges.
+_Static_assert(u8"\U"[0] == 0x00, ""); // c-error {{universal character name refers to a control character}}
+_Static_assert(u8"\U007F"[0] == 0x7F, ""); // c-error {{universal character name refers to a control character}}
+_Static_assert((unsigned char)u8"\U0080"[0] == (unsigned char)0xC2, ""); // c-error {{universal character name refers to a control character}}
+_Static_assert((unsigned char)u8"\U0080"[1] == (unsigned char)0x80, ""); // c-error {{universal character name refers to a control character}}
+_Static_assert((unsigned char)u8"\U07FF"[0] == (unsigned char)0xDF, "");
+_Static_assert((unsigned char)u8"\U07FF"[1] == (unsigned char)0xBF, "");
+_Static_assert((unsigned char)u8"\U0800"[0] == (unsigned char)0xE0, "");
+_Static_assert((unsigned char)u8"\U0800"[1] == (unsigned char)0xA0, "");
+_Static_assert((unsigned char)u8"\U0800"[2] == (unsigned char)0x80, "");
+_Static_assert(u8"\UD800"[0], ""); // expected-error {{invalid universal character}}
+_Static_assert(u8"\UDFFF"[0], ""); // expected-error {{invalid universal character}}
+_Static_assert((unsigned char)u8"\U"[0] == (unsigned char)0xEF, "");
+_Static_assert((unsigned char)u8"\U"[1] == (unsigned char)0xBF, "");
+_Static_assert((unsigned char)u8"\U"[2] == (unsigned char)0xBF, "");
+_Static_assert((unsigned char)u8"\U0001"[0] == (unsigned char)0xF0, "");
+_Static_assert((unsigned char)u8"\U0001"[1] == (unsigned char)0x90, "");
+_Static_assert((unsigned char)u8"\U0001"[2] == (unsigned char)0x80, "");
+_Static_assert((unsigned char)u8"\U0001"[3] == (unsigned char)0x80, "");
+_Static_assert((unsigned char)u8"\U0010"[0] == (unsigned char)0xF4, "");
+_Static_assert((unsigned char)u8"\U0010"[1] == (unsigned char)0x8F, "");
+_Static_assert((unsigned char)u8"\U0010"[2] == (unsigned char)0xBF, "");
+_Static_assert((unsigned char)u8"\U0010"[3] == (unsigned char)0xBF, "");
+_Static_assert(u8"\U0011"[0], ""); // expected-error {{invalid universal character}}
+
+#if !defined(__STDC_UTF_16__)
+#error __STDC_UTF_16__ is not defined.
+#endif
+#if __STDC_UTF_16__ != 1
+#error __STDC_UTF_16__ has the wrong value.
+#endif
+
+// UTF-16 character literal code point ranges.

[clang] a68039c - [Clang] Add tests and mark as implemented WG14-N2728

2023-04-27 Thread Tom Honermann via cfe-commits

Author: Tom Honermann
Date: 2023-04-27T14:25:41-07:00
New Revision: a68039c51e6123bea4a019c02b72297e0de58529

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

LOG: [Clang] Add tests and mark as implemented WG14-N2728

This change expands testing of UTF-8, UTF-16, and UTF-32 character and string
literals as validation that WG14 N2728 (char16_t & char32_t string literals
shall be UTF-16 & UTF-32) has been implemented.

Reviewed By: cor3ntin, aaron.ballman

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

Added: 


Modified: 
clang/test/Lexer/char-literal.cpp
clang/www/c_status.html

Removed: 




diff  --git a/clang/test/Lexer/char-literal.cpp 
b/clang/test/Lexer/char-literal.cpp
index a71500f8f0107..f2d72280e66cd 100644
--- a/clang/test/Lexer/char-literal.cpp
+++ b/clang/test/Lexer/char-literal.cpp
@@ -1,5 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 
-Wfour-char-constants -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c 
-Wfour-char-constants -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 
-Wfour-char-constants -fsyntax-only -verify=cxx,expected %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++17 
-Wfour-char-constants -fsyntax-only -verify=cxx,expected %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++20 
-Wfour-char-constants -fsyntax-only -verify=cxx,expected %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c11 -x c 
-Wfour-char-constants -fsyntax-only -verify=c,expected %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c2x -x c 
-Wfour-char-constants -fsyntax-only -verify=c,expected %s
 
 #ifndef __cplusplus
 typedef __WCHAR_TYPE__ wchar_t;
@@ -38,3 +41,81 @@ char16_t q[2] = u"\U0001";
 #ifdef __cplusplus
 // expected-error@-2 {{too long}}
 #endif
+
+// UTF-8 character literal code point ranges.
+#if __cplusplus >= 201703L || __STDC_VERSION__ >= 201710L
+_Static_assert(u8'\U' == 0x00, ""); // c-error {{universal character 
name refers to a control character}}
+_Static_assert(u8'\U007F' == 0x7F, ""); // c-error {{universal character 
name refers to a control character}}
+_Static_assert(u8'\U0080', ""); // c-error {{universal character name 
refers to a control character}}
+// cxx-error@-1 {{character too large for 
enclosing character literal type}}
+_Static_assert((unsigned char)u8'\xFF' == (unsigned char)0xFF, "");
+#endif
+
+// UTF-8 string literal code point ranges.
+_Static_assert(u8"\U"[0] == 0x00, ""); // c-error {{universal 
character name refers to a control character}}
+_Static_assert(u8"\U007F"[0] == 0x7F, ""); // c-error {{universal 
character name refers to a control character}}
+_Static_assert((unsigned char)u8"\U0080"[0] == (unsigned char)0xC2, ""); 
// c-error {{universal character name refers to a control character}}
+_Static_assert((unsigned char)u8"\U0080"[1] == (unsigned char)0x80, ""); 
// c-error {{universal character name refers to a control character}}
+_Static_assert((unsigned char)u8"\U07FF"[0] == (unsigned char)0xDF, "");
+_Static_assert((unsigned char)u8"\U07FF"[1] == (unsigned char)0xBF, "");
+_Static_assert((unsigned char)u8"\U0800"[0] == (unsigned char)0xE0, "");
+_Static_assert((unsigned char)u8"\U0800"[1] == (unsigned char)0xA0, "");
+_Static_assert((unsigned char)u8"\U0800"[2] == (unsigned char)0x80, "");
+_Static_assert(u8"\UD800"[0], ""); // expected-error {{invalid universal 
character}}
+_Static_assert(u8"\UDFFF"[0], ""); // expected-error {{invalid universal 
character}}
+_Static_assert((unsigned char)u8"\U"[0] == (unsigned char)0xEF, "");
+_Static_assert((unsigned char)u8"\U"[1] == (unsigned char)0xBF, "");
+_Static_assert((unsigned char)u8"\U"[2] == (unsigned char)0xBF, "");
+_Static_assert((unsigned char)u8"\U0001"[0] == (unsigned char)0xF0, "");
+_Static_assert((unsigned char)u8"\U0001"[1] == (unsigned char)0x90, "");
+_Static_assert((unsigned char)u8"\U0001"[2] == (unsigned char)0x80, "");
+_Static_assert((unsigned char)u8"\U0001"[3] == (unsigned char)0x80, "");
+_Static_assert((unsigned char)u8"\U0010"[0] == (unsigned char)0xF4, "");
+_Static_assert((unsigned char)u8"\U0010"[1] == (unsigned char)0x8F, "");
+_Static_assert((unsigned char)u8"\U0010"[2] == (unsigned char)0xBF, "");
+_Static_assert((unsigned char)u8"\U0010"[3] == (unsigned char)0xBF, "");
+_Static_assert(u8"\U0011"[0], ""); // expected-error {{invalid universal 
character}}
+
+#if !defined(__STDC_UTF_16__)
+#error __STDC_UTF_16__ is not defined.
+#endif
+#if __STDC_UTF_16__ != 1
+#error __STDC_UTF_16__ has the wrong value.
+#endif
+
+// UTF-16 character literal code 

[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2023-04-27 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.
Herald added a subscriber: jplehr.

This change appears to have negatively impacted some users that were dependent 
on the previous `Preprocessing::enableIncrementalProcessing(true)` behavior. 
See https://github.com/llvm/llvm-project/issues/62413.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127284

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


[clang] 61976af - [clang][driver] Enable MisExpect diagnostics flag outside of CC1

2023-04-27 Thread Paul Kirth via cfe-commits

Author: Paul Kirth
Date: 2023-04-27T21:19:46Z
New Revision: 61976af3ba9347935e9715067fcc0f5a568e6e7d

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

LOG: [clang][driver] Enable MisExpect diagnostics flag outside of CC1

Previously we only accepted the `-fdiagnostics-misexpect-tolerance=` at
CC1, when it should have been handled identically to
`-fdiagnostics-hotness-threshold=`. It should not have been required to
pass this flag w/ `-Xclang` as reported here:
https://reviews.llvm.org/D115907#inline-1440745

Reviewed By: hans, phosek

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 9daf1475576a..33ad50ad1348 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4033,6 +4033,13 @@ static void RenderDiagnosticsOptions(const Driver , 
const ArgList ,
 CmdArgs.push_back(Args.MakeArgString(Opt));
   }
 
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
+std::string Opt =
+std::string("-fdiagnostics-misexpect-tolerance=") + A->getValue();
+CmdArgs.push_back(Args.MakeArgString(Opt));
+  }
+
   if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
 CmdArgs.push_back("-fdiagnostics-format");
 CmdArgs.push_back(A->getValue());

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index 446bb07ee6cb..67ec82a09f85 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -140,6 +140,10 @@
 // CHECK-PROFILE-USE-DIR: 
"-fprofile-instrument-use-path={{.*}}.d/some/dir{{/|}}default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
+// RUN: %clang -### -S -fprofile-instr-use=%t.profdata 
-fdiagnostics-misexpect-tolerance=10 -Wmisexpect %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MISEXPECT-TOLLERANCE
+// CHECK-MISEXPECT-TOLLERANCE: "-fdiagnostics-misexpect-tolerance=10"
+// CHECK-MISEXPECT-TOLLERANCE-NOT: argument unused
+
 // RUN: %clang -### -S -fvectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-VECTORIZE %s
 // RUN: %clang -### -S -fno-vectorize -fvectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-VECTORIZE %s
 // RUN: %clang -### -S -fno-vectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VECTORIZE %s



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


[PATCH] D149206: [clang][driver] Enable MisExpect diagnostics flag outside of CC1

2023-04-27 Thread Paul Kirth 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 rG61976af3ba93: [clang][driver] Enable MisExpect diagnostics 
flag outside of CC1 (authored by paulkirth).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149206

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/clang_f_opts.c


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -140,6 +140,10 @@
 // CHECK-PROFILE-USE-DIR: 
"-fprofile-instrument-use-path={{.*}}.d/some/dir{{/|}}default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
+// RUN: %clang -### -S -fprofile-instr-use=%t.profdata 
-fdiagnostics-misexpect-tolerance=10 -Wmisexpect %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-MISEXPECT-TOLLERANCE
+// CHECK-MISEXPECT-TOLLERANCE: "-fdiagnostics-misexpect-tolerance=10"
+// CHECK-MISEXPECT-TOLLERANCE-NOT: argument unused
+
 // RUN: %clang -### -S -fvectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-VECTORIZE %s
 // RUN: %clang -### -S -fno-vectorize -fvectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-VECTORIZE %s
 // RUN: %clang -### -S -fno-vectorize %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VECTORIZE %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4033,6 +4033,13 @@
 CmdArgs.push_back(Args.MakeArgString(Opt));
   }
 
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
+std::string Opt =
+std::string("-fdiagnostics-misexpect-tolerance=") + A->getValue();
+CmdArgs.push_back(Args.MakeArgString(Opt));
+  }
+
   if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
 CmdArgs.push_back("-fdiagnostics-format");
 CmdArgs.push_back(A->getValue());


Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -140,6 +140,10 @@
 // CHECK-PROFILE-USE-DIR: "-fprofile-instrument-use-path={{.*}}.d/some/dir{{/|}}default.profdata"
 // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
 
+// RUN: %clang -### -S -fprofile-instr-use=%t.profdata -fdiagnostics-misexpect-tolerance=10 -Wmisexpect %s 2>&1 | FileCheck %s --check-prefix=CHECK-MISEXPECT-TOLLERANCE
+// CHECK-MISEXPECT-TOLLERANCE: "-fdiagnostics-misexpect-tolerance=10"
+// CHECK-MISEXPECT-TOLLERANCE-NOT: argument unused
+
 // RUN: %clang -### -S -fvectorize %s 2>&1 | FileCheck -check-prefix=CHECK-VECTORIZE %s
 // RUN: %clang -### -S -fno-vectorize -fvectorize %s 2>&1 | FileCheck -check-prefix=CHECK-VECTORIZE %s
 // RUN: %clang -### -S -fno-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-NO-VECTORIZE %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4033,6 +4033,13 @@
 CmdArgs.push_back(Args.MakeArgString(Opt));
   }
 
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
+std::string Opt =
+std::string("-fdiagnostics-misexpect-tolerance=") + A->getValue();
+CmdArgs.push_back(Args.MakeArgString(Opt));
+  }
+
   if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
 CmdArgs.push_back("-fdiagnostics-format");
 CmdArgs.push_back(A->getValue());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149380: [clang] Add -Wunused-result-always warning

2023-04-27 Thread Gregory Anders via Phabricator via cfe-commits
gpanders created this revision.
gpanders added a reviewer: theraven.
Herald added a project: All.
gpanders requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This flag enables warnings for unused function return values
universally, even for functions which do not have a "warn_unused_result"
attribute.

This is disabled by default as it is far too noisy for most C/C++ code;
however, there are contexts where this is a desirable warning to have
(for example, in safety critical code where ignoring return values is
usually forbidden).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149380

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/unused-result-always.c

Index: clang/test/Sema/unused-result-always.c
===
--- /dev/null
+++ clang/test/Sema/unused-result-always.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code -Wno-strict-prototypes -Wunused-result-always
+
+int t1(int X, int Y);
+void t2();
+void *t3();
+
+#define M1(a, b) t1(a, b)
+
+void bar() {
+  t1(1, 2);   // expected-warning {{ignoring return value of function}}
+
+  t2();   // no warning.
+
+  (void)t1(1, 2); // no warning;
+
+  t3();   // expected-warning {{ignoring return value of function}}
+
+  M1(1, 2);   // expected-warning {{ignoring return value of function}}
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -200,8 +200,13 @@
 static bool DiagnoseNoDiscard(Sema , const WarnUnusedResultAttr *A,
   SourceLocation Loc, SourceRange R1,
   SourceRange R2, bool IsCtor) {
-  if (!A)
+  if (!A && S.Diags.isIgnored(diag::warn_unused_result_always, Loc))
 return false;
+
+  if (!A) {
+return S.Diag(Loc, diag::warn_unused_result_always) << R1 << R2;
+  }
+
   StringRef Msg = A->getMessage();
 
   if (Msg.empty()) {
@@ -242,7 +247,10 @@
   const Expr *WarnExpr;
   SourceLocation Loc;
   SourceRange R1, R2;
-  if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context))
+  bool WarnUnusedResultAlways =
+  !Diags.isIgnored(diag::warn_unused_result_always, ExprLoc);
+  if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context,
+ WarnUnusedResultAlways))
 return;
 
   // If this is a GNU statement expression expanded from a macro, it is probably
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2578,7 +2578,7 @@
 /// warning.
 bool Expr::isUnusedResultAWarning(const Expr *, SourceLocation ,
   SourceRange , SourceRange ,
-  ASTContext ) const {
+  ASTContext , bool Always) const {
   // Don't warn if the expr is type dependent. The type could end up
   // instantiating to void.
   if (isTypeDependent())
@@ -2593,18 +2593,20 @@
 R1 = getSourceRange();
 return true;
   case ParenExprClass:
-return cast(this)->getSubExpr()->
-  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+return cast(this)->getSubExpr()->isUnusedResultAWarning(
+WarnE, Loc, R1, R2, Ctx, Always);
   case GenericSelectionExprClass:
-return cast(this)->getResultExpr()->
-  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+return cast(this)
+->getResultExpr()
+->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx, Always);
   case CoawaitExprClass:
   case CoyieldExprClass:
-return cast(this)->getResumeExpr()->
-  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+return cast(this)
+->getResumeExpr()
+->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx, Always);
   case ChooseExprClass:
-return cast(this)->getChosenSubExpr()->
-  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+return cast(this)->getChosenSubExpr()->isUnusedResultAWarning(
+WarnE, Loc, R1, R2, Ctx, Always);
   case UnaryOperatorClass: {
 const UnaryOperator *UO = cast(this);
 
@@ -2632,7 +2634,8 @@
 return false;
   break;
 case UO_Extension:
-  return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+  return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx,
+  Always);
 }
 WarnE = this;
 Loc = UO->getOperatorLoc();
@@ -2653,12 +2656,15 @@
   dyn_cast(BO->getRHS()->IgnoreParens()))
   if (IE->getValue() == 0)
 return false;
-return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, 

[PATCH] D148088: [RFC][clangd] Move preamble index task to a seperate task

2023-04-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:88
+if (PreambleIndexTask)
+  PreambleIndexTask->runAsync("task:" + Path + Version,
+  std::move(Task));

ilya-biryukov wrote:
> This definitely does not work. After `onPreambleAST` returns, the AST will be 
> destroyed and async tasks may access it afterwards.
> 
https://reviews.llvm.org/D115768 is a very rough prototype from a couple of 
years ago of how to keep the preamble AST alive in a separate object that I 
believe would be safe to index from even after returning from onPreambleAST.
(Though the patch doesn't actually do that, that was the idea)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148088

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


[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-04-27 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

This is a precursor to specifying the field with the designated initializer 
syntax. Therefore, it may be a bit cumbersome.

The code in `CGExpr.cpp` is decidedly gross. I would appreciate any advice on 
how to de-grossify it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

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


[PATCH] D149215: [MemProf] Control availability of hot/cold operator new from LTO link

2023-04-27 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

In D149215#4303197 , @tejohnson wrote:

> In D149215#4303149 , @pcc wrote:
>
>>> Adds an LTO option
>>
>> Usual question: does it need to be an option? Could the allocator expose a 
>> symbol such as `__malloc_hot_cold` that the linker could check for in the 
>> symbol table?
>
> I thought about doing something like that, but the disadvantage is that it 
> requires support in the linkers (presumably at least both lld and the gold 
> plugin), instead of being centralized in LTO itself. That being said, I do 
> see existing lld code that currently looks for certain special __* symbols, 
> so maybe this would be ok. I agree it would be nice to have something 
> automatic, at least longer term. However, I think we need the internal option 
> anyway, for testing (especially via opt for simulating regular LTO). What do 
> you think of my adding a TODO to investigate the approach you are suggesting 
> here?

That's fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149215

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


[PATCH] D146777: [clang] Preliminary fat-lto-object support

2023-04-27 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 517706.
paulkirth added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146777

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/embed-lto-fatlto.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fatlto-objects.c

Index: clang/test/Driver/fatlto-objects.c
===
--- /dev/null
+++ clang/test/Driver/fatlto-objects.c
@@ -0,0 +1,10 @@
+// REQUIRES: x86_64-linux
+// RUN: %clang -target x86_64-unknown-linux-gnu -flto -ffat-lto-objects -fintegrated-as -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC
+// CHECK-CC: -cc1
+// CHECK-CC: -emit-obj
+// CHECK-CC: -ffat-lto-objects
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -ffat-lto-objects -fintegrated-as -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO
+// CHECK-CC-NOLTO: -cc1
+// CHECK-CC-NOLTO: -emit-obj
+// CHECK-CC-NOLTO-NOT: -ffat-lto-objects
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -421,7 +421,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-ffat-lto-objects' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
 // CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ftree-dce' is not supported
Index: clang/test/CodeGen/embed-lto-fatlto.c
===
--- /dev/null
+++ clang/test/CodeGen/embed-lto-fatlto.c
@@ -0,0 +1,9 @@
+// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -S -flto=full -ffat-lto-objects -emit-llvm < %s  | FileCheck %s
+// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -S -flto=full -ffat-lto-objects -emit-llvm < %s  | FileCheck %s
+//
+// CHECK: !{{[0-9]+}} = !{i32 1, !"ThinLTO", i32 0}
+// CHECK: !{{[0-9]+}} = !{i32 1, !"EnableSplitLTOUnit", i32 1}
+
+int test(void) {
+  return 0xabcd;
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7259,6 +7259,14 @@
 }
   }
 
+  if (IsUsingLTO && Args.getLastArg(options::OPT_ffat_lto_objects)) {
+assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);
+CmdArgs.push_back(Args.MakeArgString(
+Twine("-flto=") + (LTOMode == LTOK_Thin ? "thin" : "full")));
+CmdArgs.push_back("-flto-unit");
+CmdArgs.push_back("-ffat-lto-objects");
+  }
+
   if (Args.hasArg(options::OPT_forder_file_instrumentation)) {
  CmdArgs.push_back("-forder-file-instrumentation");
  // Enable order file instrumentation when ThinLTO is not on. When ThinLTO is
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4637,8 +4637,13 @@
   }
   case phases::Backend: {
 if (isUsingLTO() && TargetDeviceOffloadKind == Action::OFK_None) {
-  types::ID Output =
-  Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
+  types::ID Output;
+  if (Args.hasArg(options::OPT_S))
+Output = types::TY_LTO_IR;
+  else if (Args.hasArg(options::OPT_ffat_lto_objects))
+Output = types::TY_PP_Asm;
+  else
+Output = types::TY_LTO_BC;
   return C.MakeAction(Input, Output);
 }
 if (isUsingLTO(/* IsOffload */ true) &&
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/Bitcode/BitcodeWriter.h"
 #include "llvm/Bitcode/BitcodeWriterPass.h"
+#include "llvm/Bitcode/EmbedBitcodePass.h"
 #include "llvm/CodeGen/RegAllocRegistry.h"
 #include "llvm/CodeGen/SchedulerRegistry.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
@@ -990,7 +991,10 @@
 MPM.addPass(InstrProfiling(*Options, false));
   });
 
-if (IsThinLTO) {
+if (CodeGenOpts.FatLTO) {
+  MPM = PB.buildFatLTODefaultPipeline(
+  Level, IsThinLTO, IsThinLTO || shouldEmitRegularLTOSummary());
+} else if (IsThinLTO) {
   MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
 } else if (IsLTO) {
   MPM = 

[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-04-27 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 517704.
void added a comment.

Fix ICE when the FD isn't found.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -61,6 +61,7 @@
 // CHECK-NEXT: DiagnoseAsBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: DisableSanitizerInstrumentation (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: DisableTailCalls (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: ElementCount (SubjectMatchRule_field)
 // CHECK-NEXT: EnableIf (SubjectMatchRule_function)
 // CHECK-NEXT: EnforceTCB (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: EnforceTCBLeaf (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8238,6 +8238,29 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleElementCountAttr(Sema , Decl *D, const ParsedAttr ) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  SmallVector Names;
+  SmallVector Ranges;
+  for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
+if (!AL.isArgIdent(ArgNo)) {
+  S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return;
+}
+
+IdentifierLoc *IL = AL.getArgAsIdent(ArgNo);
+Names.push_back(IL->Ident);
+Ranges.push_back(IL->Loc);
+  }
+
+  ElementCountAttr *ECA = ::new (S.Context) ElementCountAttr(S.Context, AL,
+ Names.data(),
+ Names.size());
+  ECA->addCountFieldSourceRange(Ranges);
+  D->addAttr(ECA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema , Decl *D,
const ParsedAttr ) {
   StringRef KindStr;
@@ -9142,6 +9165,9 @@
   case ParsedAttr::AT_FunctionReturnThunks:
 handleFunctionReturnThunksAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ElementCount:
+handleElementCountAttr(S, D, AL);
+break;
 
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17686,6 +17686,43 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))
+  if (const FieldDecl *FD = FindFieldWithElementCountAttr(SubRD))
+return FD;
+  }
+
+  return nullptr;
+}
+
+static bool CheckElementCountAttr(const RecordDecl *RD, const FieldDecl *FD,
+  SourceRange ) {
+  const ElementCountAttr *ECA = FD->getAttr();
+  unsigned Idx = 0;
+
+  for (const IdentifierInfo *II : ECA->elementCountFields()) {
+Loc = ECA->getCountFieldSourceRange(Idx++);
+
+auto DeclIter = llvm::find_if(
+RD->fields(), [&](const FieldDecl *FD){
+  return II->getName() == FD->getName();
+});
+
+if (DeclIter == RD->field_end())
+  return false;
+
+if (auto *SubRD = DeclIter->getType()->getAsRecordDecl())
+  RD = SubRD;
+  }
+
+  return true;
+}
+
 void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
 SourceRange BraceRange) {
   AdjustDeclIfTemplate(TagD);
@@ -17743,6 +17780,17 @@
  [](const FieldDecl *FD) { return FD->isBitField(); }))
   Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
   }
+
+  // Check the "element_count" attribute to ensure that the count field exists
+  // in the struct.
+  if (const RecordDecl *RD = dyn_cast(Tag)) {
+if (const FieldDecl *FD = FindFieldWithElementCountAttr(RD)) {
+  SourceRange SR;
+  if (!CheckElementCountAttr(RD, FD, SR))
+Diag(SR.getBegin(), diag::warn_element_count_placeholder)
+<< FD->getName() << SR;
+}
+  }
 }
 
 void 

[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-04-27 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 517700.
void added a comment.

Add the ability to specify a "path" to the element count if it resides within a 
sub-structure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148381

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTImporter.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -61,6 +61,7 @@
 // CHECK-NEXT: DiagnoseAsBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: DisableSanitizerInstrumentation (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_variable_is_global)
 // CHECK-NEXT: DisableTailCalls (SubjectMatchRule_function, SubjectMatchRule_objc_method)
+// CHECK-NEXT: ElementCount (SubjectMatchRule_field)
 // CHECK-NEXT: EnableIf (SubjectMatchRule_function)
 // CHECK-NEXT: EnforceTCB (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: EnforceTCBLeaf (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8238,6 +8238,29 @@
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
+static void handleElementCountAttr(Sema , Decl *D, const ParsedAttr ) {
+  // TODO: Probably needs more processing here. See Sema::AddAlignValueAttr.
+  SmallVector Names;
+  SmallVector Ranges;
+  for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
+if (!AL.isArgIdent(ArgNo)) {
+  S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
+  << AL << AANT_ArgumentIdentifier;
+  return;
+}
+
+IdentifierLoc *IL = AL.getArgAsIdent(ArgNo);
+Names.push_back(IL->Ident);
+Ranges.push_back(IL->Loc);
+  }
+
+  ElementCountAttr *ECA = ::new (S.Context) ElementCountAttr(S.Context, AL,
+ Names.data(),
+ Names.size());
+  ECA->addCountFieldSourceRange(Ranges);
+  D->addAttr(ECA);
+}
+
 static void handleFunctionReturnThunksAttr(Sema , Decl *D,
const ParsedAttr ) {
   StringRef KindStr;
@@ -9142,6 +9165,9 @@
   case ParsedAttr::AT_FunctionReturnThunks:
 handleFunctionReturnThunksAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ElementCount:
+handleElementCountAttr(S, D, AL);
+break;
 
   // Microsoft attributes:
   case ParsedAttr::AT_LayoutVersion:
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -17686,6 +17686,43 @@
  "Broken injected-class-name");
 }
 
+static const FieldDecl *FindFieldWithElementCountAttr(const RecordDecl *RD) {
+  for (const Decl *D : RD->decls()) {
+if (const auto *FD = dyn_cast(D))
+  if (FD->hasAttr())
+return FD;
+
+if (const auto *SubRD = dyn_cast(D))
+  if (const FieldDecl *FD = FindFieldWithElementCountAttr(SubRD))
+return FD;
+  }
+
+  return nullptr;
+}
+
+static bool CheckElementCountAttr(const RecordDecl *RD, const FieldDecl *FD,
+  SourceRange ) {
+  const ElementCountAttr *ECA = FD->getAttr();
+  unsigned Idx = 0;
+
+  for (const IdentifierInfo *II : ECA->elementCountFields()) {
+Loc = ECA->getCountFieldSourceRange(Idx++);
+
+auto DeclIter = llvm::find_if(
+RD->fields(), [&](const FieldDecl *FD){
+  return II->getName() == FD->getName();
+});
+
+if (DeclIter == RD->field_end())
+  return false;
+
+if (auto *SubRD = DeclIter->getType()->getAsRecordDecl())
+  RD = SubRD;
+  }
+
+  return true;
+}
+
 void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
 SourceRange BraceRange) {
   AdjustDeclIfTemplate(TagD);
@@ -17743,6 +17780,17 @@
  [](const FieldDecl *FD) { return FD->isBitField(); }))
   Diag(BraceRange.getBegin(), diag::warn_pragma_align_not_xl_compatible);
   }
+
+  // Check the "element_count" attribute to ensure that the count field exists
+  // in the struct.
+  if (const RecordDecl *RD = dyn_cast(Tag)) {
+if (const FieldDecl *FD = FindFieldWithElementCountAttr(RD)) {
+  SourceRange SR;
+  if (!CheckElementCountAttr(RD, FD, SR))
+Diag(SR.getBegin(), diag::warn_element_count_placeholder)
+ 

[PATCH] D148274: [clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization

2023-04-27 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 517699.
ayzhao marked an inline comment as done.
ayzhao added a comment.

code review comments + pull in D149301 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148274

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/Sema/SemaAccess.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp

Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -9,7 +9,7 @@
 struct B {
   A a;
   int b[20];
-  int & // expected-note {{reference member declared here}}
+  int &
 };
 
 struct C { // expected-note 5{{candidate constructor}}
@@ -21,9 +21,9 @@
   int a;
 };
 
-struct E { // expected-note 3{{candidate constructor}}
-  struct F {
-F(int, int);
+struct E {
+  struct F { // expected-note 2{{candidate constructor}}
+F(int, int); // expected-note {{candidate constructor}}
   };
   int a;
   F f;
@@ -56,6 +56,22 @@
   int b[]; // expected-note {{initialized flexible array member 'b' is here}}
 };
 
+enum K { K0, K1, K2 };
+
+struct L {
+  K k : 1;
+};
+
+struct M {
+  struct N {
+private:
+N(int);
+// expected-note@-1 {{declared private here}}
+  };
+  int i;
+  N n;
+};
+
 union U {
   int a;
   char* b;
@@ -74,7 +90,7 @@
   // beforecxx20-warning@-1 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
 }
 
-void foo() {
+void foo(int n) {
   A a1(1954, 9, 21);
   // expected-error@-1 {{excess elements in struct initializer}}
   A a2(2.1);
@@ -96,9 +112,8 @@
   B b1(2022, {7, 8});
   // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
   B b2(A(1), {}, 1);
-  // expected-error@-1 {{reference member 'c' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
-  // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
-  // beforecxx20-warning@-3 {{aggregate initialization of type 'B' from a parenthesized list of values is a C++20 extension}}
+  // beforecxx20-warning@-1 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'B' from a parenthesized list of values is a C++20 extension}}
 
   C c(A(1), 1, 2, 3, 4);
   // expected-error@-1 {{array initializer must be an initializer list}}
@@ -130,7 +145,7 @@
   // expected-error@-1 {{excess elements in union initializer}}
 
   E e1(1);
-  // expected-error@-1 {{no matching constructor for initialization of 'E'}}
+  // expected-error@-1 {{no matching constructor for initialization of 'F'}}
 
   constexpr F f1(1);
   // expected-error@-1 {{constexpr variable 'f1' must be initialized by a constant expression}}
@@ -148,18 +163,29 @@
   A a7 = Construct('i', 2.2);
   // beforecxx20-note@-1 {{in instantiation of function template specialization 'Construct' requested here}}
 
+  L l(K::K2);
+  // expected-warning@-1 {{implicit truncation}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'L' from a parenthesized list of values is a C++20 extension}}
+
   int arr4[](1, 2);
   // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
 
   int arr5[2](1, 2);
   // beforecxx20-warning@-1 {{aggregate initialization of type 'int[2]' from a parenthesized list of values is a C++20 extension}}
 
+  int arr6[n](1, 2, 3);
+  // expected-error@-1 {{variable-sized object may not be initialized}}
+
   I i(1, 2);
   // expected-error@-1 {{no matching constructor for initialization of 'I'}}
 
   J j(1, {2, 3});
   // expected-error@-1 {{initialization of flexible array member is not allowed}}
 
+  M m(1, 1);
+  // expected-error@-1 {{field of type 'N' has private constructor}}
+  // beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
+
   static_assert(__is_trivially_constructible(A, char, double));
   static_assert(__is_trivially_constructible(A, char, int));
   static_assert(__is_trivially_constructible(A, char));
@@ -221,5 +247,22 @@
 N n(43);
 // expected-error@-1 {{field of type 'L' has protected constructor}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}}
+}
+
+namespace gh61567 {
+struct O {
+  int i;
+  int &
+  // expected-note@-1 {{uninitialized reference member is here}}
+  int & = 1;
+};
+
+O o1(0, 0, 0); // no-error
+// beforecxx20-warning@-1 {{aggregate initialization of type 'O' from a parenthesized list of values 

[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-27 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

The difference is that `clang-rename` is a stand-alone binary with CLI whereas 
`clangd` isn't typically used as such (it can be, but it's a weird use-case).

I don't know if there are any existing users out there, if there are then I 
assume there are very few.

It was created as an intern project long ago (I guess 2014/2015?) and was in a 
semi-functional state, and then when I was an intern in 2016 I improved it 
significantly and built the integration with Vim and updated one for Emacs. We 
had some use-cases, but AFAIK there are none anymore at Google, and I believe 
most users we had were there.

Personally, I don't see any reason to keep `clang-rename` and support it, I 
don't think it's useful anymore. But this is Open-Source world so some people 
might object.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[PATCH] D149215: [MemProf] Control availability of hot/cold operator new from LTO link

2023-04-27 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D149215#4303149 , @pcc wrote:

>> Adds an LTO option
>
> Usual question: does it need to be an option? Could the allocator expose a 
> symbol such as `__malloc_hot_cold` that the linker could check for in the 
> symbol table?

I thought about doing something like that, but the disadvantage is that it 
requires support in the linkers (presumably at least both lld and the gold 
plugin), instead of being centralized in LTO itself. That being said, I do see 
existing lld code that currently looks for certain special __* symbols, so 
maybe this would be ok. I agree it would be nice to have something automatic, 
at least longer term. However, I think we need the internal option anyway, for 
testing (especially via opt for simulating regular LTO). What do you think of 
my adding a TODO to investigate the approach you are suggesting here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149215

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


[PATCH] D148088: [RFC][clangd] Move preamble index task to a seperate task

2023-04-27 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko added a comment.

In D148088#4302269 , @ilya-biryukov 
wrote:

> 



> Could you elaborate a bit more on what is being cached with modules and how 
> this patch would affect it?

I hope that I can provide some info here. We are going to use implicit modules 
to cache preamble i.e. the corresponding modulemap file will contain headers 
from the preamble. The idea is to provide faster goto-definition functionality 
that requires AST be built. The modules can be loaded lazily and therefore it 
can give performance boost up >10x depending on the source file. The problem 
here is the preamble indexing as soon as it mostly force the module load and 
kills the performance wins i.e. it will be ~20% instead of 10x. The possible 
solution is to move the indexing into a separate thread with possible delay for 
some functionality. Any other ideas will be also interesting here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148088

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


[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

2023-04-27 Thread Kamau Bridgeman via Phabricator via cfe-commits
kamaub accepted this revision.
kamaub added a comment.
This revision is now accepted and ready to land.

Hello, sorry for missing you ping and delaying the patch so long just for test 
case adjustments, thank you for addressing them.
Everything LGTM but lei and I had one request that can be made before you 
commit:

Please split the two functions and associated run line from 
ppc-p10-feature-builtins.c into two files named as follows
ppc-p10-mma-builtin-err.c
ppc-p10-paired-vec-memops-builtin-err.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

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


[PATCH] D149215: [MemProf] Control availability of hot/cold operator new from LTO link

2023-04-27 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

> Adds an LTO option

Usual question: does it need to be an option? Could the allocator expose a 
symbol such as `__malloc_hot_cold` that the linker could check for in the 
symbol table?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149215

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


[PATCH] D148370: [Clang][Flang][OpenMP] Add loadOffloadInfoMetadata and createOffloadEntriesAndInfoMetadata into OMPIRBuilder's finalize and initialize

2023-04-27 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 517682.
agozillon added a comment.

- Move hostIRFilePath initialize invocation to ModuleTranslation.cpp to respect 
TargetOp patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148370

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/CMakeLists.txt
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1255,19 +1255,23 @@
 llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() {
   if (!ompBuilder) {
 ompBuilder = std::make_unique(*llvmModule);
-ompBuilder->initialize();
 
 bool isDevice = false;
+llvm::StringRef hostIRFilePath = "";
 if (auto offloadMod =
-dyn_cast(mlirModule))
+dyn_cast(mlirModule)) {
   isDevice = offloadMod.getIsDevice();
+  hostIRFilePath = offloadMod.getHostIRFilePath();
+}
+
+ompBuilder->initialize(hostIRFilePath);
 
 // TODO: set the flags when available
-llvm::OpenMPIRBuilderConfig Config(
+llvm::OpenMPIRBuilderConfig config(
 isDevice, /* IsTargetCodegen */ false,
 /* HasRequiresUnifiedSharedMemory */ false,
 /* OpenMPOffloadMandatory */ false);
-ompBuilder->setConfig(Config);
+ompBuilder->setConfig(config);
   }
   return ompBuilder.get();
 }
Index: mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
===
--- mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -15,6 +15,7 @@
 #define MLIR_TARGET_LLVMIR_MODULETRANSLATION_H
 
 #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/IR/Operation.h"
 #include "mlir/IR/SymbolTable.h"
 #include "mlir/IR/Value.h"
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfoMetadata.h"
@@ -445,7 +446,28 @@
   return Fn;
 }
 
-void OpenMPIRBuilder::initialize() { initializeTypes(M); }
+void OpenMPIRBuilder::initialize(StringRef HostFilePath) {
+  initializeTypes(M);
+
+  if (!HostFilePath.empty()) {
+auto Buf = llvm::MemoryBuffer::getFile(HostFilePath);
+if (auto Err = Buf.getError())
+  assert(false && ("error opening host file from host file path inside of "
+   "OpenMPIRBuilder" +
+   Err.message())
+  .c_str());
+
+llvm::LLVMContext Ctx;
+auto M = llvm::expectedToErrorOrAndEmitErrors(
+Ctx, llvm::parseBitcodeFile(Buf.get()->getMemBufferRef(), Ctx));
+if (auto Err = M.getError())
+  assert(false && ("error parsing host file inside of OpenMPIRBuilder " +
+   Err.message())
+  .c_str());
+
+loadOffloadInfoMetadata(*M.get());
+  }
+}
 
 void OpenMPIRBuilder::finalize(Function *Fn) {
   SmallPtrSet ParallelRegionBlockSet;
@@ -534,6 +556,17 @@
 
   // Remove work items that have been completed.
   OutlineInfos = std::move(DeferredOutlines);
+
+  llvm::OpenMPIRBuilder::EmitMetadataErrorReportFunctionTy & =
+  [](llvm::OpenMPIRBuilder::EmitMetadataErrorKind kind,
+ const llvm::TargetRegionEntryInfo ) -> void {
+llvm::errs() << "Error of kind: " << kind
+ << " when emitting offload entries and metadata during "
+"OMPIRBuilder finalization \n";
+  };
+
+  if (!OffloadInfoManager.empty())
+createOffloadEntriesAndInfoMetadata(errorReportFn);
 }
 
 OpenMPIRBuilder::~OpenMPIRBuilder() {
Index: llvm/lib/Frontend/OpenMP/CMakeLists.txt
===
--- llvm/lib/Frontend/OpenMP/CMakeLists.txt
+++ llvm/lib/Frontend/OpenMP/CMakeLists.txt
@@ -19,4 +19,5 @@
   Analysis
   MC
   Scalar
+  BitReader
   )
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -419,7 +419,7 @@
   /// Initialize the internal state, this will put structures types and
   /// potentially other 

[PATCH] D149215: [MemProf] Control availability of hot/cold operator new from LTO link

2023-04-27 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 517678.
tejohnson added a comment.

Expand command and patch description for mechanism used by distributed ThinLTO


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149215

Files:
  clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/include/llvm/LTO/LTO.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/IR/ModuleSummaryIndex.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
  llvm/test/LTO/X86/memprof-supports-hot-cold-new.ll
  llvm/test/ThinLTO/X86/memprof-basic.ll
  llvm/test/ThinLTO/X86/memprof-duplicate-context-ids.ll
  llvm/test/ThinLTO/X86/memprof-duplicate-context-ids2.ll
  llvm/test/ThinLTO/X86/memprof-funcassigncloning.ll
  llvm/test/ThinLTO/X86/memprof-indirectcall.ll
  llvm/test/ThinLTO/X86/memprof-inlined.ll
  llvm/test/ThinLTO/X86/memprof-inlined2.ll
  llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
  llvm/test/Transforms/MemProfContextDisambiguation/basic.ll
  llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids.ll
  llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
  llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
  llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
  llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
  llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll

Index: llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll
@@ -42,7 +42,7 @@
 ;;
 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:	-memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:	%s -S 2>&1 | FileCheck %s --check-prefix=DUMP
 
Index: llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
@@ -41,7 +41,7 @@
 ;;
 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:	-memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:	-memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
 ; RUN:  -stats -pass-remarks=memprof-context-disambiguation \
Index: llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
@@ -51,7 +51,7 @@
 ;;
 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:  -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:  -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
 ; RUN:  -stats -pass-remarks=memprof-context-disambiguation \
Index: llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
@@ -45,7 +45,7 @@
 ;;
 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:  -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:  -stats -pass-remarks=memprof-context-disambiguation \
 ; RUN:  %s -S 2>&1 | FileCheck %s --check-prefix=DUMP --check-prefix=IR \
Index: llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
@@ -93,7 +93,7 @@
 ;;
 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:  -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:  

[PATCH] D141714: Fix ast print of variables with attributes

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/DeclPrinter.cpp:52-58
+enum AttrPrintLoc {
+  SIDE_NONE = 0,
+  SIDE_LEFT = 1,
+  SIDE_MIDDLE = 2,
+  SIDE_RIGHT = 4,
+  SIDE_ANY = SIDE_LEFT | SIDE_MIDDLE | SIDE_RIGHT,
+};

aaron.ballman wrote:
> 
I think we should use an `enum class` just so we don't steal these identifiers 
at the global scope within this file, WDYT?



Comment at: clang/lib/AST/DeclPrinter.cpp:264-266
+  // 1- should be print on the left side of a decl.
+  // 2- should be print on the middle of a decl right after the type.
+  // 3- should be print on the right side of a decl.





Comment at: clang/lib/AST/DeclPrinter.cpp:267-268
+  // 3- should be print on the right side of a decl.
+  AttrPrintLoc attrloc = Right; // We default to middle.
+  attr::Kind kind = A->getKind();
+

Minor style nits.



Comment at: clang/lib/AST/DeclPrinter.cpp:272
+  // to classify each of them.
+  if (A->isCXX11Attribute()) {
+// C++11 onwards attributes can not be placed on left side. Output on

This should also handle C2x attributes, so I'd use 
`isStandardAttributeSyntax()` instead.



Comment at: clang/lib/AST/DeclPrinter.cpp:279
+attrloc = Right;
+  } else if (kind == attr::DiagnoseIf) {
+// DiagnoseIf should be print on the right side because it may refer to

There are other attributes for which this is true as well, like `enable_if`, 
thread safety annotations, etc.



Comment at: clang/lib/AST/DeclPrinter.cpp:286-287
+attrloc = Left;
+  } else if (D->getAsFunction() &&
+ D->getAsFunction()->isThisDeclarationADefinition()) {
+// In case Decl is a function with a body, then attrs should be print





Comment at: clang/lib/AST/DeclPrinter.cpp:664-665
+
+  std::string Proto;
+  llvm::raw_string_ostream OS(Proto);
+

What's the purpose to hoisting these two lines?



Comment at: clang/test/Analysis/blocks.mm:81
 // ANALYZER-NEXT:   2: [B1.1] (CXXConstructExpr, [B1.3], 
StructWithCopyConstructor)
-// CHECK-NEXT:   3: StructWithCopyConstructor s(5) 
__attribute__((blocks("byref")));
+// CHECK-NEXT:   3: StructWithCopyConstructor s 
__attribute__((blocks("byref")))(5);
 // CHECK-NEXT:   4: ^{ }

I can't quite tell if this change is good, bad, or just different.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141714

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-04-27 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

Thanks for all the reviews.

In D149280#4301188 , @njames93 wrote:

> It may be a good idea to create unittests for the formatconverter in 
> `clang-tools-extra/unittests/clang-tidy/`

I started there but had decided that the easiest and most reviewable form for 
the tests was in lit tests since the code that uses `FormatStringConverter` is 
so simple. (Particularly since I was hoping to persuade the inventor of 
`std::format` to review the tests too.) Are you proposing that I should 
duplicate (most of) the lit tests in the unit tests or migrate most of the lit 
tests to unit tests? Are there any existing tests that do similar things that I 
should model them on?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-27 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

I am OK to give LGTM, assuming the other reviewers don't still have 
reservations?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


[clang] 3e22eb3 - Fix spacing in ReleaseNotes.rst link

2023-04-27 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-04-27T11:41:21-07:00
New Revision: 3e22eb36b6ffd60608a0e70401b021738c1c4fe8

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

LOG: Fix spacing in ReleaseNotes.rst link

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a382c5e64ece..8082e9d9f323 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -335,7 +335,7 @@ Bug Fixes in This Version
   (`#62362 `_)
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
-  (`#62296 `_)
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^



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


[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D148439#4299178 , @kbobyrev wrote:

> Thanks Aaron!
>
> Yes, fair enough, that looks good to me, probably no need to move a sanity 
> check to the front of `main()` in this case.
>
> Also, just as a note: I don't know how many people use `clang-rename` anymore 
> (especially with `clangd` being present), I rewrote a lot of what 
> clang-rename has to offer for `clangd` with better precision and results. I 
> think the tool is still useful, but not as much as before.

Should we consider deprecating clang-rename in favor of clangd, or do you think 
that's premature?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D149314#4302892 , @craig.topper 
wrote:

> Release note added in 0e02e5decc732155d8dc4b63ecccbb1477603ecd 
> 

Thanks Craig, that looks great


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Release note added in 0e02e5decc732155d8dc4b63ecccbb1477603ecd 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D148094: [DRAFT][clang][CodeGen] Break up TargetInfo.cpp [6/6]

2023-04-27 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Restructuring seems overall reasonable.  (I'm assuming there isn't actually any 
changed code, just moving code around.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

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


[clang] 0e02e5d - [RISCV] Add a release note for the removal of __attribute__((interrupt("user"))). NFC

2023-04-27 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-04-27T11:22:21-07:00
New Revision: 0e02e5decc732155d8dc4b63ecccbb1477603ecd

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

LOG: [RISCV] Add a release note for the removal of 
__attribute__((interrupt("user"))). NFC

This was removed by D149314.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 71b197a2ad29..a382c5e64ece 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -448,6 +448,8 @@ RISC-V Support
 - Fixed incorrect ABI lowering of ``_Float16`` in the case of structs
   containing ``_Float16`` that are eligible for passing via GPR+FPR or
   FPR+FPR.
+- Removed support for ``__attribute__((interrupt("user")))``. User-level
+  interrupts are not in version 1.12 of the privileged specification.
 
 CUDA/HIP Language Changes
 ^



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


[PATCH] D148092: [clang][CodeGen] Break up TargetInfo.cpp [4/6]

2023-04-27 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Is this supposed to be different from D148093 
?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148092

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


[PATCH] D148089: [clang][CodeGen] Break up TargetInfo.cpp [1/6]

2023-04-27 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/D148089/new/

https://reviews.llvm.org/D148089

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


[PATCH] D148090: [clang][CodeGen] Break up TargetInfo.cpp [2/6]

2023-04-27 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/D148090/new/

https://reviews.llvm.org/D148090

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


[PATCH] D148091: [clang][CodeGen] Break up TargetInfo.cpp [3/6]

2023-04-27 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/D148091/new/

https://reviews.llvm.org/D148091

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


[PATCH] D149364: [CUDA] Temporarily undefine __noinline__ when including bits/shared_ptr_base.h

2023-04-27 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
Herald added subscribers: mattd, carlosgalvezp, bixia, yaxunl.
Herald added a project: All.
tra updated this revision to Diff 517656.
tra added a comment.
tra published this revision for review.
tra added reviewers: jlebar, phawkins.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Removed warning.


This avoid CUDA compilation errors caused by CUDA headers defining __noinline__
and conflicting with __noinline__ use in libstdc++.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149364

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h


Index: clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
===
--- /dev/null
+++ clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
@@ -0,0 +1,9 @@
+// CUDA headers define __noinline__ which interferes with libstdc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#include_next "bits/shared_ptr_base.h"
+
+#pragma pop_macro("__noinline__")
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -257,6 +257,7 @@
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+  cuda_wrappers/bits/shared_ptr_base.h
 )
 
 set(ppc_wrapper_files


Index: clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
===
--- /dev/null
+++ clang/lib/Headers/cuda_wrappers/bits/shared_ptr_base.h
@@ -0,0 +1,9 @@
+// CUDA headers define __noinline__ which interferes with libstdc++'s use of
+// `__attribute((__noinline__))`. In order to avoid compilation error,
+// temporarily unset __noinline__ when we include affected libstdc++ header.
+
+#pragma push_macro("__noinline__")
+#undef __noinline__
+#include_next "bits/shared_ptr_base.h"
+
+#pragma pop_macro("__noinline__")
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -257,6 +257,7 @@
   cuda_wrappers/cmath
   cuda_wrappers/complex
   cuda_wrappers/new
+  cuda_wrappers/bits/shared_ptr_base.h
 )
 
 set(ppc_wrapper_files
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148505: Allow `__attribute__((warn_unused))` on individual constructors

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D148505#4300483 , @sberg wrote:

>> But the fact that these two attributes already confuse users (AND we've got 
>> unused as an attribute in the mix as well, which doesn't help) means we 
>> should proceed with caution (and likely coordinate with GCC given that all 
>> three of these attributes came from their implementation).
>
> I've brought this up at 
> https://gcc.gnu.org/pipermail/gcc/2023-April/241205.html "GCC/Clang 
> attributes guiding warnings about unused entities" now.  (I tried to 
> cross-post that also to the Clang Frontend discourse category, but that 
> probably didn't work.)

Thank you for poking on this! FWIW, I don't know that there's a way to 
cross-post to Discourse (but if I'm wrong and there is, I'd love to know how!).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148505

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


[PATCH] D149276: [Clang] Fix parsing of `(auto(x))`.

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman edited reviewers, added: hubert.reinterpretcast, 
clang-language-wg; removed: jdoerfert.
aaron.ballman added a comment.

The changes generally LGTM, but:

> in a way consistent with the proposed resolution to CWG1223.

What are the chances that CWG changes their mind and picks a different 
direction?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149276

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


[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-04-27 Thread Digger Lin via Phabricator via cfe-commits
DiggerLin added inline comments.



Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:237
 static bool Verbose = false;  ///< 'v' modifier
-static bool Symtab = true;///< 's' modifier
+static WriteSymTabType Symtab = true; ///< 's' modifier
 static bool Deterministic = true; ///< 'D' and 'U' modifiers

jhenderson wrote:
> Maybe I'm missing something, but I don't see why you need to make this a 
> custom type. You already have the BitMode value that you read in from the 
> environment/command-line, and so you can just use that in conjunction with 
> the `Symtab` boolean to determine what symbol table to write, surely?
the Symtab are use to specify whether the symbol table need to write(for 
non-AIX). and what the symbol table need to write for AIX OS.

there are function like

```
  writeArchiveToBuffer(ArrayRef NewMembers,
 WriteSymTabType WriteSymtab, object::Archive::Kind Kind,
 bool Deterministic, bool Thin)
```
and 

```
Error writeArchive(StringRef ArcName, ArrayRef NewMembers,
   WriteSymTabType WriteSymtab, object::Archive::Kind Kind,
   bool Deterministic, bool Thin,
   std::unique_ptr OldArchiveBuf = nullptr);
```

 call the function as 


```
writeArchiveToBuffer(M.second.getMembers(),
 /*WriteSymtab=*/true,
 /*Kind=*/object::Archive::K_DARWIN,
 C.Deterministic,
 /*Thin=*/false); 
```

I do not want to change the calling parameter of the /*WriteSymtab=*/true, 

I introduced a new class WriteSymTabType which has following API

 
```
 WriteSymTabType(bool PrintSym) { Value = PrintSym ? Both : None; }
  void operator=(bool PrintSym) { Value = PrintSym ? Both : None; }
  operator bool() { return Value != None; }
```






Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:1090-1091
+
+// If BigArchive, if there is 32-bit globol symbol table, we still use -X64
+// to generate the 64-bit global symbol table. Same as -X32 option.
+if (OldArchive->kind() == object::Archive::K_AIXBIG) {

jhenderson wrote:
> Just to make sure I'm following what this is trying to say: for Big Archives, 
> a -X64 specification will ignore the 32-bit symbol table and generate a 
> 64-bit one (the 32-bit one will remain in place, if present), and using -X32 
> will cause a 32-bit symbol table to be generated, right?
> 
> Assuming that's the case, I suggest the following as the comment:
> 
> "For archives in the Big Archive format, the bit mode option specifies which 
> symbol table to generate. The presence of a symbol table that does not match 
> the specified bit mode does not prevent creation of the symbol table that has 
> been requested."
yes, you are correct. I change the comment to your suggest.



Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:1421
+  // specified.
+  if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) {
+BitMode = getBitMode(getenv("OBJECT_MODE"));

jhenderson wrote:
> I think you can share this code with the llvm-ar version of the code (put it 
> in a function). You can either add an "AcceptAny" member to that function's 
> argument, or simply check if the value is "Any" after the function here.
In AIX OS ,since  ranlib do not support -Xany. it is different to share code 
with llvm-ar 

-bash-5.0$ ranlib -Xany
0654-602 The specified object mode is not valid.
Specify -X32, -X64, or -X32_64.



Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:1423
+BitMode = getBitMode(getenv("OBJECT_MODE"));
+// -X option in ranlib do not accept "any"
+if (BitMode == BitModeTy::Unknown || BitMode == BitModeTy::Any)

jhenderson wrote:
> Does it treat "any" as "32" or does it report an error? If the latter, should 
> we not do the same here?
-Xany , I will report an error.



Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:1446
+} else if (arg.front() == 'X') {
+  if (object::Archive::getDefaultKindForHost() ==
+  object::Archive::K_AIXBIG) {

jhenderson wrote:
> Similar to above, could we refactor things slightly to share the code for 
> parsing the -X option between llvm-ranlib and llvm-ar?
the logic of parsing option is different with ar_main, it is difficult to share 
the code. and the llvm-ranlib do not support -Xany,  and there only a few lines 
of duplication code, I do not think it worth us to put effort to share the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142660

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


[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-04-27 Thread Digger Lin via Phabricator via cfe-commits
DiggerLin updated this revision to Diff 517638.
DiggerLin marked 9 inline comments as done.
DiggerLin added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

address comment and set option -Xany as invalid option and environment 
OBJECT-MODE=any as invalid too(let it has same behaviors' as "ranlib" of AIX 
OS).

-bash-5.0$ export OBJECT_MODE=31
-bash-5.0$ ranlib  t_X32.a
0654-603 The OBJECT_MODE environment variable has an invalid setting.

  OBJECT_MODE must be 32, 64, or 32_64.

-bash-5.0$ ranlib  -X31 t_X32.a
0654-602 The specified object mode is not valid.

  Specify -X32, -X64, or -X32_64.

-bash-5.0$ export OBJECT_MODE=any
-bash-5.0$ ranlib  t_X32.a
0654-603 The OBJECT_MODE environment variable has an invalid setting.

  OBJECT_MODE must be 32, 64, or 32_64.

-bash-5.0$  ranlib  -Xany nosym.a
0654-602 The specified object mode is not valid.

  Specify -X32, -X64, or -X32_64.

-bash-5.0$  ranlib  -X32 t_X32.a
-bash-5.0$


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142660

Files:
  clang/test/lit.cfg.py
  llvm/include/llvm/Object/Archive.h
  llvm/include/llvm/Object/ArchiveWriter.h
  llvm/lib/Object/Archive.cpp
  llvm/lib/Object/ArchiveWriter.cpp
  llvm/test/tools/llvm-ranlib/aix-X-option.test
  llvm/tools/llvm-ar/llvm-ar.cpp

Index: llvm/tools/llvm-ar/llvm-ar.cpp
===
--- llvm/tools/llvm-ar/llvm-ar.cpp
+++ llvm/tools/llvm-ar/llvm-ar.cpp
@@ -76,7 +76,9 @@
  << "  -v --version  - Display the version of this program\n"
  << "  -D- Use zero for timestamps and uids/gids "
 "(default)\n"
- << "  -U- Use actual timestamps and uids/gids\n";
+ << "  -U- Use actual timestamps and uids/gids\n"
+ << "  -X {32|64|32_64}  - Specifies the type of object files"
+"llvm-ranlib should examine (AIX OS only)\n";
 }
 
 static void printArHelp(StringRef ToolName) {
@@ -96,7 +98,7 @@
 =windows-   windows
   --thin- create a thin archive
   --version - print the version and exit
-  -X{32|64|32_64|any}   - object mode (only for AIX OS)
+  -X {32|64|32_64}   - object mode (only for AIX OS)
   @   - read options from 
 
 OPERATIONS:
@@ -232,7 +234,7 @@
 static bool CompareFullPath = false;  ///< 'P' modifier
 static bool OnlyUpdate = false;   ///< 'u' modifier
 static bool Verbose = false;  ///< 'v' modifier
-static bool Symtab = true;///< 's' modifier
+static WriteSymTabType Symtab = true; ///< 's' modifier
 static bool Deterministic = true; ///< 'D' and 'U' modifiers
 static bool Thin = false; ///< 'T' modifier
 static bool AddLibrary = false;   ///< 'L' modifier
@@ -1081,9 +1083,25 @@
   // In summary, we only need to update the symbol table if we have none.
   // This is actually very common because of broken build systems that think
   // they have to run ranlib.
-  if (OldArchive->hasSymbolTable())
-return;
+  if (OldArchive->hasSymbolTable()) {
+if (OldArchive->kind() != object::Archive::K_AIXBIG)
+  return;
+
+// If BigArchive, if there is 32-bit globol symbol table, we still use -X64
+// to generate the 64-bit global symbol table. Same as -X32 option.
+if (OldArchive->kind() == object::Archive::K_AIXBIG) {
+  BigArchive *BigArc = dyn_cast(OldArchive);
+  if (BigArc->has32BitGlobalSymtab() &&
+  Symtab.getBitMode() == WriteSymTabType::BitMode::Bit32)
+return;
 
+  if (BigArc->has64BitGlobalSymtab() &&
+  Symtab.getBitMode() == WriteSymTabType::BitMode::Bit64)
+return;
+
+  Symtab.setBitMode(WriteSymTabType::BitMode::Both);
+}
+  }
   if (OldArchive->isThin())
 Thin = true;
   performWriteOperation(CreateSymTab, OldArchive, nullptr, nullptr);
@@ -1257,6 +1275,7 @@
 
 static BitModeTy getBitMode(const char *RawBitMode) {
   return StringSwitch(RawBitMode)
+  .Case("", BitModeTy::Bit32)
   .Case("32", BitModeTy::Bit32)
   .Case("64", BitModeTy::Bit64)
   .Case("32_64", BitModeTy::Bit32_64)
@@ -1396,6 +1415,8 @@
 
 static int ranlib_main(int argc, char **argv) {
   std::vector Archives;
+
+  bool HasAixXOption = false;
   for (int i = 1; i < argc; ++i) {
 StringRef arg(argv[i]);
 if (handleGenericOption(arg)) {
@@ -1413,6 +1434,22 @@
 } else if (arg.front() == 'v') {
   cl::PrintVersionMessage();
   return 0;
+} else if (arg.front() == 'X') {
+  if (object::Archive::getDefaultKindForHost() ==
+  object::Archive::K_AIXBIG) {
+HasAixXOption = true;
+arg.consume_front("X");
+BitMode = getBitMode(arg.data());
+// -X option in ranlib do not accept "any"
+if (BitMode == 

[PATCH] D147928: [clang] Keep multiple-include optimization for null directives

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd7354fb63471: Keep multiple-include optimization for null 
directives (authored by IncludeGuardian, committed by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147928

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Lex/MultipleIncludeOpt.h
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/multiple-inclusion-opt.cpp
  clang/test/Preprocessor/multiple-inclusion-opt.h


Index: clang/test/Preprocessor/multiple-inclusion-opt.h
===
--- /dev/null
+++ clang/test/Preprocessor/multiple-inclusion-opt.h
@@ -0,0 +1,18 @@
+# // null directive and comments before include guard
+
+#ifndef MULTIPLE_INCLUSION_OPT
+
+int foo();
+
+// The position of the define should not matter
+#define MULTIPLE_INCLUSION_OPT
+
+int bar();
+
+#endif
+
+#
+#
+/* Two null directives
+   and a multiline comment
+   after the #endif */
Index: clang/test/Preprocessor/multiple-inclusion-opt.cpp
===
--- /dev/null
+++ clang/test/Preprocessor/multiple-inclusion-opt.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -E -P -H %s 2>&1 | grep "multiple-inclusion-opt.h" | count 1
+
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1177,6 +1177,10 @@
 
   switch (Result.getKind()) {
   case tok::eod:
+// Ignore the null directive with regards to the multiple-include
+// optimization, i.e. allow the null directive to appear outside of the
+// include guard and still enable the multiple-include optimization.
+CurPPLexer->MIOpt.SetReadToken(ReadAnyTokensBeforeDirective);
 return;   // null directive.
   case tok::code_completion:
 setCodeCompletionReached();
Index: clang/include/clang/Lex/MultipleIncludeOpt.h
===
--- clang/include/clang/Lex/MultipleIncludeOpt.h
+++ clang/include/clang/Lex/MultipleIncludeOpt.h
@@ -108,6 +108,12 @@
 ImmediatelyAfterTopLevelIfndef = false;
   }
 
+  /// SetReadToken - Set whether the value of 'ReadAnyTokens'.  Called to
+  /// override when encountering tokens outside of the include guard that have
+  /// no effect if the file in question is is included multiple times (e.g. the
+  /// null directive).
+  void SetReadToken(bool Value) { ReadAnyTokens = Value; }
+
   /// ExpandedMacro - When a macro is expanded with this lexer as the current
   /// buffer, this method is called to disable the MIOpt if needed.
   void ExpandedMacro() { DidMacroExpansion = true; }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -157,6 +157,8 @@
 - A new builtin type trait ``__is_trivially_equaltiy_comparable`` has been 
added,
   which checks whether comparing two instances of a type is equivalent to
   ``memcmp(, , sizeof(T)) == 0``.
+- Clang now ignores null directives outside of the include guard when deciding
+  whether a file can be enabled for the multiple-include optimization.
 
 New Compiler Flags
 --


Index: clang/test/Preprocessor/multiple-inclusion-opt.h
===
--- /dev/null
+++ clang/test/Preprocessor/multiple-inclusion-opt.h
@@ -0,0 +1,18 @@
+# // null directive and comments before include guard
+
+#ifndef MULTIPLE_INCLUSION_OPT
+
+int foo();
+
+// The position of the define should not matter
+#define MULTIPLE_INCLUSION_OPT
+
+int bar();
+
+#endif
+
+#
+#
+/* Two null directives
+   and a multiline comment
+   after the #endif */
Index: clang/test/Preprocessor/multiple-inclusion-opt.cpp
===
--- /dev/null
+++ clang/test/Preprocessor/multiple-inclusion-opt.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -E -P -H %s 2>&1 | grep "multiple-inclusion-opt.h" | count 1
+
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1177,6 +1177,10 @@
 
   switch (Result.getKind()) {
   case tok::eod:
+// Ignore the null directive with regards to the multiple-include
+// optimization, i.e. allow the null directive to appear outside of the
+// include guard 

[clang] d7354fb - Keep multiple-include optimization for null directives

2023-04-27 Thread Aaron Ballman via cfe-commits

Author: Elliot Goodrich
Date: 2023-04-27T13:44:11-04:00
New Revision: d7354fb63471a7a38993280c8264fd8d57432dc7

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

LOG: Keep multiple-include optimization for null directives

The multiple-include optimization allows Clang to avoid opening a
files when they contain #pragma once or a proper include guard.

Both GCC and Microsoft Visual Studio allow null directives outside of
the #ifndef/#endif pair without disabling this multiple-include
optimization. GCC documents this behavior here
https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html.

> There must be no directives outside the controlling directive pair,
> but the null directive (a line containing nothing other than a
> single '#' and possibly whitespace) is permitted.

However, Clang disables the multiple-include optimization when
encountering the null directive.

In particular, this slows down preprocessing of most projects that
depend on boost as many boost libraries depend on the boost
preprocessor library, which contains null directives outside the
include guard on every header file.

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

Added: 
clang/test/Preprocessor/multiple-inclusion-opt.cpp
clang/test/Preprocessor/multiple-inclusion-opt.h

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Lex/MultipleIncludeOpt.h
clang/lib/Lex/PPDirectives.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 85eb445a87392..71b197a2ad297 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,8 @@ Non-comprehensive list of changes in this release
 - A new builtin type trait ``__is_trivially_equaltiy_comparable`` has been 
added,
   which checks whether comparing two instances of a type is equivalent to
   ``memcmp(, , sizeof(T)) == 0``.
+- Clang now ignores null directives outside of the include guard when deciding
+  whether a file can be enabled for the multiple-include optimization.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Lex/MultipleIncludeOpt.h 
b/clang/include/clang/Lex/MultipleIncludeOpt.h
index 7ceb7e53c75d7..8e570226c4b27 100644
--- a/clang/include/clang/Lex/MultipleIncludeOpt.h
+++ b/clang/include/clang/Lex/MultipleIncludeOpt.h
@@ -108,6 +108,12 @@ class MultipleIncludeOpt {
 ImmediatelyAfterTopLevelIfndef = false;
   }
 
+  /// SetReadToken - Set whether the value of 'ReadAnyTokens'.  Called to
+  /// override when encountering tokens outside of the include guard that have
+  /// no effect if the file in question is is included multiple times (e.g. the
+  /// null directive).
+  void SetReadToken(bool Value) { ReadAnyTokens = Value; }
+
   /// ExpandedMacro - When a macro is expanded with this lexer as the current
   /// buffer, this method is called to disable the MIOpt if needed.
   void ExpandedMacro() { DidMacroExpansion = true; }

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 3132d57a62d3f..7e4ba9851446a 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1177,6 +1177,10 @@ void Preprocessor::HandleDirective(Token ) {
 
   switch (Result.getKind()) {
   case tok::eod:
+// Ignore the null directive with regards to the multiple-include
+// optimization, i.e. allow the null directive to appear outside of the
+// include guard and still enable the multiple-include optimization.
+CurPPLexer->MIOpt.SetReadToken(ReadAnyTokensBeforeDirective);
 return;   // null directive.
   case tok::code_completion:
 setCodeCompletionReached();

diff  --git a/clang/test/Preprocessor/multiple-inclusion-opt.cpp 
b/clang/test/Preprocessor/multiple-inclusion-opt.cpp
new file mode 100644
index 0..0da20331fada6
--- /dev/null
+++ b/clang/test/Preprocessor/multiple-inclusion-opt.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -E -P -H %s 2>&1 | grep "multiple-inclusion-opt.h" | count 1
+
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"
+#include "multiple-inclusion-opt.h"

diff  --git a/clang/test/Preprocessor/multiple-inclusion-opt.h 
b/clang/test/Preprocessor/multiple-inclusion-opt.h
new file mode 100644
index 0..d346c9d5d22e4
--- /dev/null
+++ b/clang/test/Preprocessor/multiple-inclusion-opt.h
@@ -0,0 +1,18 @@
+# // null directive and comments before include guard
+
+#ifndef MULTIPLE_INCLUSION_OPT
+
+int foo();
+
+// The position of the define should not matter
+#define MULTIPLE_INCLUSION_OPT
+
+int bar();
+
+#endif
+
+#
+#
+/* Two null directives
+   and a multiline comment
+   after the #endif */




[PATCH] D149301: [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao 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 rG7417e9d75c9a: [clang] Fix a crash with parenthesized 
aggregate initialization and base classes (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149301

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a 
parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a 
parenthesized list of values is a C++20 extension}}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [](auto ) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), , 
false);
+auto BaseRange = map_range(RD->bases(), [&](auto ) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), , false,
+   );
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [](auto ) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), , false);
+auto BaseRange = map_range(RD->bases(), [&](auto ) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), , false,
+   );
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 

[clang] 7417e9d - [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-04-27T10:43:16-07:00
New Revision: 7417e9d75c9af7dd0d3dad12eebdee84b10b56d7

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

LOG: [clang] Fix a crash with parenthesized aggregate initialization and base 
classes

When calling InitializeBase(...), TryOrBuidlParenListInit(...) needs to
pass in the parent entity; otherwise, we erroneously try to cast
CurContext to a CXXConstructorDecl[0], which can't be done since we're
performing aggregate initialization, not constructor initialization.

Field initialization is not affected, but this patch still adds some
tests for it.

Fixes 62296

[0]: 
https://github.com/llvm/llvm-project/blob/33d6bd1c667456f7f4a9d338a7996a30a3af50a3/clang/lib/Sema/SemaAccess.cpp#L1696

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aff9ce378253..85eb445a8739 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@ Bug Fixes in This Version
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 243c3c1c9a4d..c218470d37ae 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [](auto ) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), , 
false);
+auto BaseRange = map_range(RD->bases(), [&](auto ) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), , false,
+   );
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index a5f39ff6c477..c9d73327025c 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@ void bar() {
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a 
parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a 
parenthesized list of values is a C++20 extension}}
+
+}



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


[PATCH] D149301: [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added a comment.

In D149301#4302621 , @aaron.ballman 
wrote:

> I think you should add a release note for this when landing,

Done

> and this seems pretty reasonable to consider backporting to 16.x, WDYT?

Agreed, given that this is a crash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149301

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


[PATCH] D149301: [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 517636.
ayzhao added a comment.

add release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149301

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a 
parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a 
parenthesized list of values is a C++20 extension}}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [](auto ) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), , 
false);
+auto BaseRange = map_range(RD->bases(), [&](auto ) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), , false,
+   );
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a parenthesized list of values is a C++20 extension}}
+
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [](auto ) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), , false);
+auto BaseRange = map_range(RD->bases(), [&](auto ) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), , false,
+   );
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added a comment.

In D149193#4302337 , @scott.linder 
wrote:

> In D149193#4300885 , @MaskRay wrote:
>
>> I think the patch as-is implements all the useful parts of GCC's complex 
>> rules and in the absence of `-dumpbase` (we deliberately don't implement), 
>> the rule almost exactly matches GCC unless we do `gcc -g -gsplit-dwarf d/a.c 
>> -o e/a.out` (instead of other filenames).
>>
>> https://maskray.me/blog/2023-04-25-compiler-output-files records all my 
>> findings.
>
> I agree that the special-casing of `a.out` when explicitly specified is odd.
>
> Another option to avoid any confusion or debates over exact behavior relative 
> to GCC would be to just make our own option. Rather than add `-dumpdir` we 
> could add `-dump-prefix` or something. I'm also OK with just implementing a 
> simpler subset of the GCC options though (i.e. what you have already).

I have thought about this option, using a name like `--aux-prefix=` (I'd prefer 
aux to dump), but since the behaviors are nearly identical (if we ignore the 
GCC `-o d/a.out` special case), I think using `-dumpdir` is still fine, and 
users won't need to remember two options when they have the needs.

I think the GCC `-o e/a.out` special case is a bug to detect `gcc -g 
-gsplit-dwarf d/a.c` (without `-o`; `a.dwo`). If the bug is fixed, its 
`-dumpdir` behavior should be identical (for all the experiments I have done) 
to what this patch implements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


[PATCH] D141451: [clang] report inlining decisions with -Wattribute-{warning|error}

2023-04-27 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/test/Frontend/backend-attribute-error-warning-optimize.c:12
   foo(); // expected-error {{call to 'foo' declared with 'error' attribute: oh 
no foo}}
+ // expected-note@* {{In function 'baz'}}
   if (x())

aaron.ballman wrote:
> nickdesaulniers wrote:
> > cjdb wrote:
> > > aaron.ballman wrote:
> > > > nickdesaulniers wrote:
> > > > > nickdesaulniers wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > Instead of allowing this note to appear anywhere in the file, I 
> > > > > > > think it's better to use "bookmark" comments. e.g.,
> > > > > > > ```
> > > > > > > void baz() { // #baz_defn
> > > > > > > }
> > > > > > > 
> > > > > > > void foo() {
> > > > > > >   baz(); // expected-note@#baz_defn {{whatever note text}}
> > > > > > > }
> > > > > > > ```
> > > > > > > so that we're testing where the diagnostic is emitted. (This is 
> > > > > > > especially important given that the changes are about location 
> > > > > > > tracking.)
> > > > > > oh, that's new (to me)! will do
> > > > > It looks like the "bookmarks" don't work because the notes do not 
> > > > > line+col info. They follow the warning/error diagnostic which does, 
> > > > > on the bottom most call site.
> > > > > 
> > > > > The warning is supposed to be emitted on the callsite, not the 
> > > > > definition.
> > > > I still don't think this is reasonable for test coverage because this 
> > > > means we'll accept the note *anywhere* in the file. This makes it much 
> > > > too easy to regress the behavior accidentally (e.g., accidentally emit 
> > > > all the notes on line 1 of the file). I think we need *some* way to 
> > > > nail down where these notes are emitted in the test. However, I might 
> > > > be asking you to solve "please track location information through the 
> > > > backend" for that, so perhaps this isn't a reasonable request?
> > > > 
> > > > Also, CC @cjdb for awareness of how this kind of diagnostic is produced 
> > > > (Chris is working on an idea for how we emit diagnostics so we get 
> > > > better structured information from them, so knowing about this novel 
> > > > approach might impact that idea).
> > > Very interesting, thanks for the heads up! Cross-phase diagnostics are 
> > > definitely something I hadn't considered, and it **does** impact the 
> > > design (but not in a derailing way).
> > I think we're back at "please track location information through the 
> > backend".
> > 
> > That is the tradeoff with this approach; not measurably regressing 
> > performance when these attributes aren't used in source in exchange for 
> > Note diagnostics that lack precise line+col info, but in practice provide 
> > enough info for the user to understand what's going wrong where.
> > 
> > Your call if the tradeoff is worth it.
> Here's my thinking, please correct any misunderstandings I have:
> 
> * This functionality is primarily for use with `_FORTIFY_SOURCE` (but not 
> solely for that purpose), and that's an important security feature used by 
> glibc and the Linux kernel.
> * Security of C and C++ source code is Very Important, especially now that 
> various gov't agencies [1][2] are suggesting to not use C or C++ for new 
> projects specifically because the security posture of the languages and their 
> tools.
> * Therefore, the ergonomics of this functionality are quite important for the 
> intended use cases and the ecosystem as a whole.
> * Emitting only the function name but without location information does not 
> give a good user experience, especially in circumstances where the function 
> has multiple overloads, because it pushes the burden onto the programmer to 
> figure out which functions are actually involved in the call chain. This 
> issue is also present in C because of support for 
> `__attribute__((overloadable))` and is not just a C++ concern.
> * The compile-time performance costs of tracking this location information 
> are roughly 1%, and there are no runtime or binary size overhead costs unless 
> other functionality is enabled (such as emitting debug info).
> * We can determine whether we need to enable this location tracking while 
> building the AST when we see one of these two attributes being used, so we 
> could enable this functionality selectively without burdening the user with 
> enabling it manually via a flag. (We could still consider giving the user a 
> flag to never track this even in the presence of the attributes if a user had 
> a compelling use case for it.)
> 
> If this is all reasonably accurate, I think it's worth seriously considering 
> accepting the costs. I don't want to increase our compile time overhead, but 
> at the same time, if ~1% is a "make or break" amount of compile-time 
> performance to lose, we should be addressing *that* issue rather than 
> hamstringing a user-facing diagnostic feature related to security. It's hard 
> to argue "that CVE was totally worth it because we 

[PATCH] D149301: [clang] Fix a crash with parenthesized aggregate initialization and base classes

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

LGTM, good catch! I think you should add a release note for this when landing, 
and this seems pretty reasonable to consider backporting to 16.x, WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149301

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D149314#4302342 , @asb wrote:

> In D149314#4302312 , @reames wrote:
>
>> In D149314#4302300 , 
>> @aaron.ballman wrote:
>>
>>> In D149314#4302266 , @asb wrote:
>>>
 In D149314#4302203 , 
 @aaron.ballman wrote:

> Is this a potentially breaking change that we need to call out for users 
> to be aware of?

 We should mention this in the Clang release notes I think.
>>>
>>> Beyond that, we've got a process for what to do when considering 
>>> potentially breaking changes, we should be following that: 
>>> https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes
>>>  Also, if we're all agreed this is potentially breaking, it really should 
>>> have more review time and buy-in from the code owner.
>>
>> I don't think this change should count as "potentially breaking" in the 
>> sense of that document.  We're talking about an experimental feature for an 
>> experimental ISA extension which never got to ratification.  There's no 
>> hardware in the wild which implements this (to my knowledge).  Given the 
>> churn on the RISCV extension side, we've adopted a policy for experimental 
>> extensions (https://llvm.org/docs/RISCVUsage.html#experimental-extensions) 
>> which offers much less in the way of support.  I think we should release 
>> note it just to be friendly, but the process described in your link is 
>> significant overkill.
>
> +1 on this. The upstream (RISC-V side) process for the ISA extension 
> lifecycle and their ratification is now properly established, and we gate 
> not-yet-ratified things behind `-menable-experimental-extensions` going 
> forward. This review perhaps could have been held open a bit longer to check 
> there's no concerns, and thanks to Aaron for raising the question. But I 
> think a release note only is the appropriate option here.

SGTM, thank you for the discussion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D132819: [RISCV] Add MC support of RISCV zcmp Extension

2023-04-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:3150
+  SMLoc Loc = Operands[1]->getStartLoc();
+  return Error(Loc, "'rs1' and 'rs2' mast be different.");
+}

mast -> must


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132819

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


[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-04-27 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 517616.
skatrak added a comment.

Remove checks from lowering that belong in semantic analysis


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

Files:
  flang/include/flang/Lower/OpenMP.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/OpenMP.cpp
  flang/test/Lower/OpenMP/requires-error.f90
  flang/test/Lower/OpenMP/requires-notarget.f90
  flang/test/Lower/OpenMP/requires.f90

Index: flang/test/Lower/OpenMP/requires.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires.f90
@@ -0,0 +1,14 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks the lowering of requires into MLIR
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.atomic_default_mem_order = #omp
+!CHECK-SAME: omp.requires = #omp
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f
+  !$omp declare target
+end subroutine f
Index: flang/test/Lower/OpenMP/requires-notarget.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-notarget.f90
@@ -0,0 +1,12 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.atomic_default_mem_order = #omp
+!CHECK-NOT:  omp.requires
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
Index: flang/test/Lower/OpenMP/requires-error.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-error.f90
@@ -0,0 +1,15 @@
+! RUN: not %flang_fc1 -emit-fir -fopenmp %s -o - 2>&1 | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  error: {{.*}} conflicting atomic_default_mem_order clause found:
+!CHECK-SAME: acq_rel != seq_cst
+program requires
+  !$omp requires atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f()
+  !$omp requires atomic_default_mem_order(acq_rel)
+end subroutine f
Index: flang/lib/Lower/OpenMP.cpp
===
--- flang/lib/Lower/OpenMP.cpp
+++ flang/lib/Lower/OpenMP.cpp
@@ -24,7 +24,9 @@
 #include "flang/Semantics/tools.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Dialect/SCF/IR/SCF.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
 
 using namespace mlir;
 
@@ -2239,11 +2241,13 @@
   converter.bindSymbol(sym, symThreadprivateExv);
 }
 
-void handleDeclareTarget(Fortran::lower::AbstractConverter ,
- Fortran::lower::pft::Evaluation ,
- const Fortran::parser::OpenMPDeclareTargetConstruct
- ) {
-  llvm::SmallVector symbols;
+/// Extract the list of function and variable symbols affected by the given
+/// 'declare target' directive and return the intended device type for them.
+static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo(
+Fortran::lower::pft::Evaluation ,
+const Fortran::parser::OpenMPDeclareTargetConstruct ,
+SmallVectorImpl ) {
+  // Gather the symbols
   auto findFuncAndVarSyms = [&](const Fortran::parser::OmpObjectList ) {
 for (const auto  : objList.v) {
   Fortran::common::visit(
@@ -2261,12 +2265,11 @@
 }
   };
 
+  // The default capture type
+  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   const auto {std::get(
   declareTargetConstruct.t)};
-  auto mod = converter.getFirOpBuilder().getModule();
 
-  // The default capture type
-  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   if (const auto *objectList{
   Fortran::parser::Unwrap(spec.u)}) {
 // Case: declare target(func, var1, var2)
@@ -2288,8 +2291,7 @@
  std::get_if(
  )}) {
 // Case: declare target link(var1, var2)...
-TODO(converter.getCurrentLocation(),
- "the link clause is currently unsupported");
+TODO_NOLOC("the link clause is currently unsupported");
   } else if (const auto *deviceClause{
  std::get_if(
  )}) {
@@ -2299,6 +2301,24 @@
 }
   }
 
+  switch (deviceType) {
+  case Fortran::parser::OmpDeviceTypeClause::Type::Any:
+return mlir::omp::DeclareTargetDeviceType::any;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Host:
+return 

[PATCH] D149123: [AArch64][InlineAsm]Add Clang support for flag output constraints

2023-04-27 Thread Mingming Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ab76b77cee0: [AArch64][InlineAsm]Add Clang support for flag 
output constraints (authored by mingmingl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149123

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/test/CodeGen/inline-asm-aarch64-flag-output.c
  clang/test/Preprocessor/aarch64_asm_flag_output.c
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/predefined-win-macros.c

Index: clang/test/Preprocessor/predefined-win-macros.c
===
--- clang/test/Preprocessor/predefined-win-macros.c
+++ clang/test/Preprocessor/predefined-win-macros.c
@@ -129,4 +129,5 @@
 // CHECK-ARM64-MINGW: #define WINNT 1
 // CHECK-ARM64-MINGW: #define _WIN32 1
 // CHECK-ARM64-MINGW: #define _WIN64 1
+// CHECK-ARM64-MINGW: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // CHECK-ARM64-MINGW: #define __aarch64__ 1
Index: clang/test/Preprocessor/init-aarch64.c
===
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -106,6 +106,7 @@
 // AARCH64-NEXT: #define __FLT_RADIX__ 2
 // AARCH64-NEXT: #define __FP_FAST_FMA 1
 // AARCH64-NEXT: #define __FP_FAST_FMAF 1
+// AARCH64-NEXT: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
 // AARCH64-NEXT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
Index: clang/test/Preprocessor/aarch64_asm_flag_output.c
===
--- /dev/null
+++ clang/test/Preprocessor/aarch64_asm_flag_output.c
@@ -0,0 +1,3 @@
+// RUN: %clang -target aarch64-unknown-unknown -x c -E -dM -o - %s | FileCheck -match-full-lines %s
+
+// CHECK: #define __GCC_ASM_FLAG_OUTPUTS__ 1
Index: clang/test/CodeGen/inline-asm-aarch64-flag-output.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-asm-aarch64-flag-output.c
@@ -0,0 +1,130 @@
+// RUN: %clang_cc1 -O2 -emit-llvm %s -o - -triple aarch64 | FileCheck %s
+
+int test_cceq(int a, int* b) {
+// CHECK-LABEL: @test_cceq
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cceq},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cceq"(*b));
+  return a;
+}
+
+int test_ccne(int a, int* b) {
+// CHECK-LABEL: @test_ccne
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccne},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccne"(*b));
+  return a;
+}
+
+int test_cccs(int a, int* b) {
+// CHECK-LABEL: @test_cccs
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cccs},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cccs"(*b));
+  return a;
+}
+
+int test_cchs(int a, int* b) {
+// CHECK-LABEL: @test_cchs
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cchs},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cchs"(*b));
+  return a;
+}
+
+int test_(int a, int* b) {
+// CHECK-LABEL: @test_
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@"(*b));
+  return a;
+}
+
+int test_cclo(int a, int* b) {
+// CHECK-LABEL: @test_cclo
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cclo},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@cclo"(*b));
+  return a;
+}
+
+int test_ccmi(int a, int* b) {
+// CHECK-LABEL: @test_ccmi
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccmi},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccmi"(*b));
+  return a;
+}
+
+int test_ccpl(int a, int* b) {
+// CHECK-LABEL: @test_ccpl
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccpl},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccpl"(*b));
+  return a;
+}
+
+int test_ccvs(int a, int* b) {
+// CHECK-LABEL: @test_ccvs
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccvs},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccvs"(*b));
+  return a;
+}
+
+int test_ccvc(int a, int* b) {
+// CHECK-LABEL: @test_ccvc
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@ccvc},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), "=@ccvc"(*b));
+  return a;
+}
+
+int test_cchi(int a, int* b) {
+// CHECK-LABEL: @test_cchi
+// CHECK: = tail call { i32, i32 } asm "ands ${0:w}, ${0:w}, #3", "=r,={@cchi},0"(i32 %a)
+  asm("ands %w[a], %w[a], #3"
+  : [a] "+r"(a), 

[clang] 4ab76b7 - [AArch64][InlineAsm]Add Clang support for flag output constraints

2023-04-27 Thread Mingming Liu via cfe-commits

Author: Mingming Liu
Date: 2023-04-27T09:39:08-07:00
New Revision: 4ab76b77cee0e27510d5d5cb3072ee7e92d96eec

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

LOG: [AArch64][InlineAsm]Add Clang support for flag output constraints

- Mention this change in Clang release notes

Before:
- Clang emits "invalid output constraint '=@cceq' in asm" 
https://gcc.godbolt.org/z/b9crfEo8h

After:
- For aarch64 targets (with __aarch64__ defined), Clang validates and parses 
flag output constraints to generate LLVM IR.

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

Added: 
clang/test/CodeGen/inline-asm-aarch64-flag-output.c
clang/test/Preprocessor/aarch64_asm_flag_output.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/test/Preprocessor/init-aarch64.c
clang/test/Preprocessor/predefined-win-macros.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 26fdffe920e95..aff9ce3782532 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -416,6 +416,15 @@ Arm and AArch64 Support
 - Clang builtin ``__arithmetic_fence`` and the command line option 
``-fprotect-parens``
   are now enabled for AArch64.
 
+- Clang supports flag output operands by which conditions in the NZCV could be 
outputs
+  of inline assembly for AArch64. This change is more consistent with the 
behavior of
+  GCC.
+
+   .. code-block:: c
+
+ // int a = foo(); int* b = bar();
+ asm("ands %w[a], %w[a], #3" : [a] "+r"(a), "=@cceq"(*b));
+
 Windows Support
 ^^^
 

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 67ba5f6b35145..3840139d27434 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -333,6 +333,8 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
,
  MacroBuilder ) const {
   // Target identification.
   Builder.defineMacro("__aarch64__");
+  // Inline assembly supports AArch64 flag outputs.
+  Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
   // For bare-metal.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   getTriple().isOSBinFormatELF())
@@ -1210,6 +1212,52 @@ ArrayRef 
AArch64TargetInfo::getGCCRegAliases() const {
   return llvm::ArrayRef(GCCRegAliases);
 }
 
+// Returns the length of cc constraint.
+static unsigned matchAsmCCConstraint(const char *Name) {
+  constexpr unsigned len = 5;
+  auto RV = llvm::StringSwitch(Name)
+.Case("@cceq", len)
+.Case("@ccne", len)
+.Case("@cchs", len)
+.Case("@cccs", len)
+.Case("@", len)
+.Case("@cclo", len)
+.Case("@ccmi", len)
+.Case("@ccpl", len)
+.Case("@ccvs", len)
+.Case("@ccvc", len)
+.Case("@cchi", len)
+.Case("@ccls", len)
+.Case("@ccge", len)
+.Case("@cclt", len)
+.Case("@ccgt", len)
+.Case("@ccle", len)
+.Default(0);
+  return RV;
+}
+
+std::string
+AArch64TargetInfo::convertConstraint(const char *) const {
+  std::string R;
+  switch (*Constraint) {
+  case 'U': // Three-character constraint; add "@3" hint for later parsing.
+R = std::string("@3") + std::string(Constraint, 3);
+Constraint += 2;
+break;
+  case '@':
+if (const unsigned Len = matchAsmCCConstraint(Constraint)) {
+  std::string Converted = "{" + std::string(Constraint, Len) + "}";
+  Constraint += Len - 1;
+  return Converted;
+}
+return std::string(1, *Constraint);
+  default:
+R = TargetInfo::convertConstraint(Constraint);
+break;
+  }
+  return R;
+}
+
 bool AArch64TargetInfo::validateAsmConstraint(
 const char *, TargetInfo::ConstraintInfo ) const {
   switch (*Name) {
@@ -1257,6 +1305,13 @@ bool AArch64TargetInfo::validateAsmConstraint(
   case 'y': // SVE registers (V0-V7)
 Info.setAllowsRegister();
 return true;
+  case '@':
+// CC condition
+if (const unsigned Len = matchAsmCCConstraint(Name)) {
+  Name += Len - 1;
+  Info.setAllowsRegister();
+  return true;
+}
   }
   return false;
 }

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 967a888f6b6f8..cce80e10f2bb1 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -173,19 +173,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   ArrayRef getGCCRegNames() const override;
   ArrayRef getGCCRegAliases() const override;
 
-  std::string convertConstraint(const char *) 

[PATCH] D148601: [Clang] Handle Error message to output proper Prefix

2023-04-27 Thread Usman Akinyemi via Phabricator via cfe-commits
Unique_Usman added a comment.

In D148601#4301977 , @aaron.ballman 
wrote:

> Thank you for working on this! These changes should come with test coverage 
> (we have a handful of verifier tests in `clang/test/Frontend` -- you can add 
> a new test file there), but I don't think a release note is required because 
> this is a fix for internal functionality. The test should cover the simple 
> case of `-verify=something` as well as a more complex test with 
> `-verify=something, something_else`.

Thank you, will work on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148601

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

In D149314#4302312 , @reames wrote:

> In D149314#4302300 , @aaron.ballman 
> wrote:
>
>> In D149314#4302266 , @asb wrote:
>>
>>> In D149314#4302203 , 
>>> @aaron.ballman wrote:
>>>
 Is this a potentially breaking change that we need to call out for users 
 to be aware of?
>>>
>>> We should mention this in the Clang release notes I think.
>>
>> Beyond that, we've got a process for what to do when considering potentially 
>> breaking changes, we should be following that: 
>> https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes
>>  Also, if we're all agreed this is potentially breaking, it really should 
>> have more review time and buy-in from the code owner.
>
> I don't think this change should count as "potentially breaking" in the sense 
> of that document.  We're talking about an experimental feature for an 
> experimental ISA extension which never got to ratification.  There's no 
> hardware in the wild which implements this (to my knowledge).  Given the 
> churn on the RISCV extension side, we've adopted a policy for experimental 
> extensions (https://llvm.org/docs/RISCVUsage.html#experimental-extensions) 
> which offers much less in the way of support.  I think we should release note 
> it just to be friendly, but the process described in your link is significant 
> overkill.

+1 on this. The upstream (RISC-V side) process for the ISA extension lifecycle 
and their ratification is now properly established, and we gate 
not-yet-ratified things behind `-menable-experimental-extensions` going 
forward. This review perhaps could have been held open a bit longer to check 
there's no concerns, and thanks to Aaron for raising the question. But I think 
a release note only is the appropriate option here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 517595.
dankm added a comment.

Correct test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

Files:
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclarationName.cpp
  clang/test/CodeGen/debug-prefix-map.cpp


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const 
{
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const {
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-27 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D149193#4300885 , @MaskRay wrote:

> I think the patch as-is implements all the useful parts of GCC's complex 
> rules and in the absence of `-dumpbase` (we deliberately don't implement), 
> the rule almost exactly matches GCC unless we do `gcc -g -gsplit-dwarf d/a.c 
> -o e/a.out` (instead of other filenames).
>
> https://maskray.me/blog/2023-04-25-compiler-output-files records all my 
> findings.

I agree that the special-casing of `a.out` when explicitly specified is odd.

Another option to avoid any confusion or debates over exact behavior relative 
to GCC would be to just make our own option. Rather than add `-dumpdir` we 
could add `-dump-prefix` or something. I'm also OK with just implementing a 
simpler subset of the GCC options though (i.e. what you have already).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149193

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+

dankm wrote:
> aaron.ballman wrote:
> > I'm taking a guess at correcting the RUN line here, but more tweaks may be 
> > needed. Basically, `%clang++` isn't a thing, so this test fails. Most of 
> > our tests should be testing `%clang_cc1` to test the frontend invocation, 
> > but some of the debug prefix map tests use `%clang` to test the driver 
> > functionality. I don't think there's a need to test the driver here, so I 
> > went with `%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is 
> > necessary or not, but the other tests seem to be using that, which may be 
> > worth paying attention to.
> > 
> > Finally, there's no need to have a custom check prefix for `FileCheck`, the 
> > builtin `CHECK` prefix suffices.
> Okay, noted about clang++, it did work for me locally, but that doesn't mean 
> it's correct. Good point about only testing the frontend action, the driver 
> test is unnecessary.
> 
> The custom check prefix is just a cut & paste artefact from copying from the 
> C version of the debug-prefix-map test, originally I was going to update that 
> test to a C++ file but opted later for just creating a new test.
Ah, I see now it failed on the windows build in my test. Neat.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D149314#4302312 , @reames wrote:

> In D149314#4302300 , @aaron.ballman 
> wrote:
>
>> In D149314#4302266 , @asb wrote:
>>
>>> In D149314#4302203 , 
>>> @aaron.ballman wrote:
>>>
 Is this a potentially breaking change that we need to call out for users 
 to be aware of?
>>>
>>> We should mention this in the Clang release notes I think.
>>
>> Beyond that, we've got a process for what to do when considering potentially 
>> breaking changes, we should be following that: 
>> https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes
>>  Also, if we're all agreed this is potentially breaking, it really should 
>> have more review time and buy-in from the code owner.
>
> I don't think this change should count as "potentially breaking" in the sense 
> of that document.  We're talking about an experimental feature for an 
> experimental ISA extension which never got to ratification.  There's no 
> hardware in the wild which implements this (to my knowledge).  Given the 
> churn on the RISCV extension side, we've adopted a policy for experimental 
> extensions (https://llvm.org/docs/RISCVUsage.html#experimental-extensions) 
> which offers much less in the way of support.  I think we should release note 
> it just to be friendly, but the process described in your link is significant 
> overkill.

If we don't need to use that process, it's totally reasonable to skip it. It 
wasn't clear just how disruptive this change is from the review summary and 
there was not really any chance for discussion before this landed. Release 
noting it would be fine by me if the folks with more knowledge in this area 
think that's sufficient.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Philip Reames via Phabricator via cfe-commits
reames added a comment.

In D149314#4302300 , @aaron.ballman 
wrote:

> In D149314#4302266 , @asb wrote:
>
>> In D149314#4302203 , 
>> @aaron.ballman wrote:
>>
>>> Is this a potentially breaking change that we need to call out for users to 
>>> be aware of?
>>
>> We should mention this in the Clang release notes I think.
>
> Beyond that, we've got a process for what to do when considering potentially 
> breaking changes, we should be following that: 
> https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes
>  Also, if we're all agreed this is potentially breaking, it really should 
> have more review time and buy-in from the code owner.

I don't think this change should count as "potentially breaking" in the sense 
of that document.  We're talking about an experimental feature for an 
experimental ISA extension which never got to ratification.  There's no 
hardware in the wild which implements this (to my knowledge).  Given the churn 
on the RISCV extension side, we've adopted a policy for experimental extensions 
(https://llvm.org/docs/RISCVUsage.html#experimental-extensions) which offers 
much less in the way of support.  I think we should release note it just to be 
friendly, but the process described in your link is significant overkill.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: erichkeane.
aaron.ballman added a comment.

In D149314#4302266 , @asb wrote:

> In D149314#4302203 , @aaron.ballman 
> wrote:
>
>> Is this a potentially breaking change that we need to call out for users to 
>> be aware of?
>
> We should mention this in the Clang release notes I think.

Beyond that, we've got a process for what to do when considering potentially 
breaking changes, we should be following that: 
https://llvm.org/docs/DeveloperPolicy.html#making-potentially-breaking-changes 
Also, if we're all agreed this is potentially breaking, it really should have 
more review time and buy-in from the code owner.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


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

2023-04-27 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

In D146557#4301955 , @TIFitis wrote:

> In D146557#4295550 , 
> @kiranchandramohan wrote:
>
>> In D146557#4292223 , @TIFitis 
>> wrote:
>>
>>> Cleaned up how IsBegin argument is passed for createTargetData call.
>>
>> Please submit this directly as an NFC patch.
>
> I have merged it separately.
>
>> We should always work towards simple patches that are easy to review. 
>> Sometimes a big patch is required to give the full context. But it can then 
>> be broken up into small patches for faster review. I have created D149153 
>>  for the `inlineConvertOmpRegions` change.
>
> Thanks for creating your patch. I'll try to make my patches shorter in the 
> future.
>
> Once D149153  is merged I'll rebase this 
> patch.

I have submitted D149153 . 
https://github.com/llvm/llvm-project/commit/1ed522623d95ce7dcf95e711b0f2e3844d2e6be1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+

aaron.ballman wrote:
> I'm taking a guess at correcting the RUN line here, but more tweaks may be 
> needed. Basically, `%clang++` isn't a thing, so this test fails. Most of our 
> tests should be testing `%clang_cc1` to test the frontend invocation, but 
> some of the debug prefix map tests use `%clang` to test the driver 
> functionality. I don't think there's a need to test the driver here, so I 
> went with `%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is 
> necessary or not, but the other tests seem to be using that, which may be 
> worth paying attention to.
> 
> Finally, there's no need to have a custom check prefix for `FileCheck`, the 
> builtin `CHECK` prefix suffices.
Okay, noted about clang++, it did work for me locally, but that doesn't mean 
it's correct. Good point about only testing the frontend action, the driver 
test is unnecessary.

The custom check prefix is just a cut & paste artefact from copying from the C 
version of the debug-prefix-map test, originally I was going to update that 
test to a C++ file but opted later for just creating a new test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272

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


[PATCH] D148088: [RFC][clangd] Move preamble index task to a seperate task

2023-04-27 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D148088#4302182 , @kuganv wrote:

> 1. We see preamble indexing taking as much as 18% of the time for some files. 
>  Moving  preamble indexing out of the critical path helps there.

Which operation are you measuring? 18% of first diagnostic latency?
Preamble indexing populates necessary information for many of the Clangd 
features. Some examples of the top of my head:

- code completion will not show declarations from preamble if they were not 
deserialized from the preamble (most symbols).
- diagnostics from preamble,
- multi-file rename will miss references inside template bodies.

Doing indexing of the preamble in parallel to other operations is probably an 
improvement as PCH gets available earlier for operations that need it, e.g. 
code completion can start operating faster.
However, if we want to ensure the returned results are the same as they were 
before the patch (at least for the first run), we have to synchronize with the 
operations that populates the index.

For any form of this optimization, I think the implementation is going to be a 
little tricky and we definitely want @kadircet to take a look at it. It's hard 
to list all things in Clangd that rely on preamble indexing
finishing before they run, this change definitely requires a careful design 
review.

> 2. We are also experimenting with preamble caching with clang modules. Early 
> results from this also shows that preamble indexing outside  the critical 
> path improves performance.

Could you elaborate a bit more on what is being cached with modules and how 
this patch would affect it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148088

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

In D149314#4302203 , @aaron.ballman 
wrote:

> Is this a potentially breaking change that we need to call out for users to 
> be aware of?

We should mention this in the Clang release notes I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D141627: [Clang][OpenMP] Fix the issue that list items in `has_device_addr` are still mapped to the target device

2023-04-27 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

If it is okay with is_divece_ptr.  I am okay with it.
Please add a lit test for this?

Thanks.
Jennifer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141627

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


[PATCH] D149352: [clang-format] Recognize Verilog type dimension in module header

2023-04-27 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added a reviewer: curdeius.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
sstwcw requested review of this revision.

We had the function `verilogGroupDecl` for that.  However, the type
name would be incorrectly annotated in `isStartOfName` when it was not
a C++ keyword and followed another identifier.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149352

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1615,6 +1615,13 @@
   Tokens = Annotate("extern function [1 : 0] x;");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_BitFieldColon);
+  Tokens = Annotate("module test\n"
+"(input wire [7 : 0] a[7 : 0]);\n"
+"endmodule");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_VerilogDimensionedTypeName);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_BitFieldColon);
+  EXPECT_TOKEN(Tokens[13], tok::colon, TT_BitFieldColon);
   // Test case labels and ternary operators.
   Tokens = Annotate("case (x)\n"
 "  x:\n"
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -359,6 +359,12 @@
" input var shortreal in2,\n"
" output tagged_st out);\n"
"endmodule");
+  // There should be a space following the type but not the variable name.
+  verifyFormat("module test\n"
+   "(input wire [7 : 0] a,\n"
+   " input wire b[7 : 0],\n"
+   " input wire [7 : 0] c[7 : 0]);\n"
+   "endmodule");
   // Ports should be grouped by types.
   verifyFormat("module test\n"
"(input [7 : 0] a,\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2161,6 +2161,10 @@
   /// This is a heuristic based on whether \p Tok is an identifier following
   /// something that is likely a type.
   bool isStartOfName(const FormatToken ) {
+// Handled in ExpressionParser for Verilog.
+if (Style.isVerilog())
+  return false;
+
 if (Tok.isNot(tok::identifier) || !Tok.Previous)
   return false;
 


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1615,6 +1615,13 @@
   Tokens = Annotate("extern function [1 : 0] x;");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_BitFieldColon);
+  Tokens = Annotate("module test\n"
+"(input wire [7 : 0] a[7 : 0]);\n"
+"endmodule");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_VerilogDimensionedTypeName);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_BitFieldColon);
+  EXPECT_TOKEN(Tokens[13], tok::colon, TT_BitFieldColon);
   // Test case labels and ternary operators.
   Tokens = Annotate("case (x)\n"
 "  x:\n"
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -359,6 +359,12 @@
" input var shortreal in2,\n"
" output tagged_st out);\n"
"endmodule");
+  // There should be a space following the type but not the variable name.
+  verifyFormat("module test\n"
+   "(input wire [7 : 0] a,\n"
+   " input wire b[7 : 0],\n"
+   " input wire [7 : 0] c[7 : 0]);\n"
+   "endmodule");
   // Ports should be grouped by types.
   verifyFormat("module test\n"
"(input [7 : 0] a,\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2161,6 +2161,10 @@
   /// This is a heuristic based on whether \p Tok is an identifier following
   /// something that is likely a type.
   bool isStartOfName(const FormatToken ) {
+// Handled in ExpressionParser for Verilog.
+if (Style.isVerilog())
+  return false;
+
   

[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Is this a potentially breaking change that we need to call out for users to be 
aware of?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

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


[PATCH] D149314: [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Craig Topper 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 rG05d0caef6081: [RISCV] Remove support for attribute 
interrupt(user). (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149314

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/Sema/riscv-interrupt-attr.c


Index: clang/test/Sema/riscv-interrupt-attr.c
===
--- clang/test/Sema/riscv-interrupt-attr.c
+++ clang/test/Sema/riscv-interrupt-attr.c
@@ -4,26 +4,21 @@
 // RUN: %clang_cc1 %s -triple riscv64-unknown-elf -verify -fsyntax-only
 
 #if defined(CHECK_IR)
-// CHECK-LABEL:  @foo_user() #0
-// CHECK: ret void
-__attribute__((interrupt("user"))) void foo_user(void) {}
-// CHECK-LABEL:  @foo_supervisor() #1
+// CHECK-LABEL:  @foo_supervisor() #0
 // CHECK: ret void
 __attribute__((interrupt("supervisor"))) void foo_supervisor(void) {}
-// CHECK-LABEL:  @foo_machine() #2
+// CHECK-LABEL:  @foo_machine() #1
 // CHECK: ret void
 __attribute__((interrupt("machine"))) void foo_machine(void) {}
-// CHECK-LABEL:  @foo_default() #2
+// CHECK-LABEL:  @foo_default() #1
 // CHECK: ret void
 __attribute__((interrupt())) void foo_default(void) {}
-// CHECK-LABEL:  @foo_default2() #2
+// CHECK-LABEL:  @foo_default2() #1
 // CHECK: ret void
 __attribute__((interrupt())) void foo_default2(void) {}
 // CHECK: attributes #0
-// CHECK: "interrupt"="user"
-// CHECK: attributes #1
 // CHECK: "interrupt"="supervisor"
-// CHECK: attributes #2
+// CHECK: attributes #1
 // CHECK: "interrupt"="machine"
 #else
 struct a { int b; };
@@ -31,8 +26,10 @@
 struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' 
attribute only applies to functions}}
 
 __attribute__((interrupt("USER"))) void foo1(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: USER}}
+__attribute__((interrupt("user"))) void foo1b(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: user}}
+__attribute__((interrupt("MACHINE"))) void foo1c(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: MACHINE}}
 
-__attribute__((interrupt("user", 1))) void foo2(void) {} // expected-error 
{{'interrupt' attribute takes no more than 1 argument}}
+__attribute__((interrupt("machine", 1))) void foo2(void) {} // expected-error 
{{'interrupt' attribute takes no more than 1 argument}}
 
 __attribute__((interrupt)) int foo3(void) {return 0;} // expected-warning 
{{RISC-V 'interrupt' attribute only applies to functions that have a 'void' 
return type}}
 
@@ -41,7 +38,7 @@
 
 __attribute__((interrupt())) void foo5(int a) {} // expected-warning {{RISC-V 
'interrupt' attribute only applies to functions that have no parameters}}
 
-__attribute__((interrupt("user"), interrupt("supervisor"))) void foo6(void) {} 
// expected-warning {{repeated RISC-V 'interrupt' attribute}} \
+__attribute__((interrupt("machine"), interrupt("supervisor"))) void foo6(void) 
{} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
   // expected-note {{repeated RISC-V 'interrupt' attribute is here}}
 
 __attribute__((interrupt, interrupt)) void foo7(void) {} // expected-warning 
{{repeated RISC-V 'interrupt' attribute}} \
@@ -49,11 +46,9 @@
 
 __attribute__((interrupt(""))) void foo8(void) {} // expected-warning 
{{'interrupt' attribute argument not supported}}
 
-__attribute__((interrupt("user"))) void foo9(void);
 __attribute__((interrupt("supervisor"))) void foo9(void);
 __attribute__((interrupt("machine"))) void foo9(void);
 
-__attribute__((interrupt("user"))) void foo10(void) {}
 __attribute__((interrupt("supervisor"))) void foo11(void) {}
 __attribute__((interrupt("machine"))) void foo12(void) {}
 __attribute__((interrupt())) void foo13(void) {}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -11524,7 +11524,6 @@
 
 const char *Kind;
 switch (Attr->getInterrupt()) {
-case RISCVInterruptAttr::user: Kind = "user"; break;
 case RISCVInterruptAttr::supervisor: Kind = "supervisor"; break;
 case RISCVInterruptAttr::machine: Kind = "machine"; break;
 }
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1864,8 +1864,8 @@
   let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
   let Args = [EnumArgument<"Interrupt", "InterruptType",
-   ["user", "supervisor", "machine"],
-   ["user", "supervisor", "machine"],
+   ["supervisor", "machine"],
+   

[clang] 05d0cae - [RISCV] Remove support for attribute interrupt("user").

2023-04-27 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-04-27T08:21:36-07:00
New Revision: 05d0caef6081e1a6cb23a5a5afe43dc82e8ca558

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

LOG: [RISCV] Remove support for attribute interrupt("user").

This was part of the N extension which didn't make it version
1.12 of the privilege specification.

Reviewed By: kito-cheng

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/CodeGen/TargetInfo.cpp
clang/test/Sema/riscv-interrupt-attr.c

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a23dd5ce3634b..4863ece832307 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1864,8 +1864,8 @@ def RISCVInterrupt : InheritableAttr, 
TargetSpecificAttr {
   let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
   let Args = [EnumArgument<"Interrupt", "InterruptType",
-   ["user", "supervisor", "machine"],
-   ["user", "supervisor", "machine"],
+   ["supervisor", "machine"],
+   ["supervisor", "machine"],
1>];
   let ParseKind = "Interrupt";
   let Documentation = [RISCVInterruptDocs];

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index cc332aeee40d4..a19f1605bd3aa 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -11524,7 +11524,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo 
{
 
 const char *Kind;
 switch (Attr->getInterrupt()) {
-case RISCVInterruptAttr::user: Kind = "user"; break;
 case RISCVInterruptAttr::supervisor: Kind = "supervisor"; break;
 case RISCVInterruptAttr::machine: Kind = "machine"; break;
 }

diff  --git a/clang/test/Sema/riscv-interrupt-attr.c 
b/clang/test/Sema/riscv-interrupt-attr.c
index 2f5f2a44c778d..e66a5799bb394 100644
--- a/clang/test/Sema/riscv-interrupt-attr.c
+++ b/clang/test/Sema/riscv-interrupt-attr.c
@@ -4,26 +4,21 @@
 // RUN: %clang_cc1 %s -triple riscv64-unknown-elf -verify -fsyntax-only
 
 #if defined(CHECK_IR)
-// CHECK-LABEL:  @foo_user() #0
-// CHECK: ret void
-__attribute__((interrupt("user"))) void foo_user(void) {}
-// CHECK-LABEL:  @foo_supervisor() #1
+// CHECK-LABEL:  @foo_supervisor() #0
 // CHECK: ret void
 __attribute__((interrupt("supervisor"))) void foo_supervisor(void) {}
-// CHECK-LABEL:  @foo_machine() #2
+// CHECK-LABEL:  @foo_machine() #1
 // CHECK: ret void
 __attribute__((interrupt("machine"))) void foo_machine(void) {}
-// CHECK-LABEL:  @foo_default() #2
+// CHECK-LABEL:  @foo_default() #1
 // CHECK: ret void
 __attribute__((interrupt())) void foo_default(void) {}
-// CHECK-LABEL:  @foo_default2() #2
+// CHECK-LABEL:  @foo_default2() #1
 // CHECK: ret void
 __attribute__((interrupt())) void foo_default2(void) {}
 // CHECK: attributes #0
-// CHECK: "interrupt"="user"
-// CHECK: attributes #1
 // CHECK: "interrupt"="supervisor"
-// CHECK: attributes #2
+// CHECK: attributes #1
 // CHECK: "interrupt"="machine"
 #else
 struct a { int b; };
@@ -31,8 +26,10 @@ struct a { int b; };
 struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' 
attribute only applies to functions}}
 
 __attribute__((interrupt("USER"))) void foo1(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: USER}}
+__attribute__((interrupt("user"))) void foo1b(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: user}}
+__attribute__((interrupt("MACHINE"))) void foo1c(void) {} // expected-warning 
{{'interrupt' attribute argument not supported: MACHINE}}
 
-__attribute__((interrupt("user", 1))) void foo2(void) {} // expected-error 
{{'interrupt' attribute takes no more than 1 argument}}
+__attribute__((interrupt("machine", 1))) void foo2(void) {} // expected-error 
{{'interrupt' attribute takes no more than 1 argument}}
 
 __attribute__((interrupt)) int foo3(void) {return 0;} // expected-warning 
{{RISC-V 'interrupt' attribute only applies to functions that have a 'void' 
return type}}
 
@@ -41,7 +38,7 @@ __attribute__((interrupt())) void foo4(void) {}
 
 __attribute__((interrupt())) void foo5(int a) {} // expected-warning {{RISC-V 
'interrupt' attribute only applies to functions that have no parameters}}
 
-__attribute__((interrupt("user"), interrupt("supervisor"))) void foo6(void) {} 
// expected-warning {{repeated RISC-V 'interrupt' attribute}} \
+__attribute__((interrupt("machine"), interrupt("supervisor"))) void foo6(void) 
{} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
   // expected-note {{repeated RISC-V 'interrupt' attribute is 

[PATCH] D148088: [RFC][clangd] Move preamble index task to a seperate task

2023-04-27 Thread Kugan Vivekanandarajah via Phabricator via cfe-commits
kuganv added a comment.

In D148088#4302092 , @ilya-biryukov 
wrote:

>> We would like to move the preamble index out of the critical path
>
> Could you provide motivation why you need to do it? What is the underlying 
> problem that this change is trying to solve?
> We rely on preamble being indexed at that particular time for correct results 
> in future steps, it's definitely not a no-op change even if the threading 
> issues are resolved (see the other comment).

Thanks for your comment. Motivation for this is:

1. We see preamble indexing taking as much as 18% of the time for some files.  
Moving  preamble indexing out of the critical path helps there.
2. We are also experimenting with preamble caching with clang modules. Early 
results from this also shows that preamble indexing outside  the critical path 
improves performance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148088

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


  1   2   >