[PATCH] D133092: [clang] fix generation of .debug_aranges with LTO

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



Comment at: clang/test/Driver/debug-options-aranges.c:5
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s

Avoid legacy `-target `. Delete `-fuse-ld=lld` which is unneeded.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

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


[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-29 Thread Lu Weining 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 rGb7baddc7557e: [Clang][LoongArch] Add inline asm support for 
constraints k/m/ZB/ZC (authored by SixWeining).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134638

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/test/CodeGen/LoongArch/inline-asm-constraints.c
  llvm/include/llvm/IR/InlineAsm.h
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
  llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZB.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZC.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-k.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll

Index: llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
@@ -0,0 +1,145 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA32
+; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA64
+
+define i32 @m_offset_neg_2049(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_2049:
+; LA32:   # %bb.0:
+; LA32-NEXT:lu12i.w $a1, -1
+; LA32-NEXT:ori $a1, $a1, 2047
+; LA32-NEXT:add.w $a0, $a0, $a1
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, 0
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_2049:
+; LA64:   # %bb.0:
+; LA64-NEXT:lu12i.w $a1, -1
+; LA64-NEXT:ori $a1, $a1, 2047
+; LA64-NEXT:add.d $a0, $a0, $a1
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, 0
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 -2049
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_neg_2048(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_2048:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, -2048
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_2048:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, -2048
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 -2048
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_neg_1(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_1:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, -1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_1:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, -1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 -1
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_0(ptr %p) nounwind {
+; LA32-LABEL: m_offset_0:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, 0
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_0:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, 0
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %p)
+  ret i32 %1
+}
+
+define i32 @m_offset_1(ptr %p) nounwind {
+; LA32-LABEL: m_offset_1:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, 1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_1:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, 1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 1
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_2047(ptr %p) nounwind {
+; LA32-LABEL: m_offset_2047:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, 2047
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_2047:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, 2047
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 2047
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_2048(ptr %p) nounwind {
+; LA32-LABEL: m_offset_2048:
+; LA32:   # %bb.0:
+; LA32-NEXT:ori $a1, $zero, 2048
+; LA32-NEXT:add.w $a0, $a0, $a1
+; LA32-NEXT:#AP

[clang] b7baddc - [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-29 Thread Weining Lu via cfe-commits

Author: Weining Lu
Date: 2022-09-29T15:02:08+08:00
New Revision: b7baddc7557e5c35a0f6a604a134d849265a99d4

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

LOG: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

k: A memory operand whose address is formed by a base register and
(optionally scaled) index register.

m: A memory operand whose address is formed by a base register and
offset that is suitable for use in instructions with the same
addressing mode as st.w and ld.w.

ZB: An address that is held in a general-purpose register. The offset
is zero.

ZC: A memory operand whose address is formed by a base register and
offset that is suitable for use in instructions with the same
addressing mode as ll.w and sc.w.

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

Added: 
llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZB.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZC.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint-k.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll

Modified: 
clang/lib/Basic/Targets/LoongArch.cpp
clang/lib/Basic/Targets/LoongArch.h
clang/test/CodeGen/LoongArch/inline-asm-constraints.c
llvm/include/llvm/IR/InlineAsm.h
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index cc93206dad686..1ad9c0fb8b495 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -67,14 +67,19 @@ bool LoongArchTargetInfo::validateAsmConstraint(
 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
   // See the GCC definitions here:
   // https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html
+  // Note that the 'm' constraint is handled in TargetInfo.
   switch (*Name) {
-  // TODO: handle 'k', 'm', "ZB", "ZC".
   default:
 return false;
   case 'f':
 // A floating-point register (if available).
 Info.setAllowsRegister();
 return true;
+  case 'k':
+// A memory operand whose address is formed by a base register and
+// (optionally scaled) index register.
+Info.setAllowsMemory();
+return true;
   case 'l':
 // A signed 16-bit constant.
 Info.setRequiresImmediate(-32768, 32767);
@@ -87,7 +92,36 @@ bool LoongArchTargetInfo::validateAsmConstraint(
 // An unsigned 12-bit constant (for logic instructions).
 Info.setRequiresImmediate(0, 4095);
 return true;
+  case 'Z':
+// ZB: An address that is held in a general-purpose register. The offset is
+// zero.
+// ZC: A memory operand whose address is formed by a base register
+// and offset that is suitable for use in instructions with the same
+// addressing mode as ll.w and sc.w.
+if (Name[1] == 'C' || Name[1] == 'B') {
+  Info.setAllowsMemory();
+  ++Name; // Skip over 'Z'.
+  return true;
+}
+return false;
+  }
+}
+
+std::string
+LoongArchTargetInfo::convertConstraint(const char *&Constraint) const {
+  std::string R;
+  switch (*Constraint) {
+  case 'Z':
+// "ZC"/"ZB" are two-character constraints; add "^" hint for later
+// parsing.
+R = "^" + std::string(Constraint, 2);
+++Constraint;
+break;
+  default:
+R = TargetInfo::convertConstraint(Constraint);
+break;
   }
+  return R;
 }
 
 void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,

diff  --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index 5d711c6b1db4c..47ee2fc737752 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -55,6 +55,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 
   bool validateAsmConstraint(const char *&Name,
  TargetInfo::ConstraintInfo &Info) const override;
+  std::string convertConstraint(const char *&Constraint) const override;
 
   bool hasBitIntType() const override { return true; }
 };

diff  --git a/clang/test/CodeGen/LoongArch/inline-asm-constraints.c 
b/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
index 9c9c60e484930..d7d425ea0766f 100644
--- a/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
+++ b/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
@@ -15,6 +15,12 @@ void test_f(void) {
   asm volatile ("" :: "f"(d));
 }
 
+void test_k(int *p, int idx) {
+// CHECK-LABEL: define{{.*}} void @test_k(ptr noundef %p, i32 noundef{{.*}} 
%idx)
+// CHECK:

[PATCH] D134329: [clang-format][NFC] Reformat clang/lib/Format using 6257832bf94f

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

yeah I'm ok with that too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134329

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


[PATCH] D133092: [clang] fix generation of .debug_aranges with LTO

2022-09-29 Thread Azat Khuzhin via Phabricator via cfe-commits
azat added inline comments.



Comment at: clang/test/Driver/debug-options-aranges.c:5
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s

MaskRay wrote:
> Avoid legacy `-target `. Delete `-fuse-ld=lld` which is unneeded.
>Delete -fuse-ld=lld which is unneeded

I've tried without it and in some env it may try to use gold, which will not be 
available on CI and the test will fail.
Do you have suggestions on how to overcome this? Required gold so as ld? Or 
leaving `-fuse-ld=lld` is fine?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

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


[PATCH] D134852: [clang-format][NFC] Clean up class HeaderIncludes and Format.cpp

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



Comment at: clang/lib/Format/Format.cpp:2774
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";

Did I miss where this comes from now?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134852

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


[PATCH] D134337: [clang] [Driver] More flexible rules for loading default configs

2022-09-29 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff accepted this revision.
sepavloff added a comment.

LGTM.

Thanks!


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

https://reviews.llvm.org/D134337

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


[PATCH] D133092: [clang] fix generation of .debug_aranges with LTO

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



Comment at: clang/test/Driver/debug-options-aranges.c:5
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s

azat wrote:
> MaskRay wrote:
> > Avoid legacy `-target `. Delete `-fuse-ld=lld` which is unneeded.
> >Delete -fuse-ld=lld which is unneeded
> 
> I've tried without it and in some env it may try to use gold, which will not 
> be available on CI and the test will fail.
> Do you have suggestions on how to overcome this? Required gold so as ld? Or 
> leaving `-fuse-ld=lld` is fine?
`-###` does not run the command. This shall pass in any environment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

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


[clang-tools-extra] 4c862da - [clangd] Avoid using constructor/destructor of vector

2022-09-29 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-09-29T09:30:03+02:00
New Revision: 4c862da8d43f32bed7ad7e3b700e01d04b3b0f8d

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

LOG: [clangd] Avoid using constructor/destructor of vector

This is formally invalid, and causes build errors when building with
clang in -std=c++20.

http://eel.is/c%2B%2Bdraft/vector.overview#4

Added: 


Modified: 
clang-tools-extra/clangd/support/Markup.cpp
clang-tools-extra/clangd/support/Markup.h

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Markup.cpp 
b/clang-tools-extra/clangd/support/Markup.cpp
index 7f6eb31bcdd33..4d17a2bf2b2b8 100644
--- a/clang-tools-extra/clangd/support/Markup.cpp
+++ b/clang-tools-extra/clangd/support/Markup.cpp
@@ -393,6 +393,9 @@ void Paragraph::renderPlainText(llvm::raw_ostream &OS) 
const {
   OS << '\n';
 }
 
+BulletList::BulletList() = default;
+BulletList::~BulletList() = default;
+
 void BulletList::renderMarkdown(llvm::raw_ostream &OS) const {
   for (auto &D : Items) {
 // Instead of doing this we might prefer passing Indent to children to get

diff  --git a/clang-tools-extra/clangd/support/Markup.h 
b/clang-tools-extra/clangd/support/Markup.h
index 560071031e66a..3a869c49a2cbb 100644
--- a/clang-tools-extra/clangd/support/Markup.h
+++ b/clang-tools-extra/clangd/support/Markup.h
@@ -79,6 +79,9 @@ class Paragraph : public Block {
 /// list like format, e.g. by prepending with "- " and indentation.
 class BulletList : public Block {
 public:
+  BulletList();
+  ~BulletList();
+
   void renderMarkdown(llvm::raw_ostream &OS) const override;
   void renderPlainText(llvm::raw_ostream &OS) const override;
   std::unique_ptr clone() const override;



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


[PATCH] D134337: [clang] [Driver] More flexible rules for loading default configs

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



Comment at: clang/include/clang/Driver/Driver.h:758
+  /// Return the typical executable name for the specified driver \p Mode.
+  static const char *getExecutableForDriverMode(DriverMode Mode);
 };

This should be private



Comment at: clang/lib/Driver/Driver.cpp:1094
+  //(e.g. i386-pc-linux-gnu-clang++.cfg).
+  // 2. -.cfg using executable suffix
+  //(e.g. i386-pc-linux-gnu-clang-g++.cfg).

"executable suffix" is less clear. An example will help.



Comment at: clang/lib/Driver/Driver.cpp:1101
+
+  // Try loading full config (variants 1. and 2.)
   llvm::SmallString<128> CfgFilePath;

Mention "first part" ? (And what does "first part refer to")


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

https://reviews.llvm.org/D134337

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


[PATCH] D134790: [Driver] Add --config= as canonical spelling of --config

2022-09-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

I don't know the fancy option magic you're using here, I haven't tested it but 
it seems to make sense to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134790

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


[clang] 08af5ba - [Driver] Add --config= as canonical spelling of --config

2022-09-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-09-29T00:38:12-07:00
New Revision: 08af5ba3713523d9596a414e6a64b26494199fdd

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

LOG: [Driver] Add --config= as canonical spelling of --config

Driver options usually use `Joined` instead of `Separate`. It is also weird that
`--config-system-dir=`/etc exist while `--config=` did not exist.

Reviewed By: mgorny

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/test/Driver/config-file.c

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 9c0a916f1a10d..d4c66e661dac5 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -887,14 +887,14 @@ Configuration files can be either specified on the 
command line or loaded
 from default locations. If both variants are present, the default configuration
 files are loaded first.
 
-The command line option ``--config`` can be used to specify explicit
+The command line option ``--config=`` can be used to specify explicit
 configuration files in a Clang invocation. If the option is used multiple 
times,
 all specified files are loaded, in order. For example:
 
 ::
 
-clang --config /home/user/cfgs/testing.txt
-clang --config debug.cfg --config runtimes.cfg
+clang --config=/home/user/cfgs/testing.txt
+clang --config=debug.cfg --config=runtimes.cfg
 
 If the provided argument contains a directory separator, it is considered as
 a file path, and options are read from that file. Otherwise the argument is
@@ -966,7 +966,7 @@ configuration file.
 In cases where a configuration file is deployed alongside SDK contents, the
 SDK directory can remain fully portable by using  prefixed paths.
 In this way, the user may only need to specify a root configuration file with
-``--config`` to establish every aspect of the SDK with the compiler:
+``--config=`` to establish every aspect of the SDK with the compiler:
 
 ::
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 61ffaf9d04dbd..116a12065da77 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -900,8 +900,9 @@ def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, 
Group, Flags<[CC1Op
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, 
Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
-def config : Separate<["--"], "config">, Flags<[NoXarchOption, CoreOption]>,
-  HelpText<"Specifies configuration file">;
+def config : Joined<["--"], "config=">, Flags<[NoXarchOption, CoreOption]>, 
MetaVarName<"">,
+  HelpText<"Specify configuration file">;
+def : Separate<["--"], "config">, Alias;
 def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Disable loading default configuration files">;
 def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, CoreOption, HelpHidden]>,

diff  --git a/clang/test/Driver/config-file.c b/clang/test/Driver/config-file.c
index 5cb2e485e1787..9c8d5be575f3c 100644
--- a/clang/test/Driver/config-file.c
+++ b/clang/test/Driver/config-file.c
@@ -8,6 +8,7 @@
 //--- Config file (full path) in output of -###
 //
 // RUN: %clang --config %S/Inputs/config-1.cfg -S %s -### 2>&1 | FileCheck %s 
-check-prefix CHECK-HHH
+// RUN: %clang --config=%S/Inputs/config-1.cfg -S %s -### 2>&1 | FileCheck %s 
-check-prefix CHECK-HHH
 // CHECK-HHH: Configuration file: {{.*}}Inputs{{.}}config-1.cfg
 // CHECK-HHH: -Werror
 // CHECK-HHH: -std=c99



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


[PATCH] D134790: [Driver] Add --config= as canonical spelling of --config

2022-09-29 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG08af5ba37135: [Driver] Add --config= as canonical spelling 
of --config (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134790

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/test/Driver/config-file.c


Index: clang/test/Driver/config-file.c
===
--- clang/test/Driver/config-file.c
+++ clang/test/Driver/config-file.c
@@ -8,6 +8,7 @@
 //--- Config file (full path) in output of -###
 //
 // RUN: %clang --config %S/Inputs/config-1.cfg -S %s -### 2>&1 | FileCheck %s 
-check-prefix CHECK-HHH
+// RUN: %clang --config=%S/Inputs/config-1.cfg -S %s -### 2>&1 | FileCheck %s 
-check-prefix CHECK-HHH
 // CHECK-HHH: Configuration file: {{.*}}Inputs{{.}}config-1.cfg
 // CHECK-HHH: -Werror
 // CHECK-HHH: -std=c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -900,8 +900,9 @@
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, 
Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
-def config : Separate<["--"], "config">, Flags<[NoXarchOption, CoreOption]>,
-  HelpText<"Specifies configuration file">;
+def config : Joined<["--"], "config=">, Flags<[NoXarchOption, CoreOption]>, 
MetaVarName<"">,
+  HelpText<"Specify configuration file">;
+def : Separate<["--"], "config">, Alias;
 def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Disable loading default configuration files">;
 def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, CoreOption, HelpHidden]>,
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -887,14 +887,14 @@
 from default locations. If both variants are present, the default configuration
 files are loaded first.
 
-The command line option ``--config`` can be used to specify explicit
+The command line option ``--config=`` can be used to specify explicit
 configuration files in a Clang invocation. If the option is used multiple 
times,
 all specified files are loaded, in order. For example:
 
 ::
 
-clang --config /home/user/cfgs/testing.txt
-clang --config debug.cfg --config runtimes.cfg
+clang --config=/home/user/cfgs/testing.txt
+clang --config=debug.cfg --config=runtimes.cfg
 
 If the provided argument contains a directory separator, it is considered as
 a file path, and options are read from that file. Otherwise the argument is
@@ -966,7 +966,7 @@
 In cases where a configuration file is deployed alongside SDK contents, the
 SDK directory can remain fully portable by using  prefixed paths.
 In this way, the user may only need to specify a root configuration file with
-``--config`` to establish every aspect of the SDK with the compiler:
+``--config=`` to establish every aspect of the SDK with the compiler:
 
 ::
 


Index: clang/test/Driver/config-file.c
===
--- clang/test/Driver/config-file.c
+++ clang/test/Driver/config-file.c
@@ -8,6 +8,7 @@
 //--- Config file (full path) in output of -###
 //
 // RUN: %clang --config %S/Inputs/config-1.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-HHH
+// RUN: %clang --config=%S/Inputs/config-1.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-HHH
 // CHECK-HHH: Configuration file: {{.*}}Inputs{{.}}config-1.cfg
 // CHECK-HHH: -Werror
 // CHECK-HHH: -std=c99
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -900,8 +900,9 @@
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
-def config : Separate<["--"], "config">, Flags<[NoXarchOption, CoreOption]>,
-  HelpText<"Specifies configuration file">;
+def config : Joined<["--"], "config=">, Flags<[NoXarchOption, CoreOption]>, MetaVarName<"">,
+  HelpText<"Specify configuration file">;
+def : Separate<["--"], "config">, Alias;
 def no_default_config : Flag<["--"], "no-default-config">, Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Disable loading default configuration files">;
 def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, Flags<[NoXarchOption, CoreOption, HelpHidden]>,
Index: clang/docs/UsersManual.rst
===

[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-09-29 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel commandeered this revision.
rymiel added a reviewer: eoanermine.
rymiel added a comment.

Commandeering to finish the final nits as per 
https://github.com/llvm/llvm-project/issues/56283#issuecomment-1261653291


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-09-29 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 463772.
rymiel added a comment.

Resolve nits:

- Re-sorted uses of the name RequiresExpressionIndentationKind
- Updated version to be 16
- Add test for demonstrating indentation as subexpression
- Reformatted


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24984,6 +24984,123 @@
"bar(requires);");
 }
 
+TEST_F(FormatTest, RequiresExpressionIndentation) {
+  auto Style = getLLVMStyle();
+  EXPECT_EQ(Style.RequiresExpressionIndentation, FormatStyle::REI_Keyword);
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   " { t == v } -> std::same_as;\n"
+   "   };\n"
+   "};",
+   Style);
+
+  verifyFormat(
+  "template \n"
+  "void bar(T)\n"
+  "  requires Foo && requires(T t) {\n"
+  "   { t.foo() } -> std::same_as;\n"
+  " } && requires(T t) {\n"
+  "{ t.bar() } -> std::same_as;\n"
+  "--t;\n"
+  "  };",
+  Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "  --t;\n"
+   "}\n"
+   "void bar(T);",
+   Style);
+
+  verifyFormat("template  void f() {\n"
+   "  if constexpr (requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}) {\n"
+   "  }\n"
+   "}",
+   Style);
+
+  verifyFormat(
+  "template  void f() {\n"
+  "  if constexpr (condition && requires(T t) {\n"
+  "   { t.bar() } -> std::same_as;\n"
+  " }) {\n"
+  "  }\n"
+  "}",
+  Style);
+
+  verifyFormat("template  struct C {\n"
+   "  void f()\n"
+   "requires requires(T t) {\n"
+   "   { t.bar() } -> std::same_as;\n"
+   " };\n"
+   "};",
+   Style);
+
+  Style.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   "{ t == v } -> std::same_as;\n"
+   "  };\n"
+   "};",
+   Style);
+
+  verifyFormat("template \n"
+   "void bar(T)\n"
+   "  requires Foo && requires(T t) {\n"
+   "{ t.foo() } -> std::same_as;\n"
+   "  } && requires(T t) {\n"
+   "{ t.bar() } -> std::same_as;\n"
+   "--t;\n"
+   "  };",
+   Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   " { t.bar() } -> std::same_as;\n"
+   " --t;\n"
+   "   }\n"
+   "void bar(T);",
+   Style);
+
+  verifyFormat("template  void f() {\n"
+   "  if constexpr (requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}) {\n"
+   "  }\n"
+   "}",
+   Style);
+
+  verifyFormat("template  void f() {\n"
+   "  if constexpr (condition && requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}) {\n"
+   "  }\n"
+   "}",
+   Style);
+
+  verifyFormat("template  struct C {\n"
+   "  void f()\n"
+   "requires requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "};\n"
+   "};",
+   Style);
+}
+
 TEST_F(Form

[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-09-29 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 463773.
rymiel added a comment.

Missed a spot when re-sorting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24984,6 +24984,123 @@
"bar(requires);");
 }
 
+TEST_F(FormatTest, RequiresExpressionIndentation) {
+  auto Style = getLLVMStyle();
+  EXPECT_EQ(Style.RequiresExpressionIndentation, FormatStyle::REI_Keyword);
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   " { t == v } -> std::same_as;\n"
+   "   };\n"
+   "};",
+   Style);
+
+  verifyFormat(
+  "template \n"
+  "void bar(T)\n"
+  "  requires Foo && requires(T t) {\n"
+  "   { t.foo() } -> std::same_as;\n"
+  " } && requires(T t) {\n"
+  "{ t.bar() } -> std::same_as;\n"
+  "--t;\n"
+  "  };",
+  Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "  --t;\n"
+   "}\n"
+   "void bar(T);",
+   Style);
+
+  verifyFormat("template  void f() {\n"
+   "  if constexpr (requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}) {\n"
+   "  }\n"
+   "}",
+   Style);
+
+  verifyFormat(
+  "template  void f() {\n"
+  "  if constexpr (condition && requires(T t) {\n"
+  "   { t.bar() } -> std::same_as;\n"
+  " }) {\n"
+  "  }\n"
+  "}",
+  Style);
+
+  verifyFormat("template  struct C {\n"
+   "  void f()\n"
+   "requires requires(T t) {\n"
+   "   { t.bar() } -> std::same_as;\n"
+   " };\n"
+   "};",
+   Style);
+
+  Style.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
+
+  verifyFormat("template \n"
+   "concept C = requires(T t) {\n"
+   "  typename T::value;\n"
+   "  requires requires(typename T::value v) {\n"
+   "{ t == v } -> std::same_as;\n"
+   "  };\n"
+   "};",
+   Style);
+
+  verifyFormat("template \n"
+   "void bar(T)\n"
+   "  requires Foo && requires(T t) {\n"
+   "{ t.foo() } -> std::same_as;\n"
+   "  } && requires(T t) {\n"
+   "{ t.bar() } -> std::same_as;\n"
+   "--t;\n"
+   "  };",
+   Style);
+
+  verifyFormat("template \n"
+   "  requires Foo &&\n"
+   "   requires(T t) {\n"
+   " { t.foo() } -> std::same_as;\n"
+   "   } && requires(T t) {\n"
+   " { t.bar() } -> std::same_as;\n"
+   " --t;\n"
+   "   }\n"
+   "void bar(T);",
+   Style);
+
+  verifyFormat("template  void f() {\n"
+   "  if constexpr (requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}) {\n"
+   "  }\n"
+   "}",
+   Style);
+
+  verifyFormat("template  void f() {\n"
+   "  if constexpr (condition && requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}) {\n"
+   "  }\n"
+   "}",
+   Style);
+
+  verifyFormat("template  struct C {\n"
+   "  void f()\n"
+   "requires requires(T t) {\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "};\n"
+   "};",
+   Style);
+}
+
 TEST_F(FormatTest, StatementAttributeLikeMacros) {
   FormatStyle Style = getLLVMStyle();
   StringRef Source = "void Foo::slot() {\n"
Index: clang/lib/Format

[PATCH] D134728: [clangd] Add highlighting modifiers "constructor" and "destructor"

2022-09-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

TL;DR: let's go with this patch as-is rather than borrowing problems from the 
future. This enum isn't growing very rapidly.

In D134728#3822775 , @ckandeler wrote:

> In D134728#3822653 , @sammccall 
> wrote:
>
>> It doesn't scale very well though: we're limited to 30 modifiers in total, 
>> this patch brings us up to 16, if we followed this class.constructor 
>> precedent for function.operator, class.constructor.copy enum.scoped etc we 
>> could end up exhausting this.

BTW, I remembered the other idea that could eat a bunch of the modifiers: 
rainbow highlighting a la https://github.com/clangd/clangd/issues/889. The idea 
is you could encode e.g. an 8 bit hash of the symbol identity as the 
presence/absence of 8 modifiers. But we never shipped it, and I suspect 8 would 
be enough.

> In light of this (and assuming it really has to be this way)

FWIW the reason is that modifiers are encoded as an integer, and the spec says 
integers are <2^31-1 for interop purposes. (I'm not sure why they didn't go for 
2^53-1, everyone has either doubles or 64-bit integers right? sigh).

> would it make sense to introduce a generic modifier that changes its meaning 
> depending on the main highlighting kind? It would have the drawback of not 
> being self-documenting

Neat idea. That's workable at a technical level, but requires editors/themes to 
be pretty tightly coupled to this idiosyncracy of clangd. So I'm not sure it's 
a good fit for the loosely-coupled LSP ecosystem.

> but with the given constraints might just be a pragmatic solution

Yeah, however the constraints aren't very tight at this point, I was just 
thinking out loud a bit. Let's go for the simple thing for now - we may never 
need something cleverer, and if we do then we'll have more examples to drive 
the design. I think that's worth the potential breaking change.

>   // Class -> Constructor/Destructor

We'd need Generic1 and Generic2 so you can distinguish constructor/destructor 
right?
If the distinction isn't important, maybe we should add a single "constructor 
or destructor" modifier...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134728

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


[PATCH] D134824: Fix frint ACLE intrinsic names

2022-09-29 Thread JinGu Kang via Phabricator via cfe-commits
jaykang10 accepted this revision.
jaykang10 added a comment.
This revision is now accepted and ready to land.

Thanks for fixing it!
LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134824

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


[PATCH] D134685: Fix SourceManager::isBeforeInTranslationUnit bug with token-pasting

2022-09-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks for digging into the rabbit role and the great analysis. It looks good 
from my side.

Re the test case `ID(I TWO 3)` we discussed yesterday, I verified that there is 
no issue. (we don't merge the `1 2 3` into a single SLOCEntry, each one have a 
dedicated FileID, and FileID(2) < FileID(3)).

>> However I tried to avoid mixing these with subtle behavior changes, and will 
>> send a followup instead.
>
> D134694  if you're interested. I guess I 
> should try to get performance measures though...

While doing the review, I agree that this part of code is unnecessary 
complicated, I think doing cleanup is probably a good idea.




Comment at: clang/lib/Basic/SourceManager.cpp:2108
 // quit early. The other way round unfortunately remains suboptimal.
-  } while (LOffs.first != ROffs.first && !MoveUpIncludeHierarchy(LOffs, 
*this));
-  LocSet::iterator I;
-  while((I = LChain.find(ROffs.first)) == LChain.end()) {
-if (MoveUpIncludeHierarchy(ROffs, *this))
-  break; // Met at topmost file.
-  }
-  if (I != LChain.end())
-LOffs = *I;
+if (LOffs.first == ROffs.first)
+  break;

nit:  I found the first/second usage really hurts the code readability here 
(using the struct `Entry` int all places is probably better, but this requires 
some changes to the existing interface, no required action here).



Comment at: clang/lib/Basic/SourceManager.cpp:2126
+  // This changes the relative order of local vs loaded FileIDs, but it
+  // doesn't matter as these are never mixed in macro expansion.
+  unsigned LParent = I->second.ParentFID.ID;

maybe add an assertion for "local and load FileIDs  are never mixed".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134685

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


[clang] 04a65d6 - Revert D134638 "[Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC"

2022-09-29 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-09-29T00:54:56-07:00
New Revision: 04a65d62a0c67da0ee383c8f1d74dea6d8b83a7e

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

LOG: Revert D134638 "[Clang][LoongArch] Add inline asm support for constraints 
k/m/ZB/ZC"

This reverts commit b7baddc7557e5c35a0f6a604a134d849265a99d4.

Broke CodeGen/X86/callbr-asm-kill.mir
We shall pay attention when adding new constraints.

Added: 


Modified: 
clang/lib/Basic/Targets/LoongArch.cpp
clang/lib/Basic/Targets/LoongArch.h
clang/test/CodeGen/LoongArch/inline-asm-constraints.c
llvm/include/llvm/IR/InlineAsm.h
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.h

Removed: 
llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZB.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZC.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint-k.ll
llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll



diff  --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 1ad9c0fb8b495..cc93206dad686 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -67,19 +67,14 @@ bool LoongArchTargetInfo::validateAsmConstraint(
 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
   // See the GCC definitions here:
   // https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html
-  // Note that the 'm' constraint is handled in TargetInfo.
   switch (*Name) {
+  // TODO: handle 'k', 'm', "ZB", "ZC".
   default:
 return false;
   case 'f':
 // A floating-point register (if available).
 Info.setAllowsRegister();
 return true;
-  case 'k':
-// A memory operand whose address is formed by a base register and
-// (optionally scaled) index register.
-Info.setAllowsMemory();
-return true;
   case 'l':
 // A signed 16-bit constant.
 Info.setRequiresImmediate(-32768, 32767);
@@ -92,36 +87,7 @@ bool LoongArchTargetInfo::validateAsmConstraint(
 // An unsigned 12-bit constant (for logic instructions).
 Info.setRequiresImmediate(0, 4095);
 return true;
-  case 'Z':
-// ZB: An address that is held in a general-purpose register. The offset is
-// zero.
-// ZC: A memory operand whose address is formed by a base register
-// and offset that is suitable for use in instructions with the same
-// addressing mode as ll.w and sc.w.
-if (Name[1] == 'C' || Name[1] == 'B') {
-  Info.setAllowsMemory();
-  ++Name; // Skip over 'Z'.
-  return true;
-}
-return false;
-  }
-}
-
-std::string
-LoongArchTargetInfo::convertConstraint(const char *&Constraint) const {
-  std::string R;
-  switch (*Constraint) {
-  case 'Z':
-// "ZC"/"ZB" are two-character constraints; add "^" hint for later
-// parsing.
-R = "^" + std::string(Constraint, 2);
-++Constraint;
-break;
-  default:
-R = TargetInfo::convertConstraint(Constraint);
-break;
   }
-  return R;
 }
 
 void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,

diff  --git a/clang/lib/Basic/Targets/LoongArch.h 
b/clang/lib/Basic/Targets/LoongArch.h
index 47ee2fc737752..5d711c6b1db4c 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -55,7 +55,6 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public 
TargetInfo {
 
   bool validateAsmConstraint(const char *&Name,
  TargetInfo::ConstraintInfo &Info) const override;
-  std::string convertConstraint(const char *&Constraint) const override;
 
   bool hasBitIntType() const override { return true; }
 };

diff  --git a/clang/test/CodeGen/LoongArch/inline-asm-constraints.c 
b/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
index d7d425ea0766f..9c9c60e484930 100644
--- a/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
+++ b/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
@@ -15,12 +15,6 @@ void test_f(void) {
   asm volatile ("" :: "f"(d));
 }
 
-void test_k(int *p, int idx) {
-// CHECK-LABEL: define{{.*}} void @test_k(ptr noundef %p, i32 noundef{{.*}} 
%idx)
-// CHECK: call void asm sideeffect "", "*k"(ptr elementtype(i32) %{{.*}})
-  asm volatile("" :: "k"(*(p+idx)));
-}
-
 void test_l(void) {
 // CHECK-LABEL: define{{.*}} void @test_l()
 // CHECK: call void asm sideeffect "", "l"(i32 32767)
@@ -29,12 +23,6 @@ void test_l(void) {
   asm volatile ("" :: "l"(-32768));
 }
 
-void test_m(int *p) {
-// CHECK-LABEL: define{{.*}} void @test_m(ptr noundef %p)
-// 

[PATCH] D134728: [clangd] Add highlighting modifiers "constructor" and "destructor"

2022-09-29 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

In D134728#3822898 , @sammccall wrote:

> If the distinction isn't important, maybe we should add a single "constructor 
> or destructor" modifier...

No, it's not. I will update the patch accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134728

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


[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

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

`Constraint_k` somehow broke AArch64 and X86 inlineasm. Please run `check-llvm` 
for generic changes which may have farreaching effects to other targets.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134638

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


[PATCH] D133119: [clang-tidy] Add checker 'bugprone-suspicious-realloc-usage'.

2022-09-29 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 463776.
balazske added a comment.

added test, added a comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133119

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
@@ -0,0 +1,85 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-realloc-usage %t
+
+void *realloc(void *, __SIZE_TYPE__);
+
+namespace std {
+  using ::realloc;
+}
+
+namespace n1 {
+  void *p;
+}
+
+namespace n2 {
+  void *p;
+}
+
+struct P {
+  void *p;
+  void *q;
+  P *pp;
+  void *&f();
+};
+
+struct P1 {
+  static void *p;
+  static void *q;
+};
+
+template
+struct P2 {
+  static void *p;
+  static void *q;
+};
+
+template
+void templ(void *p) {
+  A::p = realloc(A::p, 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'A::p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+  p = realloc(A::p, 10);
+  A::q = realloc(A::p, 10);
+  A::p = realloc(B::p, 10);
+  P2::p = realloc(P2::p, 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'P2::p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+  P2::p = realloc(P2::p, 1);
+}
+
+void *&getPtr();
+P &getP();
+
+void warn(void *p, P *p1, int *pi) {
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  p = std::realloc(p, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  p1->p = realloc(p1->p, 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'p1->p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  p1->pp->p = realloc(p1->pp->p, 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'p1->pp->p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  pi = (int*)realloc(pi, 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'pi' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  templ>(p);
+}
+
+void no_warn(void *p, P *p1, P *p2) {
+  void *q = realloc(p, 10);
+  q = realloc(p, 10);
+  p1->q = realloc(p1->p, 10);
+  p2->p = realloc(p1->p, 20);
+  n1::p = realloc(n2::p, 30);
+  p1->pp->p = realloc(p1->p, 10);
+  getPtr() = realloc(getPtr(), 30);
+  getP().p = realloc(getP().p, 20);
+  p1->f() = realloc(p1->f(), 30);
+}
+
+void warn_if_copy_exists(void *p) {
+  void *q = p;
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -124,6 +124,7 @@
`bugprone-suspicious-memory-comparison `_,
`bugprone-suspicious-memset-usage `_, "Yes"
`bugprone-suspicious-missing-comma `_,
+   `bugprone-suspicious-realloc-usage `_,
`bugprone-suspicious-semicolon `_, "Yes"
`bugprone-suspicious-string-compare `_, "Yes"
`bugprone-swapped-arguments `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - bugprone-suspicious-realloc-usage
+
+bugprone-suspicious-realloc-usage
+=
+
+This check finds usages of ``realloc`` where the return value is assigned to the
+same expression as passed to the first argument:
+``p = realloc(p, size);``
+The problem with this construct is that if ``realloc`` fails it returns a
+null pointer but does 

[PATCH] D133092: [clang] fix generation of .debug_aranges with LTO

2022-09-29 Thread Azat Khuzhin via Phabricator via cfe-commits
azat updated this revision to Diff 463778.
azat added a comment.

Update the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/debug-options-aranges.c


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,7 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 
2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,14 @@
 CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+CmdArgs.push_back(
+Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 


Index: clang/test/Driver/debug-options-aranges.c
===
--- /dev/null
+++ clang/test/Driver/debug-options-aranges.c
@@ -0,0 +1,7 @@
+// REQUIRES: lld
+
+// Check that the linker plugin will get -generate-arange-section
+//
+// RUN: %clang -### -g --target=x86_64-linux -flto  -gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g --target=x86_64-linux -flto=thin -gdwarf-aranges %s 2>&1 | FileCheck %s
+// CHECK: --plugin-opt=-generate-arange-section
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -508,6 +508,14 @@
 CmdArgs.push_back(Args.MakeArgString(Plugin));
   }
 
+  // Note, this solution is far from perfect, better to encode it into IR
+  // metadata, but this may not be worth it, since it looks like aranges is on
+  // the way out.
+  if (Args.hasArg(options::OPT_gdwarf_aranges)) {
+CmdArgs.push_back(
+Args.MakeArgString("--plugin-opt=-generate-arange-section"));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133092: [clang] fix generation of .debug_aranges with LTO

2022-09-29 Thread Azat Khuzhin via Phabricator via cfe-commits
azat marked 2 inline comments as done.
azat added inline comments.



Comment at: clang/test/Driver/debug-options-aranges.c:5
+//
+// RUN: %clang -### -g -target x86_64-linux -flto  -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -target x86_64-linux -flto=thin -fuse-ld=lld 
-gdwarf-aranges %s 2>&1 | FileCheck %s

MaskRay wrote:
> azat wrote:
> > MaskRay wrote:
> > > Avoid legacy `-target `. Delete `-fuse-ld=lld` which is unneeded.
> > >Delete -fuse-ld=lld which is unneeded
> > 
> > I've tried without it and in some env it may try to use gold, which will 
> > not be available on CI and the test will fail.
> > Do you have suggestions on how to overcome this? Required gold so as ld? Or 
> > leaving `-fuse-ld=lld` is fine?
> `-###` does not run the command. This shall pass in any environment.
You right, I forgot that real execution of commands had been removed in the 
latest version of the patch. Thanks. Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133092

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


[PATCH] D133413: [clang-tidy] Fix crashes on `if consteval` in readability checks

2022-09-29 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

Ping? This is fixing a segmentation fault. Please let me know if there are 
other people I should add as reviewers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133413

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-09-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, tahonermann.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This only handles floats for now, so 32 bit floating point values.

There are a few things I'm uncertain about, like how to implement 
`Floating<>::truncate()` or whether or not `Float32` should be part of 
`AluTypeClass`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -245,3 +245,24 @@
 #endif
 
 };
+
+namespace floats {
+  constexpr int i = 2;
+  constexpr float f = 1.0f;
+  static_assert(f == 1.0f, "");
+
+  constexpr float f2 = 1u * f;
+  static_assert(f2 == 1.0f, "");
+
+  static_assert(1.0f + 3u == 4, "");
+  static_assert(4.0f / 1.0f == 4, "");
+  static_assert(10.0f * false == 0, "");
+
+  constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+  constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{division by zero}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{division by zero}}
+
+};
Index: clang/lib/AST/Interp/Primitives.h
===
--- /dev/null
+++ clang/lib/AST/Interp/Primitives.h
@@ -0,0 +1,34 @@
+//===-- Primitives.h - Types for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities and helper functions for all primitive types:
+//  - Integral
+//  - Floating
+//  - Boolean
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+#define LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+
+namespace clang {
+namespace interp {
+
+/// Helper to compare two comparable types.
+template  ComparisonCategoryResult Compare(const T &X, const T &Y) {
+  if (X < Y)
+return ComparisonCategoryResult::Less;
+  if (X > Y)
+return ComparisonCategoryResult::Greater;
+  return ComparisonCategoryResult::Equal;
+}
+
+} // namespace interp
+} // namespace clang
+
+#endif
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,11 +13,12 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
 #include 
-#include "Boolean.h"
-#include "Integral.h"
 
 namespace clang {
 namespace interp {
@@ -35,6 +36,7 @@
   PT_Sint64,
   PT_Uint64,
   PT_Bool,
+  PT_Float32,
   PT_Ptr,
 };
 
@@ -48,6 +50,7 @@
 template <> struct PrimConv { using T = Integral<32, false>; };
 template <> struct PrimConv { using T = Integral<64, true>; };
 template <> struct PrimConv { using T = Integral<64, false>; };
+template <> struct PrimConv { using T = Floating<32>; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
 
@@ -70,6 +73,7 @@
   case PT_Uint32:
   case PT_Sint64:
   case PT_Uint64:
+  case PT_Float32:
 return true;
   default:
 return false;
@@ -94,6 +98,7 @@
   TYPE_SWITCH_CASE(PT_Uint32, B)   \
   TYPE_SWITCH_CASE(PT_Sint64, B)   \
   TYPE_SWITCH_CASE(PT_Uint64, B)   \
+  TYPE_SWITCH_CASE(PT_Float32, B)  \
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
 }  \
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -25,6 +25,7 @@
 def Uint32 : Type;
 def

[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-09-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 463785.

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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -245,3 +245,24 @@
 #endif
 
 };
+
+namespace floats {
+  constexpr int i = 2;
+  constexpr float f = 1.0f;
+  static_assert(f == 1.0f, "");
+
+  constexpr float f2 = 1u * f;
+  static_assert(f2 == 1.0f, "");
+
+  static_assert(1.0f + 3u == 4, "");
+  static_assert(4.0f / 1.0f == 4, "");
+  static_assert(10.0f * false == 0, "");
+
+  constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+  constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{division by zero}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{division by zero}}
+
+};
Index: clang/lib/AST/Interp/Primitives.h
===
--- /dev/null
+++ clang/lib/AST/Interp/Primitives.h
@@ -0,0 +1,34 @@
+//===-- Primitives.h - Types for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities and helper functions for all primitive types:
+//  - Integral
+//  - Floating
+//  - Boolean
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+#define LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+
+namespace clang {
+namespace interp {
+
+/// Helper to compare two comparable types.
+template  ComparisonCategoryResult Compare(const T &X, const T &Y) {
+  if (X < Y)
+return ComparisonCategoryResult::Less;
+  if (X > Y)
+return ComparisonCategoryResult::Greater;
+  return ComparisonCategoryResult::Equal;
+}
+
+} // namespace interp
+} // namespace clang
+
+#endif
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,11 +13,12 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
 #include 
-#include "Boolean.h"
-#include "Integral.h"
 
 namespace clang {
 namespace interp {
@@ -35,6 +36,7 @@
   PT_Sint64,
   PT_Uint64,
   PT_Bool,
+  PT_Float32,
   PT_Ptr,
 };
 
@@ -48,6 +50,7 @@
 template <> struct PrimConv { using T = Integral<32, false>; };
 template <> struct PrimConv { using T = Integral<64, true>; };
 template <> struct PrimConv { using T = Integral<64, false>; };
+template <> struct PrimConv { using T = Floating<32>; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
 
@@ -70,6 +73,7 @@
   case PT_Uint32:
   case PT_Sint64:
   case PT_Uint64:
+  case PT_Float32:
 return true;
   default:
 return false;
@@ -94,6 +98,7 @@
   TYPE_SWITCH_CASE(PT_Uint32, B)   \
   TYPE_SWITCH_CASE(PT_Sint64, B)   \
   TYPE_SWITCH_CASE(PT_Uint64, B)   \
+  TYPE_SWITCH_CASE(PT_Float32, B)  \
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
 }  \
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -25,6 +25,7 @@
 def Uint32 : Type;
 def Sint64 : Type;
 def Uint64 : Type;
+def Float32 : Type;
 def Ptr : Type;
 
 //===--===//
@@ -40,6 +41,7 @@
 def ArgUint32 : ArgType { let Name = "uint32_t"; }
 def ArgSint64 : ArgType { let Name = "int64_t"; }
 def ArgUint64 : ArgType { let Name = "uint64_t"; }
+def ArgFloat32 : ArgType { let Name = "float"; }
 def ArgBool : Ar

[PATCH] D134733: [clang-format][chore] transparent #include name regex

2022-09-29 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 463786.
kwk added a comment.

- Remove ad-hoc instantiated IncludeRegex objects


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134733

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 @@
   MaxInsertOffset(MinInsertOffset +
   getMaxHeaderInsertionOffset(
   FileName, Code.drop_front(MinInsertOffset), Style)),
-  Categories(Style, FileName),
-  IncludeRegex(llvm::Regex(IncludeRegexPattern)) {
+  Categories(Style, FileName) {
   // Add 0 for main header and INT_MAX for headers that are not in any
   // category.
   Priorities = {0, INT_MAX};
@@ -289,11 +281,12 @@
   SmallVector Matches;
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
-if (IncludeRegex.match(Line, &Matches)) {
+if (tooling::getCppIncludeRegex().match(Line, &Matches)) {
+  StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
-  Include(Matches[2],
+  Include(IncludeName,
   tooling::Range(
   Offset, std::min(Line.size() + 1, Code.size() - Offset))),
   NextLineOffset);
@@ -403,5 +396,24 @@
   return Result;
 }
 
+llvm::Regex getCppIncludeRegex() {
+  static const char CppIncludeRegexPattern[] =
+  R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+  return llvm::Regex(CppIncludeRegexPattern);
+}
+
+llvm::StringRef getIncludeNameFromMatches(
+const llvm::SmallVectorImpl &Matches) {
+  if (Matches.size() >= 3) {
+return Matches[2];
+  }
+  llvm_unreachable("Matches is too small");
+  return llvm::StringRef();
+}
+
+llvm::StringRef trimInclude(llvm::StringRef IncludeName) {
+  return IncludeName.trim("\"<>;");
+}
+
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/YAMLTraits.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2769,13 +2770,6 @@
   }
 }
 
-namespace {
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
-} // anonymous namespace
-
 tooling::Replacements sortCppIncludes(const FormatStyle &Style, StringRef Code,
   ArrayRef Ranges,
   StringRef FileName,
@@ -2785,7 +2779,6 @@
   .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
   .Default(0);
   unsigned SearchFrom = 0;
-  llvm::Regex IncludeRegex(CppIncludeRegexPattern);
   SmallVector Matches;
   SmallVector IncludesInBlock;
 
@@ -2842,8 +2835,9 @@
 
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
-  if (IncludeRegex.match(Line, &Matches)) {
-StringRef IncludeName = Matches[2];
+  if (tooling::getCppIncludeRegex().match(Line, &Matches)) {
+StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
+
 if (Line.contains("/*") && !Line.contains("*/")) {
   // #include with a start of a block comment, but without the end.
   // Need to keep all the lines until the end of the comment together.
@@ -3120,8 +3114,7 @@
 
 inline bool isHeaderInsertion(const tooling::Replacement &Replace) {
   return Replace.getOffset() == UINT_MAX && Replace.getLength() == 0 &&
- llvm::Regex(CppIncludeRegexPattern)
- .match(Replace.getReplacementText());
+ tooling::getCppIncludeRegex().match(Replace.getReplacementText());
 }
 
 inline bool isHeaderDeletion(const tooling::Replacement &Replace) {
@@ -3129,7 +3122,7 @@
 }
 
 // FIXME: insert empty lines between newly created blocks.
-tooling::Replacements
+static tooling::Replacements
 fixCppIncludeInsertions(StringRef Code, const tooling::Re

[clang] dba8fce - Fix frint ACLE intrinsic names

2022-09-29 Thread Michael Platings via cfe-commits

Author: Michael Platings
Date: 2022-09-29T09:13:07+01:00
New Revision: dba8fced969e2eca9e8650a874293927db17d131

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

LOG: Fix frint ACLE intrinsic names

Although the instruction names begin "frint", the ACLE spec states that
the intrinsic names begin "__rint", without the "f".

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAArch64.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/arm_acle.h
clang/test/CodeGen/aarch64-v8.5a-scalar-frint3264-intrinsic.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 3c0a5f12681d0..036df7435bfba 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -107,14 +107,14 @@ BUILTIN(__builtin_arm_tcancel, "vWUIi", "n")
 BUILTIN(__builtin_arm_ttest, "WUi", "nc")
 
 // Armv8.5-A FP rounding intrinsics
-BUILTIN(__builtin_arm_frint32zf, "ff", "")
-BUILTIN(__builtin_arm_frint32z, "dd", "")
-BUILTIN(__builtin_arm_frint64zf, "ff", "")
-BUILTIN(__builtin_arm_frint64z, "dd", "")
-BUILTIN(__builtin_arm_frint32xf, "ff", "")
-BUILTIN(__builtin_arm_frint32x, "dd", "")
-BUILTIN(__builtin_arm_frint64xf, "ff", "")
-BUILTIN(__builtin_arm_frint64x, "dd", "")
+BUILTIN(__builtin_arm_rint32zf, "ff", "")
+BUILTIN(__builtin_arm_rint32z, "dd", "")
+BUILTIN(__builtin_arm_rint64zf, "ff", "")
+BUILTIN(__builtin_arm_rint64z, "dd", "")
+BUILTIN(__builtin_arm_rint32xf, "ff", "")
+BUILTIN(__builtin_arm_rint32x, "dd", "")
+BUILTIN(__builtin_arm_rint64xf, "ff", "")
+BUILTIN(__builtin_arm_rint64x, "dd", "")
 
 // Armv8.5-A Random number generation intrinsics
 BUILTIN(__builtin_arm_rndr,   "iWUi*", "n")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2d8b0175e2ffa..786ed8c5935f9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9538,32 +9538,32 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
   "cls");
   }
 
-  if (BuiltinID == clang::AArch64::BI__builtin_arm_frint32zf ||
-  BuiltinID == clang::AArch64::BI__builtin_arm_frint32z) {
+  if (BuiltinID == clang::AArch64::BI__builtin_arm_rint32zf ||
+  BuiltinID == clang::AArch64::BI__builtin_arm_rint32z) {
 llvm::Value *Arg = EmitScalarExpr(E->getArg(0));
 llvm::Type *Ty = Arg->getType();
 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_frint32z, 
Ty),
   Arg, "frint32z");
   }
 
-  if (BuiltinID == clang::AArch64::BI__builtin_arm_frint64zf ||
-  BuiltinID == clang::AArch64::BI__builtin_arm_frint64z) {
+  if (BuiltinID == clang::AArch64::BI__builtin_arm_rint64zf ||
+  BuiltinID == clang::AArch64::BI__builtin_arm_rint64z) {
 llvm::Value *Arg = EmitScalarExpr(E->getArg(0));
 llvm::Type *Ty = Arg->getType();
 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_frint64z, 
Ty),
   Arg, "frint64z");
   }
 
-  if (BuiltinID == clang::AArch64::BI__builtin_arm_frint32xf ||
-  BuiltinID == clang::AArch64::BI__builtin_arm_frint32x) {
+  if (BuiltinID == clang::AArch64::BI__builtin_arm_rint32xf ||
+  BuiltinID == clang::AArch64::BI__builtin_arm_rint32x) {
 llvm::Value *Arg = EmitScalarExpr(E->getArg(0));
 llvm::Type *Ty = Arg->getType();
 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_frint32x, 
Ty),
   Arg, "frint32x");
   }
 
-  if (BuiltinID == clang::AArch64::BI__builtin_arm_frint64xf ||
-  BuiltinID == clang::AArch64::BI__builtin_arm_frint64x) {
+  if (BuiltinID == clang::AArch64::BI__builtin_arm_rint64xf ||
+  BuiltinID == clang::AArch64::BI__builtin_arm_rint64x) {
 llvm::Value *Arg = EmitScalarExpr(E->getArg(0));
 llvm::Type *Ty = Arg->getType();
 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_frint64x, 
Ty),

diff  --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index fc347f760d828..ed3fc1de1fd40 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -642,43 +642,43 @@ __jcvt(double __a) {
 /* Armv8.5-A FP rounding intrinsics */
 #if defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE && 
defined(__ARM_FEATURE_FRINT)
 static __inline__ float __attribute__((__always_inline__, __nodebug__))
-__frint32zf(float __a) {
-  return __builtin_arm_frint32zf(__a);
+__rint32zf(float __a) {
+  return __builtin_arm_rint32zf(__a);
 }
 
 static __inline__ double __attribute__((__always_inline__, __nodebug__))
-__frint32z(double __a) {
-  return __builtin_arm_frint32z(__a);
+__rint32z(double __a) {
+  return __builtin_a

[PATCH] D134824: Fix frint ACLE intrinsic names

2022-09-29 Thread Michael Platings 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 rGdba8fced969e: Fix frint ACLE intrinsic names (authored by 
michaelplatings).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134824

Files:
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/arm_acle.h
  clang/test/CodeGen/aarch64-v8.5a-scalar-frint3264-intrinsic.c

Index: clang/test/CodeGen/aarch64-v8.5a-scalar-frint3264-intrinsic.c
===
--- clang/test/CodeGen/aarch64-v8.5a-scalar-frint3264-intrinsic.c
+++ clang/test/CodeGen/aarch64-v8.5a-scalar-frint3264-intrinsic.c
@@ -7,58 +7,58 @@
 
 #include 
 
-// CHECK-LABEL: test_frint32zf
+// CHECK-LABEL: test_rint32zf
 // CHECK:  [[RND:%.*]] =  call float @llvm.aarch64.frint32z.f32(float %a)
 // CHECK:  ret float [[RND]]
-float test_frint32zf(float a) {
-  return __frint32zf(a);
+float test_rint32zf(float a) {
+  return __rint32zf(a);
 }
 
-// CHECK-LABEL: test_frint32z
+// CHECK-LABEL: test_rint32z
 // CHECK:  [[RND:%.*]] =  call double @llvm.aarch64.frint32z.f64(double %a)
 // CHECK:  ret double [[RND]]
-double test_frint32z(double a) {
-  return __frint32z(a);
+double test_rint32z(double a) {
+  return __rint32z(a);
 }
 
-// CHECK-LABEL: test_frint64zf
+// CHECK-LABEL: test_rint64zf
 // CHECK:  [[RND:%.*]] =  call float @llvm.aarch64.frint64z.f32(float %a)
 // CHECK:  ret float [[RND]]
-float test_frint64zf(float a) {
-  return __frint64zf(a);
+float test_rint64zf(float a) {
+  return __rint64zf(a);
 }
 
-// CHECK-LABEL: test_frint64z
+// CHECK-LABEL: test_rint64z
 // CHECK:  [[RND:%.*]] =  call double @llvm.aarch64.frint64z.f64(double %a)
 // CHECK:  ret double [[RND]]
-double test_frint64z(double a) {
-  return __frint64z(a);
+double test_rint64z(double a) {
+  return __rint64z(a);
 }
 
-// CHECK-LABEL: test_frint32xf
+// CHECK-LABEL: test_rint32xf
 // CHECK:  [[RND:%.*]] =  call float @llvm.aarch64.frint32x.f32(float %a)
 // CHECK:  ret float [[RND]]
-float test_frint32xf(float a) {
-  return __frint32xf(a);
+float test_rint32xf(float a) {
+  return __rint32xf(a);
 }
 
-// CHECK-LABEL: test_frint32x
+// CHECK-LABEL: test_rint32x
 // CHECK:  [[RND:%.*]] =  call double @llvm.aarch64.frint32x.f64(double %a)
 // CHECK:  ret double [[RND]]
-double test_frint32x(double a) {
-  return __frint32x(a);
+double test_rint32x(double a) {
+  return __rint32x(a);
 }
 
-// CHECK-LABEL: test_frint64xf
+// CHECK-LABEL: test_rint64xf
 // CHECK:  [[RND:%.*]] =  call float @llvm.aarch64.frint64x.f32(float %a)
 // CHECK:  ret float [[RND]]
-float test_frint64xf(float a) {
-  return __frint64xf(a);
+float test_rint64xf(float a) {
+  return __rint64xf(a);
 }
 
-// CHECK-LABEL: test_frint64x
+// CHECK-LABEL: test_rint64x
 // CHECK:  [[RND:%.*]] =  call double @llvm.aarch64.frint64x.f64(double %a)
 // CHECK:  ret double [[RND]]
-double test_frint64x(double a) {
-  return __frint64x(a);
+double test_rint64x(double a) {
+  return __rint64x(a);
 }
Index: clang/lib/Headers/arm_acle.h
===
--- clang/lib/Headers/arm_acle.h
+++ clang/lib/Headers/arm_acle.h
@@ -642,43 +642,43 @@
 /* Armv8.5-A FP rounding intrinsics */
 #if defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE && defined(__ARM_FEATURE_FRINT)
 static __inline__ float __attribute__((__always_inline__, __nodebug__))
-__frint32zf(float __a) {
-  return __builtin_arm_frint32zf(__a);
+__rint32zf(float __a) {
+  return __builtin_arm_rint32zf(__a);
 }
 
 static __inline__ double __attribute__((__always_inline__, __nodebug__))
-__frint32z(double __a) {
-  return __builtin_arm_frint32z(__a);
+__rint32z(double __a) {
+  return __builtin_arm_rint32z(__a);
 }
 
 static __inline__ float __attribute__((__always_inline__, __nodebug__))
-__frint64zf(float __a) {
-  return __builtin_arm_frint64zf(__a);
+__rint64zf(float __a) {
+  return __builtin_arm_rint64zf(__a);
 }
 
 static __inline__ double __attribute__((__always_inline__, __nodebug__))
-__frint64z(double __a) {
-  return __builtin_arm_frint64z(__a);
+__rint64z(double __a) {
+  return __builtin_arm_rint64z(__a);
 }
 
 static __inline__ float __attribute__((__always_inline__, __nodebug__))
-__frint32xf(float __a) {
-  return __builtin_arm_frint32xf(__a);
+__rint32xf(float __a) {
+  return __builtin_arm_rint32xf(__a);
 }
 
 static __inline__ double __attribute__((__always_inline__, __nodebug__))
-__frint32x(double __a) {
-  return __builtin_arm_frint32x(__a);
+__rint32x(double __a) {
+  return __builtin_arm_rint32x(__a);
 }
 
 static __inline__ float __attribute__((__always_inline__, __nodebug__))
-__frint64xf(float __a) {
-  return __builtin_arm_frint64xf(__a);
+__rint64xf(float __a) {
+  return __builtin_arm_rint64xf(__a);
 }
 
 static __inline__ double __attribute__((__always_inline__, _

[PATCH] D134852: [clang-format][NFC] Clean up class HeaderIncludes and Format.cpp

2022-09-29 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

I didn't see much difference in what this patch does compare to mine but I saw 
that it removes the need for instantiating multiple `llvm::Regex` objects from 
a single static pattern. But that's something I've just done in a new revision 
of my own patch: https://reviews.llvm.org/D134733?vs=463205&id=463786#toc . 
This fast clean up makes it only harder for me to get my patch in but 
essentially both do the same thing except that I also have a single convenience 
function for trimming include names from `"` and `<>"`.




Comment at: clang/lib/Format/Format.cpp:2774
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";

MyDeveloperDay wrote:
> Did I miss where this comes from now?
@MyDeveloperDay `clang/lib/Tooling/Inclusions/HeaderIncludes.cpp` still has 
this:

```lang=c++
const char IncludeRegexPattern[] =
R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
```

And in `clang/lib/Tooling/Inclusions/HeaderIncludes.cpp` @owenpan uses it to 
initialize the final regex 

```lang=c++
const llvm::Regex HeaderIncludes::IncludeRegex(IncludeRegexPattern); 
```

The fact that we have two regex that are identical is an issue on its own that 
I tried to address with [my patch](https://reviews.llvm.org/D134733) as well. I 
didn't initialize the regex like @owenpan does here but I had a function to 
return it. Eventually a function makes it easier to apply the injection from a 
config file as you've suggested 
[here](https://reviews.llvm.org/D134733#3821957). So I favor my solution.






Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134852

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


[PATCH] D134804: [clang][Interp] Implement bitwise Not operations

2022-09-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 463791.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D134804

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -3,6 +3,10 @@
 // RUN: %clang_cc1 -std=c++11 -verify=ref %s
 // RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
+#define INT_MIN (~__INT_MAX__)
+#define INT_MAX __INT_MAX__
+
+
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
 static_assert(nullptr == nullptr, "");
@@ -66,6 +70,18 @@
 static_assert(-true, "");
 static_assert(-false, ""); //expected-error{{failed}} ref-error{{failed}}
 
+static_assert(~0 == -1, "");
+static_assert(~1 == -2, "");
+static_assert(~-1 == 0, "");
+static_assert(~255 == -256, "");
+static_assert(~INT_MIN == INT_MAX, "");
+static_assert(~INT_MAX == INT_MIN, "");
+
+enum E {};
+constexpr E e = static_cast(0);
+static_assert(~e == -1, "");
+
+
 constexpr int m = 10;
 constexpr const int *p = &m;
 static_assert(p != nullptr, "");
@@ -146,7 +162,6 @@
 #endif
 };
 
-#define INT_MIN (~__INT_MAX__)
 
 namespace rem {
   static_assert(2 % 2 == 0, "");
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -422,6 +422,12 @@
   let HasGroup = 1;
 }
 
+// [Real] -> [Real]
+def Not: Opcode {
+  let Types = [NumberTypeClass];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Cast.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -238,6 +238,20 @@
   return true;
 }
 
+/// 1) Pops the value from the stack.
+/// 2) Pushes the bitwise negated value on the stack (~V).
+template ::T>
+bool Not(InterpState &S, CodePtr OpPC) {
+  const T &Val = S.Stk.pop();
+  T Result;
+  if (!T::Not(Val, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+
+  return false;
+}
+
 //===--===//
 // EQ, NE, GT, GE, LT, LE
 //===--===//
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -225,6 +225,11 @@
 return false;
   }
 
+  static bool Not(Integral A, Integral *R) {
+*R = Integral(~A.V);
+return false;
+  }
+
 private:
   template  static bool CheckAddUB(T A, T B, T &R) {
 if constexpr (std::is_signed_v) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1048,6 +1048,11 @@
   return DiscardResult ? this->emitPop(T, E) : true;
 });
   case UO_Not:// ~x
+if (!this->Visit(SubExpr))
+  return false;
+if (Optional T = classify(E->getType()))
+  return this->emitNot(*T, E);
+return false;
   case UO_Real:   // __real x
   case UO_Imag:   // __imag x
   case UO_Extension:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134717: [Clang][AArch64] Fix va_arg with -mgeneral-regs-only

2022-09-29 Thread Amanieu d'Antras via Phabricator via cfe-commits
Amanieu added a comment.

Currently using Clang with -mgeneral-regs-only generates perfectly fine 
soft-float AArch64, with the except of the va_arg() implementation which is 
fixed here. In fact Rust even has a aarch64-unknown-none-softfloat which relies 
on this behavior in LLVM. I believe this behavior is *more* useful than GCC's 
which simply rejects float/double types, and it makes sense to keep it and fix 
it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134717

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-09-29 Thread Diana Picus via Phabricator via cfe-commits
rovka added inline comments.
Herald added a subscriber: zero9178.



Comment at: flang/test/Driver/convert.f90:1
+! Ensure argument -fconvert= works as expected.
+

jpenix-quic wrote:
> awarzynski wrote:
> > rovka wrote:
> > > Nit: Shouldn't you also check that valid values (e.g. unknown, swap etc) 
> > > are accepted? 
> > Could you be more specific? IIUC, this is more about making sure that the 
> > option parser works correctly and reports invalid usage of `-fconvert` as 
> > an error, right?
> > Nit: Shouldn't you also check that valid values (e.g. unknown, swap etc) 
> > are accepted? 
> 
> I might be doing something silly/missing something obvious, but I wasn't sure 
> how to get FileCheck to basically just check that the command didn't error 
> without adding checks, so I added trivial checks (VALID/VALID_FC1) for each 
> of unknown/native/etc. Is there a better way of doing this? I also expanded 
> flang/test/Lower/convert.f90 to check lowering for each of the valid options, 
> so I didn't want to do full checks of the MLIR here. 
Just in case it's not clear, this looks good to me now, it's exactly what I had 
in mind.


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

https://reviews.llvm.org/D130513

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


[PATCH] D134733: [clang-format][chore] transparent #include name regex

2022-09-29 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added inline comments.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:407
+const llvm::SmallVectorImpl &Matches) {
+  if (Matches.size() >= 3) {
+return Matches[2];

MyDeveloperDay wrote:
> kwk wrote:
> > MyDeveloperDay wrote:
> > > ‘>= 2’
> > @MyDeveloperDay correct me if I'm wrong but if an array has size `3` it has 
> > indexes `0`, `1` and `2`. And an array of size `2` only has `0` and `1`.  
> > So the case `=2`, which is implied by your suggested`>=2`, is actually an 
> > out of bounds access when going `Matches[2]`.  Because that is effectively 
> > accessing the third element. The only valid change would be to check for 
> > `Matches.size() > 2` IMHO and that is the same as `Matches.size() >= 3`.
> > 
> > I must admit that I had to look at the regex a few times only to realize 
> > that it has two non-optional matching groups `(...)`. The third matching 
> > group at index `0` is the whole line. So in theory `>=3` isn't possible 
> > with the current regex. I wanted to give my best to have this logic 
> > "survive" a change to the regex in which for example something is added 
> > after the matching group of the include name; let's say a comment or 
> > something.
> > 
> > I hope I haven't made myself a complete fool.  
> No foolery other than my own. I meant to say '> 2',  actually the first time 
> I wrote the comment it disappear because it didn't escape the '>'
> 
> So one though I had for the config was something like this (ignore regex 
> itself I just put anything in it to show the principle)
> 
> ```
> ---
> Language Cpp
> IncludeRegex:  ^[\t\ ]*[@#][\t\ 
> ]*(import|include)([^"/]*("[^"]+")|[^]+>)|[\t/\ ]*([^;]+;)
> IncludeRegexGroup: 1
> ---
> Language: ObjectiveC
> IncludeRegex:  ^[\t\ ]*[@#][\t\ 
> ]*(import|include)([^"/]*("[^"]+")|[^]+>)|[\t/\ ]*([^;]+;)
> IncludeRegexGroup: 2
> ---
> Language: CSharp
> IncludeRegex:  using  ([A-z])*
> IncludeRegexGroup: 0
> ---
> Language: Carbon
> IncludeRegex:  package ([A-z])* api
> IncludeRegexGroup: 0
> ---
> 
> ```
> 
> Wouldn't this allow different languages to have their own Include/Import 
> regex? Just thinking out loud
> 
> It could be more powerful than having 1 regex to rule them all.
> 
> 
> 
> 
@MyDeveloperDay I like the idea of this approach! But I also see that a single 
language alone, namely C++, is quite a tough nut to crack with the advent of 
Modules (https://en.cppreference.com/w/cpp/language/modules). I'm afraid the 
bit of `IncludeRegexGroup` would need to be expanded to be either a

* **fixed number** (wherever possible)
* a **method** as in: last-non-empty-matching-group

Only then I think that your solution would work. Can one have a setting in 
clang format that allows for mixed input as in number or string? A bit of a 
hacky solution but probably cutting 100% of all regexes would be to have an 
enum with these allowed strings: 
`last-non-empty-matching-group,first-non-empty-matching-group,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134733

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


[PATCH] D134453: Introduce the `AlwaysIncludeTypeForNonTypeTemplateArgument` into printing policy

2022-09-29 Thread Nenad Mikša via Phabricator via cfe-commits
DoDoENT added a comment.

> Generally the way to do it, if you want to introspect into the type, its 
> template parameters, etc, then yes, keeping pointers to the AST or reparsing 
> the name with Clang as-needed, would be the way to go - or walking the AST 
> up-front and generating your own data structure (not necessarily a string) 
> with the data you want in some structured format.

This is precisely what I'm trying to avoid. Source files that include 
AST-related headers are extremely slow to compile, so I want to build a facade 
around the code that interacts with clang to keep my build times as low as 
possible. Thus, I will pay for the slow compilation only in a couple of files.

> Sorry, I'm confused - it sounded like you didn't actually want a string, 
> though - you want the type information to make various semantic-aware choices 
> in your tool, yes?

At the end of the line, I will need a string representation of the type name, 
at least in my current approach.

> Again, I'm not advocating for the printing as-is, I think adding the top 
> level name that disambiguates would be a good thing - and I think the GCC and 
> MSVC examples somewhat show why adding all the other layers would be harmful 
> to readability - there's a lot of text in those messages that doesn't 
> directly help the user and gets in the way of identifying the important 
> differences between the type names.

I think this is a matter of taste. In the example that you've shown, I 
personally prefer the verbosity of GCC and don't see it as "less readable", but 
as "more informative". However, I do understand that some people may prefer the 
output you suggested. What about making this configurable, i.e. behind some 
clang flag, so that developers that prefer verbosity can enable that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

2022-09-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

Sorry about the delay, I've been juggling too many things :-(

TL;DR: yes, I think it's reasonable. I think the implementation complexity is 
justified by what we get. Thanks for explaining!

I think to minimize interface complexity, we should basically consider this to 
just weaken the invariants of TypedefType etc, and have comments reflecting 
that. Accordingly like to see `inDivergent()` inverted and named something like 
`typeMatchesDecl()` if it needs to be exposed at all.

But since this is just naming nits and I'm having trouble staying responsive, 
LGTM from my side once you feel it's clear enough.

---

In D133468#3804290 , @mizvekov wrote:

>   template  struct A { using type1 = T; };
>   using Int = int;
>   
>   using type2 = A::type1;
>
> [...] We want the underlying type of `type2` to have that `Int` sugar. [...] 
> The problem here is that the TypedefType is currently limited to having the 
> declaration's underlying type, which is just from an instantiation of 
> `A`, and knows nothing about camel case `Int`.

Thanks, this is compelling! Couple of observations, not objections:

- applications often print the fully-sugared type (`type2`) and/or the 
canonical type (`int`) with nothing in between. This might limit the benefits - 
I've often wished we had better & sharable heuristics for how much desugaring 
users want.
- in this simple example we could naively solve the problem by having the class 
instantiation that it was instantiated with `Int` sugar, and making the 
original underlying type of A::type1 as `Int`. (There are downsides here, 
you can obviously get the "wrong" sugar if there are multiple instantiation 
sites).

Anyway, I don't really want to argue scope/design, you've clearly thought way 
more about this, just want to give you more to think about. Question for this 
patch is just cost vs benefits.

> This is similar to the infamous problem with `std::string` turning into 
> `std::basic_string` in templates.

Yes! Though half of my `basic_string` sugar problems are things like `substr`'s 
return type. This seems harder to solve in a principled way, though maybe 
heuristically doable when the written return type uses the injected-class-name? 
Anyway, again offtopic for this patch...

> We could emit a new TypedefDecl with the underlying type that we want, but 
> creating declarations is expensive, so we want to avoid that.
> We could create a new AST node that represented more accurately what was 
> happening. But the question is, is this worth the cost?
> Do you see use cases for this yourself?

From the API here, "divergent" exposed as a property etc, I assumed you 
expected some clients to handle it. And I also expected that it would end up 
being in more nodes than TypedefType and UsingType - it's hard to see why it 
stops there.
In that case an additional node could improve code complexity: 
isolates+centralizes the code handling this case, makes it harder to miss one 
kind of divergent node, keeps the rest of the AST simpler for code that doesn't 
care about resugaring.

But it sounds more like we expect ~no programmatic clients to care, and that 
this change is mostly:

- drop the assumption that decl & type have the same sugar, because of 
resugaring
- add isDivergent() just to enable the text dump to provide hints to human 
analysis

> But the question is, is this worth the cost?

If you're talking about *runtime* cost - it's not obvious that it's 
significantly more expensive? IIUC wherever types are resugared we're having to 
duplicate the chain of sugar (e.g. a function that returns T** is going to be 
instantiated as functiontype(pointertype(pointertype(typedeftype(int and 
then resugared as 
functiontype(pointertype(pointertype(/*divergent*/typedeftype(typedeftype(int).
 The difference between enlarging typedeftype with trailing objects vs adding 
an extra node feels like a drop in the bucket. That said, I can't think of a 
way to do this that's both compact *and* much simpler, and simplicity would be 
the point.

(I'm not really asking you to measure this: I know it's a bunch of work. Just 
want to make sure that if we're deciding about cheap vs expensive we're probing 
our intuition a bit)

> We want resugaring to be cheap and introduce as little changes in the AST as 
> possible, to get a better chance of affording to have it to be on all the 
> time.

Yes. In fact I've been scared by the discussion of "maybe we should have flags 
to ramp up/down sugar" as it's hard enough to write AST-wrangling code 
correctly against a single configuration :-)

> It does not seem too far fetched that the UsingType could point to a 
> resugared version of the declaration's underlying type, without having to 
> create a new declaration.

OK, I think I'm sold on this.
I think it's conceptually simpler to say "this may be the case" (weaken 
invariants) than say "there 

[PATCH] D134637: clang-tblgen build: avoid duplicate inclusion of libLLVMSupport

2022-09-29 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

A possible alternative solution would be to build `clangSupport_sources` as an 
object library, and then link that library into `clangSupport` and 
`clang-tblgen` which could be done unconditionally; the advantage is that you 
don't need to compile `clangSupport_sources` twice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134637

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


[PATCH] D134788: [ARM64EC][clang-cl] Add /arm64EC flag

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

Has Microsoft documented this option? Not doubting it exists but I mostly see 
how to use it rather than a specific page describing the option and its 
behaviour.

Not a big deal but if there is one, please include a link to it in the commit 
message.




Comment at: clang/lib/Driver/Driver.cpp:1384
+  TC.getTriple().getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) {
+if (UArgs->hasArg(options::OPT__SLASH_arm64EC)) {
+  getDiags().Report(clang::diag::warn_target_override_arm64ec)

This would read better to me if you put them all in one and put the most 
important check first like:
```
if ( UArgs->hasArg(options::OPT__SLASH_arm64EC) &&
( (TC.getTriple().getArch() != llvm::Triple::aarch64 ||
  TC.getTriple().getSubArch() != llvm::Triple::AArch64SubArch_arm64ec)) {
```



Comment at: clang/test/Driver/cl-options.c:787
+// RUN: %clang_cl -vctoolsdir "" /arm64EC /c -### -- %s 2>&1 | FileCheck %s 
--check-prefix ARM64EC
+// ARM64EC: "-triple" "arm64ec-pc-windows-msvc19.20.0"
+

Add an `ARM64EC-NOT` check for this part to check there is no warning.

Not going to catch much in this change but if someone goes digging into target 
setting they might change it by other means than `--target` and not realise.



Comment at: clang/test/Driver/cl-options.c:790
+// RUN: %clang_cl -vctoolsdir "" /arm64EC /c -target x86_64-pc-windows-msvc  
-### -- %s 2>&1 | FileCheck %s --check-prefix ARM64EC_OVERRIDE
+// ARM64EC_OVERRIDE: warning: /arm64EC has been overridden by specified 
target:x86_64-pc-windows-msvc; option ignored
+

A space after the ':' is a bit easier to parse IMO (unless this is matching an 
msvc warning in which case fair enough keep it as is).


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

https://reviews.llvm.org/D134788

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

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



Comment at: clang/lib/AST/Interp/Context.cpp:130
+  if (T->isFloatingType()) {
+unsigned Bytes = getASTContext().getTypeSize(T);
+if (Bytes == 32)





Comment at: clang/lib/AST/Interp/Floating.h:106
+  // ---
+
+  static bool add(Floating A, Floating B, unsigned OpBits, Floating *R) {

The operations here don't do overflow or UB handling.


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

https://reviews.llvm.org/D134859

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


[PATCH] D126481: [analyzer] Handle SymbolCast in SValBuilder

2022-09-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

> Suppose we have found the way to handle it. But what if we find a 
> contradiction while simplifying, like (short)(int x) = 0 and (int x) = 1. So 
> that we would already know that it is impossible. What SVal should we return 
> in such case? Undef? Unknown? Original one?

I think the `SValBuilder` should not reach such an ambiguity. Ideally, both 
`(short)(int x)` and `(int x)` should be constrained to the same value. If that 
is not the case then we already have an infeasible state. But it should not be 
the task of the SValBuilder to recognize this situation. So, when we add the 
second constraint **then** we should notice the contradiction immediately. This 
check should be done in the `ConstraintAssignor`.

> What we could do is to collect the constants and types on the way of the cast 
> visitation and then apply the same logic that you have in D103096 
> 

I don't think anymore that this is would be the way forward, as I said, let's 
do the check for infeasibility in the ConstraintAssignor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126481

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-09-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 463807.

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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -253,3 +253,27 @@
 #endif
 
 };
+
+namespace floats {
+  constexpr int i = 2;
+  constexpr float f = 1.0f;
+  static_assert(f == 1.0f, "");
+
+  constexpr float f2 = 1u * f;
+  static_assert(f2 == 1.0f, "");
+
+  static_assert(1.0f + 3u == 4, "");
+  static_assert(4.0f / 1.0f == 4, "");
+  static_assert(10.0f * false == 0, "");
+
+  constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+  constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{division by zero}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{division by zero}}
+
+  static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+ // expected-error {{invalid argument type 'float' to unary expression}}
+
+};
Index: clang/lib/AST/Interp/Primitives.h
===
--- /dev/null
+++ clang/lib/AST/Interp/Primitives.h
@@ -0,0 +1,34 @@
+//===-- Primitives.h - Types for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities and helper functions for all primitive types:
+//  - Integral
+//  - Floating
+//  - Boolean
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+#define LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+
+namespace clang {
+namespace interp {
+
+/// Helper to compare two comparable types.
+template  ComparisonCategoryResult Compare(const T &X, const T &Y) {
+  if (X < Y)
+return ComparisonCategoryResult::Less;
+  if (X > Y)
+return ComparisonCategoryResult::Greater;
+  return ComparisonCategoryResult::Equal;
+}
+
+} // namespace interp
+} // namespace clang
+
+#endif
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,11 +13,12 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
 #include 
-#include "Boolean.h"
-#include "Integral.h"
 
 namespace clang {
 namespace interp {
@@ -35,6 +36,7 @@
   PT_Sint64,
   PT_Uint64,
   PT_Bool,
+  PT_Float32,
   PT_Ptr,
 };
 
@@ -48,6 +50,7 @@
 template <> struct PrimConv { using T = Integral<32, false>; };
 template <> struct PrimConv { using T = Integral<64, true>; };
 template <> struct PrimConv { using T = Integral<64, false>; };
+template <> struct PrimConv { using T = Floating<32>; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
 
@@ -70,6 +73,7 @@
   case PT_Uint32:
   case PT_Sint64:
   case PT_Uint64:
+  case PT_Float32:
 return true;
   default:
 return false;
@@ -94,6 +98,7 @@
   TYPE_SWITCH_CASE(PT_Uint32, B)   \
   TYPE_SWITCH_CASE(PT_Sint64, B)   \
   TYPE_SWITCH_CASE(PT_Uint64, B)   \
+  TYPE_SWITCH_CASE(PT_Float32, B)  \
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
 }  \
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -25,6 +25,7 @@
 def Uint32 : Type;
 def Sint64 : Type;
 def Uint64 : Type;
+def Float32 : Type;
 def Ptr : Type;
 
 //===--===//
@@ -40,6 +41,7 @@
 def ArgUin

[PATCH] D134717: [Clang][AArch64] Fix va_arg with -mgeneral-regs-only

2022-09-29 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

> With -mgeneral-regs-only, all arguments are passed in GPRs, so we should use 
> gr_top/gr_offs in va_list even for floating-point types.

I don't believe that -mgeneral-regs-only was intended to define an ABI passing 
floats in GPRs for AArch64. If it has that is likely a mistake, I don't recall 
any such ABI being defined.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134717

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


[PATCH] D126481: [analyzer] Handle SymbolCast in SValBuilder

2022-09-29 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Actually, you already have a logic for checking if there is a contradiction in 
your D103096  patch, in 
ConstraintAssignor::updateExistingConstraints:

  // Update constraints in the map which bitwidth is equal or lower then
  // `MinBitWidth`.
  if (CM) {
for (auto &Item : *CM) {
  // Stop after reaching a bigger bitwidth.
  if (Item.first > MinBitWidth)
break;
  RangeSet RS = RangeFactory.intersect(Item.second, CastTo(Item.first));
  // If the intersection is empty, then the branch is infisible.
  if (RS.isEmpty()) {
State = nullptr;
return false;
  }
  NewCM = CMF.add(NewCM, Item.first, RS);
}
  }

So, the intersection should be empty in the above mentioned ambiguous case, 
shouldn't' it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126481

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


[PATCH] D134717: [Clang][AArch64] Fix va_arg with -mgeneral-regs-only

2022-09-29 Thread Amanieu d'Antras via Phabricator via cfe-commits
Amanieu added a comment.

I fully agree that this likely wasn't intentional, but this is still very 
useful for code that can't use FP registers for whatever reason (e.g. kernels). 
Regarding the ABI, it doesn't need to be officially defined: it just needs to 
be compatible with other code compiled with -mgeneral-regs-only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134717

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


[PATCH] D133119: [clang-tidy] Add checker 'bugprone-suspicious-realloc-usage'.

2022-09-29 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 463812.
balazske added a comment.

rebase to current main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133119

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
@@ -0,0 +1,85 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-realloc-usage %t
+
+void *realloc(void *, __SIZE_TYPE__);
+
+namespace std {
+  using ::realloc;
+}
+
+namespace n1 {
+  void *p;
+}
+
+namespace n2 {
+  void *p;
+}
+
+struct P {
+  void *p;
+  void *q;
+  P *pp;
+  void *&f();
+};
+
+struct P1 {
+  static void *p;
+  static void *q;
+};
+
+template
+struct P2 {
+  static void *p;
+  static void *q;
+};
+
+template
+void templ(void *p) {
+  A::p = realloc(A::p, 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'A::p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+  p = realloc(A::p, 10);
+  A::q = realloc(A::p, 10);
+  A::p = realloc(B::p, 10);
+  P2::p = realloc(P2::p, 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'P2::p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+  P2::p = realloc(P2::p, 1);
+}
+
+void *&getPtr();
+P &getP();
+
+void warn(void *p, P *p1, int *pi) {
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  p = std::realloc(p, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  p1->p = realloc(p1->p, 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'p1->p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  p1->pp->p = realloc(p1->pp->p, 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'p1->pp->p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  pi = (int*)realloc(pi, 10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'pi' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+
+  templ>(p);
+}
+
+void no_warn(void *p, P *p1, P *p2) {
+  void *q = realloc(p, 10);
+  q = realloc(p, 10);
+  p1->q = realloc(p1->p, 10);
+  p2->p = realloc(p1->p, 20);
+  n1::p = realloc(n2::p, 30);
+  p1->pp->p = realloc(p1->p, 10);
+  getPtr() = realloc(getPtr(), 30);
+  getP().p = realloc(getP().p, 20);
+  p1->f() = realloc(p1->f(), 30);
+}
+
+void warn_if_copy_exists(void *p) {
+  void *q = p;
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -124,6 +124,7 @@
`bugprone-suspicious-memory-comparison `_,
`bugprone-suspicious-memset-usage `_, "Yes"
`bugprone-suspicious-missing-comma `_,
+   `bugprone-suspicious-realloc-usage `_,
`bugprone-suspicious-semicolon `_, "Yes"
`bugprone-suspicious-string-compare `_, "Yes"
`bugprone-swapped-arguments `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-realloc-usage.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - bugprone-suspicious-realloc-usage
+
+bugprone-suspicious-realloc-usage
+=
+
+This check finds usages of ``realloc`` where the return value is assigned to the
+same expression as passed to the first argument:
+``p = realloc(p, size);``
+The problem with this construct is that if ``realloc`` fails it returns a
+null pointer but does not d

[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-29 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 463815.
SixWeining added a comment.
Herald added a subscriber: pengfei.

The flag in the INLINEASM SDNode in llvm/test/CodeGen/X86/callbr-asm-kill.mir 
is updated because enum `Constraint_k` is added before `Constraint_m`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134638

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/test/CodeGen/LoongArch/inline-asm-constraints.c
  llvm/include/llvm/IR/InlineAsm.h
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
  llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZB.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZC.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-k.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
  llvm/test/CodeGen/X86/callbr-asm-kill.mir

Index: llvm/test/CodeGen/X86/callbr-asm-kill.mir
===
--- llvm/test/CodeGen/X86/callbr-asm-kill.mir
+++ llvm/test/CodeGen/X86/callbr-asm-kill.mir
@@ -67,7 +67,7 @@
   ; CHECK-NEXT:   CALL64pcrel32 target-flags(x86-plt) @foo, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp
   ; CHECK-NEXT:   ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
   ; CHECK-NEXT:   [[COPY4:%[0-9]+]]:gr64 = COPY [[MOV64rm]]
-  ; CHECK-NEXT:   INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 196654 /* mem:m */, killed [[MOV64rm]], 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop)
+  ; CHECK-NEXT:   INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 262190 /* mem:m */, killed [[MOV64rm]], 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop)
   ; CHECK-NEXT:   JMP_1 %bb.2
   ; CHECK-NEXT: {{  $}}
   ; CHECK-NEXT: bb.2.end:
@@ -87,7 +87,7 @@
 $rdi = COPY killed %0
 CALL64pcrel32 target-flags(x86-plt) @foo, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp
 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
-INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 196654 /* mem:m */, %1, 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop)
+INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 262190 /* mem:m */, %1, 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop)
 JMP_1 %bb.2
 
   bb.2.end:
Index: llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
@@ -0,0 +1,145 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA32
+; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA64
+
+define i32 @m_offset_neg_2049(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_2049:
+; LA32:   # %bb.0:
+; LA32-NEXT:lu12i.w $a1, -1
+; LA32-NEXT:ori $a1, $a1, 2047
+; LA32-NEXT:add.w $a0, $a0, $a1
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, 0
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_2049:
+; LA64:   # %bb.0:
+; LA64-NEXT:lu12i.w $a1, -1
+; LA64-NEXT:ori $a1, $a1, 2047
+; LA64-NEXT:add.d $a0, $a0, $a1
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, 0
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 -2049
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_neg_2048(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_2048:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, -2048
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_2048:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, -2048
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 -2048
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_neg_1(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_1:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, -1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_1:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, -1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:  

[PATCH] D133885: [Clang][Arm] Convert -fallow-half-arguments-and-returns to a target option. NFC

2022-09-29 Thread Dave Green 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 rG123064dc397d: [Clang][Arm] Convert 
-fallow-half-arguments-and-returns to a target option. NFC (authored by 
dmgreen).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D133885?vs=460173&id=463816#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133885

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/PowerPC/builtins-ppc-fpconstrained.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlsegff.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlseg.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlseg_mask.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlsegff.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlsegff_mask.c
  clang/test/CodeGen/aarch64-arguments-hfa-v3.c
  clang/test/CodeGen/aarch64-neon-fp16fml.c
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-neon-ldst-one.c
  clang/test/CodeGen/aarch64-neon-misc-constrained.c
  clang/test/CodeGen/aarch64-neon-misc.c
  clang/test/CodeGen/aarch64-neon-vcombine.c
  clang/test/CodeGen/aarch64-neon-vget-hilo.c
  clang/test/CodeGen/aarch64-neon-vget.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp
  clang/test/CodeGen/aarch64-sve-inline-asm-crash.c
  clang/test/CodeGen/aarch64-sve-inline-asm-datatypes.c
  clang/test/CodeGen/aarch64-sve-inline-asm-negative-test.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_abd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_abs.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acle.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_aclt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adda.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_addv.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_and.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_andv.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_asr.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_asrd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfdot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmmla.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bic.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brka.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkn.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkpa.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkpb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cadd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cls.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clz.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmla.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpeq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmple.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmplt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpne.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpuo.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnt-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cntb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cntd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnth.c
  clang/test/CodeGen/aarc

[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-29 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added a comment.

In D134638#3822926 , @MaskRay wrote:

> `Constraint_k` somehow broke AArch64 and X86 inlineasm. Please run at least 
> `check-llvm check-clang` for generic changes which may have farreaching 
> effects to other targets.

Sorry for that. I have fix it. The fail is casued by a hard coded INLINEASM 
SDNode flag. I have updated it. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134638

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


[PATCH] D134337: [clang] [Driver] More flexible rules for loading default configs

2022-09-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 463825.
mgorny marked 2 inline comments as done.
mgorny added a comment.

Address @MaskRay 's comments.


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

https://reviews.llvm.org/D134337

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file3.c

Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -9,112 +9,256 @@
 // RUN: echo "@subdir/cfg-s2" > %t/workdir/cfg-1
 // RUN: echo "-Wundefined-var-template" > %t/workdir/subdir/cfg-s2
 //
-// RUN: ( cd %t && %clang --config workdir/cfg-1 -c -### %s 2>&1 | FileCheck %s -check-prefix CHECK-REL )
+// RUN: ( cd %t && %clang --config=workdir/cfg-1 -c -### %s 2>&1 | FileCheck %s -check-prefix CHECK-REL )
 //
 // CHECK-REL: Configuration file: {{.*}}/workdir/cfg-1
 // CHECK-REL: -Wundefined-var-template
 
+//--- Config files are searched for in binary directory as well.
+//
+// RUN: mkdir %t/testbin
+// RUN: ln -s %clang %t/testbin/clang
+// RUN: echo "-Werror" > %t/testbin/aaa.cfg
+// RUN: %t/testbin/clang --config-system-dir= --config-user-dir= --config=aaa.cfg -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-BIN
+//
+// CHECK-BIN: Configuration file: {{.*}}/testbin/aaa.cfg
+// CHECK-BIN: -Werror
 
-//--- Invocation qqq-clang-g++ tries to find config file qqq-clang-g++.cfg first.
+//--- Invocation x86_64-unknown-linux-gnu-clang-g++ tries x86_64-unknown-linux-gnu-clang++.cfg first.
 //
 // RUN: mkdir %t/testdmode
+// RUN: ln -s %clang %t/testdmode/cheribsd-riscv64-hybrid-clang++
 // RUN: ln -s %clang %t/testdmode/qqq-clang-g++
-// RUN: echo "-Wundefined-func-template" > %t/testdmode/qqq-clang-g++.cfg
-// RUN: echo "-Werror" > %t/testdmode/qqq.cfg
-// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix FULL-NAME
+// RUN: ln -s %clang %t/testdmode/x86_64-clang
+// RUN: ln -s %clang %t/testdmode/i386-unknown-linux-gnu-clang-g++
+// RUN: ln -s %clang %t/testdmode/x86_64-unknown-linux-gnu-clang-g++
+// RUN: ln -s %clang %t/testdmode/x86_64-unknown-linux-gnu-clang
+// RUN: touch %t/testdmode/cheribsd-riscv64-hybrid-clang++.cfg
+// RUN: touch %t/testdmode/cheribsd-riscv64-hybrid.cfg
+// RUN: touch %t/testdmode/qqq-clang-g++.cfg
+// RUN: touch %t/testdmode/qqq.cfg
+// RUN: touch %t/testdmode/x86_64-clang.cfg
+// RUN: touch %t/testdmode/x86_64.cfg
+// RUN: touch %t/testdmode/x86_64-unknown-linux-gnu-clang++.cfg
+// RUN: touch %t/testdmode/x86_64-unknown-linux-gnu-clang-g++.cfg
+// RUN: touch %t/testdmode/x86_64-unknown-linux-gnu-clang.cfg
+// RUN: touch %t/testdmode/x86_64-unknown-linux-gnu.cfg
+// RUN: touch %t/testdmode/i386-unknown-linux-gnu-clang++.cfg
+// RUN: touch %t/testdmode/i386-unknown-linux-gnu-clang-g++.cfg
+// RUN: touch %t/testdmode/i386-unknown-linux-gnu-clang.cfg
+// RUN: touch %t/testdmode/i386-unknown-linux-gnu.cfg
+// RUN: touch %t/testdmode/clang++.cfg
+// RUN: touch %t/testdmode/clang-g++.cfg
+// RUN: touch %t/testdmode/clang.cfg
+// RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1
+//
+// FULL1-NOT: Configuration file:
+// FULL1: Configuration file: {{.*}}/testdmode/x86_64-unknown-linux-gnu-clang++.cfg
+// FULL1-NOT: Configuration file:
+
+//--- -m32 overrides triple.
+//
+// RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ -m32 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1-I386
+//
+// FULL1-I386-NOT: Configuration file:
+// FULL1-I386: Configuration file: {{.*}}/testdmode/i386-unknown-linux-gnu-clang++.cfg
+// FULL1-I386-NOT: Configuration file:
+
+//--- --target= also works for overriding triple.
+//
+// RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --target=i386-unknown-linux-gnu --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1-I386
+
+//--- With --target= + -m64, -m64 takes precedence.
+//
+// RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --target=i386-unknown-linux-gnu -m64 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1
+
+//--- i386 prefix also works for 32-bit.
+//
+// RUN: %t/testdmode/i386-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1-I386
+
+//--- i386 prefix + -m64 also works for 64-bit.
+//
+// RUN: %t/testdmode/i386-unknown-linux-gnu-clang-g++ -m64 --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix FULL1
+
+//--- File specified by --config= is loaded after the 

[PATCH] D134337: [clang] [Driver] More flexible rules for loading default configs

2022-09-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/include/clang/Driver/Driver.h:758
+  /// Return the typical executable name for the specified driver \p Mode.
+  static const char *getExecutableForDriverMode(DriverMode Mode);
 };

MaskRay wrote:
> This should be private
No opinion but will do.



Comment at: clang/lib/Driver/Driver.cpp:1094
+  //(e.g. i386-pc-linux-gnu-clang++.cfg).
+  // 2. -.cfg using executable suffix
+  //(e.g. i386-pc-linux-gnu-clang-g++.cfg).

MaskRay wrote:
> "executable suffix" is less clear. An example will help.
Added `for *clang-g++` below. Hope that's good enough.



Comment at: clang/lib/Driver/Driver.cpp:1101
+
+  // Try loading full config (variants 1. and 2.)
   llvm::SmallString<128> CfgFilePath;

MaskRay wrote:
> Mention "first part" ? (And what does "first part refer to")
I don't understand this comment.


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

https://reviews.llvm.org/D134337

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


[PATCH] D133659: [Clang] P1169R4: static operator()

2022-09-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I only left a few comments because I'm not familiar enough with that part of 
the code to be certain the changes are correct but overall it looks fine to me.




Comment at: clang/include/clang/Sema/Overload.h:524-526
+/// StaticObjectArgumentConversion is a formal value to represent
+/// the synthesized first argument of calls to static member functions
+/// ([over.best.ics.general]p8).





Comment at: clang/lib/Sema/SemaOverload.cpp:7023
+//
+// This is a new overload rule that was introduced in C++23 to support 
static lambdas. We apply it
+// retroactively because we want to support static lambdas as an extension 
and it doesn't hurt





Comment at: clang/lib/Sema/SemaOverload.cpp:7026
+// previous code.
+unsigned ConvIdx = PO == OverloadCandidateParamOrder::Reversed ? 1 : 0;
+ImplicitConversionSequence ICS;

Can we move that outside of the scope to avoid duplication?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133659

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


[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-29 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added a comment.

The previous test results (with some of my WIP patches but unrelated to this) 
before the fix:

  Failed Tests (6):
LLVM :: CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll
LLVM :: CodeGen/AMDGPU/GlobalISel/irtranslator-inline-asm.ll
LLVM :: CodeGen/Generic/vector.ll
LLVM :: CodeGen/PowerPC/2007-11-19-VectorSplitting.ll
LLVM :: CodeGen/X86/callbr-asm-kill.mir
LLVM :: DebugInfo/Generic/missing-abstract-variable.ll

Sure enough it was caught by my native build with all targets enabled, anyway 
it's important to at least enable the "big" targets such as X86 and AArch64 
when configuring the local dev env. ;-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134638

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


[PATCH] D133856: [clang][Interp] Pass initializer through when creating variables

2022-09-29 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGda62ed6ceb12: [clang][Interp] Pass initializer when creating 
globals (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D133856?vs=460057&id=463834#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133856

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

Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -69,7 +69,7 @@
   llvm::Optional getOrCreateDummy(const ParmVarDecl *PD);
 
   /// Creates a global and returns its index.
-  llvm::Optional createGlobal(const ValueDecl *VD);
+  llvm::Optional createGlobal(const ValueDecl *VD, const Expr *E);
 
   /// Creates a global from a lifetime-extended temporary.
   llvm::Optional createGlobal(const Expr *E);
@@ -111,7 +111,8 @@
   /// Creates a descriptor for a composite type.
   Descriptor *createDescriptor(const DeclTy &D, const Type *Ty,
bool IsConst = false, bool IsTemporary = false,
-   bool IsMutable = false);
+   bool IsMutable = false,
+   const Expr *Init = nullptr);
 
   /// Context to manage declaration lifetimes.
   class DeclScope {
@@ -134,7 +135,8 @@
   friend class DeclScope;
 
   llvm::Optional createGlobal(const DeclTy &D, QualType Ty,
-bool IsStatic, bool IsExtern);
+bool IsStatic, bool IsExtern,
+const Expr *Init = nullptr);
 
   /// Reference to the VM context.
   Context &Ctx;
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -127,7 +127,7 @@
   if (auto Idx = getGlobal(VD))
 return Idx;
 
-  if (auto Idx = createGlobal(VD)) {
+  if (auto Idx = createGlobal(VD, nullptr)) {
 GlobalIndices[VD] = *Idx;
 return Idx;
   }
@@ -153,7 +153,8 @@
   return {};
 }
 
-llvm::Optional Program::createGlobal(const ValueDecl *VD) {
+llvm::Optional Program::createGlobal(const ValueDecl *VD,
+   const Expr *Init) {
   bool IsStatic, IsExtern;
   if (auto *Var = dyn_cast(VD)) {
 IsStatic = !Var->hasLocalStorage();
@@ -162,7 +163,7 @@
 IsStatic = false;
 IsExtern = true;
   }
-  if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern)) {
+  if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
 for (const Decl *P = VD; P; P = P->getPreviousDecl())
   GlobalIndices[P] = *Idx;
 return *Idx;
@@ -175,7 +176,8 @@
 }
 
 llvm::Optional Program::createGlobal(const DeclTy &D, QualType Ty,
-   bool IsStatic, bool IsExtern) {
+   bool IsStatic, bool IsExtern,
+   const Expr *Init) {
   // Create a descriptor for the global.
   Descriptor *Desc;
   const bool IsConst = Ty.isConstQualified();
@@ -310,7 +312,7 @@
 
 Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
   bool IsConst, bool IsTemporary,
-  bool IsMutable) {
+  bool IsMutable, const Expr *Init) {
   // Classes and structures.
   if (auto *RT = Ty->getAs()) {
 if (auto *Record = getOrCreateRecord(RT->getDecl()))
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -513,18 +513,22 @@
   QualType Ty;
 
   const ValueDecl *Key = nullptr;
+  const Expr *Init = nullptr;
   bool IsTemporary = false;
-  if (auto *VD = dyn_cast_or_null(Src.dyn_cast())) {
+  if (auto *VD = dyn_cast_if_present(Src.dyn_cast())) {
 Key = VD;
 Ty = VD->getType();
+
+if (const auto *VarD = dyn_cast(VD))
+  Init = VarD->getInit();
   }
   if (auto *E = Src.dyn_cast()) {
 IsTemporary = true;
 Ty = E->getType();
   }
 
-  Descriptor *D = P.createDescriptor(Src, Ty.getTypePtr(),
- Ty.isConstQualified(), IsTemporary);
+  Descriptor *D = P.createDescriptor(
+  Src, Ty.getTypePtr(), Ty.isConstQualified(), IsTemporary, false, Init);
   if (!D)
 return {};
 
@@ -657,7 +661,7 @@
 bool ByteCodeExprGen::visitDecl(const VarDecl *VD) {
   const Expr *Init = VD->getInit();
 
-  if (Optional I = P.createGlobal(VD)) {
+  if (Optional I = P.createGlobal(VD, Init)) {
 if (Optional T = classify(VD->getType())) {

[clang] da62ed6 - [clang][Interp] Pass initializer when creating globals

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:54+02:00
New Revision: da62ed6ceb12031992d863ce272bc4863505b84b

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

LOG: [clang][Interp] Pass initializer when creating globals

This is dead code right now but will be used for implementing array
fillers, where we need some information from the initializer when
allocaing the Descriptors.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Program.cpp
clang/lib/AST/Interp/Program.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 0abd3ff736741..f86a7b1aa1898 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -513,18 +513,22 @@ ByteCodeExprGen::allocateLocal(DeclTy &&Src, 
bool IsExtended) {
   QualType Ty;
 
   const ValueDecl *Key = nullptr;
+  const Expr *Init = nullptr;
   bool IsTemporary = false;
-  if (auto *VD = dyn_cast_or_null(Src.dyn_cast())) {
+  if (auto *VD = dyn_cast_if_present(Src.dyn_cast())) 
{
 Key = VD;
 Ty = VD->getType();
+
+if (const auto *VarD = dyn_cast(VD))
+  Init = VarD->getInit();
   }
   if (auto *E = Src.dyn_cast()) {
 IsTemporary = true;
 Ty = E->getType();
   }
 
-  Descriptor *D = P.createDescriptor(Src, Ty.getTypePtr(),
- Ty.isConstQualified(), IsTemporary);
+  Descriptor *D = P.createDescriptor(
+  Src, Ty.getTypePtr(), Ty.isConstQualified(), IsTemporary, false, Init);
   if (!D)
 return {};
 
@@ -657,7 +661,7 @@ template 
 bool ByteCodeExprGen::visitDecl(const VarDecl *VD) {
   const Expr *Init = VD->getInit();
 
-  if (Optional I = P.createGlobal(VD)) {
+  if (Optional I = P.createGlobal(VD, Init)) {
 if (Optional T = classify(VD->getType())) {
   {
 // Primitive declarations - compute the value and set it.

diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index 0d4d84eab376b..aa700a1ce9e6f 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -127,7 +127,7 @@ llvm::Optional Program::getOrCreateGlobal(const 
ValueDecl *VD) {
   if (auto Idx = getGlobal(VD))
 return Idx;
 
-  if (auto Idx = createGlobal(VD)) {
+  if (auto Idx = createGlobal(VD, nullptr)) {
 GlobalIndices[VD] = *Idx;
 return Idx;
   }
@@ -153,7 +153,8 @@ llvm::Optional Program::getOrCreateDummy(const 
ParmVarDecl *PD) {
   return {};
 }
 
-llvm::Optional Program::createGlobal(const ValueDecl *VD) {
+llvm::Optional Program::createGlobal(const ValueDecl *VD,
+   const Expr *Init) {
   bool IsStatic, IsExtern;
   if (auto *Var = dyn_cast(VD)) {
 IsStatic = !Var->hasLocalStorage();
@@ -162,7 +163,7 @@ llvm::Optional Program::createGlobal(const 
ValueDecl *VD) {
 IsStatic = false;
 IsExtern = true;
   }
-  if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern)) {
+  if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
 for (const Decl *P = VD; P; P = P->getPreviousDecl())
   GlobalIndices[P] = *Idx;
 return *Idx;
@@ -175,7 +176,8 @@ llvm::Optional Program::createGlobal(const Expr 
*E) {
 }
 
 llvm::Optional Program::createGlobal(const DeclTy &D, QualType Ty,
-   bool IsStatic, bool IsExtern) {
+   bool IsStatic, bool IsExtern,
+   const Expr *Init) {
   // Create a descriptor for the global.
   Descriptor *Desc;
   const bool IsConst = Ty.isConstQualified();
@@ -310,7 +312,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
 
 Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
   bool IsConst, bool IsTemporary,
-  bool IsMutable) {
+  bool IsMutable, const Expr *Init) {
   // Classes and structures.
   if (auto *RT = Ty->getAs()) {
 if (auto *Record = getOrCreateRecord(RT->getDecl()))

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index ca985af8ad30b..b711bd278bc10 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -69,7 +69,7 @@ class Program {
   llvm::Optional getOrCreateDummy(const ParmVarDecl *PD);
 
   /// Creates a global and returns its index.
-  llvm::Optional createGlobal(const ValueDecl *VD);
+  llvm::Optional createGlobal(const ValueDecl *VD, const Expr *E);
 
   /// Creates a global from a lifetime-extended temporary.
   llvm::Optional createGlobal(const Expr *E);
@@ -1

[clang] 18a5fc5 - [clang][Interp][NFC] Remove an unnecessary include.

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:55+02:00
New Revision: 18a5fc52b28e9a612c8c531209f6bda5ff0964b7

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

LOG: [clang][Interp][NFC] Remove an unnecessary  include.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 5c96cd8d2340..c8df624dfa23 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -30,7 +30,6 @@
 #include "llvm/Support/Endian.h"
 #include 
 #include 
-#include 
 
 namespace clang {
 namespace interp {



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


[clang] 1d31549 - [clang][Interp][NFC] Forward-declare Pointer in InterpFrame.h

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:55+02:00
New Revision: 1d31549e9373962a1a76eb83b304b0c616aa21e7

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

LOG: [clang][Interp][NFC] Forward-declare Pointer in InterpFrame.h

We don't need the full include here.

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpFrame.h

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 9d01bf0333fe..60217ee9da27 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -10,6 +10,7 @@
 #include "Function.h"
 #include "Interp.h"
 #include "InterpStack.h"
+#include "Pointer.h"
 #include "PrimType.h"
 #include "Program.h"
 #include "clang/AST/DeclCXX.h"

diff  --git a/clang/lib/AST/Interp/InterpFrame.h 
b/clang/lib/AST/Interp/InterpFrame.h
index 16d073c8c3a0..fbd4207d42e2 100644
--- a/clang/lib/AST/Interp/InterpFrame.h
+++ b/clang/lib/AST/Interp/InterpFrame.h
@@ -14,7 +14,6 @@
 #define LLVM_CLANG_AST_INTERP_INTERPFRAME_H
 
 #include "Frame.h"
-#include "Pointer.h"
 #include "Program.h"
 #include "State.h"
 #include 
@@ -24,6 +23,7 @@ namespace clang {
 namespace interp {
 class Function;
 class InterpState;
+class Pointer;
 
 /// Frame storing local variables.
 class InterpFrame final : public Frame {



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


[clang] 1c35f3b - [clang][Interp][NFC] Unify emit() implementations

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:55+02:00
New Revision: 1c35f3b93aff7c39832f42f470c45fd24c3a779c

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

LOG: [clang][Interp][NFC] Unify emit() implementations

Instead of two overloads, use a if constexpr to differentiate between
pointer and non-pointer parameters

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 42a3ab7837f9..20e054ab87df 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -129,30 +129,28 @@ bool ByteCodeEmitter::bail(const SourceLocation &Loc) {
 /// Helper to write bytecode and bail out if 32-bit offsets become invalid.
 /// Pointers will be automatically marshalled as 32-bit IDs.
 template 
-static std::enable_if_t::value, void>
-emit(Program &P, std::vector &Code, const T &Val, bool &Success) {
-  size_t Size = sizeof(Val);
-  if (Code.size() + Size > std::numeric_limits::max()) {
-Success = false;
-return;
-  }
+static void emit(Program &P, std::vector &Code, const T &Val,
+ bool &Success) {
+  size_t Size;
 
-  const char *Data = reinterpret_cast(&Val);
-  Code.insert(Code.end(), Data, Data + Size);
-}
+  if constexpr (std::is_pointer_v)
+Size = sizeof(uint32_t);
+  else
+Size = sizeof(T);
 
-template 
-static std::enable_if_t::value, void>
-emit(Program &P, std::vector &Code, const T &Val, bool &Success) {
-  size_t Size = sizeof(uint32_t);
   if (Code.size() + Size > std::numeric_limits::max()) {
 Success = false;
 return;
   }
 
-  uint32_t ID = P.getOrCreateNativePointer(Val);
-  const char *Data = reinterpret_cast(&ID);
-  Code.insert(Code.end(), Data, Data + Size);
+  if constexpr (!std::is_pointer_v) {
+const char *Data = reinterpret_cast(&Val);
+Code.insert(Code.end(), Data, Data + Size);
+  } else {
+uint32_t ID = P.getOrCreateNativePointer(Val);
+const char *Data = reinterpret_cast(&ID);
+Code.insert(Code.end(), Data, Data + Size);
+  }
 }
 
 template 



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


[clang] ee2e414 - [clang][Interp] Handle sizeof()

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:55+02:00
New Revision: ee2e414d66a4b3b4e1a3bade11168a108f349d8a

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

LOG: [clang][Interp] Handle sizeof()

Implement visiting UnaryExprOrTypeTraitExprs to handle sizeof()
expressions.

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

Added: 


Modified: 
clang/lib/AST/Interp/Boolean.h
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index e739ce28e92c5..f1a0b9007df80 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -47,6 +47,10 @@ class Boolean {
   Boolean operator~() const { return Boolean(true); }
 
   explicit operator unsigned() const { return V; }
+  explicit operator int8_t() const { return V; }
+  explicit operator uint8_t() const { return V; }
+  explicit operator int16_t() const { return V; }
+  explicit operator uint16_t() const { return V; }
   explicit operator int64_t() const { return V; }
   explicit operator uint64_t() const { return V; }
   explicit operator int() const { return V; }

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index f86a7b1aa1898..5974678f0cfc9 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -281,7 +281,29 @@ bool ByteCodeExprGen::VisitConstantExpr(const 
ConstantExpr *E) {
 }
 
 template 
-bool ByteCodeExprGen::discard(const Expr *E) {
+bool ByteCodeExprGen::VisitUnaryExprOrTypeTraitExpr(
+const UnaryExprOrTypeTraitExpr *E) {
+
+  if (E->getKind() == UETT_SizeOf) {
+QualType ArgType = E->getTypeOfArgument();
+
+CharUnits Size;
+if (ArgType->isVoidType() || ArgType->isFunctionType())
+  Size = CharUnits::One();
+else {
+  if (ArgType->isDependentType() || !ArgType->isConstantSizeType())
+return false;
+
+  Size = Ctx.getASTContext().getTypeSizeInChars(ArgType);
+}
+
+return this->emitConst(E, Size.getQuantity());
+  }
+
+  return false;
+}
+
+template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
 }

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 6a74bc371855e..d73a8dfb18c28 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -80,6 +80,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E);
   bool VisitInitListExpr(const InitListExpr *E);
   bool VisitConstantExpr(const ConstantExpr *E);
+  bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 49cc0e0253de6..c743807714b1f 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -427,11 +427,11 @@ def Neg: Opcode {
 // TODO: Expand this to handle casts between more types.
 
 def FromCastTypeClass : TypeClass {
-  let Types = [Uint32, Sint32, Bool];
+  let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, 
Bool];
 }
 
 def ToCastTypeClass : TypeClass {
-  let Types = [Uint32, Sint32, Bool];
+  let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, 
Bool];
 }
 
 def Cast: Opcode {

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 5c1df00a25e77..5de727f005c86 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify 
%s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify 
%s
 // RUN: %clang_cc1 -std=c++11 -verify=ref %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
@@ -72,10 +74,74 @@ static_assert(*p == 10, "");
 constexpr const int* getIntPointer() {
   return &m;
 }
-//static_assert(getIntPointer() == &m, ""); TODO
-//static_assert(*getIntPointer() == 10, ""); TODO
+static_assert(getIntPointer() == &m, "");
+static_assert(*getIntPointer() == 10, "");
 
 constexpr int gimme(int k) {
   return k;
 }
-// static_assert(gimme(5) == 5, ""); TODO
+static_assert(gimme(5) == 5, "");
+
+namespace SizeOf {
+  constexpr int soint = sizeof(int);
+  constexpr int souint = sizeof(unsigned int);
+  static_assert(soint == souint, "");
+
+  static_assert(

[clang] 7c4cad4 - [clang][Interp][NFC] Make a few InterpStack functions const

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:55+02:00
New Revision: 7c4cad43309ebce4a9f3c656ca4629f8ac9ed877

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

LOG: [clang][Interp][NFC] Make a few InterpStack functions const

Added: 


Modified: 
clang/lib/AST/Interp/InterpStack.cpp
clang/lib/AST/Interp/InterpStack.h

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpStack.cpp 
b/clang/lib/AST/Interp/InterpStack.cpp
index 5c803f3d9424..7fe678e62192 100644
--- a/clang/lib/AST/Interp/InterpStack.cpp
+++ b/clang/lib/AST/Interp/InterpStack.cpp
@@ -46,7 +46,7 @@ void *InterpStack::grow(size_t Size) {
   return Object;
 }
 
-void *InterpStack::peek(size_t Size) {
+void *InterpStack::peek(size_t Size) const {
   assert(Chunk && "Stack is empty!");
 
   StackChunk *Ptr = Chunk;

diff  --git a/clang/lib/AST/Interp/InterpStack.h 
b/clang/lib/AST/Interp/InterpStack.h
index b02d3c6a34b0..2888f88fe6d7 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -48,12 +48,12 @@ class InterpStack final {
   }
 
   /// Returns a reference to the value on the top of the stack.
-  template  T &peek() {
+  template  T &peek() const {
 return *reinterpret_cast(peek(aligned_size()));
   }
 
   /// Returns a pointer to the top object.
-  void *top() { return Chunk ? peek(0) : nullptr; }
+  void *top() const { return Chunk ? peek(0) : nullptr; }
 
   /// Returns the size of the stack in bytes.
   size_t size() const { return StackSize; }
@@ -72,7 +72,7 @@ class InterpStack final {
   /// Grows the stack to accommodate a value and returns a pointer to it.
   void *grow(size_t Size);
   /// Returns a pointer from the top of the stack.
-  void *peek(size_t Size);
+  void *peek(size_t Size) const;
   /// Shrinks the stack.
   void shrink(size_t Size);
 
@@ -94,10 +94,13 @@ class InterpStack final {
 : Next(nullptr), Prev(Prev), End(reinterpret_cast(this + 1)) {}
 
 /// Returns the size of the chunk, minus the header.
-size_t size() { return End - start(); }
+size_t size() const { return End - start(); }
 
 /// Returns a pointer to the start of the data region.
 char *start() { return reinterpret_cast(this + 1); }
+const char *start() const {
+  return reinterpret_cast(this + 1);
+}
   };
   static_assert(sizeof(StackChunk) < ChunkSize, "Invalid chunk size");
 



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


[clang] df1cc80 - [clang][Interp] Record item types in InterpStack

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:55+02:00
New Revision: df1cc801da05a6436f6dc3062ccd490f236cd7ec

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

LOG: [clang][Interp] Record item types in InterpStack

The type information is lost when pushing things on the stack. When
later pop()ing items of the wrong type, we can instead simply get
garbage values and those problems are hard to find. Add another stack to
record the type of item we pushed and use that for debugging.

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

Added: 


Modified: 
clang/lib/AST/Interp/InterpStack.h

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpStack.h 
b/clang/lib/AST/Interp/InterpStack.h
index 2888f88fe6d7..7c338aa3e0ab 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -13,7 +13,9 @@
 #ifndef LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 #define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 
+#include "PrimType.h"
 #include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -29,10 +31,18 @@ class InterpStack final {
   /// Constructs a value in place on the top of the stack.
   template  void push(Tys &&... Args) {
 new (grow(aligned_size())) T(std::forward(Args)...);
+#ifndef NDEBUG
+ItemTypes.push_back(toPrimType());
+#endif
   }
 
   /// Returns the value from the top of the stack and removes it.
   template  T pop() {
+#ifndef NDEBUG
+assert(!ItemTypes.empty());
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 auto Value = std::move(*Ptr);
 Ptr->~T();
@@ -42,6 +52,10 @@ class InterpStack final {
 
   /// Discards the top value from the stack.
   template  void discard() {
+#ifndef NDEBUG
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 Ptr->~T();
 shrink(aligned_size());
@@ -108,6 +122,45 @@ class InterpStack final {
   StackChunk *Chunk = nullptr;
   /// Total size of the stack.
   size_t StackSize = 0;
+
+#ifndef NDEBUG
+  /// vector recording the type of data we pushed into the stack.
+  std::vector ItemTypes;
+
+  template  static constexpr PrimType toPrimType() {
+if constexpr (std::is_same_v)
+  return PT_Ptr;
+else if constexpr (std::is_same_v ||
+   std::is_same_v)
+  return PT_Bool;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint8;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint8;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint16;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint16;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint32;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint32;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint64;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint64;
+
+llvm_unreachable("unknown type push()'ed into InterpStack");
+  }
+#endif
 };
 
 } // namespace interp



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


[clang] c090295 - [clang][Interp] Handle enums

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:56+02:00
New Revision: c090295916a921e809184f589c6830475e293b8b

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

LOG: [clang][Interp] Handle enums

Handle DeclRefExprs of enum types. They are otherwise handled like
integers.

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

Added: 
clang/test/AST/Interp/enums.cpp

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5974678f0cfc9..9264357c568a3 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -861,6 +861,11 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
 
   FoundDecl = true;
 }
+  } else if (const auto *ECD = dyn_cast(Decl)) {
+PrimType T = *classify(ECD->getType());
+
+return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
+   E);
   }
 
   // References are implemented using pointers, so when we get here,

diff  --git a/clang/test/AST/Interp/enums.cpp b/clang/test/AST/Interp/enums.cpp
new file mode 100644
index 0..adb09e51881de
--- /dev/null
+++ b/clang/test/AST/Interp/enums.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+enum class EC : short {
+  A, B, C
+};
+static_assert(static_cast(EC::A) == 0, "");
+static_assert(static_cast(EC::B) == 1, "");
+static_assert(static_cast(EC::C) == 2, "");
+static_assert(sizeof(EC) == sizeof(short), "");
+
+constexpr EC ec = EC::C;
+static_assert(static_cast(ec) == 2, "");
+
+constexpr int N = 12;
+constexpr int M = 2;
+
+enum CE {
+  ONE = -1,
+  TWO = 2,
+  THREE,
+  FOUR = 4,
+  FIVE = N + M,
+  SIX = FIVE + 2,
+  MAX = __INT_MAX__ * 2U + 1U
+};
+static_assert(ONE == -1, "");
+static_assert(THREE == 3, "");
+static_assert(FIVE == 14, "");
+static_assert(SIX == 16, "");
+
+constexpr EC testEnums() {
+  EC e = EC::C;
+
+  e = EC::B;
+
+  EC::B = e; // expected-error{{expression is not assignable}} \
+ // ref-error{{expression is not assignable}}
+
+  return e;
+}
+
+constexpr EC getB() {
+  EC e = EC::C;
+  e = EC::B;
+  return e;
+}
+
+
+static_assert(getB() == EC::B, "");
+
+
+enum E { // expected-warning{{enumeration values exceed range of largest 
integer}} \
+ // ref-warning{{enumeration values exceed range of largest integer}}
+  E1 = -__LONG_MAX__ -1L,
+  E2 = __LONG_MAX__ *2UL+1UL
+};



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


[clang] 202ff42 - [clang][Interp] Rename a local variable to be more specific

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:56+02:00
New Revision: 202ff42f8990fb0bd0236a413c30dab357fd809a

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

LOG: [clang][Interp] Rename a local variable to be more specific

It's called BaseSize in the Record class as well, so call it BaseSize
when creating the Record.

Added: 


Modified: 
clang/lib/AST/Interp/Program.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index aa700a1ce9e6..e0dbdaa9a118 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -234,7 +234,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   }
 
   // Number of bytes required by fields and base classes.
-  unsigned Size = 0;
+  unsigned BaseSize = 0;
   // Number of bytes required by virtual base.
   unsigned VirtSize = 0;
 
@@ -258,9 +258,9 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   const RecordDecl *BD = Spec.getType()->castAs()->getDecl();
   Record *BR = getOrCreateRecord(BD);
   if (Descriptor *Desc = GetBaseDesc(BD, BR)) {
-Size += align(sizeof(InlineDescriptor));
-Bases.push_back({BD, Size, Desc, BR});
-Size += align(BR->getSize());
+BaseSize += align(sizeof(InlineDescriptor));
+Bases.push_back({BD, BaseSize, Desc, BR});
+BaseSize += align(BR->getSize());
 continue;
   }
   return nullptr;
@@ -284,7 +284,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   Record::FieldList Fields;
   for (const FieldDecl *FD : RD->fields()) {
 // Reserve space for the field's descriptor and the offset.
-Size += align(sizeof(InlineDescriptor));
+BaseSize += align(sizeof(InlineDescriptor));
 
 // Classify the field and add its metadata.
 QualType FT = FD->getType();
@@ -300,12 +300,12 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
 }
 if (!Desc)
   return nullptr;
-Fields.push_back({FD, Size, Desc});
-Size += align(Desc->getAllocSize());
+Fields.push_back({FD, BaseSize, Desc});
+BaseSize += align(Desc->getAllocSize());
   }
 
   Record *R = new (Allocator) Record(RD, std::move(Bases), std::move(Fields),
- std::move(VirtBases), VirtSize, Size);
+ std::move(VirtBases), VirtSize, BaseSize);
   Records.insert({RD, R});
   return R;
 }



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


[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-29 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee2e414d66a4: [clang][Interp] Handle sizeof() (authored by 
tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133934

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++11 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
 // RUN: %clang_cc1 -std=c++11 -verify=ref %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
 
 static_assert(true, "");
 static_assert(false, ""); // expected-error{{failed}} ref-error{{failed}}
@@ -72,10 +74,74 @@
 constexpr const int* getIntPointer() {
   return &m;
 }
-//static_assert(getIntPointer() == &m, ""); TODO
-//static_assert(*getIntPointer() == 10, ""); TODO
+static_assert(getIntPointer() == &m, "");
+static_assert(*getIntPointer() == 10, "");
 
 constexpr int gimme(int k) {
   return k;
 }
-// static_assert(gimme(5) == 5, ""); TODO
+static_assert(gimme(5) == 5, "");
+
+namespace SizeOf {
+  constexpr int soint = sizeof(int);
+  constexpr int souint = sizeof(unsigned int);
+  static_assert(soint == souint, "");
+
+  static_assert(sizeof(&soint) == sizeof(void*), "");
+  static_assert(sizeof(&soint) == sizeof(nullptr), "");
+
+  static_assert(sizeof(long) == sizeof(unsigned long), "");
+  static_assert(sizeof(char) == sizeof(unsigned char), "");
+
+  constexpr int N = 4;
+  constexpr int arr[N] = {1,2,3,4};
+  static_assert(sizeof(arr) == N * sizeof(int), "");
+  static_assert(sizeof(arr) == N * sizeof(arr[0]), "");
+
+  constexpr bool arrB[N] = {true, true, true, true};
+  static_assert(sizeof(arrB) == N * sizeof(bool), "");
+
+  static_assert(sizeof(bool) == 1, "");
+  static_assert(sizeof(char) == 1, "");
+
+  constexpr int F = sizeof(void); // expected-error{{incomplete type 'void'}} \
+  // ref-error{{incomplete type 'void'}}
+
+  constexpr int F2 = sizeof(gimme); // expected-error{{to a function type}} \
+// ref-error{{to a function type}}
+
+
+
+  /// FIXME: The following code should be accepted.
+  struct S {
+void func();
+  };
+  constexpr void (S::*Func)() = &S::func; // expected-error {{must be initialized by a constant expression}} \
+  // expected-error {{interpreter failed to evaluate an expression}}
+  static_assert(sizeof(Func) == sizeof(&S::func), "");
+
+
+  void func() {
+int n = 12;
+constexpr int oofda = sizeof(int[n++]); // expected-error {{must be initialized by a constant expression}} \
+// ref-error {{must be initialized by a constant expression}}
+  }
+
+
+#if __cplusplus >= 202002L
+  /// FIXME: The following code should be accepted.
+  consteval int foo(int n) { // ref-error {{consteval function never produces a constant expression}}
+return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}} \
+   // expected-note {{not valid in a constant expression}}
+  }
+  constinit int var = foo(5); // ref-error {{not a constant expression}} \
+  // ref-note 2{{in call to}} \
+  // ref-error {{does not have a constant initializer}} \
+  // ref-note {{required by 'constinit' specifier}} \
+  // expected-error  {{is not a constant expression}} \
+  // expected-note {{in call to}} \
+  // expected-error {{does not have a constant initializer}} \
+  // expected-note {{required by 'constinit' specifier}} \
+
+#endif
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -427,11 +427,11 @@
 // TODO: Expand this to handle casts between more types.
 
 def FromCastTypeClass : TypeClass {
-  let Types = [Uint32, Sint32, Bool];
+  let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, Bool];
 }
 
 def ToCastTypeClass : TypeClass {
-  let Types = [Uint32, Sint32, Bool];
+  let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, Bool];
 }
 
 def Cast: Opcode {
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -80,6 +80,7 @@
  

[clang] eadd505 - [clang][Interp][NFC] Limit includes to neccessary ones

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:56+02:00
New Revision: eadd505b0c054eacba7d0349505ea9ca1acf54f0

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

LOG: [clang][Interp][NFC] Limit includes to neccessary ones

Added: 


Modified: 
clang/lib/AST/Interp/Record.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Record.h b/clang/lib/AST/Interp/Record.h
index 9cdee9003752..db559d7a6bf4 100644
--- a/clang/lib/AST/Interp/Record.h
+++ b/clang/lib/AST/Interp/Record.h
@@ -13,7 +13,8 @@
 #ifndef LLVM_CLANG_AST_INTERP_RECORD_H
 #define LLVM_CLANG_AST_INTERP_RECORD_H
 
-#include "Pointer.h"
+#include "clang/AST/Decl.h"
+#include "Descriptor.h"
 
 namespace clang {
 namespace interp {



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


[clang] d5360b9 - [clang][Interp][NFC] Make classes final that can be final

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:56+02:00
New Revision: d5360b932ecd6fc7ca45f89d7c87ffb39f7edfe2

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

LOG: [clang][Interp][NFC] Make classes final that can be final

Added: 


Modified: 
clang/lib/AST/Interp/Boolean.h
clang/lib/AST/Interp/ByteCodeStmtGen.h
clang/lib/AST/Interp/Context.h
clang/lib/AST/Interp/Descriptor.h
clang/lib/AST/Interp/Function.h
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/Program.h
clang/lib/AST/Interp/Record.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index f1a0b9007df8..20831fff9ade 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -22,7 +22,7 @@ namespace clang {
 namespace interp {
 
 /// Wrapper around boolean types.
-class Boolean {
+class Boolean final {
  private:
   /// Underlying boolean.
   bool V;

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h 
b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 3bc665b84b4d..3a9a74038ee3 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -33,7 +33,7 @@ template  class LabelScope;
 
 /// Compilation context for statements.
 template 
-class ByteCodeStmtGen : public ByteCodeExprGen {
+class ByteCodeStmtGen final : public ByteCodeExprGen {
   using LabelTy = typename Emitter::LabelTy;
   using AddrTy = typename Emitter::AddrTy;
   using OptLabelTy = llvm::Optional;

diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index fbd781026850..96e93dbfc48b 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -33,7 +33,7 @@ class State;
 enum PrimType : unsigned;
 
 /// Holds all information required to evaluate constexpr code in a module.
-class Context {
+class Context final {
 public:
   /// Initialises the constexpr VM.
   Context(ASTContext &Ctx);

diff  --git a/clang/lib/AST/Interp/Descriptor.h 
b/clang/lib/AST/Interp/Descriptor.h
index 11072cab3e90..823ecd144e7c 100644
--- a/clang/lib/AST/Interp/Descriptor.h
+++ b/clang/lib/AST/Interp/Descriptor.h
@@ -48,7 +48,7 @@ using BlockMoveFn = void (*)(Block *Storage, char 
*SrcFieldPtr,
 using InterpSize = unsigned;
 
 /// Describes a memory block created by an allocation site.
-struct Descriptor {
+struct Descriptor final {
 private:
   /// Original declaration, used to emit the error message.
   const DeclTy Source;

diff  --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index d52560eaceb2..cd8b6d86eaed 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -29,7 +29,7 @@ enum PrimType : uint32_t;
 /// Describes a scope block.
 ///
 /// The block gathers all the descriptors of the locals defined in this block.
-class Scope {
+class Scope final {
 public:
   /// Information about a local's storage.
   struct Local {
@@ -56,7 +56,7 @@ class Scope {
 ///
 /// Contains links to the bytecode of the function, as well as metadata
 /// describing all arguments and stack-local variables.
-class Function {
+class Function final {
 public:
   using ParamDescriptor = std::pair;
 

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index d2498fda6181..50c9d7b6cc86 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -53,7 +53,7 @@ template <> struct Repr<64, true> { using Type = int64_t; };
 /// These wrappers are required to shared an interface between APSint and
 /// builtin primitive numeral types, while optimising for storage and
 /// allowing methods operating on primitive type to compile to fast code.
-template  class Integral {
+template  class Integral final {
 private:
   template  friend class Integral;
 

diff  --git a/clang/lib/AST/Interp/InterpBlock.h 
b/clang/lib/AST/Interp/InterpBlock.h
index 2d5386e60b8c..e4e693dab093 100644
--- a/clang/lib/AST/Interp/InterpBlock.h
+++ b/clang/lib/AST/Interp/InterpBlock.h
@@ -32,7 +32,7 @@ enum PrimType : unsigned;
 /// A memory block, either on the stack or in the heap.
 ///
 /// The storage described by the block immediately follows it in memory.
-class Block {
+class Block final {
 public:
   // Creates a new block.
   Block(const llvm::Optional &DeclID, Descriptor *Desc,
@@ -107,7 +107,7 @@ class Block {
 ///
 /// Dead blocks are chained in a double-linked list to deallocate them
 /// whenever pointers become dead.
-class DeadBlock {
+class DeadBlock final {
 public:
   /// Copies the block.
   DeadBlock(DeadBlock *&Root, Block *Blk);

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index b711bd278bc1..4807b752deed 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/cl

[clang] 8f5b061 - [clang][Interp][NFC] Make some Record methods const

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:56+02:00
New Revision: 8f5b061254744dedd95b6c0d03b909b4084611a3

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

LOG: [clang][Interp][NFC] Make some Record methods const

Added: 


Modified: 
clang/lib/AST/Interp/Record.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Record.h b/clang/lib/AST/Interp/Record.h
index db559d7a6bf4..117dd2b32d58 100644
--- a/clang/lib/AST/Interp/Record.h
+++ b/clang/lib/AST/Interp/Record.h
@@ -66,7 +66,7 @@ class Record {
 return llvm::make_range(Fields.begin(), Fields.end());
   }
 
-  unsigned getNumFields() { return Fields.size(); }
+  unsigned getNumFields() const { return Fields.size(); }
   Field *getField(unsigned I) { return &Fields[I]; }
 
   using const_base_iter = BaseList::const_iterator;
@@ -74,7 +74,7 @@ class Record {
 return llvm::make_range(Bases.begin(), Bases.end());
   }
 
-  unsigned getNumBases() { return Bases.size(); }
+  unsigned getNumBases() const { return Bases.size(); }
   Base *getBase(unsigned I) { return &Bases[I]; }
 
   using const_virtual_iter = VirtualBaseList::const_iterator;
@@ -82,7 +82,7 @@ class Record {
 return llvm::make_range(VirtualBases.begin(), VirtualBases.end());
   }
 
-  unsigned getNumVirtualBases() { return VirtualBases.size(); }
+  unsigned getNumVirtualBases() const { return VirtualBases.size(); }
   Base *getVirtualBase(unsigned I) { return &VirtualBases[I]; }
 
 private:



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


[PATCH] D133941: [clang][Interp] Record item types in InterpStack

2022-09-29 Thread Timm Bäder 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 rGdf1cc801da05: [clang][Interp] Record item types in 
InterpStack (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D133941?vs=460697&id=463836#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133941

Files:
  clang/lib/AST/Interp/InterpStack.h


Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -13,7 +13,9 @@
 #ifndef LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 #define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 
+#include "PrimType.h"
 #include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -29,10 +31,18 @@
   /// Constructs a value in place on the top of the stack.
   template  void push(Tys &&... Args) {
 new (grow(aligned_size())) T(std::forward(Args)...);
+#ifndef NDEBUG
+ItemTypes.push_back(toPrimType());
+#endif
   }
 
   /// Returns the value from the top of the stack and removes it.
   template  T pop() {
+#ifndef NDEBUG
+assert(!ItemTypes.empty());
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 auto Value = std::move(*Ptr);
 Ptr->~T();
@@ -42,6 +52,10 @@
 
   /// Discards the top value from the stack.
   template  void discard() {
+#ifndef NDEBUG
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 Ptr->~T();
 shrink(aligned_size());
@@ -108,6 +122,45 @@
   StackChunk *Chunk = nullptr;
   /// Total size of the stack.
   size_t StackSize = 0;
+
+#ifndef NDEBUG
+  /// vector recording the type of data we pushed into the stack.
+  std::vector ItemTypes;
+
+  template  static constexpr PrimType toPrimType() {
+if constexpr (std::is_same_v)
+  return PT_Ptr;
+else if constexpr (std::is_same_v ||
+   std::is_same_v)
+  return PT_Bool;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint8;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint8;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint16;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint16;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint32;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint32;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint64;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint64;
+
+llvm_unreachable("unknown type push()'ed into InterpStack");
+  }
+#endif
 };
 
 } // namespace interp


Index: clang/lib/AST/Interp/InterpStack.h
===
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -13,7 +13,9 @@
 #ifndef LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 #define LLVM_CLANG_AST_INTERP_INTERPSTACK_H
 
+#include "PrimType.h"
 #include 
+#include 
 
 namespace clang {
 namespace interp {
@@ -29,10 +31,18 @@
   /// Constructs a value in place on the top of the stack.
   template  void push(Tys &&... Args) {
 new (grow(aligned_size())) T(std::forward(Args)...);
+#ifndef NDEBUG
+ItemTypes.push_back(toPrimType());
+#endif
   }
 
   /// Returns the value from the top of the stack and removes it.
   template  T pop() {
+#ifndef NDEBUG
+assert(!ItemTypes.empty());
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 auto Value = std::move(*Ptr);
 Ptr->~T();
@@ -42,6 +52,10 @@
 
   /// Discards the top value from the stack.
   template  void discard() {
+#ifndef NDEBUG
+assert(ItemTypes.back() == toPrimType());
+ItemTypes.pop_back();
+#endif
 auto *Ptr = &peek();
 Ptr->~T();
 shrink(aligned_size());
@@ -108,6 +122,45 @@
   StackChunk *Chunk = nullptr;
   /// Total size of the stack.
   size_t StackSize = 0;
+
+#ifndef NDEBUG
+  /// vector recording the type of data we pushed into the stack.
+  std::vector ItemTypes;
+
+  template  static constexpr PrimType toPrimType() {
+if constexpr (std::is_same_v)
+  return PT_Ptr;
+else if constexpr (std::is_same_v ||
+   std::is_same_v)
+  return PT_Bool;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Sint8;
+else if constexpr (std::is_same_v ||
+   std::is_same_v>)
+  return PT_Uint8;
+else if constexpr (std::

[clang] 84f1df8 - [clang][Interp] Properly destruct allocated Records

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:56+02:00
New Revision: 84f1df8aacd0c3eb72f20f91c9af227b65d4c7da

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

LOG: [clang][Interp] Properly destruct allocated Records

We are otherwise leaking some memory the records might allocate
themselves.

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

Added: 


Modified: 
clang/lib/AST/Interp/Program.h
clang/test/AST/Interp/references.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index 4807b752deed7..6a00246644172 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -41,6 +41,14 @@ class Program final {
 public:
   Program(Context &Ctx) : Ctx(Ctx) {}
 
+  ~Program() {
+// Records might actually allocate memory themselves, but they
+// are allocated using a BumpPtrAllocator. Call their desctructors
+// here manually so they are properly freeing their resources.
+for (auto RecordPair : Records)
+  RecordPair.second->~Record();
+  }
+
   /// Marshals a native pointer to an ID for embedding in bytecode.
   unsigned getOrCreateNativePointer(const void *Ptr);
 

diff  --git a/clang/test/AST/Interp/references.cpp 
b/clang/test/AST/Interp/references.cpp
index 2b5187ca29dd9..9a23c0a92e530 100644
--- a/clang/test/AST/Interp/references.cpp
+++ b/clang/test/AST/Interp/references.cpp
@@ -75,7 +75,6 @@ static_assert(testGetValue() == 30, "");
 constexpr const int &MCE = 1; // expected-error{{must be initialized by a 
constant expression}}
 
 
-#if 0
 struct S {
   int i, j;
 };
@@ -89,5 +88,4 @@ constexpr int RefToMemberExpr() {
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, "");
-#endif
+static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an 
integral constant expression}}



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


[clang] f927b71 - [clang][Interp] Specify Boolean conversion operartors as (u)int32

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:57+02:00
New Revision: f927b71376c198a41f0c578be896bf231a6a5fd1

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

LOG: [clang][Interp] Specify Boolean conversion operartors as (u)int32

Follow up to https://reviews.llvm.org/D133934

Added: 


Modified: 
clang/lib/AST/Interp/Boolean.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Boolean.h b/clang/lib/AST/Interp/Boolean.h
index 20831fff9ade..3122388a49a5 100644
--- a/clang/lib/AST/Interp/Boolean.h
+++ b/clang/lib/AST/Interp/Boolean.h
@@ -46,14 +46,14 @@ class Boolean final {
   Boolean operator-() const { return Boolean(V); }
   Boolean operator~() const { return Boolean(true); }
 
-  explicit operator unsigned() const { return V; }
   explicit operator int8_t() const { return V; }
   explicit operator uint8_t() const { return V; }
   explicit operator int16_t() const { return V; }
   explicit operator uint16_t() const { return V; }
+  explicit operator int32_t() const { return V; }
+  explicit operator uint32_t() const { return V; }
   explicit operator int64_t() const { return V; }
   explicit operator uint64_t() const { return V; }
-  explicit operator int() const { return V; }
   explicit operator bool() const { return V; }
 
   APSInt toAPSInt() const {



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


[clang] e8ad133 - [clang][Interp][NFC] Remove unused function

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:57+02:00
New Revision: e8ad1339d441931326554bdc4ec6b7198f289028

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

LOG: [clang][Interp][NFC] Remove unused function

Added: 


Modified: 
clang/lib/AST/Interp/Program.cpp
clang/lib/AST/Interp/Program.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index e0dbdaa9a118..cca59bee1f20 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -208,19 +208,6 @@ Function *Program::getFunction(const FunctionDecl *F) {
   return It == Funcs.end() ? nullptr : It->second.get();
 }
 
-llvm::Expected Program::getOrCreateFunction(const FunctionDecl *F) 
{
-  if (Function *Func = getFunction(F)) {
-return Func;
-  }
-
-  // Try to compile the function if it wasn't compiled yet.
-  if (const FunctionDecl *FD = F->getDefinition())
-return ByteCodeStmtGen(Ctx, *this).compileFunc(FD);
-
-  // A relocation which traps if not resolved.
-  return nullptr;
-}
-
 Record *Program::getOrCreateRecord(const RecordDecl *RD) {
   // Use the actual definition as a key.
   RD = RD->getDefinition();

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index 6a0024664417..1a175d8b0f20 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -100,11 +100,6 @@ class Program final {
   /// Returns a function.
   Function *getFunction(const FunctionDecl *F);
 
-  /// Returns a pointer to a function if it exists and can be compiled.
-  /// If a function couldn't be compiled, an error is returned.
-  /// If a function was not yet defined, a null pointer is returned.
-  llvm::Expected getOrCreateFunction(const FunctionDecl *F);
-
   /// Returns a record or creates one if it does not exist.
   Record *getOrCreateRecord(const RecordDecl *RD);
 



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


[clang] 7c65d57 - [clang][Interp][NFC] Unify the two ReadArg() implementations

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:57+02:00
New Revision: 7c65d57af0ef20ce28ca9c1efae8e3214d57268d

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

LOG: [clang][Interp][NFC] Unify the two ReadArg() implementations

Just use a constexpr if here instead of two different implementations.
[#

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index c8df624dfa23..0df7ead28cd3 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -993,17 +993,13 @@ inline bool ExpandPtr(InterpState &S, CodePtr OpPC) {
 // Read opcode arguments
 
//===--===//
 
-template 
-inline std::enable_if_t::value, T> ReadArg(InterpState &S,
-   CodePtr &OpPC) {
-  return OpPC.read();
-}
-
-template 
-inline std::enable_if_t::value, T> ReadArg(InterpState &S,
-  CodePtr &OpPC) {
-  uint32_t ID = OpPC.read();
-  return reinterpret_cast(S.P.getNativePointer(ID));
+template  inline T ReadArg(InterpState &S, CodePtr &OpPC) {
+  if constexpr (std::is_pointer::value) {
+uint32_t ID = OpPC.read();
+return reinterpret_cast(S.P.getNativePointer(ID));
+  } else {
+return OpPC.read();
+  }
 }
 
 /// Interpreter entry point.



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


[clang] 9837a3b - [clang][Interp][NFC] Remove unused opcode argument types

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:57+02:00
New Revision: 9837a3bd4b91317b1f84eab9ffc1c3c1c57e59a0

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

LOG: [clang][Interp][NFC] Remove unused opcode argument types

Added: 


Modified: 
clang/lib/AST/Interp/Opcodes.td

Removed: 




diff  --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index c743807714b1..7591c3dc7c30 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -43,17 +43,7 @@ def ArgUint64 : ArgType { let Name = "uint64_t"; }
 def ArgBool : ArgType { let Name = "bool"; }
 
 def ArgFunction : ArgType { let Name = "const Function *"; }
-def ArgRecord : ArgType { let Name = "Record *"; }
-
-def ArgSema : ArgType { let Name = "const fltSemantics *"; }
-
-def ArgExpr : ArgType { let Name = "const Expr *"; }
-def ArgFloatingLiteral : ArgType { let Name = "const FloatingLiteral *"; }
-def ArgCXXMethodDecl : ArgType { let Name = "const CXXMethodDecl *"; }
-def ArgFunctionDecl : ArgType { let Name = "const FunctionDecl *"; }
 def ArgRecordDecl : ArgType { let Name = "const RecordDecl *"; }
-def ArgCXXRecordDecl : ArgType { let Name = "const CXXRecordDecl *"; }
-def ArgValueDecl : ArgType { let Name = "const ValueDecl *"; }
 def ArgRecordField : ArgType { let Name = "const Record::Field *"; }
 
 
//===--===//



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


[PATCH] D134020: [clang][Interp] Handle enums

2022-09-29 Thread Timm Bäder 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 rGc090295916a9: [clang][Interp] Handle enums (authored by 
tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/enums.cpp


Index: clang/test/AST/Interp/enums.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/enums.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+enum class EC : short {
+  A, B, C
+};
+static_assert(static_cast(EC::A) == 0, "");
+static_assert(static_cast(EC::B) == 1, "");
+static_assert(static_cast(EC::C) == 2, "");
+static_assert(sizeof(EC) == sizeof(short), "");
+
+constexpr EC ec = EC::C;
+static_assert(static_cast(ec) == 2, "");
+
+constexpr int N = 12;
+constexpr int M = 2;
+
+enum CE {
+  ONE = -1,
+  TWO = 2,
+  THREE,
+  FOUR = 4,
+  FIVE = N + M,
+  SIX = FIVE + 2,
+  MAX = __INT_MAX__ * 2U + 1U
+};
+static_assert(ONE == -1, "");
+static_assert(THREE == 3, "");
+static_assert(FIVE == 14, "");
+static_assert(SIX == 16, "");
+
+constexpr EC testEnums() {
+  EC e = EC::C;
+
+  e = EC::B;
+
+  EC::B = e; // expected-error{{expression is not assignable}} \
+ // ref-error{{expression is not assignable}}
+
+  return e;
+}
+
+constexpr EC getB() {
+  EC e = EC::C;
+  e = EC::B;
+  return e;
+}
+
+
+static_assert(getB() == EC::B, "");
+
+
+enum E { // expected-warning{{enumeration values exceed range of largest 
integer}} \
+ // ref-warning{{enumeration values exceed range of largest integer}}
+  E1 = -__LONG_MAX__ -1L,
+  E2 = __LONG_MAX__ *2UL+1UL
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -861,6 +861,11 @@
 
   FoundDecl = true;
 }
+  } else if (const auto *ECD = dyn_cast(Decl)) {
+PrimType T = *classify(ECD->getType());
+
+return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
+   E);
   }
 
   // References are implemented using pointers, so when we get here,


Index: clang/test/AST/Interp/enums.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/enums.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+enum class EC : short {
+  A, B, C
+};
+static_assert(static_cast(EC::A) == 0, "");
+static_assert(static_cast(EC::B) == 1, "");
+static_assert(static_cast(EC::C) == 2, "");
+static_assert(sizeof(EC) == sizeof(short), "");
+
+constexpr EC ec = EC::C;
+static_assert(static_cast(ec) == 2, "");
+
+constexpr int N = 12;
+constexpr int M = 2;
+
+enum CE {
+  ONE = -1,
+  TWO = 2,
+  THREE,
+  FOUR = 4,
+  FIVE = N + M,
+  SIX = FIVE + 2,
+  MAX = __INT_MAX__ * 2U + 1U
+};
+static_assert(ONE == -1, "");
+static_assert(THREE == 3, "");
+static_assert(FIVE == 14, "");
+static_assert(SIX == 16, "");
+
+constexpr EC testEnums() {
+  EC e = EC::C;
+
+  e = EC::B;
+
+  EC::B = e; // expected-error{{expression is not assignable}} \
+ // ref-error{{expression is not assignable}}
+
+  return e;
+}
+
+constexpr EC getB() {
+  EC e = EC::C;
+  e = EC::B;
+  return e;
+}
+
+
+static_assert(getB() == EC::B, "");
+
+
+enum E { // expected-warning{{enumeration values exceed range of largest integer}} \
+ // ref-warning{{enumeration values exceed range of largest integer}}
+  E1 = -__LONG_MAX__ -1L,
+  E2 = __LONG_MAX__ *2UL+1UL
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -861,6 +861,11 @@
 
   FoundDecl = true;
 }
+  } else if (const auto *ECD = dyn_cast(Decl)) {
+PrimType T = *classify(ECD->getType());
+
+return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
+   E);
   }
 
   // References are implemented using pointers, so when we get here,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f55c4b4 - [clang][Interp] Print Function address in dump()

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T12:50:57+02:00
New Revision: f55c4b4ee3d11cb8028edeabed91284ec7c3276d

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

LOG: [clang][Interp] Print Function address in dump()

It's used in the bytecode dump of the function itself, so useful to
identify which function is being called.

Added: 


Modified: 
clang/lib/AST/Interp/Disasm.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 2edf6b908c4a..82cc8492d57a 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -40,10 +40,11 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) 
const {
   if (F) {
 if (auto *Cons = dyn_cast(F)) {
   DeclarationName Name = Cons->getParent()->getDeclName();
-  OS << Name << "::" << Name << ":\n";
+  OS << Name << "::" << Name;
 } else {
-  OS << F->getDeclName() << ":\n";
+  OS << F->getDeclName();
 }
+OS << " " << (void*)this << ":\n";
   } else {
 OS << "<>\n";
   }



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


[PATCH] D134054: [clang][Interp] Properly destruct allocated Records

2022-09-29 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG84f1df8aacd0: [clang][Interp] Properly destruct allocated 
Records (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D134054?vs=460813&id=463839#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134054

Files:
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/references.cpp


Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -75,7 +75,6 @@
 constexpr const int &MCE = 1; // expected-error{{must be initialized by a 
constant expression}}
 
 
-#if 0
 struct S {
   int i, j;
 };
@@ -89,5 +88,4 @@
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, "");
-#endif
+static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an 
integral constant expression}}
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -41,6 +41,14 @@
 public:
   Program(Context &Ctx) : Ctx(Ctx) {}
 
+  ~Program() {
+// Records might actually allocate memory themselves, but they
+// are allocated using a BumpPtrAllocator. Call their desctructors
+// here manually so they are properly freeing their resources.
+for (auto RecordPair : Records)
+  RecordPair.second->~Record();
+  }
+
   /// Marshals a native pointer to an ID for embedding in bytecode.
   unsigned getOrCreateNativePointer(const void *Ptr);
 


Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -75,7 +75,6 @@
 constexpr const int &MCE = 1; // expected-error{{must be initialized by a constant expression}}
 
 
-#if 0
 struct S {
   int i, j;
 };
@@ -89,5 +88,4 @@
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, "");
-#endif
+static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an integral constant expression}}
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -41,6 +41,14 @@
 public:
   Program(Context &Ctx) : Ctx(Ctx) {}
 
+  ~Program() {
+// Records might actually allocate memory themselves, but they
+// are allocated using a BumpPtrAllocator. Call their desctructors
+// here manually so they are properly freeing their resources.
+for (auto RecordPair : Records)
+  RecordPair.second->~Record();
+  }
+
   /// Marshals a native pointer to an ID for embedding in bytecode.
   unsigned getOrCreateNativePointer(const void *Ptr);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134871: [llvm] [lit] Move %clang_dxc substitution from clang/test

2022-09-29 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: python3kgae, beanz, MaskRay, zturner.
Herald added subscribers: StephenFan, delcypher.
Herald added a project: All.
mgorny requested review of this revision.
Herald added a project: LLVM.

Move the `%clang_dxc` substitution from local definition in clang/test
to lit's `llvm/config.py` module where all other driver definitions
are found.  This improves consistency and makes it easier to control
global clang options.


https://reviews.llvm.org/D134871

Files:
  clang/test/lit.cfg.py
  llvm/utils/lit/lit/llvm/config.py


Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -544,6 +544,8 @@
 extra_args=['--driver-mode=cpp']+additional_flags),
   ToolSubst('%clang_cl', command=self.config.clang,
 extra_args=['--driver-mode=cl']+additional_flags),
+  ToolSubst('%clang_dxc', command=self.config.clang,
+extra_args=['--driver-mode=dxc']+additional_flags),
   ToolSubst('%clangxx', command=self.config.clang,
 extra_args=['--driver-mode=g++']+additional_flags),
   ]
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -63,8 +63,6 @@
 'clang-tblgen', 'clang-scan-deps', 'opt', 'llvm-ifs', 'yaml2obj', 
'clang-linker-wrapper',
 ToolSubst('%clang_extdef_map', command=FindTool(
 'clang-extdef-mapping'), unresolved='ignore'),
-ToolSubst('%clang_dxc', command=config.clang,
-extra_args=['--driver-mode=dxc']),
 ]
 
 if config.clang_examples:


Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -544,6 +544,8 @@
 extra_args=['--driver-mode=cpp']+additional_flags),
   ToolSubst('%clang_cl', command=self.config.clang,
 extra_args=['--driver-mode=cl']+additional_flags),
+  ToolSubst('%clang_dxc', command=self.config.clang,
+extra_args=['--driver-mode=dxc']+additional_flags),
   ToolSubst('%clangxx', command=self.config.clang,
 extra_args=['--driver-mode=g++']+additional_flags),
   ]
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -63,8 +63,6 @@
 'clang-tblgen', 'clang-scan-deps', 'opt', 'llvm-ifs', 'yaml2obj', 'clang-linker-wrapper',
 ToolSubst('%clang_extdef_map', command=FindTool(
 'clang-extdef-mapping'), unresolved='ignore'),
-ToolSubst('%clang_dxc', command=config.clang,
-extra_args=['--driver-mode=dxc']),
 ]
 
 if config.clang_examples:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e6171e8 - [Clang][Arm] Fix fp16 return error tests under AArch64/Arm. NFC

2022-09-29 Thread David Green via cfe-commits

Author: David Green
Date: 2022-09-29T12:16:13+01:00
New Revision: e6171e87e16c59df5fba642d1f48de6f0a2d93d8

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

LOG: [Clang][Arm] Fix fp16 return error tests under AArch64/Arm. NFC

The -fallow-half-arguments-and-returns option was removed in
59528e4bdb27ed4ab3, replaced with an always-on target option under
AArch64/Arm. There are two tests - fp16-sema.c and renderscripts.rs that
test that an error is produced for __fp16 function args/returns, which
are now expected to pass for Arm/AArch64. i.e they no longer give the
same error as before on native Arm/AArch64 machines. Alter the targets
of those tests to compensate.

Added: 


Modified: 
clang/test/Sema/fp16-sema.c
clang/test/Sema/renderscript.rs

Removed: 




diff  --git a/clang/test/Sema/fp16-sema.c b/clang/test/Sema/fp16-sema.c
index e403ba69e826..f5406c519159 100644
--- a/clang/test/Sema/fp16-sema.c
+++ b/clang/test/Sema/fp16-sema.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -Wno-strict-prototypes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-pc-linux-gnu 
-Wno-strict-prototypes -verify %s
+// // REQUIRES: x86-registered-target
 
 // Functions cannot have parameters of type __fp16.
 extern void f (__fp16); // expected-error {{parameters cannot have __fp16 
type; did you forget * ?}}

diff  --git a/clang/test/Sema/renderscript.rs b/clang/test/Sema/renderscript.rs
index 79b50e981411..8fa0d4389e7f 100644
--- a/clang/test/Sema/renderscript.rs
+++ b/clang/test/Sema/renderscript.rs
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -x renderscript -D__RENDERSCRIPT__ %s
-// RUN: %clang_cc1 -fsyntax-only -verify -x c %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify -x c %s
+// REQUIRES: x86-registered-target
 
 #ifndef __RENDERSCRIPT__
 // expected-warning@+2 {{'kernel' attribute ignored}}



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


[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

2022-09-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D133468#3823143 , @sammccall wrote:

> Sorry about the delay, I've been juggling too many things :-(

No worries, thanks!

> TL;DR: yes, I think it's reasonable. I think the implementation complexity is 
> justified by what we get. Thanks for explaining!
>
> I think to minimize interface complexity, we should basically consider this 
> to just weaken the invariants of TypedefType etc, and have comments 
> reflecting that. Accordingly like to see `inDivergent()` inverted and named 
> something like `typeMatchesDecl()` if it needs to be exposed at all.

Yeah, I think it's better to just not expose it in general.
One minor problem with inverting it is that we would make the most common case 
the positive case. Though if we want to avoid the churn and noise, on the 
TextNode dumper we will probably want to add a flag only in the negative case.

> Thanks, this is compelling! Couple of observations, not objections:
>
> - applications often print the fully-sugared type (`type2`) and/or the 
> canonical type (`int`) with nothing in between. This might limit the benefits 
> - I've often wished we had better & sharable heuristics for how much 
> desugaring users want.

Yeah I am aware, the `aka` handling will step over typedefs, we will have to 
work on a better solution for that separate problem.

> - in this simple example we could naively solve the problem by having the 
> class instantiation that it was instantiated with `Int` sugar, and making the 
> original underlying type of A::type1 as `Int`. (There are downsides 
> here, you can obviously get the "wrong" sugar if there are multiple 
> instantiation sites).

Yeah, I think it could cause too many surprises if we instantiated only one 
time per canonical type, but then used the sugar for the first instantiation:

- It would cause surprising behavior when instantiating with attributes which 
have effects beyond meaning for the user. Think over-aligned typedefs and such.
- Unless resugaring is on and always able to correct it when printing a 
diagnostic, it could produce references to types which are distant from the 
context the problem occurred.

> Yes! Though half of my `basic_string` sugar problems are things like 
> `substr`'s return type. This seems harder to solve in a principled way, 
> though maybe heuristically doable when the written return type uses the 
> injected-class-name? Anyway, again offtopic for this patch...

Yeah, that for now is out of scope of the whole project even, except that maybe 
we could make this work for templated explicit object parameter.

The injected class name approach feels like it would even come short of solving 
it, even ignoring false positives. I think this would be a problem we would 
want to solve even for methods of regular (non-template) classes.

But it does not seem like it would justify the cost of templating a parameter 
just for the return type sugar.

> And I also expected that it would end up being in more nodes than TypedefType 
> and UsingType - it's hard to see why it stops there.

It won't stop here, we can do this for any type node which gets its sugared 
type from some other object which is expensive to rebuild (declarations, 
expressions, etc)

TypedefType is the most critical here, and UsingType is it's secret twin, so 
might as well do both in the same patch.

> But it sounds more like we expect ~no programmatic clients to care, and that 
> this change is mostly:
>
> - drop the assumption that decl & type have the same sugar, because of 
> resugaring
> - add isDivergent() just to enable the text dump to provide hints to human 
> analysis

Yeah that was the point of my question, I don't see why any user would care, 
and just rather not add complexity here. Glad that you agree :)

> If you're talking about *runtime* cost - it's not obvious that it's 
> significantly more expensive? IIUC wherever types are resugared we're having 
> to duplicate the chain of sugar (e.g. a function that returns T** is going to 
> be instantiated as functiontype(pointertype(pointertype(typedeftype(int 
> and then resugared as 
> functiontype(pointertype(pointertype(/*divergent*/typedeftype(typedeftype(int).
>  The difference between enlarging typedeftype with trailing objects vs adding 
> an extra node feels like a drop in the bucket. That said, I can't think of a 
> way to do this that's both compact *and* much simpler, and simplicity would 
> be the point.

No, I am not worried about the difference in reusing TypedefType + extra bit, 
versus making it a derived class or some such.
I was more worried about the cost of of adding AST nodes which explain how a 
type was resugared, for example providing a pointer to the naming context used 
to resugar. That seems too expensive, for no utility.

> Yes. In fact I've been scared by the discussion of "maybe we should have 
> flags to ramp up/down sugar" as it's hard enough to write AST-wrangling cod

[PATCH] D20401: [Lexer] Don't merge macro args from different macro files

2022-09-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added subscribers: hokein, sammccall.
sammccall added a comment.
Herald added a project: All.

In D20401#2770059 , @nickdesaulniers 
wrote:

> I know this was sped up slightly in 3339c568c43e4644f02289e5edfc78c860f19c9f, 
> but this change makes `updateConsecutiveMacroArgTokens` the hottest function 
> in clang in a bottom up profile of an entire build of the Linux kernel.  It 
> thrashes the one entry LastFileIDLookup cache, and we end up looking up the 
> same FileID again and again and again for each token when we expand nested 
> function like macros.
>
> Is there anything we can do to speed this up?

@hokein and I spent some time looking at this (initially trying to understand 
behavior, now performance).

Short version is:

- we can *simplify* the code a lot, we think it's now just partitioning based 
on FileID and this can be done more clearly. This may have some speedups at the 
margin.
- in terms of performance: I suspect when clang is built by GCC it's doing 
roughly 3x as much work as when it's built by clang. @nickdesaulniers can you 
tell me which you're measuring/deploying? To give some idea if we're likely to 
actually help much...

---

**Behavior: partitioning by file IDs**

I think we're back to the original (<2011) behavior of just partitioning by 
file IDs

- the original patch 

 clearly intended this to merge tokens across file IDs, and the comments still 
claim this
- then a bugfix 

 banned merging file+macro or macro+file
- then this patch banned merging macro+macro
- meanwhile, there's no code disallowing file+file, but I don't think it's 
actually possible to achieve: you can't have an `#include` or an `eof` inside a 
macro arg, and I don't know how else to switch between files.

**Performance (good case)**

The current obfuscated version *is* faster than the pre-2011 version because we 
avoid getFileID() in when testing file+macro, macro+file, and *some* 
macro+macro cases (when the locations happen to be >50 apart).
When we see a run of N consecutive macro nearby macro tokens, we do `2*(N-1)` 
getFileID()s.

We can reduce the number of getFileID() calls by caching FileID bounds (the 
expensive part is looking up the SLocEntry - given that we can hit-test a 
SourceLocation against it with simple arithmetic).

However, getFileID() has the one-element cache of SLocEntry, so this may only 
be a marginal improvement.

  // Tokens A1 A2 A3 B1 B2
  
  isWrittenInSameFile(A1, A2);
getFileID(A1); // miss
getFileID(A2);
  isWrittenInSameFile(A2, A3);
getFileID(A2);
getFileID(A3);
  isWrittenInSameFile(A3, B1);
getFileID(A3);
getFileID(B1); // miss
  isWrittenInSameFile(B1, B2);
getFileID(B1);
getFileID(B2);

All the getFileID() calls we could avoid are the cached ones. It's probably 
still a win (the cache lookup logic is kinda messy), but probably not huge.

**Performance (bad case)**

However, the implementation of `isWrittenInSameFile` is `getFileID(X) == 
getFileID(Y)`, and it's unspecified which gets evaluated first. GCC generally 
evaluates right-to-left (https://godbolt.org/z/M4bs74Tbj), producing 
substantially more misses:

  isWrittenInSameFile(A1, A2);
getFileID(A2); // miss
getFileID(A1);
  isWrittenInSameFile(A2, A3);
getFileID(A3);
getFileID(A2);
  isWrittenInSameFile(A3, B1);
getFileID(B1); // miss
getFileID(A3); // miss
  isWrittenInSameFile(B1, B2);
getFileID(B2); // miss
getFileID(B1);

So I'd expect we can improve GCC-built-clang's performance by maybe 2x by 
caching externally.
(Or by having isWrittenInSameFile try to cleverly evaluate whichever arg 
matches the cache first, but I have no idea whether that will work well across 
clang)

---

@hokein or I will try to find time to take a stab at this.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D20401

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-09-29 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 463846.

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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -253,3 +253,27 @@
 #endif
 
 };
+
+namespace floats {
+  constexpr int i = 2;
+  constexpr float f = 1.0f;
+  static_assert(f == 1.0f, "");
+
+  constexpr float f2 = 1u * f;
+  static_assert(f2 == 1.0f, "");
+
+  static_assert(1.0f + 3u == 4, "");
+  static_assert(4.0f / 1.0f == 4, "");
+  static_assert(10.0f * false == 0, "");
+
+  constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+  constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{division by zero}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{division by zero}}
+
+  static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+ // expected-error {{invalid argument type 'float' to unary expression}}
+
+};
Index: clang/lib/AST/Interp/Primitives.h
===
--- /dev/null
+++ clang/lib/AST/Interp/Primitives.h
@@ -0,0 +1,34 @@
+//===-- Primitives.h - Types for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities and helper functions for all primitive types:
+//  - Integral
+//  - Floating
+//  - Boolean
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+#define LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+
+namespace clang {
+namespace interp {
+
+/// Helper to compare two comparable types.
+template  ComparisonCategoryResult Compare(const T &X, const T &Y) {
+  if (X < Y)
+return ComparisonCategoryResult::Less;
+  if (X > Y)
+return ComparisonCategoryResult::Greater;
+  return ComparisonCategoryResult::Equal;
+}
+
+} // namespace interp
+} // namespace clang
+
+#endif
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,11 +13,12 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
 #include 
-#include "Boolean.h"
-#include "Integral.h"
 
 namespace clang {
 namespace interp {
@@ -35,6 +36,7 @@
   PT_Sint64,
   PT_Uint64,
   PT_Bool,
+  PT_Float32,
   PT_Ptr,
 };
 
@@ -48,6 +50,7 @@
 template <> struct PrimConv { using T = Integral<32, false>; };
 template <> struct PrimConv { using T = Integral<64, true>; };
 template <> struct PrimConv { using T = Integral<64, false>; };
+template <> struct PrimConv { using T = Floating<32>; };
 template <> struct PrimConv { using T = Boolean; };
 template <> struct PrimConv { using T = Pointer; };
 
@@ -70,6 +73,7 @@
   case PT_Uint32:
   case PT_Sint64:
   case PT_Uint64:
+  case PT_Float32:
 return true;
   default:
 return false;
@@ -94,6 +98,7 @@
   TYPE_SWITCH_CASE(PT_Uint32, B)   \
   TYPE_SWITCH_CASE(PT_Sint64, B)   \
   TYPE_SWITCH_CASE(PT_Uint64, B)   \
+  TYPE_SWITCH_CASE(PT_Float32, B)  \
   TYPE_SWITCH_CASE(PT_Bool, B) \
   TYPE_SWITCH_CASE(PT_Ptr, B)  \
 }  \
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -25,6 +25,7 @@
 def Uint32 : Type;
 def Sint64 : Type;
 def Uint64 : Type;
+def Float32 : Type;
 def Ptr : Type;
 
 //===--===//
@@ -40,6 +41,7 @@
 def ArgUin

[PATCH] D134020: [clang][Interp] Handle enums

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



Comment at: clang/test/AST/Interp/enums.cpp:25
+  SIX = FIVE + 2,
+
+};

shafik wrote:
> Maybe some edge case values for enumerators like `__INT_MAX__  *2U +1U` 
> (UINT_MAX) 
> 
> and 
> 
> ```
> enum E { // warning: enumeration values exceed range of largest integer 
> [-Wenum-too-large]
>   E1 = -__LONG_MAX__ -1L,
>   E2 = __LONG_MAX__ *2UL+1UL 
> };
> ```
Hm, looks like that test broke one of the windows builders: 
https://lab.llvm.org/buildbot/#/builders/123/builds/13424 - are enums larger by 
default on Windows? What do you suggest to fix the test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


[clang] f444a7c - Revert "[clang][Interp] Handle enums"

2022-09-29 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-09-29T13:45:52+02:00
New Revision: f444a7cc16bb0bbfdac719b46b7e0950e6e78ce2

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

LOG: Revert "[clang][Interp] Handle enums"

This reverts commit c090295916a921e809184f589c6830475e293b8b.

One of the test cases fails. Revert this until I know a way to make it
work reliably.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 
clang/test/AST/Interp/enums.cpp



diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 9264357c568a..5974678f0cfc 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -861,11 +861,6 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
 
   FoundDecl = true;
 }
-  } else if (const auto *ECD = dyn_cast(Decl)) {
-PrimType T = *classify(ECD->getType());
-
-return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
-   E);
   }
 
   // References are implemented using pointers, so when we get here,

diff  --git a/clang/test/AST/Interp/enums.cpp b/clang/test/AST/Interp/enums.cpp
deleted file mode 100644
index adb09e51881d..
--- a/clang/test/AST/Interp/enums.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
-// RUN: %clang_cc1 -verify=ref %s
-
-enum class EC : short {
-  A, B, C
-};
-static_assert(static_cast(EC::A) == 0, "");
-static_assert(static_cast(EC::B) == 1, "");
-static_assert(static_cast(EC::C) == 2, "");
-static_assert(sizeof(EC) == sizeof(short), "");
-
-constexpr EC ec = EC::C;
-static_assert(static_cast(ec) == 2, "");
-
-constexpr int N = 12;
-constexpr int M = 2;
-
-enum CE {
-  ONE = -1,
-  TWO = 2,
-  THREE,
-  FOUR = 4,
-  FIVE = N + M,
-  SIX = FIVE + 2,
-  MAX = __INT_MAX__ * 2U + 1U
-};
-static_assert(ONE == -1, "");
-static_assert(THREE == 3, "");
-static_assert(FIVE == 14, "");
-static_assert(SIX == 16, "");
-
-constexpr EC testEnums() {
-  EC e = EC::C;
-
-  e = EC::B;
-
-  EC::B = e; // expected-error{{expression is not assignable}} \
- // ref-error{{expression is not assignable}}
-
-  return e;
-}
-
-constexpr EC getB() {
-  EC e = EC::C;
-  e = EC::B;
-  return e;
-}
-
-
-static_assert(getB() == EC::B, "");
-
-
-enum E { // expected-warning{{enumeration values exceed range of largest 
integer}} \
- // ref-warning{{enumeration values exceed range of largest integer}}
-  E1 = -__LONG_MAX__ -1L,
-  E2 = __LONG_MAX__ *2UL+1UL
-};



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


[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-29 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 463847.
SixWeining added a comment.
Herald added subscribers: kosarev, kerbowa, jvesely.

update CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll and 
CodeGen/AMDGPU/GlobalISel/irtranslator-inline-asm.ll


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134638

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/test/CodeGen/LoongArch/inline-asm-constraints.c
  llvm/include/llvm/IR/InlineAsm.h
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.cpp
  llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-inline-asm.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZB.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-ZC.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-k.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
  llvm/test/CodeGen/X86/callbr-asm-kill.mir

Index: llvm/test/CodeGen/X86/callbr-asm-kill.mir
===
--- llvm/test/CodeGen/X86/callbr-asm-kill.mir
+++ llvm/test/CodeGen/X86/callbr-asm-kill.mir
@@ -67,7 +67,7 @@
   ; CHECK-NEXT:   CALL64pcrel32 target-flags(x86-plt) @foo, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp
   ; CHECK-NEXT:   ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
   ; CHECK-NEXT:   [[COPY4:%[0-9]+]]:gr64 = COPY [[MOV64rm]]
-  ; CHECK-NEXT:   INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 196654 /* mem:m */, killed [[MOV64rm]], 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop)
+  ; CHECK-NEXT:   INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 262190 /* mem:m */, killed [[MOV64rm]], 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop)
   ; CHECK-NEXT:   JMP_1 %bb.2
   ; CHECK-NEXT: {{  $}}
   ; CHECK-NEXT: bb.2.end:
@@ -87,7 +87,7 @@
 $rdi = COPY killed %0
 CALL64pcrel32 target-flags(x86-plt) @foo, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp
 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
-INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 196654 /* mem:m */, %1, 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop)
+INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 262190 /* mem:m */, %1, 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop)
 JMP_1 %bb.2
 
   bb.2.end:
Index: llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/inline-asm-constraint-m.ll
@@ -0,0 +1,145 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA32
+; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s | FileCheck %s --check-prefix=LA64
+
+define i32 @m_offset_neg_2049(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_2049:
+; LA32:   # %bb.0:
+; LA32-NEXT:lu12i.w $a1, -1
+; LA32-NEXT:ori $a1, $a1, 2047
+; LA32-NEXT:add.w $a0, $a0, $a1
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, 0
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_2049:
+; LA64:   # %bb.0:
+; LA64-NEXT:lu12i.w $a1, -1
+; LA64-NEXT:ori $a1, $a1, 2047
+; LA64-NEXT:add.d $a0, $a0, $a1
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, 0
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 -2049
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_neg_2048(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_2048:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, -2048
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_2048:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:ld.w $a0, $a0, -2048
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = getelementptr inbounds i8, ptr %p, i32 -2048
+  %2 = call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %1)
+  ret i32 %2
+}
+
+define i32 @m_offset_neg_1(ptr %p) nounwind {
+; LA32-LABEL: m_offset_neg_1:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:ld.w $a0, $a0, -1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: m_offset_neg_1:
+; L

[PATCH] D134638: [Clang][LoongArch] Add inline asm support for constraints k/m/ZB/ZC

2022-09-29 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added a comment.

In D134638#3823379 , @xen0n wrote:

> The previous test results (with some of my WIP patches but unrelated to this) 
> before the fix:
>
>   Failed Tests (6):
> LLVM :: CodeGen/AArch64/GlobalISel/irtranslator-inline-asm.ll
> LLVM :: CodeGen/AMDGPU/GlobalISel/irtranslator-inline-asm.ll
> LLVM :: CodeGen/Generic/vector.ll
> LLVM :: CodeGen/PowerPC/2007-11-19-VectorSplitting.ll
> LLVM :: CodeGen/X86/callbr-asm-kill.mir
> LLVM :: DebugInfo/Generic/missing-abstract-variable.ll
>
> Sure enough it was caught by my native build with all targets enabled, anyway 
> it's important to at least enable the "big" targets such as X86 and AArch64 
> when configuring the local dev env. ;-)

Thanks for the tip. Just now I enabled all official targets and LoongArch and 
find 2 more fail tests (for same reason) for AArch64 and AMDGPU. I have fixed 
them and updated the patch.

Sorry again...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134638

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


[PATCH] D134020: [clang][Interp] Handle enums

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



Comment at: clang/test/AST/Interp/enums.cpp:25
+  SIX = FIVE + 2,
+
+};

tbaeder wrote:
> shafik wrote:
> > Maybe some edge case values for enumerators like `__INT_MAX__  *2U +1U` 
> > (UINT_MAX) 
> > 
> > and 
> > 
> > ```
> > enum E { // warning: enumeration values exceed range of largest integer 
> > [-Wenum-too-large]
> >   E1 = -__LONG_MAX__ -1L,
> >   E2 = __LONG_MAX__ *2UL+1UL 
> > };
> > ```
> Hm, looks like that test broke one of the windows builders: 
> https://lab.llvm.org/buildbot/#/builders/123/builds/13424 - are enums larger 
> by default on Windows? What do you suggest to fix the test?
If we're trying to be compatible with MSVC, we use their rules for picking the 
underlying type of an enumeration is which not fixed. One way to handle this is 
to add more RUN lines with explicit triples, but I think we lose too much 
interesting coverage that way. I'd probably use a `#ifndef _MSC_VER` block to 
control the expected diagnostics with a comment as to why the diagnostic is not 
expected on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


[clang] b934be2 - [Support] Class for response file expansion (NFC)

2022-09-29 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2022-09-29T19:15:01+07:00
New Revision: b934be2c059a99351d08069bb80155e49f047b6e

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

LOG: [Support] Class for response file expansion (NFC)

Functions that implement expansion of response and config files depend
on many options, which are passes as arguments. Extending the expansion
requires new options, it in turn causes changing calls in various places
making them even more bulky.

This change introduces a class ExpansionContext, which represents set of
options that control the expansion. Its methods implements expansion of
responce files including config files. It makes extending the expansion
easier.

No functional changes.

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/tools/driver/driver.cpp
flang/tools/flang-driver/driver.cpp
llvm/include/llvm/Support/CommandLine.h
llvm/include/llvm/Support/StringSaver.h
llvm/lib/Support/CommandLine.cpp
llvm/unittests/Support/CommandLineTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a40a992ac0877..f2ae25df5825e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -956,7 +956,9 @@ static void appendOneArg(InputArgList &Args, const Arg *Opt,
 bool Driver::readConfigFile(StringRef FileName) {
   // Try reading the given file.
   SmallVector NewCfgArgs;
-  if (!llvm::cl::readConfigFile(FileName, Saver, NewCfgArgs, getVFS())) {
+  llvm::cl::ExpansionContext ExpCtx(Alloc, llvm::cl::tokenizeConfigFile);
+  ExpCtx.setVFS(&getVFS());
+  if (!ExpCtx.readConfigFile(FileName, NewCfgArgs)) {
 Diag(diag::err_drv_cannot_read_config_file) << FileName;
 return true;
   }

diff  --git a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp 
b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
index 75d0d50d851f9..c4b3abc1a0a45 100644
--- a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -60,9 +60,10 @@ class ExpandResponseFilesDatabase : public 
CompilationDatabase {
   if (!SeenRSPFile)
 continue;
   llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver(Alloc);
-  llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, 
false,
-llvm::StringRef(Cmd.Directory), *FS);
+  llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
+  ECtx.setVFS(FS.get())
+  .setCurrentDir(Cmd.Directory)
+  .expandResponseFiles(Argv);
   // Don't assign directly, Argv aliases CommandLine.
   std::vector ExpandedArgv(Argv.begin(), Argv.end());
   Cmd.CommandLine = std::move(ExpandedArgv);

diff  --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 34335a599a008..11eba44fcf22e 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -308,9 +308,8 @@ static int ExecuteCC1Tool(SmallVectorImpl 
&ArgV) {
   llvm::cl::ResetAllOptionOccurrences();
 
   llvm::BumpPtrAllocator A;
-  llvm::StringSaver Saver(A);
-  llvm::cl::ExpandResponseFiles(Saver, &llvm::cl::TokenizeGNUCommandLine, ArgV,
-/*MarkEOLs=*/false);
+  llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine);
+  ECtx.expandResponseFiles(ArgV);
   StringRef Tool = ArgV[1];
   void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath;
   if (Tool == "-cc1")
@@ -373,7 +372,8 @@ int clang_main(int Argc, char **Argv) {
 
   if (MarkEOLs && Args.size() > 1 && StringRef(Args[1]).startswith("-cc1"))
 MarkEOLs = false;
-  llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Args, MarkEOLs);
+  llvm::cl::ExpansionContext ECtx(A, Tokenizer);
+  ECtx.setMarkEOLs(MarkEOLs).expandResponseFiles(Args);
 
   // Handle -cc1 integrated tools, even if -cc1 was expanded from a response
   // file.

diff  --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index 1fee09d1df853..3ab6fc6205011 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -76,7 +76,8 @@ static void ExpandResponseFiles(
 llvm::StringSaver &saver, llvm::SmallVectorImpl &args) {
   // We're defaulting to the GNU syntax, since we don't have a CL mode.
   llvm::cl::TokenizerCallback tokenizer = &llvm::cl::TokenizeGNUCommandLine;
-  llvm::cl::ExpandResponseFiles(saver, tokenizer, args, /* MarkEOLs=*/false);
+  llvm::cl::ExpansionContext ExpCtx(saver.getAllocator(), tokenizer);
+  ExpCtx.expandResponseFiles(args);
 }
 
 int main(int argc, const char **argv) {

diff  --git a/llvm/include/llvm/Support/Com

[clang] e62b3a9 - Unwind-tables: move back to original logic outline for kind.

2022-09-29 Thread Tim Northover via cfe-commits

Author: Tim Northover
Date: 2022-09-29T13:39:06+01:00
New Revision: e62b3a9375d8694efe5bf3d1409bec9be0d288e9

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

LOG: Unwind-tables: move back to original logic outline for kind.

There are lots of options interacting in complex ways here, and when moving to
`getDefaultUnwindTableLevel` I had refactored this and changed behaviour in
some cases. So this reverts the basic structure of the logic back to the
original, while leaving the hook in the new style.

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index c93a7276f1a9..5ea9e8085302 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5470,27 +5470,24 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
   auto SanitizeArgs = TC.getSanitizerArgs(Args);
-  auto UnwindTables = TC.getDefaultUnwindTableLevel(Args);
-
-  const bool HasSyncUnwindTables = Args.hasFlag(
-  options::OPT_funwind_tables, options::OPT_fno_unwind_tables, false);
-  if (Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
-   options::OPT_fno_asynchronous_unwind_tables,
-   SanitizeArgs.needsUnwindTables()) &&
-  !Freestanding)
-UnwindTables = ToolChain::UnwindTableLevel::Asynchronous;
-  else if (HasSyncUnwindTables)
-UnwindTables = ToolChain::UnwindTableLevel::Synchronous;
-  else if (Args.hasFlag(options::OPT_fno_unwind_tables,
-   options::OPT_fno_asynchronous_unwind_tables,
-   options::OPT_funwind_tables, false) || Freestanding)
-UnwindTables = ToolChain::UnwindTableLevel::None;
-
-
-  if (UnwindTables == ToolChain::UnwindTableLevel::Synchronous)
-CmdArgs.push_back("-funwind-tables=1");
-  else if (UnwindTables == ToolChain::UnwindTableLevel::Asynchronous)
+
+  bool IsAsyncUnwindTablesDefault =
+  TC.getDefaultUnwindTableLevel(Args) == 
ToolChain::UnwindTableLevel::Asynchronous;
+  bool IsSyncUnwindTablesDefault =
+  TC.getDefaultUnwindTableLevel(Args) == 
ToolChain::UnwindTableLevel::Synchronous;
+
+  bool AsyncUnwindTables = Args.hasFlag(
+  options::OPT_fasynchronous_unwind_tables,
+  options::OPT_fno_asynchronous_unwind_tables,
+  (IsAsyncUnwindTablesDefault || SanitizeArgs.needsUnwindTables()) &&
+  !Freestanding);
+  bool UnwindTables =
+  Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
+   IsSyncUnwindTablesDefault && !Freestanding);
+  if (AsyncUnwindTables)
 CmdArgs.push_back("-funwind-tables=2");
+  else if (UnwindTables)
+ CmdArgs.push_back("-funwind-tables=1");
 
   // Prepare `-aux-target-cpu` and `-aux-target-feature` unless
   // `--gpu-use-aux-triple-only` is specified.
@@ -7316,7 +7313,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-faddrsig");
 
   if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
-  (EH || UnwindTables != ToolChain::UnwindTableLevel::None ||
+  (EH || UnwindTables || AsyncUnwindTables ||
DebugInfoKind != codegenoptions::NoDebugInfo))
 CmdArgs.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1");
 

diff  --git a/clang/test/Driver/clang-translation.c 
b/clang/test/Driver/clang-translation.c
index 715b0b3150bd..ca98ca5e8228 100644
--- a/clang/test/Driver/clang-translation.c
+++ b/clang/test/Driver/clang-translation.c
@@ -99,6 +99,17 @@
 //
 // ARM64-EXPLICIT-UWTABLE-APPLE: -funwind-tables
 
+// RUN: %clang -target arm64-apple-macosx -### -ffreestanding 
-fasynchronous-unwind-tables %s 2>&1 | \
+// RUN: FileCheck --check-prefix=ASYNC-UNWIND-FREESTANDING %s
+//
+// ASYNC-UNWIND-FREESTANDING: -funwind-tables=2
+
+// Quite weird behaviour, but it's a long-standing default.
+// RUN: %clang -target x86_64-apple-macosx -### -fno-unwind-tables %s 2>&1 |\
+// RUN: FileCheck --check-prefix=NOUNWIND-IGNORED %s
+//
+// NOUNWIND-IGNORED: -funwind-tables=2
+
 // RUN: %clang -target arm64-apple-ios10 -fno-exceptions -### -S %s -arch 
arm64 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM64-APPLE-EXCEP %s
 // ARM64-APPLE-EXCEP-NOT: -funwind-tables



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


[PATCH] D134640: Unwind-tables: move back to original logic outline for kind.

2022-09-29 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover closed this revision.
t.p.northover added a comment.

Sorry about that, committed as e62b3a9375d8 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134640

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


[PATCH] D130510: Missing tautological compare warnings due to unary operators

2022-09-29 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

In D130510#3821641 , @aaron.ballman 
wrote:

> In D130510#3817148 , @ebevhan wrote:
>
>> Hi! A bit of late feedback on this patch. We found a failure in our 
>> downstream testing likely originating from here.
>
> Thank you for the feedback! I've addressed the issue in 
> 96a79cb308d1b8c00a83b180d9fecc5d54bacb9c 
> .

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510

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


[PATCH] D131465: C++/ObjC++: switch to gnu++17 as the default standard

2022-09-29 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D131465#3821701 , @aaron.ballman 
wrote:

> Perhaps the simple rule we're going for is "when executed on Windows, Clang 
> defaults to C++17 unless it is executed from a context in which an MSVC 
> library can be detected, in which case Clang defaults to the same language 
> standard as used by that version of MSVC"? It's a bit long-winded, but the 
> idea being that we try to match MSVC's default when compiling against MSVC 
> libraries and otherwise stick with the clang default.

But the last sentence is basically what we have today. When targeting 
windows-msvc, we try to match the behavior of the msvc version being targeted, 
which is in turn determined by what flags the user passes, what msvc 
installation is found in the environment, or the default (19.14).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131465

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


[PATCH] D134872: AMDGPU: Add __builtin_amdgcn_permlane64

2022-09-29 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: yaxunl, AMDGPU.
Herald added subscribers: kosarev, kerbowa, t-tye, tpr, dstuttard, jvesely, 
kzhuravl.
Herald added a project: All.
arsenm requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D134872

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
  clang/test/SemaOpenCL/builtins-amdgcn-gfx11.cl
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td


Index: llvm/include/llvm/IR/IntrinsicsAMDGPU.td
===
--- llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -1991,6 +1991,7 @@
 
 // llvm.amdgcn.permlane64 
 def int_amdgcn_permlane64 :
+  ClangBuiltin<"__builtin_amdgcn_permlane64">,
   Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
 [IntrNoMem, IntrConvergent, IntrWillReturn]>;
 
Index: clang/test/SemaOpenCL/builtins-amdgcn-gfx11.cl
===
--- clang/test/SemaOpenCL/builtins-amdgcn-gfx11.cl
+++ clang/test/SemaOpenCL/builtins-amdgcn-gfx11.cl
@@ -13,4 +13,6 @@
 #if __has_builtin(__builtin_amdgcn_s_sendmsg_rtnl)
   *out2 = __builtin_amdgcn_s_sendmsg_rtnl(x); // GFX11-error {{argument to 
'__builtin_amdgcn_s_sendmsg_rtnl' must be a constant integer}}
 #endif
+
+  *out1 = __builtin_amdgcn_permlane64(x); // GFX10-error 
{{'__builtin_amdgcn_permlane64' needs target feature gfx11-insts}}
 }
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
@@ -31,3 +31,9 @@
 {
   *out = __builtin_amdgcn_ds_bvh_stack_rtn(addr, data, data1, 128);
 }
+
+// CHECK-LABEL: @test_permlane64(
+// CHECK: call i32 @llvm.amdgcn.permlane64(i32 %a)
+void test_permlane64(global uint* out, uint a) {
+  *out = __builtin_amdgcn_permlane64(a);
+}
Index: clang/include/clang/Basic/BuiltinsAMDGPU.def
===
--- clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -259,6 +259,9 @@
 // GFX11+ only builtins.
 
//===--===//
 
+// TODO: This is a no-op in wave32. Should the builtin require wavefrontsize64?
+TARGET_BUILTIN(__builtin_amdgcn_permlane64, "UiUi", "nc", "gfx11-insts")
+
 
//===--===//
 // WMMA builtins.
 // Postfix w32 indicates the builtin requires wavefront size of 32.


Index: llvm/include/llvm/IR/IntrinsicsAMDGPU.td
===
--- llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -1991,6 +1991,7 @@
 
 // llvm.amdgcn.permlane64 
 def int_amdgcn_permlane64 :
+  ClangBuiltin<"__builtin_amdgcn_permlane64">,
   Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
 [IntrNoMem, IntrConvergent, IntrWillReturn]>;
 
Index: clang/test/SemaOpenCL/builtins-amdgcn-gfx11.cl
===
--- clang/test/SemaOpenCL/builtins-amdgcn-gfx11.cl
+++ clang/test/SemaOpenCL/builtins-amdgcn-gfx11.cl
@@ -13,4 +13,6 @@
 #if __has_builtin(__builtin_amdgcn_s_sendmsg_rtnl)
   *out2 = __builtin_amdgcn_s_sendmsg_rtnl(x); // GFX11-error {{argument to '__builtin_amdgcn_s_sendmsg_rtnl' must be a constant integer}}
 #endif
+
+  *out1 = __builtin_amdgcn_permlane64(x); // GFX10-error {{'__builtin_amdgcn_permlane64' needs target feature gfx11-insts}}
 }
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-gfx11.cl
@@ -31,3 +31,9 @@
 {
   *out = __builtin_amdgcn_ds_bvh_stack_rtn(addr, data, data1, 128);
 }
+
+// CHECK-LABEL: @test_permlane64(
+// CHECK: call i32 @llvm.amdgcn.permlane64(i32 %a)
+void test_permlane64(global uint* out, uint a) {
+  *out = __builtin_amdgcn_permlane64(a);
+}
Index: clang/include/clang/Basic/BuiltinsAMDGPU.def
===
--- clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -259,6 +259,9 @@
 // GFX11+ only builtins.
 //===--===//
 
+// TODO: This is a no-op in wave32. Should the builtin require wavefrontsize64?
+TARGET_BUILTIN(__builtin_amdgcn_permlane64, "UiUi", "nc", "gfx11-insts")
+
 //===--===//
 // WMMA builtins.
 // Postfix w32 indicates the builtin requires wavefront size of 32.
___
cfe-commits mail

[PATCH] D134303: [AST] Preserve more structure in UsingEnumDecl node.

2022-09-29 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added a comment.

Does this still apply with the fix for dr2621 landed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134303

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


[PATCH] D134020: [clang][Interp] Handle enums

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



Comment at: clang/test/AST/Interp/enums.cpp:25
+  SIX = FIVE + 2,
+
+};

aaron.ballman wrote:
> tbaeder wrote:
> > shafik wrote:
> > > Maybe some edge case values for enumerators like `__INT_MAX__  *2U +1U` 
> > > (UINT_MAX) 
> > > 
> > > and 
> > > 
> > > ```
> > > enum E { // warning: enumeration values exceed range of largest integer 
> > > [-Wenum-too-large]
> > >   E1 = -__LONG_MAX__ -1L,
> > >   E2 = __LONG_MAX__ *2UL+1UL 
> > > };
> > > ```
> > Hm, looks like that test broke one of the windows builders: 
> > https://lab.llvm.org/buildbot/#/builders/123/builds/13424 - are enums 
> > larger by default on Windows? What do you suggest to fix the test?
> If we're trying to be compatible with MSVC, we use their rules for picking 
> the underlying type of an enumeration is which not fixed. One way to handle 
> this is to add more RUN lines with explicit triples, but I think we lose too 
> much interesting coverage that way. I'd probably use a `#ifndef _MSC_VER` 
> block to control the expected diagnostics with a comment as to why the 
> diagnostic is not expected on Windows.
The second builder that broke was  a hexagon builder: 
https://lab.llvm.org/buildbot/#/builders/38/builds/6231 - this would still fail 
with the `_MSC_VER` change, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


[PATCH] D134874: [Concepts] Fix Concepts on generic lambda in a VarTemplateSpecDecl

2022-09-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: tahonermann, shafik.
Herald added a project: All.
erichkeane requested review of this revision.

As fallout of the Deferred Concept Instantiation patch (babdef27c5 
), we
got a number of reports of a regression, where we asserted when
instantiating a constraint on a generic lambda inside of a variable
template. See: https://github.com/llvm/llvm-project/issues/57958

The problem was that getTemplateInstantiationArgs function only walked
up declaration contexts, and missed that this is not necessarily the
case with a lambda (which can ALSO be in a separate context).

This patch refactors the getTemplateInstantiationArgs function in a way
that is hopefully more readable, and fixes the problem with the concepts
on a generic lambda.


https://reviews.llvm.org/D134874

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/concepts-lambda.cpp

Index: clang/test/SemaTemplate/concepts-lambda.cpp
===
--- clang/test/SemaTemplate/concepts-lambda.cpp
+++ clang/test/SemaTemplate/concepts-lambda.cpp
@@ -13,3 +13,45 @@
   f();
   };
 }
+
+namespace GH57945_2 {
+  template
+concept c = true;
+
+  template
+auto f = [](auto... args) requires c  {
+};
+
+  template 
+  auto f2 = [](auto... args)
+requires (sizeof...(args) > 0)
+  {};
+
+  void g() {
+  f();
+  f2(5.0);
+  }
+}
+
+namespace GH57958 {
+  template concept C = true;
+  template constexpr bool v = [](C auto) { return true; }(0);
+  int _ = v<0>;
+}
+namespace GH57958_2 {
+  template concept C = true;
+  template constexpr bool v = [](C auto...) { return true; }(0);
+  int _ = v<0>;
+}
+
+namespace GH57971 {
+  template
+concept any = true;
+
+  template
+auto f = [](any auto) {
+};
+
+  using function_ptr = void(*)(int);
+  function_ptr ptr = f;
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -40,6 +40,191 @@
 // Template Instantiation Support
 //===--===/
 
+namespace {
+namespace TemplateInstArgsHelpers {
+struct Response {
+  bool IsDone = false;
+  const Decl *NextDecl = nullptr;
+  bool ChangeRelativeToPrimary = true;
+  static Response Done() {
+Response R;
+R.IsDone = true;
+return R;
+  }
+  static Response ChangeDecl(const Decl *ND) {
+Response R;
+R.NextDecl = ND;
+return R;
+  }
+  static Response ChangeDecl(const DeclContext *Ctx) {
+Response R;
+R.NextDecl = Decl::castFromDeclContext(Ctx);
+return R;
+  }
+  static Response DontChangeRelativeToPrimary() {
+Response R;
+R.ChangeRelativeToPrimary = false;
+return R;
+  }
+};
+// Add template arguments from a variable template instantiation. For a
+// class-scope explicit specialization, there are no template arguments
+// at this level, but there may be enclosing template arguments.
+Response
+HandleVarTemplateSpec(const VarTemplateSpecializationDecl *VarTemplSpec,
+  MultiLevelTemplateArgumentList &Result) {
+  if (VarTemplSpec->isClassScopeExplicitSpecialization())
+return Response::DontChangeRelativeToPrimary();
+
+  // We're done when we hit an explicit specialization.
+  if (VarTemplSpec->getSpecializationKind() == TSK_ExplicitSpecialization &&
+  !isa(VarTemplSpec))
+return Response::Done();
+
+  Result.addOuterTemplateArguments(
+  &VarTemplSpec->getTemplateInstantiationArgs());
+
+  // If this variable template specialization was instantiated from a
+  // specialized member that is a variable template, we're done.
+  assert(VarTemplSpec->getSpecializedTemplate() && "No variable template?");
+  llvm::PointerUnion
+  Specialized = VarTemplSpec->getSpecializedTemplateOrPartial();
+  if (VarTemplatePartialSpecializationDecl *Partial =
+  Specialized.dyn_cast()) {
+if (Partial->isMemberSpecialization())
+  return Response::Done();
+  } else {
+VarTemplateDecl *Tmpl = Specialized.get();
+if (Tmpl->isMemberSpecialization())
+  return Response::Done();
+  }
+  return Response::DontChangeRelativeToPrimary();
+}
+
+// If we have a template template parameter with translation unit context,
+// then we're performing substitution into a default template argument of
+// this template template parameter before we've constructed the template
+// that will own this template template parameter. In this case, we
+// use empty template parameter lists for all of the outer templates
+// to avoid performing a

[PATCH] D134454: [Driver][Distro] Fix ArchLinux sysroot detection

2022-09-29 Thread Adrian Ratiu via Phabricator via cfe-commits
10ne1 marked 7 inline comments as done.
10ne1 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Linux.cpp:363
   const StringRef TripleStr = GCCInstallation.getTriple().str();
-  const Multilib &Multilib = GCCInstallation.getMultilib();
+  std::string Path = (InstallDir + "/../../../../" + TripleStr).str();
 

nickdesaulniers wrote:
> With all of the string concatenation going on, I wonder if `Path` should be a 
> `Twine`?  `llvm::vfs::Filesystem::exists` accepts a `const Twine&`.  That 
> avoids multiple reallocations and copies, and does one lazily.
> 
> (Every time I've tried to use `Twine`, I wind up with either `-Wdangling-gsl` 
> or segfaults though! Still, please give it a shot.)
I tried making Twine work but I got many errors, couldn't even make it build. 
Looks like twine doesn't have `+=` operator for strings, and I also got many 
`error: use of deleted function ‘llvm::Twine& llvm::Twine::operator=(const 
llvm::Twine&)’`. C++ is such a mystery language.

Please let's just leave it a string for now, it's enough cleanups. :) Thanks!


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

https://reviews.llvm.org/D134454

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


[PATCH] D134454: [Driver][Distro] Fix ArchLinux sysroot detection

2022-09-29 Thread Adrian Ratiu via Phabricator via cfe-commits
10ne1 updated this revision to Diff 463864.
10ne1 marked an inline comment as done.
10ne1 added a comment.

Updated based on feedback from Nick.


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

https://reviews.llvm.org/D134454

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


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -355,40 +355,31 @@
   return AndroidSysRootPath;
   }
 
-  if (getTriple().isCSKY()) {
-// CSKY toolchains use different names for sysroot folder.
-if (!GCCInstallation.isValid())
-  return std::string();
-// GCCInstallation.getInstallPath() =
-//   $GCCToolchainPath/lib/gcc/csky-linux-gnuabiv2/6.3.0
-// Path = $GCCToolchainPath/csky-linux-gnuabiv2/libc
-std::string Path = (GCCInstallation.getInstallPath() + "/../../../../" +
-GCCInstallation.getTriple().str() + "/libc")
-   .str();
-if (getVFS().exists(Path))
-  return Path;
-return std::string();
-  }
-
-  if (!GCCInstallation.isValid() || !getTriple().isMIPS())
+  if (!GCCInstallation.isValid())
 return std::string();
 
-  // Standalone MIPS toolchains use different names for sysroot folder
-  // and put it into different places. Here we try to check some known
-  // variants.
-
   const StringRef InstallDir = GCCInstallation.getInstallPath();
   const StringRef TripleStr = GCCInstallation.getTriple().str();
-  const Multilib &Multilib = GCCInstallation.getMultilib();
+  std::string Path = (InstallDir + "/../../../../" + TripleStr).str();
 
-  std::string Path =
-  (InstallDir + "/../../../../" + TripleStr + "/libc" + 
Multilib.osSuffix())
-  .str();
+  // CSKY toolchains use different names for sysroot folder.
+  // GCCInstallation.getInstallPath() =
+  //   $GCCToolchainPath/lib/gcc/csky-linux-gnuabiv2/6.3.0
+  // Path = $GCCToolchainPath/csky-linux-gnuabiv2/libc
+  if (getTriple().isCSKY())
+Path += "/libc";
 
-  if (getVFS().exists(Path))
-return Path;
+  // Standalone MIPS toolchains use different names for sysroot folder
+  // and put it into different places. Here check the two known variants.
+  else if (getTriple().isMIPS()) {
+const std::string &OSSuffix = GCCInstallation.getMultilib().osSuffix();
 
-  Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str();
+Path += "/libc" + OSSuffix;
+if (getVFS().exists(Path))
+  return Path;
+
+Path = (InstallDir + "/../../../../sysroot" + OSSuffix).str();
+  }
 
   if (getVFS().exists(Path))
 return Path;


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -355,40 +355,31 @@
   return AndroidSysRootPath;
   }
 
-  if (getTriple().isCSKY()) {
-// CSKY toolchains use different names for sysroot folder.
-if (!GCCInstallation.isValid())
-  return std::string();
-// GCCInstallation.getInstallPath() =
-//   $GCCToolchainPath/lib/gcc/csky-linux-gnuabiv2/6.3.0
-// Path = $GCCToolchainPath/csky-linux-gnuabiv2/libc
-std::string Path = (GCCInstallation.getInstallPath() + "/../../../../" +
-GCCInstallation.getTriple().str() + "/libc")
-   .str();
-if (getVFS().exists(Path))
-  return Path;
-return std::string();
-  }
-
-  if (!GCCInstallation.isValid() || !getTriple().isMIPS())
+  if (!GCCInstallation.isValid())
 return std::string();
 
-  // Standalone MIPS toolchains use different names for sysroot folder
-  // and put it into different places. Here we try to check some known
-  // variants.
-
   const StringRef InstallDir = GCCInstallation.getInstallPath();
   const StringRef TripleStr = GCCInstallation.getTriple().str();
-  const Multilib &Multilib = GCCInstallation.getMultilib();
+  std::string Path = (InstallDir + "/../../../../" + TripleStr).str();
 
-  std::string Path =
-  (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix())
-  .str();
+  // CSKY toolchains use different names for sysroot folder.
+  // GCCInstallation.getInstallPath() =
+  //   $GCCToolchainPath/lib/gcc/csky-linux-gnuabiv2/6.3.0
+  // Path = $GCCToolchainPath/csky-linux-gnuabiv2/libc
+  if (getTriple().isCSKY())
+Path += "/libc";
 
-  if (getVFS().exists(Path))
-return Path;
+  // Standalone MIPS toolchains use different names for sysroot folder
+  // and put it into different places. Here check the two known variants.
+  else if (getTriple().isMIPS()) {
+const std::string &OSSuffix = GCCInstallation.getMultilib().osSuffix();
 
-  Path = (InstallDir + "/../../../../sysroot" + Multilib.osSuffix()).str();
+Path += "/libc" + OSSuffix;
+if (getVFS().exists(Path))
+  return Path;
+
+Path = (InstallDir 

[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-09-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D134128#3813708 , @lime wrote:

> Well, Something happened after rebasing this patch on D126907 
> . `s41` below was rejected as the constrain 
> generated from `template ` was no longer considered to subsume the 
> constrain generated from `template  requires C` in the template 
> template argument, which is not the case  in 
> both GCC and MSVC. However, GCC and MSVC also accept the redeclaration for 
> `S`, which might be ill-formed because of this rule 
> . If this kind of 
> redeclaration happens on `X`, GCC and MSVC will reject it. Rebasing this 
> patch on D126907  will also not make the 
> both redeclaration valid.
>
> Personally, I decided to make `s41` valid for Clang, a clue might be making 
> the `QualType`s the same in the parameters of two generated constrains.
>
>   template  concept C = T::f();
>   
>   template  concept C1 = T::f();
>   
>   template  struct X {};
>   
>   template  requires C struct X; // ill-formed for sure
>   
>   template  struct Y {};
>   
>   template  requires C class> struct S {};
>   
>   template  class> struct S; // GCC and MSVC accept this
>   
>   S sx; // my target
>   S sy; // ill-formed for sure

I'm not sure I get the issue here, there are some identifiers you're using that 
don't make sense to me.  I don't see that test in the lit tests either, could 
you make sure it is reflected there and commented?  ALso, can you re-arrange 
the error messages as I requested?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

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


[PATCH] D134020: [clang][Interp] Handle enums

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



Comment at: clang/test/AST/Interp/enums.cpp:25
+  SIX = FIVE + 2,
+
+};

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > shafik wrote:
> > > > Maybe some edge case values for enumerators like `__INT_MAX__  *2U +1U` 
> > > > (UINT_MAX) 
> > > > 
> > > > and 
> > > > 
> > > > ```
> > > > enum E { // warning: enumeration values exceed range of largest integer 
> > > > [-Wenum-too-large]
> > > >   E1 = -__LONG_MAX__ -1L,
> > > >   E2 = __LONG_MAX__ *2UL+1UL 
> > > > };
> > > > ```
> > > Hm, looks like that test broke one of the windows builders: 
> > > https://lab.llvm.org/buildbot/#/builders/123/builds/13424 - are enums 
> > > larger by default on Windows? What do you suggest to fix the test?
> > If we're trying to be compatible with MSVC, we use their rules for picking 
> > the underlying type of an enumeration is which not fixed. One way to handle 
> > this is to add more RUN lines with explicit triples, but I think we lose 
> > too much interesting coverage that way. I'd probably use a `#ifndef 
> > _MSC_VER` block to control the expected diagnostics with a comment as to 
> > why the diagnostic is not expected on Windows.
> The second builder that broke was  a hexagon builder: 
> https://lab.llvm.org/buildbot/#/builders/38/builds/6231 - this would still 
> fail with the `_MSC_VER` change, right?
Nope, drat.

I would recommend breaking that specific test out into a separate file where we 
can add various RUN lines with triples, and the rest of the test can remain 
targetless.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


  1   2   3   >