[clang] c9d92e6 - [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-28 Thread Freddy Ye via cfe-commits

Author: Freddy Ye
Date: 2023-07-28T15:05:54+08:00
New Revision: c9d92e66387baab18ceec1533503cc5f19048d91

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

LOG: [X86] Support -march=arrowlake,arrowlake-s,lunarlake

Reviewed By: pengfei

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

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/test/CodeGen/attr-cpuspecific-cpus.c
clang/test/CodeGen/attr-target-mv.c
clang/test/CodeGen/target-builtin-noerror.c
clang/test/Driver/x86-march.c
clang/test/Misc/target-invalid-cpu-note.c
clang/test/Preprocessor/predefined-arch-macros.c
compiler-rt/lib/builtins/cpu_model.c
llvm/include/llvm/TargetParser/X86TargetParser.def
llvm/include/llvm/TargetParser/X86TargetParser.h
llvm/lib/Target/X86/X86.td
llvm/lib/TargetParser/Host.cpp
llvm/lib/TargetParser/X86TargetParser.cpp
llvm/test/CodeGen/X86/cpus-intel.ll

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 11cb2dda15ccd8..a80b5901d36a44 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -545,6 +545,9 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case CK_Alderlake:
   case CK_Raptorlake:
   case CK_Meteorlake:
+  case CK_Arrowlake:
+  case CK_ArrowlakeS:
+  case CK_Lunarlake:
   case CK_Sierraforest:
   case CK_Grandridge:
   case CK_Graniterapids:
@@ -1437,6 +1440,9 @@ std::optional 
X86TargetInfo::getCPUCacheLineSize() const {
 case CK_Alderlake:
 case CK_Raptorlake:
 case CK_Meteorlake:
+case CK_Arrowlake:
+case CK_ArrowlakeS:
+case CK_Lunarlake:
 case CK_Sierraforest:
 case CK_Grandridge:
 case CK_Graniterapids:

diff  --git a/clang/test/CodeGen/attr-cpuspecific-cpus.c 
b/clang/test/CodeGen/attr-cpuspecific-cpus.c
index 14ae4af5fa4154..fcf4d0e1b92433 100644
--- a/clang/test/CodeGen/attr-cpuspecific-cpus.c
+++ b/clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -80,3 +80,6 @@ ATTR(cpu_specific(grandridge)) void CPU31(void){}
 ATTR(cpu_specific(graniterapids)) void CPU32(void){}
 ATTR(cpu_specific(emeraldrapids)) void CPU33(void){}
 ATTR(cpu_specific(graniterapids_d)) void CPU34(void){}
+ATTR(cpu_specific(arrowlake)) void CPU35(void){}
+ATTR(cpu_specific(arrowlake_s)) void CPU36(void){}
+ATTR(cpu_specific(lunarlake)) void CPU37(void){}

diff  --git a/clang/test/CodeGen/attr-target-mv.c 
b/clang/test/CodeGen/attr-target-mv.c
index 9d348fd771c17f..03b9dc7eb8980f 100644
--- a/clang/test/CodeGen/attr-target-mv.c
+++ b/clang/test/CodeGen/attr-target-mv.c
@@ -22,6 +22,9 @@ int __attribute__((target("arch=grandridge"))) foo(void) 
{return 17;}
 int __attribute__((target("arch=graniterapids"))) foo(void) {return 18;}
 int __attribute__((target("arch=emeraldrapids"))) foo(void) {return 19;}
 int __attribute__((target("arch=graniterapids-d"))) foo(void) {return 20;}
+int __attribute__((target("arch=arrowlake"))) foo(void) {return 21;}
+int __attribute__((target("arch=arrowlake-s"))) foo(void) {return 22;}
+int __attribute__((target("arch=lunarlake"))) foo(void) {return 23;}
 int __attribute__((target("default"))) foo(void) { return 2; }
 
 int bar(void) {
@@ -170,6 +173,12 @@ void calls_pr50025c(void) { pr50025c(); }
 // LINUX: ret i32 19
 // LINUX: define{{.*}} i32 @foo.arch_graniterapids-d()
 // LINUX: ret i32 20
+// LINUX: define{{.*}} i32 @foo.arch_arrowlake()
+// LINUX: ret i32 21
+// LINUX: define{{.*}} i32 @foo.arch_arrowlake-s()
+// LINUX: ret i32 22
+// LINUX: define{{.*}} i32 @foo.arch_lunarlake()
+// LINUX: ret i32 23
 // LINUX: define{{.*}} i32 @foo()
 // LINUX: ret i32 2
 // LINUX: define{{.*}} i32 @bar()
@@ -215,6 +224,12 @@ void calls_pr50025c(void) { pr50025c(); }
 // WINDOWS: ret i32 19
 // WINDOWS: define dso_local i32 @foo.arch_graniterapids-d()
 // WINDOWS: ret i32 20
+// WINDOWS: define dso_local i32 @foo.arch_arrowlake()
+// WINDOWS: ret i32 21
+// WINDOWS: define dso_local i32 @foo.arch_arrowlake-s()
+// WINDOWS: ret i32 22
+// WINDOWS: define dso_local i32 @foo.arch_lunarlake()
+// WINDOWS: ret i32 23
 // WINDOWS: define dso_local i32 @foo()
 // WINDOWS: ret i32 2
 // WINDOWS: define dso_local i32 @bar()

diff  --git a/clang/test/CodeGen/target-builtin-noerror.c 
b/clang/test/CodeGen/target-builtin-noerror.c
index cc6b90b9da9ecc..75fcdbbcb00822 100644
--- a/clang/test/CodeGen/target-builtin-noerror.c
+++ b/clang/test/CodeGen/target-builtin-noerror.c
@@ -111,6 +111,9 @@ void verifycpustrings(void) {
   (void)__builtin_cpu_is("graniterapids");
   (void)__builtin_cpu_is("emeraldrapids");
   (void)__builtin_cpu_is("graniterapids-d");
+  (void)__builtin_cpu_is("arrowlake");
+  (void)__builtin_cpu_is("arrowlake-s");
+  (void)__builtin_cpu_is("lunarlake");
   (void)__builtin_cpu_is("hasw

[PATCH] D156239: [X86] Support -march=arrowlake, arrowlake-s, lunarlake

2023-07-28 Thread Freddy, Ye 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 rGc9d92e66387b: [X86] Support 
-march=arrowlake,arrowlake-s,lunarlake (authored by FreddyYe).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156239

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -32,6 +32,10 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake-s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=arrowlake_s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lunarlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -90,6 +94,10 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake-s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=arrowlake_s 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=lunarlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -237,6 +237,8 @@
 FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
 constexpr FeatureBitset FeaturesGrandridge =
 FeaturesSierraforest | FeatureRAOINT;
+constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
+FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
 
 // Geode Processor.
 constexpr FeatureBitset FeaturesGeode =
@@ -422,6 +424,12 @@
   { {"raptorlake"}, CK_Raptorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
   // Meteorlake microarchitecture based processors.
   { {"meteorlake"}, CK_Meteorlake, FEATURE_AVX2, FeaturesAlderlake, 'p', false },
+  // Arrowlake microarchitecture based processors.
+  { {"arrowlake"}, CK_Arrowlake, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
+  { {"arrowlake-s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, '\0', false },
+  { {"arrowlake_s"}, CK_ArrowlakeS, FEATURE_AVX2, FeaturesArrowlakeS, 'p', true },
+  // Lunarlake microarchitecture based processors.
+  { {"lunarlake"}, CK_Lunarlake, FEATURE_AVX2, FeaturesArrowlakeS, 'p', false },
   // Sierraforest microarchitecture based processors.
   { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 'p', false },
   // Grandridge microarchitecture based processors.
Index: llvm/lib/Targe

[PATCH] D149015: [clang-tidy] Added bugprone-inc-dec-in-conditions check

2023-07-28 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/inc-dec-in-conditions.rst:62
+means that if ``i`` were initially ``5``, the first operand ``i < 5`` would
+evaluate to ``false`` and the second operand ``i > 2`` would not be evaluated.
+As a result, the decrement operation ``--i`` would not be executed and ``i``

xgupta wrote:
> If it is false then the second statement will be evaluated, right?
Yes my bad, I will correct this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149015

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


[PATCH] D156511: [clang][Interp] Diagnose more unkonwn DeclRefExprs

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

  Diagnose used non-const and/or extern globals.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156511

Files:
  clang/lib/AST/Interp/Interp.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
@@ -1056,3 +1056,31 @@
   int array[(intptr_t)(char*)0]; // ref-warning {{variable length array folded 
to constant array}} \
  // expected-warning {{variable length array 
folded to constant array}}
 }
+
+namespace InvalidDeclRefs {
+  bool b00; // ref-note {{declared here}} \
+// expected-note {{declared here}}
+  static_assert(b00, ""); // ref-error {{not an integral constant expression}} 
\
+  // ref-note {{read of non-const variable}} \
+  // expected-error {{not an integral constant 
expression}} \
+  // expected-note {{read of non-const variable}}
+
+  float b01; // ref-note {{declared here}} \
+ // expected-note {{declared here}}
+  static_assert(b01, ""); // ref-error {{not an integral constant expression}} 
\
+  // ref-note {{read of non-constexpr variable}} \
+  // expected-error {{not an integral constant 
expression}} \
+  // expected-note {{read of non-constexpr variable}}
+
+  extern const int b02; // ref-note {{declared here}} \
+// expected-note {{declared here}}
+  static_assert(b02, ""); // ref-error {{not an integral constant expression}} 
\
+  // ref-note {{initializer of 'b02' is unknown}} \
+  // expected-error {{not an integral constant 
expression}} \
+  // expected-note {{initializer of 'b02' is unknown}}
+
+  /// FIXME: This should also be diagnosed in the new interpreter.
+  int b03 = 3; // ref-note {{declared here}}
+  static_assert(b03, ""); // ref-error {{not an integral constant expression}} 
\
+  // ref-note {{read of non-const variable}}
+}
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -553,6 +553,25 @@
 return false;
   }
 
+  if (const auto *VD = dyn_cast(D)) {
+if (!VD->getType().isConstant(S.getCtx())) {
+  if (VD->getType()->isIntegralOrEnumerationType())
+S.FFDiag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD;
+  else
+S.FFDiag(E, diag::note_constexpr_ltor_non_constexpr, 1) << VD;
+
+  S.Note(VD->getLocation(), diag::note_declared_at) << 
VD->getSourceRange();
+  return false;
+}
+
+// const, but no initializer.
+if (!VD->getAnyInitializer()) {
+  S.FFDiag(E, diag::note_constexpr_var_init_unknown, 1) << VD;
+  S.Note(VD->getLocation(), diag::note_declared_at) << 
VD->getSourceRange();
+  return false;
+}
+  }
+
   return false;
 }
 


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1056,3 +1056,31 @@
   int array[(intptr_t)(char*)0]; // ref-warning {{variable length array folded to constant array}} \
  // expected-warning {{variable length array folded to constant array}}
 }
