[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:23
+enum PatchOpcodes : uint32_t {
+  PO_ADDID = 0x02c0,  // addi.d rd, rj, imm
+  PO_SD = 0x29c0, // st.d rd, base, offset

I think the `PO_` style actually harms readability. Most instructions are used 
just once. It's more readable just using the magic number when it is needed 
paired with an inline comment

`Address[10] = insn2RI12(0x02c0, RegNum::RN_S, ...) // addi.d ...`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

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


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:153
+   const XRaySledEntry ) XRAY_NEVER_INSTRUMENT {
+  // FIXME: In the future we'd need to distinguish between non-tail exits and
+  // tail exits for better information preservation.

I know you copy the pattern from other patterns, but we should use TODO here. 
An unimplemented minor feature is not FIXME.



Comment at: compiler-rt/lib/xray/xray_trampoline_loongarch64.S:27
+  .cfi_offset 1, -8
+  st.d$a7, $sp, 120
+  st.d$a6, $sp, 112

You can use `.irpc` to simplify this a bit. See 
libunwind/src/UnwindRegistersSave.S



Comment at: compiler-rt/test/xray/TestCases/Posix/arg1-arg0-logging.cpp:9
 // TODO: Support these in ARM and PPC
-// XFAIL: target={{(arm|aarch64|mips).*}}
+// XFAIL: target={{(arm|aarch64|loongarch64|mips).*}}
 // UNSUPPORTED: target=powerpc64le{{.*}}

I added aarch64 support. You may rebase and add loongarch64 on the `REQUIRES:` 
line.



Comment at: compiler-rt/test/xray/TestCases/Posix/basic-filtering.cpp:26
 //
-// REQUIRES: x86_64-target-arch
+// REQUIRES: x86_64-target-arch || loongarch64-target-arch
 // REQUIRES: built-in-llvm-tree

Most `REQUIRES: x86_64-target-arch` are unnecessarily constrained. I just 
removed them. You may rebase and avoid changes to these test files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-07-05 Thread Sunil K via Phabricator via cfe-commits
koops added inline comments.



Comment at: clang/test/OpenMP/generic_loop_ast_print.cpp:26
 //PRINT:   T j, z;
-//PRINT:   #pragma omp loop collapse(C) reduction(+: z) lastprivate(j) 
bind(thread)
+//PRINT:   #pragma omp simd collapse(C) reduction(+: z) lastprivate(j)
 //PRINT:   for (T i = 0; i < t; ++i)

ddpagan wrote:
> The AST that is printed should be what was originally specified in the source.
Since I am mapping the loop directive to new directives (in the Sema itself) I 
am trying to print the state of AST as is to the developer of clang when 
-ast-print/-ast-dump is used. Without this correct printing of the state of the 
AST (new directives)) the developer may wonder why the code is not behaving as 
he/she specified and also in which phase the code gets changed.


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

https://reviews.llvm.org/D144634

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


[PATCH] D150221: Add option -fkeep-persistent-storage-variables to emit all variables that have a persistent storage duration

2023-07-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

Update (looping back from offline discussion): The LTO use case is covered. 
There was some confusion over which meaning of "static" was meant by 
`-fkeep-static-consts`. The "static" meant was storage duration.

Furthermore, there is some discussion over covering more than just variables, 
but also artifacts with reasonable mangled names such as the symbols for 
temporaries bound to references with "persistent storage" and guard variables.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150221

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


[PATCH] D154531: [AMDGPU] Support -mcpu=native for OpenCL

2023-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 537575.
yaxunl marked an inline comment as done.
yaxunl added a comment.

revised by comments


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

https://reviews.llvm.org/D154531

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/Driver/ToolChains/AMDGPU.cpp


Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -634,6 +634,27 @@
   for (Arg *A : Args)
 DAL->append(A);
 
+  // Replace -mcpu=native with detected GPU.
+  Arg *LastMCPUArg = DAL->getLastArg(options::OPT_mcpu_EQ);
+  if (LastMCPUArg && StringRef(LastMCPUArg->getValue()) == "native") {
+DAL->eraseArg(options::OPT_mcpu_EQ);
+auto GPUsOrErr = getSystemGPUArchs(Args);
+if (!GPUsOrErr) {
+  getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
+  << llvm::Triple::getArchTypeName(getArch())
+  << llvm::toString(GPUsOrErr.takeError()) << "-mcpu";
+} else {
+  auto  = *GPUsOrErr;
+  if (GPUs.size() > 1) {
+getDriver().Diag(diag::warn_drv_multi_gpu_arch)
+<< llvm::Triple::getArchTypeName(getArch())
+<< llvm::join(GPUs, ", ") << "-mcpu";
+  }
+  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mcpu_EQ),
+Args.MakeArgString(GPUs.front()));
+}
+  }
+
   checkTargetID(*DAL);
 
   if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1336,6 +1336,9 @@
 // Warning about mixed HIP and OpenMP compilation / target offloading.
 def HIPOpenMPOffloading: DiagGroup<"hip-omp-target-directives">;
 
+// Warning about multiple GPUs are detected.
+def MultiGPU: DiagGroup<"multi-gpu">;
+
 // Warnings which cause linking of the runtime libraries like
 // libc and the CRT to be skipped.
 def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -82,6 +82,9 @@
 def err_drv_undetermined_gpu_arch : Error<
   "cannot determine %0 architecture: %1; consider passing it via "
   "'%2'">;
+def warn_drv_multi_gpu_arch : Warning<
+  "multiple %0 architectures are detected: %1; only the first one is used for "
+  "'%2'">, InGroup;
 def err_drv_cuda_version_unsupported : Error<
   "GPU arch %0 is supported by CUDA versions between %1 and %2 (inclusive), "
   "but installation at %3 is %4; use '--cuda-path' to specify a different CUDA 
"


Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -634,6 +634,27 @@
   for (Arg *A : Args)
 DAL->append(A);
 
+  // Replace -mcpu=native with detected GPU.
+  Arg *LastMCPUArg = DAL->getLastArg(options::OPT_mcpu_EQ);
+  if (LastMCPUArg && StringRef(LastMCPUArg->getValue()) == "native") {
+DAL->eraseArg(options::OPT_mcpu_EQ);
+auto GPUsOrErr = getSystemGPUArchs(Args);
+if (!GPUsOrErr) {
+  getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
+  << llvm::Triple::getArchTypeName(getArch())
+  << llvm::toString(GPUsOrErr.takeError()) << "-mcpu";
+} else {
+  auto  = *GPUsOrErr;
+  if (GPUs.size() > 1) {
+getDriver().Diag(diag::warn_drv_multi_gpu_arch)
+<< llvm::Triple::getArchTypeName(getArch())
+<< llvm::join(GPUs, ", ") << "-mcpu";
+  }
+  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mcpu_EQ),
+Args.MakeArgString(GPUs.front()));
+}
+  }
+
   checkTargetID(*DAL);
 
   if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1336,6 +1336,9 @@
 // Warning about mixed HIP and OpenMP compilation / target offloading.
 def HIPOpenMPOffloading: DiagGroup<"hip-omp-target-directives">;
 
+// Warning about multiple GPUs are detected.
+def MultiGPU: DiagGroup<"multi-gpu">;
+
 // Warnings which cause linking of the runtime libraries like
 // libc and the CRT to be skipped.
 def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td

[PATCH] D154531: [AMDGPU] Support -mcpu=native for OpenCL

2023-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:86
+def warn_drv_multi_gpu_arch : Warning<
+  "multiple %0 architecture are detected: %1; only the first one is used for "
+  "'%2'">, InGroup;

arsenm wrote:
> s/architecture/architectures/
> 
> Maybe should stick to the "device" terminology opencl uses
`multiple devices` is ambiguous since it could mean multiple devices of the 
same GPU architecture. `multiple architectures` is not ambiguous.


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

https://reviews.llvm.org/D154531

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


[PATCH] D154531: [AMDGPU] Support -mcpu=native for OpenCL

2023-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D154531#4475386 , @MaskRay wrote:

> Seems reasonable. I assume that there isn't a way to add a portable test.

Right. It is difficult to test it with lit tests, but we will test it with 
internal CI.


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

https://reviews.llvm.org/D154531

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


[PATCH] D153205: [clang-format] Support block indenting array/struct list initializers

2023-07-05 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Do you need to update the current diff to show the net change? For example, the 
unit tests you added don't show up as a diff right now.




Comment at: clang/include/clang/Format/Format.h:95-98
 /// \warning
-///  Note: This currently only applies to parentheses.
+///  Note: This currently only applies to parentheses and braced list
+///  initializers when ``Cpp11BracedListStyle`` is ``True``.
 /// \endwarning

gedare wrote:
> owenpan wrote:
> > 
> This `\note` is not currently supported? I have submitted a rev D154552 to 
> add such ability.
Ah, you are right. Please still use `warning` here and update D154552 after 
this patch lands.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153205

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


[PATCH] D153600: Implement -frecord-command-line for XCOFF

2023-07-05 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added inline comments.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:981
+
+  // Metadata needs to be padded out to an even word size.
+  size_t MetadataSize = Metadata.size();

scott.linder wrote:
> stephenpeckham wrote:
> > There's no requirement to pad the .info section. When you generate assembly 
> > language, the .info pseudo-op can only generate words of data, so the if 
> > the data length is not 0(mod 4), the last word will have to be padded with 
> > low-order 0s.  This means that the length of the .info section will be a 
> > multiple of 4. The length, on the other hand, should be exact. At link 
> > time, only "length" bytes will be copied to the output file.
> > 
> > If you emit object code directly, you will not need to emit any padding 
> > bytes.
> Does the comment still need updating then? It could capture the fact that the 
> "lowest common denominator" is the assembly syntax as it works in terms of 
> words, and so may requiring padding in the final word. We can be clear that 
> we apply the same restriction to the object case judiciously, as it make the 
> output identical and avoids more code paths. We could also note that the 
> linker can use the length to optimize the final linked binary.
> 
> These all clear things up to a fresh reader, so I think they are worthwhile 
> things to include in comments.
I updated the comment. Please let me know if it's sufficient 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153600

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


[PATCH] D153600: Implement -frecord-command-line for XCOFF

2023-07-05 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan updated this revision to Diff 537572.
Jake-Egan added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153600

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/MC/MCStreamer.h
  llvm/include/llvm/MC/MCXCOFFStreamer.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/MC/MCAsmStreamer.cpp
  llvm/lib/MC/MCStreamer.cpp
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/CodeGen/PowerPC/aix-command-line-metadata.ll

Index: llvm/test/CodeGen/PowerPC/aix-command-line-metadata.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-command-line-metadata.ll
@@ -0,0 +1,23 @@
+; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | \
+; RUN: FileCheck --check-prefix=ASM %s
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | \
+; RUN: FileCheck --check-prefix=ASM %s
+
+; RUN: not --crash llc -mtriple powerpc-ibm-aix-xcoff -filetype=obj  < %s 2>&1 | \
+; RUN: FileCheck --check-prefix=OBJ %s
+; RUN: not --crash llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj  < %s 2>&1 | \
+; RUN: FileCheck --check-prefix=OBJ %s
+
+; Verify that llvm.commandline metadata is emitted to .info sections and that the
+; metadata is padded if necessary.
+
+; OBJ: LLVM ERROR: emitXCOFFCInfoSym is not implemented yet on object generation path
+
+; ASM: .info ".GCC.command.line", 0x003a,
+; ASM: .info , 0x40282329, 0x6f707420, 0x636c616e, 0x67202d63, 0x6f6d6d61, 0x6e64202d
+; ASM: .info , 0x6c696e65, 0x0a004028, 0x23296f70, 0x7420736f, 0x6d657468, 0x696e6720
+; ASM: .info , 0x656c7365, 0x20313233, 0x0a00
+
+!llvm.commandline = !{!0, !1}
+!0 = !{!"clang -command -line"}
+!1 = !{!"something else 123"}
Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
===
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -290,6 +290,8 @@
   bool doFinalization(Module ) override;
 
   void emitTTypeReference(const GlobalValue *GV, unsigned Encoding) override;
+
+  void emitModuleCommandLines(Module ) override;
 };
 
 } // end anonymous namespace
@@ -2954,6 +2956,26 @@
   return new PPCLinuxAsmPrinter(tm, std::move(Streamer));
 }
 
+void PPCAIXAsmPrinter::emitModuleCommandLines(Module ) {
+  const NamedMDNode *NMD = M.getNamedMetadata("llvm.commandline");
+  if (!NMD || !NMD->getNumOperands())
+return;
+
+  std::string S;
+  raw_string_ostream RSOS(S);
+  for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
+const MDNode *N = NMD->getOperand(i);
+assert(N->getNumOperands() == 1 &&
+   "llvm.commandline metadata entry can have only one operand");
+const MDString *MDS = cast(N->getOperand(0));
+// Add "@(#)" to support retrieving the command line information with the
+// AIX "what" command
+RSOS << "@(#)opt " << MDS->getString() << "\n";
+RSOS.write('\0');
+  }
+  OutStreamer->emitXCOFFCInfoSym(".GCC.command.line", RSOS.str());
+}
+
 // Force static initialization.
 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCAsmPrinter() {
   TargetRegistry::RegisterAsmPrinter(getThePPC32Target(),
Index: llvm/lib/MC/MCStreamer.cpp
===
--- llvm/lib/MC/MCStreamer.cpp
+++ llvm/lib/MC/MCStreamer.cpp
@@ -1208,6 +1208,11 @@
  "XCOFF targets");
 }
 
+void MCStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) {
+  llvm_unreachable("emitXCOFFCInfoSym is only supported on"
+   "XCOFF targets");
+}
+
 void MCStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
 void MCStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
 StringRef Name, bool KeepOriginalSym) {}
Index: llvm/lib/MC/MCAsmStreamer.cpp
===
--- llvm/lib/MC/MCAsmStreamer.cpp
+++ llvm/lib/MC/MCAsmStreamer.cpp
@@ -36,6 +36,7 @@
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Path.h"
+#include 
 #include 
 
 using namespace llvm;
@@ -200,6 +201,7 @@
 const MCSymbol *Trap,
 unsigned Lang, unsigned Reason,
 unsigned FunctionSize, bool hasDebug) override;
+  void emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) override;
 
   void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
   void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
@@ -966,6 +968,70 @@
   EmitEOL();
 }
 
+void MCAsmStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) {
+  const char InfoDirective[] = "\t.info ";
+  const char *Separator = ", ";
+  constexpr int WordSize = sizeof(uint32_t);
+
+  // Start by emitting the .info pseudo-op and 

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-05 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 537564.
Ami-zhang added a comment.

(1) Rebase
(2) Make some minor changes to xray-attribute-instrumentation.ll


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/always-never-instrument.cpp
  compiler-rt/test/xray/TestCases/Posix/arg1-arg0-logging.cpp
  compiler-rt/test/xray/TestCases/Posix/arg1-logger.cpp
  compiler-rt/test/xray/TestCases/Posix/arg1-logging-implicit-this.cpp
  compiler-rt/test/xray/TestCases/Posix/basic-filtering.cpp
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/clang-no-xray-instrument.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-mode-inmemory.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-mode-multiple.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-single-thread.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  compiler-rt/test/xray/TestCases/Posix/profiling-multi-threaded.cpp
  compiler-rt/test/xray/TestCases/Posix/profiling-single-threaded.cpp
  compiler-rt/test/xray/TestCases/Posix/quiet-start.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,55 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-.Ltmp0
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp0+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Ltmp1:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-.Ltmp1
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp1+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK:  .dword .Lxray_sleds_start0-.Lxray_fn_idx0
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: 

[PATCH] D154559: [clang] Fix constant evaluation about static member function

2023-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: rjmccall, tra, rsmith.
Herald added a project: All.
yaxunl requested review of this revision.

Currently, clang does not allow static constexpr member
functions called through a const reference of an object
in constant expression, e.g. the following code

  class static_multimap{
  public:
  static constexpr int size() noexcept{
  return 8;
  }
  };
  
  template 
  void test_non_shmem_pair_retrieve(Map& map){
  auto constexpr cg_size = map.size();
  }
  
  int main(){
  static_multimap map;
  test_non_shmem_pair_retrieve(map);
  return 0;
  }

fails to compile with clang. (https://godbolt.org/z/T17vTWYcs)

This does not make sense since the evaluation of map.size
does not rely on map. The same code compiles with GCC.


https://reviews.llvm.org/D154559

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp


Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2379,15 +2379,19 @@
   template void f1(T t) {
 constexpr int k = t.size();
   }
-  template void f2(const T ) { // expected-note 2{{declared 
here}}
-constexpr int k = t.size(); // expected-error 2{{constant}} expected-note 
2{{function parameter 't' with unknown value cannot be used in a constant 
expression}}
+  template void f2a(const T ) {
+constexpr int k1 = t.size();
+constexpr int k2 = (t).size();
+  }
+  template void f2b(const T ) { // expected-note {{declared 
here}}
+constexpr int k = t.size(); // expected-error {{constant}} expected-note 
{{function parameter 't' with unknown value cannot be used in a constant 
expression}}
   }
   template void f3(const T ) {
 constexpr int k = T::size();
   }
   void g(array<3> a) {
 f1(a);
-f2(a); // expected-note {{instantiation of}}
+f2a(a);
 f3(a);
   }
 
