[PATCH] D136572: Harmonize cmake_policy() across standalone builds of all projects

2022-10-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D136572#3890835 , @mgorny wrote:

> In D136572#3889317 , @mstorsjo 
> wrote:
>
>> Also for the record, I'd love to get rid of this symlink based setup, if I 
>> could make cmake produce project files where caching works in the same way. 
>> The main requirement for that would be to have the whole cmake build started 
>> from the toplevel llvm-project directory (so that all source from all 
>> subprojects are subdirectories to this), instead of the llvm-project/llvm 
>> directory.
>
> To be honest, I also find it weird to start monorepo builds from within 
> `llvm` subdirectory. Perhaps adding a top-level `CMakeLists.txt` that would 
> work and wouldn't break people's workflows wouldn't be that hard, though.

This has been discussed briefly before - the main issue is that LLVM does some 
cmake trickery to recreate the installed directory structure (with executables 
in `$(pwd)/bin` etc) directly in the build folder, and if `llvm-project/llvm` 
is included from a toplevel `llvm-project/CMakeLists.txt`, this all ends up in 
`$(pwd)/llvm/bin` as things stand right now. See e.g. 
https://discourse.llvm.org/t/rfc-llvm-build-system-future-direction/53430/18. 
Hopefully it wouldn't be too hard to resolve - I had a brief look at it (just 
creating a stub CMakeLists.txt at the root and including the llvm subdirectory) 
a couple years ago, but didn't spend further time on looking into how things 
are set up and what it would take to fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136572

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


[PATCH] D136886: [clang] [ASTImporter] RFC: Correct importer to not duplicate sugared types

2022-10-28 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

>   (gdb) p Decl->getUnderlyingType().dump()
>   ConstantArrayType 0x118ea470 'struct __va_list_tag[1]' 1 
>   `-RecordType 0x118ea2b0 'struct __va_list_tag'
> `-Record 0x118ea228 '__va_list_tag'
>   $2 = void
>   (gdb) p Underlying
>   $3 = {Value = {Value = 295046112}}
>   (gdb) p Underlying.dump()
>   ConstantArrayType 0x11960be0 'struct __va_list_tag[1]' 1 
>   `-RecordType 0x11960a20 'struct __va_list_tag'
> `-Record 0x119609a0 '__va_list_tag'

Is it possible that `__va_list_tag` is not imported correctly (duplicated), 
there should be only one instance of this record?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136886

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


[PATCH] D135930: [X86] Add AVX-NE-CONVERT instructions.

2022-10-28 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: llvm/test/CodeGen/X86/avxneconvert-intrinsics.ll:4
+; RUN: llc < %s -O0 -verify-machineinstrs -mtriple=i686-unknown-unknown 
--show-mc-encoding -mattr=+avxneconvert | FileCheck %s --check-prefixes=X86
+
+define <4 x float> @test_int_x86_vbcstnebf162ps128(i8* %A) {

Need to add `+avx512bf16,+avx512vl` tests for shared builtin intrinsic. I just 
found it crashed for lacking new patterns for avx512bf16. I'll update ASAP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135930

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


[PATCH] D136919: [X86][RFC] Change mangle name of __bf16 from u6__bf16 to DF16b

2022-10-28 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: RKSimon, ldionne, bkramer.
Herald added a project: All.
pengfei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC folks decided to make the mangling of __bf16 the same as std::bfloat16_t.
We need to match with GCC: https://godbolt.org/z/jjne5qxPa
Other targets may still use their own mangling way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136919

Files:
  clang/lib/Basic/Targets/X86.h
  clang/test/CodeGen/X86/bfloat-mangle.cpp


Index: clang/test/CodeGen/X86/bfloat-mangle.cpp
===
--- clang/test/CodeGen/X86/bfloat-mangle.cpp
+++ clang/test/CodeGen/X86/bfloat-mangle.cpp
@@ -3,6 +3,6 @@
 // RUN: %clang_cc1 -triple i386-windows-msvc -target-feature +sse2 -emit-llvm 
-o - %s | FileCheck %s --check-prefixes=WINDOWS
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -target-feature +sse2 
-emit-llvm -o - %s | FileCheck %s --check-prefixes=WINDOWS
 
-// LINUX: define {{.*}}void @_Z3foou6__bf16(bfloat noundef %b)
+// LINUX: define {{.*}}void @_Z3fooDF16b(bfloat noundef %b)
 // WINDOWS: define {{.*}}void @"?foo@@YAXU__bf16@__clang@@@Z"(bfloat noundef 
%b)
 void foo(__bf16 b) {}
Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -410,7 +410,7 @@
 return getPointerWidthV(AddrSpace);
   }
 
-  const char *getBFloat16Mangling() const override { return "u6__bf16"; };
+  const char *getBFloat16Mangling() const override { return "DF16b"; };
 };
 
 // X86-32 generic target


Index: clang/test/CodeGen/X86/bfloat-mangle.cpp
===
--- clang/test/CodeGen/X86/bfloat-mangle.cpp
+++ clang/test/CodeGen/X86/bfloat-mangle.cpp
@@ -3,6 +3,6 @@
 // RUN: %clang_cc1 -triple i386-windows-msvc -target-feature +sse2 -emit-llvm -o - %s | FileCheck %s --check-prefixes=WINDOWS
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -target-feature +sse2 -emit-llvm -o - %s | FileCheck %s --check-prefixes=WINDOWS
 
-// LINUX: define {{.*}}void @_Z3foou6__bf16(bfloat noundef %b)
+// LINUX: define {{.*}}void @_Z3fooDF16b(bfloat noundef %b)
 // WINDOWS: define {{.*}}void @"?foo@@YAXU__bf16@__clang@@@Z"(bfloat noundef %b)
 void foo(__bf16 b) {}
Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -410,7 +410,7 @@
 return getPointerWidthV(AddrSpace);
   }
 
-  const char *getBFloat16Mangling() const override { return "u6__bf16"; };
+  const char *getBFloat16Mangling() const override { return "DF16b"; };
 };
 
 // X86-32 generic target
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136920: [clang][Interp] Array initialization via CXXConstructExpr

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136920

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


Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -181,6 +181,18 @@
   }
 };
 
+class A {
+public:
+  int a;
+  constexpr A() : a(10) {}
+};
+class B {
+public:
+  A a[2];
+  constexpr B() {}
+};
+constexpr B b;
+
 namespace IncDec {
   // FIXME: Pointer arithmethic needs to be supported in inc/dec
   //   unary operators
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1007,6 +1007,30 @@
   assert(false && "default initializer for non-primitive type");
 }
 
+return true;
+  } else if (const auto *Ctor = dyn_cast(Initializer)) {
+const ArrayType *AT = Ctor->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();
+const Function *Func = getFunction(Ctor->getConstructor());
+if (!Func || !Func->isConstexpr())
+  return false;
+
+assert(Ctor->getNumArgs() == 0);
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitDupPtr(Initializer))
+return false;
+  if (!this->emitConstUint64(I, Initializer))
+return false;
+  if (!this->emitAddOffsetUint64(Initializer))
+return false;
+  if (!this->emitNarrowPtr(Initializer))
+return false;
+
+  // Actually call the constructor
+  if (!this->emitCall(Func, Ctor))
+return false;
+}
 return true;
   }
 


Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -181,6 +181,18 @@
   }
 };
 
+class A {
+public:
+  int a;
+  constexpr A() : a(10) {}
+};
+class B {
+public:
+  A a[2];
+  constexpr B() {}
+};
+constexpr B b;
+
 namespace IncDec {
   // FIXME: Pointer arithmethic needs to be supported in inc/dec
   //   unary operators
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1007,6 +1007,30 @@
   assert(false && "default initializer for non-primitive type");
 }
 
+return true;
+  } else if (const auto *Ctor = dyn_cast(Initializer)) {
+const ArrayType *AT = Ctor->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();
+const Function *Func = getFunction(Ctor->getConstructor());
+if (!Func || !Func->isConstexpr())
+  return false;
+
+assert(Ctor->getNumArgs() == 0);
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitDupPtr(Initializer))
+return false;
+  if (!this->emitConstUint64(I, Initializer))
+return false;
+  if (!this->emitAddOffsetUint64(Initializer))
+return false;
+  if (!this->emitNarrowPtr(Initializer))
+return false;
+
+  // Actually call the constructor
+  if (!this->emitCall(Func, Ctor))
+return false;
+}
 return true;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136090: Handle errors in expansion of response files

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



Comment at: clang/unittests/Driver/ToolChainTest.cpp:604-606
+  char *StrBuff = (char *)Alloc.Allocate(6, 2);
+  std::memcpy(StrBuff, "\xFF\xFE\x00\xD8\x00\x00", 6);
+  StringRef BadUTF(StrBuff, 6);

Wouldn't it be possible to use `std::string`, or maybe even `std::array` here? I think it'd be less error-prone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

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


[PATCH] D136846: [Driver] Add -fsample-profile-use-profi

2022-10-28 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1253
+Flags<[NoXarchOption, CC1Option]>, Group,
+HelpText<"Use profi to infer block and edge counts.">;
 def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">,

A user who reads the help message might reasonably ask "what's profi". Can you 
please add some documentation about it? It would also be nice with a DocBrief 
(see e.g. -fprofile-sample-accurate above).



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:5763
 
+  // Enable profi in frontend and forward to LLVM invocation
+  if (Args.hasArg(options::OPT_fsample_profile_use_profi)) {

Perhaps consider skipping this comment, the code is clear enough.



Comment at: clang/test/CodeGen/pgo-sample-use-profi.cpp:1
+//Test if profi flat is enabled in frontend as user-facing feature.
+//

HaoyuZhang wrote:
> MaskRay wrote:
> > Remove the test.
> > 
> > This change only needs a clang/test/Driver test showing that the option 
> > passes `-sample-profile-use-profi` to -cc1.
> Thank you for the comments. So we only need to RUN the command for example:
> 
> `//RUN: %clang_cc1 %s -fsample-profile-use-profi -fdebug-pass-manager 
> -emit-llvm -o - 2>&1 | FileCheck %s`
> 
> `//CHECK: Running pass: VerifierPass`
> 
> and without any test code.
> 
I think what MaskRay is saying is that you only need a test in 
clang/test/Driver/ that does "%clang -c -fsample-profile-use-profi -###" and 
FileCheck's that the cc1 invocation contains the right -mllvm flag.

(I assume you have tests for the actual functionality somewhere in llvm/test/)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136846

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


[PATCH] D136564: [clang] Instantiate NTTPs and template default arguments with sugar

2022-10-28 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D136564#3890676 , @rtrieu wrote:

> I noticed some build failures after your commit.  I'm trying to get a 
> standalone reproducer.

Here is the broken testcase:

  // -std=c++17
  #include 
  
  template 
  using FixedTypeT = Type;
  
  template 
  class T {
T(const FixedTypeT... names)
: names_(std::string(names)...) {}
std::string names_;
  };


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136564

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


[PATCH] D136925: [clangd] Index scoped enums for code completion

2022-10-28 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders created this revision.
tom-anders added a reviewer: nridge.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
tom-anders requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

As discussed in https://github.com/clangd/clangd/issues/1082:

"Without all-scopes-completion, such nested symbols would indeed be unnecessary 
in the
index, because the only way you could get them as a completion result is if 
you're
invoking the completion in the nested scope (e.g. Foo::^), in which case result 
can be
obtained from the AST."

I tested this on the LLVM codebase and there was no significant increase in 
index size
(less than 1MB). I think this makes sense if we look at the additional data 
that is stored
in SymbolCollector::addDeclaration when IndexedForCodeCompletion is set:

- Signature: Empty string for enum constants
- SnippetSuffix: Empty
- Documentation: Empty most of the time
- ReturnType and Type: Same string for all enum constants within a enum, so 
only two additional strings per indexed enum


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136925

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeComplete.h
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1316,6 +1316,11 @@
   Black
 };
 }
+class Color3 {
+  enum {
+Blue
+  };
+};
   )";
   runSymbolCollector(Header, /*Main=*/"");
   EXPECT_THAT(Symbols,
@@ -1324,7 +1329,9 @@
   AllOf(qName("Color"), forCodeCompletion(true)),
   AllOf(qName("Green"), forCodeCompletion(true)),
   AllOf(qName("Color2"), forCodeCompletion(true)),
-  AllOf(qName("Color2::Yellow"), forCodeCompletion(false)),
+  AllOf(qName("Color2::Yellow"), forCodeCompletion(true)),
+  AllOf(qName("Color3"), forCodeCompletion(true)),
+  AllOf(qName("Color3::Blue"), forCodeCompletion(true)),
   AllOf(qName("ns"), forCodeCompletion(true)),
   AllOf(qName("ns::Black"), forCodeCompletion(true;
 }
Index: clang-tools-extra/clangd/index/Serialization.cpp
===
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -455,7 +455,7 @@
 // The current versioning scheme is simple - non-current versions are rejected.
 // If you make a breaking change, bump this version number to invalidate stored
 // data. Later we may want to support some backward compatibility.
-constexpr static uint32_t Version = 17;
+constexpr static uint32_t Version = 18;
 
 llvm::Expected readRIFF(llvm::StringRef Data,
  SymbolOrigin Origin) {
Index: clang-tools-extra/clangd/CodeComplete.h
===
--- clang-tools-extra/clangd/CodeComplete.h
+++ clang-tools-extra/clangd/CodeComplete.h
@@ -291,7 +291,7 @@
 // For index-based completion, we only consider:
 //   * symbols in namespaces or translation unit scopes (e.g. no class
 // members, no locals)
-//   * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
+//   * enum constants (both scoped and unscoped)
 //   * primary templates (no specializations)
 // For the other cases, we let Clang do the completion because it does not
 // need any non-local information and it will be much better at following
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -2129,8 +2129,10 @@
   if (InTopLevelScope(ND))
 return true;
 
+  // Always index enum constants, even if they're not in the top level scope: 
when
+  // --all-scopes-completion is set, we'll want to complete those as well.
   if (const auto *EnumDecl = dyn_cast(ND.getDeclContext()))
-return InTopLevelScope(*EnumDecl) && !EnumDecl->isScoped();
+return true;
 
   return false;
 }


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1316,6 +1316,11 @@
   Black
 };
 }
