[PATCH] D134339: [clang][llvm] generate accessibility metadata for type aliases

2022-09-22 Thread Jonathan Camilleri via Phabricator via cfe-commits
J-Camilleri updated this revision to Diff 462092.
J-Camilleri added a comment.

Addressing reviewer comments: Comply to offical style, Simplify test cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134339

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-access.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/DebugInfo/X86/debug-info-access.ll

Index: llvm/test/DebugInfo/X86/debug-info-access.ll
===
--- llvm/test/DebugInfo/X86/debug-info-access.ll
+++ llvm/test/DebugInfo/X86/debug-info-access.ll
@@ -15,8 +15,14 @@
 ;   public:
 ; void pub();
 ; static int public_static;
+;
 ;   protected:
+; typedef int prot_typedef;
+; using prot_using = prot_typedef;
+; prot_using prot_member;
+;
 ; void prot();
+;
 ;   private:
 ; void priv_default();
 ;   };
@@ -28,9 +34,13 @@
 ;   protected:
 ; union E {
 ; };
+;   private:
+; struct J {
+; };
 ;   public:
 ; D d;
 ; E e;
+; J j;
 ;   };
 ;
 ;   struct F {
@@ -57,9 +67,9 @@
 ;
 ;   void free() {}
 ;
+;   U u;
 ;   A a;
 ;   B b;
-;   U u;
 ;   C c;
 ;   F f;
 ;   H h;
@@ -92,6 +102,14 @@
 ; CHECK-NOT: DW_TAG
 ; CHECK: DW_AT_accessibility {{.*}}(DW_ACCESS_public)
 
+; CHECK: DW_TAG_member
+; CHECK: DW_AT_name {{.*}}"prot_member")
+
+; CHECK: DW_TAG_typedef
+; CHECK: DW_AT_name {{.*}}"prot_using")
+; CHECK-NOT: DW_TAG
+; CHECK: DW_AT_accessibility {{.*}}(DW_ACCESS_protected)
+
 ; CHECK: DW_TAG_subprogram
 ; CHECK: DW_AT_name {{.*}}"pub")
 ; CHECK-NOT: DW_TAG
@@ -130,42 +148,43 @@
 
 %union.U = type { i32 }
 %struct.A = type { i8 }
-%class.B = type { i8 }
-%class.C = type { %"struct.C::D", %"union.C::E" }
+%class.B = type { i32 }
+%class.C = type { %"struct.C::D", %"union.C::E", %"struct.C::J" }
 %"struct.C::D" = type { i8 }
 %"union.C::E" = type { i8 }
+%"struct.C::J" = type { i8 }
 %struct.F = type { %"union.F::G" }
 %"union.F::G" = type { i8 }
 %union.H = type { %"class.H::I" }
 %"class.H::I" = type { i8 }
 
-@u = global %union.U zeroinitializer, align 4, !dbg !0
-@a = global %struct.A zeroinitializer, align 1, !dbg !5
-@b = global %class.B zeroinitializer, align 1, !dbg !16
-@c = global %class.C zeroinitializer, align 1, !dbg !28
-@f = global %struct.F zeroinitializer, align 1, !dbg !37
-@h = global %union.H zeroinitializer, align 1, !dbg !43
+@u = dso_local global %union.U zeroinitializer, align 4, !dbg !0
+@a = dso_local global %struct.A zeroinitializer, align 1, !dbg !5
+@b = dso_local global %class.B zeroinitializer, align 4, !dbg !16
+@c = dso_local global %class.C zeroinitializer, align 1, !dbg !31
+@f = dso_local global %struct.F zeroinitializer, align 1, !dbg !42
+@h = dso_local global %union.H zeroinitializer, align 1, !dbg !48
 
-; Function Attrs: mustprogress noinline nounwind optnone
-define dso_local void @_Z4freev() #0 !dbg !59 {
+; Function Attrs: mustprogress noinline nounwind optnone uwtable
+define dso_local void @_Z4freev() #0 !dbg !69 {
 entry:
-  ret void, !dbg !62
+  ret void, !dbg !72
 }
 
-attributes #0 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+attributes #0 = { mustprogress noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
 
 !llvm.dbg.cu = !{!2}
-!llvm.module.flags = !{!56, !57}
-!llvm.ident = !{!58}
+!llvm.module.flags = !{!61, !62, !63, !64, !65, !66, !67}
+!llvm.ident = !{!68}
 
 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