@@ -2396,7 +2400,7 @@
   };
   void h(array_nonstatic<3> a) {
 f1(a);
-f2(a); // expected-note {{instantiation of}}
+f2b(a); // expected-note {{instantiation of}}
   }
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8031,6 +8031,15 @@
 
   /// Potentially visit a MemberExpr's base expression.
   void VisitIgnoredBaseExpression(const Expr *E) {
+// If E is a reference, and if so, there is no side effect.
+if (const DeclRefExpr *DRE =
+dyn_cast(E->IgnoreParenImpCasts())) {
+  if (const VarDecl *VD = dyn_cast(DRE->getDecl())) {
+if (VD->getType()->isReferenceType()) {
+  return;
+}
+  }
+}
 // While MSVC doesn't evaluate the base expression, it does diagnose the
 // presence of side-effecting behavior.
 if (Info.getLangOpts().MSVCCompat && !E->HasSideEffects(Info.Ctx))


Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2379,15 +2379,19 @@
   template void f1(T t) {
 constexpr int k = t.size();
   }
-  template void f2(const T ) { // expected-note 2{{declared here}}
-constexpr int k = t.size(); // expected-error 2{{constant}} expected-note 2{{function parameter 't' with unknown value cannot be used in a constant expression}}
+  template void f2a(const T ) {
+constexpr int k1 = t.size();
+constexpr int k2 = (t).size();
+  }
+  template void f2b(const T ) { // expected-note {{declared here}}
+constexpr int k = t.size(); // expected-error {{constant}} expected-note {{function parameter 't' with unknown value cannot be used in a constant expression}}
   }
   template void f3(const T ) {
 constexpr int k = T::size();
   }
   void g(array<3> a) {
 f1(a);
-f2(a); // expected-note {{instantiation of}}
+f2a(a);
 f3(a);
   }
 
@@ -2396,7 +2400,7 @@
   };
   void h(array_nonstatic<3> a) {
 f1(a);
-f2(a); // expected-note {{instantiation of}}
+f2b(a); // expected-note {{instantiation of}}
   }
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8031,6 +8031,15 @@
 
   /// Potentially visit a MemberExpr's base expression.
   void VisitIgnoredBaseExpression(const Expr *E) {
+// If E is a reference, and if so, there is no side effect.
+if (const DeclRefExpr *DRE =
+dyn_cast(E->IgnoreParenImpCasts())) {
+  if (const VarDecl *VD = dyn_cast(DRE->getDecl())) {
+if (VD->getType()->isReferenceType()) {
+  return;
+}
+  }
+}
 // While MSVC doesn't evaluate the base expression, it does 

[PATCH] D143241: [Clang] Reset FP options before function instantiations

2023-07-05 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added a comment.

Hi, the following assertion is getting tripped on AIX:

  Assertion failed: *FpPragmaCurrentValue == 
SemaObj->FpPragmaStack.DefaultValue && "Expected a default pragma float_control 
value", file  
/scratch/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/clang/lib/Serialization/ASTReader.cpp,
 line 8150, void clang::ASTReader::UpdateSema()()

https://lab.llvm.org/buildbot/#/builders/214/builds/8309/steps/6/logs/FAIL__Clang__late-parsed-instantiations_cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143241

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


[PATCH] D154460: [ODRHash] Stop hashing `ObjCMethodDecl::isPropertyAccessor` as it doesn't capture inherent method quality.

2023-07-05 Thread Volodymyr Sapsai 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 rGf7e0aae7284b: [ODRHash] Stop hashing 
`ObjCMethodDecl::isPropertyAccessor` as it doesnt… (authored by vsapsai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154460

Files:
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/compare-objc-nonisolated-methods.m


Index: clang/test/Modules/compare-objc-nonisolated-methods.m
===
--- clang/test/Modules/compare-objc-nonisolated-methods.m
+++ clang/test/Modules/compare-objc-nonisolated-methods.m
@@ -5,12 +5,17 @@
 // is not an error because it depends on the surrounding code and not on the 
method itself.
 // RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t/modules.cache 
-fmodule-name=Override %t/test-overriding.m
 
+// Test that different values of `ObjCMethodDecl::isPropertyAccessor` in 
different modules
+// is not an error because it depends on the surrounding code and not on the 
method itself.
+// RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t/modules.cache 
-fmodule-name=PropertyAccessor %t/test-property_accessor.m
+
 //--- include/Common.h
 @interface NSObject
 @end
 
 //--- include/Indirection.h
 #import 
+#import 
 
 //--- include/module.modulemap
 module Common {
@@ -25,6 +30,10 @@
   header "Override.h"
   export *
 }
+module PropertyAccessor {
+  header "PropertyAccessor.h"
+  export *
+}
 
 //--- include/Override.h
 #import 
@@ -52,3 +61,31 @@
 void triggerOverrideCheck(SubClass *sc) {
   [sc potentialOverride];
 }
+
+//--- include/PropertyAccessor.h
+#import 
+@interface PropertySubClass: NSObject
+- (int)potentialProperty;
+- (void)setPotentialProperty:(int)p;
+@end
+
+//--- PropertyAccessor_Internal.h
+#import 
+@interface PropertySubClass()
+@property int potentialProperty;
+@end
+
+//--- test-property_accessor.m
+//expected-no-diagnostics
+// Get a version of `PropertySubClass` where `-[PropertySubClass 
potentialProperty]`
+// is a property accessor.
+#import "PropertyAccessor_Internal.h"
+
+// Get a version of `PropertySubClass` where `-[PropertySubClass 
potentialProperty]`
+// is not a property accessor because module "PropertyAccessor" doesn't know 
about PropertyAccessor_Internal.h.
+#import 
+
+void triggerPropertyAccessorCheck(PropertySubClass *x) {
+  int tmp = [x potentialProperty];
+  [x setPotentialProperty: tmp];
+}
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -373,7 +373,6 @@
   void VisitObjCMethodDecl(const ObjCMethodDecl *Method) {
 ID.AddInteger(Method->getDeclKind());
 Hash.AddBoolean(Method->isInstanceMethod()); // false if class method
-Hash.AddBoolean(Method->isPropertyAccessor());
 Hash.AddBoolean(Method->isVariadic());
 Hash.AddBoolean(Method->isSynthesizedAccessorStub());
 Hash.AddBoolean(Method->isDefined());


Index: clang/test/Modules/compare-objc-nonisolated-methods.m
===
--- clang/test/Modules/compare-objc-nonisolated-methods.m
+++ clang/test/Modules/compare-objc-nonisolated-methods.m
@@ -5,12 +5,17 @@
 // is not an error because it depends on the surrounding code and not on the method itself.
 // RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -fmodule-name=Override %t/test-overriding.m
 
+// Test that different values of `ObjCMethodDecl::isPropertyAccessor` in different modules
+// is not an error because it depends on the surrounding code and not on the method itself.
+// RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -fmodule-name=PropertyAccessor %t/test-property_accessor.m
+
 //--- include/Common.h
 @interface NSObject
 @end
 
 //--- include/Indirection.h
 #import 
+#import 
 
 //--- include/module.modulemap
 module Common {
@@ -25,6 +30,10 @@
   header "Override.h"
   export *
 }
+module PropertyAccessor {
+  header "PropertyAccessor.h"
+  export *
+}
 
 //--- include/Override.h
 #import 
@@ -52,3 +61,31 @@
 void triggerOverrideCheck(SubClass *sc) {
   [sc potentialOverride];
 }
+
+//--- include/PropertyAccessor.h
+#import 
+@interface PropertySubClass: NSObject
+- (int)potentialProperty;
+- (void)setPotentialProperty:(int)p;
+@end
+
+//--- PropertyAccessor_Internal.h
+#import 
+@interface PropertySubClass()
+@property int potentialProperty;
+@end
+
+//--- test-property_accessor.m
+//expected-no-diagnostics
+// Get a version of `PropertySubClass` where `-[PropertySubClass potentialProperty]`
+// is a property accessor.
+#import 

[PATCH] D154459: [ODRHash] Stop hashing `ObjCMethodDecl::isOverriding` as it doesn't capture inherent method quality.

2023-07-05 Thread Volodymyr Sapsai 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 rG18530e5d0770: [ODRHash] Stop hashing 
`ObjCMethodDecl::isOverriding` as it doesnt capture… (authored by 
vsapsai).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154459

Files:
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/AST/ODRHash.cpp
  clang/test/Modules/compare-objc-nonisolated-methods.m


Index: clang/test/Modules/compare-objc-nonisolated-methods.m
===
--- /dev/null
+++ clang/test/Modules/compare-objc-nonisolated-methods.m
@@ -0,0 +1,54 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// Test that different values of `ObjCMethodDecl::isOverriding` in different 
modules
+// is not an error because it depends on the surrounding code and not on the 
method itself.
+// RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t/modules.cache 
-fmodule-name=Override %t/test-overriding.m
+
+//--- include/Common.h
+@interface NSObject
+@end
+
+//--- include/Indirection.h
+#import 
+
+//--- include/module.modulemap
+module Common {
+  header "Common.h"
+  export *
+}
+module Indirection {
+  header "Indirection.h"
+  export *
+}
+module Override {
+  header "Override.h"
+  export *
+}
+
+//--- include/Override.h
+#import 
+@interface SubClass: NSObject
+- (void)potentialOverride;
+@end
+
+//--- Override_Internal.h
+#import 
+@interface NSObject(InternalCategory)
+- (void)potentialOverride;
+@end
+
+//--- test-overriding.m
+//expected-no-diagnostics
+// Get non-modular version of `SubClass`, so that `-[SubClass 
potentialOverride]`
+// is an override of a method in `InternalCategory`.
+#import "Override_Internal.h"
+#import 
+
+// Get modular version of `SubClass` where `-[SubClass potentialOverride]` is
+// not an override because module "Override" doesn't know about 
Override_Internal.h.
+#import 
+
+void triggerOverrideCheck(SubClass *sc) {
+  [sc potentialOverride];
+}
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -377,7 +377,6 @@
 Hash.AddBoolean(Method->isVariadic());
 Hash.AddBoolean(Method->isSynthesizedAccessorStub());
 Hash.AddBoolean(Method->isDefined());
-Hash.AddBoolean(Method->isOverriding());
 Hash.AddBoolean(Method->isDirectMethod());
 Hash.AddBoolean(Method->isThisDeclarationADesignatedInitializer());
 Hash.AddBoolean(Method->hasSkippedBody());
Index: clang/lib/AST/ODRDiagsEmitter.cpp
===
--- clang/lib/AST/ODRDiagsEmitter.cpp
+++ clang/lib/AST/ODRDiagsEmitter.cpp
@@ -2096,7 +2096,8 @@
   << FirstDecl->getSourceRange();
   Diag(SecondDecl->getLocation(),
diag::note_module_odr_violation_mismatch_decl_unknown)
-  << SecondModule << FirstDiffType << SecondDecl->getSourceRange();
+  << SecondModule.empty() << SecondModule << FirstDiffType
+  << SecondDecl->getSourceRange();
   return true;
 }
 


Index: clang/test/Modules/compare-objc-nonisolated-methods.m
===
--- /dev/null
+++ clang/test/Modules/compare-objc-nonisolated-methods.m
@@ -0,0 +1,54 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// Test that different values of `ObjCMethodDecl::isOverriding` in different modules
+// is not an error because it depends on the surrounding code and not on the method itself.
+// RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -fmodule-name=Override %t/test-overriding.m
+
+//--- include/Common.h
+@interface NSObject
+@end
+
+//--- include/Indirection.h
+#import 
+
+//--- include/module.modulemap
+module Common {
+  header "Common.h"
+  export *
+}
+module Indirection {
+  header "Indirection.h"
+  export *
+}
+module Override {
+  header "Override.h"
+  export *
+}
+
+//--- include/Override.h
+#import 
+@interface SubClass: NSObject
+- (void)potentialOverride;
+@end
+
+//--- Override_Internal.h
+#import 
+@interface NSObject(InternalCategory)
+- (void)potentialOverride;
+@end
+
+//--- test-overriding.m
+//expected-no-diagnostics
+// Get non-modular version of `SubClass`, so that `-[SubClass potentialOverride]`
+// is an override of a method in `InternalCategory`.
+#import "Override_Internal.h"
+#import 
+
+// Get modular version of `SubClass` where `-[SubClass potentialOverride]` is
+// not an override because module "Override" doesn't know about Override_Internal.h.
+#import 
+
+void triggerOverrideCheck(SubClass *sc) {
+  [sc potentialOverride];
+}
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ 

[clang] f7e0aae - [ODRHash] Stop hashing `ObjCMethodDecl::isPropertyAccessor` as it doesn't capture inherent method quality.

2023-07-05 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2023-07-05T18:04:50-07:00
New Revision: f7e0aae7284b7ad0cf3cc277c5ef8731f564443d

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

LOG: [ODRHash] Stop hashing `ObjCMethodDecl::isPropertyAccessor` as it doesn't 
capture inherent method quality.

`isPropertyAccessor` depends on the surrounding code and not on the method
itself. That's why it can be different in different modules. And
mismatches shouldn't be an error.

rdar://109481753

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

Added: 


Modified: 
clang/lib/AST/ODRHash.cpp
clang/test/Modules/compare-objc-nonisolated-methods.m

Removed: 




diff  --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp
index 3ea023d3cee66a..507fb0b49f8ad3 100644
--- a/clang/lib/AST/ODRHash.cpp
+++ b/clang/lib/AST/ODRHash.cpp
@@ -373,7 +373,6 @@ class ODRDeclVisitor : public 
ConstDeclVisitor {
   void VisitObjCMethodDecl(const ObjCMethodDecl *Method) {
 ID.AddInteger(Method->getDeclKind());
 Hash.AddBoolean(Method->isInstanceMethod()); // false if class method
-Hash.AddBoolean(Method->isPropertyAccessor());
 Hash.AddBoolean(Method->isVariadic());
 Hash.AddBoolean(Method->isSynthesizedAccessorStub());
 Hash.AddBoolean(Method->isDefined());

diff  --git a/clang/test/Modules/compare-objc-nonisolated-methods.m 
b/clang/test/Modules/compare-objc-nonisolated-methods.m
index a60114148420bd..41e861547af420 100644
--- a/clang/test/Modules/compare-objc-nonisolated-methods.m
+++ b/clang/test/Modules/compare-objc-nonisolated-methods.m
@@ -5,12 +5,17 @@
 // is not an error because it depends on the surrounding code and not on the 
method itself.
 // RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t/modules.cache 
-fmodule-name=Override %t/test-overriding.m
 
+// Test that 
diff erent values of `ObjCMethodDecl::isPropertyAccessor` in 
diff erent modules
+// is not an error because it depends on the surrounding code and not on the 
method itself.
+// RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t/modules.cache 
-fmodule-name=PropertyAccessor %t/test-property_accessor.m
+
 //--- include/Common.h
 @interface NSObject
 @end
 
 //--- include/Indirection.h
 #import 
+#import 
 
 //--- include/module.modulemap
 module Common {
@@ -25,6 +30,10 @@ @interface NSObject
   header "Override.h"
   export *
 }
+module PropertyAccessor {
+  header "PropertyAccessor.h"
+  export *
+}
 
 //--- include/Override.h
 #import 
@@ -52,3 +61,31 @@ - (void)potentialOverride;
 void triggerOverrideCheck(SubClass *sc) {
   [sc potentialOverride];
 }
+
+//--- include/PropertyAccessor.h
+#import 
+@interface PropertySubClass: NSObject
+- (int)potentialProperty;
+- (void)setPotentialProperty:(int)p;
+@end
+
+//--- PropertyAccessor_Internal.h
+#import 
+@interface PropertySubClass()
+@property int potentialProperty;
+@end
+
+//--- test-property_accessor.m
+//expected-no-diagnostics
+// Get a version of `PropertySubClass` where `-[PropertySubClass 
potentialProperty]`
+// is a property accessor.
+#import "PropertyAccessor_Internal.h"
+
+// Get a version of `PropertySubClass` where `-[PropertySubClass 
potentialProperty]`
+// is not a property accessor because module "PropertyAccessor" doesn't know 
about PropertyAccessor_Internal.h.
+#import 
+
+void triggerPropertyAccessorCheck(PropertySubClass *x) {
+  int tmp = [x potentialProperty];
+  [x setPotentialProperty: tmp];
+}



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


[clang] 18530e5 - [ODRHash] Stop hashing `ObjCMethodDecl::isOverriding` as it doesn't capture inherent method quality.

2023-07-05 Thread Volodymyr Sapsai via cfe-commits

Author: Volodymyr Sapsai
Date: 2023-07-05T18:04:32-07:00
New Revision: 18530e5d0770098bc33ff6f02a7b63ea887692a6

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

LOG: [ODRHash] Stop hashing `ObjCMethodDecl::isOverriding` as it doesn't 
capture inherent method quality.

`isOverriding` depends on the surrounding code and not on the method
itself. That's why it can be different in different modules. And
mismatches shouldn't be an error.

rdar://109481753

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

Added: 
clang/test/Modules/compare-objc-nonisolated-methods.m

Modified: 
clang/lib/AST/ODRDiagsEmitter.cpp
clang/lib/AST/ODRHash.cpp

Removed: 




diff  --git a/clang/lib/AST/ODRDiagsEmitter.cpp 
b/clang/lib/AST/ODRDiagsEmitter.cpp
index d1c59bd1f2ca23..1994f0865428bd 100644
--- a/clang/lib/AST/ODRDiagsEmitter.cpp
+++ b/clang/lib/AST/ODRDiagsEmitter.cpp
@@ -2096,7 +2096,8 @@ bool ODRDiagsEmitter::diagnoseMismatch(
   << FirstDecl->getSourceRange();
   Diag(SecondDecl->getLocation(),
diag::note_module_odr_violation_mismatch_decl_unknown)
-  << SecondModule << FirstDiffType << SecondDecl->getSourceRange();
+  << SecondModule.empty() << SecondModule << FirstDiffType
+  << SecondDecl->getSourceRange();
   return true;
 }
 

diff  --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp
index 0ead0940479d85..3ea023d3cee66a 100644
--- a/clang/lib/AST/ODRHash.cpp
+++ b/clang/lib/AST/ODRHash.cpp
@@ -377,7 +377,6 @@ class ODRDeclVisitor : public 
ConstDeclVisitor {
 Hash.AddBoolean(Method->isVariadic());
 Hash.AddBoolean(Method->isSynthesizedAccessorStub());
 Hash.AddBoolean(Method->isDefined());
-Hash.AddBoolean(Method->isOverriding());
 Hash.AddBoolean(Method->isDirectMethod());
 Hash.AddBoolean(Method->isThisDeclarationADesignatedInitializer());
 Hash.AddBoolean(Method->hasSkippedBody());

diff  --git a/clang/test/Modules/compare-objc-nonisolated-methods.m 
b/clang/test/Modules/compare-objc-nonisolated-methods.m
new file mode 100644
index 00..a60114148420bd
--- /dev/null
+++ b/clang/test/Modules/compare-objc-nonisolated-methods.m
@@ -0,0 +1,54 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// Test that 
diff erent values of `ObjCMethodDecl::isOverriding` in 
diff erent modules
+// is not an error because it depends on the surrounding code and not on the 
method itself.
+// RUN: %clang_cc1 -fsyntax-only -verify -I%t/include -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t/modules.cache 
-fmodule-name=Override %t/test-overriding.m
+
+//--- include/Common.h
+@interface NSObject
+@end
+
+//--- include/Indirection.h
+#import 
+
+//--- include/module.modulemap
+module Common {
+  header "Common.h"
+  export *
+}
+module Indirection {
+  header "Indirection.h"
+  export *
+}
+module Override {
+  header "Override.h"
+  export *
+}
+
+//--- include/Override.h
+#import 
+@interface SubClass: NSObject
+- (void)potentialOverride;
+@end
+
+//--- Override_Internal.h
+#import 
+@interface NSObject(InternalCategory)
+- (void)potentialOverride;
+@end
+
+//--- test-overriding.m
+//expected-no-diagnostics
+// Get non-modular version of `SubClass`, so that `-[SubClass 
potentialOverride]`
+// is an override of a method in `InternalCategory`.
+#import "Override_Internal.h"
+#import 
+
+// Get modular version of `SubClass` where `-[SubClass potentialOverride]` is
+// not an override because module "Override" doesn't know about 
Override_Internal.h.
+#import 
+
+void triggerOverrideCheck(SubClass *sc) {
+  [sc potentialOverride];
+}



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


[PATCH] D154459: [ODRHash] Stop hashing `ObjCMethodDecl::isOverriding` as it doesn't capture inherent method quality.

2023-07-05 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154459

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


[PATCH] D154493: [X86] Support some Intel CPUs for cpu_specific/dispatch feature

2023-07-05 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked an inline comment as done.
FreddyYe added inline comments.



Comment at: llvm/lib/TargetParser/X86TargetParser.cpp:333
   { {"pentium"}, CK_Pentium, ~0U, FeatureX87 | FeatureCMPXCHG8B, 'B', false },
   { {"pentium-mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX, '\0', false },
   { {"pentium_mmx"}, CK_PentiumMMX, ~0U, FeaturesPentiumMMX, 'D', true },

RKSimon wrote:
> add this as well?
cpu names contain '-' are not supported for cpu_specific/dispatch feature since 
'-' is not an identifier character. The solution here is creating a new name 
with '_' replacing and set the OnlyForCPUDispatchSpecific as `true`, like 
`icelake-client`, `icelake-server` and `goldmont-plus`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154493

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


[PATCH] D154556: [OPENMP52] Support Support omp_cur_iteration modifier for doacross clause.

2023-07-05 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 537553.
jyu2 added a comment.

Fix typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154556

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp

Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -132,7 +132,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
@@ -155,6 +159,10 @@
 #pragma omp ordered doacross(sink : // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected expression}} omp52-error {{expected 'i' loop iteration variable}}
 #pragma omp ordered doacross(sink : i // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected 'j' loop iteration variable}}
 #pragma omp ordered doacross(sink : i) // omp52-error {{expected 'j' loop iteration variable}}
+#pragma omp ordered doacross(sink:omp_cur_iteration + 1) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration - 2) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(source:omp_cur_iteration - 1) // omp52-error {{'doacross source:' must be with 'omp_cur_iteration'}}
 #pragma omp ordered doacross(source:)
if (i == j)
 #pragma omp ordered doacross(source:) // omp52-error {{'#pragma omp ordered' with 'doacross' clause cannot be an immediate substatement}}
@@ -309,7 +317,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -84,6 +84,43 @@
 #pragma omp ordered depend(sink : i - 2)
 #endif
 d[i] = a[i - 2];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 1
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#ifdef OMP52
+#pragma omp ordered doacross(sink :omp_cur_iteration - 1)
+#else
+#pragma omp ordered depend(sink : i - 1)
+#endif
+d[i] = a[i - 1];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I:%.+]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID1:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_post(ptr [[IDENT]], i32 [[GTID1]], ptr [[TMP]])
+#if OMP52
+#pragma omp ordered doacross(source:omp_cur_iteration)
+#else
+#pragma omp ordered depend(source)
+#endif
+c[i] = c[i] + 1;
   }
   // CHECK: call void @__kmpc_for_static_fini(
   // CHECK-NORMAL: call void 

[PATCH] D154556: [OPENMP52] Support Support omp_cur_iteration modifier for doacross clause.

2023-07-05 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 created this revision.
jyu2 added reviewers: ABataev, mikerice, jdoerfert.
jyu2 added a project: OpenMP.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
jyu2 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This is just syntax to make it easier for the user. It doesn't add any
new functionality.

for
doacross(sink: omp_cur_iteration - 1)
Equivalent to
doacross(sink: ConterVar - 1, ...)

doacross(source: omp_cur_iteration)
Equivalent to
doacross(source)

And restriction is:
OMP5.2 p.327

If vector is specified with the omp_cur_iteration keyword and with
sink as the dependence-type then it must be omp_cur_iteration - 1.

If vector is specified with source as the dependence-type then it must be
omp_cur_iteration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154556

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/ordered_ast_print.cpp
  clang/test/OpenMP/ordered_doacross_codegen.c
  clang/test/OpenMP/ordered_messages.cpp

Index: clang/test/OpenMP/ordered_messages.cpp
===
--- clang/test/OpenMP/ordered_messages.cpp
+++ clang/test/OpenMP/ordered_messages.cpp
@@ -132,7 +132,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
@@ -155,6 +159,10 @@
 #pragma omp ordered doacross(sink : // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected expression}} omp52-error {{expected 'i' loop iteration variable}}
 #pragma omp ordered doacross(sink : i // omp52-error {{expected ')'}} omp52-note {{to match this '('}} omp52-error {{expected 'j' loop iteration variable}}
 #pragma omp ordered doacross(sink : i) // omp52-error {{expected 'j' loop iteration variable}}
+#pragma omp ordered doacross(sink:omp_cur_iteration + 1) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration - 2) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(sink:omp_cur_iteration) // omp52-error {{'doacross sink:' must be with 'omp_cur_iteration - 1'}}
+#pragma omp ordered doacross(source:omp_cur_iteration - 1) // omp52-error {{'doacross source:' must be with 'omp_cur_iteration'}}
 #pragma omp ordered doacross(source:)
if (i == j)
 #pragma omp ordered doacross(source:) // omp52-error {{'#pragma omp ordered' with 'doacross' clause cannot be an immediate substatement}}
@@ -309,7 +317,11 @@
 {
   foo();
 }
+#if _OPENMP >= 202111
+#pragma omp ordered doacross(source:omp_cur_iteration) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#else
 #pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
+#endif
   }
 #pragma omp parallel for ordered
   for (int i = 0; i < 10; ++i) {
Index: clang/test/OpenMP/ordered_doacross_codegen.c
===
--- clang/test/OpenMP/ordered_doacross_codegen.c
+++ clang/test/OpenMP/ordered_doacross_codegen.c
@@ -84,6 +84,43 @@
 #pragma omp ordered depend(sink : i - 2)
 #endif
 d[i] = a[i - 2];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 1
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT:%.+]], i64 0, i64 0
+// CHECK-NEXT: store i64 %{{.+}}, ptr [[TMP]],
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr [[CNT]], i64 0, i64 0
+// CHECK-NORMAL-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID]], ptr [[TMP]])
+// CHECK-IRBUILDER-NEXT: [[GTID2:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[IDENT:@.+]])
+// CHECK-IRBUILDER-NEXT: call void @__kmpc_doacross_wait(ptr [[IDENT]], i32 [[GTID2]], ptr [[TMP]])
+#ifdef OMP52
+#pragma omp ordered doacross(sink :omp_cur_iteration - 1)
+#else
+#pragma omp ordered depend(sink : i - 1)
+#endif
+d[i] = a[i - 1];
+foo();
+// CHECK: call void @foo()
+// CHECK: load i32, ptr [[I:%.+]],
+// CHECK-NEXT: sub nsw i32 %{{.+}}, 0
+// CHECK-NEXT: sdiv i32 %{{.+}}, 1
+// CHECK-NEXT: sext i32 %{{.+}} to i64
+// CHECK-NEXT: [[TMP:%.+]] = getelementptr inbounds [1 x i64], ptr 

[PATCH] D153375: [Clang] Fix incorrect use of direct initialization with copy initialization

2023-07-05 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp:293
+  e = {E::E1};
+  e = {0}; // expected-error {{cannot initialize a value of type 'E' with an 
rvalue of type 'int'}}
+}

rsmith wrote:
> This looks valid to me. The language rules say we treat this as `e = E{0};`, 
> which we accept.
Richard and I discussed this and I agree that based on 
http://eel.is/c++draft/expr.ass#8.1 this should be the same as `e = E{0}` and 
this would be direct init and we should accept this.



Comment at: clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3.cpp:292
+  E e;
+  e = {0}; // expected-error {{cannot initialize a value of type 'E' with an 
rvalue of type 'int'}}
+}

cor3ntin wrote:
> Should we add a test that passes here? Even if it currently doesn't crash
> 
>  enum class E {Foo};
>  E e;
>  e = {E::Foo};
> 
> 
Sure that makes sense, more coverage is good.


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

https://reviews.llvm.org/D153375

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D153536#4475308 , @cor3ntin wrote:

> In D153536#4475240 , @dblaikie 
> wrote:
>
>> In D153536#4475199 , @cor3ntin 
>> wrote:
>>
>>> In D153536#4474733 , @dblaikie 
>>> wrote:
>>>
 Maybe try testing with more different values, to demonstrate which 
 entities the debugger is finding?

   int _ = 1;
   int _ = 2;
   {
 int _ = 3;
 int _ = 7;
   }

 Or something like that. But, honestly, if the point is that these 
 variables should be unnameable - perhaps we shouldn't generate any DWARF 
 for them?
>>>
>>> The variables should still be inspectable, ideally. It's true it makes no 
>>> sense to be able to use them in expressions, and maybe if lldb use clang to 
>>> evaluate expressions that would just work?
>>
>> I think that's going to be tricky - because we don't emit DWARF to say where 
>> one variable's lifetime starts compared to another in the same scope - so 
>> likely a debugger would just always show the first or last variable with the 
>> same name in a given scope (so in the above example you could probably only 
>> print {1,3} or {2,7}) - and getting it wrong is more likely and more 
>> problematic than existing cases of shadowed variables. If we can't get this 
>> right, which I don't think we can, practically speaking, at the moment (the 
>> DWARF feature we'd have to support to do this better would probably be 
>> `DW_AT_start_scope` to say at what instruction the lifetime of a variable 
>> starts) - it may be best not to include it at all?
>
> It doesn't seems to be confused on simple examples
>
>   cpp
>   * thread #1, name = 'placeholder', stop reason = step in
>   frame #0: 0x5157 placeholder`main at 
> debug_placeholder.cpp:8:13
>  5{
>  6int _ = 4;
>  7int _ = 5;
>   -> 8int _ = 6;
>  9}
>  10   }
>   (lldb) frame variable
>   (int) _ = 1
>   (int) _ = 2
>   (int) _ = 3
>   (int) _ = 4
>   (int) _ = 5
>   (int) _ = -9432
>
> That being said, if you think it's more prudent, I would not mind

Huh, I guess maybe it's got some heuristics based on line number. Could 
probably thwart those by stamping this out with a macro (which would cause all 
code in the macro to be attributed to the line where the macro is named) - add 
some function calls in, so you can step back up from the call to get to more 
precise locations and you'd probably see some problems. That's probably a bit 
contrived (but maybe not - perhaps `_` would be more common in macros).

*shrug* maybe it's OK enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D138810: [RISCV] Support vector crypto extension C intrinsics

2023-07-05 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:2378
+
+multiclass RVVOutBuiltinSetP {

What does `P` in this name mean? Is this because they use OP_P as their opcode? 
If so I don't think that should be part of how we name intrinsics.



Comment at: clang/include/clang/Basic/riscv_vector.td:2379
+multiclass RVVOutBuiltinSetP {
+  if HasVV then {

Zvkb doesn't exist anymore



Comment at: clang/include/clang/Basic/riscv_vector.td:2423
+  defm vandn   : RVVIntBinBuiltinSet;
+  defm vbrev   : RVVOutBuiltinSetP<1, 0, 1, "csil", 1>;
+  defm vbrev8  : RVVOutBuiltinSetP<1, 0, 1, "csil", 1>;

I think I'd prefer to see the Zvbb instructions use their own class and not try 
to make `RVVOutBuiltinSetP` handle them and instructions that set HasVS.



Comment at: clang/include/clang/Basic/riscv_vector.td:2449
+  let UnMaskedPolicyScheme = HasPassthruOperand in
+  defm vaeskf1 : RVVOutOp1BuiltinSet<"vaeskf1", "i", [["vi", "Uv", "UvUvUe"]]>;
+  defm vaeskf2 : RVVOutOp1BuiltinSetP<0>;

I think the `Ue` needs a `K` since its required to be a constant? Also need to 
update SemaChecking to verify the valid range.

I'm not sure whether we should use `Ue` or 'z' for constants.



Comment at: clang/include/clang/Basic/riscv_vector.td:2450
+  defm vaeskf1 : RVVOutOp1BuiltinSet<"vaeskf1", "i", [["vi", "Uv", "UvUvUe"]]>;
+  defm vaeskf2 : RVVOutOp1BuiltinSetP<0>;
+  defm vaesz   : RVVOutBuiltinSetP<0>;

vaeskf2 needs `K` to mark the scalar as a constant. Should maybe use `z` 
instead of `Ue`. Need to update SemaChecking.cpp



Comment at: clang/include/clang/Basic/riscv_vector.td:2460
+  let UnMaskedPolicyScheme = HasPassthruOperand in
+  defm vsm4k   : RVVOutOp1BuiltinSet<"vsm4k", "i", [["vi", "Uv", "UvUvUe"]]>;
+  defm vsm4r   : RVVOutBuiltinSetP;

I think the `Ue` needs a `K` since its required to be a constant? Also need to 
update SemaChecking to verify the valid range.

I'm not sure whether we should use `Ue` or 'z' for constants.



Comment at: clang/include/clang/Basic/riscv_vector.td:2464
+  // zvksh
+  defm vsm3c   : RVVOutOp1BuiltinSetP<0>;
+  let UnMaskedPolicyScheme = HasPassthruOperand in

vsm3c needs `K` to mark the scalar as a constant. Should maybe use `z` instead 
of `Ue`. Need to update SemaChecking.cpp



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaeskf1.c:12
+//
+vuint32mf2_t test_vaeskf1_vi_u32mf2(vuint32mf2_t vs2, size_t uimm, size_t vl) {
+  return __riscv_vaeskf1_vi_u32mf2(vs2, 0, vl);

`uimm` is not used



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsm3c.c:12
+//
+vuint32mf2_t test_vsm3c_vi_u32mf2(vuint32mf2_t vd, vuint32mf2_t vs2, size_t 
uimm, size_t vl) {
+  return __riscv_vsm3c_vi_u32mf2(vd, vs2, 0, vl);

`uimm` isn't used



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vror.c:12
+//
+vint8mf8_t test_vror_vv_i8mf8_tu(vint8mf8_t maskedoff, vint8mf8_t vs2, 
vint8mf8_t vs1, size_t vl) {
+  return __riscv_vror_tu(maskedoff, vs2, vs1, vl);

The intrinsic spec does not define rotates for signed types



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vsm4k.c:12
+//
+vuint32mf2_t test_vsm4k_vi_u32mf2_tu(vuint32mf2_t maskedoff, vuint32mf2_t vs2, 
size_t uimm, size_t vl) {
+  return __riscv_vsm4k_tu(maskedoff, vs2, 0, vl);

`uimm` is unused



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vsm4k.c:13
+vuint32mf2_t test_vsm4k_vi_u32mf2_tu(vuint32mf2_t maskedoff, vuint32mf2_t vs2, 
size_t uimm, size_t vl) {
+  return __riscv_vsm4k_tu(maskedoff, vs2, 0, vl);
+}

Need to update SemaChecking.cpp to check the valid range for the immediate.



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vwsll.c:12
+//
+vint16mf4_t test_vwsll_vv_i16mf4_tu(vint16mf4_t maskedoff, vint8mf8_t op1, 
vint8mf8_t op2, size_t vl) {
+  return __riscv_vwsll_vv_tu(maskedoff, op1, op2, vl);

Shift amounts should always be unsigned



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vwsll.c:21
+//
+vint16mf4_t test_vwsll_vx_i16mf4_tu(vint16mf4_t maskedoff, vint8mf8_t op1, 
int8_t op2, size_t vl) {
+  return __riscv_vwsll_vx_tu(maskedoff, op1, op2, vl);

Scalar shift amount should be size_t to match other shifts. This was raised on 
the intrinsic PR


Repository:
  rG LLVM Github Monorepo

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


[PATCH] D154036: [libc] Add support for creating wrapper headers for offloading in clang

2023-07-05 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 537535.
jhuber6 added a comment.

Fix guard on the headers for offloading languages


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154036

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/llvm_libc_wrappers/ctype.h
  clang/lib/Headers/llvm_libc_wrappers/llvm-libc-decls/README.txt
  clang/lib/Headers/llvm_libc_wrappers/stdio.h
  clang/lib/Headers/llvm_libc_wrappers/stdlib.h
  clang/lib/Headers/llvm_libc_wrappers/string.h
  clang/test/Driver/gpu-libc-headers.c
  libc/cmake/modules/LLVMLibCHeaderRules.cmake
  libc/include/CMakeLists.txt
  libc/utils/HdrGen/Generator.cpp
  libc/utils/HdrGen/Generator.h
  libc/utils/HdrGen/Main.cpp

Index: libc/utils/HdrGen/Main.cpp
===
--- libc/utils/HdrGen/Main.cpp
+++ libc/utils/HdrGen/Main.cpp
@@ -32,6 +32,9 @@
 llvm::cl::list ReplacementValues(
 "args", llvm::cl::desc("Command separated = pairs."),
 llvm::cl::value_desc("[,name=value]"));
+llvm::cl::opt ExportDecls(
+"export-decls",
+llvm::cl::desc("Output a new header containing only the entrypoints."));
 
 void ParseArgValuePairs(std::unordered_map ) {
   for (std::string  : ReplacementValues) {
@@ -48,7 +51,10 @@
   std::unordered_map ArgMap;
   ParseArgValuePairs(ArgMap);
   Generator G(HeaderDefFile, EntrypointNamesOption, StandardHeader, ArgMap);
-  G.generate(OS, Records);
+  if (ExportDecls)
+G.generateDecls(OS, Records);
+  else
+G.generate(OS, Records);
 
   return false;
 }
Index: libc/utils/HdrGen/Generator.h
===
--- libc/utils/HdrGen/Generator.h
+++ libc/utils/HdrGen/Generator.h
@@ -52,6 +52,7 @@
 ArgMap(Map) {}
 
   void generate(llvm::raw_ostream , llvm::RecordKeeper );
+  void generateDecls(llvm::raw_ostream , llvm::RecordKeeper );
 };
 
 } // namespace llvm_libc
Index: libc/utils/HdrGen/Generator.cpp
===
--- libc/utils/HdrGen/Generator.cpp
+++ libc/utils/HdrGen/Generator.cpp
@@ -10,6 +10,7 @@
 
 #include "IncludeFileCommand.h"
 #include "PublicAPICommand.h"
+#include "utils/LibcTableGenUtil/APIIndexer.h"
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -116,4 +117,78 @@
   }
 }
 
+void Generator::generateDecls(llvm::raw_ostream ,
+  llvm::RecordKeeper ) {
+
+  OS << "//===-- C standard declarations for " << StdHeader << " "
+ << std::string(80 - (42 + StdHeader.size()), '-') << "===//\n"
+ << "//\n"
+ << "// Part of the LLVM Project, under the Apache License v2.0 with LLVM "
+"Exceptions.\n"
+ << "// See https://llvm.org/LICENSE.txt for license information.\n"
+ << "// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n"
+ << "//\n"
+ << "//"
+"===---"
+"---===//\n\n";
+
+  std::string HeaderGuard(StdHeader.size(), '\0');
+  llvm::transform(StdHeader, HeaderGuard.begin(), [](const char C) -> char {
+return !isalnum(C) ? '_' : llvm::toUpper(C);
+  });
+  OS << "#ifndef __LLVM_LIBC_DECLARATIONS_" << HeaderGuard << "\n"
+ << "#define __LLVM_LIBC_DECLARATIONS_" << HeaderGuard << "\n\n";
+
+  OS << "#ifndef __LIBC_ATTRS\n"
+ << "#define __LIBC_ATTRS\n"
+ << "#endif\n\n";
+
+  OS << "#ifdef __cplusplus\n"
+ << "extern \"C\" {\n"
+ << "#endif\n\n";
+
+  APIIndexer G(StdHeader, Records);
+  for (auto  : EntrypointNameList) {
+// Filter out functions not exported by this header.
+if (G.FunctionSpecMap.find(Name) == G.FunctionSpecMap.end())
+  continue;
+
+llvm::Record *FunctionSpec = G.FunctionSpecMap[Name];
+llvm::Record *RetValSpec = FunctionSpec->getValueAsDef("Return");
+llvm::Record *ReturnType = RetValSpec->getValueAsDef("ReturnType");
+
+OS << G.getTypeAsString(ReturnType) << " " << Name << "(";
+
+auto ArgsList = FunctionSpec->getValueAsListOfDefs("Args");
+for (size_t i = 0; i < ArgsList.size(); ++i) {
+  llvm::Record *ArgType = ArgsList[i]->getValueAsDef("ArgType");
+  OS << G.getTypeAsString(ArgType);
+  if (i < ArgsList.size() - 1)
+OS << ", ";
+}
+
+OS << ") __LIBC_ATTRS;\n\n";
+  }
+
+  // Make another pass over entrypoints to emit object declarations.
+  for (const auto  : EntrypointNameList) {
+if (G.ObjectSpecMap.find(Name) == G.ObjectSpecMap.end())
+  continue;
+llvm::Record *ObjectSpec = G.ObjectSpecMap[Name];
+auto Type = ObjectSpec->getValueAsString("Type");
+OS << "extern " << Type << " " << Name << " __LIBC_ATTRS;\n";
+  }
+
+  // Emit a final newline if we emitted any object declarations.
+  if (llvm::any_of(EntrypointNameList, [&](const std::string ) {
+return G.ObjectSpecMap.find(Name) != 

[PATCH] D153205: [clang-format] Support block indenting array/struct list initializers

2023-07-05 Thread Gedare Bloom via Phabricator via cfe-commits
gedare updated this revision to Diff 537531.
gedare added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153205

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25535,26 +25535,26 @@
".foo = \"x\",\n"
".bar = \"y\",\n"
".baz = \"z\"\n"
-   "};\n",
+   "};",
Style);
   // List initialization.
   verifyFormat("SomeStruct s{\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "};\n",
+   "};",
Style);
   verifyFormat("SomeStruct{\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "};\n",
+   "};",
Style);
   verifyFormat("new SomeStruct{\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "};\n",
+   "};",
Style);
   // Member initializer.
   verifyFormat("class SomeClass {\n"
@@ -25563,62 +25563,62 @@
"  \"y\",\n"
"  \"z\",\n"
"  };\n"
-   "};\n",
+   "};",
Style);
   // Constructor member initializer.
   verifyFormat("SomeClass::SomeClass : strct{\n"
"   \"x\",\n"
"   \"y\",\n"
"   \"z\",\n"
-   "   } {}\n",
+   "   } {}",
Style);
   // Copy initialization.
   verifyFormat("SomeStruct s = SomeStruct{\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "};\n",
+   "};",
Style);
   // Copy list initialization.
   verifyFormat("SomeStruct s = {\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "};\n",
+   "};",
Style);
   // Assignment operand initialization.
   verifyFormat("s = {\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "};\n",
+   "};",
Style);
   // Returned object initialization.
   verifyFormat("return {\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "};\n",
+   "};",
Style);
   // Initializer list.
   verifyFormat("auto initializerList = {\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "};\n",
+   "};",
Style);
   // Function parameter initialization.
   verifyFormat("func({\n"
"\"x\",\n"
"\"y\",\n"
"\"z\",\n"
-   "});\n",
+   "});",
Style);
   // Nested init lists.
   verifyFormat("SomeStruct s = {\n"
"{{init1, init2, init3, init4, init5},\n"
" {init1, init2, init3, init4, init5}}\n"
-   "};\n",
+   "};",
Style);
   verifyFormat("SomeStruct s = {\n"
"{{\n"
@@ -25629,7 +25629,7 @@
" .init5 = 5,\n"
" },\n"
" {init1, init2, init3, init4, init5}}\n"
-   "};\n",
+   "};",
Style);
   verifyFormat("SomeArrayT a[3] = {\n"
"{\n"
@@ -25641,7 +25641,7 @@
"bar,\n"
"},\n"
"SomeArrayT{},\n"
-   "};\n",
+   "};",
Style);
   verifyFormat("SomeArrayT a[3] = {\n"
"{foo},\n"
@@ -25658,7 +25658,7 @@
"},\n"
"},\n"
"{baz},\n"
-   "};\n",
+   "};",
Style);
 }
 
Index: clang/lib/Format/FormatToken.cpp

[PATCH] D153600: Implement -frecord-command-line for XCOFF

2023-07-05 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added inline comments.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:993
+  // Metadata needs to be padded out to an even word size.
+  uint32_t PaddedSize = alignTo(std::max((int)MetadataSize, 1), 4);
+  uint32_t PaddingSize = PaddedSize - MetadataSize;

With the `MetadataSize == 0` case handled the `std::max` should be redundant 
now, right?

Also the literal `4` can be `WordSize`



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:1018
+  for (; Index + WordSize <= MetadataSize; Index += WordSize)
+PrintWord((const uint8_t *)Metadata.data() + Index);
+

Nit: for pointer casts I would prefer an explicit `reinterpret_cast`



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:981
+
+  // Metadata needs to be padded out to an even word size.
+  size_t MetadataSize = Metadata.size();

stephenpeckham wrote:
> There's no requirement to pad the .info section. When you generate assembly 
> language, the .info pseudo-op can only generate words of data, so the if the 
> data length is not 0(mod 4), the last word will have to be padded with 
> low-order 0s.  This means that the length of the .info section will be a 
> multiple of 4. The length, on the other hand, should be exact. At link time, 
> only "length" bytes will be copied to the output file.
> 
> If you emit object code directly, you will not need to emit any padding bytes.
Does the comment still need updating then? It could capture the fact that the 
"lowest common denominator" is the assembly syntax as it works in terms of 
words, and so may requiring padding in the final word. We can be clear that we 
apply the same restriction to the object case judiciously, as it make the 
output identical and avoids more code paths. We could also note that the linker 
can use the length to optimize the final linked binary.

These all clear things up to a fresh reader, so I think they are worthwhile 
things to include in comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153600

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


[PATCH] D154531: [AMDGPU] Support -mcpu=native for OpenCL

2023-07-05 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:86
+def warn_drv_multi_gpu_arch : Warning<
+  "multiple %0 architecture are detected: %1; only the first one is used for "
+  "'%2'">, InGroup;

s/architecture/architectures/

Maybe should stick to the "device" terminology opencl uses


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

https://reviews.llvm.org/D154531

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


[PATCH] D153600: Implement -frecord-command-line for XCOFF

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/lib/MC/MCAsmStreamer.cpp:972
+void MCAsmStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) {
+  const char *InfoDirective = "\t.info ";
+  const char *Separator = ", ";




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153600

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


[PATCH] D153205: [clang-format] Support block indenting array/struct list initializers

2023-07-05 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added inline comments.



Comment at: clang/include/clang/Format/Format.h:95-98
 /// \warning
-///  Note: This currently only applies to parentheses.
+///  Note: This currently only applies to parentheses and braced list
+///  initializers when ``Cpp11BracedListStyle`` is ``True``.
 /// \endwarning

owenpan wrote:
> 
This `\note` is not currently supported? I have submitted a rev D154552 to add 
such ability.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153205

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


[PATCH] D153600: Implement -frecord-command-line for XCOFF

2023-07-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:2974
+RSOS << "@(#)" << MDS->getString();
+RSOS.write('\0');
+  }

