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

2023-04-29 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

@jp4a50 There's a mismatch between Format.h and and the resulting rst file. 
I'll rerun dump_format_style.py to fix it before merging.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


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

2023-04-29 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc12aa69a0be9: [clang-format] Add 
BracedInitializerIndentWidth option (authored by jp4a50, committed by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D146101?vs=517868&id=518140#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4855,6 +4855,191 @@
"[5] = ee};");
 }
 
+TEST_F(FormatTest, BracedInitializerIndentWidth) {
+  auto Style = getLLVMStyleWithColumns(60);
+  Style.BinPackArguments = true;
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  Style.BracedInitializerIndentWidth = 6;
+
+  // Non-initializing braces are unaffected by BracedInitializerIndentWidth.
+  verifyFormat("enum class {\n"
+   "  One,\n"
+   "  Two,\n"
+   "};\n",
+   Style);
+  verifyFormat("class Foo {\n"
+   "  Foo() {}\n"
+   "  void bar();\n"
+   "};\n",
+   Style);
+  verifyFormat("void foo() {\n"
+   "  auto bar = baz;\n"
+   "  return baz;\n"
+   "};\n",
+   Style);
+  verifyFormat("auto foo = [&] {\n"
+   "  auto bar = baz;\n"
+   "  return baz;\n"
+   "};\n",
+   Style);
+  verifyFormat("{\n"
+   "  auto bar = baz;\n"
+   "  return baz;\n"
+   "};\n",
+   Style);
+  // Non-brace initialization is unaffected by BracedInitializerIndentWidth.
+  verifyFormat("SomeClass clazz(\n"
+   "\"xx\", \"yy\",\n"
+   "\"zz\");\n",
+   Style);
+
+  // The following types of initialization are all affected by
+  // BracedInitializerIndentWidth. Aggregate initialization.
+  verifyFormat("int LongVariable[2] = {\n"
+   "  1000, 2000};",
+   Style);
+  verifyFormat("SomeStruct s{\n"
+   "  \"\", \"\",\n"
+   "  \"\"};\n",
+   Style);
+  // Designated initializers.
+  verifyFormat("int LongVariable[1] = {\n"
+   "  [0] = 1000, [1] = 2000};",
+   Style);
+  verifyFormat("SomeStruct s{\n"
+   "  .foo = \"x\",\n"
+   "  .bar = \"y\",\n"
+   "  .baz = \"z\"};\n",
+   Style);
+  // List initialization.
+  verifyFormat("SomeStruct s{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  verifyFormat("SomeStruct{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  verifyFormat("new SomeStruct{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  // Member initializer.
+  verifyFormat("class SomeClass {\n"
+   "  SomeStruct s{\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "  };\n"
+   "};\n",
+   Style);
+  // Constructor member initializer.
+  verifyFormat("SomeClass::SomeClass : strct{\n"
+   " \"x\",\n"
+   " \"y\",\n"
+   " \"z\",\n"
+   "   } {}\n",
+   Style);
+  // Copy initialization.
+  verifyFormat("SomeStruct s = SomeStruct{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "};\n",
+   Style);
+  // Copy list initialization.
+  verifyFormat("SomeStruct s = {\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"

[clang] c12aa69 - [clang-format] Add BracedInitializerIndentWidth option

2023-04-29 Thread Owen Pan via cfe-commits

Author: Jon Phillips
Date: 2023-04-29T00:36:19-07:00
New Revision: c12aa69a0be9acd0c751bf92318050d2b3730f9b

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

LOG: [clang-format] Add BracedInitializerIndentWidth option

The option allows users to specify how many columns to use to indent
the contents of initializer lists.

Closes #51070.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/docs/tools/dump_format_style.py
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 2e9038933c814..bdcd1e88d2404 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1829,6 +1829,41 @@ the configuration (without a prefix: ``Auto``).
}
 
 
+.. _BracedInitializerIndentWidth:
+
+**BracedInitializerIndentWidth** (``Unsigned``) :versionbadge:`clang-format 
17` :ref:`¶ `
+  The number of columns to use to indent the contents of braced init lists.
+  If unset, ``ContinuationIndentWidth`` is used.
+
+  .. code-block:: c++
+
+AlignAfterOpenBracket: AlwaysBreak
+BracedInitializerIndentWidth: 2
+
+void f() {
+  SomeClass c{
+"foo",
+"bar",
+"baz",
+  };
+  auto s = SomeStruct{
+.foo = "foo",
+.bar = "bar",
+.baz = "baz",
+  };
+  SomeArrayT a[3] = {
+{
+  foo,
+  bar,
+},
+{
+  foo,
+  bar,
+},
+SomeArrayT{},
+  };
+}
+
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 55fc0e6c790ba..d66993b0929fb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -513,6 +513,8 @@ clang-format
 - Add additional Qualifier Ordering support for special cases such
   as templates, requires clauses, long qualified names.
 - Fix all known issues associated with ``LambdaBodyIndentation: OuterScope``.
+- Add ``BracedInitializerIndentWidth`` which can be used to configure
+  the indentation level of the contents of braced init lists.
 
 libclang
 

diff  --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index fe6e9147ee94f..7b032894ce62c 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -69,9 +69,13 @@ def to_yaml_type(typestr: str):
   elif typestr == 'std::string':
 return 'String'
 
-  subtype, napplied = re.subn(r'^std::vector<(.*)>$', r'\1', typestr)
-  if napplied == 1:
-return 'List of ' + pluralize(to_yaml_type(subtype))
+  match = re.match(r'std::vector<(.*)>$', typestr)
+  if match:
+return 'List of ' + pluralize(to_yaml_type(match.group(1)))
+
+  match = re.match(r'std::optional<(.*)>$', typestr)
+  if match:
+return to_yaml_type(match.group(1))
 
   return typestr
 
@@ -331,7 +335,8 @@ class State:
   if option.type not in ['bool', 'unsigned', 'int', 'std::string',
  'std::vector',
  'std::vector',
- 'std::vector']:
+ 'std::vector',
+ 'std::optional']:
 if option.type in enums:
   option.enum = enums[option.type]
 elif option.type in nested_structs:

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 980e6297fd6ac..40f1ae0b49d46 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -944,6 +944,39 @@ struct FormatStyle {
   /// \version 12
   BitFieldColonSpacingStyle BitFieldColonSpacing;
 
+  /// The number of columns to use to indent the contents of braced init lists.
+  /// If unset, ``ContinuationIndentWidth`` is used.
+  /// \code
+  ///   AlignAfterOpenBracket: AlwaysBreak
+  ///   BracedInitializerIndentWidth: 2
+  ///
+  ///   void f() {
+  /// SomeClass c{
+  ///   "foo",
+  ///   "bar",
+  ///   "baz",
+  /// };
+  /// auto s = SomeStruct{
+  ///   .foo = "foo",
+  ///   .bar = "bar",
+  ///   .baz = "baz",
+  /// };
+  /// SomeArrayT a[3] = {
+  ///   {
+  /// foo,
+  /// bar,
+  ///   },
+  ///   {
+  /// foo,
+  /// bar,
+  ///   },
+  ///   SomeArrayT{},
+  /// };
+  ///

[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-04-29 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 518144.
zyounan added a comment.

Refactor tests. Obtain type from VarDecl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -18,6 +18,7 @@
 #include "clang/Format/Format.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 
 #include "gtest/gtest.h"
 #include 
@@ -529,6 +530,8 @@
[](HoverInfo &HI) {
  HI.Name = "MACRO";
  HI.Kind = index::SymbolKind::Macro;
+ HI.Value = "41 (0x29)";
+ HI.Type = "int";
  HI.Definition = "#define MACRO 41\n\n"
  "// Expands to\n"
  "41";
@@ -560,6 +563,7 @@
[](HoverInfo &HI) {
  HI.Name = "DECL_STR";
  HI.Kind = index::SymbolKind::Macro;
+ HI.Type = HoverInfo::PrintedType("const char *");
  HI.Definition = "#define DECL_STR(NAME, VALUE) const char *v_##NAME = "
  "STRINGIFY(VALUE)\n\n"
  "// Expands to\n"
@@ -1792,6 +1796,8 @@
   )cpp",
   [](HoverInfo &HI) {
 HI.Name = "MACRO";
+HI.Value = "0";
+HI.Type = "int";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0\n\n"
 "// Expands to\n"
@@ -3746,6 +3752,213 @@
   EXPECT_EQ(H->Type->Type, "int");
   EXPECT_EQ(H->Definition, "using foo = type");
 }
+
+TEST(Hover, EvaluateMacros) {
+  llvm::StringRef PredefinedCXX = R"cpp(
+#define X 42
+#define SizeOf sizeof
+#define AlignOf alignof
+#define PLUS_TWO +2
+#define TWO 2
+
+using u64 = unsigned long long;
+// calculate (a ** b) % p
+constexpr u64 pow_with_mod(u64 a, u64 b, u64 p) {
+  u64 ret = 1;
+  while (b) {
+if (b & 1)
+  ret = (ret * a) % p;
+a = (a * a) % p;
+b >>= 1;
+  }
+  return ret;
+}
+#define last_n_digit(x, y, n)  \
+  pow_with_mod(x, y, pow_with_mod(10, n, 2147483647))
+#define declare_struct(X, name, value) \
+  struct X {   \
+constexpr auto name() { return value; }\
+  }
+#define gnu_statement_expression(value)\
+  ({   \
+declare_struct(Widget, getter, value); \
+Widget().getter(); \
+  })
+#define define_lambda_begin(lambda, ...)   \
+  [&](__VA_ARGS__) {
+#define define_lambda_end() }
+
+#define left_bracket [
+#define right_bracket ]
+#define array_decl(type, name, size) type name left_bracket size right_bracket
+  )cpp";
+
+  struct {
+llvm::StringRef Code;
+const std::function, size_t /*Id*/)>
+Validator;
+  } Cases[] = {
+  {
+  /*Code=*/R"cpp(
+X^;
+  )cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_EQ(HI->Value, "42 (0x2a)");
+EXPECT_EQ(HI->Type, HoverInfo::PrintedType("int"));
+  },
+  },
+  {
+  /*Code=*/R"cpp(
+Size^Of(int);
+  )cpp",
+  /*Validator=*/
+  [](std::optional HI, size_t) {
+EXPECT_TRUE(HI->Value);
+EXPECT_TRUE(HI->Type);
+// Don't validate type or value of `sizeof` and `alignof` as we're
+// getting different values or desugared types on different
+// platforms. Same as below.
+  },
+  },
+  {
+  R"cpp(
+  struct Y {
+int y;
+double z;
+  };
+  Alig$3^nOf(Y);
+)cpp",
+  [](std::optional HI, size_t) {
+EXPECT_TRUE(HI->Value);
+EXPECT_TRUE(HI->Type);
+  },
+  },
+  {
+  R"cpp(
+  // 2**32 == 4294967296
+  last_n_di^git(2, 32, 6);
+)cpp",
+  [](std::optional HI, size_t) {
+EXPECT_EQ(HI->Value, "967296 (0xec280)");
+EXPECT_EQ(HI->Type, "u64");
+  },
+  },
+  {
+  R"cpp(
+  gnu_statement_exp^ression(42);
+)cpp",
+  [](std::optional HI, size_t) {
+EXPECT_EQ(HI->Value, "42 (0x2a)");
+EXPECT_EQ(HI->Type, "int");
+  },
+  },
+  {
+  R"cpp(
+  40 + PLU^S_TWO;
+)cpp",
+   

[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type

2023-04-29 Thread Rishabh Bali via Phabricator via cfe-commits
Ris-Bali created this revision.
Ris-Bali added a reviewer: tbaeder.
Ris-Bali added a project: clang.
Herald added a project: All.
Ris-Bali requested review of this revision.
Herald added a subscriber: cfe-commits.

Currently clang doesn't verify if the first argument in 
_builtin_assume_aligned_ is of pointer type. This leads to an assertion build 
failure. This patch aims to add a check if the first argument is of pointer 
type or not and diagnose it with `diag::err_typecheck_convert_incompatible` if 
its not of pointer type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149514

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+Qualtype firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  Qualtype expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}  
 TheCall->setArg(0, FirstArgResult.get());
   }
 


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+Qualtype firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  Qualtype expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}  
 TheCall->setArg(0, FirstArgResult.get());
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148769: Split out `CodeGenTypes` from `CodeGen` for LLT/MVT

2023-04-29 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a reviewer: dblaikie.
chapuni added a subscriber: dblaikie.
chapuni added a comment.

I am certain this works, though, I would like to ask the 2nd opinion to 
@dblaikie .

In D148769#4297552 , @arsenm wrote:

> I feel like this should have documentation explaining the library split, but 
> not sure where the best place to put that would be

I think better it may be put in front of `add_library(LLVMCodeGenTypes)`, at 
the moment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148769

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


[PATCH] D148769: Split out `CodeGenTypes` from `CodeGen` for LLT/MVT

2023-04-29 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni updated this revision to Diff 518146.
chapuni added a comment.

- Add comment lines to LLVMCodeGenTypes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148769