+
+namespace InvalidDeclRefs {
+  bool b00; // ref-note {{declared here}} \
+// expected-note {{declared here}}
+  static_assert(b00, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{read of non-const variable}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{read of non-const variable}}
+
+  float b01; // ref-note {{declared here}} \
+ // expected-note {{declared here}}
+  static_assert(b01, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{read of non-constexpr variable}} \
+  // expected-error {{not an integral constant expression}} \
+  // expected-note {{read of non-constexpr variable}}
+
+  extern const int b02; // ref-note {{declared here}} \
+// expected-note {{declared here}}
+  static_assert(b02, ""); // ref-error {{not an integral constant expression}} \
+  // ref-note {{initializer of 'b02' is unknown}} \
+  // expected-error {{not an inte

[PATCH] D155572: [clang][Interp] Start implementing binary operators for complex types

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

In D155572#4539457 , @aaron.ballman 
wrote:

> Is this intended to not handle all the binary operators in this patch?

Yes, just a subset for now.

> And also, is this intended to only impact initializers?

Yes, due to problems with (non-)initializers. This should work after 
https://reviews.llvm.org/D156027 though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155572

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


[PATCH] D142660: [AIX] supporting -X options for llvm-ranlib in AIX OS

2023-07-28 Thread James Henderson via Phabricator via cfe-commits
jhenderson added a comment.

In D142660#4538936 , @DiggerLin wrote:

>> As an alternative (but I think adds unnecessary complexity, due to needing 
>> an extra variable), you could have both tools read the environment variable 
>> into a string variable, then, if the -X option is present, overwrite that 
>> variable, and finally feed that string into the parsing code that converts 
>> into a BitMode value. If the string is invalid, the parsing code could 
>> report an error along the lines of "invalid OBJECT_MODE or -X option value".
>
> if I do not think it is better than my current implement, If I implement as 
> your suggestion, I need another variable to recoded the where the string come 
> from(from OBJECT_MODE  or -X option value). otherwise when the invalid value 
> of string , how can I report it is an invalid OBJECT_MODE"  or "invalid -X 
> option value"

I'm not convinced you need to distinguish the two. If a user hasn't specified 
the -X option, then they'll know it's the OBJECT_MODE environment variable. 
Even if they have both, it should be obvious to a quick glance of the full 
error message what the wrong value is (because you'd include it in the message) 
and you could then it won't take long to find which of the two is wrong (even 
if they don't know that -X trumps OBJET_MODE). That being said, I still prefer 
the parse OBJECT_MODE first, report an error, then later read the -X option and 
check for an error there.




Comment at: clang/test/lit.cfg.py:391
+if 'system-aix' in config.available_features:
+   config.environment['OBJECT_MODE'] = '32_64'
 

MaskRay wrote:
> Recent Python style prefers double quotes
This also applies to the line above. See discussions on Discourse about using 
"black" to format python code (it's similar to clang-format, but for python).



Comment at: llvm/test/tools/llvm-ranlib/aix-X-option.test:17-18
+## Test the OBJECT_MODE environment variable when adding symbol table.
+# RUN: unset OBJECT_MODE
+# RUN: llvm-ranlib t_X32.a
+# RUN: llvm-nm --print-armap t_X32.a 2>&1 | FileCheck --check-prefixes=GLOB32 
--implicit-check-not="in t64" %s

DiggerLin wrote:
> jhenderson wrote:
> > DiggerLin wrote:
> > > jhenderson wrote:
> > > > Assuming the unsetting is intended to be just for the llvm-ranlib line, 
> > > > I believe the preferred approach is `env -u OBJECT_MODE llvm-ranlib 
> > > > ...`. That way, you don't impact the behaviour in subsequent lines.
> > > the command `env` of AIX OS do not support -u.  and there is no mapping  
> > > option of `env -u`
> > > 
> > > https://www.ibm.com/docs/en/aix/7.2?topic=e-env-command
> > I'm 90% certain that `env` here is the built-in lit `env`, not a system 
> > `env` executable. `env -u` seems to be only rarely used in the test suite, 
> > but see llvm/utils/lit/tests/Inputs/shtest-env/env-u.txt for an example. I 
> > assume you can run this test locally?
> it run fail in AIX OS locally.
My apologies, it appears that you must be using the external shell or something 
(see lit differences internal and external shell). That might explain why `env 
-u` isn't used that much.



Comment at: llvm/tools/llvm-ar/llvm-ar.cpp:237
 static bool Verbose = false;  ///< 'v' modifier
-static bool Symtab = true;///< 's' modifier
+static WriteSymTabType Symtab = true; ///< 's' modifier
 static bool Deterministic = true; ///< 'D' and 'U' modifiers

DiggerLin wrote:
> jhenderson wrote:
> > DiggerLin wrote:
> > > jhenderson wrote:
> > > > DiggerLin wrote:
> > > > > jhenderson wrote:
> > > > > > DiggerLin wrote:
> > > > > > > jhenderson wrote:
> > > > > > > > Maybe I'm missing something, but I don't see why you need to 
> > > > > > > > make this a custom type. You already have the BitMode value 
> > > > > > > > that you read in from the environment/command-line, and so you 
> > > > > > > > can just use that in conjunction with the `Symtab` boolean to 
> > > > > > > > determine what symbol table to write, surely?
> > > > > > > the Symtab are use to specify whether the symbol table need to 
> > > > > > > write(for non-AIX). and what the symbol table need to write for 
> > > > > > > AIX OS.
> > > > > > > 
> > > > > > > there are function like
> > > > > > > 
> > > > > > > ```
> > > > > > >   writeArchiveToBuffer(ArrayRef NewMembers,
> > > > > > >  WriteSymTabType WriteSymtab, 
> > > > > > > object::Archive::Kind Kind,
> > > > > > >  bool Deterministic, bool Thin)
> > > > > > > ```
> > > > > > > and 
> > > > > > > 
> > > > > > > ```
> > > > > > > Error writeArchive(StringRef ArcName, ArrayRef 
> > > > > > > NewMembers,
> > > > > > >WriteSymTabType WriteSymtab, 
> > > > > > > object::Archive::Kind Kind,
> > > > > > >bool Deterministic, bool Thin,
> > > > > > >std::unique_ptr OldAr

[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-07-28 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D150124#4329163 , @ilya-biryukov 
wrote:

> In `clangd` we also have `findExplicitReferences` and `targetDecl` functions 
> that seem to handle the `GoToStmt`.
> In fact, I believe they are used in `findDocumentHighlights`, so I'm not sure 
> why your test did not work before this patch.
> findDocumentHighlights

I can explain this part: `findDocumentHighlights` uses `targetDecl` to 
associate the input cursor position with a symbol, but then it uses `findRefs` 
(which uses `libIndex`) to locate //other// usages of the symbol in the file.




Comment at: clang/lib/Index/IndexBody.cpp:150
+ParentDC,
+unsigned(SymbolRole::NameReference));
+  }

`NameReference` was introduced in 
https://github.com/llvm/llvm-project/commit/e7eb27a9a0edd859de49bcc9af7ca27dbb435886
 to handle the somewhat unique situation with constructors and destructors 
where the constructor/destructor references the class by name but semantically 
denotes a separate entity.

Why is that applicable here?

Note that `handleReference()` will automatically add `SymbolRole::Reference` 
[here](https://searchfox.org/llvm/rev/cea72fe34194d58ac1ba9485ee9c9a63cf98a4e6/clang/lib/Index/IndexingContext.cpp#404).



Comment at: clang/unittests/Index/IndexTests.cpp:233
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, AllOf(Contains(AllOf(QName("theLabel"),
+   WrittenAt(Position(3, 16)),

I think the outer `AllOf()` here is a no-op, since it has only one argument. 
(`AllOf(x, y, z)` means "each of the matchers `x`, `y`, and `z` match").


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150124

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


[PATCH] D147905: [clangd] Avoid passing -xobjective-c++-header to the system include extractor

2023-07-28 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a reviewer: sammccall.
nridge added a comment.

Adding Sam as well in case he has any thoughts on the discussion (another user 
ran into this recently and filed https://github.com/clangd/clangd/issues/1694)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147905

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


[PATCH] D154262: [clang][Interp] LambdaThisCaptures

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

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154262

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


[clang] e56bf13 - [RISCV] Remove some instructions from Zvfbfwma by implying Zfbfmin according to the latest spec

2023-07-28 Thread Jun Sha via cfe-commits

Author: Jun Sha (Joshua)
Date: 2023-07-28T15:52:03+08:00
New Revision: e56bf133170c9fd49c91fe943ded26a3f2b30a04

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

LOG: [RISCV] Remove some instructions from Zvfbfwma by implying Zfbfmin 
according to the latest spec

According to the latest spec, Zvfbfwma requires Zvfbfmin and Zvfbfmin requires 
Zfbfmin, with FLH/FSH/FMV.H.X/HMV.X.H removed from Zvfbfwma.

Reviewed By: asb

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

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s
llvm/test/MC/RISCV/rv64zhinx-invalid.s
llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
llvm/test/MC/RISCV/rvv/zvfbfwma.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index edfc26c9dfcf37..3a0ab9431e0769 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -698,28 +698,28 @@
 // CHECK-SSAIA-EXT: __riscv_ssaia  100{{$}}
 
 // RUN: %clang -target riscv32 -menable-experimental-extensions \
-// RUN: -march=rv32izfbfmin0p6 -x c -E -dM %s \
+// RUN: -march=rv32izfbfmin0p8 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZFBFMIN-EXT %s
 // RUN: %clang -target riscv64 -menable-experimental-extensions \
-// RUN: -march=rv64izfbfmin0p6 -x c -E -dM %s \
+// RUN: -march=rv64izfbfmin0p8 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZFBFMIN-EXT %s
-// CHECK-ZFBFMIN-EXT: __riscv_zfbfmin 6000{{$}}
+// CHECK-ZFBFMIN-EXT: __riscv_zfbfmin 8000{{$}}
 
 // RUN: %clang -target riscv32 -menable-experimental-extensions \
-// RUN: -march=rv32ifzvfbfmin0p6 -x c -E -dM %s \
+// RUN: -march=rv32ifzvfbfmin0p8 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVFBFMIN-EXT %s
 // RUN: %clang -target riscv64 -menable-experimental-extensions \
-// RUN: -march=rv64ifzvfbfmin0p6 -x c -E -dM %s \
+// RUN: -march=rv64ifzvfbfmin0p8 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVFBFMIN-EXT %s
-// CHECK-ZVFBFMIN-EXT: __riscv_zvfbfmin 6000{{$}}
+// CHECK-ZVFBFMIN-EXT: __riscv_zvfbfmin 8000{{$}}
 
 // RUN: %clang -target riscv32 -menable-experimental-extensions \
-// RUN: -march=rv32ifzvfbfwma0p6 -x c -E -dM %s \
+// RUN: -march=rv32ifzvfbfwma0p8 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVFBFWMA-EXT %s
 // RUN: %clang -target riscv64 -menable-experimental-extensions \
-// RUN: -march=rv64ifzvfbfwma0p6 -x c -E -dM %s \
+// RUN: -march=rv64ifzvfbfwma0p8 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVFBFWMA-EXT %s
-// CHECK-ZVFBFWMA-EXT: __riscv_zvfbfwma 6000{{$}}
+// CHECK-ZVFBFWMA-EXT: __riscv_zvfbfwma 8000{{$}}
 
 // RUN: %clang -target riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32iv_zvbb1p0_zvkned1p0_zvknhb1p0_zvkt1p0 -x c -E -dM %s -o - \

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index b9f9138f2404c9..07c750770d32fc 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -199,7 +199,7 @@ The primary goal of experimental support is to assist in 
the process of ratifica
   LLVM implements the `0.2 draft specification 
`__.
 
 ``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
-  LLVM implements assembler support for the `0.6.9 draft specification 
`_.
+  LLVM implements assembler support for the `0.8.0 draft specification 
`_.
 
 ``experimental-zicond``
   LLVM implements the `1.0-rc1 draft specification 
`__.

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index f0bae51ec1edf9..21605a4085ee3a 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -163,7 +163,7 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zacas", RISCVExtensionVersion{1, 0}},
 
 {"zfa", RISCVExtensionVersion{0, 2}},
-{"zfbfmin", RISCVExtensionVersion{0, 6}},
+{"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicond", RISCVExtensionVersion{1, 0}},
 
@@ -174,8 +174,8 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zvbb", RISCVExtensionVersion{1, 0}},
 {"zvbc", RISCVExtensionVersion{1, 0}},

[PATCH] D155916: [RISCV] Remove some instructions from Zvfbfwma by implying Zfbfmin according to the latest spec

2023-07-28 Thread Jun Sha via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe56bf133170c: [RISCV] Remove some instructions from Zvfbfwma 
by implying Zfbfmin according to… (authored by joshua-arch1).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D155916?vs=543350&id=545039#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155916

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv64zhinx-invalid.s
  llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
  llvm/test/MC/RISCV/rvv/zvfbfwma.s

Index: llvm/test/MC/RISCV/rvv/zvfbfwma.s
===
--- llvm/test/MC/RISCV/rvv/zvfbfwma.s
+++ llvm/test/MC/RISCV/rvv/zvfbfwma.s
@@ -45,24 +45,24 @@
 
 # CHECK-INST: flh ft0, 12(a0)
 # CHECK-ENCODING: [0x07,0x10,0xc5,0x00]
-# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 # CHECK-UNKNOWN: 07 10 c5 00 
 flh f0, 12(a0)
 
 # CHECK-INST: fsh ft6, 2047(s4)
 # CHECK-ENCODING: [0xa7,0x1f,0x6a,0x7e]
-# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 # CHECK-UNKNOWN: a7 1f 6a 7e 
 fsh f6, 2047(s4)
 
 # CHECK-INST: fmv.x.h a2, fs7
 # CHECK-ENCODING: [0x53,0x86,0x0b,0xe4]
-# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 # CHECK-UNKNOWN: 53 86 0b e4 
 fmv.x.h a2, fs7
 
 # CHECK-INST: fmv.h.x ft1, a6
 # CHECK-ENCODING: [0xd3,0x00,0x08,0xf4]
-# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+# CHECK-ERROR: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 # CHECK-UNKNOWN: d3 00 08 f4 
 fmv.h.x ft1, a6
Index: llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
===
--- llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
+++ llvm/test/MC/RISCV/rv64zhinxmin-invalid.s
@@ -1,7 +1,7 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+zhinxmin %s 2>&1 | FileCheck %s
 
 # Not support float registers
-flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 
 # Invalid instructions
 fsh a5, 12(sp) # CHECK: :[[@LINE]]:5: error: invalid operand for instruction
Index: llvm/test/MC/RISCV/rv64zhinx-invalid.s
===
--- llvm/test/MC/RISCV/rv64zhinx-invalid.s
+++ llvm/test/MC/RISCV/rv64zhinx-invalid.s
@@ -1,7 +1,7 @@
 # RUN: not llvm-mc -triple riscv64 -mattr=+zhinx %s 2>&1 | FileCheck %s
 
 # Not support float registers
-flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts) or 'Zvfbfwma' (Vector BF16 widening mul-add){{$}}
+flh fa4, 12(sp) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zfh' (Half-Precision Floating-Point) or 'Zfhmin' (Half-Precision Floating-Point Minimal) or 'Zfbfmin' (Scalar BF16 Converts){{$}}
 
 # Invalid instructions
 fsh a5, 12(

[clang] 8c0acbf - [clang][dataflow] Avoid -Wunused-variable.

2023-07-28 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-28T07:57:50Z
New Revision: 8c0acbf8370f29943798cd434cd0b91bbd554cdf

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

LOG: [clang][dataflow] Avoid -Wunused-variable.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 903d9ec300e2f6..214e0c061ed7bc 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -686,9 +686,11 @@ void Environment::setValueStrict(const Expr &E, Value 
&Val) {
   assert(E.isPRValue());
 
   if (auto *StructVal = dyn_cast(&Val)) {
-if (auto *ExistingVal = cast_or_null(getValue(E)))
+if ([[maybe_unused]] auto *ExistingVal =
+cast_or_null(getValue(E)))
   assert(&ExistingVal->getAggregateLoc() == &StructVal->getAggregateLoc());
-if (StorageLocation *ExistingLoc = getStorageLocation(E, SkipPast::None))
+if ([[maybe_unused]] StorageLocation *ExistingLoc =
+getStorageLocation(E, SkipPast::None))
   assert(ExistingLoc == &StructVal->getAggregateLoc());
 else
   setStorageLocation(E, StructVal->getAggregateLoc());



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


[PATCH] D156513: [clang] [libIndex] Remove unused 'RefD' parameter of IndexingContext::handleReference()

2023-07-28 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
nridge 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/D156513

Files:
  clang/lib/Index/IndexingContext.cpp
  clang/lib/Index/IndexingContext.h


Index: clang/lib/Index/IndexingContext.h
===
--- clang/lib/Index/IndexingContext.h
+++ clang/lib/Index/IndexingContext.h
@@ -79,7 +79,7 @@
const NamedDecl *Parent, const DeclContext *DC,
SymbolRoleSet Roles = SymbolRoleSet(),
ArrayRef Relations = std::nullopt,
-   const Expr *RefE = nullptr, const Decl *RefD = nullptr);
+   const Expr *RefE = nullptr);
 
   void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
   const MacroInfo &MI);
Index: clang/lib/Index/IndexingContext.cpp
===
--- clang/lib/Index/IndexingContext.cpp
+++ clang/lib/Index/IndexingContext.cpp
@@ -76,8 +76,7 @@
   const DeclContext *DC,
   SymbolRoleSet Roles,
   ArrayRef Relations,
-  const Expr *RefE,
-  const Decl *RefD) {
+  const Expr *RefE) {
   if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalSymbol(D))
 return true;
 
@@ -87,7 +86,7 @@
 return true;
   }
   return handleDeclOccurrence(D, Loc, /*IsRef=*/true, Parent, Roles, Relations,
-  RefE, RefD, DC);
+  RefE, nullptr, DC);
 }
 
 static void reportModuleReferences(const Module *Mod,


Index: clang/lib/Index/IndexingContext.h
===
--- clang/lib/Index/IndexingContext.h
+++ clang/lib/Index/IndexingContext.h
@@ -79,7 +79,7 @@
const NamedDecl *Parent, const DeclContext *DC,
SymbolRoleSet Roles = SymbolRoleSet(),
ArrayRef Relations = std::nullopt,
-   const Expr *RefE = nullptr, const Decl *RefD = nullptr);
+   const Expr *RefE = nullptr);
 
   void handleMacroDefined(const IdentifierInfo &Name, SourceLocation Loc,
   const MacroInfo &MI);
Index: clang/lib/Index/IndexingContext.cpp
===
--- clang/lib/Index/IndexingContext.cpp
+++ clang/lib/Index/IndexingContext.cpp
@@ -76,8 +76,7 @@
   const DeclContext *DC,
   SymbolRoleSet Roles,
   ArrayRef Relations,
-  const Expr *RefE,
-  const Decl *RefD) {
+  const Expr *RefE) {
   if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalSymbol(D))
 return true;
 
@@ -87,7 +86,7 @@
 return true;
   }
   return handleDeclOccurrence(D, Loc, /*IsRef=*/true, Parent, Roles, Relations,
-  RefE, RefD, DC);
+  RefE, nullptr, DC);
 }
 
 static void reportModuleReferences(const Module *Mod,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156513: [clang] [libIndex] Remove unused 'RefD' parameter of IndexingContext::handleReference()

2023-07-28 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Noticed this while reviewing D150124 . No 
caller was providing a value for this parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156513

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


[clang] 1195bd4 - [clang][Interp][NFC] Rename a test file to be more correct

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T10:12:36+02:00
New Revision: 1195bd48e017bb0f8237dec017e88d23d13ac2a9

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

LOG: [clang][Interp][NFC] Rename a test file to be more correct

This code is invalid, not unsupported.

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

Modified: 


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



diff  --git a/clang/test/AST/Interp/unsupported.cpp 
b/clang/test/AST/Interp/invalid.cpp
similarity index 100%
rename from clang/test/AST/Interp/unsupported.cpp
rename to clang/test/AST/Interp/invalid.cpp



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


[clang] 62a251f - [Clang][BFloat16] Upgrade __bf16 by supporting increment/decrement operations

2023-07-28 Thread Jun Sha via cfe-commits

Author: Jun Sha (Joshua)
Date: 2023-07-28T16:21:24+08:00
New Revision: 62a251f824f63a56563b246035b9bd24078aa98b

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

LOG: [Clang][BFloat16] Upgrade __bf16 by supporting increment/decrement 
operations

Since __bf16 has been upgraded from a storage-only type to an arithmetic type 
in https://reviews.llvm.org/rGe62175736551abf40a3410bc246f58e650eb8158, it 
should support all the basic arithmetic operations like other float types, 
including increment and decrement.

Reviewed By: pengfei

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

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/Sema/arm-bfloat.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index fe1a59b21f3801..33defb9c87e90f 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2764,8 +2764,8 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const 
UnaryOperator *E, LValue LV,
   amt = llvm::ConstantFP::get(VMContext,
   llvm::APFloat(static_cast(amount)));
 else {
-  // Remaining types are Half, LongDouble, __ibm128 or __float128. Convert
-  // from float.
+  // Remaining types are Half, Bfloat16, LongDouble, __ibm128 or 
__float128. 
+  // Convert from float.
   llvm::APFloat F(static_cast(amount));
   bool ignored;
   const llvm::fltSemantics *FS;
@@ -2775,6 +2775,8 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const 
UnaryOperator *E, LValue LV,
 FS = &CGF.getTarget().getFloat128Format();
   else if (value->getType()->isHalfTy())
 FS = &CGF.getTarget().getHalfFormat();
+  else if (value->getType()->isBFloatTy())
+FS = &CGF.getTarget().getBFloat16Format();
   else if (value->getType()->isPPC_FP128Ty())
 FS = &CGF.getTarget().getIbm128Format();
   else

diff  --git a/clang/test/Sema/arm-bfloat.cpp b/clang/test/Sema/arm-bfloat.cpp
index 34bea9b2ec9725..6a3eacd331d5c4 100644
--- a/clang/test/Sema/arm-bfloat.cpp
+++ b/clang/test/Sema/arm-bfloat.cpp
@@ -19,6 +19,8 @@ void test(bool b) {
   bf16 - bf16;
   bf16 * bf16;
   bf16 / bf16;
+  ++bf16;
+  --bf16;
 
   __fp16 fp16;
 



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


[PATCH] D152768: [Clang][BFloat16] Upgrade __bf16 by supporting increment/decrement operations

2023-07-28 Thread Jun Sha via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG62a251f824f6: [Clang][BFloat16] Upgrade __bf16 by supporting 
increment/decrement operations (authored by joshua-arch1).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D152768?vs=530750&id=545049#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152768

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Sema/arm-bfloat.cpp


Index: clang/test/Sema/arm-bfloat.cpp
===
--- clang/test/Sema/arm-bfloat.cpp
+++ clang/test/Sema/arm-bfloat.cpp
@@ -19,6 +19,8 @@
   bf16 - bf16;
   bf16 * bf16;
   bf16 / bf16;
+  ++bf16;
+  --bf16;
 
   __fp16 fp16;
 
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2764,8 +2764,8 @@
   amt = llvm::ConstantFP::get(VMContext,
   llvm::APFloat(static_cast(amount)));
 else {
-  // Remaining types are Half, LongDouble, __ibm128 or __float128. Convert
-  // from float.
+  // Remaining types are Half, Bfloat16, LongDouble, __ibm128 or 
__float128. 
+  // Convert from float.
   llvm::APFloat F(static_cast(amount));
   bool ignored;
   const llvm::fltSemantics *FS;
@@ -2775,6 +2775,8 @@
 FS = &CGF.getTarget().getFloat128Format();
   else if (value->getType()->isHalfTy())
 FS = &CGF.getTarget().getHalfFormat();
+  else if (value->getType()->isBFloatTy())
+FS = &CGF.getTarget().getBFloat16Format();
   else if (value->getType()->isPPC_FP128Ty())
 FS = &CGF.getTarget().getIbm128Format();
   else


Index: clang/test/Sema/arm-bfloat.cpp
===
--- clang/test/Sema/arm-bfloat.cpp
+++ clang/test/Sema/arm-bfloat.cpp
@@ -19,6 +19,8 @@
   bf16 - bf16;
   bf16 * bf16;
   bf16 / bf16;
+  ++bf16;
+  --bf16;
 
   __fp16 fp16;
 
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2764,8 +2764,8 @@
   amt = llvm::ConstantFP::get(VMContext,
   llvm::APFloat(static_cast(amount)));
 else {
-  // Remaining types are Half, LongDouble, __ibm128 or __float128. Convert
-  // from float.
+  // Remaining types are Half, Bfloat16, LongDouble, __ibm128 or __float128. 
+  // Convert from float.
   llvm::APFloat F(static_cast(amount));
   bool ignored;
   const llvm::fltSemantics *FS;
@@ -2775,6 +2775,8 @@
 FS = &CGF.getTarget().getFloat128Format();
   else if (value->getType()->isHalfTy())
 FS = &CGF.getTarget().getHalfFormat();
+  else if (value->getType()->isBFloatTy())
+FS = &CGF.getTarget().getBFloat16Format();
   else if (value->getType()->isPPC_FP128Ty())
 FS = &CGF.getTarget().getIbm128Format();
   else
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156515: [RemarkUtil] Refactor llvm-remarkutil to include size-diff

2023-07-28 Thread Zain Jaffal via Phabricator via cfe-commits
zjaffal created this revision.
zjaffal added reviewers: fhahn, thegameg, paquette, anemet.
Herald added subscribers: StephenFan, arphaman.
Herald added a project: All.
zjaffal requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This change follows from https://reviews.llvm.org/D156416 We include
`llvm-remark-size-diff` as a part of `llvm-remarkutil` under a
subcommand `size-diff`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156515

Files:
  clang/docs/ClangFormattedStatus.rst
  clang/docs/tools/clang-formatted-files.txt
  llvm/docs/CommandGuide/index.rst
  llvm/docs/CommandGuide/llvm-remark-size-diff.rst
  llvm/docs/CommandGuide/llvm-remarkutil.rst
  llvm/test/CMakeLists.txt
  llvm/test/lit.cfg.py
  llvm/test/tools/llvm-remark-size-diff/Inputs/1-func-1-instr-1-stack.yaml
  llvm/test/tools/llvm-remark-size-diff/Inputs/1-func-2-instr-2-stack.yaml
  
llvm/test/tools/llvm-remark-size-diff/Inputs/2-identical-func-1-instr-1-stack.yaml
  llvm/test/tools/llvm-remark-size-diff/Inputs/empty-file.yaml
  llvm/test/tools/llvm-remark-size-diff/Inputs/inconvertible-integer.yaml
  llvm/test/tools/llvm-remark-size-diff/Inputs/no-instruction-count-remarks.yaml
  llvm/test/tools/llvm-remark-size-diff/Inputs/unexpected-key.yaml
  llvm/test/tools/llvm-remark-size-diff/add-remove-func.test
  llvm/test/tools/llvm-remark-size-diff/empty-file.test
  llvm/test/tools/llvm-remark-size-diff/inconvertible-integer.test
  llvm/test/tools/llvm-remark-size-diff/increase-decrease-inst-count.test
  llvm/test/tools/llvm-remark-size-diff/json-add-remove-func.test
  llvm/test/tools/llvm-remark-size-diff/json-increase-decrease-inst-count.test
  llvm/test/tools/llvm-remark-size-diff/json-no-difference.test
  llvm/test/tools/llvm-remark-size-diff/no-difference.test
  llvm/test/tools/llvm-remark-size-diff/no-instruction-count-remarks.test
  llvm/test/tools/llvm-remark-size-diff/unexpected-key.test
  llvm/test/tools/llvm-remarkutil/size-diff/Inputs/1-func-1-instr-1-stack.yaml
  llvm/test/tools/llvm-remarkutil/size-diff/Inputs/1-func-2-instr-2-stack.yaml
  
llvm/test/tools/llvm-remarkutil/size-diff/Inputs/2-identical-func-1-instr-1-stack.yaml
  llvm/test/tools/llvm-remarkutil/size-diff/Inputs/empty-file.yaml
  llvm/test/tools/llvm-remarkutil/size-diff/Inputs/inconvertible-integer.yaml
  
llvm/test/tools/llvm-remarkutil/size-diff/Inputs/no-instruction-count-remarks.yaml
  llvm/test/tools/llvm-remarkutil/size-diff/Inputs/unexpected-key.yaml
  llvm/test/tools/llvm-remarkutil/size-diff/add-remove-func.test
  llvm/test/tools/llvm-remarkutil/size-diff/empty-file.test
  llvm/test/tools/llvm-remarkutil/size-diff/inconvertible-integer.test
  llvm/test/tools/llvm-remarkutil/size-diff/increase-decrease-inst-count.test
  llvm/test/tools/llvm-remarkutil/size-diff/json-add-remove-func.test
  
llvm/test/tools/llvm-remarkutil/size-diff/json-increase-decrease-inst-count.test
  llvm/test/tools/llvm-remarkutil/size-diff/json-no-difference.test
  llvm/test/tools/llvm-remarkutil/size-diff/no-difference.test
  llvm/test/tools/llvm-remarkutil/size-diff/no-instruction-count-remarks.test
  llvm/test/tools/llvm-remarkutil/size-diff/unexpected-key.test
  llvm/tools/llvm-remark-size-diff/CMakeLists.txt
  llvm/tools/llvm-remark-size-diff/RemarkSizeDiff.cpp
  llvm/tools/llvm-remarkutil/CMakeLists.txt
  llvm/tools/llvm-remarkutil/RemarkSizeDiff.cpp
  llvm/utils/gn/secondary/llvm/test/BUILD.gn
  llvm/utils/gn/secondary/llvm/tools/llvm-remark-size-diff/BUILD.gn
  utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -4443,24 +4443,6 @@
 ],
 )
 
-cc_binary(
-name = "llvm-remark-size-diff",
-srcs = glob([
-"tools/llvm-remark-size-diff/**/*.cpp",
-"tools/llvm-remark-size-diff/**/*.h",
-]),
-copts = llvm_copts,
-includes = ["tools/llvm-reark-size-diff"],
-stamp = 0,
-deps = [
-":Core",
-":Demangle",
-":Object",
-":Remarks",
-":Support",
-],
-)
-
 cc_binary(
 name = "llvm-rtdyld",
 srcs = glob([
Index: llvm/utils/gn/secondary/llvm/tools/llvm-remark-size-diff/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/tools/llvm-remark-size-diff/BUILD.gn
+++ /dev/null
@@ -1,10 +0,0 @@
-executable("llvm-remark-size-diff") {
-  deps = [
-"//llvm/lib/Demangle",
-"//llvm/lib/IR",
-"//llvm/lib/Object",
-"//llvm/lib/Remarks",
-"//llvm/lib/Support",
-  ]
-  sources = [ "RemarkSizeDiff.cpp" ]
-}
Index: llvm/utils/gn/secondary/llvm/test/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/test/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/test/BUILD.gn
@@ 

[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-07-28 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 545054.
ckandeler added a comment.

Addressed review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150124

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexBody.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -218,6 +218,28 @@
   EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar";
 }
 
+TEST(IndexTest, IndexLabels) {
+  std::string Code = R"cpp(
+int main() {
+  goto theLabel;
+  theLabel:
+return 1;
+}
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  Opts.IndexFunctionLocals = true;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("theLabel"), WrittenAt(Position(3, 16)),
+ DeclAt(Position(4, 11);
+
+  Opts.IndexFunctionLocals = false;
+  Index->Symbols.clear();
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, Not(Contains(QName("theLabel";
+}
+
 TEST(IndexTest, IndexExplicitTemplateInstantiation) {
   std::string Code = R"cpp(
 template 
Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -144,6 +144,18 @@
 Parent, ParentDC, Roles, Relations, E);
   }
 
+  bool VisitGotoStmt(GotoStmt *S) {
+return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
+ParentDC,
+unsigned(SymbolRole::NameReference));
+  }
+
+  bool VisitLabelStmt(LabelStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols())
+  return IndexCtx.handleDecl(S->getDecl());
+return true;
+  }
+
   bool VisitMemberExpr(MemberExpr *E) {
 SourceLocation Loc = E->getMemberLoc();
 if (Loc.isInvalid())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -125,6 +125,13 @@
   [Foo [[x]]:2 [[^y]]:4];
 }
   )cpp",
+  R"cpp( // Label
+int main() {
+  goto [[^theLabel]];
+  [[theLabel]]:
+return 1;
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -218,6 +218,28 @@
   EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar";
 }
 
+TEST(IndexTest, IndexLabels) {
+  std::string Code = R"cpp(
+int main() {
+  goto theLabel;
+  theLabel:
+return 1;
+}
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  Opts.IndexFunctionLocals = true;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("theLabel"), WrittenAt(Position(3, 16)),
+ DeclAt(Position(4, 11);
+
+  Opts.IndexFunctionLocals = false;
+  Index->Symbols.clear();
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, Not(Contains(QName("theLabel";
+}
+
 TEST(IndexTest, IndexExplicitTemplateInstantiation) {
   std::string Code = R"cpp(
 template 
Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -144,6 +144,18 @@
 Parent, ParentDC, Roles, Relations, E);
   }
 
+  bool VisitGotoStmt(GotoStmt *S) {
+return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
+ParentDC,
+unsigned(SymbolRole::NameReference));
+  }
+
+  bool VisitLabelStmt(LabelStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols())
+  return IndexCtx.handleDecl(S->getDecl());
+return true;
+  }
+
   bool VisitMemberExpr(MemberExpr *E) {
 SourceLocation Loc = E->getMemberLoc();
 if (Loc.isInvalid())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -125,6 +125,13 @@
   [Foo [[x]]:2 [[^y]]:4];
 }
   )cpp",
+   

[clang] c2273e3 - [clang][Interp] Implement __builtin_nan family

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T10:28:55+02:00
New Revision: c2273e33bd13a227271a53cde5868546e41dc3bf

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

LOG: [clang][Interp] Implement __builtin_nan family

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

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index b29747221ab552..a8758d8cc0569a 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -9,6 +9,7 @@
 #include "Interp.h"
 #include "PrimType.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
 
 namespace clang {
 namespace interp {
@@ -59,6 +60,67 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_nan(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F,
+bool Signaling) {
+  const Pointer &Arg = getParam(Frame, 0);
+
+  if (!CheckLoad(S, OpPC, Arg))
+return false;
+
+  assert(Arg.getFieldDesc()->isPrimitiveArray());
+
+  // Convert the given string to an integer using StringRef's API.
+  llvm::APInt Fill;
+  std::string Str;
+  assert(Arg.getNumElems() >= 1);
+  for (unsigned I = 0;; ++I) {
+const Pointer &Elem = Arg.atIndex(I);
+
+if (!CheckLoad(S, OpPC, Elem))
+  return false;
+
+if (Elem.deref() == 0)
+  break;
+
+Str += Elem.deref();
+  }
+
+  // Treat empty strings as if they were zero.
+  if (Str.empty())
+Fill = llvm::APInt(32, 0);
+  else if (StringRef(Str).getAsInteger(0, Fill))
+return false;
+
+  const llvm::fltSemantics &TargetSemantics =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  Floating Result;
+  if (S.getCtx().getTargetInfo().isNan2008()) {
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, &Fill));
+else
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, &Fill));
+  } else {
+// Prior to IEEE 754-2008, architectures were allowed to choose whether
+// the first bit of their significand was set for qNaN or sNaN. MIPS chose
+// a 
diff erent encoding to what became a standard in 2008, and for pre-
+// 2008 revisions, MIPS interpreted sNaN-2008 as qNan and qNaN-2008 as
+// sNaN. This is now known as "legacy NaN" encoding.
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, &Fill));
+else
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, &Fill));
+  }
+
+  S.Stk.push(Result);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -72,7 +134,24 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F) {
   case Builtin::BI__builtin_strcmp:
 if (interp__builtin_strcmp(S, OpPC, Frame))
   return Ret(S, OpPC, Dummy);
-return false;
+break;
+  case Builtin::BI__builtin_nan:
+  case Builtin::BI__builtin_nanf:
+  case Builtin::BI__builtin_nanl:
+  case Builtin::BI__builtin_nanf16:
+  case Builtin::BI__builtin_nanf128:
+if (interp__builtin_nan(S, OpPC, Frame, F, /*Signaling=*/false))
+  return Ret(S, OpPC, Dummy);
+break;
+  case Builtin::BI__builtin_nans:
+  case Builtin::BI__builtin_nansf:
+  case Builtin::BI__builtin_nansl:
+  case Builtin::BI__builtin_nansf16:
+  case Builtin::BI__builtin_nansf128:
+if (interp__builtin_nan(S, OpPC, Frame, F, /*Signaling=*/true))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }

diff  --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index eff8f80b7649a1..ef28f003117dc3 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s 
-verify
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -34,3 +37,26 @@ namespace strcmp {
 // 
ref-error {{not an integral constant}} \
 // 
ref-note {{derefer

[PATCH] D155356: [clang][Interp] Implement __builtin_nan family of functions

2023-07-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 rGc2273e33bd13: [clang][Interp] Implement __builtin_nan family 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D155356?vs=544435&id=545055#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155356

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+
 
 namespace strcmp {
   constexpr char kFoobar[6] = {'f','o','o','b','a','r'};
@@ -34,3 +37,26 @@
 // ref-error {{not an integral constant}} \
 // ref-note {{dereferenced one-past-the-end}}
 }
+
+namespace nan {
+  constexpr double NaN1 = __builtin_nan("");
+
+  /// The current interpreter does not accept this, but it should.
+  constexpr float NaN2 = __builtin_nans([](){return "0xAE98";}()); // ref-error {{must be initialized by a constant expression}}
+
+  constexpr double NaN3 = __builtin_nan("foo"); // expected-error {{must be initialized by a constant expression}} \
+// ref-error {{must be initialized by a constant expression}}
+  constexpr float NaN4 = __builtin_nanf("");
+  constexpr long double NaN5 = __builtin_nanf128("");
+
+  /// FIXME: This should be accepted by the current interpreter as well.
+  constexpr char f[] = {'0', 'x', 'A', 'E', '\0'};
+  constexpr double NaN6 = __builtin_nan(f); // ref-error {{must be initialized by a constant expression}}
+
+  /// FIXME: Current interpreter misses diagnostics.
+  constexpr char f2[] = {'0', 'x', 'A', 'E'}; /// No trailing 0 byte.
+  constexpr double NaN7 = __builtin_nan(f2); // ref-error {{must be initialized by a constant expression}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{read of dereferenced one-past-the-end pointer}} \
+ // expected-note {{in call to}}
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -9,6 +9,7 @@
 #include "Interp.h"
 #include "PrimType.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetInfo.h"
 
 namespace clang {
 namespace interp {
@@ -59,6 +60,67 @@
   return true;
 }
 
+static bool interp__builtin_nan(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F,
+bool Signaling) {
+  const Pointer &Arg = getParam(Frame, 0);
+
+  if (!CheckLoad(S, OpPC, Arg))
+return false;
+
+  assert(Arg.getFieldDesc()->isPrimitiveArray());
+
+  // Convert the given string to an integer using StringRef's API.
+  llvm::APInt Fill;
+  std::string Str;
+  assert(Arg.getNumElems() >= 1);
+  for (unsigned I = 0;; ++I) {
+const Pointer &Elem = Arg.atIndex(I);
+
+if (!CheckLoad(S, OpPC, Elem))
+  return false;
+
+if (Elem.deref() == 0)
+  break;
+
+Str += Elem.deref();
+  }
+
+  // Treat empty strings as if they were zero.
+  if (Str.empty())
+Fill = llvm::APInt(32, 0);
+  else if (StringRef(Str).getAsInteger(0, Fill))
+return false;
+
+  const llvm::fltSemantics &TargetSemantics =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  Floating Result;
+  if (S.getCtx().getTargetInfo().isNan2008()) {
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getSNaN(TargetSemantics, /*Negative=*/false, &Fill));
+else
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/false, &Fill));
+  } else {
+// Prior to IEEE 754-2008, architectures were allowed to choose whether
+// the first bit of their significand was set for qNaN or sNaN. MIPS chose
+// a different encoding to what became a standard in 2008, and for pre-
+// 2008 revisions, MIPS interpreted sNaN-2008 as qNan and qNaN-2008 as
+// sNaN. This is now known as "legacy NaN" encoding.
+if (Signaling)
+  Result = Floating(
+  llvm::APFloat::getQNaN(TargetSemantics, /*Negative=*/fal

[PATCH] D154588: [CSKY] Optimize implementation of intrinsic 'llvm.cttz.i32'

2023-07-28 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu added inline comments.



Comment at: clang/test/CodeGen/CSKY/csky-builtins.c:1
+// RUN: %clang_cc1 -triple csky -emit-llvm -o - %s | FileCheck %s
+

benshi001 wrote:
> This file is pure test, has nothing to do with `llvm.cttz`, just to avoid 
> another patch.
Don't make unrelated patch together in one single commit.



Comment at: clang/test/CodeGen/CSKY/csky-builtins.c:67
+  return __builtin_bswap64(x);
+}

Those are target-independent intrinsics/builtins. I think it's no more need to 
test for specific target such as csky again, unless it's different behavior or 
output.



Comment at: llvm/test/CodeGen/CSKY/intrinsic.ll:36
+define i16 @bswap16(i16 %x) {
+; CHECK-LABEL: bswap16:
+; CHECK:   # %bb.0: # %entry

Again. It's related to cttz?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154588

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


[PATCH] D156277: [Parser][ObjC] Fix parser crash on nested top-level block with better recovery path

2023-07-28 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 545056.
danix800 retitled this revision from "[Parser][ObjC] Stop parsing on eof" to 
"[Parser][ObjC] Fix parser crash on nested top-level block with better recovery 
path".
danix800 edited the summary of this revision.
danix800 added a comment.

Delay consuming tokens and bail out early if nested top-level block are met
for better diag & recovery.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

Files:
  clang/lib/Parse/ParseObjc.cpp
  clang/test/Parser/missing-end-1-gh64065-nocrash.m
  clang/test/Parser/missing-end-2.m
  clang/test/Parser/missing-end-3.m
  clang/test/Parser/missing-end-4.m

Index: clang/test/Parser/missing-end-4.m
===
--- clang/test/Parser/missing-end-4.m
+++ clang/test/Parser/missing-end-4.m
@@ -37,10 +37,10 @@
 - (C*) MyMeth {}
 @end
 
-@interface I2 {}
-@protocol P2; // expected-error {{illegal interface qualifier}}
-@class C2; // expected-error {{illegal interface qualifier}}
-@end
+@interface I2 {} // expected-note {{class started here}}
+@protocol P2; // expected-error {{missing '@end'}}
+@class C2;
+@end // expected-error {{'@end' must appear in an Objective-C context}}
 
 @interface I3
 @end
Index: clang/test/Parser/missing-end-3.m
===
--- clang/test/Parser/missing-end-3.m
+++ clang/test/Parser/missing-end-3.m
@@ -1,10 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // rdar://8283484
+// expected-note@+1 {{previous definition is here}}
 @interface blah { // expected-note {{class started here}}
 @private
 }
 // since I forgot the @end here it should say something
 
+// expected-error@+1 {{duplicate interface definition for class 'blah'}}
 @interface blah  // expected-error {{missing '@end'}}
-@end // and Unknown type name 'end' here
+@end
 
Index: clang/test/Parser/missing-end-2.m
===
--- clang/test/Parser/missing-end-2.m
+++ clang/test/Parser/missing-end-2.m
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
 // rdar: //7824372
 
 @interface A // expected-note {{class started here}}
--(void) im0;
+-(void) im0; // expected-note {{method 'im0' declared here}}
 
+// expected-warning@+1 {{method definition for 'im0' not found}}
 @implementation A // expected-error {{missing '@end'}}
 @end
 
@@ -13,7 +14,8 @@
 @implementation B // expected-error {{missing '@end'}}
 @end
 
-@interface C // expected-note 2 {{class started here}}
+@interface C // expected-note 1 {{class started here}}
 @property int P;
 
+// expected-note@+1 {{implementation started here}}
 @implementation C // expected-error 2 {{missing '@end'}}
Index: clang/test/Parser/missing-end-1-gh64065-nocrash.m
===
--- /dev/null
+++ clang/test/Parser/missing-end-1-gh64065-nocrash.m
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@interface Roo // expected-note {{class started here}}
+// expected-error@+1 {{missing '@end'}}
+@interface // expected-error {{expected identifier}}
Index: clang/lib/Parse/ParseObjc.cpp
===
--- clang/lib/Parse/ParseObjc.cpp
+++ clang/lib/Parse/ParseObjc.cpp
@@ -705,15 +705,30 @@
   continue;
 }
 
-// Otherwise, we have an @ directive, eat the @.
-SourceLocation AtLoc = ConsumeToken(); // the "@"
-if (Tok.is(tok::code_completion)) {
+// Otherwise, we have an @ directive, peak at the next token
+SourceLocation AtLoc = Tok.getLocation();
+const auto &NextTok = NextToken();
+if (NextTok.is(tok::code_completion)) {
   cutOffParsing();
   Actions.CodeCompleteObjCAtDirective(getCurScope());
   return;
 }
 
-tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
+tok::ObjCKeywordKind DirectiveKind = NextTok.getObjCKeywordID();
+// Bail out as if we saw an '@end'
+switch (DirectiveKind) {
+case tok::objc_class:
+case tok::objc_compatibility_alias:
+case tok::objc_interface:
+case tok::objc_implementation:
+case tok::objc_protocol:
+  goto MISSING_END;
+default:
+  break;
+}
+
+// Otherwise parse it as part of the current declaration. Eat the "@".
+ConsumeToken();
 
 if (DirectiveKind == tok::objc_end) { // @end -> terminate list
   AtEnd.setBegin(AtLoc);
@@ -739,15 +754,6 @@
   SkipUntil(tok::r_brace, tok::at, StopAtSemi);
   break;
 
-case tok::objc_implementation:
-case tok::objc_interface:
-  Diag(AtLoc, diag::err_objc_missing_end)
-  << FixItHint::CreateInsertion(AtLoc, "@end\n");
-  Diag(CDecl->getBeginLoc(), diag::note_objc_container_start)
-  << (int)Actions.getObjCContainerKind();
-  ConsumeTo

[PATCH] D156337: [clang] Allow setting the uninitialized attribute on record

2023-07-28 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 545060.
serge-sans-paille added a comment.

Take reviewers comment into account.


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

https://reviews.llvm.org/D156337

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-uninitialized.c
  clang/test/SemaCXX/constant-expression-cxx14.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp

Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -1362,6 +1362,9 @@
   static_assert(&zti == &typeid(Y));
 }
 
+struct __attribute__((uninitialized)) j { int v; constexpr j() {}};
+static_assert(j().v == 0, ""); // expected-error {{constant expression}} expected-note {{read of uninitialized object is not allowed in a constant expression}}
+
 namespace PR45133 {
   struct A { long x; };
 
Index: clang/test/SemaCXX/constant-expression-cxx14.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -849,6 +849,13 @@
 ({ if (true) {} }); // expected-note {{not supported}}
 return 0;
   }
+
+  // Make sure the uninitialized attribute does not silent constant expression
+  // warnings.
+  constexpr int i() {
+return ({ __attribute__((uninitialized)) int n; n; }); // expected-note {{read of uninitialized object}}
+  }
+  static_assert(i() == 0, ""); // expected-error {{constant expression}} expected-note {{in call}}
 }
 
 namespace VirtualFromBase {
Index: clang/test/Sema/attr-uninitialized.c
===
--- clang/test/Sema/attr-uninitialized.c
+++ clang/test/Sema/attr-uninitialized.c
@@ -18,4 +18,4 @@
 
 struct TheWordIsOut {
   __attribute((uninitialized)) int youre_doin_wrong; // expected-warning {{'uninitialized' attribute only applies to local variables}}
-} __attribute((uninitialized));  // expected-warning {{'uninitialized' attribute only applies to local variables}}
+} __attribute((uninitialized));
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -188,7 +188,7 @@
 // CHECK-NEXT: TargetVersion (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: TrivialABI (SubjectMatchRule_record)
-// CHECK-NEXT: Uninitialized (SubjectMatchRule_variable_is_local)
+// CHECK-NEXT: Uninitialized (SubjectMatchRule_variable_is_local, SubjectMatchRule_record)
 // CHECK-NEXT: UnsafeBufferUsage (SubjectMatchRule_function)
 // CHECK-NEXT: UseHandle (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: VecReturn (SubjectMatchRule_record)
Index: clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
===
--- clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
+++ clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
@@ -38,4 +38,24 @@
 }
 #pragma clang attribute pop
 
+struct [[clang::uninitialized]] uninitialized_record {
+  int i;
+};
+
+// UNINIT-LABEL:  test_record_attribute_uninitialized(
+// UNINIT:  alloca
+// UNINIT-NEXT: call void
+// ZERO-LABEL:test_record_attribute_uninitialized(
+// ZERO:  alloca
+// ZERO-NOT:  !annotation
+// ZERO-NEXT: call void
+// PATTERN-LABEL: test_record_attribute_uninitialized(
+// PATTERN:  alloca
+// PATTERN-NOT:  !annotation
+// PATTERN-NEXT: call void
+void test_record_attribute_uninitialized() {
+  uninitialized_record some;
+  used(some);
+}
+
 } // extern "C"
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8438,8 +8438,10 @@
 }
 
 static void handleUninitializedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
-  assert(cast(D)->getStorageDuration() == SD_Automatic &&
- "uninitialized is only valid on automatic duration variables");
+  assert((isa(D) ||
+  (cast(D)->getStorageDuration() == SD_Automatic)) &&
+ "uninitialized is only valid on automatic duration variables and "
+ "record type");
   D->addAttr(::new (S.Context) UninitializedAttr(S.Context, AL));
 }
 
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp

[clang] b395e91 - [clang][Interp] Implement __builtin_inf() etc.

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T10:50:13+02:00
New Revision: b395e91f2ef41e44c99857b5dd4e241a57d12b76

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

LOG: [clang][Interp] Implement __builtin_inf() etc.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index a8758d8cc0569a..7d8ca716cc8025 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -121,6 +121,15 @@ static bool interp__builtin_nan(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F) {
+  const llvm::fltSemantics &TargetSemantics =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  S.Stk.push(Floating::getInf(TargetSemantics));
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -152,6 +161,20 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F) {
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_huge_val:
+  case Builtin::BI__builtin_huge_valf:
+  case Builtin::BI__builtin_huge_vall:
+  case Builtin::BI__builtin_huge_valf16:
+  case Builtin::BI__builtin_huge_valf128:
+  case Builtin::BI__builtin_inf:
+  case Builtin::BI__builtin_inff:
+  case Builtin::BI__builtin_infl:
+  case Builtin::BI__builtin_inff16:
+  case Builtin::BI__builtin_inff128:
+if (interp__builtin_inf(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }



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


[PATCH] D155367: [clang][Interp] Implement __builtin_inf() etc.

2023-07-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 rGb395e91f2ef4: [clang][Interp] Implement __builtin_inf() etc. 
(authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155367

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp


Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -121,6 +121,15 @@
   return true;
 }
 
+static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F) {
+  const llvm::fltSemantics &TargetSemantics =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  S.Stk.push(Floating::getInf(TargetSemantics));
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -152,6 +161,20 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_huge_val:
+  case Builtin::BI__builtin_huge_valf:
+  case Builtin::BI__builtin_huge_vall:
+  case Builtin::BI__builtin_huge_valf16:
+  case Builtin::BI__builtin_huge_valf128:
+  case Builtin::BI__builtin_inf:
+  case Builtin::BI__builtin_inff:
+  case Builtin::BI__builtin_infl:
+  case Builtin::BI__builtin_inff16:
+  case Builtin::BI__builtin_inff128:
+if (interp__builtin_inf(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }


Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -121,6 +121,15 @@
   return true;
 }
 
+static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function *F) {
+  const llvm::fltSemantics &TargetSemantics =
+  S.getCtx().getFloatTypeSemantics(F->getDecl()->getReturnType());
+
+  S.Stk.push(Floating::getInf(TargetSemantics));
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -152,6 +161,20 @@
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_huge_val:
+  case Builtin::BI__builtin_huge_valf:
+  case Builtin::BI__builtin_huge_vall:
+  case Builtin::BI__builtin_huge_valf16:
+  case Builtin::BI__builtin_huge_valf128:
+  case Builtin::BI__builtin_inf:
+  case Builtin::BI__builtin_inff:
+  case Builtin::BI__builtin_infl:
+  case Builtin::BI__builtin_inff16:
+  case Builtin::BI__builtin_inff128:
+if (interp__builtin_inf(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 57ca62d - [clang][Interp] Implement __builtin_copysign

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T10:55:34+02:00
New Revision: 57ca62d5d35a424722059f42da4a6c75fbba2eb0

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

LOG: [clang][Interp] Implement __builtin_copysign

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 7d8ca716cc8025..e4c0091452e399 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -130,6 +130,19 @@ static bool interp__builtin_inf(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_copysign(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *F) {
+  const Floating &Arg1 = getParam(Frame, 0);
+  const Floating &Arg2 = getParam(Frame, 1);
+
+  APFloat Copy = Arg1.getAPFloat();
+  Copy.copySign(Arg2.getAPFloat());
+  S.Stk.push(Floating(Copy));
+
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -174,6 +187,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F) {
 if (interp__builtin_inf(S, OpPC, Frame, F))
   return Ret(S, OpPC, Dummy);
 break;
+  case Builtin::BI__builtin_copysign:
+  case Builtin::BI__builtin_copysignf:
+  case Builtin::BI__builtin_copysignl:
+  case Builtin::BI__builtin_copysignf128:
+if (interp__builtin_copysign(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
 
   default:
 return false;



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


[PATCH] D155368: [clang][Interp] __builtin_copysign

2023-07-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 rG57ca62d5d35a: [clang][Interp] Implement __builtin_copysign 
(authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D155368?vs=541325&id=545065#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155368

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp


Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -130,6 +130,19 @@
   return true;
 }
 
+static bool interp__builtin_copysign(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *F) {
+  const Floating &Arg1 = getParam(Frame, 0);
+  const Floating &Arg2 = getParam(Frame, 1);
+
+  APFloat Copy = Arg1.getAPFloat();
+  Copy.copySign(Arg2.getAPFloat());
+  S.Stk.push(Floating(Copy));
+
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -174,6 +187,13 @@
 if (interp__builtin_inf(S, OpPC, Frame, F))
   return Ret(S, OpPC, Dummy);
 break;
+  case Builtin::BI__builtin_copysign:
+  case Builtin::BI__builtin_copysignf:
+  case Builtin::BI__builtin_copysignl:
+  case Builtin::BI__builtin_copysignf128:
+if (interp__builtin_copysign(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
 
   default:
 return false;


Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -130,6 +130,19 @@
   return true;
 }
 
+static bool interp__builtin_copysign(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *F) {
+  const Floating &Arg1 = getParam(Frame, 0);
+  const Floating &Arg2 = getParam(Frame, 1);
+
+  APFloat Copy = Arg1.getAPFloat();
+  Copy.copySign(Arg2.getAPFloat());
+  S.Stk.push(Floating(Copy));
+
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
   InterpFrame *Frame = S.Current;
   APValue Dummy;
@@ -174,6 +187,13 @@
 if (interp__builtin_inf(S, OpPC, Frame, F))
   return Ret(S, OpPC, Dummy);
 break;
+  case Builtin::BI__builtin_copysign:
+  case Builtin::BI__builtin_copysignf:
+  case Builtin::BI__builtin_copysignl:
+  case Builtin::BI__builtin_copysignf128:
+if (interp__builtin_copysign(S, OpPC, Frame, F))
+  return Ret(S, OpPC, Dummy);
+break;
 
   default:
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156277: [Parser][ObjC] Fix parser crash on nested top-level block with better recovery path

2023-07-28 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 545069.
danix800 added a comment.

Update `clang/docs/ReleaseNotes.rst`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseObjc.cpp
  clang/test/Parser/missing-end-1-gh64065-nocrash.m
  clang/test/Parser/missing-end-2.m
  clang/test/Parser/missing-end-3.m
  clang/test/Parser/missing-end-4.m

Index: clang/test/Parser/missing-end-4.m
===
--- clang/test/Parser/missing-end-4.m
+++ clang/test/Parser/missing-end-4.m
@@ -37,10 +37,10 @@
 - (C*) MyMeth {}
 @end
 
-@interface I2 {}
-@protocol P2; // expected-error {{illegal interface qualifier}}
-@class C2; // expected-error {{illegal interface qualifier}}
-@end
+@interface I2 {} // expected-note {{class started here}}
+@protocol P2; // expected-error {{missing '@end'}}
+@class C2;
+@end // expected-error {{'@end' must appear in an Objective-C context}}
 
 @interface I3
 @end
Index: clang/test/Parser/missing-end-3.m
===
--- clang/test/Parser/missing-end-3.m
+++ clang/test/Parser/missing-end-3.m
@@ -1,10 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // rdar://8283484
+// expected-note@+1 {{previous definition is here}}
 @interface blah { // expected-note {{class started here}}
 @private
 }
 // since I forgot the @end here it should say something
 
+// expected-error@+1 {{duplicate interface definition for class 'blah'}}
 @interface blah  // expected-error {{missing '@end'}}
-@end // and Unknown type name 'end' here
+@end
 
Index: clang/test/Parser/missing-end-2.m
===
--- clang/test/Parser/missing-end-2.m
+++ clang/test/Parser/missing-end-2.m
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -verify %s
 // rdar: //7824372
 
 @interface A // expected-note {{class started here}}
--(void) im0;
+-(void) im0; // expected-note {{method 'im0' declared here}}
 
+// expected-warning@+1 {{method definition for 'im0' not found}}
 @implementation A // expected-error {{missing '@end'}}
 @end
 
@@ -13,7 +14,8 @@
 @implementation B // expected-error {{missing '@end'}}
 @end
 
-@interface C // expected-note 2 {{class started here}}
+@interface C // expected-note 1 {{class started here}}
 @property int P;
 
+// expected-note@+1 {{implementation started here}}
 @implementation C // expected-error 2 {{missing '@end'}}
Index: clang/test/Parser/missing-end-1-gh64065-nocrash.m
===
--- /dev/null
+++ clang/test/Parser/missing-end-1-gh64065-nocrash.m
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@interface Roo // expected-note {{class started here}}
+// expected-error@+1 {{missing '@end'}}
+@interface // expected-error {{expected identifier}}
Index: clang/lib/Parse/ParseObjc.cpp
===
--- clang/lib/Parse/ParseObjc.cpp
+++ clang/lib/Parse/ParseObjc.cpp
@@ -705,15 +705,30 @@
   continue;
 }
 
-// Otherwise, we have an @ directive, eat the @.
-SourceLocation AtLoc = ConsumeToken(); // the "@"
-if (Tok.is(tok::code_completion)) {
+// Otherwise, we have an @ directive, peak at the next token
+SourceLocation AtLoc = Tok.getLocation();
+const auto &NextTok = NextToken();
+if (NextTok.is(tok::code_completion)) {
   cutOffParsing();
   Actions.CodeCompleteObjCAtDirective(getCurScope());
   return;
 }
 
-tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID();
+tok::ObjCKeywordKind DirectiveKind = NextTok.getObjCKeywordID();
+// Bail out as if we saw an '@end'
+switch (DirectiveKind) {
+case tok::objc_class:
+case tok::objc_compatibility_alias:
+case tok::objc_interface:
+case tok::objc_implementation:
+case tok::objc_protocol:
+  goto MISSING_END;
+default:
+  break;
+}
+
+// Otherwise parse it as part of the current declaration. Eat the "@".
+ConsumeToken();
 
 if (DirectiveKind == tok::objc_end) { // @end -> terminate list
   AtEnd.setBegin(AtLoc);
@@ -739,15 +754,6 @@
   SkipUntil(tok::r_brace, tok::at, StopAtSemi);
   break;
 
-case tok::objc_implementation:
-case tok::objc_interface:
-  Diag(AtLoc, diag::err_objc_missing_end)
-  << FixItHint::CreateInsertion(AtLoc, "@end\n");
-  Diag(CDecl->getBeginLoc(), diag::note_objc_container_start)
-  << (int)Actions.getObjCContainerKind();
-  ConsumeToken();
-  break;
-
 case tok::objc_required:
 case tok::objc_optional:
   // This is only valid on protocols.
@@ -825,6 +831,7 @@
   } else if (Tok.isObjCAtKeyword(tok::objc_end)) {
 ConsumeToken(); // the "end" identifier
   } 

[PATCH] D156277: [Parser][ObjC] Fix parser crash on nested top-level block with better recovery path

2023-07-28 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/Parse/ParseObjc.cpp:749
+  if (!Tok.is(tok::eof))
+ConsumeToken();
   break;

rjmccall wrote:
> danix800 wrote:
> > rjmccall wrote:
> > > aaron.ballman wrote:
> > > > rjmccall wrote:
> > > > > aaron.ballman wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > danix800 wrote:
> > > > > > > > tbaeder wrote:
> > > > > > > > > Why is there a `ConsumeToken()` call at all here? The token 
> > > > > > > > > is already being consumed in line 729.
> > > > > > > > Didn't notice this, thanks for reminding!
> > > > > > > I have the same question as @tbaeder -- what token is this 
> > > > > > > intending to consume? CC @rjmccall for Obj-C expertise
> > > > > > OH! This is consuming the identifier for the 
> > > > > > implementation/interface name itself. e.g.,
> > > > > > ```
> > > > > > @interface Frobble
> > > > > > ```
> > > > > > The consume on line 709 gets the `@`, the consume on line 729 gets 
> > > > > > the `interface`, and the consume on line 749 is getting the 
> > > > > > `Frobble`. That makes sense to me now.
> > > > > > 
> > > > > I don't think any language expertise is required here — just seems 
> > > > > like a straightforward bug on an error path that's probably not 
> > > > > exercised all that often.  Maybe somebody moved the `ConsumeToken` 
> > > > > and forgot to fix this case or something.
> > > > What concerns me about this fix is that we don't typically check 
> > > > whether the token is EOF or not before consuming; that's usually an 
> > > > anti-pattern, isn't it? Wouldn't it make sense for this to use 
> > > > `SkipUntil(tok::identifier)` instead?
> > > Okay, so now I can bring a little language expertise to bear. :)
> > > 
> > > We're in the middle of parsing an ObjC block (e.g. `@interface`), and we 
> > > see `@interface` or `@implementation`, which starts a new block.  You can 
> > > never nest these ObjC blocks, so the parser is reasonably assuming that 
> > > the second `@keyword` is an attempt to start a new block and the user 
> > > just forgot to terminate the last block with `@end`.  Unfortunately, the 
> > > actual recovery done by the parser doesn't seem to match the diagnostic 
> > > and the fixit — it's trying to swallow `@interface Foo` (or whatever) and 
> > > then continue the loop as if it were part of the current block, which is 
> > > definitely not the right thing to do.
> > > 
> > > The right way to recover here is to act like we actually saw `@end` and 
> > > break out of the loop, leaving `Tok` on the `@` so that the parser will 
> > > pick up parsing `@interface` normally after we return.  To do that, we 
> > > just need to get the ObjC keyword by peeking at the next token instead of 
> > > consuming.
> > > 
> > > Also, we should take this recovery path on every `@` keyword that's only 
> > > allowed at the top level (so `@class`, `@compatibility_alias`, 
> > > `@interface`, `@implementation`, and `@protocol`).
> > It's really great to learn things here! I don't know two much about ObjC. I 
> > seached google trying to find some standard or specs for ObjC but only docs 
> > like tutorials teaching how to use it can be found, so I might not be able 
> > to give a good enough fix for this issue. I'll give it a try though.
> You should be able to follow the guidance here without needing to know much 
> more about ObjC, just understanding how the parser works.  The key is that 
> you need to delay consuming tokens until you're certain you're going to 
> commit to parsing this `@`-directive as part of the current declaration.
> 
> Start with the line `SourceLocation AtLoc = ConsumeToken();`  Instead of 
> consuming the `@` and then looking at `Tok` to see what the keyword is, you 
> can get the location of `Tok` without consuming it, then use `NextToken()` to 
> peek ahead to the next token to see the keyword.
> 
> Be sure to sink the right number of `ConsumeToken` calls down onto all of the 
> paths that *aren't* bailing out.
Actually `clang/lib/Parse/ParseObjc.cpp` has ObjC part of the syntax well 
documented, plus well written code, it's really helpful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156277

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


[clang] 9a0164a - [clang][Interp] Fix comparing nan/inf floating point values

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T11:12:25+02:00
New Revision: 9a0164a0c66c28363fbc9410edd5656b28811427

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

LOG: [clang][Interp] Fix comparing nan/inf floating point values

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

Added: 


Modified: 
clang/lib/AST/Interp/Floating.h
clang/test/AST/Interp/floats.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Floating.h b/clang/lib/AST/Interp/Floating.h
index 85876236a9998e..447361a43696b0 100644
--- a/clang/lib/AST/Interp/Floating.h
+++ b/clang/lib/AST/Interp/Floating.h
@@ -90,7 +90,18 @@ class Floating final {
   bool isFinite() const { return F.isFinite(); }
 
   ComparisonCategoryResult compare(const Floating &RHS) const {
-return Compare(F, RHS.F);
+llvm::APFloatBase::cmpResult CmpRes = F.compare(RHS.F);
+switch (CmpRes) {
+case llvm::APFloatBase::cmpLessThan:
+  return ComparisonCategoryResult::Less;
+case llvm::APFloatBase::cmpEqual:
+  return ComparisonCategoryResult::Equal;
+case llvm::APFloatBase::cmpGreaterThan:
+  return ComparisonCategoryResult::Greater;
+case llvm::APFloatBase::cmpUnordered:
+  return ComparisonCategoryResult::Unordered;
+}
+llvm_unreachable("Inavlid cmpResult value");
   }
 
   static APFloat::opStatus fromIntegral(APSInt Val,

diff  --git a/clang/test/AST/Interp/floats.cpp 
b/clang/test/AST/Interp/floats.cpp
index fb9f1ac24bc75f..4ec00a2d677ede 100644
--- a/clang/test/AST/Interp/floats.cpp
+++ b/clang/test/AST/Interp/floats.cpp
@@ -145,3 +145,12 @@ namespace ZeroInit {
 namespace LongDouble {
   constexpr long double ld = 3.1425926539;
 }
+
+namespace Compare {
+  constexpr float nan = __builtin_nan("");
+  constexpr float inf = __builtin_inf();
+  static_assert(!(nan == nan), "");
+  static_assert(nan != nan, "");
+  static_assert(!(inf < nan), "");
+  static_assert(!(inf > nan), "");
+}



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


[PATCH] D155410: [clang][Interp] Fix comparing nan/inf floating point values

2023-07-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 rG9a0164a0c66c: [clang][Interp] Fix comparing nan/inf floating 
point values (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D155410?vs=540832&id=545072#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155410

Files:
  clang/lib/AST/Interp/Floating.h
  clang/test/AST/Interp/floats.cpp


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -145,3 +145,12 @@
 namespace LongDouble {
   constexpr long double ld = 3.1425926539;
 }
+
+namespace Compare {
+  constexpr float nan = __builtin_nan("");
+  constexpr float inf = __builtin_inf();
+  static_assert(!(nan == nan), "");
+  static_assert(nan != nan, "");
+  static_assert(!(inf < nan), "");
+  static_assert(!(inf > nan), "");
+}
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -90,7 +90,18 @@
   bool isFinite() const { return F.isFinite(); }
 
   ComparisonCategoryResult compare(const Floating &RHS) const {
-return Compare(F, RHS.F);
+llvm::APFloatBase::cmpResult CmpRes = F.compare(RHS.F);
+switch (CmpRes) {
+case llvm::APFloatBase::cmpLessThan:
+  return ComparisonCategoryResult::Less;
+case llvm::APFloatBase::cmpEqual:
+  return ComparisonCategoryResult::Equal;
+case llvm::APFloatBase::cmpGreaterThan:
+  return ComparisonCategoryResult::Greater;
+case llvm::APFloatBase::cmpUnordered:
+  return ComparisonCategoryResult::Unordered;
+}
+llvm_unreachable("Inavlid cmpResult value");
   }
 
   static APFloat::opStatus fromIntegral(APSInt Val,


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -145,3 +145,12 @@
 namespace LongDouble {
   constexpr long double ld = 3.1425926539;
 }
+
+namespace Compare {
+  constexpr float nan = __builtin_nan("");
+  constexpr float inf = __builtin_inf();
+  static_assert(!(nan == nan), "");
+  static_assert(nan != nan, "");
+  static_assert(!(inf < nan), "");
+  static_assert(!(inf > nan), "");
+}
Index: clang/lib/AST/Interp/Floating.h
===
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -90,7 +90,18 @@
   bool isFinite() const { return F.isFinite(); }
 
   ComparisonCategoryResult compare(const Floating &RHS) const {
-return Compare(F, RHS.F);
+llvm::APFloatBase::cmpResult CmpRes = F.compare(RHS.F);
+switch (CmpRes) {
+case llvm::APFloatBase::cmpLessThan:
+  return ComparisonCategoryResult::Less;
+case llvm::APFloatBase::cmpEqual:
+  return ComparisonCategoryResult::Equal;
+case llvm::APFloatBase::cmpGreaterThan:
+  return ComparisonCategoryResult::Greater;
+case llvm::APFloatBase::cmpUnordered:
+  return ComparisonCategoryResult::Unordered;
+}
+llvm_unreachable("Inavlid cmpResult value");
   }
 
   static APFloat::opStatus fromIntegral(APSInt Val,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1478d4d - [clang][Interp] Disable a float128/long double test

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T11:19:35+02:00
New Revision: 1478d4dc8dc44c109bff1bbe0486cc40674a0ee2

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

LOG: [clang][Interp] Disable a float128/long double test

This breaks ppc64le builders:
https://lab.llvm.org/buildbot/#builders/230/builds/16405

Added: 


Modified: 
clang/test/AST/Interp/builtin-functions.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index ef28f003117dc3..eec6c9ec4bbf81 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -47,7 +47,7 @@ namespace nan {
   constexpr double NaN3 = __builtin_nan("foo"); // expected-error {{must be 
initialized by a constant expression}} \
 // ref-error {{must be 
initialized by a constant expression}}
   constexpr float NaN4 = __builtin_nanf("");
-  constexpr long double NaN5 = __builtin_nanf128("");
+  //constexpr long double NaN5 = __builtin_nanf128("");
 
   /// FIXME: This should be accepted by the current interpreter as well.
   constexpr char f[] = {'0', 'x', 'A', 'E', '\0'};



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


[PATCH] D156337: [clang] Allow setting the uninitialized attribute on record

2023-07-28 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 545074.
serge-sans-paille added a comment.

(rebased on `main`)


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

https://reviews.llvm.org/D156337

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-uninitialized.c
  clang/test/SemaCXX/constant-expression-cxx14.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp

Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -1362,6 +1362,9 @@
   static_assert(&zti == &typeid(Y));
 }
 
+struct __attribute__((uninitialized)) j { int v; constexpr j() {}};
+static_assert(j().v == 0, ""); // expected-error {{constant expression}} expected-note {{read of uninitialized object is not allowed in a constant expression}}
+
 namespace PR45133 {
   struct A { long x; };
 
Index: clang/test/SemaCXX/constant-expression-cxx14.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -850,6 +850,13 @@
 ({ if (true) {} }); // expected-note {{not supported}}
 return 0;
   }
+
+  // Make sure the uninitialized attribute does not silent constant expression
+  // warnings.
+  constexpr int i() {
+return ({ __attribute__((uninitialized)) int n; n; }); // expected-note {{read of uninitialized object}}
+  }
+  static_assert(i() == 0, ""); // expected-error {{constant expression}} expected-note {{in call}}
 }
 
 namespace VirtualFromBase {
Index: clang/test/Sema/attr-uninitialized.c
===
--- clang/test/Sema/attr-uninitialized.c
+++ clang/test/Sema/attr-uninitialized.c
@@ -18,4 +18,4 @@
 
 struct TheWordIsOut {
   __attribute((uninitialized)) int youre_doin_wrong; // expected-warning {{'uninitialized' attribute only applies to local variables}}
-} __attribute((uninitialized));  // expected-warning {{'uninitialized' attribute only applies to local variables}}
+} __attribute((uninitialized));
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -188,7 +188,7 @@
 // CHECK-NEXT: TargetVersion (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: TrivialABI (SubjectMatchRule_record)
-// CHECK-NEXT: Uninitialized (SubjectMatchRule_variable_is_local)
+// CHECK-NEXT: Uninitialized (SubjectMatchRule_variable_is_local, SubjectMatchRule_record)
 // CHECK-NEXT: UnsafeBufferUsage (SubjectMatchRule_function)
 // CHECK-NEXT: UseHandle (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: VecReturn (SubjectMatchRule_record)
Index: clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
===
--- clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
+++ clang/test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
@@ -38,4 +38,24 @@
 }
 #pragma clang attribute pop
 
+struct [[clang::uninitialized]] uninitialized_record {
+  int i;
+};
+
+// UNINIT-LABEL:  test_record_attribute_uninitialized(
+// UNINIT:  alloca
+// UNINIT-NEXT: call void
+// ZERO-LABEL:test_record_attribute_uninitialized(
+// ZERO:  alloca
+// ZERO-NOT:  !annotation
+// ZERO-NEXT: call void
+// PATTERN-LABEL: test_record_attribute_uninitialized(
+// PATTERN:  alloca
+// PATTERN-NOT:  !annotation
+// PATTERN-NEXT: call void
+void test_record_attribute_uninitialized() {
+  uninitialized_record some;
+  used(some);
+}
+
 } // extern "C"
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8457,8 +8457,10 @@
 }
 
 static void handleUninitializedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
-  assert(cast(D)->getStorageDuration() == SD_Automatic &&
- "uninitialized is only valid on automatic duration variables");
+  assert((isa(D) ||
+  (cast(D)->getStorageDuration() == SD_Automatic)) &&
+ "uninitialized is only valid on automatic duration variables and "
+ "record type");
   D->addAttr(::new (S.Context) UninitializedAttr(S.Context, AL));
 }
 
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -1905,13 +1905

[PATCH] D138263: [clang-format] Supress aligning of trailing namespace comments

2023-07-28 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2964-2965
   if (FormatTok->is(tok::l_brace)) {
+FormatToken *LBrace = FormatTok;
+LBrace->setFinalizedType(TT_NamespaceLBrace);
+

Nit.


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

https://reviews.llvm.org/D138263

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


[PATCH] D156518: Fix handling of medial hyphens in Unicode Names.

2023-07-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added subscribers: mstorsjo, hiraditya, dschuff.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

In a Unicode name was stored in a way that caused
a medial hyphen to be at the end of a a chunk, it would not
be properly ignored by the loose matching algorithm.

For example if `LEFT-TO-RIGHT OVERRIDE` was stored as
`LEFT-` [...], the `-` would not be ignored.

The generators now ensures nodes are not cut accross
medial hyphen boundaries.

Fixes #64161


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156518

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[clang] f04ccad - [Flang] Add support for fsave-optimization-record

2023-07-28 Thread Kiran Chandramohan via cfe-commits

Author: Victor Kingi
Date: 2023-07-28T09:26:40Z
New Revision: f04ccadf35441b2e13b3ab30edeef251818fa9c7

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

LOG: [Flang] Add support for fsave-optimization-record

Add support for generating and saving the optimization record.
Optimization record lists the optimizations performed by LLVM.

This patch enables the flag in Flang. Clang handles this functionality
using the BackendConsumer which Flang doesn't have, hence, was
implemented in CodeGenAction::executeAction

FlangOption added to all variants of fsave-optimization-record in
clang/include/clang/Driver/Options.td . Clang handles it the
same way.

opt_record_file, opt_record_passes and opt_record_format flags
in Options.td were moved out of the group [CC1Option, NoDriverOption]
to allow flang -fc1 support.

The renderRemarksOptions and willEmitRemarks functions in
clang/lib/Driver/ToolChains/Flang.cpp follow same syntax as clang.
In flang/lib/Frontend/CompilerInvocation.cpp we update the field
OptRecordFile with the provided optimization file value. Clang
doesn't do this as it processes the Options.td, mapping the
OptRecordFile earlier on.

Reviewed By: awarzynski, tblah

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

Added: 
flang/test/Driver/fsave-optimization-record.f90

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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8be3fbf61ce106..9b44e11535c2a9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3084,18 +3084,18 @@ def foperator_arrow_depth_EQ : Joined<["-"], 
"foperator-arrow-depth=">, Group's to call for a member access">,
   MarshallingInfoInt, "256">;
 
-def fsave_optimization_record : Flag<["-"], "fsave-optimization-record">,
+def fsave_optimization_record : Flag<["-"], "fsave-optimization-record">, 
Flags<[FlangOption]>,
   Group, HelpText<"Generate a YAML optimization record file">;
-def fsave_optimization_record_EQ : Joined<["-"], "fsave-optimization-record=">,
+def fsave_optimization_record_EQ : Joined<["-"], 
"fsave-optimization-record=">, Flags<[FlangOption]>,
   Group, HelpText<"Generate an optimization record file in a specific 
format">,
   MetaVarName<"">;
 def fno_save_optimization_record : Flag<["-"], "fno-save-optimization-record">,
-  Group, Flags<[NoArgumentUnused]>;
-def foptimization_record_file_EQ : Joined<["-"], "foptimization-record-file=">,
+  Group, Flags<[FlangOption, NoArgumentUnused]>;
+def foptimization_record_file_EQ : Joined<["-"], 
"foptimization-record-file=">, Flags<[FlangOption]>,
   Group,
   HelpText<"Specify the output name of the file containing the optimization 
remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot 
be used with multiple -arch  options.">,
   MetaVarName<"">;
-def foptimization_record_passes_EQ : Joined<["-"], 
"foptimization-record-passes=">,
+def foptimization_record_passes_EQ : Joined<["-"], 
"foptimization-record-passes=">, Flags<[FlangOption]>,
   Group,
   HelpText<"Only include passes which match a specified regular expression in 
the generated optimization record (by default, include all passes)">,
   MetaVarName<"">;
@@ -6390,14 +6390,6 @@ def arcmt_action_EQ : Joined<["-"], "arcmt-action=">, 
Flags<[CC1Option, NoDriver
   NormalizedValues<["ARCMT_Check", "ARCMT_Modify", "ARCMT_Migrate"]>,
   MarshallingInfoEnum, "ARCMT_None">;
 
-def opt_record_file : Separate<["-"], "opt-record-file">,
-  HelpText<"File name to use for YAML optimization record output">,
-  MarshallingInfoString>;
-def opt_record_passes : Separate<["-"], "opt-record-passes">,
-  HelpText<"Only record remark information for passes whose names match the 
given regular expression">;
-def opt_record_format : Separate<["-"], "opt-record-format">,
-  HelpText<"The format used for serializing remarks (default: YAML)">;
-
 def print_stats : Flag<["-"], "print-stats">,
   HelpText<"Print performance metrics and statistics">,
   MarshallingInfoFlag>;
@@ -6838,6 +6830,14 @@ defm debug_pass_manager : BoolOption<"f", 
"debug-pass-manager",
   PosFlag,
   NegFlag>;
 
+def opt_record_file : Separate<["-"], "opt-record-file">,
+  HelpText<"File name to use for YAML optimization record output">,
+  MarshallingInfoString>;
+def opt_record_passes : Separate<["-"], "opt-record-passes">,
+  HelpText<"Only record remark information for passes whose names match the 
given regular expression">;
+def opt_record_f

[PATCH] D155452: [Flang] Add support for fsave-optimization-record

2023-07-28 Thread Kiran Chandramohan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf04ccadf3544: [Flang] Add support for 
fsave-optimization-record (authored by Victor Kingi 
, committed by kiranchandramohan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155452

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/fsave-optimization-record.f90

Index: flang/test/Driver/fsave-optimization-record.f90
===
--- /dev/null
+++ flang/test/Driver/fsave-optimization-record.f90
@@ -0,0 +1,59 @@
+! Tests for the '-f[no-]save-optimization-record[=]' flag.
+
+! Test opt_record flags get generated for fc1
+! RUN: %flang -### %s 2>&1 \
+! RUN: -foptimization-record-file=%t.opt.yaml \
+! RUN:   | FileCheck --check-prefix=YAML %s
+
+! RUN: %flang -### %s 2>&1 \
+! RUN: -fsave-optimization-record \
+! RUN:   | FileCheck --check-prefix=YAML %s
+
+
+! Test -foptimization-record-file produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -foptimization-record-file=%t.opt.yaml -c %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+
+! Test -fsave-optimization-record produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -c -o %t.o %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -o %t.s %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+
+! Produces an empty file
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -emit-llvm -o %t.ll %s
+! RUN: cat %t.opt.yaml
+
+
+!Test unknown format produces error
+! RUN: not %flang -fsave-optimization-record=hello %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-FORMAT-ERROR %s
+
+
+! YAML: "-opt-record-file" "{{.+}}.opt.yaml"
+! YAML: "-opt-record-format" "yaml"
+
+! CHECK: --- !Analysis
+! CHECK: Pass:prologepilog
+! CHECK: Name:StackSize
+! CHECK: Function:_QQmain
+! CHECK: Pass:asm-printer
+! CHECK: Name:InstructionMix
+! CHECK: Name:InstructionCount
+
+! CHECK-FORMAT-ERROR: error: unknown remark serializer format: 'hello'
+
+program forttest
+implicit none
+integer :: n
+
+n = 1 * 1
+
+end program forttest
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -54,8 +54,16 @@
 ! HELP-NEXT: -fopenmp-version=
 ! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-NEXT: -foptimization-record-file=
+! HELP-NEXT:Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch  options.
+! HELP-NEXT: -foptimization-record-passes=
+! HELP-NEXT:Only include passes which match a specified regular expression in the generated optimization record (by default, include all passes)
 ! HELP-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-NEXT: -freciprocal-math  Allow division operations to be reassociated
+! HELP-NEXT: -fsave-optimization-record=
+! HELP-NEXT:Generate an optimization record file in a specific format
+! HELP-NEXT: -fsave-optimization-record
+! HELP-NEXT:Generate a YAML optimization record file
 ! HELP-NEXT: -fstack-arrays Attempt to allocate array temporaries on the stack, no matter their size
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -funderscoring Appends one trailing underscore to external names
@@ -186,6 +194,12 @@
 ! HELP-FC1-NEXT: -mrelocation-model 
 ! HELP-FC1-NEXT:The relocation model to use
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
+! HELP-FC1-NEXT: -opt-record-file 
+! HELP-FC1-NEXT:File name to use for YAML optimization record output
+! HELP-FC1-NEXT: -opt-record-format 
+! HELP-FC1-NEXT:The format used for serializing remarks (default: YAML)
+! HELP-FC1-NEXT: -opt-record-passes 
+! HELP-FC1-NEXT:Only record remark information for passes whose names match the given regular expression
 ! HELP-F

[PATCH] D156518: Fix handling of medial hyphens in Unicode Names.

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



Comment at: llvm/lib/Support/UnicodeNameToCodepoint.cpp:350
 bool DoesStartWith = startsWith(Name, Item.Prefix, Strict, Consummed,
-NameStart, NeedleStart, /*isPrefix*/ true);
+NameStart, /*IsPrefix*/ true);
 if (!DoesStartWith)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156518

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


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

2023-07-28 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added subscribers: thieta, tstellar.
ilya-biryukov added a comment.

@aaron.ballman the internal `-cc1` flag is good enough for us and should 
aleviate most of the concerns in this thread. We could also live without a 
libc++ change.
I suggest to move forward with `-cc1` flag. Would that be okay or do you feel 
this does not address some of the concerns mentioned in the thread?

@thieta, @tstellar would you be willing to cherry-pick a flag to disable 
coroutines to a release branch?
There are two potential forms, in case the answers differ:

- user-facing `clang -fno-coroutines` flag,
- internal `clang -cc1 -fno-coroutines`.



In D156247#4540228 , @Mordante wrote:

> 2. My biggest concern is the timing of this patch. The date of the branching 
> is know upfront and well communicated by the release managers. This patch was 
> created after the LLVM-17 branch was created. For libc++ this patch would be 
> a new feature which has no patch at the moment. This means we're asked to add 
> a new feature after RC1. In libc++ we normally avoid adding new features in 
> the release branch.

I am sorry for sending the patch late, we have not thought about it before. I 
have already mentioned that before in the thread.
We could have foreseen the need for this change before, but we did not and 
there is nothing I can do to fix it now.

> @ilya-biryukov if you feel strongly about pursuing this patch I would like to 
> see:

As mentioned before, we feel this would give us substantial benefits when 
rolling out C++20.
I acknowledge that coroutines are good enough for most people and those bugs 
may not be a problem. We are overly cautious, our bar is higher and we would 
not to ship coroutines with those bugs (at the very least we'd like to have an 
option to bail out).

> - a consensus of the Clang developers this is really needed,
> - a pre-approval by the release managers to apply these changes to the 
> release branch,

I have asked the release managers above.

> - a libc++ patch that works with `-fno-coroutines`, which I would be happy to 
> review.

I will check what needs to be done for libc++ here, I suspect adding `#error` 
inside `` if the feature macro is not defined should be enough.
It might not be necessary if we use a `-cc1` flag.

In D156247#4541003 , @ChuanqiXu wrote:

>> We should reach out to some GCC folks to see if this is an oversight in 
>> their documentation or not.
>
> I've sent a mail: https://gcc.gnu.org/pipermail/gcc/2023-July/242159.html

Thanks, there is now a response in the thread saying that documentation 
intentionally leaves out most `-fno-foo` flags and GCC supports 
`-fno-coroutines`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[PATCH] D156518: Fix handling of medial hyphens in Unicode Names.

2023-07-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 545078.
cor3ntin added a comment.

Fix comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156518

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D156405: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 545079.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156405

Files:
  clang/lib/Frontend/FrontendAction.cpp


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) 
=
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) =
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156406: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 545080.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156406

Files:
  clang/include/clang/Sema/IdentifierResolver.h


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor &PP);
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver &operator=(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor &PP);
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver &operator=(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156415: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 545082.
Fznamznon added a comment.

Rebase to maybe pass precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156415

Files:
  clang/include/clang/Analysis/CFGStmtMap.h


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap &operator=(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap &operator=(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105759: Implement P2361 Unevaluated string literals

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

In D105759#4540716 , 
@hubert.reinterpretcast wrote:

>> I hope this patch may allow to gather some data on that.
>
> @cor3ntin, I have reports that applications having encoding prefixes in 
> `static_assert` are failing to build. The committee did not adopt the subject 
> paper as a "DR resolution". Is it possible to downgrade to a warning?

You know how frequent it is?

Making it a warning is possible but not straightforward.

Previously with a prefix, it was parsed as a wide (for example) string, and we 
relied on the fact that L was UTF-16/32 to sometimes print a reasonable 
diagnostics - and sometimes not https://godbolt.org/z/f3Pj4T5aj
This is going to be worse when we add -fexec-charset:

- `static_assert(true, L"やあ")` is going to be ill-formed when coded as, eg, 
EBCDIC because it's not representable, and if it is representable we need to 
either output mojibake or convert the string back to UTF-8 which we are 
currently not doing.

Another solution maybe to lexically ignore prefixes by replacing the string 
literal token on the fly such that they are still parsed as unevaluated strings 
and not encoded, i could look into that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105759

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


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

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

How does a -cc1 flag alleviate the burden concerns for libc++? It would still 
be something they would have to support, unless we plan to remove the flag 
before c++26 and you are happy with the inclusion of `` and 
`` producing subpar errors.
However, in the C++26 cycle, `` (P2300 
) is going to have a dependency on 
``, and it does not seem reasonable for that to lead to errors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[PATCH] D156503: [clang][Interp] Don't assume throw stmts have a subexpr

2023-07-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

This one was easy!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156503

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


[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a subscriber: rsmith.
cor3ntin added a comment.

@efriedma I sent a mail to core last night, some discussion is happening. 
@rsmith  made some good point so hopefully we will be able to produce some hard 
error in that case,
But given this is preexisting, I'm going to land that and hopefully we can 
merge it in the 17 branch in the next few weeks. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

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


[clang] 81fb216 - [clang][Diagnostics] Provide source range to invalid casts in const expr

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T12:28:45+02:00
New Revision: 81fb216245784582277663a68d535dd7f66456cb

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

LOG: [clang][Diagnostics] Provide source range to invalid casts in const expr

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Interp/Interp.cpp
clang/test/Misc/constexpr-source-ranges.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 755e71f6011d6c..d9208b53e44994 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13773,7 +13773,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) 
{
 
   case CK_PointerToIntegral: {
 CCEDiag(E, diag::note_constexpr_invalid_cast)
-<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
+<< 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
 
 LValue LV;
 if (!EvaluatePointer(SubExpr, LV, Info))

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 4d49c75799637b..b891306e6aa405 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -469,7 +469,7 @@ bool CheckPotentialReinterpretCast(InterpState &S, CodePtr 
OpPC,
 
   const SourceInfo &E = S.Current->getSource(OpPC);
   S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 2 << S.getLangOpts().CPlusPlus;
+  << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
   return false;
 }
 

diff  --git a/clang/test/Misc/constexpr-source-ranges.cpp 
b/clang/test/Misc/constexpr-source-ranges.cpp
index 9ab6cc49200166..c4f83cbb0e23a4 100644
--- a/clang/test/Misc/constexpr-source-ranges.cpp
+++ b/clang/test/Misc/constexpr-source-ranges.cpp
@@ -7,3 +7,9 @@ constexpr int f() {
 }
 
 // CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}
+
+
+constexpr int I = 12;
+constexpr const int *P = &I;
+constexpr long L = (long)P;
+// CHECK: constexpr-source-ranges.cpp:14:20:{14:20-14:27}



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


[PATCH] D153241: [clang][Diagnostics] Provide source range to invalid casts in const expr

2023-07-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 rG81fb21624578: [clang][Diagnostics] Provide source range to 
invalid casts in const expr (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153241

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/test/Misc/constexpr-source-ranges.cpp


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -7,3 +7,9 @@
 }
 
 // CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}
+
+
+constexpr int I = 12;
+constexpr const int *P = &I;
+constexpr long L = (long)P;
+// CHECK: constexpr-source-ranges.cpp:14:20:{14:20-14:27}
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -469,7 +469,7 @@
 
   const SourceInfo &E = S.Current->getSource(OpPC);
   S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 2 << S.getLangOpts().CPlusPlus;
+  << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
   return false;
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13773,7 +13773,7 @@
 
   case CK_PointerToIntegral: {
 CCEDiag(E, diag::note_constexpr_invalid_cast)
-<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
+<< 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
 
 LValue LV;
 if (!EvaluatePointer(SubExpr, LV, Info))


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -7,3 +7,9 @@
 }
 
 // CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}
+
+
+constexpr int I = 12;
+constexpr const int *P = &I;
+constexpr long L = (long)P;
+// CHECK: constexpr-source-ranges.cpp:14:20:{14:20-14:27}
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -469,7 +469,7 @@
 
   const SourceInfo &E = S.Current->getSource(OpPC);
   S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 2 << S.getLangOpts().CPlusPlus;
+  << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
   return false;
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13773,7 +13773,7 @@
 
   case CK_PointerToIntegral: {
 CCEDiag(E, diag::note_constexpr_invalid_cast)
-<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
+<< 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
 
 LValue LV;
 if (!EvaluatePointer(SubExpr, LV, Info))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156415: [NFC][analyzer] Fix static analyzer concerns

2023-07-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156415

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


[clang] 7010a4f - [clang][Interp] Don't assume throw stmts have a subexpr

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T12:44:53+02:00
New Revision: 7010a4f14e0bb397773915910fbcf557f6ad6816

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

LOG: [clang][Interp] Don't assume throw stmts have a subexpr

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 9f17ba1d7aa05f..70ce1c3750bbf1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1000,7 +1000,7 @@ bool ByteCodeExprGen::VisitPredefinedExpr(const 
PredefinedExpr *E) {
 
 template 
 bool ByteCodeExprGen::VisitCXXThrowExpr(const CXXThrowExpr *E) {
-  if (!this->discard(E->getSubExpr()))
+  if (E->getSubExpr() && !this->discard(E->getSubExpr()))
 return false;
 
   return this->emitInvalid(E);

diff  --git a/clang/test/AST/Interp/invalid.cpp 
b/clang/test/AST/Interp/invalid.cpp
index 9f3477e397eb5c..522ad02f71ce07 100644
--- a/clang/test/AST/Interp/invalid.cpp
+++ b/clang/test/AST/Interp/invalid.cpp
@@ -23,6 +23,17 @@ namespace Throw {
  // ref-note {{subexpression not valid in a constant expression}}
 return 0;
   }
+
+  constexpr int NoSubExpr() { // ref-error {{never produces a constant 
expression}} \
+  // expected-error {{never produces a constant 
expression}}
+throw; // ref-note 2{{subexpression not valid}} \
+   // expected-note 2{{subexpression not valid}}
+return 0;
+  }
+  static_assert(NoSubExpr() == 0, ""); // ref-error {{not an integral constant 
expression}} \
+   // ref-note {{in call to}} \
+   // expected-error {{not an integral 
constant expression}} \
+   // expected-note {{in call to}}
 }
 
 namespace Asm {



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


[PATCH] D156503: [clang][Interp] Don't assume throw stmts have a subexpr

2023-07-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 rG7010a4f14e0b: [clang][Interp] Don't assume throw stmts 
have a subexpr (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156503

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


Index: clang/test/AST/Interp/invalid.cpp
===
--- clang/test/AST/Interp/invalid.cpp
+++ clang/test/AST/Interp/invalid.cpp
@@ -23,6 +23,17 @@
  // ref-note {{subexpression not valid in a constant expression}}
 return 0;
   }
+
+  constexpr int NoSubExpr() { // ref-error {{never produces a constant 
expression}} \
+  // expected-error {{never produces a constant 
expression}}
+throw; // ref-note 2{{subexpression not valid}} \
+   // expected-note 2{{subexpression not valid}}
+return 0;
+  }
+  static_assert(NoSubExpr() == 0, ""); // ref-error {{not an integral constant 
expression}} \
+   // ref-note {{in call to}} \
+   // expected-error {{not an integral 
constant expression}} \
+   // expected-note {{in call to}}
 }
 
 namespace Asm {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1000,7 +1000,7 @@
 
 template 
 bool ByteCodeExprGen::VisitCXXThrowExpr(const CXXThrowExpr *E) {
-  if (!this->discard(E->getSubExpr()))
+  if (E->getSubExpr() && !this->discard(E->getSubExpr()))
 return false;
 
   return this->emitInvalid(E);


Index: clang/test/AST/Interp/invalid.cpp
===
--- clang/test/AST/Interp/invalid.cpp
+++ clang/test/AST/Interp/invalid.cpp
@@ -23,6 +23,17 @@
  // ref-note {{subexpression not valid in a constant expression}}
 return 0;
   }
+
+  constexpr int NoSubExpr() { // ref-error {{never produces a constant expression}} \
+  // expected-error {{never produces a constant expression}}
+throw; // ref-note 2{{subexpression not valid}} \
+   // expected-note 2{{subexpression not valid}}
+return 0;
+  }
+  static_assert(NoSubExpr() == 0, ""); // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to}} \
+   // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to}}
 }
 
 namespace Asm {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1000,7 +1000,7 @@
 
 template 
 bool ByteCodeExprGen::VisitCXXThrowExpr(const CXXThrowExpr *E) {
-  if (!this->discard(E->getSubExpr()))
+  if (E->getSubExpr() && !this->discard(E->getSubExpr()))
 return false;
 
   return this->emitInvalid(E);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3b34d69 - Revert "For #64088: mark vtable as used if we might emit a reference to it."

2023-07-28 Thread Dmitry Chernenkov via cfe-commits

Author: Dmitry Chernenkov
Date: 2023-07-28T10:49:53Z
New Revision: 3b34d69ac7a643742364be3591b324ddd14ef9aa

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

LOG: Revert "For #64088: mark vtable as used if we might emit a reference to 
it."

This reverts commit b6847edfc235829b37dd6d734ef5bbfa0a58b6fc.

Added: 


Modified: 
clang/lib/Sema/SemaCast.cpp
clang/test/CodeGenCXX/dynamic-cast-exact.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index b338d601db7397..d65ecf52c52310 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -935,14 +935,6 @@ void CastOperation::CheckDynamicCast() {
   << isClangCL;
   }
 
-  // For a dynamic_cast to a final type, IR generation might emit a reference
-  // to the vtable.
-  if (DestRecord) {
-auto *DestDecl = DestRecord->getAsCXXRecordDecl();
-if (DestDecl->isEffectivelyFinal())
-  Self.MarkVTableUsed(OpRange.getBegin(), DestDecl);
-  }
-
   // Done. Everything else is run-time checks.
   Kind = CK_Dynamic;
 }

diff  --git a/clang/test/CodeGenCXX/dynamic-cast-exact.cpp 
b/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
index bd283e85101b4b..676aa975a72686 100644
--- a/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
+++ b/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
@@ -76,12 +76,3 @@ H *exact_multi(A *a) {
   // CHECK: phi ptr [ %[[RESULT]], %[[LABEL_NOTNULL]] ], [ null, 
%[[LABEL_FAILED]] ]
   return dynamic_cast(a);
 }
