[PATCH] D141824: [clang-repl] Add a command to load dynamic libraries

2023-03-29 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

Hi @argentite, the test you added is failing on the PS4 linux builder because 
the test seems to require linking and the PS4 target requires an external 
linker which is not present on the system. Can the test be rewritten to not 
require linking?

https://lab.llvm.org/buildbot/#/builders/139/builds/38153

  clang: error: unable to execute command: Executable "orbis-ld" doesn't exist!
  clang: error: linker command failed with exit code 1 (use -v to see 
invocation)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141824

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


[clang] e43247d - [Clang][Flang][AMDGPU] Add support for AMDGPU to Flang driver

2023-03-29 Thread Dominik Adamski via cfe-commits

Author: Dominik Adamski
Date: 2023-03-29T02:23:37-05:00
New Revision: e43247dd329cabf7eb4dd4323b3422d3774e57a7

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

LOG: [Clang][Flang][AMDGPU] Add support for AMDGPU to Flang driver

Scope of changes:
  1) Extract common code between Clang and Flang for parsing AMDGPU features
  2) Add function which adds implicit target features for AMDGPU as Clang does
  3) Add AMDGPU target as one of valid targets for Flang

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

Reviewed By: yaxunl, awarzynski

Added: 


Modified: 
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/Flang.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/target-cpu-features-invalid.f90
flang/test/Driver/target-cpu-features.f90
llvm/include/llvm/TargetParser/TargetParser.h
llvm/lib/TargetParser/TargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 9b3a0b0f40edb..5b99755c21e2b 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -179,197 +179,19 @@ ArrayRef 
AMDGPUTargetInfo::getGCCRegNames() const {
 bool AMDGPUTargetInfo::initFeatureMap(
 llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU,
 const std::vector &FeatureVec) const {
-  const bool IsNullCPU = CPU.empty();
-  bool IsWave32Capable = false;
 
   using namespace llvm::AMDGPU;
-
-  // XXX - What does the member GPU mean if device name string passed here?
-  if (isAMDGCN(getTriple())) {
-switch (llvm::AMDGPU::parseArchAMDGCN(CPU)) {
-case GK_GFX1103:
-case GK_GFX1102:
-case GK_GFX1101:
-case GK_GFX1100:
-  IsWave32Capable = true;
-  Features["ci-insts"] = true;
-  Features["dot5-insts"] = true;
-  Features["dot7-insts"] = true;
-  Features["dot8-insts"] = true;
-  Features["dot9-insts"] = true;
-  Features["dot10-insts"] = true;
-  Features["dl-insts"] = true;
-  Features["16-bit-insts"] = true;
-  Features["dpp"] = true;
-  Features["gfx8-insts"] = true;
-  Features["gfx9-insts"] = true;
-  Features["gfx10-insts"] = true;
-  Features["gfx10-3-insts"] = true;
-  Features["gfx11-insts"] = true;
-  Features["atomic-fadd-rtn-insts"] = true;
-  break;
-case GK_GFX1036:
-case GK_GFX1035:
-case GK_GFX1034:
-case GK_GFX1033:
-case GK_GFX1032:
-case GK_GFX1031:
-case GK_GFX1030:
-  IsWave32Capable = true;
-  Features["ci-insts"] = true;
-  Features["dot1-insts"] = true;
-  Features["dot2-insts"] = true;
-  Features["dot5-insts"] = true;
-  Features["dot6-insts"] = true;
-  Features["dot7-insts"] = true;
-  Features["dot10-insts"] = true;
-  Features["dl-insts"] = true;
-  Features["16-bit-insts"] = true;
-  Features["dpp"] = true;
-  Features["gfx8-insts"] = true;
-  Features["gfx9-insts"] = true;
-  Features["gfx10-insts"] = true;
-  Features["gfx10-3-insts"] = true;
-  Features["s-memrealtime"] = true;
-  Features["s-memtime-inst"] = true;
-  break;
-case GK_GFX1012:
-case GK_GFX1011:
-  Features["dot1-insts"] = true;
-  Features["dot2-insts"] = true;
-  Features["dot5-insts"] = true;
-  Features["dot6-insts"] = true;
-  Features["dot7-insts"] = true;
-  Features["dot10-insts"] = true;
-  [[fallthrough]];
-case GK_GFX1013:
-case GK_GFX1010:
-  IsWave32Capable = true;
-  Features["dl-insts"] = true;
-  Features["ci-insts"] = true;
-  Features["16-bit-insts"] = true;
-  Features["dpp"] = true;
-  Features["gfx8-insts"] = true;
-  Features["gfx9-insts"] = true;
-  Features["gfx10-insts"] = true;
-  Features["s-memrealtime"] = true;
-  Features["s-memtime-inst"] = true;
-  break;
-case GK_GFX940:
-  Features["gfx940-insts"] = true;
-  Features["fp8-insts"] = true;
-  Features["atomic-ds-pk-add-16-insts"] = true;
-  Features["atomic-flat-pk-add-16-insts"] = true;
-  Features["atomic-global-pk-add-bf16-inst"] = true;
-  [[fallthrough]];
-case GK_GFX90A:
-  Features["gfx90a-insts"] = true;
-  Features["atomic-buffer-global-pk-add-f16-insts"] = true;
-  Features["atomic-fadd-rtn-insts"] = true;
-  [[fallthrough]];
-case GK_GFX908:
-  Features["dot3-insts"] = true;
-  Features["dot4-insts"] = true;
-  Features["dot5-insts"] = true;
-  Features["dot6-insts"] = true;
-  Features["mai-insts"] = true;
-  [[fallthrough]];
-case GK_GFX906:
-  Features["dl-insts"] = true;
-  Features["dot1-insts"] = true;
-  Features["dot2-insts"] = true;
-   

[PATCH] D145579: [Clang][Flang][AMDGPU] Add support for AMDGPU to Flang driver

2023-03-29 Thread Dominik Adamski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe43247dd329c: [Clang][Flang][AMDGPU] Add support for AMDGPU 
to Flang driver (authored by domada).

Changed prior to commit:
  https://reviews.llvm.org/D145579?vs=508977&id=509233#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145579

Files:
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/target-cpu-features-invalid.f90
  flang/test/Driver/target-cpu-features.f90
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/TargetParser/TargetParser.cpp

Index: llvm/lib/TargetParser/TargetParser.cpp
===
--- llvm/lib/TargetParser/TargetParser.cpp
+++ llvm/lib/TargetParser/TargetParser.cpp
@@ -251,3 +251,218 @@
 
   return T.isAMDGCN() ? getArchNameAMDGCN(ProcKind) : getArchNameR600(ProcKind);
 }
+
+void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
+  StringMap &Features) {
+  // XXX - What does the member GPU mean if device name string passed here?
+  if (T.isAMDGCN()) {
+switch (parseArchAMDGCN(GPU)) {
+case GK_GFX1103:
+case GK_GFX1102:
+case GK_GFX1101:
+case GK_GFX1100:
+  Features["ci-insts"] = true;
+  Features["dot5-insts"] = true;
+  Features["dot7-insts"] = true;
+  Features["dot8-insts"] = true;
+  Features["dot9-insts"] = true;
+  Features["dot10-insts"] = true;
+  Features["dl-insts"] = true;
+  Features["16-bit-insts"] = true;
+  Features["dpp"] = true;
+  Features["gfx8-insts"] = true;
+  Features["gfx9-insts"] = true;
+  Features["gfx10-insts"] = true;
+  Features["gfx10-3-insts"] = true;
+  Features["gfx11-insts"] = true;
+  Features["atomic-fadd-rtn-insts"] = true;
+  break;
+case GK_GFX1036:
+case GK_GFX1035:
+case GK_GFX1034:
+case GK_GFX1033:
+case GK_GFX1032:
+case GK_GFX1031:
+case GK_GFX1030:
+  Features["ci-insts"] = true;
+  Features["dot1-insts"] = true;
+  Features["dot2-insts"] = true;
+  Features["dot5-insts"] = true;
+  Features["dot6-insts"] = true;
+  Features["dot7-insts"] = true;
+  Features["dot10-insts"] = true;
+  Features["dl-insts"] = true;
+  Features["16-bit-insts"] = true;
+  Features["dpp"] = true;
+  Features["gfx8-insts"] = true;
+  Features["gfx9-insts"] = true;
+  Features["gfx10-insts"] = true;
+  Features["gfx10-3-insts"] = true;
+  Features["s-memrealtime"] = true;
+  Features["s-memtime-inst"] = true;
+  break;
+case GK_GFX1012:
+case GK_GFX1011:
+  Features["dot1-insts"] = true;
+  Features["dot2-insts"] = true;
+  Features["dot5-insts"] = true;
+  Features["dot6-insts"] = true;
+  Features["dot7-insts"] = true;
+  Features["dot10-insts"] = true;
+  [[fallthrough]];
+case GK_GFX1013:
+case GK_GFX1010:
+  Features["dl-insts"] = true;
+  Features["ci-insts"] = true;
+  Features["16-bit-insts"] = true;
+  Features["dpp"] = true;
+  Features["gfx8-insts"] = true;
+  Features["gfx9-insts"] = true;
+  Features["gfx10-insts"] = true;
+  Features["s-memrealtime"] = true;
+  Features["s-memtime-inst"] = true;
+  break;
+case GK_GFX940:
+  Features["gfx940-insts"] = true;
+  Features["fp8-insts"] = true;
+  Features["atomic-ds-pk-add-16-insts"] = true;
+  Features["atomic-flat-pk-add-16-insts"] = true;
+  Features["atomic-global-pk-add-bf16-inst"] = true;
+  [[fallthrough]];
+case GK_GFX90A:
+  Features["gfx90a-insts"] = true;
+  Features["atomic-buffer-global-pk-add-f16-insts"] = true;
+  Features["atomic-fadd-rtn-insts"] = true;
+  [[fallthrough]];
+case GK_GFX908:
+  Features["dot3-insts"] = true;
+  Features["dot4-insts"] = true;
+  Features["dot5-insts"] = true;
+  Features["dot6-insts"] = true;
+  Features["mai-insts"] = true;
+  [[fallthrough]];
+case GK_GFX906:
+  Features["dl-insts"] = true;
+  Features["dot1-insts"] = true;
+  Features["dot2-insts"] = true;
+  Features["dot7-insts"] = true;
+  Features["dot10-insts"] = true;
+  [[fallthrough]];
+case GK_GFX90C:
+case GK_GFX909:
+case GK_GFX904:
+case GK_GFX902:
+case GK_GFX900:
+  Features["gfx9-insts"] = true;
+  [[fallthrough]];
+case GK_GFX810:
+case GK_GFX805:
+case GK_GFX803:
+case GK_GFX802:
+case GK_GFX801:
+  Features["gfx8-insts"] = true;
+  Features["16-bit-insts"] = true;
+  Features["dpp"] = true;
+  Features["s-memrealtime"] = true;
+  [[fallthrough]];
+case GK_GFX705:
+case GK_GFX704:
+case GK_GFX703:
+case GK_GFX702:
+case GK

[PATCH] D141824: [clang-repl] Add a command to load dynamic libraries

2023-03-29 Thread Anubhab Ghosh via Phabricator via cfe-commits
argentite added a comment.

Hi, @dyung ! It seems the dynamic library generation is failing from the lack 
of a linker. We need a test library to load at runtime in clang-repl. Do you 
have any idea how we can create one without a linker? Otherwise we can disable 
the test on PS4 as it is probably an unlikely use case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141824

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


[PATCH] D146717: [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/CollectMacros.h:69
   const MacroDefinition &MD) override;
+  using PPCallbacks::Elifdef;
+  using PPCallbacks::Elifndef;

kadircet wrote:
> why do we have these using decls?
This is to suppress the -Woverloaded-virtual diagnostic from gcc 
(https://godbolt.org/z/9b76fYbjx) -- PPCallback has two overloads of 
`Elifdefs`, here we only override one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146717

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


[PATCH] D141824: [clang-repl] Add a command to load dynamic libraries

2023-03-29 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

In D141824#4229693 , @argentite wrote:

> Hi, @dyung ! It seems the dynamic library generation is failing from the lack 
> of a linker. We need a test library to load at runtime in clang-repl. Do you 
> have any idea how we can create one without a linker? Otherwise we can 
> disable the test on PS4 as it is probably an unlikely use case.

If you need to generate a library at test time, then the test won't work on the 
PS4 platform since the external linker won't be present. (Note that it should 
work on PS5 as that uses LLD for the linker). I think you should probably just 
mark the test as unsupported on PS4.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141824

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


[PATCH] D143364: [RISCV] Support scalar/fix-length vector NTLH intrinsic with different domain

2023-03-29 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 509244.
BeMg edited the summary of this revision.
BeMg added a comment.
Herald added a subscriber: jobnoorman.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143364

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_ntlh.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/ntlh-intrinsics/riscv32-zihintntl.c
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/Target/RISCV/RISCVInsertNTLHInsts.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.h
  llvm/lib/Target/RISCV/RISCVInstrInfoZihintntl.td

Index: llvm/lib/Target/RISCV/RISCVInstrInfoZihintntl.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoZihintntl.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoZihintntl.td
@@ -11,12 +11,24 @@
 ///
 //===--===//
 
-let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Size = 4 in {
-  def PseudoNTLALL :  Pseudo<(outs), (ins), [], "ntl.all">, 
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Size = 4, isCodeGenOnly = 1 in {
+  def PseudoNTLP1   :  Pseudo<(outs), (ins), [], "ntl.p1">, 
+ PseudoInstExpansion<(ADD X0, X0, X2)>;
+  def PseudoNTLPALL :  Pseudo<(outs), (ins), [], "ntl.pall">, 
+ PseudoInstExpansion<(ADD X0, X0, X3)>;
+  def PseudoNTLS1   :  Pseudo<(outs), (ins), [], "ntl.s1">, 
+ PseudoInstExpansion<(ADD X0, X0, X4)>;
+  def PseudoNTLALL  :  Pseudo<(outs), (ins), [], "ntl.all">, 
  PseudoInstExpansion<(ADD X0, X0, X5)>;
 }
 
-let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Size = 2 in {
-  def PseudoCNTLALL :  Pseudo<(outs), (ins), [], "c.ntl.all">,
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0, Size = 2, isCodeGenOnly = 1 in {
+  def PseudoCNTLP1   :  Pseudo<(outs), (ins), [], "c.ntl.p1">,
+  PseudoInstExpansion<(C_ADD_HINT X0, X0, X2)>;
+  def PseudoCNTLPALL :  Pseudo<(outs), (ins), [], "c.ntl.pall">,
+  PseudoInstExpansion<(C_ADD_HINT X0, X0, X3)>;
+  def PseudoCNTLS1   :  Pseudo<(outs), (ins), [], "c.ntl.s1">,
+  PseudoInstExpansion<(C_ADD_HINT X0, X0, X4)>;
+  def PseudoCNTLALL  :  Pseudo<(outs), (ins), [], "c.ntl.all">,
   PseudoInstExpansion<(C_ADD_HINT X0, X0, X5)>;
 }
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.h
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.h
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.h
@@ -25,6 +25,11 @@
 
 class RISCVSubtarget;
 
+static const MachineMemOperand::Flags MONontemporalBit0 =
+MachineMemOperand::MOTargetFlag1;
+static const MachineMemOperand::Flags MONontemporalBit1 =
+MachineMemOperand::MOTargetFlag2;
+
 namespace RISCVCC {
 
 enum CondCode {
@@ -238,6 +243,9 @@
 return hasAllNBitUsers(MI, MRI, 32);
   }
 
+  ArrayRef>
+  getSerializableMachineMemOperandTargetFlags() const override;
+
 protected:
   const RISCVSubtarget &STI;
 };
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -2848,6 +2848,14 @@
   return true;
 }
 
+ArrayRef>
+RISCVInstrInfo::getSerializableMachineMemOperandTargetFlags() const {
+  static const std::pair TargetFlags[] =
+  {{MONontemporalBit0, "riscv-non-temporal-domain-bit-0"},
+   {MONontemporalBit1, "riscv-non-temporal-domain-bit-1"}};
+  return makeArrayRef(TargetFlags);
+}
+
 // Returns true if this is the sext.w pattern, addiw rd, rs1, 0.
 bool RISCV::isSEXT_W(const MachineInstr &MI) {
   return MI.getOpcode() == RISCV::ADDIW && MI.getOperand(1).isReg() &&
Index: llvm/lib/Target/RISCV/RISCVInsertNTLHInsts.cpp
===
--- llvm/lib/Target/RISCV/RISCVInsertNTLHInsts.cpp
+++ llvm/lib/Target/RISCV/RISCVInsertNTLHInsts.cpp
@@ -67,11 +67,27 @@
 continue;
   MachineMemOperand *MMO = *(MBBI.memoperands_begin());
   if (MMO->isNonTemporal()) {
+uint64_t NontemporalMode = 0;
+if (MMO->getFlags() & MONontemporalBit0)
+  NontemporalMode += 0b1;
+if (MMO->getFlags() & MONontemporalBit1)
+  NontemporalMode += 0b10;
+
+static const uint16_t NTLOpc[] = {
+RISCV::PseudoNTLP1, RISCV::PseudoNTLPALL, RISCV::PseudoNTLS1,
+RISCV::PseudoNTLALL};
+static const uint16_t CNTLOpc[] = {
+RISCV::PseudoCNTLP1, 

[PATCH] D146717: [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146717

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


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-29 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 509249.
Krishna-13-cyber added a comment.

I have removed the redundant comments and have moved the `if' condition above 
with the ongoing conditional statement (to avoid printing obvious expressions).

- Updated static_assert warning message
- Added Test cases




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
 
+  static_assert(true && false, ""); // expected-error {{failed}}
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16725,7 +16725,7 @@
   return;
 
 // Don't print obvious expressions.
-if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
+if ((!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS)) || 
Op->getOpcode() == BO_LOr)
   return;
 
 struct {


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
 
+  static_assert(true && false, ""); // expected-error {{failed}}
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16725,7 +16725,7 @@
   return;
 
 // Don't print obvious expressions.
-if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
+if ((!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS)) || Op->getOpcode() == BO_LOr)
   return;
 
 struct {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141824: [clang-repl] Add a command to load dynamic libraries

2023-03-29 Thread Anubhab Ghosh via Phabricator via cfe-commits
argentite added a comment.

Just to confirm, `UNSUPPORTED: target=x86_64-scei-ps4` should be enough, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141824

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


[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 509264.

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

https://reviews.llvm.org/D145545

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h

Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -54,6 +54,7 @@
   // Statement visitors.
   bool visitStmt(const Stmt *S);
   bool visitCompoundStmt(const CompoundStmt *S);
+  bool visitUnscopedCompoundStmt(const Stmt *S);
   bool visitDeclStmt(const DeclStmt *DS);
   bool visitReturnStmt(const ReturnStmt *RS);
   bool visitIfStmt(const IfStmt *IS);
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -194,6 +194,21 @@
   }
 }
 
+template 
+bool ByteCodeStmtGen::visitUnscopedCompoundStmt(const Stmt *S) {
+  if (isa(S))
+return true;
+
+  if (const auto *CS = dyn_cast(S)) {
+for (auto *InnerStmt : CS->body())
+  if (!visitStmt(InnerStmt))
+return false;
+return true;
+  }
+
+  return this->visitStmt(S);
+}
+
 template 
 bool ByteCodeStmtGen::visitCompoundStmt(
 const CompoundStmt *CompoundStmt) {
@@ -306,11 +321,15 @@
   if (!this->jumpFalse(EndLabel))
 return false;
 
-  if (!this->visitStmt(Body))
-return false;
+  LocalScope Scope(this);
+  {
+DestructorScope DS(Scope);
+if (!this->visitUnscopedCompoundStmt(Body))
+  return false;
+  }
+
   if (!this->jump(CondLabel))
 return false;
-
   this->emitLabel(EndLabel);
 
   return true;
@@ -325,15 +344,21 @@
   LabelTy EndLabel = this->getLabel();
   LabelTy CondLabel = this->getLabel();
   LoopScope LS(this, EndLabel, CondLabel);
+  LocalScope Scope(this);
 
   this->emitLabel(StartLabel);
-  if (!this->visitStmt(Body))
-return false;
-  this->emitLabel(CondLabel);
-  if (!this->visitBool(Cond))
-return false;
+  {
+DestructorScope DS(Scope);
+
+if (!this->visitUnscopedCompoundStmt(Body))
+  return false;
+this->emitLabel(CondLabel);
+if (!this->visitBool(Cond))
+  return false;
+  }
   if (!this->jumpTrue(StartLabel))
 return false;
+
   this->emitLabel(EndLabel);
   return true;
 }
@@ -350,6 +375,7 @@
   LabelTy CondLabel = this->getLabel();
   LabelTy IncLabel = this->getLabel();
   LoopScope LS(this, EndLabel, IncLabel);
+  LocalScope Scope(this);
 
   if (Init && !this->visitStmt(Init))
 return false;
@@ -360,11 +386,17 @@
 if (!this->jumpFalse(EndLabel))
   return false;
   }
-  if (Body && !this->visitStmt(Body))
-return false;
-  this->emitLabel(IncLabel);
-  if (Inc && !this->discard(Inc))
-return false;
+
+  {
+DestructorScope DS(Scope);
+
+if (Body && !this->visitUnscopedCompoundStmt(Body))
+  return false;
+this->emitLabel(IncLabel);
+if (Inc && !this->discard(Inc))
+  return false;
+  }
+
   if (!this->jump(CondLabel))
 return false;
   this->emitLabel(EndLabel);
@@ -386,38 +418,40 @@
   LabelTy CondLabel = this->getLabel();
   LabelTy IncLabel = this->getLabel();
   LoopScope LS(this, EndLabel, IncLabel);
-  {
-ExprScope ES(this);
 
-// Emit declarations needed in the loop.
-if (Init && !this->visitStmt(Init))
-  return false;
-if (!this->visitStmt(RangeStmt))
-  return false;
-if (!this->visitStmt(BeginStmt))
-  return false;
-if (!this->visitStmt(EndStmt))
-  return false;
+  // Emit declarations needed in the loop.
+  if (Init && !this->visitStmt(Init))
+return false;
+  if (!this->visitStmt(RangeStmt))
+return false;
+  if (!this->visitStmt(BeginStmt))
+return false;
+  if (!this->visitStmt(EndStmt))
+return false;
 
-// Now the condition as well as the loop variable assignment.
-this->emitLabel(CondLabel);
-if (!this->visitBool(Cond))
-  return false;
-if (!this->jumpFalse(EndLabel))
-  return false;
+  // Now the condition as well as the loop variable assignment.
+  this->emitLabel(CondLabel);
+  if (!this->visitBool(Cond))
+return false;
+  if (!this->jumpFalse(EndLabel))
+return false;
 
-if (!this->visitVarDecl(LoopVar))
-  return false;
+  if (!this->visitVarDecl(LoopVar))
+return false;
+
+  // Body.
+  LocalScope Scope(this);
+  {
+DestructorScope DS(Scope);
 
-// Body.
-if (!this->visitStmt(Body))
+if (!this->visitUnscopedCompoundStmt(Body))
   return false;
 this->emitLabel(IncLabel);
 if (!this->discard(Inc))
   return false;
-if (!this->jump(CondLabel))
-  return false;
   }
+  if (!this->jump(CondLabel))
+return false;
 
   this->emitLabel(EndLabel);
   return true;
@@ -428,7 +462,7 @@
   if (!BreakLabel)
 return false;
 
-  this->emitCleanup();
+  this->VarScope->emit

[clang-tools-extra] 3ddfea0 - [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-29 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-03-29T11:24:44+02:00
New Revision: 3ddfea07f8d033a7e78695baf282a54f0d6765e5

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

LOG: [clangd] Handle the C++2b elifdef and elindef PP structure in 
CollectMainFileMacros.

Reviewed By: kadircet

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

Added: 


Modified: 
clang-tools-extra/clangd/CollectMacros.cpp
clang-tools-extra/clangd/CollectMacros.h
clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CollectMacros.cpp 
b/clang-tools-extra/clangd/CollectMacros.cpp
index c0ed8b68ea481..9fa3d6955fc6f 100644
--- a/clang-tools-extra/clangd/CollectMacros.cpp
+++ b/clang-tools-extra/clangd/CollectMacros.cpp
@@ -36,33 +36,51 @@ void CollectMainFileMacros::FileChanged(SourceLocation Loc, 
FileChangeReason,
 SrcMgr::CharacteristicKind, FileID) {
   InMainFile = isInsideMainFile(Loc, SM);
 }
+
 void CollectMainFileMacros::MacroExpands(const Token &MacroName,
  const MacroDefinition &MD,
  SourceRange Range,
  const MacroArgs *Args) {
   add(MacroName, MD.getMacroInfo());
 }
+
 void CollectMainFileMacros::MacroUndefined(const clang::Token &MacroName,
const clang::MacroDefinition &MD,
const clang::MacroDirective *Undef) 
{
   add(MacroName, MD.getMacroInfo());
 }
+
 void CollectMainFileMacros::Ifdef(SourceLocation Loc, const Token &MacroName,
   const MacroDefinition &MD) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
 void CollectMainFileMacros::Ifndef(SourceLocation Loc, const Token &MacroName,
const MacroDefinition &MD) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
+void CollectMainFileMacros::Elifdef(SourceLocation Loc, const Token &MacroName,
+const MacroDefinition &MD) {
+  add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
+  /*InConditionalDirective=*/true);
+}
+
+void CollectMainFileMacros::Elifndef(SourceLocation Loc, const Token 
&MacroName,
+ const MacroDefinition &MD) {
+  add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
+  /*InConditionalDirective=*/true);
+}
+
 void CollectMainFileMacros::Defined(const Token &MacroName,
 const MacroDefinition &MD,
 SourceRange Range) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
 void CollectMainFileMacros::SourceRangeSkipped(SourceRange R,
SourceLocation EndifLoc) {
   if (!InMainFile)

diff  --git a/clang-tools-extra/clangd/CollectMacros.h 
b/clang-tools-extra/clangd/CollectMacros.h
index d5789a2a88912..716a5d58070fd 100644
--- a/clang-tools-extra/clangd/CollectMacros.h
+++ b/clang-tools-extra/clangd/CollectMacros.h
@@ -12,6 +12,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "index/SymbolID.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,11 +62,16 @@ class CollectMainFileMacros : public PPCallbacks {
   const clang::MacroDefinition &MD,
   const clang::MacroDirective *Undef) override;
 
-  // FIXME: handle C++23 #elifdef, #elifndef
   void Ifdef(SourceLocation Loc, const Token &MacroName,
  const MacroDefinition &MD) override;
   void Ifndef(SourceLocation Loc, const Token &MacroName,
   const MacroDefinition &MD) override;
+  using PPCallbacks::Elifdef;
+  using PPCallbacks::Elifndef;
+  void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
+   const MacroDefinition &MD) override;
+  void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
+const MacroDefinition &MD) override;
 
   void Defined(const Token &MacroName, const MacroDefinition &MD,
SourceRange Range) override;

diff  --git a/clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp 
b/clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
index 163a7f1a31707..459d18aed07d6 100644
--- a/clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -56,6 +56,11 @@ TEST(CollectMainFileMacros, SelectedMacros) {
   // )cpp"

[PATCH] D146717: [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-29 Thread Haojian Wu 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 rG3ddfea07f8d0: [clangd] Handle the C++2b elifdef and elindef 
PP structure in… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146717

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp

Index: clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
===
--- clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -56,6 +56,11 @@
   // )cpp",
   R"cpp(
 #ifdef $Unknown(condit)[[UNDEFINED]]
+#elifdef $Unknown(condit)[[UNDEFINED]]
+#endif
+
+#ifdef $Unknown(condit)[[UNDEFINED]]
+#elifndef $Unknown(condit)[[UNDEFINED]]
 #endif
 
 #ifndef $Unknown(condit)[[UNDEFINED]]
@@ -101,11 +106,12 @@
 
   for (const char *Test : Tests) {
 Annotations T(Test);
-auto AST = TestTU::withCode(T.code()).build();
+auto Inputs = TestTU::withCode(T.code());
+Inputs.ExtraArgs.push_back("-std=c++2b");
+auto AST = Inputs.build();
 auto ActualMacroRefs = AST.getMacros();
 auto &SM = AST.getSourceManager();
 auto &PP = AST.getPreprocessor();
-
 for (const auto &[Name, Ranges] : T.all_ranges()) {
   if (Name == "Unknown") {
 EXPECT_THAT(ActualMacroRefs.UnknownMacros,
Index: clang-tools-extra/clangd/CollectMacros.h
===
--- clang-tools-extra/clangd/CollectMacros.h
+++ clang-tools-extra/clangd/CollectMacros.h
@@ -12,6 +12,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "index/SymbolID.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,11 +62,16 @@
   const clang::MacroDefinition &MD,
   const clang::MacroDirective *Undef) override;
 
-  // FIXME: handle C++23 #elifdef, #elifndef
   void Ifdef(SourceLocation Loc, const Token &MacroName,
  const MacroDefinition &MD) override;
   void Ifndef(SourceLocation Loc, const Token &MacroName,
   const MacroDefinition &MD) override;
+  using PPCallbacks::Elifdef;
+  using PPCallbacks::Elifndef;
+  void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
+   const MacroDefinition &MD) override;
+  void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
+const MacroDefinition &MD) override;
 
   void Defined(const Token &MacroName, const MacroDefinition &MD,
SourceRange Range) override;
Index: clang-tools-extra/clangd/CollectMacros.cpp
===
--- clang-tools-extra/clangd/CollectMacros.cpp
+++ clang-tools-extra/clangd/CollectMacros.cpp
@@ -36,33 +36,51 @@
 SrcMgr::CharacteristicKind, FileID) {
   InMainFile = isInsideMainFile(Loc, SM);
 }
+
 void CollectMainFileMacros::MacroExpands(const Token &MacroName,
  const MacroDefinition &MD,
  SourceRange Range,
  const MacroArgs *Args) {
   add(MacroName, MD.getMacroInfo());
 }
+
 void CollectMainFileMacros::MacroUndefined(const clang::Token &MacroName,
const clang::MacroDefinition &MD,
const clang::MacroDirective *Undef) {
   add(MacroName, MD.getMacroInfo());
 }
+
 void CollectMainFileMacros::Ifdef(SourceLocation Loc, const Token &MacroName,
   const MacroDefinition &MD) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
 void CollectMainFileMacros::Ifndef(SourceLocation Loc, const Token &MacroName,
const MacroDefinition &MD) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
+void CollectMainFileMacros::Elifdef(SourceLocation Loc, const Token &MacroName,
+const MacroDefinition &MD) {
+  add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
+  /*InConditionalDirective=*/true);
+}
+
+void CollectMainFileMacros::Elifndef(SourceLocation Loc, const Token &MacroName,
+ const MacroDefinition &MD) {
+  add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
+  /*InConditionalDirective=*/true);
+}
+
 void CollectMainFileMacros::Defined(const Token &MacroName,
 const MacroDefinit

[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 3 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeStmtGen.cpp:324-328
+  LocalScope Scope(this);
+  if (!this->visitUnscopedCompoundStmt(Body))
 return false;
+
+  Scope.emitDestructors();

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > `AutoScope` and some curly braces to delimit the scope object lifetime?
> > The problem is that we want to emit the destructors before the jump, but 
> > not destroy the scope. That should happen after the end label, when the 
> > loop is finished altogether so an `AutoScope` doesn't work.
> Ahh yeah, that's a good point... but this still worries me a bit because of 
> how easy it is to misuse the scope after emitting the destructors. 
> Notionally, we want two scopes, right? One scope for the loop construct guts 
> and a second (inner) scope for the loop body. That's how the construct is 
> modeled in the standard: http://eel.is/c++draft/stmt.while#2
Add a `DestructorScope` that just emits the destructors of a given scope.


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

https://reviews.llvm.org/D145545

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


[clang] 55916de - [clang][HIP][OpenMP] Add warning if mixed HIP / OpenMP offloading

2023-03-29 Thread Michael Halkenhaeuser via cfe-commits

Author: Michael Halkenhaeuser
Date: 2023-03-29T11:31:17+02:00
New Revision: 55916de2d37742fe334c0726ccf9e584bdaed09f

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

LOG: [clang][HIP][OpenMP] Add warning if mixed HIP / OpenMP offloading

Adds a warning, issued by the clang semantic analysis, if HIP and OpenMP target 
offloading is requested concurrently.
That is, if HIP language mode is active but OpenMP target directives are 
encountered.
Previously, a user might not have been aware that target directives are ignored 
in such a case.

Generation of this warning is (lit-)tested via "make check-clang-semaopenmp".
The warning can be ignored via "-Wno-hip-omp-target-directives".

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

Added: 
clang/test/SemaOpenMP/hip-omp-mix.cpp

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2b6525ca5f866..0d2829d64501f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1321,6 +1321,9 @@ def CudaUnknownVersion: DiagGroup<"unknown-cuda-version">;
 // ignored by CUDA.
 def HIPOnly : DiagGroup<"hip-only">;
 
+// Warning about mixed HIP and OpenMP compilation / target offloading.
+def HIPOpenMPOffloading: DiagGroup<"hip-omp-target-directives">;
+
 // Warnings which cause linking of the runtime libraries like
 // libc and the CRT to be skipped.
 def AVRRtlibLinkingQuirks : DiagGroup<"avr-rtlib-linking-quirks">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 79225036f7f2b..eedc8c18f93dc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8634,6 +8634,10 @@ def 
note_cuda_device_builtin_surftex_should_be_template_class : Note<
 def err_hip_invalid_args_builtin_mangled_name : Error<
 "invalid argument: symbol must be a device-side function or global 
variable">;
 
+def warn_hip_omp_target_directives : Warning<
+  "HIP does not support OpenMP target directives; directive has been ignored">,
+  InGroup, DefaultError;
+
 def warn_non_pod_vararg_with_format_string : Warning<
   "cannot pass %select{non-POD|non-trivial}0 object of type %1 to variadic "
   "%select{function|block|method|constructor}2; expected type from format "

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 1cd263b8a5b1c..08ca536e34631 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6122,6 +6122,11 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
 BindKind, StartLoc))
 return StmtError();
 
+  // Report affected OpenMP target offloading behavior when in HIP lang-mode.
+  if (getLangOpts().HIP && (isOpenMPTargetExecutionDirective(Kind) ||
+isOpenMPTargetDataManagementDirective(Kind)))
+Diag(StartLoc, diag::warn_hip_omp_target_directives);
+
   llvm::SmallVector ClausesWithImplicit;
   VarsWithInheritedDSAType VarsWithInheritedDSA;
   bool ErrorFound = false;
@@ -13286,6 +13291,10 @@ StmtResult 
Sema::ActOnOpenMPTeamsDirective(ArrayRef Clauses,
   if (!AStmt)
 return StmtError();
 
+  // Report affected OpenMP target offloading behavior when in HIP lang-mode.
+  if (getLangOpts().HIP && (DSAStack->getParentDirective() == OMPD_target))
+Diag(StartLoc, diag::warn_hip_omp_target_directives);
+
   auto *CS = cast(AStmt);
   // 1.2.2 OpenMP Language Terminology
   // Structured block - An executable statement with a single entry at the
@@ -22855,6 +22864,11 @@ bool Sema::ActOnStartOpenMPDeclareTargetContext(
 Diag(DTCI.Loc, diag::err_omp_region_not_file_context);
 return false;
   }
+
+  // Report affected OpenMP target offloading behavior when in HIP lang-mode.
+  if (getLangOpts().HIP)
+Diag(DTCI.Loc, diag::warn_hip_omp_target_directives);
+
   DeclareTargetNesting.push_back(DTCI);
   return true;
 }
@@ -22927,6 +22941,10 @@ void Sema::ActOnOpenMPDeclareTargetName(NamedDecl *ND, 
SourceLocation Loc,
   (ND->isUsed(/*CheckUsedAttr=*/false) || ND->isReferenced()))
 Diag(Loc, diag::warn_omp_declare_target_after_first_use);
 
+  // Report affected OpenMP target offloading behavior when in HIP lang-mode.
+  if (getLangOpts().HIP)
+Diag(Loc, diag::warn_hip_omp_target_directives);
+
   // Explicit declare target lists have precedence.
   const unsigned Level = -1;
 

diff  --git a/clang/test/SemaOpenMP/hip-omp-mix.cpp 
b/clang/test/SemaOpenMP/hip-omp-mix.cpp
new file mode 100644
index 0..a05b

[PATCH] D145591: [clang][HIP][OpenMP] Add warning if mixed HIP / OpenMP offloading

2023-03-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG55916de2d377: [clang][HIP][OpenMP] Add warning if mixed HIP 
/ OpenMP offloading (authored by Michael Halkenhaeuser 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145591

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/SemaOpenMP/hip-omp-mix.cpp

Index: clang/test/SemaOpenMP/hip-omp-mix.cpp
===
--- /dev/null
+++ clang/test/SemaOpenMP/hip-omp-mix.cpp
@@ -0,0 +1,165 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 %s -x c++ -fopenmp -fsyntax-only -verify=host
+// host-no-diagnostics
+
+// RUN: %clang_cc1 %s -x hip -fopenmp -fsyntax-only -verify=device
+// device-error@#01 {{HIP does not support OpenMP target directives}}
+// device-error@#02 {{HIP does not support OpenMP target directives}}
+// device-error@#03 {{HIP does not support OpenMP target directives}}
+// device-error@#04 {{HIP does not support OpenMP target directives}}
+// device-error@#05 {{HIP does not support OpenMP target directives}}
+// device-error@#06 {{HIP does not support OpenMP target directives}}
+// device-error@#07 {{HIP does not support OpenMP target directives}}
+// device-error@#08 {{HIP does not support OpenMP target directives}}
+// device-error@#09 {{HIP does not support OpenMP target directives}}
+// device-error@#10 {{HIP does not support OpenMP target directives}}
+// device-error@#11 {{HIP does not support OpenMP target directives}}
+// device-error@#12 {{HIP does not support OpenMP target directives}}
+// device-error@#13 {{HIP does not support OpenMP target directives}}
+// device-error@#14 {{HIP does not support OpenMP target directives}}
+// device-error@#15 {{HIP does not support OpenMP target directives}}
+// device-error@#16 {{HIP does not support OpenMP target directives}}
+// device-error@#17 {{HIP does not support OpenMP target directives}}
+// device-error@#18 {{HIP does not support OpenMP target directives}}
+// device-error@#19 {{HIP does not support OpenMP target directives}}
+// device-error@#20 {{HIP does not support OpenMP target directives}}
+// device-error@#21 {{HIP does not support OpenMP target directives}}
+// device-error@#22 {{HIP does not support OpenMP target directives}}
+// device-error@#23 {{HIP does not support OpenMP target directives}}
+// device-error@#24 {{HIP does not support OpenMP target directives}}
+
+void test01() {
+#pragma omp target // #01
+  ;
+}
+
+
+void test02() {
+#pragma omp target parallel // #02
+  ;
+}
+
+void test03() {
+#pragma omp target parallel for // #03
+  for (int i = 0; i < 1; ++i);
+}
+
+void test04(int x) {
+#pragma omp target data map(x) // #04
+  ;
+}
+
+void test05(int * x, int n) {
+#pragma omp target enter data map(to:x[:n]) // #05
+}
+
+void test06(int * x, int n) {
+#pragma omp target exit data map(from:x[:n]) // #06
+}
+
+void test07(int * x, int n) {
+#pragma omp target update to(x[:n]) // #07
+}
+
+#pragma omp declare target (test07) // #08
+void test08() {
+
+}
+
+#pragma omp begin declare target // #09
+void test09_1() {
+
+}
+
+void test09_2() {
+
+}
+#pragma omp end declare target
+
+void test10(int n) {
+  #pragma omp target parallel // #10
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test11(int n) {
+  #pragma omp target parallel for // #11
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test12(int n) {
+  #pragma omp target parallel for simd // #12
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test13(int n) {
+  #pragma omp target parallel loop // #13
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test14(int n) {
+  #pragma omp target simd // #14
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test15(int n) {
+  #pragma omp target teams // #15
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test16(int n) {
+  #pragma omp target teams distribute // #16
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test17(int n) {
+  #pragma omp target teams distribute simd // #17
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test18(int n) {
+  #pragma omp target teams loop // #18
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test19(int n) {
+  #pragma omp target teams distribute parallel for // #19
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test20(int n) {
+  #pragma omp target teams distribute parallel for simd // #20
+  for (int i = 0; i < n; ++i)
+;
+}
+
+void test21() {
+#pragma omp target // #21
+  {
+#pragma omp teams // #22
+{}
+  }
+}
+
+void test22() {
+#pragma omp target // #23
+#pragma omp teams // #24
+  {}
+}
+
+void test23() {
+// host code
+#pragma omp teams
+  {}
+}
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/

[clang] 7911647 - Revert "Revert ExtractAPI from https://reviews.llvm.org/D146656"

2023-03-29 Thread Daniel Grumberg via cfe-commits

Author: Daniel Grumberg
Date: 2023-03-29T10:51:13+01:00
New Revision: 79116475124112051625b1a0665e35c861bb13fd

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

LOG: Revert "Revert ExtractAPI from https://reviews.llvm.org/D146656";

This reverts commit 158a431227a876306fe5838936413dd51588d0c6.

Added: 
clang/include/clang/ExtractAPI/TypedefUnderlyingTypeResolver.h

Modified: 
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/lib/ExtractAPI/CMakeLists.txt
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
clang/test/Index/extract-api-cursor.m
clang/tools/c-index-test/c-index-test.c
clang/tools/libclang/CXExtractAPI.cpp

Removed: 
clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h



diff  --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h 
b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index f6546fb4776a6..a31648b80195a 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -14,24 +14,27 @@
 #ifndef LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
 #define LLVM_CLANG_EXTRACTAPI_EXTRACT_API_VISITOR_H
 
+#include "llvm/ADT/FunctionExtras.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/ExtractAPI/API.h"
-#include "llvm/ADT/FunctionExtras.h"
+#include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h"
+#include 
 
 namespace clang {
 namespace extractapi {
+namespace impl {
 
-/// The RecursiveASTVisitor to traverse symbol declarations and collect API
-/// information.
-class ExtractAPIVisitor : public RecursiveASTVisitor {
-public:
-  ExtractAPIVisitor(ASTContext &Context,
-llvm::unique_function 
LocationChecker,
-APISet &API)
-  : Context(Context), API(API),
-LocationChecker(std::move(LocationChecker)) {}
+template 
+class ExtractAPIVisitorBase : public RecursiveASTVisitor {
+protected:
+  ExtractAPIVisitorBase(ASTContext &Context, APISet &API)
+  : Context(Context), API(API) {}
 
+public:
   const APISet &getAPI() const { return API; }
 
   bool VisitVarDecl(const VarDecl *Decl);
@@ -50,7 +53,11 @@ class ExtractAPIVisitor : public 
RecursiveASTVisitor {
 
   bool VisitObjCCategoryDecl(const ObjCCategoryDecl *Decl);
 
-private:
+  bool shouldDeclBeIncluded(const Decl *Decl) const;
+
+  const RawComment *fetchRawCommentForDecl(const Decl *Decl) const;
+
+protected:
   /// Collect API information for the enum constants and associate with the
   /// parent enum.
   void recordEnumConstants(EnumRecord *EnumRecord,
@@ -77,9 +84,582 @@ class ExtractAPIVisitor : public 
RecursiveASTVisitor {
 
   void recordObjCProtocols(ObjCContainerRecord *Container,
ObjCInterfaceDecl::protocol_range Protocols);
+
   ASTContext &Context;
   APISet &API;
-  llvm::unique_function LocationChecker;
+
+  StringRef getTypedefName(const TagDecl *Decl) {
+if (const auto *TypedefDecl = Decl->getTypedefNameForAnonDecl())
+  return TypedefDecl->getName();
+
+return {};
+  }
+
+  bool isInSystemHeader(const Decl *D) {
+return Context.getSourceManager().isInSystemHeader(D->getLocation());
+  }
+
+private:
+  Derived &getDerivedExtractAPIVisitor() {
+return *static_cast(this);
+  }
+};
+
+template 
+bool ExtractAPIVisitorBase::VisitVarDecl(const VarDecl *Decl) {
+  // skip function parameters.
+  if (isa(Decl))
+return true;
+
+  // Skip non-global variables in records (struct/union/class).
+  if (Decl->getDeclContext()->isRecord())
+return true;
+
+  // Skip local variables inside function or method.
+  if (!Decl->isDefinedOutsideFunctionOrMethod())
+return true;
+
+  // If this is a template but not specialization or instantiation, skip.
+  if (Decl->getASTContext().getTemplateOrSpecializationInfo(Decl) &&
+  Decl->getTemplateSpecializationKind() == TSK_Undeclared)
+return true;
+
+  if (!getDerivedExtractAPIVisitor().shouldDeclBeIncluded(Decl))
+return true;
+
+  // Collect symbol information.
+  StringRef Name = Decl->getName();
+  StringRef USR = API.recordUSR(Decl);
+  PresumedLoc Loc =
+  Context.getSourceManager().getPresumedLoc(Decl->getLocation());
+  LinkageInfo Linkage = Decl->getLinkageAndVisibility();
+  DocComment Comment;
+  if (auto *RawComment =
+  getDerivedExtractAPIVisitor().fetchRawCommentForDecl(Decl))
+Comment = RawComment->getFormattedLines(Context.getSourceManager(),
+Context.getDiagnostics());
+
+  // Build declaration fra

[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 509279.

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

https://reviews.llvm.org/D145545

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h

Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -54,6 +54,7 @@
   // Statement visitors.
   bool visitStmt(const Stmt *S);
   bool visitCompoundStmt(const CompoundStmt *S);
+  bool visitLoopBody(const Stmt *S);
   bool visitDeclStmt(const DeclStmt *DS);
   bool visitReturnStmt(const ReturnStmt *RS);
   bool visitIfStmt(const IfStmt *IS);
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -194,6 +194,23 @@
   }
 }
 
+/// Visits the given statment without creating a variable
+/// scope for it in case it is a compound statement.
+template 
+bool ByteCodeStmtGen::visitLoopBody(const Stmt *S) {
+  if (isa(S))
+return true;
+
+  if (const auto *CS = dyn_cast(S)) {
+for (auto *InnerStmt : CS->body())
+  if (!visitStmt(InnerStmt))
+return false;
+return true;
+  }
+
+  return this->visitStmt(S);
+}
+
 template 
 bool ByteCodeStmtGen::visitCompoundStmt(
 const CompoundStmt *CompoundStmt) {
@@ -306,11 +323,15 @@
   if (!this->jumpFalse(EndLabel))
 return false;
 
-  if (!this->visitStmt(Body))
-return false;
+  LocalScope Scope(this);
+  {
+DestructorScope DS(Scope);
+if (!this->visitLoopBody(Body))
+  return false;
+  }
+
   if (!this->jump(CondLabel))
 return false;
-
   this->emitLabel(EndLabel);
 
   return true;
@@ -325,15 +346,21 @@
   LabelTy EndLabel = this->getLabel();
   LabelTy CondLabel = this->getLabel();
   LoopScope LS(this, EndLabel, CondLabel);
+  LocalScope Scope(this);
 
   this->emitLabel(StartLabel);
-  if (!this->visitStmt(Body))
-return false;
-  this->emitLabel(CondLabel);
-  if (!this->visitBool(Cond))
-return false;
+  {
+DestructorScope DS(Scope);
+
+if (!this->visitLoopBody(Body))
+  return false;
+this->emitLabel(CondLabel);
+if (!this->visitBool(Cond))
+  return false;
+  }
   if (!this->jumpTrue(StartLabel))
 return false;
+
   this->emitLabel(EndLabel);
   return true;
 }
@@ -350,6 +377,7 @@
   LabelTy CondLabel = this->getLabel();
   LabelTy IncLabel = this->getLabel();
   LoopScope LS(this, EndLabel, IncLabel);
+  LocalScope Scope(this);
 
   if (Init && !this->visitStmt(Init))
 return false;
@@ -360,11 +388,17 @@
 if (!this->jumpFalse(EndLabel))
   return false;
   }
-  if (Body && !this->visitStmt(Body))
-return false;
-  this->emitLabel(IncLabel);
-  if (Inc && !this->discard(Inc))
-return false;
+
+  {
+DestructorScope DS(Scope);
+
+if (Body && !this->visitLoopBody(Body))
+  return false;
+this->emitLabel(IncLabel);
+if (Inc && !this->discard(Inc))
+  return false;
+  }
+
   if (!this->jump(CondLabel))
 return false;
   this->emitLabel(EndLabel);
@@ -386,38 +420,40 @@
   LabelTy CondLabel = this->getLabel();
   LabelTy IncLabel = this->getLabel();
   LoopScope LS(this, EndLabel, IncLabel);
-  {
-ExprScope ES(this);
 
-// Emit declarations needed in the loop.
-if (Init && !this->visitStmt(Init))
-  return false;
-if (!this->visitStmt(RangeStmt))
-  return false;
-if (!this->visitStmt(BeginStmt))
-  return false;
-if (!this->visitStmt(EndStmt))
-  return false;
+  // Emit declarations needed in the loop.
+  if (Init && !this->visitStmt(Init))
+return false;
+  if (!this->visitStmt(RangeStmt))
+return false;
+  if (!this->visitStmt(BeginStmt))
+return false;
+  if (!this->visitStmt(EndStmt))
+return false;
 
-// Now the condition as well as the loop variable assignment.
-this->emitLabel(CondLabel);
-if (!this->visitBool(Cond))
-  return false;
-if (!this->jumpFalse(EndLabel))
-  return false;
+  // Now the condition as well as the loop variable assignment.
+  this->emitLabel(CondLabel);
+  if (!this->visitBool(Cond))
+return false;
+  if (!this->jumpFalse(EndLabel))
+return false;
 
-if (!this->visitVarDecl(LoopVar))
-  return false;
+  if (!this->visitVarDecl(LoopVar))
+return false;
+
+  // Body.
+  LocalScope Scope(this);
+  {
+DestructorScope DS(Scope);
 
-// Body.
-if (!this->visitStmt(Body))
+if (!this->visitLoopBody(Body))
   return false;
 this->emitLabel(IncLabel);
 if (!this->discard(Inc))
   return false;
-if (!this->jump(CondLabel))
-  return false;
   }
+  if (!this->jump(CondLabel))
+return false;
 
   this->emitLabel(EndLabel);
   return true;
@@ -428,7 +464,7 @@
   if (!BreakLabel)
 return false;
 
-  thi

[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 509281.

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

https://reviews.llvm.org/D145545

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h

Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -54,6 +54,7 @@
   // Statement visitors.
   bool visitStmt(const Stmt *S);
   bool visitCompoundStmt(const CompoundStmt *S);
+  bool visitLoopBody(const Stmt *S);
   bool visitDeclStmt(const DeclStmt *DS);
   bool visitReturnStmt(const ReturnStmt *RS);
   bool visitIfStmt(const IfStmt *IS);
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -194,6 +194,23 @@
   }
 }
 
+/// Visits the given statment without creating a variable
+/// scope for it in case it is a compound statement.
+template 
+bool ByteCodeStmtGen::visitLoopBody(const Stmt *S) {
+  if (isa(S))
+return true;
+
+  if (const auto *CS = dyn_cast(S)) {
+for (auto *InnerStmt : CS->body())
+  if (!visitStmt(InnerStmt))
+return false;
+return true;
+  }
+
+  return this->visitStmt(S);
+}
+
 template 
 bool ByteCodeStmtGen::visitCompoundStmt(
 const CompoundStmt *CompoundStmt) {
@@ -306,11 +323,15 @@
   if (!this->jumpFalse(EndLabel))
 return false;
 
-  if (!this->visitStmt(Body))
-return false;
+  LocalScope Scope(this);
+  {
+DestructorScope DS(Scope);
+if (!this->visitLoopBody(Body))
+  return false;
+  }
+
   if (!this->jump(CondLabel))
 return false;
-
   this->emitLabel(EndLabel);
 
   return true;
@@ -325,15 +346,21 @@
   LabelTy EndLabel = this->getLabel();
   LabelTy CondLabel = this->getLabel();
   LoopScope LS(this, EndLabel, CondLabel);
+  LocalScope Scope(this);
 
   this->emitLabel(StartLabel);
-  if (!this->visitStmt(Body))
-return false;
-  this->emitLabel(CondLabel);
-  if (!this->visitBool(Cond))
-return false;
+  {
+DestructorScope DS(Scope);
+
+if (!this->visitLoopBody(Body))
+  return false;
+this->emitLabel(CondLabel);
+if (!this->visitBool(Cond))
+  return false;
+  }
   if (!this->jumpTrue(StartLabel))
 return false;
+
   this->emitLabel(EndLabel);
   return true;
 }
@@ -350,6 +377,7 @@
   LabelTy CondLabel = this->getLabel();
   LabelTy IncLabel = this->getLabel();
   LoopScope LS(this, EndLabel, IncLabel);
+  LocalScope Scope(this);
 
   if (Init && !this->visitStmt(Init))
 return false;
@@ -360,11 +388,17 @@
 if (!this->jumpFalse(EndLabel))
   return false;
   }
-  if (Body && !this->visitStmt(Body))
-return false;
-  this->emitLabel(IncLabel);
-  if (Inc && !this->discard(Inc))
-return false;
+
+  {
+DestructorScope DS(Scope);
+
+if (Body && !this->visitLoopBody(Body))
+  return false;
+this->emitLabel(IncLabel);
+if (Inc && !this->discard(Inc))
+  return false;
+  }
+
   if (!this->jump(CondLabel))
 return false;
   this->emitLabel(EndLabel);
@@ -386,38 +420,40 @@
   LabelTy CondLabel = this->getLabel();
   LabelTy IncLabel = this->getLabel();
   LoopScope LS(this, EndLabel, IncLabel);
-  {
-ExprScope ES(this);
 
-// Emit declarations needed in the loop.
-if (Init && !this->visitStmt(Init))
-  return false;
-if (!this->visitStmt(RangeStmt))
-  return false;
-if (!this->visitStmt(BeginStmt))
-  return false;
-if (!this->visitStmt(EndStmt))
-  return false;
+  // Emit declarations needed in the loop.
+  if (Init && !this->visitStmt(Init))
+return false;
+  if (!this->visitStmt(RangeStmt))
+return false;
+  if (!this->visitStmt(BeginStmt))
+return false;
+  if (!this->visitStmt(EndStmt))
+return false;
 
-// Now the condition as well as the loop variable assignment.
-this->emitLabel(CondLabel);
-if (!this->visitBool(Cond))
-  return false;
-if (!this->jumpFalse(EndLabel))
-  return false;
+  // Now the condition as well as the loop variable assignment.
+  this->emitLabel(CondLabel);
+  if (!this->visitBool(Cond))
+return false;
+  if (!this->jumpFalse(EndLabel))
+return false;
 
-if (!this->visitVarDecl(LoopVar))
-  return false;
+  if (!this->visitVarDecl(LoopVar))
+return false;
+
+  // Body.
+  LocalScope Scope(this);
+  {
+DestructorScope DS(Scope);
 
-// Body.
-if (!this->visitStmt(Body))
+if (!this->visitLoopBody(Body))
   return false;
 this->emitLabel(IncLabel);
 if (!this->discard(Inc))
   return false;
-if (!this->jump(CondLabel))
-  return false;
   }
+  if (!this->jump(CondLabel))
+return false;
 
   this->emitLabel(EndLabel);
   return true;
@@ -428,7 +464,7 @@
   if (!BreakLabel)
 return false;
 
-  thi

[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.h:338
+this->emitDestructors();
+this->Ctx->emitDestroy(*Idx, SourceInfo{});
+  }

aaron.ballman wrote:
> Should we be setting `Idx = std::nullopt;` after this so that the 
> `LocalScope` destructor does not also emit a destroy for the same `Idx`?
Yeah I think that makes sense, thanks.



Comment at: clang/lib/AST/Interp/ByteCodeStmtGen.cpp:199-200
+bool ByteCodeStmtGen::visitUnscopedCompoundStmt(const Stmt *S) {
+  if (isa(S))
+return true;
+

tbaeder wrote:
> aaron.ballman wrote:
> > Errr, I'm surprised it isn't UB to call this with anything but a 
> > `CompoundStmt` given the function name.
> Yeah, I'm not too happy about that either. I'll see what I can do.
Renamed it to `visitLoopBody` and added a doc comment explaining its purpose.


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

https://reviews.llvm.org/D145545

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


[PATCH] D146412: [NFC] Fix potential use-after-free in DumpModuleInfoAction::ExecuteAction()

2023-03-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 509285.
Fznamznon added a comment.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Use private shared_ptr in `DumpModuleInfoAction`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146412

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,9 @@
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
-   llvm::sys::fs::OF_TextWithCRLF));
-OutputStream = OutFile.get();
+OutputStream.reset(new llvm::raw_fd_ostream(
+OutputFileName.str(), EC, llvm::sys::fs::OF_TextWithCRLF));
   }
   llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs();
 
Index: clang/include/clang/Frontend/FrontendActions.h
===
--- clang/include/clang/Frontend/FrontendActions.h
+++ clang/include/clang/Frontend/FrontendActions.h
@@ -177,9 +177,8 @@
 /// Dump information about the given module file, to be used for
 /// basic debugging and discovery.
 class DumpModuleInfoAction : public ASTFrontendAction {
-public:
   // Allow other tools (ex lldb) to direct output for their use.
-  llvm::raw_ostream *OutputStream = nullptr;
+  std::shared_ptr OutputStream;
 
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
@@ -188,6 +187,9 @@
   void ExecuteAction() override;
 
 public:
+  DumpModuleInfoAction() = default;
+  DumpModuleInfoAction(std::shared_ptr Out)
+  : OutputStream(Out) {}
   bool hasPCHSupport() const override { return false; }
   bool hasASTFileSupport() const override { return true; }
   bool hasIRSupport() const override { return false; }


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,9 @@
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
-   llvm::sys::fs::OF_TextWithCRLF));
-OutputStream = OutFile.get();
+OutputStream.reset(new llvm::raw_fd_ostream(
+OutputFileName.str(), EC, llvm::sys::fs::OF_TextWithCRLF));
   }
   llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs();
 

[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-03-29 Thread suman meena via Phabricator via cfe-commits
simideveloper added a comment.

hey, I was working on the same issue so can we collaborate on this issue?


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

https://reviews.llvm.org/D146358

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


[PATCH] D146101: [clang-format] Add DesignatedInitializerIndentWidth option.

2023-03-29 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1665-1669
+  const auto DesignatedInitializerIndentWidth =
+  Style.DesignatedInitializerIndentWidth < 0
+  ? Style.ContinuationIndentWidth
+  : Style.DesignatedInitializerIndentWidth;
+  NewIndent = CurrentState.LastSpace + DesignatedInitializerIndentWidth;

owenpan wrote:
> jp4a50 wrote:
> > HazardyKnusperkeks wrote:
> > > owenpan wrote:
> > > > jp4a50 wrote:
> > > > > owenpan wrote:
> > > > > > owenpan wrote:
> > > > > > > Using -1 to mean `ContinuationIndentWidth` is unnecessary and 
> > > > > > > somewhat confusing IMO.
> > > > > > Please disregard my comment above.
> > > > > Just to make sure we are on the same page, does this mean that you 
> > > > > are happy with the approach of using `-1` as a default value to 
> > > > > indicate that `ContinuationIndentWidth` should be used?
> > > > > 
> > > > > I did initially consider using `std::optional` and using 
> > > > > empty optional to indicate that `ContinuationIndentWidth` should be 
> > > > > used but I saw that `PPIndentWidth` was using `-1` to default to 
> > > > > using `IndentWidth` so I followed that precedent.
> > > > Yep! I would prefer the `optional`, but as you pointed out, we already 
> > > > got `PPIndentWidth`using `-1`.
> > > From the C++ side I totally agree. One could use `value_or()`, which 
> > > would make the code much more readable.
> > > And just because `PPIndentWidth` is using -1 is no reason to repeat that, 
> > > we could just as easily change `PPIndentWidht` to an optional.
> > > 
> > > But how would it look in yaml?
> > In YAML we wouldn't need to support empty optional being *explicitly* 
> > specified - it would just be the default.
> > 
> > So specifying `DesignatedInitializerIndentWidth: 4` would set the 
> > `std::optional` to `4` but if `DesignatedInitializerIndentWidth` 
> > was omitted from the YAML then the optional would simply not be set during 
> > parsing.
> > 
> > Of course, if we were to change `PPIndentWidth` to work that way too, it 
> > would technically be a breaking change because users may have *explicitly* 
> > specified `-1` in their YAML.
> > And just because `PPIndentWidth` is using -1 is no reason to repeat that, 
> > we could just as easily change `PPIndentWidht` to an optional.
> 
> We would have to deal with backward compatibility to avoid regressions though.
> In YAML we wouldn't need to support empty optional being *explicitly* 
> specified - it would just be the default.
> 
> So specifying `DesignatedInitializerIndentWidth: 4` would set the 
> `std::optional` to `4` but if `DesignatedInitializerIndentWidth` 
> was omitted from the YAML then the optional would simply not be set during 
> parsing.
> 
> Of course, if we were to change `PPIndentWidth` to work that way too, it 
> would technically be a breaking change because users may have *explicitly* 
> specified `-1` in their YAML.

You need an explicit entry, because you need to be able to write the empty 
optional on `--dump-config`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Make sure to include context in the patch you upload: 
https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

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


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16732
+// Ignore BO_LOr operators at the toplevel.
+if (Op->getOpcode() == BO_LOr)
+  return;

tbaeder wrote:
> You can just drop the comment and move this into the `if` statement above, 
> e..g  `if (...; BO && BO->getOpcode() != BO_Lor)`.
I was talking about the one that checks that `E` is a `BinaryOperator`. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

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


[PATCH] D147111: [clang-format] Add MinDigits suboptions to IntegerLiteralSeparator

2023-03-29 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Format/Format.h:4299
InsertNewlineAtEOF == R.InsertNewlineAtEOF &&
IntegerLiteralSeparator.Binary == R.IntegerLiteralSeparator.Binary 
&&
+   IntegerLiteralSeparator.BinaryMinDigits ==

Could we move that to (a not yet existing) 
`IntegerLiteralSeparatorStyle::operator==`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147111

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


[PATCH] D147037: [Clang][ICE] Corrected invalid invalid parameter index on some attributes with invalid indices applied to varargs functions

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:3764-3767
   if (!checkFunctionOrMethodParameterIndex(S, D, AL, 1, IdxExpr, Idx))
 return;
-
+  if (Idx.getASTIndex() >= getFunctionOrMethodNumParams(D))
+return;

erichkeane wrote:
> aaron.ballman wrote:
> > Did you look into fixing this within 
> > `checkFunctionOrMethodParameterIndex()` instead? That way, all callers of 
> > the API get the correct behavior instead of having to find individual 
> > attributes to check the logic (I believe there are other attributes with 
> > the same underlying problem).
> I would also expect any such issue to diagnose.  Also, isn't there an 
> off-by-one error here in the case of variadic args?
`handleFormatAttr()` has:
```
  if (Idx < 1 || Idx > NumArgs) {
S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
<< AL << 2 << IdxExpr->getSourceRange();
return;
  }
```

which is also what I'd expect to see here.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147037

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


[PATCH] D147135: [include-cleaner] Visit the VarDecl in ASTWalker.

2023-03-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: ilya-biryukov.
Herald added a project: clang-tools-extra.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147135

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -300,6 +300,12 @@
"int k = string() ^+ string();");
 }
 
+TEST(WalkAST, VarDecls) {
+  // Definition uses declaration, not the other way around.
+  testWalk("extern int $explicit^x;", "int ^x = 1;");
+  testWalk("int x = 1;", "extern int ^x;");
+}
+
 TEST(WalkAST, Functions) {
   // Definition uses declaration, not the other way around.
   testWalk("void $explicit^foo();", "void ^foo() {}");
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -64,7 +64,7 @@
 };
   }
 
-  llvm::DenseMap>
+  std::multimap>
   offsetToProviders(TestAST &AST, SourceManager &SM,
 llvm::ArrayRef MacroRefs = {}) {
 llvm::SmallVector TopLevelDecls;
@@ -73,13 +73,13 @@
 continue;
   TopLevelDecls.emplace_back(D);
 }
-llvm::DenseMap> OffsetToProviders;
+std::multimap> OffsetToProviders;
 walkUsed(TopLevelDecls, MacroRefs, &PI, SM,
  [&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
auto [FID, Offset] = SM.getDecomposedLoc(Ref.RefLocation);
if (FID != SM.getMainFileID())
  ADD_FAILURE() << "Reference outside of the main file!";
-   OffsetToProviders.try_emplace(Offset, Providers.vec());
+   OffsetToProviders.emplace(Offset, Providers.vec());
  });
 return OffsetToProviders;
   }
@@ -90,9 +90,9 @@
   #include "header.h"
   #include "private.h"
 
-  void $bar^bar($private^Private) {
+  void $bar^bar($private^Private $p^p) {
 $foo^foo();
-std::$vector^vector $vconstructor^v;
+std::$vector^vector $vconstructor^$v^v;
   }
   )cpp");
   Inputs.Code = Code.code();
@@ -116,11 +116,14 @@
   offsetToProviders(AST, SM),
   UnorderedElementsAre(
   Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
+  Pair(Code.point("p"), UnorderedElementsAre(MainFile)),
   Pair(Code.point("private"),
UnorderedElementsAre(PublicFile, PrivateFile)),
   Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),
   Pair(Code.point("vector"), UnorderedElementsAre(VectorSTL)),
-  Pair(Code.point("vconstructor"), UnorderedElementsAre(VectorSTL;
+  Pair(Code.point("vconstructor"), UnorderedElementsAre(VectorSTL)),
+  Pair(Code.point("v"), UnorderedElementsAre(MainFile))
+  ));
 }
 
 TEST_F(WalkUsedTest, MultipleProviders) {
@@ -155,8 +158,8 @@
 TEST_F(WalkUsedTest, MacroRefs) {
   llvm::Annotations Code(R"cpp(
 #include "hdr.h"
-int x = $1^ANSWER;
-int y = $2^ANSWER;
+int $3^x = $1^ANSWER;
+int $4^y = $2^ANSWER;
   )cpp");
   llvm::Annotations Hdr(guard("#define ^ANSWER 42"));
   Inputs.Code = Code.code();
@@ -164,6 +167,8 @@
   TestAST AST(Inputs);
   auto &SM = AST.sourceManager();
   const auto *HdrFile = SM.getFileManager().getFile("hdr.h").get();
+  auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
+
   auto HdrID = SM.translateFile(HdrFile);
 
   IdentifierTable Idents;
@@ -181,7 +186,10 @@
  Answer2, RefType::Explicit}}),
   UnorderedElementsAre(
   Pair(Code.point("1"), UnorderedElementsAre(HdrFile)),
-  Pair(Code.point("2"), UnorderedElementsAre(HdrFile;
+  Pair(Code.point("2"), UnorderedElementsAre(HdrFile)),
+  Pair(Code.point("3"), UnorderedElementsAre(MainFile)),
+  Pair(Code.point("4"), UnorderedElementsAre(MainFile))
+  ));
 }
 
 class AnalyzeTest : public testing::Test {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -156,6 +156,12 @@
   report(FD->getLocation(), FD);
 return true;
   }
+  bool VisitVarDecl(VarDecl *VD) {
+// Mark declaration from definition as it needs type-checking.
+if (VD->isThisDeclarationADefinition())
+ 

[clang] 81358e9 - [clang][MinGW] Add asan DLL lib before other libs and objects

2023-03-29 Thread Alvin Wong via cfe-commits

Author: Alvin Wong
Date: 2023-03-29T19:04:35+08:00
New Revision: 81358e9193a9282372c145b63042b2852d3afa18

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

LOG: [clang][MinGW] Add asan DLL lib before other libs and objects

As stated in https://github.com/llvm/llvm-project/issues/61685, by
passing LLD the import lib of the asan DLL first, the asan DLL will be
listed as the first entry in the Import Directory Table, making it be
loaded first before other user DLLs. This allows asan to be initialized
as early as possible to increase its instrumentation coverage to include
other DLLs not built with asan.

This also avoids some false asan reports on `realloc` for memory
allocated during initialization of user DLLs being loaded earlier than
asan, because after this change they will be loaded later than asan.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/MinGW.cpp
clang/test/Driver/mingw-sanitizers.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 908484fcc0b81..bac486bab8857 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -200,6 +200,16 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
   Args.AddLastArg(CmdArgs, options::OPT_Z_Flag);
 
+  // Add asan_dynamic as the first import lib before other libs. This allows
+  // asan to be initialized as early as possible to increase its 
instrumentation
+  // coverage to include other user DLLs which has not been built with asan.
+  if (Sanitize.needsAsanRt() && !Args.hasArg(options::OPT_nostdlib) &&
+  !Args.hasArg(options::OPT_nodefaultlibs)) {
+// MinGW always links against a shared MSVCRT.
+CmdArgs.push_back(
+TC.getCompilerRTArgString(Args, "asan_dynamic", ToolChain::FT_Shared));
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
 if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_mdll)) {
   CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("dllcrt2.o")));

diff  --git a/clang/test/Driver/mingw-sanitizers.c 
b/clang/test/Driver/mingw-sanitizers.c
index 701e9107f4850..d165648a8fdf6 100644
--- a/clang/test/Driver/mingw-sanitizers.c
+++ b/clang/test/Driver/mingw-sanitizers.c
@@ -1,13 +1,20 @@
-// RUN: %clang -target i686-windows-gnu %s -### -fsanitize=address 2>&1 | 
FileCheck --check-prefix=ASAN-I686 %s
-// ASAN-I686: "{{.*}}libclang_rt.asan_dynamic-i386.dll.a"
-// ASAN-I686: "{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a"
-// ASAN-I686: "--require-defined" "___asan_seh_interceptor"
-// ASAN-I686: "--whole-archive" 
"{{.*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a" "--no-whole-archive"
-
-// RUN: %clang -target x86_64-windows-gnu %s -### -fsanitize=address 2>&1 | 
FileCheck --check-prefix=ASAN-X86_64 %s
-// ASAN-X86_64: "{{.*}}libclang_rt.asan_dynamic-x86_64.dll.a"
+// RUN: touch %t.a
+// RUN: %clang -target i686-windows-gnu %s -### -fsanitize=address -lcomponent 
%/t.a 2>&1 | FileCheck --check-prefixes=ASAN-ALL,ASAN-I686 -DINPUT=%/t.a %s
+// RUN: %clang -target x86_64-windows-gnu %s -### -fsanitize=address 
-lcomponent %/t.a 2>&1 | FileCheck --check-prefixes=ASAN-ALL,ASAN-X86_64 
-DINPUT=%/t.a %s
+//
+// ASAN-ALL-NOT:"-l{{[^"]+"]}}"
+// ASAN-ALL-NOT:"[[INPUT]]"
+// ASAN-I686:   "{{[^"]*}}libclang_rt.asan_dynamic-i386.dll.a"
+// ASAN-X86_64: "{{[^"]*}}libclang_rt.asan_dynamic-x86_64.dll.a"
+// ASAN-ALL:"-lcomponent"
+// ASAN-ALL:"[[INPUT]]"
+// ASAN-I686:   "{{[^"]*}}libclang_rt.asan_dynamic-i386.dll.a"
+// ASAN-I686:   "{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a"
+// ASAN-I686:   "--require-defined" "___asan_seh_interceptor"
+// ASAN-I686:   "--whole-archive" 
"{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a" "--no-whole-archive"
+// ASAN-X86_64: "{{[^"]*}}libclang_rt.asan_dynamic-x86_64.dll.a"
 // ASAN-X86_64: "{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-x86_64.a"
 // ASAN-X86_64: "--require-defined" "__asan_seh_interceptor"
-// ASAN-X86_64: "--whole-archive" 
"{{.*}}libclang_rt.asan_dynamic_runtime_thunk-x86_64.a" "--no-whole-archive"
+// ASAN-X86_64: "--whole-archive" 
"{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-x86_64.a" "--no-whole-archive"
 
 // RUN: %clang -target x86_64-windows-gnu %s -### -fsanitize=vptr



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


[PATCH] D147138: [clang][ExtractAPI] Add queried symbol to parent contexts in libclang

2023-03-29 Thread Daniel Grumberg via Phabricator via cfe-commits
dang created this revision.
dang added reviewers: zixuw, ributzka.
Herald added a subscriber: arphaman.
Herald added a project: All.
dang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Ensure that the current symbol is added to the parent contexts in the
output of libclang function for generating symbol graphs for single symbols.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147138

Files:
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/Index/extract-api-cursor.m
  clang/test/Index/extract-api-usr.m

Index: clang/test/Index/extract-api-usr.m
===
--- clang/test/Index/extract-api-usr.m
+++ clang/test/Index/extract-api-usr.m
@@ -28,7 +28,7 @@
 
 // Checking for Foo
 // RUN: c-index-test "-single-symbol-sgf-for=c:@S@Foo" %s | FileCheck -check-prefix=CHECK-FOO %s
-// CHECK-FOO: "parentContexts":[]
+// CHECK-FOO: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"}]
 // CHECK-FOO-SAME: "relatedSymbols":[]
 // CHECK-FOO-SAME: "relationships":[]
 // CHECK-FOO-SAME: "text":"Foo docs"
@@ -38,7 +38,7 @@
 
 // Checking for bar
 // RUN: c-index-test "-single-symbol-sgf-for=c:@S@Foo@FI@bar" %s | FileCheck -check-prefix=CHECK-BAR %s
-// CHECK-BAR: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"}]
+// CHECK-BAR: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"},{"kind":"objective-c.property","name":"bar","usr":"c:@S@Foo@FI@bar"}]
 // CHECK-BAR-SAME: "relatedSymbols":[]
 // CHECK-BAR-SAME: "relationships":[{"kind":"memberOf","source":"c:@S@Foo@FI@bar","target":"c:@S@Foo"
 // CHECK-BAR-SAME: "text":"Bar docs"
@@ -47,7 +47,7 @@
 
 // Checking for Base
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base" %s | FileCheck -check-prefix=CHECK-BASE %s
-// CHECK-BASE: "parentContexts":[]
+// CHECK-BASE: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
 // CHECK-BASE-SAME: "relatedSymbols":[]
 // CHECK-BASE-SAME: "relationships":[]
 // CHECK-BASE-SAME: "text":"Base docs"
@@ -56,7 +56,7 @@
 
 // Checking for baseProperty
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base(py)baseProperty" %s | FileCheck -check-prefix=CHECK-BASEPROP %s
-// CHECK-BASEPROP: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASEPROP: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.property","name":"baseProperty","usr":"c:objc(cs)Base(py)baseProperty"}]
 // CHECK-BASEPROP-SAME:"relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
 // CHECK-BASEPROP-SAME: "isSystem":false
 // CHECK-BASEPROP-SAME: "usr":"c:@S@Foo"}]
@@ -67,7 +67,7 @@
 
 // Checking for baseMethodWithArg
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base(im)baseMethodWithArg:" %s | FileCheck -check-prefix=CHECK-BASEMETHOD %s
-// CHECK-BASEMETHOD: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASEMETHOD: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.method","name":"baseMethodWithArg:","usr":"c:objc(cs)Base(im)baseMethodWithArg:"}]
 // CHECK-BASEMETHOD-SAME:"relatedSymbols":[]
 // CHECK-BASEMETHOD-SAME: "relationships":[{"kind":"memberOf","source":"c:objc(cs)Base(im)baseMethodWithArg:","target":"c:objc(cs)Base"
 // CHECK-BASEMETHOD-SAME: "text":"Base method docs"
@@ -76,7 +76,7 @@
 
 // Checking for Protocol
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(pl)Protocol" %s | FileCheck -check-prefix=CHECK-PROT %s
-// CHECK-PROT: "parentContexts":[]
+// CHECK-PROT: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"}]
 // CHECK-PROT-SAME: "relatedSymbols":[]
 // CHECK-PROT-SAME: "relationships":[]
 // CHECK-PROT-SAME: "text":"Protocol docs"
@@ -85,7 +85,7 @@
 
 // Checking for protocolProperty
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(pl)Protocol(py)protocolProperty" %s | FileCheck -check-prefix=CHECK-PROTPROP %s
-// CHECK-PROTPROP: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"}]
+// CHECK-PROTPROP: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"},{"kind":"objective-c.property","name":"protocolProperty","usr":"c:objc(pl)Protocol(py)protocolProperty"}]
 // CHECK-PROTPROP-SAME:"relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
 // CHECK-PROTPROP-SAME: "isSystem":false
 // CHECK-PROTPROP-SAME: "usr":"c:@S@Foo"}]
@@ -96,7 +96,7 @@
 
 // Checking for Derived
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Derived" %s | FileCheck -check-prefix=CHECK-DERIVED %s
-// CHECK-DERIVED: "parentContexts":[]
+// CHECK-DERIVED: "parentContexts":[{"kind":"objective-c.class","name":"Derived

[PATCH] D146908: [clang][MinGW] Add asan DLL lib before other libs and objects

2023-03-29 Thread Alvin Wong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG81358e9193a9: [clang][MinGW] Add asan DLL lib before other 
libs and objects (authored by alvinhochun).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146908

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/mingw-sanitizers.c


Index: clang/test/Driver/mingw-sanitizers.c
===
--- clang/test/Driver/mingw-sanitizers.c
+++ clang/test/Driver/mingw-sanitizers.c
@@ -1,13 +1,20 @@
-// RUN: %clang -target i686-windows-gnu %s -### -fsanitize=address 2>&1 | 
FileCheck --check-prefix=ASAN-I686 %s
-// ASAN-I686: "{{.*}}libclang_rt.asan_dynamic-i386.dll.a"
-// ASAN-I686: "{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a"
-// ASAN-I686: "--require-defined" "___asan_seh_interceptor"
-// ASAN-I686: "--whole-archive" 
"{{.*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a" "--no-whole-archive"
-
-// RUN: %clang -target x86_64-windows-gnu %s -### -fsanitize=address 2>&1 | 
FileCheck --check-prefix=ASAN-X86_64 %s
-// ASAN-X86_64: "{{.*}}libclang_rt.asan_dynamic-x86_64.dll.a"
+// RUN: touch %t.a
+// RUN: %clang -target i686-windows-gnu %s -### -fsanitize=address -lcomponent 
%/t.a 2>&1 | FileCheck --check-prefixes=ASAN-ALL,ASAN-I686 -DINPUT=%/t.a %s
+// RUN: %clang -target x86_64-windows-gnu %s -### -fsanitize=address 
-lcomponent %/t.a 2>&1 | FileCheck --check-prefixes=ASAN-ALL,ASAN-X86_64 
-DINPUT=%/t.a %s
+//
+// ASAN-ALL-NOT:"-l{{[^"]+"]}}"
+// ASAN-ALL-NOT:"[[INPUT]]"
+// ASAN-I686:   "{{[^"]*}}libclang_rt.asan_dynamic-i386.dll.a"
+// ASAN-X86_64: "{{[^"]*}}libclang_rt.asan_dynamic-x86_64.dll.a"
+// ASAN-ALL:"-lcomponent"
+// ASAN-ALL:"[[INPUT]]"
+// ASAN-I686:   "{{[^"]*}}libclang_rt.asan_dynamic-i386.dll.a"
+// ASAN-I686:   "{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a"
+// ASAN-I686:   "--require-defined" "___asan_seh_interceptor"
+// ASAN-I686:   "--whole-archive" 
"{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a" "--no-whole-archive"
+// ASAN-X86_64: "{{[^"]*}}libclang_rt.asan_dynamic-x86_64.dll.a"
 // ASAN-X86_64: "{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-x86_64.a"
 // ASAN-X86_64: "--require-defined" "__asan_seh_interceptor"
-// ASAN-X86_64: "--whole-archive" 
"{{.*}}libclang_rt.asan_dynamic_runtime_thunk-x86_64.a" "--no-whole-archive"
+// ASAN-X86_64: "--whole-archive" 
"{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-x86_64.a" "--no-whole-archive"
 
 // RUN: %clang -target x86_64-windows-gnu %s -### -fsanitize=vptr
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -200,6 +200,16 @@
   Args.AddAllArgs(CmdArgs, options::OPT_u_Group);
   Args.AddLastArg(CmdArgs, options::OPT_Z_Flag);
 
+  // Add asan_dynamic as the first import lib before other libs. This allows
+  // asan to be initialized as early as possible to increase its 
instrumentation
+  // coverage to include other user DLLs which has not been built with asan.
+  if (Sanitize.needsAsanRt() && !Args.hasArg(options::OPT_nostdlib) &&
+  !Args.hasArg(options::OPT_nodefaultlibs)) {
+// MinGW always links against a shared MSVCRT.
+CmdArgs.push_back(
+TC.getCompilerRTArgString(Args, "asan_dynamic", ToolChain::FT_Shared));
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
 if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_mdll)) {
   CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("dllcrt2.o")));


Index: clang/test/Driver/mingw-sanitizers.c
===
--- clang/test/Driver/mingw-sanitizers.c
+++ clang/test/Driver/mingw-sanitizers.c
@@ -1,13 +1,20 @@
-// RUN: %clang -target i686-windows-gnu %s -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-I686 %s
-// ASAN-I686: "{{.*}}libclang_rt.asan_dynamic-i386.dll.a"
-// ASAN-I686: "{{[^"]*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a"
-// ASAN-I686: "--require-defined" "___asan_seh_interceptor"
-// ASAN-I686: "--whole-archive" "{{.*}}libclang_rt.asan_dynamic_runtime_thunk-i386.a" "--no-whole-archive"
-
-// RUN: %clang -target x86_64-windows-gnu %s -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-X86_64 %s
-// ASAN-X86_64: "{{.*}}libclang_rt.asan_dynamic-x86_64.dll.a"
+// RUN: touch %t.a
+// RUN: %clang -target i686-windows-gnu %s -### -fsanitize=address -lcomponent %/t.a 2>&1 | FileCheck --check-prefixes=ASAN-ALL,ASAN-I686 -DINPUT=%/t.a %s
+// RUN: %clang -target x86_64-windows-gnu %s -### -fsanitize=address -lcomponent %/t.a 2>&1 | FileCheck --check-prefixes=ASAN-ALL,ASAN-X86_64 -DINPUT=%/t.a %s
+//
+// ASAN-ALL-NOT:"-l{{[^"]+"]}}"
+// ASAN-ALL-NOT:"[[INPUT]]"
+// ASAN-I686:   "{{[^"]*}}libclang_rt.asan_dynamic-i386.dll.a"
+/

[PATCH] D147139: [clangd] Map references from include'd files to directives

2023-03-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147139

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


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -384,6 +384,35 @@
   EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, MacroExpandedThroughIncludes) {
+  Annotations MainFile(R"cpp(
+  #include "all.h"
+  #define FOO(X) const Foo *X
+  void foo() {
+  #include [["expander.inc"]]
+  }
+)cpp");
+
+  TestTU TU;
+  TU.AdditionalFiles["expander.inc"] = guard("FOO(f1);FOO(f2);");
+  TU.AdditionalFiles["foo.h"] = guard("struct Foo {};");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+
+  TU.Code = MainFile.code();
+  ParsedAST AST = TU.build();
+
+  auto Findings = computeIncludeCleanerFindings(AST).MissingIncludes;
+  // FIXME: Deduplicate references resulting from expansion of the same macro 
in
+  // multiple places.
+  EXPECT_THAT(Findings, testing::SizeIs(2));
+  auto RefRange = Findings.front().SymRefRange;
+  auto &SM = AST.getSourceManager();
+  EXPECT_EQ(RefRange.file(), SM.getMainFileID());
+  // FIXME: Point at the spelling location, rather than the include.
+  EXPECT_EQ(halfOpenToRange(SM, RefRange.toCharRange(SM)), MainFile.range());
+  EXPECT_EQ(RefRange, Findings[1].SymRefRange);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -51,9 +51,11 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -266,7 +268,6 @@
 }
 } // namespace
 
-
 std::vector
 collectMacroReferences(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
@@ -398,6 +399,10 @@
 // FIXME: Use presumed locations to map such usages back to patched
 // locations safely.
 auto Loc = SM.getFileLoc(Ref.RefLocation);
+// File locations can be outside of the main file if macro is expanded
+// through an #include.
+while (SM.getFileID(Loc) != SM.getMainFileID())
+  Loc = SM.getIncludeLoc(SM.getFileID(Loc));
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
 MissingIncludeDiagInfo DiagInfo{Ref.Target, Token->range(SM),
 Providers};


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -384,6 +384,35 @@
   EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, MacroExpandedThroughIncludes) {
+  Annotations MainFile(R"cpp(
+  #include "all.h"
+  #define FOO(X) const Foo *X
+  void foo() {
+  #include [["expander.inc"]]
+  }
+)cpp");
+
+  TestTU TU;
+  TU.AdditionalFiles["expander.inc"] = guard("FOO(f1);FOO(f2);");
+  TU.AdditionalFiles["foo.h"] = guard("struct Foo {};");
+  TU.AdditionalFiles["all.h"] = guard("#include \"foo.h\"");
+
+  TU.Code = MainFile.code();
+  ParsedAST AST = TU.build();
+
+  auto Findings = computeIncludeCleanerFindings(AST).MissingIncludes;
+  // FIXME: Deduplicate references resulting from expansion of the same macro in
+  // multiple places.
+  EXPECT_THAT(Findings, testing::SizeIs(2));
+  auto RefRange = Findings.front().SymRefRange;
+  auto &SM = AST.getSourceManager();
+  EXPECT_EQ(RefRange.file(), SM.getMainFileID());
+  // FIXME: Point at the spelling location, rather than the include.
+  EXPECT_EQ(halfOpenToRange(SM, RefRange.toCharRange(SM)), MainFile.range());
+  EXPECT_EQ(RefRange, Findings[1].SymRefRange);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -51,9 +51,11 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -266,7 +268,6 @@
 }
 } // namespace
 
-
 std::vector
 collectMacroReferenc

[PATCH] D145852: [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-03-29 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 509298.
royjacobson added a comment.

Add some ((packed)) tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145852

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@
 static_assert(!has_unique_object_representations::value, 
"Alignment causes padding");
 static_assert(!has_unique_object_representations::value, 
"Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+struct __attribute__((packed)) PackedNoPadding2 {
+  int j;
+  short i;
+};
+static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+
 static_assert(!has_unique_object_representations::value, "Functions 
are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
@@ -2878,9 +2889,35 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) UnnamedBitfieldPacked {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
+static_assert(has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong 
size");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2810,6 +2810,11 @@
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+// If we have explicit padding bits, they don't contribute bits
+// to the actual object representation, so return 0.
+if (Field->isUnnamedBitfield())
+  return 0;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -202,6 +202,9 @@
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@
 static_assert(!has_unique_object_representations::value, "Alignment causes padding");
 static_assert(!has_unique_object_representations::value, "Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+struct __attribute__((packed)) PackedNoPadding2 {
+  int j;
+  short i;
+};
+static_assert(has_unique_object_representations::value, "Packed structs have no padding");
+static_assert(has_unique_object_representations::value, "Packed structs have no padding");
+
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
 static_assert(!has_unique_object_representations::value, "Functions are not unique");
@@ -2878,9 +2889,35 @@
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) UnnamedBitfieldPacked {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert

[clang] d3291c6 - [RISCV][MC] Add support for the experimental zicond extension

2023-03-29 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2023-03-29T12:17:50+01:00
New Revision: d3291c692c0a83b8b60e13ad1326e2b7d61e5f34

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

LOG: [RISCV][MC] Add support for the experimental zicond extension

This patch adds the basic MC layer support for Zicond, based on
[1.0-rc1](https://github.com/riscv/riscv-zicond/releases/tag/v1.0-rc1).
As with other extensions, if there are additional changes between
release candidates without incrementing the version number we won't be
able to reflect that in the version number. I believe we've previously
decided this is not a problem for extensions still considered
experimental (i.e. not yet ratified).

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

Added: 
llvm/lib/Target/RISCV/RISCVInstrInfoZicond.td
llvm/test/MC/RISCV/rv32zicond-invalid.s
llvm/test/MC/RISCV/rv32zicond-valid.s

Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/docs/ReleaseNotes.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index e979f967c0fa2..617be1d41c999 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -58,6 +58,7 @@
 // CHECK-NOT: __riscv_zvks {{.*$}}
 // CHECK-NOT: __riscv_zvksed {{.*$}}
 // CHECK-NOT: __riscv_zvksh {{.*$}}
+// CHECK-NOT: __riscv_zicond {{.*$}}
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
 // RUN: -o - | FileCheck %s
@@ -595,3 +596,11 @@
 // RUN: -march=rv64i_zve32x_zvksh0p3 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVKSH-EXT %s
 // CHECK-ZVKSH-EXT: __riscv_zvksh  3000{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zicond1p0 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zicond1p0 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
+// CHECK-ZICOND-EXT: __riscv_zicond  100{{$}}

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index b7de3f9cf880d..44a074f405652 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -155,6 +155,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zfa``
   LLVM implements a subset of `0.1 draft specification 
`_
 (see Chapter 25). Load-immediate instructions (fli.s/fli.d/fli.h) haven't been 
implemented yet.
 
+``experimental-zicond``
+  LLVM implements the `1.0-rc1 draft specification 
_.
+
 ``experimental-zihintntl``
   LLVM implements the `0.2 draft specification 
`_.
 

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 3791d5116124e..80ba9b5f97823 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -151,6 +151,8 @@ Changes to the RISC-V Backend
 * Adds support for the vendor-defined XTHeadSync (multi-core synchronization 
instructions) extension.
 * Added support for the vendor-defined XTHeadFMemIdx (indexed memory 
operations for floating point) extension.
 * Assembler support for RV64E was added.
+* Assembler support was added for the experimental Zicond (integer conditional
+  operations) extension.
 
 Changes to the WebAssembly Backend
 --

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 0d49c3a39cd0f..f4e0c04152b5a 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -135,6 +135,7 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zcd", RISCVExtensionVersion{1, 0}},
 {"zcf", RISCVExtensionVersion{1, 0}},
 {"zfa", RISCVExtensionVersion{0, 1}},
+{"zicond", RISCVExtensionVersion{1, 0}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
 {"ztso", RISCVExtensionVersion{0, 1}},
 

diff  --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 9a87fcefe803c..de36751662a68 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -536,6 +536,13 @@ def HasStdExtZvksh : 
Predicate<"Subtarget->hasStdExtZvksh()">,
  

[PATCH] D146946: [RISCV][MC] Add support for experimental zicond extension

2023-03-29 Thread Alex Bradbury 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 rGd3291c692c0a: [RISCV][MC] Add support for the experimental 
zicond extension (authored by asb).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146946

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZicond.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zicond-invalid.s
  llvm/test/MC/RISCV/rv32zicond-valid.s

Index: llvm/test/MC/RISCV/rv32zicond-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zicond-valid.s
@@ -0,0 +1,18 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zicond -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zicond -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zicond < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zicond -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zicond < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zicond -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: czero.eqz t0, a3, ra
+# CHECK-ASM: encoding: [0xb3,0xd2,0x16,0x0e]
+czero.eqz t0, a3, ra
+
+# CHECK-ASM-AND-OBJ: czero.nez a1, gp, t6
+# CHECK-ASM: encoding: [0xb3,0xf5,0xf1,0x0f]
+czero.nez a1, gp, t6
Index: llvm/test/MC/RISCV/rv32zicond-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zicond-invalid.s
@@ -0,0 +1,18 @@
+# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zicond < %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-zicond < %s 2>&1 | FileCheck %s
+
+# Use of operand modifier on register name
+czero.eqz t1, %lo(t2), t3 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction
+
+# Invalid register name
+czero.nez a4, a3, foo # CHECK: :[[@LINE]]:19: error: invalid operand for instruction
+
+# Invalid operand type
+czero.eqz t1, 2, t3 # CHECK: :[[@LINE]]:15: error: invalid operand for instruction
+
+# Too many operands
+czero.eqz t1, t2, t3, t4 # CHECK: :[[@LINE]]:23: error: invalid operand for instruction
+czero.nez t1, t2, t3, 4 # CHECK: :[[@LINE]]:23: error: invalid operand for instruction
+
+# Too few operands
+czero.eqz t1, t2 # CHECK: :[[@LINE]]:1: error: too few operands for instruction
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -236,3 +236,6 @@
 
 .attribute arch, "rv32izfa0p1"
 # CHECK: attribute  5, "rv32i2p0_f2p0_zfa0p1"
+
+.attribute arch, "rv32izicond1p0"
+# CHECK: attribute  5, "rv32i2p0_zicond1p0"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -64,6 +64,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zve32x -mattr=+experimental-zvks %s -o - | FileCheck --check-prefix=RV32ZVKS %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zve32x -mattr=+experimental-zvksed %s -o - | FileCheck --check-prefix=RV32ZVKSED %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zve32x -mattr=+experimental-zvksh %s -o - | FileCheck --check-prefix=RV32ZVKSH %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV32ZICOND %s
 
 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -135,6 +136,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zve32x -mattr=+experimental-zvks %s -o - | FileCheck --check-prefix=RV64ZVKS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zve32x -mattr=+experimental-zvksed %s -o - | FileCheck --check-prefix=RV64ZVKSED %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zve32x -mattr=+experimental-zvksh %s -o - | FileCheck --check-prefix=RV64ZVKSH %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicond %s -o - | FileCheck --check-prefix=RV64ZICOND %s
 
 ; CHECK: .attribute 4, 16
 
@@ -201,6 +203,7 @@
 ; RV32ZVKS: .attribute 5, "rv32i2p0_zve32x1p0_zvkb0p3_zvks0p3_zvksed0p3_zvksh0p3_zvl32b1p0"
 ; RV32ZVKSED: .attribute 5, "rv32i2p0_zve32x1p0_zvksed0p3_zvl32b1p0"
 ; RV32ZVKSH: .attribute 5, "rv32i2p0_zve32x1p0_zvksh0p3_zvl32b1p0"
+; RV32ZICOND: .attribute 5, "rv32i2p0_zicon

[PATCH] D146101: [clang-format] Add DesignatedInitializerIndentWidth option.

2023-03-29 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1665-1669
+  const auto DesignatedInitializerIndentWidth =
+  Style.DesignatedInitializerIndentWidth < 0
+  ? Style.ContinuationIndentWidth
+  : Style.DesignatedInitializerIndentWidth;
+  NewIndent = CurrentState.LastSpace + DesignatedInitializerIndentWidth;

HazardyKnusperkeks wrote:
> owenpan wrote:
> > jp4a50 wrote:
> > > HazardyKnusperkeks wrote:
> > > > owenpan wrote:
> > > > > jp4a50 wrote:
> > > > > > owenpan wrote:
> > > > > > > owenpan wrote:
> > > > > > > > Using -1 to mean `ContinuationIndentWidth` is unnecessary and 
> > > > > > > > somewhat confusing IMO.
> > > > > > > Please disregard my comment above.
> > > > > > Just to make sure we are on the same page, does this mean that you 
> > > > > > are happy with the approach of using `-1` as a default value to 
> > > > > > indicate that `ContinuationIndentWidth` should be used?
> > > > > > 
> > > > > > I did initially consider using `std::optional` and using 
> > > > > > empty optional to indicate that `ContinuationIndentWidth` should be 
> > > > > > used but I saw that `PPIndentWidth` was using `-1` to default to 
> > > > > > using `IndentWidth` so I followed that precedent.
> > > > > Yep! I would prefer the `optional`, but as you pointed out, we 
> > > > > already got `PPIndentWidth`using `-1`.
> > > > From the C++ side I totally agree. One could use `value_or()`, which 
> > > > would make the code much more readable.
> > > > And just because `PPIndentWidth` is using -1 is no reason to repeat 
> > > > that, we could just as easily change `PPIndentWidht` to an optional.
> > > > 
> > > > But how would it look in yaml?
> > > In YAML we wouldn't need to support empty optional being *explicitly* 
> > > specified - it would just be the default.
> > > 
> > > So specifying `DesignatedInitializerIndentWidth: 4` would set the 
> > > `std::optional` to `4` but if 
> > > `DesignatedInitializerIndentWidth` was omitted from the YAML then the 
> > > optional would simply not be set during parsing.
> > > 
> > > Of course, if we were to change `PPIndentWidth` to work that way too, it 
> > > would technically be a breaking change because users may have 
> > > *explicitly* specified `-1` in their YAML.
> > > And just because `PPIndentWidth` is using -1 is no reason to repeat that, 
> > > we could just as easily change `PPIndentWidht` to an optional.
> > 
> > We would have to deal with backward compatibility to avoid regressions 
> > though.
> > In YAML we wouldn't need to support empty optional being *explicitly* 
> > specified - it would just be the default.
> > 
> > So specifying `DesignatedInitializerIndentWidth: 4` would set the 
> > `std::optional` to `4` but if `DesignatedInitializerIndentWidth` 
> > was omitted from the YAML then the optional would simply not be set during 
> > parsing.
> > 
> > Of course, if we were to change `PPIndentWidth` to work that way too, it 
> > would technically be a breaking change because users may have *explicitly* 
> > specified `-1` in their YAML.
> 
> You need an explicit entry, because you need to be able to write the empty 
> optional on `--dump-config`.
> > In YAML we wouldn't need to support empty optional being *explicitly* 
> > specified - it would just be the default.
> > 
> > So specifying `DesignatedInitializerIndentWidth: 4` would set the 
> > `std::optional` to `4` but if `DesignatedInitializerIndentWidth` 
> > was omitted from the YAML then the optional would simply not be set during 
> > parsing.
> > 
> > Of course, if we were to change `PPIndentWidth` to work that way too, it 
> > would technically be a breaking change because users may have *explicitly* 
> > specified `-1` in their YAML.
> 
> You need an explicit entry, because you need to be able to write the empty 
> optional on `--dump-config`.

It looks like the YAML IO logic just does the right thing (TM) with 
`std::optional`s. When calling `IO.mapOptional()` on output, it simply doesn't 
write the key out if the value is an empty optional. So I don't think this is 
an issue.

As @owenpan says, though, there is still the issue of backward compatibility 
with `PPIndentWidth`.

I don't feel strongly about which way to go so I'll leave it to you two to 
decide!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D147121: [hwasan] remove requirment for PIE

2023-03-29 Thread Mingjie Xu via Phabricator via cfe-commits
Enna1 created this revision.
Herald added subscribers: yaneury, supersymetrie, Chia-hungDuan, cryptoad.
Herald added a project: All.
Enna1 updated this revision to Diff 509252.
Enna1 added a comment.
Enna1 edited the summary of this revision.
Enna1 added reviewers: eugenis, alekseyshl, pcc, vitalybuka.
Enna1 added a subscriber: MTC.
Enna1 published this revision for review.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

update


Enna1 added a comment.

Under my test on aarch64 linux, all hwasan tests passed without PIE.
IIUC, only global variables in hwasan are affected by PIE.
Without PIE, a special instruction sequence assembly will be to emitted to add 
the tag to the global variable address, see https://reviews.llvm.org/D120305 .
I'm not sure if hwasan linux x86-64 is different from linux aarch64 and have a 
special requirment for PIE.

Also note that since https://reviews.llvm.org/D120305, 
CLANG_DEFAULT_PIE_ON_LINUX was default on.


The requirement for PIE of hwasan was introduced in 
https://reviews.llvm.org/D44745,  this patch removes requirement for PIE.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147121

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/sanitizer-ld.c


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -961,7 +961,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-HWASAN-X86-64-LINUX %s
 //
 // CHECK-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.a"
 // CHECK-HWASAN-X86-64-LINUX-NOT: "--export-dynamic"
@@ -979,7 +978,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-X86-64-LINUX %s
 //
 // CHECK-SHARED-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SHARED-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
 // CHECK-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
@@ -996,7 +994,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-DSO-SHARED-HWASAN-X86-64-LINUX %s
 //
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: 
"{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-DSO_SHARED-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX: libclang_rt.hwasan-x86_64.so"
 // CHECK-DSO-SHARED-HWASAN-X86-64-LINUX-NOT: "-lpthread"
@@ -1013,7 +1010,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-HWASAN-AARCH64-LINUX %s
 //
 // CHECK-HWASAN-AARCH64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-HWASAN-AARCH64-LINUX: "-pie"
 // CHECK-HWASAN-AARCH64-LINUX-NOT: "-lc"
 // CHECK-HWASAN-AARCH64-LINUX: libclang_rt.hwasan-aarch64.a"
 // CHECK-HWASAN-AARCH64-LINUX-NOT: "--export-dynamic"
@@ -1032,7 +1028,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHARED-HWASAN-AARCH64-LINUX %s
 //
 // CHECK-SHARED-HWASAN-AARCH64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-SHARED-HWASAN-AARCH64-LINUX: "-pie"
 // CHECK-SHARED-HWASAN-AARCH64-LINUX-NOT: "-lc"
 // CHECK-SHARED-HWASAN-AARCH64-LINUX: libclang_rt.hwasan-aarch64.so"
 // CHECK-SHARED-HWASAN-AARCH64-LINUX-NOT: "-lpthread"
@@ -1049,7 +1044,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX %s
 //
 // CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX: 
"{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-DSO_SHARED-HWASAN-AARCH64-LINUX: "-pie"
 // CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX-NOT: "-lc"
 // CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX: libclang_rt.hwasan-aarch64.so"
 // CHECK-DSO-SHARED-HWASAN-AARCH64-LINUX-NOT: "-lpthread"
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -38,8 +38,7 @@
 static const SanitizerMask NotAllowedWithMinimalRuntime =
 SanitizerKind::Function | SanitizerKind::Vptr;
 static const SanitizerMask RequiresPIE =
-SanitizerKind::DataFlow | SanitizerKind::HWAddress | SanitizerKind::Scudo |
-SanitizerKind::KCFI;
+SanitizerKind::DataFlow | SanitizerKind::Scudo | SanitizerKind::KCFI;
 static const SanitizerMask NeedsUnwindTables =
 SanitizerKind::Address | SanitizerKind::HWAddress | SanitizerKind::Thread |
 SanitizerKind::Memory | SanitizerKind::DataFlow;


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -961,7 +961,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-HWASAN-X86-64-LINUX %s
 //
 // CHECK-HWASAN-X86-64-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-HWASAN-X86-64-LINUX: "-pie"
 // CHECK-HWASAN-X86-64-LINUX-NOT: "-lc"
 // CHECK-HWASAN-X86-64-LINUX: libclang_rt.hwas

[clang] 6ce272b - [Doc][Clang] Update Clang 16 from 'unreleased' to 'full'

2023-03-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-03-29T14:20:27+03:00
New Revision: 6ce272b3f4ceb54e31cac660371a1a9af94b70d7

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

LOG: [Doc][Clang] Update Clang 16 from 'unreleased' to 'full'

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 79cfca34fb4f3..8b1e8712e3944 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -912,7 +912,7 @@ C++20 implementation status
 

 https://wg21.link/p0857r0";>P0857R0
-Clang 16
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
@@ -923,7 +923,7 @@ C++20 implementation status
   

 https://wg21.link/p0848r3";>P0848R3
-
+
   
 Clang 16 (Partial)
 Because of other concepts implementation deficits, the 
__cpp_concepts macro is not yet set to 202002L.
@@ -955,11 +955,11 @@ C++20 implementation status
   
   
 https://wg21.link/p2092r0";>P2092R0
-Clang 16
+Clang 16
   
   
 https://wg21.link/p2113r0";>P2113R0
-Clang 16
+Clang 16
   
 
 
@@ -1044,7 +1044,7 @@ C++20 implementation status
 
   typename optional in more contexts
   https://wg21.link/p0634r3";>P0634R3
-  Clang 16
+  Clang 16
 
 
   Pack expansion in lambda init-capture
@@ -1147,7 +1147,7 @@ C++20 implementation status
 
   Structured binding extensions
   https://wg21.link/p1091r3";>P1091R3
-  Clang 16
+  Clang 16
 
   
 https://wg21.link/p1381r1";>P1381R1
@@ -1445,7 +1445,7 @@ C++2b implementation status
 
   The Equality Operator You Are Looking For
   https://wg21.link/P2468R2";>P2468R2
-  Clang 16
+  Clang 16
 
 
   De-deprecating volatile compound operations
@@ -1465,7 +1465,7 @@ C++2b implementation status
 
   Labels at the end of compound statements
   https://wg21.link/P2324R2";>P2324R2
-  Clang 16
+  Clang 16
 
 
   Delimited escape sequences
@@ -1490,7 +1490,7 @@ C++2b implementation status
 
   static operator()
   https://wg21.link/P1169R4";>P1169R4
-  Clang 16
+  Clang 16
 
 
   Extended floating-point types and standard names
@@ -1515,7 +1515,7 @@ C++2b implementation status
 
   char8_t Compatibility and Portability Fix
   https://wg21.link/P2513R3";>P2513R3
-  Clang 16
+  Clang 16
 
 
   Relax requirements on wchar_t to match existing 
practices
@@ -1531,12 +1531,12 @@ C++2b implementation status
 
   static operator[]
   https://wg21.link/P2589R1";>P2589R1
-  Clang 16
+  Clang 16
 
 
   Permitting static constexpr variables in constexpr functions
   https://wg21.link/P2647R1";>P2647R1
-  Clang 16
+  Clang 16
 
 
   consteval needs to propagate up



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


[clang] da71cba - [Doc][Clang] Update information about default standard version

2023-03-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-03-29T14:25:27+03:00
New Revision: da71cbacfc3f2b7519356ca105b4c1cde0026106

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

LOG: [Doc][Clang] Update information about default standard version

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 8b1e8712e394..fe2a16d9cee1 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -498,8 +498,7 @@ C++14 implementation status
 href="https://www.iso.org/standard/64029.html";>ISO
 C++ 2014 standard.
 
-By default, Clang builds C++ code according to the C++14 standard.
-You can use Clang in C++14 mode with the -std=c++14 option
+You can use Clang in C++14 mode with the -std=c++14 option
 (use -std=c++1y in Clang 3.4 and earlier).
 
 
@@ -593,7 +592,8 @@ C++17 implementation status
 Clang 5 and later implement all the features of the
 https://www.iso.org/standard/68564.html";>ISO C++ 2017 
standard.
 
-You can use Clang in C++17 mode with the -std=c++17 option
+By default, Clang 16 or later builds C++ code according to the C++17 
standard.
+You can use Clang in C++17 mode with the -std=c++17 option
 (use -std=c++1z in Clang 4 and earlier).
 
 



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


[PATCH] D147141: [clang][documentation][enhancement]Documented Optimization Flags

2023-03-29 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 created this revision.
Herald added a project: All.
ipriyanshi1708 added reviewers: samtebbs, aaron.ballman.
ipriyanshi1708 published this revision for review.
Herald added a project: clang.

Fixes https://github.com/llvm/llvm-project/issues/53681 . Optimization flags 
are not documented in the Clang documentation. So I have added information 
about Optimization flags in the documentation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147141

Files:
  clang/docs/UsersManual.rst


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -2199,6 +2199,41 @@
   link-time optimizations like whole program inter-procedural basic block
   reordering.
 
+Optimization Flags
+--
+
+The optimization flags control the level of optimization that the compiler 
performs on the code. For example, ``-O1`` enables a set of optimizations that 
are designed to improve code performance while still maintaining debugging 
capabilities. ``-Og`` enables optimizations that do not interfere with 
debugging, while ``-Ofast`` enables more aggressive optimizations that may 
sacrifice some debugging capabilities in exchange for maximum performance.
+
+You can use these optimization flags with the Clang compiler by specifying 
them on the command line when invoking the compiler. For example, to compile a 
C++ source file with the ``-O2`` optimization level, you would run the 
following command:
+
+  .. code-block:: console
+
+   $ clang++ -O2 myfile.cpp -o myfile
+
+Here are some common optimization flags with basic descriptions for different 
versions of the Clang compiler:
+
+Clang 3.8 and earlier:
+""
+
+1. ``-O0``: no optimization
+2. ``-O1``: basic optimization, such as function inlining and constant 
propagation
+3. ``-O2``: more aggressive optimization, such as loop unrolling and 
instruction scheduling
+4. ``-O3``: even more aggressive optimization, such as loop vectorization and 
function cloning
+5. ``-Os``: optimize for code size rather than execution speed
+6. ``-Ofast``: enable all optimizations that do not violate strict standards 
compliance
+
+Clang 3.9 and later:
+
+
+1. ``-O0``: no optimization
+2. ``-O1``: basic optimization, such as function inlining and constant 
propagation
+3. ``-O2``: more aggressive optimization, such as loop unrolling and 
instruction scheduling
+4. ``-O3``: even more aggressive optimization, such as loop vectorization and 
function cloning
+5. ``-Os``: optimize for code size rather than execution speed
+6. ``-Ofast``: enable all optimizations that do not violate strict standards 
compliance
+7. ``-Oz``: like -Os, but with more aggressive optimization for code size
+8. ``-Og``: optimize for debuggability, with minimal optimization that does 
not interfere with debugging
+
 Profile Guided Optimization
 ---
 


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -2199,6 +2199,41 @@
   link-time optimizations like whole program inter-procedural basic block
   reordering.
 
+Optimization Flags
+--
+
+The optimization flags control the level of optimization that the compiler performs on the code. For example, ``-O1`` enables a set of optimizations that are designed to improve code performance while still maintaining debugging capabilities. ``-Og`` enables optimizations that do not interfere with debugging, while ``-Ofast`` enables more aggressive optimizations that may sacrifice some debugging capabilities in exchange for maximum performance.
+
+You can use these optimization flags with the Clang compiler by specifying them on the command line when invoking the compiler. For example, to compile a C++ source file with the ``-O2`` optimization level, you would run the following command:
+
+  .. code-block:: console
+
+   $ clang++ -O2 myfile.cpp -o myfile
+
+Here are some common optimization flags with basic descriptions for different versions of the Clang compiler:
+
+Clang 3.8 and earlier:
+""
+
+1. ``-O0``: no optimization
+2. ``-O1``: basic optimization, such as function inlining and constant propagation
+3. ``-O2``: more aggressive optimization, such as loop unrolling and instruction scheduling
+4. ``-O3``: even more aggressive optimization, such as loop vectorization and function cloning
+5. ``-Os``: optimize for code size rather than execution speed
+6. ``-Ofast``: enable all optimizations that do not violate strict standards compliance
+
+Clang 3.9 and later:
+
+
+1. ``-O0``: no optimization
+2. ``-O1``: basic optimization, such as function inlining and constant propagation
+3. ``-O2``: more aggressive optimization, such as loop unrolling and instruction scheduling
+4. ``-O3``: even more aggressive optimi

[PATCH] D146814: [Flang] Add debug flag to enable current debug information pass

2023-03-29 Thread Sacha Ballantyne via Phabricator via cfe-commits
SBallantyne updated this revision to Diff 509303.
SBallantyne added a comment.

Clang format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146814

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.def
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/include/flang/Tools/CLOptions.inc
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/mlir-debug-pass-pipeline.f90

Index: flang/test/Driver/mlir-debug-pass-pipeline.f90
===
--- /dev/null
+++ flang/test/Driver/mlir-debug-pass-pipeline.f90
@@ -0,0 +1,83 @@
+! Test the debug pass pipeline
+
+! RUN: %flang -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline -o /dev/null %s 2>&1 | FileCheck --check-prefixes=ALL,NO-DEBUG %s
+
+! RUN: %flang -g0 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,NO-DEBUG %s
+! RUN: %flang -g -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG %s
+! RUN: %flang -g1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG %s
+! RUN: %flang -gline-tables-only -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG %s
+! RUN: %flang -gline-directives-only -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG,DEBUG-DIRECTIVES %s
+! RUN: %flang -g2 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG,DEBUG-CONSTRUCT %s
+! RUN: %flang -g3 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG,DEBUG-CONSTRUCT %s
+
+! RUN: not %flang_fc1 -debug-info-kind=invalid -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=DEBUG-ERR %s
+
+! REQUIRES: asserts
+
+end program
+
+! DEBUG-CONSTRUCT: warning: Unsupported debug option: constructor
+! DEBUG-DIRECTIVES: warning: Unsupported debug option: line-directives-only
+!
+! DEBUG-ERR: error: invalid value 'invalid' in '-debug-info-kind=invalid'
+! DEBUG-ERR-NOT: Pass statistics report
+
+! ALL: Pass statistics report
+
+! ALL: Fortran::lower::VerifierPass
+! ALL-NEXT: LowerHLFIRIntrinsics
+! ALL-NEXT: BufferizeHLFIR
+! ALL-NEXT: ConvertHLFIRtoFIR
+! ALL-NEXT: CSE
+! Ideally, we need an output with only the pass names, but
+! there is currently no way to get that, so in order to
+! guarantee that the passes are in the expected order
+! (i.e. use -NEXT) we have to check the statistics output as well.
+! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd
+
+! ALL-NEXT: 'func.func' Pipeline
+! ALL-NEXT:   ArrayValueCopy
+! ALL-NEXT:   CharacterConversion
+
+! ALL-NEXT: Canonicalizer
+! ALL-NEXT: SimplifyRegionLite
+! ALL-NEXT: CSE
+! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd
+
+! ALL-NEXT: 'func.func' Pipeline
+! ALL-NEXT:   MemoryAllocationOpt
+
+! ALL-NEXT: Inliner
+! ALL-NEXT: SimplifyRegionLite
+! ALL-NEXT: CSE
+! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd
+
+! ALL-NEXT: 'func.func' Pipeline
+! ALL-NEXT:   PolymorphicOpConversion
+! ALL-NEXT:   CFGConversion
+
+! ALL-NEXT: SCFToControlFlow
+! ALL-NEXT: Canonicalizer
+! ALL-NEXT: SimplifyRegionLite
+! ALL-NEXT: CSE
+! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd
+! ALL-NEXT: BoxedProcedurePass
+
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func']
+! ALL-NEXT:   'fir.global' Pipeline
+! ALL-NEXT:AbstractResultOnGlobalOpt
+! ALL-NEXT:  'func.func' Pipeline
+! ALL-NEXT:AbstractResultOnFuncOpt
+
+! ALL-NEXT: CodeGenRewrite
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations eliminated
+! ALL-NEXT: TargetRewrite
+! ALL-NEXT: ExternalNameConversion
+! DEBUG-NEXT: AddDebugFoundation
+! NO-DEBUG-NOT: AddDebugFoundation
+! ALL-NEXT: FIRToLLVMLowering
+! ALL-NOT: LLVMIRLoweringPass
Index: flang/test/Driver/driver-help.f90
=

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-03-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 509305.
junaire added a comment.

Update + Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/ASTHelpers.cpp
  clang/lib/Interpreter/ASTHelpers.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -139,7 +144,6 @@
 
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
 
-  // Fail to undo.
   auto Err1 = Interp->Undo();
   EXPECT_EQ("Operation failed. Too many undos",
 llvm::toString(std::move(Err1)));
@@ -276,8 +280,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +317,38 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing agai

[PATCH] D146809: [WIP][clang-repl] Implement Value pretty printing

2023-03-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 509306.
junaire added a comment.

Update + Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146809

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_interpreter_runtime_printvalue.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/Value.cpp
  clang/lib/Interpreter/ValuePrinter.cpp
  clang/test/Interpreter/pretty-print.cpp

Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,38 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) 'a'
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2f
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.210
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S &) [[Addr:@0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:@0x.*]]
+
+struct SS { ~SS() {} };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:@0x.*]]
+
+%quit
+
Index: clang/lib/Interpreter/ValuePrinter.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/ValuePrinter.cpp
@@ -0,0 +1,524 @@
+#include "ASTHelpers.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/Value.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+
+using namespace clang;
+
+static std::string PrintDeclType(const QualType &QT, NamedDecl *D) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  if (QT.hasQualifiers())
+SS << QT.getQualifiers().getAsString() << " ";
+  SS << D->getQualifiedNameAsString();
+  return Str;
+}
+
+static std::string PrintQualType(ASTContext &Ctx, QualType QT) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  PrintingPolicy Policy(Ctx.getPrintingPolicy());
+  // Print the Allocator in STL containers, for instance.
+  Policy.SuppressDefaultTemplateArgs = false;
+  Policy.SuppressUnwrittenScope = true;
+  // Print 'a >' rather than 'a>'.
+  Policy.SplitTemplateClosers = true;
+
+  class LocalPrintingPolicyRAII {
+  public:
+LocalPrintingPolicyRAII(ASTContext &Ctx, PrintingPolicy &PPol)
+: Context(Ctx), Policy(Ctx.getPrintingPolicy()) {
+  Context.setPrintingPolicy(PPol);
+}
+~LocalPrintingPolicyRAII() { Context.setPrintingPolicy(Policy); }
+
+  private:
+ASTContext &Context;
+PrintingPolicy Policy;
+  } X(Ctx, Policy);
+
+  const QualType NonRefTy = QT.getNonReferenceType();
+
+  if (const auto *TTy = llvm::dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TTy->getDecl());
+  else if (const auto *TRy = dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TRy->getDecl());
+  else {
+const QualType Canon = NonRefTy.getCanonicalType();
+if (Canon->isBuiltinType() && !NonRefTy->isFunctionPointerType() &&
+!NonRefTy->isMemberPointerType()) {
+  SS << Canon.getAsString(Ctx.getPrintingPolicy());
+} else if (const auto *TDTy = dyn_cast(NonRefTy)) {
+  // FIXME: TemplateSpecializationType & SubstTemplateTypeParmType checks
+  // are predominately to get STL containers to print nicer and might be
+  // better handled in GetFullyQualifiedName.
+  //
+  // std::vector::iterator is a TemplateSpecializationType
+  // std::vector::value_type is a SubstTemplateTypeParmType
+  //
+  QualType SSDesugar = TDTy->getLocallyUnqualifiedSingleStepDesugaredType();
+  if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, Canon);
+  else if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, NonRefTy);
+  else
+SS << PrintDeclType(NonRefTy, TDTy->getDecl());
+} else
+  SS << GetFullTypeName(Ctx, NonRefTy);
+  }
+
+  if (QT->isReferenceType())
+SS << " &";
+
+  return Str;
+}
+
+static std::string PrintEnum(const Value &V) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  ASTContext &Ctx = V.getASTContext();
+
+  QualType DesugaredTy = V.getType().getDesugaredType(Ctx);
+  const EnumType *EnumTy = DesugaredTy.getNonReferenceType()->getAs();
+  assert(EnumTy && "Fail to cast to enum type");
+
+  EnumDecl *ED = EnumTy->getDecl();
+  uint64_t Data = V.getULongLong();
+  bool IsFirst = true;
+  llvm::APSInt AP = Ctx.MakeIntValue(Data, DesugaredTy);
+
+  for (auto I = ED->enumerator_begin(), E = ED->enumerator_end(); I

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-03-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 509307.
junaire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/ASTHelpers.cpp
  clang/lib/Interpreter/ASTHelpers.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -139,7 +144,6 @@
 
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
 
-  // Fail to undo.
   auto Err1 = Interp->Undo();
   EXPECT_EQ("Operation failed. Too many undos",
 llvm::toString(std::move(Err1)));
@@ -276,8 +280,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +317,38 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except

[clang] 41c92c0 - [Assignment Tracking] Give -fexperimental-assignment-tracking flag 3 options

2023-03-29 Thread via cfe-commits

Author: OCHyams
Date: 2023-03-29T12:47:54+01:00
New Revision: 41c92c0dc679022bf270c460629e998380183a2c

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

LOG: [Assignment Tracking]  Give -fexperimental-assignment-tracking flag 3 
options

Without this patch assignment tracking is enabled with
`-fexperimental-assignment-tracking` and disabled with
`-fno-experimental-assignment-tracking` (default). This patch removes the
`-fno-` version and changes `-fexperimental-assignment-tracking` to take 3
values: `enabled`, `disabled` (default), and `forced`.

`clang -Xclang -fexperimental-assignment-tracking=enabled` enables the feature
if some other conditions are met and `=forced` enables it without any further
checks.

If `enabled` is specified the feature will remain disabled if any of the
following are true: it's an LTO or ThinLTO build, optimisations are not
enabled, or lldb debugger tuning has been specified. See this short RFC
for more info:
https://discourse.llvm.org/t/rfc-enable-assignment-tracking/69399

Reviewed By: jmorse

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
clang/test/CodeGen/assignment-tracking/flag.cpp
clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
clang/test/CodeGen/assignment-tracking/nested-scope.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 6383ebea40a5a..d82ad06010857 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -335,8 +335,8 @@ VALUE_CODEGENOPT(WarnStackSize , 32, UINT_MAX) ///< Set 
via -fwarn-stack-siz
 CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF 
info.
 
-CODEGENOPT(EnableAssignmentTracking, 1,0) ///< Enable the Assignment Tracking
-  ///< debug info feature.
+/// Control the Assignment Tracking debug info feature.
+ENUM_CODEGENOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2, 
AssignmentTrackingOpts::Disabled)
 
 CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
   ///< in debug info.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 04a516df1911e..2e067c228a277 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -163,6 +163,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 Never,// No loop is assumed to be finite.
   };
 
+  enum AssignmentTrackingOpts {
+Disabled,
+Enabled,
+Forced,
+  };
+
   /// The code model to use (-mcmodel).
   std::string CodeModel;
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c01859bc18a9a..6f3a325d6310d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5796,11 +5796,11 @@ def fctor_dtor_return_this : Flag<["-"], 
"fctor-dtor-return-this">,
"and non-deleting destructors. (No effect on Microsoft ABI)">,
   MarshallingInfoFlag>;
 
-defm experimental_assignment_tracking :
-  BoolOption<"f", "experimental-assignment-tracking",
-  CodeGenOpts<"EnableAssignmentTracking">, DefaultFalse,
-  PosFlag, NegFlag, BothFlags<[CoreOption]>>,
-  Group;
+def experimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignment-tracking=">,
+  Group, CodeGenOpts<"EnableAssignmentTracking">,
+  NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
+  Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
+  MarshallingInfoEnum, "Disabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 17d0d8d653ac6..e6e058bfc5b86 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -840,11 +840,29 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   SI.registerCallbacks(PIC, &MAM);
   PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
 
-  if (CodeGenOpts.EnableAssignmentTracking) {
+  // Handle the assignment tracking feature options.
+  switch (CodeGenOpts.getAssignmentTrackingMode()) {
+  case CodeGenOptions::AssignmentTrackingOpts::Forced:
 PB.registerPipelineStartEPCallback(
 [&](ModulePassManager &MPM, OptimizationLevel Level) {
   MPM.addPass(Assi

[PATCH] D146615: [Assignment Tracking] Give -fexperimental-assignment-tracking flag 3 options

2023-03-29 Thread Orlando Cazalet-Hyams 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 rG41c92c0dc679: [Assignment Tracking]  Give 
-fexperimental-assignment-tracking flag 3 options (authored by Orlando).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D146615?vs=507285&id=509310#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146615

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
  clang/test/CodeGen/assignment-tracking/flag.cpp
  clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
  clang/test/CodeGen/assignment-tracking/nested-scope.cpp

Index: clang/test/CodeGen/assignment-tracking/nested-scope.cpp
===
--- clang/test/CodeGen/assignment-tracking/nested-scope.cpp
+++ clang/test/CodeGen/assignment-tracking/nested-scope.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone -O0 \
-// RUN: -emit-llvm  -fexperimental-assignment-tracking %s -o -   \
+// RUN: -emit-llvm  -fexperimental-assignment-tracking=forced %s -o -\
 // RUN: | FileCheck %s
 
 // Check that dbg.assign intrinsics get a !dbg with with the same scope as
Index: clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
===
--- clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
+++ clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone -O0 \
-// RUN: -emit-llvm  -fexperimental-assignment-tracking %s -o -   \
+// RUN: -emit-llvm  -fexperimental-assignment-tracking=forced %s -o -\
 // RUN: | FileCheck %s
 
 // Check that the (debug) codegen looks right with assignment tracking
Index: clang/test/CodeGen/assignment-tracking/flag.cpp
===
--- clang/test/CodeGen/assignment-tracking/flag.cpp
+++ clang/test/CodeGen/assignment-tracking/flag.cpp
@@ -1,24 +1,64 @@
  Explicitly enabled:
-// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone -O0 \
-// RUN: -emit-llvm  -fexperimental-assignment-tracking %s -o -   \
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   \
+// RUN: -emit-llvm  -fexperimental-assignment-tracking=enabled %s -o - -O1 \
 // RUN: | FileCheck %s --check-prefixes=ENABLE
+
+ Explicitly disabled:
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   \
+// RUN: -emit-llvm  %s -o - -fexperimental-assignment-tracking=disabled -O1\
+// RUN: | FileCheck %s --check-prefixes=DISABLE
+
  Disabled by default:
-// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone -O0 \
-// RUN: -emit-llvm  %s -o -  \
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   \
+// RUN: -emit-llvm  %s -o - -O1\
 // RUN: | FileCheck %s --check-prefixes=DISABLE
- Explicitly disabled:
-// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone -O0 \
-// RUN: -emit-llvm  %s -o - -fno-experimental-assignment-tracking\
+
+ Disabled at O0 unless forced.
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   \
+// RUN: -emit-llvm %s -o - -fexperimental-assignment-tracking=enabled  \
+// RUN: -O0\
+// RUN: | FileCheck %s --check-prefixes=DISABLE
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   \
+// RUN: -emit-llvm %s -o - -fexperimental-assignment-tracking=forced   \
+// RUN: -O0\
+// RUN: | FileCheck %s --check-prefixes=ENABLE
+
+ Disabled for LTO and thinLTO unless forced.
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   \
+// RUN: -emit-llvm %s -o - -fexperimental-assignment-tracking=enabled  \
+// RUN: -O1 -flto=full \
 // RUN: | FileCheck %s --check-prefixes=DISABLE
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   \
+// RUN: -emit-llvm %s -o - -fexperimental-assignment-tracking=enabled  \
+// RUN: -O1 -flto=thin \
+// RUN: | FileCheck %s --check-prefixes=DISABLE
+// RUN: %cla

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-03-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 509311.
junaire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/ASTHelpers.cpp
  clang/lib/Interpreter/ASTHelpers.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -139,7 +144,6 @@
 
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
 
-  // Fail to undo.
   auto Err1 = Interp->Undo();
   EXPECT_EQ("Operation failed. Too many undos",
 llvm::toString(std::move(Err1)));
@@ -276,8 +280,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +317,38 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_EQ(V2.getAs(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.castAs(), 3);
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 42);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 43);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except

[clang] ab49747 - [NFC][Clang] Move DebugOptions to llvm/Frontend for reuse in Flang

2023-03-29 Thread Sacha Ballantyne via cfe-commits

Author: Kiran Chandramohan
Date: 2023-03-29T12:01:54Z
New Revision: ab49747f9d67d82a1cf0f19196ff29f01d4384f5

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

LOG: [NFC][Clang] Move DebugOptions to llvm/Frontend for reuse in Flang

This patch moves the Debug Options to llvm/Frontend so that it can be shared by 
Flang as well.

Reviewed By: kiranchandramohan, awarzynski

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

Added: 
llvm/include/llvm/Frontend/Debug/Options.h

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/ToolChain.h
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Clang.h
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h
clang/lib/Driver/ToolChains/HIPSPV.cpp
clang/lib/Driver/ToolChains/HIPSPV.h
clang/lib/Driver/ToolChains/MSVC.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/Rewrite/FrontendActions.cpp
clang/tools/clang-import-test/clang-import-test.cpp

Removed: 
clang/include/clang/Basic/DebugInfoOptions.h



diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index d82ad06010857..7151fe9d65682 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -358,7 +358,7 @@ CODEGENOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to 
emit complete
  ///< template parameter descriptions 
in
  ///< forward declarations (versus just
  ///< including them in the name).
-ENUM_CODEGENOPT(DebugSimpleTemplateNames, 
codegenoptions::DebugTemplateNamesKind, 2, 
codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit template 
parameters
+ENUM_CODEGENOPT(DebugSimpleTemplateNames, 
llvm::codegenoptions::DebugTemplateNamesKind, 2, 
llvm::codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit 
template parameters
///< in the textual names of 
template
   ///< specializations.
   ///< Implies DebugFwdTemplateNames to
@@ -388,7 +388,7 @@ VALUE_CODEGENOPT(SmallDataLimit, 32, 0)
 VALUE_CODEGENOPT(SSPBufferSize, 32, 0)
 
 /// The kind of generated debug info.
-ENUM_CODEGENOPT(DebugInfo, codegenoptions::DebugInfoKind, 4, 
codegenoptions::NoDebugInfo)
+ENUM_CODEGENOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4, 
llvm::codegenoptions::NoDebugInfo)
 
 /// Whether to generate macro debug info.
 CODEGENOPT(MacroDebugInfo, 1, 0)

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 2e067c228a277..97853799807fc 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -13,10 +13,10 @@
 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 
-#include "clang/Basic/DebugInfoOptions.h"
 #include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/XRayInstr.h"
 #include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/Frontend/Debug/Options.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Target/TargetOptions.h"
@@ -505,12 +505,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// Check if type and variable info should be emitted.
   bool hasReducedDebugInfo() const {
-return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
+return getDebugInfo() >= llvm::codegenoptions::DebugInfoConstructor;
   }
 
   /// Check if maybe unused type info should be emitted.
   bool hasMaybeUnusedDebugInfo() const {
-return getDebugInfo() >= codegenoptions::UnusedTypeInfo;
+return getDebugInfo() >= llvm::codegenoptions::UnusedTypeInfo;
   }
 
   // Check if any one of SanitizeCoverage* is enabled.

diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 4d66e577b107f..e969edfc4e866 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -9,7 +9,6 @@
 #ifndef LLVM_CLANG_DRIVER_TOOLCHAIN_H
 #define LLVM_CLANG_DRIVER_TOOLCHAIN_H
 
-#include "clang/Basic/DebugInfoOptions.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Sanitizers.h"
@@ -21,6 +20,7 @@
 #include "llvm/ADT/FloatingPointMo

[PATCH] D142347: [NFC][Clang] Move DebugOptions to llvm/Frontend for reuse in Flang

2023-03-29 Thread Sacha Ballantyne 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 rGab49747f9d67: [NFC][Clang] Move DebugOptions to 
llvm/Frontend for reuse in Flang (authored by kiranchandramohan, committed by 
SBallantyne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142347

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DebugInfoOptions.h
  clang/include/clang/Driver/ToolChain.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Clang.h
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Driver/ToolChains/HIPSPV.h
  clang/lib/Driver/ToolChains/MSVC.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/Rewrite/FrontendActions.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  llvm/include/llvm/Frontend/Debug/Options.h

Index: llvm/include/llvm/Frontend/Debug/Options.h
===
--- llvm/include/llvm/Frontend/Debug/Options.h
+++ llvm/include/llvm/Frontend/Debug/Options.h
@@ -6,10 +6,10 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_BASIC_DEBUGINFOOPTIONS_H
-#define LLVM_CLANG_BASIC_DEBUGINFOOPTIONS_H
+#ifndef LLVM_FRONTEND_DEBUG_OPTIONS_H
+#define LLVM_FRONTEND_DEBUG_OPTIONS_H
 
-namespace clang {
+namespace llvm {
 namespace codegenoptions {
 
 enum DebugInfoFormat {
@@ -54,13 +54,9 @@
   UnusedTypeInfo,
 };
 
-enum class DebugTemplateNamesKind {
-  Full,
-  Simple,
-  Mangled
-};
+enum class DebugTemplateNamesKind { Full, Simple, Mangled };
 
 } // end namespace codegenoptions
-} // end namespace clang
+} // end namespace llvm
 
 #endif
Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -200,7 +200,7 @@
   Inv->getLangOpts()->CXXExceptions = true;
   // Needed for testing dynamic_cast.
   Inv->getLangOpts()->RTTI = true;
-  Inv->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
+  Inv->getCodeGenOpts().setDebugInfo(llvm::codegenoptions::FullDebugInfo);
   Inv->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple();
 
   Ins->setInvocation(std::move(Inv));
Index: clang/lib/Frontend/Rewrite/FrontendActions.cpp
===
--- clang/lib/Frontend/Rewrite/FrontendActions.cpp
+++ clang/lib/Frontend/Rewrite/FrontendActions.cpp
@@ -165,10 +165,11 @@
   if (std::unique_ptr OS =
   CI.createDefaultOutputFile(false, InFile, "cpp")) {
 if (CI.getLangOpts().ObjCRuntime.isNonFragile())
-  return CreateModernObjCRewriter(
-  std::string(InFile), std::move(OS), CI.getDiagnostics(),
-  CI.getLangOpts(), CI.getDiagnosticOpts().NoRewriteMacros,
-  (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo));
+  return CreateModernObjCRewriter(std::string(InFile), std::move(OS),
+  CI.getDiagnostics(), CI.getLangOpts(),
+  CI.getDiagnosticOpts().NoRewriteMacros,
+  (CI.getCodeGenOpts().getDebugInfo() !=
+   llvm::codegenoptions::NoDebugInfo));
 return CreateObjCRewriter(std::string(InFile), std::move(OS),
   CI.getDiagnostics(), CI.getLangOpts(),
   CI.getDiagnosticOpts().NoRewriteMacros);
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -12,7 +12,6 @@
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/CommentOptions.h"
-#include "clang/Basic/DebugInfoOptions.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Basic/DiagnosticOptions.h"
@@ -59,6 +58,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Config/llvm-config.h"
+#include "llvm/Frontend/Debug/Options.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/Linker/Linker.h"
 #include "llvm/MC/MCTargetOptions.h"
@@ -1397,28 +1397,28 @@
 
   std::optional DebugInfoVal;
   switch (Opts.DebugInfo) {
-  case codegenoptions::DebugLineTablesOnly:
+  case llvm::codegenopti

[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-29 Thread jonathan molinatto via Phabricator via cfe-commits
jrmolin updated this revision to Diff 509317.
jrmolin added a comment.

ran the formatter, ran the documentation generator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.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
@@ -25393,6 +25393,27 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, BreakBeforeParameterList) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.AlwaysBreakBeforeFunctionParameters, false);
+
+  const StringRef Code("int function1(int param1, int param2, int param3);\n"
+   "int function2();\n");
+
+  // verify that there is no break by default
+  verifyFormat("int function1(int param1, int param2, int param3);\n"
+   "int function2();\n",
+   Code, Style);
+
+  // verify that there is a break when told to break
+  Style.AlwaysBreakBeforeFunctionParameters = true;
+  verifyFormat("int function1(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3);\n"
+   "int function2();\n",
+   Code, Style);
+}
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -149,6 +149,7 @@
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
+  CHECK_PARSE_BOOL(AlwaysBreakBeforeFunctionParameters);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4783,6 +4783,14 @@
 return true;
   }
 
+  // If AlwaysBreakBeforeFunctionParameters is true, we want to break before
+  // the next parameter, if there is one.
+  if (Left.is(tok::l_paren) && Style.AlwaysBreakBeforeFunctionParameters &&
+  !Right.is(tok::r_paren) && Left.Previous &&
+  Left.Previous->is(TT_FunctionDeclarationName)) {
+return true;
+  }
+
   // If the last token before a '}', ']', or ')' is a comma or a trailing
   // comment, the intention is to insert a line break after it in order to make
   // shuffling around entries easier. Import statements, especially in
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -870,6 +870,8 @@
Style.AlwaysBreakAfterReturnType);
 IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
+IO.mapOptional("AlwaysBreakBeforeFunctionParameters",
+   Style.AlwaysBreakBeforeFunctionParameters);
 IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
 IO.mapOptional("AttributeMacros", Style.AttributeMacros);
@@ -1325,6 +1327,7 @@
   LLVMStyle.AllowShortLoopsOnASingleLine = false;
   LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
+  LLVMStyle.AlwaysBreakBeforeFunctionParameters = false;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
   LLVMStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
   LLVMStyle.AttributeMacros.push_back("__capability");
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -354,6 +354,12 @@
 auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack);
 return LambdaBodyLength > getColumnLimit(State);
   }
+  // Check if we want to break before function parameters in declarations
+  if (startsNextParameter(Current, Style) &&
+  Style.AlwaysBreakBeforeFunctionParameters &&
+  State.Line->MustBeDeclaration) {
+return true;
+  }
   if (Current.MustBreakBefore ||
   (Current.is(TT_InlineASMColon) &&
(Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always ||
@@ -1055,7 +1061,9 @@
 // If we are breaking after '(', '{', '<', or 

[PATCH] D147144: [include-cleaner] Report references to operator calls as implicit

2023-03-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Missing these references can result in false negatives in the used-ness
analysis and break builds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147144

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -292,12 +292,13 @@
 
 TEST(WalkAST, Operator) {
   // References to operators are not counted as uses.
-  testWalk("struct string {}; int operator+(string, string);",
+  testWalk("struct string {}; int $implicit^operator+(string, string);",
"int k = string() ^+ string();");
-  testWalk("struct string {int operator+(string); }; ",
-   "int k = string() ^+ string();");
-  testWalk("struct string { friend int operator+(string, string); }; ",
+  testWalk("struct string {int $implicit^operator+(string); }; ",
"int k = string() ^+ string();");
+  testWalk(
+  "struct string { friend int $implicit^operator+(string, string); }; ",
+  "int k = string() ^+ string();");
 }
 
 TEST(WalkAST, Functions) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -87,14 +87,16 @@
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
+  // Operators are always ADL extension points, by design references to them
+  // doesn't count as uses (generally the type should provide them). Hence
+  // treat these as implicit references.
+  // We do this in traverse to make sure rest of the visitor doesn't see
+  // operator calls.
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 if (!WalkUpFromCXXOperatorCallExpr(S))
   return false;
-
-// Operators are always ADL extension points, by design references to them
-// doesn't count as uses (generally the type should provide them).
-// Don't traverse the callee.
-
+report(S->getOperatorLoc(), llvm::cast(S->getCalleeDecl()),
+   RefType::Implicit);
 for (auto *Arg : S->arguments())
   if (!TraverseStmt(Arg))
 return false;


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -292,12 +292,13 @@
 
 TEST(WalkAST, Operator) {
   // References to operators are not counted as uses.
-  testWalk("struct string {}; int operator+(string, string);",
+  testWalk("struct string {}; int $implicit^operator+(string, string);",
"int k = string() ^+ string();");
-  testWalk("struct string {int operator+(string); }; ",
-   "int k = string() ^+ string();");
-  testWalk("struct string { friend int operator+(string, string); }; ",
+  testWalk("struct string {int $implicit^operator+(string); }; ",
"int k = string() ^+ string();");
+  testWalk(
+  "struct string { friend int $implicit^operator+(string, string); }; ",
+  "int k = string() ^+ string();");
 }
 
 TEST(WalkAST, Functions) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -87,14 +87,16 @@
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
+  // Operators are always ADL extension points, by design references to them
+  // doesn't count as uses (generally the type should provide them). Hence
+  // treat these as implicit references.
+  // We do this in traverse to make sure rest of the visitor doesn't see
+  // operator calls.
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
 if (!WalkUpFromCXXOperatorCallExpr(S))
   return false;
-
-// Operators are always ADL extension points, by design references to them
-// doesn't count as uses (generally the type should provide them).
-// Don't traverse the callee.
-
+report(S->getOperatorLoc(), llvm::cast(S->getCalleeDecl()),
+   RefType::Implicit);
 for (auto *Arg : S->arguments())
   if (!TraverseStmt(Arg))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125171: Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-03-29 Thread jonathan molinatto via Phabricator via cfe-commits
jrmolin added a comment.

I think I have hit all the requests now. We're in the middle of building 
release candidates and testing, so management is taking longer and longer to 
get back to me about a style guide for my team.

We added it, because it forces a consistent look across all function 
declarations. I don't know what the next steps are now. I'm stuck; you're 
stuck. :shrug:




Comment at: clang/lib/Format/TokenAnnotator.cpp:4742-4748
+  if (Left.is(tok::l_paren) && Style.AlwaysBreakBeforeFunctionParameters &&
+  !Right.is(tok::r_paren) && Left.Previous) {
+  const FormatToken &TwoPrevious = *Left.Previous;
+  if (TwoPrevious.is(TT_FunctionDeclarationName)) {
+  return true;
+  }
+  }

HazardyKnusperkeks wrote:
> jrmolin wrote:
> > HazardyKnusperkeks wrote:
> > > That I meant with merge.
> > Ah, understood. I generally don't collapse `if`s, so I didn't know how much 
> > you wanted. It seems like ... all of it.
> I think now you need to format it.
I ran the formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D146814: [Flang] Add debug flag to enable current debug information pass

2023-03-29 Thread Sacha Ballantyne 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 rGe2b7424d0666: [Flang] Add debug flag to enable current debug 
information pass (authored by SBallantyne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146814

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.def
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/include/flang/Tools/CLOptions.inc
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/mlir-debug-pass-pipeline.f90

Index: flang/test/Driver/mlir-debug-pass-pipeline.f90
===
--- /dev/null
+++ flang/test/Driver/mlir-debug-pass-pipeline.f90
@@ -0,0 +1,83 @@
+! Test the debug pass pipeline
+
+! RUN: %flang -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline -o /dev/null %s 2>&1 | FileCheck --check-prefixes=ALL,NO-DEBUG %s
+
+! RUN: %flang -g0 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,NO-DEBUG %s
+! RUN: %flang -g -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG %s
+! RUN: %flang -g1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG %s
+! RUN: %flang -gline-tables-only -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG %s
+! RUN: %flang -gline-directives-only -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG,DEBUG-DIRECTIVES %s
+! RUN: %flang -g2 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG,DEBUG-CONSTRUCT %s
+! RUN: %flang -g3 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,DEBUG,DEBUG-CONSTRUCT %s
+
+! RUN: not %flang_fc1 -debug-info-kind=invalid -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o /dev/null 2>&1 | FileCheck --check-prefixes=DEBUG-ERR %s
+
+! REQUIRES: asserts
+
+end program
+
+! DEBUG-CONSTRUCT: warning: Unsupported debug option: constructor
+! DEBUG-DIRECTIVES: warning: Unsupported debug option: line-directives-only
+!
+! DEBUG-ERR: error: invalid value 'invalid' in '-debug-info-kind=invalid'
+! DEBUG-ERR-NOT: Pass statistics report
+
+! ALL: Pass statistics report
+
+! ALL: Fortran::lower::VerifierPass
+! ALL-NEXT: LowerHLFIRIntrinsics
+! ALL-NEXT: BufferizeHLFIR
+! ALL-NEXT: ConvertHLFIRtoFIR
+! ALL-NEXT: CSE
+! Ideally, we need an output with only the pass names, but
+! there is currently no way to get that, so in order to
+! guarantee that the passes are in the expected order
+! (i.e. use -NEXT) we have to check the statistics output as well.
+! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd
+
+! ALL-NEXT: 'func.func' Pipeline
+! ALL-NEXT:   ArrayValueCopy
+! ALL-NEXT:   CharacterConversion
+
+! ALL-NEXT: Canonicalizer
+! ALL-NEXT: SimplifyRegionLite
+! ALL-NEXT: CSE
+! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd
+
+! ALL-NEXT: 'func.func' Pipeline
+! ALL-NEXT:   MemoryAllocationOpt
+
+! ALL-NEXT: Inliner
+! ALL-NEXT: SimplifyRegionLite
+! ALL-NEXT: CSE
+! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd
+
+! ALL-NEXT: 'func.func' Pipeline
+! ALL-NEXT:   PolymorphicOpConversion
+! ALL-NEXT:   CFGConversion
+
+! ALL-NEXT: SCFToControlFlow
+! ALL-NEXT: Canonicalizer
+! ALL-NEXT: SimplifyRegionLite
+! ALL-NEXT: CSE
+! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd
+! ALL-NEXT: BoxedProcedurePass
+
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func']
+! ALL-NEXT:   'fir.global' Pipeline
+! ALL-NEXT:AbstractResultOnGlobalOpt
+! ALL-NEXT:  'func.func' Pipeline
+! ALL-NEXT:AbstractResultOnFuncOpt
+
+! ALL-NEXT: CodeGenRewrite
+! ALL-NEXT:   (S) 0 num-dce'd - Number of operations eliminated
+! ALL-NEXT: TargetRewrite
+! ALL-NEXT: ExternalNameConversion
+! DEBUG-NEXT: AddDebugFoundation
+! NO-DEBUG-NOT: AddDebugFoundation
+! 

[clang] e2b7424 - [Flang] Add debug flag to enable current debug information pass

2023-03-29 Thread Sacha Ballantyne via cfe-commits

Author: Sacha Ballantyne
Date: 2023-03-29T12:21:26Z
New Revision: e2b7424d06663f92b958c0b4649ed08b55216a49

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

LOG: [Flang] Add debug flag to enable current debug information pass

While a pass exists to generate basic debug information, currently there is not 
a corresponding flag to enable it.
This patch adds support for activating this pass at any debug level >= -g1, as 
well as emiting a warning for higher levels that the functionality is not yet 
fully implemented.

This patch also adds -g and -gline-tables-only to appear when `flang-new` 
--help is run

Depends on D142347.

Reviewed By: awarzynski

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

Added: 
flang/test/Driver/mlir-debug-pass-pipeline.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CodeGenOptions.def
flang/include/flang/Frontend/CodeGenOptions.h
flang/include/flang/Tools/CLOptions.inc
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6f3a325d6310d..0cc7052b67105 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3232,9 +3232,9 @@ def femit_dwarf_unwind_EQ : Joined<["-"], 
"femit-dwarf-unwind=">,
   NormalizedValuesScope<"llvm::EmitDwarfUnwindType">,
   MarshallingInfoEnum, "Default">;
 def g_Flag : Flag<["-"], "g">, Group,
-  HelpText<"Generate source-level debug information">;
+Flags<[CoreOption,FlangOption]>, HelpText<"Generate source-level debug 
information">;
 def gline_tables_only : Flag<["-"], "gline-tables-only">, Group,
-  Flags<[CoreOption]>, HelpText<"Emit debug line number tables only">;
+  Flags<[CoreOption,FlangOption]>, HelpText<"Emit debug line number tables 
only">;
 def gline_directives_only : Flag<["-"], "gline-directives-only">, 
Group,
   Flags<[CoreOption]>, HelpText<"Emit debug line info directives only">;
 def gmlt : Flag<["-"], "gmlt">, Alias;
@@ -5466,12 +5466,12 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValuesScope<"llvm::Reloc">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
+def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
 
 } // let Flags = [CC1Option, CC1AsOption, FC1Option, NoDriverOption]
 
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
 
-def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
 def debug_info_macro : Flag<["-"], "debug-info-macro">,
   HelpText<"Emit macro debug information">,
   MarshallingInfoFlag>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 873fb350c0f2c..f5efcebb3bbd9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -403,22 +403,6 @@ static bool ShouldEnableAutolink(const ArgList &Args, 
const ToolChain &TC,
   Default);
 }
 
-// Convert an arg of the form "-gN" or "-ggdbN" or one of their aliases
-// to the corresponding DebugInfoKind.
-static llvm::codegenoptions::DebugInfoKind DebugLevelToInfoKind(const Arg &A) {
-  assert(A.getOption().matches(options::OPT_gN_Group) &&
- "Not a -g option that specifies a debug-info level");
-  if (A.getOption().matches(options::OPT_g0) ||
-  A.getOption().matches(options::OPT_ggdb0))
-return llvm::codegenoptions::NoDebugInfo;
-  if (A.getOption().matches(options::OPT_gline_tables_only) ||
-  A.getOption().matches(options::OPT_ggdb1))
-return llvm::codegenoptions::DebugLineTablesOnly;
-  if (A.getOption().matches(options::OPT_gline_directives_only))
-return llvm::codegenoptions::DebugDirectivesOnly;
-  return llvm::codegenoptions::DebugInfoConstructor;
-}
-
 static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
   switch (Triple.getArch()){
   default:
@@ -977,28 +961,7 @@ RenderDebugEnablingArgs(const ArgList &Args, ArgStringList 
&CmdArgs,
 llvm::codegenoptions::DebugInfoKind DebugInfoKind,
 unsigned DwarfVersion,
 llvm::DebuggerKind DebuggerTuning) {
-  switch (DebugInfoKind) {
-  case llvm::codegenoptions::DebugDirectivesOnly:
-CmdArgs.push_back("-debug-info-kind=line-directives-only");
-break;
-  case llvm::codegenoptions::DebugLineTablesOnly:
-CmdArgs.push_back("-deb

[PATCH] D146412: [NFC] Fix potential for use-after-free in DumpModuleInfoAction

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

This looks much better to me, thank you! LGTM with one small nit for safety.




Comment at: clang/include/clang/Frontend/FrontendActions.h:191
+  DumpModuleInfoAction() = default;
+  DumpModuleInfoAction(std::shared_ptr Out)
+  : OutputStream(Out) {}

A bit of extra safety around implicit conversions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146412

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


[clang] 78b0689 - [Assignment Tracking] Follow up for D147129 - fix broken clang tests

2023-03-29 Thread via cfe-commits

Author: OCHyams
Date: 2023-03-29T13:54:10+01:00
New Revision: 78b0689ff289f3ab52d5a90fc782d556c05f21ed

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

LOG: [Assignment Tracking] Follow up for D147129 - fix broken clang tests

D147129 causes the assignment tracking pass to skip optnone functions, which
ends up overriding the "-fexperimental-assignment-tracking=forced" option at
O0. Add -disable-O0-optnone to the tests so that optnone doesn't interfere.

Buildbot example: https://lab.llvm.org/buildbot/#/builders/216/builds/18986

Added: 


Modified: 
clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
clang/test/CodeGen/assignment-tracking/flag.cpp
clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
clang/test/CodeGen/assignment-tracking/nested-scope.cpp

Removed: 




diff  --git a/clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp 
b/clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
index 2e3045754471..b96ad7ca6fac 100644
--- a/clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
+++ b/clang/test/CodeGen/assignment-tracking/assignment-tracking.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone 
-O0 \
 // RUN: -emit-llvm  -fexperimental-assignment-tracking=forced %s -o -  
  \
+// RUN: -disable-O0-optnone
  \
 // RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
 
 // Based on llvm/test/DebugInfo/Generic/track-assignments.ll - check that using

diff  --git a/clang/test/CodeGen/assignment-tracking/flag.cpp 
b/clang/test/CodeGen/assignment-tracking/flag.cpp
index 9da6f01e9cfa..aa1f054dae4d 100644
--- a/clang/test/CodeGen/assignment-tracking/flag.cpp
+++ b/clang/test/CodeGen/assignment-tracking/flag.cpp
@@ -16,11 +16,11 @@
  Disabled at O0 unless forced.
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\
 // RUN: -emit-llvm %s -o - -fexperimental-assignment-tracking=enabled  
\
-// RUN: -O0
\
+// RUN: -O0 -disable-O0-optnone   \
 // RUN: | FileCheck %s --check-prefixes=DISABLE
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\
 // RUN: -emit-llvm %s -o - -fexperimental-assignment-tracking=forced   
\
-// RUN: -O0
\
+// RUN: -O0 -disable-O0-optnone
\
 // RUN: | FileCheck %s --check-prefixes=ENABLE
 
  Disabled for LTO and thinLTO unless forced.

diff  --git a/clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp 
b/clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
index 14e4d84e4683..126bc8f54eb4 100644
--- a/clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
+++ b/clang/test/CodeGen/assignment-tracking/memcpy-fragment.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone 
-O0 \
 // RUN: -emit-llvm  -fexperimental-assignment-tracking=forced %s -o -  
  \
+// RUN: -disable-O0-optnone
  \
 // RUN: | FileCheck %s
 
 // Check that the (debug) codegen looks right with assignment tracking

diff  --git a/clang/test/CodeGen/assignment-tracking/nested-scope.cpp 
b/clang/test/CodeGen/assignment-tracking/nested-scope.cpp
index 431bf04f1280..d94e42a139c1 100644
--- a/clang/test/CodeGen/assignment-tracking/nested-scope.cpp
+++ b/clang/test/CodeGen/assignment-tracking/nested-scope.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone 
-O0 \
 // RUN: -emit-llvm  -fexperimental-assignment-tracking=forced %s -o -  
  \
+// RUN: -disable-O0-optnone
  \
 // RUN: | FileCheck %s
 
 // Check that dbg.assign intrinsics get a !dbg with with the same scope as



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


[PATCH] D146875: [clang-tidy] Fix example provided by add_new_check.py

2023-03-29 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Ok, lets do that, I will change this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146875

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


[PATCH] D146678: Summary: Fix ArgsAsWritten being null for ConceptSpecializationExpr in certain circumstances when parsing ASTs

2023-03-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D146678#4229052 , @yeswalrus wrote:

> In D146678#4220408 , @erichkeane 
> wrote:
>
>> In D146678#4220360 , @yeswalrus 
>> wrote:
>>
>>> -I can handle it. -
>>> Edit: I cannot handle it, I don't have commit access. If you could commit 
>>> to both main and the 16.x lines with the attribution to Walter Gray 
>>>  that would be much appreciated. Thanks!
>>
>> You already have commit rights?  Ok then.  In order to get this merged into 
>> the 16 release, you need to create a github issue to cherry-pick it, and add 
>> it to the https://github.com/llvm/llvm-project/milestone/21 milestone.
>
> I think there was a mixup. While I initially thought I could handle it, I do 
> not in fact have commit rights.

Ok, not a problem!  I need you to provide your requested 'author' string in the 
form of: "Your Name "


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146678

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


[clang] 4444eeb - Improve requirement clause limitation on non templated function

2023-03-29 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-03-29T06:27:25-07:00
New Revision: eeb753e5b7918141b830213cd3eae0c1fd75

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

LOG: Improve requirement clause limitation on non templated function

The current implementation 6da3d66f03f9162ef341cc67218be40e22fe9808
got a few things wrong, particularly that a template, or  definition
or member in a templated entity is required to be allowed to have a
trailing requires clause.

This patch corrects this, as reproted by #61748

Fixes: #61748

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaLambda.cpp
clang/test/CXX/dcl.decl/dcl.decl.general/p4-20.cpp
clang/test/Parser/cxx2b-lambdas.cpp
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aabaab5ca5dc..a41010d91e24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -248,7 +248,11 @@ Bug Fixes in This Version
 - Fix false-positive diagnostic issued for consteval initializers of temporary
   objects.
   (`#60286 `_)
-
+- Correct restriction of trailing requirements clauses on a templated function.
+  Previously we only rejected non-'templated' things, but the restrictions 
ALSO need
+  to limit non-defined/non-member functions as well. Additionally, we now 
diagnose
+  requires on lambdas when not allowed, which we previously missed.
+  (`#61748 `_)
 Bug Fixes to Compiler Builtins
 ^^
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index dd001dba2b91..7596b51bf054 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11882,8 +11882,33 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 // member-declarator shall be present only if the declarator declares a
 // templated function ([dcl.fct]).
 if (Expr *TRC = NewFD->getTrailingRequiresClause()) {
-  if (!NewFD->isTemplated() && !NewFD->isTemplateInstantiation())
+  // [temp.pre]/8:
+  // An entity is templated if it is
+  // - a template,
+  // - an entity defined ([basic.def]) or created ([class.temporary]) in a
+  // templated entity,
+  // - a member of a templated entity,
+  // - an enumerator for an enumeration that is a templated entity, or
+  // - the closure type of a lambda-expression ([expr.prim.lambda.closure])
+  // appearing in the declaration of a templated entity. [Note 6: A local
+  // class, a local or block variable, or a friend function defined in a
+  // templated entity is a templated entity.  — end note]
+  //
+  // A templated function is a function template or a function that is
+  // templated. A templated class is a class template or a class that is
+  // templated. A templated variable is a variable template or a variable
+  // that is templated.
+
+  if (!NewFD->getDescribedFunctionTemplate() && // -a template
+  // defined... in a templated entity
+  !(DeclIsDefn && NewFD->isTemplated()) &&
+  // a member of a templated entity
+  !(isa(NewFD) && NewFD->isTemplated()) &&
+  // Don't complain about instantiations, they've already had these
+  // rules + others enforced.
+  !NewFD->isTemplateInstantiation()) {
 Diag(TRC->getBeginLoc(), diag::err_constrained_non_templated_function);
+  }
 }
 
 if (CXXConversionDecl *Conversion = dyn_cast(NewFD))

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 64db9d065f9c..b6a4f2604255 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1380,6 +1380,37 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++20: dcl.decl.general p4:
+  // The optional requires-clause ([temp.pre]) in an init-declarator or
+  // member-declarator shall be present only if the declarator declares a
+  // templated function ([dcl.fct]).
+  if (Expr *TRC = Method->getTrailingRequiresClause()) {
+// [temp.pre]/8:
+// An entity is templated if it is
+// - a template,
+// - an entity defined ([basic.def]) or created ([class.temporary]) in a
+// templated entity,
+// - a member of a templated entity,
+// - an enumerator for an enumeration that is a templated entity, or
+// - the closure type of a lambda-expression ([expr.prim.lambda.closure])
+// appearing in the declaration of a templated entity. [Note 6: A local
+ 

[PATCH] D147070: Improve requirement clause limitation on non templated function

2023-03-29 Thread Erich Keane 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 rGeeb753e5: Improve requirement clause limitation on non 
templated function (authored by erichkeane).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D147070?vs=509101&id=509337#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147070

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CXX/dcl.decl/dcl.decl.general/p4-20.cpp
  clang/test/Parser/cxx2b-lambdas.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- clang/test/SemaCXX/lambda-capture-type-deduction.cpp
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -48,6 +48,7 @@
   static_assert(noexcept([&] mutable noexcept(is_same) {}()));
 }
 
+template
 void test_requires() {
 
   int x;
@@ -77,6 +78,10 @@
   [x = 1]() mutable requires is_same {} ();
 }
 
+void use() {
+  test_requires();
+}
+
 void err() {
   int y, z;
   (void)[x = 1]
Index: clang/test/Parser/cxx2b-lambdas.cpp
===
--- clang/test/Parser/cxx2b-lambdas.cpp
+++ clang/test/Parser/cxx2b-lambdas.cpp
@@ -18,7 +18,7 @@
 auto L10 = [] noexcept { return true; };
 auto L11 = [] -> bool { return true; };
 auto L12 = [] consteval {};
-auto L13 = []() requires true {};
+auto L13 = []() requires true {}; // expected-error{{non-templated function cannot have a requires clause}}
 auto L14 = [] requires true() requires true {};
 auto L15 = [] requires true noexcept {};
 auto L16 = [] [[maybe_unused]]{};
Index: clang/test/CXX/dcl.decl/dcl.decl.general/p4-20.cpp
===
--- clang/test/CXX/dcl.decl/dcl.decl.general/p4-20.cpp
+++ clang/test/CXX/dcl.decl/dcl.decl.general/p4-20.cpp
@@ -23,3 +23,41 @@
 // expected-error@+1{{expected expression}}
 auto *p = new void(*)(char)
   requires true;
+
+namespace GH61748 {
+template
+struct S {
+  // expected-error@+1 {{non-templated function cannot have a requires clause}}
+  friend void declared_friend() requires(sizeof(T) > 1);
+  // OK, is a definition.
+  friend void defined_friend() requires(sizeof(T) > 1){}
+  // OK, is a member.
+  void member() requires(sizeof(T) > 1);
+};
+
+template
+void ContainingFunction() {
+  // expected-error@+1 {{non-templated function cannot have a requires clause}}
+  void bad() requires(sizeof(T) > 1);
+  // expected-error@+1 {{function definition is not allowed here}}
+  void still_bad() requires(sizeof(T) > 1) {}
+
+}
+
+void NonTemplContainingFunction() {
+  // expected-error@+1 {{non-templated function cannot have a requires clause}}
+  (void)[]() requires (sizeof(int)>1){};
+  // OK, a template.
+  auto X = [](auto) requires (sizeof(int)>1){};
+  // OK, a template.
+  auto Y = [](T t) requires (sizeof(int)>1){};
+
+  X(1);
+  Y(1);
+}
+
+template
+union U {
+  void f() requires true;
+};
+}
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1380,6 +1380,37 @@
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++20: dcl.decl.general p4:
+  // The optional requires-clause ([temp.pre]) in an init-declarator or
+  // member-declarator shall be present only if the declarator declares a
+  // templated function ([dcl.fct]).
+  if (Expr *TRC = Method->getTrailingRequiresClause()) {
+// [temp.pre]/8:
+// An entity is templated if it is
+// - a template,
+// - an entity defined ([basic.def]) or created ([class.temporary]) in a
+// templated entity,
+// - a member of a templated entity,
+// - an enumerator for an enumeration that is a templated entity, or
+// - the closure type of a lambda-expression ([expr.prim.lambda.closure])
+// appearing in the declaration of a templated entity. [Note 6: A local
+// class, a local or block variable, or a friend function defined in a
+// templated entity is a templated entity.  — end note]
+//
+// A templated function is a function template or a function that is
+// templated. A templated class is a class template or a class that is
+// templated. A templated variable is a variable template or a variable
+// that is templated.
+
+// Note: we only have to check if this is defined in a template entity, OR
+// if we are a template, since the rest don't apply. The requires clause
+// applies to the call operator, which we already know is a member function,
+// AND defined.
+if (!Method->getDescribedFunctionTemplate() && !Method->isTemplated()) {
+  Diag(TRC->getBeginLoc(), diag::err_constrained_n

[PATCH] D147097: [SYCL] Always set NoUnwind attribute for SYCL.

2023-03-29 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk updated this revision to Diff 509335.
hvdijk added a comment.

Apparently the test was already passing without my change, so I updated the 
test to make it a function that did not previously get the nounwind attribute. 
This also revealed that the test was more fragile than I realised: it depends 
on the precise order in which functions are emitted. We always match "Function 
Attrs:" to the first emitted function, and then `CHECK-NEXT` can fail. We'd 
ideally first `CHECK`  for `void @_Z3foov()`  (now `void⋅@_Z3barv()`) and then 
`CHECK-PREV`  for the attributes, but FileCheck does not support that. What we 
can do instead though is find the matching `attributes #n = { ... }`  line and 
verify that everything is in there; updated accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147097

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenSYCL/convergent.cpp
  clang/test/CodeGenSYCL/function-attrs.cpp


Index: clang/test/CodeGenSYCL/function-attrs.cpp
===
--- clang/test/CodeGenSYCL/function-attrs.cpp
+++ clang/test/CodeGenSYCL/function-attrs.cpp
@@ -1,11 +1,18 @@
 // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN:  -triple spir64 -emit-llvm %s -o - | FileCheck %s
+// RUN:  -triple spir64 -fexceptions -emit-llvm %s -o - | FileCheck %s
 
-// CHECK-DAG: Function Attrs:
-// CHECK-DAG-SAME: convergent
-// CHECK-DAG-NEXT: define void @_Z3foov
-void foo() {
-  int a = 1;
+int foo();
+
+// CHECK: define dso_local spir_func void @_Z3barv() [[BAR:#[0-9]+]]
+// CHECK: attributes [[BAR]] =
+// CHECK-SAME: convergent
+// CHECK-SAME: nounwind
+void bar() {
+  int a = foo();
+}
+
+int foo() {
+  return 1;
 }
 
 template 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1971,10 +1971,9 @@
   }
 
   // TODO: NoUnwind attribute should be added for other GPU modes HIP,
-  // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device
-  // code.
+  // OpenMP offload. AFAIK, neither of them support exceptions in device code.
   if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) ||
-  getLangOpts().OpenCL) {
+  getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   }
 


Index: clang/test/CodeGenSYCL/function-attrs.cpp
===
--- clang/test/CodeGenSYCL/function-attrs.cpp
+++ clang/test/CodeGenSYCL/function-attrs.cpp
@@ -1,11 +1,18 @@
 // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN:  -triple spir64 -emit-llvm %s -o - | FileCheck %s
+// RUN:  -triple spir64 -fexceptions -emit-llvm %s -o - | FileCheck %s
 
-// CHECK-DAG: Function Attrs:
-// CHECK-DAG-SAME: convergent
-// CHECK-DAG-NEXT: define void @_Z3foov
-void foo() {
-  int a = 1;
+int foo();
+
+// CHECK: define dso_local spir_func void @_Z3barv() [[BAR:#[0-9]+]]
+// CHECK: attributes [[BAR]] =
+// CHECK-SAME: convergent
+// CHECK-SAME: nounwind
+void bar() {
+  int a = foo();
+}
+
+int foo() {
+  return 1;
 }
 
 template 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1971,10 +1971,9 @@
   }
 
   // TODO: NoUnwind attribute should be added for other GPU modes HIP,
-  // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device
-  // code.
+  // OpenMP offload. AFAIK, neither of them support exceptions in device code.
   if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) ||
-  getLangOpts().OpenCL) {
+  getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-03-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 509342.
qiongsiwu1 added a comment.

Rebase and address feedback other than test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/PowerPC/aix-roptr.c
  clang/test/Driver/ppc-roptr.c

Index: clang/test/Driver/ppc-roptr.c
===
--- /dev/null
+++ clang/test/Driver/ppc-roptr.c
@@ -0,0 +1,45 @@
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -c -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mxcoff-roptr -mno-xcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=NO_ROPTR
+
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -S -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=NO_ROPTR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=LTO_ROPTR
+// RUN: touch %t.o
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \
+// RUN: FileCheck %s --check-prefix=LINK
+
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mxcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -shared \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=SHARED_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mxcoff-roptr -flto \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto -fno-data-sections \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mno-xcoff-roptr -flto -fno-data-sections \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=NO_DATA_SECTION_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bforceimprw"
+
+// DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
+// NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections
+// TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
+// TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
+// SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
Index: clang/test/CodeGen/PowerPC/aix-roptr.c
===
--- /dev/null
+++ clang/test/CodeGen/PowerPC/aix-roptr.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK32
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK64
+// RUN: not %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -mxcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+
+char c1 = 10;
+char c2 = 20;
+char* const c1_ptr = &c1;
+// CHECK32: .csect c1_ptr[RO],2
+// CHECK32-NEXT:	.globl	c1_ptr[RO]
+// CHECK32-NEXT:	.align	2
+// CHECK32-NEXT:	.vbyte	4, c1[RW]
+
+// CHECK64: .csect c1_ptr[RO],3
+// CHECK64-NEXT:	.globl	c1_ptr[RO]
+// CHECK64-NEXT:	.align	3
+// CHECK64-NEXT:	.vbyte	8, c1[RW]
+
+// DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
+// TARGET_RO

[clang] 76e50f3 - Fix missing newline in ReleaseNotes which caused sphinx problems

2023-03-29 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-03-29T06:37:01-07:00
New Revision: 76e50f38ba891e647b6da1ed64cf0879df6693ea

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

LOG: Fix missing newline in ReleaseNotes which caused sphinx problems

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a41010d91e24..271e01b8a47d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -253,6 +253,7 @@ Bug Fixes in This Version
   to limit non-defined/non-member functions as well. Additionally, we now 
diagnose
   requires on lambdas when not allowed, which we previously missed.
   (`#61748 `_)
+
 Bug Fixes to Compiler Builtins
 ^^
 



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


[PATCH] D147097: [SYCL] Always set NoUnwind attribute for SYCL.

2023-03-29 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk updated this revision to Diff 509355.
hvdijk added a comment.

Forgot to update the call to `foo()` to call `bar()` instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147097

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenSYCL/convergent.cpp
  clang/test/CodeGenSYCL/function-attrs.cpp


Index: clang/test/CodeGenSYCL/function-attrs.cpp
===
--- clang/test/CodeGenSYCL/function-attrs.cpp
+++ clang/test/CodeGenSYCL/function-attrs.cpp
@@ -1,11 +1,18 @@
 // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN:  -triple spir64 -emit-llvm %s -o - | FileCheck %s
+// RUN:  -triple spir64 -fexceptions -emit-llvm %s -o - | FileCheck %s
 
-// CHECK-DAG: Function Attrs:
-// CHECK-DAG-SAME: convergent
-// CHECK-DAG-NEXT: define void @_Z3foov
-void foo() {
-  int a = 1;
+int foo();
+
+// CHECK: define dso_local spir_func void @_Z3barv() [[BAR:#[0-9]+]]
+// CHECK: attributes [[BAR]] =
+// CHECK-SAME: convergent
+// CHECK-SAME: nounwind
+void bar() {
+  int a = foo();
+}
+
+int foo() {
+  return 1;
 }
 
 template 
@@ -14,6 +21,6 @@
 }
 
 int main() {
-  kernel_single_task([] { foo(); });
+  kernel_single_task([] { bar(); });
   return 0;
 }
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1971,10 +1971,9 @@
   }
 
   // TODO: NoUnwind attribute should be added for other GPU modes HIP,
-  // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device
-  // code.
+  // OpenMP offload. AFAIK, neither of them support exceptions in device code.
   if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) ||
-  getLangOpts().OpenCL) {
+  getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   }
 


Index: clang/test/CodeGenSYCL/function-attrs.cpp
===
--- clang/test/CodeGenSYCL/function-attrs.cpp
+++ clang/test/CodeGenSYCL/function-attrs.cpp
@@ -1,11 +1,18 @@
 // RUN: %clang_cc1 -fsycl-is-device -emit-llvm -disable-llvm-passes \
-// RUN:  -triple spir64 -emit-llvm %s -o - | FileCheck %s
+// RUN:  -triple spir64 -fexceptions -emit-llvm %s -o - | FileCheck %s
 
-// CHECK-DAG: Function Attrs:
-// CHECK-DAG-SAME: convergent
-// CHECK-DAG-NEXT: define void @_Z3foov
-void foo() {
-  int a = 1;
+int foo();
+
+// CHECK: define dso_local spir_func void @_Z3barv() [[BAR:#[0-9]+]]
+// CHECK: attributes [[BAR]] =
+// CHECK-SAME: convergent
+// CHECK-SAME: nounwind
+void bar() {
+  int a = foo();
+}
+
+int foo() {
+  return 1;
 }
 
 template 
@@ -14,6 +21,6 @@
 }
 
 int main() {
-  kernel_single_task([] { foo(); });
+  kernel_single_task([] { bar(); });
   return 0;
 }
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1971,10 +1971,9 @@
   }
 
   // TODO: NoUnwind attribute should be added for other GPU modes HIP,
-  // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device
-  // code.
+  // OpenMP offload. AFAIK, neither of them support exceptions in device code.
   if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) ||
-  getLangOpts().OpenCL) {
+  getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146408: [clang][Interp] Start supporting complex types

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

LGTM but perhaps we should add an expected-failing test case for the `_BitInt` 
situation just so we don't forget about it.




Comment at: clang/lib/AST/Interp/PrimType.h:108
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\

tbaeder wrote:
> aaron.ballman wrote:
> > Oh boy, this is going to be interesting, isn't it?
> > ```
> > consteval _Complex _BitInt(12) UhOh() { return (_Complex _BitInt(12))1; }
> > consteval _Complex _BitInt(18) Why() { return (_Complex _BitInt(18))1; }
> > 
> > static_assert(UhOh() + Why() == 2);
> > ```
> > 
> `_BitInt` isn't supported in the new interpreter at all right now, so this 
> just gets rejected.
> 
> 
> Apart from that... is a complex bitint really something that should be 
> supported? Not just in the new interpreter but generally?
> _BitInt isn't supported in the new interpreter at all right now, so this just 
> gets rejected.

Well, that's sort of good then! :-D We'll have to deal with `_BitInt` at some 
point, so maybe we can add this as a test case with expected failures and a 
fixit comment so we don't forget about it?

> Apart from that... is a complex bitint really something that should be 
> supported? Not just in the new interpreter but generally?

I don't see why not; we support complex integer types and `_BitInt` is an 
integer type. We support `_Complex` from C in C++ and we support `_BitInt` from 
C in C++, so it seems reasonable to expect `_Complex _BitInt` to work.


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

https://reviews.llvm.org/D146408

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


[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

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

LGTM!




Comment at: clang/lib/AST/Interp/ByteCodeStmtGen.cpp:324-328
+  LocalScope Scope(this);
+  if (!this->visitUnscopedCompoundStmt(Body))
 return false;
+
+  Scope.emitDestructors();

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > `AutoScope` and some curly braces to delimit the scope object lifetime?
> > > The problem is that we want to emit the destructors before the jump, but 
> > > not destroy the scope. That should happen after the end label, when the 
> > > loop is finished altogether so an `AutoScope` doesn't work.
> > Ahh yeah, that's a good point... but this still worries me a bit because of 
> > how easy it is to misuse the scope after emitting the destructors. 
> > Notionally, we want two scopes, right? One scope for the loop construct 
> > guts and a second (inner) scope for the loop body. That's how the construct 
> > is modeled in the standard: http://eel.is/c++draft/stmt.while#2
> Add a `DestructorScope` that just emits the destructors of a given scope.
Thank you, I like this!


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

https://reviews.llvm.org/D145545

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


[PATCH] D146408: [clang][Interp] Start supporting complex types

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 509359.
tbaeder set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146408

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/EvalEmitter.cpp
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/complex.cpp

Index: clang/test/AST/Interp/complex.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/complex.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+constexpr _Complex double z1 = {1.0, 2.0};
+static_assert(__real(z1) == 1.0, "");
+static_assert(__imag(z1) == 2.0, "");
+
+constexpr double setter() {
+  _Complex float d = {1.0, 2.0};
+
+  __imag(d) = 4.0;
+  return __imag(d);
+}
+static_assert(setter() == 4, "");
+
+constexpr _Complex double getter() {
+  return {1.0, 3.0};
+}
+constexpr _Complex double D = getter();
+static_assert(__real(D) == 1.0, "");
+static_assert(__imag(D) == 3.0, "");
+
+
+constexpr _Complex int I1 = {1, 2};
+static_assert(__real(I1) == 1, "");
+static_assert(__imag(I1) == 2, "");
+
+
+/// FIXME: This should work in the new interpreter as well.
+// constexpr _Complex _BitInt(8) A = 0;// = {4};
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -102,6 +102,22 @@
 }  \
   } while (0)
 
+#define INT_TYPE_SWITCH(Expr, B)   \
+  do { \
+switch (Expr) {\
+  TYPE_SWITCH_CASE(PT_Sint8, B)\
+  TYPE_SWITCH_CASE(PT_Uint8, B)\
+  TYPE_SWITCH_CASE(PT_Sint16, B)   \
+  TYPE_SWITCH_CASE(PT_Uint16, B)   \
+  TYPE_SWITCH_CASE(PT_Sint32, B)   \
+  TYPE_SWITCH_CASE(PT_Uint32, B)   \
+  TYPE_SWITCH_CASE(PT_Sint64, B)   \
+  TYPE_SWITCH_CASE(PT_Uint64, B)   \
+default:   \
+  llvm_unreachable("Unhandled integer type");  \
+}  \
+  } while (0)
+
 #define BITCAST_TYPE_SWITCH(Expr, B)   \
   do { \
 switch (Expr) {\
Index: clang/lib/AST/Interp/EvalEmitter.cpp
===
--- clang/lib/AST/Interp/EvalEmitter.cpp
+++ clang/lib/AST/Interp/EvalEmitter.cpp
@@ -196,6 +196,27 @@
   }
   return Ok;
 }
+
+// Complex types.
+if (const auto *CT = Ty->getAs()) {
+  QualType ElemTy = CT->getElementType();
+  std::optional ElemT = Ctx.classify(ElemTy);
+  assert(ElemT);
+
+  if (ElemTy->isIntegerType()) {
+INT_TYPE_SWITCH(*ElemT, {
+  auto V1 = Ptr.atIndex(0).deref();
+  auto V2 = Ptr.atIndex(1).deref();
+  Result = APValue(V1.toAPSInt(), V2.toAPSInt());
+  return true;
+});
+  } else if (ElemTy->isFloatingType()) {
+Result = APValue(Ptr.atIndex(0).deref().getAPFloat(),
+ Ptr.atIndex(1).deref().getAPFloat());
+return true;
+  }
+  return false;
+}
 llvm_unreachable("invalid value to return");
   };
 
Index: clang/lib/AST/Interp/Context.cpp
===
--- clang/lib/AST/Interp/Context.cpp
+++ clang/lib/AST/Interp/Context.cpp
@@ -81,6 +81,9 @@
   if (T->isBooleanType())
 return PT_Bool;
 
+  if (T->isAnyComplexType())
+return std::nullopt;
+
   if (T->isSignedIntegerOrEnumerationType()) {
 switch (Ctx.getIntWidth(T)) {
 case 64:
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -139,6 +139,7 @@
   bool visitArrayInitializer(const Expr *Initializer);
   /// Compiles a record initializer.
   bool visitRecordInitializer(const Expr *Initializer);
+  bool visi

[PATCH] D146408: [clang][Interp] Start supporting complex types

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/PrimType.h:108
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > Oh boy, this is going to be interesting, isn't it?
> > > ```
> > > consteval _Complex _BitInt(12) UhOh() { return (_Complex _BitInt(12))1; }
> > > consteval _Complex _BitInt(18) Why() { return (_Complex _BitInt(18))1; }
> > > 
> > > static_assert(UhOh() + Why() == 2);
> > > ```
> > > 
> > `_BitInt` isn't supported in the new interpreter at all right now, so this 
> > just gets rejected.
> > 
> > 
> > Apart from that... is a complex bitint really something that should be 
> > supported? Not just in the new interpreter but generally?
> > _BitInt isn't supported in the new interpreter at all right now, so this 
> > just gets rejected.
> 
> Well, that's sort of good then! :-D We'll have to deal with `_BitInt` at some 
> point, so maybe we can add this as a test case with expected failures and a 
> fixit comment so we don't forget about it?
> 
> > Apart from that... is a complex bitint really something that should be 
> > supported? Not just in the new interpreter but generally?
> 
> I don't see why not; we support complex integer types and `_BitInt` is an 
> integer type. We support `_Complex` from C in C++ and we support `_BitInt` 
> from C in C++, so it seems reasonable to expect `_Complex _BitInt` to work.
> I don't see why not; we support complex integer types and _BitInt is an 
> integer type. We support _Complex from C in C++ and we support _BitInt from C 
> in C++, so it seems reasonable to expect _Complex _BitInt to work.

My immediate reaction to something like `_Complex` is "this is stupid, this 
belongs in user code". For floating-point values it at least makes sense from a 
mathematical POV I guess. But complex ints is already weird and complex 
arbitrary-width integers? What's the use case? `_Complex bool` is rejected as 
well after all.



Comment at: clang/lib/AST/Interp/PrimType.h:108
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > Oh boy, this is going to be interesting, isn't it?
> > > > ```
> > > > consteval _Complex _BitInt(12) UhOh() { return (_Complex _BitInt(12))1; 
> > > > }
> > > > consteval _Complex _BitInt(18) Why() { return (_Complex _BitInt(18))1; }
> > > > 
> > > > static_assert(UhOh() + Why() == 2);
> > > > ```
> > > > 
> > > `_BitInt` isn't supported in the new interpreter at all right now, so 
> > > this just gets rejected.
> > > 
> > > 
> > > Apart from that... is a complex bitint really something that should be 
> > > supported? Not just in the new interpreter but generally?
> > > _BitInt isn't supported in the new interpreter at all right now, so this 
> > > just gets rejected.
> > 
> > Well, that's sort of good then! :-D We'll have to deal with `_BitInt` at 
> > some point, so maybe we can add this as a test case with expected failures 
> > and a fixit comment so we don't forget about it?
> > 
> > > Apart from that... is a complex bitint really something that should be 
> > > supported? Not just in the new interpreter but generally?
> > 
> > I don't see why not; we support complex integer types and `_BitInt` is an 
> > integer type. We support `_Complex` from C in C++ and we support `_BitInt` 
> > from C in C++, so it seems reasonable to expect `_Complex _BitInt` to work.
> > I don't see why not; we support complex integer types and _BitInt is an 
> > integer type. We support _Complex from C in C++ and we support _BitInt from 
> > C in C++, so it seems reasonable to expect _Complex _BitInt to work.
> 
> My immediate reaction to something like `_Complex` is "this is stupid, this 
> belongs in user code". For floating-point values it at least makes sense from 
> a mathematical POV I guess. But complex ints is already weird and complex 
> arbitrary-width integers? What's the use case? `_Complex bool` is rejected as 
> well after all.
> We'll have to deal with _BitInt at some point, so maybe we can add this as a 
> test case with expected failures and a fixit comment so we don't forget about 
> it?

It's running into an assertion for the test case, so I added it commented-out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146408

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.

[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-03-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 509360.
qiongsiwu1 added a comment.

Moving the `-shared` check to the AIX linker and modifying the tests so we test 
pure linking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/PowerPC/aix-roptr.c
  clang/test/Driver/ppc-roptr.c

Index: clang/test/Driver/ppc-roptr.c
===
--- /dev/null
+++ clang/test/Driver/ppc-roptr.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -c -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mxcoff-roptr -mno-xcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=NO_ROPTR
+
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -S -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=NO_ROPTR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: touch %t.o
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \
+// RUN: FileCheck %s --check-prefix=LINK
+
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mxcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
+// RUN: touch %t.o
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -shared \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=SHARED_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mxcoff-roptr -flto \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto -fno-data-sections \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mno-xcoff-roptr -flto -fno-data-sections \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=NO_DATA_SECTION_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bforceimprw"
+
+// DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
+// NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections
+// TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
+// TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
+// SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
Index: clang/test/CodeGen/PowerPC/aix-roptr.c
===
--- /dev/null
+++ clang/test/CodeGen/PowerPC/aix-roptr.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK32
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK64
+// RUN: not %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -mxcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+
+char c1 = 10;
+char c2 = 20;
+char* const c1_ptr = &c1;
+// CHECK32: .csect c1_ptr[RO],2
+// CHECK32-NEXT:	.globl	c1_ptr[RO]
+// CHECK32-NEXT:	.align	2
+// CHECK32-NEXT:	.vbyte	4, c1[RW]
+
+// CHECK64: .csect c1_ptr[RO],3
+// CHECK64-NEXT:	.globl	c1_ptr[RO]
+// CHECK64-NEXT:	.align	3
+// CHECK64-NEXT:	.vbyte	8, c1[RW]
+
+// DATA

[PATCH] D145815: [Flang][Driver] Add support for fopenmp-is-device and fembed-offload-object to Flang ToolChain

2023-03-29 Thread Jean Perier via Phabricator via cfe-commits
jeanPerier added a comment.

@agozillon, in the test added here (omp-frontend-forwarding.f90), I am seeing 
failures in some patches windows pre-merge checks that I think are not related 
to the patches.
Could you check if there is a stability/reproducibility issue with the 
omp-frontend-forwarding.f90 on windows?

The failure message look like:

  # command stderr:
  
C:\ws\w8\llvm-project\premerge-checks\flang\test\Driver\omp-frontend-forwarding.f90:21:23:
 error: CHECK-OPENMP-EMBED: expected string not found in input
  ! CHECK-OPENMP-EMBED: "{{[^"]*}}clang-offload-packager" {{.*}} 
"--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
^
  :6:435: note: scanning from here
   "c:\\ws\\w8\\llvm-project\\premerge-checks\\build\\bin\\flang-new" "-fc1" 
"-triple" "amdgcn-amd-amdhsa" "-emit-llvm-bc" "-fopenmp" "-mrelocation-model" 
"pic" "-pic-level" "2" "-fopenmp-is-device" "-o" 
"C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-gfx90a-6808f0.bc"
 "-x" "f95-cpp-input" 
"C:\\ws\\w8\\llvm-project\\premerge-checks\\flang\\test\\Driver\\omp-frontend-forwarding.f90"





^
  :7:266: note: possible intended match here
   "c:\\program files\\llvm\\bin\\clang-offload-packager.exe" "-o" 
"C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-9beea6.out"
 
"--image=file=C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-gfx90a-6808f0.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"

I wonder if this is an issue with the ".exe" command suffix in the windows 
output.

Example of pre-merge failures:

https://reviews.llvm.org/D146989
https://buildkite.com/llvm-project/premerge-checks/builds/143821#01872b65-9b0c-457b-8714-c1f0ca00d02b

or
https://reviews.llvm.org/D147130
https://buildkite.com/llvm-project/premerge-checks/builds/143873#01872ccb-9251-499a-b9fd-9155e3ffb1f1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145815

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


[PATCH] D145815: [Flang][Driver] Add support for fopenmp-is-device and fembed-offload-object to Flang ToolChain

2023-03-29 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D145815#4230780 , @jeanPerier 
wrote:

> @agozillon, in the test added here (omp-frontend-forwarding.f90), I am seeing 
> failures in some patches windows pre-merge checks that I think are not 
> related to the patches.
> Could you check if there is a stability/reproducibility issue with the 
> omp-frontend-forwarding.f90 on windows?
>
> The failure message look like:
>
>   # command stderr:
>   
> C:\ws\w8\llvm-project\premerge-checks\flang\test\Driver\omp-frontend-forwarding.f90:21:23:
>  error: CHECK-OPENMP-EMBED: expected string not found in input
>   ! CHECK-OPENMP-EMBED: "{{[^"]*}}clang-offload-packager" {{.*}} 
> "--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
> ^
>   :6:435: note: scanning from here
>"c:\\ws\\w8\\llvm-project\\premerge-checks\\build\\bin\\flang-new" "-fc1" 
> "-triple" "amdgcn-amd-amdhsa" "-emit-llvm-bc" "-fopenmp" "-mrelocation-model" 
> "pic" "-pic-level" "2" "-fopenmp-is-device" "-o" 
> "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-gfx90a-6808f0.bc"
>  "-x" "f95-cpp-input" 
> "C:\\ws\\w8\\llvm-project\\premerge-checks\\flang\\test\\Driver\\omp-frontend-forwarding.f90"
>   
>   
>   
>   
>   
>   ^
>   :7:266: note: possible intended match here
>"c:\\program files\\llvm\\bin\\clang-offload-packager.exe" "-o" 
> "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-9beea6.out"
>  
> "--image=file=C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-gfx90a-6808f0.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
>
> I wonder if this is an issue with the ".exe" command suffix in the windows 
> output.
>
> Example of pre-merge failures:
>
> https://reviews.llvm.org/D146989
> https://buildkite.com/llvm-project/premerge-checks/builds/143821#01872b65-9b0c-457b-8714-c1f0ca00d02b
>
> or
> https://reviews.llvm.org/D147130
> https://buildkite.com/llvm-project/premerge-checks/builds/143873#01872ccb-9251-499a-b9fd-9155e3ffb1f1

Most likely the classic `.exe` on Windows problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145815

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


[PATCH] D145815: [Flang][Driver] Add support for fopenmp-is-device and fembed-offload-object to Flang ToolChain

2023-03-29 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon added a comment.

In D145815#4230780 , @jeanPerier 
wrote:

> @agozillon, in the test added here (omp-frontend-forwarding.f90), I am seeing 
> failures in some patches windows pre-merge checks that I think are not 
> related to the patches.
> Could you check if there is a stability/reproducibility issue with the 
> omp-frontend-forwarding.f90 on windows?
>
> The failure message look like:
>
>   # command stderr:
>   
> C:\ws\w8\llvm-project\premerge-checks\flang\test\Driver\omp-frontend-forwarding.f90:21:23:
>  error: CHECK-OPENMP-EMBED: expected string not found in input
>   ! CHECK-OPENMP-EMBED: "{{[^"]*}}clang-offload-packager" {{.*}} 
> "--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
> ^
>   :6:435: note: scanning from here
>"c:\\ws\\w8\\llvm-project\\premerge-checks\\build\\bin\\flang-new" "-fc1" 
> "-triple" "amdgcn-amd-amdhsa" "-emit-llvm-bc" "-fopenmp" "-mrelocation-model" 
> "pic" "-pic-level" "2" "-fopenmp-is-device" "-o" 
> "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-gfx90a-6808f0.bc"
>  "-x" "f95-cpp-input" 
> "C:\\ws\\w8\\llvm-project\\premerge-checks\\flang\\test\\Driver\\omp-frontend-forwarding.f90"
>   
>   
>   
>   
>   
>   ^
>   :7:266: note: possible intended match here
>"c:\\program files\\llvm\\bin\\clang-offload-packager.exe" "-o" 
> "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-9beea6.out"
>  
> "--image=file=C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\lit-tmp-1koflt_t\\omp-frontend-forwarding-gfx90a-6808f0.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
>
> I wonder if this is an issue with the ".exe" command suffix in the windows 
> output.
>
> Example of pre-merge failures:
>
> https://reviews.llvm.org/D146989
> https://buildkite.com/llvm-project/premerge-checks/builds/143821#01872b65-9b0c-457b-8714-c1f0ca00d02b
>
> or
> https://reviews.llvm.org/D147130
> https://buildkite.com/llvm-project/premerge-checks/builds/143873#01872ccb-9251-499a-b9fd-9155e3ffb1f1

Hi @jeanPerier,

Thank you! I noticed this today as well and I'm currently looking into it, i 
have a fix upcoming, just forcing another patch 
(https://reviews.llvm.org/D144896) to test it via buildbot as I have no easy 
access to a windows machine to test it at the moment, and yes @jhuber6 is 
correct, it appears to be the .exe postfix on windows! I'll submit the fix as 
soon as it clears the buildbot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145815

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


[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added a comment.

Thanks, I'll verify the patch once again with an msan build before I push, just 
to be sure.


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

https://reviews.llvm.org/D145545

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


[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-03-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 509367.
qiongsiwu1 marked an inline comment as done.
qiongsiwu1 added a comment.

Fix the LTO data sections check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/PowerPC/aix-roptr.c
  clang/test/Driver/ppc-roptr.c

Index: clang/test/Driver/ppc-roptr.c
===
--- /dev/null
+++ clang/test/Driver/ppc-roptr.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -c -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mxcoff-roptr -mno-xcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=NO_ROPTR
+
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -S -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=NO_ROPTR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: touch %t.o
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \
+// RUN: FileCheck %s --check-prefix=LINK
+
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mxcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
+// RUN: touch %t.o
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -shared \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=SHARED_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mxcoff-roptr -flto \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto -fno-data-sections \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mno-xcoff-roptr -flto -fno-data-sections \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=NO_DATA_SECTION_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bforceimprw"
+
+// DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
+// NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections
+// TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
+// TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
+// SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
Index: clang/test/CodeGen/PowerPC/aix-roptr.c
===
--- /dev/null
+++ clang/test/CodeGen/PowerPC/aix-roptr.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK32
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK64
+// RUN: not %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -mxcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+
+char c1 = 10;
+char c2 = 20;
+char* const c1_ptr = &c1;
+// CHECK32: .csect c1_ptr[RO],2
+// CHECK32-NEXT:	.globl	c1_ptr[RO]
+// CHECK32-NEXT:	.align	2
+// CHECK32-NEXT:	.vbyte	4, c1[RW]
+
+// CHECK64: .csect c1_ptr[RO],3
+// CHECK64-NEXT:	.globl	c1_ptr[RO]
+// CHECK64-NEXT:	.align	3
+// CHECK64-NEXT:	.vbyte	8, c1[RW]
+
+// DATA_SECTION_ERR: err

[PATCH] D146408: [clang][Interp] Start supporting complex types

2023-03-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/PrimType.h:108
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\

tbaeder wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > tbaeder wrote:
> > > > aaron.ballman wrote:
> > > > > Oh boy, this is going to be interesting, isn't it?
> > > > > ```
> > > > > consteval _Complex _BitInt(12) UhOh() { return (_Complex 
> > > > > _BitInt(12))1; }
> > > > > consteval _Complex _BitInt(18) Why() { return (_Complex 
> > > > > _BitInt(18))1; }
> > > > > 
> > > > > static_assert(UhOh() + Why() == 2);
> > > > > ```
> > > > > 
> > > > `_BitInt` isn't supported in the new interpreter at all right now, so 
> > > > this just gets rejected.
> > > > 
> > > > 
> > > > Apart from that... is a complex bitint really something that should be 
> > > > supported? Not just in the new interpreter but generally?
> > > > _BitInt isn't supported in the new interpreter at all right now, so 
> > > > this just gets rejected.
> > > 
> > > Well, that's sort of good then! :-D We'll have to deal with `_BitInt` at 
> > > some point, so maybe we can add this as a test case with expected 
> > > failures and a fixit comment so we don't forget about it?
> > > 
> > > > Apart from that... is a complex bitint really something that should be 
> > > > supported? Not just in the new interpreter but generally?
> > > 
> > > I don't see why not; we support complex integer types and `_BitInt` is an 
> > > integer type. We support `_Complex` from C in C++ and we support 
> > > `_BitInt` from C in C++, so it seems reasonable to expect `_Complex 
> > > _BitInt` to work.
> > > I don't see why not; we support complex integer types and _BitInt is an 
> > > integer type. We support _Complex from C in C++ and we support _BitInt 
> > > from C in C++, so it seems reasonable to expect _Complex _BitInt to work.
> > 
> > My immediate reaction to something like `_Complex` is "this is stupid, this 
> > belongs in user code". For floating-point values it at least makes sense 
> > from a mathematical POV I guess. But complex ints is already weird and 
> > complex arbitrary-width integers? What's the use case? `_Complex bool` is 
> > rejected as well after all.
> > We'll have to deal with _BitInt at some point, so maybe we can add this as 
> > a test case with expected failures and a fixit comment so we don't forget 
> > about it?
> 
> It's running into an assertion for the test case, so I added it commented-out.
> My immediate reaction to something like _Complex is "this is stupid, this 
> belongs in user code". For floating-point values it at least makes sense from 
> a mathematical POV I guess. But complex ints is already weird and complex 
> arbitrary-width integers? What's the use case? _Complex bool is rejected as 
> well after all.

How would you explain this?
```
_Complex int32_t Val; // OK
_Complex _BitInt(32) OtherVal; // Not OK
```
The use case is the same as for `_Complex int`, just with getting to pick the 
width you want to use, which users can already do for some specific widths. 
Neither is a particularly strong motivation (to me anyway!), but I can't see 
why we'd allow a 32-bit integer but not a 32-bit (et al) precise integer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146408

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


[PATCH] D146408: [clang][Interp] Start supporting complex types

2023-03-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/PrimType.h:108
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\

aaron.ballman wrote:
> tbaeder wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > tbaeder wrote:
> > > > > aaron.ballman wrote:
> > > > > > Oh boy, this is going to be interesting, isn't it?
> > > > > > ```
> > > > > > consteval _Complex _BitInt(12) UhOh() { return (_Complex 
> > > > > > _BitInt(12))1; }
> > > > > > consteval _Complex _BitInt(18) Why() { return (_Complex 
> > > > > > _BitInt(18))1; }
> > > > > > 
> > > > > > static_assert(UhOh() + Why() == 2);
> > > > > > ```
> > > > > > 
> > > > > `_BitInt` isn't supported in the new interpreter at all right now, so 
> > > > > this just gets rejected.
> > > > > 
> > > > > 
> > > > > Apart from that... is a complex bitint really something that should 
> > > > > be supported? Not just in the new interpreter but generally?
> > > > > _BitInt isn't supported in the new interpreter at all right now, so 
> > > > > this just gets rejected.
> > > > 
> > > > Well, that's sort of good then! :-D We'll have to deal with `_BitInt` 
> > > > at some point, so maybe we can add this as a test case with expected 
> > > > failures and a fixit comment so we don't forget about it?
> > > > 
> > > > > Apart from that... is a complex bitint really something that should 
> > > > > be supported? Not just in the new interpreter but generally?
> > > > 
> > > > I don't see why not; we support complex integer types and `_BitInt` is 
> > > > an integer type. We support `_Complex` from C in C++ and we support 
> > > > `_BitInt` from C in C++, so it seems reasonable to expect `_Complex 
> > > > _BitInt` to work.
> > > > I don't see why not; we support complex integer types and _BitInt is an 
> > > > integer type. We support _Complex from C in C++ and we support _BitInt 
> > > > from C in C++, so it seems reasonable to expect _Complex _BitInt to 
> > > > work.
> > > 
> > > My immediate reaction to something like `_Complex` is "this is stupid, 
> > > this belongs in user code". For floating-point values it at least makes 
> > > sense from a mathematical POV I guess. But complex ints is already weird 
> > > and complex arbitrary-width integers? What's the use case? `_Complex 
> > > bool` is rejected as well after all.
> > > We'll have to deal with _BitInt at some point, so maybe we can add this 
> > > as a test case with expected failures and a fixit comment so we don't 
> > > forget about it?
> > 
> > It's running into an assertion for the test case, so I added it 
> > commented-out.
> > My immediate reaction to something like _Complex is "this is stupid, this 
> > belongs in user code". For floating-point values it at least makes sense 
> > from a mathematical POV I guess. But complex ints is already weird and 
> > complex arbitrary-width integers? What's the use case? _Complex bool is 
> > rejected as well after all.
> 
> How would you explain this?
> ```
> _Complex int32_t Val; // OK
> _Complex _BitInt(32) OtherVal; // Not OK
> ```
> The use case is the same as for `_Complex int`, just with getting to pick the 
> width you want to use, which users can already do for some specific widths. 
> Neither is a particularly strong motivation (to me anyway!), but I can't see 
> why we'd allow a 32-bit integer but not a 32-bit (et al) precise integer.
Sure, the bitint one is just a bit crazier, I was hoping we could draw the line 
a little earlier and save ourselves some headaches, but this doesn't seem to be 
a problem in the current interpreter.

With `constexpr` being in c++ now and c++20 having enough to implement complex 
numbers in user code anyway, are there any plans to deprecate `_Complex` in 
c++20 onward (not sure about C2x)? That doesn't help me of course but it would 
maybe give me more hope for the future :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146408

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


[PATCH] D146408: [clang][Interp] Start supporting complex types

2023-03-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/PrimType.h:108
+switch (Expr) {
\
+  TYPE_SWITCH_CASE(PT_Sint8, B)
\
+  TYPE_SWITCH_CASE(PT_Uint8, B)
\

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > tbaeder wrote:
> > > > aaron.ballman wrote:
> > > > > tbaeder wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > Oh boy, this is going to be interesting, isn't it?
> > > > > > > ```
> > > > > > > consteval _Complex _BitInt(12) UhOh() { return (_Complex 
> > > > > > > _BitInt(12))1; }
> > > > > > > consteval _Complex _BitInt(18) Why() { return (_Complex 
> > > > > > > _BitInt(18))1; }
> > > > > > > 
> > > > > > > static_assert(UhOh() + Why() == 2);
> > > > > > > ```
> > > > > > > 
> > > > > > `_BitInt` isn't supported in the new interpreter at all right now, 
> > > > > > so this just gets rejected.
> > > > > > 
> > > > > > 
> > > > > > Apart from that... is a complex bitint really something that should 
> > > > > > be supported? Not just in the new interpreter but generally?
> > > > > > _BitInt isn't supported in the new interpreter at all right now, so 
> > > > > > this just gets rejected.
> > > > > 
> > > > > Well, that's sort of good then! :-D We'll have to deal with `_BitInt` 
> > > > > at some point, so maybe we can add this as a test case with expected 
> > > > > failures and a fixit comment so we don't forget about it?
> > > > > 
> > > > > > Apart from that... is a complex bitint really something that should 
> > > > > > be supported? Not just in the new interpreter but generally?
> > > > > 
> > > > > I don't see why not; we support complex integer types and `_BitInt` 
> > > > > is an integer type. We support `_Complex` from C in C++ and we 
> > > > > support `_BitInt` from C in C++, so it seems reasonable to expect 
> > > > > `_Complex _BitInt` to work.
> > > > > I don't see why not; we support complex integer types and _BitInt is 
> > > > > an integer type. We support _Complex from C in C++ and we support 
> > > > > _BitInt from C in C++, so it seems reasonable to expect _Complex 
> > > > > _BitInt to work.
> > > > 
> > > > My immediate reaction to something like `_Complex` is "this is stupid, 
> > > > this belongs in user code". For floating-point values it at least makes 
> > > > sense from a mathematical POV I guess. But complex ints is already 
> > > > weird and complex arbitrary-width integers? What's the use case? 
> > > > `_Complex bool` is rejected as well after all.
> > > > We'll have to deal with _BitInt at some point, so maybe we can add this 
> > > > as a test case with expected failures and a fixit comment so we don't 
> > > > forget about it?
> > > 
> > > It's running into an assertion for the test case, so I added it 
> > > commented-out.
> > > My immediate reaction to something like _Complex is "this is stupid, this 
> > > belongs in user code". For floating-point values it at least makes sense 
> > > from a mathematical POV I guess. But complex ints is already weird and 
> > > complex arbitrary-width integers? What's the use case? _Complex bool is 
> > > rejected as well after all.
> > 
> > How would you explain this?
> > ```
> > _Complex int32_t Val; // OK
> > _Complex _BitInt(32) OtherVal; // Not OK
> > ```
> > The use case is the same as for `_Complex int`, just with getting to pick 
> > the width you want to use, which users can already do for some specific 
> > widths. Neither is a particularly strong motivation (to me anyway!), but I 
> > can't see why we'd allow a 32-bit integer but not a 32-bit (et al) precise 
> > integer.
> Sure, the bitint one is just a bit crazier, I was hoping we could draw the 
> line a little earlier and save ourselves some headaches, but this doesn't 
> seem to be a problem in the current interpreter.
> 
> With `constexpr` being in c++ now and c++20 having enough to implement 
> complex numbers in user code anyway, are there any plans to deprecate 
> `_Complex` in c++20 onward (not sure about C2x)? That doesn't help me of 
> course but it would maybe give me more hope for the future :)
C++ has `std::complex` as the official API for complex numbers 
(http://eel.is/c++draft/complex.numbers), but we expose `_Complex` in C++ as an 
extension because it makes it easier to ensure you're getting the same ABI 
between C and C++ with that datatype. (That said, I've always had the 
impression that `std::complex` and `_Complex` are intended to be ABI compatible 
in practice, but there's nothing in the C++ standard that requires it.) I'm not 
certain that we'd want to deprecate support for `_Complex` in C++ without 
plenty of investigation into whether it's used in practice or not.

As for deprecating `_Complex` in C, I'd be surprised but stranger things have 
happened.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTI

[PATCH] D146412: [NFC] Fix potential for use-after-free in DumpModuleInfoAction

2023-03-29 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 509372.
Fznamznon added a comment.

Add a little bit of safety.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146412

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,9 @@
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
-   llvm::sys::fs::OF_TextWithCRLF));
-OutputStream = OutFile.get();
+OutputStream.reset(new llvm::raw_fd_ostream(
+OutputFileName.str(), EC, llvm::sys::fs::OF_TextWithCRLF));
   }
   llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs();
 
Index: clang/include/clang/Frontend/FrontendActions.h
===
--- clang/include/clang/Frontend/FrontendActions.h
+++ clang/include/clang/Frontend/FrontendActions.h
@@ -177,9 +177,8 @@
 /// Dump information about the given module file, to be used for
 /// basic debugging and discovery.
 class DumpModuleInfoAction : public ASTFrontendAction {
-public:
   // Allow other tools (ex lldb) to direct output for their use.
-  llvm::raw_ostream *OutputStream = nullptr;
+  std::shared_ptr OutputStream;
 
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
@@ -188,6 +187,9 @@
   void ExecuteAction() override;
 
 public:
+  DumpModuleInfoAction() = default;
+  explicit DumpModuleInfoAction(std::shared_ptr Out)
+  : OutputStream(Out) {}
   bool hasPCHSupport() const override { return false; }
   bool hasASTFileSupport() const override { return true; }
   bool hasIRSupport() const override { return false; }


Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -2179,8 +2179,9 @@
 const char *clang_args[] = {"clang", pcm_path};
 compiler.setInvocation(clang::createInvocation(clang_args));
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);
 // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
 compiler.getPCHContainerOperations()->registerReader(
 std::make_unique());
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -780,14 +780,12 @@
 void DumpModuleInfoAction::ExecuteAction() {
   assert(isCurrentFileAST() && "dumping non-AST?");
   // Set up the output file.
-  std::unique_ptr OutFile;
   CompilerInstance &CI = getCompilerInstance();
   StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
   if (!OutputFileName.empty() && OutputFileName != "-") {
 std::error_code EC;
-OutFile.reset(new llvm::raw_fd_ostream(OutputFileName.str(), EC,
-   llvm::sys::fs::OF_TextWithCRLF));
-OutputStream = OutFile.get();
+OutputStream.reset(new llvm::raw_fd_ostream(
+OutputFileName.str(), EC, llvm::sys::fs::OF_TextWithCRLF));
   }
   llvm::raw_ostream &Out = OutputStream ? *OutputStream : llvm::outs();
 
Index: clang/include/clang/Frontend/FrontendActions.h

[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-29 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

You will need to rebase this as I made some changes recently to how 
`ExtractAPIVisitor` is structured. We can either set up a time to talk about it 
and do it together or I can handle doing this work once we are happy with this.




Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:52
+template 
+void modifyRecord(const T &Records, const llvm::StringRef &name) {
+  for (const auto &Record : Records) {

this should be a marked `static` or put in an anonymous namespace.



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:56
+  Record.second.get()->Declaration.removeLast();
+  Record.second.get()
+  ->Declaration

I think this warrants adding methods to declaration fragments to streamline 
this sort of operation (merging fragments at arbitrary offsets. This should 
probably be done as a follow up patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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


[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-03-29 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 marked an inline comment as done.
qiongsiwu1 added inline comments.



Comment at: clang/test/Driver/ppc-roptr.c:37
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"

hubert.reinterpretcast wrote:
> This needs the backend option also renamed. Has a commit for that landed yet?
No the commit has not landed. The patch is up https://reviews.llvm.org/D147161. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

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


[PATCH] D133102: [clang-tidy] Extend simplify-boolean-expr check

2023-03-29 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.
Herald added a subscriber: PiotrZSL.

In D133102#3774151 , @alexfh wrote:

> For example, LLVM coding standards recommends using early exits: 
> https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code

How is the proposed replacement not an early exit?  It's an unconditional exit: 
it either returns a bool constant or it returns a variable that is a bool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133102

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


[PATCH] D146866: [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id

2023-03-29 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:176
+
+// id is an qualified id type
+if (!T->getAs()->isObjCQualifiedIdType()) {





Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:176
+
+// id is an qualified id type
+if (!T->getAs()->isObjCQualifiedIdType()) {

dang wrote:
> 
IIUC the distinction here is that `id` is a `id` qualified type, but 
`id *` is not? If so this is a fairly subtle point, and worth 
mentioning in this comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146866

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


[clang] 1cfe1e7 - [clang][ExtractAPI] Add queried symbol to parent contexts in libclang

2023-03-29 Thread Daniel Grumberg via cfe-commits

Author: Daniel Grumberg
Date: 2023-03-29T16:32:26+01:00
New Revision: 1cfe1e732ad8e8148f6fa8fc0f0c86f4b965d567

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

LOG: [clang][ExtractAPI] Add queried symbol to parent contexts in libclang

Ensure that the current symbol is added to the parent contexts in the
output of libclang function for generating symbol graphs for single symbols.

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

Added: 


Modified: 
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/test/Index/extract-api-cursor.m
clang/test/Index/extract-api-usr.m

Removed: 




diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 8a98f5cf0c71f..7676c74af6869 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -547,10 +547,6 @@ Array generateParentContexts(const RecordTy &Record, const 
APISet &API,
serializeParentContext(PC, Lang));
  });
 
-  // The last component would be the record itself so let's remove it.
-  if (!ParentContexts.empty())
-ParentContexts.pop_back();
-
   return ParentContexts;
 }
 

diff  --git a/clang/test/Index/extract-api-cursor.m 
b/clang/test/Index/extract-api-cursor.m
index 16844ca1674ee..1b27b6f61437b 100644
--- a/clang/test/Index/extract-api-cursor.m
+++ b/clang/test/Index/extract-api-cursor.m
@@ -34,7 +34,7 @@ - (void)derivedMethodWithValue:(id)value {
 @end
 
 // RUN: c-index-test -single-symbol-sgf-at=%s:4:9 local %s | FileCheck 
-check-prefix=CHECK-FOO %s
-// CHECK-FOO: "parentContexts":[]
+// CHECK-FOO: 
"parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"}]
 // CHECK-FOO: "relatedSymbols":[]
 // CHECK-FOO: "relationships":[]
 // CHECK-FOO: "text":"Foo docs"
@@ -42,7 +42,7 @@ - (void)derivedMethodWithValue:(id)value {
 // CHECK-FOO: "title":"Foo"
 
 // RUN: c-index-test -single-symbol-sgf-at=%s:6:9 local %s | FileCheck 
-check-prefix=CHECK-BAR %s
-// CHECK-BAR: 
"parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"}]
+// CHECK-BAR: 
"parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"},{"kind":"objective-c.property","name":"bar","usr":"c:@S@Foo@FI@bar"}]
 // CHECK-BAR: "relatedSymbols":[]
 // CHECK-BAR: 
"relationships":[{"kind":"memberOf","source":"c:@S@Foo@FI@bar","target":"c:@S@Foo"
 // CHECK-BAR: "text":"Bar docs"
@@ -50,7 +50,7 @@ - (void)derivedMethodWithValue:(id)value {
 // CHECK-BAR: "title":"bar"
 
 // RUN: c-index-test -single-symbol-sgf-at=%s:10:11 local %s | FileCheck 
-check-prefix=CHECK-BASE %s
-// CHECK-BASE: "parentContexts":[]
+// CHECK-BASE: 
"parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
 // CHECK-BASE: "relatedSymbols":[]
 // CHECK-BASE: "relationships":[]
 // CHECK-BASE: "text":"Base docs"
@@ -58,7 +58,7 @@ - (void)derivedMethodWithValue:(id)value {
 // CHECK-BASE: "title":"Base"
 
 // RUN: c-index-test -single-symbol-sgf-at=%s:12:25 local %s | FileCheck 
-check-prefix=CHECK-BASE-PROP %s
-// CHECK-BASE-PROP: 
"parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASE-PROP: 
"parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.property","name":"baseProperty","usr":"c:objc(cs)Base(py)baseProperty"}]
 // CHECK-BASE-PROP: 
"relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
 // CHECK-BASE-PROP: "isSystem":false
 // CHECK-BASE-PROP: "usr":"c:@S@Foo"}]
@@ -68,7 +68,7 @@ - (void)derivedMethodWithValue:(id)value {
 // CHECK-BASE-PROP: "title":"baseProperty"
 
 // RUN: c-index-test -single-symbol-sgf-at=%s:15:9 local %s | FileCheck 
-check-prefix=CHECK-BASE-METHOD %s
-// CHECK-BASE-METHOD: 
"parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASE-METHOD: 
"parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.method","name":"baseMethodWithArg:","usr":"c:objc(cs)Base(im)baseMethodWithArg:"}]
 // CHECK-BASE-METHOD: "relatedSymbols":[]
 // CHECK-BASE-METHOD: 
"relationships":[{"kind":"memberOf","source":"c:objc(cs)Base(im)baseMethodWithArg:","target":"c:objc(cs)Base"
 // CHECK-BASE-METHOD: "text":"Base method docs"
@@ -76,7 +76,7 @@ - (void)derivedMethodWithValue:(id)value {
 // CHECK-BASE-METHOD: "title":"baseMethodWithArg:"
 
 // RUN: c-index-test -single-symbol-sgf-at=%s:19:11 local %s | FileCheck 
-check-prefix=CHECK-PROTOCOL %s
-// CHECK-PROTOCOL: "parentContexts":[]
+// CHECK-PROTOCOL: 
"parentContexts":[{"kind":"objective-c.protocol","name

[PATCH] D147138: [clang][ExtractAPI] Add queried symbol to parent contexts in libclang

2023-03-29 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1cfe1e732ad8: [clang][ExtractAPI] Add queried symbol to 
parent contexts in libclang (authored by dang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147138

Files:
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/Index/extract-api-cursor.m
  clang/test/Index/extract-api-usr.m

Index: clang/test/Index/extract-api-usr.m
===
--- clang/test/Index/extract-api-usr.m
+++ clang/test/Index/extract-api-usr.m
@@ -28,7 +28,7 @@
 
 // Checking for Foo
 // RUN: c-index-test "-single-symbol-sgf-for=c:@S@Foo" %s | FileCheck -check-prefix=CHECK-FOO %s
-// CHECK-FOO: "parentContexts":[]
+// CHECK-FOO: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"}]
 // CHECK-FOO-SAME: "relatedSymbols":[]
 // CHECK-FOO-SAME: "relationships":[]
 // CHECK-FOO-SAME: "text":"Foo docs"
@@ -38,7 +38,7 @@
 
 // Checking for bar
 // RUN: c-index-test "-single-symbol-sgf-for=c:@S@Foo@FI@bar" %s | FileCheck -check-prefix=CHECK-BAR %s
-// CHECK-BAR: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"}]
+// CHECK-BAR: "parentContexts":[{"kind":"objective-c.struct","name":"Foo","usr":"c:@S@Foo"},{"kind":"objective-c.property","name":"bar","usr":"c:@S@Foo@FI@bar"}]
 // CHECK-BAR-SAME: "relatedSymbols":[]
 // CHECK-BAR-SAME: "relationships":[{"kind":"memberOf","source":"c:@S@Foo@FI@bar","target":"c:@S@Foo"
 // CHECK-BAR-SAME: "text":"Bar docs"
@@ -47,7 +47,7 @@
 
 // Checking for Base
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base" %s | FileCheck -check-prefix=CHECK-BASE %s
-// CHECK-BASE: "parentContexts":[]
+// CHECK-BASE: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
 // CHECK-BASE-SAME: "relatedSymbols":[]
 // CHECK-BASE-SAME: "relationships":[]
 // CHECK-BASE-SAME: "text":"Base docs"
@@ -56,7 +56,7 @@
 
 // Checking for baseProperty
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base(py)baseProperty" %s | FileCheck -check-prefix=CHECK-BASEPROP %s
-// CHECK-BASEPROP: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASEPROP: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.property","name":"baseProperty","usr":"c:objc(cs)Base(py)baseProperty"}]
 // CHECK-BASEPROP-SAME:"relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
 // CHECK-BASEPROP-SAME: "isSystem":false
 // CHECK-BASEPROP-SAME: "usr":"c:@S@Foo"}]
@@ -67,7 +67,7 @@
 
 // Checking for baseMethodWithArg
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Base(im)baseMethodWithArg:" %s | FileCheck -check-prefix=CHECK-BASEMETHOD %s
-// CHECK-BASEMETHOD: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"}]
+// CHECK-BASEMETHOD: "parentContexts":[{"kind":"objective-c.class","name":"Base","usr":"c:objc(cs)Base"},{"kind":"objective-c.method","name":"baseMethodWithArg:","usr":"c:objc(cs)Base(im)baseMethodWithArg:"}]
 // CHECK-BASEMETHOD-SAME:"relatedSymbols":[]
 // CHECK-BASEMETHOD-SAME: "relationships":[{"kind":"memberOf","source":"c:objc(cs)Base(im)baseMethodWithArg:","target":"c:objc(cs)Base"
 // CHECK-BASEMETHOD-SAME: "text":"Base method docs"
@@ -76,7 +76,7 @@
 
 // Checking for Protocol
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(pl)Protocol" %s | FileCheck -check-prefix=CHECK-PROT %s
-// CHECK-PROT: "parentContexts":[]
+// CHECK-PROT: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"}]
 // CHECK-PROT-SAME: "relatedSymbols":[]
 // CHECK-PROT-SAME: "relationships":[]
 // CHECK-PROT-SAME: "text":"Protocol docs"
@@ -85,7 +85,7 @@
 
 // Checking for protocolProperty
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(pl)Protocol(py)protocolProperty" %s | FileCheck -check-prefix=CHECK-PROTPROP %s
-// CHECK-PROTPROP: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"}]
+// CHECK-PROTPROP: "parentContexts":[{"kind":"objective-c.protocol","name":"Protocol","usr":"c:objc(pl)Protocol"},{"kind":"objective-c.property","name":"protocolProperty","usr":"c:objc(pl)Protocol(py)protocolProperty"}]
 // CHECK-PROTPROP-SAME:"relatedSymbols":[{"accessLevel":"public","declarationLanguage":"objective-c"
 // CHECK-PROTPROP-SAME: "isSystem":false
 // CHECK-PROTPROP-SAME: "usr":"c:@S@Foo"}]
@@ -96,7 +96,7 @@
 
 // Checking for Derived
 // RUN: c-index-test "-single-symbol-sgf-for=c:objc(cs)Derived" %s | FileCheck -check-prefix=CHECK-DERIVED %s
-// CHECK-DERIVED: "parentContexts":[]
+// CHECK-DERIVED: "parentContexts":[{"kind":"objective-c.class","name":"Derived","usr":"c:objc(cs)Derived"}]
 // CHECK-DERIVED-SAME:"relatedSymbols":[{

[PATCH] D128697: [clang-tidy] Add new check `bugprone-unhandled-exception-at-sto`

2023-03-29 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.
Herald added a subscriber: PiotrZSL.

In D128697#3638467 , @Sockke wrote:

> In D128697#3619310 , 
> @LegalizeAdulthood wrote:
>
>> This whole check seems weird to me.  I mean, almost every use of a standard 
>> container could throw `std::bad_alloc` but we don't insist on a local 
>> `catch` for `bad_alloc` at every possible throwing call site.
>>
>> Why would we assume that every call site of `stoi` or `stod` **must** have 
>> an exception handler immediately around it?  It's perfectly acceptable for 
>> an application to handle this at an outer scope that can't be detected by 
>> clang-tidy.
>
> Makes sense, I implemented this check here because some projects in ByteDance 
> used stoi with missing exception handlers caused an online crash, I think 
> this is a relatively common problem.  Perhaps only report diagnostics for 
> stoi calls in nothrow functions?

I don't have anything more to add; I mean, you answered my question with 
another question.  I still don't see that this check is making things better.  
Have you run it on large code bases to see what kind of nuisance it creates?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128697

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


[PATCH] D147165: [Windows SEH] Fix catch+return crash for Windows -EHa

2023-03-29 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: tentzen, efriedma, victork1996.
Herald added subscribers: kbarton, nemanjai.
Herald added a project: All.
pengfei requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

This change also turns on -fasync-exceptions by default under -EHa
option due to the backend patch merged.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147165

Files:
  clang/lib/CodeGen/CGCleanup.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions 
-fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S 
-emit-llvm %s -o - | FileCheck %s
+
+// CHECK: define dso_local void @"?foo@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK-NOT: llvm.seh.scope.begin
+// CHECK-NOT: llvm.seh.scope.end
+
+// FIXME: Do we actually need llvm.seh.scope*?
+void foo() {
+  try {}
+  catch (...) {
+  return;
+  }
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7700,6 +7700,8 @@
 if (types::isCXX(InputType))
   CmdArgs.push_back("-fcxx-exceptions");
 CmdArgs.push_back("-fexceptions");
+if (EH.Asynch)
+  CmdArgs.push_back("-fasync-exceptions");
   }
   if (types::isCXX(InputType) && EH.Synch && EH.NoUnwindC)
 CmdArgs.push_back("-fexternc-nounwind");
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -836,7 +836,7 @@
   EmitBlock(NormalEntry);
 
   // intercept normal cleanup to mark SEH scope end
-  if (IsEHa) {
+  if (IsEHa && getInvokeDest()) {
 if (Personality.isMSVCXXPersonality())
   EmitSehCppScopeEnd();
 else


Index: clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
===
--- /dev/null
+++ clang/test/CodeGen/windows-seh-EHa-CppCatchReturn.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions -fms-extensions -x c++ -Wno-implicit-function-declaration -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: define dso_local void @"?foo@@YAXXZ
+// CHECK: invoke void @llvm.seh.try.begin()
+// CHECK-NOT: llvm.seh.scope.begin
+// CHECK-NOT: llvm.seh.scope.end
+
+// FIXME: Do we actually need llvm.seh.scope*?
+void foo() {
+  try {}
+  catch (...) {
+  return;
+  }
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7700,6 +7700,8 @@
 if (types::isCXX(InputType))
   CmdArgs.push_back("-fcxx-exceptions");
 CmdArgs.push_back("-fexceptions");
+if (EH.Asynch)
+  CmdArgs.push_back("-fasync-exceptions");
   }
   if (types::isCXX(InputType) && EH.Synch && EH.NoUnwindC)
 CmdArgs.push_back("-fexternc-nounwind");
Index: clang/lib/CodeGen/CGCleanup.cpp
===
--- clang/lib/CodeGen/CGCleanup.cpp
+++ clang/lib/CodeGen/CGCleanup.cpp
@@ -836,7 +836,7 @@
   EmitBlock(NormalEntry);
 
   // intercept normal cleanup to mark SEH scope end
-  if (IsEHa) {
+  if (IsEHa && getInvokeDest()) {
 if (Personality.isMSVCXXPersonality())
   EmitSehCppScopeEnd();
 else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145815: [Flang][Driver] Add support for fopenmp-is-device and fembed-offload-object to Flang ToolChain

2023-03-29 Thread Jean Perier via Phabricator via cfe-commits
jeanPerier added a comment.



> Hi @jeanPerier,
>
> Thank you! I noticed this today as well and I'm currently looking into it, i 
> have a fix upcoming, just forcing another patch 
> (https://reviews.llvm.org/D144896) to test it via buildbot as I have no easy 
> access to a windows machine to test it at the moment, and yes @jhuber6 and 
> you are correct I believe, it appears to be the .exe suffix on windows! I'll 
> submit the fix as soon as it clears the buildbot.

Thanks a lot for fixing the issue!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145815

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


[PATCH] D126735: [clang-tidy] Silence modernize-redundant-void-arg in the case of vexing parses

2023-03-29 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added inline comments.
Herald added a reviewer: njames93.
Herald added a subscriber: PiotrZSL.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp:596
+
+// Explicitly specifying `(void)` is a way to sidestep -Wvexing-parse, so we
+// should not warn about it here.

This is not the only way to eliminate the vexing parse warning.  For instance, 
if the intention is to declare `foo` as a function not in this translation 
unit, then:

```
void most_vexing_parse() {
  extern int foo();
}
```
does the trick.

Why assume that the only way to fix vexing-parse is to add `(void)`?


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

https://reviews.llvm.org/D126735

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


[clang] 98ea471 - Properly Propagate RecoveryExpr through RequiresExpr

2023-03-29 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2023-03-29T09:04:59-07:00
New Revision: 98ea4712828b0802c99b3e8a6808cdc908f5b5b9

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

LOG: Properly Propagate RecoveryExpr through RequiresExpr

Commit 3d7946c58 implemented a DR that allowed us to error in a case
where an ill-formedness in a RequiresExpr is diagnosed as a satisfaction
failure.  However, it failed to cover cases where the RequiresExpr had
Requirements that failed for similar reasons.

This patch propagates the RecoveryExpr "containsErrors" correctly
through RequiresExpr.

Fixes: #61776

Added: 


Modified: 
clang/lib/AST/ExprConcepts.cpp
clang/test/CXX/drs/dr25xx.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConcepts.cpp b/clang/lib/AST/ExprConcepts.cpp
index fc8f1eb2abf14..a8a35d73815f9 100644
--- a/clang/lib/AST/ExprConcepts.cpp
+++ b/clang/lib/AST/ExprConcepts.cpp
@@ -112,6 +112,19 @@ 
concepts::ExprRequirement::ReturnTypeRequirement::getTypeConstraint() const {
   ->getTypeConstraint();
 }
 
+// Search through the requirements, and see if any have a RecoveryExpr in it,
+// which means this RequiresExpr ALSO needs to be invalid.
+static bool RequirementContainsError(concepts::Requirement *R) {
+  if (auto *ExprReq = dyn_cast(R))
+return ExprReq->getExpr() && ExprReq->getExpr()->containsErrors();
+
+  if (auto *NestedReq = dyn_cast(R))
+return !NestedReq->hasInvalidConstraint() &&
+   NestedReq->getConstraintExpr() &&
+   NestedReq->getConstraintExpr()->containsErrors();
+  return false;
+}
+
 RequiresExpr::RequiresExpr(ASTContext &C, SourceLocation RequiresKWLoc,
RequiresExprBodyDecl *Body,
ArrayRef LocalParameters,
@@ -138,6 +151,9 @@ RequiresExpr::RequiresExpr(ASTContext &C, SourceLocation 
RequiresKWLoc,
   if (!RequiresExprBits.IsSatisfied)
 break;
 }
+
+if (RequirementContainsError(R))
+  setDependence(getDependence() | ExprDependence::Error);
   }
   std::copy(LocalParameters.begin(), LocalParameters.end(),
 getTrailingObjects());

diff  --git a/clang/test/CXX/drs/dr25xx.cpp b/clang/test/CXX/drs/dr25xx.cpp
index 0800adda63928..28ebda22a8017 100644
--- a/clang/test/CXX/drs/dr25xx.cpp
+++ b/clang/test/CXX/drs/dr25xx.cpp
@@ -75,4 +75,25 @@ namespace dr2565 { // dr2565: 16 open
   // expected-error@-1{{constraints not satisfied for class template 
'VariadicStruct'}}
   // expected-note@#VSREQ{{because 'Variadic' 
evaluated to false}}
   // expected-note@#VC{{because 'b' would be invalid: argument may not have 
'void' type}}
+
+  template
+  // expected-error@+1 {{unknown type name 'ErrorRequires'}}
+  concept ErrorRequires = requires (ErrorRequires auto x) {
+x;
+  };
+  static_assert(ErrorRequires);
+  // expected-error@-1{{static assertion failed}}
+  // expected-note@-2{{because substituted constraint expression is 
ill-formed: constraint depends on a previously diagnosed expression}}
+
+  template
+  // expected-error@+2 {{unknown type name 'NestedErrorInRequires'}}
+  concept NestedErrorInRequires = requires (T x) {
+requires requires (NestedErrorInRequires auto y) {
+  y;
+};
+  };
+  static_assert(NestedErrorInRequires);
+  // expected-error@-1{{static assertion failed}}
+  // expected-note@-2{{because substituted constraint expression is 
ill-formed: constraint depends on a previously diagnosed expression}}
+
 }



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


[PATCH] D146412: [NFC] Fix potential for use-after-free in DumpModuleInfoAction

2023-03-29 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: lldb/source/Commands/CommandObjectTarget.cpp:2182-2183
 
-clang::DumpModuleInfoAction dump_module_info;
-dump_module_info.OutputStream = &result.GetOutputStream().AsRawOstream();
+std::shared_ptr Out(
+&result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+clang::DumpModuleInfoAction dump_module_info(Out);

Use of `std::shared_ptr` with a deleter that doesn't do anything is unusual; I 
think this deserves a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146412

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


[clang-tools-extra] 498c885 - [clang-tidy] Fix if-constexpr false-positive in readability-misleading-indentation

2023-03-29 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-03-29T16:08:54Z
New Revision: 498c88563b7f6379d9e6ae4d89d182756fa1c0bc

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

LOG: [clang-tidy] Fix if-constexpr false-positive in 
readability-misleading-indentation

When  depend on template parameter,
compiler can use NullStmt instead of CompoundStmt.
This causes issues as we losing information about
end location of that Stmt. To avoid this issue
check now ignores ifStmt with NullStmt on true-branch.

Fixes: https://github.com/llvm/llvm-project/issues/61435

Reviewed By: carlosgalvezp

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
index 4c10b6f6eebe0..2c011f5c0e690 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -104,7 +104,8 @@ void MisleadingIndentationCheck::missingBracesCheck(const 
SourceManager &SM,
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(unless(hasThen(nullStmt())), hasElse(stmt())).bind("if"), this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 03ba9e160b738..413f8925aec2c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,10 @@ Changes in existing checks
   magic numbers in type aliases such as ``using`` and ``typedef`` declarations 
if
   the new ``IgnoreTypeAliases`` option is set to true.
 
+- Fixed a false positive in :doc:`readability-misleading-indentation
+  ` check when warning 
would
+  be unnecessarily emitted for template dependent ``if constexpr``.
+
 - Fixed a false positive in :doc:`cppcoreguidelines-slicing
   ` check when warning would be
   emitted in constructor for virtual base class initialization.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp
new file mode 100644
index 0..31e3893a3e70b
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s 
readability-misleading-indentation %t -- -- -fno-delayed-template-parsing
+
+namespace PR61435 {
+
+template
+constexpr auto lam_correct = []{
+  if constexpr (N == 1) {
+  } else {
+  }
+};
+
+template
+constexpr auto lam_incorrect = []{
+  if constexpr (N == 1) {
+  }
+   else {
+  }
+  // CHECK-MESSAGES: :[[@LINE-2]]:4: warning: 
diff erent indentation for 'if' and corresponding 'else' 
[readability-misleading-indentation]
+};
+
+void test() {
+  lam_correct<1>();
+  lam_correct<2>();
+
+  lam_incorrect<1>();
+  lam_incorrect<2>();
+}
+
+}



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


[PATCH] D146887: [clang-tidy] Fix if-constexpr false-positive in readability-misleading-indentation

2023-03-29 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG498c88563b7f: [clang-tidy] Fix if-constexpr false-positive 
in readability-misleading… (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146887

Files:
  clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s 
readability-misleading-indentation %t -- -- -fno-delayed-template-parsing
+
+namespace PR61435 {
+
+template
+constexpr auto lam_correct = []{
+  if constexpr (N == 1) {
+  } else {
+  }
+};
+
+template
+constexpr auto lam_incorrect = []{
+  if constexpr (N == 1) {
+  }
+   else {
+  }
+  // CHECK-MESSAGES: :[[@LINE-2]]:4: warning: different indentation for 'if' 
and corresponding 'else' [readability-misleading-indentation]
+};
+
+void test() {
+  lam_correct<1>();
+  lam_correct<2>();
+
+  lam_incorrect<1>();
+  lam_incorrect<2>();
+}
+
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,10 @@
   magic numbers in type aliases such as ``using`` and ``typedef`` declarations 
if
   the new ``IgnoreTypeAliases`` option is set to true.
 
+- Fixed a false positive in :doc:`readability-misleading-indentation
+  ` check when warning 
would
+  be unnecessarily emitted for template dependent ``if constexpr``.
+
 - Fixed a false positive in :doc:`cppcoreguidelines-slicing
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -104,7 +104,8 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(unless(hasThen(nullStmt())), hasElse(stmt())).bind("if"), this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),


Index: clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation-cpp17.cpp
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s readability-misleading-indentation %t -- -- -fno-delayed-template-parsing
+
+namespace PR61435 {
+
+template
+constexpr auto lam_correct = []{
+  if constexpr (N == 1) {
+  } else {
+  }
+};
+
+template
+constexpr auto lam_incorrect = []{
+  if constexpr (N == 1) {
+  }
+   else {
+  }
+  // CHECK-MESSAGES: :[[@LINE-2]]:4: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+};
+
+void test() {
+  lam_correct<1>();
+  lam_correct<2>();
+
+  lam_incorrect<1>();
+  lam_incorrect<2>();
+}
+
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,10 @@
   magic numbers in type aliases such as ``using`` and ``typedef`` declarations if
   the new ``IgnoreTypeAliases`` option is set to true.
 
+- Fixed a false positive in :doc:`readability-misleading-indentation
+  ` check when warning would
+  be unnecessarily emitted for template dependent ``if constexpr``.
+
 - Fixed a false positive in :doc:`cppcoreguidelines-slicing
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -104,7 +104,8 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(unless(hasThen(nullStmt())), hasElse(stmt())).bind("if"), this);
   Finder->addMatcher

[PATCH] D146604: [NFC] Fix uninitalized member variable use in ASTReader::ParseTargetOptions()

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

Changes look good to me. Thanks, Sindhu!


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

https://reviews.llvm.org/D146604

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


[PATCH] D146678: Summary: Fix ArgsAsWritten being null for ConceptSpecializationExpr in certain circumstances when parsing ASTs

2023-03-29 Thread Walter Gray via Phabricator via cfe-commits
yeswalrus added a comment.

"Walter Gray"
Thank you, and sorry about the back and forth.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146678

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


[PATCH] D143704: [flang] Feature list plugin

2023-03-29 Thread Ethan Luis McDonough via Phabricator via cfe-commits
elmcdonough updated this revision to Diff 509395.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143704

Files:
  flang/examples/CMakeLists.txt
  flang/examples/FeatureList/CMakeLists.txt
  flang/examples/FeatureList/FeatureList.cpp
  flang/test/CMakeLists.txt
  flang/test/Examples/feature-list-class.f90
  flang/test/Examples/feature-list-functions.f90

Index: flang/test/Examples/feature-list-functions.f90
===
--- /dev/null
+++ flang/test/Examples/feature-list-functions.f90
@@ -0,0 +1,76 @@
+! UNSUPPORTED: system-windows
+! REQUIRES: plugins, shell, examples
+
+! RUN: %flang_fc1 -load %llvmshlibdir/flangFeatureList%pluginext \
+! RUN:-plugin feature-list %s 2>&1 | FileCheck %s
+
+program list_features_test
+implicit none
+call test_sub(test_func(2, 3), 4)
+contains
+subroutine test_sub(a, b)
+integer, intent(in) :: a, b
+print "(I0)", a + b
+end subroutine
+
+integer function test_func(a, b)
+integer, intent(in) :: a, b
+test_func = a * b
+end function
+end program list_features_test
+
+! CHECK: Name: 19
+! CHECK-NEXT: Expr: 11
+! CHECK-NEXT: DataRef: 5
+! CHECK-NEXT: Designator: 5
+! CHECK-NEXT: ActualArg: 4
+! CHECK-NEXT: ActualArgSpec: 4
+! CHECK-NEXT: EntityDecl: 4
+! CHECK-NEXT: LiteralConstant: 4
+! CHECK-NEXT: ActionStmt: 3
+! CHECK-NEXT: Block: 3
+! CHECK-NEXT: DeclarationTypeSpec: 3
+! CHECK-NEXT: ExecutableConstruct: 3
+! CHECK-NEXT: ExecutionPart: 3
+! CHECK-NEXT: ExecutionPartConstruct: 3
+! CHECK-NEXT: ImplicitPart: 3
+! CHECK-NEXT: IntLiteralConstant: 3
+! CHECK-NEXT: IntegerTypeSpec: 3
+! CHECK-NEXT: IntrinsicTypeSpec: 3
+! CHECK-NEXT: SpecificationPart: 3
+! CHECK-NEXT: AttrSpec: 2
+! CHECK-NEXT: Call: 2
+! CHECK-NEXT: DeclarationConstruct: 2
+! CHECK-NEXT: DummyArg: 2
+! CHECK-NEXT: IntentSpec: 2
+! CHECK-NEXT: IntentSpec::Intent: 2
+! CHECK-NEXT: InternalSubprogram: 2
+! CHECK-NEXT: ProcedureDesignator: 2
+! CHECK-NEXT: SpecificationConstruct: 2
+! CHECK-NEXT: TypeDeclarationStmt: 2
+! CHECK-NEXT: AssignmentStmt: 1
+! CHECK-NEXT: CallStmt: 1
+! CHECK-NEXT: CharLiteralConstant: 1
+! CHECK-NEXT: ContainsStmt: 1
+! CHECK-NEXT: EndFunctionStmt: 1
+! CHECK-NEXT: EndProgramStmt: 1
+! CHECK-NEXT: EndSubroutineStmt: 1
+! CHECK-NEXT: Expr::Add: 1
+! CHECK-NEXT: Expr::Multiply: 1
+! CHECK-NEXT: Format: 1
+! CHECK-NEXT: FunctionReference: 1
+! CHECK-NEXT: FunctionStmt: 1
+! CHECK-NEXT: FunctionSubprogram: 1
+! CHECK-NEXT: ImplicitPartStmt: 1
+! CHECK-NEXT: ImplicitStmt: 1
+! CHECK-NEXT: InternalSubprogramPart: 1
+! CHECK-NEXT: MainProgram: 1
+! CHECK-NEXT: OutputItem: 1
+! CHECK-NEXT: PrefixSpec: 1
+! CHECK-NEXT: PrintStmt: 1
+! CHECK-NEXT: Program: 1
+! CHECK-NEXT: ProgramStmt: 1
+! CHECK-NEXT: ProgramUnit: 1
+! CHECK-NEXT: SubroutineStmt: 1
+! CHECK-NEXT: SubroutineSubprogram: 1
+! CHECK-NEXT: Variable: 1
Index: flang/test/Examples/feature-list-class.f90
===
--- /dev/null
+++ flang/test/Examples/feature-list-class.f90
@@ -0,0 +1,88 @@
+! UNSUPPORTED: system-windows
+! REQUIRES: plugins, shell, examples
+
+! RUN: %flang_fc1 -load %llvmshlibdir/flangFeatureList%pluginext \
+! RUN:-plugin feature-list %s 2>&1 | FileCheck %s
+
+module list_features_test
+implicit none
+
+type :: test_class_1
+integer :: a
+real :: b
+contains
+procedure :: sum => sum_test_class_1
+procedure :: set => set_values_test_class_1
+end type
+contains
+real function sum_test_class_1(self)
+class(test_class_1), intent(in) :: self
+sum_test_class_1 = self%a + self%b
+end function
+
+subroutine set_values_test_class_1(self, a, b)
+class(test_class_1), intent(out) :: self
+integer, intent(in) :: a, b
+self%a = a
+self%b = b
+end subroutine
+end module list_features_test
+
+! CHECK: Name: 32
+! CHECK-NEXT: DataRef: 11
+! CHECK-NEXT: Designator: 7
+! CHECK-NEXT: DeclarationTypeSpec: 6
+! CHECK-NEXT: Expr: 5
+! CHECK-NEXT: DeclarationConstruct: 4
+! CHECK-NEXT: EntityDecl: 4
+! CHECK-NEXT: IntrinsicTypeSpec: 4
+! CHECK-NEXT: SpecificationConstruct: 4
+! CHECK-NEXT: StructureComponent: 4
+! CHECK-NEXT: ActionStmt: 3
+! CHECK-NEXT: AssignmentStmt: 3
+! CHECK-NEXT: AttrSpec: 3
+! CHECK-NEXT: DummyArg: 3
+! CHECK-NEXT: ExecutableConstruct: 3
+! CHECK-NEXT: ExecutionPartConstruct: 3
+! CHECK-NEXT: ImplicitPart: 3
+! CHECK-NEXT: IntentSpec: 3
+! CHECK-NEXT: IntentSpec::Intent: 3
+! CHECK-NEXT: SpecificationPart: 3
+! CHECK-NEXT: TypeDeclarationStmt: 3
+! CHECK-NEXT: Variable: 3
+! CHECK-NEXT: Block: 2
+! CHECK-NEXT: ComponentDecl: 2
+! CHECK-NEXT: ComponentDefStmt: 2
+! CHECK-NEXT: ComponentOrFill: 2
+! CHECK-NEXT: ContainsStmt: 2
+! CHECK-NEXT: DataComponentDefStmt: 2
+! CHECK-NEXT: DeclarationTypeSpec::Class: 2
+! CHECK-NEXT: DerivedTypeS

[clang] 6f2a865 - [NFC] Fix uninitalized member variable use in ASTReader::ParseTargetOptions()

2023-03-29 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-03-29T09:29:14-07:00
New Revision: 6f2a865d2f6bc426a61939a0a1acfcb25d5c1a18

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

LOG: [NFC] Fix uninitalized member variable use in 
ASTReader::ParseTargetOptions()

Added: 


Modified: 
clang/include/clang/Basic/TargetOptions.h

Removed: 




diff  --git a/clang/include/clang/Basic/TargetOptions.h 
b/clang/include/clang/Basic/TargetOptions.h
index f9e5cedbafcd1..9197282f3b566 100644
--- a/clang/include/clang/Basic/TargetOptions.h
+++ b/clang/include/clang/Basic/TargetOptions.h
@@ -45,7 +45,7 @@ class TargetOptions {
   std::string ABI;
 
   /// The EABI version to use
-  llvm::EABI EABIVersion;
+  llvm::EABI EABIVersion = llvm::EABI::Default;
 
   /// If given, the version string of the linker in use.
   std::string LinkerVersion;
@@ -88,7 +88,7 @@ class TargetOptions {
 COV_5 = 500,
   };
   /// \brief Code object version for AMDGPU.
-  CodeObjectVersionKind CodeObjectVersion;
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
 
   // The code model to be used as specified by the user. Corresponds to
   // CodeModel::Model enum defined in include/llvm/Support/CodeGen.h, plus



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


[clang] bbc204b - [PS4][clang] Limit ThinLTO parallelism when requested

2023-03-29 Thread Matthew Voss via cfe-commits

Author: Matthew Voss
Date: 2023-03-29T09:36:46-07:00
New Revision: bbc204b944eea829a029268fff37faabdf61fcaf

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

LOG: [PS4][clang] Limit ThinLTO parallelism when requested

Pass the correct option to the linker when "-flto-jobs=" is passed to
the driver.

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/test/Driver/lto-jobs.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index b3e14618f307e..8c8b7c73c1bf5 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -187,6 +187,12 @@ void tools::PScpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   AddCodeGenFlag(Twine("-crash-diagnostics-dir=") + A->getValue());
   }
 
+  if (IsPS5 && UseLTO) {
+StringRef Parallelism = getLTOParallelism(Args, D);
+if (!Parallelism.empty())
+  CmdArgs.push_back(Args.MakeArgString("-plugin-opt=jobs=" + Parallelism));
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 

diff  --git a/clang/test/Driver/lto-jobs.c b/clang/test/Driver/lto-jobs.c
index c28d0ad300f4e..443f8abced788 100644
--- a/clang/test/Driver/lto-jobs.c
+++ b/clang/test/Driver/lto-jobs.c
@@ -3,6 +3,9 @@
 // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -flto-jobs=5 2> 
%t
 // RUN: FileCheck -check-prefix=CHECK-LINK-THIN-JOBS-ACTION < %t %s
 //
+// RUN: %clang -target x86_64-sie-ps5 -### %s -flto=thin -flto-jobs=5 2> %t
+// RUN: FileCheck -check-prefix=CHECK-LINK-THIN-JOBS-ACTION < %t %s
+//
 // CHECK-LINK-THIN-JOBS-ACTION: "-plugin-opt=jobs=5"
 
 // RUN: %clang -target x86_64-apple-darwin13.3.0 -### %s -flto=thin 
-flto-jobs=5 2> %t



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


[PATCH] D146604: [NFC] Fix uninitalized member variable use in ASTReader::ParseTargetOptions()

2023-03-29 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir added a comment.

Thank you, @aaron.ballman and @tahonermann  for your comments!
This was committed to https://github.com/llvm/llvm-project.git with hash 
6f2a865d2f6bc426a61939a0a1acfcb25d5c1a18 



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

https://reviews.llvm.org/D146604

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


[PATCH] D146678: Summary: Fix ArgsAsWritten being null for ConceptSpecializationExpr in certain circumstances when parsing ASTs

2023-03-29 Thread Erich Keane 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 rG1f48a1fce235: Fix ArgsAsWritten being null for 
ConceptSpecializationExpr in certain (authored by yeswalrus, committed by 
erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D146678?vs=509175&id=509402#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146678

Files:
  clang/include/clang/AST/ExprConcepts.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ExprConcepts.cpp
  clang/test/PCH/cxx2a-constraints.cpp


Index: clang/test/PCH/cxx2a-constraints.cpp
===
--- clang/test/PCH/cxx2a-constraints.cpp
+++ clang/test/PCH/cxx2a-constraints.cpp
@@ -26,6 +26,8 @@
 
 void j(SizedLike auto ...ints) {}
 
+template class P> struct S1 { };
+
 #else /*included pch*/
 
 int main() {
Index: clang/lib/AST/ExprConcepts.cpp
===
--- clang/lib/AST/ExprConcepts.cpp
+++ clang/lib/AST/ExprConcepts.cpp
@@ -72,13 +72,14 @@
 
 ConceptSpecializationExpr::ConceptSpecializationExpr(
 const ASTContext &C, ConceptDecl *NamedConcept,
+const ASTTemplateArgumentListInfo *ArgsAsWritten,
 ImplicitConceptSpecializationDecl *SpecDecl,
 const ConstraintSatisfaction *Satisfaction, bool Dependent,
 bool ContainsUnexpandedParameterPack)
 : Expr(ConceptSpecializationExprClass, C.BoolTy, VK_PRValue, OK_Ordinary),
   ConceptReference(NestedNameSpecifierLoc(), SourceLocation(),
DeclarationNameInfo(), NamedConcept, NamedConcept,
-   nullptr),
+   ArgsAsWritten),
   SpecDecl(SpecDecl),
   Satisfaction(Satisfaction
? ASTConstraintSatisfaction::Create(C, *Satisfaction)
@@ -95,12 +96,13 @@
 
 ConceptSpecializationExpr *ConceptSpecializationExpr::Create(
 const ASTContext &C, ConceptDecl *NamedConcept,
+const ASTTemplateArgumentListInfo *ArgsAsWritten,
 ImplicitConceptSpecializationDecl *SpecDecl,
 const ConstraintSatisfaction *Satisfaction, bool Dependent,
 bool ContainsUnexpandedParameterPack) {
-  return new (C)
-  ConceptSpecializationExpr(C, NamedConcept, SpecDecl, Satisfaction,
-Dependent, ContainsUnexpandedParameterPack);
+  return new (C) ConceptSpecializationExpr(C, NamedConcept, ArgsAsWritten,
+   SpecDecl, Satisfaction, Dependent,
+   ContainsUnexpandedParameterPack);
 }
 
 const TypeConstraint *
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -840,7 +840,8 @@
   CSE->getNamedConcept()->getLocation(), NewConverted);
 
   Expr *NewIDC = ConceptSpecializationExpr::Create(
-  C, CSE->getNamedConcept(), CSD, nullptr, CSE->isInstantiationDependent(),
+  C, CSE->getNamedConcept(), CSE->getTemplateArgsAsWritten(), CSD,
+  /*Satisfaction=*/nullptr, CSE->isInstantiationDependent(),
   CSE->containsUnexpandedParameterPack());
 
   if (auto *OrigFold = dyn_cast(IDC))
Index: clang/include/clang/AST/ExprConcepts.h
===
--- clang/include/clang/AST/ExprConcepts.h
+++ clang/include/clang/AST/ExprConcepts.h
@@ -64,6 +64,7 @@
 const ConstraintSatisfaction *Satisfaction);
 
   ConceptSpecializationExpr(const ASTContext &C, ConceptDecl *NamedConcept,
+const ASTTemplateArgumentListInfo *ArgsAsWritten,
 ImplicitConceptSpecializationDecl *SpecDecl,
 const ConstraintSatisfaction *Satisfaction,
 bool Dependent,
@@ -81,6 +82,7 @@
 
   static ConceptSpecializationExpr *
   Create(const ASTContext &C, ConceptDecl *NamedConcept,
+ const ASTTemplateArgumentListInfo *ArgsAsWritten,
  ImplicitConceptSpecializationDecl *SpecDecl,
  const ConstraintSatisfaction *Satisfaction, bool Dependent,
  bool ContainsUnexpandedParameterPack);


Index: clang/test/PCH/cxx2a-constraints.cpp
===
--- clang/test/PCH/cxx2a-constraints.cpp
+++ clang/test/PCH/cxx2a-constraints.cpp
@@ -26,6 +26,8 @@
 
 void j(SizedLike auto ...ints) {}
 
+template class P> struct S1 { };
+
 #else /*included pch*/
 
 int main() {
Index: clang/lib/AST/ExprConcepts.cpp
===
--- clang/lib/AST/ExprConcepts.cpp
+++ clang/lib/AST/ExprConcepts.cpp
@@ -72,13 +72,14 @@
 
 ConceptSpecializationExpr::ConceptSpecializationExpr(
 const ASTContext &C, ConceptDecl *NamedConcept,
+const ASTTemplateArgume

[clang] 1f48a1f - Fix ArgsAsWritten being null for ConceptSpecializationExpr in certain

2023-03-29 Thread Erich Keane via cfe-commits

Author: Walter Gray
Date: 2023-03-29T09:44:01-07:00
New Revision: 1f48a1fce23551cc24f5b598af5994f5cfc6b6d0

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

LOG: Fix ArgsAsWritten being null for ConceptSpecializationExpr in certain
circumstances when parsing ASTs

Fix ArgsAsWritten being null for ConceptSpecializationExpr in certain
circumstances when parsing ASTs

ASTStmtWriter::VisitConceptSpecializationExpr specifically expects
getTemplateArgsAsWritten() to return true, which it wasn't when parsed
by ASTContext.cpp in certain edge cases.

Fixes: #61486

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

Added: 


Modified: 
clang/include/clang/AST/ExprConcepts.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ExprConcepts.cpp
clang/test/PCH/cxx2a-constraints.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ExprConcepts.h 
b/clang/include/clang/AST/ExprConcepts.h
index f02c140c14c19..d900e980852b4 100644
--- a/clang/include/clang/AST/ExprConcepts.h
+++ b/clang/include/clang/AST/ExprConcepts.h
@@ -64,6 +64,7 @@ class ConceptSpecializationExpr final : public Expr, public 
ConceptReference {
 const ConstraintSatisfaction *Satisfaction);
 
   ConceptSpecializationExpr(const ASTContext &C, ConceptDecl *NamedConcept,
+const ASTTemplateArgumentListInfo *ArgsAsWritten,
 ImplicitConceptSpecializationDecl *SpecDecl,
 const ConstraintSatisfaction *Satisfaction,
 bool Dependent,
@@ -81,6 +82,7 @@ class ConceptSpecializationExpr final : public Expr, public 
ConceptReference {
 
   static ConceptSpecializationExpr *
   Create(const ASTContext &C, ConceptDecl *NamedConcept,
+ const ASTTemplateArgumentListInfo *ArgsAsWritten,
  ImplicitConceptSpecializationDecl *SpecDecl,
  const ConstraintSatisfaction *Satisfaction, bool Dependent,
  bool ContainsUnexpandedParameterPack);

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5196f1e3555ac..94b7d9978c148 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -840,7 +840,8 @@ canonicalizeImmediatelyDeclaredConstraint(const ASTContext 
&C, Expr *IDC,
   CSE->getNamedConcept()->getLocation(), NewConverted);
 
   Expr *NewIDC = ConceptSpecializationExpr::Create(
-  C, CSE->getNamedConcept(), CSD, nullptr, CSE->isInstantiationDependent(),
+  C, CSE->getNamedConcept(), CSE->getTemplateArgsAsWritten(), CSD,
+  /*Satisfaction=*/nullptr, CSE->isInstantiationDependent(),
   CSE->containsUnexpandedParameterPack());
 
   if (auto *OrigFold = dyn_cast(IDC))

diff  --git a/clang/lib/AST/ExprConcepts.cpp b/clang/lib/AST/ExprConcepts.cpp
index a8a35d73815f9..5698b78d193e5 100644
--- a/clang/lib/AST/ExprConcepts.cpp
+++ b/clang/lib/AST/ExprConcepts.cpp
@@ -72,13 +72,14 @@ ConceptSpecializationExpr 
*ConceptSpecializationExpr::Create(
 
 ConceptSpecializationExpr::ConceptSpecializationExpr(
 const ASTContext &C, ConceptDecl *NamedConcept,
+const ASTTemplateArgumentListInfo *ArgsAsWritten,
 ImplicitConceptSpecializationDecl *SpecDecl,
 const ConstraintSatisfaction *Satisfaction, bool Dependent,
 bool ContainsUnexpandedParameterPack)
 : Expr(ConceptSpecializationExprClass, C.BoolTy, VK_PRValue, OK_Ordinary),
   ConceptReference(NestedNameSpecifierLoc(), SourceLocation(),
DeclarationNameInfo(), NamedConcept, NamedConcept,
-   nullptr),
+   ArgsAsWritten),
   SpecDecl(SpecDecl),
   Satisfaction(Satisfaction
? ASTConstraintSatisfaction::Create(C, *Satisfaction)
@@ -95,12 +96,13 @@ ConceptSpecializationExpr::ConceptSpecializationExpr(
 
 ConceptSpecializationExpr *ConceptSpecializationExpr::Create(
 const ASTContext &C, ConceptDecl *NamedConcept,
+const ASTTemplateArgumentListInfo *ArgsAsWritten,
 ImplicitConceptSpecializationDecl *SpecDecl,
 const ConstraintSatisfaction *Satisfaction, bool Dependent,
 bool ContainsUnexpandedParameterPack) {
-  return new (C)
-  ConceptSpecializationExpr(C, NamedConcept, SpecDecl, Satisfaction,
-Dependent, ContainsUnexpandedParameterPack);
+  return new (C) ConceptSpecializationExpr(C, NamedConcept, ArgsAsWritten,
+   SpecDecl, Satisfaction, Dependent,
+   ContainsUnexpandedParameterPack);
 }
 
 const TypeConstraint *

diff  --git a/clang/test/PCH/cxx2a-constraints.cpp 
b/clang/test/PCH/cxx2a-constraints.cpp
index 3f3b5e536cc93..a7fd2a7816372 100644
--- a/clang/test/PCH/cxx2a-constraints.cpp
+++ b/clang/test/PCH/cxx2

  1   2   >