Files:
  clang/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/GlobalISel/CMakeLists.txt
  llvm/lib/CodeGen/MIRParser/CMakeLists.txt
  llvm/lib/CodeGen/SelectionDAG/CMakeLists.txt
  llvm/lib/DWARFLinker/CMakeLists.txt
  llvm/lib/LTO/CMakeLists.txt
  llvm/lib/Target/AArch64/AsmParser/CMakeLists.txt
  llvm/lib/Target/AArch64/CMakeLists.txt
  llvm/lib/Target/AArch64/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/AMDGPU/AsmParser/CMakeLists.txt
  llvm/lib/Target/AMDGPU/CMakeLists.txt
  llvm/lib/Target/AMDGPU/Disassembler/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCA/CMakeLists.txt
  llvm/lib/Target/AMDGPU/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/AMDGPU/Utils/CMakeLists.txt
  llvm/lib/Target/ARC/CMakeLists.txt
  llvm/lib/Target/ARC/Disassembler/CMakeLists.txt
  llvm/lib/Target/ARM/AsmParser/CMakeLists.txt
  llvm/lib/Target/ARM/CMakeLists.txt
  llvm/lib/Target/ARM/Disassembler/CMakeLists.txt
  llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/AVR/AsmParser/CMakeLists.txt
  llvm/lib/Target/AVR/CMakeLists.txt
  llvm/lib/Target/AVR/Disassembler/CMakeLists.txt
  llvm/lib/Target/BPF/CMakeLists.txt
  llvm/lib/Target/CSKY/CMakeLists.txt
  llvm/lib/Target/CSKY/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/DirectX/CMakeLists.txt
  llvm/lib/Target/Hexagon/CMakeLists.txt
  llvm/lib/Target/Lanai/AsmParser/CMakeLists.txt
  llvm/lib/Target/Lanai/CMakeLists.txt
  llvm/lib/Target/Lanai/Disassembler/CMakeLists.txt
  llvm/lib/Target/LoongArch/CMakeLists.txt
  llvm/lib/Target/M68k/AsmParser/CMakeLists.txt
  llvm/lib/Target/M68k/CMakeLists.txt
  llvm/lib/Target/M68k/Disassembler/CMakeLists.txt
  llvm/lib/Target/MSP430/AsmParser/CMakeLists.txt
  llvm/lib/Target/MSP430/CMakeLists.txt
  llvm/lib/Target/Mips/CMakeLists.txt
  llvm/lib/Target/Mips/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/NVPTX/CMakeLists.txt
  llvm/lib/Target/PowerPC/CMakeLists.txt
  llvm/lib/Target/PowerPC/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/RISCV/CMakeLists.txt
  llvm/lib/Target/RISCV/MCA/CMakeLists.txt
  llvm/lib/Target/SPIRV/CMakeLists.txt
  llvm/lib/Target/SPIRV/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/Sparc/CMakeLists.txt
  llvm/lib/Target/SystemZ/CMakeLists.txt
  llvm/lib/Target/SystemZ/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/VE/AsmParser/CMakeLists.txt
  llvm/lib/Target/VE/CMakeLists.txt
  llvm/lib/Target/VE/Disassembler/CMakeLists.txt
  llvm/lib/Target/VE/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt
  llvm/lib/Target/WebAssembly/CMakeLists.txt
  llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt
  llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/WebAssembly/Utils/CMakeLists.txt
  llvm/lib/Target/X86/CMakeLists.txt
  llvm/lib/Target/X86/MCA/CMakeLists.txt
  llvm/lib/Target/X86/MCTargetDesc/CMakeLists.txt
  llvm/lib/Target/XCore/CMakeLists.txt
  llvm/lib/Target/XCore/Disassembler/CMakeLists.txt
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/llc/CMakeLists.txt
  llvm/tools/llvm-dwarfutil/CMakeLists.txt
  llvm/tools/llvm-exegesis/CMakeLists.txt
  llvm/tools/llvm-exegesis/lib/AArch64/CMakeLists.txt
  llvm/tools/llvm-exegesis/lib/CMakeLists.txt
  llvm/tools/llvm-exegesis/lib/Mips/CMakeLists.txt
  llvm/tools/llvm-exegesis/lib/PowerPC/CMakeLists.txt
  llvm/tools/llvm-exegesis/lib/X86/CMakeLists.txt
  llvm/tools/llvm-reduce/CMakeLists.txt
  llvm/unittests/CodeGen/CMakeLists.txt
  llvm/unittests/CodeGen/GlobalISel/CMakeLists.txt
  llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
  llvm/unittests/MI/CMakeLists.txt
  llvm/unittests/MIR/CMakeLists.txt
  llvm/unittests/Target/AArch64/CMakeLists.txt
  llvm/unittests/Target/AMDGPU/CMakeLists.txt
  llvm/unittests/Target/ARM/CMakeLists.txt
  llvm/unittests/Target/LoongArch/CMakeLists.txt
  llvm/unittests/Target/WebAssembly/CMakeLists.txt
  llvm/unittests/Target/X86/CMakeLists.txt
  llvm/unittests/tools/llvm-exegesis/CMakeLists.txt
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/GlobalISel/CMakeLists.txt
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel
  utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
  utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
@@ -141,6 +141,7 @@
 "//llvm:AsmParser",
 "//llvm:BinaryFormat",
 "//llvm:CodeGen",
+"//llvm:CodeGenTypes",
 "//llvm:Core",
 "//llvm:MC",
 "//llvm:Passes",
@@ -169,6 +170,7 @@
 "//llvm:AllTargetsAsmP

[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-04-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

> Obviously we're expecting evaluation on such macro (which is just what the 
> original issue addresses).

That wasn't (and isn't) obvious to me - the issue didn't mention the macro in 
question, i assumed it was `#define alignof(x) __alignof(x)` or similar. Looks 
like both forms are in use but clang provides `#define alignof __alignof` as a 
built-in.

A couple of ideas:

- special-case alignof
- (generalization) allow partial selection via macros that expand to a single 
token
- (generalization) allow partial selection as long as it's of a single node - 
the common ancestor is partially selected and no children are


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148457

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


[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type

2023-04-29 Thread Rishabh Bali via Phabricator via cfe-commits
Ris-Bali updated this revision to Diff 518153.
Ris-Bali added a comment.

Clang-format fix


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

https://reviews.llvm.org/D149514

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+Qualtype firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  Qualtype expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}
 TheCall->setArg(0, FirstArgResult.get());
   }
 


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+Qualtype firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  Qualtype expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}
 TheCall->setArg(0, FirstArgResult.get());
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-04-29 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed: https://github.com/llvm/llvm-project/issues/62408
`setInvalidDecl` for invalid `CXXDeductionGuideDecl` to
avoid crashes during semantic analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149516

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11074,8 +11074,9 @@
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
 /// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
+  bool IsValid = true;
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
   assert(GuidedTemplateDecl && "missing template decl for deduction guide");
@@ -11124,7 +11125,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return IsValid;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11138,6 +11139,7 @@
   break;
 }
 if (!Chunk.Fun.hasTrailingReturnType()) {
+  IsValid = false;
   Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
   break;
@@ -11177,6 +11179,7 @@
 }
 
 if (!AcceptableReturnType) {
+  IsValid = false;
   Diag(TSI->getTypeLoc().getBeginLoc(),
diag::err_deduction_guide_bad_trailing_return_type)
   << GuidedTemplate << TSI->getType()
@@ -11191,6 +11194,7 @@
 
   if (D.isFunctionDefinition())
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
+  return IsValid;
 }
 
 //===--===//
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9199,11 +9199,13 @@
   SemaRef.Diag(TrailingRequiresClause->getBeginLoc(),

[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

2023-04-29 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 updated this revision to Diff 518155.
HerrCai0907 added a comment.

add release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
  clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp

Index: clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-deduction-guide-as-template-candidates.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  class Foo {}; // expected-note {{candidate template ignored: couldn't infer template argument 'T'}} \
+ // expected-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
+Foo(); // expected-error {{deduction guide declaration without trailing return type}}
+Foo vs; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -241,9 +241,8 @@
 };
 
 struct A2 {
-  template  // expected-note {{non-deducible template parameter 'Ty'}}
+  template 
   B() noexcept(false); // expected-error {{deduction guide must be declared in the same scope as template 'PR49735::B'}} \
-   // expected-error {{deduction guide template contains a template parameter that cannot be deduced}} \
// expected-error {{deduction guide declaration without trailing return type}}
 };
 
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
===
--- clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -173,10 +173,10 @@
 concept g = f::h;
 template 
 concept i = g;
-template  class j { // expected-note {{candidate template ignored}}
+template  class j {
   template 
   requires requires { requires i; }
-  j(); // expected-note {{candidate template ignored}}
+  j();
 };
-template <> j(); // expected-error {{deduction guide declaration without trailing return type}} // expected-error {{no function template}}
+template <> j(); // expected-error {{deduction guide declaration without trailing return type}}
 }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11074,8 +11074,9 @@
 /// These aren't actually declarators in the grammar, so we need to check that
 /// the user didn't specify any pieces that are not part of the deduction-guide
 /// grammar.
-void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
+bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
  StorageClass &SC) {
+  bool IsValid = true;
   TemplateName GuidedTemplate = D.getName().TemplateName.get().get();
   TemplateDecl *GuidedTemplateDecl = GuidedTemplate.getAsTemplateDecl();
   assert(GuidedTemplateDecl && "missing template decl for deduction guide");
@@ -11124,7 +11125,7 @@
   }
 
   if (D.isInvalidType())
-return;
+return IsValid;
 
   // Check the declarator is simple enough.
   bool FoundFunction = false;
@@ -11138,6 +11139,7 @@
   break;
 }
 if (!Chunk.Fun.hasTrailingReturnType()) {
+  IsValid = false;
   Diag(D.getName().getBeginLoc(),
diag::err_deduction_guide_no_trailing_return_type);
   break;
@@ -11177,6 +11179,7 @@
 }
 
 if (!AcceptableReturnType) {
+  IsValid = false;
   Diag(TSI->getTypeLoc().getBeginLoc(),
diag::err_deduction_guide_bad_trailing_return_type)
   << GuidedTemplate << TSI->getType()
@@ -11191,6 +11194,7 @@
 
   if (D.isFunctionDefinition())
 Diag(D.getIdentifierLoc(), diag::err_deduction_guide_defines_function);
+  return IsValid;
 }
 
 //===--===//
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9199,11 +9199,13 @@
   SemaRef.Diag(TrailingRequiresClause->getBeginLoc(),
diag::err_trailing_requires_clause_on_deduction_guide)
   << TrailingRequiresClause->getSourceRange();
-SemaRef.CheckDeduc

[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type

2023-04-29 Thread Rishabh Bali via Phabricator via cfe-commits
Ris-Bali updated this revision to Diff 518156.
Ris-Bali added a comment.

QualType error fix


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

https://reviews.llvm.org/D149514

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+QualType firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  QualType expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}
 TheCall->setArg(0, FirstArgResult.get());
   }
 


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+QualType firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  QualType expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}
 TheCall->setArg(0, FirstArgResult.get());
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] cb133a4 - [clangd] Hover: Add CalleeArgInfo for constructor expressions

2023-04-29 Thread Tom Praschan via cfe-commits

Author: Tom Praschan
Date: 2023-04-29T14:37:16+02:00
New Revision: cb133a4629a56f8c8a67fb7549356839917b52f9

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