-
-namespace GH64088 {
-  // Ensure we mark the B vtable as used here, because we're going to emit a
-  // reference to it.
-  // CHECK: define {{.*}} @_ZN7GH640881BD0
-  struct A { virtual ~A(); };
-  struct B final : A { virtual ~B() = default; };
-  B *cast(A *p) { return dynamic_cast(p); }
-}



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


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

2023-07-28 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

In D156247#4541756 , @ilya-biryukov 
wrote:

> @aaron.ballman the internal -cc1 flag
>
> - internal `clang -cc1 -fno-coroutines`.

I'm sorry, but I find this wording misleading. `-cc1 -fno-coroutines` is not 
internal in the same sense as e.g. `-verify` is. Both are hidden from 
user-facing drivers, but unlike `-verify`, potential `-cc1 -fno-coroutines` is 
not just intended, but focused on users outside of monorepo. So I'd say it's 
going to be hidden but user-facing feature, rather than internal one. And the 
one that we should document and test if not for users, then for ourselves to 
make sure we maintain its semantics and don't break users. At this point I'd 
say if we go for it, we should go for proper driver option, rather than 
frontend one.

I also wonder how much complexity this language dialect would introduce while 
interacting with other language dialect flags. Is it really worth it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[PATCH] D156357: clang: Add elementwise bitreverse builtin

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