-!1 = distinct !DIGlobalVariable(name: "u", scope: !2, file: !7, line: 73, type: !49, isLocal: false, isDefinition: true)
-!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
-!3 = !DIFile(filename: "clang/test/CodeGenCXX/", directory: "")
-!4 = !{!0, !5, !16, !28, !37, !43}
+!1 = distinct !DIGlobalVariable(name: "u", scope: !2, file: !7, line: 86, type: !54, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 16.0.0 (https://github.com/llvm/llvm-project.git 113a643a597b6a8f68099fedbeb7509449d4bd50)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "/home/jon/sources/llvm-project/clang/test/CodeGenCXX/debug-info-access.cpp", directory: "/home/jon/sources/llvm-project/

[PATCH] D134339: [clang][llvm] generate accessibility metadata for type aliases

2022-09-22 Thread Jonathan Camilleri via Phabricator via cfe-commits
J-Camilleri marked 3 inline comments as done.
J-Camilleri added inline comments.



Comment at: clang/test/CodeGenCXX/debug-info-access.cpp:23-27
+
+  // CHECK-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "pub_typedef",{{.*}} 
line: [[@LINE+1]],{{.*}} flags: DIFlagPublic)
+  typedef int pub_typedef;
+  pub_typedef pub_member;
+

dblaikie wrote:
> Arguably/I'd be fine with testing just one case here - since the 
> implementation of choosing when to put an access modifier, which modifier to 
> put, etc, is is already implemented and tested for other cases - so we might 
> not need to duplicate that testing for this case. 
> 
> But I don't mind too much either way.
I agree with your assesment. I changed the test to just check that type aliases 
emit the flag not the logic of which flag is emitted.



Comment at: llvm/lib/IR/DIBuilder.cpp:351
 DIScope *Context, uint32_t AlignInBits,
+DINode::DIFlags Flags,
 DINodeArray Annotations) {

dblaikie wrote:
> While we usually split llvm & clang commits, in this case since it changes an 
> API used by clang, this part of the llvm change should go along with the 
> clang change.
Regarding this and the previous comment about separating the llvm commit.

Am I to have 2 commits as follows?
1. change llvm to emit flag + test case
2. modify llvm interface + change clang to emit flag + test case

I do not have merge rights so I will ask for this when I get to the merge stage.

Thanks for the review.



Comment at: llvm/test/DebugInfo/X86/debug-info-access.ll:12-32
+;
+; using pub_default_using = int;
+; pub_default_using a_pub;
 ;   };
 ;
 ;   class B : public A {
 ;   public:

dblaikie wrote:
> Probably don't need all this test coverage - since most of this is motivated 
> by the features up in clang - on the LLVM side we just need one case that 
> demonstrates that if we put an access specifier in the flags, that gets 
> emitted.
I left the llvm to be the same as generated by the cpp file but changed the 
`CHECK` to just verify that the accessibility flag is emitted for a `typedef`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134339

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


[PATCH] D134362: [clang] Fix interaction between asm labels and inline builtins

2022-09-22 Thread serge 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 rGd4420402927e: [clang] Fix interaction between asm labels and 
inline builtins (authored by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D134362?vs=462009&id=462096#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134362

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/asm-label-inline-builtins.c


Index: clang/test/CodeGen/asm-label-inline-builtins.c
===
--- /dev/null
+++ clang/test/CodeGen/asm-label-inline-builtins.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | 
FileCheck %s
+//
+// Verifies that clang-generated *.inline carry the same name at call and 
callee
+// site, in spite of asm labels.
+
+typedef struct _IO_FILE FILE;
+extern FILE *stdout;
+extern int vprintf (const char *__restrict __format, __builtin_va_list __arg);
+extern int __vfprintf_chk (FILE *__restrict __stream, int __flag,
+  const char *__restrict __format, __builtin_va_list __ap);
+extern int __vprintf_chk (int __flag, const char *__restrict __format,
+ __builtin_va_list __ap);
+
+extern __typeof (vprintf) vprintf __asm ("__vprintfieee128");
+extern __typeof (__vfprintf_chk) __vfprintf_chk __asm 
("__vfprintf_chkieee128");
+extern __typeof (__vprintf_chk) __vprintf_chk __asm ("__vprintf_chkieee128");
+
+extern __inline __attribute__ ((__always_inline__)) __attribute__ 
((__gnu_inline__)) __attribute__ ((__artificial__)) int
+vprintf (const char *__restrict __fmt, __builtin_va_list __ap)
+{
+  return __vfprintf_chk (stdout, 2 - 1, __fmt, __ap);
+}
+
+void test(const char *fmt, __builtin_va_list ap) {
+  vprintf(fmt, ap);
+}
+
+// CHECK-LABEL: void @test(
+// CHECK: call i32 @__vprintfieee128.inline(
+//
+// CHECK-LABEL: internal i32 @__vprintfieee128.inline(
+// CHECK: call i32 @__vfprintf_chkieee128(
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5051,7 +5051,10 @@
   if (auto builtinID = FD->getBuiltinID()) {
 std::string NoBuiltinFD = ("no-builtin-" + FD->getName()).str();
 std::string NoBuiltins = "no-builtins";
-std::string FDInlineName = (FD->getName() + ".inline").str();
+
+auto *A = FD->getAttr();
+StringRef Ident = A ? A->getLabel() : FD->getName();
+std::string FDInlineName = (Ident + ".inline").str();
 
 bool IsPredefinedLibFunction =
 CGF.getContext().BuiltinInfo.isPredefinedLibFunction(builtinID);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -162,6 +162,7 @@
   `Issue 53628 `_
 - The template arguments of a variable template being accessed as a
   member will now be represented in the AST.
+- Fix incorrect handling of inline builtins with asm labels.
 
 
 Improvements to Clang's diagnostics


Index: clang/test/CodeGen/asm-label-inline-builtins.c
===
--- /dev/null
+++ clang/test/CodeGen/asm-label-inline-builtins.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+//
+// Verifies that clang-generated *.inline carry the same name at call and callee
+// site, in spite of asm labels.
+
+typedef struct _IO_FILE FILE;
+extern FILE *stdout;
+extern int vprintf (const char *__restrict __format, __builtin_va_list __arg);
+extern int __vfprintf_chk (FILE *__restrict __stream, int __flag,
+  const char *__restrict __format, __builtin_va_list __ap);
+extern int __vprintf_chk (int __flag, const char *__restrict __format,
+ __builtin_va_list __ap);
+
+extern __typeof (vprintf) vprintf __asm ("__vprintfieee128");
+extern __typeof (__vfprintf_chk) __vfprintf_chk __asm ("__vfprintf_chkieee128");
+extern __typeof (__vprintf_chk) __vprintf_chk __asm ("__vprintf_chkieee128");
+
+extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) int
+vprintf (const char *__restrict __fmt, __builtin_va_list __ap)
+{
+  return __vfprintf_chk (stdout, 2 - 1, __fmt, __ap);
+}
+
+void test(const char *fmt, __builtin_va_list ap) {
+  vprintf(fmt, ap);
+}
+
+// CHECK-LABEL: void @test(
+// CHECK: call i32 @__vprintfieee128.inline(
+//
+// CHECK-LABEL: internal i32 @__vprintfieee128.inline(
+// CHECK: call i32 @__vfprintf_chkieee128(
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -5051,7 +5051,

[clang] d442040 - [clang] Fix interaction between asm labels and inline builtins

2022-09-22 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-09-22T09:24:47+02:00
New Revision: d4420402927eed63d21eab5f71f5dbdaf6244a66

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

LOG: [clang] Fix interaction between asm labels and inline builtins

One must pick the same name as the one referenced in CodeGenFunction when
generating .inline version of an inline builtin, otherwise they are not
correctly replaced.

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

Added: 
clang/test/CodeGen/asm-label-inline-builtins.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c50dd90f1a4a..5d517eb676be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -162,6 +162,7 @@ Bug Fixes
   `Issue 53628 `_
 - The template arguments of a variable template being accessed as a
   member will now be represented in the AST.
+- Fix incorrect handling of inline builtins with asm labels.
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index d51245905175..80a05c984f60 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5051,7 +5051,10 @@ static CGCallee EmitDirectCallee(CodeGenFunction &CGF, 
GlobalDecl GD) {
   if (auto builtinID = FD->getBuiltinID()) {
 std::string NoBuiltinFD = ("no-builtin-" + FD->getName()).str();
 std::string NoBuiltins = "no-builtins";
-std::string FDInlineName = (FD->getName() + ".inline").str();
+
+auto *A = FD->getAttr();
+StringRef Ident = A ? A->getLabel() : FD->getName();
+std::string FDInlineName = (Ident + ".inline").str();
 
 bool IsPredefinedLibFunction =
 CGF.getContext().BuiltinInfo.isPredefinedLibFunction(builtinID);

diff  --git a/clang/test/CodeGen/asm-label-inline-builtins.c 
b/clang/test/CodeGen/asm-label-inline-builtins.c
new file mode 100644
index ..ab9afc29411d
--- /dev/null
+++ b/clang/test/CodeGen/asm-label-inline-builtins.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | 
FileCheck %s
+//
+// Verifies that clang-generated *.inline carry the same name at call and 
callee
+// site, in spite of asm labels.
+
+typedef struct _IO_FILE FILE;
+extern FILE *stdout;
+extern int vprintf (const char *__restrict __format, __builtin_va_list __arg);
+extern int __vfprintf_chk (FILE *__restrict __stream, int __flag,
+  const char *__restrict __format, __builtin_va_list __ap);
+extern int __vprintf_chk (int __flag, const char *__restrict __format,
+ __builtin_va_list __ap);
+
+extern __typeof (vprintf) vprintf __asm ("__vprintfieee128");
+extern __typeof (__vfprintf_chk) __vfprintf_chk __asm 
("__vfprintf_chkieee128");
+extern __typeof (__vprintf_chk) __vprintf_chk __asm ("__vprintf_chkieee128");
+
+extern __inline __attribute__ ((__always_inline__)) __attribute__ 
((__gnu_inline__)) __attribute__ ((__artificial__)) int
+vprintf (const char *__restrict __fmt, __builtin_va_list __ap)
+{
+  return __vfprintf_chk (stdout, 2 - 1, __fmt, __ap);
+}
+
+void test(const char *fmt, __builtin_va_list ap) {
+  vprintf(fmt, ap);
+}
+
+// CHECK-LABEL: void @test(
+// CHECK: call i32 @__vprintfieee128.inline(
+//
+// CHECK-LABEL: internal i32 @__vprintfieee128.inline(
+// CHECK: call i32 @__vfprintf_chkieee128(



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


[PATCH] D134352: [AArch64] Add Neoverse V2 CPU support

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

Thanks. Should RNG be added? And Why is Crypto no longer enabled?


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

https://reviews.llvm.org/D134352

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


[PATCH] D133711: [Sema] Reject array element types whose sizes aren't a multiple of their alignments

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

This has caused 2 test suite failures across our bots, for example: 
https://lab.llvm.org/buildbot/#/builders/174/builds/13518 
`GCC-C-execute-pr36093.test` / `GCC-C-execute-pr43783.test`

Pretty likely the tests are doing something strange, I will look into it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133711

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


[PATCH] D134416: Allow getting template args for ClassTemplateSpecializations

2022-09-22 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands created this revision.
Herald added a project: All.
anderslanglands requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Modifies clang_Cursor_getNumTemplateArguments() and friends to work on Struct, 
Class and ClassTemplatePartialSpecialization decls as well as functions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134416

Files:
  clang/docs/ReleaseNotes.rst
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1353,34 +1353,42 @@
 }
 
 int clang_Cursor_getNumTemplateArguments(CXCursor C) {
-  if (clang_getCursorKind(C) != CXCursor_FunctionDecl) {
+  CXCursorKind kind = clang_getCursorKind(C);
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
+  kind != CXCursor_ClassDecl &&
+  kind != CXCursor_ClassTemplatePartialSpecialization) {
 return -1;
   }
 
-  const FunctionDecl *FD =
-  llvm::dyn_cast_or_null(getCursorDecl(C));
-  if (!FD) {
-return -1;
-  }
-
-  const FunctionTemplateSpecializationInfo *SpecInfo =
-  FD->getTemplateSpecializationInfo();
-  if (!SpecInfo) {
+  if (const FunctionDecl *FD =
+  llvm::dyn_cast_if_present(getCursorDecl(C))) {
+const FunctionTemplateSpecializationInfo *SpecInfo =
+FD->getTemplateSpecializationInfo();
+if (!SpecInfo) {
+  return -1;
+}
+return SpecInfo->TemplateArguments->size();
+  } else if (const ClassTemplateSpecializationDecl *SD =
+ llvm::dyn_cast_if_present<
+ clang::ClassTemplateSpecializationDecl>(
+ getCursorDecl(C))) {
+return SD->getTemplateArgs().size();
+  } else {
 return -1;
   }
-
-  return SpecInfo->TemplateArguments->size();
 }
 
 enum CXGetTemplateArgumentStatus {
   /** The operation completed successfully */
   CXGetTemplateArgumentStatus_Success = 0,
 
-  /** The specified cursor did not represent a FunctionDecl. */
-  CXGetTemplateArgumentStatus_CursorNotFunctionDecl = -1,
+  /** The specified cursor did not represent a FunctionDecl or
+  ClassTemplateSpecializationDecl. */
+  CXGetTemplateArgumentStatus_CursorNotCompatibleDecl = -1,
 
-  /** The specified cursor was not castable to a FunctionDecl. */
-  CXGetTemplateArgumentStatus_BadFunctionDeclCast = -2,
+  /** The specified cursor was not castable to a FunctionDecl or
+  ClassTemplateSpecializationDecl. */
+  CXGetTemplateArgumentStatus_BadDeclCast = -2,
 
   /** A NULL FunctionTemplateSpecializationInfo was retrieved. */
   CXGetTemplateArgumentStatus_NullTemplSpecInfo = -3,
@@ -1391,28 +1399,43 @@
 
 static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I,
 TemplateArgument *TA) {
-  if (clang_getCursorKind(C) != CXCursor_FunctionDecl) {
-return CXGetTemplateArgumentStatus_CursorNotFunctionDecl;
+  CXCursorKind kind = clang_getCursorKind(C);
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
+  kind != CXCursor_ClassDecl &&
+  kind != CXCursor_ClassTemplatePartialSpecialization) {
+return -1;
   }
 
-  const FunctionDecl *FD =
-  llvm::dyn_cast_or_null(getCursorDecl(C));
-  if (!FD) {
-return CXGetTemplateArgumentStatus_BadFunctionDeclCast;
-  }
+  if (const FunctionDecl *FD =
+  llvm::dyn_cast_if_present(getCursorDecl(C))) {
 
-  const FunctionTemplateSpecializationInfo *SpecInfo =
-  FD->getTemplateSpecializationInfo();
-  if (!SpecInfo) {
-return CXGetTemplateArgumentStatus_NullTemplSpecInfo;
-  }
+const FunctionTemplateSpecializationInfo *SpecInfo =
+FD->getTemplateSpecializationInfo();
+if (!SpecInfo) {
+  return CXGetTemplateArgumentStatus_NullTemplSpecInfo;
+}
 
-  if (I >= SpecInfo->TemplateArguments->size()) {
-return CXGetTemplateArgumentStatus_InvalidIndex;
-  }
+if (I >= SpecInfo->TemplateArguments->size()) {
+  return CXGetTemplateArgumentStatus_InvalidIndex;
+}
 
-  *TA = SpecInfo->TemplateArguments->get(I);
-  return 0;
+*TA = SpecInfo->TemplateArguments->get(I);
+return 0;
+  } else if (const ClassTemplateSpecializationDecl *SD =
+ llvm::dyn_cast_if_present<
+ clang::ClassTemplateSpecializationDecl>(
+ getCursorDecl(C))) {
+if (I >= SD->getTemplateArgs().size()) {
+  printf("INVALID INDEX\n");
+  return CXGetTemplateArgumentStatus_InvalidIndex;
+}
+
+*TA = SD->getTemplateArgs()[I];
+return 0;
+  } else {
+printf("CAST FAILED\n");
+return CXGetTemplateArgumentStatus_BadDeclCast;
+  }
 }
 
 enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(CXCursor C,
Index: clang/docs/ReleaseNotes.rst
===
--- 

[PATCH] D134416: Allow getting template args for ClassTemplateSpecializations

2022-09-22 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands added reviewers: tbaeder, aaron.ballman.
anderslanglands added a comment.

Hello again, this generalizes the template argument functionality to operate on 
cursor kinds other than functions.

I could use some help creating a test for this. On my previous path I was able 
to just copy/paste and modify an existing test, but from a quick scan of the 
current tests I can't see how I'd modify one of them to test this functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134416

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


[PATCH] D134416: Allow getting template args for ClassTemplateSpecializations

2022-09-22 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands updated this revision to Diff 462103.
anderslanglands added a comment.
Herald added a subscriber: arphaman.

Updating doc comments to reflect new functionality


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134416

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1353,34 +1353,42 @@
 }
 
 int clang_Cursor_getNumTemplateArguments(CXCursor C) {
-  if (clang_getCursorKind(C) != CXCursor_FunctionDecl) {
+  CXCursorKind kind = clang_getCursorKind(C);
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
+  kind != CXCursor_ClassDecl &&
+  kind != CXCursor_ClassTemplatePartialSpecialization) {
 return -1;
   }
 
-  const FunctionDecl *FD =
-  llvm::dyn_cast_or_null(getCursorDecl(C));
-  if (!FD) {
-return -1;
-  }
-
-  const FunctionTemplateSpecializationInfo *SpecInfo =
-  FD->getTemplateSpecializationInfo();
-  if (!SpecInfo) {
+  if (const FunctionDecl *FD =
+  llvm::dyn_cast_if_present(getCursorDecl(C))) {
+const FunctionTemplateSpecializationInfo *SpecInfo =
+FD->getTemplateSpecializationInfo();
+if (!SpecInfo) {
+  return -1;
+}
+return SpecInfo->TemplateArguments->size();
+  } else if (const ClassTemplateSpecializationDecl *SD =
+ llvm::dyn_cast_if_present<
+ clang::ClassTemplateSpecializationDecl>(
+ getCursorDecl(C))) {
+return SD->getTemplateArgs().size();
+  } else {
 return -1;
   }
-
-  return SpecInfo->TemplateArguments->size();
 }
 
 enum CXGetTemplateArgumentStatus {
   /** The operation completed successfully */
   CXGetTemplateArgumentStatus_Success = 0,
 
-  /** The specified cursor did not represent a FunctionDecl. */
-  CXGetTemplateArgumentStatus_CursorNotFunctionDecl = -1,
+  /** The specified cursor did not represent a FunctionDecl or
+  ClassTemplateSpecializationDecl. */
+  CXGetTemplateArgumentStatus_CursorNotCompatibleDecl = -1,
 
-  /** The specified cursor was not castable to a FunctionDecl. */
-  CXGetTemplateArgumentStatus_BadFunctionDeclCast = -2,
+  /** The specified cursor was not castable to a FunctionDecl or
+  ClassTemplateSpecializationDecl. */
+  CXGetTemplateArgumentStatus_BadDeclCast = -2,
 
   /** A NULL FunctionTemplateSpecializationInfo was retrieved. */
   CXGetTemplateArgumentStatus_NullTemplSpecInfo = -3,
@@ -1391,28 +1399,43 @@
 
 static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I,
 TemplateArgument *TA) {
-  if (clang_getCursorKind(C) != CXCursor_FunctionDecl) {
-return CXGetTemplateArgumentStatus_CursorNotFunctionDecl;
+  CXCursorKind kind = clang_getCursorKind(C);
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
+  kind != CXCursor_ClassDecl &&
+  kind != CXCursor_ClassTemplatePartialSpecialization) {
+return -1;
   }
 
-  const FunctionDecl *FD =
-  llvm::dyn_cast_or_null(getCursorDecl(C));
-  if (!FD) {
-return CXGetTemplateArgumentStatus_BadFunctionDeclCast;
-  }
+  if (const FunctionDecl *FD =
+  llvm::dyn_cast_if_present(getCursorDecl(C))) {
 
-  const FunctionTemplateSpecializationInfo *SpecInfo =
-  FD->getTemplateSpecializationInfo();
-  if (!SpecInfo) {
-return CXGetTemplateArgumentStatus_NullTemplSpecInfo;
-  }
+const FunctionTemplateSpecializationInfo *SpecInfo =
+FD->getTemplateSpecializationInfo();
+if (!SpecInfo) {
+  return CXGetTemplateArgumentStatus_NullTemplSpecInfo;
+}
 
-  if (I >= SpecInfo->TemplateArguments->size()) {
-return CXGetTemplateArgumentStatus_InvalidIndex;
-  }
+if (I >= SpecInfo->TemplateArguments->size()) {
+  return CXGetTemplateArgumentStatus_InvalidIndex;
+}
 
-  *TA = SpecInfo->TemplateArguments->get(I);
-  return 0;
+*TA = SpecInfo->TemplateArguments->get(I);
+return 0;
+  } else if (const ClassTemplateSpecializationDecl *SD =
+ llvm::dyn_cast_if_present<
+ clang::ClassTemplateSpecializationDecl>(
+ getCursorDecl(C))) {
+if (I >= SD->getTemplateArgs().size()) {
+  printf("INVALID INDEX\n");
+  return CXGetTemplateArgumentStatus_InvalidIndex;
+}
+
+*TA = SD->getTemplateArgs()[I];
+return 0;
+  } else {
+printf("CAST FAILED\n");
+return CXGetTemplateArgumentStatus_BadDeclCast;
+  }
 }
 
 enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(CXCursor C,
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@

[PATCH] D134352: [AArch64] Add Neoverse V2 CPU support

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

Oh, A release note would be good to add too.


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

https://reviews.llvm.org/D134352

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


[PATCH] D133711: [Sema] Reject array element types whose sizes aren't a multiple of their alignments

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

GCC also rejects those tests so https://reviews.llvm.org/D134417 to disable 
them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133711

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


[PATCH] D130460: [pseudo] Add recovery for declarations

2022-09-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 462107.
hokein added a comment.

- rebase, fixed a few conflicts
- address comments
- fix some bugs
- restructure the code, moving the implementation to a separate file
- add unittests for recoveryNextDeclaration
- keep the left-recursive declaration-seq grammar rule to void performance 
regression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130460

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Language.h
  clang-tools-extra/pseudo/include/clang-pseudo/cxx/Recovery.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/cxx/CMakeLists.txt
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/cxx/Recovery.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/recovery-declarations.cpp
  clang-tools-extra/pseudo/unittests/CMakeLists.txt
  clang-tools-extra/pseudo/unittests/CXXRecoveryTest.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp

Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -48,13 +48,13 @@
testing::UnorderedElementsAreArray(Parents));
 }
 
-Token::Index recoverBraces(Token::Index Begin, const TokenStream &Code) {
-  EXPECT_GT(Begin, 0u);
-  const Token &Left = Code.tokens()[Begin - 1];
+Token::Index recoverBraces(const RecoveryParams &P) {
+  EXPECT_GT(P.Begin, 0u);
+  const Token &Left = P.Tokens.tokens()[P.Begin - 1];
   EXPECT_EQ(Left.Kind, tok::l_brace);
   if (const auto* Right = Left.pair()) {
 EXPECT_EQ(Right->Kind, tok::r_brace);
-return Code.index(*Right);
+return P.Tokens.index(*Right);
   }
   return Token::Invalid;
 }
@@ -613,7 +613,7 @@
   TestLang.Table = LRTable::buildSLR(TestLang.G);
   TestLang.RecoveryStrategies.try_emplace(
   extensionID("Skip"),
-  [](Token::Index Start, const TokenStream &) { return Start; });
+  [](const RecoveryParams& P) { return P.Begin; });
   clang::LangOptions LOptions;
   TokenStream Tokens = cook(lex("foo", LOptions), LOptions);
 
@@ -641,7 +641,7 @@
   TestLang.Table = LRTable::buildSLR(TestLang.G);
   TestLang.RecoveryStrategies.try_emplace(
   extensionID("AcceptAnyTokenInstead"),
-  [](Token::Index Start, const TokenStream &Stream) { return Start + 1; });
+  [](const RecoveryParams& P) { return P.Begin + 1; });
 
   const ForestNode &Parsed =
   glrParse({Tokens, Arena, GSStack}, id("sentence"), TestLang);
@@ -660,9 +660,9 @@
   )bnf");
   TestLang.Table = LRTable::buildSLR(TestLang.G);
   bool fallback_recovered = false;
-  auto fallback = [&](Token::Index Start, const TokenStream & Code) {
+  auto fallback = [&](const RecoveryParams& P) {
 fallback_recovered = true;
-return Code.tokens().size();
+return P.Tokens.tokens().size();
   };
   TestLang.RecoveryStrategies.try_emplace(
   extensionID("Fallback"),
@@ -694,7 +694,7 @@
   TestLang.Table = LRTable::buildSLR(TestLang.G);
   TestLang.RecoveryStrategies.try_emplace(
   extensionID("Skip"),
-  [](Token::Index Start, const TokenStream &) { return Start; });
+  [](const RecoveryParams& P) { return P.Begin; });
   clang::LangOptions LOptions;
   TokenStream Tokens = cook(lex("main", LOptions), LOptions);
 
Index: clang-tools-extra/pseudo/unittests/CXXRecoveryTest.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/unittests/CXXRecoveryTest.cpp
@@ -0,0 +1,110 @@
+//===--- CXXRecoveryTest.cpp - --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang-pseudo/Bracket.h"
+#include "clang-pseudo/Language.h"
+#include "clang-pseudo/Token.h"
+#include "clang-pseudo/cxx/Recovery.h"
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "gtest/gtest.h"
+
+namespace clang::pseudo {
+
+namespace {
+
+std::pair
+extract(const llvm::Annotations &Test) {
+  assert(Test.points().size() == 2 && "Expect two ^s in the test annotations");
+  LangOptions Opts = clang::pseudo::genericLangOpts();
+  std::string Code = Test.code().str();
+  TokenStream Cook = cook(lex(Code, Opts), Opts);
+  pairBrackets(Cook);
+
+  RecoveryParams P{0, Token::Invalid, Cook};
+  auto StartOffset = [&](const Token &T) -> size_t {
+return T.Data - Code.data();
+  };
+  for (const auto &T : Cook.tokens()) {
+if (StartOffset(T) == Test.points().front()) {
+  P.Cursor = Cook.index(T);
+  break;
+}
+  }
+  assert(P.Cursor != Token::Invalid && "no curs

[PATCH] D133338: [clang][PowerPC] PPC64 VAArg use coerced integer type for direct aggregate fits in register

2022-09-22 Thread Ting Wang via Phabricator via cfe-commits
tingwang updated this revision to Diff 462113.
tingwang added a comment.

Add TODO comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D18

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/PowerPC/ppc64-align-struct.c


Index: clang/test/CodeGen/PowerPC/ppc64-align-struct.c
===
--- clang/test/CodeGen/PowerPC/ppc64-align-struct.c
+++ clang/test/CodeGen/PowerPC/ppc64-align-struct.c
@@ -129,15 +129,15 @@
   return y;
 }
 
-// Error pattern will be fixed in https://reviews.llvm.org/D18
 // CHECK: define{{.*}} void @test8va(%struct.test8* noalias 
sret(%struct.test8) align 1 %[[AGG_RESULT:.*]], i32 noundef signext %x, ...)
 // CHECK: %[[CUR:[^ ]+]] = load i8*, i8** %ap
 // CHECK: %[[NEXT:[^ ]+]] = getelementptr inbounds i8, i8* %[[CUR]], i64 8
 // CHECK: store i8* %[[NEXT]], i8** %ap
-// CHECK: [[T0:%.*]] = bitcast i8* %[[CUR]] to %struct.test8*
+// CHECK: [[T0:%.*]] = getelementptr inbounds i8, i8* %[[CUR]], i64 7
+// CHECK: [[T1:%.*]] = bitcast i8* [[T0]] to %struct.test8*
 // CHECK: [[DEST:%.*]] = bitcast %struct.test8* %[[AGG_RESULT]] to i8*
-// CHECK: [[SRC:%.*]] = bitcast %struct.test8* [[T0]] to i8*
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[DEST]], i8* align 
8 [[SRC]], i64 1, i1 false)
+// CHECK: [[SRC:%.*]] = bitcast %struct.test8* [[T1]] to i8*
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[DEST]], i8* align 
1 [[SRC]], i64 1, i1 false)
 struct test8 test8va (int x, ...)
 {
   struct test8 y;
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -322,13 +322,19 @@
 ///   leaving one or more empty slots behind as padding.  If this
 ///   is false, the returned address might be less-aligned than
 ///   DirectAlign.
+/// \param ForceRightAdjust - Default is false. On big-endian platform and
+///   if the argument is smaller than a slot, set this flag will force
+///   right-adjust the argument in its slot irrespective of the type.
+///   TODO: this is workaround. Should use same logic for caller and callee
+///   to deduce the adjustment, and get rid of this flag.
 static Address emitVoidPtrDirectVAArg(CodeGenFunction &CGF,
   Address VAListAddr,
   llvm::Type *DirectTy,
   CharUnits DirectSize,
   CharUnits DirectAlign,
   CharUnits SlotSize,
-  bool AllowHigherAlign) {
+  bool AllowHigherAlign,
+  bool ForceRightAdjust = false) {
   // Cast the element type to i8* if necessary.  Some platforms define
   // va_list as a struct containing an i8* instead of just an i8*.
   if (VAListAddr.getElementType() != CGF.Int8PtrTy)
@@ -354,7 +360,7 @@
   // If the argument is smaller than a slot, and this is a big-endian
   // target, the argument will be right-adjusted in its slot.
   if (DirectSize < SlotSize && CGF.CGM.getDataLayout().isBigEndian() &&
-  !DirectTy->isStructTy()) {
+  (!DirectTy->isStructTy() || ForceRightAdjust)) {
 Addr = CGF.Builder.CreateConstInBoundsByteGEP(Addr, SlotSize - DirectSize);
   }
 
@@ -375,11 +381,15 @@
 ///   an argument type with an alignment greater than the slot size
 ///   will be emitted on a higher-alignment address, potentially
 ///   leaving one or more empty slots behind as padding.
+/// \param ForceRightAdjust - Default is false. On big-endian platform and
+///   if the argument is smaller than a slot, set this flag will force
+///   right-adjust the argument in its slot irrespective of the type.
 static Address emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType ValueTy, bool IsIndirect,
 TypeInfoChars ValueInfo,
 CharUnits SlotSizeAndAlign,
-bool AllowHigherAlign) {
+bool AllowHigherAlign,
+bool ForceRightAdjust = false) {
   // The size and alignment of the value that was passed directly.
   CharUnits DirectSize, DirectAlign;
   if (IsIndirect) {
@@ -395,9 +405,9 @@
   if (IsIndirect)
 DirectTy = DirectTy->getPointerTo(0);
 
-  Address Addr =
-  emitVoidPtrDirectVAArg(CGF, VAListAddr, DirectTy, DirectSize, 
DirectAlign,
- SlotSizeAndAlign, AllowHigherAlign);
+  Address Addr = emitVoidPtrDirectVAArg(CGF, VAListAddr, DirectTy, DirectSize,
+DirectAlign, SlotSizeAndAlign,
+AllowHigherAlign, ForceRightAdjust);
 
   if (Is

[PATCH] D133338: [clang][PowerPC] PPC64 VAArg use coerced integer type for direct aggregate fits in register

2022-09-22 Thread Ting Wang via Phabricator via cfe-commits
tingwang added a comment.

In D18#3786406 , @nemanjai wrote:

> I am not crazy about adding the Boolean parameter here or about the name. 
> Seems somewhat unclear when a caller wants to pass `true` there.
>
> What I think would be a more robust solution would be to use the same logic 
> that decides whether to coerce the struct argument to an integer type. It 
> seems that any big endian ABI that does this would want to ensure the access 
> is on the right side.
>
> Ultimately what I am getting at here is that we consider how the caller 
> passes the value and how the callee accesses it separately - which is what 
> leads to problems like this. Can we decide using the same function for the 
> caller and the callee?

I think this requirement is nontrivial for me right now, so I added TODO 
comments. Can we take this as a workaround for the issue #55900?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D18

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


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

2022-09-22 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:4866
   auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
-  auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
+  auto ToEnumLoc = importChecked(Err, D->getEnumType());
   auto ToEnumDecl = importChecked(Err, D->getEnumDecl());

This name would be more consistent with `getEnumType`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134303

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


[PATCH] D130460: [pseudo] Add recovery for declarations

2022-09-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

I think the current version should be good to review, some bits need to take 
care of:

- left-recursive vs right-recursive of declaration-seq rule, see my other 
comments about it. Currently I keep it as-is to avoid the performance 
regression on large files (I still don't see your point how right-recursive can 
simplify the error recovery, it seems to me either can work at least for this 
case)
- recoveryNextDeclaration will consume at least 1 token (the return token index 
> Cursor) to avoid the risk of running in an infinite loop
- I keep the original implementation as-is (except fixing some bugs), but IMO 
`T->Indent == OrigIndent && LikelyStartsDeclaration(T->Kind)` is too strict 
(see my FIXME testcases), and we should probably include the IDENTIFIER (I 
believe it is a common case), `LikelyStartsDeclaration(T->Kind) || (T->Kind = 
IDENTIFIER && T->Indent == OrigIndent)` might be better.




Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:291
+  // they appear at the beginning of a line.
+  auto LikelyStartsDeclaration = [&](tok::TokenKind K) -> bool {
+switch (K) {

hokein wrote:
> the list looks reasonable -- I think we can lookup the `Follow(declaration)` 
> set to find more.
added more: kw_friend, kw_inline, kw_explicit, kw_virtual.



Comment at: clang-tools-extra/pseudo/lib/cxx/cxx.bnf:313
-declaration-seq := declaration
-declaration-seq := declaration-seq declaration
 declaration := block-declaration

hokein wrote:
> Just want to spell out, this causes a performance hit :(
> (a pure change of this has a ~6% slowdown, 7.17 MB/s -> 6.7MB/s on 
> SemaCodeComplete.cpp).
> 
> left-cursive grammar is more friendly to LR-like parsers, because the parser 
> can do the reduction earlier (after a parsed a `declaration`, we can perform 
> a `declaration-seq` reduce); while right-cursive grammar, the reduction 
> starts from the last declaration (this means our GSS is more deeper).
> 
> > change decl-sequence to right-recursive to simplify this
> I remembered we discussed this bit before, but I don't really remember the 
> details now :(
> 
Got more data, it does hurt the performance on large files:

SemaExpr.cpp: 9.54MB/s -> 7.98MB/s
SemaDeclCXX.cpp: 10.16MB/s -> 9.25MB/s

small/medium files doesn't seem to be affected (hypothesis: these files has 
less declarations than large files, thus being less affected by the 
right-recursive declaration-seq grammar rule)

Hover.cpp: 8MB/s -> 7.92MB/s
ASTSignals.cpp: 12.34M/s -> 12.29MB/s



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130460

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


[clang-tools-extra] 983cb53 - [pseudo] NFC, Remove an extral blank line.

2022-09-22 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-09-22T11:07:25+02:00
New Revision: 983cb53845efde4b2a142a3e520ebe30c6673515

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

LOG: [pseudo] NFC, Remove an extral blank line.

Added: 


Modified: 
clang-tools-extra/pseudo/lib/GLR.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/GLR.cpp 
b/clang-tools-extra/pseudo/lib/GLR.cpp
index 0639990e8f7f1..e49cbc40efce0 100644
--- a/clang-tools-extra/pseudo/lib/GLR.cpp
+++ b/clang-tools-extra/pseudo/lib/GLR.cpp
@@ -699,7 +699,6 @@ void glrReduce(std::vector &Heads, 
SymbolID Lookahead,
 }
 
 const GSS::Node *GSS::addNode(LRTable::StateID State, const ForestNode *Symbol,
-
   llvm::ArrayRef Parents) {
   Node *Result = new (allocate(Parents.size())) Node();
   Result->State = State;



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


[PATCH] D134379: [clangd] IncludeCleaner: handle using namespace

2022-09-22 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D134379#3807770 , @ArcsinX wrote:

> Anyway if this is the only concern, we can handle namespace declaration as a 
> special case inside `ReferencedLocationCrawler::add()`. something like this:
>
>   diff
>   -for (const Decl *Redecl : D->redecls())
>   -  Result.User.insert(Redecl->getLocation());
>   +if (llvm::isa(D)) {
>   +  Result.User.insert(D->getCanonicalDecl()->getLocation());
>   +} else {
>   +  for (const Decl *Redecl : D->redecls())
>   +Result.User.insert(Redecl->getLocation());
>   +}
>
> And in the above example `#include bar.h` will be suggested to remove
>
> Could this be a suitable solution?

I don't think picking the canonical declaration would be helpful in general 
case; it'll likely preserve the first header all the time, which might be 
unused otherwise.

I feel like the best option here is, diagnosing the unused using directive as 
well. but I am not sure if changing the lookup semantics would always be 
"right".
The other option would be to consider headers in batches after full analysis is 
complete, while keeping track of symbols provided by a particular header.
That way when we have a symbol that's only re-declared in a bunch of headers, 
we can rank them based on other symbols being provided and only keep the 
headers that are providing some extra "used" symbols in addition to redecls.
In the absence of such we get to pick an option between "all/none/forward 
declare ourselves". I guess picking "all" in this case is less troublesome, the 
user will get all the "unused include" warnings as soon as they use a symbol 
from that namespace.

This is not easy in the current implementation of clangd, as we preserve 
symbols provided by headers, but the new include-cleaner library we're working 
on is more accommodating for such logic. Hence I'd rather leave this 
implementation as-is today, and see if such a behaviour would be desired in 
general (not only for namespace-decls, but pretty much any declaration for 
which we can only see "forward declarations" without a clear "canonical 
declaration"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134379

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


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

2022-09-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

Thanks everyone! So if no one else has comments I'm planning to merge this 
tomorrow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133659

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


[PATCH] D134352: [AArch64] Add Neoverse V2 CPU support

2022-09-22 Thread David Sherwood via Phabricator via cfe-commits
david-arm updated this revision to Diff 462124.
david-arm added a comment.

- Added FEAT_RNG to the neoverse-v2 CPU.
- Added message to release notes.


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

https://reviews.llvm.org/D134352

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

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1026,6 +1026,16 @@
 AArch64::AEK_PROFILE | AArch64::AEK_RAND |
 AArch64::AEK_FP16FML | AArch64::AEK_I8MM,
 "8.4-A"),
+ARMCPUTestParams(
+"neoverse-v2", "armv9-a", "neon-fp-armv8",
+AArch64::AEK_RAS | AArch64::AEK_SVE | AArch64::AEK_SSBS |
+AArch64::AEK_RCPC | AArch64::AEK_CRC | AArch64::AEK_FP |
+AArch64::AEK_SIMD | AArch64::AEK_RAS | AArch64::AEK_LSE |
+AArch64::AEK_RDM | AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+AArch64::AEK_FP16 | AArch64::AEK_BF16 | AArch64::AEK_SVE2 |
+AArch64::AEK_PROFILE | AArch64::AEK_FP16FML |
+AArch64::AEK_I8MM | AArch64::AEK_RAND,
+"9-A"),
 ARMCPUTestParams("cortex-r82", "armv8-r", "crypto-neon-fp-armv8",
  AArch64::AEK_CRC | AArch64::AEK_RDM |
  AArch64::AEK_SSBS | AArch64::AEK_DOTPROD |
@@ -1257,7 +1267,7 @@
  AArch64::AEK_LSE | AArch64::AEK_RDM,
  "8.2-A")));
 
-static constexpr unsigned NumAArch64CPUArchs = 54;
+static constexpr unsigned NumAArch64CPUArchs = 55;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/test/CodeGen/AArch64/cpus.ll
===
--- llvm/test/CodeGen/AArch64/cpus.ll
+++ llvm/test/CodeGen/AArch64/cpus.ll
@@ -23,6 +23,7 @@
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=neoverse-n2 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=neoverse-512tvb 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=neoverse-v1 2>&1 | FileCheck %s
+; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=neoverse-v2 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=exynos-m3 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=exynos-m4 2>&1 | FileCheck %s
 ; RUN: llc < %s -mtriple=arm64-unknown-unknown -mcpu=exynos-m5 2>&1 | FileCheck %s
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -74,6 +74,7 @@
 NeoverseN2,
 Neoverse512TVB,
 NeoverseV1,
+NeoverseV2,
 Saphira,
 ThunderX2T99,
 ThunderX,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -199,6 +199,7 @@
 MaxBytesForLoopAlignment = 16;
 break;
   case NeoverseN2:
+  case NeoverseV2:
 PrefFunctionLogAlignment = 4;
 PrefLoopLogAlignment = 5;
 MaxBytesForLoopAlignment = 16;
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -936,6 +936,12 @@
   FeatureLSLFast,
   FeaturePostRAScheduler]>;
 
+def TuneNeoverseV2 : SubtargetFeature<"neoversev2", "ARMProcFamily", "NeoverseV2",
+  "Neoverse V2 ARM processors", [
+  FeatureFuseAES,
+  FeatureLSLFast,
+  FeaturePostRAScheduler]>;
+
 def TuneSaphira  : SubtargetFeature<"saphira", "ARMProcFamily", "Saphira",
"Qualcomm Saphira processors", [
FeatureCustomCheapAsMoveHandling,
@@ -1100,6 +1106,10 @@
FeatureFullFP16, FeatureMatMulInt8, FeatureNEON,
FeaturePerfMon, FeatureRandGen, FeatureSPE,
FeatureSSBS, FeatureSVE];
+  list NeoverseV2 = [HasV9_0aOps, FeatureBF16, FeatureSPE,
+   FeaturePerfMon, Fea

[clang] 677da09 - AArch64: add support for newer Apple CPUs

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

Author: Tim Northover
Date: 2022-09-22T11:58:51+01:00
New Revision: 677da09d0259d7530d32e85cb561bee15f0066e2

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

LOG: AArch64: add support for newer Apple CPUs

They're roughly ARMv8.6. This works in the .td file, but in
AArch64TargetParser.def, marking them v8.6 brings in support for the SM4
cryptographic hash and we don't actually have that. So TargetParser side
they're marked as v8.5, with the extra features (BF16 and I8MM added manually).

Finally, A16 supports the HCX extension in addition to v8.6. This has no
TargetParser implications.

Added: 


Modified: 
clang/test/Misc/target-invalid-cpu-note.c
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 08e54b9a74889..1f5899fa2649f 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, cortex-x1c, 
cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, apple-a12, 
apple-a13, apple-a14, apple-m1, apple-s4, apple-s5, exynos-m3, exynos-m4, 
exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, 
thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, cortex-x1c, 
cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, apple-a12, 
apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, apple-s4, 
apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, thunderx2t99, 
thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, 
carmel, ampere1{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-m1, apple-s4, apple-s5, exynos-m3, 
exynos-m4, exynos-m5, falkor, saphira, kryo, thunderx2t99, thunderx3t110, 
thunderx, thunderxt88, thunderxt81, thunderxt83, tsv110, a64fx, carmel, 
ampere1{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16,  apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1{{$}}
 
 // RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix X86
 // X86: error: unknown target CPU 'not-a-cpu'

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.def 
b/llvm/include/llvm/Support/AArch64TargetParser.def
index e2f949856d9f7..72286439e0f84 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.def
+++ b/llvm/include/llvm/Support/AArch64TargetParser

[PATCH] D134351: AArch64: add definitions for recent Apple CPUs

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

Thanks, committed as 677da09d0259 
.


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

https://reviews.llvm.org/D134351

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


[PATCH] D134352: [AArch64] Add Neoverse V2 CPU support

2022-09-22 Thread David Sherwood via Phabricator via cfe-commits
david-arm added a comment.

In D134352#3806896 , @tschuett wrote:

> `VScaleForTuning` is 1 for N2 and V2. It is 2 for V1. I though the V2 is more 
> like the V1 than the N2?
> Sorry. This is throughput right?

Hi @tschuett, Neoverse V2 will have 128-bit SVE vector lengths, hence 
VScaleForTuning should be 1.


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

https://reviews.llvm.org/D134352

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


[PATCH] D134425: Create a AllocLikeOpInterface and make memref::AllocLikeOp and gpu::AllocOp implement it.

2022-09-22 Thread Arnab Dutta via Phabricator via cfe-commits
arnab-oss created this revision.
Herald added subscribers: zero9178, bzcheeseman, ThomasRaoux, sdasgup3, 
wenzhicui, wrengr, cota, mravishankar, teijeong, rdzhabarov, tatianashp, 
msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, 
arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a reviewer: aartbik.
Herald added a reviewer: bondhugula.
Herald added a project: All.
arnab-oss requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache.
Herald added a reviewer: dcaballe.
Herald added projects: clang, MLIR.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134425

Files:
  clang/docs/tools/clang-formatted-files.txt
  mlir/include/mlir/Dialect/MemRef/IR/MemRef.h
  mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
  mlir/include/mlir/Interfaces/CMakeLists.txt
  mlir/lib/Dialect/Affine/Utils/Utils.cpp
  mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
  mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
  mlir/lib/Interfaces/CMakeLists.txt
  mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
  utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -922,6 +922,13 @@
 ],
 )
 
+td_library(
+name = "AllocLikeOpInterfaceTdFiles",
+srcs = ["include/mlir/Interfaces/AllocLikeOpInterface.td"],
+includes = ["include"],
+deps = [":OpBaseTdFiles"],
+)
+
 td_library(
 name = "CallInterfacesTdFiles",
 srcs = ["include/mlir/Interfaces/CallInterfaces.td"],
@@ -2726,6 +2733,17 @@
 ],
 )
 
+cc_library(
+name = "AllocLikeOpInterface",
+srcs = ["lib/Interfaces/AllocLikeOpInterface.cpp"],
+hdrs = ["include/mlir/Interfaces/AllocLikeOpInterface.h"],
+includes = ["include"],
+deps = [
+":AllocLikeOpInterfaceIncGen",
+":IR",
+],
+)
+
 cc_library(
 name = "DataLayoutInterfaces",
 srcs = ["lib/Interfaces/DataLayoutInterfaces.cpp"],
@@ -5301,6 +5319,24 @@
 deps = [":ViewLikeInterfaceTdFiles"],
 )
 
+gentbl_cc_library(
+name = "AllocLikeOpInterfaceIncGen",
+strip_include_prefix = "include",
+tbl_outs = [
+(
+["-gen-op-interface-decls"],
+"include/mlir/Interfaces/AllocLikeOpInterface.h.inc",
+),
+(
+["-gen-op-interface-defs"],
+"include/mlir/Interfaces/AllocLikeOpInterface.cpp.inc",
+),
+],
+tblgen = ":mlir-tblgen",
+td_file = "include/mlir/Interfaces/AllocLikeOpInterface.td",
+deps = [":AllocLikeOpInterfaceTdFiles"],
+)
+
 gentbl_cc_library(
 name = "CopyOpInterfaceIncGen",
 strip_include_prefix = "include",
@@ -8766,6 +8802,24 @@
 ],
 )
 
+gentbl_cc_library(
+name = "AllocLikeOpInterfaceIncGen",
+strip_include_prefix = "include",
+tbl_outs = [
+(
+["-gen-op-interface-decls"],
+"include/mlir/Interfaces/AllocLikeOpInterface.h.inc",
+),
+(
+["-gen-op-interface-defs"],
+"include/mlir/Interfaces/AllocLikeOpInterface.cpp.inc",
+),
+],
+tblgen = ":mlir-tblgen",
+td_file = "include/mlir/Interfaces/AllocLikeOpInterface.td",
+deps = [":AllocLikeOpInterfaceTdFiles"],
+)
+
 gentbl_cc_library(
 name = "MemRefBaseIncGen",
 strip_include_prefix = "include",
@@ -8823,6 +8877,7 @@
 ],
 includes = ["include"],
 deps = [
+":AllocLikeOpInterface",
 ":ArithmeticDialect",
 ":ArithmeticUtils",
 ":ControlFlowInterfaces",
Index: mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
===
--- mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
+++ mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
@@ -8,6 +8,7 @@
 
 #include 
 
+#include "mlir/Analysis/AffineAnalysis.h"
 #include "mlir/Analysis/SliceAnalysis.h"
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
Index: mlir/lib/Interfaces/CMakeLists.txt
===
--- mlir/lib/Interfaces/CMakeLists.txt
+++ mlir/lib/Interfaces/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_OPTIONAL_SOURCES
+  AllocLikeOpInterface.cpp
   CallInterfaces.cpp
   CastInterfaces.cpp
   ControlFlowInterfaces.cpp
@@ -31,6 +32,7 @@
 endfunction(add_mlir_interface_library)
 
 
+add_mlir_interface_library(AllocLikeOpInterface)
 add_mlir_interface_library(CallInterfaces)
 add_mlir_interface_library(CastInterfaces)
 add_mlir_interface_library(ControlFlowInterfaces)
Index: mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
===
--- mlir/lib/Dialect/Linalg/Transforms/Vec

[PATCH] D121599: [AST] Better recovery on an expression refers to an invalid decl.

2022-09-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 462131.
hokein marked 3 inline comments as done.
hokein added a comment.

rebase and address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121599

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaTemplate/constraints.cpp
  clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp

Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -28,7 +28,7 @@
   template constexpr T b = a; // expected-error {{invalid application of 'sizeof' to an incomplete type 'void'}}
 
   static_assert(b == 1, "");
-  static_assert(b == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}}
+  static_assert(b == 1, ""); // expected-note {{in instantiation of}}
 
   template void f() {
 static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
Index: clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
===
--- clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
+++ clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
@@ -26,28 +26,22 @@
 
 namespace constant_evaluated {
   template requires f struct S {};
-  // expected-note@-1{{in instantiation of}} expected-note@-1{{while substituting}} \
- expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}} \
- expected-note@-1{{subexpression not valid}}
+  // expected-note@-1{{in instantiation of}} expected-note@-1{{while substituting}}
   using s = S;
-  // expected-note@-1 2{{while checking}}
+  // expected-note@-1 {{while checking}}
   template void foo() requires f { };
   // expected-note@-1{{in instantiation}} expected-note@-1{{while substituting}} \
- expected-note@-1{{candidate template ignored}} expected-note@-1{{subexpression not valid}} \
- expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}}
+ expected-note@-1{{candidate template ignored}}
   int a = (foo(), 0);
-  // expected-note@-1 2{{while checking}} expected-error@-1{{no matching function}} \
- expected-note@-1 2{{in instantiation}}
+  // expected-note@-1 {{while checking}} expected-error@-1{{no matching function}} \
+ expected-note@-1 {{in instantiation}}
   template void bar() requires requires { requires f; } { };
-  // expected-note@-1{{in instantiation}} expected-note@-1{{subexpression not valid}} \
+  // expected-note@-1{{in instantiation}} \
  expected-note@-1{{while substituting}} \
- expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}} \
- expected-note@-1 2{{while checking the satisfaction of nested requirement}}
+ expected-note@-1 {{while checking the satisfaction of nested requirement}}
   int b = (bar(), 0);
   template struct M { static void foo() requires f { }; };
-  // expected-note@-1{{in instantiation}} expected-note@-1{{subexpression not valid}} \
- expected-note@-1{{while substituting}} \
- expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}}
+  // expected-note@-1{{in instantiation}} expected-note@-1{{while substituting}}
   int c = (M::foo(), 0);