+class Color3 {
+  enum {
+Blue
+  };
+};
   )";
   runSymbolCollector(Header, /*Main=*/"");
   EXPECT_THAT(Symbols,
@@ -1324,7 +1329,9 @@
 

[clang] beb9977 - [Clang] Improve diagnostic message for loop hint pragma

2022-10-28 Thread via cfe-commits

Author: eopXD
Date: 2022-10-28T01:51:24-07:00
New Revision: beb997799d823aece097494f156c6d277d26571c

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

LOG: [Clang] Improve diagnostic message for loop hint pragma

Originally the loop hint is not displayed correctly in the diagnostic.
This patch fixes it.

Reviewed By: Meinersbur

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

Added: 


Modified: 
clang/lib/Parse/ParsePragma.cpp
clang/test/Parser/pragma-loop.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 123d94ee703f1..cddc3780133b8 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1303,7 +1303,9 @@ struct PragmaLoopHintInfo {
 
 static std::string PragmaLoopHintString(Token PragmaName, Token Option) {
   StringRef Str = PragmaName.getIdentifierInfo()->getName();
-  std::string ClangLoopStr = (llvm::Twine("clang loop ") + Str).str();
+  std::string ClangLoopStr("clang loop ");
+  if (Str == "loop" && Option.getIdentifierInfo())
+ClangLoopStr += Option.getIdentifierInfo()->getName();
   return std::string(llvm::StringSwitch(Str)
  .Case("loop", ClangLoopStr)
  .Case("unroll_and_jam", Str)

diff  --git a/clang/test/Parser/pragma-loop.cpp 
b/clang/test/Parser/pragma-loop.cpp
index 750affbddf97e..0203e90104d4f 100644
--- a/clang/test/Parser/pragma-loop.cpp
+++ b/clang/test/Parser/pragma-loop.cpp
@@ -305,34 +305,34 @@ void foo(void) {
 void foo(int *List, int Length) {
   int i;
 #pragma clang loop vectorize(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize' - 
ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop interleave(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop interleave' - 
ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop unroll(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop unroll' - 
ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop vectorize_predicate(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop 
vectorize_predicate' - ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop pipeline(disable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop pipeline' - 
ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ #pragma clang loop vectorize_width(2, scalable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ #pragma clang loop interleave_count(2, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ #pragma clang loop unroll_count(2, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ #pragma clang loop pipeline_initiation_interval(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop 
vectorize_width' - ignored}}*/ #pragma clang loop vectorize_width(2, scalable, 
extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop 
interleave_count' - ignored}}*/ #pragma clang loop interleave_count(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop unroll_count' 
- ignored}}*/ #pragma clang loop unroll_count(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop 
pipeline_initiation_interval' - ignored}}*/ #pragma clang loop 
pipeline_initiation_interval(2, extra)
   while (i-6 < Length) {
 List[i] = i;
   }



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


[PATCH] D136784: [Clang] Improve diagnostic message for loop hint pragma

2022-10-28 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbeb997799d82: [Clang] Improve diagnostic message for loop 
hint pragma (authored by eopXD).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136784

Files:
  clang/lib/Parse/ParsePragma.cpp
  clang/test/Parser/pragma-loop.cpp


Index: clang/test/Parser/pragma-loop.cpp
===
--- clang/test/Parser/pragma-loop.cpp
+++ clang/test/Parser/pragma-loop.cpp
@@ -305,34 +305,34 @@
 void foo(int *List, int Length) {
   int i;
 #pragma clang loop vectorize(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize' - 
ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop interleave(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop interleave' - 
ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop unroll(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop unroll' - 
ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop vectorize_predicate(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop 
vectorize_predicate' - ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop pipeline(disable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop pipeline' - 
ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ #pragma clang loop vectorize_width(2, scalable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ #pragma clang loop interleave_count(2, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ #pragma clang loop unroll_count(2, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - 
ignored}}*/ #pragma clang loop pipeline_initiation_interval(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop 
vectorize_width' - ignored}}*/ #pragma clang loop vectorize_width(2, scalable, 
extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop 
interleave_count' - ignored}}*/ #pragma clang loop interleave_count(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop unroll_count' 
- ignored}}*/ #pragma clang loop unroll_count(2, extra)
+/* expected-warning {{extra tokens at end of '#pragma clang loop 
pipeline_initiation_interval' - ignored}}*/ #pragma clang loop 
pipeline_initiation_interval(2, extra)
   while (i-6 < Length) {
 List[i] = i;
   }
Index: clang/lib/Parse/ParsePragma.cpp
===
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -1303,7 +1303,9 @@
 
 static std::string PragmaLoopHintString(Token PragmaName, Token Option) {
   StringRef Str = PragmaName.getIdentifierInfo()->getName();
-  std::string ClangLoopStr = (llvm::Twine("clang loop ") + Str).str();
+  std::string ClangLoopStr("clang loop ");
+  if (Str == "loop" && Option.getIdentifierInfo())
+ClangLoopStr += Option.getIdentifierInfo()->getName();
   return std::string(llvm::StringSwitch(Str)
  .Case("loop", ClangLoopStr)
  .Case("unroll_and_jam", Str)


Index: clang/test/Parser/pragma-loop.cpp
===
--- clang/test/Parser/pragma-loop.cpp
+++ clang/test/Parser/pragma-loop.cpp
@@ -305,34 +305,34 @@
 void foo(int *List, int Length) {
   int i;
 #pragma clang loop vectorize(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop vectorize' - ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop interleave(enable, extra)
-/* expected-warning {{extra tokens at end of '#pragma clang loop loop' - ignored}}*/ while (i-6 < Length) {
+/* expected-warning {{extra tokens at end of '#pragma clang loop interleave' - ignored}}*/ while (i-6 < Length) {
 List[i] = i;
   }
 
 #pragma clang loop unroll(enable, extra)
-/* expected-warning {{extra tokens at en

[PATCH] D116735: [RISCV] Adjust RV64I data layout by using n32:64 in layout string

2022-10-28 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck accepted this revision.
frasercrmck added a comment.

LGTM other than a nit, but I concur that a comment in AutoUpgrade would be nice.




Comment at: llvm/docs/ReleaseNotes.rst:123
+* i32 is now a native type in the datalayout string. This enables
+  LoopStrengthReduce for loops with i32 induction variables. And other
+  optimizations.

something like `, among other optimizations` to avoid full stop + "and"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116735

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


[PATCH] D136710: [include-cleaner] Add the missing parts of Symbol and Header clases.

2022-10-28 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks, i agree with your comments around `std::variant`, let's see what kind 
of patterns will emerge in the future.

so, still LG, but please address the triple slash issue and const-ness before 
landing




Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:40
+  enum Kind {
+// A canonical clang declaration.
+Declaration,

triple slashes (here and elsewhere)



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h:60
+  // Order must match Kind enum!
+  std::variant Storage;
 };

sammccall wrote:
> kadircet wrote:
> > nit: any particular reason for dropping const here?
> Oh, the constructor was nonconst so I assumed const was an oversight. Changed 
> to const everywhere.
i guess you forgot to upload the diff? (the constructor was definitely an 
oversight, thanks for noticing that)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136710

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


[PATCH] D136930: [RISCV] Support -mcpu/mtune=native

2022-10-28 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead created this revision.
pcwang-thead added reviewers: kito-cheng, craig.topper, asb.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, frasercrmck, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, 
arichardson.
Herald added a project: All.
pcwang-thead requested review of this revision.
Herald added subscribers: cfe-commits, eopXD, MaskRay.
Herald added a project: clang.

We may need hosted Clang/LLVM to compile.

I don't know how to test it, but all that this patch rely on
is `getHostCpuName`, so pacthes like D123978  
may have covered it?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136930

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/Clang.cpp


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2187,7 +2187,10 @@
 
   if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
 CmdArgs.push_back("-tune-cpu");
-CmdArgs.push_back(A->getValue());
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
   }
 }
 
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -16,6 +16,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
@@ -70,8 +71,12 @@
 
   // If users give march and mcpu, get std extension feature from MArch
   // and other features (ex. mirco architecture feature) from mcpu
-  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
-getRISCFeaturesFromMcpu(D, Triple, Args, A, A->getValue(), Features);
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+StringRef CPU = A->getValue();
+if (CPU == "native")
+  CPU = llvm::sys::getHostCPUName();
+getRISCFeaturesFromMcpu(D, Triple, Args, A, CPU, Features);
+  }
 
   // Handle features corresponding to "-ffixed-X" options
   if (Args.hasArg(options::OPT_ffixed_x1))
@@ -260,7 +265,10 @@
 
   // 2. Get march (isa string) based on `-mcpu=`
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
-StringRef MArch = llvm::RISCV::getMArchFromMcpu(A->getValue());
+StringRef CPU = A->getValue();
+if (CPU == "native")
+  CPU = llvm::sys::getHostCPUName();
+StringRef MArch = llvm::RISCV::getMArchFromMcpu(CPU);
 // Bypass if target cpu's default march is empty.
 if (MArch != "")
   return MArch;


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2187,7 +2187,10 @@
 
   if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
 CmdArgs.push_back("-tune-cpu");
-CmdArgs.push_back(A->getValue());
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
   }
 }
 
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -16,6 +16,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/raw_ostream.h"
@@ -70,8 +71,12 @@
 
   // If users give march and mcpu, get std extension feature from MArch
   // and other features (ex. mirco architecture feature) from mcpu
-  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
-getRISCFeaturesFromMcpu(D, Triple, Args, A, A->getValue(), Features);
+  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
+StringRef CPU = A->getValue();
+if (CPU == "native")
+  CPU = llvm::sys::getHostCPUName();
+getRISCFeaturesFromMcpu(D, Triple, Args, A, CPU, Features);
+  }
 
   // Handle features corresponding to "-ffixed-X" options
   if (Args.hasArg(options::OPT_ffixed_x1))
@@ -260,7 +265,10 @@
 
   // 2. Get march (isa string) based on `-mcpu=`
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
-StringRef MArch = llvm::RISCV::getMArchFromMcpu(A->getValue());
+StringRef CPU = A->getValue();
+if (CPU == "native")
+  

[PATCH] D136385: Add support for MC/DC in LLVM Source-Based Code Coverage

2022-10-28 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

I've got about as far as the clang changes. As I mentioned in Discourse I'm not 
familiar enough in this area to give good feedback on the implementation, most 
if not all my comments fall under the bike shedding category. Will need to 
leave the high-level feedback to people that are more experienced in this area.

Thanks very much for uploading the design doc pdf, that was very useful. 
Although likely not for this patch as it is large enough already, will be worth 
updating https://llvm.org/docs/CoverageMappingFormat.html and 
https://clang.llvm.org/docs/SourceBasedCodeCoverage.html

I suspect that this patch will need to get split up into smaller parts. While 
it is very useful to see everything at once, it may be better to use this as a 
kind of support for the RFC, and then split off the implementation into smaller 
independently reviewable parts, even if the full functionality isn't useable 
until the last patch lands. For example the LLVM changes could be looked at and 
accepted prior to clang.

Will try and look and some more parts next week, my apologies I can't go 
through it all at once.




Comment at: clang/lib/CodeGen/CodeGenFunction.h:1522
+  /// Used by MC/DC to track the execution state of a boolean expression.
+  Address MCDCTempAddr = Address::invalid();
+

Would MCDCTrackingStateAddr be more appropriate? It could save people some time 
tracking back up to the comment to work out what Temp is being used for.



Comment at: clang/lib/CodeGen/CodeGenFunction.h:1542
 
+  bool isMCDCCoverageEnabled() {
+return (CGM.getCodeGenOpts().hasProfileClangInstr() &&

Can this be `bool isMCDCCoverageEnabled() const`



Comment at: clang/lib/CodeGen/CodeGenFunction.h:1554
+  MCDCTempAddr = CreateIRTemp(getContext().UnsignedIntTy, "mcdc.addr");
+  return;
+}

Is the return necessary here?



Comment at: clang/lib/CodeGen/CodeGenFunction.h:1558
+
+  bool isBinaryLogicalOp(const Expr *S) {
+const BinaryOperator *BOp = dyn_cast(S->IgnoreParens());

This looks like it doesn't need to be a member function? I can appreciate that 
here may be the most convenient place to  put it though.



Comment at: clang/lib/CodeGen/CodeGenPGO.cpp:164
+  /// The next bitmask byte index to assign.
+  unsigned NextBitmask;
+  /// The map of statements to bitmask coverage objects.

perhaps worth including index in the name, for example `NextBitmaskIdx` . Will 
help prevent confusion as to whether this is an index or an actual bitmask 
(comment does say, but harder to see from reading the code).



Comment at: clang/lib/CodeGen/CodeGenPGO.cpp:979
+  // set it to zero.
+  unsigned MCDCMaxConditions = 0;
+  if (CGM.getCodeGenOpts().MCDCCoverage)

`unsigned MCDCMaxConditions = (CGM.getCodeGenOpts().MCDCCoverage) ? 
CGM.getCodeGenOpts().MCDCMaxConditionCount : 0;`

Purely subjective opinion on my part though.



Comment at: clang/lib/CodeGen/CoverageMappingGen.cpp:102
 
+  unsigned Mask = 0;
+  unsigned Conditions = 0;

Worth a comment that these are associated with MCDC?



Comment at: clang/lib/CodeGen/CoverageMappingGen.cpp:662
+  /// Is this a logical-AND operation?
+  bool isLAnd(const BinaryOperator *E) { return E->getOpcode() == BO_LAnd; }
+

Could this be a free function? If not then could it be `const`? 



Comment at: clang/lib/CodeGen/CoverageMappingGen.cpp:718
+  void pushAndAssignIDs(const BinaryOperator *E) {
+if (CGM.getCodeGenOpts().MCDCCoverage) {
+  // If binary expression is disqualified, don't do mapping.

Would it be better to invert the condition and early exit? This would save a 
level of indentation for the rest of the function.



Comment at: clang/lib/CodeGen/CoverageMappingGen.cpp:759
+unsigned TotalConds = 0;
+if (CGM.getCodeGenOpts().MCDCCoverage) {
+  // Pop Stmt from 'NestLevel' stack.

Would it be better to invert the condition and early exit? This would save a 
level of indentation for the rest of the function.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:924
+   false)) {
+if (!CoverageMapping)
+  D.Diag(clang::diag::err_drv_argument_only_allowed_with)

Maybe able to simplify this to `if 
(Args.hasFlag(options::OPT_fcoverage_mapping)` and remove `CoverageMapping`. I 
think that in the case of `!ProfileGenerateArg` there are several options so it 
needed to be a variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136385

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

[clang] bf07c33 - Revert "[clang] Instantiate NTTPs and template default arguments with sugar"

2022-10-28 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-10-28T11:56:19+02:00
New Revision: bf07c338bb78c54b8d96fb42a75b168bf1550ad7

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

LOG: Revert "[clang] Instantiate NTTPs and template default arguments with 
sugar"

This patch reverts
- commit d4b1964f0554046b1e64908e5c1cd701b25f4c9e
- commit 59f0827e2cf3755834620e7e0b6d946832440f80([clang] Instantiate alias 
templates with sugar)

As it makes clang fail to pass some code it used to compile.
See comments: https://reviews.llvm.org/D136564#3891065

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.const/p3-0x.cpp
clang/test/CXX/temp/temp.deduct.guide/p3.cpp
clang/test/Misc/diag-template-diffing.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaTemplate/instantiation-default-1.cpp
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp

lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py

lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py

lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8bca0dc974539..9f64defaf898f 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1067,7 +1067,7 @@ class Foo final {})cpp";
  HI.LocalScope = "";
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "template  using AA = A";
- HI.Type = {"A", "T"};
+ HI.Type = {"A", "type-parameter-0-0"}; // FIXME: should be 'T'
  HI.TemplateParameters = {{{"typename"}, std::string("T"), 
llvm::None}};
}},
   {// Constant array

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b7a52aeea592c..b32dfe158c8f3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8199,11 +8199,14 @@ class Sema final {
 SourceLocation TemplateLoc,
 Declarator &D);
 
-  TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(
-  TemplateDecl *Template, SourceLocation TemplateLoc,
-  SourceLocation RAngleLoc, Decl *Param,
-  ArrayRef SugaredConverted,
-  ArrayRef CanonicalConverted, bool &HasDefaultArg);
+  TemplateArgumentLoc
+  SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
+  SourceLocation TemplateLoc,
+  SourceLocation RAngleLoc,
+  Decl *Param,
+  SmallVectorImpl
+&Converted,
+  bool &HasDefaultArg);
 
   /// Specifies the context in which a particular template
   /// argument is being checked.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 802c9574745f0..bf6acd52f2856 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3854,8 +3854,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 
 // Only substitute for the innermost template argument list.
 MultiLevelTemplateArgumentList TemplateArgLists;
-TemplateArgLists.addOuterTemplateArguments(Template, SugaredConverted,
-   /*Final=*/true);
+TemplateArgLists.addOuterTemplateArguments(Template, CanonicalConverted,
+   /*Final=*/false);
 TemplateArgLists.addOuterRetainedLevels(
 AliasTemplate->getTemplateParameters()->getDepth());
 
@@ -5261,25 +5261,27 @@ bool Sema::CheckTemplateTypeArgument(
 /// \param Converted the list of template arguments provided for template
 /// parameters that precede \p Param in the template parameter list.
 /// \returns the substituted template argument, or NULL if an error occurred.
-static TypeSourceInfo *SubstDefaultTemplateArgument(
-Sema &SemaRef, TemplateDecl *Template, SourceLocation TemplateLoc,
-SourceLocation RAngleLoc, TemplateTypeParmDecl *Param,
-ArrayRef SugaredConverted,
-ArrayRef CanonicalConverted) {
+static TypeSourceInfo *
+SubstDefaultTemplateArgument(Sema &SemaRef,
+ Templa

[clang-tools-extra] bf07c33 - Revert "[clang] Instantiate NTTPs and template default arguments with sugar"

2022-10-28 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-10-28T11:56:19+02:00
New Revision: bf07c338bb78c54b8d96fb42a75b168bf1550ad7

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

LOG: Revert "[clang] Instantiate NTTPs and template default arguments with 
sugar"

This patch reverts
- commit d4b1964f0554046b1e64908e5c1cd701b25f4c9e
- commit 59f0827e2cf3755834620e7e0b6d946832440f80([clang] Instantiate alias 
templates with sugar)

As it makes clang fail to pass some code it used to compile.
See comments: https://reviews.llvm.org/D136564#3891065

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/AST/ast-dump-template-decls.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.const/p3-0x.cpp
clang/test/CXX/temp/temp.deduct.guide/p3.cpp
clang/test/Misc/diag-template-diffing.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaTemplate/instantiation-default-1.cpp
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp

lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py

lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py

lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8bca0dc974539..9f64defaf898f 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1067,7 +1067,7 @@ class Foo final {})cpp";
  HI.LocalScope = "";
  HI.Kind = index::SymbolKind::TypeAlias;
  HI.Definition = "template  using AA = A";
- HI.Type = {"A", "T"};
+ HI.Type = {"A", "type-parameter-0-0"}; // FIXME: should be 'T'
  HI.TemplateParameters = {{{"typename"}, std::string("T"), 
llvm::None}};
}},
   {// Constant array

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b7a52aeea592c..b32dfe158c8f3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8199,11 +8199,14 @@ class Sema final {
 SourceLocation TemplateLoc,
 Declarator &D);
 
-  TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(
-  TemplateDecl *Template, SourceLocation TemplateLoc,
-  SourceLocation RAngleLoc, Decl *Param,
-  ArrayRef SugaredConverted,
-  ArrayRef CanonicalConverted, bool &HasDefaultArg);
+  TemplateArgumentLoc
+  SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template,
+  SourceLocation TemplateLoc,
+  SourceLocation RAngleLoc,
+  Decl *Param,
+  SmallVectorImpl
+&Converted,
+  bool &HasDefaultArg);
 
   /// Specifies the context in which a particular template
   /// argument is being checked.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 802c9574745f0..bf6acd52f2856 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3854,8 +3854,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 
 // Only substitute for the innermost template argument list.
 MultiLevelTemplateArgumentList TemplateArgLists;
-TemplateArgLists.addOuterTemplateArguments(Template, SugaredConverted,
-   /*Final=*/true);
+TemplateArgLists.addOuterTemplateArguments(Template, CanonicalConverted,
+   /*Final=*/false);
 TemplateArgLists.addOuterRetainedLevels(
 AliasTemplate->getTemplateParameters()->getDepth());
 
@@ -5261,25 +5261,27 @@ bool Sema::CheckTemplateTypeArgument(
 /// \param Converted the list of template arguments provided for template
 /// parameters that precede \p Param in the template parameter list.
 /// \returns the substituted template argument, or NULL if an error occurred.
-static TypeSourceInfo *SubstDefaultTemplateArgument(
-Sema &SemaRef, TemplateDecl *Template, SourceLocation TemplateLoc,
-SourceLocation RAngleLoc, TemplateTypeParmDecl *Param,
-ArrayRef SugaredConverted,
-ArrayRef CanonicalConverted) {
+static TypeSourceInfo *
+SubstDefaultTemplateArgument(Sema &SemaRef,
+ Templa

[PATCH] D136936: [clang][Interp] Handle undefined functions better

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

Make sure we add body-less functions to our program as well, and add the actual 
body later. We then need to compile functions again later once we have the 
definition with a body.

We do  a bunch of work in `ByteCodeEmitter::compileFunc()` to prepare the 
values passed to `Program::createFunction()` even if we don't need them now, 
that's a possible optimization for a later commit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136936

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/functions.cpp

Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -1,9 +1,6 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 
-// expected-no-diagnostics
-// ref-no-diagnostics
-
 constexpr void doNothing() {}
 constexpr int gimme5() {
   doNothing();
@@ -74,11 +71,16 @@
 static_assert(getNum<10>() == 10, "");
 static_assert(getNum() == 5, "");
 
-constexpr int f();
+constexpr int f(); // expected-note {{declared here}} \
+   // ref-note {{declared here}}
+static_assert(f() == 5, ""); // expected-error {{not an integral constant expression}} \
+ // expected-note {{undefined function 'f'}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{undefined function 'f'}}
 constexpr int a() {
   return f();
 }
 constexpr int f() {
   return 5;
 }
-static_assert(a() == 5);
+static_assert(a() == 5, "");
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -94,6 +94,7 @@
   /// Creates a new function from a code range.
   template 
   Function *createFunction(const FunctionDecl *Def, Ts &&... Args) {
+Def = Def->getCanonicalDecl();
 auto *Func = new Function(*this, Def, std::forward(Args)...);
 Funcs.insert({Def, std::unique_ptr(Func)});
 return Func;
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -207,7 +207,8 @@
 }
 
 Function *Program::getFunction(const FunctionDecl *F) {
-  F = F->getDefinition();
+  F = F->getCanonicalDecl();
+  assert(F);
   auto It = Funcs.find(F);
   return It == Funcs.end() ? nullptr : It->second.get();
 }
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -83,7 +83,7 @@
 bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
 
 /// Checks if a method can be called.
-bool CheckCallable(InterpState &S, CodePtr OpPC, Function *F);
+bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F);
 
 /// Checks the 'this' pointer.
 bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This);
@@ -1347,9 +1347,11 @@
 if (!CheckInvoke(S, PC, NewFrame->getThis())) {
   return false;
 }
-// TODO: CheckCallable
   }
 
+  if (!CheckCallable(S, PC, Func))
+return false;
+
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -338,17 +338,18 @@
   return true;
 }
 
-bool CheckCallable(InterpState &S, CodePtr OpPC, Function *F) {
-  const SourceLocation &Loc = S.Current->getLocation(OpPC);
+bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
 
   if (F->isVirtual()) {
 if (!S.getLangOpts().CPlusPlus20) {
+  const SourceLocation &Loc = S.Current->getLocation(OpPC);
   S.CCEDiag(Loc, diag::note_constexpr_virtual_call);
   return false;
 }
   }
 
   if (!F->isConstexpr()) {
+const SourceLocation &Loc = S.Current->getLocation(OpPC);
 if (S.getLangOpts().CPlusPlus11) {
   const FunctionDecl *DiagDecl = F->getDecl();
 
Index: clang/lib/AST/Interp/Context.cpp
===
--- clang/lib/AST/Interp/Context.cpp
+++ clang/lib/AST/Interp/Context.cpp
@@ -29,7 +29,7 @@
 bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
   assert(Stk.empty());
   Function *

[PATCH] D136090: Handle errors in expansion of response files

2022-10-28 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/unittests/Driver/ToolChainTest.cpp:604-606
+  char *StrBuff = (char *)Alloc.Allocate(6, 2);
+  std::memcpy(StrBuff, "\xFF\xFE\x00\xD8\x00\x00", 6);
+  StringRef BadUTF(StrBuff, 6);

mgorny wrote:
> Wouldn't it be possible to use `std::string`, or maybe even `std::array ...>` here? I think it'd be less error-prone.
Nor `std::string` neither `std::array` provide custom alignment.

UTF-16 string is constructed here from array of chars to avoid problems with 
endianness. It consists of 2-byte elements and is expected to be aligned on 
2-byte boundary. Array of chars is aligned on byte and sometimes the test 
failed due to invalid alignment.

So we have to use bare pointer to have guaranteed alignment.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

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


[clang] 6e7f421 - [clang][Interp][NFC] Fix a file header comment

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T12:49:38+02:00
New Revision: 6e7f421e5574b5669153a73ac0f1879098d2dd0e

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

LOG: [clang][Interp][NFC] Fix a file header comment

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index e9bda12a9d0b..a5984a21efb1 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -1,4 +1,4 @@
-//===--- InterpState.cpp - Interpreter for the constexpr VM -*- C++ 
-*-===//
+//===--- Interpcpp - Interpreter for the constexpr VM --*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.



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


[clang] b61e8c5 - [clang][Interp][NFC] Add Record::getName()

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T12:49:34+02:00
New Revision: b61e8c517eff2083252b1b74544bc25f7ad5a368

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

LOG: [clang][Interp][NFC] Add Record::getName()

Useful for debugging.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Record.h b/clang/lib/AST/Interp/Record.h
index 7743ad8dbb6fd..38920f75fe120 100644
--- a/clang/lib/AST/Interp/Record.h
+++ b/clang/lib/AST/Interp/Record.h
@@ -48,6 +48,8 @@ class Record final {
 public:
   /// Returns the underlying declaration.
   const RecordDecl *getDecl() const { return Decl; }
+  /// Returns the name of the underlying declaration.
+  const std::string getName() const { return Decl->getNameAsString(); }
   /// Checks if the record is a union.
   bool isUnion() const { return getDecl()->isUnion(); }
   /// Returns the size of the record.



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


[clang] c1dd7f9 - [clang][Interp][NFC] Print more info in Program::dump()

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T12:49:38+02:00
New Revision: c1dd7f90132a8a767d91f9b2b3e2bf1a9d7aa04f

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

LOG: [clang][Interp][NFC] Print more info in Program::dump()

Number of functions and global variables is useful to know.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 9fc22f2b6ea0..db68887f0558 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -72,6 +72,10 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) 
const {
 LLVM_DUMP_METHOD void Program::dump() const { dump(llvm::errs()); }
 
 LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
+  OS << ":: Program\n";
+  OS << "Global Variables: " << Globals.size() << "\n";
+  OS << "Functions: " << Funcs.size() << "\n";
+  OS << "\n";
   for (auto &Func : Funcs) {
 Func.second->dump();
   }



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


[clang] 0ad3ad6 - [clang][Interp][NFC] Remove leftover comment fragment

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T12:49:38+02:00
New Revision: 0ad3ad6bc7e1629703d931222514b2a97e885cb9

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

LOG: [clang][Interp][NFC] Remove leftover comment fragment

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Record.h b/clang/lib/AST/Interp/Record.h
index 38920f75fe12..f638ae90a1c4 100644
--- a/clang/lib/AST/Interp/Record.h
+++ b/clang/lib/AST/Interp/Record.h
@@ -112,7 +112,6 @@ class Record final {
   llvm::DenseMap FieldMap;
   /// Mapping from declarations to virtual bases.
   llvm::DenseMap VirtualBaseMap;
-  /// Mapping from
   /// Size of the structure.
   unsigned BaseSize;
   /// Size of all virtual bases.



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


[clang] 6fa1795 - [clang][Interp] Implement String- and CharacterLiterals

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T12:49:38+02:00
New Revision: 6fa1795d1fd4770f9f5c00f5a30937d68c3feb17

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

LOG: [clang][Interp] Implement String- and CharacterLiterals

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp
clang/test/Lexer/char-escapes.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 9472f1aed9178..7e00fc4f707e9 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -397,6 +397,18 @@ bool 
ByteCodeExprGen::VisitAbstractConditionalOperator(
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitStringLiteral(const StringLiteral *E) {
+  unsigned StringIndex = P.createGlobalString(E);
+  return this->emitGetPtrGlobal(StringIndex, E);
+}
+
+template 
+bool ByteCodeExprGen::VisitCharacterLiteral(
+const CharacterLiteral *E) {
+  return this->emitConst(E, E->getValue());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index a254a1baee8f9..1759d17d3288f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -83,6 +83,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
   bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
+  bool VisitStringLiteral(const StringLiteral *E);
+  bool VisitCharacterLiteral(const CharacterLiteral *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index f0083e63f35d9..ca76be9b0bf94 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -278,3 +278,46 @@ namespace bitOr {
   static_assert((0 | gimme(12)) == 12, "");
   static_assert((12 | true) == 13, "");
 };
+
+namespace strings {
+  constexpr const char *S = "abc";
+  static_assert(S[0] == 97, "");
+  static_assert(S[1] == 98, "");
+  static_assert(S[2] == 99, "");
+  static_assert(S[3] == 0, "");
+
+  static_assert("foobar"[2] == 'o', "");
+  static_assert(2["foobar"] == 'o', "");
+
+  constexpr const wchar_t *wide = L"bar";
+  static_assert(wide[0] == L'b', "");
+
+  constexpr const char32_t *u32 = U"abc";
+  static_assert(u32[1] == U'b', "");
+
+  constexpr char32_t c = U'\U0001F60E';
+  static_assert(c == 0x0001F60EL, "");
+
+  constexpr char k = -1;
+  static_assert(k == -1, "");
+
+  static_assert('\N{LATIN CAPITAL LETTER E}' == 'E', "");
+  static_assert('\t' == 9, "");
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+  constexpr int mc = 'abc';
+  static_assert(mc == 'abc', "");
+  __WCHAR_TYPE__ wm = L'abc'; // ref-error{{wide character literals may not 
contain multiple characters}} \
+  // expected-error{{wide character literals may 
not contain multiple characters}}
+  __WCHAR_TYPE__ wu = u'abc'; // ref-error{{Unicode character literals may not 
contain multiple characters}} \
+  // expected-error{{Unicode character literals 
may not contain multiple characters}}
+  __WCHAR_TYPE__ wU = U'abc'; // ref-error{{Unicode character literals may not 
contain multiple characters}} \
+  // expected-error{{Unicode character literals 
may not contain multiple characters}}
+#if __cplusplus > 201103L
+  __WCHAR_TYPE__ wu8 = u8'abc'; // ref-error{{Unicode character literals may 
not contain multiple characters}} \
+// expected-error{{Unicode character literals 
may not contain multiple characters}}
+#endif
+
+#pragma clang diagnostic pop
+};

diff  --git a/clang/test/Lexer/char-escapes.c b/clang/test/Lexer/char-escapes.c
index 32a1c6140d53c..11e25a6d251fe 100644
--- a/clang/test/Lexer/char-escapes.c
+++ b/clang/test/Lexer/char-escapes.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+// RUN: %clang_cc1 -fsyntax-only -pedantic 
-fexperimental-new-constant-interpreter -verify %s
 
 int test['\\' == 92 ? 1 : -1];
 int test['\"' == 34 ? 1 : -1];



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


[clang] 7f3013c - [clang][Interp][NFC] Fix instance method check

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T12:49:38+02:00
New Revision: 7f3013c5f9767c3dabd41d4219893e3154b126ea

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

LOG: [clang][Interp][NFC] Fix instance method check

This was a change suggested by Aaron that I forgot to commit.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 13284703bba1..5bd6d51e78ab 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -44,10 +44,10 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
 
   // If the function decl is a member decl, the next parameter is
   // the 'this' pointer. This parameter is pop()ed from the
-  // InterStack when calling the function.
+  // InterpStack when calling the function.
   bool HasThisPointer = false;
   if (const auto *MD = dyn_cast(FuncDecl);
-  MD && !MD->isStatic()) {
+  MD && MD->isInstance()) {
 HasThisPointer = true;
 ParamTypes.push_back(PT_Ptr);
 ParamOffset += align(primSize(PT_Ptr));



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


[PATCH] D135366: [clang][Interp] Implement String- and CharacterLiterals

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6fa1795d1fd4: [clang][Interp] Implement String- and 
CharacterLiterals (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135366

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp
  clang/test/Lexer/char-escapes.c


Index: clang/test/Lexer/char-escapes.c
===
--- clang/test/Lexer/char-escapes.c
+++ clang/test/Lexer/char-escapes.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+// RUN: %clang_cc1 -fsyntax-only -pedantic 
-fexperimental-new-constant-interpreter -verify %s
 
 int test['\\' == 92 ? 1 : -1];
 int test['\"' == 34 ? 1 : -1];
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -278,3 +278,46 @@
   static_assert((0 | gimme(12)) == 12, "");
   static_assert((12 | true) == 13, "");
 };
+
+namespace strings {
+  constexpr const char *S = "abc";
+  static_assert(S[0] == 97, "");
+  static_assert(S[1] == 98, "");
+  static_assert(S[2] == 99, "");
+  static_assert(S[3] == 0, "");
+
+  static_assert("foobar"[2] == 'o', "");
+  static_assert(2["foobar"] == 'o', "");
+
+  constexpr const wchar_t *wide = L"bar";
+  static_assert(wide[0] == L'b', "");
+
+  constexpr const char32_t *u32 = U"abc";
+  static_assert(u32[1] == U'b', "");
+
+  constexpr char32_t c = U'\U0001F60E';
+  static_assert(c == 0x0001F60EL, "");
+
+  constexpr char k = -1;
+  static_assert(k == -1, "");
+
+  static_assert('\N{LATIN CAPITAL LETTER E}' == 'E', "");
+  static_assert('\t' == 9, "");
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+  constexpr int mc = 'abc';
+  static_assert(mc == 'abc', "");
+  __WCHAR_TYPE__ wm = L'abc'; // ref-error{{wide character literals may not 
contain multiple characters}} \
+  // expected-error{{wide character literals may 
not contain multiple characters}}
+  __WCHAR_TYPE__ wu = u'abc'; // ref-error{{Unicode character literals may not 
contain multiple characters}} \
+  // expected-error{{Unicode character literals 
may not contain multiple characters}}
+  __WCHAR_TYPE__ wU = U'abc'; // ref-error{{Unicode character literals may not 
contain multiple characters}} \
+  // expected-error{{Unicode character literals 
may not contain multiple characters}}
+#if __cplusplus > 201103L
+  __WCHAR_TYPE__ wu8 = u8'abc'; // ref-error{{Unicode character literals may 
not contain multiple characters}} \
+// expected-error{{Unicode character literals 
may not contain multiple characters}}
+#endif
+
+#pragma clang diagnostic pop
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -83,6 +83,8 @@
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
   bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
+  bool VisitStringLiteral(const StringLiteral *E);
+  bool VisitCharacterLiteral(const CharacterLiteral *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -397,6 +397,18 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitStringLiteral(const StringLiteral *E) {
+  unsigned StringIndex = P.createGlobalString(E);
+  return this->emitGetPtrGlobal(StringIndex, E);
+}
+
+template 
+bool ByteCodeExprGen::VisitCharacterLiteral(
+const CharacterLiteral *E) {
+  return this->emitConst(E, E->getValue());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);


Index: clang/test/Lexer/char-escapes.c
===
--- clang/test/Lexer/char-escapes.c
+++ clang/test/Lexer/char-escapes.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+// RUN: %clang_cc1 -fsyntax-only -pedantic -fexperimental-new-constant-interpreter -verify %s
 
 int test['\\' == 92 ? 1 : -1];
 int test['\"' == 34 ? 1 : -1];
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -278,3 +278,46 @@
   static_assert((0 | gimme(12)) == 12, "");
   static_assert((1

[PATCH] D135366: [clang][Interp] Implement String- and CharacterLiterals

2022-10-28 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

One of your commits doesn't build on windows with clang-cl as host compiler: 
http://45.33.8.238/win/68965/step_4.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135366

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


[PATCH] D136940: [clang][Driver] allow tilde in user config dir

2022-10-28 Thread LJC via Phabricator via cfe-commits
paperchalice created this revision.
paperchalice added a reviewer: MaskRay.
paperchalice added a project: clang.
Herald added a subscriber: StephenFan.
Herald added a project: All.
paperchalice requested review of this revision.
Herald added a subscriber: cfe-commits.

This patch allows users to configure clang with option e.g. 
`-DCLANG_CONFIG_FILE_USER_DIR=~/.config/clang` or invoke clang with 
`--config-user-dir=~/.config/clang`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136940

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -219,7 +219,11 @@
   SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
 #endif
 #if defined(CLANG_CONFIG_FILE_USER_DIR)
-  UserConfigDir = CLANG_CONFIG_FILE_USER_DIR;
+  {
+SmallString<128> P;
+llvm::sys::fs::expand_tilde(CLANG_CONFIG_FILE_USER_DIR, P);
+UserConfigDir = static_cast(P);
+  }
 #endif
 
   // Compute the path to the resource directory.
@@ -979,8 +983,8 @@
 }
 if (CLOptions->hasArg(options::OPT_config_user_dir_EQ)) {
   SmallString<128> CfgDir;
-  CfgDir.append(
-  CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ));
+  llvm::sys::fs::expand_tilde(
+  CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ), CfgDir);
   if (!CfgDir.empty()) {
 if (llvm::sys::fs::make_absolute(CfgDir).value() != 0)
   UserConfigDir.clear();


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -219,7 +219,11 @@
   SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
 #endif
 #if defined(CLANG_CONFIG_FILE_USER_DIR)
-  UserConfigDir = CLANG_CONFIG_FILE_USER_DIR;
+  {
+SmallString<128> P;
+llvm::sys::fs::expand_tilde(CLANG_CONFIG_FILE_USER_DIR, P);
+UserConfigDir = static_cast(P);
+  }
 #endif
 
   // Compute the path to the resource directory.
@@ -979,8 +983,8 @@
 }
 if (CLOptions->hasArg(options::OPT_config_user_dir_EQ)) {
   SmallString<128> CfgDir;
-  CfgDir.append(
-  CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ));
+  llvm::sys::fs::expand_tilde(
+  CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ), CfgDir);
   if (!CfgDir.empty()) {
 if (llvm::sys::fs::make_absolute(CfgDir).value() != 0)
   UserConfigDir.clear();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 63e3fe1 - Revert "[clang][Interp] Implement String- and CharacterLiterals"

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T13:34:37+02:00
New Revision: 63e3fe10882476696d8a05907dfe627bd61638a3

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

LOG: Revert "[clang][Interp] Implement String- and CharacterLiterals"

This reverts commit 6fa1795d1fd4770f9f5c00f5a30937d68c3feb17.

This breaks a windows builder:

../../clang/lib/AST/Interp/ByteCodeExprGen.h(236,11): error: call to 
constructor of 'clang::interp::APInt' (aka 'llvm::APInt') is ambiguous
APInt WrappedValue(getIntWidth(Ty), Value, std::is_signed::value);
  ^
../../clang/lib/AST/Interp/ByteCodeExprGen.cpp(409,16): note: in instantiation 
of function template specialization 
'clang::interp::ByteCodeExprGen::emitConst' requested here
  return this->emitConst(E, E->getValue());
   ^
../../clang/lib/AST/Interp/ByteCodeExprGen.cpp(1149,16): note: in instantiation 
of member function 
'clang::interp::ByteCodeExprGen::VisitCharacterLiteral'
 requested here
template class ByteCodeExprGen;
   ^
../../llvm/include\llvm/ADT/APInt.h(108,3): note: candidate constructor
  APInt(unsigned numBits, uint64_t val, bool isSigned = false)
  ^
../../llvm/include\llvm/ADT/APInt.h(134,3): note: candidate constructor
  APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
  ^

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp
clang/test/Lexer/char-escapes.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 7e00fc4f707e9..9472f1aed9178 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -397,18 +397,6 @@ bool 
ByteCodeExprGen::VisitAbstractConditionalOperator(
   return true;
 }
 
-template 
-bool ByteCodeExprGen::VisitStringLiteral(const StringLiteral *E) {
-  unsigned StringIndex = P.createGlobalString(E);
-  return this->emitGetPtrGlobal(StringIndex, E);
-}
-
-template 
-bool ByteCodeExprGen::VisitCharacterLiteral(
-const CharacterLiteral *E) {
-  return this->emitConst(E, E->getValue());
-}
-
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 1759d17d3288f..a254a1baee8f9 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -83,8 +83,6 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
   bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
-  bool VisitStringLiteral(const StringLiteral *E);
-  bool VisitCharacterLiteral(const CharacterLiteral *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index ca76be9b0bf94..f0083e63f35d9 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -278,46 +278,3 @@ namespace bitOr {
   static_assert((0 | gimme(12)) == 12, "");
   static_assert((12 | true) == 13, "");
 };
-
-namespace strings {
-  constexpr const char *S = "abc";
-  static_assert(S[0] == 97, "");
-  static_assert(S[1] == 98, "");
-  static_assert(S[2] == 99, "");
-  static_assert(S[3] == 0, "");
-
-  static_assert("foobar"[2] == 'o', "");
-  static_assert(2["foobar"] == 'o', "");
-
-  constexpr const wchar_t *wide = L"bar";
-  static_assert(wide[0] == L'b', "");
-
-  constexpr const char32_t *u32 = U"abc";
-  static_assert(u32[1] == U'b', "");
-
-  constexpr char32_t c = U'\U0001F60E';
-  static_assert(c == 0x0001F60EL, "");
-
-  constexpr char k = -1;
-  static_assert(k == -1, "");
-
-  static_assert('\N{LATIN CAPITAL LETTER E}' == 'E', "");
-  static_assert('\t' == 9, "");
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wmultichar"
-  constexpr int mc = 'abc';
-  static_assert(mc == 'abc', "");
-  __WCHAR_TYPE__ wm = L'abc'; // ref-error{{wide character literals may not 
contain multiple characters}} \
-  // expected-error{{wide character literals may 
not contain multiple characters}}
-  __WCHAR_TYPE__ wu = u'abc'; // ref-error{{Unicode character literals may not 
contain multiple characters}} \
-  // expected-error{{Unicode character literals 
may not contain multiple characters}}
-  __WCHAR_TYPE__ wU = U'abc'; // ref-error{{Unicode character literals may not 
contain multiple characters}} \
-

[PATCH] D136603: [analyzer] Model cast after LValueToRValueBitCasts

2022-10-28 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D136603#3888065 , @steakhal wrote:

> Previously, even in the `RegionStoreManager::getBinding()` even if `T` was 
> non-null, we replaced it with `TVR->getValueType()` in case the `MR` was 
> `TypedValueRegion`.

Yeah, that means, we actually evaded a cast, am I right?

> IMO we shouldn't overwrite the type unless we actually need to auto-detect 
> the binding type.

I agree.

> This was particularly wrong when we reinterpret-cast some typed memory region 
> (such as a stack-local variable's address) to something else while operating 
> on the store.

You mean like when we loaded a value of reinterprec-cast(t2) with 
`evalLoad`?

> I haven't done any measurements yet, but I'm still curious about what you 
> think about this.

I think this is a good approach and the change is at the right place. But, any 
change that relates to casts are very fragile unfortunately. So, I agree, it 
would be great to see measurements and that we don't have new assertion 
failures.




Comment at: clang/test/Analysis/svalbuilder-float-cast.c:18-19
   *p += 1;
   // This should NOT be (float)$x + 1. Symbol $x was never casted to float.
-  // FIXME: Ideally, this should be $x + 1.
-  clang_analyzer_express(*p); // expected-warning{{Not a symbol}}
+  clang_analyzer_express(*p); // expected-warning{{$x + 1}}
 }

I think it would make sense to have another RUN line with 
`support-symbolic-integer-casts`.  In that case I guess we should see 
`(int)(float)x` (?).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136603

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


[PATCH] D136940: [clang][Driver] allow tilde in user config dir

2022-10-28 Thread LJC via Phabricator via cfe-commits
paperchalice updated this revision to Diff 471494.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136940

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -220,7 +220,11 @@
   SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
 #endif
 #if defined(CLANG_CONFIG_FILE_USER_DIR)
-  UserConfigDir = CLANG_CONFIG_FILE_USER_DIR;
+  {
+SmallString<128> P;
+llvm::sys::fs::expand_tilde(CLANG_CONFIG_FILE_USER_DIR, P);
+UserConfigDir = static_cast(P);
+  }
 #endif
 
   // Compute the path to the resource directory.
@@ -999,8 +1003,8 @@
 }
 if (CLOptions->hasArg(options::OPT_config_user_dir_EQ)) {
   SmallString<128> CfgDir;
-  CfgDir.append(
-  CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ));
+  llvm::sys::fs::expand_tilde(
+  CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ), CfgDir);
   if (CfgDir.empty() || getVFS().makeAbsolute(CfgDir))
 UserConfigDir.clear();
   else


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -220,7 +220,11 @@
   SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
 #endif
 #if defined(CLANG_CONFIG_FILE_USER_DIR)
-  UserConfigDir = CLANG_CONFIG_FILE_USER_DIR;
+  {
+SmallString<128> P;
+llvm::sys::fs::expand_tilde(CLANG_CONFIG_FILE_USER_DIR, P);
+UserConfigDir = static_cast(P);
+  }
 #endif
 
   // Compute the path to the resource directory.
@@ -999,8 +1003,8 @@
 }
 if (CLOptions->hasArg(options::OPT_config_user_dir_EQ)) {
   SmallString<128> CfgDir;
-  CfgDir.append(
-  CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ));
+  llvm::sys::fs::expand_tilde(
+  CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ), CfgDir);
   if (CfgDir.empty() || getVFS().makeAbsolute(CfgDir))
 UserConfigDir.clear();
   else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136941: [clang][Interp] Implement String-and CharacterLiterals

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Including a fix for the ambiguous APInt constructor.