Comment at: clang/docs/LanguageExtensions.rst:634
  the most negative integer remains 
the most negative integer
- T __builtin_elementwise_fma(T x, T y, T z)  fused multiply add, (x * y) +  z. 
 floating point types
+ T __builtin_elementwise_fma(T x, T y, T z)  fused multiply add, (x * y) +  z. 
   floating point types
  T __builtin_elementwise_ceil(T x)   return the smallest integral 
value greater than or equal to xfloating point types

Unrelated but I noticed a couple of the elementwise builtins are missing from 
this list if you're fixing up the docs for them. Can't remember which off the 
top of my head



Comment at: clang/test/Sema/builtins-elementwise-math.c:272
 
+void test_builtin_elementwise_bitreverse(int i, float f, double d, float4 v, 
int3 iv, unsigned u, unsigned4 uv) {
+

Test the vector of float case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156357

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


[PATCH] D149172: [clang][Interp] Emit proper diagnostic when comparing unrelated pointers

2023-07-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 rG9092acc51010: [clang][Interp] Emit proper diagnostic when 
comparing unrelated pointers (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D149172?vs=516847&id=545097#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149172

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Pointer.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
@@ -122,6 +122,35 @@
   static_assert(!!FP, "");
 }
 
+namespace PointerComparison {
+
+  struct S { int a, b; } s;
+  constexpr void *null = 0;
+  constexpr void *pv = (void*)&s.a;
+  constexpr void *qv = (void*)&s.b;
+  constexpr bool v1 = null < (int*)0;
+  constexpr bool v2 = null < pv; // expected-error {{must be initialized by a 
constant expression}} \
+ // expected-note {{comparison between 
'nullptr' and '&s.a' has unspecified value}} \
+ // ref-error {{must be initialized by a 
constant expression}} \
+ // ref-note {{comparison between 'nullptr' 
and '&s.a' has unspecified value}} \
+
+  constexpr bool v3 = null == pv; // ok
+  constexpr bool v4 = qv == pv; // ok
+
+  /// FIXME: These two are rejected by the current interpreter, but
+  ///   accepted by GCC.
+  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
+// ref-note {{unequal pointers to void}}
+  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
+// ref-note {{unequal pointers to 
void}}
+  constexpr bool v6 = qv > null; // expected-error {{must be initialized by a 
constant expression}} \
+ // expected-note {{comparison between '&s.b' 
and 'nullptr' has unspecified value}} \
+ // ref-error {{must be initialized by a 
constant expression}} \
+ // ref-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
+
+  constexpr bool v7 = qv <= (void*)&s.b; // ok
+}
+
 namespace SizeOf {
   constexpr int soint = sizeof(int);
   constexpr int souint = sizeof(unsigned int);
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -145,6 +145,13 @@
   return APValue(Base, Offset, Path, IsOnePastEnd, IsNullPtr);
 }
 