-  // expected-note@-1 2{{while checking}}
+  // expected-note@-1 {{while checking}}
 }
Index: clang/test/SemaTemplate/constraints.cpp
===
--- clang/test/SemaTemplate/constraints.cpp
+++ clang/test/SemaTemplate/constraints.cpp
@@ -15,12 +15,11 @@
 
   template constexpr int test = 0;
   template requires C constexpr int test = 1;
-  template requires (B && C) || (X::value && C) constexpr int test = 2; // expected-error {{non-constant expression}} expected-note {{subexpression}} expected-note {{instantiation of}} expected-note {{while substituting}}
+  template requires (B && C) || (X::value && C) constexpr int test = 2; // expected-note {{instantiation of}} expected-note {{while substituting}}
   static_assert(test == 2);
   static_assert(test == 2);
   static_assert(test == 2); // satisfaction of second term of || not considered
   static_assert(test == 1);
   static_assert(test == 2); // constraints are partially ordered
-  // FIXME: These diagnostics are excessive.
-  static_assert(test == 1); // expected-note 2{{while}} expected-note 2{{during}}
+  static_assert(test == 1); // expected-note {{while}} expected-note {{during}}
 }
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
++

[PATCH] D121599: [AST] Better recovery on an expression refers to an invalid decl.

2022-09-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:1230
   LookupResult Result(*this, Name, NameLoc, LookupOrdinaryName);
   return BuildDeclarationNameExpr(SS, Result, /*ADL=*/true);
 }

sammccall wrote:
> wonder if if the results of setting AcceptInvalidDecl here would be good/bad?
> (happy with in this patch/separate one/not at all, just curious)
> 
> Also possible candidates are the calls in:
>  - Sema::ActOnIdExpression
>  - Sema::BuildQualifiedDeclarationNameExpr
>  - Sema::BuildPossibleImplicitMemberExpr
>  - BuildRecoveryCallExpr in SemaOverload
> 
yeah, this is interesting. we need to try it and see how well it goes. I will 
follow-up after this patch.



Comment at: clang/lib/Sema/SemaExpr.cpp:3478
+  if (VD->isInvalidDecl() && E)
+return CreateRecoveryExpr(E->getBeginLoc(), E->getEndLoc(), {E});
+  return E;

sammccall wrote:
> This means we're changing the AST returned for existing 
> `AcceptInvalidDecl=true` callers, right?
> 
> I think this is just attemptRecovery() in SemaCXX.cpp, which is part of typo 
> correction. Previously we might transforming typos into DeclRefExpr to 
> invalid, but now we're transforming them to RecoveryExpr wrapping DeclExpr to 
> invalid.
> 
> This seems sensible, but I'm a little concerned there are no test changes for 
> it. Is it possible to construct one?
> 
> I kind of expected this to work:
> ```
> m *foo;
> void z() {
>   goo;
> }
> ```
> but in fact we produce an opaque RecoveryExpr (with no DeclRefExpr) inside 
> today.
you're right. Added one testcase for the typo correction case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121599

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


[PATCH] D134425: Create a AllocLikeOpInterface and make memref::AllocLikeOp and gpu::AllocOp implement it.

2022-09-22 Thread Arnab Dutta via Phabricator via cfe-commits
arnab-oss updated this revision to Diff 462132.
arnab-oss added a comment.
Herald added a subscriber: csigg.
Herald added a reviewer: herhut.
Herald added a reviewer: ThomasRaoux.

Make gpu.alloc op implement AllocLikeOpInterface


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134425

Files:
  clang/docs/tools/clang-formatted-files.txt
  mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h
  mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
  mlir/include/mlir/Dialect/MemRef/IR/MemRef.h
  mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
  mlir/include/mlir/Interfaces/CMakeLists.txt
  mlir/lib/Dialect/Affine/Utils/Utils.cpp
  mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
  mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
  mlir/lib/Interfaces/CMakeLists.txt
  mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
  utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -922,6 +922,13 @@
 ],
 )
 
+td_library(
+name = "AllocLikeOpInterfaceTdFiles",
+srcs = ["include/mlir/Interfaces/AllocLikeOpInterface.td"],
+includes = ["include"],
+deps = [":OpBaseTdFiles"],
+)
+
 td_library(
 name = "CallInterfacesTdFiles",
 srcs = ["include/mlir/Interfaces/CallInterfaces.td"],
@@ -2726,6 +2733,17 @@
 ],
 )
 
+cc_library(
+name = "AllocLikeOpInterface",
+srcs = ["lib/Interfaces/AllocLikeOpInterface.cpp"],
+hdrs = ["include/mlir/Interfaces/AllocLikeOpInterface.h"],
+includes = ["include"],
+deps = [
+":AllocLikeOpInterfaceIncGen",
+":IR",
+],
+)
+
 cc_library(
 name = "DataLayoutInterfaces",
 srcs = ["lib/Interfaces/DataLayoutInterfaces.cpp"],
@@ -5301,6 +5319,24 @@
 deps = [":ViewLikeInterfaceTdFiles"],
 )
 
+gentbl_cc_library(
+name = "AllocLikeOpInterfaceIncGen",
+strip_include_prefix = "include",
+tbl_outs = [
+(
+["-gen-op-interface-decls"],
+"include/mlir/Interfaces/AllocLikeOpInterface.h.inc",
+),
+(
+["-gen-op-interface-defs"],
+"include/mlir/Interfaces/AllocLikeOpInterface.cpp.inc",
+),
+],
+tblgen = ":mlir-tblgen",
+td_file = "include/mlir/Interfaces/AllocLikeOpInterface.td",
+deps = [":AllocLikeOpInterfaceTdFiles"],
+)
+
 gentbl_cc_library(
 name = "CopyOpInterfaceIncGen",
 strip_include_prefix = "include",
@@ -8766,6 +8802,24 @@
 ],
 )
 
+gentbl_cc_library(
+name = "AllocLikeOpInterfaceIncGen",
+strip_include_prefix = "include",
+tbl_outs = [
+(
+["-gen-op-interface-decls"],
+"include/mlir/Interfaces/AllocLikeOpInterface.h.inc",
+),
+(
+["-gen-op-interface-defs"],
+"include/mlir/Interfaces/AllocLikeOpInterface.cpp.inc",
+),
+],
+tblgen = ":mlir-tblgen",
+td_file = "include/mlir/Interfaces/AllocLikeOpInterface.td",
+deps = [":AllocLikeOpInterfaceTdFiles"],
+)
+
 gentbl_cc_library(
 name = "MemRefBaseIncGen",
 strip_include_prefix = "include",
@@ -8823,6 +8877,7 @@
 ],
 includes = ["include"],
 deps = [
+":AllocLikeOpInterface",
 ":ArithmeticDialect",
 ":ArithmeticUtils",
 ":ControlFlowInterfaces",
Index: mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
===
--- mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
+++ mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
@@ -8,6 +8,7 @@
 
 #include 
 
+#include "mlir/Analysis/AffineAnalysis.h"
 #include "mlir/Analysis/SliceAnalysis.h"
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
Index: mlir/lib/Interfaces/CMakeLists.txt
===
--- mlir/lib/Interfaces/CMakeLists.txt
+++ mlir/lib/Interfaces/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_OPTIONAL_SOURCES
+  AllocLikeOpInterface.cpp
   CallInterfaces.cpp
   CastInterfaces.cpp
   ControlFlowInterfaces.cpp
@@ -31,6 +32,7 @@
 endfunction(add_mlir_interface_library)
 
 
+add_mlir_interface_library(AllocLikeOpInterface)
 add_mlir_interface_library(CallInterfaces)
 add_mlir_interface_library(CastInterfaces)
 add_mlir_interface_library(ControlFlowInterfaces)
Index: mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
===
--- mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
+++ mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
@@ -1157,9 +1157,12 @@
 return failure();
 
   // Transfer into `view`.
-  Value viewOrAlloc = xferOp.getSource();
-  if (!viewOrAlloc.getDefiningOp() &&
-  !viewOrAlloc.getDefiningO

[PATCH] D115169: Create a generic ABI document for _BitInt

2022-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D115169#3805964 , @gustedt wrote:

> It seems that this has already shipped on some platforms. Since this 
> basically binds others to use the same ABI, it would perhaps be nice if the 
> document could have a table that lists `MaxFundamentalWidth` and `chunk_t` 
> for those platforms.

Sure, that seems reasonable.

> Also discussing consequences for `va_arg` functions such as `printf` would be 
> nice.

Does the information in the `Passing and Returning an Object` section suffice, 
or are there more details you're looking for there?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115169

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


[PATCH] D115169: Create a generic ABI document for _BitInt

2022-09-22 Thread Jens Gustedt via Phabricator via cfe-commits
gustedt added a comment.

>> Also discussing consequences for `va_arg` functions such as `printf` would 
>> be nice.
>
> Does the information in the `Passing and Returning an Object` section 
> suffice, or are there more details you're looking for there?

Ah, sorry must have overlooked this.
Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115169

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


[PATCH] D134425: Create a AllocLikeOpInterface and make memref::AllocLikeOp and gpu::AllocOp implement it.

2022-09-22 Thread Arnab Dutta via Phabricator via cfe-commits
arnab-oss updated this revision to Diff 462137.
arnab-oss added a comment.

Refactoring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134425

Files:
  clang/docs/tools/clang-formatted-files.txt
  mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h
  mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
  mlir/include/mlir/Dialect/MemRef/IR/MemRef.h
  mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
  mlir/include/mlir/Interfaces/AllocLikeOpInterface.h
  mlir/include/mlir/Interfaces/AllocLikeOpInterface.td
  mlir/include/mlir/Interfaces/CMakeLists.txt
  mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
  mlir/lib/Dialect/Affine/Utils/Utils.cpp
  mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocation.cpp
  mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
  mlir/lib/Dialect/MemRef/Transforms/NormalizeMemRefs.cpp
  mlir/lib/Interfaces/AllocLikeOpInterface.cpp
  mlir/lib/Interfaces/CMakeLists.txt
  mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
  utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -922,6 +922,13 @@
 ],
 )
 
+td_library(
+name = "AllocLikeOpInterfaceTdFiles",
+srcs = ["include/mlir/Interfaces/AllocLikeOpInterface.td"],
+includes = ["include"],
+deps = [":OpBaseTdFiles"],
+)
+
 td_library(
 name = "CallInterfacesTdFiles",
 srcs = ["include/mlir/Interfaces/CallInterfaces.td"],
@@ -2726,6 +2733,17 @@
 ],
 )
 
+cc_library(
+name = "AllocLikeOpInterface",
+srcs = ["lib/Interfaces/AllocLikeOpInterface.cpp"],
+hdrs = ["include/mlir/Interfaces/AllocLikeOpInterface.h"],
+includes = ["include"],
+deps = [
+":AllocLikeOpInterfaceIncGen",
+":IR",
+],
+)
+
 cc_library(
 name = "DataLayoutInterfaces",
 srcs = ["lib/Interfaces/DataLayoutInterfaces.cpp"],
@@ -5301,6 +5319,24 @@
 deps = [":ViewLikeInterfaceTdFiles"],
 )
 
+gentbl_cc_library(
+name = "AllocLikeOpInterfaceIncGen",
+strip_include_prefix = "include",
+tbl_outs = [
+(
+["-gen-op-interface-decls"],
+"include/mlir/Interfaces/AllocLikeOpInterface.h.inc",
+),
+(
+["-gen-op-interface-defs"],
+"include/mlir/Interfaces/AllocLikeOpInterface.cpp.inc",
+),
+],
+tblgen = ":mlir-tblgen",
+td_file = "include/mlir/Interfaces/AllocLikeOpInterface.td",
+deps = [":AllocLikeOpInterfaceTdFiles"],
+)
+
 gentbl_cc_library(
 name = "CopyOpInterfaceIncGen",
 strip_include_prefix = "include",
@@ -8766,6 +8802,24 @@
 ],
 )
 
+gentbl_cc_library(
+name = "AllocLikeOpInterfaceIncGen",
+strip_include_prefix = "include",
+tbl_outs = [
+(
+["-gen-op-interface-decls"],
+"include/mlir/Interfaces/AllocLikeOpInterface.h.inc",
+),
+(
+["-gen-op-interface-defs"],
+"include/mlir/Interfaces/AllocLikeOpInterface.cpp.inc",
+),
+],
+tblgen = ":mlir-tblgen",
+td_file = "include/mlir/Interfaces/AllocLikeOpInterface.td",
+deps = [":AllocLikeOpInterfaceTdFiles"],
+)
+
 gentbl_cc_library(
 name = "MemRefBaseIncGen",
 strip_include_prefix = "include",
@@ -8823,6 +8877,7 @@
 ],
 includes = ["include"],
 deps = [
+":AllocLikeOpInterface",
 ":ArithmeticDialect",
 ":ArithmeticUtils",
 ":ControlFlowInterfaces",
Index: mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
===
--- mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
+++ mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp
@@ -8,6 +8,7 @@
 
 #include 
 
+#include "mlir/Analysis/AffineAnalysis.h"
 #include "mlir/Analysis/SliceAnalysis.h"
 #include "mlir/Dialect/Affine/IR/AffineOps.h"
 #include "mlir/Dialect/Func/IR/FuncOps.h"
Index: mlir/lib/Interfaces/CMakeLists.txt
===
--- mlir/lib/Interfaces/CMakeLists.txt
+++ mlir/lib/Interfaces/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_OPTIONAL_SOURCES
+  AllocLikeOpInterface.cpp
   CallInterfaces.cpp
   CastInterfaces.cpp
   ControlFlowInterfaces.cpp
@@ -31,6 +32,7 @@
 endfunction(add_mlir_interface_library)
 
 
+add_mlir_interface_library(AllocLikeOpInterface)
 add_mlir_interface_library(CallInterfaces)
 add_mlir_interface_library(CastInterfaces)
 add_mlir_interface_library(ControlFlowInterfaces)
Index: mlir/lib/Interfaces/AllocLikeOpInterface.cpp
===
--- /dev/null
+++ mlir/lib/Interfaces/AllocLikeOpInterface.cpp
@@ -0,0 +1,14 @@
+//===- AllocLikeOpInterface.cpp - Alloc like operations interface in MLIR-===//
+//
+// Part of the LLVM Pr

[PATCH] D130131: [HLSL] CodeGen hlsl cbuffer/tbuffer.

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



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:81-83
+auto *GV = Const.first;
+Const.second = EltTys.size();
+auto *Ty = GV->getValueType();

Please spell out these types.



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:101-102
+  for (auto &Const : Buf.Constants) {
+auto *EltTy = Buf.LayoutStruct->getElementType(Const.second);
+auto *GV = Const.first;
+unsigned Offset = Const.second;

Please spell out these types.



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:108
+
+auto *GVTy = GV->getValueType();
+assert(EltTy == GVTy && "constant type mismatch");

Same here



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:151
+  for (Decl *it : DC->decls()) {
+if (VarDecl *ConstDecl = dyn_cast(it)) {
+  addConstant(ConstDecl, CB);





Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:153-156
+} else if (isa(*it)) {
+  // Nothing to do for this declaration.
+} else if (isa(it)) {
+  // Nothing to do for this declaration.





Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:181
+
+  auto &DL = M.getDataLayout();
+

Please spell out the type.



Comment at: clang/lib/CodeGen/CGHLSLRuntime.h:51
+  struct Buffer {
+Buffer(HLSLBufferDecl *D);
+llvm::StringRef Name;





Comment at: clang/lib/CodeGen/CGHLSLRuntime.h:76
 
+  void addBuffer(HLSLBufferDecl *D);
   void finishCodeGen();




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130131

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


[PATCH] D134157: [LoongArch] Add inline asm support for constraints f/l/I/K

2022-09-22 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 462139.
SixWeining added a comment.

Use double dashes for --mtriple.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134157

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/test/CodeGen/LoongArch/inline-asm-constraints-error.c
  clang/test/CodeGen/LoongArch/inline-asm-constraints.c
  clang/test/CodeGen/LoongArch/inline-asm-gcc-regs-error.c
  clang/test/CodeGen/LoongArch/inline-asm-gcc-regs.c
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/test/CodeGen/LoongArch/inline-asm-clobbers.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-error.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint-f.ll
  llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
  llvm/test/CodeGen/LoongArch/inline-asm-reg-names-error.ll
  llvm/test/CodeGen/LoongArch/inline-asm-reg-names-f-error.ll
  llvm/test/CodeGen/LoongArch/inline-asm-reg-names-f.ll
  llvm/test/CodeGen/LoongArch/inline-asm-reg-names.ll

Index: llvm/test/CodeGen/LoongArch/inline-asm-reg-names.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/inline-asm-reg-names.ll
@@ -0,0 +1,109 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --verify-machineinstrs < %s \
+; RUN:   | FileCheck --check-prefix=LA32 %s
+; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s \
+; RUN:   | FileCheck --check-prefix=LA64 %s
+
+;; These test that we can use architectural names ($r*) refer to registers in
+;; inline asm constraint lists. In each case, the named register should be used
+;; for the source register of the `addi.w`. It is very likely that `$a0` will
+;; be chosen as the designation register, but this is left to the compiler to
+;; choose.
+;;
+;; Parenthesised registers in comments are the other aliases for this register.
+
+;; NOTE: This test has to pass in 0 to the inline asm, because that's the only
+;; value `$r0` (`$zero`) can take.
+define i32 @register_r0() nounwind {
+; LA32-LABEL: register_r0:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:addi.w $a0, $zero, 0
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: register_r0:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:addi.w $a0, $zero, 0
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = tail call i32 asm "addi.w $0, $1, 0", "=r,{$r0}"(i32 0)
+  ret i32 %1
+}
+
+define i32 @register_r4(i32 %a) nounwind {
+; LA32-LABEL: register_r4:
+; LA32:   # %bb.0:
+; LA32-NEXT:#APP
+; LA32-NEXT:addi.w $a0, $a0, 1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ret
+;
+; LA64-LABEL: register_r4:
+; LA64:   # %bb.0:
+; LA64-NEXT:#APP
+; LA64-NEXT:addi.w $a0, $a0, 1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ret
+  %1 = tail call i32 asm "addi.w $0, $1, 1", "=r,{$r4}"(i32 %a)
+  ret i32 %1
+}
+
+;; NOTE: This test uses `$r22` (`$s9`, `$fp`) as an input, so it should be saved.
+define i32 @register_r22(i32 %a) nounwind {
+; LA32-LABEL: register_r22:
+; LA32:   # %bb.0:
+; LA32-NEXT:addi.w $sp, $sp, -16
+; LA32-NEXT:st.w $fp, $sp, 12 # 4-byte Folded Spill
+; LA32-NEXT:move $fp, $a0
+; LA32-NEXT:#APP
+; LA32-NEXT:addi.w $a0, $fp, 1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ld.w $fp, $sp, 12 # 4-byte Folded Reload
+; LA32-NEXT:addi.w $sp, $sp, 16
+; LA32-NEXT:ret
+;
+; LA64-LABEL: register_r22:
+; LA64:   # %bb.0:
+; LA64-NEXT:addi.d $sp, $sp, -16
+; LA64-NEXT:st.d $fp, $sp, 8 # 8-byte Folded Spill
+; LA64-NEXT:move $fp, $a0
+; LA64-NEXT:#APP
+; LA64-NEXT:addi.w $a0, $fp, 1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ld.d $fp, $sp, 8 # 8-byte Folded Reload
+; LA64-NEXT:addi.d $sp, $sp, 16
+; LA64-NEXT:ret
+  %1 = tail call i32 asm "addi.w $0, $1, 1", "=r,{$r22}"(i32 %a)
+  ret i32 %1
+}
+
+;; NOTE: This test uses `$r31` (`$s8`) as an input, so it should be saved.
+define i32 @register_r31(i32 %a) nounwind {
+; LA32-LABEL: register_r31:
+; LA32:   # %bb.0:
+; LA32-NEXT:addi.w $sp, $sp, -16
+; LA32-NEXT:st.w $s8, $sp, 12 # 4-byte Folded Spill
+; LA32-NEXT:move $s8, $a0
+; LA32-NEXT:#APP
+; LA32-NEXT:addi.w $a0, $s8, 1
+; LA32-NEXT:#NO_APP
+; LA32-NEXT:ld.w $s8, $sp, 12 # 4-byte Folded Reload
+; LA32-NEXT:addi.w $sp, $sp, 16
+; LA32-NEXT:ret
+;
+; LA64-LABEL: register_r31:
+; LA64:   # %bb.0:
+; LA64-NEXT:addi.d $sp, $sp, -16
+; LA64-NEXT:st.d $s8, $sp, 8 # 8-byte Folded Spill
+; LA64-NEXT:move $s8, $a0
+; LA64-NEXT:#APP
+; LA64-NEXT:addi.w $a0, $s8, 1
+; LA64-NEXT:#NO_APP
+; LA64-NEXT:ld.d $s8, $sp, 8 # 8-byte Folded Reload
+; LA64-NEXT:addi.d $sp, $sp, 16
+; LA64-NEXT:ret
+  %1 = tail call i32 as

[PATCH] D133108: [clang] Rework IsTailPaddedMemberArray into isFlexibleArrayMemberExpr

2022-09-22 Thread serge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdad36245a5c2: [clang] Rework IsTailPaddedMemberArray into 
isFlexibleArrayMemberExpr (authored by serge-sans-paille).

Changed prior to commit:
  https://reviews.llvm.org/D133108?vs=460899&id=462140#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133108

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/unbounded-array-bounds.c

Index: clang/test/Sema/unbounded-array-bounds.c
===
--- clang/test/Sema/unbounded-array-bounds.c
+++ clang/test/Sema/unbounded-array-bounds.c
@@ -84,3 +84,33 @@
 void func() {
   func + 0xdeadUL; // no crash
 }
+
+struct {
+  int _;
+  char tail[];  // addr16-note {{declared here}} addr32-note {{declared here}}
+} fam;
+
+struct {
+  int _;
+  char tail[0];  // addr16-note {{declared here}} addr32-note {{declared here}}
+} fam0;
+
+struct {
+  int _;
+  char tail[1];  // addr16-note {{declared here}} addr32-note {{declared here}}
+} fam1;
+
+void fam_ily() {
+  ++fam.tail[7073650413200313099];
+  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4294967296 elements)}}
+  // No warning for addr64 because the array index is inbound in that case.
+  ++fam0.tail[7073650413200313099];
+  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4294967296 elements)}}
+  // No warning for addr64 because the array index is inbound in that case.
+  ++fam1.tail[7073650413200313099];
+  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4294967296 elements)}}
+  // No warning for addr64 because the array index is inbound in that case.
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15898,17 +15898,24 @@
 << TRange << Op->getSourceRange();
 }
 
-/// Check whether this array fits the idiom of a size-one tail padded
-/// array member of a struct.
+/// Check whether this array fits the idiom of a flexible array member,
+/// depending on the value of -fstrict-flex-array.
 ///