LOG: [clangd] Hover: Add CalleeArgInfo for constructor expressions

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index f59642dbf721d..558769f209860 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -981,12 +981,23 @@ void maybeAddCalleeArgInfo(const SelectionTree::Node *N, 
HoverInfo &HI,
   const auto &OuterNode = N->outerImplicit();
   if (!OuterNode.Parent)
 return;
-  const auto *CE = OuterNode.Parent->ASTNode.get();
-  if (!CE)
+
+  const FunctionDecl *FD = nullptr;
+  llvm::ArrayRef Args;
+
+  if (const auto *CE = OuterNode.Parent->ASTNode.get()) {
+FD = CE->getDirectCallee();
+Args = {CE->getArgs(), CE->getNumArgs()};
+  } else if (const auto *CE =
+ OuterNode.Parent->ASTNode.get()) {
+FD = CE->getConstructor();
+Args = {CE->getArgs(), CE->getNumArgs()};
+  }
+  if (!FD)
 return;
-  const FunctionDecl *FD = CE->getDirectCallee();
-  // For non-function-call-like operatators (e.g. operator+, operator<<) it's
-  // not immediattely obvious what the "passed as" would refer to and, given
+
+  // For non-function-call-like operators (e.g. operator+, operator<<) it's
+  // not immediately obvious what the "passed as" would refer to and, given
   // fixed function signature, the value would be very low anyway, so we choose
   // to not support that.
   // Both variadic functions and operator() (especially relevant for lambdas)
@@ -999,8 +1010,8 @@ void maybeAddCalleeArgInfo(const SelectionTree::Node *N, 
HoverInfo &HI,
   auto Parameters = resolveForwardingParameters(FD);
 
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
-if (CE->getArg(I) != OuterNode.ASTNode.get())
+  for (unsigned I = 0; I < Args.size() && I < Parameters.size(); ++I) {
+if (Args[I] != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 5bf089fbbfeca..ce546f54dd75f 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -956,6 +956,29 @@ class Foo final {})cpp";
 HI.CalleeArgInfo->Type = "const float &";
 HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
   }},
+  {
+  R"cpp(
+  struct Foo {
+explicit Foo(const float& arg) {}
+  };
+  int main() {
+int a = 0;
+Foo foo([[^a]]);
+  }
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Name = "a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Definition = "int a = 0";
+HI.LocalScope = "main::";
+HI.Value = "0";
+HI.Type = "int";
+HI.CalleeArgInfo.emplace();
+HI.CalleeArgInfo->Name = "arg";
+HI.CalleeArgInfo->Type = "const float &";
+HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
+  }},
   {// Literal passed to function call
R"cpp(
   void fun(int arg_a, const int &arg_b) {};
@@ -1342,6 +1365,7 @@ class CustomClass {
   CustomClass(const Base &x) {}
   CustomClass(int &x) {}
   CustomClass(float x) {}
+  CustomClass(int x, int y) {}
 };
 
 void int_by_ref(int &x) {}
@@ -1388,6 +1412,11 @@ void fun() {
   {"base_by_ref([[^derived]]);", PassMode::Ref, false},
   {"base_by_const_ref([[^derived]]);", PassMode::ConstRef, false},
   {"base_by_value([[^derived]]);", PassMode::Value, false},
+  // Custom class constructor tests
+  {"CustomClass c1([[^base]]);", PassMode::ConstRef, false},
+  {"auto c2 = new CustomClass([[^base]]);", PassMode::ConstRef, false},
+  {"CustomClass c3([[^int_x]]);", PassMode::Ref, false},
+  {"CustomClass c3(int_x, [[^int_x]]);", PassMode::Value, false},
   // Converted tests
   {"float_by_value([[^int_x]]);", PassMode::Value, true},
   {"float_by_value([[^int_ref]]);", PassMode::Value, true},



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


[PATCH] D147847: [clangd] Hover: Add CalleeArgInfo for constructor expressions

2023-04-29 Thread Tom Praschan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcb133a4629a5: [clangd] Hover: Add CalleeArgInfo for 
constructor expressions (authored by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147847

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -956,6 +956,29 @@
 HI.CalleeArgInfo->Type = "const float &";
 HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
   }},
+  {
+  R"cpp(
+  struct Foo {
+explicit Foo(const float& arg) {}
+  };
+  int main() {
+int a = 0;
+Foo foo([[^a]]);
+  }
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Name = "a";
+HI.Kind = index::SymbolKind::Variable;
+HI.NamespaceScope = "";
+HI.Definition = "int a = 0";
+HI.LocalScope = "main::";
+HI.Value = "0";
+HI.Type = "int";
+HI.CalleeArgInfo.emplace();
+HI.CalleeArgInfo->Name = "arg";
+HI.CalleeArgInfo->Type = "const float &";
+HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
+  }},
   {// Literal passed to function call
R"cpp(
   void fun(int arg_a, const int &arg_b) {};
@@ -1342,6 +1365,7 @@
   CustomClass(const Base &x) {}
   CustomClass(int &x) {}
   CustomClass(float x) {}
+  CustomClass(int x, int y) {}
 };
 
 void int_by_ref(int &x) {}
@@ -1388,6 +1412,11 @@
   {"base_by_ref([[^derived]]);", PassMode::Ref, false},
   {"base_by_const_ref([[^derived]]);", PassMode::ConstRef, false},
   {"base_by_value([[^derived]]);", PassMode::Value, false},
+  // Custom class constructor tests
+  {"CustomClass c1([[^base]]);", PassMode::ConstRef, false},
+  {"auto c2 = new CustomClass([[^base]]);", PassMode::ConstRef, false},
+  {"CustomClass c3([[^int_x]]);", PassMode::Ref, false},
+  {"CustomClass c3(int_x, [[^int_x]]);", PassMode::Value, false},
   // Converted tests
   {"float_by_value([[^int_x]]);", PassMode::Value, true},
   {"float_by_value([[^int_ref]]);", PassMode::Value, true},
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -981,12 +981,23 @@
   const auto &OuterNode = N->outerImplicit();
   if (!OuterNode.Parent)
 return;
-  const auto *CE = OuterNode.Parent->ASTNode.get();
-  if (!CE)
+
+  const FunctionDecl *FD = nullptr;
+  llvm::ArrayRef Args;
+
+  if (const auto *CE = OuterNode.Parent->ASTNode.get()) {
+FD = CE->getDirectCallee();
+Args = {CE->getArgs(), CE->getNumArgs()};
+  } else if (const auto *CE =
+ OuterNode.Parent->ASTNode.get()) {
+FD = CE->getConstructor();
+Args = {CE->getArgs(), CE->getNumArgs()};
+  }
+  if (!FD)
 return;
-  const FunctionDecl *FD = CE->getDirectCallee();
-  // For non-function-call-like operatators (e.g. operator+, operator<<) it's
-  // not immediattely obvious what the "passed as" would refer to and, given
+
+  // For non-function-call-like operators (e.g. operator+, operator<<) it's
+  // not immediately obvious what the "passed as" would refer to and, given
   // fixed function signature, the value would be very low anyway, so we choose
   // to not support that.
   // Both variadic functions and operator() (especially relevant for lambdas)
@@ -999,8 +1010,8 @@
   auto Parameters = resolveForwardingParameters(FD);
 
   // Find argument index for N.
-  for (unsigned I = 0; I < CE->getNumArgs() && I < Parameters.size(); ++I) {
-if (CE->getArg(I) != OuterNode.ASTNode.get())
+  for (unsigned I = 0; I < Args.size() && I < Parameters.size(); ++I) {
+if (Args[I] != OuterNode.ASTNode.get())
   continue;
 
 // Extract matching argument from function declaration.


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -956,6 +956,29 @@
 HI.CalleeArgInfo->Type = "const float &";
 HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
   }},
+  {
+  R"cpp(
+  struct Foo {
+explicit Foo(const float& arg) {}
+  };
+  int main() {
+int a = 0;
+Foo foo([[^a]]);
+  }
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Name = "a";
+HI.Kind 

[PATCH] D141757: [clangd] allow extracting to variable for complete lambda expressions

2023-04-29 Thread Julian Schmidt via Phabricator via cfe-commits
5chmidti updated this revision to Diff 518159.
5chmidti added a comment.

I took a little break, but here are the changes/fixes:

- moved the logic for variables referenced in captures into the visitor
  - short circuiting the `TraverseLambdaExpression` and using 
`TraverseLambdaCapture` to handle variable captures and the initialization fo 
init-captures
  - fixes both problems mentioned by nridge
- fix for immediately invoked lambda expressions
  - the selection of an IIL would mark the call operator as a referenced decl 
(fixed in `VisitDeclRefExpr`)
- fix condition in `CanExtractOutside` to allow an unselected parent that is a 
lambda expression
  - allows for the extraction of an initializer for init-capture variables
- block default arguments from prarameters of a lambda from being extracted to 
a function-local scope (fixed in `CanExtractOutside`)
- added more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141757

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
  clang-tools-extra/docs/ReleaseNotes.rst

Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -66,6 +66,11 @@
 Code completion
 ^^^
 
+Code actions
+
+
+- The extract variable tweak gained support for extracting lambda expressions to a variable.
+
 Signature help
 ^^
 
Index: clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -131,7 +131,43 @@
   goto label;
   label:
 a = [[1]];
-}
+
+  // lambdas
+  [][[(){}]];
+
+  // lambdas: captures
+  int x = 0;
+  [ [[=]] ](){};
+  [ [[&]] ](){};
+  [ [[x]] ](){};
+  [ [[&x] ]](){};
+  [y = [[x]] ](){};
+  [ [[y = x]] ](){};
+
+  // lambdas: default args
+  [](int x = [[10]]){};
+  [](auto h = [i = [[ [](){} ]]](){}) {};
+  [](auto h = [[ [i = [](){}](){} ]]) {};
+
+  // lambdas: scope
+  if (int a = 1)
+if ([[ [&](){ return a + 1; } ]]() == 4)
+  a = a + 1;
+
+  for (int c = 0; [[ [&]() { return c < b; } ]](); ++c) {
+  }
+  for (int c = 0; [[ [&]() { return c < b; } () ]]; ++c) {
+  }
+
+  // lambdas: scope with structured binding
+  struct Coordinates {
+int x{};
+int y{};
+  };
+  Coordinates c{};
+  if (const auto [x, y] = c; x > y)
+auto f = [[ [&]() { return x + y; } ]];
+  }
   )cpp";
   EXPECT_UNAVAILABLE(UnavailableCases);
 
@@ -282,6 +318,209 @@
  void f() {
auto placeholder = S(2) + S(3) + S(4); S x = S(1) + placeholder + S(5);
  })cpp"},
+  // lambda expressions
+  {R"cpp(template  void f(T) {}
+void f2() {
+  f([[ [](){ return 42; }]]);
+}
+)cpp",
+   R"cpp(template  void f(T) {}
+void f2() {
+  auto placeholder = [](){ return 42; }; f( placeholder);
+}
+)cpp"},
+  {R"cpp(auto foo(int VarA) {
+  return [VarA]() {
+return [[ [VarA, VarC = 42 + VarA](int VarB) { return VarA + VarB + VarC; }]];
+  };
+}
+)cpp",
+   R"cpp(auto foo(int VarA) {
+  return [VarA]() {
+auto placeholder = [VarA, VarC = 42 + VarA](int VarB) { return VarA + VarB + VarC; }; return  placeholder;
+  };
+}
+)cpp"},
+  {R"cpp(template  void f(T) {}
+void f2(int var) {
+  f([[ [&var](){ auto internal_val = 42; return var + internal_val; }]]);
+}
+)cpp",
+   R"cpp(template  void f(T) {}
+void f2(int var) {
+  auto placeholder = [&var](){ auto internal_val = 42; return var + internal_val; }; f( placeholder);
+}
+)cpp"},
+  {R"cpp(template  void f(T) { }
+struct A {
+void f2(int& var) {
+auto local_var = 42;
+f([[ [&var, &local_var, this]() {
+auto internal_val = 42;
+return var + local_var + internal_val + member;
+}]]);
+}
+
+int member = 42;
+};
+)cpp",
+   R"cpp(template  void f(T) { }
+struct A {
+void f2(

[PATCH] D142401: [Clang] Fix a crash when recursively callig a default member initializer.

2023-04-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 518161.
cor3ntin added a comment.

I don't think this is actually testable, ultimately we may run out of stack
any way, the warning (when emitted) even say so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142401

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/cxx11-default-member-initializers-recurse.cpp

Index: clang/test/SemaCXX/cxx11-default-member-initializers-recurse.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx11-default-member-initializers-recurse.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++20 %s
+
+// Recursively constructing default member initializers
+// should not crash clang.
+namespace GH60082 {
+
+struct A;
+
+int f(const A&) { return 42; }
+
+struct A {
+   int x = f(A());
+   A() { }
+};
+
+void foo() { A(); }
+
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5926,7 +5926,9 @@
   Param);
   ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
   SkipImmediateInvocations;
-  MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables*/ true);
+  runWithSufficientStackSpace(CallLoc, [&] {
+MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables=*/true);
+  });
   return false;
 }
 
@@ -6036,8 +6038,11 @@
   ExprEvalContexts.back().DelayedDefaultInitializationContext = {
   CallLoc, Param, CurContext};
   EnsureImmediateInvocationInDefaultArgs Immediate(*this);