+std::string Pointer::toDiagnosticString(const ASTContext &Ctx) const {
+  if (!Pointee)
+return "nullptr";
+
+  return toAPValue().getAsString(Ctx, getType());
+}
+
 bool Pointer::isInitialized() const {
   assert(Pointee && "Cannot check if null pointer was initialized");
   const Descriptor *Desc = getFieldDesc();
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -701,7 +701,9 @@
 
   if (!Pointer::hasSameBase(LHS, RHS)) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
+S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
+<< LHS.toDiagnosticString(S.getCtx())
+<< RHS.toDiagnosticString(S.getCtx());
 return false;
   } else {
 unsigned VL = LHS.getByteOffset();
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -143,6 +143,7 @@
   case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_UserDefinedConversion:
+  case CK_BitCast:
 return this->visit(SubExpr);
 
   case CK_IntegralToBoolean:


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -122,6 +122,35 @@
   static_assert(!!FP, "");
 }
 
+namespace PointerComparison {
+
+  struct S { int a, b; } s;
+  constexpr void *null = 0;
+  constexpr void *pv = (void*)&s.a;
+  constexpr void *qv = (void*)&s.b;
+  constexpr bool v1 = null < (int*)0;
+  constexpr bool v2 = null < pv; // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{comparison between 'nullptr' and '&s.a' has unspecified value}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // r

[clang] 9092acc - [clang][Interp] Emit proper diagnostic when comparing unrelated pointers

2023-07-28 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-28T13:23:48+02:00
New Revision: 9092acc510108737e0e9e3857756a65032debc6f

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

LOG: [clang][Interp] Emit proper diagnostic when comparing unrelated pointers

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

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Pointer.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 70ce1c3750bbf1..de024180765031 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -143,6 +143,7 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr 
*CE) {
   case CK_NonAtomicToAtomic:
   case CK_NoOp:
   case CK_UserDefinedConversion:
+  case CK_BitCast:
 return this->visit(SubExpr);
 
   case CK_IntegralToBoolean:

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index ee3b953bb69cc2..9eae79ba5d1e7a 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -701,7 +701,9 @@ inline bool CmpHelper(InterpState &S, CodePtr 
OpPC, CompareFn Fn) {
 
   if (!Pointer::hasSameBase(LHS, RHS)) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
+S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
+<< LHS.toDiagnosticString(S.getCtx())
+<< RHS.toDiagnosticString(S.getCtx());
 return false;
   } else {
 unsigned VL = LHS.getByteOffset();

diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index 00943dc846d3b2..e0ea25d8f560b9 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -145,6 +145,13 @@ APValue Pointer::toAPValue() const {
   return APValue(Base, Offset, Path, IsOnePastEnd, IsNullPtr);
 }
 
+std::string Pointer::toDiagnosticString(const ASTContext &Ctx) const {
+  if (!Pointee)
+return "nullptr";
+
+  return toAPValue().getAsString(Ctx, getType());
+}
+
 bool Pointer::isInitialized() const {
   assert(Pointee && "Cannot check if null pointer was initialized");
   const Descriptor *Desc = getFieldDesc();

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 10e0330daecbda..d2b5f4a5a1901f 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -122,6 +122,35 @@ namespace PointerToBool {
   static_assert(!!FP, "");
 }
 
+namespace PointerComparison {
+
+  struct S { int a, b; } s;
+  constexpr void *null = 0;
+  constexpr void *pv = (void*)&s.a;
+  constexpr void *qv = (void*)&s.b;
+  constexpr bool v1 = null < (int*)0;
+  constexpr bool v2 = null < pv; // expected-error {{must be initialized by a 
constant expression}} \
+ // expected-note {{comparison between 
'nullptr' and '&s.a' has unspecified value}} \
+ // ref-error {{must be initialized by a 
constant expression}} \
+ // ref-note {{comparison between 'nullptr' 
and '&s.a' has unspecified value}} \
+
+  constexpr bool v3 = null == pv; // ok
+  constexpr bool v4 = qv == pv; // ok
+
+  /// FIXME: These two are rejected by the current interpreter, but
+  ///   accepted by GCC.
+  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
+// ref-note {{unequal pointers to void}}
+  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
+// ref-note {{unequal pointers to 
void}}
+  constexpr bool v6 = qv > null; // expected-error {{must be initialized by a 
constant expression}} \
+ // expected-note {{comparison between '&s.b' 
and 'nullptr' has unspecified value}} \
+ // ref-error {{must be initialized by a 
constant expression}} \
+ // ref-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
+
+  constexpr bool v7 = qv <= (void*)&s.b; // ok
+}
+
 namespace SizeOf {
   constexpr int soint = sizeof(int);
   constexpr int souint = sizeof(unsigned int);



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


[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 545099.
cor3ntin edited the summary of this revision.
cor3ntin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp

Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
@@ -0,0 +1,95 @@
+// RUN: %clang_cc1 -std=c++20 -verify -fconstexpr-steps=1024 -Wvla %s
+
+namespace std {
+  using size_t = decltype(sizeof(0));
+}
+
+void *operator new(std::size_t, void *p) { return p; }
+
+namespace std {
+  template struct allocator {
+constexpr T *allocate(size_t N) {
+  return (T*)operator new(sizeof(T) * N); // #alloc
+}
+constexpr void deallocate(void *p) {
+  operator delete(p);
+}
+  };
+  template
+  constexpr void construct_at(void *p, Args &&...args) { // #construct
+new (p) T((Args&&)args...);
+  }
+}
+
+namespace GH63562 {
+
+template 
+struct S {
+constexpr S(unsigned long long N)
+: data(nullptr){
+data = alloc.allocate(N);  // #call
+for(std::size_t i = 0; i < N; i ++)
+std::construct_at(data + i, i); // #construct_call
+}
+constexpr T operator[](std::size_t i) const {
+  return data[i];
+}
+
+constexpr ~S() {
+alloc.deallocate(data);
+}
+std::allocator alloc;
+T* data;
+};
+
+constexpr std::size_t s = S(109951162)[42]; // expected-error {{constexpr variable 's' must be initialized by a constant expression}} \
+   // expected-note@#call {{in call to 'this->alloc.allocate(109951162)'}} \
+   // expected-note@#alloc {{cannot allocate array; evaluated array bound 109951162 is too large}} \
+   // expected-note {{in call to 'S(109951162)'}}
+// Check that we do not try to fold very large arrays
+std::size_t s2 = S(109951162)[42];
+std::size_t s3 = S(~0ULL)[42];
+
+// We can allocate and initialize a small array
+constexpr std::size_t ssmall = S(100)[42];
+
+// We can allocate this array but we hikt the number of steps
+constexpr std::size_t s4 = S(1024)[42]; // expected-error {{constexpr variable 's4' must be initialized by a constant expression}} \
+   // expected-note@#construct {{constexpr evaluation hit maximum step limit; possible infinite loop?}} \
+   // expected-note@#construct_call {{in call}} \
+   // expected-note {{in call}}
+
+
+
+constexpr std::size_t s5 = S(1025)[42]; // expected-error{{constexpr variable 's5' must be initialized by a constant expression}} \
+   // expected-note@#alloc {{cannot allocate array; evaluated array bound 1025 exceeds the limit (1024); use '-fconstexpr-steps' to increase this limit}} \
+   // expected-note@#call {{in call to 'this->alloc.allocate(1025)'}} \
+   // expected-note {{in call}}
+
+
+// Check we do not perform constant initialization in the presence
+// of very large arrays (this used to crash)
+
+template 
+constexpr int stack_array() {
+[[maybe_unused]] char BIG[N] = {1};  // expected-note  3{{cannot allocate array; evaluated array bound 1025 exceeds the limit (1024); use '-fconstexpr-steps' to increase this limit}}
+return BIG[N-1];
+}
+
+int a = stack_array<~0U>();
+int c = stack_array<1024>();
+int d = stack_array<1025>();
+constexpr int e = stack_array<1024>();
+constexpr int f = stack_array<1025>(); // expected-error {{constexpr variable 'f' must be initialized by a constant expression}} \
+   //  expected-note {{in call}}
+void ohno() {
+  int bar[stack_array<1024>()];
+  int foo[stack_array<1025>()]; // expected-warning {{variable length arrays are a C99 feature}} \
+// expected-note {{in call to 'stack_array()'}}
+
+  constexpr int foo[stack_array<1025>()]; // expected-warning {{variable length arrays are a C99 feature}} \
+  // expected-error {{constexpr variable cannot have non-literal type 'const int[stack_array<1025>()]'}} \
+  // expected-note {{in call to 'stack_array()'}}
+}
+
+}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -175,6 +175,11 @@
   return TotalSize.getActiveBits();
 }
 
+unsigned
+C

[PATCH] D156523: [clang][DeclPrinter] Fix AST print to suppress output of implicit (non-written) constructor initializers

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

DeclPrinter::PrintConstructorInitializers did output non-written constructor 
initiaizers. In particular, implicit constructor initializers of base classes 
were output.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156523

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,28 @@
 
   // CHECK-NEXT: };
 };