Precommit CI should work on this now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136941

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp
  clang/test/Lexer/char-escapes.c

Index: clang/test/Lexer/char-escapes.c
===
--- clang/test/Lexer/char-escapes.c
+++ clang/test/Lexer/char-escapes.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+// RUN: %clang_cc1 -fsyntax-only -pedantic -fexperimental-new-constant-interpreter -verify %s
 
 int test['\\' == 92 ? 1 : -1];
 int test['\"' == 34 ? 1 : -1];
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -278,3 +278,46 @@
   static_assert((0 | gimme(12)) == 12, "");
   static_assert((12 | true) == 13, "");
 };
+
+namespace strings {
+  constexpr const char *S = "abc";
+  static_assert(S[0] == 97, "");
+  static_assert(S[1] == 98, "");
+  static_assert(S[2] == 99, "");
+  static_assert(S[3] == 0, "");
+
+  static_assert("foobar"[2] == 'o', "");
+  static_assert(2["foobar"] == 'o', "");
+
+  constexpr const wchar_t *wide = L"bar";
+  static_assert(wide[0] == L'b', "");
+
+  constexpr const char32_t *u32 = U"abc";
+  static_assert(u32[1] == U'b', "");
+
+  constexpr char32_t c = U'\U0001F60E';
+  static_assert(c == 0x0001F60EL, "");
+
+  constexpr char k = -1;
+  static_assert(k == -1, "");
+
+  static_assert('\N{LATIN CAPITAL LETTER E}' == 'E', "");
+  static_assert('\t' == 9, "");
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+  constexpr int mc = 'abc';
+  static_assert(mc == 'abc', "");
+  __WCHAR_TYPE__ wm = L'abc'; // ref-error{{wide character literals may not contain multiple characters}} \
+  // expected-error{{wide character literals may not contain multiple characters}}
+  __WCHAR_TYPE__ wu = u'abc'; // ref-error{{Unicode character literals may not contain multiple characters}} \
+  // expected-error{{Unicode character literals may not contain multiple characters}}
+  __WCHAR_TYPE__ wU = U'abc'; // ref-error{{Unicode character literals may not contain multiple characters}} \
+  // expected-error{{Unicode character literals may not contain multiple characters}}
+#if __cplusplus > 201103L
+  __WCHAR_TYPE__ wu8 = u8'abc'; // ref-error{{Unicode character literals may not contain multiple characters}} \
+// expected-error{{Unicode character literals may not contain multiple characters}}
+#endif
+
+#pragma clang diagnostic pop
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -83,6 +83,8 @@
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
   bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
+  bool VisitStringLiteral(const StringLiteral *E);
+  bool VisitCharacterLiteral(const CharacterLiteral *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -231,7 +233,7 @@
   /// Emits an integer constant.
   template  bool emitConst(const Expr *E, T Value) {
 QualType Ty = E->getType();
-APInt WrappedValue(getIntWidth(Ty), Value, std::is_signed::value);
+APInt WrappedValue(getIntWidth(Ty), static_cast(Value), std::is_signed::value);
 return emitConst(*Ctx.classify(Ty), WrappedValue, E);
   }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -397,6 +397,18 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitStringLiteral(const StringLiteral *E) {
+  unsigned StringIndex = P.createGlobalString(E);
+  return this->emitGetPtrGlobal(StringIndex, E);
+}
+
+template 
+bool ByteCodeExprGen::VisitCharacterLiteral(
+const CharacterLiteral *E) {
+  return this->emitConst(E, E->getValue());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136942: [C2x] Add test coverage for WG14 N2322

2022-10-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: clang-language-wg, erichkeane, jyknight.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

The changes in this paper add a new recommended practice. I had originally 
marked Clang as supporting this paper because we're not obligated to follow a 
recommended practice. However, in retrospect, it seems more useful to document 
whether we implement the recommendation or not. This adds a test for those 
changes. However, the recommended practice is just tricky enough to test, I 
wanted a second set of eyes on my test coverage to see if there's agreement I'm 
testing the right things and have come to the right conclusion.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136942

Files:
  clang/test/C/C2x/n2322.c
  clang/www/c_status.html


Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -696,7 +696,15 @@
 
   Preprocessor line numbers unspecified
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2322.htm";>N2322
-  Yes
+  
+Partial
+The line number associated with a macro invocation is not the line
+number of the first character of the macro name in the invocation.
+Additionally, Clang may not associate the line number of a pp-directive
+with the first # token. As these are recommended practices
+and not normative requirements, Clang's behavior is still conforming.
+
+  
 
 
   deprecated attribute
Index: clang/test/C/C2x/n2322.c
===
--- /dev/null
+++ clang/test/C/C2x/n2322.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -std=c2x -ast-dump %s | FileCheck %s
+
+/* WG14 N2322: partial
+ * Preprocessor line numbers unspecified
+ */
+void n2322() {
+  // The line number associated with a pp-token should be the line number of
+  // the first character of the pp-token.
+  "this string literal  \
+   spans multiple lines \
+   before terminating";
+// CHECK: ImplicitCastExpr {{.*}} 
+
+  // The line number associated with a pp-directive should be the line number
+  // of the line with the first # token.
+  // Possible FIXME: The AST node should be on line 1002 if we take the line
+  // number to be associated with the first # token. However, this relies on an
+  // interpretation of the standard definition of "presumed line" to be before
+  // line splices are removed. The standard leaves this unspecified, so this
+  // may not represent an actual issue.
+  #\
+  line\
+  1000
+  "string literal";
+// CHECK: ImplicitCastExpr {{.*}} 
+
+  // The line number associated with a macro invocation should be the line
+  // number of the first character of the macro name in the invocation.
+  //
+  // Reset the line number to make it easier to understand the next test.
+  // FIXME: The line number should be 2005 (first letter of the macro name) and
+  // not 2007 (closing parenthesis of the macro invocation).
+  #line 2000
+  #define F( \
+)\
+_\
+_LINE__
+
+  _Static_assert(F(\
+  \
+  ) == 2007);
+}
+


Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -696,7 +696,15 @@
 
   Preprocessor line numbers unspecified
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2322.htm";>N2322
-  Yes
+  
+Partial
+The line number associated with a macro invocation is not the line
+number of the first character of the macro name in the invocation.
+Additionally, Clang may not associate the line number of a pp-directive
+with the first # token. As these are recommended practices
+and not normative requirements, Clang's behavior is still conforming.
+
+  
 
 
   deprecated attribute
Index: clang/test/C/C2x/n2322.c
===
--- /dev/null
+++ clang/test/C/C2x/n2322.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -std=c2x -ast-dump %s | FileCheck %s
+
+/* WG14 N2322: partial
+ * Preprocessor line numbers unspecified
+ */
+void n2322() {
+  // The line number associated with a pp-token should be the line number of
+  // the first character of the pp-token.
+  "this string literal  \
+   spans multiple lines \
+   before terminating";
+// CHECK: ImplicitCastExpr {{.*}} 
+
+  // The line number associated with a pp-directive should be the line number
+  // of the line with the first # token.
+  // Possible FIXME: The AST node should be on line 1002 if we take the line
+  // number to be associated with the first # token. However, this relies on an
+  // interpretation of the standard definition of "presumed line" to be before
+  // line splices are removed. The standard leaves this unspecified

[PATCH] D136567: [clangd] Avoid hanging in Selection when PP corrects the token sequence.

2022-10-28 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Selection.cpp:316
 // return the eof token.
 if (ExpandedTokens.back().kind() == tok::eof)
   ExpandedTokens = ExpandedTokens.drop_back();

It reminds me of this fix, the symptom is the same (triggers the 
`Batch.empty()` assertion).
With the current fix, it is no longer needed I think (maybe we should keep it, 
it seems an interesting special case.)



Comment at: clang-tools-extra/clangd/Selection.cpp:331
+// See https://github.com/llvm/llvm-project/issues/58482
+return T.location() >= Start && T.location() <= Limit;
   });

This is bad :(  but I don't see other better alternative, I agree the current 
behavior is better than hanging forever. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136567

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


[clang] 76cf890 - Add some more C11 DR tests and update the status page

2022-10-28 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-10-28T08:17:03-04:00
New Revision: 76cf890984bf091bfd9efd6dc7bf0ef96b8b9f45

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

LOG: Add some more C11 DR tests and update the status page

Added: 


Modified: 
clang/test/C/drs/dr4xx.c
clang/www/c_dr_status.html

Removed: 




diff  --git a/clang/test/C/drs/dr4xx.c b/clang/test/C/drs/dr4xx.c
index c1e55f5153d12..e2cf2499d7f4f 100644
--- a/clang/test/C/drs/dr4xx.c
+++ b/clang/test/C/drs/dr4xx.c
@@ -48,6 +48,18 @@
  * diagnostic behavior, not runtime behavior. Also, both are a matter of QoI as
  * to what they optimize/diagnose. But if someone thinks of a way to test this,
  * we can add a test case for it then.
+ *
+ * WG14 DR448: yes
+ * What are the semantics of a # non-directive?
+ *
+ * WG14 DR454: yes
+ * ATOMIC_VAR_INIT (issues 3 and 4)
+ *
+ * WG14 DR455: yes
+ * ATOMIC_VAR_INIT issue 5
+ *
+ * WG14 DR459: yes
+ * atomic_load missing const qualifier
  */
 
 /* WG14 DR412: yes
@@ -162,3 +174,40 @@ void dr444(void) {
*/
   _Alignas(int) _Alignas(double) int k;
 }
+
+/* WG14 DR447: yes
+ * Boolean from complex
+ *
+ * Ensure that the imaginary part contributes to the conversion to bool, not
+ * just the real part.
+ */
+_Static_assert((_Bool)0.0 + 3.0 * (__extension__ 1.0iF), "");  /* 
c89only-warning {{'_Bool' is a C99 extension}}
+  
expected-warning {{expression is not an integer constant expression; folding it 
to a constant is a GNU extension}}
+*/
+_Static_assert(!(_Bool)0.0 + 0.0 * (__extension__ 1.0iF), ""); /* 
c89only-warning {{'_Bool' is a C99 extension}}
+  
expected-warning {{expression is not an integer constant expression; folding it 
to a constant is a GNU extension}}
+   */
+
+/* WG14 DR463: yes
+ * Left-shifting into the sign bit
+ *
+ * This DR was NAD and leaves shifting a bit into the high bit of a signed
+ * integer type undefined behavior, unlike in C++. Note, the diagnostic is also
+ * issued in C++ for shifting into that bit despite being well-defined because
+ * the code is questionable and should be validated by the programmer.
+ */
+void dr463(void) {
+  (void)(1 << (__CHAR_BIT__ * sizeof(int))); /* expected-warning {{shift count 
>= width of type}} */
+  (void)(1 << ((__CHAR_BIT__ * sizeof(int)) - 1));
+}
+
+/* WG14 DR464: yes
+ * Clarifying the Behavior of the #line Directive
+ *
+ * Note: the behavior described by this DR allows for two 
diff erent
+ * interpretations, but WG14 N2322 (adopted for C2x) adds a recommended
+ * practice which is what we're testing our interpretation against.
+ */
+#line 1
+_Static_assert(__LI\
+NE__ == 1, "");

diff  --git a/clang/www/c_dr_status.html b/clang/www/c_dr_status.html
index b0a54cf0b934c..ff5646de6b261 100644
--- a/clang/www/c_dr_status.html
+++ b/clang/www/c_dr_status.html
@@ -2327,7 +2327,7 @@ C defect report implementation status
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_447";>447
 C11
 Boolean from complex
-Unknown
+Yes
   
   
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_448";>448
@@ -2381,7 +2381,7 @@ C defect report implementation status
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_456";>456
 Dup
 Compile time definition of UINTN_C(value)
-Duplicate of 209
+Duplicate of 209
   
   
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_457";>457
@@ -2399,7 +2399,7 @@ C defect report implementation status
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_459";>459
 C11
 atomic_load missing const qualifier
-Unknown
+Yes
   
   
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_460";>460
@@ -2423,13 +2423,13 @@ C defect report implementation status
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_463";>463
 NAD
 Left-shifting into the sign bit
-Unknown
+Yes
   
   
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_464";>464
 C11
 Clarifying the Behavior of the #line Directive
-Unknown
+Yes
   
   
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_465";>465



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


[PATCH] D136090: Handle errors in expansion of response files

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

LGTM




Comment at: clang/unittests/Driver/ToolChainTest.cpp:604-606
+  char *StrBuff = (char *)Alloc.Allocate(6, 2);
+  std::memcpy(StrBuff, "\xFF\xFE\x00\xD8\x00\x00", 6);
+  StringRef BadUTF(StrBuff, 6);

sepavloff wrote:
> mgorny wrote:
> > Wouldn't it be possible to use `std::string`, or maybe even 
> > `std::array` here? I think it'd be less error-prone.
> Nor `std::string` neither `std::array` provide custom alignment.
> 
> UTF-16 string is constructed here from array of chars to avoid problems with 
> endianness. It consists of 2-byte elements and is expected to be aligned on 
> 2-byte boundary. Array of chars is aligned on byte and sometimes the test 
> failed due to invalid alignment.
> 
> So we have to use bare pointer to have guaranteed alignment.
> 
Ah. Could you leave a comment to make the alignment requirements clear? I'm a 
bit surprised that we have to meet alignment requirements when "reading" a file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136090

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


[PATCH] D134453: Disambiguate type names when printing NTTP types

2022-10-28 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG835b99e4c838: Disambiguate type names when printing NTTP 
types (authored by DoDoENT, committed by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/TemplateBase.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/SemaCXX/cxx2a-nttp-printing.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
  clang/test/SemaTemplate/temp_arg_string_printing.cpp
  clang/unittests/AST/StmtPrinterTest.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -48,7 +48,7 @@
   std::string Code = R"cpp(
 namespace N {
   template  struct Type {};
-  
+
   template 
   void Foo(const Type &Param);
 }
@@ -115,14 +115,14 @@
 
   ASSERT_TRUE(PrintedTypeMatches(
   Code, {"-std=c++20"}, Matcher,
-  R"(ASCII<{"this nontype template argument is [...]"}> &&)",
+  R"(ASCII{"this nontype template argument is [...]"}> &&)",
   [](PrintingPolicy &Policy) {
 Policy.EntireContentsOfLargeArray = false;
   }));
 
   ASSERT_TRUE(PrintedTypeMatches(
   Code, {"-std=c++20"}, Matcher,
-  R"(ASCII<{"this nontype template argument is too long to print"}> &&)",
+  R"(ASCII{"this nontype template argument is too long to print"}> &&)",
   [](PrintingPolicy &Policy) {
 Policy.EntireContentsOfLargeArray = true;
   }));
Index: clang/unittests/AST/StmtPrinterTest.cpp
===
--- clang/unittests/AST/StmtPrinterTest.cpp
+++ clang/unittests/AST/StmtPrinterTest.cpp
@@ -161,9 +161,9 @@
 }
 
 TEST(StmtPrinter, TestStringLiteralOperatorTemplate_Class) {
-  ASSERT_TRUE(
-  PrintedStmtCXXMatches(StdVer::CXX20,
-R"cpp(
+  ASSERT_TRUE(PrintedStmtCXXMatches(
+  StdVer::CXX20,
+  R"cpp(
 struct C {
   template  constexpr C(const char (&)[N]) : n(N) {}
   unsigned n;
@@ -173,8 +173,8 @@
   constexpr auto waldo = "abc"_c;
 }
 )cpp",
-FunctionBodyMatcher("A"),
-"constexpr auto waldo = operator\"\"_c<{4}>();\n"));
+  FunctionBodyMatcher("A"),
+  "constexpr auto waldo = operator\"\"_c();\n"));
 }
 
 TEST(StmtPrinter, TestCXXConversionDeclImplicit) {
Index: clang/test/SemaTemplate/temp_arg_string_printing.cpp
===
--- clang/test/SemaTemplate/temp_arg_string_printing.cpp
+++ clang/test/SemaTemplate/temp_arg_string_printing.cpp
@@ -19,111 +19,111 @@
 template  class ASCII {};
 
 void not_string() {
-  // CHECK{LITERAL}: ASCII<{{9, -1, 42}}>
+  // CHECK{LITERAL}: ASCII{{9, -1, 42}}>
   new ASCII<(int[]){9, -1, 42}>;
-  // CHECK{LITERAL}: ASCII<{{3.14e+00, 0.00e+00, 4.20e+01}}>
+  // CHECK{LITERAL}: ASCII{{3.14e+00, 0.00e+00, 4.20e+01}}>
   new ASCII<(double[]){3.14, 0., 42.}>;
 }
 
 void narrow() {
-  // CHECK{LITERAL}: ASCII<{""}>
+  // CHECK{LITERAL}: ASCII{""}>
   new ASCII<"">;
-  // CHECK{LITERAL}: ASCII<{"the quick brown fox jumps"}>
+  // CHECK{LITERAL}: ASCII{"the quick brown fox jumps"}>
   new ASCII<"the quick brown fox jumps">;
-  // CHECK{LITERAL}: ASCII<{"OVER THE LAZY DOG 0123456789"}>
+  // CHECK{LITERAL}: ASCII{"OVER THE LAZY DOG 0123456789"}>
   new ASCII<"OVER THE LAZY DOG 0123456789">;
-  // CHECK{LITERAL}: ASCII<{"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
+  // CHECK{LITERAL}: ASCII{"\\`~!@#$%^&*()_+-={}[]|\'\";:,.<>?/"}>
   new ASCII?/)">;
-  // CHECK{LITERAL}: ASCII<{{101, 115, 99, 97, 112, 101, 0, 0}}>
+  // CHECK{LITERAL}: ASCII{{101, 115, 99, 97, 112, 101, 0, 0}}>
   new ASCII<"escape\0">;
-  // CHECK{LITERAL}: ASCII<{"escape\r\n"}>
+  // CHECK{LITERAL}: ASCII{"escape\r\n"}>
   new ASCII<"escape\r\n">;
-  // CHECK{LITERAL}: ASCII<{"escape\\\t\f\v"}>
+  // CHECK{LITERAL}: ASCII{"escape\\\t\f\v"}>
   new ASCII<"escape\\\t\f\v">;
-  // CHECK{LITERAL}: ASCII<{"escape\a\bc"}>
+  // CHECK{LITERAL}: ASCII{"escape\a\bc"}>
   new ASCII<"escape\a\b\c">;
-  // CHECK{LITERAL}: ASCII<{{110, 111, 116, 17, 0}}>
+  // CHECK{LITERAL}: ASCII{{110, 111, 116, 17, 0}}>
   new ASCII<"not\x11">;
-  // CHECK{LITERAL}: ASCII<{{18, 20, 127, 16, 1, 32, 97, 98, 99, 0}}>
+  // CHECK{LITERAL}: ASCII{{18, 20, 127, 16, 1, 32, 97, 98, 99, 0}}>
   new ASCII<"\x12\x14\x7f\x10\x01 abc">;
-  // CHECK{LITERAL}: ASCII<{{18, 20, 127, 16, 1, 32, 97, 98, 99, 100, 0}}>
+  // CHECK{LITERAL}: ASCII{{18, 20, 127, 16, 1, 32, 97, 98, 99, 100, 0}}>
   new ASCII<"\x12\x14\x7f\x10\x01 abcd">;
-  // CHECK{LITERAL}: ASCII<{"print more characters as string"}>
+  // CHECK{LITERAL}: ASCII{"print more charact

[clang] 835b99e - Disambiguate type names when printing NTTP types

2022-10-28 Thread Aaron Ballman via cfe-commits

Author: Nenad Mikša
Date: 2022-10-28T08:18:38-04:00
New Revision: 835b99e4c8381f6dd1dda7e2ef0e9c72359460dd

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

LOG: Disambiguate type names when printing NTTP types

When printing NTTP template types, ensure that type name of the NTTP is
printed.

Fixes #57562

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/TemplateBase.cpp
clang/test/CodeGenCXX/debug-info-template.cpp
clang/test/SemaCXX/cxx2a-nttp-printing.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
clang/test/SemaTemplate/temp_arg_string_printing.cpp
clang/unittests/AST/StmtPrinterTest.cpp
clang/unittests/AST/TypePrinterTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dd859c9269cfd..edf31b90a74c1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -336,6 +336,8 @@ Improvements to Clang's diagnostics
   `_ failures. This 
diagnostic
   is grouped under ``-Wcast-function-type`` as it identifies a more strict set 
of
   potentially problematic function type casts.
+- Clang will now disambiguate NTTP types when printing diagnostic that contain 
NTTP types.
+  Fixes `Issue 57562 `_.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 579684c94f80f..ca06f0b0caefa 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -422,10 +422,10 @@ void TemplateArgument::print(const PrintingPolicy 
&Policy, raw_ostream &Out,
   }
 
   case Declaration: {
-// FIXME: Include the type if it's not obvious from the context.
 NamedDecl *ND = getAsDecl();
 if (getParamTypeForDecl()->isRecordType()) {
   if (auto *TPO = dyn_cast(ND)) {
+TPO->getType().getUnqualifiedType().print(Out, Policy);
 TPO->printAsInit(Out, Policy);
 break;
   }

diff  --git a/clang/test/CodeGenCXX/debug-info-template.cpp 
b/clang/test/CodeGenCXX/debug-info-template.cpp
index 4ea2b20c74d0e..cf45524769785 100644
--- a/clang/test/CodeGenCXX/debug-info-template.cpp
+++ b/clang/test/CodeGenCXX/debug-info-template.cpp
@@ -165,7 +165,7 @@ template struct 
ClassTemplateArgTemplate {
   static constexpr const ClassTemplateArg &Arg = A;
 };
 
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"ClassTemplateArgTemplate<{1, 2.00e+00}>", {{.*}}, templateParams: 
![[CLASS_TEMP_ARGS:[0-9]*]],
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"ClassTemplateArgTemplate", {{.*}}, 
templateParams: ![[CLASS_TEMP_ARGS:[0-9]*]],
 // CHECK: ![[CLASS_TEMP_ARG_CONST_REF_TYPE:[0-9]*]] = !DIDerivedType(tag: 
DW_TAG_reference_type, baseType: ![[CLASS_TEMP_ARG_CONST_TYPE:[0-9]*]],
 // CHECK: ![[CLASS_TEMP_ARG_CONST_TYPE]] = !DIDerivedType(tag: 
DW_TAG_const_type, baseType: ![[CLASS_TEMP_ARG_TYPE:[0-9]*]])
 // CHECK: ![[CLASS_TEMP_ARG_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "ClassTemplateArg",
@@ -225,16 +225,16 @@ template void f1();
 // CHECK-SAME: templateParams: ![[RAW_FUNC_QUAL_ARGS:[0-9]*]],
 
 // CHECK: ![[RAW_FUNC_QUAL_ARGS]] = !{![[RAW_FUNC_QUAL_T1:[0-9]*]], 
![[RAW_FUNC_QUAL_T2:[0-9]*]], ![[RAW_FUNC_QUAL_T3:[0-9]*]], 
![[RAW_FUNC_QUAL_T4:[0-9]*]]}
-// CHECK: ![[RAW_FUNC_QUAL_T1]] = !DITemplateTypeParameter(name: "T1", type: 
![[RAW_FUNC_QUAL_VOL:[0-9]*]]) 
+// CHECK: ![[RAW_FUNC_QUAL_T1]] = !DITemplateTypeParameter(name: "T1", type: 
![[RAW_FUNC_QUAL_VOL:[0-9]*]])
 // CHECK: ![[RAW_FUNC_QUAL_VOL]] = !DIDerivedType(tag: DW_TAG_volatile_type, 
baseType: ![[RAW_FUNC_QUAL_TYPE:[0-9]*]])
 // CHECK: ![[RAW_FUNC_QUAL_TYPE]] = !DISubroutineType(types: 
![[RAW_FUNC_QUAL_LIST:[0-9]*]]
 // CHECK: ![[RAW_FUNC_QUAL_LIST]] = !{![[RAW_FUNC_QUAL_STRUCT:[0-9]*]]}
 // CHECK: ![[RAW_FUNC_QUAL_STRUCT]] = !DICompositeType(tag: 
DW_TAG_structure_type, name: "t1"
-// CHECK: ![[RAW_FUNC_QUAL_T2]] = !DITemplateTypeParameter(name: "T2", type: 
![[RAW_FUNC_QUAL_CNST:[0-9]*]]) 
+// CHECK: ![[RAW_FUNC_QUAL_T2]] = !DITemplateTypeParameter(name: "T2", type: 
![[RAW_FUNC_QUAL_CNST:[0-9]*]])
 // CHECK: ![[RAW_FUNC_QUAL_CNST]] = !DIDerivedType(tag: DW_TAG_const_type, 
baseType: ![[RAW_FUNC_QUAL_TYPE:[0-9]*]])
-// CHECK: ![[RAW_FUNC_QUAL_T3]] = !DITemplateTypeParameter(name: "T3", type: 
![[RAW_FUNC_QUAL_REF:[0-9]*]]) 
+// CHECK: ![[RAW_FUNC_QUAL_T3]] = !DITemplateTypeParameter(name: "T3", type: 
![[RAW_FUNC_QUAL_REF:[0-9]*]])
 // CHECK: ![[RAW_FUNC_QUAL_REF]] = !DISubroutineType(flags: 
DIFlagLValueReference, types: ![[RAW_FUNC_QU

Re: [Diffusion] rGe4ec6ce8a75c: Clang: Add release note for defaulted-special-members-POD GCC ABI fix

2022-10-28 Thread Aaron Ballman via cfe-commits
Also, please be sure to post something to
https://discourse.llvm.org/c/announce/46 with the potentially-breaking
tag applied to it.

~Aaron

On Thu, Oct 27, 2022 at 8:19 PM Hubert Tong via Phabricator via
cfe-commits  wrote:
>
> hubert.reinterpretcast added inline comments.
>
> BRANCHES
>   main
>
> /clang/docs/ReleaseNotes.rst:612-613 Shouldn't the usage of POD here be 
> clarified to say that we mean "POD for the purposes of Itanium ABI layout"?
>
> Users:
>   dblaikie (Author)
>
> https://reviews.llvm.org/rGe4ec6ce8a75c
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136941: [clang][Interp] Implement String-and CharacterLiterals

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 471505.

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

https://reviews.llvm.org/D136941

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp
  clang/test/Lexer/char-escapes.c

Index: clang/test/Lexer/char-escapes.c
===
--- clang/test/Lexer/char-escapes.c
+++ clang/test/Lexer/char-escapes.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+// RUN: %clang_cc1 -fsyntax-only -pedantic -fexperimental-new-constant-interpreter -verify %s
 
 int test['\\' == 92 ? 1 : -1];
 int test['\"' == 34 ? 1 : -1];
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -278,3 +278,46 @@
   static_assert((0 | gimme(12)) == 12, "");
   static_assert((12 | true) == 13, "");
 };
+
+namespace strings {
+  constexpr const char *S = "abc";
+  static_assert(S[0] == 97, "");
+  static_assert(S[1] == 98, "");
+  static_assert(S[2] == 99, "");
+  static_assert(S[3] == 0, "");
+
+  static_assert("foobar"[2] == 'o', "");
+  static_assert(2["foobar"] == 'o', "");
+
+  constexpr const wchar_t *wide = L"bar";
+  static_assert(wide[0] == L'b', "");
+
+  constexpr const char32_t *u32 = U"abc";
+  static_assert(u32[1] == U'b', "");
+
+  constexpr char32_t c = U'\U0001F60E';
+  static_assert(c == 0x0001F60EL, "");
+
+  constexpr char k = -1;
+  static_assert(k == -1, "");
+
+  static_assert('\N{LATIN CAPITAL LETTER E}' == 'E', "");
+  static_assert('\t' == 9, "");
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+  constexpr int mc = 'abc';
+  static_assert(mc == 'abc', "");
+  __WCHAR_TYPE__ wm = L'abc'; // ref-error{{wide character literals may not contain multiple characters}} \
+  // expected-error{{wide character literals may not contain multiple characters}}
+  __WCHAR_TYPE__ wu = u'abc'; // ref-error{{Unicode character literals may not contain multiple characters}} \
+  // expected-error{{Unicode character literals may not contain multiple characters}}
+  __WCHAR_TYPE__ wU = U'abc'; // ref-error{{Unicode character literals may not contain multiple characters}} \
+  // expected-error{{Unicode character literals may not contain multiple characters}}
+#if __cplusplus > 201103L
+  __WCHAR_TYPE__ wu8 = u8'abc'; // ref-error{{Unicode character literals may not contain multiple characters}} \
+// expected-error{{Unicode character literals may not contain multiple characters}}
+#endif
+
+#pragma clang diagnostic pop
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -83,6 +83,8 @@
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
   bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
+  bool VisitStringLiteral(const StringLiteral *E);
+  bool VisitCharacterLiteral(const CharacterLiteral *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -231,7 +233,8 @@
   /// Emits an integer constant.
   template  bool emitConst(const Expr *E, T Value) {
 QualType Ty = E->getType();
-APInt WrappedValue(getIntWidth(Ty), Value, std::is_signed::value);
+APInt WrappedValue(getIntWidth(Ty), static_cast(Value),
+   std::is_signed::value);
 return emitConst(*Ctx.classify(Ty), WrappedValue, E);
   }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -397,6 +397,18 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitStringLiteral(const StringLiteral *E) {
+  unsigned StringIndex = P.createGlobalString(E);
+  return this->emitGetPtrGlobal(StringIndex, E);
+}
+
+template 
+bool ByteCodeExprGen::VisitCharacterLiteral(
+const CharacterLiteral *E) {
+  return this->emitConst(E, E->getValue());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135859: [Includecleaner] Introduce RefType to ast walking

2022-10-28 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 6 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/AnalysisInternal.h:33
+/// Indicates the relation between the reference and the target.
+enum class RefType {
+  /// Target is explicit from the reference, e.g. function call.

sammccall wrote:
> kadircet wrote:
> > hokein wrote:
> > > I'm wondering what's our plan of supporting policy (different 
> > > coding-style may have different decisions about which includes are used)?
> > > 
> > > IIUC, the RefType is part of the picture, providing fine-grained 
> > > information about each reference, and the caller can make their decisions 
> > > based on it?
> > > 
> > > Thinking about the `Implicit` type, I think cases like non-spelled 
> > > constructor call, implicit conversion calls (maybe more?) fall into this 
> > > type, if we support `Policy.Constructor`, and `Policy.Conversion`, how do 
> > > we distinguish with these cases? We can probably do some ad-hoc checks on 
> > > the `TargetDecl`, but I'm not sure that the tuple ` > > TargetDecl, Ref>` will provide enough information to implement different 
> > > policy .
> > > IIUC, the RefType is part of the picture, providing fine-grained 
> > > information about each reference, and the caller can make their decisions 
> > > based on it?
> > 
> > Exactly that's the idea.
> > 
> > > if we support Policy.Constructor, and Policy.Conversion, how do we 
> > > distinguish with these cases? We can probably do some ad-hoc checks on 
> > > the TargetDecl
> > 
> > In our previous discussions we've also come to the conclusion that 
> > TargetDecl will have enough information for the caller to infer such 
> > information later on. We've decided to not make it part of the public api 
> > (at least initially) because it's unclear how widely useful those signals 
> > will be. But if it turns out to be needed by a variety of applications the 
> > design is extensible to either provide a:
> > - inferDetails(Symbol) helper, which would derive a signal structure that 
> > extracts most of those signals needed, or
> > - update Callback signature to also carry that information derived from the 
> > Symbol
> > 
> > Does that make sense?
> > In our previous discussions we've also come to the conclusion that 
> > TargetDecl will have enough information for the caller to infer such 
> > information later on
> 
> It was a while ago and my memory is bad, but this isn't my recollection 
> (maybe you're talking about different discussions). I think it was rather 
> "this is the bare minimum we need to get going, and we want to punt on real 
> policy support for now".
> 
> At least "TargetDecl will have enough information" seems implausible on its 
> face, e.g. how could you implement "types of variables are used, but types of 
> expressions are not used" based on inspecting TargetDecl?
> It was a while ago and my memory is bad, but this isn't my recollection 
> (maybe you're talking about different discussions). I think it was rather 
> "this is the bare minimum we need to get going, and we want to punt on real 
> policy support for now".
> At least "TargetDecl will have enough information" seems implausible on its 
> face, e.g. how could you implement "types of variables are used, but types of 
> expressions are not used" based on inspecting TargetDecl?

Right. I wasn't talking about inferring signals about how a decl was found 
(e.g. type of an expression, as you've also mentioned), but rather talking 
about information about the decl itself (is this a member, constructor etc.).



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:107
 TEST(WalkAST, DeclRef) {
-  testWalk("int ^x;", "int y = ^x;");
-  testWalk("int ^foo();", "int y = ^foo();");
-  testWalk("namespace ns { int ^x; }", "int y = ns::^x;");
-  testWalk("struct S { static int ^x; };", "int y = S::^x;");
+  testWalk("int $explicit^x;", "int y = ^x;");
+  testWalk("int $explicit^foo();", "int y = ^foo();");

sammccall wrote:
> kadircet wrote:
> > sammccall wrote:
> > > This is very noisy. please find a way to avoid having to mark all test 
> > > cases as `$explicit`, e.g. by splitting implicit cases into different 
> > > tests
> > what about treating non-named points as explicit? that way we would only 
> > annotate non-explicit references (which are rare).
> Not sure implicit references are actually rare, more like our examples are 
> trivial for now :-)
> 
> But I might be wrong, up to you.
> 
> (I would at least use $A^x instead of $ambiguous^x)
i don't like the idea of splitting tests because i feel like that'll lead to 
duplicating lots of test cases when we have a mixture of references happening 
(e.g. implicit type conversion and an explicitly spelled type from same 
reference).

so another option i can think of here is returning annotations for points from 
testWalk and building expectations on top of that, 

[PATCH] D135859: [Includecleaner] Introduce RefType to ast walking

2022-10-28 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 471512.
kadircet added a comment.

- Fix typo in Ambiguous
- Rebase for Types.h, introduce SymbolReference
- Use comments rather than an optional parameter to indicate header-ness of 
main files in tests
- Rather than assuming Root is in main file, check that either root isn't in 
main file or main file is a header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135859

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -12,11 +12,15 @@
 #include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Testing/TestAST.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
 #include 
 
 namespace clang::include_cleaner {
@@ -24,10 +28,23 @@
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
+llvm::StringLiteral to_string(RefType RT) {
+  switch (RT) {
+  case RefType::Explicit:
+return "explicit";
+  case RefType::Implicit:
+return "implicit";
+  case RefType::Ambiguous:
+return "ambiguous";
+  }
+  llvm_unreachable("Unexpected RefType");
+}
+
 // Specifies a test of which symbols are referenced by a piece of code.
-//
+// If `// c++-header` is present, treats referencing code as a header file.
+// Target should contain points annotated with the reference kind.
 // Example:
-//   Target:  int ^foo();
+//   Target:  int $explicit^foo();
 //   Referencing: int x = ^foo();
 // There must be exactly one referencing location marked.
 void testWalk(llvm::StringRef TargetCode, llvm::StringRef ReferencingCode) {
@@ -39,6 +56,8 @@
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("target.h");
   Inputs.ExtraArgs.push_back("-std=c++17");
+  if (Referencing.code().contains("// c++-header\n"))
+Inputs.ExtraArgs.push_back("-xc++-header");
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
 
@@ -51,20 +70,21 @@
   llvm::cantFail(AST.fileManager().getFileRef("target.h")));
 
   // Perform the walk, and capture the offsets of the referenced targets.
-  std::vector ReferencedOffsets;
+  std::unordered_map> ReferencedOffsets;
   for (Decl *D : AST.context().getTranslationUnitDecl()->decls()) {
 if (ReferencingFile != SM.getDecomposedExpansionLoc(D->getLocation()).first)
   continue;
-walkAST(*D, [&](SourceLocation Loc, NamedDecl &ND) {
+walkAST(*D, [&](SourceLocation Loc, NamedDecl &ND, RefType RT) {
   if (SM.getFileLoc(Loc) != ReferencingLoc)
 return;
   auto NDLoc = SM.getDecomposedLoc(SM.getFileLoc(ND.getLocation()));
   if (NDLoc.first != TargetFile)
 return;
-  ReferencedOffsets.push_back(NDLoc.second);
+  ReferencedOffsets[RT].push_back(NDLoc.second);
 });
   }
-  llvm::sort(ReferencedOffsets);
+  for (auto &Entry : ReferencedOffsets)
+llvm::sort(Entry.second);
 
   // Compare results to the expected points.
   // For each difference, show the target point in context, like a diagnostic.
@@ -74,17 +94,22 @@
   DiagOpts->ShowLevel = 0;
   DiagOpts->ShowNoteIncludeStack = 0;
   TextDiagnostic Diag(DiagOS, AST.context().getLangOpts(), DiagOpts);
-  auto DiagnosePoint = [&](const char *Message, unsigned Offset) {
+  auto DiagnosePoint = [&](llvm::StringRef Message, unsigned Offset) {
 Diag.emitDiagnostic(
 FullSourceLoc(SM.getComposedLoc(TargetFile, Offset), SM),
 DiagnosticsEngine::Note, Message, {}, {});
   };
-  for (auto Expected : Target.points())
-if (!llvm::is_contained(ReferencedOffsets, Expected))
-  DiagnosePoint("location not marked used", Expected);
-  for (auto Actual : ReferencedOffsets)
-if (!llvm::is_contained(Target.points(), Actual))
-  DiagnosePoint("location unexpectedly used", Actual);
+  for (auto RT : {RefType::Explicit, RefType::Implicit, RefType::Ambiguous}) {
+auto RTStr = to_string(RT);
+for (auto Expected : Target.points(RTStr))
+  if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
+DiagnosePoint(("location not marked used with type " + RTStr).str(),
+

[PATCH] D136694: [clang][Interp] Check that constructor calls initialize all record fields

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



Comment at: clang/lib/AST/Interp/Interp.cpp:465
+bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This) {
+  assert(!This.isZero());
+  const Record *R = This.getRecord();

shafik wrote:
> Should we also check `isLive()` or should that just turn into a diagnostic?
Since cc79ddb52c310be50d2ed0e0307b695cc7c142ce, we use `CheckInvoke()` for the 
instance pointer, which already calls `isLive()`.


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

https://reviews.llvm.org/D136694

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


[clang] 52ba50c - [clang][Interp] Implement String- and CharacterLiterals

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T15:05:21+02:00
New Revision: 52ba50c24c5572330a04b86879fdefaa81705a18

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

LOG: [clang][Interp] Implement String- and CharacterLiterals

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/AST/Interp/literals.cpp
clang/test/Lexer/char-escapes.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 9472f1aed9178..7e00fc4f707e9 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -397,6 +397,18 @@ bool 
ByteCodeExprGen::VisitAbstractConditionalOperator(
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitStringLiteral(const StringLiteral *E) {
+  unsigned StringIndex = P.createGlobalString(E);
+  return this->emitGetPtrGlobal(StringIndex, E);
+}
+
+template 
+bool ByteCodeExprGen::VisitCharacterLiteral(
+const CharacterLiteral *E) {
+  return this->emitConst(E, E->getValue());
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index a254a1baee8f9..d1cda8939d585 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -83,6 +83,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E);
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
   bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
+  bool VisitStringLiteral(const StringLiteral *E);
+  bool VisitCharacterLiteral(const CharacterLiteral *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -231,7 +233,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   /// Emits an integer constant.
   template  bool emitConst(const Expr *E, T Value) {
 QualType Ty = E->getType();
-APInt WrappedValue(getIntWidth(Ty), Value, std::is_signed::value);
+APInt WrappedValue(getIntWidth(Ty), static_cast(Value),
+   std::is_signed::value);
 return emitConst(*Ctx.classify(Ty), WrappedValue, E);
   }
 

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index f0083e63f35d9..ca76be9b0bf94 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -278,3 +278,46 @@ namespace bitOr {
   static_assert((0 | gimme(12)) == 12, "");
   static_assert((12 | true) == 13, "");
 };
+
+namespace strings {
+  constexpr const char *S = "abc";
+  static_assert(S[0] == 97, "");
+  static_assert(S[1] == 98, "");
+  static_assert(S[2] == 99, "");
+  static_assert(S[3] == 0, "");
+
+  static_assert("foobar"[2] == 'o', "");
+  static_assert(2["foobar"] == 'o', "");
+
+  constexpr const wchar_t *wide = L"bar";
+  static_assert(wide[0] == L'b', "");
+
+  constexpr const char32_t *u32 = U"abc";
+  static_assert(u32[1] == U'b', "");
+
+  constexpr char32_t c = U'\U0001F60E';
+  static_assert(c == 0x0001F60EL, "");
+
+  constexpr char k = -1;
+  static_assert(k == -1, "");
+
+  static_assert('\N{LATIN CAPITAL LETTER E}' == 'E', "");
+  static_assert('\t' == 9, "");
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+  constexpr int mc = 'abc';
+  static_assert(mc == 'abc', "");
+  __WCHAR_TYPE__ wm = L'abc'; // ref-error{{wide character literals may not 
contain multiple characters}} \
+  // expected-error{{wide character literals may 
not contain multiple characters}}
+  __WCHAR_TYPE__ wu = u'abc'; // ref-error{{Unicode character literals may not 
contain multiple characters}} \
+  // expected-error{{Unicode character literals 
may not contain multiple characters}}
+  __WCHAR_TYPE__ wU = U'abc'; // ref-error{{Unicode character literals may not 
contain multiple characters}} \
+  // expected-error{{Unicode character literals 
may not contain multiple characters}}
+#if __cplusplus > 201103L
+  __WCHAR_TYPE__ wu8 = u8'abc'; // ref-error{{Unicode character literals may 
not contain multiple characters}} \
+// expected-error{{Unicode character literals 
may not contain multiple characters}}
+#endif
+
+#pragma clang diagnostic pop
+};