-  ExprResult Res = Immediate.TransformInitializer(Param->getInit(),
-  /*NotCopy=*/false);
+  ExprResult Res;
+  runWithSufficientStackSpace(CallLoc, [&] {
+Res = Immediate.TransformInitializer(Param->getInit(),
+ /*NotCopy=*/false);
+  });
   if (Res.isInvalid())
 return ExprError();
   Res = ConvertParamDefaultArgument(Param, Res.get(),
@@ -6117,10 +6122,11 @@
 NestedDefaultChecking;
 
 EnsureImmediateInvocationInDefaultArgs Immediate(*this);
-
-ExprResult Res =
-Immediate.TransformInitializer(Field->getInClassInitializer(),
-   /*CXXDirectInit=*/false);
+ExprResult Res;
+runWithSufficientStackSpace(Loc, [&] {
+  Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
+   /*CXXDirectInit=*/false);
+});
 if (!Res.isInvalid())
   Res = ConvertMemberDefaultInitExpression(Field, Res.get(), Loc);
 if (Res.isInvalid()) {
@@ -6133,7 +6139,9 @@
   if (Field->getInClassInitializer()) {
 Expr *E = Init ? Init : Field->getInClassInitializer();
 if (!NestedDefaultChecking)
-  MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
+  runWithSufficientStackSpace(Loc, [&] {
+MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
+  });
 // C++11 [class.base.init]p7:
 //   The initialization of each base and member constitutes a
 //   full-expression.
@@ -18545,7 +18553,9 @@
   if (CXXConstructorDecl *Constructor = dyn_cast(Func)) {
 for (CXXCtorInitializer *Init : Constructor->inits()) {
   if (Init->isInClassMemberInitializer())
-MarkDeclarationsReferencedInExpr(Init->getInit());
+runWithSufficientStackSpace(Init->getSourceLocation(), [&]() {
+  MarkDeclarationsReferencedInExpr(Init->getInit());
+});
 }
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -313,8 +313,8 @@
   not a type concept.
 - Fix crash when a doc comment contains a line splicing.
   (`#62054 `_)
-- Work around with a clang coverage crash which happens when visiting 
-  expressions/statements with invalid source locations in non-assert builds. 
+- Work around with a clang coverage crash which happens when visiting
+  expressions/statements with invalid source locations in non-assert builds.
   Assert builds may still see assertions triggered from this.
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
@@ -338,6 +338,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix a stack overflow issue when evaluating ``consteval`` default arguments.
+  (`#60082` `_)
 
 Bug Fixes to Compiler Builtins
 

[clang] bc37be1 - LangRef: Add "dynamic" option to "denormal-fp-math"

2023-04-29 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2023-04-29T08:44:59-04:00
New Revision: bc37be1855773c1dcf8c6bf577a096a81fd58652

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

LOG: LangRef: Add "dynamic" option to "denormal-fp-math"

This is stricter than the default "ieee", and should probably be the
default. This patch leaves the default alone. I can change this in a
future patch.

There are non-reversible transforms I would like to perform which are
legal under IEEE denormal handling, but illegal with flushing zero
behavior. Namely, conversions between llvm.is.fpclass and fcmp with
zeroes.

Under "ieee" handling, it is legal to translate between
llvm.is.fpclass(x, fcZero) and fcmp x, 0.

Under "preserve-sign" handling, it is legal to translate between
llvm.is.fpclass(x, fcSubnormal|fcZero) and fcmp x, 0.

I would like to compile and distribute some math library functions in
a mode where it's callable from code with and without denormals
enabled, which requires not changing the compares with denormals or
zeroes.

If an IEEE function transforms an llvm.is.fpclass call into an fcmp 0,
it is no longer possible to call the function from code with denormals
enabled, or write an optimization to move the function into a denormal
flushing mode. For the original function, if x was a denormal, the
class would evaluate to false. If the function compiled with denormal
handling was converted to or called from a preserve-sign function, the
fcmp now evaluates to true.

This could also be of use for strictfp handling, where code may be
changing the denormal mode.

Alternative name could be "unknown".

Replaces the old AMDGPU custom inlining logic with more conservative
logic which tries to permit inlining for callees with dynamic handling
and avoids inlining other mismatched modes.

Added: 
clang/test/CodeGenCUDA/Inputs/ocml-sample.cl
clang/test/CodeGenCUDA/link-builtin-bitcode-denormal-fp-mode.cu
llvm/test/CodeGen/Generic/denormal-fp-math-cl-opt.ll

Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenAction.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGen/denormalfpmode-f32.c
clang/test/CodeGen/denormalfpmode.c
clang/test/Driver/denormal-fp-math.c
llvm/docs/LangRef.rst
llvm/include/llvm/ADT/FloatingPointMode.h
llvm/include/llvm/Analysis/ConstantFolding.h
llvm/include/llvm/IR/Attributes.td
llvm/include/llvm/IR/Function.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Function.cpp
llvm/lib/Target/AMDGPU/SIModeRegisterDefaults.h
llvm/test/CodeGen/X86/sqrt-fastmath.ll
llvm/test/Transforms/Inline/AMDGPU/inline-denormal-fp-math.ll
llvm/test/Transforms/InstSimplify/canonicalize.ll
llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll
llvm/unittests/ADT/FloatingPointMode.cpp
llvm/utils/TableGen/Attributes.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 63296aeec5b9f..9cdf689b74440 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1829,10 +1829,32 @@ static bool HasStrictReturn(const CodeGenModule 
&Module, QualType RetTy,
  Module.getLangOpts().Sanitize.has(SanitizerKind::Return);
 }
 
-void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
- bool HasOptnone,
- bool AttrOnCallSite,
-   llvm::AttrBuilder &FuncAttrs) {
+/// Add denormal-fp-math and denormal-fp-math-f32 as appropriate for the
+/// requested denormal behavior, accounting for the overriding behavior of the
+/// -f32 case.
+static void addDenormalModeAttrs(llvm::DenormalMode FPDenormalMode,
+ llvm::DenormalMode FP32DenormalMode,
+ llvm::AttrBuilder &FuncAttrs) {
+  if (FPDenormalMode != llvm::DenormalMode::getDefault())
+FuncAttrs.addAttribute("denormal-fp-math", FPDenormalMode.str());
+
+  if (FP32DenormalMode != FPDenormalMode && FP32DenormalMode.isValid())
+FuncAttrs.addAttribute("denormal-fp-math-f32", FP32DenormalMode.str());
+}
+
+/// Add default attributes to a function, which have merge semantics under
+/// -mlink-builtin-bitcode and should not simply overwrite any existing
+/// attributes in the linked library.
+static void
+addMergableDefaultFunctionAttributes(const CodeGenOptions &CodeGenOpts,
+ llvm::AttrBuilder &FuncAttrs) {
+  addDenormalModeAttrs(CodeGenOpts.FPDenormalMode, 
CodeGenOpts.FP32DenormalMode,
+   FuncAttrs);
+}
+
+void CodeGenModul

[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

2023-04-29 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm closed this revision.
arsenm added a comment.

bc37be1855773c1dcf8c6bf577a096a81fd58652


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

https://reviews.llvm.org/D142907

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


[PATCH] D149518: [clang] Optimize clang::ASTNodeKind::isBaseOf

2023-04-29 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
Herald added subscribers: luismarques, s.egerton, PkmX, simoncook, arichardson.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead.
Herald added a project: clang.

Create dedicated isBaseOf method without calculating
distance.

Tested on RISCVISelDAGToDAG.cpp with:
clang-tidy --checks=*,-bugprone-unchecked-optional-access

Amount of CPU cycles for isBaseOf reduced by ~15% (according to perf).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149518

Files:
  clang/include/clang/AST/ASTTypeTraits.h
  clang/lib/AST/ASTTypeTraits.cpp


Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -56,10 +56,23 @@
 {NKI_None, "ObjCProtocolLoc"},
 };
 
+bool ASTNodeKind::isBaseOf(ASTNodeKind Other) const {
+  return isBaseOf(KindId, Other.KindId);
+}
+
 bool ASTNodeKind::isBaseOf(ASTNodeKind Other, unsigned *Distance) const {
   return isBaseOf(KindId, Other.KindId, Distance);
 }
 
+bool ASTNodeKind::isBaseOf(NodeKindId Base, NodeKindId Derived) {
+  if (Base == NKI_None || Derived == NKI_None)
+return false;
+  while (Derived != Base && Derived != NKI_None) {
+Derived = AllKindInfo[Derived].ParentId;
+  }
+  return Derived == Base;
+}
+
 bool ASTNodeKind::isBaseOf(NodeKindId Base, NodeKindId Derived,
unsigned *Distance) {
   if (Base == NKI_None || Derived == NKI_None) return false;
@@ -96,7 +109,7 @@
 ASTNodeKind ASTNodeKind::getMostDerivedCommonAncestor(ASTNodeKind Kind1,
   ASTNodeKind Kind2) {
   NodeKindId Parent = Kind1.KindId;
-  while (!isBaseOf(Parent, Kind2.KindId, nullptr) && Parent != NKI_None) {
+  while (!isBaseOf(Parent, Kind2.KindId) && Parent != NKI_None) {
 Parent = AllKindInfo[Parent].ParentId;
   }
   return ASTNodeKind(Parent);
Index: clang/include/clang/AST/ASTTypeTraits.h
===
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -77,10 +77,13 @@
   /// Returns \c true only for the default \c ASTNodeKind()
   constexpr bool isNone() const { return KindId == NKI_None; }
 
+  /// Returns \c true if \c this is a base kind of (or same as) \c Other.
+  bool isBaseOf(ASTNodeKind Other) const;
+
   /// Returns \c true if \c this is a base kind of (or same as) \c Other.
   /// \param Distance If non-null, used to return the distance between \c this
   /// and \c Other in the class hierarchy.
-  bool isBaseOf(ASTNodeKind Other, unsigned *Distance = nullptr) const;
+  bool isBaseOf(ASTNodeKind Other, unsigned *Distance) const;
 
   /// String representation of the kind.
   StringRef asStringRef() const;
@@ -166,6 +169,10 @@
   /// Use getFromNodeKind() to construct the kind.
   constexpr ASTNodeKind(NodeKindId KindId) : KindId(KindId) {}
 
+  /// Returns \c true if \c Base is a base kind of (or same as) \c
+  ///   Derived.
+  static bool isBaseOf(NodeKindId Base, NodeKindId Derived);
+
   /// Returns \c true if \c Base is a base kind of (or same as) \c
   ///   Derived.
   /// \param Distance If non-null, used to return the distance between \c Base


Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -56,10 +56,23 @@
 {NKI_None, "ObjCProtocolLoc"},
 };
 
+bool ASTNodeKind::isBaseOf(ASTNodeKind Other) const {
+  return isBaseOf(KindId, Other.KindId);
+}
+
 bool ASTNodeKind::isBaseOf(ASTNodeKind Other, unsigned *Distance) const {
   return isBaseOf(KindId, Other.KindId, Distance);
 }
 
+bool ASTNodeKind::isBaseOf(NodeKindId Base, NodeKindId Derived) {
+  if (Base == NKI_None || Derived == NKI_None)
+return false;
+  while (Derived != Base && Derived != NKI_None) {
+Derived = AllKindInfo[Derived].ParentId;
+  }
+  return Derived == Base;
+}
+
 bool ASTNodeKind::isBaseOf(NodeKindId Base, NodeKindId Derived,
unsigned *Distance) {
   if (Base == NKI_None || Derived == NKI_None) return false;
@@ -96,7 +109,7 @@
 ASTNodeKind ASTNodeKind::getMostDerivedCommonAncestor(ASTNodeKind Kind1,
   ASTNodeKind Kind2) {
   NodeKindId Parent = Kind1.KindId;
-  while (!isBaseOf(Parent, Kind2.KindId, nullptr) && Parent != NKI_None) {
+  while (!isBaseOf(Parent, Kind2.KindId) && Parent != NKI_None) {
 Parent = AllKindInfo[Parent].ParentId;
   }
   return ASTNodeKind(Parent);
Index: clang/include/clang/AST/ASTTypeTraits.h
===
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -77,10 +77,13 @@
   /// Returns \c true only for the default \c ASTNodeKind()
   constexpr 

[PATCH] D149518: [clang] Optimize clang::ASTNodeKind::isBaseOf

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

Lookup matrix gives best result (~-80%), bu it consume lot of memory due to big 
amount of enumerators (~950).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149518

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


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

2023-04-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 518166.
junaire marked 4 inline comments as done.
junaire added a comment.

Partially address some comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,11 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+// JIT reports symbol not found on Windows without the visibility attribute.
+REPL_EXTERNAL_VISIBILITY int getGlobal() { return Global; }
+REPL_EXTERNAL_VISIBILITY void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +282,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -315,4 +320,55 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+  EXPECT_FALSE(V1.isPointerOrObjectType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+  EXPECT_FALSE(V2.isPointerOrObjectType());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+  EXPECT_TRUE(V3.isPointerOrObjectType());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Interpreter/Value.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/Value.cpp
@@ -0,0 +1,260 @@
+//===--- Interpreter.h - Incremental Compiation

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

2023-04-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:96
+
+  size_t getEffectivePTUSize() const;
+

aaron.ballman wrote:
> It looks like this can be private?
> 
> Also, just a note (not something you have to deal with in this review), the 
> local naming convention seems to have decided that if the function starts 
> with `get` then it's camel case and otherwise the name is pascal case.
Fixed.



Comment at: clang/include/clang/Interpreter/Value.h:83
+  Value() = default;
+  Value(void /*Interpreter*/ *In, void /*QualType*/ *Ty);
+  Value(const Value &RHS);

aaron.ballman wrote:
> v.g.vassilev wrote:
> > junaire wrote:
> > > aaron.ballman wrote:
> > > > Why do these take `void *` instead of the expected type?
> > > Yeah for the first parameter, we could just use `Interpreter*` but the 
> > > second one is an opaque type so I think we should keep it?
> > See my previous comments on performance. We cannot include anything bulky 
> > in the header file.
> I think I understand why the design is the way it is, but it still makes me 
> uneasy. The constructor takes a pointer to some bucket of bytes... no size 
> information, no type information, etc. Just "here's a random pointer". And 
> then later, we hope the user calls `setKind()` in a way that makes sense.
> 
> We need it to be fast, but we also need it to be correct -- the type system 
> is the best tool for helping with that.
Not really... The user doesn't need to call `setKind()` explicitly to construct 
a `Value`, the constructor will handle it automatically. See 
`ConvertQualTypeToKind` in `Value.cpp`. So if the pointer is just some garbage 
data, the constructor should fail before yielding out a valid instance.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:22
 #include "clang/FrontendTool/Utils.h"
+#include "clang/Interpreter/Interpreter.h"
 #include "clang/Parse/Parser.h"

aaron.ballman wrote:
> v.g.vassilev wrote:
> > This introduces a layering violation. Can we avoid it?
> Does it? This file is in `clang/lib/Interpreter` so including other things 
> from `clang/Interpreter` would not be a layering violation normally.
That's an old comment, already fixed and marked it as done :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

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


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

2023-04-29 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked 12 inline comments as done.
mikecrowe added a comment.

Thank you for all the review comments.




Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:322
+  if (!isRealCharType(Pointee))
+ArgFixes.emplace_back(Arg, "reinterpret_cast(");
+}

njames93 wrote:
> By default this check should not do this conversion, we shouldn't be creating 
> UB in fixes emitted by clang-tidy unless the user explicitly opts in.
> Maybe a good framework moving forward is to still a warning about converting 
> up std::print, but emit a note here saying why the automatic conversation 
> isn't possible.
Good spot. This was wider than I intended. The cast is only supposed to be used 
if the argument is a pointer to `unsigned char` or `signed char`.

I think that I probably ought to make sure that all the places that decide that 
conversion is not possible emit a warning explaining why.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:412
+else
+  ArgFixes.emplace_back(Arg, "reinterpret_cast(");
+break;

njames93 wrote:
> `reinterpret_cast` is not needed here, a static cast to`const void*` will 
> work.
Good spot. I'm sure I used the right cast in an earlier version... :(



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:73
+   printf-style format string and the arguments to be formatted follow
+   immediately afterwards.
+

Eugene.Zelenko wrote:
> Please add information about default value.
The current implementation always "fixes" `printf`, `fprintf`, `absl::PrintF` 
and `absl::FPrintf`, even when this option is used (see `UseStdPrintCheck` 
constructor.) Should the option inhibit this default?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:92
+
+It is helpful to use the `readability-redundant-string-cstr
+<../readability/redundant-string-cstr.html>` check after this check to

njames93 wrote:
> It may be wise in a future version to just do that conversion anyway. 2 stage 
> fixes are annoying for users to have to use 
I shall investigate how to do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


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

2023-04-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/printf-to-std-print.rst:73
+   printf-style format string and the arguments to be formatted follow
+   immediately afterwards.
+

mikecrowe wrote:
> Eugene.Zelenko wrote:
> > Please add information about default value.
> The current implementation always "fixes" `printf`, `fprintf`, `absl::PrintF` 
> and `absl::FPrintf`, even when this option is used (see `UseStdPrintCheck` 
> constructor.) Should the option inhibit this default?
It may be reasonable to provide possibility to override default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D148093: [clang][CodeGen] Break up TargetInfo.cpp [5/6]

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 518187.
barannikov88 added a comment.

Upload the correct diff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148093

Files:
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -125,7 +125,7 @@
 /// registers when expanded?
 ///
 /// This is intended to be the basis of a reasonable basic implementation
-/// of should{Pass,Return}IndirectlyForSwift.
+/// of should{Pass,Return}Indirectly.
 ///
 /// For most targets, a limit of four total registers is reasonable; this
 /// limits the amount of code required in order to move around the value
@@ -134,15 +134,14 @@
 /// immediately within the callee.  But some targets may need to further
 /// limit the register count due to an inability to support that many
 /// return registers.
-static bool occupiesMoreThan(CodeGenTypes &cgt,
- ArrayRef scalarTypes,
- unsigned maxAllRegisters) {
+bool SwiftABIInfo::occupiesMoreThan(ArrayRef scalarTypes,
+unsigned maxAllRegisters) const {
   unsigned intCount = 0, fpCount = 0;
   for (llvm::Type *type : scalarTypes) {
 if (type->isPointerTy()) {
   intCount++;
 } else if (auto intTy = dyn_cast(type)) {
-  auto ptrWidth = cgt.getTarget().getPointerWidth(LangAS::Default);
+  auto ptrWidth = CGT.getTarget().getPointerWidth(LangAS::Default);
   intCount += (intTy->getBitWidth() + ptrWidth - 1) / ptrWidth;
 } else {
   assert(type->isVectorTy() || type->isFloatingPointTy());
@@ -155,7 +154,7 @@
 
 bool SwiftABIInfo::shouldPassIndirectly(ArrayRef ComponentTys,
 bool AsReturnValue) const {
-  return occupiesMoreThan(CGT, ComponentTys, /*total=*/4);
+  return occupiesMoreThan(ComponentTys, /*total=*/4);
 }
 
 bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
@@ -1246,7 +1245,7 @@
 // integer registers and three fp registers.  Oddly, it'll use up to
 // four vector registers for vectors, but those can overlap with the
 // scalar registers.
-return occupiesMoreThan(CGT, ComponentTys, /*total=*/3);
+return occupiesMoreThan(ComponentTys, /*total=*/3);
   }
 };
 
Index: clang/lib/CodeGen/ABIInfo.h
===
--- clang/lib/CodeGen/ABIInfo.h
+++ clang/lib/CodeGen/ABIInfo.h
@@ -120,6 +120,9 @@
 CodeGenTypes &CGT;
 bool SwiftErrorInRegister;
 
+bool occupiesMoreThan(ArrayRef scalarTypes,
+  unsigned maxAllRegisters) const;
+
   public:
 SwiftABIInfo(CodeGen::CodeGenTypes &CGT, bool SwiftErrorInRegister)
 : CGT(CGT), SwiftErrorInRegister(SwiftErrorInRegister) {}


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -125,7 +125,7 @@
 /// registers when expanded?
 ///
 /// This is intended to be the basis of a reasonable basic implementation
-/// of should{Pass,Return}IndirectlyForSwift.
+/// of should{Pass,Return}Indirectly.
 ///
 /// For most targets, a limit of four total registers is reasonable; this
 /// limits the amount of code required in order to move around the value
@@ -134,15 +134,14 @@
 /// immediately within the callee.  But some targets may need to further
 /// limit the register count due to an inability to support that many
 /// return registers.
-static bool occupiesMoreThan(CodeGenTypes &cgt,
- ArrayRef scalarTypes,
- unsigned maxAllRegisters) {
+bool SwiftABIInfo::occupiesMoreThan(ArrayRef scalarTypes,
+unsigned maxAllRegisters) const {
   unsigned intCount = 0, fpCount = 0;
   for (llvm::Type *type : scalarTypes) {
 if (type->isPointerTy()) {
   intCount++;
 } else if (auto intTy = dyn_cast(type)) {
-  auto ptrWidth = cgt.getTarget().getPointerWidth(LangAS::Default);
+  auto ptrWidth = CGT.getTarget().getPointerWidth(LangAS::Default);
   intCount += (intTy->getBitWidth() + ptrWidth - 1) / ptrWidth;
 } else {
   assert(type->isVectorTy() || type->isFloatingPointTy());
@@ -155,7 +154,7 @@
 
 bool SwiftABIInfo::shouldPassIndirectly(ArrayRef ComponentTys,
 bool AsReturnValue) const {
-  return occupiesMoreThan(CGT, ComponentTys, /*total=*/4);
+  return occupiesMoreThan(ComponentTys, /*total=*/4);
 }
 
 bool SwiftABIInfo::isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
@@ -1246,7 +1245,7 @@
 // integer registers and three fp registers.  Oddly, it'll use up to
 // four vector registers fo

[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type

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

Thank you for the fix, you need to add a test that exercises the diagnostic you 
added, I think `clang/test/Sema/builtin-assume-aligned.c`  would be the right 
place to add it.

Also please add a release note in `clang/docs/ReleaseNotes.rst`


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

https://reviews.llvm.org/D149514

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


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

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

In D148092#4302861 , @efriedma wrote:

> Is this supposed to be different from D148093 
> ?

Yes indeed. I've updated D148093 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148092

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


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

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 518188.
barannikov88 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148089

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9072,13 +9072,17 @@
 
 namespace {
 class LanaiABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   LanaiABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
 
   bool shouldUseInReg(QualType Ty, CCState &State) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // Lanai uses 4 registers to pass arguments unless the function has the
 // regparm attribute set.
 if (FI.getHasRegParm()) {
@@ -10090,6 +10094,10 @@
 namespace {
 
 class ARCABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   using DefaultABIInfo::DefaultABIInfo;
 
@@ -10112,7 +10120,7 @@
   }
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // ARC uses 8 registers to pass arguments.
 State.FreeRegs = 8;
 


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9072,13 +9072,17 @@
 
 namespace {
 class LanaiABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   LanaiABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
 
   bool shouldUseInReg(QualType Ty, CCState &State) const;
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // Lanai uses 4 registers to pass arguments unless the function has the
 // regparm attribute set.
 if (FI.getHasRegParm()) {
@@ -10090,6 +10094,10 @@
 namespace {
 
 class ARCABIInfo : public DefaultABIInfo {
+  struct CCState {
+unsigned FreeRegs;
+  };
+
 public:
   using DefaultABIInfo::DefaultABIInfo;
 
@@ -10112,7 +10120,7 @@
   }
 
   void computeInfo(CGFunctionInfo &FI) const override {
-CCState State(FI);
+CCState State;
 // ARC uses 8 registers to pass arguments.
 State.FreeRegs = 8;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 518189.
barannikov88 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148090

Files:
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -828,19 +828,18 @@
 // This is a very simple ABI that relies a lot on DefaultABIInfo.
 //===--===//
 
-class WebAssemblyABIInfo final : public ABIInfo {
-public:
-  enum ABIKind {
-MVP = 0,
-ExperimentalMV = 1,
-  };
+enum class WebAssemblyABIKind {
+  MVP = 0,
+  ExperimentalMV = 1,
+};
 
-private:
+class WebAssemblyABIInfo final : public ABIInfo {
   DefaultABIInfo defaultInfo;
-  ABIKind Kind;
+  WebAssemblyABIKind Kind;
 
 public:
-  explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind)
+  explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT,
+  WebAssemblyABIKind Kind)
   : ABIInfo(CGT), defaultInfo(CGT), Kind(Kind) {}
 
 private:
@@ -864,7 +863,7 @@
 class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
 public:
   explicit WebAssemblyTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
-WebAssemblyABIInfo::ABIKind K)
+WebAssemblyABIKind K)
   : TargetCodeGenInfo(std::make_unique(CGT, K)) {
 SwiftInfo =
 std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
@@ -929,7 +928,7 @@
 if (const Type *SeltTy = isSingleElementStruct(Ty, getContext()))
   return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
 // For the experimental multivalue ABI, fully expand all other aggregates
-if (Kind == ABIKind::ExperimentalMV) {
+if (Kind == WebAssemblyABIKind::ExperimentalMV) {
   const RecordType *RT = Ty->getAs();
   assert(RT);
   bool HasBitField = false;
@@ -962,7 +961,7 @@
   if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext()))
 return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
   // For the experimental multivalue ABI, return all other aggregates
-  if (Kind == ABIKind::ExperimentalMV)
+  if (Kind == WebAssemblyABIKind::ExperimentalMV)
 return ABIArgInfo::getDirect();
 }
   }
@@ -4989,21 +4988,19 @@
 // PowerPC-64
 
 namespace {
+enum class PPC64_SVR4_ABIKind {
+  ELFv1 = 0,
+  ELFv2,
+};
+
 /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
 class PPC64_SVR4_ABIInfo : public ABIInfo {
-public:
-  enum ABIKind {
-ELFv1 = 0,
-ELFv2
-  };
-
-private:
   static const unsigned GPRBits = 64;
-  ABIKind Kind;
+  PPC64_SVR4_ABIKind Kind;
   bool IsSoftFloatABI;
 
 public:
-  PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind,
+  PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
  bool SoftFloatABI)
   : ABIInfo(CGT), Kind(Kind), IsSoftFloatABI(SoftFloatABI) {}
 
@@ -5051,8 +5048,7 @@
 class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {
 
 public:
-  PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT,
-   PPC64_SVR4_ABIInfo::ABIKind Kind,
+  PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT, PPC64_SVR4_ABIKind Kind,
bool SoftFloatABI)
   : TargetCodeGenInfo(
 std::make_unique(CGT, Kind, SoftFloatABI)) {
@@ -5151,7 +5147,7 @@
   // Likewise for ELFv2 homogeneous aggregates.
   const Type *Base = nullptr;
   uint64_t Members = 0;
-  if (!AlignAsType && Kind == ELFv2 &&
+  if (!AlignAsType && Kind == PPC64_SVR4_ABIKind::ELFv2 &&
   isAggregateTypeForABI(Ty) && isHomogeneousAggregate(Ty, Base, Members))
 AlignAsType = Base;
 
@@ -5345,7 +5341,7 @@
 // ELFv2 homogeneous aggregates are passed as array types.
 const Type *Base = nullptr;
 uint64_t Members = 0;
-if (Kind == ELFv2 &&
+if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&
 isHomogeneousAggregate(Ty, Base, Members)) {
   llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
   llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
@@ -5415,7 +5411,7 @@
 // ELFv2 homogeneous aggregates are returned as array types.
 const Type *Base = nullptr;
 uint64_t Members = 0;
-if (Kind == ELFv2 &&
+if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&
 isHomogeneousAggregate(RetTy, Base, Members)) {
   llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
   llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
@@ -5424,7 +5420,7 @@
 
 // ELFv2 small aggregates are returned in up to two registers.
 uint64_t Bits = getContext().getTypeSize(RetTy);
-if (Kind == ELFv2 && Bits <= 2 * GPRBits) {
+if (Kind == PPC64_SVR4_ABIKind::ELFv2 &&

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

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 518190.
barannikov88 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148091

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5065,9 +5065,10 @@
llvm::Value *Address) const override;
 };
 
-class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
-  PPC64TargetCodeGenInfo(CodeGenTypes &CGT) : DefaultTargetCodeGenInfo(CGT) {}
+  PPC64TargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 // This is recovered from gcc output.
@@ -5077,7 +5078,6 @@
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
llvm::Value *Address) const override;
 };
-
 }
 
 // Return true if the ABI requires Ty to be passed sign- or zero-
@@ -8600,10 +8600,10 @@
 
 namespace {
 
-class TCETargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class TCETargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   TCETargetCodeGenInfo(CodeGenTypes &CGT)
-: DefaultTargetCodeGenInfo(CGT) {}
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5065,9 +5065,10 @@
llvm::Value *Address) const override;
 };
 
-class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
-  PPC64TargetCodeGenInfo(CodeGenTypes &CGT) : DefaultTargetCodeGenInfo(CGT) {}
+  PPC64TargetCodeGenInfo(CodeGenTypes &CGT)
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 // This is recovered from gcc output.
@@ -5077,7 +5078,6 @@
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
llvm::Value *Address) const override;
 };
-
 }
 
 // Return true if the ABI requires Ty to be passed sign- or zero-
@@ -8600,10 +8600,10 @@
 
 namespace {
 
-class TCETargetCodeGenInfo : public DefaultTargetCodeGenInfo {
+class TCETargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   TCETargetCodeGenInfo(CodeGenTypes &CGT)
-: DefaultTargetCodeGenInfo(CGT) {}
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 518191.
barannikov88 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148092

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2483,10 +2483,6 @@
 std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
   }
 
-  const X86_64ABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   /// Disable tail call on x86-64. The epilogue code before the tail jump 
blocks
   /// autoreleaseRV/retainRV and autoreleaseRV/unsafeClaimRV optimizations.
   bool markARCOptimizedReturnCallsAsNoTail() const override { return true; }
@@ -2523,7 +2519,8 @@
   bool HasAVXType = false;
   for (CallArgList::const_iterator
  it = args.begin(), ie = args.end(); it != ie; ++it) {
-if (getABIInfo().isPassedUsingAVXType(it->Ty)) {
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isPassedUsingAVXType(it->Ty)) {
   HasAVXType = true;
   break;
 }
@@ -6404,10 +6401,6 @@
 SwiftInfo = std::make_unique(CGT);
   }
 
-  const ARMABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 return 13;
   }
@@ -6426,7 +6419,9 @@
   }
 
   unsigned getSizeOfUnwindException() const override {
-if (getABIInfo().isEABI()) return 88;
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isEABI())
+  return 88;
 return TargetCodeGenInfo::getSizeOfUnwindException();
   }
 
@@ -6493,7 +6488,7 @@
 
 Fn->addFnAttr("interrupt", Kind);
 
-ARMABIKind ABI = cast(getABIInfo()).getABIKind();
+ARMABIKind ABI = static_cast(getABIInfo()).getABIKind();
 if (ABI == ARMABIKind::APCS)
   return;
 
@@ -7431,10 +7426,6 @@
 class SystemZTargetCodeGenInfo : public TargetCodeGenInfo {
   ASTContext &Ctx;
 
-  const SystemZABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   // These are used for speeding up the search for a visible vector ABI.
   mutable bool HasVisibleVecABIFlag = false;
   mutable std::set SeenTypes;
@@ -7884,7 +7875,9 @@
 // be passed via "hidden" pointer where any extra alignment is not
 // required (per GCC).
 const Type *SingleEltTy =
-  getABIInfo().GetSingleElementType(QualType(Ty, 0)).getTypePtr();
+static_cast(TargetCodeGenInfo::getABIInfo())
+.GetSingleElementType(QualType(Ty, 0))
+.getTypePtr();
 bool SingleVecEltStruct = SingleEltTy != Ty && SingleEltTy->isVectorType() 
&&
   Ctx.getTypeSize(SingleEltTy) == Ctx.getTypeSize(Ty);
 if (Ty->isVectorType() || SingleVecEltStruct)
@@ -11857,10 +11850,6 @@
 public:
   BPFTargetCodeGenInfo(CodeGenTypes &CGT)
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
-
-  const BPFABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
 };
 
 }


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2483,10 +2483,6 @@
 std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
   }
 
-  const X86_64ABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   /// Disable tail call on x86-64. The epilogue code before the tail jump blocks
   /// autoreleaseRV/retainRV and autoreleaseRV/unsafeClaimRV optimizations.
   bool markARCOptimizedReturnCallsAsNoTail() const override { return true; }
@@ -2523,7 +2519,8 @@
   bool HasAVXType = false;
   for (CallArgList::const_iterator
  it = args.begin(), ie = args.end(); it != ie; ++it) {
-if (getABIInfo().isPassedUsingAVXType(it->Ty)) {
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isPassedUsingAVXType(it->Ty)) {
   HasAVXType = true;
   break;
 }
@@ -6404,10 +6401,6 @@
 SwiftInfo = std::make_unique(CGT);
   }
 
-  const ARMABIInfo &getABIInfo() const {
-return static_cast(TargetCodeGenInfo::getABIInfo());
-  }
-
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
 return 13;
   }
@@ -6426,7 +6419,9 @@
   }
 
   unsigned getSizeOfUnwindException() const override {
-if (getABIInfo().isEABI()) return 88;
+if (static_cast(TargetCodeGenInfo::getABIInfo())
+.isEABI())
+  return 88;
 return TargetCodeGenInfo::getSizeOfUnwindException();
   }
 
@@ -6493,7 +6488,7 @@
 
 Fn->addFnAttr("interrupt", Kind);
 
-ARMABIKind ABI = cast(getABIInfo()).getABIKind();
+ARMABIKind ABI = static_cast(getABIInfo()).getABIKind

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

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 518199.
barannikov88 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

Files:
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AArch64.h
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/AMDGPU.h
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARC.h
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/ARM.h
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/AVR.h
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/BPF.h
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/CSKY.h
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Hexagon.h
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/Lanai.h
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/LoongArch.h
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/M68k.h
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/MSP430.h
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/Mips.h
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/NVPTX.h
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PNaCl.h
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/PPC.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/RISCV.h
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/SPIR.h
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/Sparc.h
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/SystemZ.h
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/TCE.h
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/VE.h
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/WebAssembly.h
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/X86.h
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/lib/CodeGen/Targets/XCore.h

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


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

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

Thank you all for taking a look!

In D148094#4296346 , @aaron.ballman 
wrote:

> I did not verify that the refactoring didn't change functionality, but 
> spot-checking did not find any differences.



In D148094#4302879 , @efriedma wrote:

> I'm assuming there isn't actually any changed code, just moving code around.

Apart from code moving this patch splits some methods into
declaration + definition so that the header files only need to include 
"TargetInfo.h".

This could be avoided by taking a different approach, i.e. the header files
contain only a factory function and cpp files contain the implementation
(of both ABIInfo and TargetCodeGenInfo). This is not a very C++-ish way,
but it would make the changes more straingforward.
I can do it if it's preferable.

In D148094#4296351 , @MaskRay wrote:

> This refactoring looks reasonable to me as well. In `clang/lib/Driver`, we 
> have D30372  that splits some huge files 
> into target-specific files.

Thanks, I've updated the RFC with this link.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

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


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

2023-04-29 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

Hi @craig.topper , this patch is causing a build failure:

  In file included from /llvm-project/clang/lib/Sema/SemaType.cpp:43:
  /llvm-project/llvm/include/llvm/TargetParser/RISCVTargetParser.h:32:10: fatal 
error: 'llvm/TargetParser/RISCVTargetParserDef.inc' file not found

To reproduce, configure from a clean build directory like this:

  cmake -G Ninja /path/to/llvm-project/llvm \
-DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DLLVM_ENABLE_PROJECTS="clang"

Then run:

  ninja tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaType.cpp.o

Could you take a look? 🙏


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D147888: Update declaration message of extern linkage

2023-04-29 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

In D147888#4288149 , 
@Krishna-13-cyber wrote:

> I have tried a little modification from my side thinking on a beneficial 
> note. I will make the changes to all the other test files as well if this 
> diagnostic representation goes well after mentor review.
>
> For refactoring and restructuring the whole of the re-declaration would need 
> some time I have been through it and would initiate another patch for that,In 
> the concern of giving or having just one diagnostic for getting all cases of 
> re-declaration would also need multiple conditional or switch statements 
> inside our function block.At present we have the same with conditional 
> statements taking care of each linkage but it has multiple permutations of 
> diagnostic messages which is nice but can be improved.GCC differs only for 
> this case of extern linkage which can be better/precise in clang where as 
> others seem to be more precise in clang than former as I worked out with good 
> number of test cases regarding this.

Ping!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147888

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


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

2023-04-29 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 518226.
bolshakov-a added a comment.

`SmallVector` instead of `std::stack`; fixing formatting.


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

https://reviews.llvm.org/D146386

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/test/CodeGenCXX/mangle-class-nttp.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp

Index: clang/test/CodeGenCXX/mangle-ms-templates.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-templates.cpp
+++ clang/test/CodeGenCXX/mangle-ms-templates.cpp
@@ -272,7 +272,7 @@
 };
 extern const record inst;
 void recref(type1) {}
-// CHECK: "?recref@@YAXU?$type1@$E?inst@@3Urecord@@B@@@Z"
+// CHECK: "?recref@@YAXU?$type1@$1?inst@@3Urecord@@B@@@Z"
 
 struct _GUID {};
 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
@@ -286,7 +286,7 @@
 void fun(UUIDType1 a) {}
 // CHECK: "?fun@@YAXU?$UUIDType1@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
 void fun(UUIDType2 b) {}
-// CHECK: "?fun@@YAXU?$UUIDType2@Uuuid@@$E?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
+// CHECK: "?fun@@YAXU?$UUIDType2@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
 
 template  struct TypeWithFriendDefinition {
   friend void FunctionDefinedWithInjectedName(TypeWithFriendDefinition) {}
Index: clang/test/CodeGenCXX/mangle-class-nttp.cpp
===
--- clang/test/CodeGenCXX/mangle-class-nttp.cpp
+++ clang/test/CodeGenCXX/mangle-class-nttp.cpp
@@ -15,7 +15,7 @@
 
 int n = 0;
 // CHECK: define weak_odr void @_Z1fIXtl1BadL_Z1nvv(
-// MSABI: define {{.*}} @"??$f@$2UB@@PEBH1?n@@3HAH0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UB@@PEBHE?n@@3HAH0AYAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1BLPKi0ELi1vv(
 // MSABI: define {{.*}} @"??$f@$2UB@@PEBH0A@H00@@@YAXXZ"
@@ -36,15 +36,19 @@
 
 // Pointers to subobjects.
 struct Nested { union { int k; int arr[2]; }; } nested[2];
-struct Derived : A, Nested { int z; } extern derived;
+struct Derived : A, Nested { int z; A a_field; } extern derived;
 // CHECK: define weak_odr void @_Z1fIXtl1BadsoKiL_Z7derivedE16vv
 // MSABI: define {{.*}} void @"??$f@$2UB@@PEBH56E?derived@@3UDerived@@Az@@@H0AYAXXZ"
 template void f();
-// FIXME: We don't know the MS ABI mangling for array subscripting and
-// past-the-end pointers yet.
-#ifndef _WIN32
+// CHECK: define weak_odr void @_Z1fIXtl1BadsoKiL_Z7derivedE20vv
+// MSABI: define {{.*}} void @"??$f@$2UB@@PEBH566E?derived@@3UDerived@@Aa_field@@a@@@H0AYAXXZ"
+template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1BadsoKiL_Z6nestedE_vv
+// MSABI: define {{.*}} void @"??$f@$2UB@@PEBH56CE?nested@@3PAUNested@@A0A@@k@@@H0AYAXXZ"
 template void f();
+// Mangling of pointers to nested array elements and past-the-end pointers
+// is still incorrect in MSVC.
+#ifndef _WIN32
 // CHECK: define weak_odr void @_Z1fIXtl1BadsoKiL_Z6nestedE16_0pvv
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1BadsoKiL_Z7derivedE8pvv
@@ -59,14 +63,16 @@
 // CHECK: define weak_odr void @_Z1fIXtl2BRsoKiL_Z7derivedE16vv
 // MSABI: define {{.*}} void @"??$f@$2UBR@@AEBH6E?derived@@3UDerived@@Az@YAXXZ"
 template void f();
-// FIXME: We don't know the MS ABI mangling for array subscripting yet.
-#ifndef _WIN32
 // CHECK: define weak_odr void @_Z1fIXtl2BRsoKiL_Z6nestedE_vv
+// MSABI: define {{.*}} void @"??$f@$2UBR@@AEBH6CE?nested@@3PAUNested@@A0A@@k@YAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl2BRsoKiL_Z6nestedE12_0vv
+// MSABI: define {{.*}} void @"??$f@$2UBR@@AEBHC6CE?nested@@3PAUNested@@A00@arr@@00YAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl2BRsoKiL_Z7derivedE4vv
+// MSABI: define {{.*}} void @"??$f@$2UBR@@AEBH66E?derived@@3UDerived@@AA@@b@YAXXZ"
 template void f();
+#ifndef _WIN32
 // CHECK: define weak_odr void @_Z1fIXtl2BRdecvPKiplcvPcadL_Z7derivedELl16vv
 template void f();
 #endif
@@ -77,42 +83,93 @@
 // CHECK: define weak_odr void @_Z1fIXtl1CadsoKiL_Z7derivedE16vv
 // MSABI: define {{.*}} void @"??$f@$2UC@@PEBH56E?derived@@3UDerived@@Az@@YAXXZ"
 template void f();
-#ifndef _WIN32
 // CHECK: define weak_odr void @_Z1fIXtl1CadsoKiL_Z7derivedE4vv
+// MSABI: define {{.*}} void @"??$f@$2UC@@PEBH566E?derived@@3UDerived@@AA@@b@@YAXXZ"
 template void f();
-#endif
 
 // Pointers to members.
 struct D { const int Derived::*p; int k; };
 template void f() {}
 // CHECK: define weak_odr void @_Z1fIXtl1DLM7DerivedKi0ELi1vv
-// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H0?0H00@@@YAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@HNH00@@@YAXXZ"
 template void f();
 // CHECK: define weak_odr void @_Z1fIXtl1DEEEvv
-// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@H0?0H0AYAXXZ"
+// MSABI: define {{.*}} @"??$f@$2UD@@PERDerived@@HNH0AYA

[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type

2023-04-29 Thread Rishabh Bali via Phabricator via cfe-commits
Ris-Bali updated this revision to Diff 518228.
Ris-Bali added a comment.

Added test and made changes in ReleaseNotes.rst


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

https://reviews.llvm.org/D149514

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtin-assume-aligned.c


Index: clang/test/Sema/builtin-assume-aligned.c
===
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -71,6 +71,11 @@
   return a[0];
 }
 
+int test14(int *a, int b) {
+  a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{passing 
'int' to parameter of incompatible type 'int *'}}
+  return a[0];
+}
+
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // 
no-warning
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+QualType firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  QualType expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}
 TheCall->setArg(0, FirstArgResult.get());
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,9 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when attempting to pass a non-pointer type as first argument of
+  ``__builtin_assume_aligned``.
+  (`#62305 `)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Sema/builtin-assume-aligned.c
===
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -71,6 +71,11 @@
   return a[0];
 }
 
+int test14(int *a, int b) {
+  a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{passing 'int' to parameter of incompatible type 'int *'}}
+  return a[0];
+}
+
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+QualType firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  QualType expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}
 TheCall->setArg(0, FirstArgResult.get());
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,9 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when attempting to pass a non-pointer type as first argument of
+  ``__builtin_assume_aligned``.
+  (`#62305 `)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a479786 - [RISCV][Sema] Add a build dependency on RISCVTargetParserTableGen after D145088.

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

Author: Craig Topper
Date: 2023-04-29T13:33:54-07:00
New Revision: a4797869e73355209206a5175c11bedb14013211

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

LOG: [RISCV][Sema] Add a build dependency on RISCVTargetParserTableGen after 
D145088.

Need to find a better home for RISCV::RVVBitsPerBlock to remove
this dependency. This just a quick fix to fix the build.

Added: 


Modified: 
clang/lib/Sema/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 629fafadcf9f4..843a269dac720 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -71,6 +71,7 @@ add_clang_library(clangSema
   DEPENDS
   ClangOpenCLBuiltinsImpl
   omp_gen
+  RISCVTargetParserTableGen
 
   LINK_LIBS
   clangAST



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


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

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

In D145088#4307772 , @akyrtzi wrote:

> Hi @craig.topper , this patch is causing a build failure:
>
>   In file included from /llvm-project/clang/lib/Sema/SemaType.cpp:43:
>   /llvm-project/llvm/include/llvm/TargetParser/RISCVTargetParser.h:32:10: 
> fatal error: 'llvm/TargetParser/RISCVTargetParserDef.inc' file not found
>
> To reproduce, configure from a clean build directory like this:
>
>   cmake -G Ninja /path/to/llvm-project/llvm \
> -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" \
> -DCMAKE_BUILD_TYPE:STRING=Release \
> -DLLVM_ENABLE_PROJECTS="clang"
>
> Then run:
>
>   ninja tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaType.cpp.o
>
> Could you take a look? 🙏

Thanks, I pushed a4797869e73355209206a5175c11bedb14013211 
 to fix 
this. I'm going to find a better home for `RISCV::RVVBitsPerBlock` so we can 
remove this dependency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D147197: [llvm-docs] Added documentation for the 'neg' operation

2023-04-29 Thread Victor Salami Oyale via Phabricator via cfe-commits
oyalesalami abandoned this revision.
oyalesalami added a comment.

These instructions do not exist anymore, so there is no need for documentation 
on them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147197

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


[PATCH] D146490: [Support] On Windows, ensure that UniqueID is really stable

2023-04-29 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D146490#4307269 , @falhumai96 
wrote:

> I would like to follow up on this issue whether or not there has been an 
> update on it.

There's no update currently; I think there's some amount of consensus that this 
approach, while fixing the issue, would cause too much other collateral issues.

I'm considering making a patch that switches to hashing the canonicalized path, 
for the cases where we know the path isn't a local path; it's not an entirely 
correct solution, but a rough approximation for when the file IDs are stable or 
not. I just haven't had time to try doing that yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146490

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


[clang] ee9cbe3 - [RISCV] Move RISCV::RVVBitsPerBlock from TargetParser to Support/RISCVISAInfo.h.

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

Author: Craig Topper
Date: 2023-04-29T15:04:55-07:00
New Revision: ee9cbe3548cded885c6409d6dd8a616b515a06d3

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

LOG: [RISCV] Move RISCV::RVVBitsPerBlock from TargetParser to 
Support/RISCVISAInfo.h.

RISCVTargetParser.h has a dependency on a tablegen generated file.

Using RISCVISAInfo.h instead avoids this dependency.

We just need this constant somewhere visible to the frontend and
backend and I'm trying to avoid adding a header just for it.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/SemaType.cpp
llvm/include/llvm/Support/RISCVISAInfo.h
llvm/include/llvm/TargetParser/RISCVTargetParser.h
llvm/lib/Target/RISCV/RISCVISelLowering.h

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 3a72c3d257944..c04b056cba78f 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -85,7 +85,7 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 #include 

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index ed481a4c06962..20282c08afab5 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -46,7 +46,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include 
 #include 
 #include 

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index ff4d516090ea4..7f02621777004 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -33,7 +33,7 @@
 #include "llvm/IR/Type.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 8fe8ef2265c99..1aadc67a2d0cb 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -19,7 +19,6 @@
 #include "llvm/Support/SpecialCaseList.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
-#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 

diff  --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 843a269dac720..629fafadcf9f4 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -71,7 +71,6 @@ add_clang_library(clangSema
   DEPENDS
   ClangOpenCLBuiltinsImpl
   omp_gen
-  RISCVTargetParserTableGen
 
   LINK_LIBS
   clangAST

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 19a41b022ecda..6442d3182b85b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -40,7 +40,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include 
 #include 
 

diff  --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 6eb085c32b5b2..1a260e93b64a9 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -22,6 +22,11 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
+namespace RISCV {
+// We use 64 bits as the known part in the scalable vector types.
+static constexpr unsigned RVVBitsPerBlock = 64;
+}
+
 class RISCVISAInfo {
 public:
   RISCVISAInfo(const RISCVISAInfo &) = delete;

diff  --git a/llvm/include/llvm/TargetParser/RISCVTargetParser.h 
b/llvm/include/llvm/TargetParser/RISCVTargetParser.h
index 993f653455a0d..83effbc184897 100644
--- a/llvm/include/llvm/TargetParser/RISCVTargetParser.h
+++ b/llvm/include/llvm/TargetParser/RISCVTargetParser.h
@@ -15,17 +15,11 @@
 #define LLVM_TARGETPARSER_RISCVTARGETPARSER_H
 
 #include "llvm/ADT/StringRef.h"
-#include 
 
 namespace llvm {
 
-class Triple;
-
 namespace RISCV {
 
-// We use 64 bits as the known part in the scalable vector types.
-static constexpr unsigned RVVBitsPerBlock = 64;
-
 enum CPUKind : unsigned {
 #define PROC(ENUM, NAME, DEFAULT_MARCH) CK_##ENUM,
 #define TUNE_PROC(ENUM, NAME) CK_##ENUM,

diff 

[PATCH] D141757: [clangd] allow extracting to variable for lambda expressions

2023-04-29 Thread Julian Schmidt via Phabricator via cfe-commits
5chmidti added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:178
+  // Allow all expressions except partial LambdaExpr selections since we
+  // don't want to extract from the captures/default arguments of a lambda
+  if (isa(Stmt)) {

Noticed that this can be removed because extracting from captures is allowed. 
Will change in the next update



Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp:182-184
+if (InsertionPoint->Parent->ASTNode.get() != nullptr) {
+  return false;
+}

This is supposed to stop the following invalid code from happening:
```
void foo() {
  int placeholder = 42;
  [](int x = placeholder {};
  extern void bar(int x = placeholder);
}
```

clangd does not seem to support extracting from the initializers of defaulted 
parameters, should I keep the condition as is, or should I do something 
different here? It is legal to have default arguments in global scope (examples 
below).

The following insertions could exist (out of scope for this patch):
```
int placeholder = 42;
void foo() {
  [](int x = placeholder {};
  extern void bar(int x = placeholder);
}
```
```
struct X {
  static inline int placeholder = 42;
  void foo(int x = placeholder) {}
};
```

Either way, I'll have to adjust the comment because this is not just to stop 
default parameter initializers in lambdas from being extracted to a local scope.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141757

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


[PATCH] D149516: [Sema] `setInvalidDecl` for error deduction declaration

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

Thank you for the fix.

I have some questions, why don't we always call `CheckDeductionGuideDeclarator` 
when calling `CXXDeductionGuideDecl::Create`, I felt like perhaps 
`CheckDeductionGuideDeclarator` should be rolled into 
`CXXDeductionGuideDecl::Create` but then I noticed they are not paired up in 
other locations.

CC @rsmith


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149516

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


[PATCH] D149451: [NVPTX] Add NVPTXCtorDtorLoweringPass to handle global ctors / dtors

2023-04-29 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 518262.
jhuber6 added a comment.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Update to only enable this when in "freestanding" mode. Also add a hash based 
on the module name to the global.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149451

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/Cuda.h
  clang/test/Driver/cuda-cross-compiling.c
  llvm/lib/Target/NVPTX/CMakeLists.txt
  llvm/lib/Target/NVPTX/NVPTX.h
  llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.h
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
  llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll

Index: llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/lower-ctor-dtor.ll
@@ -0,0 +1,27 @@
+; RUN: opt -S -mtriple=nvptx64-- -nvptx-lower-ctor-dtor < %s | FileCheck %s
+; RUN: opt -S -mtriple=nvptx64-- -passes=nvptx-lower-ctor-dtor < %s | FileCheck %s
+
+; Make sure we get the same result if we run multiple times
+; RUN: opt -S -mtriple=nvptx64-- -passes=nvptx-lower-ctor-dtor,nvptx-lower-ctor-dtor < %s | FileCheck %s
+; RUN: llc -nvptx-lower-global-ctor-dtor -mtriple=nvptx64-amd-amdhsa -mcpu=sm_70 -filetype=asm -o - < %s | FileCheck %s -check-prefix=VISIBILITY
+
+@llvm.global_ctors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @foo, ptr null }]
+@llvm.global_dtors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @bar, ptr null }]
+
+; CHECK-NOT: @llvm.global_ctors
+; CHECK-NOT: @llvm.global_dtors
+
+; CHECK: @__init_array_object_foo_[[HASH:[0-9a-f]+]]_1 = protected addrspace(4) constant ptr @foo, section ".init_array.1"
+; CHECK: @__fini_array_object_bar_[[HASH:[0-9a-f]+]]_1 = protected addrspace(4) constant ptr @bar, section ".fini_array.1"
+; CHECK: @llvm.used = appending global [2 x ptr] [ptr addrspacecast (ptr addrspace(4) @__init_array_object_foo_[[HASH]]_1 to ptr), ptr addrspacecast (ptr addrspace(4) @__fini_array_object_bar_[[HASH]]_1 to ptr)], section "llvm.metadata"
+
+; VISIBILITY: .visible .const .align 8 .u64 __init_array_object_foo_[[HASH:[0-9a-f]+]]_1 = foo;
+; VISIBILITY: .visible .const .align 8 .u64 __fini_array_object_bar_[[HASH:[0-9a-f]+]]_1 = bar;
+
+define internal void @foo() {
+  ret void
+}
+
+define internal void @bar() {
+  ret void
+}
Index: llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
===
--- llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -15,6 +15,7 @@
 #include "NVPTXAliasAnalysis.h"
 #include "NVPTXAllocaHoisting.h"
 #include "NVPTXAtomicLower.h"
+#include "NVPTXCtorDtorLowering.h"
 #include "NVPTXLowerAggrCopies.h"
 #include "NVPTXMachineFunctionInfo.h"
 #include "NVPTXTargetObjectFile.h"
@@ -68,8 +69,10 @@
 void initializeNVPTXAllocaHoistingPass(PassRegistry &);
 void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry&);
 void initializeNVPTXAtomicLowerPass(PassRegistry &);
+void initializeNVPTXCtorDtorLoweringLegacyPass(PassRegistry &);
 void initializeNVPTXLowerAggrCopiesPass(PassRegistry &);
 void initializeNVPTXLowerAllocaPass(PassRegistry &);
+void initializeNVPTXCtorDtorLoweringLegacyPass(PassRegistry &);
 void initializeNVPTXLowerArgsPass(PassRegistry &);
 void initializeNVPTXProxyRegErasurePass(PassRegistry &);
 void initializeNVVMIntrRangePass(PassRegistry &);
@@ -95,6 +98,7 @@
   initializeNVPTXAtomicLowerPass(PR);
   initializeNVPTXLowerArgsPass(PR);
   initializeNVPTXLowerAllocaPass(PR);
+  initializeNVPTXCtorDtorLoweringLegacyPass(PR);
   initializeNVPTXLowerAggrCopiesPass(PR);
   initializeNVPTXProxyRegErasurePass(PR);
   initializeNVPTXDAGToDAGISelPass(PR);
@@ -249,6 +253,10 @@
   PB.registerPipelineParsingCallback(
   [](StringRef PassName, ModulePassManager &PM,
  ArrayRef) {
+if (PassName == "nvptx-lower-ctor-dtor") {
+  PM.addPass(NVPTXCtorDtorLoweringPass());
+  return true;
+}
 if (PassName == "generic-to-nvvm") {
   PM.addPass(GenericToNVVMPass());
   return true;
@@ -369,6 +377,7 @@
   }
 
   addPass(createAtomicExpandPass());
+  addPass(createNVPTXCtorDtorLoweringLegacyPass());
 
   // === LSR and other generic IR passes ===
   TargetPassConfig::addIRPasses();
Index: llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.h
===
--- /dev/null
+++ llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.h
@@ -0,0 +1,30 @@
+//===-- NVPTXCtorDtorLowering.h *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for l

[clang] 9b1aaaf - Revert "[RISCV] Move RISCV::RVVBitsPerBlock from TargetParser to Support/RISCVISAInfo.h."

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

Author: Craig Topper
Date: 2023-04-29T18:05:56-07:00
New Revision: 9b1aaaf933cfbd1f3061cf9954d50672600b0c8b

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

LOG: Revert "[RISCV] Move RISCV::RVVBitsPerBlock from TargetParser to 
Support/RISCVISAInfo.h."

This reverts commit ee9cbe3548cded885c6409d6dd8a616b515a06d3.

I've been told this cauess a namespace clash in lld.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Type.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/SemaType.cpp
llvm/include/llvm/Support/RISCVISAInfo.h
llvm/include/llvm/TargetParser/RISCVTargetParser.h
llvm/lib/Target/RISCV/RISCVISelLowering.h

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c04b056cba78f..3a72c3d257944 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -85,7 +85,7 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 #include 

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 20282c08afab5..ed481a4c06962 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -46,7 +46,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include 
 #include 
 #include 

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 7f02621777004..ff4d516090ea4 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -33,7 +33,7 @@
 #include "llvm/IR/Type.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1aadc67a2d0cb..8fe8ef2265c99 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/SpecialCaseList.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/TargetParser/TargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 

diff  --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 629fafadcf9f4..843a269dac720 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -71,6 +71,7 @@ add_clang_library(clangSema
   DEPENDS
   ClangOpenCLBuiltinsImpl
   omp_gen
+  RISCVTargetParserTableGen
 
   LINK_LIBS
   clangAST

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 6442d3182b85b..19a41b022ecda 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -40,7 +40,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/RISCVISAInfo.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include 
 #include 
 

diff  --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 1a260e93b64a9..6eb085c32b5b2 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -22,11 +22,6 @@ struct RISCVExtensionInfo {
   unsigned MinorVersion;
 };
 
-namespace RISCV {
-// We use 64 bits as the known part in the scalable vector types.
-static constexpr unsigned RVVBitsPerBlock = 64;
-}
-
 class RISCVISAInfo {
 public:
   RISCVISAInfo(const RISCVISAInfo &) = delete;

diff  --git a/llvm/include/llvm/TargetParser/RISCVTargetParser.h 
b/llvm/include/llvm/TargetParser/RISCVTargetParser.h
index 83effbc184897..993f653455a0d 100644
--- a/llvm/include/llvm/TargetParser/RISCVTargetParser.h
+++ b/llvm/include/llvm/TargetParser/RISCVTargetParser.h
@@ -15,11 +15,17 @@
 #define LLVM_TARGETPARSER_RISCVTARGETPARSER_H
 
 #include "llvm/ADT/StringRef.h"
+#include 
 
 namespace llvm {
 
+class Triple;
+
 namespace RISCV {
 
+// We use 64 bits as the known part in the scalable vector types.
+static constexpr unsigned RVVBitsPerBlock = 64;
+
 enum CPUKind : unsigned {
 #define PROC(ENUM, NAME, DEFAULT_MARCH) CK_##ENUM,
 #define TUNE_PROC(ENUM, NAME) CK_##ENUM,

diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.h 
b/llvm/lib/Target/RISCV/RISCVISelLowering.h
index 65881f8204a6b..849b11

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

2023-04-29 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 518264.
barannikov88 added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

- Update references to modified files in non-code files
- Add LLVM_LIBRARY_VISIBILITY to classes in header files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148094

Files:
  clang/docs/UsersManual.rst
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AArch64.h
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/AMDGPU.h
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARC.h
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/ARM.h
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/AVR.h
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/BPF.h
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/CSKY.h
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Hexagon.h
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/Lanai.h
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/LoongArch.h
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/M68k.h
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/MSP430.h
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/Mips.h
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/NVPTX.h
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PNaCl.h
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/PPC.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/RISCV.h
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/SPIR.h
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/Sparc.h
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/SystemZ.h
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/TCE.h
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/VE.h
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/WebAssembly.h
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/X86.h
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/lib/CodeGen/Targets/XCore.h
  llvm/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn

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


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

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

Add unittests for void & member pointers types


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,11 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+// JIT reports symbol not found on Windows without the visibility attribute.
+REPL_EXTERNAL_VISIBILITY int getGlobal() { return Global; }
+REPL_EXTERNAL_VISIBILITY void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +282,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -315,4 +320,78 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+  EXPECT_FALSE(V1.isPointerOrObjectType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+  EXPECT_FALSE(V2.isPointerOrObjectType());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+  EXPECT_TRUE(V3.isPointerOrObjectType());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+
+  Value V6;
+  llvm::cantFail(Interp->ParseAndExecute("void foo() {}"));
+  llvm::cantFail(Interp->ParseAndExecute("foo()", &V6));
+  EXPECT_TRUE(V6.isValid());
+  EXPECT_TRUE(V6.getType()->isVoidType());
+  EXPECT_EQ(V6.getKind(), Value::K_Void);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+
+  Value V7;
+  llvm::cantFail(Interp->ParseAndExecute("foo", &V7));
+  EXPECT_TRUE(V7.isValid());
+  EXPECT_TRUE(V7.getType()->isFunctionProtoType());
+  EXPECT_EQ(V7.getKind(), Value::K_PtrOrObj);
+  EXPECT_FALSE(V7.isManuallyAlloc());
+
+  Value V8;
+  llvm::cantFail(Interp->ParseAndExecute("struct SS{ void f() {} };"));
+  llvm::cantFail(Interp->ParseAndExecute("&SS::f", &V8));
+  EXPECT_TRUE(V8.isValid());
+  EXPECT_TRUE(V8.getType()->isMemberFunctionPointerType());
+  EXPECT_EQ(V8.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V8.isManuallyAlloc());
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
==

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

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

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146809

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

Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,144 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+extern "C" int printf(const char*,...);
+
+char c = 'a';
+c
+// CHECK: (char) 'a'
+
+const char* c_str = "Goodbye, world!";
+c_str
+// CHECK-NEXT: (const char *) "Goodbye, world!"
+
+const char* c_null_str = 0;
+c_null_str
+// CHECK-NEXT: (const char *) nullptr
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+&x
+// CHECK-NEXT: (int *) [[Addr:@0x.*]]
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2f
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.210
+
+struct S1{};
+S1 s1;
+s1
+// CHECK-NEXT: (S1 &) [[Addr:@0x.*]]
+
+S1{}
+// CHECK-NEXT: (S1) [[Addr:@0x.*]]
+
+struct S2 {int d;} E = {22};
+E
+// CHECK-NEXT: (struct S2 &) [[Addr:@0x.*]]
+E.d
+// CHECK-NEXT: (int) 22
+
+struct S3 { int* p; S3() { p = new int(42); } ~S3() { delete p; } };
+S3{}
+// CHECK-NEXT: (S3) [[Addr:@0x.*]]
+S3 s3;
+s3
+// CHECK-NEXT: (S3 &) [[Addr:@0x.*]]
+
+struct S4 { ~S4() { printf("~S4()\n"); }};
+S4{}
+// CHECK-NEXT: (S4) [[Addr:@0x.*]]
+
+enum Enum{ e1 = -12, e2, e3=33, e4, e5 = 33};
+e2
+// CHECK-NEXT: (Enum) (e2) : int -11
+::e1
+// CHECK-NEXT: (Enum) (e1) : int -12
+
+enum class Color { Black = 0, Red, Green };
+Color::Black
+// CHECK-NEXT: (Color) (Color::Black) : int 0
+
+int arr[3] = {1,2,3};
+arr
+// CHECK-NEXT: (int[3]) { 1, 2, 3 }
+
+auto Lambda1 = []{};
+Lambda1
+// CHECK-NEXT: ((lambda) &) [[Addr:@0x.*]]
+[]{}
+// CHECK-NEXT: ((lambda at input_line_81:1:1)) [[Addr:@0x.*]]
+
+template struct F{ enum {RET=F::RET*n} ; };
+template<> struct F<0> { enum {RET = 1}; };
+F<7>::RET
+// CHECK-NEXT: (F<7>::(unnamed enum at input_line_84:1:27)) (F<7>::RET) : unsigned int 5040
+
+int foo() { return 42; }
+foo()
+// CHECK-NEXT: (int) 42
+
+void bar() {}
+bar()
+
+struct S5 { int foo() { return 42; }};
+&S5::foo
+// CHECK-NEXT: (int (S5::*)()) Function [[Addr:@0x.*]]
+
+#include 
+
+auto p1 = std::make_shared(42);
+p1
+// CHECK-NEXT: (shared_ptr &) std::shared_ptr -> [[Addr:@0x.*]]
+
+#include 
+std::array a{1, 2, 3};
+a
+// CHECK-NEXT: (std::array &) { 1, 2, 3 }
+
+#include 
+std::vector v = {7, 5, 16, 8};
+v
+// CHECK-NEXT: (std::vector &) { 7, 5, 16, 8 }
+
+#include 
+std::deque dq = {7, 5, 16, 8};
+dq
+// CHECK-NEXT: (std::deque &) { 7, 5, 16, 8 }
+
+#include 
+std::forward_list fl {3,4,5,6};
+fl
+// CHECK-NEXT: (std::forward_list &) { 3, 4, 5, 6 }
+
+#include 
+std::set z = {2,4,6,8};
+z
+// CHECK-NEXT: (std::set &) { 2, 4, 6, 8 }
+
+std::multiset e {3,2,1,2,4,7,3};
+e
+// CHECK-NEXT: (std::multiset &) { 1, 2, 2, 3, 3, 4, 7 }
+
+#include 
+std::string std_str = "Hello, world!";
+std_str
+// CHECK-NEXT: (std::string &) "Hello, world!"
+
+struct MyType {};
+std::string PrintValueRuntime(const MyType*) { return "My pretty printer!"; }
+MyType{}
+// CHECK-NEXT: (MyType) My pretty printer!
+%quit
+
Index: clang/lib/Interpreter/ValuePrinter.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/ValuePrinter.cpp
@@ -0,0 +1,530 @@
+#include "InterpreterUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/Value.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+
+using namespace clang;
+
+static std::string PrintDeclType(const QualType &QT, NamedDecl *D) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  if (QT.hasQualifiers())
+SS << QT.getQualifiers().getAsString() << " ";
+  SS << D->getQualifiedNameAsString();
+  return Str;
+}
+
+s

[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type

2023-04-29 Thread Rishabh Bali via Phabricator via cfe-commits
Ris-Bali updated this revision to Diff 518274.
Ris-Bali added a comment.
Herald added subscribers: carlosgalvezp, kbarton, nemanjai.
Herald added a project: clang-tools-extra.

Removed __builtin_assume_aligned from ignoredbuiltinstest() in 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp.


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

https://reviews.llvm.org/D149514

Files:
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtin-assume-aligned.c


Index: clang/test/Sema/builtin-assume-aligned.c
===
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -71,6 +71,11 @@
   return a[0];
 }
 
+int test14(int *a, int b) {
+  a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{passing 
'int' to parameter of incompatible type 'int *'}}
+  return a[0];
+}
+
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // 
expected-warning {{'assume_aligned' attribute only applies to return values 
that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // 
no-warning
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+QualType firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  QualType expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+}
 TheCall->setArg(0, FirstArgResult.get());
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,9 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix crash when attempting to pass a non-pointer type as first argument of
+  ``__builtin_assume_aligned``.
+  (`#62305 `)
 
 Bug Fixes to Compiler Builtins
 ^^
Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
@@ -52,7 +52,6 @@
 int my_vprintf(const char* format, va_list arg ); // OK to declare function 
taking va_list
 
 void ignoredBuiltinsTest() {
-  (void)__builtin_assume_aligned(0, 8);
   (void)__builtin_constant_p(0);
   (void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f);
   (void)__builtin_isinf_sign(0.f);


Index: clang/test/Sema/builtin-assume-aligned.c
===
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -71,6 +71,11 @@
   return a[0];
 }
 
+int test14(int *a, int b) {
+  a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{passing 'int' to parameter of incompatible type 'int *'}}
+  return a[0];
+}
+
 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7981,6 +7981,14 @@
 DefaultFunctionArrayLvalueConversion(FirstArg);
 if (FirstArgResult.isInvalid())
   return true;
+QualType firstArgType = FirstArgResult.get()->getType();
+
+if (!firstArgType->isAnyPointerType()) {
+  QualType expectedType = Context.getPointerType(firstArgType);
+  return Diag(FirstArg->getBeginLoc(),
+  diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+  

[PATCH] D149456: Basic documentation of -mrecip=... option

2023-04-29 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149456

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