+
+
+
+//  Check that implict (non-written) constructor initializers are not 
output
+
+struct ImplicitCtorInit1 {
+  int a;
+};
+
+// CHECK: struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+
+  // CHECK-NEXT: ImplicitCtorInit2(int *) {
+  ImplicitCtorInit2(int *) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  // CHECK-NEXT: }
+  }
+
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -309,6 +309,8 @@
   for (const auto *BMInitializer : CDecl->inits()) {
 if (BMInitializer->isInClassMemberInitializer())
   continue;
+if (!BMInitializer->isWritten())
+  continue;
 
 if (!HasInitializerList) {
   Proto += " : ";


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,28 @@
 
   // CHECK-NEXT: };
 };
+
+
+
+//  Check that implict (non-written) constructor initializers are not output
+
+struct ImplicitCtorInit1 {
+  int a;
+};
+
+// CHECK: struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+
+  // CHECK-NEXT: ImplicitCtorInit2(int *) {
+  ImplicitCtorInit2(int *) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  // CHECK-NEXT: }
+  }
+
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -309,6 +309,8 @@
   for (const auto *BMInitializer : CDecl->inits()) {
 if (BMInitializer->isInClassMemberInitializer())
   continue;
+if (!BMInitializer->isWritten())
+  continue;
 
 if (!HasInitializerList) {
   Proto += " : ";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156523: [clang][DeclPrinter] Fix AST print to suppress output of implicit (non-written) constructor initializers

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

The current output of the test case can be shown here: 
https://godbolt.org/z/95ToPbqrP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156523

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


[PATCH] D156524: [flang][nfc] Simplify option forwarding

2023-07-28 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
awarzynski added a reviewer: kiranchandramohan.
Herald added a reviewer: sscalpone.
Herald added a subscriber: sunshaoce.
Herald added projects: Flang, All.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert, MaskRay.
Herald added a project: clang.

Use `AddAllArgs` to keep the implementation succinct. Also adds missing
'-flang-experimental-hlfir` in "frontend-forwarding.f90"


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156524

Files:
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/test/Driver/frontend-forwarding.f90


Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -17,6 +17,7 @@
 ! RUN: -fpass-plugin=Bye%pluginext \
 ! RUN: -fversion-loops-for-stride \
 ! RUN: -flang-experimental-polymorphism \
+! RUN: -flang-experimental-hlfir \
 ! RUN: -mllvm -print-before-all \
 ! RUN: -save-temps=obj \
 ! RUN: -P \
@@ -36,7 +37,8 @@
 ! CHECK: "-freciprocal-math"
 ! CHECK: "-fconvert=little-endian"
 ! CHECK: "-fpass-plugin=Bye
-! CHECK: "-flang-experimental-polymorphism"
 ! CHECK: "-fversion-loops-for-stride"
+! CHECK: "-flang-experimental-polymorphism"
+! CHECK: "-flang-experimental-hlfir"
 ! CHECK: "-mllvm" "-print-before-all"
 ! CHECK: "-save-temps=obj"
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -140,12 +140,11 @@
   !stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
 CmdArgs.push_back("-fstack-arrays");
 
-  if (Args.hasArg(options::OPT_flang_experimental_hlfir))
-CmdArgs.push_back("-flang-experimental-hlfir");
-  if (Args.hasArg(options::OPT_flang_experimental_polymorphism))
-CmdArgs.push_back("-flang-experimental-polymorphism");
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
+
+  Args.AddAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
+options::OPT_flang_experimental_polymorphism});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {


Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -17,6 +17,7 @@
 ! RUN: -fpass-plugin=Bye%pluginext \
 ! RUN: -fversion-loops-for-stride \
 ! RUN: -flang-experimental-polymorphism \
+! RUN: -flang-experimental-hlfir \
 ! RUN: -mllvm -print-before-all \
 ! RUN: -save-temps=obj \
 ! RUN: -P \
@@ -36,7 +37,8 @@
 ! CHECK: "-freciprocal-math"
 ! CHECK: "-fconvert=little-endian"
 ! CHECK: "-fpass-plugin=Bye
-! CHECK: "-flang-experimental-polymorphism"
 ! CHECK: "-fversion-loops-for-stride"
+! CHECK: "-flang-experimental-polymorphism"
+! CHECK: "-flang-experimental-hlfir"
 ! CHECK: "-mllvm" "-print-before-all"
 ! CHECK: "-save-temps=obj"
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -140,12 +140,11 @@
   !stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
 CmdArgs.push_back("-fstack-arrays");
 
-  if (Args.hasArg(options::OPT_flang_experimental_hlfir))
-CmdArgs.push_back("-flang-experimental-hlfir");
-  if (Args.hasArg(options::OPT_flang_experimental_polymorphism))
-CmdArgs.push_back("-flang-experimental-polymorphism");
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
+
+  Args.AddAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
+options::OPT_flang_experimental_polymorphism});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

2023-07-28 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D156247#4541826 , @cor3ntin wrote:

> How does a -cc1 flag alleviate the burden concerns for libc++? It would still 
> be something they would have to support, unless we plan to remove the flag 
> before c++26 and you are happy with the inclusion of `` and 
> `` producing subpar errors.
> However, in the C++26 cycle, `` (P2300 
> ) is going to have a dependency on 
> ``, and it does not seem reasonable for that to lead to errors.

We would be okay with `` and `` producing subpar errors. 
Because it's on users of those flags (i.e. us) to handle those errors, the 
users (i.e. **us**) will have to stop using it in C++26 or whenever libc++ 
starts to depend on coroutine in other headers.
If we are the only ones who need this configuration (and this is my impression 
right now), it makes sense that we are the ones who need to figure out who to 
deal with issues like this.