-/// We avoid emitting out-of-bounds access warnings for such arrays as they are
-/// commonly used to emulate flexible arrays in C89 code.
-static bool IsTailPaddedMemberArray(Sema &S, const llvm::APInt &Size,
-const NamedDecl *ND,
-unsigned StrictFlexArraysLevel) {
+/// We avoid emitting out-of-bounds access warnings for such arrays.
+static bool isFlexibleArrayMemberExpr(Sema &S, const Expr *E,
+  const NamedDecl *ND,
+  unsigned StrictFlexArraysLevel) {
+
   if (!ND)
 return false;
 
+  const ConstantArrayType *ArrayTy =
+  S.Context.getAsConstantArrayType(E->getType());
+  llvm::APInt Size = ArrayTy->getSize();
+
+  if (Size == 0)
+return true;
+
   // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
   // arrays to be treated as flexible-array-members, we still emit diagnostics
   // as if they are not. Pending further discussion...
@@ -15974,9 +15981,19 @@
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 
+  unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+
+  const NamedDecl *ND = nullptr;
+  if (const auto *DRE = dyn_cast(BaseExpr))
+ND = DRE->getDecl();
+  else if (const auto *ME = dyn_cast(BaseExpr))
+ND = ME->getMemberDecl();
+
   const Type *BaseType =
   ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
-  bool IsUnboundedArray = (BaseType == nullptr);
+  bool IsUnboundedArray =
+  BaseType == nullptr ||
+  isFlexibleArrayMemberExpr(*this, BaseExpr, ND, StrictFlexArraysLevel);
   if (EffectiveType->isDependentType() ||
   (!IsUnboundedA

[clang] dad3624 - [clang] Rework IsTailPaddedMemberArray into isFlexibleArrayMemberExpr

2022-09-22 Thread via cfe-commits

Author: serge-sans-paille
Date: 2022-09-22T14:04:35+02:00
New Revision: dad36245a5c2e3779b4eede6fcbbddad19a2f01d

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

LOG: [clang] Rework IsTailPaddedMemberArray into isFlexibleArrayMemberExpr

This fixes a bunch of FIXME within IsTailPaddedMemberArray related code.

As a side effect, this now also triggers a warning when trying to access a
"struct hack" member with an index above address space index range.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/unbounded-array-bounds.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5d517eb676bec..d2b3e7d944c95 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -208,6 +208,8 @@ Improvements to Clang's diagnostics
   underlying type is ``long long`` or ``unsigned long long`` as an extension in
   C89 mode . Clang previously only diagnosed if the literal had an explicit
   ``LL`` suffix.
+- Clang now correctly diagnoses index that refers past the last possible 
element
+  of FAM-like arrays.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1b74b091dd270..90eca753f3059 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -15898,17 +15898,24 @@ void Sema::CheckCastAlign(Expr *Op, QualType T, 
SourceRange TRange) {
 << TRange << Op->getSourceRange();
 }
 
-/// Check whether this array fits the idiom of a size-one tail padded
-/// array member of a struct.
+/// Check whether this array fits the idiom of a flexible array member,
+/// depending on the value of -fstrict-flex-array.
 ///
-/// We avoid emitting out-of-bounds access warnings for such arrays as they are
-/// commonly used to emulate flexible arrays in C89 code.
-static bool IsTailPaddedMemberArray(Sema &S, const llvm::APInt &Size,
-const NamedDecl *ND,
-unsigned StrictFlexArraysLevel) {
+/// We avoid emitting out-of-bounds access warnings for such arrays.
+static bool isFlexibleArrayMemberExpr(Sema &S, const Expr *E,
+  const NamedDecl *ND,
+  unsigned StrictFlexArraysLevel) {
+
   if (!ND)
 return false;
 
+  const ConstantArrayType *ArrayTy =
+  S.Context.getAsConstantArrayType(E->getType());
+  llvm::APInt Size = ArrayTy->getSize();
+
+  if (Size == 0)
+return true;
+
   // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
   // arrays to be treated as flexible-array-members, we still emit diagnostics
   // as if they are not. Pending further discussion...
@@ -15974,9 +15981,19 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 
+  unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+
+  const NamedDecl *ND = nullptr;
+  if (const auto *DRE = dyn_cast(BaseExpr))
+ND = DRE->getDecl();
+  else if (const auto *ME = dyn_cast(BaseExpr))
+ND = ME->getMemberDecl();
+
   const Type *BaseType =
   ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
-  bool IsUnboundedArray = (BaseType == nullptr);
+  bool IsUnboundedArray =
+  BaseType == nullptr ||
+  isFlexibleArrayMemberExpr(*this, BaseExpr, ND, StrictFlexArraysLevel);
   if (EffectiveType->isDependentType() ||
   (!IsUnboundedArray && BaseType->isDependentType()))
 return;
@@ -15991,12 +16008,6 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,
 index = -index;
   }
 
-  const NamedDecl *ND = nullptr;
-  if (const DeclRefExpr *DRE = dyn_cast(BaseExpr))
-ND = DRE->getDecl();
-  if (const MemberExpr *ME = dyn_cast(BaseExpr))
-ND = ME->getMemberDecl();
-
   if (IsUnboundedArray) {
 if (EffectiveType->isFunctionType())
   return;
@@ -16074,17 +16085,10 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,
 // example). In this case we have no information about whether the array
 // access exceeds the array bounds. However we can still diagnose an array
 // access which precedes the array bounds.
-//
-// FIXME: this check should be redundant with the IsUnboundedArray check
-// above.
 if (BaseType->isIncompleteType())
   return;
 
-// FIXME: this check should be used to set IsUnboundedArray from the
-// beginning.
 llvm::APInt size = ArrayTy->getSize();
-if (!size

[PATCH] D134157: [LoongArch] Add inline asm support for constraints f/l/I/K

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

In D134157#3805855 , @xen0n wrote:

> I don't know if the clang changes should be split into its own commit (or the 
> title of this commit amended to mention `[Clang]` but I don't know if this is 
> appropriate), but the rest looks reasonable.

Yes, I ever thought about spliting the patches into 2 (clang+llvm). But I 
finally decide to use a single one becuse I think this may help others a bit to 
understand how these inline asm(constrainsts, ...) are used and translated from 
frontend to backend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134157

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


[PATCH] D133983: [HLSL] Add SV_DispatchThreadID

2022-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D133983#3807284 , @python3kgae 
wrote:

> In D133983#3805761 , @aaron.ballman 
> wrote:
>
>> There are no tests for applying this to a global variable, so those should 
>> be added.
>
> The global variable in the Subjects is wrong.
> It should be Field.

I wondered if that was the case, thanks for the fix. :-)

> Support for semantic on field is a bigger change.
> Created https://github.com/llvm/llvm-project/issues/57889 to track it.

Thanks!

You should add additional test coverage: applying the attribute to a static 
data member, to a non-static data member, to a variable, to an unnamed 
parameter, and to a lambda parameter. The tests should demonstrate that we give 
good diagnostics where appropriate, instead of crashing, asserting, or silently 
accepting.




Comment at: clang/include/clang/Basic/AttrDocs.td:6596-6598
+The ``SV_DispatchThreadID`` semantic, when applied to an input parameter, 
specifies a
+data binding to map global thread offset within the Dispatch call(per 
dimension of the group) to the specified parameter.
+When applied to a field of a struct, the data binding is specified to the 
field when the struct is used as a parameter type.

You should also wrap the docs to the usual 80-col limit.

Can you apply the attribute to a static data member in a struct, or only fields?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11656
+def err_hlsl_attr_invalid_type : Error<
+   "Attribute %0 only applies to fields/parameters that have type %1">;
 def err_hlsl_numthreads_argument_oor : Error<"argument '%select{X|Y|Z}0' to 
numthreads attribute cannot exceed %1">;





Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6916
+return false;
+  if (auto *VT = T->getAs())
+return VT->getNumElements() <= 3;





Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6940
+
+  auto *VD = cast(D);
+  if (!isLegalTypeForHLSLSV_DispatchThreadID(VD->getType())) {

This will cause an assert when the attribute appears on a field -- you need to 
check for a field decl above and give a diagnostic about it not being supported 
yet.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6943
+S.Diag(AL.getLoc(), diag::err_hlsl_attr_invalid_type)
+<< "SV_DispatchThreadID"
+<< "uint/uint2/uint3";





Comment at: clang/test/SemaHLSL/Semantics/entry_parameter.hlsl:4
 
 [numthreads(8,8, 1)]
+// expected-error@+2 {{attribute 'SV_GroupIndex' is unsupported in Mesh 
shaders, requires Compute}}





Comment at: clang/test/SemaHLSL/Semantics/invalid_entry_parameter.hlsl:3-13
+[numthreads(8,8, 1)]
+// expected-error@+1 {{Attribute SV_DispatchThreadID only applies to 
fields/parameters that have type uint/uint2/uint3}}
+void CSMain(float ID : SV_DispatchThreadID) {
+
+}
+
+struct ST {





Comment at: clang/test/SemaHLSL/Semantics/valid_entry_parameter.hlsl:3-16
+[numthreads(8,8, 1)]
+void CSMain(uint ID : SV_DispatchThreadID) {
+// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain 
'void (uint)'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:18 ID 'uint'
+// CHECK-NEXT: HLSLSV_DispatchThreadIDAttr
+}
+[numthreads(8,8, 1)]




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133983

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


[clang] e0cdafe - [AST] Better recovery on an expression refers to an invalid decl.

2022-09-22 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-09-22T14:23:47+02:00
New Revision: e0cdafe8d4b2f1585f4756447b677fec37954ec4

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

LOG: [AST] Better recovery on an expression refers to an invalid decl.

Prior to the patch, we didn't build a DeclRefExpr if the Decl being
referred to is invalid, because many clang downstream AST consumers
assume it, violating it will cause many diagnostic regressions.

With this patch, we build a DeclRefExpr enven for an invalid decl (when the
AcceptInvalidDecl is true), and wrap it with a dependent-type
RecoveryExpr (to prevent follow-up semantic analysis, and diagnostic
regressions).

This is a revised version of https://reviews.llvm.org/D76831

Reviewed By: sammccall

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/SemaTemplate/constraints.cpp
clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
clang/test/SemaTemplate/instantiate-var-template.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a916db238389f..85b2bca535809 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1275,7 +1275,7 @@ ExprResult Sema::ActOnNameClassifiedAsNonType(Scope *S, 
const CXXScopeSpec &SS,
   Result.resolveKind();
 
   bool ADL = UseArgumentDependentLookup(SS, Result, 
NextToken.is(tok::l_paren));
-  return BuildDeclarationNameExpr(SS, Result, ADL);
+  return BuildDeclarationNameExpr(SS, Result, ADL, /*AcceptInvalidDecl=*/true);
 }
 
 ExprResult Sema::ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *E) {

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b49b7ce45cf4a..7f70cf331c7f9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3183,8 +3183,9 @@ bool Sema::UseArgumentDependentLookup(const CXXScopeSpec 
&SS,
 /// as an expression.  This is only actually called for lookups that
 /// were not overloaded, and it doesn't promise that the declaration
 /// will in fact be used.
-static bool CheckDeclInExpr(Sema &S, SourceLocation Loc, NamedDecl *D) {
-  if (D->isInvalidDecl())
+static bool CheckDeclInExpr(Sema &S, SourceLocation Loc, NamedDecl *D,
+bool AcceptInvalid) {
+  if (D->isInvalidDecl() && !AcceptInvalid)
 return true;
 
   if (isa(D)) {
@@ -3230,7 +3231,8 @@ ExprResult Sema::BuildDeclarationNameExpr(const 
CXXScopeSpec &SS,
   // result, because in the overloaded case the results can only be
   // functions and function templates.
   if (R.isSingleResult() && !ShouldLookupResultBeMultiVersionOverload(R) &&
-  CheckDeclInExpr(*this, R.getNameLoc(), R.getFoundDecl()))
+  CheckDeclInExpr(*this, R.getNameLoc(), R.getFoundDecl(),
+  AcceptInvalidDecl))
 return ExprError();
 
   // Otherwise, just build an unresolved lookup expression.  Suppress
@@ -3262,7 +3264,7 @@ ExprResult Sema::BuildDeclarationNameExpr(
  "Cannot refer unambiguously to a function template");
 
   SourceLocation Loc = NameInfo.getLoc();
-  if (CheckDeclInExpr(*this, Loc, D)) {
+  if (CheckDeclInExpr(*this, Loc, D, AcceptInvalidDecl)) {
 // Recovery from invalid cases (e.g. D is an invalid Decl).
 // We use the dependent type for the RecoveryExpr to prevent bogus 
follow-up
 // diagnostics, as invalid decls use int as a fallback type.
@@ -3494,9 +3496,16 @@ ExprResult Sema::BuildDeclarationNameExpr(
 break;
   }
 
-  return BuildDeclRefExpr(VD, type, valueKind, NameInfo, &SS, FoundD,
-  /*FIXME: TemplateKWLoc*/ SourceLocation(),
-  TemplateArgs);
+  auto *E =
+  BuildDeclRefExpr(VD, type, valueKind, NameInfo, &SS, FoundD,
+   /*FIXME: TemplateKWLoc*/ SourceLocation(), 
TemplateArgs);
+  // Clang AST consumers assume a DeclRefExpr refers to a valid decl. We
+  // wrap a DeclRefExpr referring to an invalid decl with a dependent-type
+  // RecoveryExpr to avoid follow-up semantic analysis (thus prevent bogus
+  // diagnostics).
+  if (VD->isInvalidDecl() && E)
+return CreateRecoveryExpr(E->getBeginLoc(), E->getEndLoc(), {E});
+  return E;
 }
 
 static void ConvertUTF8ToWideString(unsigned CharByteWidth, StringRef Source,

diff  --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index 53043027ddb8c..cc4f8afbfc444 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -406,8 +406,17 @@ void RecoveryExprForInvalidDecls(Unknown InvalidDecl) {
   InvalidDecl + 1;
   // CHECK:  BinaryOperator {{.*}}
   // CHECK-NEXT: |-RecoveryExpr {{.*}} ''
+  // CHECK-NEXT: |

[PATCH] D121599: [AST] Better recovery on an expression refers to an invalid decl.

2022-09-22 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe0cdafe8d4b2: [AST] Better recovery on an expression refers 
to an invalid decl. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121599

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaTemplate/constraints.cpp
  clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp

Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -28,7 +28,7 @@
   template constexpr T b = a; // expected-error {{invalid application of 'sizeof' to an incomplete type 'void'}}
 
   static_assert(b == 1, "");
-  static_assert(b == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}}
+  static_assert(b == 1, ""); // expected-note {{in instantiation of}}
 
   template void f() {
 static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
Index: clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
===
--- clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
+++ clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp
@@ -26,28 +26,22 @@
 
 namespace constant_evaluated {
   template requires f struct S {};
-  // expected-note@-1{{in instantiation of}} expected-note@-1{{while substituting}} \
- expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}} \
- expected-note@-1{{subexpression not valid}}
+  // expected-note@-1{{in instantiation of}} expected-note@-1{{while substituting}}
   using s = S;
-  // expected-note@-1 2{{while checking}}
+  // expected-note@-1 {{while checking}}
   template void foo() requires f { };
   // expected-note@-1{{in instantiation}} expected-note@-1{{while substituting}} \
- expected-note@-1{{candidate template ignored}} expected-note@-1{{subexpression not valid}} \
- expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}}
+ expected-note@-1{{candidate template ignored}}
   int a = (foo(), 0);
-  // expected-note@-1 2{{while checking}} expected-error@-1{{no matching function}} \
- expected-note@-1 2{{in instantiation}}
+  // expected-note@-1 {{while checking}} expected-error@-1{{no matching function}} \
+ expected-note@-1 {{in instantiation}}
   template void bar() requires requires { requires f; } { };
-  // expected-note@-1{{in instantiation}} expected-note@-1{{subexpression not valid}} \
+  // expected-note@-1{{in instantiation}} \
  expected-note@-1{{while substituting}} \
- expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}} \
- expected-note@-1 2{{while checking the satisfaction of nested requirement}}
+ expected-note@-1 {{while checking the satisfaction of nested requirement}}
   int b = (bar(), 0);
   template struct M { static void foo() requires f { }; };
-  // expected-note@-1{{in instantiation}} expected-note@-1{{subexpression not valid}} \
- expected-note@-1{{while substituting}} \
- expected-error@-1{{substitution into constraint expression resulted in a non-constant expression}}
+  // expected-note@-1{{in instantiation}} expected-note@-1{{while substituting}}
   int c = (M::foo(), 0);
-  // expected-note@-1 2{{while checking}}
+  // expected-note@-1 {{while checking}}
 }
Index: clang/test/SemaTemplate/constraints.cpp
===
--- clang/test/SemaTemplate/constraints.cpp
+++ clang/test/SemaTemplate/constraints.cpp
@@ -15,12 +15,11 @@
 
   template constexpr int test = 0;
   template requires C constexpr int test = 1;
-  template requires (B && C) || (X::value && C) constexpr int test = 2; // expected-error {{non-constant expression}} expected-note {{subexpression}} expected-note {{instantiation of}} expected-note {{while substituting}}
+  template requires (B && C) || (X::value && C) constexpr int test = 2; // expected-note {{instantiation of}} expected-note {{while substituting}}
   static_assert(test == 2);
   static_assert(test == 2);
   static_assert(test == 2); // satisfaction of second term of || not considered
   static_assert(test == 1);
   static_assert(test == 2); // constraints are partially ordered
-  // FIXME: These diagnostics are excessive.
-  static_assert(test == 1); // expected-note 2{{while}} expected-note 2{{during}}
+  static_assert(test == 1); // expected-note {{while}} expected-note {{during}}
 }
Index: clang/test/AST/ast-dump-recovery.cpp

[PATCH] D134432: [clang][dataflow] Add support for nested method calls.

2022-09-22 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, sgatev.
Herald added subscribers: martong, rnkovacs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Extend the context-sensitive analysis to handle a call to a method (of the same
class) from within a method. That, is a member-call expression through `this`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134432

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4359,7 +4359,7 @@
   std::string Code = R"(
 class MyClass {
 public:
-  bool setField(bool Val) { Field = Val; }
+  void setField(bool Val) { Field = Val; }
 
   bool Field;
 };
@@ -4392,7 +4392,7 @@
 class MyClass {
 public:
   bool getField() { return Field; }
-  bool setField(bool Val) { Field = Val; }
+  void setField(bool Val) { Field = Val; }
 
 private:
   bool Field;
@@ -4421,6 +4421,73 @@
   {TransferOptions{ContextSensitiveOptions{}}});
 }
 
+
+TEST(TransferTest, ContextSensitiveMethodTwoLayersVoid) {
+  std::string Code = R"(
+class MyClass {
+public:
+  void Inner() { MyField = true; }
+  void Outer() { Inner(); }
+
+  bool MyField;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.Outer();
+  bool Foo = MyObj.MyField;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));;
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal = *cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {TransferOptions{ContextSensitiveOptions{}}});
+}
+
+TEST(TransferTest, ContextSensitiveMethodTwoLayersReturn) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool Inner() { return MyField; }
+  bool Outer() { return Inner(); }
+
+  bool MyField;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.MyField = true;
+  bool Foo = MyObj.Outer();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));;
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal = *cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {TransferOptions{ContextSensitiveOptions{}}});
+}
+
 TEST(TransferTest, ContextSensitiveConstructorBody) {
   std::string Code = R"(
 class MyClass {
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -215,8 +215,11 @@
   Env.ReturnLoc = getStorageLocation(*Call, SkipPast::Reference);
 
   if (const auto *MethodCall = dyn_cast(Call)) {
-if (const Expr *Arg = MethodCall->getImplicitObjectArgument()) {
-  Env.ThisPointeeLoc = getStorageLocation(*Arg, SkipPast::Reference);
+if (const Expr *Arg = MethodCall->getImplicitObjectArgument()){
+  if(!isa(Arg))
+Env.ThisPointeeLoc = getStorageLocation(*Arg, SkipPast::Reference);
+  // Otherwise (when the argument is `this`), retain the current
+  // environment's `ThisPointeeLoc`.
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134432: [clang][dataflow] Add support for nested method calls.

2022-09-22 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 462153.
ymandel added a comment.

formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134432

Files:
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4359,7 +4359,7 @@
   std::string Code = R"(
 class MyClass {
 public:
-  bool setField(bool Val) { Field = Val; }
+  void setField(bool Val) { Field = Val; }
 
   bool Field;
 };
@@ -4392,7 +4392,7 @@
 class MyClass {
 public:
   bool getField() { return Field; }
-  bool setField(bool Val) { Field = Val; }
+  void setField(bool Val) { Field = Val; }
 
 private:
   bool Field;
@@ -4421,6 +4421,73 @@
   {TransferOptions{ContextSensitiveOptions{}}});
 }
 
+
+TEST(TransferTest, ContextSensitiveMethodTwoLayersVoid) {
+  std::string Code = R"(
+class MyClass {
+public:
+  void Inner() { MyField = true; }
+  void Outer() { Inner(); }
+
+  bool MyField;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.Outer();
+  bool Foo = MyObj.MyField;
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));;
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal = *cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {TransferOptions{ContextSensitiveOptions{}}});
+}
+
+TEST(TransferTest, ContextSensitiveMethodTwoLayersReturn) {
+  std::string Code = R"(
+class MyClass {
+public:
+  bool Inner() { return MyField; }
+  bool Outer() { return Inner(); }
+
+  bool MyField;
+};
+
+void target() {
+  MyClass MyObj;
+  MyObj.MyField = true;
+  bool Foo = MyObj.Outer();
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));;
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal = *cast(Env.getValue(*FooDecl, SkipPast::None));
+EXPECT_TRUE(Env.flowConditionImplies(FooVal));
+  },
+  {TransferOptions{ContextSensitiveOptions{}}});
+}
+
 TEST(TransferTest, ContextSensitiveConstructorBody) {
   std::string Code = R"(
 class MyClass {
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -216,7 +216,10 @@
 
   if (const auto *MethodCall = dyn_cast(Call)) {
 if (const Expr *Arg = MethodCall->getImplicitObjectArgument()) {
-  Env.ThisPointeeLoc = getStorageLocation(*Arg, SkipPast::Reference);
+  if (!isa(Arg))
+Env.ThisPointeeLoc = getStorageLocation(*Arg, SkipPast::Reference);
+  // Otherwise (when the argument is `this`), retain the current
+  // environment's `ThisPointeeLoc`.
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: hans, majnemer, rnk.
aaron.ballman added a comment.

In D131465#3806709 , @MaskRay wrote:

> In D131465#3804893 , @glandium 
> wrote:
>
>> This didn't change the default for msvc targets, was that expected?
>
> I think it is expected (but I did not know when I made the change)
>
> https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170
>  says the default is `/std:c++14`.
> If I use `/Zc:__cplusplus` on godbolt.org, I get `__cplusplus => 201402`. I 
> think clang-cl likely wants to follow MSVC.
> The relevant code is around 
> https://github.com/llvm/llvm-project/blob/669e508772e5e00db6285d699ee82a428dc00f32/clang/lib/Driver/ToolChains/Clang.cpp#L6628

I don't recall us sticking with the MSVC defaults the last time we bumped 
default language versions, but I've not gone back through email to look yet. 
Regardless, I don't think it's ergonomic for Clang to have a different default 
language standard for Windows targets -- that means when I run tests, they're 
all run in C++14 mode but when my coworker runs them, they're all C++17; we 
will assuredly run into "why does this test behave differently for you than 
me?" problems from diverging. Not everyone using clang is using clang-cl, so I 
think clang should default to the same language version for Windows as Linux. I 
think it's reasonable for clang-cl specifically to default to what MSVC does 
though. (CC @hans @majnemer @rnk to see if they recall details or have 
opinions.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131465

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


[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

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

In D126907#3807707 , @wlei wrote:

> Tested this and confirmed the issue I reported is gone, thanks!

Thank you all for the quick responses!


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

https://reviews.llvm.org/D126907

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


[PATCH] D134394: Update docs about [[likely]] vs. PGO

2022-09-22 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

While running this small experiment: 
https://sergesanspaille.fedorapeople.org/proftest.sh
I get the following output:

  clang version 16.0.0 (...)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  InstalledDir: ...
   - instrumentation + likely: puts first
  
  06d0 :
   6d0: 50  push   %rax
   6d1: 83 ff 01cmp$0x1,%edi
   6d4: 75 10   jne6e6 
   6d6: 48 8d 3d a7 00 00 00lea0xa7(%rip),%rdi# 784 
<_IO_stdin_used+0x4>
   6dd: e8 ce fe ff ff  callq  5b0 
   6e2: 31 c0   xor%eax,%eax
   6e4: 59  pop%rcx
   6e5: c3  retq   
   6e6: 48 8b 06mov(%rsi),%rax
   6e9: 48 8b 56 08 mov0x8(%rsi),%rdx
   6ed: 48 8d 3d 9b 00 00 00lea0x9b(%rip),%rdi# 78f 
<_IO_stdin_used+0xf>
   6f4: 48 89 c6mov%rax,%rsi
   6f7: 31 c0   xor%eax,%eax
   6f9: e8 92 fe ff ff  callq  590 
   6fe: eb e2   jmp6e2 
  
  0700 <__libc_csu_init>:
  
    + instrumentation + likely: puts first
  
  05e0 :
   5e0: 50  push   %rax
   5e1: 83 ff 01cmp$0x1,%edi
   5e4: 75 10   jne5f6 
   5e6: 48 8d 3d 97 01 00 00lea0x197(%rip),%rdi# 784 
<_IO_stdin_used+0x4>
   5ed: e8 be ff ff ff  callq  5b0 
   5f2: 31 c0   xor%eax,%eax
   5f4: 59  pop%rcx
   5f5: c3  retq   
   5f6: 48 8b 06mov(%rsi),%rax
   5f9: 48 8b 56 08 mov0x8(%rsi),%rdx
   5fd: 48 8d 3d 8b 01 00 00lea0x18b(%rip),%rdi# 78f 
<_IO_stdin_used+0xf>
   604: 48 89 c6mov%rax,%rsi
   607: 31 c0   xor%eax,%eax
   609: e8 82 ff ff ff  callq  590 
   60e: eb e2   jmp5f2 
  
  0610 <_start>:
  ./b1.out 12
   - instrumentation - likely: puts first
  
  06d0 :
   6d0: 50  push   %rax
   6d1: 83 ff 01cmp$0x1,%edi
   6d4: 75 0e   jne6e4 
   6d6: 48 8d 3d a7 00 00 00lea0xa7(%rip),%rdi# 784 
<_IO_stdin_used+0x4>
   6dd: e8 ce fe ff ff  callq  5b0 
   6e2: eb 18   jmp6fc 
   6e4: 48 8b 06mov(%rsi),%rax
   6e7: 48 8b 56 08 mov0x8(%rsi),%rdx
   6eb: 48 8d 3d 9d 00 00 00lea0x9d(%rip),%rdi# 78f 
<_IO_stdin_used+0xf>
   6f2: 48 89 c6mov%rax,%rsi
   6f5: 31 c0   xor%eax,%eax
   6f7: e8 94 fe ff ff  callq  590 
   6fc: 31 c0   xor%eax,%eax
   6fe: 59  pop%rcx
   6ff: c3  retq   
  
  0700 <__libc_csu_init>:
  
    + instrumentation - likely: printf first
  
  05e0 :
   5e0: 50  push   %rax
   5e1: 83 ff 01cmp$0x1,%edi
   5e4: 74 1c   je 602 
   5e6: 48 8b 06mov(%rsi),%rax
   5e9: 48 8b 56 08 mov0x8(%rsi),%rdx
   5ed: 48 8d 3d 9b 01 00 00lea0x19b(%rip),%rdi# 78f 
<_IO_stdin_used+0xf>
   5f4: 48 89 c6mov%rax,%rsi
   5f7: 31 c0   xor%eax,%eax
   5f9: e8 92 ff ff ff  callq  590 
   5fe: 31 c0   xor%eax,%eax
   600: 59  pop%rcx
   601: c3  retq   
   602: 48 8d 3d 7b 01 00 00lea0x17b(%rip),%rdi# 784 
<_IO_stdin_used+0x4>
   609: e8 a2 ff ff ff  callq  5b0 
   60e: eb ee   jmp5fe 
  
  0610 <_start>:

To me, it means that `[[likely]]` takes precedence over profile information...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134394

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


[PATCH] D134394: Update docs about [[likely]] vs. PGO

2022-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D134394#3808397 , 
@serge-sans-paille wrote:

> While running this small experiment: 
> https://sergesanspaille.fedorapeople.org/proftest.sh

Thank you for the help with testing the assumptions here!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134394

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


[PATCH] D115169: Create a generic ABI document for _BitInt

2022-09-22 Thread Jens Gustedt via Phabricator via cfe-commits
gustedt added a comment.

>> Also discussing consequences for `va_arg` functions such as `printf` would 
>> be nice.
>
> Does the information in the `Passing and Returning an Object` section 
> suffice, or are there more details you're looking for there?

The narrow `_BitInt` types are not promoted to `int` for arithmetic.

For the function call ABI we would need to know if the same strategy holds for 
`va_arg` parameters. For each of these types with representing standard integer 
type `T` two scenarios would be possible

- When passed to a `va_arg` function the same rules for `T` as an argument for 
a prototyped function parameter apply.
- When passed to a `va_arg` function the value is promoted as if it where a 
`T`, that is in general there is a promotion to `int`.

This has in particular implications to whether or not the `wN` length modifier 
for `printf` and `scanf` can be used for narrow `_BitInt` types or not: in the 
first scenario that would not be possible in the second in would be possible 
without problems.

I would be much in favor of the second choice, `va_arg` functions usually are 
not made to handle narrow input well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115169

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


[PATCH] D134157: [Clang][LoongArch] Add inline asm support for constraints f/l/I/K

2022-09-22 Thread Renato Golin via Phabricator via cfe-commits
rengolin added inline comments.



Comment at: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp:1958
+  // constraints while the official register name is prefixed with a '$'.
+  // So we manually select general purpose registers here.
+  // For now, no need to support ABI names (e.g. `$a0`) as clang will correctly

Can't you just clip the `$`, upper-case and match against some table-gen'd 
names?



Comment at: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp:2064
+uint64_t CVal = C->getSExtValue();
+if (isInt<16>(CVal))
+  Ops.push_back(

Shouldn't this break if the constant isn't in the right type? What happens if 
it isn't? 

It seems it just doesn't append the operand and return. Wouldn't that just 
break the op's format?

On Arm, the logic is simpler:
 - Iterate through all constraints, validating the input
 - If valie, set the Result and append to the Op at the end
 - Otherwise bail and let `TargetLowering::LowerAsmOperandForConstraint` handle 
it.



Comment at: llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll:5
+; RUN: llc --mtriple=loongarch64 --verify-machineinstrs --no-integrated-as < 
%s \
+; RUN:   | FileCheck --check-prefix=LA64 %s
+

I'm not seeing differences between LA32 and LA64, is splitting the CHECK lines 
really necessary?

On some other tests, too...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134157

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


[PATCH] D108211: Emit sizeof/alignof values as notes when a static_assert fails

2022-09-22 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson abandoned this revision.
arichardson added a comment.

Would require significant work to still be useful now that we print the value 
of expressions (e.g. only print for more complex expressions).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108211

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


[PATCH] D108212: Emit offsetof values as notes when a static_assert fails

2022-09-22 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson abandoned this revision.
arichardson added a comment.
Herald added a project: All.

No longer needed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108212

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


[clang] cf77333 - [clang][docs] Fix supported element types for __builtin_reduce_(add|mul)

2022-09-22 Thread Joe Loser via cfe-commits

Author: Joe Loser
Date: 2022-09-22T07:52:22-06:00
New Revision: cf77333da986720e9aded4301d81a581e2be9611

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

LOG: [clang][docs] Fix supported element types for __builtin_reduce_(add|mul)

The docs mention that `__builtin_reduce_add` and `__builtin_reduce_mul` support
both integer and floating point element types, but only integer element types
are actually supported. See https://github.com/llvm/llvm-project/issues/57847,
and specifically,
https://github.com/llvm/llvm-project/blob/00874c48ea4d291908517afaab50d1dcbfb016c3/clang/lib/Sema/SemaChecking.cpp#L2631
 for the fact that floating point element types are not supported yet.

Fix the docs to only mention support for integer element types.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6522e0492f8b..17b2f8a00297 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -648,8 +648,8 @@ Let ``VT`` be a vector type and ``ET`` the element type of 
``VT``.
  ET __builtin_reduce_min(VT a)   return x or y, whichever is smaller; 
If exactly one argument integer and floating point types
  is a NaN, return the other argument. 
If both arguments are
  NaNs, fmax() return a NaN.
- ET __builtin_reduce_add(VT a)   \+
   integer and floating point types
- ET __builtin_reduce_mul(VT a)   \*
   integer and floating point types
+ ET __builtin_reduce_add(VT a)   \+
   integer types
+ ET __builtin_reduce_mul(VT a)   \*
   integer types
  ET __builtin_reduce_and(VT a)   & 
   integer types
  ET __builtin_reduce_or(VT a)\|
   integer types
  ET __builtin_reduce_xor(VT a)   ^ 
   integer types



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


[PATCH] D134316: [clang][docs] Fix supported element types for `__builtin_reduce_(add|mul)`

2022-09-22 Thread Joe Loser via Phabricator via cfe-commits
jloser closed this revision.
jloser added a comment.

This landed with 
https://github.com/llvm/llvm-project/commit/cf77333da986720e9aded4301d81a581e2be9611.
  The revision didn't auto-close for some reason.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134316

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


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

2022-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin, 
lichray.
aaron.ballman added a comment.

In D133659#3808095 , @royjacobson 
wrote:

> Thanks everyone! So if no one else has comments I'm planning to merge this 
> tomorrow.

FWIW, you shouldn't merge something that has nobody signed on as the reviewer 
(and has only mild acceptance from people subscribing) -- a better approach is 
to add some reviewers, get them to accept, then land. Otherwise, coming back to 
this review in the future when doing code archeology leads to confusion about 
whether the changes should have even gone in at all, etc. I've added some more 
reviewers so we can make sure this gets the pretty green checkmark before 
landing. :-)




Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:1033
+def err_static_lambda: Error<
+  "static lambdas is a C++2b extension">;
+def warn_cxx20_compat_static_lambda: Warning<

This is a bit confusing -- we're saying it's an extension but then making it an 
error? I've reworded based on how I think you're intending it to be issued.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:1037-1041
+def err_static_mutable_lambda : Error<
+  "lambda cannot be both mutable and static">;
+def err_static_lambda_captures : Error<
+  "a static lambda cannot have any captures">;
+def note_lambda_captures : Note<"captures declared here">;

These are semantic errors, not parsing ones. This means these will be diagnosed 
when parsing the lambda rather than when instantiating it. I don't think that 
matters for the cast of combining `mutable` and `static`, but I'm less certain 
about "have any captures" because of cases like:
```
template 
auto func(Types... Ts) {
  return [Ts...] { return 1; };
}

int main() {
  auto lambda = func();
}
```
I'm pretty sure that lambda has no captures for that call, but it could have 
captures depending on the instantiation.

Actually, from some off-list discussion with @erichkeane, even mutable and 
static are a problem in code like:
```
template 
void func(T t) {
  if constexpr (Something) {
[](){};
  } else {
[t](){};
  }
```
where the lambda is in a discarded statement.

So I think these might need to change to be Sema diagnostics (and we should add 
some additional test coverage).



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9075
+def ext_operator_overload_static : ExtWarn<
+  "making static overloaded %0 is a C++2b extension">, 
InGroup, DefaultIgnore;
+def err_call_operator_overload_static : Error<





Comment at: clang/lib/Sema/SemaDeclCXX.cpp:15938-15944
+Diag(FnDecl->getLocation(),
+ (LangOpts.CPlusPlus2b ? diag::ext_operator_overload_static
+   : diag::err_call_operator_overload_static))
+<< FnDecl->getDeclName();
+  else
+return Diag(FnDecl->getLocation(), diag::err_operator_overload_static)
+   << FnDecl->getDeclName();

The diagnostic formatter knows how to format anything that inherits from 
`NamedDecl`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133659

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


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

2022-09-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:1037-1041
+def err_static_mutable_lambda : Error<
+  "lambda cannot be both mutable and static">;
+def err_static_lambda_captures : Error<
+  "a static lambda cannot have any captures">;
+def note_lambda_captures : Note<"captures declared here">;

aaron.ballman wrote:
> These are semantic errors, not parsing ones. This means these will be 
> diagnosed when parsing the lambda rather than when instantiating it. I don't 
> think that matters for the cast of combining `mutable` and `static`, but I'm 
> less certain about "have any captures" because of cases like:
> ```
> template 
> auto func(Types... Ts) {
>   return [Ts...] { return 1; };
> }
> 
> int main() {
>   auto lambda = func();
> }
> ```
> I'm pretty sure that lambda has no captures for that call, but it could have 
> captures depending on the instantiation.
> 
> Actually, from some off-list discussion with @erichkeane, even mutable and 
> static are a problem in code like:
> ```
> template 
> void func(T t) {
>   if constexpr (Something) {
> [](){};
>   } else {
> [t](){};
>   }
> ```
> where the lambda is in a discarded statement.
> 
> So I think these might need to change to be Sema diagnostics (and we should 
> add some additional test coverage).
From https://eel.is/c++draft/expr.prim.lambda.general#4 

> If the lambda-specifier-seq contains static, there shall be no lambda-capture

So this should be a parsing error. Or maybe I don't understand what you're 
saying. There are no static lambdas in your examples so I'm not sure how 
they're related.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133659

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


[PATCH] D134316: [clang][docs] Fix supported element types for `__builtin_reduce_(add|mul)`

2022-09-22 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D134316#3808544 , @jloser wrote:

> This landed with 
> https://github.com/llvm/llvm-project/commit/cf77333da986720e9aded4301d81a581e2be9611.
>   The revision didn't auto-close for some reason.

You need to make sure the commit message includes `Differential Revision: 
https://reviews.llvm.org/D134316` for it to auto-close.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134316

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


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

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



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:1037-1041
+def err_static_mutable_lambda : Error<
+  "lambda cannot be both mutable and static">;
+def err_static_lambda_captures : Error<
+  "a static lambda cannot have any captures">;
+def note_lambda_captures : Note<"captures declared here">;

royjacobson wrote:
> aaron.ballman wrote:
> > These are semantic errors, not parsing ones. This means these will be 
> > diagnosed when parsing the lambda rather than when instantiating it. I 
> > don't think that matters for the cast of combining `mutable` and `static`, 
> > but I'm less certain about "have any captures" because of cases like:
> > ```
> > template 
> > auto func(Types... Ts) {
> >   return [Ts...] { return 1; };
> > }
> > 
> > int main() {
> >   auto lambda = func();
> > }
> > ```
> > I'm pretty sure that lambda has no captures for that call, but it could 
> > have captures depending on the instantiation.
> > 
> > Actually, from some off-list discussion with @erichkeane, even mutable and 
> > static are a problem in code like:
> > ```
> > template 
> > void func(T t) {
> >   if constexpr (Something) {
> > [](){};
> >   } else {
> > [t](){};
> >   }
> > ```
> > where the lambda is in a discarded statement.
> > 
> > So I think these might need to change to be Sema diagnostics (and we should 
> > add some additional test coverage).
> From https://eel.is/c++draft/expr.prim.lambda.general#4 
> 
> > If the lambda-specifier-seq contains static, there shall be no 
> > lambda-capture
> 
> So this should be a parsing error. Or maybe I don't understand what you're 
> saying. There are no static lambdas in your examples so I'm not sure how 
> they're related.
> 
> So this should be a parsing error. Or maybe I don't understand what you're 
> saying. 

Parsing errors are where the grammar disallows something, generally. The rest 
are semantic diagnostics (e.g., we can parse the construct just fine, but we 
diagnose when turning it into an AST node because that's the point at which we 
have complete information about what we've parsed).

That said, my concern was mostly around SFINAE situations. My recollection is 
that SFINAE traps do not cover parsing errors only type substitution errors. So 
for my first example, I would expect there to be no parsing error despite 
specifying a capture list because that capture list can be empty when the pack 
is empty, but we would get a SFINAE diagnostic when rebuilding declaration 
during template instantiation if the pack was not empty.

>  There are no static lambdas in your examples so I'm not sure how they're 
> related.

Sorry, I was being lazy with my examples and showing more about the capture 
list. Consider:
```
template 
auto func(Types... Ts) {
  return [Ts...] static { return 1; };
}

int main() {
  auto lambda = func();
}
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133659

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


[PATCH] D134441: [ObjC][ARC] Don't use operand bundle "clang.arc.attachedcall" in codegen for Windows

2022-09-22 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz created this revision.
sgraenitz added reviewers: ahatanak, rjmccall, theraven, rnk.
Herald added a subscriber: pengfei.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch is an attempt to fix regression 
https://github.com/llvm/llvm-project/issues/56952 for Clang 
CodeGen on Windows. It appears that the operand bundle `clang.arc.attachedcall` 
is not fully supported
in the x86_64 backend for Windows. This patch prevents Clang from emitting it 
in the first place.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134441

Files:
  clang/lib/CodeGen/CGObjC.cpp


Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2359,7 +2359,8 @@
   // FIXME: Do this on all targets and at -O0 too. This can be enabled only if
   // the target backend knows how to handle the operand bundle.
   if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 &&
-  (Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::x86_64)) {
+  (Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::x86_64) &&
+  !CGF.CGM.getTarget().getTriple().isOSWindows()) {
 llvm::Value *bundleArgs[] = {EP};
 llvm::OperandBundleDef OB("clang.arc.attachedcall", bundleArgs);
 auto *oldCall = cast(value);


Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2359,7 +2359,8 @@
   // FIXME: Do this on all targets and at -O0 too. This can be enabled only if
   // the target backend knows how to handle the operand bundle.
   if (CGF.CGM.getCodeGenOpts().OptimizationLevel > 0 &&
-  (Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::x86_64)) {
+  (Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::x86_64) &&
+  !CGF.CGM.getTarget().getTriple().isOSWindows()) {
 llvm::Value *bundleArgs[] = {EP};
 llvm::OperandBundleDef OB("clang.arc.attachedcall", bundleArgs);
 auto *oldCall = cast(value);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134441: [ObjC][ARC] Don't use operand bundle "clang.arc.attachedcall" in codegen for Windows

2022-09-22 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added a comment.

I assume is that this can only be a temporary fix as it probably has an impact 
on performance of compiled output. I am eager to fix this properly. The FIXME 
comment says that we need specific support in the target backend. Any ideas 
what the x86_64 backend for Windows might be missing to handle the operand 
bundle correctly? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134441

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


[PATCH] D134441: [ObjC][ARC] Don't use operand bundle "clang.arc.attachedcall" in codegen for Windows

2022-09-22 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added a comment.

Bisectioning showed that the regression started with this patch: 
https://reviews.llvm.org/D111331


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134441

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


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

2022-09-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:1037-1041
+def err_static_mutable_lambda : Error<
+  "lambda cannot be both mutable and static">;
+def err_static_lambda_captures : Error<
+  "a static lambda cannot have any captures">;
+def note_lambda_captures : Note<"captures declared here">;

aaron.ballman wrote:
> royjacobson wrote:
> > aaron.ballman wrote:
> > > These are semantic errors, not parsing ones. This means these will be 
> > > diagnosed when parsing the lambda rather than when instantiating it. I 
> > > don't think that matters for the cast of combining `mutable` and 
> > > `static`, but I'm less certain about "have any captures" because of cases 
> > > like:
> > > ```
> > > template 
> > > auto func(Types... Ts) {
> > >   return [Ts...] { return 1; };
> > > }
> > > 
> > > int main() {
> > >   auto lambda = func();
> > > }
> > > ```
> > > I'm pretty sure that lambda has no captures for that call, but it could 
> > > have captures depending on the instantiation.
> > > 
> > > Actually, from some off-list discussion with @erichkeane, even mutable 
> > > and static are a problem in code like:
> > > ```
> > > template 
> > > void func(T t) {
> > >   if constexpr (Something) {
> > > [](){};
> > >   } else {
> > > [t](){};
> > >   }
> > > ```
> > > where the lambda is in a discarded statement.
> > > 
> > > So I think these might need to change to be Sema diagnostics (and we 
> > > should add some additional test coverage).
> > From https://eel.is/c++draft/expr.prim.lambda.general#4 
> > 
> > > If the lambda-specifier-seq contains static, there shall be no 
> > > lambda-capture
> > 
> > So this should be a parsing error. Or maybe I don't understand what you're 
> > saying. There are no static lambdas in your examples so I'm not sure how 
> > they're related.
> > 
> > So this should be a parsing error. Or maybe I don't understand what you're 
> > saying. 
> 
> Parsing errors are where the grammar disallows something, generally. The rest 
> are semantic diagnostics (e.g., we can parse the construct just fine, but we 
> diagnose when turning it into an AST node because that's the point at which 
> we have complete information about what we've parsed).
> 
> That said, my concern was mostly around SFINAE situations. My recollection is 
> that SFINAE traps do not cover parsing errors only type substitution errors. 
> So for my first example, I would expect there to be no parsing error despite 
> specifying a capture list because that capture list can be empty when the 
> pack is empty, but we would get a SFINAE diagnostic when rebuilding 
> declaration during template instantiation if the pack was not empty.
> 
> >  There are no static lambdas in your examples so I'm not sure how they're 
> > related.
> 
> Sorry, I was being lazy with my examples and showing more about the capture 
> list. Consider:
> ```
> template 
> auto func(Types... Ts) {
>   return [Ts...] static { return 1; };
> }
> 
> int main() {
>   auto lambda = func();
> }
> ```
> 
Like I said,

> If the lambda-specifier-seq contains static, there shall be no lambda-capture

`Ts...` is still a syntactic `lambda-capture`, even if it's instantiated as an 
empty pack. I don't see how that's not a parsing error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133659

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


[PATCH] D134441: [ObjC][ARC] Don't use operand bundle "clang.arc.attachedcall" in codegen for Windows

2022-09-22 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added a comment.

The symptom is that Clang emits `movq %rax, %rdi` instead of `movq %rax, %rcx` 
while `objc_retainAutoreleasedReturnValue()` still expects the value in `%rcx`.
It appears related to D94597 . Is this a 
calling convention issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134441

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


[PATCH] D133853: [AST] Add msvc-specific C++11 attributes

2022-09-22 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added a comment.

In D133853#3799344 , @aaron.ballman 
wrote:

> It's a conforming extension in older language modes like C++98, where we 
> couldn't steal the `constexpr` keyword because it's not reserved, which is 
> one benefit to it. Does MSVC support this as far back as C++98?

Tbh, I cannot understand your question in relation to your statement, and where 
did you get that statement from 🙂

> Does MSVC support this as far back as C++98?

I don't know. AFAIK - no.

@h-vetinari thanks for your input.

I'll try to update this patch as per our discussion:

1. `[[msvc::constexpr]]` handle like `constexpr` for functions with 
`-fms-extensions` (according to MSVC error message: `C7687: [[msvc::constexpr]] 
may only be applied to statements and functions`); I won't implement semantic 
meaning for statements, as I am now aware of it and there's no constexpr effect 
on statements.
2. Possibly take a look at `[[msvc::no_unique_address]]`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133853

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


[PATCH] D133853: [AST] Add msvc-specific C++11 attributes

2022-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D133853#3808669 , @RIscRIpt wrote:

> In D133853#3799344 , @aaron.ballman 
> wrote:
>
>> It's a conforming extension in older language modes like C++98, where we 
>> couldn't steal the `constexpr` keyword because it's not reserved, which is 
>> one benefit to it. Does MSVC support this as far back as C++98?
>
> Tbh, I cannot understand your question in relation to your statement, and 
> where did you get that statement from 🙂

Ah, I forgot that MSVC's `/std:` flag only goes as far back as C++14. I was 
wondering two things: 1) does MSVC support `[[]]` attributes in C++ modes 
earlier than C++11 (moot, there is no C++ earlier than 14 for MSVC) and 2) does 
MSVC support `[[msvc::constexpr]]` in C++ modes earlier than C++11 (also moot). 
If the answer to both of those questions was "yes", then I'd understand why 
this attribute exists (it would be a conforming extension in those language 
modes, where they could not expose `constexpr` as a keyword). Now I'm wondering 
why the attribute exists at all. If it's functionally equivalent to `constexpr` 
as a keyword, what are the use cases for the attribute?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133853

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


[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-22 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added subscribers: joanahalili, alexfh.
mizvekov added a comment.

FYI, I fixed all known points made, I think this review can progress.

Another thing, which I noticed only after we improved and merged D128113 
, is that it does have an impact similar to 
what D128113  had before we inverted the 
indexing order.
Specifically regarding the repro contained in this comment: 
https://reviews.llvm.org/D128113#3742779
On more real-world like code such as the tests in llvm-compile-time-tracker, 
there is no discernible impact from this patch: 
http://llvm-compile-time-tracker.com/compare.php?from=a5a9b896fe0645f1060b33b19693786146f83375&to=f2e03cd6d07901c4848242368a0b0c29c88331f6&stat=instructions

Both @alexfh and @joanahalili first reported this problem on D128113 
, although it seems they managed to refactor 
the original code so it would not be a problem anymore for them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D134410: [clang][CodeGen] Add noundef metadata to load instructions (preliminary)

2022-09-22 Thread John McIver via Phabricator via cfe-commits
jmciver created this revision.
Herald added subscribers: mattd, asavonic, jdoerfert, pengfei.
Herald added a project: All.
jmciver retitled this revision from "[clang][CodeGen] Add noundef metadata to 
scalar load instructions" to "[clang][CodeGen] Add noundef metadata to scalar 
load instructions (preliminary)".
jmciver edited the summary of this revision.
jmciver retitled this revision from "[clang][CodeGen] Add noundef metadata to 
scalar load instructions (preliminary)" to "[clang][CodeGen] Add noundef 
metadata to load instructions (preliminary)".
jmciver edited the summary of this revision.
jmciver added reviewers: nikic, efriedma, aqjune, rjmccall.
jmciver published this revision for review.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, pcwang-thead, sstefan1.
Herald added a project: clang.

This patch adds noundef metadata to scalar load instructions and is intended to 
gain implementation feedback before proceeding to adding noundef to other load 
types.

The intent is to apply noundef to scalar load instructions that are not of type:

- char (if the target system maps to unsigned char)
- unsigned char
- std::byte

These types are excluded because of their different indeterminate value 
semantics (I think this is correct, but need to ask someone).

Feedback is greatly appreciated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134410

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/X86/avx-builtins.c
  clang/test/CodeGen/X86/avx512bw-builtins.c
  clang/test/CodeGen/X86/avx512f-builtins.c
  clang/test/CodeGen/X86/avx512fp16-builtins.c
  clang/test/CodeGen/X86/avx512vl-builtins.c
  clang/test/CodeGen/X86/avx512vlbw-builtins.c
  clang/test/CodeGen/X86/sse-builtins.c
  clang/test/CodeGen/X86/sse2-builtins.c
  clang/test/CodeGen/aarch64-ls64-inline-asm.c
  clang/test/CodeGen/aarch64-ls64.c
  clang/test/CodeGen/memcpy-inline-builtin.c
  clang/test/CodeGen/tbaa-array.cpp
  clang/test/CodeGen/tbaa-base.cpp
  clang/test/CodeGen/tbaa.cpp
  clang/test/CodeGen/ubsan-pass-object-size.c
  clang/test/CodeGenCXX/attr-likelihood-if-branch-weights.cpp
  clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
  clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp
  clang/test/CodeGenCXX/debug-info-line.cpp
  clang/test/CodeGenCXX/pr12251.cpp
  clang/test/CodeGenCXX/pragma-followup_inner.cpp
  clang/test/OpenMP/cancel_codegen.cpp
  clang/test/OpenMP/cancellation_point_codegen.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/for_reduction_task_codegen.cpp
  clang/test/OpenMP/irbuilder_safelen.cpp
  clang/test/OpenMP/irbuilder_simdlen.cpp
  clang/test/OpenMP/irbuilder_simdlen_safelen.cpp
  clang/test/OpenMP/master_taskloop_in_reduction_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_in_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/ordered_codegen.cpp
  clang/test/OpenMP/parallel_for_codegen.cpp
  clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_for_simd_aligned_codegen.cpp
  clang/test/OpenMP/parallel_for_simd_codegen.cpp
  clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_lastprivate_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/parallel_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp
  clang/test/OpenMP/sections_reduction_task_codegen.cpp
  clang/test/OpenMP/target_defaultmap_codegen_01.cpp
  clang/test/OpenMP/target_in_reduction_codegen.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  clang/test/OpenMP/target_map_codegen_00.cpp
  clang/test/OpenMP/target_map_codegen_01.cpp
  clang/test/OpenMP/target_map_codegen_02.cpp
  clang/test/OpenMP/target_map_codegen_04.cpp
  clang/test/OpenMP/target_map_codegen_05.cpp
  clang/test/OpenMP/target_map_codegen_07.cpp
  clang/test/OpenMP/target_map_codegen_11.cpp
  clang/test/Ope

[PATCH] D134445: [PR57881][OpenCL] Fix incorrect diagnostics with templated types in kernel arguments

2022-09-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added reviewers: svenvh, olestrohm, rjmccall.
Herald added subscribers: Naghasan, ebevhan, yaxunl.
Herald added a project: All.
Anastasia requested review of this revision.

It seems relying on `isStandardLayoutType` helpers is fragile when kernel 
arguments are references/pointers to templated types.

Clang uses lazy template instantiation in this case and therefore types are not 
fully instantiated when those are used.

Example:

  template
  struct outer{
  public:
  struct inner{
  int size;
  };
  };
  void foo(outer::inner& p)  
  {
  } 

will have the following AST when p is a reference:

  | `-ClassTemplateSpecializationDecl  line:2:8 struct 
outer definition
  |   |-DefinitionData pass_in_registers empty aggregate standard_layout 
trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor 
can_const_default_init
  |   | |-DefaultConstructor exists trivial constexpr needs_implicit 
defaulted_is_constexpr
  |   | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  |   | |-MoveConstructor exists simple trivial needs_implicit
  |   | |-CopyAssignment simple trivial has_const_param needs_implicit 
implicit_has_const_param
  |   | |-MoveAssignment exists simple trivial needs_implicit
  |   | `-Destructor simple irrelevant trivial needs_implicit
  |   |-TemplateArgument type 'int'
  |   | `-BuiltinType 'int'
  |   |-CXXRecordDecl  col:8 implicit struct outer
  |   |-AccessSpecDecl  col:1 public
  |   `-CXXRecordDecl  col:12 referenced struct inner

and when it is not a reference

  | `-ClassTemplateSpecializationDecl  line:2:8 struct 
outer definition
  |   |-DefinitionData pass_in_registers empty aggregate standard_layout 
trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor 
can_const_default_init
  |   | |-DefaultConstructor exists trivial constexpr needs_implicit 
defaulted_is_constexpr
  |   | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  |   | |-MoveConstructor exists simple trivial needs_implicit
  |   | |-CopyAssignment simple trivial has_const_param needs_implicit 
implicit_has_const_param
  |   | |-MoveAssignment exists simple trivial needs_implicit
  |   | `-Destructor simple irrelevant trivial needs_implicit
  |   |-TemplateArgument type 'int'
  |   | `-BuiltinType 'int'
  |   |-CXXRecordDecl  col:8 implicit struct outer
  |   |-AccessSpecDecl  col:1 public
  |   `-CXXRecordDecl  line:4:12 referenced struct inner 
definition
  | |-DefinitionData pass_in_registers aggregate standard_layout 
trivially_copyable pod trivial literal
  | | |-DefaultConstructor exists trivial needs_implicit
  | | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveConstructor exists simple trivial needs_implicit
  | | |-CopyAssignment simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveAssignment exists simple trivial needs_implicit
  | | `-Destructor simple irrelevant trivial needs_implicit
  | |-CXXRecordDecl  col:12 implicit struct inner
  | `-FieldDecl  col:13 size 'int'

In the first case for reference type `inner` is incomplete while if we use a 
non-reference type the definition of template specialization is complete.

I have attempted to workaround this issue for the reported test cases, however 
it still doesn't quite work when the type is created from the template 
parameter (see FIXME test case in the patch). I presume we want to allow this? 
If so we might need to disable lazy template instantiation in this case. My 
guess is the only issue this this is that we will have performance penalty for 
the code of this format:

  template struct Dummy {
  T i;
  };
  
  extern kernel void foo(Dummy& i);

which doesn't technically need the full instantiation.

Also I have discovered that in OpenCL C we have allowed passing kernel 
parameters with pointers to forward declared structs, but in C++ for OpenCL 
that no longer compiles. Not sure whether we should keep this restriction but 
if not it might interfere with the idea of always instantiating the structs 
definitions fully and even providing the safe diagnostics. So another approach 
we could take is to change this diagnostics into warnings and then if we can't 
fully detect the type provide the messaging that we can't detect whether the 
type is safe...

Another aspect to consider is that we have an extension that allows disabling 
all of this safe checks completely: 
https://clang.llvm.org/docs/LanguageExtensions.html#cl-clang-non-portable-kernel-param-types

While this matter might need more thoughts and investigations I wonder whether 
it makes sense to commit this fix for the time being since it's fixing the 
reported test case at least?


https://reviews.llvm.org/D134445

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaOpenCLCXX/invalid-

[PATCH] D131469: [Clang] change default storing path of `-ftime-trace`

2022-09-22 Thread dongjunduo via Phabricator via cfe-commits
dongjunduo added a comment.

In D131469#3798409 , @Maetveis wrote:

> As discussed with @jamieschmeiser on D133662 
> , I have left suggestions regarding the 
> approach I took for handling `-o` and passing the option to the jobs.
>
> I'm really happy to see this area getting attention, and I'm sorry for the 
> confusion I must have caused.

I'm sorry that I didn't see the comments until now because of some personal 
work... Thank you for your kindness and suppot, I will improve this part of 
work according to your idea in D133662  : )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131469

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


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

2022-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: hubert.reinterpretcast.
aaron.ballman added a subscriber: hubert.reinterpretcast.
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:1037-1041
+def err_static_mutable_lambda : Error<
+  "lambda cannot be both mutable and static">;
+def err_static_lambda_captures : Error<
+  "a static lambda cannot have any captures">;
+def note_lambda_captures : Note<"captures declared here">;

royjacobson wrote:
> aaron.ballman wrote:
> > royjacobson wrote:
> > > aaron.ballman wrote:
> > > > These are semantic errors, not parsing ones. This means these will be 
> > > > diagnosed when parsing the lambda rather than when instantiating it. I 
> > > > don't think that matters for the cast of combining `mutable` and 
> > > > `static`, but I'm less certain about "have any captures" because of 
> > > > cases like:
> > > > ```
> > > > template 
> > > > auto func(Types... Ts) {
> > > >   return [Ts...] { return 1; };
> > > > }
> > > > 
> > > > int main() {
> > > >   auto lambda = func();
> > > > }
> > > > ```
> > > > I'm pretty sure that lambda has no captures for that call, but it could 
> > > > have captures depending on the instantiation.
> > > > 
> > > > Actually, from some off-list discussion with @erichkeane, even mutable 
> > > > and static are a problem in code like:
> > > > ```
> > > > template 
> > > > void func(T t) {
> > > >   if constexpr (Something) {
> > > > [](){};
> > > >   } else {
> > > > [t](){};
> > > >   }
> > > > ```
> > > > where the lambda is in a discarded statement.
> > > > 
> > > > So I think these might need to change to be Sema diagnostics (and we 
> > > > should add some additional test coverage).
> > > From https://eel.is/c++draft/expr.prim.lambda.general#4 
> > > 
> > > > If the lambda-specifier-seq contains static, there shall be no 
> > > > lambda-capture
> > > 
> > > So this should be a parsing error. Or maybe I don't understand what 
> > > you're saying. There are no static lambdas in your examples so I'm not 
> > > sure how they're related.
> > > 
> > > So this should be a parsing error. Or maybe I don't understand what 
> > > you're saying. 
> > 
> > Parsing errors are where the grammar disallows something, generally. The 
> > rest are semantic diagnostics (e.g., we can parse the construct just fine, 
> > but we diagnose when turning it into an AST node because that's the point 
> > at which we have complete information about what we've parsed).
> > 
> > That said, my concern was mostly around SFINAE situations. My recollection 
> > is that SFINAE traps do not cover parsing errors only type substitution 
> > errors. So for my first example, I would expect there to be no parsing 
> > error despite specifying a capture list because that capture list can be 
> > empty when the pack is empty, but we would get a SFINAE diagnostic when 
> > rebuilding declaration during template instantiation if the pack was not 
> > empty.
> > 
> > >  There are no static lambdas in your examples so I'm not sure how they're 
> > > related.
> > 
> > Sorry, I was being lazy with my examples and showing more about the capture 
> > list. Consider:
> > ```
> > template 
> > auto func(Types... Ts) {
> >   return [Ts...] static { return 1; };
> > }
> > 
> > int main() {
> >   auto lambda = func();
> > }
> > ```
> > 
> Like I said,
> 
> > If the lambda-specifier-seq contains static, there shall be no 
> > lambda-capture
> 
> `Ts...` is still a syntactic `lambda-capture`, even if it's instantiated as 
> an empty pack. I don't see how that's not a parsing error.
Ah, I think I maybe see where the confusion is coming in, now: you think my 
example should be diagnosed and I think my example should be accepted.

Based on the standards wording, I think you're right. The standard specifically 
uses "lambda-capture" as a grammar term, so it *is* a parsing error at that 
point.

Based on my understanding of the intent behind the feature, I think I'm right 
and there's a core issue here. I don't think we intended to prohibit empty 
packs from being captured as non-SFINAEable error (and in off-list talks with 
@erichkeane, he agrees). as that allows different specializations of the 
function containing the lambda, which could be of use. However, I'm not 100% 
sure on the intent. CC @hubert.reinterpretcast as the C++ standards conformance 
code owner to see if he has an opinion or other recollections here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133659

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


[PATCH] D134445: [PR57881][OpenCL] Fix incorrect diagnostics with templated types in kernel arguments

2022-09-22 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/test/SemaOpenCLCXX/invalid-kernel.clcpp:110
+
+// FIXME: Use of templates doesn't work due to lazy instantiation of reference 
types. 
+//template

I think here should be something like - `the use of templated types doesn't 
work...`



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

https://reviews.llvm.org/D134445

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


[PATCH] D133705: [HIP] Fix unbundling archive

2022-09-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 462189.
yaxunl added a comment.

allow archive files to have unknown extension


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

https://reviews.llvm.org/D133705

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/hip-link-bundle-archive.hip

Index: clang/test/Driver/hip-link-bundle-archive.hip
===
--- clang/test/Driver/hip-link-bundle-archive.hip
+++ clang/test/Driver/hip-link-bundle-archive.hip
@@ -8,7 +8,23 @@
 // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
 // RUN:   --target=x86_64-unknown-linux-gnu \
 // RUN:   -nogpulib %s -fgpu-rdc -L%t -lhipBundled \
-// RUN:   2>&1 | FileCheck -check-prefix=GNU %s
+// RUN:   2>&1 | FileCheck -check-prefixes=GNU,GNU1,GNU-L %s
+
+// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
+// RUN:   --target=x86_64-unknown-linux-gnu \
+// RUN:   -nogpulib %s -fgpu-rdc -L%t -l:libhipBundled.a \
+// RUN:   2>&1 | FileCheck -check-prefixes=GNU,GNU1,GNU-LA %s
+
+// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
+// RUN:   --target=x86_64-unknown-linux-gnu \
+// RUN:   -nogpulib %s -fgpu-rdc %t/libhipBundled.a \
+// RUN:   2>&1 | FileCheck -check-prefixes=GNU,GNU1,GNU-A %s
+
+// RUN: touch %t/libhipBundled.a.5.2
+// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
+// RUN:   --target=x86_64-unknown-linux-gnu \
+// RUN:   -nogpulib %s -fgpu-rdc %t/libhipBundled.a.5.2 \
+// RUN:   2>&1 | FileCheck -check-prefixes=GNU,GNU2,GNU-A %s
 
 // RUN: touch %t/hipBundled2.lib
 // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
@@ -16,14 +32,27 @@
 // RUN:   -nogpulib %s -fgpu-rdc -L%t -lhipBundled2 \
 // RUN:   2>&1 | FileCheck -check-prefix=MSVC %s
 
-// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles"
+// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
+// RUN:   --target=x86_64-pc-windows-msvc \
+// RUN:   -nogpulib %s -fgpu-rdc -L%t -l:hipBundled2.lib \
+// RUN:   2>&1 | FileCheck -check-prefix=MSVC %s
+
+// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
+// RUN:   --target=x86_64-pc-windows-msvc \
+// RUN:   -nogpulib %s -fgpu-rdc %t/hipBundled2.lib \
+// RUN:   2>&1 | FileCheck -check-prefix=MSVC %s
+
+// GNU1: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}[[LIB:libhipBundled\.a]]" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles"
+// GNU2: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}[[LIB:libhipBundled\.a\.5\.2]]" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles"
 // GNU: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
-// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles"
+// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}[[LIB]]" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles"
 // GNU: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"
-// GNU: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" {{.*}}"-lhipBundled"
+// GNU-L: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" {{.*}}"-lhipBundled"
+// GNU-LA: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" {{.*}}"-l:libhipBundled.a"
+// GNU-A: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" "{{.*}}[[LIB]]"
 
 // MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles"
 // MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
 // MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles"
 // MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"
-// MSVC: "{{.*}}link{{.*}}" {{.*}}"-out:a.exe" {{.*}}"hipBundled2.lib"
+// MSVC: "{{.*}}link{{.*}}" {{.*}}"-out:a.exe" {{.*}}hipBundled2.lib"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1812,85 +1812,101 @@
 return false;
 
   bool FoundAOB = false;
-  SmallVector AOBFileNames;
   std::string ArchiveOfBundles;
-  for (auto LPath : LibraryPaths) {
-ArchiveOfBundles.clear();
-
-llvm::Triple Triple(D.getTargetTriple());
-bool IsMSVC = Triple.isWindowsMSVCEnvironment();
-for (auto Prefix : {"/libdevice/", "/"}) {
-  if (IsMSVC)
-AOBFileNames.push_back(Twine(LPath + Prefix + Lib + ".lib").str());
-  AOBF

[PATCH] D134441: [ObjC][ARC] Don't use operand bundle "clang.arc.attachedcall" in codegen for Windows

2022-09-22 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D134441#3808655 , @sgraenitz wrote:

> The symptom is that Clang emits `movq %rax, %rdi` instead of `movq %rax, 
> %rcx` while `objc_retainAutoreleasedReturnValue()` still expects the value in 
> `%rcx`.
> It appears related to D94597 . Is this a 
> calling convention issue?

Oh right, so a different marker is used on Windows? The code that adds the 
marker is here: 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86ExpandPseudo.cpp#L224

It would probably be better to just add Windows support there. Also, this 
should have a test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134441

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


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2022-09-22 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a subscriber: aaron.ballman.
shafik added a comment.

I made mostly small comments but I think @aaron.ballman and/or @erichkeane 
should take a look as well.




Comment at: clang/lib/Parse/ParseDecl.cpp:3434-3435
  &SS) &&
-  isConstructorDeclarator(/*Unqualified*/ false))
+  isConstructorDeclarator(/*Unqualified*/ false,
+  /*DeductionGuide*/ false,
+  DS.isFriendSpecified()))





Comment at: clang/lib/Parse/ParseDecl.cpp:5592
+bool Parser::isConstructorDeclarator(bool IsUnqualified, bool DeductionGuide,
+ bool IsFriend) {
   TentativeParsingAction TPA(*this);

Instead of adding yet another `bool` flag maybe we can consider using something 
like `enum isFriend : bool {No, Yes}`.

I am sure @aaron.ballman will want to chime in here as well.



Comment at: clang/lib/Parse/ParseTemplate.cpp:20
 #include "clang/Sema/DeclSpec.h"
+#include "clang/Sema/Lookup.h"
 #include "clang/Sema/ParsedTemplate.h"

Do we still need this?



Comment at: clang/lib/Parse/ParseTemplate.cpp:1450
 TemplateArgsPtr, TemplateId->RAngleLoc,
-/*IsCtorOrDtorName*/ false, IsClassName);
+/*IsCtorOrDtorName*/ false, IsClassName, 
AllowImplicitTypename);
   // Create the new "type" annotation token.





Comment at: clang/lib/Sema/Sema.cpp:51
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/TimeProfiler.h"

Do we need this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

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


[PATCH] D134416: Allow getting template args for ClassTemplateSpecializations

2022-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Mostly nits from me (FWIW, we use `auto` when the type is explicitly spelled 
out in the initialization and we don't usually use `else` after an 
unconditional `return` as a matter of coding style.) In terms of the test 
coverage, I would probably make a new test modeled after 
https://github.com/llvm/llvm-project/blob/main/clang/test/Index/cxx14-lambdas.cpp.




Comment at: clang/include/clang-c/Index.h:3594-3595
 /**
- *Returns the number of template args of a function decl representing a
- * template specialization.
+ *Returns the number of template args of a function, struct, or class decl
+ *representing a template specialization.
  *

Since we're in the area already...



Comment at: clang/tools/libclang/CXCursor.cpp:1357
+  CXCursorKind kind = clang_getCursorKind(C);
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
+  kind != CXCursor_ClassDecl &&

`CXCursor_StructDecl` is interesting -- does that only get used in C or will it 
also show up in C++? If it's C-only, we can drop that bit.



Comment at: clang/tools/libclang/CXCursor.cpp:1363
 
-  const FunctionDecl *FD =
-  llvm::dyn_cast_or_null(getCursorDecl(C));
-  if (!FD) {
-return -1;
-  }
-
-  const FunctionTemplateSpecializationInfo *SpecInfo =
-  FD->getTemplateSpecializationInfo();
-  if (!SpecInfo) {
+  if (const FunctionDecl *FD =
+  llvm::dyn_cast_if_present(getCursorDecl(C))) {





Comment at: clang/tools/libclang/CXCursor.cpp:1370-1379
+return SpecInfo->TemplateArguments->size();
+  } else if (const ClassTemplateSpecializationDecl *SD =
+ llvm::dyn_cast_if_present<
+ clang::ClassTemplateSpecializationDecl>(
+ getCursorDecl(C))) {
+return SD->getTemplateArgs().size();
+  } else {





Comment at: clang/tools/libclang/CXCursor.cpp:1403
+  CXCursorKind kind = clang_getCursorKind(C);
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
+  kind != CXCursor_ClassDecl &&

Same question here about struct decl as above.



Comment at: clang/tools/libclang/CXCursor.cpp:1409
 
-  const FunctionDecl *FD =
-  llvm::dyn_cast_or_null(getCursorDecl(C));
-  if (!FD) {
-return CXGetTemplateArgumentStatus_BadFunctionDeclCast;
-  }
+  if (const FunctionDecl *FD =
+  llvm::dyn_cast_if_present(getCursorDecl(C))) {





Comment at: clang/tools/libclang/CXCursor.cpp:1423-1439
+return 0;
+  } else if (const ClassTemplateSpecializationDecl *SD =
+ llvm::dyn_cast_if_present<
+ clang::ClassTemplateSpecializationDecl>(
+ getCursorDecl(C))) {
+if (I >= SD->getTemplateArgs().size()) {
+  printf("INVALID INDEX\n");




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134416

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


[PATCH] D134445: [PR57881][OpenCL] Fix incorrect diagnostics with templated types in kernel arguments

2022-09-22 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

> I have attempted to workaround this issue for the reported test cases, 
> however it still doesn't quite work when the type is created from the 
> template parameter (see FIXME test case in the patch). I presume we want to 
> allow this? If so we might need to disable lazy template instantiation in 
> this case. My guess is the only issue this this is that we will have 
> performance penalty for the code of this format:

I don't have enough experience with lazy template instantiation to give 
meaningful advice here.  Though I'm not too worried about performance penalties 
for the example you're giving, as I'd expect most realistic use cases will 
require the full instantiation of a templated type sooner or later in the 
source program anyway (e.g. near the calling point).

> While this matter might need more thoughts and investigations I wonder 
> whether it makes sense to commit this fix for the time being since it's 
> fixing the reported test case at least?

That sounds reasonable to me; clang currently hard-rejects a valid source due 
to an over-conservative diagnostic which isn't a great user experience.

> So another approach we could take is to change this diagnostics into warnings 
> and then if we can't fully detect the type provide the messaging that we 
> can't detect whether the type is safe...

I think that makes sense, and should be fine to leave as a followup.




Comment at: clang/lib/Sema/SemaDecl.cpp:8856
+ if (CXXRec) {
+   if (!CXXRec->hasDefinition())
+ CXXRec = CXXRec->getTemplateInstantiationPattern();

A comment explaining what we're trying to do here would be nice.



Comment at: clang/test/SemaOpenCLCXX/invalid-kernel.clcpp:99
+struct Outer {
+struct Inner{
+int i;

Indenting would help readability.


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

https://reviews.llvm.org/D134445

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


[PATCH] D134339: [clang][llvm] generate accessibility metadata for type aliases

2022-09-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

I'll commit this shortly.




Comment at: llvm/lib/IR/DIBuilder.cpp:351
 DIScope *Context, uint32_t AlignInBits,
+DINode::DIFlags Flags,
 DINodeArray Annotations) {

J-Camilleri wrote:
> dblaikie wrote:
> > While we usually split llvm & clang commits, in this case since it changes 
> > an API used by clang, this part of the llvm change should go along with the 
> > clang change.
> Regarding this and the previous comment about separating the llvm commit.
> 
> Am I to have 2 commits as follows?
> 1. change llvm to emit flag + test case
> 2. modify llvm interface + change clang to emit flag + test case
> 
> I do not have merge rights so I will ask for this when I get to the merge 
> stage.
> 
> Thanks for the review.
If you don't have commit rights, no worries - I can sort this out when I commit 
this on your behalf.
But yes, your list of the two steps/order/pieces is correct.



Comment at: llvm/test/DebugInfo/X86/debug-info-access.ll:12-32
+;
+; using pub_default_using = int;
+; pub_default_using a_pub;
 ;   };
 ;
 ;   class B : public A {
 ;   public:

J-Camilleri wrote:
> dblaikie wrote:
> > Probably don't need all this test coverage - since most of this is 
> > motivated by the features up in clang - on the LLVM side we just need one 
> > case that demonstrates that if we put an access specifier in the flags, 
> > that gets emitted.
> I left the llvm to be the same as generated by the cpp file but changed the 
> `CHECK` to just verify that the accessibility flag is emitted for a `typedef`.
Ah, makes sense - thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134339

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


[clang] db664a6 - [Doc][OpenCL] Fixed typos in code examples

2022-09-22 Thread Anastasia Stulova via cfe-commits

Author: Anastasia Stulova
Date: 2022-09-22T17:46:47+01:00
New Revision: db664a666c2c0cc144c7827dbdad1b893a63408c

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

LOG: [Doc][OpenCL] Fixed typos in code examples

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 17b2f8a00297b..bbaf31cc9792e 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2136,7 +2136,7 @@ between the host and device is known to be compatible.
   struct OnlySL {
 int a;
 int b;
-NotPod() : a(0), b(0) {}
+OnlySL() : a(0), b(0) {}
   };
 
   // Not standard layout type because of two 
diff erent access controls.
@@ -2144,16 +2144,17 @@ between the host and device is known to be compatible.
 int a;
   private:
 int b;
-  }
+  };
 
+  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable
   kernel void kernel_main(
 Pod a,
-  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : enable
+
 OnlySL b,
 global NotSL *c,
-  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : disable
-global OnlySL *d,
+global OnlySL *d
   );
+  #pragma OPENCL EXTENSION __cl_clang_non_portable_kernel_param_types : disable
 
 Remove address space builtin function
 -



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


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

2022-09-22 Thread Nenad Mikša via Phabricator via cfe-commits
DoDoENT created this revision.
Herald added a project: All.
DoDoENT requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If enabled, it will ensure that full type name is always printed.
This should fix issue reported here: 
https://github.com/llvm/llvm-project/issues/57562

Currently, I've disabled the policy by default, as enabling it makes some tests 
fail, notably:

- CodeGenCXX/debug-info-template.cpp
- SemaCXX/constexpr-printing.cpp
- SemaCXX/cxx2a-nttp-printing.cpp
- SemaTemplate/temp_arg_string_printing.cpp

However, my opinion is that those tests should be updated and new policy always 
enabled, to mimic GCC's behavior.

I've added 2 new tests in AST/TypePrinterTest.cpp, one of which actually 
demonstrates the issue I've had in the first place (which was also reported on 
GitHub).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134453

Files:
  clang/include/clang/AST/PrettyPrinter.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/unittests/AST/TypePrinterTest.cpp

Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -48,7 +48,7 @@
   std::string Code = R"cpp(
 namespace N {
   template  struct Type {};
-  
+
   template 
   void Foo(const Type &Param);
 }
@@ -127,3 +127,86 @@
 Policy.EntireContentsOfLargeArray = true;
   }));
 }
+
+TEST(TypePrinter, TemplateIdWithFullTypeNTTP) {
+  constexpr char Code[] = R"cpp(
+enum struct Encoding { UTF8, ASCII };
+template 
+struct Str {
+  constexpr Str(char const (&s)[N]) { __builtin_memcpy(value, s, N); }
+  char value[N];
+};
+template  class ASCII {};
+
+ASCII<"some string"> x;
+  )cpp";
+  auto Matcher = classTemplateSpecializationDecl(
+  hasName("ASCII"), has(cxxConstructorDecl(
+isMoveConstructor(),
+has(parmVarDecl(hasType(qualType().bind("id")));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(ASCII{"some string"}> &&)",
+  [](PrintingPolicy &Policy) {
+Policy.AlwaysIncludeTypeForNonTypeTemplateArgument = true;
+  }));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher, R"(ASCII<{"some string"}> &&)",
+  [](PrintingPolicy &Policy) {
+Policy.AlwaysIncludeTypeForNonTypeTemplateArgument = false;
+  }));
+}
+
+TEST(TypePrinter, TemplateIdWithComplexFullTypeNTTP) {
+  constexpr char Code[] = R"cpp(
+  template< typename T, auto ... dims >
+  struct NDArray {};
+
+  struct Dimension
+  {
+  using value_type = unsigned short;
+
+  value_type size{ value_type( 0 ) };
+  };
+
+  template < typename ConcreteDim >
+  struct DimensionImpl : Dimension {};
+
+  struct Width: DimensionImpl< Width> {};
+  struct Height   : DimensionImpl< Height   > {};
+  struct Channels : DimensionImpl< Channels > {};
+
+  inline constexpr WidthW;
+  inline constexpr Height   H;
+  inline constexpr Channels C;
+
+  template< auto ... Dims >
+  consteval auto makeArray() noexcept
+  {
+  return NDArray< float, Dims ... >{};
+  }
+
+  [[ maybe_unused ]] auto x { makeArray< H, W, C >() };
+
+  )cpp";
+  auto Matcher = varDecl(
+  allOf(hasAttr(attr::Kind::Unused), hasType(qualType().bind("id";
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(NDArray)",
+  [](PrintingPolicy &Policy) {
+Policy.PrintCanonicalTypes = true;
+Policy.AlwaysIncludeTypeForNonTypeTemplateArgument = false;
+  }));
+
+  ASSERT_TRUE(PrintedTypeMatches(
+  Code, {"-std=c++20"}, Matcher,
+  R"(NDArray{Dimension{0}}}, Width{DimensionImpl{Dimension{0}}}, Channels{DimensionImpl{Dimension{0}}}>)",
+  [](PrintingPolicy &Policy) {
+Policy.PrintCanonicalTypes = true;
+Policy.AlwaysIncludeTypeForNonTypeTemplateArgument = true;
+  }));
+}
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -432,10 +432,11 @@
   }
 
   case Declaration: {
-// FIXME: Include the type if it's not obvious from the context.
 NamedDecl *ND = getAsDecl();
 if (getParamTypeForDecl()->isRecordType()) {
   if (auto *TPO = dyn_cast(ND)) {
+if (Policy.AlwaysIncludeTypeForNonTypeTemplateArgument)
+  TPO->getType().getUnqualifiedType().print(Out, Policy);
 TPO->printAsInit(Out, Policy);
 break;
   }
Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -892,6 +892,8 @@
 assert(BI != CD->bases_end());
 if (!First)
   Out << ", ";
+if (Policy.AlwaysIncludeT

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

2022-09-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/include/clang/AST/PrettyPrinter.h:307
+  /// decltype(s) will be printed as "S" if enabled and as 
"S<{1,2}>" if disabled,
+  /// regardless if PrintCanonicalTypes is enabled.
+  unsigned AlwaysIncludeTypeForNonTypeTemplateArgument : 1;

What does `PrintCanonicalTypes` have to do with this? Does it overlap with this 
functionality in some way, but doesn't provide the functionality you want in 
particular?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

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

I think this is on the right track, but would like to see more work done on 
that fixme before we commit (or at least better understand what is causing 
this).  I'm afraid of what else can get us into that situation besides the 
export-decl.




Comment at: clang/lib/Sema/SemaDecl.cpp:367
+// with this method returning a non-null ParsedType?
+if (isa(CurContext))
+  return nullptr;

Hmm... this scares me quite a bit, I don't really know what other fallout 
results from this, or other code that would hit here.

We should probably spend more time making sure we understand this better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

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


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

2022-09-22 Thread Nenad Mikša via Phabricator via cfe-commits
DoDoENT added inline comments.



Comment at: clang/include/clang/AST/PrettyPrinter.h:307
+  /// decltype(s) will be printed as "S" if enabled and as 
"S<{1,2}>" if disabled,
+  /// regardless if PrintCanonicalTypes is enabled.
+  unsigned AlwaysIncludeTypeForNonTypeTemplateArgument : 1;

dblaikie wrote:
> What does `PrintCanonicalTypes` have to do with this? Does it overlap with 
> this functionality in some way, but doesn't provide the functionality you 
> want in particular?
Thank you for the question. If you set the `PrintCanonicalTypes` to `false`, 
the `S` would be printed as `S` even without this 
patch. However, if you set it to `true`, it will be printed as `S<{1, 2}>`.

I don't fully understand why it does that, but it's quite annoying.

For a better example, please take a look at the 
`TemplateIdWithComplexFullTypeNTTP` unit tests that I've added: if 
`PrintCanonicalTypes` is set to `true`, the original print output of type is 
`NDArray`, and if set to `false` (which is 
default), the output is `NDArray` - so the NTTP type is neither fully written nor fully 
omitted, which is weird.

As I said, I don't really understand the idea behind `PrintCanonicalTypes`, but 
when my new `AlwaysIncludeTypeForNonTypeTemplateArgument` is enabled, you will 
get the full type printed, regardless of value of `PrintCanonicalTypes` setting.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


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

2022-09-22 Thread Adrian Ratiu via Phabricator via cfe-commits
10ne1 created this revision.
10ne1 added reviewers: nickdesaulniers, nathanchance, manojgupta.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
10ne1 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

While cross-compiling Linux kernel tools with Clang on ArchLinux, it
was revealed the sysroot and triplet are not properly detected and
instead of fixing the root cause in Clang, kernel developers started
doing workarounds [1] upon workarounds [2] in the kernel build to be
able to pass a working sysroot and triplet during Clang invocation.

To give a concrete example, ArchLinux installs its cross-compliation
sysroot in /usr/aarch64-linux-gnu for triplet aarch64-linux-gnu.
This causes two problems which this commit fixes:

1. The triplet results in an Unknown OS & Unknown distro. To fix this

error, we call Triplet::normalize() which does the following transform
aarch64-linux-gnu -> aarch64-unknown-linux-gnu, then the OS & Distro
are properly detected.

2. The sysroot under /usr/ itself is not properly detected

in Linux::computeSysRoot() so we add a relative path to the ArchLinux
installed GCC toolchain.

Fixing these two bugs allows to significantly clean up the kernel
build as well as fix the cross-compilation detection on ArchLinux.

[1] 
https://github.com/torvalds/linux/commit/cebdb7374577ac6e14afb11311af8c2c44a259fa
[2] 
https://github.com/torvalds/linux/commit/7fd9fd46a459272e641be78c1cc36baab1921fa1


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134454

Files:
  clang/include/clang/Driver/Distro.h
  clang/lib/Driver/Distro.cpp
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -370,6 +370,16 @@
 return std::string();
   }
 
+  const Distro Distro(getDriver().getVFS(), getTriple());
+  const StringRef InstallDir = GCCInstallation.getInstallPath();
+  const StringRef TripleStr = GCCInstallation.getTriple().str();
+
+  if (Distro.IsArchLinux()) {
+std::string Path = (InstallDir + "/../../../../"  + TripleStr).str();
+if (getVFS().exists(Path))
+  return Path;
+  }
+
   if (!GCCInstallation.isValid() || !getTriple().isMIPS())
 return std::string();
 
@@ -377,8 +387,6 @@
   // and put it into different places. Here we try to check some known
   // variants.
 
-  const StringRef InstallDir = GCCInstallation.getInstallPath();
-  const StringRef TripleStr = GCCInstallation.getTriple().str();
   const Multilib &Multilib = GCCInstallation.getMultilib();
 
   std::string Path =
Index: clang/lib/Driver/Distro.cpp
===
--- clang/lib/Driver/Distro.cpp
+++ clang/lib/Driver/Distro.cpp
@@ -205,9 +205,16 @@
 
 static Distro::DistroType GetDistro(llvm::vfs::FileSystem &VFS,
 const llvm::Triple &TargetOrHost) {
+
+  // Sometimes the OS can't be detected from the triplet due to ambiguity, for
+  // eg. ArchLinux uses aarch64-linux-gnu which results in Uknonwn OS & distro,
+  // so normalize the triplet which results in aarch64-unknown-linux-gnu, such
+  // that the Linux OS and distro are properly detected in this cases.
+  llvm::Triple NormTargetOrHost = 
llvm::Triple(Twine(TargetOrHost.normalize()));
+
   // If we don't target Linux, no need to check the distro. This saves a few
   // OS calls.
-  if (!TargetOrHost.isOSLinux())
+  if (!NormTargetOrHost.isOSLinux())
 return Distro::UnknownDistro;
 
   // True if we're backed by a real file system.
Index: clang/include/clang/Driver/Distro.h
===
--- clang/include/clang/Driver/Distro.h
+++ clang/include/clang/Driver/Distro.h
@@ -134,6 +134,8 @@
 
   bool IsGentoo() const { return DistroVal == Gentoo; }
 
+  bool IsArchLinux() const { return DistroVal == ArchLinux; }
+
   /// @}
 };
 


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -370,6 +370,16 @@
 return std::string();
   }
 
+  const Distro Distro(getDriver().getVFS(), getTriple());
+  const StringRef InstallDir = GCCInstallation.getInstallPath();
+  const StringRef TripleStr = GCCInstallation.getTriple().str();
+
+  if (Distro.IsArchLinux()) {
+std::string Path = (InstallDir + "/../../../../"  + TripleStr).str();
+if (getVFS().exists(Path))
+  return Path;
+  }
+
   if (!GCCInstallation.isValid() || !getTriple().isMIPS())
 return std::string();
 
@@ -377,8 +387,6 @@
   // and put it into different places. Here we try to check some known
   // variants.
 
-  const StringRef InstallDir = GCCInstallation.getInstallPath();
-  const StringRef TripleStr = GCCInstallation.getTriple

[clang] 9018fa1 - Update the C status page for WG14 N2359

2022-09-22 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-09-22T13:05:49-04:00
New Revision: 9018fa174598ab53567ef36b4bd171f47daf14f5

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

LOG: Update the C status page for WG14 N2359

We don't yet implement this paper, so this adds a basic test
demonstrating that.

Added: 
clang/test/C/C2x/n2359.c

Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C2x/n2359.c
new file mode 100644
index 0..3a6641fbeaede
--- /dev/null
+++ b/clang/test/C/C2x/n2359.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -verify -std=c2x -ffreestanding %s
+
+/* WG14 N2359: no
+ * Remove conditional "WANT" macros from numbered clauses
+ */
+
+#include 
+#ifndef __STDC_VERSION_LIMITS_H__
+#error "__STDC_VERSION_LIMITS_H__ not defined"
+// expected-error@-1 {{"__STDC_VERSION_LIMITS_H__ not defined"}}
+#endif
+
+#include 
+#ifndef __STDC_VERSION_STDARG_H__
+#error "__STDC_VERSION_STDARG_H__ not defined"
+// expected-error@-1 {{"__STDC_VERSION_STDARG_H__ not defined"}}
+#endif
+
+#include 
+#ifndef __STDC_VERSION_STDATOMIC_H__
+#error "__STDC_VERSION_STDATOMIC_H__ not defined"
+// expected-error@-1 {{"__STDC_VERSION_STDATOMIC_H__ not defined"}}
+#endif
+
+#include 
+#ifndef __STDC_VERSION_STDDEF_H__
+#error "__STDC_VERSION_STDDEF_H__ not defined"
+// expected-error@-1 {{"__STDC_VERSION_STDDEF_H__ not defined"}}
+#endif
+
+#include 
+#ifndef __STDC_VERSION_STDINT_H__
+#error "__STDC_VERSION_STDINT_H__ not defined"
+// expected-error@-1 {{"__STDC_VERSION_STDINT_H__ not defined"}}
+#endif
+

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 395bdf5d22da9..6333a0f07191f 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -675,7 +675,7 @@ C2x implementation status
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2359.pdf";>N2359
-Unknown
+No
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2546.pdf";>N2546



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


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2022-09-22 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 46.
ayzhao marked 2 inline comments as done.
ayzhao added a comment.

address some review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/drs/dr4xx.cpp
  clang/test/CXX/drs/dr5xx.cpp
  clang/test/CXX/temp/temp.res/p3.cpp
  clang/test/CXX/temp/temp.res/p4.cpp
  clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp
  clang/test/FixIt/fixit.cpp
  clang/test/Parser/cxx-member-initializers.cpp
  clang/test/SemaCXX/MicrosoftCompatibility.cpp
  clang/test/SemaCXX/MicrosoftExtensions.cpp
  clang/test/SemaCXX/MicrosoftSuper.cpp
  clang/test/SemaCXX/rounding-math-crash.cpp
  clang/test/SemaCXX/typo-correction.cpp
  clang/test/SemaCXX/unknown-type-name.cpp
  clang/test/SemaTemplate/alias-templates.cpp
  clang/test/SemaTemplate/typename-specifier-3.cpp

Index: clang/test/SemaTemplate/typename-specifier-3.cpp
===
--- clang/test/SemaTemplate/typename-specifier-3.cpp
+++ clang/test/SemaTemplate/typename-specifier-3.cpp
@@ -28,7 +28,7 @@
   typedef int arg;
 };
 struct C {
-  typedef B::X x; // expected-error {{missing 'typename'}}
+  typedef B::X x; // precxx17-warning{{missing 'typename' prior to dependent type name B::X; implicit 'typename' is a C++20 extension}}
 };
   };
 
Index: clang/test/SemaTemplate/alias-templates.cpp
===
--- clang/test/SemaTemplate/alias-templates.cpp
+++ clang/test/SemaTemplate/alias-templates.cpp
@@ -193,11 +193,10 @@
   struct base {
 template  struct derived;
   };
-  // FIXME: The diagnostics here are terrible.
   template 
-  using derived = base::template derived; // expected-error {{expected a type}} expected-error {{expected ';'}}
+  using derived = base::template derived; // expected-warning {{missing 'typename'}}
   template 
-  using derived2 = ::PR16904::base::template derived; // expected-error {{expected a type}} expected-error {{expected ';'}}
+  using derived2 = ::PR16904::base::template derived; // expected-warning {{missing 'typename'}}
 }
 
 namespace PR14858 {
Index: clang/test/SemaCXX/unknown-type-name.cpp
===
--- clang/test/SemaCXX/unknown-type-name.cpp
+++ clang/test/SemaCXX/unknown-type-name.cpp
@@ -36,15 +36,15 @@
 
   static int n;
   static type m;
-  static int h(T::type, int); // expected-error{{missing 'typename'}}
-  static int h(T::type x, char); // expected-error{{missing 'typename'}}
+  static int h(T::type, int); // expected-warning{{implicit 'typename' is a C++20 extension}}
+  static int h(T::type x, char); // expected-warning{{implicit 'typename' is a C++20 extension}}
 };
 
 template
-A::type g(T t) { return t; } // expected-error{{missing 'typename'}}
+A::type g(T t) { return t; } // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template
-A::type A::f() { return type(); } // expected-error{{missing 'typename'}}
+A::type A::f() { return type(); } // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template
 void f(T::type) { } // expected-error{{missing 'typename'}}
@@ -84,11 +84,11 @@
 
 template int A::n(T::value); // ok
 template
-A::type // expected-error{{missing 'typename'}}
+A::type // expected-warning {{implicit 'typename' is a C++20 extension}}
 A::m(T::value, 0); // ok
 
-template int A::h(T::type, int) {} // expected-error{{missing 'typename'}}
-template int A::h(T::type x, char) {} // expected-error{{missing 'typename'}}
+template int A::h(T::type, int) {} // expected-warning{{implicit 'typename' is a C++20 extension}}
+template int A::h(T::type x, char) {} // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template int h(T::type, int); // expected-error{{missing 'typename'}}
 template int h(T::type x, char); // expected-error{{missing 'typename'}}
@@ -116,4 +116,5 @@
 // FIXME: We know which type specifier should have been specified here. Provide
 //a fix-it to add 'typename A::type'
 template
-A::g() { } // expected-error{{a type specifier is required}}
+A::g() { } // expected-error{{expected unqualified-id}}
+// expected-warning@-1{{implicit 'typename' is a C++20 extension}}
Index: clang/test/

[PATCH] D134339: [clang][llvm] generate accessibility metadata for type aliases

2022-09-22 Thread David Blaikie 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 rG08288052aef2: [DebugInfo] Emit access specifiers for 
typedefs (authored by J-Camilleri, committed by dblaikie).

Changed prior to commit:
  https://reviews.llvm.org/D134339?vs=462092&id=462223#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134339

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/X86/debug-info-access.ll

Index: llvm/test/DebugInfo/X86/debug-info-access.ll
===
--- llvm/test/DebugInfo/X86/debug-info-access.ll
+++ llvm/test/DebugInfo/X86/debug-info-access.ll
@@ -15,8 +15,14 @@
 ;   public:
 ; void pub();
 ; static int public_static;
+;
 ;   protected:
+; typedef int prot_typedef;
+; using prot_using = prot_typedef;
+; prot_using prot_member;
+;
 ; void prot();
+;
 ;   private:
 ; void priv_default();
 ;   };
@@ -28,9 +34,13 @@
 ;   protected:
 ; union E {
 ; };
+;   private:
+; struct J {
+; };
 ;   public:
 ; D d;
 ; E e;
+; J j;
 ;   };
 ;
 ;   struct F {
@@ -57,9 +67,9 @@
 ;
 ;   void free() {}
 ;
+;   U u;
 ;   A a;
 ;   B b;
-;   U u;
 ;   C c;
 ;   F f;
 ;   H h;
@@ -92,6 +102,14 @@
 ; CHECK-NOT: DW_TAG
 ; CHECK: DW_AT_accessibility {{.*}}(DW_ACCESS_public)
 
+; CHECK: DW_TAG_member
+; CHECK: DW_AT_name {{.*}}"prot_member")
+
+; CHECK: DW_TAG_typedef
+; CHECK: DW_AT_name {{.*}}"prot_using")
+; CHECK-NOT: DW_TAG
+; CHECK: DW_AT_accessibility {{.*}}(DW_ACCESS_protected)
+
 ; CHECK: DW_TAG_subprogram
 ; CHECK: DW_AT_name {{.*}}"pub")
 ; CHECK-NOT: DW_TAG
@@ -130,42 +148,43 @@
 
 %union.U = type { i32 }
 %struct.A = type { i8 }
-%class.B = type { i8 }
-%class.C = type { %"struct.C::D", %"union.C::E" }
+%class.B = type { i32 }
+%class.C = type { %"struct.C::D", %"union.C::E", %"struct.C::J" }
 %"struct.C::D" = type { i8 }
 %"union.C::E" = type { i8 }
+%"struct.C::J" = type { i8 }
 %struct.F = type { %"union.F::G" }
 %"union.F::G" = type { i8 }
 %union.H = type { %"class.H::I" }
 %"class.H::I" = type { i8 }
 
-@u = global %union.U zeroinitializer, align 4, !dbg !0
-@a = global %struct.A zeroinitializer, align 1, !dbg !5
-@b = global %class.B zeroinitializer, align 1, !dbg !16
-@c = global %class.C zeroinitializer, align 1, !dbg !28
-@f = global %struct.F zeroinitializer, align 1, !dbg !37
-@h = global %union.H zeroinitializer, align 1, !dbg !43
+@u = dso_local global %union.U zeroinitializer, align 4, !dbg !0
+@a = dso_local global %struct.A zeroinitializer, align 1, !dbg !5
+@b = dso_local global %class.B zeroinitializer, align 4, !dbg !16
+@c = dso_local global %class.C zeroinitializer, align 1, !dbg !31
+@f = dso_local global %struct.F zeroinitializer, align 1, !dbg !42
+@h = dso_local global %union.H zeroinitializer, align 1, !dbg !48
 
-; Function Attrs: mustprogress noinline nounwind optnone
-define dso_local void @_Z4freev() #0 !dbg !59 {
+; Function Attrs: mustprogress noinline nounwind optnone uwtable
+define dso_local void @_Z4freev() #0 !dbg !69 {
 entry:
-  ret void, !dbg !62
+  ret void, !dbg !72
 }
 
-attributes #0 = { mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
+attributes #0 = { mustprogress noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
 
 !llvm.dbg.cu = !{!2}
-!llvm.module.flags = !{!56, !57}
-!llvm.ident = !{!58}
+!llvm.module.flags = !{!61, !62, !63, !64, !65, !66, !67}
+!llvm.ident = !{!68}
 
 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
-!1 = distinct !DIGlobalVariable(name: "u", scope: !2, file: !7, line: 73, type: !49, isLocal: false, isDefinition: true)
-!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
-!3 = !DIFile(filename: "clang/test/CodeGenCXX/", directory: "")
-!4 = !{!0, !5, !16, !28, !37, !43}
+!1 = distinct !DIGlobalVariable(name: "u", scope: !2, file: !7, line: 86, type: !54, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 16.0.0 (https://github.com/llvm/llvm-project.git 113a643a597b6a8f68099fedbeb7509449d4bd50)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "/home/jon/sources/llvm-project/clang/test/CodeGenCXX/debug-info-access.cpp

[clang] 4cd7529 - [clang][DebugInfo] Emit access specifiers for typedefs

2022-09-22 Thread David Blaikie via cfe-commits

Author: Jonathan Camilleri
Date: 2022-09-22T17:08:41Z
New Revision: 4cd7529e4caa00fa7ba27d9de18adea3c702ad8f

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

LOG: [clang][DebugInfo] Emit access specifiers for typedefs

The accessibility level of a typedef or using declaration in a
struct or class was being lost when producing debug information.

Reviewed By: dblaikie

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-access.cpp
llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 73cb80816fae7..a5cc5930728aa 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1283,6 +1283,33 @@ llvm::DIType *CGDebugInfo::CreateType(const 
TemplateSpecializationType *Ty,
 getDeclContextDescriptor(AliasDecl));
 }
 
+/// Convert an AccessSpecifier into the corresponding DINode flag.
+/// As an optimization, return 0 if the access specifier equals the
+/// default for the containing type.
+static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access,
+   const RecordDecl *RD) {
+  AccessSpecifier Default = clang::AS_none;
+  if (RD && RD->isClass())
+Default = clang::AS_private;
+  else if (RD && (RD->isStruct() || RD->isUnion()))
+Default = clang::AS_public;
+
+  if (Access == Default)
+return llvm::DINode::FlagZero;
+
+  switch (Access) {
+  case clang::AS_private:
+return llvm::DINode::FlagPrivate;
+  case clang::AS_protected:
+return llvm::DINode::FlagProtected;
+  case clang::AS_public:
+return llvm::DINode::FlagPublic;
+  case clang::AS_none:
+return llvm::DINode::FlagZero;
+  }
+  llvm_unreachable("unexpected access enumerator");
+}
+
 llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
   llvm::DIFile *Unit) {
   llvm::DIType *Underlying =
@@ -1298,10 +1325,16 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType 
*Ty,
   uint32_t Align = getDeclAlignIfRequired(Ty->getDecl(), CGM.getContext());
   // Typedefs are derived from some other type.
   llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(Ty->getDecl());
+
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
+  const DeclContext *DC = Ty->getDecl()->getDeclContext();
+  if (isa(DC))
+Flags = getAccessFlag(Ty->getDecl()->getAccess(), cast(DC));
+
   return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
 getOrCreateFile(Loc), getLineNumber(Loc),
 getDeclContextDescriptor(Ty->getDecl()), Align,
-Annotations);
+Flags, Annotations);
 }
 
 static unsigned getDwarfCC(CallingConv CC) {
@@ -1395,33 +1428,6 @@ llvm::DIType *CGDebugInfo::CreateType(const FunctionType 
*Ty,
   return F;
 }
 
-/// Convert an AccessSpecifier into the corresponding DINode flag.
-/// As an optimization, return 0 if the access specifier equals the
-/// default for the containing type.
-static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access,
-   const RecordDecl *RD) {
-  AccessSpecifier Default = clang::AS_none;
-  if (RD && RD->isClass())
-Default = clang::AS_private;
-  else if (RD && (RD->isStruct() || RD->isUnion()))
-Default = clang::AS_public;
-
-  if (Access == Default)
-return llvm::DINode::FlagZero;
-
-  switch (Access) {
-  case clang::AS_private:
-return llvm::DINode::FlagPrivate;
-  case clang::AS_protected:
-return llvm::DINode::FlagProtected;
-  case clang::AS_public:
-return llvm::DINode::FlagPublic;
-  case clang::AS_none:
-return llvm::DINode::FlagZero;
-  }
-  llvm_unreachable("unexpected access enumerator");
-}
-
 llvm::DIType *CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl,
   llvm::DIScope *RecordTy,
   const RecordDecl *RD) {

diff  --git a/clang/test/CodeGenCXX/debug-info-access.cpp 
b/clang/test/CodeGenCXX/debug-info-access.cpp
index cd5328be0a85c..9f2c044843d0f 100644
--- a/clang/test/CodeGenCXX/debug-info-access.cpp
+++ b/clang/test/CodeGenCXX/debug-info-access.cpp
@@ -9,7 +9,6 @@ struct A {
   static int pub_default_static;
 };
 
-
 // CHECK: !DIDerivedType(tag: DW_TAG_inheritance,{{.*}} baseType: 
![[A]],{{.*}} flags: DIFlagPublic, extraData: i32 0)
 class B : public A {
 public:
@@ -17,9 +16,17 @@ class B : public A {
   void pub();
   // CHECK-DAG: !DIDerivedType(tag: DW_TAG_member, name: 
"publi

[clang-tools-extra] 0ca5993 - [clang-tidy] Add option WarnOnSizeOfPointerToAggregate.

2022-09-22 Thread Michael Benfield via cfe-commits

Author: Michael Benfield
Date: 2022-09-22T17:09:43Z
New Revision: 0ca5993741877ab7fd27a251cbc1895bd092d5ee

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

LOG: [clang-tidy] Add option WarnOnSizeOfPointerToAggregate.

This is now an option under the check bugprone-sizeof-expression.

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index fe5c80658f268..57086af9c7031 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -67,7 +67,9 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
   Options.get("WarnOnSizeOfIntegerExpression", false)),
   WarnOnSizeOfThis(Options.get("WarnOnSizeOfThis", true)),
   WarnOnSizeOfCompareToConstant(
-  Options.get("WarnOnSizeOfCompareToConstant", true)) {}
+  Options.get("WarnOnSizeOfCompareToConstant", true)),
+  WarnOnSizeOfPointerToAggregate(
+  Options.get("WarnOnSizeOfPointerToAggregate", true)) {}
 
 void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -76,6 +78,8 @@ void 
SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfThis", WarnOnSizeOfThis);
   Options.store(Opts, "WarnOnSizeOfCompareToConstant",
 WarnOnSizeOfCompareToConstant);
+  Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
+WarnOnSizeOfPointerToAggregate);
 }
 
 void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -135,46 +139,48 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
 
   // Detect sizeof(ptr) where ptr points to an aggregate (i.e. sizeof(&S)).
   // Do not find it if RHS of a 'sizeof(arr) / sizeof(arr[0])' expression.
-  const auto ArrayExpr =
-  ignoringParenImpCasts(hasType(hasCanonicalType(arrayType(;
-  const auto ArrayCastExpr = expr(anyOf(
-  unaryOperator(hasUnaryOperand(ArrayExpr), unless(hasOperatorName("*"))),
-  binaryOperator(hasEitherOperand(ArrayExpr)),
-  castExpr(hasSourceExpression(ArrayExpr;
-  const auto PointerToArrayExpr = ignoringParenImpCasts(
-  hasType(hasCanonicalType(pointerType(pointee(arrayType());
-
-  const auto StructAddrOfExpr = unaryOperator(
-  hasOperatorName("&"), hasUnaryOperand(ignoringParenImpCasts(
-hasType(hasCanonicalType(recordType());
-  const auto PointerToStructType =
-  hasUnqualifiedDesugaredType(pointerType(pointee(recordType(;
-  const auto PointerToStructExpr = ignoringParenImpCasts(expr(
-  hasType(hasCanonicalType(PointerToStructType)), unless(cxxThisExpr(;
-
-  const auto ArrayOfPointersExpr = ignoringParenImpCasts(
-  hasType(hasCanonicalType(arrayType(hasElementType(pointerType()))
-   .bind("type-of-array-of-pointers";
-  const auto ArrayOfSamePointersExpr =
-  ignoringParenImpCasts(hasType(hasCanonicalType(
-  arrayType(equalsBoundNode("type-of-array-of-pointers");
-  const auto ZeroLiteral = ignoringParenImpCasts(integerLiteral(equals(0)));
-  const auto ArrayOfSamePointersZeroSubscriptExpr =
-  
ignoringParenImpCasts(arraySubscriptExpr(hasBase(ArrayOfSamePointersExpr),
-   hasIndex(ZeroLiteral)));
-  const auto ArrayLengthExprDenom =
-  expr(hasParent(expr(ignoringParenImpCasts(binaryOperator(
-   hasOperatorName("/"), hasLHS(ignoringParenImpCasts(sizeOfExpr(
- has(ArrayOfPointersExpr,
-   sizeOfExpr(has(ArrayOfSamePointersZeroSubscriptExpr)));
-
-  Finder->addMatcher(expr(anyOf(sizeOfExpr(has(ignoringParenImpCasts(anyOf(
-ArrayCastExpr, PointerToArrayExpr,
-StructAddrOfExpr, PointerToStructExpr,
-sizeOfExpr(has(PointerToStructType))),
-  unless(ArrayLengthExprDenom))
- .bind("sizeof-pointer-to-aggregate"),
- this);
+  if (WarnOnSizeOfPointerToAggregate) {
+const auto ArrayExpr =
+ignoringParenImpCasts(hasType(hasCanonicalType(arrayType(;
+const auto Arra

[PATCH] D134381: [clang-tidy] Add option WarnOnSizeOfPointerToAggregate.

2022-09-22 Thread Michael Benfield 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 rG0ca599374187: [clang-tidy] Add option 
WarnOnSizeOfPointerToAggregate. (authored by mbenfield).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134381

Files:
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp
@@ -0,0 +1,76 @@
+// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t -- -config="{CheckOptions: [{key: bugprone-sizeof-expression.WarnOnSizeOfPointerToAggregate, value: false}]}" --
+
+class C {
+  int size() { return sizeof(this); }
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(this)'
+};
+
+#pragma pack(1)
+struct  S { char a, b, c; };
+
+int Test5() {
+  typedef int Array10[10];
+  typedef C ArrayC[10];
+
+  struct MyStruct {
+Array10 arr;
+Array10* ptr;
+  };
+  typedef const MyStruct TMyStruct;
+  typedef const MyStruct *PMyStruct;
+  typedef TMyStruct *PMyStruct2;
+
+  static TMyStruct kGlocalMyStruct = {};
+  static TMyStruct volatile * kGlocalMyStructPtr = &kGlocalMyStruct;
+
+  MyStruct S;
+  PMyStruct PS;
+  PMyStruct2 PS2;
+  Array10 A10;
+  C *PtrArray[10];
+  C *PC;
+
+  int sum = 0;
+  sum += sizeof(&S.arr);
+  // No warning.
+  sum += sizeof(&kGlocalMyStruct.arr);
+  // No warning.
+  sum += sizeof(&kGlocalMyStructPtr->arr);
+  // No warning.
+  sum += sizeof(S.arr + 0);
+  // No warning.
+  sum += sizeof(+ S.arr);
+  // No warning.
+  sum += sizeof((int*)S.arr);
+  // No warning.
+
+  sum += sizeof(S.ptr);
+  // No warning.
+  sum += sizeof(kGlocalMyStruct.ptr);
+  // No warning.
+  sum += sizeof(kGlocalMyStructPtr->ptr);
+  // No warning.
+
+  sum += sizeof(&kGlocalMyStruct);
+  // No warning.
+  sum += sizeof(&S);
+  // No warning.
+  sum += sizeof(MyStruct*);
+  sum += sizeof(PMyStruct);
+  sum += sizeof(PS);
+  // No warning.
+  sum += sizeof(PS2);
+  // No warning.
+  sum += sizeof(&A10);
+  // No warning.
+  sum += sizeof(PtrArray) / sizeof(PtrArray[1]);
+  // No warning.
+  sum += sizeof(A10) / sizeof(PtrArray[0]);
+  // No warning.
+  sum += sizeof(PC) / sizeof(PtrArray[0]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
+  sum += sizeof(ArrayC) / sizeof(PtrArray[0]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
+
+  return sum;
+}
Index: clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
@@ -31,6 +31,7 @@
   const bool WarnOnSizeOfIntegerExpression;
   const bool WarnOnSizeOfThis;
   const bool WarnOnSizeOfCompareToConstant;
+  const bool WarnOnSizeOfPointerToAggregate;
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -67,7 +67,9 @@
   Options.get("WarnOnSizeOfIntegerExpression", false)),
   WarnOnSizeOfThis(Options.get("WarnOnSizeOfThis", true)),
   WarnOnSizeOfCompareToConstant(
-  Options.get("WarnOnSizeOfCompareToConstant", true)) {}
+  Options.get("WarnOnSizeOfCompareToConstant", true)),
+  WarnOnSizeOfPointerToAggregate(
+  Options.get("WarnOnSizeOfPointerToAggregate", true)) {}
 
 void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -76,6 +78,8 @@
   Options.store(Opts, "WarnOnSizeOfThis", WarnOnSizeOfThis);
   Options.store(Opts, "WarnOnSizeOfCompareToConstant",
 WarnOnSizeOfCompareToConstant);
+  Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
+WarnOnSizeOfPointerToAggregate);
 }
 
 void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -135,46 +139,48 @@
 
   // Detect sizeof(ptr) where ptr points to an aggregate (i.e. sizeof(&S)).
   // Do not find it if RHS of a 'sizeof(arr) / sizeof(arr[0])' expression.
-  const auto ArrayExpr =
-  ignoringParenImpCasts(hasType(hasCanonicalType(arrayTyp

[PATCH] D133853: [AST] Add msvc-specific C++11 attributes

2022-09-22 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added a comment.

> Now I'm wondering why the attribute exists at all. If it's functionally 
> equivalent to `constexpr` as a keyword, what are the use cases for the 
> attribute?

I'm guessing something to do with ABI-compatibility with artefacts produced by 
their older compilers (though I have no idea what scenario they have come up 
with that would break). It's also for a very recent version (17.3, the last 
non-preview release as of writing), and I cannot find documentation for it.

Though while searching for it, I stumbled over 
https://reviews.llvm.org/D110485, which relates to `[[no_unique_address]]` & 
how it's incompatible to use it for clang on windows if MSVC doesn't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133853

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


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

2022-09-22 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Thanks for the patch. Can you please post a full diff (git diff -U).

Adding @MaskRay as a reviewer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134454

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


[PATCH] D134456: [PGO] Consider parent context when weighing branches with likelyhood.

2022-09-22 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev created this revision.
AntonBikineev added a reviewer: hans.
Herald added a subscriber: wenlei.
Herald added a project: All.
AntonBikineev requested review of this revision.
Herald added a project: clang.

Generally, with PGO enabled the C++20 likelyhood attributes shall be
dropped assuming the profile has a good coverage. However, currently
this is not the case for the following code:

  if (always_false()) [[likely]] {
...
  }


The patch fixes this and drops the attribute, if the parent context was
executed in the profile. The patch still preserves the attribute, if the
parent context was not executed, e.g. to support the cases when the
profile has insufficient coverage and the programmer's assumption is
correct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134456

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/Profile/Inputs/cxx-never-executed-branch.proftext
  clang/test/Profile/cxx-never-executed-branch.cpp


Index: clang/test/Profile/cxx-never-executed-branch.cpp
===
--- /dev/null
+++ clang/test/Profile/cxx-never-executed-branch.cpp
@@ -0,0 +1,32 @@
+// Test the clang doesn't emit llvm.expect when the counter is 0
+
+// RUN: llvm-profdata merge %S/Inputs/cxx-never-executed-branch.proftext -o 
%t.profdata
+// RUN: %clang_cc1 -std=c++20 %s -O2 -o - -emit-llvm 
-fprofile-instrument-use-path=%t.profdata -disable-llvm-passes | FileCheck %s
+
+int rand();
+
+// CHECK: define {{.*}}@_Z13is_in_profilev
+// CHECK-NOT: call {{.*}}@llvm.expect
+
+int is_in_profile() {
+  int rando = rand();
+  int x = 0;
+  if (rando == 0) [[likely]]
+x = 2;
+  else
+x = 3;
+  return x;
+}
+
+// CHECK: define {{.*}}@_Z17is_not_in_profilev
+// CHECK: call {{.*}}@llvm.expect
+
+int is_not_in_profile() {
+  int rando = rand();
+  int x = 0;
+  if (rando == 0) [[likely]]
+x = 2;
+  else
+x = 3;
+  return x;
+}
Index: clang/test/Profile/Inputs/cxx-never-executed-branch.proftext
===
--- /dev/null
+++ clang/test/Profile/Inputs/cxx-never-executed-branch.proftext
@@ -0,0 +1,13 @@
+_Z13is_in_profilev
+0x00029f493458
+2
+2
+# The branch is never executed.
+0
+
+_Z17is_not_in_profilev
+0x00029f493458
+2
+# The function was never executed
+0
+0
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -815,11 +815,21 @@
   // Prefer the PGO based weights over the likelihood attribute.
   // When the build isn't optimized the metadata isn't used, so don't generate
   // it.
+  // Also, differentiate between disabled PGO and a never executed branch with
+  // PGO. Assuming PGO is in use:
+  // - we want to ignore the [[likely]] attribute if the branch is never
+  // executed,
+  // - assuming the profile is poor, preserving the attribute may still be
+  // beneficial.
+  // As an approximation, preserve the attribute only if both the branch and 
the
+  // parent context were not executed.
   Stmt::Likelihood LH = Stmt::LH_None;
-  uint64_t Count = getProfileCount(S.getThen());
-  if (!Count && CGM.getCodeGenOpts().OptimizationLevel)
+  uint64_t ThenCount = getProfileCount(S.getThen());
+  if (!ThenCount && !getCurrentProfileCount() &&
+  CGM.getCodeGenOpts().OptimizationLevel) {
 LH = Stmt::getLikelihood(S.getThen(), S.getElse());
-  EmitBranchOnBoolExpr(S.getCond(), ThenBlock, ElseBlock, Count, LH);
+  }
+  EmitBranchOnBoolExpr(S.getCond(), ThenBlock, ElseBlock, ThenCount, LH);
 
   // Emit the 'then' code.
   EmitBlock(ThenBlock);


Index: clang/test/Profile/cxx-never-executed-branch.cpp
===
--- /dev/null
+++ clang/test/Profile/cxx-never-executed-branch.cpp
@@ -0,0 +1,32 @@
+// Test the clang doesn't emit llvm.expect when the counter is 0
+
+// RUN: llvm-profdata merge %S/Inputs/cxx-never-executed-branch.proftext -o %t.profdata
+// RUN: %clang_cc1 -std=c++20 %s -O2 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -disable-llvm-passes | FileCheck %s
+
+int rand();
+
+// CHECK: define {{.*}}@_Z13is_in_profilev
+// CHECK-NOT: call {{.*}}@llvm.expect
+
+int is_in_profile() {
+  int rando = rand();
+  int x = 0;
+  if (rando == 0) [[likely]]
+x = 2;
+  else
+x = 3;
+  return x;
+}
+
+// CHECK: define {{.*}}@_Z17is_not_in_profilev
+// CHECK: call {{.*}}@llvm.expect
+
+int is_not_in_profile() {
+  int rando = rand();
+  int x = 0;
+  if (rando == 0) [[likely]]
+x = 2;
+  else
+x = 3;
+  return x;
+}
Index: clang/test/Profile/Inputs/cxx-never-executed-branch.proftext
===
--- /dev/null
+++ clang/test/Profile/Inputs/cxx-never-executed-branch.proftext
@@ -0,0 +1,13 @@
+_Z13is_in_profilev
+0x00029f493458
+2
+2
+# The branch is never executed.
+0
+
+_Z17is_not_in_profilev
+

[PATCH] D134457: Document WarnOnSizeOfPointerToAggregate.

2022-09-22 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield created this revision.
mbenfield added a reviewer: mizvekov.
Herald added a project: All.
mbenfield requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This option was just landed in D134381 . It 
would make sense to actually
document it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134457

Files:
  clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
@@ -187,3 +187,9 @@
When `true`, the check will warn on an expression like
``sizeof(expr) <= k`` for a suspicious constant `k` while `k` is `0` or
greater than `0x8000`. Default is `true`.
+
+.. option:: WarnOnSizeOfPointerToAggregate
+
+   When `true, the check will warn on an expression like
+   ``sizeof(expr)`` where the expression is a pointer
+   to aggregate. Default is `true`.


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
@@ -187,3 +187,9 @@
When `true`, the check will warn on an expression like
``sizeof(expr) <= k`` for a suspicious constant `k` while `k` is `0` or
greater than `0x8000`. Default is `true`.
+
+.. option:: WarnOnSizeOfPointerToAggregate
+
+   When `true, the check will warn on an expression like
+   ``sizeof(expr)`` where the expression is a pointer
+   to aggregate. Default is `true`.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133959: Add clang flag equivalent to clang-cl /Zl flag

2022-09-22 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 462230.
akhuang marked an inline comment as done.
akhuang added a comment.

Fix flag name in test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133959

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-runtime-flags.c


Index: clang/test/Driver/cl-runtime-flags.c
===
--- clang/test/Driver/cl-runtime-flags.c
+++ clang/test/Driver/cl-runtime-flags.c
@@ -97,6 +97,9 @@
 
 // RUN: %clang_cl -### /Zl -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTZl %s
 // RUN: %clang_cl -### /MT /Zl -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTZl 
%s
+// RUN: %clang -### --target=x86_64-windows-msvc -fms-runtime-lib=static \
+// RUN:   -fms-omit-default-lib -- %s 2>&1 | FileCheck \
+// RUN:   -check-prefix=CHECK-MTZl %s
 // CHECK-MTZl-NOT: "-D_DEBUG"
 // CHECK-MTZl: "-D_MT"
 // CHECK-MTZl-NOT: "-D_DLL"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4499,7 +4499,7 @@
 llvm_unreachable("Unexpected option ID.");
   }
 
-  if (Args.hasArg(options::OPT__SLASH_Zl)) {
+  if (Args.hasArg(options::OPT_fms_omit_default_lib)) {
 CmdArgs.push_back("-D_VC_NODEFAULTLIB");
   } else {
 CmdArgs.push_back(FlagForCRT.data());
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2227,6 +2227,8 @@
 to the cl flags /MT and /MTd which use the multithread, static version. "dll"
 and "dll_dbg" correspond to the cl flags /MD and /MDd which use the 
multithread,
 dll version.}]>;
+def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">,
+  Group, Flags<[NoXarchOption, CoreOption]>;
 defm delayed_template_parsing : BoolFOption<"delayed-template-parsing",
   LangOpts<"DelayedTemplateParsing">, DefaultFalse,
   PosFlag,
@@ -6784,7 +6786,7 @@
   HelpText<"Volatile loads and stores have acquire and release semantics">;
 def _SLASH_clang : CLJoined<"clang:">,
   HelpText<"Pass  to the clang driver">, MetaVarName<"">;
-def _SLASH_Zl : CLFlag<"Zl">,
+def _SLASH_Zl : CLFlag<"Zl">, Alias,
   HelpText<"Do not let object file auto-link default libraries">;
 
 def _SLASH_Yc : CLJoined<"Yc">,


Index: clang/test/Driver/cl-runtime-flags.c
===
--- clang/test/Driver/cl-runtime-flags.c
+++ clang/test/Driver/cl-runtime-flags.c
@@ -97,6 +97,9 @@
 
 // RUN: %clang_cl -### /Zl -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTZl %s
 // RUN: %clang_cl -### /MT /Zl -- %s 2>&1 | FileCheck -check-prefix=CHECK-MTZl %s
+// RUN: %clang -### --target=x86_64-windows-msvc -fms-runtime-lib=static \
+// RUN:   -fms-omit-default-lib -- %s 2>&1 | FileCheck \
+// RUN:   -check-prefix=CHECK-MTZl %s
 // CHECK-MTZl-NOT: "-D_DEBUG"
 // CHECK-MTZl: "-D_MT"
 // CHECK-MTZl-NOT: "-D_DLL"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4499,7 +4499,7 @@
 llvm_unreachable("Unexpected option ID.");
   }
 
-  if (Args.hasArg(options::OPT__SLASH_Zl)) {
+  if (Args.hasArg(options::OPT_fms_omit_default_lib)) {
 CmdArgs.push_back("-D_VC_NODEFAULTLIB");
   } else {
 CmdArgs.push_back(FlagForCRT.data());
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2227,6 +2227,8 @@
 to the cl flags /MT and /MTd which use the multithread, static version. "dll"
 and "dll_dbg" correspond to the cl flags /MD and /MDd which use the multithread,
 dll version.}]>;
+def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">,
+  Group, Flags<[NoXarchOption, CoreOption]>;
 defm delayed_template_parsing : BoolFOption<"delayed-template-parsing",
   LangOpts<"DelayedTemplateParsing">, DefaultFalse,
   PosFlag,
@@ -6784,7 +6786,7 @@
   HelpText<"Volatile loads and stores have acquire and release semantics">;
 def _SLASH_clang : CLJoined<"clang:">,
   HelpText<"Pass  to the clang driver">, MetaVarName<"">;
-def _SLASH_Zl : CLFlag<"Zl">,
+def _SLASH_Zl : CLFlag<"Zl">, Alias,
   HelpText<"Do not let object file auto-link default libraries">;
 
 def _SLASH_Yc : CLJoined<"Yc">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

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



Comment at: clang/include/clang/Parse/Parser.h:2343
+  static ImplicitTypenameContext
+  isImplicitTypenameContext(DeclSpecContext DSC) {
+switch (DSC) {

Starting with `is` implies contextual conversion to bool (generally), so I'd 
suggest renaming.



Comment at: clang/include/clang/Sema/DeclSpec.h:1806
+// typename is allowed (C++2a [temp.res]p5]).
+enum class ImplicitTypenameContext {
+  No,

Not opposed to this construct, but I am worried about how well it will scale. I 
don't know that we want to add a bunch of named enums that all boil down to a 
bool. (If someone thinks they have good ideas here, that'd be a good RFC topic 
for Discourse because we have a ton of interfaces that take a bunch of bools.)



Comment at: clang/lib/Parse/ParseDecl.cpp:5592
+bool Parser::isConstructorDeclarator(bool IsUnqualified, bool DeductionGuide,
+ bool IsFriend) {
   TentativeParsingAction TPA(*this);

shafik wrote:
> Instead of adding yet another `bool` flag maybe we can consider using 
> something like `enum isFriend : bool {No, Yes}`.
> 
> I am sure @aaron.ballman will want to chime in here as well.
Heh, so this is where I get worried about the scalability of using enums for 
these. We really want to use three different enums here, but do we really want 
to *add* three different enums? I'm unconvinced.

However, if we can come up with some template magic to allow for named bool 
parameters as a generic interface, that would be valuable to use.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

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


[PATCH] D134458: [AST] Add msvc-specific C++11 attribute 'msvc::no_unique_address'

2022-09-22 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt created this revision.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
RIscRIpt 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/D134458

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/lib/AST/Decl.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/AST/msvc-attrs.cpp

Index: clang/test/AST/msvc-attrs.cpp
===
--- clang/test/AST/msvc-attrs.cpp
+++ clang/test/AST/msvc-attrs.cpp
@@ -1,6 +1,14 @@
 // RUN: %clang_cc1 -fms-extensions -std=c++20 -ast-dump %s | FileCheck %s
-// RUN: not %clang_cc1 -Werror=ignored-attributes -ast-dump %s 2>&1 | grep "1 error generated"
+// RUN: not %clang_cc1 -Werror=ignored-attributes -ast-dump %s 2>&1 | grep "3 errors generated"
 
-// CHECK: msvc-attrs.cpp:[[@LINE+2]]:21, col:61> col:27 constexpr New1 'void *(void *)'
+struct Empty {};
+
+// CHECK:  col:27 constexpr New1 'void *(void *)'
 // CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
 [[msvc::constexpr]] void *New1(void *where) { return where; }
+
+struct StructWithNUAField {
+  [[msvc::no_unique_address]] Empty e;
+  int f1;
+};
+static_assert(sizeof(StructWithNUAField) == sizeof(int)); // expected to fail without -fms-extensions
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -578,8 +578,7 @@
   // according to the Itanium ABI.  The exception applies only to records,
   // not arrays of records, so we must also check whether we stripped off an
   // array type above.
-  if (isa(RT->getDecl()) &&
-  (WasArray || !FD->hasAttr()))
+  if (isa(RT->getDecl()) && (WasArray || !FD->hasNoUniqueAddress()))
 return false;
 
   return isEmptyRecord(Context, FT, AllowArrays);
@@ -7524,8 +7523,7 @@
   // do count.  So do anonymous bitfields that aren't zero-sized.
 
   // Like isSingleElementStruct(), ignore C++20 empty data members.
-  if (FD->hasAttr() &&
-  isEmptyRecord(getContext(), FD->getType(), true))
+  if (FD->hasNoUniqueAddress() && isEmptyRecord(getContext(), FD->getType(), true))
 continue;
 
   // Unlike isSingleElementStruct(), arrays do not count.
Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -744,7 +744,7 @@
 Prior->Data = getByteArrayType(bitsToCharUnits(llvm::alignTo(
 cast(Prior->Data)->getIntegerBitWidth(), 8)));
   else {
-assert(Prior->FD->hasAttr() &&
+assert(Prior->FD->hasNoUniqueAddress() &&
"should not have reused this field's tail padding");
 Prior->Data = getByteArrayType(
 Context.getTypeInfoDataSizeInChars(Prior->FD->getType()).Width);
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -755,7 +755,7 @@
 return false;
   // After emitting a non-empty field with [[no_unique_address]], we may
   // need to overwrite its tail padding.
-  if (Field->hasAttr())
+  if (Field->hasNoUniqueAddress())
 AllowOverwrite = true;
 } else {
   // Otherwise we have a bitfield.
@@ -856,7 +856,7 @@
 return false;
   // After emitting a non-empty field with [[no_unique_address]], we may
   // need to overwrite its tail padding.
-  if (Field->hasAttr())
+  if (Field->hasNoUniqueAddress())
 AllowOverwrite = true;
 } else {
   // Otherwise we have a bitfield.
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -2015,7 +2015,7 @@
 
 AggValueSlot::Overlap_t
 CodeGenFunction::getOverlapForFieldInit(const FieldDecl *FD) {
-  if (!FD->hasAttr() || !FD->getType()->isRecordType())
+  if (!FD->hasNoUniqueAddress() || !FD->getType()->isRecordType())
 return AggValueSlot::DoesNotOverlap;
 
   // If the field lies entirely within the enclosing class's nvsize, its tail
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -474,7 +474,7 @@
 
   // We are able to place the member variable at this offset.
   // Make sure to update the empty field subobject map.
-  UpdateEmptyFieldSubobjects(FD, Offset, FD->hasAttr());
+  UpdateEmpt

[PATCH] D133853: [AST] Add msvc-specific C++11 attributes

2022-09-22 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added a comment.

I am new to `arc`, I tried `arc diff --edit --verbatim` as it's said in the 
docs, but it still created a new revision: https://reviews.llvm.org/D134458




Comment at: clang/lib/Sema/SemaStmtAttr.cpp:296
+  // Validation is in Sema::ActOnAttributedStmt().
+  return ::new (S.Context) MSConstexprAttr(S.Context, A);
+}

erichkeane wrote:
> Typically we try to do the ::Create function that is generated for 
> attributes, rather than placement new.  I realize we are consistently 
> inconsistent...
I could address this, but could you please provide an example? Because all 
`handle` functions in this file use placement new.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133853

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


[PATCH] D134458: [AST] Add msvc-specific C++11 attributes

2022-09-22 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 462234.
RIscRIpt retitled this revision from "[AST] Add msvc-specific C++11 attribute 
'msvc::no_unique_address'" to "[AST] Add msvc-specific C++11 attributes".
RIscRIpt edited the summary of this revision.
RIscRIpt added a comment.

Add msvc::constexpr commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134458

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Decl.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/msvc-attrs.cpp

Index: clang/test/AST/msvc-attrs.cpp
===
--- /dev/null
+++ clang/test/AST/msvc-attrs.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fms-extensions -std=c++20 -ast-dump %s | FileCheck %s
+// RUN: not %clang_cc1 -Werror=ignored-attributes -ast-dump %s 2>&1 | grep "3 errors generated"
+
+struct Empty {};
+
+// CHECK:  col:27 constexpr New1 'void *(void *)'
+// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+[[msvc::constexpr]] void *New1(void *where) { return where; }
+
+struct StructWithNUAField {
+  [[msvc::no_unique_address]] Empty e;
+  int f1;
+};
+static_assert(sizeof(StructWithNUAField) == sizeof(int)); // expected to fail without -fms-extensions
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -4992,6 +4992,9 @@
   case ParsedAttr::AT_PreserveAll:
 D->addAttr(::new (S.Context) PreserveAllAttr(S.Context, AL));
 return;
+  case ParsedAttr::AT_MSConstexpr:
+D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));
+return;
   default:
 llvm_unreachable("unexpected attribute kind");
   }
@@ -6975,6 +6978,14 @@
   D->addAttr(::new (S.Context) ThreadAttr(S.Context, AL));
 }
 
+static void handleMSConstexprAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  if (auto *FD = dyn_cast(D))
+FD->setConstexprKind(ConstexprSpecKind::Constexpr);
+  else
+S.Diag(AL.getLoc(), diag::warn_attribute_ignored_on_non_function) << AL;
+  D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));
+}
+
 static void handleAbiTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   SmallVector Tags;
   for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
@@ -8912,6 +8923,9 @@
   case ParsedAttr::AT_Thread:
 handleDeclspecThreadAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_MSConstexpr:
+handleMSConstexprAttr(S, D, AL);
+break;
 
   // HLSL attributes:
   case ParsedAttr::AT_HLSLNumThreads:
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -578,8 +578,7 @@
   // according to the Itanium ABI.  The exception applies only to records,
   // not arrays of records, so we must also check whether we stripped off an
   // array type above.
-  if (isa(RT->getDecl()) &&
-  (WasArray || !FD->hasAttr()))
+  if (isa(RT->getDecl()) && (WasArray || !FD->hasNoUniqueAddress()))
 return false;
 
   return isEmptyRecord(Context, FT, AllowArrays);
@@ -7524,8 +7523,7 @@
   // do count.  So do anonymous bitfields that aren't zero-sized.
 
   // Like isSingleElementStruct(), ignore C++20 empty data members.
-  if (FD->hasAttr() &&
-  isEmptyRecord(getContext(), FD->getType(), true))
+  if (FD->hasNoUniqueAddress() && isEmptyRecord(getContext(), FD->getType(), true))
 continue;
 
   // Unlike isSingleElementStruct(), arrays do not count.
Index: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
===
--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -744,7 +744,7 @@
 Prior->Data = getByteArrayType(bitsToCharUnits(llvm::alignTo(
 cast(Prior->Data)->getIntegerBitWidth(), 8)));
   else {
-assert(Prior->FD->hasAttr() &&
+assert(Prior->FD->hasNoUniqueAddress() &&
"should not have reused this field's tail padding");
 Prior->Data = getByteArrayType(
 Context.getTypeInfoDataSizeInChars(Prior->FD->getType()).Width);
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -755,7 +755,7 @@
 return false;
   // After emitting a non-empty field with [[no_unique_address]], we may
   // need to overwrite its tail padding.
-  if (Field->hasAttr())
+ 

[clang-tools-extra] 33bc9c3 - Document WarnOnSizeOfPointerToAggregate.

2022-09-22 Thread Michael Benfield via cfe-commits

Author: Michael Benfield
Date: 2022-09-22T17:38:04Z
New Revision: 33bc9c3bf2e09f15ea7be7bc090492fad8226b34

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

LOG: Document WarnOnSizeOfPointerToAggregate.

This option was just landed in D134381. It would make sense to actually
document it.

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

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
index 4ba7c3008bd6a..a3e88b837d375 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
@@ -187,3 +187,9 @@ Options
When `true`, the check will warn on an expression like
``sizeof(expr) <= k`` for a suspicious constant `k` while `k` is `0` or
greater than `0x8000`. Default is `true`.
+
+.. option:: WarnOnSizeOfPointerToAggregate
+
+   When `true, the check will warn on an expression like
+   ``sizeof(expr)`` where the expression is a pointer
+   to aggregate. Default is `true`.



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


[PATCH] D134457: Document WarnOnSizeOfPointerToAggregate.

2022-09-22 Thread Michael Benfield via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33bc9c3bf2e0: Document WarnOnSizeOfPointerToAggregate. 
(authored by mbenfield).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134457

Files:
  clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
@@ -187,3 +187,9 @@
When `true`, the check will warn on an expression like
``sizeof(expr) <= k`` for a suspicious constant `k` while `k` is `0` or
greater than `0x8000`. Default is `true`.
+
+.. option:: WarnOnSizeOfPointerToAggregate
+
+   When `true, the check will warn on an expression like
+   ``sizeof(expr)`` where the expression is a pointer
+   to aggregate. Default is `true`.


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst
@@ -187,3 +187,9 @@
When `true`, the check will warn on an expression like
``sizeof(expr) <= k`` for a suspicious constant `k` while `k` is `0` or
greater than `0x8000`. Default is `true`.
+
+.. option:: WarnOnSizeOfPointerToAggregate
+
+   When `true, the check will warn on an expression like
+   ``sizeof(expr)`` where the expression is a pointer
+   to aggregate. Default is `true`.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134456: [PGO] Consider parent context when weighing branches with likelyhood.

2022-09-22 Thread Hans Wennborg via Phabricator via cfe-commits
hans added reviewers: Mordante, aaron.ballman.
hans added a comment.

Looks reasonable to me.

+the folks from D85091  fyi or if they want to 
take a look.




Comment at: clang/test/Profile/cxx-never-executed-branch.cpp:1
+// Test the clang doesn't emit llvm.expect when the counter is 0
+

ultra nit: s/the/that/ (for the first one)



Comment at: clang/test/Profile/cxx-never-executed-branch.cpp:4
+// RUN: llvm-profdata merge %S/Inputs/cxx-never-executed-branch.proftext -o 
%t.profdata
+// RUN: %clang_cc1 -std=c++20 %s -O2 -o - -emit-llvm 
-fprofile-instrument-use-path=%t.profdata -disable-llvm-passes | FileCheck %s
+

This probably needs a -target flag, since otherwise the mangled function names 
might not match the profile (e.g. on Windows).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134456

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


[PATCH] D134394: Update docs about [[likely]] vs. PGO

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

See also D134456  which affects the behavior 
here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134394

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


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2022-09-22 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:5592
+bool Parser::isConstructorDeclarator(bool IsUnqualified, bool DeductionGuide,
+ bool IsFriend) {
   TentativeParsingAction TPA(*this);

aaron.ballman wrote:
> shafik wrote:
> > Instead of adding yet another `bool` flag maybe we can consider using 
> > something like `enum isFriend : bool {No, Yes}`.
> > 
> > I am sure @aaron.ballman will want to chime in here as well.
> Heh, so this is where I get worried about the scalability of using enums for 
> these. We really want to use three different enums here, but do we really 
> want to *add* three different enums? I'm unconvinced.
> 
> However, if we can come up with some template magic to allow for named bool 
> parameters as a generic interface, that would be valuable to use.
I prefer enums over bools TBH, even if we end up with a million of then 
somewhere.

That said, what about:

https://godbolt.org/z/Kz6jdjobj

```
template
class Is {
Is(bool v) : value(v){}
  public:
  bool value;
  static const Is Yes() { return Is{true};}
  static const Is No() { return Is{false};}

  operator bool() { return value; }
};

class Friend{}; // #1
 
void foo(Is f) {
if (f) {
///...
}
}

void baz() {
foo(Is::Yes());
}
```

Adding a 'new' thing is as simple as just adding #1 for anything we care about. 
 We might want to put them in a namespace of some sort, but perhaps not awful?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

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


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

2022-09-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a subscriber: aaron.ballman.
dblaikie added inline comments.



Comment at: clang/include/clang/AST/PrettyPrinter.h:307
+  /// decltype(s) will be printed as "S" if enabled and as 
"S<{1,2}>" if disabled,
+  /// regardless if PrintCanonicalTypes is enabled.
+  unsigned AlwaysIncludeTypeForNonTypeTemplateArgument : 1;

DoDoENT wrote:
> dblaikie wrote:
> > What does `PrintCanonicalTypes` have to do with this? Does it overlap with 
> > this functionality in some way, but doesn't provide the functionality you 
> > want in particular?
> Thank you for the question. If you set the `PrintCanonicalTypes` to `false`, 
> the `S` would be printed as `S` even without this 
> patch. However, if you set it to `true`, it will be printed as `S<{1, 2}>`.
> 
> I don't fully understand why it does that, but it's quite annoying.
> 
> For a better example, please take a look at the 
> `TemplateIdWithComplexFullTypeNTTP` unit tests that I've added: if 
> `PrintCanonicalTypes` is set to `true`, the original print output of type is 
> `NDArray`, and if set to `false` (which is 
> default), the output is `NDArray Channels{{{0}}}>` - so the NTTP type is neither fully written nor fully 
> omitted, which is weird.
> 
> As I said, I don't really understand the idea behind `PrintCanonicalTypes`, 
> but when my new `AlwaysIncludeTypeForNonTypeTemplateArgument` is enabled, you 
> will get the full type printed, regardless of value of `PrintCanonicalTypes` 
> setting.
> 
Perhaps this might be more of a bug in PrintCanonicalTypes than something to 
add a separate flag for.

@aaron.ballman D2 for context here... 

Hmm, actually, just adding the top level `Height{{0}}, Width{{0}}, 
Channels{{0}}` is sufficient to make this code compile (whereas with the 
`{{{0}}}` it doesn't form a valid identifier.

So what's your use case for needing more explicitness than that top level? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134453

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


  1   2   3   >