hubert.reinterpretcast wrote:
> stephenpeckham wrote:
> > I would use a newline here.  The AIX **what **command looks for @(#) and 
> > echos subsequent bytes until it sees a double quote, a backslash, a > 
> > symbol, newline, or null byte.  The @(#) is not echoed, nor is the 
> > terminating character.  The **what **command prints a newline after it 
> > finds a terminating character.  This means that if the command line 
> > contains any of the special characters, the line will be truncated.
> > 
> > Exception:  If the @(#) is followed by "opt " or " opt ", the terminating 
> > characters are only a newline or null byte. This allows any of the other 
> > special characters to be part of the command line. It doesn't really matter 
> > if you use a newline or a null byte, but the legacy XL compiler uses a 
> > newline. The "opt" keyword should appear if the command line can contain a 
> > double quote, a > or a backslash.
> > 
> > The legacy compiler also uses other keywords besides "opt", including 
> > "version" and "cfg".  The **what** command doesn't do anything special with 
> > these keywords.
> As mentioned offline, newline on its own has potential of ambiguity because 
> it can appear in command line options (null bytes cannot). If there is a 
> preference for newline to be present, then having a null byte after could 
> help.
> 
> Note that `@(#)opt ` can appear on the command line too. Using `what` will 
> have limitations (but we should leave the possibility open for other 
> tools/methods to work).
> 
Thanks; I confirm that my comment has been addressed. I have no further 
comments at this time. Feel free to commit if another reviewer approves the 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153600

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


[PATCH] D154552: [clang-format] Add note directive generation for docs

2023-07-05 Thread Gedare Bloom via Phabricator via cfe-commits
gedare created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
gedare requested review of this revision.
Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Generate a ..note:: directive when the \note is encountered in Format.h


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154552

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -133,8 +133,10 @@
   /// if not ``None``, when using initialization for an array of structs
   /// aligns the fields into columns.
   ///
-  /// NOTE: As of clang-format 15 this option only applied to arrays with equal
-  /// number of columns per row.
+  /// \note
+  ///  As of clang-format 15 this option only applied to arrays with equal
+  ///  number of columns per row.
+  /// \endnote
   ///
   /// \version 13
   ArrayInitializerAlignmentStyle AlignArrayOfStructures;
@@ -439,8 +441,10 @@
 
   /// Control of trailing comments.
   ///
-  /// NOTE: As of clang-format 16 this option is not a bool but can be set
-  /// to the options. Conventional bool options still can be parsed as before.
+  /// \note
+  ///  As of clang-format 16 this option is not a bool but can be set
+  ///  to the options. Conventional bool options still can be parsed as before.
+  /// \endnote
   ///
   /// \code{.yaml}
   ///   # Example of usage:
@@ -1093,8 +1097,10 @@
 /// \endcode
 bool AfterNamespace;
 /// Wrap ObjC definitions (interfaces, implementations...).
-/// \note @autoreleasepool and @synchronized blocks are wrapped
-/// according to `AfterControlStatement` flag.
+/// \note
+///  @autoreleasepool and @synchronized blocks are wrapped
+///  according to `AfterControlStatement` flag.
+/// \endnote
 bool AfterObjCDeclaration;
 /// Wrap struct definitions.
 /// \code
@@ -1289,7 +1295,9 @@
   /// otherwise it will scan until the closing `]` to determine if it should add
   /// newlines between elements (prettier compatible).
   ///
-  /// NOTE: This is currently only for formatting JSON.
+  /// \note
+  ///  This is currently only for formatting JSON.
+  /// \endnote
   /// \code
   ///true:  false:
   ///[  vs.  [1, 2, 3, 4]
@@ -2179,8 +2187,10 @@
   /// made, clang-format analyzes whether there are other bin-packed cases in
   /// the input file and act accordingly.
   ///
-  /// NOTE: This is an experimental flag, that might go away or be renamed. Do
-  /// not use this in config files, etc. Use at your own risk.
+  /// \note
+  ///  This is an experimental flag, that might go away or be renamed. Do
+  ///  not use this in config files, etc. Use at your own risk.
+  /// \endnote
   /// \version 3.7
   bool ExperimentalAutoDetectBinPacking;
 
@@ -3199,10 +3209,12 @@
   ///   * restrict
   ///   * type
   ///
-  /// Note: it MUST contain 'type'.
-  /// Items to the left of 'type' will be placed to the left of the type and
-  /// aligned in the order supplied. Items to the right of 'type' will be placed
-  /// to the right of the type and aligned in the order supplied.
+  /// \note
+  ///  it MUST contain 'type'.
+  ///  Items to the left of 'type' will be placed to the left of the type and
+  ///  aligned in the order supplied. Items to the right of 'type' will be
+  ///  placed to the right of the type and aligned in the order supplied.
+  /// \endnote
   ///
   /// \code{.yaml}
   ///   QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
Index: clang/docs/tools/dump_format_style.py
===
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -257,6 +257,14 @@
 endwarning_match = re.match(r"^/// +\\endwarning$", line)
 if endwarning_match:
 return ""
+
+match = 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

hubert.reinterpretcast wrote:
> cor3ntin wrote:
> > cor3ntin wrote:
> > > cor3ntin wrote:
> > > > hubert.reinterpretcast wrote:
> > > > > hubert.reinterpretcast wrote:
> > > > > > hubert.reinterpretcast wrote:
> > > > > > > hubert.reinterpretcast wrote:
> > > > > > > > Can we have tests for:
> > > > > > > > ```
> > > > > > > > struct { int _, _; } a = { ._ = 0 };
> > > > > > > > ```
> > > > > > > > 
> > > > > > > > and
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > struct A {
> > > > > > > >   A();
> > > > > > > >   int _, _;
> > > > > > > > };
> > > > > > > > 
> > > > > > > > A::A() : _(0) {}
> > > > > > > > ```
> > > > > > > Codegen test for
> > > > > > > ```
> > > > > > > static union { int _ = 42; };
> > > > > > > int  = _;
> > > > > > > int foo() { return 13; }
> > > > > > > static union { int _ = foo(); };
> > > > > > > int main(void) { return ref; }
> > > > > > > ```
> > > > > > > might be interesting.
> > > > > > > 
> > > > > > > I suspect that this case was missed in the committee discussion 
> > > > > > > of the paper @cor3ntin.
> > > > > > Less controversial tests to consider:
> > > > > > ```
> > > > > > struct A {
> > > > > >   int _;
> > > > > >   union { int _; };
> > > > > > };
> > > > > > struct B { union { int _, _; }; };
> > > > > > ```
> > > > > > 
> > > > > In a similar vein, a codegen test for:
> > > > > ```
> > > > > struct A { A(); };
> > > > > inline void f [[gnu::used]]() {
> > > > >   static union { A _{}; };
> > > > >   static union { A _{}; };
> > > > > }
> > > > > ```
> > > > > 
> > > > > Perhaps not intended to be allowed though (premise was no symbols 
> > > > > with "linkage"?)
> > > > What's interesting about 
> > > > 
> > > > ```
> > > > static union { int _ = 42; };
> > > > int  = _;
> > > > int foo() { return 13; }
> > > > static union { int _ = foo(); };
> > > > int main(void) { return ref; }
> > > > ```
> > > > ?
> > > > It's already supported by clang https://godbolt.org/z/6j89EdnEo
> > > > 
> > > > 
> > > > I'm adding the other tests (and fixing the associated bugs, of which 
> > > > there were a few...)
> > > > 
> > > > Perhaps not intended to be allowed though (premise was no symbols with 
> > > > "linkage"?)
> > > 
> > > 
> > > Yes, this should be ill-formed, anything where we would have to mangle  
> > > multiple `_` should be ill-formed.
> > > I do believe that's covered though, `_` does not have storage duration.
> > > What's interesting about 
> > > 
> > > ```
> > > static union { int _ = 42; };
> > > int  = _;
> > > int foo() { return 13; }
> > > static union { int _ = foo(); };
> > > int main(void) { return ref; }
> > > ```
> > > ?
> > > It's already supported by clang https://godbolt.org/z/6j89EdnEo
> > > 
> > > 
> > > I'm adding the other tests (and fixing the associated bugs, of which 
> > > there were a few...)
> > > 
> > 
> > I see it now. Thanks, I hate it. There is apparently a preexisting bug.
> > And yes, i think we should say something about members of anonymous union 
> > declared at namespace scope in the standard I realize now this is 
> > missing
> > Thanks for catching that.
> > Thanks for catching that.
> 
> Glad to be of help!
> I do believe that's covered though, `_` does not have storage duration.

It's not covered by the wording: `_` //is// a non-static data member.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D154531: [AMDGPU] Support -mcpu=native for OpenCL

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Seems reasonable. I assume that there isn't a way to add a portable test.


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

https://reviews.llvm.org/D154531

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


[PATCH] D154484: [clang-format] Add an option to remove redundant parentheses

2023-07-05 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I reckon you could detect the `=` condition between the matching paren don't 
you?  I ran this on my quite large code base and this was one of the only 
issues I've seen thus far..

This is a great feature, for my codebase this generated changes in about 10% of 
all files (but often only a couple of lines or so per file, mostly people doing 
return (*this);

I think this will be a great feature to have.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154484

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

cor3ntin wrote:
> cor3ntin wrote:
> > cor3ntin wrote:
> > > hubert.reinterpretcast wrote:
> > > > hubert.reinterpretcast wrote:
> > > > > hubert.reinterpretcast wrote:
> > > > > > hubert.reinterpretcast wrote:
> > > > > > > Can we have tests for:
> > > > > > > ```
> > > > > > > struct { int _, _; } a = { ._ = 0 };
> > > > > > > ```
> > > > > > > 
> > > > > > > and
> > > > > > > 
> > > > > > > ```
> > > > > > > struct A {
> > > > > > >   A();
> > > > > > >   int _, _;
> > > > > > > };
> > > > > > > 
> > > > > > > A::A() : _(0) {}
> > > > > > > ```
> > > > > > Codegen test for
> > > > > > ```
> > > > > > static union { int _ = 42; };
> > > > > > int  = _;
> > > > > > int foo() { return 13; }
> > > > > > static union { int _ = foo(); };
> > > > > > int main(void) { return ref; }
> > > > > > ```
> > > > > > might be interesting.
> > > > > > 
> > > > > > I suspect that this case was missed in the committee discussion of 
> > > > > > the paper @cor3ntin.
> > > > > Less controversial tests to consider:
> > > > > ```
> > > > > struct A {
> > > > >   int _;
> > > > >   union { int _; };
> > > > > };
> > > > > struct B { union { int _, _; }; };
> > > > > ```
> > > > > 
> > > > In a similar vein, a codegen test for:
> > > > ```
> > > > struct A { A(); };
> > > > inline void f [[gnu::used]]() {
> > > >   static union { A _{}; };
> > > >   static union { A _{}; };
> > > > }
> > > > ```
> > > > 
> > > > Perhaps not intended to be allowed though (premise was no symbols with 
> > > > "linkage"?)
> > > What's interesting about 
> > > 
> > > ```
> > > static union { int _ = 42; };
> > > int  = _;
> > > int foo() { return 13; }
> > > static union { int _ = foo(); };
> > > int main(void) { return ref; }
> > > ```
> > > ?
> > > It's already supported by clang https://godbolt.org/z/6j89EdnEo
> > > 
> > > 
> > > I'm adding the other tests (and fixing the associated bugs, of which 
> > > there were a few...)
> > > 
> > > Perhaps not intended to be allowed though (premise was no symbols with 
> > > "linkage"?)
> > 
> > 
> > Yes, this should be ill-formed, anything where we would have to mangle  
> > multiple `_` should be ill-formed.
> > I do believe that's covered though, `_` does not have storage duration.
> > What's interesting about 
> > 
> > ```
> > static union { int _ = 42; };
> > int  = _;
> > int foo() { return 13; }
> > static union { int _ = foo(); };
> > int main(void) { return ref; }
> > ```
> > ?
> > It's already supported by clang https://godbolt.org/z/6j89EdnEo
> > 
> > 
> > I'm adding the other tests (and fixing the associated bugs, of which there 
> > were a few...)
> > 
> 
> I see it now. Thanks, I hate it. There is apparently a preexisting bug.
> And yes, i think we should say something about members of anonymous union 
> declared at namespace scope in the standard I realize now this is missing
> Thanks for catching that.
> Thanks for catching that.

Glad to be of help!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D154550: [clang-format] Allow empty loops on a single line.

2023-07-05 Thread Gedare Bloom via Phabricator via cfe-commits
gedare created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
gedare requested review of this revision.

Changes the AllowShortLoopsOnASingleLine from a boolean to a style option
consisting of three choices: Never, NonEmpty, and All. Never does not merge a
loop body back to the header's line. NonEmpty allows for merging a loop body
only if it has an expression. The new option is All, which will merge empty
loop bodies, i.e., a semi-colon.

The options of true and false are maintained for backward compatibility to mean
NonEmpty and Never, respectively.

See also Github Issue 61708.
https://github.com/llvm/llvm-project/issues/61708


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154550

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1380,7 +1380,7 @@
 
 TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) {
   FormatStyle AllowsMergedLoops = getLLVMStyle();
-  AllowsMergedLoops.AllowShortLoopsOnASingleLine = true;
+  AllowsMergedLoops.AllowShortLoopsOnASingleLine = FormatStyle::SWFLS_NonEmpty;
   verifyFormat("while (true) continue;", AllowsMergedLoops);
   verifyFormat("for (;;) continue;", AllowsMergedLoops);
   verifyFormat("for (int  : vec) v *= 2;", AllowsMergedLoops);
@@ -1436,6 +1436,66 @@
"  while (true);\n"
"}",
AllowsMergedLoops);
+  AllowsMergedLoops.AllowShortLoopsOnASingleLine = FormatStyle::SWFLS_All;
+  verifyFormat("while (true) continue;", AllowsMergedLoops);
+  verifyFormat("for (;;) continue;", AllowsMergedLoops);
+  verifyFormat("for (int  : vec) v *= 2;", AllowsMergedLoops);
+  verifyFormat("BOOST_FOREACH (int , vec) v *= 2;", AllowsMergedLoops);
+  verifyFormat("while (true) ;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;) ;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;)\n"
+   "  for (;;) continue;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;)\n"
+   "  for (;;) ;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;)\n"
+   "  while (true) ;",
+   AllowsMergedLoops);
+  verifyFormat("while (true)\n"
+   "  for (;;) continue;",
+   AllowsMergedLoops);
+  verifyFormat("while (true)\n"
+   "  for (;;) ;",
+   AllowsMergedLoops);
+  verifyFormat("BOOST_FOREACH (int , vec)\n"
+   "  for (;;) ;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;)\n"
+   "  BOOST_FOREACH (int , vec) ;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;) // Can't merge this\n"
+   "  ;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;) /* still don't merge */\n"
+   "  ;",
+   AllowsMergedLoops);
+  verifyFormat("do a++;\n"
+   "while (true);",
+   AllowsMergedLoops);
+  verifyFormat("do /* Don't merge */\n"
+   "  a++;\n"
+   "while (true);",
+   AllowsMergedLoops);
+  verifyFormat("do // Don't merge\n"
+   "  a++;\n"
+   "while (true);",
+   AllowsMergedLoops);
+  verifyFormat("do\n"
+   "  // Don't merge\n"
+   "  a++;\n"
+   "while (true);",
+   AllowsMergedLoops);
+  // Without braces labels are interpreted differently.
+  verifyFormat("{\n"
+   "  do\n"
+   "  label:\n"
+   "a++;\n"
+   "  while (true);\n"
+   "}",
+   AllowsMergedLoops);
 }
 
 TEST_F(FormatTest, FormatShortBracedStatements) {
@@ -1443,7 +1503,8 @@
   EXPECT_EQ(AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine, false);
   EXPECT_EQ(AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine,
 FormatStyle::SIS_Never);
-  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine, false);
+  EXPECT_EQ(AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine,
+FormatStyle::SWFLS_Never);
   EXPECT_EQ(AllowSimpleBracedStatements.BraceWrapping.AfterFunction, false);
   verifyFormat("for (;;) {\n"
"  f();\n"
@@ -1488,7 +1549,8 @@
   AllowSimpleBracedStatements.ColumnLimit = 40;
   AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine =
   FormatStyle::SBS_Always;
-  AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
+  AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

cor3ntin wrote:
> cor3ntin wrote:
> > hubert.reinterpretcast wrote:
> > > hubert.reinterpretcast wrote:
> > > > hubert.reinterpretcast wrote:
> > > > > hubert.reinterpretcast wrote:
> > > > > > Can we have tests for:
> > > > > > ```
> > > > > > struct { int _, _; } a = { ._ = 0 };
> > > > > > ```
> > > > > > 
> > > > > > and
> > > > > > 
> > > > > > ```
> > > > > > struct A {
> > > > > >   A();
> > > > > >   int _, _;
> > > > > > };
> > > > > > 
> > > > > > A::A() : _(0) {}
> > > > > > ```
> > > > > Codegen test for
> > > > > ```
> > > > > static union { int _ = 42; };
> > > > > int  = _;
> > > > > int foo() { return 13; }
> > > > > static union { int _ = foo(); };
> > > > > int main(void) { return ref; }
> > > > > ```
> > > > > might be interesting.
> > > > > 
> > > > > I suspect that this case was missed in the committee discussion of 
> > > > > the paper @cor3ntin.
> > > > Less controversial tests to consider:
> > > > ```
> > > > struct A {
> > > >   int _;
> > > >   union { int _; };
> > > > };
> > > > struct B { union { int _, _; }; };
> > > > ```
> > > > 
> > > In a similar vein, a codegen test for:
> > > ```
> > > struct A { A(); };
> > > inline void f [[gnu::used]]() {
> > >   static union { A _{}; };
> > >   static union { A _{}; };
> > > }
> > > ```
> > > 
> > > Perhaps not intended to be allowed though (premise was no symbols with 
> > > "linkage"?)
> > What's interesting about 
> > 
> > ```
> > static union { int _ = 42; };
> > int  = _;
> > int foo() { return 13; }
> > static union { int _ = foo(); };
> > int main(void) { return ref; }
> > ```
> > ?
> > It's already supported by clang https://godbolt.org/z/6j89EdnEo
> > 
> > 
> > I'm adding the other tests (and fixing the associated bugs, of which there 
> > were a few...)
> > 
> > Perhaps not intended to be allowed though (premise was no symbols with 
> > "linkage"?)
> 
> 
> Yes, this should be ill-formed, anything where we would have to mangle  
> multiple `_` should be ill-formed.
> I do believe that's covered though, `_` does not have storage duration.
> What's interesting about 
> 
> ```
> static union { int _ = 42; };
> int  = _;
> int foo() { return 13; }
> static union { int _ = foo(); };
> int main(void) { return ref; }
> ```
> ?
> It's already supported by clang https://godbolt.org/z/6j89EdnEo
> 
> 
> I'm adding the other tests (and fixing the associated bugs, of which there 
> were a few...)
> 

I see it now. Thanks, I hate it. There is apparently a preexisting bug.
And yes, i think we should say something about members of anonymous union 
declared at namespace scope in the standard I realize now this is missing
Thanks for catching that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D153536#4475215 , @philnik wrote:

> Would it be possible to make `__` also a placeholder, so standard libraries 
> can use this before C++26? Or is `_` already a reserved identifier? (I don't 
> think so)

I don't see an issue allowing that in the std namespace. If we allow it 
everywhere, I'm afraid people will rely on it, which would hurt portability/be 
confusing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D153536#4475240 , @dblaikie wrote:

> In D153536#4475199 , @cor3ntin 
> wrote:
>
>> In D153536#4474733 , @dblaikie 
>> wrote:
>>
>>> Maybe try testing with more different values, to demonstrate which entities 
>>> the debugger is finding?
>>>
>>>   int _ = 1;
>>>   int _ = 2;
>>>   {
>>> int _ = 3;
>>> int _ = 7;
>>>   }
>>>
>>> Or something like that. But, honestly, if the point is that these variables 
>>> should be unnameable - perhaps we shouldn't generate any DWARF for them?
>>
>> The variables should still be inspectable, ideally. It's true it makes no 
>> sense to be able to use them in expressions, and maybe if lldb use clang to 
>> evaluate expressions that would just work?
>
> I think that's going to be tricky - because we don't emit DWARF to say where 
> one variable's lifetime starts compared to another in the same scope - so 
> likely a debugger would just always show the first or last variable with the 
> same name in a given scope (so in the above example you could probably only 
> print {1,3} or {2,7}) - and getting it wrong is more likely and more 
> problematic than existing cases of shadowed variables. If we can't get this 
> right, which I don't think we can, practically speaking, at the moment (the 
> DWARF feature we'd have to support to do this better would probably be 
> `DW_AT_start_scope` to say at what instruction the lifetime of a variable 
> starts) - it may be best not to include it at all?

It doesn't seems to be confused on simple examples

  cpp
  * thread #1, name = 'placeholder', stop reason = step in
  frame #0: 0x5157 placeholder`main at 
debug_placeholder.cpp:8:13
 5{
 6int _ = 4;
 7int _ = 5;
  -> 8int _ = 6;
 9}
 10   }
  (lldb) frame variable
  (int) _ = 1
  (int) _ = 2
  (int) _ = 3
  (int) _ = 4
  (int) _ = 5
  (int) _ = -9432

That being said, if you think it's more prudent, I would not mind


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D154295: [Driver][MSVC] Support DWARF fission when using LTO on Windows

2023-07-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added subscribers: hans, rnk.
mstorsjo added a comment.
This revision is now accepted and ready to land.

I think this looks reasonable, unless e.g. @hans or @rnk would disagree.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154295

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D153536#4475199 , @cor3ntin wrote:

> In D153536#4474733 , @dblaikie 
> wrote:
>
>> Maybe try testing with more different values, to demonstrate which entities 
>> the debugger is finding?
>>
>>   int _ = 1;
>>   int _ = 2;
>>   {
>> int _ = 3;
>> int _ = 7;
>>   }
>>
>> Or something like that. But, honestly, if the point is that these variables 
>> should be unnameable - perhaps we shouldn't generate any DWARF for them?
>
> The variables should still be inspectable, ideally. It's true it makes no 
> sense to be able to use them in expressions, and maybe if lldb use clang to 
> evaluate expressions that would just work?

I think that's going to be tricky - because we don't emit DWARF to say where 
one variable's lifetime starts compared to another in the same scope - so 
likely a debugger would just always show the first or last variable with the 
same name in a given scope (so in the above example you could probably only 
print {1,3} or {2,7}) - and getting it wrong is more likely and more 
problematic than existing cases of shadowed variables. If we can't get this 
right, which I don't think we can, practically speaking, at the moment (the 
DWARF feature we'd have to support to do this better would probably be 
`DW_AT_start_scope` to say at what instruction the lifetime of a variable 
starts) - it may be best not to include it at all?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

Would it be possible to make `__` also a placeholder, so standard libraries can 
use this before C++26? Or is `_` already a reserved identifier? (I don't think 
so)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D153536#4474733 , @dblaikie wrote:

> Maybe try testing with more different values, to demonstrate which entities 
> the debugger is finding?
>
>   int _ = 1;
>   int _ = 2;
>   {
> int _ = 3;
> int _ = 7;
>   }
>
> Or something like that. But, honestly, if the point is that these variables 
> should be unnameable - perhaps we shouldn't generate any DWARF for them?

The variables should still be inspectable, ideally. It's true it makes no sense 
to be able to use them in expressions, and maybe if lldb use clang to evaluate 
expressions that would just work?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D153835: [Sema] Clone VisibilityAttr for functions in template instantiations

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153835

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

hubert.reinterpretcast wrote:
> hubert.reinterpretcast wrote:
> > hubert.reinterpretcast wrote:
> > > hubert.reinterpretcast wrote:
> > > > Can we have tests for:
> > > > ```
> > > > struct { int _, _; } a = { ._ = 0 };
> > > > ```
> > > > 
> > > > and
> > > > 
> > > > ```
> > > > struct A {
> > > >   A();
> > > >   int _, _;
> > > > };
> > > > 
> > > > A::A() : _(0) {}
> > > > ```
> > > Codegen test for
> > > ```
> > > static union { int _ = 42; };
> > > int  = _;
> > > int foo() { return 13; }
> > > static union { int _ = foo(); };
> > > int main(void) { return ref; }
> > > ```
> > > might be interesting.
> > > 
> > > I suspect that this case was missed in the committee discussion of the 
> > > paper @cor3ntin.
> > Less controversial tests to consider:
> > ```
> > struct A {
> >   int _;
> >   union { int _; };
> > };
> > struct B { union { int _, _; }; };
> > ```
> > 
> In a similar vein, a codegen test for:
> ```
> struct A { A(); };
> inline void f [[gnu::used]]() {
>   static union { A _{}; };
>   static union { A _{}; };
> }
> ```
> 
> Perhaps not intended to be allowed though (premise was no symbols with 
> "linkage"?)
What's interesting about 

```
static union { int _ = 42; };
int  = _;
int foo() { return 13; }
static union { int _ = foo(); };
int main(void) { return ref; }
```
?
It's already supported by clang https://godbolt.org/z/6j89EdnEo


I'm adding the other tests (and fixing the associated bugs, of which there were 
a few...)




Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