In D156247#4541880 , @Endill wrote:

> In D156247#4541756 , @ilya-biryukov 
> wrote:
>
>> @aaron.ballman the internal -cc1 flag
>>
>> - internal `clang -cc1 -fno-coroutines`.
>
> I'm sorry, but I find this wording misleading. `-cc1 -fno-coroutines` is not 
> internal in the same sense as e.g. `-verify` is. Both are hidden from 
> user-facing drivers, but unlike `-verify`, potential `-cc1 -fno-coroutines` 
> is not just intended, but focused on users outside of monorepo. So I'd say 
> it's going to be hidden but user-facing feature, rather than internal one. 
> And the one that we should document and test if not for users, then for 
> ourselves to make sure we maintain its semantics and don't break users. At 
> this point I'd say if we go for it, we should go for proper driver option, 
> rather than frontend one.

The `-cc1` flags can change between compiler releases and do not need to 
provide the same level of guarantees as user-facing features.
I do not see why we would want to put a high bar on documenting, testing `-cc1 
-fno-coroutines` and making sure that it works.
E.g. Clang has `-cc1 -fcoroutines`, but it does not enable 
 coroutines in `-std=c++17` like GCC does. 
We don't test it, we intend to ship Clang 17 with this behavior and I don't see 
why that's a problem.

> I also wonder how much complexity this language dialect would introduce while 
> interacting with other language dialect flags. Is it really worth it?

The complexity on the compiler side seems very low (this patch or something not 
much harder). If we do not require libc++ to support this configuration and 
allow it to break going forward (that is my proposal).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[PATCH] D156518: Fix handling of medial hyphens in Unicode Names.

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

LGTM




Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:100
+for (auto ChIt = Name.begin(); ChIt != Name.end();
+ ChIt += IsBeforeMedial ? 3 : 1) {
+  char Ch = *ChIt;

Parens here might be a kindness to folks who don't keep precedence rules in 
their head very well. ;-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156518

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


[PATCH] D156237: Complete the implementation of P2361 Unevaluated string literals

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

LGTM with a minor formatting nit that @Fznamznon had pointed out but was missed.




Comment at: clang/lib/Parse/ParseDecl.cpp:431-436
+if (Expr.isInvalid()) {
+  SawError = true;
+  break;
+} else {
+  Exprs.push_back(Expr.get());
+}




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156237

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


[PATCH] D112921: [clang] Enable sized deallocation by default in C++14 onwards

2023-07-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D112921#4535716 , @wangpc wrote:

> I am not familiar  with libcxx, can you please help me to fix these tests? I 
> hope we can catch up with the release of LLVM 17.

I think it's too late to put this into Clang 17. This is a significant amount 
of change to add to the release branch; I'd prefer if it stayed in Clang 18 to 
give it some extra time to bake.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112921

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


[PATCH] D156237: Complete the implementation of P2361 Unevaluated string literals

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



Comment at: clang/lib/Parse/ParseDecl.cpp:431-436
+if (Expr.isInvalid()) {
+  SawError = true;
+  break;
+} else {
+  Exprs.push_back(Expr.get());
+}

aaron.ballman wrote:
> 
Oups, sorry @Fznamznon, I'll fix that!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156237

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


[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-07-28 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

sorry for missing this review. Nathan's explanation around `targetDecl` vs 
`findRefs` is absolutely right (btw, thanks a lot Nathan for taking good care 
of clangd, I don't think I say that enough). hopefully one day we can switch 
clangd's usage of libindex to our internal find target/explicitrefs 
implementation, but until then we actually need to address such things in both 
places to make sure functionality is actually consistent.




Comment at: clang/lib/Index/IndexBody.cpp:150
+ParentDC,
+unsigned(SymbolRole::NameReference));
+  }

nridge wrote:
> `NameReference` was introduced in 
> https://github.com/llvm/llvm-project/commit/e7eb27a9a0edd859de49bcc9af7ca27dbb435886
>  to handle the somewhat unique situation with constructors and destructors 
> where the constructor/destructor references the class by name but 
> semantically denotes a separate entity.
> 
> Why is that applicable here?
> 
> Note that `handleReference()` will automatically add `SymbolRole::Reference` 
> [here](https://searchfox.org/llvm/rev/cea72fe34194d58ac1ba9485ee9c9a63cf98a4e6/clang/lib/Index/IndexingContext.cpp#404).
+1 we shouldn't be setting namereference here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150124

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


[PATCH] D156524: [flang][nfc] Simplify option forwarding

2023-07-28 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan accepted this revision.
kiranchandramohan added a comment.
This revision is now accepted and ready to land.

LG.




Comment at: clang/lib/Driver/ToolChains/Flang.cpp:146-147
+
+  Args.AddAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
+options::OPT_flang_experimental_polymorphism});
 }

Is the order changing in the tests below (poly before hlfir) expected?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156524

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


[PATCH] D155290: [PGO] Use Unique Profile Files when New Processes are Forked

2023-07-28 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 added a comment.

Ping for review. Thanks so much!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155290

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


[PATCH] D156405: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The failures are unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156405

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


[PATCH] D156406: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The failures are unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156406

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


[PATCH] D156415: [NFC][analyzer] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

The failures are unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156415

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


[clang] a623f4c - [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread via cfe-commits

Author: Podchishchaeva, Mariya
Date: 2023-07-28T05:29:56-07:00
New Revision: a623f4c7849838361c9a69324cf669100bc0e414

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

LOG: [NFC][clang] Fix static analyzer concerns

DelegatingDeserializationListener frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Frontend/FrontendAction.cpp

Removed: 




diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index c6f958a6077bf6..f14557c316ec7a 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@ class DelegatingDeserializationListener : public 
ASTDeserializationListener {
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) 
=
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);



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


[PATCH] D156405: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva 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 rGa623f4c78498: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156405

Files:
  clang/lib/Frontend/FrontendAction.cpp


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) 
=
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);


Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -61,6 +61,11 @@
   delete Previous;
   }
 