diff  --git a/clang/test/Lexer/char-escapes.c b/clang/test/Lexer/char-escapes.c
index 32a1c6140d53c..11e25a6d251fe 100644
--- a/clang/test/Lexer/char-escapes.c
+++ b/clang/test/Lexer/char-escapes.c
@@ -1,4 +1,5 @@
 // RUN: %clan

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

2022-10-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D134128#3890447 , @h-vetinari 
wrote:

> Congratulations for landing this!
>
> How far do you (both) think we're away from completing concepts? Are the 
> issues (aside from CWG1496 & CWG1734) mentioned on 
> https://clang.llvm.org/cxx_status.html tracked anywhere else? I see that 
> https://github.com/orgs/llvm/projects/14 has 45 concept-related issues, but 
> presumably not all of those are necessary to set the feature macro?

There is enough on that list of failures that I'm not quite comfortable 
updating the macro.  I think this is a question we should evaluate right before 
the release.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

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


[PATCH] D127762: [Clang][AArch64] Add ACLE attributes for SME.

2022-10-28 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 471515.
sdesmalen marked 9 inline comments as done.
sdesmalen edited the summary of this revision.
sdesmalen added a comment.

- Rebased patch
- Use `InheritableAttr` for the `ArmLocallyStreaming` attribute instead of 
`DeclOrTypeAttr`
- Added test-case to test inheritable property of `ArmLocallyStreaming`
- Refactored enum as suggested


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/aarch64-sme-attrs-no-sme.c
  clang/test/Sema/aarch64-sme-func-attrs.c

Index: clang/test/Sema/aarch64-sme-func-attrs.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sme-func-attrs.c
@@ -0,0 +1,273 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s
+
+// Valid attributes
+
+__attribute__((arm_streaming)) void sme_arm_streaming(void);
+__attribute__((arm_streaming_compatible)) void sme_arm_streaming_compatible(void);
+
+__attribute__((arm_new_za)) void sme_arm_new_za(void);
+__attribute__((arm_shared_za)) void sme_arm_shared_za(void);
+__attribute__((arm_preserves_za)) void sme_arm_preserves_za(void);
+
+__attribute__((arm_streaming, arm_new_za)) void sme_arm_streaming_new_za(void);
+__attribute__((arm_streaming, arm_shared_za)) void sme_arm_streaming_shared_za(void);
+__attribute__((arm_streaming, arm_preserves_za)) void sme_arm_streaming_preserves_za(void);
+
+__attribute__((arm_streaming_compatible, arm_new_za)) void sme_arm_sc_new_za(void);
+__attribute__((arm_streaming_compatible, arm_shared_za)) void sme_arm_sc_shared_za(void);
+__attribute__((arm_streaming_compatible, arm_preserves_za)) void sme_arm_sc_preserves_za(void);
+
+__attribute__((arm_shared_za, arm_preserves_za)) void sme_arm_shared_preserves_za(void);
+
+__attribute__((arm_locally_streaming)) void sme_arm_locally_streaming(void) { }
+__attribute__((arm_locally_streaming, arm_streaming)) void sme_arm_streaming_and_locally_streaming(void) { }
+__attribute__((arm_locally_streaming, arm_streaming_compatible)) void sme_arm_streaming_and_streaming_compatible(void) { }
+
+__attribute__((arm_locally_streaming, arm_new_za)) void sme_arm_ls_new_za(void) { }
+__attribute__((arm_locally_streaming, arm_shared_za)) void sme_arm_ls_shared_za(void) { }
+__attribute__((arm_locally_streaming, arm_preserves_za)) void sme_arm_ls_preserves_za(void) { }
+
+// Valid attributes on function pointers
+
+void __attribute__((arm_streaming)) streaming_ptr(void);
+typedef __attribute__((arm_streaming)) void (*fptrty1) (void);
+fptrty1 call_streaming_func() { return streaming_ptr; }
+
+void __attribute__((arm_streaming_compatible)) streaming_compatible_ptr(void);
+typedef __attribute__((arm_streaming_compatible)) void (*fptrty2) (void);
+fptrty2 call_sc_func() { return streaming_compatible_ptr; }
+
+void __attribute__((arm_new_za)) new_za_ptr(void);
+typedef __attribute__((arm_new_za)) void (*fptrty3) (void);
+fptrty3 call_new_za_func() { return new_za_ptr; }
+
+void __attribute__((arm_shared_za)) shared_za_ptr(void);
+typedef __attribute__((arm_shared_za)) void (*fptrty4) (void);
+fptrty4 call_shared_za_func() { return shared_za_ptr; }
+
+void __attribute__((arm_preserves_za)) preserves_za_ptr(void);
+typedef __attribute__((arm_preserves_za)) void (*fptrty5) (void);
+fptrty5 call_preserve_za_func() { return preserves_za_ptr; }
+
+void __attribute__((arm_shared_za, arm_preserves_za)) shared_preserves_za_ptr(void);
+typedef __attribute__((arm_shared_za, arm_preserves_za)) void (*fptrty6) (void);
+fptrty6 call_shared_preserve_za_func() { return shared_preserves_za_ptr; }
+
+typedef void (*fptrty7) (void);
+fptrty7 cast_ls_func_to_normal() { return sme_arm_locally_streaming; }
+
+// FIXME: Add invalid function pointer assignments such as assigning:
+//   1. A streaming compatible function to a normal function pointer,
+//   2. A locally streaming function to a streaming function pointer,
+// etc.
+
+// Invalid attributes
+
+// expected-cpp-error@+4 {{'arm_streaming_compatible' and 'arm_streaming' att

[PATCH] D127762: [Clang][AArch64] Add ACLE attributes for SME.

2022-10-28 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a subscriber: rsandifo-arm.
sdesmalen added a comment.

The past few months we've worked to get the attributes at the LLVM IR side 
implemented. Since that work has now landed, this patch should no longer be 
held up by the LLVM side of things.

@aaron.ballman I've updated and rebased the patch. I went through all the 
comments again and believe that all of them have been addressed. Would you be 
happy to give this patch another look?




Comment at: clang/include/clang/Basic/Attr.td:2345
+
+def ArmLocallyStreaming : DeclOrStmtAttr, TargetSpecificAttr 
{
+  let Spellings = [GNU<"arm_locally_streaming">];

aaron.ballman wrote:
> sdesmalen wrote:
> > aaron.ballman wrote:
> > > Why is this a *statement* attribute?
> > You're right that it shouldn't be. I want it to just be a decl attribute 
> > and don't want it to be either a Type or a Stmt attribute, but that doesn't 
> > seem to exist.
> > I find their meaning quite confusing, because both allow me to limit their 
> > applicability to Functions. What is the right class to derive from here?
> Hmm, we have some documentation at 
> https://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute but 
> it's not very clear on all the choices and when to pick which one.
> 
> For declaration attributes on a function, the question really boils down to 
> whether you want redeclarations to automatically inherit the attribute or 
> not. e.g.,
> ```
> __attribute__((arm_locally_streaming)) void func(void);
> void func(void); // Is this declaration also marked locally streaming?
> 
> void use(void) {
>   func(); // Does this use see the attribute or not?
> }
> ```
> If you want the call in `use()` to see the attribute, then you want the 
> attribute to be inherited on the redeclaration, and so you'd use 
> `InheritableAttr`. If you don't want the call in `use()` to see the 
> attribute, then you'd use `Attr`.
Thanks for clarifying. I've changed the code to use `InheritableAttr`, since 
future redeclarations/redefinitions should inherit the `arm_locally_streaming` 
attribute (and also added an extra test-case for this)



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2000
   "overridden virtual function is here">;
+def err_conflicting_overriding_attributes : Error<
+  "virtual function %0 has different attributes "

aaron.ballman wrote:
> sdesmalen wrote:
> > aaron.ballman wrote:
> > > This error and the one below make me wonder whether an attribute spelling 
> > > is the appropriate way to surface this functionality as opposed to a 
> > > keyword. Attributes don't typically don't cause errors in these 
> > > situations, but because these attributes are strongly coupled to their 
> > > type system effects I can see why you want these to be errors.
> > > This error and the one below make me wonder whether an attribute spelling 
> > > is the appropriate way to surface this functionality as opposed to a 
> > > keyword. 
> > I'm not sure I understand what you mean, do you have an example?
> `override` and `final` could have been surfaced via attributes, and in Clang 
> we semantically express them as such (see `Final` and `Override` in Attr.td), 
> but instead they are surfaced to the user as keywords in the language 
> standard. You're not under the same constraints as the standard (you're 
> making a vendor-specific attribute). We're not super consistent with whether 
> we use the same approach as the standard (we have some type attributes that 
> are spelled as attributes like `vector_size` and others that are spelled via 
> keywords like `_Nullable`.
> 
> So you could spell your type attributes the way you have been with 
> `__attribute__`, or you could come up with keywords for them (so instead of 
> using `GNU<"whatever">` for the attribute, you could use `Keyword<_Whatever>` 
> or `Keyword<__whatever>` (you'd also need to add them as recognized keyword 
> tokens, parse them as appropriate, etc).
> 
> Note: I don't insist on you using a keyword for these, but I am wondering if 
> that approach was considered or not given how non-portable the attributes are 
> (if an implementation ignores this attribute, it sounds like the program 
> semantics are unlikely to be correct).
@rsandifo-arm can you shed some light on whether using a keyword instead of an 
`attribute` was considered?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

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


[clang] 83b97b3 - [clang] Fix a -Wcast-qual GCC warning. NFC.

2022-10-28 Thread Martin Storsjö via cfe-commits

Author: Martin Storsjö
Date: 2022-10-28T16:11:34+03:00
New Revision: 83b97b3b277281c3b90d245c7816addccc756158

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

LOG: [clang] Fix a -Wcast-qual GCC warning. NFC.

This fixes the following warning:

../tools/clang/lib/AST/Interp/Disasm.cpp: In member function ‘void 
clang::interp::Function::dump(llvm::raw_ostream&) const’:
../tools/clang/lib/AST/Interp/Disasm.cpp:43:25: warning: cast from type ‘const 
clang::interp::Function*’ to type ‘void*’ casts away qualifiers [-Wcast-qual]
   43 | OS << " " << (void*)this << ":\n";
  | ^~~~

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index db68887f0558..82debe4fcae1 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -40,7 +40,7 @@ LLVM_DUMP_METHOD void Function::dump(llvm::raw_ostream &OS) 
const {
 } else {
   OS << F->getDeclName();
 }
-OS << " " << (void*)this << ":\n";
+OS << " " << (const void*)this << ":\n";
   } else {
 OS << "<>\n";
   }



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


[PATCH] D136936: [clang][Interp] Handle undefined functions better

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 471517.

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

https://reviews.llvm.org/D136936

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/functions.cpp

Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -1,9 +1,6 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 
-// expected-no-diagnostics
-// ref-no-diagnostics
-
 constexpr void doNothing() {}
 constexpr int gimme5() {
   doNothing();
@@ -73,3 +70,17 @@
 static_assert(getNum<-2>() == -2, "");
 static_assert(getNum<10>() == 10, "");
 static_assert(getNum() == 5, "");
+
+constexpr int f(); // expected-note {{declared here}} \
+   // ref-note {{declared here}}
+static_assert(f() == 5, ""); // expected-error {{not an integral constant expression}} \
+ // expected-note {{undefined function 'f'}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{undefined function 'f'}}
+constexpr int a() {
+  return f();
+}
+constexpr int f() {
+  return 5;
+}
+static_assert(a() == 5, "");
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -94,6 +94,7 @@
   /// Creates a new function from a code range.
   template 
   Function *createFunction(const FunctionDecl *Def, Ts &&... Args) {
+Def = Def->getCanonicalDecl();
 auto *Func = new Function(*this, Def, std::forward(Args)...);
 Funcs.insert({Def, std::unique_ptr(Func)});
 return Func;
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -207,7 +207,8 @@
 }
 
 Function *Program::getFunction(const FunctionDecl *F) {
-  F = F->getDefinition();
+  F = F->getCanonicalDecl();
+  assert(F);
   auto It = Funcs.find(F);
   return It == Funcs.end() ? nullptr : It->second.get();
 }
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -83,7 +83,7 @@
 bool CheckInit(InterpState &S, CodePtr OpPC, const Pointer &Ptr);
 
 /// Checks if a method can be called.
-bool CheckCallable(InterpState &S, CodePtr OpPC, Function *F);
+bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F);
 
 /// Checks the 'this' pointer.
 bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This);
@@ -1347,9 +1347,11 @@
 if (!CheckInvoke(S, PC, NewFrame->getThis())) {
   return false;
 }
-// TODO: CheckCallable
   }
 
+  if (!CheckCallable(S, PC, Func))
+return false;
+
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -338,17 +338,18 @@
   return true;
 }
 
-bool CheckCallable(InterpState &S, CodePtr OpPC, Function *F) {
-  const SourceLocation &Loc = S.Current->getLocation(OpPC);
+bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
 
   if (F->isVirtual()) {
 if (!S.getLangOpts().CPlusPlus20) {
+  const SourceLocation &Loc = S.Current->getLocation(OpPC);
   S.CCEDiag(Loc, diag::note_constexpr_virtual_call);
   return false;
 }
   }
 
   if (!F->isConstexpr()) {
+const SourceLocation &Loc = S.Current->getLocation(OpPC);
 if (S.getLangOpts().CPlusPlus11) {
   const FunctionDecl *DiagDecl = F->getDecl();
 
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -135,6 +135,9 @@
 
   bool hasThisPointer() const { return HasThisPointer; }
 
+  // Checks if the funtion already has a body attached.
+  bool hasBody() const { return HasBody; }
+
   unsigned getNumParams() const { return ParamTypes.size(); }
 
 private:
@@ -152,6 +155,7 @@
 SrcMap = std::move(NewSrcMap);
 Scopes = std::move(NewScopes);
 IsValid = true;
+HasBody = true;
   }
 
   void setIsFullyCompiled(bool FC) { IsFullyCompiled = FC; }
@@ -192,6 +196,8 @@
   /// the return value is constructed in the caller's stack frame.
   /// This is done for functions that return non-primive values.
   bool HasRVO = false;
+  /// If we've already compile

[clang] fd448bb - [clang][LTO] Passing vec-extabi to the Backend on AIX

2022-10-28 Thread Qiongsi Wu via cfe-commits

Author: Qiongsi Wu
Date: 2022-10-28T09:13:17-04:00
New Revision: fd448bbedce91bcc6aad9072af58a4fcb7f7bf70

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

LOG: [clang][LTO] Passing vec-extabi to the Backend on AIX

This patch passes on the `vec-extabi` mabi option on AIX.

Reviewed By: w2yehia

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/lto-aix.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 3feb1a2a63af3..1fcd160b76fab 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -599,6 +599,10 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
 options::OPT_gno_strict_dwarf, true))
   CmdArgs.push_back(
   Args.MakeArgString(Twine(PluginOptPrefix) + "-strict-dwarf=true"));
+
+if (Args.getLastArg(options::OPT_mabi_EQ_vec_extabi))
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine(PluginOptPrefix) + "-vec-extabi"));
   }
 
   bool UseSeparateSections =

diff  --git a/clang/test/Driver/lto-aix.c b/clang/test/Driver/lto-aix.c
index 88e7eaa4d5df0..e12fa1c3afaee 100644
--- a/clang/test/Driver/lto-aix.c
+++ b/clang/test/Driver/lto-aix.c
@@ -27,6 +27,16 @@
 // O2: "-bplugin_opt:-O2"
 // O3: "-bplugin_opt:-O3"
 //
+// vec-extabi option
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -mabi=vec-extabi -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=VECEXTABI %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -### 2>&1 | FileCheck --check-prefix=NOVECEXTABI %s
+//
+// VECEXTABI: "-bplugin_opt:-vec-extabi"
+// NOVECEXTABI-NOT: "-bplugin_opt:-vec-extabi"
+//
 // Test debugging options
 // RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \
 // RUN:   | FileCheck -check-prefix=DBX %s



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


[PATCH] D136874: [clang][LTO] Passing vec-extabi to the Backend on AIX

2022-10-28 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd448bbedce9: [clang][LTO] Passing vec-extabi to the Backend 
on AIX (authored by Qiongsi Wu ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136874

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/lto-aix.c


Index: clang/test/Driver/lto-aix.c
===
--- clang/test/Driver/lto-aix.c
+++ clang/test/Driver/lto-aix.c
@@ -27,6 +27,16 @@
 // O2: "-bplugin_opt:-O2"
 // O3: "-bplugin_opt:-O3"
 //
+// vec-extabi option
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -mabi=vec-extabi -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=VECEXTABI %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -### 2>&1 | FileCheck --check-prefix=NOVECEXTABI %s
+//
+// VECEXTABI: "-bplugin_opt:-vec-extabi"
+// NOVECEXTABI-NOT: "-bplugin_opt:-vec-extabi"
+//
 // Test debugging options
 // RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \
 // RUN:   | FileCheck -check-prefix=DBX %s
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -599,6 +599,10 @@
 options::OPT_gno_strict_dwarf, true))
   CmdArgs.push_back(
   Args.MakeArgString(Twine(PluginOptPrefix) + "-strict-dwarf=true"));
+
+if (Args.getLastArg(options::OPT_mabi_EQ_vec_extabi))
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine(PluginOptPrefix) + "-vec-extabi"));
   }
 
   bool UseSeparateSections =


Index: clang/test/Driver/lto-aix.c
===
--- clang/test/Driver/lto-aix.c
+++ clang/test/Driver/lto-aix.c
@@ -27,6 +27,16 @@
 // O2: "-bplugin_opt:-O2"
 // O3: "-bplugin_opt:-O3"
 //
+// vec-extabi option
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -mabi=vec-extabi -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=VECEXTABI %s
+// RUN: %clang --target=powerpc-ibm-aix --sysroot %S/Inputs/aix_ppc_tree %s \
+// RUN:   -fuse-ld=ld -flto -### 2>&1 | FileCheck --check-prefix=NOVECEXTABI %s
+//
+// VECEXTABI: "-bplugin_opt:-vec-extabi"
+// NOVECEXTABI-NOT: "-bplugin_opt:-vec-extabi"
+//
 // Test debugging options
 // RUN: %clang --target=powerpc-ibm-aix -### %s -flto -fuse-ld=ld -gdbx 2>&1 \
 // RUN:   | FileCheck -check-prefix=DBX %s
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -599,6 +599,10 @@
 options::OPT_gno_strict_dwarf, true))
   CmdArgs.push_back(
   Args.MakeArgString(Twine(PluginOptPrefix) + "-strict-dwarf=true"));