cor3ntin wrote:
> hubert.reinterpretcast wrote:
> > hubert.reinterpretcast wrote:
> > > hubert.reinterpretcast wrote:
> > > > hubert.reinterpretcast wrote:
> > > > > Can we have tests for:
> > > > > ```
> > > > > struct { int _, _; } a = { ._ = 0 };
> > > > > ```
> > > > > 
> > > > > and
> > > > > 
> > > > > ```
> > > > > struct A {
> > > > >   A();
> > > > >   int _, _;
> > > > > };
> > > > > 
> > > > > A::A() : _(0) {}
> > > > > ```
> > > > Codegen test for
> > > > ```
> > > > static union { int _ = 42; };
> > > > int  = _;
> > > > int foo() { return 13; }
> > > > static union { int _ = foo(); };
> > > > int main(void) { return ref; }
> > > > ```
> > > > might be interesting.
> > > > 
> > > > I suspect that this case was missed in the committee discussion of the 
> > > > paper @cor3ntin.
> > > Less controversial tests to consider:
> > > ```
> > > struct A {
> > >   int _;
> > >   union { int _; };
> > > };
> > > struct B { union { int _, _; }; };
> > > ```
> > > 
> > In a similar vein, a codegen test for:
> > ```
> > struct A { A(); };
> > inline void f [[gnu::used]]() {
> >   static union { A _{}; };
> >   static union { A _{}; };
> > }
> > ```
> > 
> > Perhaps not intended to be allowed though (premise was no symbols with 
> > "linkage"?)
> What's interesting about 
> 
> ```
> static union { int _ = 42; };
> int  = _;
> int foo() { return 13; }
> static union { int _ = foo(); };
> int main(void) { return ref; }
> ```
> ?
> It's already supported by clang https://godbolt.org/z/6j89EdnEo
> 
> 
> I'm adding the other tests (and fixing the associated bugs, of which there 
> were a few...)
> 
> Perhaps not intended to be allowed though (premise was no symbols with 
> "linkage"?)