+  DelegatingDeserializationListener(const DelegatingDeserializationListener &) =
+  delete;
+  DelegatingDeserializationListener &
+  operator=(const DelegatingDeserializationListener &) = delete;
+
   void ReaderInitialized(ASTReader *Reader) override {
 if (Previous)
   Previous->ReaderInitialized(Reader);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9fe23fb - [NFC][analyzer] Fix static analyzer concerns

2023-07-28 Thread via cfe-commits

Author: Podchishchaeva, Mariya
Date: 2023-07-28T05:30:34-07:00
New Revision: 9fe23fbb2318f86eab0a8404c5024ee04f1eb83d

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

LOG: [NFC][analyzer] Fix static analyzer concerns

CFGStmtMap frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.

Reviewed By: cor3ntin

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

Added: 


Modified: 
clang/include/clang/Analysis/CFGStmtMap.h

Removed: 




diff  --git a/clang/include/clang/Analysis/CFGStmtMap.h 
b/clang/include/clang/Analysis/CFGStmtMap.h
index 8cf02372ff0fb7..93cd9cfc5bdff2 100644
--- a/clang/include/clang/Analysis/CFGStmtMap.h
+++ b/clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@ class CFGStmtMap {
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap &operator=(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();



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


[PATCH] D156415: [NFC][analyzer] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva 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 rG9fe23fbb2318: [NFC][analyzer] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156415

Files:
  clang/include/clang/Analysis/CFGStmtMap.h


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap &operator=(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();


Index: clang/include/clang/Analysis/CFGStmtMap.h
===
--- clang/include/clang/Analysis/CFGStmtMap.h
+++ clang/include/clang/Analysis/CFGStmtMap.h
@@ -26,6 +26,8 @@
   void *M;
 
   CFGStmtMap(ParentMap *pm, void *m) : PM(pm), M(m) {}
+  CFGStmtMap(const CFGStmtMap &) = delete;
+  CFGStmtMap &operator=(const CFGStmtMap &) = delete;
 
 public:
   ~CFGStmtMap();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a457067 - [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread via cfe-commits

Author: Podchishchaeva, Mariya
Date: 2023-07-28T05:32:41-07:00
New Revision: a457067d2c6b3416233d67e280c9b73dc170da46

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

LOG: [NFC][clang] Fix static analyzer concerns

IdentifierResolver frees resources in the destructor but doesn't
have user-written copy c'tor or assignment operator, so copying it using
default ones can cause double free.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Sema/IdentifierResolver.h

Removed: 




diff  --git a/clang/include/clang/Sema/IdentifierResolver.h 
b/clang/include/clang/Sema/IdentifierResolver.h
index 1fbd6c48e51806..557f513146406f 100644
--- a/clang/include/clang/Sema/IdentifierResolver.h
+++ b/clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@ class IdentifierResolver {
   explicit IdentifierResolver(Preprocessor &PP);
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver &operator=(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 



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


[PATCH] D156406: [NFC][clang] Fix static analyzer concerns

2023-07-28 Thread Mariya Podchishchaeva 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 rGa457067d2c6b: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156406

Files:
  clang/include/clang/Sema/IdentifierResolver.h


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor &PP);
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver &operator=(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 


Index: clang/include/clang/Sema/IdentifierResolver.h
===
--- clang/include/clang/Sema/IdentifierResolver.h
+++ clang/include/clang/Sema/IdentifierResolver.h
@@ -134,6 +134,9 @@
   explicit IdentifierResolver(Preprocessor &PP);
   ~IdentifierResolver();
 
+  IdentifierResolver(const IdentifierResolver &) = delete;
+  IdentifierResolver &operator=(const IdentifierResolver &) = delete;
+
   /// Returns a range of decls with the name 'Name'.
   llvm::iterator_range decls(DeclarationName Name);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151834: Include math-errno with fast-math

2023-07-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2313-2315
+  // Math intrinsics are generated only when math-errno is disabled. Any pragma
+  // or attribute that affect math-errno, should prevent or allow math
+  // intrincs to be generated. Intrinsics are generated:




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

https://reviews.llvm.org/D151834

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


[clang] 45ab2b4 - [Clang] Improve the handling of large arrays evaluation.

2023-07-28 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-28T14:38:22+02:00
New Revision: 45ab2b48bd55e50a86f6026ed31d2b60a118bdce

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

LOG: [Clang] Improve the handling of large arrays evaluation.

This is a temporary fix (for clang 17) that caps the size of
any array we try to constant evaluate:

There are 2 limits:
  * We cap to UINT_MAX the size of ant constant evaluated array,
because the constant evaluator does not support size_t.
  * We cap to `-fconstexpr-steps` elements the size of each individual
array and dynamic array allocations.
This works out because the number of constexpr steps already limits
how many array elements can be initialized, which makes this new
limit conservatively generous.
This ensure that the compiler does not crash when attempting to
constant-fold valid programs.

If the limit is reached by a given array, constant evaluation will fail,
and the program will be ill-formed, until a bigger limit is given.
Or, constant folding will fail and the array will be evaluated at runtime.

Fixes #63562

Reviewed By: efriedma

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

Added: 
clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 98f50b428c2dc3..8ba3d22253a62b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -112,6 +112,11 @@ Bug Fixes to Attribute Support
 Bug Fixes to C++ Support
 
 
+- Clang limits the size of arrays it will try to evaluate at compile time
+  to avoid memory exhaustion.
+  This limit can be modified by `-fconstexpr-steps`.
+  (`#63562 `_)
+
 Bug Fixes to AST Handling
 ^
 

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 14af07d35f5e1d..a774fd91aa277f 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3348,7 +3348,9 @@ Controlling implementation limits
 .. option:: -fconstexpr-steps=N
 
   Sets the limit for the number of full-expressions evaluated in a single
-  constant expression evaluation.  The default is 1048576.
+  constant expression evaluation. This also controls the maximum size
+  of array and dynamic array allocation that can be constant evaluated.
+  The default is 1048576.
 
 .. option:: -ftemplate-depth=N
 

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 8d20d088bb63c4..7526ec8906a32c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3144,6 +3144,8 @@ class ConstantArrayType final
QualType ElementType,
const llvm::APInt &NumElements);
 
+  unsigned getNumAddressingBits(const ASTContext &Context) const;
+
   /// Determine the maximum number of active bits that an array's size
   /// can require, which limits the maximum size of the array.
   static unsigned getMaxSizeBits(const ASTContext &Context);

diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 566cdc3406058f..f73a289f80ca95 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -351,6 +351,9 @@ def note_constexpr_new_negative : Note<
   "cannot allocate array; evaluated array bound %0 is negative">;
 def note_constexpr_new_too_large : Note<
   "cannot allocate array; evaluated array bound %0 is too large">;
+def note_constexpr_new_exceeds_limits : Note<
+  "cannot allocate array; evaluated array bound %0 exceeds the limit (%1); "
+  "use '-fconstexpr-steps' to increase this limit">;
 def note_constexpr_new_too_small : Note<
   "cannot allocate array; evaluated array bound %0 is too small to hold "
   "%1 explicitly initialized elements">;

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d9208b53e44994..c06ca3c405370e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1019,6 +1019,34 @@ namespace {
   return false;
 }
 
+bool CheckArraySize(SourceLocation Loc, unsigned BitWidth,
+uint64_t ElemCount, bool Diag) {
+  // FIXME: GH63562
+  // APValue stores array extents as unsigned,
+  // so anything that is greater that unsigned would overflow when
+  // constructing the

[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-28 Thread Corentin Jabot 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 rG45ab2b48bd55: [Clang] Improve the handling of large arrays 
evaluation. (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp

Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
@@ -0,0 +1,95 @@
+// RUN: %clang_cc1 -std=c++20 -verify -fconstexpr-steps=1024 -Wvla %s
+
+namespace std {
+  using size_t = decltype(sizeof(0));
+}
+
+void *operator new(std::size_t, void *p) { return p; }
+
+namespace std {
+  template struct allocator {
+constexpr T *allocate(size_t N) {
+  return (T*)operator new(sizeof(T) * N); // #alloc
+}
+constexpr void deallocate(void *p) {
+  operator delete(p);
+}
+  };
+  template
+  constexpr void construct_at(void *p, Args &&...args) { // #construct
+new (p) T((Args&&)args...);
+  }
+}
+
+namespace GH63562 {
+
+template 
+struct S {
+constexpr S(unsigned long long N)
+: data(nullptr){
+data = alloc.allocate(N);  // #call
+for(std::size_t i = 0; i < N; i ++)
+std::construct_at(data + i, i); // #construct_call
+}
+constexpr T operator[](std::size_t i) const {
+  return data[i];
+}
+
+constexpr ~S() {
+alloc.deallocate(data);
+}
+std::allocator alloc;
+T* data;
+};
+
+constexpr std::size_t s = S(109951162)[42]; // expected-error {{constexpr variable 's' must be initialized by a constant expression}} \
+   // expected-note@#call {{in call to 'this->alloc.allocate(109951162)'}} \
+   // expected-note@#alloc {{cannot allocate array; evaluated array bound 109951162 is too large}} \
+   // expected-note {{in call to 'S(109951162)'}}
+// Check that we do not try to fold very large arrays
+std::size_t s2 = S(109951162)[42];
+std::size_t s3 = S(~0ULL)[42];
+
+// We can allocate and initialize a small array
+constexpr std::size_t ssmall = S(100)[42];
+
+// We can allocate this array but we hikt the number of steps
+constexpr std::size_t s4 = S(1024)[42]; // expected-error {{constexpr variable 's4' must be initialized by a constant expression}} \
+   // expected-note@#construct {{constexpr evaluation hit maximum step limit; possible infinite loop?}} \
+   // expected-note@#construct_call {{in call}} \
+   // expected-note {{in call}}
+
+
+
+constexpr std::size_t s5 = S(1025)[42]; // expected-error{{constexpr variable 's5' must be initialized by a constant expression}} \
+   // expected-note@#alloc {{cannot allocate array; evaluated array bound 1025 exceeds the limit (1024); use '-fconstexpr-steps' to increase this limit}} \
+   // expected-note@#call {{in call to 'this->alloc.allocate(1025)'}} \
+   // expected-note {{in call}}
+
+
+// Check we do not perform constant initialization in the presence
+// of very large arrays (this used to crash)
+
+template 
+constexpr int stack_array() {
+[[maybe_unused]] char BIG[N] = {1};  // expected-note  3{{cannot allocate array; evaluated array bound 1025 exceeds the limit (1024); use '-fconstexpr-steps' to increase this limit}}
+return BIG[N-1];
+}
+
+int a = stack_array<~0U>();
+int c = stack_array<1024>();
+int d = stack_array<1025>();
+constexpr int e = stack_array<1024>();
+constexpr int f = stack_array<1025>(); // expected-error {{constexpr variable 'f' must be initialized by a constant expression}} \
+   //  expected-note {{in call}}
+void ohno() {
+  int bar[stack_array<1024>()];
+  int foo[stack_array<1025>()]; // expected-warning {{variable length arrays are a C99 feature}} \
+// expected-note {{in call to 'stack_array()'}}
+
+  constexpr int foo[stack_array<1025>()]; // expected-warning {{variable length arrays are a C99 feature}} \
+  // expected-error {{constexpr variable cannot have non-literal type 'const int[stack_array<1025>()]'}} \
+  // expected-note {{in call to 'stack_array()'}}
+}
+
+}
Index: clang/lib/AST/Type.cpp
===
--- clang/li

[clang] 163a6e2 - [clang][CodeGen][NFC] remove trailing whitespace (fix check-format)

2023-07-28 Thread via cfe-commits

Author: dingfei
Date: 2023-07-28T20:39:30+08:00
New Revision: 163a6e237596071dbe97fe46044fb3dca0464e6a

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

LOG: [clang][CodeGen][NFC] remove trailing whitespace (fix check-format)

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 33defb9c87e90f..f6a5235ce58579 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2764,7 +2764,7 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const 
UnaryOperator *E, LValue LV,
   amt = llvm::ConstantFP::get(VMContext,
   llvm::APFloat(static_cast(amount)));
 else {
-  // Remaining types are Half, Bfloat16, LongDouble, __ibm128 or 
__float128. 
+  // Remaining types are Half, Bfloat16, LongDouble, __ibm128 or 
__float128.
   // Convert from float.
   llvm::APFloat F(static_cast(amount));
   bool ignored;



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


[PATCH] D156201: [ASTImporter] Fix corrupted RecordLayout introduced by circular referenced fields

2023-07-28 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:7418
+
+  return UO;
 }

Why is it better to use `CreateEmpty` instead of the old code? Does `Create` do 
something that does not work at this situation (probably getting the layout)? 
If yes the same should be done later at some point, can you explain how this 
works?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156201

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


[PATCH] D156247: [Clang] Add a warning on uses of coroutine keywords

2023-07-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Given the views expressed on this thread, I think this requires a wider 
community discussion to determine whether we want to support this idea or not, 
regardless of -cc1 or driver-level option. We should not be adding a novel 
language dialect as we're getting ready to cut a release unless the need and 
benefits are *very* compelling, and I don't think that's the case here. We need 
the time to think about the long-term effects of such a mode, so I don't think 
Clang 17 is an appropriate ship vehicle for this change, especially because 
Google can carry this patch in your downstream easily enough.

My recommendation is to start an RFC on Discourse. If the community quickly and 
decisively agrees this should land in Clang 17 in the next few days, it might 
still be reasonable to make the rc2 cutoff, but I'd leave that decision to the 
release managers and it would be contingent on strong libc++ maintainer 
agreement to whatever direction we go (because they'll be the most impacted by 
this decision).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156247

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


[PATCH] D156518: Fix handling of medial hyphens in Unicode Names.

2023-07-28 Thread Corentin Jabot 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 rG68410fbed769: Fix handling of medial hyphens in Unicode 
Names. (authored by cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D156518?vs=545078&id=545124#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156518

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D156518: Fix handling of medial hyphens in Unicode Names.

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



Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:100
+for (auto ChIt = Name.begin(); ChIt != Name.end();
+ ChIt += IsBeforeMedial ? 3 : 1) {
+  char Ch = *ChIt;

aaron.ballman wrote:
> Parens here might be a kindness to folks who don't keep precedence rules in 
> their head very well. ;-)
you are not wrong, I added parens!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156518

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


[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-07-28 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added inline comments.



Comment at: clang/lib/Index/IndexBody.cpp:150
+ParentDC,
+unsigned(SymbolRole::NameReference));
+  }

kadircet wrote:
> nridge wrote:
> > `NameReference` was introduced in 
> > https://github.com/llvm/llvm-project/commit/e7eb27a9a0edd859de49bcc9af7ca27dbb435886
> >  to handle the somewhat unique situation with constructors and destructors 
> > where the constructor/destructor references the class by name but 
> > semantically denotes a separate entity.
> > 
> > Why is that applicable here?
> > 
> > Note that `handleReference()` will automatically add 
> > `SymbolRole::Reference` 
> > [here](https://searchfox.org/llvm/rev/cea72fe34194d58ac1ba9485ee9c9a63cf98a4e6/clang/lib/Index/IndexingContext.cpp#404).
> +1 we shouldn't be setting namereference here.
So set nothing at all here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150124

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


[PATCH] D156533: [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

DeclPrinter used FunctionDecl::isThisDeclarationADefinition to decide if the 
decl requires a semicolon at the end. However, there are several methods 
without body (that require a semicolon) that are definitions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156533

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,18 @@
 
   // CHECK-NEXT: };
 };
+
+
+// CHECK: struct DefMethodsWithoutBody {
+struct DefMethodsWithoutBody {
+  // CHECK-NEXT: DefMethodsWithoutBody() = delete;
+  DefMethodsWithoutBody() = delete;
+
+  // CHECK-NEXT: DefMethodsWithoutBody() = default;
+  ~DefMethodsWithoutBody() = default;
+
+  // CHECK-NEXT: void m1() __attribute__((alias("X")));
+  void m1() __attribute__((alias("X")));
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -463,12 +463,12 @@
 else if (isa(*D) && cast(*D)->hasBody())
   Terminator = nullptr;
 else if (auto FD = dyn_cast(*D)) {
-  if (FD->isThisDeclarationADefinition())
+  if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
 Terminator = nullptr;
   else
 Terminator = ";";
 } else if (auto TD = dyn_cast(*D)) {
-  if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
+  if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
 Terminator = nullptr;
   else
 Terminator = ";";


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,18 @@
 
   // CHECK-NEXT: };
 };
+
+
+// CHECK: struct DefMethodsWithoutBody {
+struct DefMethodsWithoutBody {
+  // CHECK-NEXT: DefMethodsWithoutBody() = delete;
+  DefMethodsWithoutBody() = delete;
+
+  // CHECK-NEXT: DefMethodsWithoutBody() = default;
+  ~DefMethodsWithoutBody() = default;
+
+  // CHECK-NEXT: void m1() __attribute__((alias("X")));
+  void m1() __attribute__((alias("X")));
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -463,12 +463,12 @@
 else if (isa(*D) && cast(*D)->hasBody())
   Terminator = nullptr;
 else if (auto FD = dyn_cast(*D)) {
-  if (FD->isThisDeclarationADefinition())
+  if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
 Terminator = nullptr;
   else
 Terminator = ";";
 } else if (auto TD = dyn_cast(*D)) {
-  if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
+  if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
 Terminator = nullptr;
   else
 Terminator = ";";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154189: [clang][Interp] Implement zero-init of record types

2023-07-28 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 545131.
tbaeder marked 2 inline comments as done.

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

https://reviews.llvm.org/D154189

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Descriptor.h
  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
@@ -931,3 +931,63 @@
   O o1(0);
 }
 #endif
+
+
+namespace ZeroInit {
+  struct F {
+int a;
+  };
+
+  namespace Simple {
+struct A {
+  char a;
+  bool b;
+  int c[4];
+  float d;
+};
+constexpr int foo(A x) {
+  return x.a + static_cast(x.b) + x.c[0] + x.c[3] + static_cast(x.d);
+}
+static_assert(foo(A()) == 0, "");
+  }
+
+  namespace Inheritance {
+struct F2 : F {
+  float f;
+};
+
+constexpr int foo(F2 f) {
+  return (int)f.f + f.a;
+}
+static_assert(foo(F2()) == 0, "");
+  }
+
+  namespace BitFields {
+struct F {
+  unsigned a : 6;
+};
+constexpr int foo(F f) {
+  return f.a;
+}
+static_assert(foo(F()) == 0, "");
+  }
+
+
+#if __cplusplus >= 202002L
+  namespace Failure {
+struct S {
+  int a;
+  F f{12};
+};
+constexpr int foo(S x) {
+  return x.a; // expected-note {{read of uninitialized object}} \
+  // ref-note {{read of uninitialized object}}
+}
+static_assert(foo(S()) == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+  };
+#endif
+}
+
Index: clang/lib/AST/Interp/Descriptor.h
===
--- clang/lib/AST/Interp/Descriptor.h
+++ clang/lib/AST/Interp/Descriptor.h
@@ -140,6 +140,7 @@
  bool IsTemporary, bool IsMutable);
 
   QualType getType() const;
+  QualType getElemQualType() const;
   SourceLocation getLocation() const;
 
   const Decl *asDecl() const { return Source.dyn_cast(); }
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -289,6 +289,12 @@
   llvm_unreachable("Invalid descriptor type");
 }
 
+QualType Descriptor::getElemQualType() const {
+  assert(isArray());
+  const auto *AT = cast(getType());
+  return AT->getElementType();
+}
+
 SourceLocation Descriptor::getLocation() const {
   if (auto *D = Source.dyn_cast())
 return D->getLocation();
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -222,6 +222,7 @@
 
   /// Emits a zero initializer.
   bool visitZeroInitializer(QualType QT, const Expr *E);
+  bool visitZeroRecordInitializer(const Record *R, const Expr *E);
 
   enum class DerefKind {
 /// Value is read and pushed to stack.
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1394,7 +1394,15 @@
   assert(!classify(T));
 
   if (T->isRecordType()) {
-const Function *Func = getFunction(E->getConstructor());
+const CXXConstructorDecl *Ctor = E->getConstructor();
+
+// Trivial zero initialization.
+if (E->requiresZeroInitialization() && Ctor->isTrivial()) {
+  const Record *R = getRecord(E->getType());
+  return this->visitZeroRecordInitializer(R, E);
+}
+
+const Function *Func = getFunction(Ctor);
 
 if (!Func)
   return false;
@@ -1467,7 +1475,7 @@
 return true;
   }
 
-  return false;
+  return DiscardResult ? this->emitPopPtr(E) : true;
 }
 
 template 
@@ -1698,6 +1706,62 @@
   llvm_unreachable("unknown primitive type");
 }
 
+template 
+bool ByteCodeExprGen::visitZeroRecordInitializer(const Record *R,
+  const Expr *E) {
+  assert(E);
+  assert(R);
+  // Fields
+  for (const Record::Field &Field : R->fields()) {
+const Descriptor *D = Field.Desc;
+if (D->isPrimitive()) {
+  QualType QT = D->getType();
+  PrimType T = classifyPrim(D->getType());
+  if (!this->visitZeroInitializer(QT, E))
+return false;
+  if (!this->emitInitField(T, Field.Offset, E))
+return false;
+  continue;
+}
+
+// TODO: Add GetPtrFieldPop and get rid of this dup.
+if (!this->emitDupPtr(E))
+  return false;
+if (!this->emitGetPtrField(Field.Offset, E))
+  ret

[PATCH] D154189: [clang][Interp] Implement zero-init of record types

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1240
+  // Fields
+  for (const Record::Field &Field : R->fields()) {
+const Descriptor *D = Field.Desc;

aaron.ballman wrote:
> It looks like you're not initializing base classes or padding bits: 
> http://eel.is/c++draft/dcl.init#general-6.2 -- we could use test coverage for 
> both of those cases (don't forget to also test bit-fields). You should also 
> have a test for zero init of unions.
Unions and bitfields are generally not supported yet, and I'm not sure what you 
mean by padding bits - they don't exist at this stage. In storage however, they 
are always zero since we memset that to 0.



Comment at: clang/lib/AST/Interp/Descriptor.cpp:281-289
+QualType Descriptor::getElemQualType() const {
+  assert(isArray());
+  QualType T = getType();
+
+  const auto *CAT = cast(T);
+  return CAT->getElementType();
+

aaron.ballman wrote:
> This looks pretty dangerous -- is it safe to assume the type is a constant 
> array, or should this be a `dyn_cast` and the spurious `return` is for the 
> `else` branch?
I only need an `ArrayType` anyway, so should be fine.



Comment at: clang/test/AST/Interp/records.cpp:931
+constexpr int foo(S x) {
+  return x.a; // expected-note {{read of object outside its lifetime}} \
+  // ref-note {{read of uninitialized object}}

aaron.ballman wrote:
> Why is `x.a` outside of its lifetime?
That was just a wrong diagnostic that has since been fixed.


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

https://reviews.llvm.org/D154189

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


[PATCH] D154189: [clang][Interp] Implement zero-init of record types

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



Comment at: clang/test/AST/Interp/records.cpp:939
+  };
+#endif
+

aaron.ballman wrote:
> I think we should have more test coverage. I mentioned a few above, but other 
> things to test would be inner classes (and anonymous members), like:
> ```
> struct S {
>   struct {
> int x, y;
>   } v;
>   union {
> float a;
> int b;
>   };
> };
> ```
> and member pointers (because those aren't simple pointers):
> ```
> struct A {
>   void func();
> };
> struct S {
>   void (A::*ptr)();
> };
> ```
member pointers are also not handled yet.


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

https://reviews.llvm.org/D154189

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


[PATCH] D156533: [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

https://github.com/llvm/llvm-project/issues/62996


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156533

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


[PATCH] D154093: [clang-format] Break long strings in Verilog

2023-07-28 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

@owenpan What do you think about this revision especially the replacement part?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

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


[PATCH] D155546: [clang][Interp] Implement __builtin_fmin

2023-07-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D155546#4541144 , @tbaeder wrote:

> Thanks for the info @jcranmer-intel.
>
> I see that the current intepreter doesn't check this for `__builtin_fmin`(GCC 
> does) either, but it does error out for e.g. `__builtin_nan("") + 1` (GCC 
> doesn't).
>
> @aaron.ballman I'd like to handle that in a separate patch where I also 
> handle regular floating point operations.

I think that's reasonable.

In D155546#4541249 , @tbaeder wrote:

> As for signaling vs. quiet NaNs, it seems like both GCC and Clang only check 
> for NaNs, and don't care if it's signaling or not.

Yeah, I'm not too surprised that we missed these kinds of "edge" cases.


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

https://reviews.llvm.org/D155546

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


[PATCH] D154568: [Clang][OpenMP] GPU simd directive code generation

2023-07-28 Thread Dominik Adamski via Phabricator via cfe-commits
domada added a comment.

Hi,
thank you for your contribution.
Could you fix assertion failure which was reported by Clang CI ( 
https://buildkite.com/llvm-project/premerge-checks/builds/166519#01898852-f9c9-4dd2-9933-b32be792c976
 ) ?
`Assertion failed: OpenMPRuntime != nullptr, file 
C:\ws\w9\llvm-project\premerge-checks\clang\lib\CodeGen\CodeGenModule.h, line 
635 `


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

https://reviews.llvm.org/D154568

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


[PATCH] D155546: [clang][Interp] Implement __builtin_fmin

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

LGTM, we can handle NaN behavior in a follow-up.


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

https://reviews.llvm.org/D155546

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


[PATCH] D156537: [CodeGen] Keep track of eagerly emitted globals

2023-07-28 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.
Hahnfeld added reviewers: v.g.vassilev, rjmccall, aaron.ballman.
Herald added a project: All.
Hahnfeld requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

An inline virtual function must be emitted, but we need to remember
it and emit the same definition again in the future in case later
LLVM optimizations stripped it from the Module. The added test case
shows the problem; before this patch, it would fail with:

  Symbols not found: [ _ZN1AD0Ev, _ZN1AD1Ev ]


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156537

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/inline-virtual.cpp


Index: clang/test/Interpreter/inline-virtual.cpp
===
--- /dev/null
+++ clang/test/Interpreter/inline-virtual.cpp
@@ -0,0 +1,21 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char *, ...);
+
+struct A { int a; A(int a) : a(a) {} virtual ~A(); };
+
+// Then define the virtual destructor as inline out-of-line, in a separate
+// PartialTranslationUnit.
+inline A::~A() { printf("~A(%d)\n", a); }
+
+// Create one instance with new and delete it.
+A *a1 = new A(1);
+delete a1;
+// CHECK: ~A(1)
+
+// Also create one global that will be auto-destructed.
+A a2(2);
+// CHECK: ~A(2)
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3638,6 +3638,7 @@
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
+addEmittedDeferredDecl(GD);
 return;
   }
 


Index: clang/test/Interpreter/inline-virtual.cpp
===
--- /dev/null
+++ clang/test/Interpreter/inline-virtual.cpp
@@ -0,0 +1,21 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char *, ...);
+
+struct A { int a; A(int a) : a(a) {} virtual ~A(); };
+
+// Then define the virtual destructor as inline out-of-line, in a separate
+// PartialTranslationUnit.
+inline A::~A() { printf("~A(%d)\n", a); }
+
+// Create one instance with new and delete it.
+A *a1 = new A(1);
+delete a1;
+// CHECK: ~A(1)
+
+// Also create one global that will be auto-destructed.
+A a2(2);
+// CHECK: ~A(2)
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3638,6 +3638,7 @@
   if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
 // Emit the definition if it can't be deferred.
 EmitGlobalDefinition(GD);
+addEmittedDeferredDecl(GD);
 return;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154189: [clang][Interp] Implement zero-init of record types

2023-07-28 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 545146.

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

https://reviews.llvm.org/D154189

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Descriptor.h
  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
@@ -931,3 +931,63 @@
   O o1(0);
 }
 #endif
+
+
+namespace ZeroInit {
+  struct F {
+int a;
+  };
+
+  namespace Simple {
+struct A {
+  char a;
+  bool b;
+  int c[4];
+  float d;
+};
+constexpr int foo(A x) {
+  return x.a + static_cast(x.b) + x.c[0] + x.c[3] + static_cast(x.d);
+}
+static_assert(foo(A()) == 0, "");
+  }
+
+  namespace Inheritance {
+struct F2 : F {
+  float f;
+};
+
+constexpr int foo(F2 f) {
+  return (int)f.f + f.a;
+}
+static_assert(foo(F2()) == 0, "");
+  }
+
+  namespace BitFields {
+struct F {
+  unsigned a : 6;
+};
+constexpr int foo(F f) {
+  return f.a;
+}
+static_assert(foo(F()) == 0, "");
+  }
+
+
+#if __cplusplus >= 202002L
+  namespace Failure {
+struct S {
+  int a;
+  F f{12};
+};
+constexpr int foo(S x) {
+  return x.a; // expected-note {{read of uninitialized object}} \
+  // ref-note {{read of uninitialized object}}
+}
+static_assert(foo(S()) == 0, ""); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+  };
+#endif
+}
+
Index: clang/lib/AST/Interp/Descriptor.h
===
--- clang/lib/AST/Interp/Descriptor.h
+++ clang/lib/AST/Interp/Descriptor.h
@@ -140,6 +140,7 @@
  bool IsTemporary, bool IsMutable);
 
   QualType getType() const;
+  QualType getElemQualType() const;
   SourceLocation getLocation() const;
 
   const Decl *asDecl() const { return Source.dyn_cast(); }
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -289,6 +289,12 @@
   llvm_unreachable("Invalid descriptor type");
 }
 
+QualType Descriptor::getElemQualType() const {
+  assert(isArray());
+  const auto *AT = cast(getType());
+  return AT->getElementType();
+}
+
 SourceLocation Descriptor::getLocation() const {
   if (auto *D = Source.dyn_cast())
 return D->getLocation();
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -222,6 +222,7 @@
 
   /// Emits a zero initializer.
   bool visitZeroInitializer(QualType QT, const Expr *E);
+  bool visitZeroRecordInitializer(const Record *R, const Expr *E);
 
   enum class DerefKind {
 /// Value is read and pushed to stack.
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1394,7 +1394,15 @@
   assert(!classify(T));
 
   if (T->isRecordType()) {
-const Function *Func = getFunction(E->getConstructor());
+const CXXConstructorDecl *Ctor = E->getConstructor();
+
+// Trivial zero initialization.
+if (E->requiresZeroInitialization() && Ctor->isTrivial()) {
+  const Record *R = getRecord(E->getType());
+  return this->visitZeroRecordInitializer(R, E);
+}
+
+const Function *Func = getFunction(Ctor);
 
 if (!Func)
   return false;
@@ -1698,6 +1706,62 @@
   llvm_unreachable("unknown primitive type");
 }
 
+template 
+bool ByteCodeExprGen::visitZeroRecordInitializer(const Record *R,
+  const Expr *E) {
+  assert(E);
+  assert(R);
+  // Fields
+  for (const Record::Field &Field : R->fields()) {
+const Descriptor *D = Field.Desc;
+if (D->isPrimitive()) {
+  QualType QT = D->getType();
+  PrimType T = classifyPrim(D->getType());
+  if (!this->visitZeroInitializer(QT, E))
+return false;
+  if (!this->emitInitField(T, Field.Offset, E))
+return false;
+  continue;
+}
+
+// TODO: Add GetPtrFieldPop and get rid of this dup.
+if (!this->emitDupPtr(E))
+  return false;
+if (!this->emitGetPtrField(Field.Offset, E))
+  return false;
+
+if (D->isPrimitiveArray()) {
+  QualType ET = D->getElemQualType();
+  PrimType T = classifyPrim(ET);
+  for (uint32_t I = 0, N = D->getNumElems()

[PATCH] D156539: [Clang][CodeGen] `__builtin_alloca`s should care about address spaces too

2023-07-28 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx created this revision.
AlexVlx added reviewers: rjmccall, yaxunl.
AlexVlx added a project: clang.
Herald added a subscriber: arichardson.
Herald added a project: All.
AlexVlx requested review of this revision.
Herald added a subscriber: cfe-commits.

`alloca` instructions always return pointers to the stack / alloca address 
space. This composes poorly with most HLLs which are address space agnostic and 
thus have all pointers point to generic/flat. Static `alloca`s were already 
handled on the AST level, in the implementation of the `CreateTempAlloca` 
family of functions, however dynamic allocas were not, which would make the 
following valid C++ code:

  const char* p = static_cast(__builtin_alloca(42));

lead to subtly incorrect IR / an assert flaring. This patch addresses that by 
inserting an address space cast iff the alloca address space is different from 
generic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156539

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dynamic-alloca-with-address-space.c


Index: clang/test/CodeGen/dynamic-alloca-with-address-space.c
===
--- /dev/null
+++ clang/test/CodeGen/dynamic-alloca-with-address-space.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s
+
+void allocas(unsigned long n) {
+void *a = __builtin_alloca(n);
+void *uninitialized_a = __builtin_alloca_uninitialized(n);
+void *aligned_a = __builtin_alloca_with_align(n, 8);
+void *aligned_uninitialized_a = 
__builtin_alloca_with_align_uninitialized(n, 8);
+}
+
+// CHECK: @allocas(
+// CHECK: store i64 %n, ptr %n.addr.ascast, align 8
+// CHECK: %0 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %1 = alloca i8, i64 %0, align 8, addrspace(5)
+// CHECK: %2 = addrspacecast ptr addrspace(5) %1 to ptr
+// CHECK: store ptr %2, ptr %a.ascast, align 8
+// CHECK: %3 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %4 = alloca i8, i64 %3, align 8, addrspace(5)
+// CHECK: %5 = addrspacecast ptr addrspace(5) %4 to ptr
+// CHECK: store ptr %5, ptr %uninitialized_a.ascast, align 8
+// CHECK: %6 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %7 = alloca i8, i64 %6, align 1, addrspace(5)
+// CHECK: %8 = addrspacecast ptr addrspace(5) %7 to ptr
+// CHECK: store ptr %8, ptr %aligned_a.ascast, align 8
+// CHECK: %9 = load i64, ptr %n.addr.ascast, align 8
+// CHECK: %10 = alloca i8, i64 %9, align 1, addrspace(5)
+// CHECK: %11 = addrspacecast ptr addrspace(5) %10 to ptr
+// CHECK: store ptr %11, ptr %aligned_uninitialized_a.ascast, align 8
+// CHECK: ret void
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3514,6 +3514,12 @@
 return RValue::get(Result);
   }
 
+  // An alloca will always return a pointer to the alloca (stack) address
+  // space. This address space need not be the same as the AST / Language
+  // default (e.g. in C / C++ auto vars are in the generic address space). At
+  // the AST level this is handled within CreateTempAlloca et al., but for the
+  // builtin / dynamic alloca we have to handle it here. We use an explicit 
cast
+  // instead of passing an AS to CreateAlloca so as to not inhibit 
optimisation.
   case Builtin::BIalloca:
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca_uninitialized:
@@ -3529,7 +3535,10 @@
 AI->setAlignment(SuitableAlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
   initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
-return RValue::get(AI);
+if (getASTAllocaAddressSpace() != LangAS::Default)
+  return RValue::get(Builder.CreateAddrSpaceCast(AI, CGM.Int8PtrTy));
+else
+  return RValue::get(AI);
   }
 
   case Builtin::BI__builtin_alloca_with_align_uninitialized:
@@ -3544,7 +3553,10 @@
 AI->setAlignment(AlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_with_align_uninitialized)
   initializeAlloca(*this, AI, Size, AlignmentInBytes);
-return RValue::get(AI);
+if (getASTAllocaAddressSpace() != LangAS::Default)
+  return RValue::get(Builder.CreateAddrSpaceCast(AI, CGM.Int8PtrTy));
+else
+  return RValue::get(AI);
   }
 
   case Builtin::BIbzero:


Index: clang/test/CodeGen/dynamic-alloca-with-address-space.c
===
--- /dev/null
+++ clang/test/CodeGen/dynamic-alloca-with-address-space.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s
+
+void allocas(unsigned long n) {
+void *a = __builtin_alloca(n);
+void *uninitialized_a = __builtin_alloca_uninitialized(n);
+void *aligned_a = __builtin_alloca_with_align(n, 8);
+void *aligned_uninitialized_a = __builtin_alloca_with_align_uninitialized(n, 8);
+}
+
+// CHECK: @allocas(

  1   2   3   >