+
+if (Args.getLastArg(options::OPT_mabi_EQ_vec_extabi))
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine(PluginOptPrefix) + "-vec-extabi"));
   }
 
   bool UseSeparateSections =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133052: [clang] Avoid crash when expanding conversion templates in concepts.

2022-10-28 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 added a comment.

My suggestion would be to properly handle cycles in 
`CheckConstraintSatisfaction`. This problem goes beyond cycles introduced by 
conversion. See #53213  and 
#44304  
https://godbolt.org/z/v41ez6eW4. These two bugs are due to an assertion failure 
while inserting entry into SatisfactionCache.

My suggestion would be detect cycles in `CheckConstraintSatisfaction`. We 
already have a way to check "whether we have seen this before ?" in 
`SatisfactionCache` using `FoldingSet` for `ConstraintSatisfaction`. We could 
use a similar set to track the constraints being evaluated. Stop evaluation 
when we detect a cycle. Attach appropriate details to the Satisfaction and fail 
the constraint.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133052

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


[PATCH] D136942: [C2x] Add test coverage for WG14 N2322

2022-10-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I had two suggestions for more tests, but this is probably covering everything.




Comment at: clang/test/C/C2x/n2322.c:44
+  ) == 2007);
+}
+

I might suggest:

_Static_assert(555 == __\
LI\
NE\
__)

Which, is basically exactly what the first bullet point in J.1 is trying to 
figure out (it should be the opening character).

I think this is a repeat of the string-literal test, but it is basically 
exactly what they were talking about with PP-token.

Not a great addition to this file perhaps, but something with #warning might be 
a nice exercise of the pp-directive, to make sure it hits the diagnostics 
engine right?




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136942

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


[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 471528.
TIFitis added a comment.

Moved loadOffloadInfoMetadata inside OpenMPIRBuilder class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136872

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4692,6 +4692,61 @@
   }
 }
 
+/// Loads all the offload entries information from the host IR
+/// metadata.
+void OpenMPIRBuilder::loadOffloadInfoMetadata(
+Module &M, OffloadEntriesInfoManager &OffloadEntriesInfoManager,
+bool isDevice) {
+  // If we are in target mode, load the metadata from the host IR. This code has
+  // to match the metadaata creation in createOffloadEntriesAndInfoMetadata().
+
+  if (!isDevice)
+return;
+
+  NamedMDNode *MD = M.getNamedMetadata(ompOffloadInfoName);
+  if (!MD)
+return;
+
+  for (MDNode *MN : MD->operands()) {
+auto &&GetMDInt = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return cast(V->getValue())->getZExtValue();
+};
+
+auto &&GetMDString = [MN](unsigned Idx) {
+  auto *V = cast(MN->getOperand(Idx));
+  return V->getString();
+};
+
+switch (GetMDInt(0)) {
+default:
+  llvm_unreachable("Unexpected metadata!");
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoTargetRegion:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
+  /*DeviceID=*/GetMDInt(1), /*FileID=*/GetMDInt(2),
+  /*ParentName=*/GetMDString(3), /*Line=*/GetMDInt(4),
+  /*Order=*/GetMDInt(5));
+  break;
+case OffloadEntriesInfoManager::OffloadEntryInfo::
+OffloadingEntryInfoDeviceGlobalVar:
+  assert(isDevice && "Initialization of entries is "
+ "only required for the "
+ "device code generation.");
+  OffloadEntriesInfoManager.initializeDeviceGlobalVarEntryInfo(
+  /*MangledName=*/GetMDString(1),
+  static_cast(
+  /*Flags=*/GetMDInt(2)),
+  /*Order=*/GetMDInt(3));
+  break;
+}
+  }
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -70,6 +70,212 @@
 BasicBlock *splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
   llvm::Twine Suffix = ".split");
 
+/// Class that manages information about offload code regions and data
+class OffloadEntriesInfoManager {
+  /// Number of entries registered so far.
+  unsigned OffloadingEntriesNum = 0;
+
+public:
+  /// Base class of the entries info.
+  class OffloadEntryInfo {
+  public:
+/// Kind of a given entry.
+enum OffloadingEntryInfoKinds : unsigned {
+  /// Entry is a target region.
+  OffloadingEntryInfoTargetRegion = 0,
+  /// Entry is a declare target variable.
+  OffloadingEntryInfoDeviceGlobalVar = 1,
+  /// Invalid entry info.
+  OffloadingEntryInfoInvalid = ~0u
+};
+
+  protected:
+OffloadEntryInfo() = delete;
+explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) : Kind(Kind) {}
+explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order,
+  uint32_t Flags)
+: Flags(Flags), Order(Order), Kind(Kind) {}
+~OffloadEntryInfo() = default;
+
+  public:
+bool isValid() const { return Order != ~0u; }
+unsigned getOrder() const { return Order; }
+OffloadingEntryInfoKinds getKind() const { return Kind; }
+uint32_t getFlags() const { return Flags; }
+void setFlags(uint32_t NewFlags) { Flags = NewFlags; }
+Constant *getAddress() const { return cast_or_null(Addr); }
+void setAddress(Constant *V) {
+  assert(!Addr.pointsToAliveValue() && "Address has been set before!");
+  Addr = V;
+}
+static bool classof(const OffloadEntryInfo *Info) { return true; }
+
+  private:
+/// Address of the entity that has to be mapped for offloading.
+WeakTrackingVH Addr;
+
+/// Flags associated with the device global.
+uint32_t Flags = 0u;
+
+/// Order this entry was emitted.
+unsigned Order = ~0u;
+
+OffloadingEntryInfoKinds Kind = OffloadingEntryInfoInvalid;
+  };
+
+  /// Return true if a ther

[PATCH] D136872: [OpenMP][OpenMPIRBuilder] Migrate loadOffloadInfoMetadata from clang to OMPIRbuilder

2022-10-28 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 3 inline comments as done.
TIFitis added inline comments.



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:4717
+  if (!isDevice)
+return;
+

jdoerfert wrote:
> Why do we call it if isDevice is false? Module should be available to the 
> IRBuilder.
loadOffloadInfoMetadata is called from clang with a different Module generated 
using parseBitcodeFile. I've checked that the module available from 
OMPIRBuilder and the one passed by clang are different and cause errors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136872

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


[PATCH] D136920: [clang][Interp] Array initialization via CXXConstructExpr

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 471534.

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

https://reviews.llvm.org/D136920

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/arrays.cpp

Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -181,6 +181,18 @@
   }
 };
 
+class A {
+public:
+  int a;
+  constexpr A() : a(10) {}
+};
+class B {
+public:
+  A a[2];
+  constexpr B() {}
+};
+constexpr B b;
+
 namespace IncDec {
   // FIXME: Pointer arithmethic needs to be supported in inc/dec
   //   unary operators
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -270,6 +270,9 @@
 return FPO.getRoundingMode();
   }
 
+  bool callFunction(const Function *Func, unsigned NumArgs,
+const Expr *const *Args, const Expr *E);
+
 protected:
   /// Variable to storage mapping.
   llvm::DenseMap Locals;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1007,6 +1007,29 @@
   assert(false && "default initializer for non-primitive type");
 }
 
+return true;
+  } else if (const auto *Ctor = dyn_cast(Initializer)) {
+const ArrayType *AT = Ctor->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();
+const Function *Func = getFunction(Ctor->getConstructor());
+if (!Func || !Func->isConstexpr())
+  return false;
+
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!this->emitDupPtr(Initializer))
+return false;
+  if (!this->emitConstUint64(I, Initializer))
+return false;
+  if (!this->emitAddOffsetUint64(Initializer))
+return false;
+  if (!this->emitNarrowPtr(Initializer))
+return false;
+
+  if (!this->callFunction(Func, Ctor->getNumArgs(), Ctor->getArgs(),
+  Initializer))
+return false;
+}
 return true;
   }
 
@@ -1030,13 +1053,8 @@
 if (!this->emitDupPtr(Initializer))
   return false;
 
-// Constructor arguments.
-for (const auto *Arg : CtorExpr->arguments()) {
-  if (!this->visit(Arg))
-return false;
-}
-
-return this->emitCall(Func, Initializer);
+return this->callFunction(Func, CtorExpr->getNumArgs(), CtorExpr->getArgs(),
+  Initializer);
   } else if (const auto *InitList = dyn_cast(Initializer)) {
 const Record *R = getRecord(InitList->getType());
 
@@ -1161,6 +1179,20 @@
   return Func;
 }
 
+template 
+bool ByteCodeExprGen::callFunction(const Function *Func,
+unsigned NumArgs,
+const Expr *const *Args,
+const Expr *E) {
+  // Constructor arguments.
+  for (unsigned I = 0; I != NumArgs; ++I) {
+if (!this->visit(Args[I]))
+  return false;
+  }
+
+  return this->emitCall(Func, E);
+}
+
 template 
 bool ByteCodeExprGen::visitExpr(const Expr *Exp) {
   ExprScope RootScope(this);
@@ -1249,16 +1281,10 @@
   }
 }
 
-// Put arguments on the stack.
-for (const auto *Arg : E->arguments()) {
-  if (!this->visit(Arg))
-return false;
-}
-
-// In any case call the function. The return value will end up on the stack and
-// if the function has RVO, we already have the pointer on the stack to write
-// the result into.
-if (!this->emitCall(Func, E))
+// Emit arguments and call the function. The return value will end up on the
+// stack and if the function has RVO, we already have the pointer on the
+// stack to write the result into.
+if (!this->callFunction(Func, E->getNumArgs(), E->getArgs(), E))
   return false;
 
 if (DiscardResult && !ReturnType->isVoidType() && T)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-10-28 Thread Guillot Tony via Phabricator via cfe-commits
to268 updated this revision to Diff 471535.
to268 added a comment.

Reworked the parsing side of the patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133289

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

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1184,7 +1184,7 @@
 
   Type inference for object declarations
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm";>N3007
-  No
+  Clang 16
 
 
   constexpr for object definitions
Index: clang/test/Sema/c2x-auto.c
===
--- /dev/null
+++ clang/test/Sema/c2x-auto.c
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x %s
+
+void test_basic_types(void) {
+  auto undefined; // expected-error {{declaration of variable 'undefined' with deduced type 'auto' requires an initializer}}
+  auto auto_int = 4;
+  auto auto_long = 4UL;
+}
+
+void test_sizeof_typeof(void) {
+  auto auto_size = sizeof(auto);  // expected-error {{expected expression}}
+  typeof(auto) tpof = 4;  // expected-error {{expected expression}}
+}
+
+void test_casts(void) {
+  auto int_cast = (int)(4 + 3);
+  auto double_cast = (double)(1 / 3);
+  auto long_cast = (long)(4UL + 3UL);
+  auto auto_cast = (auto)(4 + 3); // expected-error {{expected expression}}
+}
+
+void test_compound_literral(void) {
+  auto int_cl = (int){13};
+  auto double_cl = (double){2.5};
+
+  // FIXME: This should be accepted per C2x 6.5.2.5p4
+  auto auto_cl = (auto){13};  // expected-error {{'auto' is not allowed in a compound literal}}
+  auto array[] = { 1, 2, 3 }; // expected-error {{'array' declared as array of 'auto'}}
+}
+
+void test_qualifiers(const int y) {
+  const auto a = 12;
+  auto b = y;
+  static auto c = 1UL;
+  int* pa = &a; // expected-warning {{initializing 'int *' with an expression of type 'const int *' discards qualifiers}}
+  const int* pb = &b;
+  int* pc = &c; // expected-warning {{incompatible pointer types initializing 'int *' with an expression of type 'unsigned long *'}}
+
+}
+
+void test_strings(void) {
+  auto str = "this is a string";
+  // FIXME: This should work for char*
+  auto str2[] = "this is a string"; // expected-error {{str2' declared as array of 'auto'}}
+  auto (str3) = "this is a string";
+  auto (((str4))) = "this is a string";
+}
+
+// FIXME: All these statements should fails (cannot declare a variable as a auto*)
+void test_pointers(void) {
+  auto a = 12;
+  auto *ptr = &a;
+  auto *str = "this is a string";
+  const auto *str2 = "this is a string";
+  auto *b = &a;
+  *b = &a;  // expected-error {{incompatible pointer to integer conversion assigning to 'int' from 'int *'; remove &}}
+}
+
+void test_scopes(void) {
+  {
+auto a = 7;
+auto b = 9;
+auto c = a + b;
+  }
+  {
+auto d = a * b;   // expected-error {{use of undeclared identifier 'a'}} \
+ expected-error {{use of undeclared identifier 'b'}}
+{
+  auto e = d + c; // expected-error {{use of undeclared identifier 'c'}}
+}
+  }
+}
Index: clang/test/Parser/c2x-auto.c
===
--- /dev/null
+++ clang/test/Parser/c2x-auto.c
@@ -0,0 +1,123 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c2x -std=c2x %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c17 -std=c17 %s
+
+#define AUTO_MACRO(_NAME, ARG, ARG2, ARG3) \
+  auto _NAME = ARG + (ARG2 / ARG3);
+
+struct S {
+int a;
+auto b;   // c2x-error {{'auto' not allowed in struct member}} \
+ c17-error {{type name does not allow storage class to be specified}} \
+ c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
+union {
+  char c;
+  auto smth;  // c2x-error {{'auto' not allowed in union member}} \
+ c17-error {{type name does not allow storage class to be specified}} \
+ c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
+} u;
+};
+
+enum E : auto { // c2x-error {{'auto' not allowed here}} \
+   c17-error {{expected a type}} \
+   c17-error {{type name does not allow storage class to be specified}}
+  One,
+  Two,
+  Tree,
+};
+
+auto basic_usage(auto auto) {   // c2x-error {{'auto' not allowed in function prototype}} \
+   c2x-error {{'auto' not allowed in function return type}} \
+   c2x-error {{cannot combi

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

2022-10-28 Thread Nicolai Hähnle via cfe-commits

Author: Nicolai Hähnle
Date: 2022-10-28T15:48:20+02:00
New Revision: dce78646f07ff67f7d4887525e908dbf47d9e86b

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

LOG: clang-tblgen build: avoid duplicate inclusion of libLLVMSupport

TableGen executables are supposed to never be linked against libLLVM-*.so,
even when LLVM_LINK_LLVM_DYLIB=ON, presumably for cross-compilation.

It turns out that clang-tblgen *did* link against libLLVM-*.so,
indirectly so via the clangSupport.

This lead to a regression in what should have been unrelated work of
cleaning up ManagedStatics in LLVMSupport. A running clang-tblgen
process ended up with two copies of a cl::opt static global:

- one from libLLVMSupport linked statically into clang-tblgen as a
  direct dependency
- one from libLLVMSupport linked into libLLVM-*.so, which clang-tblgen
  linked against due to the clangSupport dependency

For a bit more context, see the discussion at
https://discourse.llvm.org/t/flang-aarch64-dylib-buildbot-need-help-understanding-a-regression-in-clang-tblgen/64871/

None of the potential solutions I could find are perfect. Presumably one
possible solution would be to remove "Support" from the explicit
dependencies of clang-tblgen. However, relying on the transitive
inclusion via clangSupport seems risky, and in any case this wouldn't
address the issue of clang-tblgen surprisingly linking against libLLVM-*.so.

This change instead creates a second version of the clangSupport library
that is explicitly linked statically, to be used by clang-tblgen.

v2:
- define an alias so that clang-tblgen can always link against
  "clangSupport_tablegen"
- use add_llvm_library(... BUILDTREE_ONLY ...)

v3:
- use the object library version of clangSupport if available

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

Added: 


Modified: 
clang/lib/Support/CMakeLists.txt
clang/utils/TableGen/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Support/CMakeLists.txt 
b/clang/lib/Support/CMakeLists.txt
index c24324bd7b0d3..8ea5620052ed8 100644
--- a/clang/lib/Support/CMakeLists.txt
+++ b/clang/lib/Support/CMakeLists.txt
@@ -9,8 +9,24 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-add_clang_library(clangSupport
+set(clangSupport_sources
   RISCVVIntrinsicUtils.cpp
   )
 
+add_clang_library(clangSupport ${clangSupport_sources})
+
+if (NOT XCODE)
+  add_library(clangSupport_tablegen ALIAS obj.clangSupport)
+elseif (NOT LLVM_LINK_LLVM_DYLIB)
+  add_library(clangSupport_tablegen ALIAS clangSupport)
+else()
+  # Build a version of the support library that does not link against
+  # libLLVM-*.so, to be used by clang-tblgen. This is so clang-tblgen doesn't
+  # link against libLLVMSupport twice (once statically and once via
+  # libLLVM-*.so).
+  add_llvm_library(clangSupport_tablegen
+BUILDTREE_ONLY STATIC DISABLE_LLVM_LINK_LLVM_DYLIB
+${clangSupport_sources})
+endif()
+
 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS_OLD})

diff  --git a/clang/utils/TableGen/CMakeLists.txt 
b/clang/utils/TableGen/CMakeLists.txt
index 4666d4d7aa5ce..f136cbfee5fa1 100644
--- a/clang/utils/TableGen/CMakeLists.txt
+++ b/clang/utils/TableGen/CMakeLists.txt
@@ -25,6 +25,6 @@ add_tablegen(clang-tblgen CLANG
   TableGen.cpp
   )
 
-target_link_libraries(clang-tblgen PRIVATE clangSupport)
+target_link_libraries(clang-tblgen PRIVATE clangSupport_tablegen)
 
 set_target_properties(clang-tblgen PROPERTIES FOLDER "Clang tablegenning")



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


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

2022-10-28 Thread Nicolai Hähnle via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdce78646f07f: clang-tblgen build: avoid duplicate inclusion 
of libLLVMSupport (authored by nhaehnle).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134637

Files:
  clang/lib/Support/CMakeLists.txt
  clang/utils/TableGen/CMakeLists.txt


Index: clang/utils/TableGen/CMakeLists.txt
===
--- clang/utils/TableGen/CMakeLists.txt
+++ clang/utils/TableGen/CMakeLists.txt
@@ -25,6 +25,6 @@
   TableGen.cpp
   )
 
-target_link_libraries(clang-tblgen PRIVATE clangSupport)
+target_link_libraries(clang-tblgen PRIVATE clangSupport_tablegen)
 
 set_target_properties(clang-tblgen PROPERTIES FOLDER "Clang tablegenning")
Index: clang/lib/Support/CMakeLists.txt
===
--- clang/lib/Support/CMakeLists.txt
+++ clang/lib/Support/CMakeLists.txt
@@ -9,8 +9,24 @@
   Support
   )
 
-add_clang_library(clangSupport
+set(clangSupport_sources
   RISCVVIntrinsicUtils.cpp
   )
 
+add_clang_library(clangSupport ${clangSupport_sources})
+
+if (NOT XCODE)
+  add_library(clangSupport_tablegen ALIAS obj.clangSupport)
+elseif (NOT LLVM_LINK_LLVM_DYLIB)
+  add_library(clangSupport_tablegen ALIAS clangSupport)
+else()
+  # Build a version of the support library that does not link against
+  # libLLVM-*.so, to be used by clang-tblgen. This is so clang-tblgen doesn't
+  # link against libLLVMSupport twice (once statically and once via
+  # libLLVM-*.so).
+  add_llvm_library(clangSupport_tablegen
+BUILDTREE_ONLY STATIC DISABLE_LLVM_LINK_LLVM_DYLIB
+${clangSupport_sources})
+endif()
+
 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS_OLD})


Index: clang/utils/TableGen/CMakeLists.txt
===
--- clang/utils/TableGen/CMakeLists.txt
+++ clang/utils/TableGen/CMakeLists.txt
@@ -25,6 +25,6 @@
   TableGen.cpp
   )
 
-target_link_libraries(clang-tblgen PRIVATE clangSupport)
+target_link_libraries(clang-tblgen PRIVATE clangSupport_tablegen)
 
 set_target_properties(clang-tblgen PROPERTIES FOLDER "Clang tablegenning")
Index: clang/lib/Support/CMakeLists.txt
===
--- clang/lib/Support/CMakeLists.txt
+++ clang/lib/Support/CMakeLists.txt
@@ -9,8 +9,24 @@
   Support
   )
 
-add_clang_library(clangSupport
+set(clangSupport_sources
   RISCVVIntrinsicUtils.cpp
   )
 
+add_clang_library(clangSupport ${clangSupport_sources})
+
+if (NOT XCODE)
+  add_library(clangSupport_tablegen ALIAS obj.clangSupport)
+elseif (NOT LLVM_LINK_LLVM_DYLIB)
+  add_library(clangSupport_tablegen ALIAS clangSupport)
+else()
+  # Build a version of the support library that does not link against
+  # libLLVM-*.so, to be used by clang-tblgen. This is so clang-tblgen doesn't
+  # link against libLLVMSupport twice (once statically and once via
+  # libLLVM-*.so).
+  add_llvm_library(clangSupport_tablegen
+BUILDTREE_ONLY STATIC DISABLE_LLVM_LINK_LLVM_DYLIB
+${clangSupport_sources})
+endif()
+
 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS_OLD})
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-10-28 Thread Guillot Tony via Phabricator via cfe-commits
to268 added a comment.

Also i'm not sure if must add C2x to this condition just in case (falling back 
or add an assertion)