Yes, this should be ill-formed, anything where we would have to mangle  
multiple `_` should be ill-formed.
I do believe that's covered though, `_` does not have storage duration.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D154495: clang: Attach !fpmath metadata to __builtin_sqrt based on language flags

2023-07-05 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:5602
+// source are correctly rounded.
+SetFPAccuracy(Val, 2.5);
+  }

arsenm wrote:
> yaxunl wrote:
> > the spec says sqrt relative error is 3ULP 
> > https://registry.khronos.org/OpenCL/specs/2.2/html/OpenCL_C.html#relative-error-as-ulps
> Did that change between versions? In any case I don’t want to change the 
> currently used threshold in this patch. We only need 1.0 anyway 
Oh, I see the threshold is 2.5 for fdiv and 3.0 for sqrt.


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

https://reviews.llvm.org/D154495

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


[PATCH] D154396: [clang] Add support for SerenityOS

2023-07-05 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.h:38
+
+class LLVM_LIBRARY_VISIBILITY Serenity : public ToolChain {
+public:

Have you considered inheriting from `Generic_GCC` to allow more code reuse?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-07-05 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 537498.

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

https://reviews.llvm.org/D153883

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/amdgcn_target_device_vla.cpp

Index: clang/test/OpenMP/amdgcn_target_device_vla.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn_target_device_vla.cpp
@@ -0,0 +1,1260 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+int foo1() {
+  int sum = 0.0;
+  #pragma omp target map(tofrom: sum)
+  {
+int N = 10;
+int A[N];
+
+for (int i = 0; i < N; i++)
+  A[i] = i;
+
+for (int i = 0; i < N; i++)
+  sum += A[i];
+  }
+  return sum;
+}
+
+int foo2() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute parallel for map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo3() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo4() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  int N = 10;
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int main() {
+  return foo1() + foo2() + foo3() + foo4();
+}
+
+#endif
+// CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z4foo1v_l12
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(4) [[SUM:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUM_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-NEXT:[[N:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__VLA_EXPR0:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[I1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[SUM_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[SUM_ADDR]] to ptr
+// CHECK-NEXT:[[N_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[N]] to ptr
+// CHECK-NEXT:[[__VLA_EXPR0_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[__VLA_EXPR0]] to ptr
+// CHECK-NEXT:[[I_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I]] to ptr
+// CHECK-NEXT:[[I1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I1]] to ptr
+// CHECK-NEXT:store ptr [[SUM]], ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1:[0-9]+]] to ptr), i8 1, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP1]], -1
+// CHECK-NEXT:br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
+// CHECK:   user_code.entry:
+// CHECK-NEXT:store i32 10, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = zext i32 [[TMP2]] to i64
+// CHECK-NEXT:[[TMP4:%.*]] = mul nuw i64 [[TMP3]], 4
+// CHECK-NEXT:[[TMP5:%.*]] = add nuw i64 [[TMP4]], 3
+// CHECK-NEXT:[[TMP6:%.*]] = udiv i64 [[TMP5]], 4
+// CHECK-NEXT:[[TMP7:%.*]] = mul nuw i64 [[TMP6]], 4
+// CHECK-NEXT:[[A:%.*]] = call align 4 ptr @__kmpc_alloc_shared(i64 [[TMP7]])
+// CHECK-NEXT:store i64 [[TMP3]], ptr [[__VLA_EXPR0_ASCAST]], align 8
+// 

[PATCH] D154484: [clang-format] Add an option to remove redundant parentheses

2023-07-05 Thread Owen Pan via Phabricator via cfe-commits
owenpan planned changes to this revision.
owenpan added a comment.

Yep! After reformating `clang/lib/Format/` and rebuilding clang-format, I got 
the same warning:

  WhitespaceManager.cpp:233:45: warning: using the result of an assignment as a 
condition without parentheses [-Wparentheses]
} else if (Change.StartOfBlockComment = LastBlockComment) {
   ~~~^~
  /Users/Owen/llvm-project/clang/lib/Format/WhitespaceManager.cpp:233:45: note: 
place parentheses around the assignment to silence this warning
} else if (Change.StartOfBlockComment = LastBlockComment) {
  ^
   ()
  /Users/Owen/llvm-project/clang/lib/Format/WhitespaceManager.cpp:233:45: note: 
use '==' to turn this assignment into an equality comparison
} else if (Change.StartOfBlockComment = LastBlockComment) {
  ^
  ==
  1 warning generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154484

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-07-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:591
+  auto  =
+  *(static_cast(()));
+  RT.getKmpcFreeShared(CGF, AddrSizePair);

Same, just CGOpenMPRuntime  = CGM.getOpenMPRuntime();



Comment at: clang/lib/CodeGen/CGDecl.cpp:1605
+if (getLangOpts().OpenMPIsDevice) {
+  auto  = static_cast(CGM.getOpenMPRuntime());
+  if (RT.isDelayedVariableLengthDecl(*this, )) {

Here and in other places, jusy remove the cast to CGOpenMPRuntimeGPU, 
CGM.getOpenMPRuntime() already provides virtual functions, use them directly 
without cast:
```
CGOpenMPRuntime  = CGM.getOpenMPRuntime();
```



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:699-710
+  /// Get call to __kmpc_alloc_shared
+  virtual std::pair
+  getKmpcAllocShared(CodeGenFunction , const VarDecl *VD) {
+llvm_unreachable("not implemented");
+  }
+
+  /// Get call to __kmpc_free_shared

doru1004 wrote:
> @ABataev I have added the interface entries here.
Then you already good, just do not gast to CGOpenMPRuntimeGPU, use 
CGM.getOpenMPRuntime() directly since it already has these member functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-07-05 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.h:699-710
+  /// Get call to __kmpc_alloc_shared
+  virtual std::pair
+  getKmpcAllocShared(CodeGenFunction , const VarDecl *VD) {
+llvm_unreachable("not implemented");
+  }
+
+  /// Get call to __kmpc_free_shared

@ABataev I have added the interface entries here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-07-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1606
+  CGOpenMPRuntimeGPU  =
+  *(static_cast(()));
+  if (RT.isDelayedVariableLengthDecl(*this, )) {

doru1004 wrote:
> ABataev wrote:
> > ABataev wrote:
> > > 1. use `static_cast(CGM.getOpenMPRuntime())`
> > > 2. It will crash if your device is not GPU. Better to make 
> > > `getKmpcAllocShared` and `getKmpcFreeShared` virtual (just like 
> > > `isDelayedVariableLengthDecl`) in base CGOpenMPRuntime, since it may be 
> > > required not only for GPU-based devices.
> > Check the second item, please, better to make all new member function 
> > virtual and handle it for non-GPU devices too
> The support I am adding is only meant for GPUs. I am not sure why we need to 
> consider non-GPUs. There already exists a VLA handling for non-GPUs and that 
> one should be used.
1. It will crash the compiler if your device is not a GPU (say, CPU).
2. I'm not asking to implement it for non-GPU, I'm asking to provide common 
interface. The general implementation should call just llvm_unreachable, 
nothing else.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-07-05 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1606
+  CGOpenMPRuntimeGPU  =
+  *(static_cast(()));
+  if (RT.isDelayedVariableLengthDecl(*this, )) {

ABataev wrote:
> ABataev wrote:
> > 1. use `static_cast(CGM.getOpenMPRuntime())`
> > 2. It will crash if your device is not GPU. Better to make 
> > `getKmpcAllocShared` and `getKmpcFreeShared` virtual (just like 
> > `isDelayedVariableLengthDecl`) in base CGOpenMPRuntime, since it may be 
> > required not only for GPU-based devices.
> Check the second item, please, better to make all new member function virtual 
> and handle it for non-GPU devices too
The support I am adding is only meant for GPUs. I am not sure why we need to 
consider non-GPUs. There already exists a VLA handling for non-GPUs and that 
one should be used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D154388: Don't pass -ibuiltininc, which is used only by the driver, to CC1

2023-07-05 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
ahatanak marked an inline comment as done.
Closed by commit rGa2b7297dff34: Dont pass -ibuiltininc, which is used 
only by the driver, to CC1 (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D154388?vs=536884=537488#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154388

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/darwin-header-search-system.cpp


Index: clang/test/Driver/darwin-header-search-system.cpp
===
--- clang/test/Driver/darwin-header-search-system.cpp
+++ clang/test/Driver/darwin-header-search-system.cpp
@@ -131,6 +131,7 @@
 // RUN:   -DRESOURCE=%S/Inputs/resource_dir \
 // RUN:   --check-prefix=CHECK-NOSTDINC-BUILTINC %s
 // CHECK-NOSTDINC-BUILTINC: "-cc1"
+// CHECK-NOSTDINC-BUILTINC-NOT: "-ibuiltininc"
 // CHECK-NOSTDINC-BUILTINC-NOT: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
 // CHECK-NOSTDINC-BUILTINC: "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK-NOSTDINC-BUILTINC-NOT: "-internal-externc-isystem" 
"[[SYSROOT]]/usr/include"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -1305,6 +1305,9 @@
 } else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) {
   // Translated to -internal-isystem by the driver, no need to pass to cc1.
   continue;
+} else if (A->getOption().matches(options::OPT_ibuiltininc)) {
+  // This is used only by the driver. No need to pass to cc1.
+  continue;
 }
 
 // Not translated, render as usual.


Index: clang/test/Driver/darwin-header-search-system.cpp
===
--- clang/test/Driver/darwin-header-search-system.cpp
+++ clang/test/Driver/darwin-header-search-system.cpp
@@ -131,6 +131,7 @@
 // RUN:   -DRESOURCE=%S/Inputs/resource_dir \
 // RUN:   --check-prefix=CHECK-NOSTDINC-BUILTINC %s
 // CHECK-NOSTDINC-BUILTINC: "-cc1"
+// CHECK-NOSTDINC-BUILTINC-NOT: "-ibuiltininc"
 // CHECK-NOSTDINC-BUILTINC-NOT: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
 // CHECK-NOSTDINC-BUILTINC: "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK-NOSTDINC-BUILTINC-NOT: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -1305,6 +1305,9 @@
 } else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) {
   // Translated to -internal-isystem by the driver, no need to pass to cc1.
   continue;
+} else if (A->getOption().matches(options::OPT_ibuiltininc)) {
+  // This is used only by the driver. No need to pass to cc1.
+  continue;
 }
 
 // Not translated, render as usual.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a2b7297 - Don't pass -ibuiltininc, which is used only by the driver, to CC1

2023-07-05 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2023-07-05T14:03:21-07:00
New Revision: a2b7297dff345e3fc4886c7e76a67d32ea2cd134

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

LOG: Don't pass -ibuiltininc, which is used only by the driver, to CC1

This fixes a fallout from 5b77e752dcd073846b89559d6c0e1a7699e58615.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/darwin-header-search-system.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f85584b3335e4b..0321da8e43f636 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1305,6 +1305,9 @@ void Clang::AddPreprocessingOptions(Compilation , const 
JobAction ,
 } else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) {
   // Translated to -internal-isystem by the driver, no need to pass to cc1.
   continue;
+} else if (A->getOption().matches(options::OPT_ibuiltininc)) {
+  // This is used only by the driver. No need to pass to cc1.
+  continue;
 }
 
 // Not translated, render as usual.

diff  --git a/clang/test/Driver/darwin-header-search-system.cpp 
b/clang/test/Driver/darwin-header-search-system.cpp
index 590535fae354de..5fb83b62ce7e63 100644
--- a/clang/test/Driver/darwin-header-search-system.cpp
+++ b/clang/test/Driver/darwin-header-search-system.cpp
@@ -131,6 +131,7 @@
 // RUN:   -DRESOURCE=%S/Inputs/resource_dir \
 // RUN:   --check-prefix=CHECK-NOSTDINC-BUILTINC %s
 // CHECK-NOSTDINC-BUILTINC: "-cc1"
+// CHECK-NOSTDINC-BUILTINC-NOT: "-ibuiltininc"
 // CHECK-NOSTDINC-BUILTINC-NOT: "-internal-isystem" 
"[[SYSROOT]]/usr/local/include"
 // CHECK-NOSTDINC-BUILTINC: "-internal-isystem" "[[RESOURCE]]/include"
 // CHECK-NOSTDINC-BUILTINC-NOT: "-internal-externc-isystem" 
"[[SYSROOT]]/usr/include"



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


[PATCH] D153205: [clang-format] Support block indenting array/struct list initializers

2023-07-05 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/include/clang/Format/Format.h:95-98
 /// \warning
-///  Note: This currently only applies to parentheses.
+///  Note: This currently only applies to parentheses and braced list
+///  initializers when ``Cpp11BracedListStyle`` is ``True``.
 /// \endwarning





Comment at: clang/lib/Format/FormatToken.cpp:79-81
+  if (isNot(tok::r_brace))
+return false;
+  if (Style.Cpp11BracedListStyle != true ||





Comment at: clang/lib/Format/FormatToken.cpp:85-86
+  }
+  auto LBrace = MatchingParen;
+  assert(LBrace);
+  if (LBrace->is(BK_BracedInit))





Comment at: clang/unittests/Format/FormatTest.cpp:25519
+   ".baz = \"z\"\n"
+   "};\n",
+   Style);

Ditto below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153205

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-07-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1606
+  CGOpenMPRuntimeGPU  =
+  *(static_cast(()));
+  if (RT.isDelayedVariableLengthDecl(*this, )) {

ABataev wrote:
> 1. use `static_cast(CGM.getOpenMPRuntime())`
> 2. It will crash if your device is not GPU. Better to make 
> `getKmpcAllocShared` and `getKmpcFreeShared` virtual (just like 
> `isDelayedVariableLengthDecl`) in base CGOpenMPRuntime, since it may be 
> required not only for GPU-based devices.
Check the second item, please, better to make all new member function virtual 
and handle it for non-GPU devices too


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

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


[PATCH] D148654: Modify BoundsSan to improve debuggability

2023-07-05 Thread Oskar Wirga via Phabricator via cfe-commits
oskarwirga added a comment.

ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148654

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

hubert.reinterpretcast wrote:
> hubert.reinterpretcast wrote:
> > hubert.reinterpretcast wrote:
> > > Can we have tests for:
> > > ```
> > > struct { int _, _; } a = { ._ = 0 };
> > > ```
> > > 
> > > and
> > > 
> > > ```
> > > struct A {
> > >   A();
> > >   int _, _;
> > > };
> > > 
> > > A::A() : _(0) {}
> > > ```
> > Codegen test for
> > ```
> > static union { int _ = 42; };
> > int  = _;
> > int foo() { return 13; }
> > static union { int _ = foo(); };
> > int main(void) { return ref; }
> > ```
> > might be interesting.
> > 
> > I suspect that this case was missed in the committee discussion of the 
> > paper @cor3ntin.
> Less controversial tests to consider:
> ```
> struct A {
>   int _;
>   union { int _; };
> };
> struct B { union { int _, _; }; };
> ```
> 
In a similar vein, a codegen test for:
```
struct A { A(); };
inline void f [[gnu::used]]() {
  static union { A _{}; };
  static union { A _{}; };
}
```

Perhaps not intended to be allowed though (premise was no symbols with 
"linkage"?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D145227: [LLVM][OHOS] Clang toolchain and targets

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.
Herald added a subscriber: wangpc.



Comment at: clang/lib/Driver/ToolChains/OHOS.h:38
+  bool isPICDefaultForced() const override { return false; }
+  bool useRelaxRelocations() const override { return false; }
+  UnwindLibType GetUnwindLibType(const llvm::opt::ArgList ) const 
override;

Why is `useRelaxRelocations` false?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145227

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


[PATCH] D154495: clang: Attach !fpmath metadata to __builtin_sqrt based on language flags

2023-07-05 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:5602
+// source are correctly rounded.
+SetFPAccuracy(Val, 2.5);
+  }

yaxunl wrote:
> the spec says sqrt relative error is 3ULP 
> https://registry.khronos.org/OpenCL/specs/2.2/html/OpenCL_C.html#relative-error-as-ulps
Did that change between versions? In any case I don’t want to change the 
currently used threshold in this patch. We only need 1.0 anyway 


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

https://reviews.llvm.org/D154495

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


[PATCH] D154397: [Driver] Default to -ftls-model=initial-exec on SerenityOS

2023-07-05 Thread Daniel Bertalan via Phabricator via cfe-commits
BertalanD added a comment.

Hi MaskRay!

Your blog post (alongside the Drepper TLS doc) proved to be a very helpful 
resource for our implementation of the dynamic TLS interface. I currently have 
a SerenityOS PR  open that 
implements `__tls_get_addr` and TLSDESC on top of our current TLS 
infrastructure which only supports static TLS blocks. (Long story short, our 
loader passes the initial TLS image to the kernel, which automagically copies 
it over and sets up the thread pointer whenever a new thread is created. We 
need to move it to the userspace if we want to have a dynamic thread vector and 
separately allocated TLS blocks). I'd love it if you'd take a look at the PR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154397

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


[PATCH] D154396: [clang] Add support for SerenityOS

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:85
+  auto linkerIs = [Exec](const char *name) {
+return llvm::sys::path::filename(Exec).equals_insensitive(name) ||
+   llvm::sys::path::stem(Exec).equals_insensitive(name);

Avoid `equals_insensitive`. It's only recommended in some places for Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[clang] cf08c10 - [NFC][clang] add extra member-alignment testcase

2023-07-05 Thread David Tenty via cfe-commits

Author: David Tenty
Date: 2023-07-05T16:44:05-04:00
New Revision: cf08c103266b7ee59cbc2352c4d20f27472cb257

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

LOG: [NFC][clang] add extra member-alignment testcase

for when an alignment attribute is used. This will be useful for D147184 to 
demonstrate what changes.

Added: 


Modified: 
clang/test/CodeGenCXX/member-alignment.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/member-alignment.cpp 
b/clang/test/CodeGenCXX/member-alignment.cpp
index ff6bb442b8470d..72f992ffe8f980 100644
--- a/clang/test/CodeGenCXX/member-alignment.cpp
+++ b/clang/test/CodeGenCXX/member-alignment.cpp
@@ -11,8 +11,19 @@ class t {
 public:
   virtual void foo(void);
   void bar(void);
+  void baz(void);
 };
 
+// The original alignment is observed if >=2, regardless of any extra alignment
+// of member functions.
+[[gnu::aligned(16)]]
+void
+t::baz(void) {
+// CHECK-NOEXTRAALIGN: @_ZN1t3bazEv({{.*}}) #0 align 16 {
+// CHECK-EXTRAALIGN: @_ZN1t3bazEv({{.*}}) #0 align 16 {
+// CHECK-MSVC: @"?baz@t@@QEAAXXZ"({{.*}}) #0 align 16 {
+}
+
 void
 t::bar(void) {
 // CHECK-ITANIUM: @_ZN1t3barEv({{.*}}) #0 align 2 {



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


[PATCH] D154396: [clang] Add support for SerenityOS

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Upstreaming support requires rigid testing, otherwise it's fairly easy for 
other contributors to break your code while refactoring.
https://maskray.me/blog/2021-08-08-toolchain-testing "I don't know whether a 
test is needed"

`clang/test/Driver` has many tests that could have been written in a better 
way. There are some good ones, e.g. `linux-cross.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-07-05 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 537485.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/amdgcn_target_device_vla.cpp

Index: clang/test/OpenMP/amdgcn_target_device_vla.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn_target_device_vla.cpp
@@ -0,0 +1,1260 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+int foo1() {
+  int sum = 0.0;
+  #pragma omp target map(tofrom: sum)
+  {
+int N = 10;
+int A[N];
+
+for (int i = 0; i < N; i++)
+  A[i] = i;
+
+for (int i = 0; i < N; i++)
+  sum += A[i];
+  }
+  return sum;
+}
+
+int foo2() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute parallel for map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo3() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo4() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  int N = 10;
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int main() {
+  return foo1() + foo2() + foo3() + foo4();
+}
+
+#endif
+// CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z4foo1v_l12
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(4) [[SUM:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUM_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-NEXT:[[N:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__VLA_EXPR0:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[I1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[SUM_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[SUM_ADDR]] to ptr
+// CHECK-NEXT:[[N_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[N]] to ptr
+// CHECK-NEXT:[[__VLA_EXPR0_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[__VLA_EXPR0]] to ptr
+// CHECK-NEXT:[[I_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I]] to ptr
+// CHECK-NEXT:[[I1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I1]] to ptr
+// CHECK-NEXT:store ptr [[SUM]], ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1:[0-9]+]] to ptr), i8 1, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP1]], -1
+// CHECK-NEXT:br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
+// CHECK:   user_code.entry:
+// CHECK-NEXT:store i32 10, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = zext i32 [[TMP2]] to i64
+// CHECK-NEXT:[[TMP4:%.*]] = mul nuw i64 [[TMP3]], 4
+// CHECK-NEXT:[[TMP5:%.*]] = add nuw i64 [[TMP4]], 3
+// CHECK-NEXT:[[TMP6:%.*]] = udiv i64 [[TMP5]], 4
+// CHECK-NEXT:[[TMP7:%.*]] = mul nuw i64 [[TMP6]], 4
+// CHECK-NEXT:[[A:%.*]] = call align 4 ptr @__kmpc_alloc_shared(i64 [[TMP7]])
+// CHECK-NEXT:store i64 [[TMP3]], 

[PATCH] D154397: [Driver] Default to -ftls-model=initial-exec on SerenityOS

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I don't think this belongs to the upstream, either. Note: musl's TLS 
implementation is very clean and  may be a good reference.

https://maskray.me/blog/2021-02-14-all-about-thread-local-storage

> glibc ld.so reserves some space in static TLS blocks and allows dlopen on 
> such a shared object if its TLS size is small. There could be an obscure 
> reason for using such an attribute: general dynamic and local dynamic TLS 
> models are not async-signal-safe in glibc. However, other libc 
> implementations may not reserve additional TLS space for dlopen'ed 
> initial-exec shared objects, e.g. musl will error.

glibc's model makes it very error-prone, even if dlopen TLS is supported to 
some extent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154397

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


[PATCH] D154543: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-07-05 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian created this revision.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
IncludeGuardian requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Add missing parts that caused https://reviews.llvm.org/D153229 to fail compile 
on main.

Move the implementation of the `toString` function from
`llvm/Support/Error.h` to the source file, which allows us to move
`#include "llvm/ADT/StringExtras.h"` to the source file as well.

As `Error.h` is present in a large number of translation units this
means we are unnecessarily bringing in the contents of
`StringExtras.h` - itself a large file with lots of includes - and
slowing down compilation.

Also move the `#include "llvm/ADT/SmallVector.h"` directive to the
source file as it's no longer needed, but this does not give as much of
a benefit.

This reduces the total number of preprocessing tokens across the LLVM
source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a
reduction of ~0.87%. This should result in a small improvement in
compilation time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154543

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  llvm/include/llvm/Support/Error.h
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/Support/Error.cpp
  llvm/lib/Transforms/IPO/Internalize.cpp
  llvm/lib/Transforms/Scalar/MergeICmps.cpp
  llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
  llvm/lib/Transforms/Utils/ModuleUtils.cpp

Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -12,6 +12,7 @@

 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "llvm/Analysis/VectorUtils.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
@@ -19,15 +20,16 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/xxhash.h"
+
 using namespace llvm;

 #define DEBUG_TYPE "moduleutils"

 static void appendToGlobalArray(StringRef ArrayName, Module , Function *F,
 int Priority, Constant *Data) {
   IRBuilder<> IRB(M.getContext());
   FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false);

   // Get the current set of static global constructors and add the new ctor
   // to the list.
   SmallVector CurrentCtors;
Index: llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
===
--- llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
+++ llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
@@ -11,22 +11,23 @@
 //===--===//

 #include "llvm/Transforms/Utils/MemoryOpRemark.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include 

 using namespace llvm;
 using namespace llvm::ore;

 MemoryOpRemark::~MemoryOpRemark() = default;

 bool MemoryOpRemark::canHandle(const Instruction *I, const TargetLibraryInfo ) {
   if (isa(I))
 return true;

   if (auto *II = dyn_cast(I)) {
 switch (II->getIntrinsicID()) {
 case Intrinsic::memcpy_inline:
Index: llvm/lib/Transforms/Scalar/MergeICmps.cpp
===
--- llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -42,6 +42,7 @@
 //===--===//

 #include "llvm/Transforms/Scalar/MergeICmps.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/Loads.h"
Index: llvm/lib/Transforms/IPO/Internalize.cpp
===
--- llvm/lib/Transforms/IPO/Internalize.cpp
+++ llvm/lib/Transforms/IPO/Internalize.cpp
@@ -19,6 +19,7 @@
 //===--===//

 #include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Analysis/CallGraph.h"
Index: llvm/lib/Support/Error.cpp
===
--- llvm/lib/Support/Error.cpp
+++ llvm/lib/Support/Error.cpp
@@ -7,27 +7,29 @@
 //===--===//

 #include "llvm/Support/Error.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 

 using namespace llvm;

 

[PATCH] D153883: [Clang][OpenMP] Delay emission of __kmpc_alloc_shared for escaped VLAs

2023-07-05 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 537478.
doru1004 marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153883

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/amdgcn_target_device_vla.cpp

Index: clang/test/OpenMP/amdgcn_target_device_vla.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn_target_device_vla.cpp
@@ -0,0 +1,1260 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+int foo1() {
+  int sum = 0.0;
+  #pragma omp target map(tofrom: sum)
+  {
+int N = 10;
+int A[N];
+
+for (int i = 0; i < N; i++)
+  A[i] = i;
+
+for (int i = 0; i < N; i++)
+  sum += A[i];
+  }
+  return sum;
+}
+
+int foo2() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute parallel for map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo3() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo4() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  int N = 10;
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int main() {
+  return foo1() + foo2() + foo3() + foo4();
+}
+
+#endif
+// CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z4foo1v_l12
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(4) [[SUM:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUM_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-NEXT:[[N:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__VLA_EXPR0:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[I1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[SUM_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[SUM_ADDR]] to ptr
+// CHECK-NEXT:[[N_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[N]] to ptr
+// CHECK-NEXT:[[__VLA_EXPR0_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[__VLA_EXPR0]] to ptr
+// CHECK-NEXT:[[I_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I]] to ptr
+// CHECK-NEXT:[[I1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I1]] to ptr
+// CHECK-NEXT:store ptr [[SUM]], ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1:[0-9]+]] to ptr), i8 1, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP1]], -1
+// CHECK-NEXT:br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
+// CHECK:   user_code.entry:
+// CHECK-NEXT:store i32 10, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = zext i32 [[TMP2]] to i64
+// CHECK-NEXT:[[TMP4:%.*]] = mul nuw i64 [[TMP3]], 4
+// CHECK-NEXT:[[TMP5:%.*]] = add nuw i64 [[TMP4]], 3
+// CHECK-NEXT:[[TMP6:%.*]] = udiv i64 [[TMP5]], 4
+// CHECK-NEXT:[[TMP7:%.*]] = mul nuw i64 [[TMP6]], 4
+// CHECK-NEXT:[[A:%.*]] = call align 4 ptr @__kmpc_alloc_shared(i64 

[PATCH] D154130: [lit] Avoid os.path.realpath on Windows due to MAX_PATH limitations

2023-07-05 Thread Tristan Labelle via Phabricator via cfe-commits
MrTrillian added a comment.
Herald added a subscriber: wangpc.

How do I take action on the test failure? It runs without issues on my machine:

  tristan@nuc-on-wood:~/project-llvm$ python3 build/bin/llvm-lit -sv --filter 
test.toy build/tools/mlir
  /test/
  
  Testing Time: 0.55s
Excluded: 1636
Passed  :1

And I see that the failure is a timeout so I wonder if it's reliable?

  Exit Code: -9
  Timeout: Reached timeout of 60 seconds


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154130

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

hubert.reinterpretcast wrote:
> Can we have tests for:
> ```
> struct { int _, _; } a = { ._ = 0 };
> ```
> 
> and
> 
> ```
> struct A {
>   A();
>   int _, _;
> };
> 
> A::A() : _(0) {}
> ```
Codegen test for
```
static union { int _ = 42; };
int  = _;
int foo() { return 13; }
static union { int _ = foo(); };
int main(void) { return ref; }
```
might be interesting.

I suspect that this case was missed in the committee discussion of the paper 
@cor3ntin.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

hubert.reinterpretcast wrote:
> hubert.reinterpretcast wrote:
> > Can we have tests for:
> > ```
> > struct { int _, _; } a = { ._ = 0 };
> > ```
> > 
> > and
> > 
> > ```
> > struct A {
> >   A();
> >   int _, _;
> > };
> > 
> > A::A() : _(0) {}
> > ```
> Codegen test for
> ```
> static union { int _ = 42; };
> int  = _;
> int foo() { return 13; }
> static union { int _ = foo(); };
> int main(void) { return ref; }
> ```
> might be interesting.
> 
> I suspect that this case was missed in the committee discussion of the paper 
> @cor3ntin.
Less controversial tests to consider:
```
struct A {
  int _;
  union { int _; };
};
struct B { union { int _, _; }; };
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[clang] 4b5ca17 - Remove unused test file

2023-07-05 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-07-05T15:59:22-04:00
New Revision: 4b5ca175431c559a91ffd40333a0fae9e8ac424c

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

LOG: Remove unused test file

pth.h hasn't been used since we removed support for PTH in
0a6b5b653ee47234674614fecc213c1d73bb1e28

Added: 


Modified: 


Removed: 
clang/test/PCH/pth.h



diff  --git a/clang/test/PCH/pth.h b/clang/test/PCH/pth.h
deleted file mode 100644
index 9ae7021a5e4af7..00
--- a/clang/test/PCH/pth.h
+++ /dev/null
@@ -1,12 +0,0 @@
-// This case came up when using PTH with Boost ().
-
-# ifndef R8227989_PREPROCESSOR_CONFIG_CONFIG_HPP
-# ifndef R8227989_PP_CONFIG_FLAGS
-# endif
-#
-# ifndef R8227989_PP_CONFIG_ERRORS
-#ifdef NDEBUG
-#endif
-# endif
-# endif
-



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


[PATCH] D154495: clang: Attach !fpmath metadata to __builtin_sqrt based on language flags

2023-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:5602
+// source are correctly rounded.
+SetFPAccuracy(Val, 2.5);
+  }

the spec says sqrt relative error is 3ULP 
https://registry.khronos.org/OpenCL/specs/2.2/html/OpenCL_C.html#relative-error-as-ulps


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

https://reviews.llvm.org/D154495

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


[PATCH] D154388: Don't pass -ibuiltininc, which is used only by the driver, to CC1

2023-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:1309
+} else if (A->getOption().matches(options::OPT_ibuiltininc)) {
+  // This is used only by the driver. No no need to pass to cc1.
+  continue;

Typo: `No need`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154388

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


[PATCH] D154366: [clang][ExprConstant] Print template arguments when describing stack frame

2023-07-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Do we not already have some function name printing helper we could be reusing 
that might have some smarts about not printing deduced template arguments, 
using preferred names, whatever else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154366

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


[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:542
+N = Decls.size();
+  }
+

This is going to fire on every single ordinary lookup that finds multiple 
declarations, right?  I haven't fully internalized the issue you're solving 
here, but this is a very performance-sensitive path in the compiler; there's a 
reason this code is written to very carefully only do extra work when we've 
detected in the loop below that we're in a hidden-declarations situation.  Is 
there any way we can restore that basic structure?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154503

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


[clang] 92f4bf2 - Fix aggregate CTAD with string literals adding extra const

2023-07-05 Thread Yuanfang Chen via cfe-commits

Author: Mital Ashok
Date: 2023-07-05T11:54:51-07:00
New Revision: 92f4bf268998201ec05dab9917c2873afc578a94

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

LOG: Fix aggregate CTAD with string literals adding extra const

Missing a `withConst`, so when deducing from a string literal, a `const` is 
erroneously added to the deduced type.

Reviewed By: ychen

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 6db211a20e311f..f2bbdae3d5f36b 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
   ElementTypes[I] = 
Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = 
Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
 llvm::FoldingSetNodeID ID;

diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
index 175e27e6e2ed63..e4b6156235ecc0 100644
--- a/clang/test/CXX/drs/dr26xx.cpp
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -126,3 +126,27 @@ void f() {
 brachiosaur |= neck;// OK
 }
 }
+
+namespace dr2681 { // dr2681: 17
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction 
guide}}
+}

diff  --git a/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp 
b/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
index 71189be0762364..d455d424ab3d0e 100644
--- a/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
+++ b/clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -198,22 +198,22 @@ namespace Array {
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
   // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
   // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 
0 index 1 N
-  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T (&)[N]) -> A'
-  // CHECK: | `-ParmVarDecl {{.*}} 'T (&)[N]'
-  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
-  // CHECK:   |-TemplateArgument type 'const char'
-  // CHECK:   | `-QualType {{.*}} 'const char' const
-  // CHECK:   |   `-BuiltinType {{.*}} 'char'
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (const T (&)[N]) -> A'
+  // CHECK: | `-ParmVarDecl {{.*}} 'const T (&)[N]'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
+  // CHECK:   |-TemplateArgument type 'char'
+  // CHECK:   | `-BuiltinType {{.*}} 'char'
   // CHECK:   |-TemplateArgument integral 5
   // CHECK:   `-ParmVarDecl {{.*}} 'const char (&)[5]'
-  // CHECK: FunctionProtoType {{.*}} 'auto (T (&)[N]) -> A' dependent 
trailing_return cdecl
+  // CHECK: FunctionProtoType {{.*}} 'auto (const T (&)[N]) -> A' 
dependent trailing_return cdecl
   // CHECK: |-InjectedClassNameType {{.*}} 'A' dependent
   // CHECK: | `-CXXRecord {{.*}} 'A'
-  // CHECK: `-LValueReferenceType {{.*}} 'T (&)[N]' dependent
-  // CHECK:   `-DependentSizedArrayType {{.*}} 'T[N]' dependent
-  // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
-  // CHECK: | `-TemplateTypeParm {{.*}} 'T'
-  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned {{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned {{.*}}'
+  // CHECK: `-LValueReferenceType {{.*}} 'const T (&)[N]' dependent
+  // CHECK:   `-QualType {{.*}} 'const T[N]' const
+  // CHECK: `-DependentSizedArrayType {{.*}} 'T[N]' dependent
+  // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
+  // CHECK:   `-DeclRefExpr {{.*}} 'size_t':'unsigned{{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned{{.*}}'
 }
 
 namespace BraceElision {

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 13b230706b9e80..702d84ebba9859 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html

[PATCH] D154301: Fix aggregate CTAD with string literals adding extra const

2023-07-05 Thread Yuanfang Chen 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 rG92f4bf268998: Fix aggregate CTAD with string literals adding 
extra const (authored by MitalAshok, committed by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154301

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15893,7 +15893,7 @@
 https://cplusplus.github.io/CWG/issues/2681.html;>2681
 DR
 Deducing member array type from string literal
-Unknown
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/2682.html;>2682
Index: clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
===
--- clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
+++ clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -198,22 +198,22 @@
   // CHECK: FunctionTemplateDecl {{.*}} implicit 
   // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
   // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'size_t':'unsigned {{.*}}' depth 
0 index 1 N
-  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (T (&)[N]) -> A'
-  // CHECK: | `-ParmVarDecl {{.*}} 'T (&)[N]'
-  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
-  // CHECK:   |-TemplateArgument type 'const char'
-  // CHECK:   | `-QualType {{.*}} 'const char' const
-  // CHECK:   |   `-BuiltinType {{.*}} 'char'
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  
'auto (const T (&)[N]) -> A'
+  // CHECK: | `-ParmVarDecl {{.*}} 'const T (&)[N]'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (const char (&)[5]) -> Array::A'
+  // CHECK:   |-TemplateArgument type 'char'
+  // CHECK:   | `-BuiltinType {{.*}} 'char'
   // CHECK:   |-TemplateArgument integral 5
   // CHECK:   `-ParmVarDecl {{.*}} 'const char (&)[5]'
-  // CHECK: FunctionProtoType {{.*}} 'auto (T (&)[N]) -> A' dependent 
trailing_return cdecl
+  // CHECK: FunctionProtoType {{.*}} 'auto (const T (&)[N]) -> A' 
dependent trailing_return cdecl
   // CHECK: |-InjectedClassNameType {{.*}} 'A' dependent
   // CHECK: | `-CXXRecord {{.*}} 'A'
-  // CHECK: `-LValueReferenceType {{.*}} 'T (&)[N]' dependent
-  // CHECK:   `-DependentSizedArrayType {{.*}} 'T[N]' dependent
-  // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
-  // CHECK: | `-TemplateTypeParm {{.*}} 'T'
-  // CHECK: `-DeclRefExpr {{.*}} 'size_t':'unsigned {{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned {{.*}}'
+  // CHECK: `-LValueReferenceType {{.*}} 'const T (&)[N]' dependent
+  // CHECK:   `-QualType {{.*}} 'const T[N]' const
+  // CHECK: `-DependentSizedArrayType {{.*}} 'T[N]' dependent
+  // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
+  // CHECK:   `-DeclRefExpr {{.*}} 'size_t':'unsigned{{.*}}' 
NonTypeTemplateParm {{.*}} 'N' 'size_t':'unsigned{{.*}}'
 }
 
 namespace BraceElision {
Index: clang/test/CXX/drs/dr26xx.cpp
===
--- clang/test/CXX/drs/dr26xx.cpp
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -126,3 +126,27 @@
 brachiosaur |= neck;// OK
 }
 }
+
+namespace dr2681 { // dr2681: 17
+using size_t = decltype(sizeof(int));
+
+template
+struct H {
+  T array[N];
+};
+template
+struct I {
+  volatile T array[N];
+};
+template
+struct J {  // expected-note 3{{candidate}}
+  unsigned char array[N];
+};
+
+H h = { "abc" };
+I i = { "def" };
+static_assert(__is_same(decltype(h), H));  // Not H
+static_assert(__is_same(decltype(i), I));
+
+J j = { "ghi" };  // expected-error {{no viable constructor or deduction 
guide}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -10714,7 +10714,8 @@
   ElementTypes[I] = 
Context.getRValueReferenceType(ElementTypes[I]);
 else if (isa(
  ListInit->getInit(I)->IgnoreParenImpCasts()))
-  ElementTypes[I] = 
Context.getLValueReferenceType(ElementTypes[I]);
+  ElementTypes[I] =
+  Context.getLValueReferenceType(ElementTypes[I].withConst());
   }
 
 llvm::FoldingSetNodeID ID;


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15893,7 +15893,7 @@
 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Maybe try testing with more different values, to demonstrate which entities the 
debugger is finding?

  int _ = 1;
  int _ = 2;
  {
int _ = 3;
int _ = 7;
  }

Or something like that. But, honestly, if the point is that these variables 
should be unnameable - perhaps we shouldn't generate any DWARF for them?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D135849: [llvm] Return canonical virtual path from `RedirectingFileSystem`

2023-07-05 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D135849#4469376 , @benlangmuir 
wrote:

> In D135849#4469347 , @jansvoboda11 
> wrote:
>
>> It'd be really nice to have DirectoryEntry::getDir() API, so that we can 
>> walk up the directory hierarchy while preserving the virtual/real 
>> distinction between directories in the overlay/on disk, never accidentally 
>> "bubbling up" into the overlay again. What's your take on that?
>
> Can you say more about how you would do this and preserve the real/virtual 
> distinction? Currently FileManager is just filling in the directory based on 
> the parent path with a lookup to the VFS, so isn't it the same issue? Or did 
> you mean we would keep more info?

Yes, the mechanism you mention has the same issue. My idea was that we could 
keep more information when looking up the path in the VFS, associate each 
`{File,Directory}Entry` with list of `FileSystem *` that "owns" each of its 
parent directories. We could then send the `llvm::sys::path::parent_path(...)` 
argument directly to the owning FS instead to the top one. This is not 
realistic from performance standpoint, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135849

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


[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-07-05 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D86993#4474392 , @rjmccall wrote:

> In D86993#4474267 , @RalfJung wrote:
>
>> The first point is important for LLVM's own memcpy/memmove intrinsics, which 
>> are documented as NOPs on size 0 (and e.g. Rust relies on that).
>
> Right, I understand that these assumptions come directly from the stronger 
> semantics offered by the LLVM intrinsics.  The C committee is not going to 
> find that compelling, though — we don't get to default-win arguments just 
> because we've defined an IR with stronger semantics than necessary.  They are 
> going to want to see arguments about why it's valuable for the C library to 
> have these stronger semantics, which for us means talking about code patterns 
> in user programs that take advantage of those stronger semantics and the 
> benefits they see from that.

I think the argument for this one is pretty clear:

- Lower code size: No need to add an explicit `n != 0` check.
- Better performance: If the `n == 0` case is rare, you don't have to do that 
redundant check.
- Better security: You are less likely to cause UB by forgetting a `n != 0` 
check in place that needs it.

When I made an old code base ubsan compliant some time ago, adding these checks 
certainly felt like the one case where fixing the sanitizer diagnostics made 
the code objectively worse on all possible metrics. Take into account that the 
requirement for nonnull pointers for `n != 0` does not allow any useful 
optimization of the memcpy implementation, and this seems like a no-brainer.

In D86993#4474549 , @RalfJung wrote:

> I was told that "glibc explicitly only marks memcpy arguments as nonnull for 
> external use of headers (i.e. the nonnull assumptions are disabled when 
> compiling the implementation)"... okay now re-reading this, that's a 
> statement about glibc, not GCC.

Right. glibc only adds nonnull annotations to declarations when included by 
users of glibc. The implementation is compiled without any such assumptions 
(though of course, usually you get an assembly implementation anyway). Musl 
doesn't annotate nonnull either way.

> Anyway this is outside my expertise. I will try to add Nikita here who said 
> "GCC also requires passing equal pointer to memcpy to be legal".

GCC uses equal pointer memcpy in pretty much exactly the same cases as Clang 
does: Aggregate assignments.

> I continue to think it's a mistake for us to document that Clang will not 
> work with a conforming C standard library implementation unless we're filing 
> issues with WG14 to alert them to the reasons why. If there's a DR filed with 
> the committee, that gives us something to point our users to as 
> justification. Otherwise, our users will correctly put these bugs at our feet.

As you are involved with WG14, can you please take care of that? I couldn't 
even find out how one is supposed to file a DR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


[PATCH] D152109: Update clang-repl documentation

2023-07-05 Thread Vassil Vassilev 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 rG1ac3e13c3e4a: [clang-repl] Improve the clang-repl 
documentation. (authored by Krishna-13-cyber, committed by v.g.vassilev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152109

Files:
  clang/docs/ClangRepl.rst

Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -16,22 +16,6 @@
 of Cling upstream, making them useful and available to a broader audience.
 
 
-
-Clang-Repl Usage
-
-
-
-.. code-block:: text
-
-  clang-repl> #include 
-  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
-  clang-repl> auto r = f();
-  // Prints Hello Interpreted World!
-
-Note that the implementation is not complete and highly experimental. We do
-not yet support statements on the global scope, for example.
-
-
 Clang-Repl Basic Data Flow
 ==
 
@@ -63,14 +47,173 @@
 
 8. The machine code is then executed.
 
+===
+Build Instructions:
+===
+
+
+.. code-block:: console
+
+   $ cd llvm-project
+   $ mkdir build
+   $ cd build
+   $ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
+
+**Note here**, above RelWithDebInfo - Debug / Release
+
+.. code-block:: console
+
+   cmake --build . --target clang clang-repl -j n
+  OR
+   cmake --build . --target clang clang-repl
+
+**Clang-repl** is built under llvm-project/build/bin. Proceed into the directory **llvm-project/build/bin**
+
+.. code-block:: console
+
+   ./clang-repl
+   clang-repl>
+
+
+
+Clang-Repl Usage
+
+
+**Clang-Repl** is an interactive C++ interpreter that allows for incremental
+compilation. It supports interactive programming for C++ in a
+read-evaluate-print-loop (REPL) style. It uses Clang as a library to compile the
+high level programming language into LLVM IR. Then the LLVM IR is executed by
+the LLVM just-in-time (JIT) infrastructure.
+
+
+Basic:
+==
+
+.. code-block:: text
+
+  clang-repl> #include 
+  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
+  clang-repl> auto r = f();
+   // Prints Hello Interpreted World!
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> std::cout << "Welcome to CLANG-REPL" << std::endl;
+   Welcome to CLANG-REPL
+   // Prints Welcome to CLANG-REPL
+
+
+Function Definitions and Calls:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> int sum(int a, int b){ return a+b; };
+   clang-repl> int c = sum(9,10);
+   clang-repl> std::cout << c << std::endl;
+   19
+   clang-repl>
+
+Iterative Structures:
+=
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> for (int i = 0;i < 3;i++){ std::cout << i << std::endl;}
+   0
+   1
+   2
+   clang-repl> while(i < 7){ i++; std::cout << i << std::endl;}
+   4
+   5
+   6
+   7
+
+Classes and Structures:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> class Rectangle {int width, height; public: void set_values (int,int);\
+   clang-repl... int area() {return width*height;}};
+   clang-repl>  void Rectangle::set_values (int x, int y) { width = x;height = y;}
+   clang-repl> int main () { Rectangle rect;rect.set_values (3,4);\
+   clang-repl... std::cout << "area: " << rect.area() << std::endl;\
+   clang-repl... return 0;}
+   clang-repl> main();
+   area: 12
+   clang-repl>
+   // Note: This '\' can be used for continuation of the statements in the next line
+
+Lamdas:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> using namespace std;
+   clang-repl> auto welcome = []()  { std::cout << "Welcome to REPL" << std::endl;};
+   clang-repl> welcome();
+   Welcome to REPL
+
+Using Dynamic Library:
+==
+
+.. code-block:: text
+
+   clang-repl> %lib print.so
+   clang-repl> #include"print.hpp"
+   clang-repl> print(9);
+   9
+
+**Generation of dynamic library**
+
+.. code-block:: text
+
+   // print.cpp
+   #include 
+   #include "print.hpp"
+
+   void print(int a)
+   {
+  std::cout << a << std::endl;
+   }
+
+   // print.hpp
+   void print (int a);
+
+   // Commands
+   clang++-17  -c -o print.o print.cpp
+   clang-17 -shared print.o -o print.so
+
+Comments:
+=
+
+.. code-block:: text
+
+   clang-repl> // Comments in Clang-Repl
+   clang-repl> /* Comments in Clang-Repl */
+
+
+Closure or Termination:
+===
+
+.. code-block:: text
+
+   clang-repl>%quit
+
 
-Just like Clang, Clang-Repl can be integrated in existing applications as a
-library (via using the clangInterpreter library). This 

[clang] 1ac3e13 - [clang-repl] Improve the clang-repl documentation.

2023-07-05 Thread Vassil Vassilev via cfe-commits

Author: Krishna-13-cyber
Date: 2023-07-05T18:27:22Z
New Revision: 1ac3e13c3e4ab6816116a6e6997f81acf1039849

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

LOG: [clang-repl] Improve the clang-repl documentation.

We add usage, build instructions and examples illustrating how clang-repl works.

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

Added: 


Modified: 
clang/docs/ClangRepl.rst

Removed: 




diff  --git a/clang/docs/ClangRepl.rst b/clang/docs/ClangRepl.rst
index e4892bb9ff72f9..ff986be9da89b6 100644
--- a/clang/docs/ClangRepl.rst
+++ b/clang/docs/ClangRepl.rst
@@ -16,22 +16,6 @@ analysis framework `ROOT `_. Clang-Repl 
allows to move parts
 of Cling upstream, making them useful and available to a broader audience.
 
 
-
-Clang-Repl Usage
-
-
-
-.. code-block:: text
-
-  clang-repl> #include 
-  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
-  clang-repl> auto r = f();
-  // Prints Hello Interpreted World!
-
-Note that the implementation is not complete and highly experimental. We do
-not yet support statements on the global scope, for example.
-
-
 Clang-Repl Basic Data Flow
 ==
 
@@ -63,14 +47,173 @@ Clang-Repl data flow can be divided into roughly 8 phases:
 
 8. The machine code is then executed.
 
+===
+Build Instructions:
+===
+
+
+.. code-block:: console
+
+   $ cd llvm-project
+   $ mkdir build
+   $ cd build
+   $ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -G 
"Unix Makefiles" ../llvm
+
+**Note here**, above RelWithDebInfo - Debug / Release
+
+.. code-block:: console
+
+   cmake --build . --target clang clang-repl -j n
+  OR
+   cmake --build . --target clang clang-repl
+
+**Clang-repl** is built under llvm-project/build/bin. Proceed into the 
directory **llvm-project/build/bin**
+
+.. code-block:: console
+
+   ./clang-repl
+   clang-repl>
+
+
+
+Clang-Repl Usage
+
+
+**Clang-Repl** is an interactive C++ interpreter that allows for incremental
+compilation. It supports interactive programming for C++ in a
+read-evaluate-print-loop (REPL) style. It uses Clang as a library to compile 
the
+high level programming language into LLVM IR. Then the LLVM IR is executed by
+the LLVM just-in-time (JIT) infrastructure.
+
+
+Basic:
+==
+
+.. code-block:: text
+
+  clang-repl> #include 
+  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
+  clang-repl> auto r = f();
+   // Prints Hello Interpreted World!
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> std::cout << "Welcome to CLANG-REPL" << std::endl;
+   Welcome to CLANG-REPL
+   // Prints Welcome to CLANG-REPL
+
+
+Function Definitions and Calls:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> int sum(int a, int b){ return a+b; };
+   clang-repl> int c = sum(9,10);
+   clang-repl> std::cout << c << std::endl;
+   19
+   clang-repl>
+
+Iterative Structures:
+=
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> for (int i = 0;i < 3;i++){ std::cout << i << std::endl;}
+   0
+   1
+   2
+   clang-repl> while(i < 7){ i++; std::cout << i << std::endl;}
+   4
+   5
+   6
+   7
+
+Classes and Structures:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> class Rectangle {int width, height; public: void set_values 
(int,int);\
+   clang-repl... int area() {return width*height;}};
+   clang-repl>  void Rectangle::set_values (int x, int y) { width = x;height = 
y;}
+   clang-repl> int main () { Rectangle rect;rect.set_values (3,4);\
+   clang-repl... std::cout << "area: " << rect.area() << std::endl;\
+   clang-repl... return 0;}
+   clang-repl> main();
+   area: 12
+   clang-repl>
+   // Note: This '\' can be used for continuation of the statements in the 
next line
+
+Lamdas:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> using namespace std;
+   clang-repl> auto welcome = []()  { std::cout << "Welcome to REPL" << 
std::endl;};
+   clang-repl> welcome();
+   Welcome to REPL
+
+Using Dynamic Library:
+==
+
+.. code-block:: text
+
+   clang-repl> %lib print.so
+   clang-repl> #include"print.hpp"
+   clang-repl> print(9);
+   9
+
+**Generation of dynamic library**
+
+.. code-block:: text
+
+   // print.cpp
+   #include 
+   #include "print.hpp"
+
+   void print(int a)
+   {
+  std::cout << a << std::endl;
+   }
+
+   // print.hpp
+   void print (int a);
+
+   // Commands
+   clang++-17  -c -o print.o print.cpp
+   clang-17 -shared print.o -o print.so
+
+Comments:

[PATCH] D153738: Add LibClang guide

2023-07-05 Thread Manuel via Phabricator via cfe-commits
manuel5975p updated this revision to Diff 537443.
manuel5975p marked 9 inline comments as done.
manuel5975p added a comment.

Incorporate Aaron Ballman's corrections


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153738

Files:
  clang/docs/LibClang.rst

Index: clang/docs/LibClang.rst
===
--- /dev/null
+++ clang/docs/LibClang.rst
@@ -0,0 +1,344 @@
+.. role:: raw-html(raw)
+:format: html
+
+Libclang tutorial
+
+The C Interface to Clang provides a relatively small API that exposes facilities for parsing source code into an abstract syntax tree (AST), loading already-parsed ASTs, traversing the AST, associating physical source locations with elements within the AST, and other facilities that support Clang-based development tools.
+This C interface to Clang will never provide all of the information representation stored in Clang's C++ AST, nor should it: the intent is to maintain an API that is relatively stable from one release to the next, providing only the basic functionality needed to support development tools.
+The entire C interface of libclang is available in the file `Index.h`_
+
+Essential types overview
+-
+
+All types of libclang are prefixed with ``CX``
+
+CXIndex
+~~~
+An Index that consists of a set of translation units that would typically be linked together into an executable or library.
+
+CXTranslationUnit
+~
+A single translation unit, which resides in an index.
+
+CXCursor
+~
+A cursor representing a pointer to some element in the abstract syntax tree of a translation unit.
+
+
+Code example
+
+
+.. code-block:: cpp
+  
+  // file.hpp
+  struct foo{
+int bar;
+int* bar_pointer;
+  };
+.. code-block:: cpp
+  
+  #include 
+  #include 
+
+  int main(){
+CXIndex index = clang_createIndex(0, 0); //Create index
+CXTranslationUnit unit = clang_parseTranslationUnit(
+  index,
+  "file.hpp", nullptr, 0,
+  nullptr, 0,
+  CXTranslationUnit_None); //Parse "file.hpp"
+
+
+if (unit == nullptr){
+  std::cerr << "Unable to parse translation unit. Quitting.\n";
+  return 0;
+}
+CXCursor cursor = clang_getTranslationUnitCursor(unit); //Obtain a cursor at the root of the translation unit
+  }
+
+Visiting elements of an AST
+~~~
+The elements of an AST can be recursively visited with pre-order traversal with ``clang_visitChildren``.
+
+.. code-block:: cpp
+
+  clang_visitChildren(
+cursor, //Root cursor
+[](CXCursor current_cursor, CXCursor parent, CXClientData client_data){
+
+  CXString current_display_name = clang_getCursorDisplayName(current_cursor); 
+  //Allocate a CXString representing the name of the current cursor
+  
+  std::cout << "Visiting element " << clang_getCString(current_display_name) << "\n";
+  //Print the char* value of current_display_name
+
+  clang_disposeString(current_display_name);
+  //Since clang_getCursorDisplayName allocates a new CXString, it must be freed. This applies
+  //to all functions returning a CXString
+
+  return CXChildVisit_Recurse;
+
+
+}, //CXCursorVisitor: a function pointer
+nullptr //client_data
+);
+
+The return value of ``CXCursorVisitor``, the callable argument of ``clang_visitChildren``, can return of of the three:
+
+#. ``CXChildVisit_Break``: Terminates the cursor traversal
+
+#. ``CXChildVisit_Continue``: Continues the cursor traversal with the next sibling of the cursor just visited, without visiting its children.
+
+#. ``CXChildVisit_Recurse``: Recursively traverse the children of this cursor, using the same visitor and client data
+
+The expected output of that program is
+
+.. code-block:: 
+
+  Visiting element foo
+  Visiting element bar
+  Visiting element bar_pointer
+
+
+Extracting information from a Cursor
+
+.. The following functions take a ``CXCursor`` as an argument and return associated information.
+
+
+
+Extracting the Cursor kind
+""
+
+``CXCursorKind clang_getCursorKind(CXCursor)`` Describes the kind of entity that a cursor refers to. Example values:
+  
+- ``CXCursor_StructDecl``: A C or C++ struct.
+- ``CXCursor_FieldDecl``: A field in a struct, union, or C++ class.
+- ``CXCursor_CallExpr``: An expression that calls a function
+
+
+Extracting the Cursor type
+""
+``CXType clang_getCursorType(CXCursor)``: Retrieve the type of a CXCursor (if any).
+
+``CXType`` is a struct with two members:
+
+.. code-block:: cpp
+
+  typedef struct {
+enum CXTypeKind kind;
+void *data[2];
+  } CXType;
+
+Example values for ``CXTypeKind kind``
+
+- ``CXType_Invalid``: Represents an invalid type (e.g., where no type is available)
+- ``CXType_Pointer``: A pointer to another type

[PATCH] D153906: [clang] Allow disassembly of multi-module bitcode files

2023-07-05 Thread Matthew Voss via Phabricator via cfe-commits
ormris added a comment.

Yes, I'm working on a new test that's less target dependent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153906

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


[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-07-05 Thread Ralf via Phabricator via cfe-commits
RalfJung added a comment.

I was told that "glibc explicitly only marks memcpy arguments as nonnull for 
external use of headers (i.e. the nonnull assumptions are disabled when 
compiling the implementation)"... okay now re-reading this, that's a statement 
about glibc, not GCC.

Anyway this is outside my expertise. I will try to add Nikita here who said 
"GCC also requires passing equal pointer to memcpy to be legal".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


[PATCH] D154502: [AST] Fix bug in UnresolvedSet::erase of last element

2023-07-05 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added inline comments.



Comment at: clang/unittests/AST/UnresolvedSetTest.cpp:11
+};
+} // namespace clang
+

jroelofs wrote:
> This ODR violation broke the build for me because it's picking up the 
> definition from Decl.h instead of this one.
> 
> ```
> /Users/jonathan_roelofs/llvm-upstream/clang/unittests/AST/UnresolvedSetTest.cpp:30:1:
>  error: call to implicitly-deleted default constructor of 'UnresolvedSetTest'
> TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
> ^
> /Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/gtest.h:2368:3:
>  note: expanded from macro 'TEST_F'
>   GTEST_TEST_(test_fixture, test_name, test_fixture, \
>   ^
> /Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/internal/gtest-internal.h:1362:5:
>  note: expanded from macro 'GTEST_TEST_'
> GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {}   
> \
> ^
> /Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/internal/gtest-internal.h:1351:3:
>  note: expanded from macro 'GTEST_TEST_CLASS_NAME_'
>   test_suite_name##_##test_name##_Test
>   ^
> :30:1: note: expanded from here
> UnresolvedSetTest_Size_Test
> ^
> /Users/jonathan_roelofs/llvm-upstream/clang/unittests/AST/UnresolvedSetTest.cpp:19:13:
>  note: default constructor of 'UnresolvedSetTest' is implicitly deleted 
> because field 'n0' has no default constructor
>   NamedDecl n0, n1, n2, n3;
> ^
> ```
> 
> Maybe it needs to be something like this instead?
> 
> ```
> diff --git a/clang/unittests/AST/UnresolvedSetTest.cpp 
> b/clang/unittests/AST/UnresolvedSetTest.cpp
> index ada857e0e382..3c9077ddc3ec 100644
> --- a/clang/unittests/AST/UnresolvedSetTest.cpp
> +++ b/clang/unittests/AST/UnresolvedSetTest.cpp
> @@ -1,22 +1,23 @@
>  #include "clang/AST/UnresolvedSet.h"
> +#include "clang/AST/Decl.h"
>  #include "gtest/gtest.h"
>  
> -namespace clang {
> -class NamedDecl {
> +namespace dummy {
> +class NamedDecl : public clang::NamedDecl {
>// DeclAccessPair assumes that NamedDecl is at least 4-byte aligned, so we
>// we need to have a dummy value to make this dummy NamedDecl also be 
> aligned.
>[[maybe_unused]] int dummy;
>  
>  public:
> -  NamedDecl() {}
> +  NamedDecl() : clang::NamedDecl(clang::NamedDecl::Kind(0), nullptr, 
> clang::SourceLocation::getFromRawEncoding(0), clang::DeclarationName()) {}
>  };
> -} // namespace clang
> +} // namespace dummy
>  
>  using namespace clang;
>  
>  class UnresolvedSetTest : public ::testing::Test {
>  protected:
> -  NamedDecl n0, n1, n2, n3;
> +  dummy::NamedDecl n0, n1, n2, n3;
>UnresolvedSet<2> set;
>  
>void SetUp() override {
> 
> ```
You might need to build with `-DLLVM_ENABLE_MODULES=On` to see this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154502

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


[PATCH] D154502: [AST] Fix bug in UnresolvedSet::erase of last element

2023-07-05 Thread Jon Roelofs via Phabricator via cfe-commits
jroelofs added inline comments.



Comment at: clang/unittests/AST/UnresolvedSetTest.cpp:11
+};
+} // namespace clang
+

This ODR violation broke the build for me because it's picking up the 
definition from Decl.h instead of this one.

```
/Users/jonathan_roelofs/llvm-upstream/clang/unittests/AST/UnresolvedSetTest.cpp:30:1:
 error: call to implicitly-deleted default constructor of 'UnresolvedSetTest'
TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
^
/Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/gtest.h:2368:3:
 note: expanded from macro 'TEST_F'
  GTEST_TEST_(test_fixture, test_name, test_fixture, \
  ^
/Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/internal/gtest-internal.h:1362:5:
 note: expanded from macro 'GTEST_TEST_'
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {}   \
^
/Users/jonathan_roelofs/llvm-upstream/third-party/unittest/googletest/include/gtest/internal/gtest-internal.h:1351:3:
 note: expanded from macro 'GTEST_TEST_CLASS_NAME_'
  test_suite_name##_##test_name##_Test
  ^
:30:1: note: expanded from here
UnresolvedSetTest_Size_Test
^
/Users/jonathan_roelofs/llvm-upstream/clang/unittests/AST/UnresolvedSetTest.cpp:19:13:
 note: default constructor of 'UnresolvedSetTest' is implicitly deleted because 
field 'n0' has no default constructor
  NamedDecl n0, n1, n2, n3;
^
```

Maybe it needs to be something like this instead?

```
diff --git a/clang/unittests/AST/UnresolvedSetTest.cpp 
b/clang/unittests/AST/UnresolvedSetTest.cpp
index ada857e0e382..3c9077ddc3ec 100644
--- a/clang/unittests/AST/UnresolvedSetTest.cpp
+++ b/clang/unittests/AST/UnresolvedSetTest.cpp
@@ -1,22 +1,23 @@
 #include "clang/AST/UnresolvedSet.h"
+#include "clang/AST/Decl.h"
 #include "gtest/gtest.h"
 
-namespace clang {
-class NamedDecl {
+namespace dummy {
+class NamedDecl : public clang::NamedDecl {
   // DeclAccessPair assumes that NamedDecl is at least 4-byte aligned, so we
   // we need to have a dummy value to make this dummy NamedDecl also be 
aligned.
   [[maybe_unused]] int dummy;
 
 public:
-  NamedDecl() {}
+  NamedDecl() : clang::NamedDecl(clang::NamedDecl::Kind(0), nullptr, 
clang::SourceLocation::getFromRawEncoding(0), clang::DeclarationName()) {}
 };
-} // namespace clang
+} // namespace dummy
 
 using namespace clang;
 
 class UnresolvedSetTest : public ::testing::Test {
 protected:
-  NamedDecl n0, n1, n2, n3;
+  dummy::NamedDecl n0, n1, n2, n3;
   UnresolvedSet<2> set;
 
   void SetUp() override {

```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154502

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


[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-07-05 Thread Stephen Peckham via Phabricator via cfe-commits
stephenpeckham added a comment.

Is memmove() expected to perform a lot worse than memcpy()?  Why not just use 
memmove() all the time.  In some library implementations, memcpy() and 
memmove() are the same function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


[PATCH] D154366: [clang][ExprConstant] Print template arguments when describing stack frame

2023-07-05 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a subscriber: dblaikie.
cjdb added a comment.

Generally in favour of this, but I wonder if we ought to have a way of 
suppressing it when the specialisation is known and ends up being a gargantuan 
name (this is a discussion, not an action item). cc @dblaikie


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154366

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


[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-07-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

You can't just consider the declared function signatures; `memcpy`ing two 
non-empty objects with perfect overlap is a violation of `restrict`, and yet 
IIRC GCC is known to assume that that works in some places.  (I can't duplicate 
that off-hand, though — GCC seems determined to generate inlined `memcpy`s in 
my quick efforts to test this.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


[PATCH] D154484: [clang-format] Add an option to remove redundant parentheses

2023-07-05 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Here is a potential failure scenario

(test.cpp)

  void *bar();
  
  void foo() {
void *p;
int i = 0;
  
while ((p = bar())) {
  i++;
}
  }

(.clang-format)

  Language: Cpp
  RemoveParentheses: ReturnStatement



  clang-format test.cpp > test2.cpp



  test2.cpp:7:12: warning: using the result of an assignment as a condition
without parentheses [-Wparentheses]
while (p = bar()) {
   ~~^~~
  test2.cpp:7:12: note: place parentheses around the assignment to silence this
warning
while (p = bar()) {
 ^
   ()
  test2.cpp:7:12: note: use '==' to turn this assignment into an equality
comparison
while (p = bar()) {
 ^
 ==
  1 warning generated.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154484

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


[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-07-05 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D86993#4474403 , @RalfJung wrote:

> Yeah, agreed. Though I hear that GCC makes similar assumptions, so this 
> should count as something I think. (I don't have a source for this, so it 
> should probably be verified.)

glibc's header files mark the pointer as non-null:
extern void *memcpy (void *restrict dest, const void *restrict src,

size_t __n) throw () __attribute__ ((__nonnull__ (1, 2)));
c99: 7.21.2.1 "The memcpy function copies n characters from the object pointed 
to by s2 into the
object pointed to by s1. If copying takes place between objects that overlap, 
the behavior
is undefined."

null is not a pointer to an object


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


[PATCH] D154531: [AMDGPU] Support -mcpu=native for OpenCL

2023-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, arsenm, MaskRay.
Herald added subscribers: kerbowa, Anastasia, tpr, dstuttard, jvesely, kzhuravl.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: wdng.

When -mcpu=native is specified, try detecting GPU
on the system by using amdgpu-arch tool. If it
fails to detect GPU, emit an error about GPU
not detected. If multiple GPUs are detected,
use the first GPU and emit a warning.


https://reviews.llvm.org/D154531

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/Driver/ToolChains/AMDGPU.cpp


Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -634,6 +634,27 @@
   for (Arg *A : Args)
 DAL->append(A);
 
+  // Replace -mcpu=native with detected GPU.
+  Arg *LastMCPUArg = DAL->getLastArg(options::OPT_mcpu_EQ);
+  if (LastMCPUArg && StringRef(LastMCPUArg->getValue()) == "native") {
+DAL->eraseArg(options::OPT_mcpu_EQ);
+auto GPUsOrErr = getSystemGPUArchs(Args);
+if (!GPUsOrErr) {
+  getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
+  << llvm::Triple::getArchTypeName(getArch())
+  << llvm::toString(GPUsOrErr.takeError()) << "-mcpu";
+} else {
+  auto  = *GPUsOrErr;
+  if (GPUs.size() > 1) {
+getDriver().Diag(diag::warn_drv_multi_gpu_arch)
+<< llvm::Triple::getArchTypeName(getArch())
+<< llvm::join(GPUs, ", ") << "-mcpu";
+  }
+  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mcpu_EQ),
+Args.MakeArgString(GPUs.front()));
+}
+  }
+
   checkTargetID(*DAL);
 
   if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1336,6 +1336,9 @@
 // Warning about mixed HIP and OpenMP compilation / target offloading.
 def HIPOpenMPOffloading: DiagGroup<"hip-omp-target-directives">;
 
+// Warning about multiple GPUs are detected.
+def MultiGPU: DiagGroup<"multi-gpu">;
+
 // Warnings which cause linking of the runtime libraries like
 // libc and the CRT to be skipped.
 def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -82,6 +82,9 @@
 def err_drv_undetermined_gpu_arch : Error<
   "cannot determine %0 architecture: %1; consider passing it via "
   "'%2'">;
+def warn_drv_multi_gpu_arch : Warning<
+  "multiple %0 architecture are detected: %1; only the first one is used for "
+  "'%2'">, InGroup;
 def err_drv_cuda_version_unsupported : Error<
   "GPU arch %0 is supported by CUDA versions between %1 and %2 (inclusive), "
   "but installation at %3 is %4; use '--cuda-path' to specify a different CUDA 
"


Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -634,6 +634,27 @@
   for (Arg *A : Args)
 DAL->append(A);
 
+  // Replace -mcpu=native with detected GPU.
+  Arg *LastMCPUArg = DAL->getLastArg(options::OPT_mcpu_EQ);
+  if (LastMCPUArg && StringRef(LastMCPUArg->getValue()) == "native") {
+DAL->eraseArg(options::OPT_mcpu_EQ);
+auto GPUsOrErr = getSystemGPUArchs(Args);
+if (!GPUsOrErr) {
+  getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
+  << llvm::Triple::getArchTypeName(getArch())
+  << llvm::toString(GPUsOrErr.takeError()) << "-mcpu";
+} else {
+  auto  = *GPUsOrErr;
+  if (GPUs.size() > 1) {
+getDriver().Diag(diag::warn_drv_multi_gpu_arch)
+<< llvm::Triple::getArchTypeName(getArch())
+<< llvm::join(GPUs, ", ") << "-mcpu";
+  }
+  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mcpu_EQ),
+Args.MakeArgString(GPUs.front()));
+}
+  }
+
   checkTargetID(*DAL);
 
   if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1336,6 +1336,9 @@
 // Warning about mixed HIP and OpenMP compilation / target offloading.
 def HIPOpenMPOffloading: DiagGroup<"hip-omp-target-directives">;
 
+// Warning about multiple GPUs are detected.
+def MultiGPU: DiagGroup<"multi-gpu">;
+
 // Warnings which cause linking of the runtime libraries 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

Can we have tests for:
```
struct { int _, _; } a = { ._ = 0 };
```

and

```
struct A {
  A();
  int _, _;
};

A::A() : _(0) {}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D133289: [C2X] N3007 Type inference for object definitions

2023-07-05 Thread Guillot Tony via Phabricator via cfe-commits
to268 updated this revision to Diff 537422.
to268 added a comment.

Minor code reformatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133289

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/C/C2x/n3007.c
  clang/test/CodeGen/auto.c
  clang/test/Parser/c2x-auto.c
  clang/test/Sema/c2x-auto.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1190,12 +1190,12 @@
 
   Underspecified object definitions
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3006.htm;>N3006
-  Unknown
+  Unknown
 
 
   Type inference for object declarations
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm;>N3007
-  No
+  Clang 17
 
 
   constexpr for object definitions
Index: clang/test/Sema/c2x-auto.c
===
--- /dev/null
+++ clang/test/Sema/c2x-auto.c
@@ -0,0 +1,119 @@
+// RUN: %clang_cc1 -std=c2x -verify -pedantic -Wno-comments %s
+
+void test_basic_types(void) {
+  auto undefined; // expected-error {{declaration of variable 'undefined' with deduced type 'auto' requires an initializer}}
+  auto auto_int = 4;
+  auto auto_long = 4UL;
+
+  _Static_assert(_Generic(auto_int, int : 1));
+  _Static_assert(_Generic(auto_long, unsigned long : 1));
+}
+
+void test_sizeof_typeof(void) {
+  auto auto_size = sizeof(auto);  // expected-error {{expected expression}}
+  typeof(auto) tpof = 4;  // expected-error {{expected expression}}
+}
+
+void test_casts(void) {
+  auto int_cast = (int)(4 + 3);
+  auto double_cast = (double)(1 / 3);
+  auto long_cast = (long)(4UL + 3UL);
+  auto auto_cast = (auto)(4 + 3); // expected-error {{expected expression}}
+
+  _Static_assert(_Generic(int_cast, int : 1));
+  _Static_assert(_Generic(double_cast, double : 1));
+  _Static_assert(_Generic(long_cast, long : 1));
+}
+
+void test_compound_literral(void) {
+  auto int_cl = (int){13};
+  auto double_cl = (double){2.5};
+  auto array[] = { 1, 2, 3 }; // expected-error {{cannot use 'auto' with initializer list in C}}
+
+  auto auto_cl = (auto){13};  // expected-error {{expected expression}}
+
+  _Static_assert(_Generic(int_cl, int : 1));
+  _Static_assert(_Generic(double_cl, double : 1));
+}
+
+void test_array_pointers(void) {
+  double array[3] = { 0 };
+  auto a = array;
+  auto b = 
+
+  _Static_assert(_Generic(array, double * : 1));
+  _Static_assert(_Generic(a, double * : 1));
+  _Static_assert(_Generic(b, double (*)[3] : 1));
+}
+
+void test_typeof() {
+  int typeof_target();
+  auto result = (typeof(typeof_target())){12};
+
+  _Static_assert(_Generic(result, int : 1));
+}
+
+void test_qualifiers(const int y) {
+  const auto a = 12;
+  auto b = y;
+  static auto c = 1UL;
+  int* pa =  // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
+  const int* pb = 
+  int* pc =  // expected-warning {{incompatible pointer types initializing 'int *' with an expression of type 'unsigned long *'}}
+
+  _Static_assert(_Generic(a, int : 1));
+  _Static_assert(_Generic(b, int : 1));
+  _Static_assert(_Generic(c, unsigned long : 1));
+  _Static_assert(_Generic(pa, int * : 1));
+  _Static_assert(_Generic(pb, const int * : 1));
+  _Static_assert(_Generic(pc, int * : 1));
+}
+
+void test_strings(void) {
+  auto str = "this is a string";
+  auto str2[] = "this is a string";
+  auto (str3) = "this is a string";
+  auto (((str4))) = "this is a string";
+
+  _Static_assert(_Generic(str, char * : 1));
+  _Static_assert(_Generic(str2, char * : 1));
+  _Static_assert(_Generic(str3, char * : 1));
+  _Static_assert(_Generic(str4, char * : 1));
+}
+
+void test_pointers(void) {
+  auto a = 12;
+  auto *ptr =  // expected-warning {{explicit declaration of 'auto' pointers is a Clang extension}}
+  auto *str = "this is a string"; // expected-warning {{explicit declaration of 'auto' pointers is a Clang extension}}
+  const auto *str2 = "this is a string";  // expected-warning {{explicit declaration of 'auto' pointers is a Clang extension}}
+  auto *b =// expected-warning {{explicit declaration of 'auto' pointers is a Clang extension}}
+  *b = // expected-error {{incompatible pointer to integer conversion assigning to 'int' from 'int *'; remove &}}
+  auto nptr = nullptr;
+
+  _Static_assert(_Generic(a, int : 1));
+  _Static_assert(_Generic(ptr, int * : 1));
+  _Static_assert(_Generic(str, char * : 1));
+  _Static_assert(_Generic(str2, const char * : 1));
+  _Static_assert(_Generic(b, int * : 1));
+}
+
+void 

[PATCH] D145823: [OpenMP][CodeGen] Add codegen for combined 'loop' directives.

2023-07-05 Thread David Pagan 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 rGeb61bde829bc: [OpenMP][CodeGen] Add codegen for combined 
loop directives. (authored by ddpagan).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145823

Files:
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/generic_loop_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_generic_loop_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_generic_loop_generic_mode_codegen.cpp
  clang/test/OpenMP/parallel_generic_loop_codegen.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen-1.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen-2.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen-3.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen.cpp
  clang/test/OpenMP/target_parallel_generic_loop_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_generic_loop_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_codegen-1.cpp
  clang/test/OpenMP/target_teams_generic_loop_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_depend_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_order_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_private_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_reduction_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_uses_allocators_codegen.cpp
  clang/test/OpenMP/teams_generic_loop_codegen-1.cpp
  clang/test/OpenMP/teams_generic_loop_codegen.cpp
  clang/test/OpenMP/teams_generic_loop_collapse_codgen.cpp
  clang/test/OpenMP/teams_generic_loop_private_codegen.cpp
  clang/test/OpenMP/teams_generic_loop_reduction_codegen.cpp

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


[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-07-05 Thread Ralf via Phabricator via cfe-commits
RalfJung added a comment.

Yeah, agreed. Though I hear that GCC makes similar assumptions, so this should 
count as something I think. (I don't have a source for this, so it should 
probably be verified.)

Anyway I don't think LLVM documenting its assumptions should be blocked on 
changing the C standard. Maybe LLVM should have blocked *making* those 
assumptions on changing the standard, but that ship has sailed long ago...
(I have less of an opinion about clang since I am not involved there.)

> I think it makes sense to document this both from the Clang perspective and 
> from the LLVM perspective, as they're somewhat different.

What would be the right place in LLVM to document this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-07-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D86993#4474267 , @RalfJung wrote:

> The first point is important for LLVM's own memcpy/memmove intrinsics, which 
> are documented as NOPs on size 0 (and e.g. Rust relies on that).

Right, I understand that these assumptions come directly from the stronger 
semantics offered by the LLVM intrinsics.  The C committee is not going to find 
that compelling, though — we don't get to default-win arguments just because 
we've defined an IR with stronger semantics than necessary.  They are going to 
want to see arguments about why it's valuable for the C library to have these 
stronger semantics, which for us means talking about code patterns in user 
programs that take advantage of those stronger semantics and the benefits they 
see from that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


  1   2   3   >