Comment at: clang/lib/Sema/DeclSpec.cpp:1362
   // type specifier.
   if (S.getLangOpts().CPlusPlus &&
   TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) {

Do we need to include C2x just in case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133289

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


[PATCH] D136533: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-28 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

Is it possible that it would be one of those two bugs? 
https://github.com/llvm/llvm-project/issues?q=is%3Aopen+is%3Aissue+author%3Aldionne+availability+


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D136951: [clangd] Populate ranges and symbol origin for paramname completions

2022-10-28 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: nridge, hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136951

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -21,6 +21,7 @@
 #include "TestTU.h"
 #include "index/Index.h"
 #include "index/MemIndex.h"
+#include "index/SymbolOrigin.h"
 #include "support/Threading.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -29,6 +30,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "llvm/Testing/Support/Error.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -83,6 +85,9 @@
 MATCHER_P(snippetSuffix, Text, "") { return arg.SnippetSuffix == Text; }
 MATCHER_P(origin, OriginSet, "") { return arg.Origin == OriginSet; }
 MATCHER_P(signature, S, "") { return arg.Signature == S; }
+MATCHER_P(replacesRange, Range, "") {
+  return arg.CompletionTokenRange == Range;
+}
 
 // Shorthand for Contains(named(Name)).
 Matcher &> has(std::string Name) {
@@ -3713,7 +3718,6 @@
 }
 
 TEST(CompletionTest, CommentParamName) {
-  clangd::CodeCompleteOptions Opts;
   const std::string Code = R"cpp(
 void fun(int foo, int bar);
 void overloaded(int param_int);
@@ -3722,23 +3726,46 @@
 int main() {
   )cpp";
 
-  EXPECT_THAT(completions(Code + "fun(/*^", {}, Opts).Completions,
-  UnorderedElementsAre(labeled("foo=")));
-  EXPECT_THAT(completions(Code + "fun(1, /*^", {}, Opts).Completions,
-  UnorderedElementsAre(labeled("bar=")));
-  EXPECT_THAT(completions(Code + "/*^", {}, Opts).Completions, IsEmpty());
+  EXPECT_THAT(completions(Code + "fun(/*^").Completions,
+  UnorderedElementsAre(labeled("foo=*/")));
+  EXPECT_THAT(completions(Code + "fun(1, /*^").Completions,
+  UnorderedElementsAre(labeled("bar=*/")));
+  EXPECT_THAT(completions(Code + "/*^").Completions, IsEmpty());
   // Test de-duplication.
   EXPECT_THAT(
-  completions(Code + "overloaded(/*^", {}, Opts).Completions,
-  UnorderedElementsAre(labeled("param_int="), labeled("param_char=")));
+  completions(Code + "overloaded(/*^").Completions,
+  UnorderedElementsAre(labeled("param_int=*/"), labeled("param_char=*/")));
   // Comment already has some text in it.
-  EXPECT_THAT(completions(Code + "fun(/*  ^", {}, Opts).Completions,
-  UnorderedElementsAre(labeled("foo=")));
-  EXPECT_THAT(completions(Code + "fun(/* f^", {}, Opts).Completions,
-  UnorderedElementsAre(labeled("foo=")));
-  EXPECT_THAT(completions(Code + "fun(/* x^", {}, Opts).Completions, IsEmpty());
-  EXPECT_THAT(completions(Code + "fun(/* f ^", {}, Opts).Completions,
-  IsEmpty());
+  EXPECT_THAT(completions(Code + "fun(/*  ^").Completions,
+  UnorderedElementsAre(labeled("foo=*/")));
+  EXPECT_THAT(completions(Code + "fun(/* f^").Completions,
+  UnorderedElementsAre(labeled("foo=*/")));
+  EXPECT_THAT(completions(Code + "fun(/* x^").Completions, IsEmpty());
+  EXPECT_THAT(completions(Code + "fun(/* f ^").Completions, IsEmpty());
+
+  // Test ranges
+  {
+std::string CompletionRangeTest(Code + "fun(/*[[^]]");
+auto Results = completions(CompletionRangeTest);
+EXPECT_THAT(Results.CompletionRange,
+llvm::ValueIs(Annotations(CompletionRangeTest).range()));
+EXPECT_THAT(
+Results.Completions,
+testing::Each(
+AllOf(replacesRange(Annotations(CompletionRangeTest).range()),
+  origin(SymbolOrigin::AST), kind(CompletionItemKind::Text;
+  }
+  {
+std::string CompletionRangeTest(Code + "fun(/*[[fo^]]");
+auto Results = completions(CompletionRangeTest);
+EXPECT_THAT(Results.CompletionRange,
+llvm::ValueIs(Annotations(CompletionRangeTest).range()));
+EXPECT_THAT(
+Results.Completions,
+testing::Each(
+AllOf(replacesRange(Annotations(CompletionRangeTest).range()),
+  origin(SymbolOrigin::AST), kind(CompletionItemKind::Text;
+  }
 }
 
 TEST(CompletionTest, Concepts) {
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -2014,14 +2014,23 @@
 return CodeCompleteResult();
 
   CodeCompleteResult Result;
+  Range Com

[PATCH] D136533: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D136533#3891905 , @ldionne wrote:

> Is it possible that it would be one of those two bugs? 
> https://github.com/llvm/llvm-project/issues?q=is%3Aopen+is%3Aissue+author%3Aldionne+availability+

I don't think so.

It does look like libc++ makes some uses within itself of types which were 
marked unavailable.
It's just that we missed diagnosing those cases before, which is what this 
patch is fixing.

Ie if you see the included test case:

  struct A {
using ta [[deprecated]] = int;
  };
  using t1 = typename A::ta; // expected-warning {{'ta' is deprecated}}

We missed diagnosing that before, when performing a 'typename' member access.
The `availability` attribute is supposed to work on the same principles as 
`deprecated` does.

This is diagnosed by GCC as well, and I thought libc++ was also tested with it. 
Is that maybe not the case for those old Apple systems?

In any case, let me know if you think otherwise, or if we will need to 
implement some kind of workaround...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[clang] 8b87cb4 - [clang][Interp] Remove unused getGlobalIdx()

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T16:34:29+02:00
New Revision: 8b87cb4853409ea8066e451ee87f550a9ecd3c34

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

LOG: [clang][Interp] Remove unused getGlobalIdx()

Remove the only use with the version we already use in
VisitDeclRefExpr().

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 7e00fc4f707e..2ec14afdf9ac 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -553,7 +553,7 @@ bool ByteCodeExprGen::dereferenceVar(
 return false;
   return DiscardResult ? true : this->emitGetPtrLocal(L.Offset, LV);
 }
-  } else if (auto Idx = getGlobalIdx(VD)) {
+  } else if (auto Idx = P.getGlobal(VD)) {
 switch (AK) {
 case DerefKind::Read:
   if (!this->emitGetGlobal(T, *Idx, LV))
@@ -867,21 +867,6 @@ bool ByteCodeExprGen::visitInitializer(const Expr 
*Initializer) {
   return this->Visit(Initializer);
 }
 
-template 
-llvm::Optional
-ByteCodeExprGen::getGlobalIdx(const VarDecl *VD) {
-  if (VD->isConstexpr()) {
-// Constexpr decl - it must have already been defined.
-return P.getGlobal(VD);
-  }
-  if (!VD->hasLocalStorage()) {
-// Not constexpr, but a global var - can have pointer taken.
-Program::DeclScope Scope(P, VD);
-return P.getOrCreateGlobal(VD);
-  }
-  return {};
-}
-
 template 
 const RecordType *ByteCodeExprGen::getRecordTy(QualType Ty) {
   if (const PointerType *PT = dyn_cast(Ty))

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index d1cda8939d58..489e8bdb79ca 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -238,9 +238,6 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 return emitConst(*Ctx.classify(Ty), WrappedValue, E);
   }
 
-  /// Returns the index of a global.
-  llvm::Optional getGlobalIdx(const VarDecl *VD);
-
   /// Emits the initialized pointer.
   bool emitInitFn() {
 assert(InitFn && "missing initializer");



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


[clang] 0ccff03 - [clang][Interp] Fix record members of reference type

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T16:34:45+02:00
New Revision: 0ccff030f3b4145bd658e362a63db9aae2942bee

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

LOG: [clang][Interp] Fix record members of reference type

When assigning to them, we can't classify the expression type, because
that doesn't contain the right information.

And when reading from them, we need to do the extra deref, just like we
do when reading from a DeclRefExpr.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 2ec14afdf9ac1..cbbd6f33e685d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -343,6 +343,8 @@ bool ByteCodeExprGen::VisitMemberExpr(const 
MemberExpr *E) {
 const Record *R = getRecord(RD);
 const Record::Field *F = R->getField(FD);
 // Leave a pointer to the field on the stack.
+if (F->Decl->getType()->isReferenceType())
+  return this->emitGetFieldPop(PT_Ptr, F->Offset, E);
 return this->emitGetPtrField(F->Offset, E);
   }
 
@@ -809,7 +811,7 @@ bool ByteCodeExprGen::visitRecordInitializer(const 
Expr *Initializer) {
   if (!this->emitDupPtr(Initializer))
 return false;
 
-  if (Optional T = classify(Init->getType())) {
+  if (Optional T = classify(Init)) {
 if (!this->visit(Init))
   return false;
 

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index bdb072c3b0aa0..bbe4d04c8974b 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -105,7 +105,7 @@ bool ByteCodeStmtGen::visitFunc(const FunctionDecl 
*F) {
   if (const FieldDecl *Member = Init->getMember()) {
 const Record::Field *F = R->getField(Member);
 
-if (Optional T = this->classify(InitExpr->getType())) {
+if (Optional T = this->classify(InitExpr)) {
   if (!this->emitThis(InitExpr))
 return false;
 

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 73b1bc9bb406b..8e53a76d563f4 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -470,6 +470,8 @@ bool SetParam(InterpState &S, CodePtr OpPC, uint32_t I) {
   return true;
 }
 
+/// 1) Peeks a pointer on the stack
+/// 2) Pushes the value of the pointer's field on the stack
 template ::T>
 bool GetField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const Pointer &Obj = S.Stk.peek();
@@ -499,6 +501,8 @@ bool SetField(InterpState &S, CodePtr OpPC, uint32_t I) {
   return true;
 }
 
+/// 1) Pops a pointer from the stack
+/// 2) Pushes the value of the pointer's field on the stack
 template ::T>
 bool GetFieldPop(InterpState &S, CodePtr OpPC, uint32_t I) {
   const Pointer &Obj = S.Stk.pop();

diff  --git a/clang/test/AST/Interp/references.cpp 
b/clang/test/AST/Interp/references.cpp
index 7d2ed6058361a..0e6d5532ba0e8 100644
--- a/clang/test/AST/Interp/references.cpp
+++ b/clang/test/AST/Interp/references.cpp
@@ -88,3 +88,29 @@ constexpr int RefToMemberExpr() {
   return j;
 }
 static_assert(RefToMemberExpr() == 11, "");
+
+struct Ref {
+  int &a;
+};
+
+constexpr int RecordWithRef() {
+  int m = 100;
+  Ref r{m};
+  m = 200;
+  return r.a;
+}
+static_assert(RecordWithRef() == 200, "");
+
+
+struct Ref2 {
+  int &a;
+  constexpr Ref2(int &a) : a(a) {}
+};
+
+constexpr int RecordWithRef2() {
+  int m = 100;
+  Ref2 r(m);
+  m = 200;
+  return r.a;
+}
+static_assert(RecordWithRef2() == 200, "");



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


[PATCH] D136012: [clang][Interp] Fix record members of reference type

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
tbaeder marked an inline comment as done.
Closed by commit rG0ccff030f3b4: [clang][Interp] Fix record members of 
reference type (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136012

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


Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -88,3 +88,29 @@
   return j;
 }
 static_assert(RefToMemberExpr() == 11, "");
+
+struct Ref {
+  int &a;
+};
+
+constexpr int RecordWithRef() {
+  int m = 100;
+  Ref r{m};
+  m = 200;
+  return r.a;
+}
+static_assert(RecordWithRef() == 200, "");
+
+
+struct Ref2 {
+  int &a;
+  constexpr Ref2(int &a) : a(a) {}
+};
+
+constexpr int RecordWithRef2() {
+  int m = 100;
+  Ref2 r(m);
+  m = 200;
+  return r.a;
+}
+static_assert(RecordWithRef2() == 200, "");
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -470,6 +470,8 @@
   return true;
 }
 
+/// 1) Peeks a pointer on the stack
+/// 2) Pushes the value of the pointer's field on the stack
 template ::T>
 bool GetField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const Pointer &Obj = S.Stk.peek();
@@ -499,6 +501,8 @@
   return true;
 }
 
+/// 1) Pops a pointer from the stack
+/// 2) Pushes the value of the pointer's field on the stack
 template ::T>
 bool GetFieldPop(InterpState &S, CodePtr OpPC, uint32_t I) {
   const Pointer &Obj = S.Stk.pop();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -105,7 +105,7 @@
   if (const FieldDecl *Member = Init->getMember()) {
 const Record::Field *F = R->getField(Member);
 
-if (Optional T = this->classify(InitExpr->getType())) {
+if (Optional T = this->classify(InitExpr)) {
   if (!this->emitThis(InitExpr))
 return false;
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -343,6 +343,8 @@
 const Record *R = getRecord(RD);
 const Record::Field *F = R->getField(FD);
 // Leave a pointer to the field on the stack.
+if (F->Decl->getType()->isReferenceType())
+  return this->emitGetFieldPop(PT_Ptr, F->Offset, E);
 return this->emitGetPtrField(F->Offset, E);
   }
 
@@ -809,7 +811,7 @@
   if (!this->emitDupPtr(Initializer))
 return false;
 
-  if (Optional T = classify(Init->getType())) {
+  if (Optional T = classify(Init)) {
 if (!this->visit(Init))
   return false;
 


Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -88,3 +88,29 @@
   return j;
 }
 static_assert(RefToMemberExpr() == 11, "");
+
+struct Ref {
+  int &a;
+};
+
+constexpr int RecordWithRef() {
+  int m = 100;
+  Ref r{m};
+  m = 200;
+  return r.a;
+}
+static_assert(RecordWithRef() == 200, "");
+
+
+struct Ref2 {
+  int &a;
+  constexpr Ref2(int &a) : a(a) {}
+};
+
+constexpr int RecordWithRef2() {
+  int m = 100;
+  Ref2 r(m);
+  m = 200;
+  return r.a;
+}
+static_assert(RecordWithRef2() == 200, "");
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -470,6 +470,8 @@
   return true;
 }
 
+/// 1) Peeks a pointer on the stack
+/// 2) Pushes the value of the pointer's field on the stack
 template ::T>
 bool GetField(InterpState &S, CodePtr OpPC, uint32_t I) {
   const Pointer &Obj = S.Stk.peek();
@@ -499,6 +501,8 @@
   return true;
 }
 
+/// 1) Pops a pointer from the stack
+/// 2) Pushes the value of the pointer's field on the stack
 template ::T>
 bool GetFieldPop(InterpState &S, CodePtr OpPC, uint32_t I) {
   const Pointer &Obj = S.Stk.pop();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -105,7 +105,7 @@
   if (const FieldDecl *Member = Init->getMember()) {
 const Record::Field *F = R->getField(Member);
 
-if (Optional T = this->classify(InitExpr->getType())) {
+if (Optional T = this->classify(InitExpr)) {
   if (!this->emitThis(InitExpr))

[PATCH] D136886: [clang] [ASTImporter] RFC: Correct importer to not duplicate sugared types

2022-10-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

I agree having two different val_list types is suspect, it might not have been 
imported and is simply referring to the va_list of the original context.

One other note, is that if a problem exists for TypedefType, it probably exists 
for UsingType as well, as they are very closely related.

The one difference is that TypedefType still uses the TypeDecl scheme of 
uniquing, instead of using a FoldingSet as UsingType does, and the former is a 
bit unfriendly to the ASTImporter/ASTReader as there is a cycle there, the Decl 
holds a reference to the type and vice versa.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136886

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


[clang] 38ffc89 - [clang][Interp] Fix ignoring expression return values

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T16:45:38+02:00
New Revision: 38ffc89c87ac3b0b1c2173728fba2258dead9ae0

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

LOG: [clang][Interp] Fix ignoring expression return values

Randomly noticed this. We need to honor DiscardResult here.

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index cbbd6f33e685..20e5d2911a1f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -329,6 +329,9 @@ bool 
ByteCodeExprGen::VisitUnaryExprOrTypeTraitExpr(
 
 template 
 bool ByteCodeExprGen::VisitMemberExpr(const MemberExpr *E) {
+  if (DiscardResult)
+return true;
+
   // 'Base.Member'
   const Expr *Base = E->getBase();
   const ValueDecl *Member = E->getMemberDecl();
@@ -982,7 +985,18 @@ bool ByteCodeExprGen::VisitCallExpr(const 
CallExpr *E) {
 // In any case call the function. The return value will end up on the 
stack and
 // if the function has RVO, we already have the pointer on the stack to 
write
 // the result into.
-return this->emitCall(Func, E);
+if (!this->emitCall(Func, E))
+  return false;
+
+QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
+if (DiscardResult && !ReturnType->isVoidType()) {
+  Optional T = classify(ReturnType);
+  if (T)
+return this->emitPop(*T, E);
+  // TODO: This is a RVO function and we need to ignore the return value.
+}
+
+return true;
   } else {
 assert(false && "We don't support non-FunctionDecl callees right now.");
   }
@@ -1032,11 +1046,16 @@ bool 
ByteCodeExprGen::VisitCXXNullPtrLiteralExpr(
 
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
+  if (DiscardResult)
+return true;
   return this->emitThis(E);
 }
 
 template 
 bool ByteCodeExprGen::VisitUnaryOperator(const UnaryOperator *E) {
+  if (DiscardResult)
+return true;
+
   const Expr *SubExpr = E->getSubExpr();
 
   switch (E->getOpcode()) {

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index ca76be9b0bf9..3eba13cff188 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -279,6 +279,16 @@ namespace bitOr {
   static_assert((12 | true) == 13, "");
 };
 
+#if __cplusplus >= 201402L
+constexpr bool IgnoredUnary() {
+  bool bo = true;
+  !bo; // expected-warning {{expression result unused}} \
+   // ref-warning {{expression result unused}}
+  return bo;
+}
+static_assert(IgnoredUnary(), "");
+#endif
+
 namespace strings {
   constexpr const char *S = "abc";
   static_assert(S[0] == 97, "");

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 18caf5d8f4f0..d8ac72319c0a 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -204,6 +204,26 @@ static_assert(a2.i == 200, ""); // ref-error {{static 
assertion failed}} \
 // expected-error {{static assertion failed}} \
 // expected-note {{evaluates to '12 == 200'}}
 
+
+struct S {
+  int a = 0;
+  constexpr int get5() const { return 5; }
+  constexpr void fo() const {
+this; // expected-warning {{expression result unused}} \
+  // ref-warning {{expression result unused}}
+this->a; // expected-warning {{expression result unused}} \
+ // ref-warning {{expression result unused}}
+get5();
+  }
+
+  constexpr int m() const {
+fo();
+return 1;
+  }
+};
+constexpr S s;
+static_assert(s.m() == 1, "");
+
 namespace MI {
   class A {
   public:



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


[PATCH] D136013: [clang][Interp] Fix ignoring expression return values

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38ffc89c87ac: [clang][Interp] Fix ignoring expression return 
values (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D136013?vs=468006&id=471552#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136013

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -204,6 +204,26 @@
 // expected-error {{static assertion failed}} \
 // expected-note {{evaluates to '12 == 200'}}
 
+
+struct S {
+  int a = 0;
+  constexpr int get5() const { return 5; }
+  constexpr void fo() const {
+this; // expected-warning {{expression result unused}} \
+  // ref-warning {{expression result unused}}
+this->a; // expected-warning {{expression result unused}} \
+ // ref-warning {{expression result unused}}
+get5();
+  }
+
+  constexpr int m() const {
+fo();
+return 1;
+  }
+};
+constexpr S s;
+static_assert(s.m() == 1, "");
+
 namespace MI {
   class A {
   public:
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -279,6 +279,16 @@
   static_assert((12 | true) == 13, "");
 };
 
+#if __cplusplus >= 201402L
+constexpr bool IgnoredUnary() {
+  bool bo = true;
+  !bo; // expected-warning {{expression result unused}} \
+   // ref-warning {{expression result unused}}
+  return bo;
+}
+static_assert(IgnoredUnary(), "");
+#endif
+
 namespace strings {
   constexpr const char *S = "abc";
   static_assert(S[0] == 97, "");
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -329,6 +329,9 @@
 
 template 
 bool ByteCodeExprGen::VisitMemberExpr(const MemberExpr *E) {
+  if (DiscardResult)
+return true;
+
   // 'Base.Member'
   const Expr *Base = E->getBase();
   const ValueDecl *Member = E->getMemberDecl();
@@ -982,7 +985,18 @@
 // In any case call the function. The return value will end up on the stack and
 // if the function has RVO, we already have the pointer on the stack to write
 // the result into.
-return this->emitCall(Func, E);
+if (!this->emitCall(Func, E))
+  return false;
+
+QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
+if (DiscardResult && !ReturnType->isVoidType()) {
+  Optional T = classify(ReturnType);
+  if (T)
+return this->emitPop(*T, E);
+  // TODO: This is a RVO function and we need to ignore the return value.
+}
+
+return true;
   } else {
 assert(false && "We don't support non-FunctionDecl callees right now.");
   }
@@ -1032,11 +1046,16 @@
 
 template 
 bool ByteCodeExprGen::VisitCXXThisExpr(const CXXThisExpr *E) {
+  if (DiscardResult)
+return true;
   return this->emitThis(E);
 }
 
 template 
 bool ByteCodeExprGen::VisitUnaryOperator(const UnaryOperator *E) {
+  if (DiscardResult)
+return true;
+
   const Expr *SubExpr = E->getSubExpr();
 
   switch (E->getOpcode()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136953: [C++20] Diagnosed invalid and reserved module names

2022-10-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: iains, urnathan, ChuanqiXu, clang-language-wg.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

[module.unit]p1 specifies that `module` and `import` are invalid components of 
a module name, that module names cannot contain reserved identifiers, and that 
`std` followed by zero or more digits is reserved.

The first issue (`module` and `import` pseudo-keywords) requires a diagnostic, 
the second issue (use of reserved identifiers) does not require a diagnostic. 
We diagnose both the same -- the code is ill-formed unless the module 
declaration is in a system header. This allows STL implementations to use the 
reserved module names while preventing users from stealing them out from under 
us.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136953

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/reserved-names.cpp


Index: clang/test/Modules/reserved-names.cpp
===
--- /dev/null
+++ clang/test/Modules/reserved-names.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// expected-note@1 14{{add 'module;' to the start of the file to introduce a 
global module fragment}}
+
+module std;// expected-error {{'std' is a reserved name for a module}}
+module _Test;  // expected-error {{'_Test' is a reserved name for a module}} \
+  expected-error {{module declaration must occur at the start 
of the translation unit}}
+module module; // expected-error {{'module' is an invalid name for a module}} \
+  expected-error {{module declaration must occur at the start 
of the translation unit}}
+module std0;   // expected-error {{'std0' is a reserved name for a module}} \
+  expected-error {{module declaration must occur at the start 
of the translation unit}}
+
+export module module; // expected-error {{'module' is an invalid name for a 
module}} \
+ expected-error {{module declaration must occur at the 
start of the translation unit}}
+export module import; // expected-error {{'import' is an invalid name for a 
module}} \
+ expected-error {{module declaration must occur at the 
start of the translation unit}}
+export module _Test;  // expected-error {{'_Test' is a reserved name for a 
module}} \
+ expected-error {{module declaration must occur at the 
start of the translation unit}}
+export module __test; // expected-error {{'__test' is a reserved name for a 
module}} \
+ expected-error {{module declaration must occur at the 
start of the translation unit}}
+export module te__st; // expected-error {{'te__st' is a reserved name for a 
module}} \
+ expected-error {{module declaration must occur at the 
start of the translation unit}}
+export module std;// expected-error {{'std' is a reserved name for a 
module}} \
+ expected-error {{module declaration must occur at the 
start of the translation unit}}
+export module std0;   // expected-error {{'std0' is a reserved name for a 
module}} \
+ expected-error {{module declaration must occur at the 
start of the translation unit}}
+export module std100; // expected-error {{'std100' is a reserved name 
for a module}} \
+ expected-error {{module declaration must occur at the 
start of the translation unit}}
+
+export module should_fail.std0;  // expected-error {{'std0' is a reserved name 
for a module}} \
+expected-error {{module declaration must 
occur at the start of the translation unit}}
+export module should_fail._Test; // expected-error {{'_Test' is a reserved 
name for a module}} \
+expected-error {{module declaration must 
occur at the start of the translation unit}}
+
+// Show that we suppress the diagnostic in a system header.
+# 100 "file.cpp" 1 3 // Enter a system header
+export module std;   // expected-error {{module declaration must occur at the 
start of the translation unit}}
+# 100 "file.cpp" 2 3 // Leave the system header
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -238,6 +238,33 @@
 }
   }
 
+  // C++2b [module.unit]p1: ... The identifiers module and import shall not
+  // appear as identifiers in a module-name or module-partition. All
+  // module-names either beginning with an identifier consisting of std
+  // followed by zero or more digits or containing a reserved identifier
+  // ([lex.name]) are reserved and shall not be specified in a
+  // module-declaration; no diagnostic is required.
+  for (auto Part : P

[PATCH] D136942: [C2x] Add test coverage for WG14 N2322

2022-10-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 471554.
aaron.ballman marked an inline comment as done.
aaron.ballman added a comment.

Added an additional test case.


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

https://reviews.llvm.org/D136942

Files:
  clang/test/C/C2x/n2322.c
  clang/www/c_status.html


Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -696,7 +696,15 @@
 
   Preprocessor line numbers unspecified
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2322.htm";>N2322
-  Yes
+  
+Partial
+The line number associated with a macro invocation is not the line
+number of the first character of the macro name in the invocation.
+Additionally, Clang may not associate the line number of a pp-directive
+with the first # token. As these are recommended practices
+and not normative requirements, Clang's behavior is still conforming.
+
+  
 
 
   deprecated attribute
Index: clang/test/C/C2x/n2322.c
===
--- /dev/null
+++ clang/test/C/C2x/n2322.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -std=c2x -ast-dump %s | FileCheck %s
+
+/* WG14 N2322: partial
+ * Preprocessor line numbers unspecified
+ */
+void n2322() {
+  // The line number associated with a pp-token should be the line number of
+  // the first character of the pp-token.
+  "this string literal  \
+   spans multiple lines \
+   before terminating";
+// CHECK: ImplicitCastExpr {{.*}} 
+
+  // The line number associated with a pp-directive should be the line number
+  // of the line with the first # token.
+  // Possible FIXME: The AST node should be on line 1002 if we take the line
+  // number to be associated with the first # token. However, this relies on an
+  // interpretation of the standard definition of "presumed line" to be before
+  // line splices are removed. The standard leaves this unspecified, so this
+  // may not represent an actual issue.
+  #\
+  line\
+  1000
+  "string literal";
+// CHECK: ImplicitCastExpr {{.*}} 
+
+  // The line number associated with a macro invocation should be the line
+  // number of the first character of the macro name in the invocation.
+  //
+  // Reset the line number to make it easier to understand the next test.
+  // FIXME: The line number should be 2005 (first letter of the macro name) and
+  // not 2007 (closing parenthesis of the macro invocation).
+  #line 2000
+  #define F( \
+)\
+_\
+_LINE__
+
+  _Static_assert(F(\
+  \
+  ) == 2007);
+
+  // Reset the line number again for ease.
+  #line 2000
+  _Static_assert(2001 == \
+__LI\
+NE__\
+  );
+}


Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -696,7 +696,15 @@
 
   Preprocessor line numbers unspecified
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2322.htm";>N2322
-  Yes
+  
+Partial
+The line number associated with a macro invocation is not the line
+number of the first character of the macro name in the invocation.
+Additionally, Clang may not associate the line number of a pp-directive
+with the first # token. As these are recommended practices
+and not normative requirements, Clang's behavior is still conforming.
+
+  
 
 
   deprecated attribute
Index: clang/test/C/C2x/n2322.c
===
--- /dev/null
+++ clang/test/C/C2x/n2322.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -std=c2x -ast-dump %s | FileCheck %s
+
+/* WG14 N2322: partial
+ * Preprocessor line numbers unspecified
+ */
+void n2322() {
+  // The line number associated with a pp-token should be the line number of
+  // the first character of the pp-token.
+  "this string literal  \
+   spans multiple lines \
+   before terminating";
+// CHECK: ImplicitCastExpr {{.*}} 
+
+  // The line number associated with a pp-directive should be the line number
+  // of the line with the first # token.
+  // Possible FIXME: The AST node should be on line 1002 if we take the line
+  // number to be associated with the first # token. However, this relies on an
+  // interpretation of the standard definition of "presumed line" to be before
+  // line splices are removed. The standard leaves this unspecified, so this
+  // may not represent an actual issue.
+  #\
+  line\
+  1000
+  "string literal";
+// CHECK: ImplicitCastExpr {{.*}} 
+
+  // The line number associated with a macro invocation should be the line
+  // number of the first character of the macro name in the invocation.
+  //
+  // Reset the line number to make it easier to understand the next test.
+  // FIXME: The line number should be 2005 (first letter of the macro name) and
+  // not 2

[PATCH] D136942: [C2x] Add test coverage for WG14 N2322

2022-10-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/C/C2x/n2322.c:44
+  ) == 2007);
+}
+

erichkeane wrote:
> I might suggest:
> 
> _Static_assert(555 == __\
> LI\
> NE\
> __)
> 
> Which, is basically exactly what the first bullet point in J.1 is trying to 
> figure out (it should be the opening character).
> 
> I think this is a repeat of the string-literal test, but it is basically 
> exactly what they were talking about with PP-token.
> 
> Not a great addition to this file perhaps, but something with #warning might 
> be a nice exercise of the pp-directive, to make sure it hits the diagnostics 
> engine right?
> 
> 
I've added the test.


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

https://reviews.llvm.org/D136942

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


[PATCH] D136942: [C2x] Add test coverage for WG14 N2322

2022-10-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

I'm OK with this either way, I think you've proved out the important cases.


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

https://reviews.llvm.org/D136942

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


[PATCH] D136826: [clang][Interp] Make sure we free() allocated InitMaps

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee9bbfa5e6ac: [clang][Interp] Make sure we free() allocated 
InitMaps (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136826

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/InterpBlock.h
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h


Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -47,6 +47,13 @@
 // here manually so they are properly freeing their resources.
 for (auto RecordPair : Records)
   RecordPair.second->~Record();
+
+// Manually destroy all the blocks. They are almost all harmless,
+// but primitive arrays might have an InitMap* heap allocated and
+// that needs to be freed.
+for (Global *G : Globals) {
+  G->block()->invokeDtor();
+}
   }
 
   /// Marshals a native pointer to an ID for embedding in bytecode.
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -64,6 +64,7 @@
   unsigned Sz = Desc->getAllocSize();
   auto *G = new (Allocator, Sz) Global(Desc, /*isStatic=*/true,
/*isExtern=*/false);
+  G->block()->invokeCtor();
   Globals.push_back(G);
 
   // Construct the string in storage.
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -143,7 +143,7 @@
   Descriptor *Desc = getFieldDesc();
   assert(Desc);
   if (Desc->isPrimitiveArray()) {
-if (Pointee->IsStatic)
+if (isStatic() && Base == 0)
   return true;
 // Primitive array field are stored in a bitset.
 InitMap *Map = getInitMap();
@@ -164,7 +164,11 @@
 
   assert(Desc);
   if (Desc->isArray()) {
-if (Desc->isPrimitiveArray() && !Pointee->IsStatic) {
+if (Desc->isPrimitiveArray()) {
+  // Primitive global arrays don't have an initmap.
+  if (isStatic() && Base == 0)
+return;
+
   // Primitive array initializer.
   InitMap *&Map = getInitMap();
   if (Map == (InitMap *)-1)
Index: clang/lib/AST/Interp/InterpBlock.h
===
--- clang/lib/AST/Interp/InterpBlock.h
+++ clang/lib/AST/Interp/InterpBlock.h
@@ -73,6 +73,12 @@
/*isActive=*/true, Desc);
   }
 
+  // Invokes the Destructor.
+  void invokeDtor() {
+if (Desc->DtorFn)
+  Desc->DtorFn(this, data(), Desc);
+  }
+
 protected:
   friend class Pointer;
   friend class DeadBlock;
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -39,6 +39,11 @@
 
 template 
 static void dtorArrayTy(Block *, char *Ptr, Descriptor *D) {
+  InitMap *IM = *reinterpret_cast(Ptr);
+  if (IM != (InitMap *)-1)
+free(IM);
+
+  Ptr += sizeof(InitMap *);
   for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
 reinterpret_cast(Ptr)[I].~T();
   }
@@ -178,7 +183,7 @@
 }
 
 static BlockDtorFn getDtorArrayPrim(PrimType Type) {
-  COMPOSITE_TYPE_SWITCH(Type, return dtorArrayTy, return nullptr);
+  TYPE_SWITCH(Type, return dtorArrayTy);
 }
 
 static BlockMoveFn getMoveArrayPrim(PrimType Type) {


Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -47,6 +47,13 @@
 // here manually so they are properly freeing their resources.
 for (auto RecordPair : Records)
   RecordPair.second->~Record();
+
+// Manually destroy all the blocks. They are almost all harmless,
+// but primitive arrays might have an InitMap* heap allocated and
+// that needs to be freed.
+for (Global *G : Globals) {
+  G->block()->invokeDtor();
+}
   }
 
   /// Marshals a native pointer to an ID for embedding in bytecode.
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -64,6 +64,7 @@
   unsigned Sz = Desc->getAllocSize();
   auto *G = new (Allocator, Sz) Global(Desc, /*isStatic=*/true,
/*isExtern=*/false);
+  G->block()->invokeCtor();
   Globals.push_back(G);
 
   // Construct the string in storage.
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -143,7 +14

[clang] ee9bbfa - [clang][Interp] Make sure we free() allocated InitMaps

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T17:00:15+02:00
New Revision: ee9bbfa5e6acaea6d2a116bc29b7086441f86b6a

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

LOG: [clang][Interp] Make sure we free() allocated InitMaps

They get allocated when calling initialize() on a primitive array. And
they get free'd when the array is fully initialized. However, when that
never happens, they get leaked. Fix that by calling the destructor of
global variables.

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

Added: 


Modified: 
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/Pointer.cpp
clang/lib/AST/Interp/Program.cpp
clang/lib/AST/Interp/Program.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 34240ed4352d..55182ec383fa 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -39,6 +39,11 @@ static void ctorArrayTy(Block *, char *Ptr, bool, bool, 
bool, Descriptor *D) {
 
 template 
 static void dtorArrayTy(Block *, char *Ptr, Descriptor *D) {
+  InitMap *IM = *reinterpret_cast(Ptr);
+  if (IM != (InitMap *)-1)
+free(IM);
+
+  Ptr += sizeof(InitMap *);
   for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
 reinterpret_cast(Ptr)[I].~T();
   }
@@ -178,7 +183,7 @@ static BlockCtorFn getCtorArrayPrim(PrimType Type) {
 }
 
 static BlockDtorFn getDtorArrayPrim(PrimType Type) {
-  COMPOSITE_TYPE_SWITCH(Type, return dtorArrayTy, return nullptr);
+  TYPE_SWITCH(Type, return dtorArrayTy);
 }
 
 static BlockMoveFn getMoveArrayPrim(PrimType Type) {

diff  --git a/clang/lib/AST/Interp/InterpBlock.h 
b/clang/lib/AST/Interp/InterpBlock.h
index e4e693dab093..9c0b5612b9fa 100644
--- a/clang/lib/AST/Interp/InterpBlock.h
+++ b/clang/lib/AST/Interp/InterpBlock.h
@@ -73,6 +73,12 @@ class Block final {
/*isActive=*/true, Desc);
   }
 
+  // Invokes the Destructor.
+  void invokeDtor() {
+if (Desc->DtorFn)
+  Desc->DtorFn(this, data(), Desc);
+  }
+
 protected:
   friend class Pointer;
   friend class DeadBlock;

diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index ad4e4e8a8a85..c7d9c3a5cd11 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -143,7 +143,7 @@ bool Pointer::isInitialized() const {
   Descriptor *Desc = getFieldDesc();
   assert(Desc);
   if (Desc->isPrimitiveArray()) {
-if (Pointee->IsStatic)
+if (isStatic() && Base == 0)
   return true;
 // Primitive array field are stored in a bitset.
 InitMap *Map = getInitMap();
@@ -164,7 +164,11 @@ void Pointer::initialize() const {
 
   assert(Desc);
   if (Desc->isArray()) {
-if (Desc->isPrimitiveArray() && !Pointee->IsStatic) {
+if (Desc->isPrimitiveArray()) {
+  // Primitive global arrays don't have an initmap.
+  if (isStatic() && Base == 0)
+return;
+
   // Primitive array initializer.
   InitMap *&Map = getInitMap();
   if (Map == (InitMap *)-1)

diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index cca59bee1f20..8ad48976f33d 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -64,6 +64,7 @@ unsigned Program::createGlobalString(const StringLiteral *S) {
   unsigned Sz = Desc->getAllocSize();
   auto *G = new (Allocator, Sz) Global(Desc, /*isStatic=*/true,
/*isExtern=*/false);
+  G->block()->invokeCtor();
   Globals.push_back(G);
 
   // Construct the string in storage.

diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index 1a175d8b0f20..5123dde88c87 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -47,6 +47,13 @@ class Program final {
 // here manually so they are properly freeing their resources.
 for (auto RecordPair : Records)
   RecordPair.second->~Record();
+
+// Manually destroy all the blocks. They are almost all harmless,
+// but primitive arrays might have an InitMap* heap allocated and
+// that needs to be freed.
+for (Global *G : Globals) {
+  G->block()->invokeDtor();
+}
   }
 
   /// Marshals a native pointer to an ID for embedding in bytecode.



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


[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

2022-10-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:257
+else if (PartName.startswith("std") &&
+ (PartName.size() == 3 || isDigit(PartName.drop_front(3)[0])))
+  Reason = /*reserved*/ 1;





Comment at: clang/lib/Sema/SemaModule.cpp:262
+// diagnose (because we expect system headers to use reserved identifiers).
+if (Reason != -1 && !getSourceManager().isInSystemHeader(Part.second)) {
+  Diag(Part.second, diag::err_invalid_module_name) << Part.first << Reason;

I think `module` in a standard header is still invalid. We could not do the 
check in a  system header at all



Comment at: clang/test/Modules/reserved-names.cpp:37
+# 100 "file.cpp" 1 3 // Enter a system header
+export module std;   // expected-error {{module declaration must occur at the 
start of the translation unit}}
+# 100 "file.cpp" 2 3 // Leave the system header

you should add a test for `__test`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136953

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


[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

2022-10-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I'll leave it to the modules experts to decide whether they're happy with this, 
but I had a drive-by.

Also, I see none of the tests validate 'import', just 'export'.  Based on the 
standard, BOTH are illegal, right :D




Comment at: clang/lib/Sema/SemaModule.cpp:248
+  for (auto Part : Path) {
+int Reason = -1;
+const IdentifierInfo *II = Part.first;

Urgh, could you make this an enum?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136953

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


[clang] 524c640 - [clang][DebugInfo] Emit DISubprogram for extern functions with reserved names

2022-10-28 Thread Yonghong Song via cfe-commits

Author: Eduard Zingerman
Date: 2022-10-28T08:07:54-07:00
New Revision: 524c640090a8463305acbafd7606f1db3c1256e2

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

LOG: [clang][DebugInfo] Emit DISubprogram for extern functions with reserved 
names

Callsite `DISubprogram` entries are not generated for:
- builtin functions;
- external functions with reserved names (e.g. names starting from "__").

This limitation was added by the commit [1] as a workaround for the
situation described in [2] that triggered the IR verifier error.
The goal of the present commit is to lift this limitation by adjusting
the IR verifier logic.

The logic behind [1] is to avoid the following situation:
- a `DISubprogram` is added for some builtin function;
- there is some location where this builtin is also emitted by a
  transformation (w/o debug location);
- the `Verifier::visitCallBase` sees a call to a function with
  `DISubprogram` but w/o debug location and emits an error.

Here is an updated example of such situation taken from [2]:

```
extern "C" int memcmp(void *, void *, long);

struct a { int b; int c; int d; };

struct e { int f[1000]; };

bool foo(e g, e &h) {
  // DISubprogram for memcmp is created here when [1] is commented out
  return memcmp(&g, &h, sizeof(e));
}

bool bar(a &g, a &h) {
  // memcmp might be generated here by MergeICmps
  return g.b == h.b && g.c == h.c && g.d == h.d;
}
```

This triggers the verifier error when:
- compiled for AArch64:
  `clang++ -c -g -Oz -target aarch64-unknown-linux-android21 test.cpp`;
- [1] check is commented out.

Instead of forbidding generation of `DISubprogram` entries as in [1]
one can instead adjust the verifier to additionally check if callee
has a body. Functions w/o bodies cannot be inlined and thus verifier
warning is not necessary.

E.g. `llvm::InlineFunction` requires functions for which
`GlobalValue::isDeclaration() == false`.

[1] 568db780bb7267651a902da8e85bc59fc89aea70
[2] https://bugs.chromium.org/p/chromium/issues/detail?id=1022296

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-info-extern-call.c
llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/callsite-dbgloc.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index aa02821aa971..4b56e155022a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4228,17 +4228,11 @@ void 
CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
   if (Func->getSubprogram())
 return;
 
-  // Do not emit a declaration subprogram for a builtin, a function with 
nodebug
-  // attribute, or if call site info isn't required. Also, elide declarations
-  // for functions with reserved names, as call site-related features aren't
-  // interesting in this case (& also, the compiler may emit calls to these
-  // functions without debug locations, which makes the verifier complain).
-  if (CalleeDecl->getBuiltinID() != 0 || CalleeDecl->hasAttr() ||
+  // Do not emit a declaration subprogram for a function with nodebug
+  // attribute, or if call site info isn't required.
+  if (CalleeDecl->hasAttr() ||
   getCallSiteRelatedAttrs() == llvm::DINode::FlagZero)
 return;
-  if (CalleeDecl->isReserved(CGM.getLangOpts()) !=
-  ReservedIdentifierStatus::NotReserved)
-return;
 
   // If there is no DISubprogram attached to the function being called,
   // create the one describing the function in order to have complete

diff  --git a/clang/test/CodeGen/debug-info-extern-call.c 
b/clang/test/CodeGen/debug-info-extern-call.c
index fad52d0df0b3..0d18dc436040 100644
--- a/clang/test/CodeGen/debug-info-extern-call.c
+++ b/clang/test/CodeGen/debug-info-extern-call.c
@@ -29,8 +29,8 @@
 // DECLS-FOR-EXTERN: [[FN1_TYPES]] = !{[[X_TYPE:![0-9]+]],
 // DECLS-FOR-EXTERN: [[X_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: 
"x",
 // DECLS-FOR-EXTERN-SAME: baseType: [[INT_TYPE]])
-// DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "memcmp"
-// DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "__some_reserved_name"
+// DECLS-FOR-EXTERN: !DISubprogram(name: "memcmp"
+// DECLS-FOR-EXTERN: !DISubprogram(name: "__some_reserved_name"
 
 // NO-DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "fn1"
 // NO-DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "memcmp"

diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 06f03164c19e..0614f206981a 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3468,9 +3468,11 @@ void Verifier::visitCallBase(CallBase &Call) {
   // Verify that each inlinable callsite of a debug-info-bearing function in a
   // debug-info-bearing function has a debug location attached to it. Failure 

[PATCH] D136041: [clang][DebugInfo] Emit DISubprogram for extern functions with reserved names

2022-10-28 Thread Yonghong Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG524c640090a8: [clang][DebugInfo] Emit DISubprogram for 
extern functions with reserved names (authored by eddyz87, committed by 
yonghong-song).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136041

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-extern-call.c
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/callsite-dbgloc.ll


Index: llvm/test/Verifier/callsite-dbgloc.ll
===
--- llvm/test/Verifier/callsite-dbgloc.ll
+++ llvm/test/Verifier/callsite-dbgloc.ll
@@ -33,18 +33,24 @@
   ret void, !dbg !22
 }
 
-declare void @i(...) #1
+declare !dbg !23 void @i(...) #1
 
 ; Function Attrs: nounwind ssp uwtable
 define void @g() #0 !dbg !11 {
 entry:
 ; Manually removed !dbg.
 ; CHECK: inlinable function call in a function with debug info must have a 
!dbg location
+; CHECK: @h()
   call void @h()
 ; CHECK-NOT: inlinable function call in a function with debug info must have a 
!dbg location
+; CHECK-NOT: @j()
   call void @j()
 ; CHECK: inlinable function call in a function with debug info must have a 
!dbg location
+; CHECK: @k()
   call void @k()
+; CHECK-NOT: inlinable function call in a function with debug info must have a 
!dbg location
+; CHECK-NOT: @i()
+  call void (...) @i()
   ret void, !dbg !13
 }
 
@@ -86,3 +92,6 @@
 !20 = distinct !DISubprogram(name: "k", scope: !1, file: !1, line: 6, type: 
!8, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: false, unit: 
!0, retainedNodes: !2)
 !21 = !DILocation(line: 4, column: 12, scope: !20)
 !22 = !DILocation(line: 4, column: 17, scope: !20)
+!23 = !DISubprogram(name: "i", scope: !1, file: !1, line: 1, type: !24, flags: 
DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
+!24 = !DISubroutineType(types: !25)
+!25 = !{null}
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -3468,9 +3468,11 @@
   // Verify that each inlinable callsite of a debug-info-bearing function in a
   // debug-info-bearing function has a debug location attached to it. Failure 
to
   // do so causes assertion failures when the inliner sets up inline scope info
-  // (Interposable functions are not inlinable).
+  // (Interposable functions are not inlinable, neither are functions without
+  //  definitions.)
   if (Call.getFunction()->getSubprogram() && Call.getCalledFunction() &&
   !Call.getCalledFunction()->isInterposable() &&
+  !Call.getCalledFunction()->isDeclaration() &&
   Call.getCalledFunction()->getSubprogram())
 CheckDI(Call.getDebugLoc(),
 "inlinable function call in a function with "
Index: clang/test/CodeGen/debug-info-extern-call.c
===
--- clang/test/CodeGen/debug-info-extern-call.c
+++ clang/test/CodeGen/debug-info-extern-call.c
@@ -29,8 +29,8 @@
 // DECLS-FOR-EXTERN: [[FN1_TYPES]] = !{[[X_TYPE:![0-9]+]],
 // DECLS-FOR-EXTERN: [[X_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: 
"x",
 // DECLS-FOR-EXTERN-SAME: baseType: [[INT_TYPE]])
-// DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "memcmp"
-// DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "__some_reserved_name"
+// DECLS-FOR-EXTERN: !DISubprogram(name: "memcmp"
+// DECLS-FOR-EXTERN: !DISubprogram(name: "__some_reserved_name"
 
 // NO-DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "fn1"
 // NO-DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "memcmp"
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4228,17 +4228,11 @@
   if (Func->getSubprogram())
 return;
 
-  // Do not emit a declaration subprogram for a builtin, a function with 
nodebug
-  // attribute, or if call site info isn't required. Also, elide declarations
-  // for functions with reserved names, as call site-related features aren't
-  // interesting in this case (& also, the compiler may emit calls to these
-  // functions without debug locations, which makes the verifier complain).
-  if (CalleeDecl->getBuiltinID() != 0 || CalleeDecl->hasAttr() ||
+  // Do not emit a declaration subprogram for a function with nodebug
+  // attribute, or if call site info isn't required.
+  if (CalleeDecl->hasAttr() ||
   getCallSiteRelatedAttrs() == llvm::DINode::FlagZero)
 return;
-  if (CalleeDecl->isReserved(CGM.getLangOpts()) !=
-  ReservedIdentifierStatus::NotReserved)
-return;
 
   // If there is no DISubprogram attached to the function being called,
   // create the one describing the function in order to have complete


Index: llvm/test/Verifier/callsite-dbgloc.ll
===
--- llv

[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

2022-10-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D136953#3892060 , @erichkeane 
wrote:

> I'll leave it to the modules experts to decide whether they're happy with 
> this, but I had a drive-by.
>
> Also, I see none of the tests validate 'import', just 'export'.  Based on the 
> standard, BOTH are illegal, right :D

`export module export` is perfectly ~~fine~~ conforming


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136953

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


[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

2022-10-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked 2 inline comments as done.
aaron.ballman added a comment.

In D136953#3892077 , @cor3ntin wrote:

> In D136953#3892060 , @erichkeane 
> wrote:
>
>> I'll leave it to the modules experts to decide whether they're happy with 
>> this, but I had a drive-by.
>>
>> Also, I see none of the tests validate 'import', just 'export'.  Based on 
>> the standard, BOTH are illegal, right :D

Heh, Erich is joking about my malicious reading of the standard where 
module-name has blanket wording for what is reserved, but that same grammar 
production is used with importing modules. e.g., a malicious reading of the 
standard could make you think `import module std;` is also invalid because it's 
using a reserved module name.

> `export module export` is perfectly ~~fine~~ conforming

Nope, that's not going to compile because `export` is a real keyword instead of 
an identifier masquerading as a keyword like `module` and `import`.




Comment at: clang/lib/Sema/SemaModule.cpp:248
+  for (auto Part : Path) {
+int Reason = -1;
+const IdentifierInfo *II = Part.first;

erichkeane wrote:
> Urgh, could you make this an enum?
Absolutely.



Comment at: clang/lib/Sema/SemaModule.cpp:257
+else if (PartName.startswith("std") &&
+ (PartName.size() == 3 || isDigit(PartName.drop_front(3)[0])))
+  Reason = /*reserved*/ 1;

cor3ntin wrote:
> 
lol but my way is so much more complicated, so it must be more right... ;-)



Comment at: clang/lib/Sema/SemaModule.cpp:262
+// diagnose (because we expect system headers to use reserved identifiers).
+if (Reason != -1 && !getSourceManager().isInSystemHeader(Part.second)) {
+  Diag(Part.second, diag::err_invalid_module_name) << Part.first << Reason;

cor3ntin wrote:
> I think `module` in a standard header is still invalid. We could not do the 
> check in a  system header at all
Good catch, that's a think-o on my part!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136953

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


[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

2022-10-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:257
+else if (PartName.startswith("std") &&
+ (PartName.size() == 3 || isDigit(PartName.drop_front(3)[0])))
+  Reason = /*reserved*/ 1;

aaron.ballman wrote:
> cor3ntin wrote:
> > 
> lol but my way is so much more complicated, so it must be more right... ;-)
Is this logic right?  By my reading of the standard, 

`export module stdFoo.bar` << fine
`export module std00Foo.bar` << fine

as neither  'consist of std followed by zero or more digits'.

This patch looks like it'll only allow the 1st, but not the 2nd.  



Comment at: clang/test/Modules/reserved-names.cpp:30
+
+export module should_fail.std0;  // expected-error {{'std0' is a reserved name 
for a module}} \
+expected-error {{module declaration must 
occur at the start of the translation unit}}

SHOULD this fail?  

This is NOT a module name beginning with an identifier-consisting-of-std 
followed by 0 or more digits.

The 'containing' part applies to just the reserved identifiers.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136953

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


[PATCH] D136956: [clang][Interp] Implement BitXor opcode

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136956

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


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -279,6 +279,18 @@
   static_assert((12 | true) == 13, "");
 };
 
+namespace bitXor {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wxor-used-as-pow"
+  static_assert((10 ^ 1) == 11, "");
+  static_assert((10 ^ 10) == 0, "");
+
+  static_assert((1337 ^ -1) == -1338, "");
+  static_assert((0 | gimme(12)) == 12, "");
+  static_assert((12 ^ true) == 13, "");
+#pragma clang diagnostic pop
+};
+
 #if __cplusplus >= 201402L
 constexpr bool IgnoredUnary() {
   bool bo = true;
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -419,6 +419,7 @@
   let Types = [NumberTypeClass];
   let HasGroup = 1;
 }
+def BitXor : IntegerOpcode;
 
 
//===--===//
 // Unary operators.
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -211,6 +211,23 @@
   return false;
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS ^ RHS' on the stack
+template ::T>
+bool BitXor(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::bitXor(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from the stack.
 /// 3) Pushes 'LHS % RHS' on the stack (the remainder of dividing LHS by RHS).
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -227,6 +227,11 @@
 return false;
   }
 
+  static bool bitXor(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V ^ B.V);
+return false;
+  }
+
   static bool neg(Integral A, Integral *R) {
 *R = -A;
 return false;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -241,6 +241,8 @@
 return Discard(this->emitBitAnd(*T, BO));
   case BO_Or:
 return Discard(this->emitBitOr(*T, BO));
+  case BO_Xor:
+return Discard(this->emitBitXor(*T, BO));
   case BO_LAnd:
   case BO_LOr:
   default:


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -279,6 +279,18 @@
   static_assert((12 | true) == 13, "");
 };
 
+namespace bitXor {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wxor-used-as-pow"
+  static_assert((10 ^ 1) == 11, "");
+  static_assert((10 ^ 10) == 0, "");
+
+  static_assert((1337 ^ -1) == -1338, "");
+  static_assert((0 | gimme(12)) == 12, "");
+  static_assert((12 ^ true) == 13, "");
+#pragma clang diagnostic pop
+};
+
 #if __cplusplus >= 201402L
 constexpr bool IgnoredUnary() {
   bool bo = true;
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -419,6 +419,7 @@
   let Types = [NumberTypeClass];
   let HasGroup = 1;
 }
+def BitXor : IntegerOpcode;
 
 //===--===//
 // Unary operators.
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -211,6 +211,23 @@
   return false;
 }
 
+/// 1) Pops the RHS from the stack.
+/// 2) Pops the LHS from the stack.
+/// 3) Pushes 'LHS ^ RHS' on the stack
+template ::T>
+bool BitXor(InterpState &S, CodePtr OpPC) {
+  const T &RHS = S.Stk.pop();
+  const T &LHS = S.Stk.pop();
+
+  unsigned Bits = RHS.bitWidth();
+  T Result;
+  if (!T::bitXor(LHS, RHS, Bits, &Result)) {
+S.Stk.push(Result);
+return true;
+  }
+  return false;
+}
+
 /// 1) Pops the RHS from the stack.
 /// 2) Pops the LHS from

[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

2022-10-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:257
+else if (PartName.startswith("std") &&
+ (PartName.size() == 3 || isDigit(PartName.drop_front(3)[0])))
+  Reason = /*reserved*/ 1;

erichkeane wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > 
> > lol but my way is so much more complicated, so it must be more right... ;-)
> Is this logic right?  By my reading of the standard, 
> 
> `export module stdFoo.bar` << fine
> `export module std00Foo.bar` << fine
> 
> as neither  'consist of std followed by zero or more digits'.
> 
> This patch looks like it'll only allow the 1st, but not the 2nd.  
I've been wondering the same, I think the standard is a bit confusing in that 
regard.
`std00Foo` is "std followed by 0 or more digit".



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136953

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


[PATCH] D136953: [C++20] Diagnose invalid and reserved module names

2022-10-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaModule.cpp:257
+else if (PartName.startswith("std") &&
+ (PartName.size() == 3 || isDigit(PartName.drop_front(3)[0])))
+  Reason = /*reserved*/ 1;

cor3ntin wrote:
> erichkeane wrote:
> > aaron.ballman wrote:
> > > cor3ntin wrote:
> > > > 
> > > lol but my way is so much more complicated, so it must be more right... 
> > > ;-)
> > Is this logic right?  By my reading of the standard, 
> > 
> > `export module stdFoo.bar` << fine
> > `export module std00Foo.bar` << fine
> > 
> > as neither  'consist of std followed by zero or more digits'.
> > 
> > This patch looks like it'll only allow the 1st, but not the 2nd.  
> I've been wondering the same, I think the standard is a bit confusing in that 
> regard.
> `std00Foo` is "std followed by 0 or more digit".
> 
But it isn't 'consisting' of that, it is consisting of std, 0 or more digits, 
then 'Foo'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136953

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


[PATCH] D136957: [AArch64] Add support for the Cortex-A715 CPU

2022-10-28 Thread Simi Pallipurath via Phabricator via cfe-commits
simpal01 created this revision.
simpal01 added reviewers: vhscampos, dmgreen, stuij.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
simpal01 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Cortex-A715 is an Armv9-A AArch64 CPU.

This patch introduces support for Cortex-A715.

Technical Reference Manual: 
https://developer.arm.com/documentation/101590/latest.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136957

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-mcpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1016,6 +1016,19 @@
  AArch64::AEK_FLAGM | AArch64::AEK_SB |
  AArch64::AEK_I8MM | AArch64::AEK_BF16,
  "9-A"),
+ARMCPUTestParams("cortex-a715", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP | AArch64::AEK_BF16 |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_MTE | AArch64::AEK_PAUTH |
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SSBS |
+ AArch64::AEK_SB | AArch64::AEK_I8MM |
+ AArch64::AEK_PERFMON | AArch64::AEK_PREDRES |
+ AArch64::AEK_PROFILE | AArch64::AEK_FP16FML |
+ AArch64::AEK_FP16 | AArch64::AEK_FLAGM,
+ "9-A"),
 ARMCPUTestParams(
 "neoverse-v1", "armv8.4-a", "crypto-neon-fp-armv8",
 AArch64::AEK_RAS | AArch64::AEK_SVE | AArch64::AEK_SSBS |
@@ -1296,7 +1309,7 @@
  "8.2-A")));
 
 // Note: number of CPUs includes aliases.
-static constexpr unsigned NumAArch64CPUArchs = 59;
+static constexpr unsigned NumAArch64CPUArchs = 60;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -64,6 +64,7 @@
 CortexA78,
 CortexA78C,
 CortexA710,
+CortexA715,
 CortexR82,
 CortexX1,
 CortexX1C,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -142,6 +142,7 @@
 MaxBytesForLoopAlignment = 8;
 break;
   case CortexA710:
+  case CortexA715:
   case CortexX2:
 PrefFunctionLogAlignment = 4;
 VScaleForTuning = 1;
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -764,6 +764,12 @@
FeatureLSLFast,
FeaturePostRAScheduler]>;
 
+def TuneA715 : SubtargetFeature<"a715", "ARMProcFamily", "CortexA715",
+ "Cortex-A715 ARM processors", [
+ FeatureFuseAES,
+ FeaturePostRAScheduler,
+ FeatureCmpBccFusion]>;
+
 def TuneR82 : SubtargetFeature<"cortex-r82", "ARMProcFamily",
"CortexR82",
"Cortex-R82 ARM processors", [
@@ -1093,6 +1099,10 @@
   list A710 = [HasV9_0aOps, FeatureNEON, FeaturePerfMon,
  FeatureETE, FeatureMTE, FeatureFP16FML,
  FeatureSVE2BitPerm, FeatureBF16, FeatureMatMulInt8];
+  list A715 = [HasV9_0aOps, FeatureNEON, FeatureMTE,
+ FeatureFP16FML, FeatureSVE, FeatureTRBE,
+ FeatureSVE2BitPerm, FeatureBF16, FeatureETE,
+ FeaturePerfMon, FeatureMatMulInt8, FeatureSPE];
   list R82  = [HasV8_0rOps, FeaturePerfMon, FeatureFullFP16,
  FeatureFP16FML, FeatureSSBS, FeaturePredRes,
  FeatureSB];
@@ -1231,6 +1241,8 @@

[clang] 974e2e6 - [RISCV] Adjust RV64I data layout by using n32:64 in layout string

2022-10-28 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2022-10-28T08:27:03-07:00
New Revision: 974e2e690b4024c2677dde26cc76ec31e0047c1d

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

LOG: [RISCV] Adjust RV64I data layout by using n32:64 in layout string

Although i32 type is illegal in the backend, RV64I has pretty good support for 
i32 types by using W instructions.

By adding n32 to the DataLayout string, middle end optimizations will consider 
i32 to be a native type. One known effect of this is enabling 
LoopStrengthReduce on loops with i32 induction variables. This can be 
beneficial because C/C++ code often has loops with i32 induction variables due 
to the use of `int` or `unsigned int`.

If this patch exposes performance issues, those are better addressed by tuning 
LSR or other passes.

Reviewed By: asb, frasercrmck

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

Added: 


Modified: 
clang/lib/Basic/Targets/RISCV.h
llvm/docs/ReleaseNotes.rst
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
llvm/test/CodeGen/RISCV/aext-to-sext.ll
llvm/test/CodeGen/RISCV/loop-strength-reduce-add-cheaper-than-mul.ll
llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 868b1bd5ad04..a80fbbd7a095 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -140,7 +140,7 @@ class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public 
RISCVTargetInfo {
   : RISCVTargetInfo(Triple, Opts) {
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
 IntMaxType = Int64Type = SignedLong;
-resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
+resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
   }
 
   bool setABI(const std::string &Name) override {

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 1515fe47be37..9205d24346e0 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -119,6 +119,9 @@ Changes to the RISC-V Backend
 
 * Support for the unratified Zbe, Zbf, Zbm, Zbp, Zbr, and Zbt extensions have
   been removed.
+* i32 is now a native type in the datalayout string. This enables
+  LoopStrengthReduce for loops with i32 induction variables, among other
+  optimizations.
 
 Changes to the WebAssembly Backend
 --

diff  --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index d1732a7dee99..15961c32ea8b 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -4847,6 +4847,14 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, 
StringRef TT) {
 return DL.empty() ? std::string("G1") : (DL + "-G1").str();
   }
 
+  if (T.isRISCV64()) {
+// Make i32 a native type for 64-bit RISC-V.
+auto I = DL.find("-n64-");
+if (I != StringRef::npos)
+  return (DL.take_front(I) + "-n32:64-" + DL.drop_front(I + 5)).str();
+return DL.str();
+  }
+
   std::string Res = DL.str();
   if (!T.isX86())
 return Res;

diff  --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp 
b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
index 2f5ea98c7d4d..d4529442df4e 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -69,7 +69,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void 
LLVMInitializeRISCVTarget() {
 
 static StringRef computeDataLayout(const Triple &TT) {
   if (TT.isArch64Bit())
-return "e-m:e-p:64:64-i64:64-i128:128-n64-S128";
+return "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128";
   assert(TT.isArch32Bit() && "only RV32 and RV64 are currently supported");
   return "e-m:e-p:32:32-i64:64-n32-S128";
 }

diff  --git a/llvm/test/CodeGen/RISCV/aext-to-sext.ll 
b/llvm/test/CodeGen/RISCV/aext-to-sext.ll
index 4a533a187af6..806c495fa677 100644
--- a/llvm/test/CodeGen/RISCV/aext-to-sext.ll
+++ b/llvm/test/CodeGen/RISCV/aext-to-sext.ll
@@ -11,24 +11,21 @@
 define void @quux(i32 signext %arg, i32 signext %arg1) nounwind {
 ; RV64I-LABEL: quux:
 ; RV64I:   # %bb.0: # %bb
-; RV64I-NEXT:addi sp, sp, -32
-; RV64I-NEXT:sd ra, 24(sp) # 8-byte Folded Spill
-; RV64I-NEXT:sd s0, 16(sp) # 8-byte Folded Spill
-; RV64I-NEXT:sd s1, 8(sp) # 8-byte Folded Spill
+; RV64I-NEXT:addi sp, sp, -16
+; RV64I-NEXT:sd ra, 8(sp) # 8-byte Folded Spill
+; RV64I-NEXT:sd s0, 0(sp) # 8-byte Folded Spill
 ; RV64I-NEXT:beq a0, a1, .LBB0_3
 ; RV64I-NEXT:  # %bb.1: # %bb2.preheader
-; RV64I-NEXT:mv s0, a1
-; RV64I-NEXT:mv s1, a0
+; RV64I

[PATCH] D116735: [RISCV] Adjust RV64I data layout by using n32:64 in layout string

2022-10-28 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG974e2e690b40: [RISCV] Adjust RV64I data layout by using 
n32:64 in layout string (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D116735?vs=471385&id=471564#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116735

Files:
  clang/lib/Basic/Targets/RISCV.h
  llvm/docs/ReleaseNotes.rst
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/test/CodeGen/RISCV/aext-to-sext.ll
  llvm/test/CodeGen/RISCV/loop-strength-reduce-add-cheaper-than-mul.ll
  llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
  llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp

Index: llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
===
--- llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
+++ llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
@@ -31,6 +31,11 @@
   // Check that AMDGPU targets add -G1 if it's not present.
   EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32", "r600"), "e-p:32:32-G1");
   EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64", "amdgcn"), "e-p:64:64-G1");
+
+  // Check that RISCV64 upgrades -n64 to -n32:64.
+  EXPECT_EQ(UpgradeDataLayoutString("e-m:e-p:64:64-i64:64-i128:128-n64-S128",
+"riscv64"),
+"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
 }
 
 TEST(DataLayoutUpgradeTest, NoDataLayoutUpgrade) {
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
===
--- llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
@@ -286,14 +286,12 @@
 ; RV64-NEXT:addi a1, a1, %lo(.LCPI12_0)
 ; RV64-NEXT:vsetivli zero, 4, e32, m1, ta, ma
 ; RV64-NEXT:vlse32.v v8, (a1), zero
-; RV64-NEXT:li a1, 0
-; RV64-NEXT:li a2, 1024
+; RV64-NEXT:li a1, 1024
 ; RV64-NEXT:  .LBB12_1: # =>This Inner Loop Header: Depth=1
-; RV64-NEXT:slli a3, a1, 2
-; RV64-NEXT:add a3, a0, a3
-; RV64-NEXT:addiw a1, a1, 4
-; RV64-NEXT:vse32.v v8, (a3)
-; RV64-NEXT:bne a1, a2, .LBB12_1
+; RV64-NEXT:vse32.v v8, (a0)
+; RV64-NEXT:addiw a1, a1, -4
+; RV64-NEXT:addi a0, a0, 16
+; RV64-NEXT:bnez a1, .LBB12_1
 ; RV64-NEXT:  # %bb.2:
 ; RV64-NEXT:ret
   br label %2
Index: llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
===
--- llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
+++ llvm/test/CodeGen/RISCV/rvv/fixed-vector-strided-load-store-asm.ll
@@ -794,20 +794,20 @@
 ; CHECK-NEXT:  # %bb.4:
 ; CHECK-NEXT:beq a4, a5, .LBB12_7
 ; CHECK-NEXT:  .LBB12_5:
-; CHECK-NEXT:slli a2, a3, 2
-; CHECK-NEXT:add a2, a2, a3
-; CHECK-NEXT:add a1, a1, a2
-; CHECK-NEXT:li a2, 1024
+; CHECK-NEXT:addiw a2, a3, -1024
+; CHECK-NEXT:add a0, a0, a3
+; CHECK-NEXT:slli a4, a3, 2
+; CHECK-NEXT:add a3, a4, a3
+; CHECK-NEXT:add a1, a1, a3
 ; CHECK-NEXT:  .LBB12_6: # =>This Inner Loop Header: Depth=1
-; CHECK-NEXT:lb a4, 0(a1)
-; CHECK-NEXT:add a5, a0, a3
-; CHECK-NEXT:lb a6, 0(a5)
-; CHECK-NEXT:addw a4, a6, a4
-; CHECK-NEXT:sb a4, 0(a5)
-; CHECK-NEXT:addiw a4, a3, 1
-; CHECK-NEXT:addi a3, a3, 1
+; CHECK-NEXT:lb a3, 0(a1)
+; CHECK-NEXT:lb a4, 0(a0)
+; CHECK-NEXT:addw a3, a4, a3
+; CHECK-NEXT:sb a3, 0(a0)
+; CHECK-NEXT:addiw a2, a2, 1
+; CHECK-NEXT:addi a0, a0, 1
 ; CHECK-NEXT:addi a1, a1, 5
-; CHECK-NEXT:bne a4, a2, .LBB12_6
+; CHECK-NEXT:bnez a2, .LBB12_6
 ; CHECK-NEXT:  .LBB12_7:
 ; CHECK-NEXT:ret
   %4 = icmp eq i32 %2, 1024
Index: llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
===
--- llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
+++ llvm/test/CodeGen/RISCV/loop-strength-reduce-loop-invar.ll
@@ -53,25 +53,24 @@
 ; RV64:   # %bb.0: # %entry
 ; RV64-NEXT:blez a1, .LBB0_3
 ; RV64-NEXT:  # %bb.1: # %cond_true.preheader
-; RV64-NEXT:li a4, 0
+; RV64-NEXT:li a2, 0
 ; RV64-NEXT:slli a0, a0, 6
-; RV64-NEXT:lui a2, %hi(A)
-; RV64-NEXT:addi a2, a2, %lo(A)
-; RV64-NEXT:add a0, a2, a0
-; RV64-NEXT:li a2, 4
-; RV64-NEXT:li a3, 5
+; RV64-NEXT:lui a3, %hi(A)
+; RV64-NEXT:addi a3, a3, %lo(A)
+; RV64-NEXT:add a0, a3, a0
+; RV64-NEXT:addi a3, a0, 4
+; RV64-NEXT:li a4, 4
+; RV64-NEXT:li a5, 5
 ; RV64-NEXT:  .LBB0_2: # %cond_true
 ; RV64-NEXT:# =>This Inner Loop Header: Depth=1
-; RV64-NEXT:addiw a5, a4, 1
-; RV64-NEXT:slli a6, a5, 2
+; RV64-NEXT:sw a4, 0(a3)
+; RV64-NEXT:addiw

[PATCH] D136817: [RISCV] Add H extension

2022-10-28 Thread Philip Reames via Phabricator via cfe-commits
reames added inline comments.



Comment at: llvm/docs/RISCVUsage.rst:54
  ``F``Supported
+ ``H``Supported
  ``M``Supported

If I'm reading the code right here, we only have assembly support here.  Given 
that, shouldn't this be Assembly Support?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136817

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


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

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 471565.

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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Floating.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/InterpState.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/lib/AST/Interp/State.h
  clang/test/AST/Interp/literals.cpp
  clang/test/SemaCXX/rounding-math.cpp

Index: clang/test/SemaCXX/rounding-math.cpp
===
--- clang/test/SemaCXX/rounding-math.cpp
+++ clang/test/SemaCXX/rounding-math.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s
 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas
+// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -fexperimental-new-constant-interpreter -Wno-unknown-pragmas
 // rounding-no-diagnostics
 
 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -466,3 +466,42 @@
   static_assert(subAll(213) == 0, "");
 };
 #endif
+
+namespace floats {
+  constexpr int i = 2;
+  constexpr float f = 1.0f;
+  static_assert(f == 1.0f, "");
+
+  constexpr float f2 = 1u * f;
+  static_assert(f2 == 1.0f, "");
+
+  static_assert(1.0f + 3u == 4, "");
+  static_assert(4.0f / 1.0f == 4, "");
+  static_assert(10.0f * false == 0, "");
+
+  constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+  constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{division by zero}} \
+   // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{division by zero}}
+
+  static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+ // expected-error {{invalid argument type 'float' to unary expression}}
+
+  /// Initialized by a double.
+  constexpr float df = 0.0;
+  /// The other way around.
+  constexpr double fd = 0.0f;
+
+  static_assert(0.0f == -0.0f, "");
+
+  const int k = 3 * (1.0f / 3.0f);
+  static_assert(k == 1, "");
+
+  constexpr bool b = 1.0;
+  static_assert(b, "");
+
+  constexpr double db = true;
+  static_assert(db == 1.0, "");
+};
Index: clang/lib/AST/Interp/State.h
===
--- clang/lib/AST/Interp/State.h
+++ clang/lib/AST/Interp/State.h
@@ -71,6 +71,7 @@
   virtual unsigned getCallStackDepth() = 0;
 
 public:
+  State() : InConstantContext(false) {}
   // Diagnose that the evaluation could not be folded (FF => FoldFailure)
   OptionalDiagnostic
   FFDiag(SourceLocation Loc,
@@ -118,6 +119,10 @@
 
   const LangOptions &getLangOpts() const;
 
+  /// Whether or not we're in a context where the front end requires a
+  /// constant value.
+  bool InConstantContext;
+
 private:
   void addCallStack(unsigned Limit);
 
Index: clang/lib/AST/Interp/Primitives.h
===
--- /dev/null
+++ clang/lib/AST/Interp/Primitives.h
@@ -0,0 +1,36 @@
+//===-- Primitives.h - Types for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities and helper functions for all primitive types:
+//  - Integral
+//  - Floating
+//  - Boolean
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+#define LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+
+#include "clang/AST/ComparisonCategories.h"
+
+namespace clang {
+namespace interp {
+
+/// Helper to compare two comparable types.
+template  ComparisonCategoryResult Compare(const T &X, const T &Y) {
+  if (X < Y)
+return ComparisonCategoryResult::Less;
+  if (X > Y)
+return ComparisonCategoryResult::Greater;
+  return ComparisonCategoryResult::Equal;
+}
+
+} // namespace interp
+} // namespace clang
+
+#endif
Index: clang/lib/AST/Interp/PrimType.h

[PATCH] D136786: Fix `unsafe-fp-math` attribute emission.

2022-10-28 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

>> I'm not following entirely, but -funsafe-math-optimizations is just a subset 
>> of -ffast-math, so checking only the properties that contribute to 
>> -funsafe-math-optimizations should be enough. 
>>  I think it is way simpler to reason in these terms than enumerating all the 
>> possible scenarios.

Exactly my point Since -funsafe-math-optimizations is a subset of -ffast-math, 
shouldn't it be the "minimal" option to trigger the unsafe-fp-math attribute 
for functions? 
I agree with the second part of the condition; it should be
updated with (LangOpts.getDefaultFPContractMode() ==  
LangOptions::FPModeKind::FPM_Fast ||   LangOpts.getDefaultFPContractMode() == 
LangOptions::FPModeKind::FPM_FastHonorPragmas) 
but I am still hesitant about the change you are proposing for the first part 
of the condition.
@andrew.w.kaylor Can you please weigh in on this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136786

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


[clang] 5eb1fbd - [clang][Docs] Correct typo: "may_trap" is rejected, the value is "maytrap".

2022-10-28 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2022-10-28T11:40:42-04:00
New Revision: 5eb1fbd109734771554465aa307e8205c2a2632e

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

LOG: [clang][Docs] Correct typo: "may_trap" is rejected, the value is "maytrap".

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 8d825691721aa..11bc5c9066111 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1371,7 +1371,7 @@ describes the various floating point semantic modes and 
the corresponding option
   :header: "Mode", "Values"
   :widths: 15, 30, 30
 
-  "ffp-exception-behavior", "{ignore, strict, may_trap}",
+  "ffp-exception-behavior", "{ignore, strict, maytrap}",
   "fenv_access", "{off, on}", "(none)"
   "frounding-math", "{dynamic, tonearest, downward, upward, towardzero}"
   "ffp-contract", "{on, off, fast, fast-honor-pragmas}"



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


[clang] 55b4344 - [HIP] add --offload-add-rpath

2022-10-28 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2022-10-28T11:42:38-04:00
New Revision: 55b43449978cc7050bef3ec255cbf5c5feee274e

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

LOG: [HIP] add --offload-add-rpath

Add an option --[no-]offload-add-rpath to control whether to
pass -rpath to linker for HIP runtime library. By default it
is off to match gcc/clang behavior for not adding -rpath
for runtime library by default.

Reviewed by: Artem Belevich

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Linux.cpp
clang/test/Driver/hip-runtime-libs-linux.hip

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7c5974813ffa4..efbc758c84f73 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4153,6 +4153,10 @@ def frtlib_add_rpath: Flag<["-"], "frtlib-add-rpath">, 
Flags<[NoArgumentUnused]>
   HelpText<"Add -rpath with architecture-specific resource directory to the 
linker flags">;
 def fno_rtlib_add_rpath: Flag<["-"], "fno-rtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
   HelpText<"Do not add -rpath with architecture-specific resource directory to 
the linker flags">;
+def offload_add_rpath: Flag<["--"], "offload-add-rpath">, 
Flags<[NoArgumentUnused]>,
+  HelpText<"Add -rpath with HIP runtime library directory to the linker 
flags">;
+def no_offload_add_rpath: Flag<["--"], "no-offload-add-rpath">, 
Flags<[NoArgumentUnused]>,
+  HelpText<"Do not add -rpath with HIP runtime library directory to the linker 
flags">;
 defm openmp_implicit_rpath: BoolFOption<"openmp-implicit-rpath",
   LangOpts<"OpenMP">,
   DefaultTrue,

diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index ccbdda11345f2..b6a93fe95e276 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -689,9 +689,13 @@ void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs,
 
 void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
-  CmdArgs.append(
-  {Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()),
-   "-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
+  CmdArgs.push_back(
+  Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()));
+
+  if (Args.hasFlag(options::OPT_offload_add_rpath,
+   options::OPT_no_offload_add_rpath, false))
+CmdArgs.append(
+{"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
 
   CmdArgs.push_back("-lamdhip64");
 }

diff  --git a/clang/test/Driver/hip-runtime-libs-linux.hip 
b/clang/test/Driver/hip-runtime-libs-linux.hip
index 0b577ae0904d0..aa71798a80bb4 100644
--- a/clang/test/Driver/hip-runtime-libs-linux.hip
+++ b/clang/test/Driver/hip-runtime-libs-linux.hip
@@ -12,6 +12,10 @@
 // RUN:   --target=x86_64-linux-gnu %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
 
+// RUN: %clang -### --hip-link --target=x86_64-linux-gnu \
+// RUN:   --rocm-path=%S/Inputs/rocm %t.o --offload-add-rpath 2>&1 \
+// RUN:   | FileCheck -check-prefixes=ROCM-RPATH %s
+
 // Test detecting latest /opt/rocm-{release} directory.
 // RUN: rm -rf %t && mkdir -p %t/opt
 // RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.9.0-1234
@@ -35,8 +39,9 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
-// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" 
"-lamdhip64"
-// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-rpath" "[[HIPRT]]" 
"-lamdhip64"
+// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-lamdhip64"
+// ROCM-RPATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" 
"-lamdhip64"
+// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-lamdhip64"
 // NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-lamdhip64"



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


[PATCH] D136854: [HIP] add --offload-add-rpath

2022-10-28 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG55b43449978c: [HIP] add --offload-add-rpath (authored by 
yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136854

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/hip-runtime-libs-linux.hip


Index: clang/test/Driver/hip-runtime-libs-linux.hip
===
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -12,6 +12,10 @@
 // RUN:   --target=x86_64-linux-gnu %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
 
+// RUN: %clang -### --hip-link --target=x86_64-linux-gnu \
+// RUN:   --rocm-path=%S/Inputs/rocm %t.o --offload-add-rpath 2>&1 \
+// RUN:   | FileCheck -check-prefixes=ROCM-RPATH %s
+
 // Test detecting latest /opt/rocm-{release} directory.
 // RUN: rm -rf %t && mkdir -p %t/opt
 // RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.9.0-1234
@@ -35,8 +39,9 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
-// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" 
"-lamdhip64"
-// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-rpath" "[[HIPRT]]" 
"-lamdhip64"
+// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-lamdhip64"
+// ROCM-RPATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" 
"-lamdhip64"
+// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-lamdhip64"
 // NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-lamdhip64"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -689,9 +689,13 @@
 
 void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
-  CmdArgs.append(
-  {Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()),
-   "-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
+  CmdArgs.push_back(
+  Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()));
+
+  if (Args.hasFlag(options::OPT_offload_add_rpath,
+   options::OPT_no_offload_add_rpath, false))
+CmdArgs.append(
+{"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
 
   CmdArgs.push_back("-lamdhip64");
 }
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4153,6 +4153,10 @@
   HelpText<"Add -rpath with architecture-specific resource directory to the 
linker flags">;
 def fno_rtlib_add_rpath: Flag<["-"], "fno-rtlib-add-rpath">, 
Flags<[NoArgumentUnused]>,
   HelpText<"Do not add -rpath with architecture-specific resource directory to 
the linker flags">;
+def offload_add_rpath: Flag<["--"], "offload-add-rpath">, 
Flags<[NoArgumentUnused]>,
+  HelpText<"Add -rpath with HIP runtime library directory to the linker 
flags">;
+def no_offload_add_rpath: Flag<["--"], "no-offload-add-rpath">, 
Flags<[NoArgumentUnused]>,
+  HelpText<"Do not add -rpath with HIP runtime library directory to the linker 
flags">;
 defm openmp_implicit_rpath: BoolFOption<"openmp-implicit-rpath",
   LangOpts<"OpenMP">,
   DefaultTrue,


Index: clang/test/Driver/hip-runtime-libs-linux.hip
===
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -12,6 +12,10 @@
 // RUN:   --target=x86_64-linux-gnu %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
 
+// RUN: %clang -### --hip-link --target=x86_64-linux-gnu \
+// RUN:   --rocm-path=%S/Inputs/rocm %t.o --offload-add-rpath 2>&1 \
+// RUN:   | FileCheck -check-prefixes=ROCM-RPATH %s
+
 // Test detecting latest /opt/rocm-{release} directory.
 // RUN: rm -rf %t && mkdir -p %t/opt
 // RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.9.0-1234
@@ -35,8 +39,9 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
-// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
-// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
+// ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-lamdhip64"
+// ROCM-RPATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
+// ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-lamdhip64"
 // NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-lamdhip64"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- c

[PATCH] D135930: [X86] Add AVX-NE-CONVERT instructions.

2022-10-28 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/lib/Headers/avx512vlbf16intrin.h:164
+#define _mm_cvtneps_pbh(A) \
+  ((__m128bh)__builtin_ia32_vcvtneps2bf16128((__v4sf)(A)))
 

Is there no way for __attribute__ to allow different attribute permutations?

Also, can we keep the __builtin_ia32_cvtneps2bf16_128 naming convention?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135930

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


[clang] ddec896 - [clang][Interp][NFC] Use right visit() function

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T17:44:53+02:00
New Revision: ddec89670dd873a293c958a8fc7f778e3cc4297b

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

LOG: [clang][Interp][NFC] Use right visit() function

visit (lowercase V) sets DiscardValue to false and calls Visit
(uppercase V). So we can't just call Visit (uppercase V) ourselves,
since then we aren't handling DiscardValue correctly.
This is currently irrelevant but will make a difference later.

Also, the naming isn't my fault and might change later.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 20e5d2911a1f..02d7ff2d2304 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -130,7 +130,7 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
   case CK_NoOp:
   case CK_UserDefinedConversion:
   case CK_NullToPointer:
-return this->Visit(SubExpr);
+return this->visit(SubExpr);
 
   case CK_IntegralToBoolean:
   case CK_IntegralCast: {
@@ -139,7 +139,7 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
 if (!FromT || !ToT)
   return false;
 
-if (!this->Visit(SubExpr))
+if (!this->visit(SubExpr))
   return false;
 
 // TODO: Emit this only if FromT != ToT.
@@ -167,7 +167,7 @@ bool ByteCodeExprGen::VisitIntegerLiteral(const 
IntegerLiteral *LE) {
 
 template 
 bool ByteCodeExprGen::VisitParenExpr(const ParenExpr *PE) {
-  return this->Visit(PE->getSubExpr());
+  return this->visit(PE->getSubExpr());
 }
 
 template 
@@ -180,7 +180,7 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   case BO_Comma:
 if (!discard(LHS))
   return false;
-if (!this->Visit(RHS))
+if (!this->visit(RHS))
   return false;
 return true;
   default:
@@ -264,10 +264,10 @@ bool ByteCodeExprGen::VisitArraySubscriptExpr(
   // Take pointer of LHS, add offset from RHS, narrow result.
   // What's left on the stack after this is a pointer.
   if (Optional IndexT = classify(Index->getType())) {
-if (!this->Visit(Base))
+if (!this->visit(Base))
   return false;
 
-if (!this->Visit(Index))
+if (!this->visit(Index))
   return false;
 
 if (!this->emitAddOffset(*IndexT, E))
@@ -590,7 +590,7 @@ bool ByteCodeExprGen::dereferenceVar(
 if (VD->hasLocalStorage() && VD->hasInit() && !VD->isConstexpr()) {
   QualType VT = VD->getType();
   if (VT.isConstQualified() && VT->isFundamentalType())
-return this->Visit(VD->getInit());
+return this->visit(VD->getInit());
 }
   }
 
@@ -869,7 +869,7 @@ bool ByteCodeExprGen::visitInitializer(const Expr 
*Initializer) {
 return visitRecordInitializer(Initializer);
 
   // Otherwise, visit the expression like normal.
-  return this->Visit(Initializer);
+  return this->visit(Initializer);
 }
 
 template 
@@ -1066,21 +1066,21 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 return false;
 
   case UO_LNot: // !x
-if (!this->Visit(SubExpr))
+if (!this->visit(SubExpr))
   return false;
 return this->emitInvBool(E);
   case UO_Minus: // -x
-if (!this->Visit(SubExpr))
+if (!this->visit(SubExpr))
   return false;
 if (Optional T = classify(E->getType()))
   return this->emitNeg(*T, E);
 return false;
   case UO_Plus:  // +x
-return this->Visit(SubExpr); // noop
+return this->visit(SubExpr); // noop
 
   case UO_AddrOf: // &x
 // We should already have a pointer when we get here.
-return this->Visit(SubExpr);
+return this->visit(SubExpr);
 
   case UO_Deref:  // *x
 return dereference(
@@ -1093,7 +1093,7 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
   return DiscardResult ? this->emitPop(T, E) : true;
 });
   case UO_Not:// ~x
-if (!this->Visit(SubExpr))
+if (!this->visit(SubExpr))
   return false;
 if (Optional T = classify(E->getType()))
   return this->emitComp(*T, E);



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


[PATCH] D136959: clang: Improve errors for DiagnosticInfoResourceLimit

2022-10-28 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: nickdesaulniers, yaxunl, aaron.ballman, qcolombet, 
aeubanks, olista01, dnovillo, echristo, MaskRay.
Herald added subscribers: kosarev, StephenFan, tpr.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.

Print source location info and demangle the name, compared
to the default behavior.

  

Several observations:

1. Specially handling this seems to give source locations

without enabling debug info, and also gives columns compared
to the backend diagnostic. This seems like a bug?

 

2. We're duplicating diagnostic effort in DiagnosticInfo

and clang. This feels wrong, but clang can demangle and I guess
have better debug info available? Should clang really have any of this
code? For the purposes of this diagnostic, the important piece
is just reading the source location out of the llvm::Function.

  

3. lld is not duplicating the same effort as clang with LTO, and just

directly printing the DiagnosticInfo as-is. e.g.


  $ clang -fgpu-rdc
lld: error: local memory (48) exceeds limit (65536) in function 
'_Z12use_huge_ldsIiEvv'
lld: error: local memory (96) exceeds limit (65536) in function 
'_Z12use_huge_ldsIdEvv'

  $ clang -fno-gpu-rdc
backend-resource-limit-diagnostics.hip:8:17: error: local memory 
(48) exceeds limit (65536) in 'void use_huge_lds()'
 __global__ void use_huge_lds() {
^
backend-resource-limit-diagnostics.hip:8:17: error: local memory 
(96) exceeds limit (65536) in 'void use_huge_lds()'
2 errors generated when compiling for gfx90a.


4. Backend errors are not observed with -save-temps and -fno-gpu-rdc or -flto,

and the compile incorrectly succeeds.

  

5. The backend version prints error: ; clang prints : error:

6. -emit-codegen-only is totally broken for AMDGPU. MC

gets a null target streamer. I do not understand why this
is a thing. This just creates a horrible edge case.
Just work around this by emitting actual code instead of blocking
this patch.


https://reviews.llvm.org/D136959

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Misc/backend-resource-limit-diagnostics.cl
  clang/test/Misc/backend-resource-limit-diagnostics.hip

Index: clang/test/Misc/backend-resource-limit-diagnostics.hip
===
--- clang/test/Misc/backend-resource-limit-diagnostics.hip
+++ clang/test/Misc/backend-resource-limit-diagnostics.hip
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -debug-info-kind=standalone -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip -fcuda-is-device -S -o /dev/null < %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip -fcuda-is-device -S -o /dev/null %s 2>&1 | FileCheck %s
 // FIXME: Use -emit-codegen-only
 
 #define __global__ __attribute__((global))
@@ -10,10 +10,10 @@
 huge[0] = 2;
 }
 
-// CHECK: error: :[[@LINE-5]]:0: local memory (48) exceeds limit (65536) in function '_Z12use_huge_ldsIiEvv'
+// CHECK: :[[@LINE-5]]:17: error: local memory (48) exceeds limit (65536) in 'void use_huge_lds()'
  template
  __global__ void use_huge_lds();
 
-// CHECK: error: :[[@LINE-9]]:0: local memory (96) exceeds limit (65536) in function '_Z12use_huge_ldsIdEvv'
+// CHECK: :[[@LINE-9]]:17: error: local memory (96) exceeds limit (65536) in 'void use_huge_lds()'
  template
  __global__ void use_huge_lds();
Index: clang/test/Misc/backend-resource-limit-diagnostics.cl
===
--- clang/test/Misc/backend-resource-limit-diagnostics.cl
+++ clang/test/Misc/backend-resource-limit-diagnostics.cl
@@ -1,7 +1,7 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: not %clang_cc1 -debug-info-kind=standalone -x cl -emit-codegen-only -triple=amdgcn-- < %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -x cl -emit-codegen-only -triple=amdgcn-- < %s 2>&1 | FileCheck %s
 
-// CHECK: error: :[[@LINE+1]]:0: local memory (48) exceeds limit (32768) in function 'use_huge_lds'
+// CHECK: :[[@LINE+1]]:13: error: local memory (48) exceeds limit (32768) in 'use_huge_lds'
 kernel void use_huge_lds() {
 volatile local int huge[12];
 huge[0] = 2;
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -435,6 +435,11 @@
 /// \return True if the diagnostic has been successfully reported, false
 /// otherwise.
 bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D);
+/// Specialized handler for ResourceLimit diagnostic.
+/// \return True if the diagnostic has been successfully reported, false
+/// otherwise.
+bool ResourceLimitDiagHandler(const llvm::DiagnosticInfoResourceLimit

[clang] f79f64b - [clang][Interp] Implement inc and dec operators

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T17:47:32+02:00
New Revision: f79f64b8d0829c404609d98f069580fa8cfb4d82

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

LOG: [clang][Interp] Implement inc and dec operators

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 02d7ff2d2304..30ae7fbfc637 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1053,35 +1053,67 @@ bool ByteCodeExprGen::VisitCXXThisExpr(const 
CXXThisExpr *E) {
 
 template 
 bool ByteCodeExprGen::VisitUnaryOperator(const UnaryOperator *E) {
-  if (DiscardResult)
-return true;
-
   const Expr *SubExpr = E->getSubExpr();
+  Optional T = classify(SubExpr->getType());
 
+  // TODO: Support pointers for inc/dec operators.
   switch (E->getOpcode()) {
-  case UO_PostInc: // x++
-  case UO_PostDec: // x--
-  case UO_PreInc:  // --x
-  case UO_PreDec:  // ++x
-return false;
+  case UO_PostInc: { // x++
+if (!this->visit(SubExpr))
+  return false;
+
+return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E);
+  }
+  case UO_PostDec: { // x--
+if (!this->visit(SubExpr))
+  return false;
+
+return DiscardResult ? this->emitDecPop(*T, E) : this->emitDec(*T, E);
+  }
+  case UO_PreInc: { // ++x
+if (!this->visit(SubExpr))
+  return false;
+
+// Post-inc and pre-inc are the same if the value is to be discarded.
+if (DiscardResult)
+  return this->emitIncPop(*T, E);
 
+this->emitLoad(*T, E);
+this->emitConst(E, 1);
+this->emitAdd(*T, E);
+return this->emitStore(*T, E);
+  }
+  case UO_PreDec: { // --x
+if (!this->visit(SubExpr))
+  return false;
+
+// Post-dec and pre-dec are the same if the value is to be discarded.
+if (DiscardResult)
+  return this->emitDecPop(*T, E);
+
+this->emitLoad(*T, E);
+this->emitConst(E, 1);
+this->emitSub(*T, E);
+return this->emitStore(*T, E);
+  }
   case UO_LNot: // !x
 if (!this->visit(SubExpr))
   return false;
-return this->emitInvBool(E);
+// The Inv doesn't change anything, so skip it if we don't need the result.
+return DiscardResult ? this->emitPop(*T, E) : this->emitInvBool(E);
   case UO_Minus: // -x
 if (!this->visit(SubExpr))
   return false;
-if (Optional T = classify(E->getType()))
-  return this->emitNeg(*T, E);
-return false;
+return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
   case UO_Plus:  // +x
-return this->visit(SubExpr); // noop
-
+if (!this->visit(SubExpr)) // noop
+  return false;
+return DiscardResult ? this->emitPop(*T, E) : true;
   case UO_AddrOf: // &x
 // We should already have a pointer when we get here.
-return this->visit(SubExpr);
-
+if (!this->visit(SubExpr))
+  return false;
+return DiscardResult ? this->emitPop(*T, E) : true;
   case UO_Deref:  // *x
 return dereference(
 SubExpr, DerefKind::Read,
@@ -1095,9 +1127,7 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
   case UO_Not:// ~x
 if (!this->visit(SubExpr))
   return false;
-if (Optional T = classify(E->getType()))
-  return this->emitComp(*T, E);
-return false;
+return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
   case UO_Real:   // __real x
   case UO_Imag:   // __imag x
   case UO_Extension:

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 8e53a76d563f..81f833735258 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -281,6 +281,105 @@ bool Neg(InterpState &S, CodePtr OpPC) {
   return true;
 }
 
+enum class PushVal : bool {
+  No,
+  Yes,
+};
+enum class IncDecOp {
+  Inc,
+  Dec,
+};
+
+template 
+bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
+  T Value = Ptr.deref();
+  T Result;
+
+  if constexpr (DoPush == PushVal::Yes)
+S.Stk.push(Result);
+
+  if constexpr (Op == IncDecOp::Inc) {
+if (!T::increment(Value, &Result)) {
+  Ptr.deref() = Result;
+  return true;
+}
+  } else {
+if (!T::decrement(Value, &Result)) {
+  Ptr.deref() = Result;
+  return true;
+}
+  }
+
+  // Something went wrong with the previous operation. Compute the
+  // result with another bit of precision.
+  unsigned Bits = Value.bitWidth() + 1;
+  APSInt APResult;
+  if constexpr (Op == IncDecOp::Inc)
+APResult = ++Value.toAPSInt(Bits);
+  

[PATCH] D136423: [clang][Interp] Implement inc/dec postfix and prefix operators

2022-10-28 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf79f64b8d082: [clang][Interp] Implement inc and dec 
operators (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D136423?vs=470163&id=471574#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136423

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

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -331,3 +331,88 @@
 
 #pragma clang diagnostic pop
 };
+
+#if __cplusplus > 201402L
+namespace IncDec {
+  constexpr int zero() {
+int a = 0;
+a++;
+++a;
+a--;
+--a;
+return a;
+  }
+  static_assert(zero() == 0, "");
+
+  constexpr int preInc() {
+int a = 0;
+return ++a;
+  }
+  static_assert(preInc() == 1, "");
+
+  constexpr int postInc() {
+int a = 0;
+return a++;
+  }
+  static_assert(postInc() == 0, "");
+
+  constexpr int preDec() {
+int a = 0;
+return --a;
+  }
+  static_assert(preDec() == -1, "");
+
+  constexpr int postDec() {
+int a = 0;
+return a--;
+  }
+  static_assert(postDec() == 0, "");
+
+  constexpr int three() {
+int a = 0;
+return ++a + ++a; // expected-warning {{multiple unsequenced modifications to 'a'}} \
+  // ref-warning {{multiple unsequenced modifications to 'a'}} \
+
+  }
+  static_assert(three() == 3, "");
+
+  constexpr bool incBool() {
+bool b = false;
+return ++b; // expected-error {{ISO C++17 does not allow incrementing expression of type bool}} \
+// ref-error {{ISO C++17 does not allow incrementing expression of type bool}}
+  }
+  static_assert(incBool(), "");
+
+  constexpr int uninit() {
+int a;
+++a; // ref-note {{increment of uninitialized}} \
+ // FIXME: Should also be rejected by new interpreter
+return 1;
+  }
+  static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'uninit()'}}
+
+  constexpr int OverFlow() { // ref-error {{never produces a constant expression}}
+int a = INT_MAX;
+++a; // ref-note 2{{is outside the range}} \
+ // expected-note {{is outside the range}}
+return -1;
+  }
+  static_assert(OverFlow() == -1, "");  // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'OverFlow()'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'OverFlow()'}}
+
+
+  constexpr int UnderFlow() { // ref-error {{never produces a constant expression}}
+int a = INT_MIN;
+--a; // ref-note 2{{is outside the range}} \
+ // expected-note {{is outside the range}}
+return -1;
+  }
+  static_assert(UnderFlow() == -1, "");  // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to 'UnderFlow()'}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to 'UnderFlow()'}}
+};
+#endif
Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -131,3 +131,18 @@
  constexpr int x = arr.a[0];
   }
 };
+
+namespace IncDec {
+  // FIXME: Pointer arithmethic needs to be supported in inc/dec
+  //   unary operators
+#if 0
+  constexpr int getNextElem(const int *A, int I) {
+const int *B = (A + I);
+++B;
+return *B;
+  }
+  constexpr int E[] = {1,2,3,4};
+
+  static_assert(getNextElem(E, 1) == 3);
+#endif
+};
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -419,6 +419,11 @@
   let HasGroup = 1;
 }
 
+def Inc: IntegerOpcode;
+def IncPop : IntegerOpcode;
+def Dec: IntegerOpcode;
+def DecPop: IntegerOpcode;
+
 // [Real] -> [Real]
 def Neg: Opcode {
   let Types = [AluTypeClass];
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -281,6 +281,105 @@
   return true;
 }
 
+enum class PushVal : bool {
+  No,
+  Yes,
+};
+enum class IncDecOp {
+  Inc,
+  Dec,
+};
+
+template 
+bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
+  T Value = Ptr.deref

[clang] 5a72df2 - [clang][Interp] Add missing expected test output

2022-10-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-10-28T18:07:10+02:00
New Revision: 5a72df21cbbe2092e5f58e94d733f95df87daf09

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

LOG: [clang][Interp] Add missing expected test output

Added: 


Modified: 
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 739910d3bc45..1c6aa4e26979 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -390,7 +390,8 @@ namespace IncDec {
 return 1;
   }
   static_assert(uninit(), ""); // ref-error {{not an integral constant 
expression}} \
-   // ref-note {{in call to 'uninit()'}}
+   // ref-note {{in call to 'uninit()'}} \
+   // expected-error {{not an integral constant 
expression}}
 
   constexpr int OverFlow() { // ref-error {{never produces a constant 
expression}}
 int a = INT_MAX;



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


  1   2   3   >