[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-21 Thread krishna chaitanya sankisa via Phabricator via cfe-commits
skc7 created this revision.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
skc7 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add the ability to put __attribute__((maybe_undef)) on function arguments. 
Clang will now remove noundef attribute and introduces a freeze instruction on 
the argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130224

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-maybeundef.c
  clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -83,6 +83,7 @@
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
+// CHECK-NEXT: MayBeUndef (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: MinSize (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: MinVectorWidth (SubjectMatchRule_function)
Index: clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
===
--- /dev/null
+++ clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -no-opaque-pointers -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip -fcuda-is-device -emit-llvm  %s \
+// RUN:   -o - | FileCheck %s
+
+#define __global__ __attribute__((global))
+#define __device__ __attribute__((device))
+#define __maybe_undef __attribute__((maybe_undef))
+#define WARP_SIZE 64
+
+static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE;
+
+__device__ static inline unsigned int __lane_id() {
+return  __builtin_amdgcn_mbcnt_hi(
+-1, __builtin_amdgcn_mbcnt_lo(-1, 0));
+}
+
+__device__
+inline
+int __shfl_sync(int __maybe_undef var, int src_lane, int width = warpSize) {
+int self = __lane_id();
+int index = src_lane + (self & ~(width-1));
+return __builtin_amdgcn_ds_bpermute(index<<2, var);
+}
+
+// CHECK: define dso_local amdgpu_kernel void @_Z13shufflekernelv()
+// CHECK: [[TMP1:%.*]] = freeze i32 [[TMP2:%.*]]
+// CHECK: define linkonce_odr noundef i32 @_Z11__shfl_synciii(i32 %var, i32 noundef %src_lane, i32 noundef %width)
+__global__ void
+shufflekernel()
+{
+int t;
+int res;
+res = __shfl_sync(t, WARP_SIZE, 0);
+}
Index: clang/test/CodeGen/attr-maybeundef.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-maybeundef.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - | FileCheck %s
+
+#define __maybe_undef __attribute__((maybe_undef))
+
+// CHECK: define dso_local void @t1(i32 noundef %param1, i32 %param2, float noundef %param3) #[[attr1:[0-9]+]]
+void t1(int param1, int __maybe_undef param2, float param3) {}
+
+// CHECK: define dso_local void @t2(i32 noundef %param1, i32 noundef %param2, float noundef %param3)
+// CHECK: [[TMP1:%.*]] = freeze i32 [[TMP2:%.*]]
+// CHECK: call void @t1(i32 noundef %0, i32 [[TMP1:%.*]], float noundef %2)
+// expected-error {{'maybe_undef' attribute only applies to parameters [-Wignored-attributes]}}
+void __maybe_undef t2(int param1, int param2, float param3) {
+t1(param1, param2, param3);
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8634,6 +8634,9 @@
   case ParsedAttr::AT_NoEscape:
 handleNoEscapeAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_MayBeUndef:
+handleSimpleAttribute(S, D, AL);
+break;
   case ParsedAttr::AT_AssumeAligned:
 handleAssumeAlignedAttr(S, D, AL);
 break;
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2046,6 +2046,22 @@
   return false;
 }
 
+/// Check if the argument of a function has maybe_undef attribute.
+static bool IsArgumentMayBeUndef(const Decl *TargetDecl, unsigned ArgNo) {
+  bool ArgHasMayBeUndefAttr = false;
+  if (TargetDecl) {
+if (const FunctionDecl *FD = dyn_cast(TargetDecl)) {
+  if (FD && (ArgNo < FD->getNumParams())) {
+const ParmVarDecl *Param = FD->getParamDecl(ArgNo);
+if (Param && Param->hasAttr()) {
+  ArgHasMayBeUndefAttr = true;
+}
+  }
+}
+  }
+  return ArgHasMayBeUndefAttr;
+}
+

[PATCH] D126189: [C++20][Modules] Build module static initializers per P1874R1.

2022-07-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

I feel like we could land this sooner to avoid any unimagined failures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126189

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


[clang] ecdeabe - enable P10 vector builtins test on AIX 64 bit; NFC

2022-07-21 Thread Chen Zheng via cfe-commits

Author: Chen Zheng
Date: 2022-07-21T03:51:30-04:00
New Revision: ecdeabef385d13bc0c3b935cc56b09883fd7b108

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

LOG: enable P10 vector builtins test on AIX 64 bit; NFC

Verify that P10 vector builtins with type `vector signed __int128`
and `vector unsigned __int128` work well on AIX 64 bit.

Added: 


Modified: 
clang/test/CodeGen/PowerPC/builtins-ppc-p10vector.c

Removed: 




diff  --git a/clang/test/CodeGen/PowerPC/builtins-ppc-p10vector.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-p10vector.c
index c76298a4f0f98..694d2795d335b 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-p10vector.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-p10vector.c
@@ -5,6 +5,9 @@
 // RUN: %clang_cc1 -flax-vector-conversions=none -no-opaque-pointers 
-target-feature +vsx \
 // RUN:   -target-cpu pwr10 -triple powerpc64le-unknown-unknown -emit-llvm %s \
 // RUN:   -o - | FileCheck %s -check-prefixes=CHECK-LE,CHECK
+// RUN: %clang_cc1 -flax-vector-conversions=none -no-opaque-pointers 
-target-feature +vsx \
+// RUN:   -target-cpu pwr10 -triple powerpc64-ibm-aix-xcoff -emit-llvm %s \
+// RUN:   -o - | FileCheck %s -check-prefixes=CHECK-BE,CHECK
 
 #include 
 



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


[PATCH] D129222: [pseudo] Implement a guard to determine function declarator.

2022-07-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks for digging!
Agreed then that reverting this patch won't really solve anything. I expect I 
can reproduce on linux by enabling LLVM_OPTIMIZED_TABLEGEN in the same way, 
looking into it...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129222

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


[clang-tools-extra] 2955192 - [pseudo] Make sure we rebuild pseudo_gen tool.

2022-07-21 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-07-21T10:09:21+02:00
New Revision: 2955192df8ac270515b5fa4aaa9e9380148e7f00

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

LOG: [pseudo] Make sure we rebuild pseudo_gen tool.

Added: 


Modified: 
clang-tools-extra/pseudo/include/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index 11a3e47157ead..ce2f97db78ad9 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -8,7 +8,9 @@ if(NOT CLANG_PSEUDO_GEN STREQUAL "clang-pseudo-gen")
   set(pseudo_gen ${CLANG_PSEUDO_GEN})
   set(pseudo_gen_target ${CLANG_PSEUDO_GEN})
 elseif(LLVM_USE_HOST_TOOLS)
-  build_native_tool(clang-pseudo-gen pseudo_gen)
+  # The NATIVE executable *must* depend on the current target, otherwise the
+  # native one won't get rebuilt when the pseudo-gen sources change.
+  build_native_tool(clang-pseudo-gen pseudo_gen DEPENDS clang-pseudo-gen)
   set(pseudo_gen_target "${pseudo_gen}")
 else()
   set(pseudo_gen $)



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


[PATCH] D129222: [pseudo] Implement a guard to determine function declarator.

2022-07-21 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

I'm sorry for the trouble it causes, and thanks for all details!

> This could have something to do with "LLVM_OPTIMIZED_TABLEGEN": "ON", 
> perhaps, and there is some dependency missing to rebuild the NATIVE target.

Yeah,  the native clang-pseudo-gen tool didn't rebuild somehow even its source 
file changes, it is a bug in our cmake config. Should be fixed in 
2955192df8ac270515b5fa4aaa9e9380148e7f00 
 (I 
verified it locally). Can you retry it with `LLVM_OPTIMIZED_TABLEGEN` on?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129222

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


[PATCH] D130226: [clang-doc] Default to Standalone executor and improve documentation

2022-07-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: abrachet, paulkirth.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
phosek requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This should provide a more intuitive usage consistent with other tools.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130226

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/docs/clang-doc.rst

Index: clang-tools-extra/docs/clang-doc.rst
===
--- clang-tools-extra/docs/clang-doc.rst
+++ clang-tools-extra/docs/clang-doc.rst
@@ -25,19 +25,23 @@
 see `How To Setup Tooling For LLVM
 `_).
 
-By default, the tool will run on all files listed in the given compile commands
-database:
+The tool will process listed files by default:
 
 .. code-block:: console
 
-  $ clang-doc /path/to/compile_commands.json
+  $ clang-doc File1.cpp File2.cpp ... FileN.cpp
 
-The tool can also be used on a single file or multiple files if a build path is
-passed with the ``-p`` flag.
+The tool can be also used with compile commands database:
 
 .. code-block:: console
 
-  $ clang-doc /path/to/file.cpp -p /path/to/build
+  $ clang-doc --executor=all-TUs compile_commands.json
+
+To select only a subset of files from the database, use the ``--filter`` flag:
+
+.. code-block:: console
+
+  $ clang-doc --executor=all-TUs --filter=File[0-9]+.cpp compile_commands.json
 
 Output
 ==
@@ -50,7 +54,7 @@
 
 .. code-block:: console
 
-  $ clang-doc -output=output/directory/ compile_commands.json
+  $ clang-doc --output=output/directory/ compile_commands.json
 
 Configuration
 =
@@ -67,6 +71,17 @@
 .. code-block:: console
 
   $ clang-doc --help
+  OVERVIEW:
+Generates documentation from source code and comments.
+
+Example usage for files without flags:
+
+$ clang-doc File1.cpp File2.cpp ... FileN.cpp
+
+Example usage for a project using compile commands database:
+
+$ clang-doc --executor=all-TUs ompile_commands.json
+
   USAGE: clang-doc [options]  [... ]
 
   OPTIONS:
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -182,12 +182,23 @@
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
 
-  ExecutorName.setInitialValue("all-TUs");
-  auto Exec = clang::tooling::createExecutorFromCommandLineArgs(
-  argc, argv, ClangDocCategory);
+  const char *Overview = R"(
+  Generates documentation from source code and comments.
 
-  if (!Exec) {
-llvm::errs() << toString(Exec.takeError()) << "\n";
+  Example usage for files without flags:
+
+  $ clang-doc File1.cpp File2.cpp ... FileN.cpp
+
+  Example usage for a project using compile commands database:
+
+  $ clang-doc --executor=all-TUs compile_commands.json
+  )";
+
+  auto Executor = clang::tooling::createExecutorFromCommandLineArgs(
+  argc, argv, ClangDocCategory, Overview);
+
+  if (!Executor) {
+llvm::errs() << toString(Executor.takeError()) << "\n";
 return 1;
   }
 
@@ -208,7 +219,7 @@
 ArgAdjuster);
 
   clang::doc::ClangDocContext CDCtx = {
-  Exec->get()->getExecutionContext(),
+  Executor->get()->getExecutionContext(),
   ProjectName,
   PublicOnly,
   OutDirectory,
@@ -239,7 +250,7 @@
   // Mapping phase
   llvm::outs() << "Mapping decls...\n";
   auto Err =
-  Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
+  Executor->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
 if (IgnoreMappingFailures)
   llvm::errs() << "Error mapping decls in files. Clang-doc will ignore "
@@ -256,7 +267,7 @@
   // bitcode-encoded representation of the Info object.
   llvm::outs() << "Collecting infos...\n";
   llvm::StringMap> USRToBitcode;
-  Exec->get()->getToolResults()->forEachResult(
+  Executor->get()->getToolResults()->forEachResult(
   [&](StringRef Key, StringRef Value) {
 auto R = USRToBitcode.try_emplace(Key, std::vector());
 R.first->second.emplace_back(Value);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 97af17c - re-land [C++20][Modules] Update handling of implicit inlines [P1779R3]

2022-07-21 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-21T09:17:01+01:00
New Revision: 97af17c5cae64f5fd5e89806e8cf20f50fec30ec

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

LOG: re-land [C++20][Modules] Update handling of implicit inlines [P1779R3]

re-land fixes an unwanted interaction with module-map modules, seen in
Greendragon testing.

This provides updates to
[class.mfct]:
Pre C++20 [class.mfct]p2:
  A member function may be defined (8.4) in its class definition, in
  which case it is an inline member function (7.1.2)
Post C++20 [class.mfct]p1:
  If a member function is attached to the global module and is defined
  in its class definition, it is inline.

and
[class.friend]:
Pre-C++20 [class.friend]p5
  A function can be defined in a friend declaration of a
  class . . . . Such a function is implicitly inline.
Post C++20 [class.friend]p7
  Such a function is implicitly an inline function if it is attached
  to the global module.

We add the output of implicit-inline to the TextNodeDumper, and amend
a couple of existing tests to account for this, plus add tests for the
cases covered above.

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

Added: 
clang/test/CXX/class/class.friend/p7-cxx20.cpp
clang/test/CXX/class/class.mfct/p1-cxx20.cpp

Modified: 
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/ast-dump-constant-expr.cpp
clang/test/AST/ast-dump-lambda.cpp

Removed: 




diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index 79e9fa6ab86fc..22643d4edbecb 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1720,6 +1720,9 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl 
*D) {
 }
   }
 
+  if (!D->isInlineSpecified() && D->isInlined()) {
+OS << " implicit-inline";
+  }
   // Since NumParams comes from the FunctionProtoType of the FunctionDecl and
   // the Params are set later, it is possible for a dump during debugging to
   // encounter a FunctionDecl that has been created but hasn't been assigned

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5a546503ccedc..736c299f38bb8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9411,15 +9411,27 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 NewFD->setLocalExternDecl();
 
   if (getLangOpts().CPlusPlus) {
+// The rules for implicit inlines changed in C++20 for methods and friends
+// with an in-class definition (when such a definition is not attached to
+// the global module).  User-specified 'inline' overrides this (set when
+// the function decl is created above).
+// FIXME: We need a better way to separate C++ standard and clang modules.
+bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlusModules ||
+   !NewFD->getOwningModule() ||
+   NewFD->getOwningModule()->isGlobalModule() ||
+   NewFD->getOwningModule()->isModuleMapModule();
 bool isInline = D.getDeclSpec().isInlineSpecified();
 bool isVirtual = D.getDeclSpec().isVirtualSpecified();
 bool hasExplicit = D.getDeclSpec().hasExplicitSpecifier();
 isFriend = D.getDeclSpec().isFriendSpecified();
 if (isFriend && !isInline && D.isFunctionDefinition()) {
-  // C++ [class.friend]p5
+  // Pre-C++20 [class.friend]p5
   //   A function can be defined in a friend declaration of a
   //   class . . . . Such a function is implicitly inline.
-  NewFD->setImplicitlyInline();
+  // Post C++20 [class.friend]p7
+  //   Such a function is implicitly an inline function if it is attached
+  //   to the global module.
+  NewFD->setImplicitlyInline(ImplicitInlineCXX20);
 }
 
 // If this is a method defined in an __interface, and is not a constructor
@@ -9702,11 +9714,14 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
 }
 
 if (isa(NewFD) && DC == CurContext &&
-D.isFunctionDefinition()) {
-  // C++ [class.mfct]p2:
+D.isFunctionDefinition() && !isInline) {
+  // Pre C++20 [class.mfct]p2:
   //   A member function may be defined (8.4) in its class definition, in
   //   which case it is an inline member function (7.1.2)
-  NewFD->setImplicitlyInline();
+  // Post C++20 [class.mfct]p1:
+  //   If a member function is attached to the global module and is defined
+  //   in its class definition, it is inline.
+  NewFD->setImplicitlyInline(ImplicitInlineCXX20);
 }
 
 if (SC == SC_Static && isa(NewFD) &&

diff  --git a/clang/test/AST/ast-dump-constant-expr.cpp 
b/clang/test/AST/ast-dump-constant-expr.cpp
index 79cdfc639af5b

[PATCH] D129045: [C++20][Modules] Update handling of implicit inlines [P1779R3]

2022-07-21 Thread Iain Sandoe via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG97af17c5cae6: re-land [C++20][Modules] Update handling of 
implicit inlines [P1779R3] (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129045

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-constant-expr.cpp
  clang/test/AST/ast-dump-lambda.cpp
  clang/test/CXX/class/class.friend/p7-cxx20.cpp
  clang/test/CXX/class/class.mfct/p1-cxx20.cpp

Index: clang/test/CXX/class/class.mfct/p1-cxx20.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.mfct/p1-cxx20.cpp
@@ -0,0 +1,57 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 no-modules.cpp -fsyntax-only -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-NM %s
+// RUN: %clang_cc1 -std=c++20 -xc++-user-header header-unit.h -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-HU %s
+// RUN: %clang_cc1 -std=c++20 module.cpp -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-MOD %s
+
+//--- no-modules.cpp
+
+class X {
+  void x(){};
+};
+
+// CHECK-NM: `-CXXRecordDecl {{.*}}  line:2:7 class X definition
+// CHECK-NM:   |-CXXRecordDecl {{.*}}  col:7 implicit class X
+// CHECK-NM-NEXT: `-CXXMethodDecl {{.*}}  col:8 x 'void ()' implicit-inline
+
+// A header unit header
+//--- header-unit.h
+
+class Y {
+  void y(){};
+};
+
+// CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 class Y definition
+// CHECK-HU: |-CXXRecordDecl {{.*}}  col:7 implicit class Y
+// CHECK-HU-NEXT: `-CXXMethodDecl {{.*}}  col:8 y 'void ()' implicit-inline
+
+// A textually-included header
+//--- header.h
+
+class A {
+  void a(){};
+};
+
+//--- module.cpp
+module;
+#include "header.h"
+
+export module M;
+
+class Z {
+  void z(){};
+};
+
+// CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in M. hidden class A definition
+// CHECK-MOD: | |-CXXRecordDecl {{.*}}  col:7 in M. hidden implicit class A
+// CHECK-MOD-NEXT: | `-CXXMethodDecl {{.*}}  col:8 in M. hidden a 'void ()' implicit-inline
+
+// CHECK-MOD: `-CXXRecordDecl {{.*}}  line:6:7 in M hidden class Z{{( ReachableWhenImported)?}} definition
+// CHECK-MOD: |-CXXRecordDecl {{.*}}  col:7 in M hidden implicit class Z{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-CXXMethodDecl {{.*}}  col:8 in M hidden z 'void ()'{{( ReachableWhenImported)?}}
Index: clang/test/CXX/class/class.friend/p7-cxx20.cpp
===
--- /dev/null
+++ clang/test/CXX/class/class.friend/p7-cxx20.cpp
@@ -0,0 +1,59 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 no-modules.cpp -fsyntax-only -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-NM %s
+// RUN: %clang_cc1 -std=c++20 -xc++-user-header header-unit.h -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-HU %s
+// RUN: %clang_cc1 -std=c++20 module.cpp -ast-dump | \
+// RUN: FileCheck --match-full-lines --check-prefix=CHECK-MOD %s
+
+//--- no-modules.cpp
+
+class X {
+  friend void x(){};
+};
+
+// CHECK-NM: `-CXXRecordDecl {{.*}}  line:2:7 class X definition
+// CHECK-NM:   |-CXXRecordDecl {{.*}}  col:7 implicit class X
+// CHECK-NM-NEXT: `-FriendDecl {{.*}}  col:15
+// CHECK-NM-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 x 'void ()' implicit-inline
+
+//--- header-unit.h
+
+class Y {
+  friend void y(){};
+};
+
+// CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 class Y definition
+// CHECK-HU: |-CXXRecordDecl {{.*}}  col:7 implicit class Y
+// CHECK-HU-NEXT: `-FriendDecl {{.*}}  col:15
+// CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 y 'void ()' implicit-inline
+
+// A textually-included header
+//--- header.h
+
+class A {
+  friend void a(){};
+};
+
+//--- module.cpp
+module;
+#include "header.h"
+
+export module M;
+
+class Z {
+  friend void z(){};
+};
+// CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in M. hidden class A definition
+// CHECK-MOD: | |-CXXRecordDecl {{.*}}  col:7 in M. hidden implicit class A
+// CHECK-MOD-NEXT: | `-FriendDecl {{.*}}  col:15 in M.
+// CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}}  col:15 in M. hidden a 'void ()' implicit-inline
+
+// CHECK-MOD: `-CXXRecordDecl {{.*}}  line:6:7 in M hidden class Z{{( ReachableWhenImported)?}} definition
+// CHECK-MOD: |-CXXRecordDecl {{.*}}  col:7 in M hidden implicit class Z{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-FriendDecl {{.*}}  col:15 in M{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 in M hidden z 'void ()'{{( ReachableWhenImported)?}}
Index: clang/test/A

[PATCH] D124447: [clang-tidy] Add infrastructure support for running on project-level information

2022-07-21 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D124447#3651074 , @whisperity 
wrote:

> I will attempt to write a concise response to this today (and tomorrow)! 
> Sorry, I was away travelling to and doing post-action bureaucracy of 
> conferences the past few weeks.

@aaron.ballman @kadircet @sammccall, FYI, I have posted it here: 
http://discourse.llvm.org/t/rfc-enhancing-clang-tidy-with-project-level-knowledge/63960


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124447

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


[PATCH] D130228: [clangd] Mention whether compile flags were inferred in check mode

2022-07-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.

That way when looking at logs it's clear whether diagnostics are a
result of compile flags mismatch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130228

Files:
  clang-tools-extra/clangd/tool/Check.cpp


Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -111,7 +111,8 @@
 
 if (auto TrueCmd = CDB->getCompileCommand(File)) {
   Cmd = std::move(*TrueCmd);
-  log("Compile command from CDB is: {0}", printArgv(Cmd.CommandLine));
+  log("Compile command {1} is: {0}", printArgv(Cmd.CommandLine),
+  Cmd.Heuristic.empty() ? "from CDB" : Cmd.Heuristic);
 } else {
   Cmd = CDB->getFallbackCommand(File);
   log("Generic fallback command is: {0}", printArgv(Cmd.CommandLine));


Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -111,7 +111,8 @@
 
 if (auto TrueCmd = CDB->getCompileCommand(File)) {
   Cmd = std::move(*TrueCmd);
-  log("Compile command from CDB is: {0}", printArgv(Cmd.CommandLine));
+  log("Compile command {1} is: {0}", printArgv(Cmd.CommandLine),
+  Cmd.Heuristic.empty() ? "from CDB" : Cmd.Heuristic);
 } else {
   Cmd = CDB->getFallbackCommand(File);
   log("Generic fallback command is: {0}", printArgv(Cmd.CommandLine));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130091: [clang][analyzer] Added partial wide character support to CStringChecker

2022-07-21 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 446385.
balazske added a comment.

Fix in overlap check, replaced test file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130091

Files:
  clang/docs/analyzer/checkers.rst
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/wstring.c

Index: clang/test/Analysis/wstring.c
===
--- /dev/null
+++ clang/test/Analysis/wstring.c
@@ -0,0 +1,389 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.cstring \
+// RUN:   -analyzer-checker=alpha.unix.cstring \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.UninitializedRead \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false  
+//
+// RUN: %clang_analyze_cc1 -verify %s -DUSE_BUILTINS \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.cstring \
+// RUN:   -analyzer-checker=alpha.unix.cstring \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.UninitializedRead \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false
+
+//===--===
+// Declarations
+//===--===
+
+// Some functions are implemented as builtins. These should be #defined as
+// BUILTIN(f), which will prepend "__builtin_" if USE_BUILTINS is defined.
+
+#ifdef USE_BUILTINS
+# define BUILTIN(f) __builtin_ ## f
+#else /* USE_BUILTINS */
+# define BUILTIN(f) f
+#endif /* USE_BUILTINS */
+
+typedef __SIZE_TYPE__ size_t;
+typedef __WCHAR_TYPE__ wchar_t;
+
+void clang_analyzer_eval(int);
+
+//===--===
+// wwmemcpy()
+//===--===
+
+#define wmemcpy BUILTIN(wmemcpy)
+wchar_t *wmemcpy(wchar_t *restrict s1, const wchar_t *restrict s2, size_t n);
+
+void wmemcpy0 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[4] = {0};
+
+  wmemcpy(dst, src, 4); // no-warning
+
+  clang_analyzer_eval(wmemcpy(dst, src, 4) == dst); // expected-warning{{TRUE}}
+
+  // If we actually model the copy, we can make this known.
+  // The important thing for now is that the old value has been invalidated.
+  clang_analyzer_eval(dst[0] != 0); // expected-warning{{UNKNOWN}}
+}
+
+void wmemcpy1 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[10];
+
+  wmemcpy(dst, src, 5); // expected-warning{{Memory copy function accesses out-of-bound array element}}
+}
+
+void wmemcpy2 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[1];
+
+  wmemcpy(dst, src, 4); // expected-warning {{Memory copy function overflows the destination buffer}}
+}
+
+void wmemcpy3 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[3];
+
+  wmemcpy(dst+1, src+2, 2); // no-warning
+}
+
+void wmemcpy4 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[10];
+
+  wmemcpy(dst+2, src+2, 3); // expected-warning{{Memory copy function accesses out-of-bound array element}}
+}
+
+void wmemcpy5(void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[3];
+
+  wmemcpy(dst + 2, src + 2, 2); // expected-warning{{Memory copy function overflows the destination buffer}}
+}
+
+void wmemcpy6(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a, a, 2); // expected-warning{{overlapping}}
+}
+
+void wmemcpy7(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a+2, a+1, 2); // expected-warning{{overlapping}}
+}
+
+void wmemcpy8(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a+1, a+2, 2); // expected-warning{{overlapping}}
+}
+
+void wmemcpy9(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a+2, a+1, 1); // no-warning
+  wmemcpy(a+1, a+2, 1); // no-warning
+}
+
+void wmemcpy10(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(0, a, 1); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
+}
+
+void wmemcpy11(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a, 0, 1); // expected-warning{{Null pointer passed as 2nd argument to memory copy function}}
+}
+
+void wmemcpy12(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(0, a, 0); // no-warning
+}
+
+void wmemcpy13(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a, 0, 0); // no-warning
+}
+
+void wmemcpy_unknown_size (size_t n) {
+  wchar_t a[4], b[4] = {1};
+  clang_analyzer_eval(wmemcpy(a, b, n) == a); // expected-warning{{TRUE}}
+}
+
+void wmemcpy_unknown_size_warn (size_t n) {
+  wchar_t a[4];
+  void *result = wmemcpy(a, 0, n); // expected-warning{{Null pointer passed as 2nd argument to memory copy function}}
+  clang_analyzer_eval(result == a); // no-warning (above is fatal)
+}
+
+//===--===
+// wcslen()
+//===--===
+
+#define wcslen BUILTIN(wcslen)

[clang] 708084e - [PowerPC] Support x86 compatible intrinsics on AIX

2022-07-21 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2022-07-21T16:33:41+08:00
New Revision: 708084ec379ea8f409fbae6ba5d4154ea469f25a

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

LOG: [PowerPC] Support x86 compatible intrinsics on AIX

These headers used to be guarded only on PowerPC64 Linux or FreeBSD, but
they can also be enabled for AIX OS target since it's big-endian ready.

Reviewed By: shchenz

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Headers/ppc_wrappers/emmintrin.h
clang/lib/Headers/ppc_wrappers/mm_malloc.h
clang/lib/Headers/ppc_wrappers/mmintrin.h
clang/lib/Headers/ppc_wrappers/pmmintrin.h
clang/lib/Headers/ppc_wrappers/smmintrin.h
clang/lib/Headers/ppc_wrappers/tmmintrin.h
clang/lib/Headers/ppc_wrappers/xmmintrin.h
clang/test/CodeGen/PowerPC/ppc-emmintrin.c
clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
clang/test/CodeGen/PowerPC/ppc-mmintrin.c
clang/test/CodeGen/PowerPC/ppc-pmmintrin.c
clang/test/CodeGen/PowerPC/ppc-smmintrin.c
clang/test/CodeGen/PowerPC/ppc-tmmintrin.c
clang/test/CodeGen/PowerPC/ppc-x86gprintrin.c
clang/test/CodeGen/PowerPC/ppc-xmmintrin.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 19054ae53d7bb..64be5fe23558f 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -222,11 +222,13 @@ void AIX::AddClangSystemIncludeArgs(const ArgList 
&DriverArgs,
   llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
   const Driver &D = getDriver();
 
-  // Add the Clang builtin headers (/include).
   if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
 SmallString<128> P(D.ResourceDir);
-path::append(P, "/include");
-addSystemInclude(DriverArgs, CC1Args, P.str());
+// Add the PowerPC intrinsic headers (/include/ppc_wrappers)
+path::append(P, "include", "ppc_wrappers");
+addSystemInclude(DriverArgs, CC1Args, P);
+// Add the Clang builtin headers (/include)
+addSystemInclude(DriverArgs, CC1Args, path::parent_path(P.str()));
   }
 
   // Return if -nostdlibinc is specified as a driver option.

diff  --git a/clang/lib/Headers/ppc_wrappers/emmintrin.h 
b/clang/lib/Headers/ppc_wrappers/emmintrin.h
index 8c6aa23c1a0de..a4c458a41bcf4 100644
--- a/clang/lib/Headers/ppc_wrappers/emmintrin.h
+++ b/clang/lib/Headers/ppc_wrappers/emmintrin.h
@@ -36,7 +36,8 @@
 #ifndef EMMINTRIN_H_
 #define EMMINTRIN_H_
 
-#if defined(__ppc64__) && (defined(__linux__) || defined(__FreeBSD__))
+#if defined(__ppc64__) &&  
\
+(defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
 
 #include 
 
@@ -2261,7 +2262,7 @@ extern __inline __m128d
 
 #else
 #include_next 
-#endif /* defined(__ppc64__) && (defined(__linux__) || defined(__FreeBSD__))   
\
-*/
+#endif /* defined(__ppc64__) &&
+*   (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX)) */
 
 #endif /* EMMINTRIN_H_ */

diff  --git a/clang/lib/Headers/ppc_wrappers/mm_malloc.h 
b/clang/lib/Headers/ppc_wrappers/mm_malloc.h
index 29c1de4a83e1a..65920917f3bdc 100644
--- a/clang/lib/Headers/ppc_wrappers/mm_malloc.h
+++ b/clang/lib/Headers/ppc_wrappers/mm_malloc.h
@@ -10,7 +10,8 @@
 #ifndef _MM_MALLOC_H_INCLUDED
 #define _MM_MALLOC_H_INCLUDED
 
-#if defined(__ppc64__) && (defined(__linux__) || defined(__FreeBSD__))
+#if defined(__ppc64__) &&  
\
+(defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
 
 #include 
 

diff  --git a/clang/lib/Headers/ppc_wrappers/mmintrin.h 
b/clang/lib/Headers/ppc_wrappers/mmintrin.h
index 6f9c137b6a095..70e8b81e11ee6 100644
--- a/clang/lib/Headers/ppc_wrappers/mmintrin.h
+++ b/clang/lib/Headers/ppc_wrappers/mmintrin.h
@@ -35,7 +35,8 @@
 #ifndef _MMINTRIN_H_INCLUDED
 #define _MMINTRIN_H_INCLUDED
 
-#if defined(__ppc64__) && (defined(__linux__) || defined(__FreeBSD__))
+#if defined(__ppc64__) &&  
\
+(defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
 
 #include 
 /* The Intel API is flexible enough that we must allow aliasing with other
@@ -1446,7 +1447,7 @@ extern __inline __m64
 
 #else
 #include_next 
-#endif /* defined(__ppc64__) && (defined(__linux__) || defined(__FreeBSD__))   
\
-*/
+#endif /* defined(__ppc64__) &&
+*   (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX)) */
 
 #endif /* _MMINTRIN_H_INCLUDED */

diff  --git a/clang/lib/Headers/ppc_wrappers/pmmintrin.h 
b/clang/lib/Headers/ppc_wrappers/pmmintrin.h
index 889f57ae89d8f..fda39edbaa223 100644
--- a/clang/lib/Headers/ppc_wrappers/pmmintrin.h
+++ b/clang/lib/He

[PATCH] D129461: [PowerPC] Support x86 compatible intrinsics on AIX

2022-07-21 Thread Qiu Chaofan 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 rG708084ec379e: [PowerPC] Support x86 compatible intrinsics on 
AIX (authored by qiucf).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129461

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Headers/ppc_wrappers/emmintrin.h
  clang/lib/Headers/ppc_wrappers/mm_malloc.h
  clang/lib/Headers/ppc_wrappers/mmintrin.h
  clang/lib/Headers/ppc_wrappers/pmmintrin.h
  clang/lib/Headers/ppc_wrappers/smmintrin.h
  clang/lib/Headers/ppc_wrappers/tmmintrin.h
  clang/lib/Headers/ppc_wrappers/xmmintrin.h
  clang/test/CodeGen/PowerPC/ppc-emmintrin.c
  clang/test/CodeGen/PowerPC/ppc-mm-malloc.c
  clang/test/CodeGen/PowerPC/ppc-mmintrin.c
  clang/test/CodeGen/PowerPC/ppc-pmmintrin.c
  clang/test/CodeGen/PowerPC/ppc-smmintrin.c
  clang/test/CodeGen/PowerPC/ppc-tmmintrin.c
  clang/test/CodeGen/PowerPC/ppc-x86gprintrin.c
  clang/test/CodeGen/PowerPC/ppc-xmmintrin.c

Index: clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
===
--- clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
+++ clang/test/CodeGen/PowerPC/ppc-xmmintrin.c
@@ -10,7 +10,7 @@
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
 // RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr10 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-P10
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-P10-LE
 
 // RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -target powerpc64-unknown-freebsd13.0 -mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
@@ -21,6 +21,13 @@
 // RUN: %clang -Xclang -no-opaque-pointers -x c++ -fsyntax-only -target powerpc64le-unknown-freebsd13.0 -mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
+// RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -target powerpc64-ibm-aix -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: %clang -Xclang -no-opaque-pointers -x c++ -fsyntax-only -target powerpc64-ibm-aix -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
+// RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -target powerpc64-ibm-aix -mcpu=pwr10 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-P10-BE
+
 #include 
 
 __m128 res, m1, m2;
@@ -388,7 +395,8 @@
 // CHECK-LABEL: define available_externally signext i32 @_mm_cvtss_si32
 // CHECK-LE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
 // CHECK-BE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
-// CHECK-P10: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
+// CHECK-P10-LE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xxsldwi ${0:x},${0:x},${0:x},3;\0Axscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
+// CHECK-P10-BE: %[[VEC:[0-9a-zA-Z_.]+]] = call { <4 x float>, i32, double } asm "xscvspdp ${2:x},${0:x};\0Afctiw  $2,$2;\0Amfvsrd  $1,${2:x};\0A", "=^wa,=r,=f,0"
 // CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 0
 // CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 1
 // CHECK: extractvalue { <4 x float>, i32, double } %[[VEC]], 2
@@ -688,7 +696,8 @@
 // CHECK-BE: call <2 x i64> @vec_vbpermq(unsigned char vector[16], unsigned char vector[16])(<16 x i8> noundef %{{[0-9a-zA-Z_.]+}}, <16 x i8> noundef bitcast (<4 x i32>  to <16 x i8>))
 // CHECK-BE: %[[EXT:[0-9a-zA-Z_.]+]] = extractelement <2 x i64> %{{[0-9a-zA-Z_.]+}}, i32 0
 // CHECK-BE: trunc i64 %[[EXT]] to i32
-// CHECK-P10: call zeroext i32 @vec_extractm(unsigned int vector[4])(<4 x i32> noundef %{{[0-9a-zA-Z_.]+}})
+// CHECK-P10-LE: call zeroext i32 @vec_extractm(unsigned int vector[4])(<4 x i32> noundef %{{[0-9a-

[PATCH] D130160: [pseudo] Eliminate the dangling-else syntax ambiguity.

2022-07-21 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 446388.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130160

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Language.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/dangling-else.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
@@ -634,11 +634,12 @@
 start := IDENTIFIER [guard=TestOnly]
   )bnf");
   TestLang.Guards.try_emplace(
-  extensionID("TestOnly"),
-  [&](llvm::ArrayRef RHS, const TokenStream &Tokens) {
-assert(RHS.size() == 1 &&
-   RHS.front()->symbol() == tokenSymbol(clang::tok::identifier));
-return Tokens.tokens()[RHS.front()->startTokenIndex()].text() == "test";
+  extensionID("TestOnly"), [&](const GuardParams &P) {
+assert(P.RHS.size() == 1 &&
+   P.RHS.front()->symbol() ==
+   tokenSymbol(clang::tok::identifier));
+return P.Tokens.tokens()[P.RHS.front()->startTokenIndex()]
+   .text() == "test";
   });
   clang::LangOptions LOptions;
   TestLang.Table = LRTable::buildSLR(TestLang.G);
Index: clang-tools-extra/pseudo/test/cxx/dangling-else.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/dangling-else.cpp
@@ -0,0 +1,22 @@
+// RUN: clang-pseudo -grammar=cxx -source=%s --start-symbol=statement-seq --print-forest | FileCheck %s
+
+// Verify the else should belong to the nested if statement
+if (true) if (true) {} else {}
+
+// CHECK:  statement-seq~selection-statement := IF ( condition ) statement
+// CHECK-NEXT: ├─IF
+// CHECK-NEXT: ├─(
+// CHECK-NEXT: ├─condition~TRUE
+// CHECK-NEXT: ├─)
+// CHECK-NEXT: └─statement~selection-statement
+// CHECK-NEXT:   ├─IF
+// CHECK-NEXT:   ├─(
+// CHECK-NEXT:   ├─condition~TRUE
+// CHECK-NEXT:   ├─)
+// CHECK-NEXT:   ├─statement~compound-statement := { }
+// CHECK-NEXT:   │ ├─{
+// CHECK-NEXT:   │ └─}
+// CHECK-NEXT:   ├─ELSE 
+// CHECK-NEXT:   └─statement~compound-statement := { }
+// CHECK-NEXT: ├─{ 
+// CHECK-NEXT: └─}
Index: clang-tools-extra/pseudo/lib/cxx/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx/cxx.bnf
@@ -290,7 +290,7 @@
 compound-statement := { statement-seq_opt [recover=Brackets] }
 statement-seq := statement
 statement-seq := statement-seq statement
-selection-statement := IF CONSTEXPR_opt ( init-statement_opt condition ) statement
+selection-statement := IF CONSTEXPR_opt ( init-statement_opt condition ) statement [guard=NextTokenNotElse]
 selection-statement := IF CONSTEXPR_opt ( init-statement_opt condition ) statement ELSE statement
 selection-statement := SWITCH ( init-statement_opt condition ) statement
 iteration-statement := WHILE ( condition ) statement
Index: clang-tools-extra/pseudo/lib/cxx/CXX.cpp
===
--- clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -11,6 +11,7 @@
 #include "clang-pseudo/Language.h"
 #include "clang-pseudo/grammar/Grammar.h"
 #include "clang-pseudo/grammar/LRTable.h"
+#include "clang/Basic/TokenKinds.h"
 #include 
 
 namespace clang {
@@ -21,29 +22,25 @@
 #include "CXXBNF.inc"
 ;
 
-bool guardOverride(llvm::ArrayRef RHS,
-   const TokenStream &Tokens) {
-  assert(RHS.size() == 1 &&
- RHS.front()->symbol() == tokenSymbol(clang::tok::identifier));
-  return Tokens.tokens()[RHS.front()->startTokenIndex()].text() == "override";
+bool guardOverride(const GuardParams &P) {
+  assert(P.RHS.size() == 1 &&
+ P.RHS.front()->symbol() == tokenSymbol(clang::tok::identifier));
+  return P.Tokens.tokens()[P.RHS.front()->startTokenIndex()].text() ==
+ "override";
 }
-bool guardFinal(llvm::ArrayRef RHS,
-const TokenStream &Tokens) {
-  assert(RHS.size() == 1 &&
- RHS.front()->symbol() == tokenSymbol(clang::tok::identifier));
-  return Tokens.tokens()[RHS.front()->startTokenIndex()].text() == "final";
+bool guardFinal(const GuardParams &P) {
+  assert(P.RHS.size() == 1 &&
+ P.RHS.front()->symbol() == tokenSymbol(clang::tok::identifier));
+  return P.Tokens.tokens()[P.RHS.front()->startTokenIndex()].text() == "final";
 }
-bool guardModule(llvm::ArrayRef RHS,
- const TokenStream &Tokens) {
-  return Tokens.tokens()[RHS

[PATCH] D130160: [pseudo] Eliminate the dangling-else syntax ambiguity.

2022-07-21 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/pseudo/include/clang-pseudo/Language.h:25
+  const TokenStream &Tokens;
+  SymbolID Lookahead;
+};

sammccall wrote:
> passing the position in the stream would be more general, there's no reason 
> in particular that the amount of lookahead the guard needs is the same as 
> what we have in GLR
> 
> OTOH as long as it *is* the same this is probably faster
+1, agree. This'd requires some non-trivial changes in the GLR because we use 
Lookahead in the Reduce rather than the token stream index. I think it is 
better to do it in a followup patch. I added a FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130160

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


[PATCH] D130091: [clang][analyzer] Added partial wide character support to CStringChecker

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

I did not found the existing tests in other files, now all tests for the 
"non-wide" functions are copied for the "wide" functions. I do not like fully 
this solution but a single test file with macros for wide and non-wide case is 
probably not better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130091

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


[PATCH] D130091: [clang][analyzer] Added partial wide character support to CStringChecker

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



Comment at: clang/test/Analysis/wstring.c:385
+  wchar_t a[32];
+  // FIXME: This should work with 'w_str' instead of 'w_str1'
+  const wchar_t w_str1[] = L"Hello world";

The problem may be that the global constant is not encountered as statement 
when a function is analyzed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130091

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


[PATCH] D130231: [WIP][clang-doc] Improve the Markdown output

2022-07-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: abrachet, paulkirth.
Herald added a project: All.
phosek requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This change tries to improve the usability of Markdown output, taking
the inspiration from other documentation generators where appropriate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130231

Files:
  clang-tools-extra/clang-doc/MDGenerator.cpp

Index: clang-tools-extra/clang-doc/MDGenerator.cpp
===
--- clang-tools-extra/clang-doc/MDGenerator.cpp
+++ clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -20,6 +20,37 @@
 
 // Markdown generation
 
+static std::string genEscaped(StringRef Name) {
+  std::string Buffer;
+  llvm::raw_string_ostream Stream(Buffer);
+  for (unsigned I = 0, E = Name.size(); I != E; ++I) {
+unsigned char C = Name[I];
+switch (C) {
+  case '\\':
+  case '`':
+  case '*':
+  case '_':
+  case '{':
+  case '}':
+  case '[':
+  case ']':
+  case '(':
+  case ')':
+  case '#':
+  case '+':
+  case '-':
+  case '.':
+  case '!':
+Stream << '\\';
+LLVM_FALLTHROUGH;
+  default:
+Stream << C;
+break;
+}
+  }
+  return Stream.str();
+}
+
 static std::string genItalic(const Twine &Text) {
   return "*" + Text.str() + "*";
 }
@@ -28,6 +59,10 @@
   return "**" + Text.str() + "**";
 }
 
+static std::string genCode(const Twine &Text) {
+  return "`" + Text.str() + "`";
+}
+
 static std::string
 genReferenceList(const llvm::SmallVectorImpl &Refs) {
   std::string Buffer;
@@ -40,21 +75,18 @@
   return Stream.str();
 }
 
-static void writeLine(const Twine &Text, raw_ostream &OS) {
-  OS << Text << "\n\n";
-}
-
-static void writeNewLine(raw_ostream &OS) { OS << "\n\n"; }
-
-static void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS) {
-  OS << std::string(Num, '#') + " " + Text << "\n\n";
+static void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS, const Twine &Anchor = "") {
+  OS << std::string(Num, '#') << " " << genEscaped(Text.str());
+  if (!Anchor.isTriviallyEmpty()) {
+OS << " {#" << Anchor << "}";
+  }
+  OS << "\n";
 }
 
 static void writeFileDefinition(const ClangDocContext &CDCtx, const Location &L,
 raw_ostream &OS) {
-
   if (!CDCtx.RepositoryUrl) {
-OS << "*Defined at " << L.Filename << "#" << std::to_string(L.LineNumber)
+OS << "*foobar Defined at " << L.Filename << "#" << std::to_string(L.LineNumber)
<< "*";
   } else {
 OS << "*Defined at [" << L.Filename << "#" << std::to_string(L.LineNumber)
@@ -63,7 +95,7 @@
<< std::to_string(L.LineNumber) << ")"
<< "*";
   }
-  OS << "\n\n";
+  OS << "\n";
 }
 
 static void writeDescription(const CommentInfo &I, raw_ostream &OS) {
@@ -73,28 +105,37 @@
   } else if (I.Kind == "ParagraphComment") {
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
-writeNewLine(OS);
+OS << "\n";
   } else if (I.Kind == "BlockCommandComment") {
+// TODO: @return is a block command and should be included in the "Returns" table.
+// TODO: @see block commands should be grouped and rendered as "See Also" section.
+// TODO: Figure out handling for @brief.
+// TODO: What other block commands need special handling?
 OS << genEmphasis(I.Name);
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
   } else if (I.Kind == "InlineCommandComment") {
-OS << genEmphasis(I.Name) << " " << I.Text;
+OS << genEmphasis(I.ParamName) << " " << I.Text;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "ParamCommandComment") {
+// TODO: @param commands should included in the "Parameters" table.
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
 OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
   } else if (I.Kind == "TParamCommandComment") {
+// TODO: @tparam commands should included in the "Template Parameters" table.
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
 OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
   } else if (I.Kind == "VerbatimBlockComment") {
+// TODO: We should use ``` or indentation for verbatim blocks.
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
   } else if (I.Kind == "VerbatimBlockLineComment") {
-OS << I.Text;
-writeNewLine(OS);
+// TODO: We should use ` for verbatim block lines.
+OS << I.Text << "\n";
   } else if (I.Kind == "VerbatimLineComment") {
-OS << I.Text;
-writeNewLine(OS);
+// TODO: We should use ` for verbatim lines.
+OS << I.Text << "\n";
   } else if (I.Kind == "HTMLStartTagComment") {
 if (I.AttrKeys.size() != I.AttrV

[PATCH] D130231: [WIP][clang-doc] Improve the Markdown output

2022-07-21 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 446391.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130231

Files:
  clang-tools-extra/clang-doc/MDGenerator.cpp

Index: clang-tools-extra/clang-doc/MDGenerator.cpp
===
--- clang-tools-extra/clang-doc/MDGenerator.cpp
+++ clang-tools-extra/clang-doc/MDGenerator.cpp
@@ -20,6 +20,37 @@
 
 // Markdown generation
 
+static std::string genEscaped(StringRef Name) {
+  std::string Buffer;
+  llvm::raw_string_ostream Stream(Buffer);
+  for (unsigned I = 0, E = Name.size(); I != E; ++I) {
+unsigned char C = Name[I];
+switch (C) {
+  case '\\':
+  case '`':
+  case '*':
+  case '_':
+  case '{':
+  case '}':
+  case '[':
+  case ']':
+  case '(':
+  case ')':
+  case '#':
+  case '+':
+  case '-':
+  case '.':
+  case '!':
+Stream << '\\';
+LLVM_FALLTHROUGH;
+  default:
+Stream << C;
+break;
+}
+  }
+  return Stream.str();
+}
+
 static std::string genItalic(const Twine &Text) {
   return "*" + Text.str() + "*";
 }
@@ -28,6 +59,10 @@
   return "**" + Text.str() + "**";
 }
 
+static std::string genCode(const Twine &Text) {
+  return "`" + Text.str() + "`";
+}
+
 static std::string
 genReferenceList(const llvm::SmallVectorImpl &Refs) {
   std::string Buffer;
@@ -40,19 +75,16 @@
   return Stream.str();
 }
 
-static void writeLine(const Twine &Text, raw_ostream &OS) {
-  OS << Text << "\n\n";
-}
-
-static void writeNewLine(raw_ostream &OS) { OS << "\n\n"; }
-
-static void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS) {
-  OS << std::string(Num, '#') + " " + Text << "\n\n";
+static void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS, const Twine &Anchor = "") {
+  OS << std::string(Num, '#') << " " << genEscaped(Text.str());
+  if (!Anchor.isTriviallyEmpty()) {
+OS << " {#" << Anchor << "}";
+  }
+  OS << "\n";
 }
 
 static void writeFileDefinition(const ClangDocContext &CDCtx, const Location &L,
 raw_ostream &OS) {
-
   if (!CDCtx.RepositoryUrl) {
 OS << "*Defined at " << L.Filename << "#" << std::to_string(L.LineNumber)
<< "*";
@@ -63,7 +95,7 @@
<< std::to_string(L.LineNumber) << ")"
<< "*";
   }
-  OS << "\n\n";
+  OS << "\n";
 }
 
 static void writeDescription(const CommentInfo &I, raw_ostream &OS) {
@@ -73,28 +105,37 @@
   } else if (I.Kind == "ParagraphComment") {
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
-writeNewLine(OS);
+OS << "\n";
   } else if (I.Kind == "BlockCommandComment") {
+// TODO: @return is a block command and should be included in the "Returns" table.
+// TODO: @see block commands should be grouped and rendered as "See Also" section.
+// TODO: Figure out handling for @brief.
+// TODO: What other block commands need special handling?
 OS << genEmphasis(I.Name);
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
   } else if (I.Kind == "InlineCommandComment") {
-OS << genEmphasis(I.Name) << " " << I.Text;
+OS << genEmphasis(I.ParamName) << " " << I.Text;
+for (const auto &Child : I.Children)
+  writeDescription(*Child, OS);
   } else if (I.Kind == "ParamCommandComment") {
+// TODO: @param commands should included in the "Parameters" table.
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
 OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
   } else if (I.Kind == "TParamCommandComment") {
+// TODO: @tparam commands should included in the "Template Parameters" table.
 std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
 OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
   } else if (I.Kind == "VerbatimBlockComment") {
+// TODO: We should use ``` or indentation for verbatim blocks.
 for (const auto &Child : I.Children)
   writeDescription(*Child, OS);
   } else if (I.Kind == "VerbatimBlockLineComment") {
-OS << I.Text;
-writeNewLine(OS);
+// TODO: We should use ` for verbatim block lines.
+OS << I.Text << "\n";
   } else if (I.Kind == "VerbatimLineComment") {
-OS << I.Text;
-writeNewLine(OS);
+// TODO: We should use ` for verbatim lines.
+OS << I.Text << "\n";
   } else if (I.Kind == "HTMLStartTagComment") {
 if (I.AttrKeys.size() != I.AttrValues.size())
   return;
@@ -104,11 +145,11 @@
   Attrs << " \"" << I.AttrKeys[Idx] << "=" << I.AttrValues[Idx] << "\"";
 
 std::string CloseTag = I.SelfClosing ? "/>" : ">";
-writeLine("<" + I.Name + Attrs.str() + CloseTag, OS);
+OS << "<" << I.Name << Attrs.str() << CloseTag << "\n";
   } else if (I.Kind == "HTMLEndTagComment") {
-writeLine("", OS);
+OS << "" << "\n";
   } else if (I.Kind == "TextComment"

[PATCH] D130081: Add foldings for multi-line comment.

2022-07-21 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/Protocol.h:1782
   unsigned endCharacter;
-  std::string kind;
+  FoldingRangeKind kind;
 };

sorry for not being clear on my previous comment, I think the current `string 
kind;` is good, and it aligns with the LSP one.

what I suggest was adding string literals to FoldingRange, something like


```
struct FoldingRange {
  const static llvm::StringLiteral REGION_KIND;
  const static llvm::StringLiteral COMMENT_KIND;
  const static llvm::StringLiteral IMPORT_KIND;
  
  // other fields keep as-is.
  ...
}
```
we're diverging from the LSP structure. 



Comment at: clang-tools-extra/clangd/SemanticSelection.cpp:232
+while (T != Tokens.end() && T->Kind == tok::comment &&
+   LastComment->Line == T->Line + 1) {
+  LastComment = T;

this seems incorrect -- the ` LastComment->Line == T->Line + 1` condition is 
not true initially (because `LastComment == T`), so we will never run into this 
loop, then I'm confused, why the unittest are passed (premerge test is green).



Comment at: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp:351
+int c;
+[[// A comment 
+// expanding more than

usaxena95 wrote:
> hokein wrote:
> > For this case, my personal preference would be to have 3 different 
> > foldings, rather than a union one.
> > 
> > If you think about cases like below, it makes more sense to have individual 
> > folding per comment.
> > 
> > ```
> > /* comment 1
> > */
> > 
> > /* comment 2
> > */
> > ```
> > 
> > ```
> > /* comment 1
> > */
> > 
> > // comment 2
> > ```
> In the cases mentioned, I think these comments would be about the same 
> context. If I want to fold (possibly long) comments with interleaved new 
> lines, I would be interested in folding all the related comments to look at 
> the code clearly.
> In the cases mentioned, I think these comments would be about the same 
> context.

I'm not sure this is true. I could image a case like below, these comments are 
not about the same context. I think for cases where these comments are about 
the same context, they are generally separated by `// ` rather than 
``.

btw, Kirill has a patch (https://reviews.llvm.org/D83914) for proposed folding 
behaviors, see the comments part (which seems reasonable to me). 

```
//===-- This is a file comment --===//
//
// ...
//
//===--===//


// This is a doc comment of `foo` class
class Foo {};
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130081

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


[clang] ea623af - [C++20] [Modules] Avoid inifinite loop when iterating default args

2022-07-21 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2022-07-21T17:25:05+08:00
New Revision: ea623af7c90f0c02fed72010a018cb1e259cca8d

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

LOG: [C++20] [Modules] Avoid inifinite loop when iterating default args

Currently, clang may meet an infinite loop in a very tricky case when it
iterates the default args. This patch tries to fix this by adding a
`fixed` check.

Added: 
clang/test/Modules/inherited_arg.cppm

Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index aa87a33ce8ae1..242e1f81d75c0 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1615,7 +1615,10 @@ hasAcceptableDefaultArgument(Sema &S, const ParmDecl *D,
   if (!D->hasDefaultArgument())
 return false;
 
-  while (D) {
+  llvm::SmallDenseSet Visited;
+  while (D && !Visited.count(D)) {
+Visited.insert(D);
+
 auto &DefaultArg = D->getDefaultArgStorage();
 if (!DefaultArg.isInherited() && S.isAcceptable(D, Kind))
   return true;
@@ -1625,7 +1628,8 @@ hasAcceptableDefaultArgument(Sema &S, const ParmDecl *D,
   Modules->push_back(S.getOwningModule(NonConstD));
 }
 
-// If there was a previous default argument, maybe its parameter is 
visible.
+// If there was a previous default argument, maybe its parameter is
+// acceptable.
 D = DefaultArg.getInheritedFrom();
   }
   return false;

diff  --git a/clang/test/Modules/inherited_arg.cppm 
b/clang/test/Modules/inherited_arg.cppm
new file mode 100644
index 0..eb66b70cdce33
--- /dev/null
+++ b/clang/test/Modules/inherited_arg.cppm
@@ -0,0 +1,78 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A-B.cppm -I%t -emit-module-interface -o 
%t/A-B.pcm
+// RUN: %clang_cc1 -std=c++20 %t/A-C.cppm -I%t -emit-module-interface -o 
%t/A-C.pcm
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface 
-fprebuilt-module-path=%t -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify 
-fsyntax-only
+
+//--- foo.h
+template 
+class pair {};
+
+template 
+class allocator {};
+
+template 
+class my_traits {};
+
+template  > >
+class unordered_map
+{
+public:
+unordered_map() {}
+};
+
+template struct my_enable_if {};
+template struct my_enable_if { using type = T; };
+template using my_enable_if_t = typename 
my_enable_if::type;
+
+template>,
+ class = my_enable_if_t<_InputIterator::value>>
+unordered_map(_InputIterator, _InputIterator, _Allocator = _Allocator())
+  -> unordered_map, my_traits<_InputIterator>, 
_Allocator>;
+
+template ,
+  class _Allocator = allocator<_CharT> >
+class basic_string;
+typedef basic_string, allocator > string;
+
+template
+class basic_string
+{
+public:
+basic_string();
+
+template > 
+basic_string(_InputIterator __first, _InputIterator __last, const 
_Allocator& __a);
+
+void resize(unsigned __n, _CharT __c);
+};
+
+extern template void basic_string::resize(unsigned, char);
+
+//--- A-B.cppm
+module;
+#include "foo.h"
+export module A:B;
+export using ::string;
+
+//--- A-C.cppm
+module;
+#include "foo.h"
+export module A:C;
+
+//--- A.cppm
+export module A;
+export import :B;
+export import :C;
+
+//--- Use.cpp
+import A;
+string s;
+::unordered_map mime_map; // expected-error {{missing '#include'; 
'unordered_map' must be declared before it is used}}
+// expected-note@* {{declaration here is 
not visible}}



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


[PATCH] D130190: [Driver] Error for -gsplit-dwarf with RISC-V linker relaxation

2022-07-21 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng accepted this revision.
kito-cheng added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130190

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


[PATCH] D129748: [C++20] [Modules] Warn for the use of preferred_name in modules

2022-07-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 446404.
ChuanqiXu retitled this revision from "[Modules] Disable preferred_name 
attribute in C++20 Modules" to "[C++20] [Modules] Warn for the use of 
preferred_name in modules".
ChuanqiXu edited the summary of this revision.
ChuanqiXu added a comment.

Don't try to skip the problem. Warns for it instead.


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

https://reviews.llvm.org/D129748

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Modules/preferred_name.cppm


Index: clang/test/Modules/preferred_name.cppm
===
--- /dev/null
+++ clang/test/Modules/preferred_name.cppm
@@ -0,0 +1,43 @@
+// Tests that the ODR check wouldn't produce false-positive result for 
preferred_name attribute.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm 
-verify
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm 
-DDISABLE_PREFERRED_NAME
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use.cppm 
-verify -fsyntax-only -DDISABLE_PREFERRED_NAME
+//
+
+//--- foo.h
+template
+class foo_templ;
+
+typedef foo_templ foo;
+
+template
+class
+#ifndef DISABLE_PREFERRED_NAME
+__attribute__((__preferred_name__(foo)))
+#endif
+foo_templ {
+public:
+foo_templ() {}
+};
+
+inline foo_templ bar()
+{
+  return foo_templ();
+}
+
+//--- A.cppm
+module;
+#include "foo.h" // expected-warning@foo.h:11 {{preferred_name in modules may 
cause incorrect ODR checks now. Considering to not use it}}
+export module A;
+
+//--- Use.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module Use;
+import A;
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -1424,6 +1424,11 @@
 }
 
 static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) {
+  // FIXME: See https://github.com/llvm/llvm-project/issues/56490 for
+  // details. Remove this one when we fix it actually.
+  if (S.getLangOpts().CPlusPlusModules && D->getOwningModule())
+S.Diag(D->getLocation(), clang::diag::warn_preferred_name_in_modules);
+
   auto *RD = cast(D);
   ClassTemplateDecl *CTD = RD->getDescribedClassTemplate();
   assert(CTD && "attribute does not appertain to this declaration");
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11196,6 +11196,10 @@
   "'%0' included multiple times, additional include site in header from module 
'%1'">;
 def note_redefinition_include_same_file : Note<
   "'%0' included multiple times, additional include site here">;
+
+def warn_preferred_name_in_modules : Warning<
+  "preferred_name in modules may cause incorrect ODR checks now. Considering 
to not use it">,
+  InGroup;
 }
 
 let CategoryName = "Coroutines Issue" in {
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -442,6 +442,7 @@
 def IncompleteModule : DiagGroup<"incomplete-module",
 [IncompleteUmbrella, NonModularIncludeInModule]>;
 def PrivateModule : DiagGroup<"private-module">;
+def UnsupportedAttrInModule : DiagGroup<"unsupported-attr-in-module">;
 
 def CXX11InlineNamespace : DiagGroup<"c++11-inline-namespace">;
 def InlineNamespaceReopenedNoninline


Index: clang/test/Modules/preferred_name.cppm
===
--- /dev/null
+++ clang/test/Modules/preferred_name.cppm
@@ -0,0 +1,43 @@
+// Tests that the ODR check wouldn't produce false-positive result for preferred_name attribute.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm -DDISABLE_PREFERRED_NAME
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/Use.cppm -verify -fsyntax-only -DDISABLE_PREFERRED_NAME
+//
+
+//--- foo.h
+template
+class foo_templ;
+
+typedef foo_templ foo;
+
+template
+class
+#ifndef DISABLE_PREFERRED_NAME
+__attribute__((__preferred_name__(foo)))
+#endif
+foo_templ {
+public:
+foo_templ() {}
+};
+
+inline foo_templ bar()
+{
+  return foo_templ();
+}
+
+//--- A.cppm
+module;
+#include "foo.h" // expected-warning@foo.h:11 {{preferred_name in modules may cause incorrect ODR checks now. Considering to not use it}}
+export module A;
+
+//--- Use.cppm
+// expected-no-diagnostics
+module;
+#in

[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-07-21 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 446405.
pmatos added a comment.

Rebase on top of main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp

Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -304,6 +304,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(10)
+  static PointerType *Ty = PointerType::get(C, 10);
+  return Ty;
+}
+
+Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(20)
+  static PointerType *Ty = PointerType::get(C, 20);
+  return Ty;
+}
+
 //===--===//
 //   IntegerType Implementation
 //===--===//
Index: llvm/lib/CodeGen/ValueTypes.cpp
===
--- llvm/lib/CodeGen/ValueTypes.cpp
+++ llvm/lib/CodeGen/ValueTypes.cpp
@@ -204,12 +204,8 @@
   case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
   case MVT::x86amx:  return Type::getX86_AMXTy(Context);
   case MVT::i64x8:   return IntegerType::get(Context, 512);
-  case MVT::externref:
-// pointer to opaque struct in addrspace(10)
-return PointerType::get(StructType::create(Context), 10);
-  case MVT::funcref:
-// pointer to i8 addrspace(20)
-return PointerType::get(Type::getInt8Ty(Context), 20);
+  case MVT::externref: return Type::getWasm_ExternrefTy(Context);
+  case MVT::funcref: return Type::getWasm_FuncrefTy(Context);
   case MVT::v1i1:
 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
   case MVT::v2i1:
Index: llvm/include/llvm/IR/Type.h
===
--- llvm/include/llvm/IR/Type.h
+++ llvm/include/llvm/IR/Type.h
@@ -468,6 +468,8 @@
   static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
+  static Type *getWasm_ExternrefTy(LLVMContext &C);
+  static Type *getWasm_FuncrefTy(LLVMContext &C);
 
   /// Return a pointer to the current type. This is equivalent to
   /// PointerType::get(Foo, AddrSpace).
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1627,6 +1627,8 @@
 #include "clang/Basic/PPCTypes.def"
 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
Index: clang/test/SemaTemplate/address_space-dependent.cpp
==

[PATCH] D128440: [WebAssembly] Initial support for reference type funcref in clang

2022-07-21 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 446406.
pmatos added a comment.

Rebase on top of main. Add missing code in Sema* to ensure the new funcref 
builtin is checked for.
Thanks to @asb for helping fix this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128440

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Format/FormatToken.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/wasm-funcref.c
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388586)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388585)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x7FFFEA>();
+  correct<0x7FFFE9>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/CodeGen/WebAssembly/wasm-funcref.c
===
--- /dev/null
+++ clang/test/CodeGen/WebAssembly/wasm-funcref.c
@@ -0,0 +1,84 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -o - -emit-llvm %s | FileCheck %s
+
+typedef void (*__funcref funcref_t)();
+typedef int (*__funcref fn_funcref_t)(int);
+typedef int (*fn_t)(int);
+
+// Null funcref builtin call
+// CHECK-LABEL: @get_null(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t get_null() {
+  return __builtin_wasm_ref_null_func();
+}
+
+// Call to null funcref builtin but requires cast since
+// default return value for builtin is a funcref with function type () -> ().
+// CHECK-LABEL: @get_null_ii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+fn_funcref_t get_null_ii() {
+  return (fn_funcref_t) __builtin_wasm_ref_null_func();
+}
+
+// Identity function for funcref.
+// CHECK-LABEL: @identity(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t identity(funcref_t fn) {
+  return fn;
+}
+
+void helper(funcref_t);
+
+// Pass funcref ref as an argument to a helper function.
+// CHECK-LABEL: @handle(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:call void @helper(ptr addrspace(20) noundef [[TMP0]])
+// CHECK-NEXT:ret i32 0
+//
+int handle(funcref_t fn) {
+  helper(fn);
+  return 0;
+}
+
+// Return funcref from function pointer.
+// CHECK-LABEL: @get_ref(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FNPTR_ADDR:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:store ptr [[FNPTR:%.*]], ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = addrspacecast ptr [[TMP0]

[PATCH] D129748: [C++20] [Modules] Warn for the use of preferred_name in modules

2022-07-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D129748#3666511 , @tahonermann 
wrote:

> I can imagine several ways in which things may be going wrong. Perhaps 
> (de)serialization is switching to a canonical declaration when it should not 
> be (e.g., reading/writing a definition when only a declaration should be). 
> Perhaps, for implicitly instantiated declarations (at least for ones for 
> which `__preferred_name__` is attached), separate non-defining and defining 
> declarations should be (de)serialized (in the dumps above, there appears to 
> only be a single address associated with the `basic_string_view` 
> specialization). Perhaps `ClassTemplateSpecializationDecl` should be 
> (de)serialized such that a (valid) non-defining declaration is created before 
> attempting to load anything else that might lead to recursion to the same 
> declaration (the intent being that an early return when recursion is detected 
> still yields a valid incomplete declaration).

I feel like the problem may come in the process of instantiation. For example, 
if we add the attribute for  `CXXRecordDecl` at `0x7913a18` in this specific 
case, it would be fine. Although it **may** be OK to address the problem in 
serialization/deserialization side too, I just feel like it might not be worhy 
now..


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

https://reviews.llvm.org/D129748

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


[PATCH] D129748: [C++20] [Modules] Warn for the use of preferred_name in modules

2022-07-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@erichkeane @aaron.ballman @tahonermann I get another idea. We could tell the 
user honestly that we couldn't handle it (temporarily). We could still 
modularize the STL by a trick: 
https://github.com/ChuanqiXu9/stdmodules/blob/e81f4e9e74f96021f2e45c48f44da93e806c4524/Makefile#L3

In this way, we don't need to worry about the dirty implementation pollutes the 
sources. (I think it is not bad to emit a warning to tell the user we couldn't 
do something (now).)


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

https://reviews.llvm.org/D129748

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


[PATCH] D130199: [pseudo] Add ambiguity & unparseability metrics to -print-statistics

2022-07-21 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 added a comment.

Would it make sense to expose this tool run + statistics as a library. This 
would help share the code for all the metrics with google3 (as we wanted to 
keep these metrics in both the places).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130199

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


[PATCH] D130089: update-test-checks: safely handle tests with #if's

2022-07-21 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

In D130089#3666076 , @mizvekov wrote:

> This seems to have introduced a test which always fails on windows:
>
>   $ ":" "RUN: at line 4"
>   $ "cp" "clang\test\utils\update_cc_test_checks/Inputs/ifdef.c" 
> "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
>   $ "C:/Program Files (x86)/Microsoft Visual 
> Studio/Shared/Python39_64/python.exe" "llvm\utils\update_cc_test_checks.py" 
> "--clang" "build\llvm\RelWithDebInfo\bin\clang" "--opt" 
> "build\llvm\RelWithDebInfo\bin\opt" 
> "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
>   $ ":" "RUN: at line 5"
>   $ "diff" "-u" 
> "clang\test\utils\update_cc_test_checks/Inputs/ifdef.c.expected" 
> "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
>   # command output:
>   --- clang\test\utils\update_cc_test_checks/Inputs/ifdef.c.expected
>   +++ 
> build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c
>   @@ -1,21 +1,21 @@
>   -// NOTE: Assertions have been autogenerated by 
> utils/update_cc_test_checks.py
>   -// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
> FileCheck -check-prefixes=CHECK %s
>   -// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s 
> -DFOO | FileCheck -check-prefixes=CHECK,FOO %s
>   -
>   -#ifdef FOO
>   -// FOO-LABEL: @foo(
>   -// FOO-NEXT:  entry:
>   -// FOO-NEXT:ret i32 1
>   -//
>   -int foo() {
>   -  return 1;
>   -}
>   -#endif
>   -
>   -// CHECK-LABEL: @bar(
>   -// CHECK-NEXT:  entry:
>   -// CHECK-NEXT:ret i32 2
>   -//
>   -int bar() {
>   -  return 2;
>   -}
>   +// NOTE: Assertions have been autogenerated by 
> utils/update_cc_test_checks.py
>   +// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | 
> FileCheck -check-prefixes=CHECK %s
>   +// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s 
> -DFOO | FileCheck -check-prefixes=CHECK,FOO %s
>   +
>   +#ifdef FOO
>   +// FOO-LABEL: @foo(
>   +// FOO-NEXT:  entry:
>   +// FOO-NEXT:ret i32 1
>   +//
>   +int foo() {
>   +  return 1;
>   +}
>   +#endif
>   +
>   +// CHECK-LABEL: @bar(
>   +// CHECK-NEXT:  entry:
>   +// CHECK-NEXT:ret i32 2
>   +//
>   +int bar() {
>   +  return 2;
>   +}
>   
>   error: command failed with exit status: 1
>   
>   --
>   
>   
>   Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
>   
>   Failed Tests (1):
> Clang :: utils/update_cc_test_checks/ifdef.test
>   
>   
>   Testing Time: 0.28s
> Failed: 1

Aren't the before and after lines of the diff identical? Is this a Windows 
new-lines issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130089

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


[PATCH] D120185: [ASTMatchers] Output currently processing match and nodes on crash

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

This change broke standalone build of clang. Please fix.




Comment at: clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp:15
 #include "llvm/ADT/Triple.h"
+#include "llvm/Config/config.h"
 #include "llvm/Support/Host.h"

This is private header of LLVM and you can't use it in clang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120185

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


[PATCH] D130089: update-test-checks: safely handle tests with #if's

2022-07-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D130089#3668022 , @nhaehnle wrote:

> Aren't the before and after lines of the diff identical? Is this a Windows 
> new-lines issue?

Yeah it looks like it from a glance, but I haven't had time to take a harder 
look at this yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130089

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


[PATCH] D124750: [MLIR] Add a utility to sort the operands of commutative ops

2022-07-21 Thread Srishti Srivastava via Phabricator via cfe-commits
srishti-pm marked an inline comment as done.
srishti-pm added inline comments.



Comment at: mlir/lib/Transforms/Utils/CommutativityUtils.cpp:110
+  /// operand at a particular point in time.
+  DenseSet visitedAncestors;
+

Mogball wrote:
> Since this is a set of pointers expected to be small, you can use 
> `SmallPtrSet` for a big efficiency boost (linear scan instead of hashing when 
> small).
This set isn't expected to be small, right? There can be many ancestors. The 
only thing that is small in this context is the number of operands, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124750

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


[PATCH] D130089: update-test-checks: safely handle tests with #if's

2022-07-21 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

I've been staring at ifdef.test vs. basic-cplusplus.test for a while now and 
don't see any relevant difference, including when I look at the line endings in 
a hex editor (on Linux). So I guess there is a difference that appears only on 
Windows somehow? Unfortunately, I simply have no idea at the moment where it 
could come from.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130089

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


[PATCH] D129222: [pseudo] Implement a guard to determine function declarator.

2022-07-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D129222#3667638 , @hokein wrote:

> Yeah,  the native clang-pseudo-gen tool didn't rebuild somehow even its 
> source file changes, it is a bug in our cmake config. Should be fixed in 
> 2955192df8ac270515b5fa4aaa9e9380148e7f00 
>  (I 
> verified it locally). Can you retry it with `LLVM_OPTIMIZED_TABLEGEN` on?

Yeah I confirm that fixes it, thanks!

Though it's strange that you would have to declare that dependency explicitly, 
I think it should be implied.

One other small thing I noticed: It seems the pseudo-gen tool generated output 
takes care of undefining the macros it takes as input to expand, but we don't 
take advantage of that fact on 
`clang-tools-extra\pseudo\include\clang-pseudo\cxx\CXX.h` and are always 
undefing them. Just a minor thing :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129222

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


[PATCH] D130089: update-test-checks: safely handle tests with #if's

2022-07-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D130089#3668061 , @nhaehnle wrote:

> I've been staring at ifdef.test vs. basic-cplusplus.test for a while now and 
> don't see any relevant difference, including when I look at the line endings 
> in a hex editor (on Linux). So I guess there is a difference that appears 
> only on Windows somehow? Unfortunately, I simply have no idea at the moment 
> where it could come from.

Yeah it could be that there is some flag we should be passing to diff, or some 
other thing that we normally do on llvm to take care of this issue, so that 
diff ignores the line ending difference.
I haven't had time to look at what is the standard practice we have for that 
yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130089

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


[PATCH] D130089: update-test-checks: safely handle tests with #if's

2022-07-21 Thread Nicolai Hähnle via Phabricator via cfe-commits
nhaehnle added a comment.

My version of `diff` has a `--strip-trailing-cr` flag. But I don't really see 
that being used in many places at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130089

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


[PATCH] D130089: update-test-checks: safely handle tests with #if's

2022-07-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D130089#3668111 , @nhaehnle wrote:

> My version of `diff` has a `--strip-trailing-cr` flag. But I don't really see 
> that being used in many places at all.

What I see is that the sources are checked out with the expected windows (\r\n) 
line endings, but the file we generate 
(`build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c`)
 has unix (\n) line endings.
I am not sure yet what we would usually do here, but it makes more sense to 
generate the file with line endings expected for the native platform.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130089

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


[clang] 396e944 - [Flang] Generate documentation for compiler flags

2022-07-21 Thread Dylan Fleming via cfe-commits

Author: Dylan Fleming
Date: 2022-07-21T11:33:19Z
New Revision: 396e944d82f3e212746cd241e4caba445523aff6

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

LOG: [Flang] Generate documentation for compiler flags

This patch aims to create a webpage to document
Flang's command line options on https://flang.llvm.org/docs/
in a similar way to Clang's
https://clang.llvm.org/docs/ClangCommandLineReference.html

This is done by using clang_tablegen to generate an .rst
file from Options.td (which is current shared with Clang)
For this to work, ClangOptionDocEmitter.cpp was updated
to allow specific Flang flags to be included,
rather than bulk excluding clang flags.

Reviewed By: awarzynski

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

Added: 
flang/include/flang/FlangOptionsDocs.td

Modified: 
clang/utils/TableGen/ClangOptionDocEmitter.cpp
flang/docs/CMakeLists.txt
flang/docs/index.md

Removed: 




diff  --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp 
b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
index 6c24ad2bdcc53..75f5d057c33a5 100644
--- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -168,6 +168,29 @@ bool hasFlag(const Record *OptionOrGroup, StringRef 
OptionFlag) {
   return false;
 }
 
+bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) {
+  assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags");
+  for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags"))
+if (hasFlag(OptionOrGroup, Inclusion))
+  return true;
+  return false;
+}
+
+bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) {
+  if (isIncluded(Group.Group, DocInfo))
+return true;
+  for (auto &O : Group.Options)
+if (isIncluded(O.Option, DocInfo))
+  return true;
+  for (auto &G : Group.Groups) {
+if (isIncluded(G.Group, DocInfo))
+  return true;
+if (isGroupIncluded(G, DocInfo))
+  return true;
+  }
+  return false;
+}
+
 bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) {
   // FIXME: Provide a flag to specify the set of exclusions.
   for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags"))
@@ -304,6 +327,8 @@ void emitOption(const DocumentedOption &Option, const 
Record *DocInfo,
 raw_ostream &OS) {
   if (isExcluded(Option.Option, DocInfo))
 return;
+  if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, 
DocInfo))
+return;
   if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" ||
   Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT")
 return;
@@ -379,6 +404,9 @@ void emitGroup(int Depth, const DocumentedGroup &Group, 
const Record *DocInfo,
   if (isExcluded(Group.Group, DocInfo))
 return;
 
+  if (DocInfo->getValue("IncludedFlags") && !isGroupIncluded(Group, DocInfo))
+return;
+
   emitHeading(Depth,
   getRSTStringWithTextFallback(Group.Group, "DocName", "Name"), 
OS);
 

diff  --git a/flang/docs/CMakeLists.txt b/flang/docs/CMakeLists.txt
index 044697a104507..077c01d3310ff 100644
--- a/flang/docs/CMakeLists.txt
+++ b/flang/docs/CMakeLists.txt
@@ -91,6 +91,16 @@ if (LLVM_ENABLE_DOXYGEN)
 endif()
 endif()
 
+function (gen_rst_file_from_td output_file td_option source docs_target)
+  if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
+message(FATAL_ERROR "Cannot find source file: ${source} in 
${CMAKE_CURRENT_SOURCE_DIR}")
+  endif()
+  get_filename_component(TABLEGEN_INCLUDE_DIR 
"${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY)
+  list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}")
+  clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET 
"gen-${output_file}")
+  add_dependencies(${docs_target} "gen-${output_file}")
+endfunction()
+
 if (LLVM_ENABLE_SPHINX)
   include(AddSphinxTarget)
   if (SPHINX_FOUND)
@@ -114,6 +124,7 @@ if (LLVM_ENABLE_SPHINX)
   COMMAND "${Python3_EXECUTABLE}"
   ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py)
 
+  gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs 
../include/flang/FlangOptionsDocs.td docs-flang-html)
 endif()
 if (${SPHINX_OUTPUT_MAN})
   add_sphinx_target(man flang)

diff  --git a/flang/docs/index.md b/flang/docs/index.md
index 3c3e2de2a8078..d6b05115f8611 100644
--- a/flang/docs/index.md
+++ b/flang/docs/index.md
@@ -45,6 +45,7 @@ on how to get in touch with us and to learn more about the 
current status.
DoConcurrent
Extensions
FIRLangRef
+   FlangCommandLineReference
FlangDriver
FortranIR
FortranLLVMTestSuite

diff  --git a/flang/include/flang/FlangOptionsDocs.td 
b/flang/include/flang/FlangOptionsDocs.td
new file

[PATCH] D129864: [Flang] Generate documentation for compiler flags

2022-07-21 Thread Dylan Fleming via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG396e944d82f3: [Flang] Generate documentation for compiler 
flags (authored by DylanFleming-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129864

Files:
  clang/utils/TableGen/ClangOptionDocEmitter.cpp
  flang/docs/CMakeLists.txt
  flang/docs/index.md
  flang/include/flang/FlangOptionsDocs.td

Index: flang/include/flang/FlangOptionsDocs.td
===
--- /dev/null
+++ flang/include/flang/FlangOptionsDocs.td
@@ -0,0 +1,35 @@
+//==--- FlangOptionDocs.td - Option documentation -===//
+//
+// 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
+//
+//===--===//
+
+def GlobalDocumentation {
+  code Intro =[{..
+  ---
+  NOTE: This file is automatically generated by running clang-tblgen
+  -gen-opt-docs. Do not edit this file by hand!!
+  ---
+
+=
+Flang command line argument reference
+=
+.. contents::
+   :local:
+
+Introduction
+
+
+}];
+
+  string Program = "flang";
+
+  list ExcludedFlags = [];
+  list IncludedFlags = ["FlangOption"];
+
+}
+
+
+include "../../../clang/include/clang/Driver/Options.td"
Index: flang/docs/index.md
===
--- flang/docs/index.md
+++ flang/docs/index.md
@@ -45,6 +45,7 @@
DoConcurrent
Extensions
FIRLangRef
+   FlangCommandLineReference
FlangDriver
FortranIR
FortranLLVMTestSuite
Index: flang/docs/CMakeLists.txt
===
--- flang/docs/CMakeLists.txt
+++ flang/docs/CMakeLists.txt
@@ -91,6 +91,16 @@
 endif()
 endif()
 
+function (gen_rst_file_from_td output_file td_option source docs_target)
+  if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
+message(FATAL_ERROR "Cannot find source file: ${source} in ${CMAKE_CURRENT_SOURCE_DIR}")
+  endif()
+  get_filename_component(TABLEGEN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY)
+  list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}")
+  clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET "gen-${output_file}")
+  add_dependencies(${docs_target} "gen-${output_file}")
+endfunction()
+
 if (LLVM_ENABLE_SPHINX)
   include(AddSphinxTarget)
   if (SPHINX_FOUND)
@@ -114,6 +124,7 @@
   COMMAND "${Python3_EXECUTABLE}"
   ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py)
 
+  gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs ../include/flang/FlangOptionsDocs.td docs-flang-html)
 endif()
 if (${SPHINX_OUTPUT_MAN})
   add_sphinx_target(man flang)
Index: clang/utils/TableGen/ClangOptionDocEmitter.cpp
===
--- clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -168,6 +168,29 @@
   return false;
 }
 
+bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) {
+  assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags");
+  for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags"))
+if (hasFlag(OptionOrGroup, Inclusion))
+  return true;
+  return false;
+}
+
+bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) {
+  if (isIncluded(Group.Group, DocInfo))
+return true;
+  for (auto &O : Group.Options)
+if (isIncluded(O.Option, DocInfo))
+  return true;
+  for (auto &G : Group.Groups) {
+if (isIncluded(G.Group, DocInfo))
+  return true;
+if (isGroupIncluded(G, DocInfo))
+  return true;
+  }
+  return false;
+}
+
 bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) {
   // FIXME: Provide a flag to specify the set of exclusions.
   for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags"))
@@ -304,6 +327,8 @@
 raw_ostream &OS) {
   if (isExcluded(Option.Option, DocInfo))
 return;
+  if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, DocInfo))
+return;
   if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" ||
   Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT")
 return;
@@ -379,6 +404,9 @@
   if (isExcluded(Group.Group, DocInfo))
 return;
 
+  if (DocInfo->getValue("IncludedFlags") && !isGroupIncluded(Group, DocInfo))
+return;
+
   emitHeading(Depth,
   getRSTStringWithTextFallback(

[PATCH] D129222: [pseudo] Implement a guard to determine function declarator.

2022-07-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D129222#3668073 , @mizvekov wrote:

> In D129222#3667638 , @hokein wrote:
>
>> Yeah,  the native clang-pseudo-gen tool didn't rebuild somehow even its 
>> source file changes, it is a bug in our cmake config. Should be fixed in 
>> 2955192df8ac270515b5fa4aaa9e9380148e7f00 
>>  (I 
>> verified it locally). Can you retry it with `LLVM_OPTIMIZED_TABLEGEN` on?
>
> Yeah I confirm that fixes it, thanks!
>
> Though it's strange that you would have to declare that dependency 
> explicitly, I think it should be implied.

I think what's going on here: outer cmake invokes this opaque external command 
(which just _happens_ to be cmake --build) to produce an exe. The outer cmake 
has no special knowledge of what the inner cmake is going to use as inputs, so 
i it never invalidates the exe and invokes inner cmake again. Having the native 
exe depend on the target exe is a hack: it means that it (indirectly) depends 
on the right set of sources and is invalidated when they change. (In a perfect 
world we wouldn't build the target clang-pseudo-gen at all)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129222

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


[PATCH] D67025: Add .inl as valid C++ header type

2022-07-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D67025#3666513 , @sammccall wrote:

>> ! In D67025#3665293 , 
>> @aaron.ballman wrote:
>>  this is why we have the `-x` option so that users can specify a specific 
>> language mode to use. Is there a reason that option does not suffice for 
>> clangd?
>
> The difficulty here is that command-line flags are a very awkward/brittle 
> interface but also the only one we have.

Thank you for the explanation (and thanks to @nridge as well). That is an 
awkward situation. :-(

In D67025#3666544 , @tschuett wrote:

> Note that in this directory is an ,inl file:
> https://github.com/openucx/ucx/tree/master/src/uct/ib/mlx5
> It is a pure C library with C++ gtest.
>
> I believe that .inl is about inlining, but it is not tied to a language.

This captures my fear about trying to nail down this extension in the compiler. 
File extensions are the best we've got for identifying the purpose for a file, 
and .inl sounds a lot like it's used somewhat as a header file and somewhat as 
an implementation file, which means it's close in nature to a .inc or .def 
file. We've traditionally avoided trying to classify these because of the 
chances of getting the behavior wrong. That said, in all of these cases, the 
most common usage pattern is to include the file inside of another file rather 
than compile it directly, which does map fairly closely to header files.

I'm not certain what the best answer is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67025

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


[PATCH] D130228: [clangd] Mention whether compile flags were inferred in check mode

2022-07-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM.
Please note the NIT that arguably improves readability.




Comment at: clang-tools-extra/clangd/tool/Check.cpp:114
   Cmd = std::move(*TrueCmd);
-  log("Compile command from CDB is: {0}", printArgv(Cmd.CommandLine));
+  log("Compile command {1} is: {0}", printArgv(Cmd.CommandLine),
+  Cmd.Heuristic.empty() ? "from CDB" : Cmd.Heuristic);

NIT: maybe change the order of arguments and the format string placeholders?
it's a bit hard to swap arguments inside one's head when reading the code.

```
log("{1}, {0}!", "world", "Hello");
// vs
log("{0}, {1}!", "Hello", "world");
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130228

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


[clang] ce82407 - Revert "[Flang] Generate documentation for compiler flags"

2022-07-21 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-07-21T11:54:49Z
New Revision: ce824078de2fbd46e8514e7f6e8b8dde6f201259

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

LOG: Revert "[Flang] Generate documentation for compiler flags"

This reverts commit 396e944d82f3e212746cd241e4caba445523aff6.

Failing bot: https://lab.llvm.org/buildbot/#/builders/89/builds/30096

Added: 


Modified: 
clang/utils/TableGen/ClangOptionDocEmitter.cpp
flang/docs/CMakeLists.txt
flang/docs/index.md

Removed: 
flang/include/flang/FlangOptionsDocs.td



diff  --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp 
b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
index 75f5d057c33a5..6c24ad2bdcc53 100644
--- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -168,29 +168,6 @@ bool hasFlag(const Record *OptionOrGroup, StringRef 
OptionFlag) {
   return false;
 }
 
-bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) {
-  assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags");
-  for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags"))
-if (hasFlag(OptionOrGroup, Inclusion))
-  return true;
-  return false;
-}
-
-bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) {
-  if (isIncluded(Group.Group, DocInfo))
-return true;
-  for (auto &O : Group.Options)
-if (isIncluded(O.Option, DocInfo))
-  return true;
-  for (auto &G : Group.Groups) {
-if (isIncluded(G.Group, DocInfo))
-  return true;
-if (isGroupIncluded(G, DocInfo))
-  return true;
-  }
-  return false;
-}
-
 bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) {
   // FIXME: Provide a flag to specify the set of exclusions.
   for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags"))
@@ -327,8 +304,6 @@ void emitOption(const DocumentedOption &Option, const 
Record *DocInfo,
 raw_ostream &OS) {
   if (isExcluded(Option.Option, DocInfo))
 return;
-  if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, 
DocInfo))
-return;
   if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" ||
   Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT")
 return;
@@ -404,9 +379,6 @@ void emitGroup(int Depth, const DocumentedGroup &Group, 
const Record *DocInfo,
   if (isExcluded(Group.Group, DocInfo))
 return;
 
-  if (DocInfo->getValue("IncludedFlags") && !isGroupIncluded(Group, DocInfo))
-return;
-
   emitHeading(Depth,
   getRSTStringWithTextFallback(Group.Group, "DocName", "Name"), 
OS);
 

diff  --git a/flang/docs/CMakeLists.txt b/flang/docs/CMakeLists.txt
index 077c01d3310ff..044697a104507 100644
--- a/flang/docs/CMakeLists.txt
+++ b/flang/docs/CMakeLists.txt
@@ -91,16 +91,6 @@ if (LLVM_ENABLE_DOXYGEN)
 endif()
 endif()
 
-function (gen_rst_file_from_td output_file td_option source docs_target)
-  if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
-message(FATAL_ERROR "Cannot find source file: ${source} in 
${CMAKE_CURRENT_SOURCE_DIR}")
-  endif()
-  get_filename_component(TABLEGEN_INCLUDE_DIR 
"${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY)
-  list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}")
-  clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET 
"gen-${output_file}")
-  add_dependencies(${docs_target} "gen-${output_file}")
-endfunction()
-
 if (LLVM_ENABLE_SPHINX)
   include(AddSphinxTarget)
   if (SPHINX_FOUND)
@@ -124,7 +114,6 @@ if (LLVM_ENABLE_SPHINX)
   COMMAND "${Python3_EXECUTABLE}"
   ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py)
 
-  gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs 
../include/flang/FlangOptionsDocs.td docs-flang-html)
 endif()
 if (${SPHINX_OUTPUT_MAN})
   add_sphinx_target(man flang)

diff  --git a/flang/docs/index.md b/flang/docs/index.md
index d6b05115f8611..3c3e2de2a8078 100644
--- a/flang/docs/index.md
+++ b/flang/docs/index.md
@@ -45,7 +45,6 @@ on how to get in touch with us and to learn more about the 
current status.
DoConcurrent
Extensions
FIRLangRef
-   FlangCommandLineReference
FlangDriver
FortranIR
FortranLLVMTestSuite

diff  --git a/flang/include/flang/FlangOptionsDocs.td 
b/flang/include/flang/FlangOptionsDocs.td
deleted file mode 100644
index 32054428ad3f8..0
--- a/flang/include/flang/FlangOptionsDocs.td
+++ /dev/null
@@ -1,35 +0,0 @@
-//==--- FlangOptionDocs.td - Option documentation 
-===//
-//
-// 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: 

[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I'm in C standards meetings this week and don't have a lot of ability to 
thoroughly review this yet, but the most immediate concern which springs to 
mind for me is that this is exposing LLVM implementation details to users. 
Users should not have to think about things in terms of LLVM IR markings like 
poison and undef, and I worry that this is an expert-only feature that will be 
easy to misuse and introduce security issues. It sounds like there's an 
extremely specific use case in mind for this attribute; is there a reason why 
this needs to be the user's problem instead of something the compiler can infer 
or handle on the backend?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130224

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


[clang-tools-extra] 65c8e24 - [pseudo] Fix an invalid assertion on recoveryBrackets.

2022-07-21 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-07-21T14:02:11+02:00
New Revision: 65c8e246222940b458b72dddf7158303ca33c2ba

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

LOG: [pseudo] Fix an invalid assertion on recoveryBrackets.

The `Begin` is not the index of the left bracket, `Begin-1` is,
otherwise the assertion will be triggered on case `Foo().call();`.

Added: 


Modified: 
clang-tools-extra/pseudo/lib/cxx/CXX.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx/CXX.cpp 
b/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
index d6c056a25e365..4b78a67e0be0f 100644
--- a/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ b/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -124,7 +124,7 @@ Token::Index recoverBrackets(Token::Index Begin, const 
TokenStream &Tokens) {
   assert(Left.Kind == tok::l_brace || Left.Kind == tok::l_paren ||
  Left.Kind == tok::l_square);
   if (const Token *Right = Left.pair()) {
-assert(Tokens.index(*Right) > Begin);
+assert(Tokens.index(*Right) > Begin - 1);
 return Tokens.index(*Right);
   }
   return Token::Invalid;



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


[PATCH] D129886: [clang] Add -fdiagnostics-format=sarif option for future SARIF output

2022-07-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129886

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


[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D130224#3668225 , @aaron.ballman 
wrote:

> It sounds like there's an extremely specific use case in mind for this 
> attribute; is there a reason why this needs to be the user's problem instead 
> of something the compiler can infer or handle on the backend?

The intended user is a handful of header wrapper functions around intrinsics, 
not general users


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130224

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


[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D130224#3668240 , @arsenm wrote:

> In D130224#3668225 , @aaron.ballman 
> wrote:
>
>> It sounds like there's an extremely specific use case in mind for this 
>> attribute; is there a reason why this needs to be the user's problem instead 
>> of something the compiler can infer or handle on the backend?
>
> The intended user is a handful of header wrapper functions around intrinsics, 
> not general users

Great, then it sounds like we don't need to expose this as an attribute because 
we know which intrinsics need special behavior, so we can handle them specially 
at codegen time or within the backend?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130224

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


[PATCH] D130254: [CMake][Clang] Copy folder without permissions

2022-07-21 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne created this revision.
sebastian-ne added reviewers: awarzynski, PeteSteinfeld.
Herald added a subscriber: mgorny.
Herald added a project: All.
sebastian-ne requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Copying the folder keeps the original permissions by default. This
creates problems when the source folder is read-only, e.g. in a
packaging environment.
Then, the copied folder in the build directory is read-only as well.
Later on, with configure_file, ClangConfig.cmake is copied into that
directory (in the build tree), failing when the directory is read-only.

Fix that problem by copying the folder without keeping the original
permissions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130254

Files:
  clang/cmake/modules/CMakeLists.txt


Index: clang/cmake/modules/CMakeLists.txt
===
--- clang/cmake/modules/CMakeLists.txt
+++ clang/cmake/modules/CMakeLists.txt
@@ -32,8 +32,10 @@
 
 # For compatibility with projects that include(ClangConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
+# Copy without source permissions because the source could be read-only
 file(COPY .
   DESTINATION ${clang_cmake_builddir}
+  NO_SOURCE_PERMISSIONS
   FILES_MATCHING PATTERN *.cmake
   PATTERN CMakeFiles EXCLUDE
   )


Index: clang/cmake/modules/CMakeLists.txt
===
--- clang/cmake/modules/CMakeLists.txt
+++ clang/cmake/modules/CMakeLists.txt
@@ -32,8 +32,10 @@
 
 # For compatibility with projects that include(ClangConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
+# Copy without source permissions because the source could be read-only
 file(COPY .
   DESTINATION ${clang_cmake_builddir}
+  NO_SOURCE_PERMISSIONS
   FILES_MATCHING PATTERN *.cmake
   PATTERN CMakeFiles EXCLUDE
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D130224#3668243 , @aaron.ballman 
wrote:

> In D130224#3668240 , @arsenm wrote:
>
>> In D130224#3668225 , 
>> @aaron.ballman wrote:
>>
>>> It sounds like there's an extremely specific use case in mind for this 
>>> attribute; is there a reason why this needs to be the user's problem 
>>> instead of something the compiler can infer or handle on the backend?
>>
>> The intended user is a handful of header wrapper functions around 
>> intrinsics, not general users
>
> Great, then it sounds like we don't need to expose this as an attribute 
> because we know which intrinsics need special behavior, so we can handle them 
> specially at codegen time or within the backend?

The problem is the wrappers. We originally talked about specifically handling 
the builtins, but that falls apart given the real users come from wrapper 
functions which look like ordinary code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130224

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


[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-21 Thread Lu Weining via Phabricator via cfe-commits
SixWeining created this revision.
SixWeining added reviewers: xen0n, xry111, MaskRay, rengolin.
Herald added subscribers: StephenFan, krytarowski, mgorny.
Herald added a project: All.
SixWeining requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With the initial support added, clang can compile simple .c
to executable file for loongarch64. For example:

$ cat main.c
int main() {

  return 0;

}
$ clang --target=loongarch64-linux-gnu --gcc-toolchain=xxx --sysroot=xxx main.c

Currently gcc toolchain and sysroot can be found here:
https://github.com/loongson/build-tools/releases/download/2022.05.29/loongarch64-clfs-5.0-cross-tools-gcc-glibc.tar.xz

Reference: https://github.com/loongson/LoongArch-Documentation
The last commit hash (main branch) is:
99016636af64d02dee05e39974d4c1e55875c45b

Note loongarch32 is not fully tested because there is no reference
gcc toolchain yet.

Depends on D130239 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130255

Files:
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/Arch/LoongArch.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Clang.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/bin/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/include/.keep
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64d/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64f/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64s/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/bin/ld
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/lib/.keep
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/lib64/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/sysroot/usr/lib/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/sysroot/usr/lib64/.keep
  clang/test/Driver/frame-pointer.c
  clang/test/Driver/loongarch-abi.c
  clang/test/Driver/loongarch64-toolchain.c
  clang/test/Preprocessor/init-loongarch.c

Index: clang/test/Preprocessor/init-loongarch.c
===
--- /dev/null
+++ clang/test/Preprocessor/init-loongarch.c
@@ -0,0 +1,641 @@
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32 < /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA32 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32-unknown-linux < /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefixes=LA32,LA32-LINUX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32 \
+// RUN: -fforce-enable-int128 < /dev/null | FileCheck --match-full-lines \
+// RUN: --check-prefixes=LA32,LA32-INT128 %s
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64 < /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA64 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64-unknown-linux < /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefixes=LA64,LA64-LINUX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64 \
+// RUN: -fforce-enable-int128 < /dev/null | FileCheck --match-full-lines \
+// RUN: --check-prefixes=LA64,LA64-INT128 %s
+
+ Note that common macros are tested in init.c, such as __VERSION__. So they're not listed here.
+
+// LA32: #define _ILP32 1
+// LA32: #define __ATOMIC_ACQUIRE 2
+// LA32: #define __ATOMIC_ACQ_REL 4
+// LA32: #define __ATOMIC_CONSUME 1
+// LA32: #define __ATOMIC_RELAXED 0
+// LA32: #define __ATOMIC_RELEASE 3
+// LA32: #define __ATOMIC_SEQ_CST 5
+// LA32: #define __BIGGEST_ALIGNMENT__ 16
+// LA32: #define __BITINT_MAXWIDTH__ 128
+// LA32: #define __BOOL_WIDTH__ 8
+// LA32: #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// LA32: #define __CHAR16_TYPE__ unsigned short
+// LA32: #define __CHAR32_TYPE__ unsigned int
+// LA32: #define __CHAR_BIT__ 8
+// LA32: #define __CLANG_ATOMIC_BOOL_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR16_T_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR32_T_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_INT_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_LLONG

[PATCH] D130089: update-test-checks: safely handle tests with #if's

2022-07-21 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

I see what is going on here. The problem is not in this patch, but there is a 
problem in update_cc_test_checks.py.

I had all the other files in `clang/test/utils/update_cc_test_checks` still 
checked out as unix line endings from before I had updated the config, and that 
is why they were not failing.

Fixing `update_cc_test_checks.py` and restoring those other files makes every 
test pass.
Here is my diff:

  diff --git a/llvm/utils/update_cc_test_checks.py 
b/llvm/utils/update_cc_test_checks.py
  index b9e91f19461b..0e755d100760 100755
  --- a/llvm/utils/update_cc_test_checks.py
  +++ b/llvm/utils/update_cc_test_checks.py
  @@ -414,7 +414,7 @@ def main():
  output_lines, global_vars_seen_dict, True, 
False)
   common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))
   with open(ti.path, 'wb') as f:
  -  f.writelines(['{}\n'.format(l).encode('utf-8') for l in output_lines])
  +  f.writelines(['{}{}'.format(l, os.linesep).encode('utf-8') for l in 
output_lines])
  
 return 0

I will submit a MR with this patch later today.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130089

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


[PATCH] D130259: [clangd] fix crash and handle implicit conversions in inlay hints for forwarding functions

2022-07-21 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj created this revision.
upsj added reviewers: nridge, sammccall, kadircet.
upsj added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
upsj requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

The `ForwardingCallVisitor` previously picked up on (constructor or function) 
calls inside a single argument of a variadic function, where the corresponding 
pack expression is (partially) expanded, but only consists of a single entry. 
This mismatch between expecting the full pack and finding only a single entry 
caused a crash, which the first half of this diff fixes.

The second half deals with the failure of `resolveForwardingParameters` to 
detect forwarded parameters when implicit conversions happen via constructor 
calls, not normal `ImplicitCastExpr`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130259

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -680,6 +680,71 @@
   ExpectedHint{"C: ", "param3"});
 }
 
+TEST(ParameterHints, VariadicWithConstructorConversion) {
+  // variadic call that involves a conversion via a (potentially implicitly
+  // provided) constructor, here move-construction Foo&& -> Foo
+  assertParameterHints(
+  R"cpp(
+struct Foo {};
+void foo(Foo s, int x);
+
+template 
+void bar(_Args ...__args) {
+  foo(__args...);
+}
+
+void foo() {
+  bar($param1[[Foo{}]], $param2[[3]]);
+}
+  )cpp",
+  ExpectedHint{"s: ", "param1"}, ExpectedHint{"x: ", "param2"});
+}
+
+TEST(ParameterHints, VariadicWithOperatorConversion) {
+  // variadic call that involves a conversion via an operator, here Foo -> Bar
+  assertParameterHints(
+  R"cpp(
+struct Bar {};
+struct Foo {
+  operator Bar();
+};
+void foo(Bar s, int x);
+
+template 
+void bar(_Args ...__args) {
+  foo(__args...);
+}
+
+void foo() {
+  bar($param1[[Foo{}]], $param2[[3]]);
+}
+  )cpp" /*, ExpectedHint{"s: ", "param1"}, ExpectedHint{"x: ", "param2"}*/);
+}
+
+TEST(ParameterHints, VariadicWithFunctionCall) {
+  // variadic call that involves an explicit transformation via a function, here
+  // we don't output an inlay hint, since it's not clear what transform does.
+  assertParameterHints(
+  R"cpp(
+struct Bar {};
+struct Foo {
+  operator Bar();
+};
+template 
+T transform(T);
+void foo(Bar s, int x);
+
+template 
+void bar(_Args ...__args) {
+  foo(transform(__args)...);
+}
+
+void foo() {
+  bar(Foo{}, 3);
+}
+  )cpp");
+}
+
 TEST(ParameterHints, VariadicReferenceHint) {
   assertParameterHints(R"cpp(
 void foo(int&);
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -832,10 +832,26 @@
   }
   return false;
 });
-if (FirstMatch == Args.end()) {
-  return llvm::None;
+if (FirstMatch != Args.end()) {
+  const auto NumArgs =
+  static_cast(std::distance(Args.begin(), Args.end()));
+  const auto FirstMatchIdx =
+  static_cast(std::distance(Args.begin(), FirstMatch));
+  // Now we found the first parameter, check whether the last one also fits
+  // This is necessary because we may be matching a function call inside an
+  // argument of the variadic function if we didn't successfully match the
+  // outer variadic call.
+  const auto LastMatchIdx = FirstMatchIdx + Parameters.size() - 1;
+  if (LastMatchIdx < NumArgs) {
+if (const auto *RefArg =
+unwrapArgument(*(Args.begin() + LastMatchIdx))) {
+  if (Parameters.back() == dyn_cast(RefArg->getDecl())) {
+return FirstMatchIdx;
+  }
+}
+  }
 }
-return std::distance(Args.begin(), FirstMatch);
+return llvm::None;
   }
 
   static FunctionDecl *getCalleeDeclOrUniqueOverload(CallExpr *E) {
@@ -881,7 +897,7 @@
 return E;
   }
 
-  // Maps std::forward(E) to E, nullptr otherwise
+  // Maps std::forward(E) to E
   static const Expr *unwrapForward(const Expr *E) {
 if (const auto *Call = dyn_cast(E)) {
   const auto Callee = Call->getBuiltinCallee();
@@ -892,10 +908,26 @@
 return E;
   }
 
+  // Maps an argument implicitly calling a converting constructor to the
+  // constructor's argument
+  static const Expr *unwrapConstructorConversion(const Expr *E) {
+if (const auto *CBTE = dyn_cast(E)) {
+  E = CBTE->getSubExpr();
+}
+if (const auto *CCE = dyn_cast(E)) {
+  const auto *C = CCE->getConstructor();
+  

[PATCH] D130259: [clangd] fix crash and handle implicit conversions in inlay hints for forwarding functions

2022-07-21 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj added inline comments.



Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:721
+}
+  )cpp" /*, ExpectedHint{"s: ", "param1"}, ExpectedHint{"x: ", "param2"}*/);
+}

I'm not sure whether we should detect this case, since it would be nice to 
handle, but also involves digging deep through `CXXConstructExpression -> 
MaterializeTemporaryExpression -> CXXMemberCallExpr -> MemberExpr -> 
DeclRefExpr`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130259

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


[PATCH] D130260: [clangd] Make forwarding parameter detection logic resilient

2022-07-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.

This could crash when our heuristic picks the wrong function. Make sure
there is enough parameters in the candidate to prevent those crashes.

Also special case copy/move constructors to make the heuristic work in
presence of those.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130260

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1432,26 +1432,30 @@
 TEST(ParameterHints, ArgPacksAndConstructors) {
   assertParameterHints(
   R"cpp(
-struct Foo{ Foo(int x); };
+struct Foo{ Foo(); Foo(int x); };
 void foo(Foo a, int b);
-
 template 
-void bar(Args... args) { foo(args...); }
-
+void bar(Args... args) {
+  foo(args...);
+}
 template 
-void baz(Args... args) { foo(Foo(args...), args...); }
+void baz(Args... args) { foo($param1[[Foo{args...}]], $param2[[1]]); }
 
 template 
-void bax(Args... args) { foo({args...}, args...); }
+void bax(Args... args) { foo($param3[[{args...}]], args...); }
 
 void foo() {
-  bar($param1[[Foo{2}]], $param2[[42]]);
-  baz($param3[[42]]);
-  bax($param4[[42]]);
+  bar($param4[[Foo{}]], $param5[[42]]);
+  bar($param6[[42]], $param7[[42]]);
+  baz($param8[[42]]);
+  bax($param9[[42]]);
 }
   )cpp",
   ExpectedHint{"a: ", "param1"}, ExpectedHint{"b: ", "param2"},
-  ExpectedHint{"x: ", "param3"}, ExpectedHint{"x: ", "param4"});
+  ExpectedHint{"a: ", "param3"}, ExpectedHint{"a: ", "param4"},
+  ExpectedHint{"b: ", "param5"}, ExpectedHint{"a: ", "param6"},
+  ExpectedHint{"b: ", "param7"}, ExpectedHint{"x: ", "param8"},
+  ExpectedHint{"b: ", "param9"});
 }
 
 // FIXME: Low-hanging fruit where we could omit a type hint:
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -786,6 +786,9 @@
   // inspects the given callee with the given args to check whether it
   // contains Parameters, and sets Info accordingly.
   void handleCall(FunctionDecl *Callee, typename CallExpr::arg_range Args) {
+// Skip functions with less parameters, they can't be the target.
+if (Callee->parameters().size() < Parameters.size())
+  return;
 if (std::any_of(Args.begin(), Args.end(), [](const Expr *E) {
   return dyn_cast(E) != nullptr;
 })) {
@@ -823,8 +826,7 @@
   llvm::Optional findPack(typename CallExpr::arg_range Args) {
 // find the argument directly referring to the first parameter
 for (auto It = Args.begin(); It != Args.end(); ++It) {
-  const Expr *Arg = *It;
-  if (const auto *RefArg = unwrapForward(Arg)) {
+  if (const auto *RefArg = unwrapForward(*It)) {
 if (Parameters.front() != dyn_cast(RefArg->getDecl()))
   continue;
 return std::distance(Args.begin(), It);
@@ -871,6 +873,13 @@
   // Maps std::forward(E) to E, identity otherwise.
   static const DeclRefExpr *unwrapForward(const Expr *E) {
 E = E->IgnoreImplicitAsWritten();
+// There might be an implicit copy/move constructor call on top of the
+// forwarded arg.
+// FIXME: Maybe mark that in the AST as so, this might skip explicit calls
+// too.
+if (const auto *Const = dyn_cast(E))
+  if (Const->getConstructor()->isCopyOrMoveConstructor())
+E = Const->getArg(0)->IgnoreImplicitAsWritten();
 if (const auto *Call = dyn_cast(E)) {
   const auto Callee = Call->getBuiltinCallee();
   if (Callee == Builtin::BIforward) {


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1432,26 +1432,30 @@
 TEST(ParameterHints, ArgPacksAndConstructors) {
   assertParameterHints(
   R"cpp(
-struct Foo{ Foo(int x); };
+struct Foo{ Foo(); Foo(int x); };
 void foo(Foo a, int b);
-
 template 
-void bar(Args... args) { foo(args...); }
-
+void bar(Args... args) {
+  foo(args...);
+}
 template 
-void baz(Args... args) { foo(Foo(args...), args...); }
+void baz(Args... args) { foo($param1[[Foo{args...}]], $param2[[1]]); }
 
 template 
-void bax(Args... args) { foo({args...}, args...); }
+void bax(Args... args) { foo($param3[[{args...}]], args...); }
 

[PATCH] D130261: [clangd] Refactor forwarding call detection logic

2022-07-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130261

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1429,6 +1429,31 @@
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, ArgPacksAndConstructors) {
+  assertParameterHints(
+  R"cpp(
+struct Foo{ Foo(int x); };
+void foo(Foo a, int b);
+
+template 
+void bar(Args... args) { foo(args...); }
+
+template 
+void baz(Args... args) { foo(Foo(args...), args...); }
+
+template 
+void bax(Args... args) { foo({args...}, args...); }
+
+void foo() {
+  bar($param1[[Foo{2}]], $param2[[42]]);
+  baz($param3[[42]]);
+  bax($param4[[42]]);
+}
+  )cpp",
+  ExpectedHint{"a: ", "param1"}, ExpectedHint{"b: ", "param2"},
+  ExpectedHint{"x: ", "param3"}, ExpectedHint{"x: ", "param4"});
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -792,50 +792,45 @@
   return;
 }
 auto OptPackLocation = findPack(Args);
-if (OptPackLocation) {
-  size_t PackLocation = OptPackLocation.value();
-  ArrayRef MatchingParams =
-  Callee->parameters().slice(PackLocation, Parameters.size());
-  // Check whether the function has a parameter pack as the last template
-  // parameter
-  if (const auto *TTPT = getFunctionPackType(Callee)) {
-// In this case: Separate the parameters into head, pack and tail
-auto IsExpandedPack = [&](const ParmVarDecl *P) {
-  return getUnderylingPackType(P) == TTPT;
-};
-ForwardingInfo FI;
-FI.Head = MatchingParams.take_until(IsExpandedPack);
-FI.Pack = MatchingParams.drop_front(FI.Head.size())
-  .take_while(IsExpandedPack);
-FI.Tail = MatchingParams.drop_front(FI.Head.size() + FI.Pack.size());
-FI.PackTarget = Callee;
-Info = FI;
-return;
-  }
-  // Default case: assume all parameters were fully resolved
+if (!OptPackLocation)
+  return;
+ArrayRef MatchingParams =
+Callee->parameters().slice(*OptPackLocation, Parameters.size());
+// Check whether the function has a parameter pack as the last template
+// parameter
+if (const auto *TTPT = getFunctionPackType(Callee)) {
+  // In this case: Separate the parameters into head, pack and tail
+  auto IsExpandedPack = [&](const ParmVarDecl *P) {
+return getUnderylingPackType(P) == TTPT;
+  };
   ForwardingInfo FI;
-  FI.Head = MatchingParams;
+  FI.Head = MatchingParams.take_until(IsExpandedPack);
+  FI.Pack =
+  MatchingParams.drop_front(FI.Head.size()).take_while(IsExpandedPack);
+  FI.Tail = MatchingParams.drop_front(FI.Head.size() + FI.Pack.size());
+  FI.PackTarget = Callee;
   Info = FI;
+  return;
 }
+// Default case: assume all parameters were fully resolved
+ForwardingInfo FI;
+FI.Head = MatchingParams;
+Info = FI;
   }
 
   // Returns the beginning of the expanded pack represented by Parameters
   // in the given arguments, if it is there.
   llvm::Optional findPack(typename CallExpr::arg_range Args) {
 // find the argument directly referring to the first parameter
-auto FirstMatch = std::find_if(Args.begin(), Args.end(), [&](Expr *Arg) {
-  const auto *RefArg = unwrapArgument(Arg);
-  if (RefArg) {
-if (Parameters.front() == dyn_cast(RefArg->getDecl())) {
-  return true;
-}
+for (auto It = Args.begin(); It != Args.end(); ++It) {
+  const Expr *Arg = *It;
+  if (const auto *RefArg = unwrapForward(Arg)) {
+if (Parameters.front() != dyn_cast(RefArg->getDecl()))
+  continue;
+return std::distance(Args.begin(), It);
   }
-  return false;
-});
-if (FirstMatch == Args.end()) {
-  return llvm::None;
 }
-return std::distance(Args.begin(), FirstMatch);
+return llvm::None;
   }
 
   static FunctionDecl *getCalleeDeclOrUniqueOverload(CallExpr *E) {
@@ -847,7 +842,7 @@
   }
 }
 // Ignore the callee if the number of arguments is wrong (deal with va_args)
-if (Callee->getNumParams(

[PATCH] D130210: [SemaCXX] Set promotion type for enum bool to integer type.

2022-07-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:16198-16201
+if (EnumTy->isPromotableIntegerType())
+  ED->setPromotionType(Context.getPromotedIntegerType(EnumTy));
+else
+  ED->setPromotionType(EnumTy);





Comment at: clang/lib/Sema/SemaDecl.cpp:16824-16828
+  QualType EnumTy = ED->getIntegerType();
+  if (EnumTy->isPromotableIntegerType())
+ED->setPromotionType(Context.getPromotedIntegerType(EnumTy));
+  else
+ED->setPromotionType(EnumTy);

Same here as above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130210

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


[PATCH] D122683: [OpenMP] Use new offloading binary when embedding offloading images

2022-07-21 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

I'm sorry for noticing it this late but this change seems to have broken the 
test on 32-bit x86:

  FAIL: Clang :: Frontend/embed-object.ll (8280 of 15613)
   TEST 'Clang :: Frontend/embed-object.ll' FAILED 

  Script:
  --
  : 'RUN: at line 1';   
/var/tmp/portage/sys-devel/clang-15.0.0./work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-15.0.0./work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/15.0.0/include
 -nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm 
-fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/Inputs/empty.h
 
-fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/Inputs/empty.h
 -x ir 
/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll
 -o - | /usr/lib/llvm/15/bin/FileCheck 
/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll
 -check-prefix=CHECK
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  + : 'RUN: at line 1'
  + 
/var/tmp/portage/sys-devel/clang-15.0.0./work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-15.0.0./work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/15.0.0/include
 -nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm 
-fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/Inputs/empty.h
 
-fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/Inputs/empty.h
 -x ir 
/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll
 -o -
  + /usr/lib/llvm/15/bin/FileCheck 
/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll
 -check-prefix=CHECK
  warning: overriding the module target triple with x86_64-unknown-linux-gnu 
[-Woverride-module]
  1 warning generated.
  
/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll:6:10:
 error: CHECK: expected string not found in input
  ; CHECK: @[[OBJECT_1:.+]] = private constant [0 x i8] zeroinitializer, 
section ".llvm.offloading", align 8, !exclude
   ^
  :1:1: note: scanning from here
  ; ModuleID = 
'/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll'
  ^
  :8:20: note: possible intended match here
  @llvm.embedded.object.1 = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading", align 4, !exclude !0
 ^
  
  Input file: 
  Check file: 
/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll
  
  -dump-input=help explains the following input dump.
  
  Input was:
  <<
 1: ; ModuleID = 
'/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll'
 
  check:6'0 
X
 error: no match found
 2: source_filename = 
"/var/tmp/portage/sys-devel/clang-15.0.0./work/clang/test/Frontend/embed-object.ll"
 
  check:6'0 
~~
 3: target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 
  check:6'0 
~
 4: target triple = "x86_64-unknown-linux-gnu" 
  check:6'0 ~~~
 5:  
  check:6'0 ~
 6: @x = private constant i8 1 
  check:6'0 ~~~
 7: @llvm.embedded.object = private constant [0 x i8] 
zeroinitializer, section ".llvm.offloading", align 4, !exclude !0 
  check:6'0 

 8: @llvm.embedded.object.1 = private constant [0 x i8] 
zeroinitializer, section ".llvm.offloading", align 4, !exclude !0 
  check:6'0 
~~
  check:6'1?
   possible intended match
 9: @llvm.compiler.used = appending global [3 x ptr] [ptr @x, ptr 
@llvm.embedded.object, ptr @llvm.embedded.object.1], section "llvm.metadata" 
  check:6'0 
~~~
10:  
  check:6'0 ~
11: define i32 @foo() { 
  check:6'0 
12:  ret i32 0 
  check:6'0 ~~~
   

[PATCH] D111617: [RISCV] Lazily add RVV C intrinsics.

2022-07-21 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111617

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


[PATCH] D122683: [OpenMP] Use new offloading binary when embedding offloading images

2022-07-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D122683#3668412 , @mgorny wrote:

> I'm sorry for noticing it this late but this change seems to have broken the 
> test on 32-bit x86:

Seems to be a difference in the alignment, I'm not sure why this changes though 
because the test should specify x86_64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122683

___
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-07-21 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D126907#3667265 , @ChuanqiXu wrote:

> In D126907#3665900 , @erichkeane 
> wrote:
>
>> The more I look at this... the more I question my approach.  I now am 
>> definitely sure we won't make Clang15, and hope that I can figure something 
>> better out for 16 :/
>
> I feel like it could be helpful to split it into several small patches next 
> time.

I REALLY wish I knew how to make that happen.  The problem is the main idea 
(deferring instantiation) is an 'all or nothing' that really seems to break 
things.  There are a handful of small-ish 'cleanup' tasks that I did along the 
way, and could probably come up with another, but I'm not sure how much I can 
remove from the patch to split it up :/


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] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-21 Thread Renato Golin via Phabricator via cfe-commits
rengolin added a comment.

This looks great, thanks!

Exciting that we can finally go all the way from C source to LoongArch binary.

The changes look good to me, other than a few nits. But please wait for a day 
or two for other people to review on their own time.




Comment at: clang/lib/Basic/Targets/LoongArch.h:69
+// TODO: select appropriate ABI.
+ABI = "ilp32d";
+  }

nit: this should use `setABI`. Right now, there's no difference, but once the 
function does more (like setting other ABI flags), you won't need to change it 
here. Same for the 64-bit version.



Comment at: clang/lib/Driver/ToolChains/Arch/LoongArch.h:25
+} // end namespace loongarch
+} // namespace tools
+} // end namespace driver

nit: comment mismatch "end"



Comment at: clang/test/Driver/loongarch-abi.c:41
+
+// CHECK-LA32-LP64S: error: unknown target ABI 'lp64s'
+// CHECK-LA32-LP64F: error: unknown target ABI 'lp64f'

please, split between pass and error by adding a new `loongarch-abi-error.c` 
and adding the `error` tests to it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130255

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


[PATCH] D122683: [OpenMP] Use new offloading binary when embedding offloading images

2022-07-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D122683#3668423 , @jhuber6 wrote:

> In D122683#3668412 , @mgorny wrote:
>
>> I'm sorry for noticing it this late but this change seems to have broken the 
>> test on 32-bit x86:
>
> Seems to be a difference in the alignment, I'm not sure why this changes 
> though because the test should specify x86_64.

Actually I think the alignment comes from `alignof` on a struct which doesn't 
care about the target, just the machine compiling it. Even still that struct 
has `int64_t` members so I figured it would be 8-byte aligned. I should 
probably just hard-code it to 8.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122683

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


[PATCH] D129748: [C++20] [Modules] Warn for the use of preferred_name in modules

2022-07-21 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D129748#3667932 , @ChuanqiXu wrote:

> @erichkeane @aaron.ballman @tahonermann I get another idea. We could tell the 
> user honestly that we couldn't handle it (temporarily). We could still 
> modularize the STL by a trick: 
> https://github.com/ChuanqiXu9/stdmodules/blob/e81f4e9e74f96021f2e45c48f44da93e806c4524/Makefile#L3
>
> In this way, we don't need to worry about the dirty implementation pollutes 
> the sources. (I think it is not bad to emit a warning to tell the user we 
> couldn't do something (now).)

Thats a heck of an "STL Trick".  The diagnostic itself needs some rewording, 
and I don't know if we do diagnostics for our implementation deficiencies.

I still consider the 'disable the attribute' as perhaps the 'best idea' for now 
other than fixing the bug, but had suggested earlier doing it NOT at the 
SemaDeclAttr level, but to do it at the ASTWriter-when-in-modules level.


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

https://reviews.llvm.org/D129748

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


[PATCH] D130265: [clangd] resolve forwarded parameters in Hover

2022-07-21 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj created this revision.
upsj added reviewers: sammccall, kadircet.
upsj added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
upsj requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

This uses `resolveForwardedParameters` to get parameter names in Hover. The 
patch currently produces a slight inconsistency, since the definition uses the 
original function decl, while the parameters are resolved correctly.
I could use some feedback on how this should be handled - maybe add a comment 
in the style of "This function involves forwarding" that explains why the 
parameter names don't match?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130265

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


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -263,6 +263,29 @@
  {{"bool"}, std::string("T"), std::string("false")},
  };
}},
+  // Forwarding function decl
+  {R"cpp(
+  void baz(int a);
+  template 
+  void foo(Args... args) {
+baz(args...);
+  }
+
+  void bar() {
+[[fo^o]](3);
+  }
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "foo";
+ HI.Kind = index::SymbolKind::Function;
+ HI.Definition = "template <> void foo << int >> (int args)";
+ HI.ReturnType = "void";
+ HI.Type = "void (int)";
+ HI.Parameters = {
+ {{"int"}, std::string("a"), llvm::None},
+ };
+   }},
   // Pointers to lambdas
   {R"cpp(
 void foo() {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -369,7 +369,7 @@
const FunctionDecl *FD,
const PrintingPolicy &PP) {
   HI.Parameters.emplace();
-  for (const ParmVarDecl *PVD : FD->parameters())
+  for (const ParmVarDecl *PVD : resolveForwardingParameters(FD))
 HI.Parameters->emplace_back(toHoverInfoParam(PVD, PP));
 
   // We don't want any type info, if name already contains it. This is true for
@@ -385,7 +385,6 @@
   if (const VarDecl *VD = llvm::dyn_cast(D)) // Lambdas
 QT = VD->getType().getDesugaredType(D->getASTContext());
   HI.Type = printType(QT, D->getASTContext(), PP);
-  // FIXME: handle variadics.
 }
 
 // Non-negative numbers are printed using min digits


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -263,6 +263,29 @@
  {{"bool"}, std::string("T"), std::string("false")},
  };
}},
+  // Forwarding function decl
+  {R"cpp(
+  void baz(int a);
+  template 
+  void foo(Args... args) {
+baz(args...);
+  }
+
+  void bar() {
+[[fo^o]](3);
+  }
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.Name = "foo";
+ HI.Kind = index::SymbolKind::Function;
+ HI.Definition = "template <> void foo << int >> (int args)";
+ HI.ReturnType = "void";
+ HI.Type = "void (int)";
+ HI.Parameters = {
+ {{"int"}, std::string("a"), llvm::None},
+ };
+   }},
   // Pointers to lambdas
   {R"cpp(
 void foo() {
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -369,7 +369,7 @@
const FunctionDecl *FD,
const PrintingPolicy &PP) {
   HI.Parameters.emplace();
-  for (const ParmVarDecl *PVD : FD->parameters())
+  for (const ParmVarDecl *PVD : resolveForwardingParameters(FD))
 HI.Parameters->emplace_back(toHoverInfoParam(PVD, PP));
 
   // We don't want any type info, if name already contains it. This is true for
@@ -385,7 +385,6 @@
   if (const VarDecl *VD = llvm::dyn_cast(D)) // Lambdas
 QT = VD->getType().getDesugaredType(D->getASTContext());
   HI.Type = printType(QT, D->getASTContext(), PP);
-  // FIXME: handle variadics.
 }
 
 // Non-negative numbers are printed using min digits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang] ee88c0c - [NFCI] Fix unused variable/function warnings in MacroCallReconstructorTest.cpp when asserts are disabled.

2022-07-21 Thread Manuel Klimek via cfe-commits
Ping :)

On Mon, Jul 18, 2022 at 1:22 PM Manuel Klimek  wrote:

> Ping :)
>
> On Wed, Jul 13, 2022 at 11:43 AM Manuel Klimek  wrote:
>
>> This is a functional change, as it removes the debug output when the
>> tokens do not match, which is important for understanding test failures.
>>
>> On Wed, Jul 13, 2022 at 1:47 AM Jorge Gorbe Moya via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>>
>>> Author: Jorge Gorbe Moya
>>> Date: 2022-07-12T16:46:58-07:00
>>> New Revision: ee88c0cf09969ba44307068797e12533b94768a6
>>>
>>> URL:
>>> https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6
>>> DIFF:
>>> https://github.com/llvm/llvm-project/commit/ee88c0cf09969ba44307068797e12533b94768a6.diff
>>>
>>> LOG: [NFCI] Fix unused variable/function warnings in
>>> MacroCallReconstructorTest.cpp when asserts are disabled.
>>>
>>> Added:
>>>
>>>
>>> Modified:
>>> clang/unittests/Format/MacroCallReconstructorTest.cpp
>>>
>>> Removed:
>>>
>>>
>>>
>>>
>>> 
>>> diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp
>>> b/clang/unittests/Format/MacroCallReconstructorTest.cpp
>>> index 2bda62aa42be..3abe0383aeae 100644
>>> --- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
>>> +++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
>>> @@ -91,14 +91,6 @@ struct Chunk {
>>>llvm::SmallVector Children;
>>>  };
>>>
>>> -bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
>>> -  if (Left->getType() == Right->getType() &&
>>> -  Left->TokenText == Right->TokenText)
>>> -return true;
>>> -  llvm::dbgs() << Left->TokenText << " != " << Right->TokenText << "\n";
>>> -  return false;
>>> -}
>>> -
>>>  // Allows to produce chunks of a token list by typing the code of equal
>>> tokens.
>>>  //
>>>  // Created from a list of tokens, users call "consume" to get the next
>>> chunk
>>> @@ -110,7 +102,9 @@ struct Matcher {
>>>Chunk consume(StringRef Tokens) {
>>>  TokenList Result;
>>>  for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
>>> -  assert(tokenMatches(*It, Token));
>>> +  (void)Token;  // Fix unused variable warning when asserts are
>>> disabled.
>>> +  assert((*It)->getType() == Token->getType() &&
>>> + (*It)->TokenText == Token->TokenText);
>>>Result.push_back(*It);
>>>++It;
>>>  }
>>>
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-21 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Tests ran clean for me as well.  Looking at the CI, it appears that the libcxx 
tests are improperly configured, and are being run against an 'older' version 
of the compiler (not including this patch).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129048

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


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-21 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D129048#3668542 , @erichkeane 
wrote:

> Tests ran clean for me as well.  Looking at the CI, it appears that the 
> libcxx tests are improperly configured, and are being run against an 'older' 
> version of the compiler (not including this patch).

The libc++ CI isn't misconfigured. libc++ supports older clang versions. Please 
revert this and fix the tests. You should be able to use a regex.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129048

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


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-21 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

Also, please wait for #libc  approval next 
time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129048

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


[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 created this revision.
yurai007 added reviewers: nikic, dexonsmith, wolfgangp, dblaikie.
Herald added subscribers: jsji, ecnelises, pengfei, kbarton, hiraditya, 
nemanjai.
Herald added a project: All.
yurai007 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Depends on: https://reviews.llvm.org/D129781 and address comment: 
https://reviews.llvm.org/D129781#3655571

TODO: add unit tests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130268

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/Parser.cpp
  llvm/include/llvm/ADT/SmallVector.h
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -7653,7 +7653,7 @@
 
   /// Functions adds masks, merging them into  single one.
   void addMask(ArrayRef SubMask) {
-SmallVector NewMask(SubMask.begin(), SubMask.end());
+SmallVector NewMask = SubMask;
 addMask(NewMask);
   }
 
@@ -8749,7 +8749,7 @@
   return PoisonValue::get(FixedVectorType::get(
   cast(V1->getType())->getElementType(), Mask.size()));
 Value *Op = V1;
-SmallVector CombinedMask(Mask.begin(), Mask.end());
+SmallVector CombinedMask = Mask;
 PeekThroughShuffles(Op, CombinedMask);
 if (!isa(Op->getType()) ||
 !IsIdentityMask(CombinedMask, cast(Op->getType( {
Index: llvm/lib/Target/X86/X86MCInstLower.cpp
===
--- llvm/lib/Target/X86/X86MCInstLower.cpp
+++ llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -1857,7 +1857,7 @@
   SrcOp2.isReg() ? GetRegisterName(SrcOp2.getReg()) : "mem";
 
   // One source operand, fix the mask to print all elements in one span.
-  SmallVector ShuffleMask(Mask.begin(), Mask.end());
+  SmallVector ShuffleMask = Mask;
   if (Src1Name == Src2Name)
 for (int i = 0, e = ShuffleMask.size(); i != e; ++i)
   if (ShuffleMask[i] >= e)
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -6133,7 +6133,7 @@
 SmallVectorImpl &WidenedMask) {
   // Create an alternative mask with info about zeroable elements.
   // Here we do not set undef elements as zeroable.
-  SmallVector ZeroableMask(Mask.begin(), Mask.end());
+  SmallVector ZeroableMask = Mask;
   if (V2IsZero) {
 assert(!Zeroable.isZero() && "V2's non-undef elements are used?!");
 for (int i = 0, Size = Mask.size(); i != Size; ++i)
@@ -11883,7 +11883,7 @@
   MVT VT = MVT::getVectorVT(EltVT, Mask.size());
 
   // We can't assume a canonical shuffle mask, so try the commuted version too.
-  SmallVector CommutedMask(Mask.begin(), Mask.end());
+  SmallVector CommutedMask = Mask;
   ShuffleVectorSDNode::commuteMask(CommutedMask);
 
   // Match any of unary/binary or low/high.
@@ -12742,7 +12742,7 @@
SelectionDAG &DAG) {
   uint64_t BlendMask = 0;
   bool ForceV1Zero = false, ForceV2Zero = false;
-  SmallVector Mask(Original.begin(), Original.end());
+  SmallVector Mask = Original;
   if (!matchShuffleAsBlend(V1, V2, Mask, Zeroable, ForceV1Zero, ForceV2Zero,
BlendMask))
 return SDValue();
@@ -14185,7 +14185,7 @@
 assert(VT == ExtVT && "Cannot change extended type when non-zeroable!");
 if (!VT.isFloatingPoint() || V2Index != 0)
   return SDValue();
-SmallVector V1Mask(Mask.begin(), Mask.end());
+SmallVector V1Mask = Mask;
 V1Mask[V2Index] = -1;
 if (!isNoopShuffleMask(V1Mask))
   return SDValue();
@@ -14334,7 +14334,7 @@
   // Match extracts of each half of the wide source vector. Commute the shuffle
   // if the extract of the low half is N1.
   unsigned NumElts = VT.getVectorNumElements();
-  SmallVector NewMask(Mask.begin(), Mask.end());
+  SmallVector NewMask = Mask;
   const APInt &ExtIndex0 = N0.getConstantOperandAPInt(1);
   const APInt &ExtIndex1 = N1.getConstantOperandAPInt(1);
   if (ExtIndex1 == 0 && ExtIndex0 == NumElts)
@@ -14638,7 +14638,7 @@
 return true;
 
   // Commute and try again.
-  SmallVector CommutedMask(Mask.begin(), Mask.end());
+  SmallVector Commute

[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:504
   llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
-  CGM.getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
+  CGM.getLLVMContext(), Packed ? PackedElems : to_vector(UnpackedElems),
+  Packed);

That's because of "error: conditional expression is ambiguous; 
'llvm::SmallVector' can be converted to 
'ArrayRef' and vice versa". Need to check if there is easier 
workaround.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130270: [clang][dataflow] Use a dedicated bool to encode which branch was taken

2022-07-21 Thread Sam Estep via Phabricator via cfe-commits
samestep created this revision.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
samestep requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a continuation of https://reviews.llvm.org/D129289 using @sgatev's 
feedback.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130270

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -1175,4 +1175,32 @@
   });
 }
 
+TEST_F(FlowConditionTest, JoinBackedge) {
+  std::string Code = R"(
+void target(bool Cond) {
+  bool Foo = true;
+  while (true) {
+(void)0;
+// [[p]]
+Foo = false;
+  }
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+auto &FooVal = *cast(Env.getValue(*FooDecl, SkipPast::None));
+
+EXPECT_FALSE(Env.flowConditionImplies(FooVal));
+  });
+}
+
 } // namespace
Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -179,7 +179,8 @@
   Context.addFlowConditionConstraint(FC2, C2);
   Context.addFlowConditionConstraint(FC2, C3);
 
-  auto &FC3 = Context.joinFlowConditions(FC1, FC2);
+  auto &B = Context.createAtomicBoolValue();
+  auto &FC3 = Context.joinFlowConditions(FC1, FC2, B);
   EXPECT_FALSE(Context.flowConditionImplies(FC3, C1));
   EXPECT_FALSE(Context.flowConditionImplies(FC3, C2));
   EXPECT_TRUE(Context.flowConditionImplies(FC3, C3));
@@ -435,38 +436,49 @@
   // FC2 = Y
   auto &FC2 = Context.makeFlowConditionToken();
   Context.addFlowConditionConstraint(FC2, Y);
-  // JoinedFC = (FC1 || FC2) && Z = (X || Y) && Z
-  auto &JoinedFC = Context.joinFlowConditions(FC1, FC2);
+  // JoinedFC = ((!B && FC1) || (B && FC2)) && Z = ((!B && X) || (B && Y)) && Z
+  auto &B = Context.createAtomicBoolValue();
+  auto &JoinedFC = Context.joinFlowConditions(FC1, FC2, B);
   Context.addFlowConditionConstraint(JoinedFC, Z);
 
-  // If any of X, Y is true in JoinedFC, JoinedFC = (X || Y) && Z is equivalent
-  // to evaluating the remaining Z
-  auto &JoinedFCWithXTrue =
-  Context.buildAndSubstituteFlowCondition(JoinedFC, {{&X, &True}});
-  auto &JoinedFCWithYTrue =
-  Context.buildAndSubstituteFlowCondition(JoinedFC, {{&Y, &True}});
+  // If any of (!B && X), (B && Y) is true in JoinedFC,
+  // JoinedFC = ((!B && X) || (B && Y)) && Z is equivalent to evaluating the
+  // remaining Z
+  auto &JoinedFCWithXTrue = Context.buildAndSubstituteFlowCondition(
+  JoinedFC, {{&B, &False}, {&X, &True}});
+  auto &JoinedFCWithYTrue = Context.buildAndSubstituteFlowCondition(
+  JoinedFC, {{&B, &True}, {&Y, &True}});
   EXPECT_TRUE(Context.equivalentBoolValues(JoinedFCWithXTrue, Z));
   EXPECT_TRUE(Context.equivalentBoolValues(JoinedFCWithYTrue, Z));
 
-  // If Z is true in JoinedFC, JoinedFC = (X || Y) && Z is equivalent to
-  // evaluating the remaining disjunction (X || Y)
+  // If Z is true in JoinedFC, JoinedFC = ((!B && X) || (B && Y)) && Z is
+  // equivalent to evaluating the remaining disjunction ((!B && X) || (B && Y))
   auto &JoinedFCWithZTrue =
   Context.buildAndSubstituteFlowCondition(JoinedFC, {{&Z, &True}});
   EXPECT_TRUE(Context.equivalentBoolValues(
-  JoinedFCWithZTrue, Context.getOrCreateDisjunction(X, Y)));
-
-  // If any of X, Y is false in JoinedFC, JoinedFC = (X || Y) && Z is equivalent
-  // to evaluating the conjunction of the other value and Z
+  JoinedFCWithZTrue,
+  Context.getOrCreateDisjunction(
+  Context.getOrCreateConjunction(Context.getOrCreateNegation(B), X),
+  Context.getOrCreateConjunction(B, Y;
+
+  // If any of X, Y is false in JoinedFC,
+  // JoinedFC = ((!B && X) || (B && Y)) && Z is equivalent to evaluating the
+  // conjunction of the other disjunct and Z
   auto &JoinedFCWithXFalse =
   Context.buildA

[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 added a comment.

Instead adding one more constructor another option is tweaking existing 
SmallVector(const iterator_range &R) one in following way:

  -  template 
  -  explicit SmallVector(const iterator_range &R)
  -  : SmallVectorImpl(N) {
  +  template , T>::value>>
  +  SmallVector(const Range &R) : SmallVectorImpl(N) {
   this->append(R.begin(), R.end());
  }

That would unlock possibility of creating SmallVector not only from ArrayRef 
but from every range as long as types are convertible.
I didn't explore this way further, I'm not sure but I believe it should work. 
It's more than just "adding ArrayRef constructor" but if you are interested I 
can check where it leads.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130261: [clangd] Refactor forwarding call detection logic

2022-07-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov requested changes to this revision.
ilya-biryukov added a comment.
This revision now requires changes to proceed.

The new test fails in the pre merge checks.
Maybe the diff is missing some more changes?




Comment at: clang-tools-extra/clangd/AST.cpp:794
 }
 auto OptPackLocation = findPack(Args);
+if (!OptPackLocation)

NIT: maybe rename to `PackLocation`?
now that there is only 1 variable we could use a shorter name without any 
confusion



Comment at: clang-tools-extra/clangd/AST.cpp:828
+  if (const auto *RefArg = unwrapForward(Arg)) {
+if (Parameters.front() != dyn_cast(RefArg->getDecl()))
+  continue;

NIT: doesn't this work without `dyn_cast`? looks redundant, I expect 
derived-to-base conversion to do the right thing.



Comment at: clang-tools-extra/clangd/AST.cpp:871
 
-  // Removes any implicit cast expressions around the given expression.
-  static const Expr *unwrapImplicitCast(const Expr *E) {
-while (const auto *Cast = dyn_cast(E)) {
-  E = Cast->getSubExpr();
-}
-return E;
-  }
-
-  // Maps std::forward(E) to E, nullptr otherwise
-  static const Expr *unwrapForward(const Expr *E) {
+  // Maps std::forward(E) to E, identity otherwise.
+  static const DeclRefExpr *unwrapForward(const Expr *E) {

Could you update the comment to account for the new semantics?



Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:1446
+void bax(Args... args) { foo({args...}, args...); }
+
+void foo() {

NIT: maybe test for the case with a single expansion here:
```
foo(Foo(args...), 1);
foo({args...}, 1);
```
?


testing multiple expansions is also interesting, but seems orthogonal to the 
change being made here.
E.g. tests for it would probably benefit from more than 2 appearances of `args` 
and more complicated nesting structures.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130261

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


[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:504
   llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
-  CGM.getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
+  CGM.getLLVMContext(), Packed ? PackedElems : to_vector(UnpackedElems),
+  Packed);

yurai007 wrote:
> That's because of "error: conditional expression is ambiguous; 
> 'llvm::SmallVector' can be converted to 
> 'ArrayRef' and vice versa". Need to check if there is 
> easier workaround.
Would making the ctor explicit help?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[clang] ceb6c23 - [NFC][LoopVectorize] Explicitly disable tail-folding on some SVE tests

2022-07-21 Thread David Sherwood via cfe-commits

Author: David Sherwood
Date: 2022-07-21T15:23:00+01:00
New Revision: ceb6c23b708d4cae3fbb0a569c5ac14069524a63

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

LOG: [NFC][LoopVectorize] Explicitly disable tail-folding on some SVE tests

This patch is in preparation for enabling vectorisation with tail-folding
by default for SVE targets. Once we do that many existing tests will
break that depend upon having normal unpredicated vector loops. For
all such tests I have added the flag:

  -prefer-predicate-over-epilogue=scalar-epilogue

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

Added: 


Modified: 
clang/test/CodeGen/aarch64-sve-vector-bits-codegen.c

llvm/test/Transforms/LoopVectorize/AArch64/gather-do-not-vectorize-addressing.ll
llvm/test/Transforms/LoopVectorize/AArch64/i1-reg-usage.ll
llvm/test/Transforms/LoopVectorize/AArch64/scalable-call.ll
llvm/test/Transforms/LoopVectorize/AArch64/scalable-reduction-inloop-cond.ll
llvm/test/Transforms/LoopVectorize/AArch64/scalable-reductions.ll
llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll

llvm/test/Transforms/LoopVectorize/AArch64/scalarize-store-with-predication.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-basic-vec.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-epilog-vect.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-fneg.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter-cost.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-illegal-type.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-inductions-unusual-types.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-inductions.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-loads.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-masked-loadstore.ll

llvm/test/Transforms/LoopVectorize/AArch64/sve-runtime-check-size-based-threshold.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-select-cmp.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-vector-reverse-mask4.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-vector-reverse.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll
llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-sve-vector-bits-codegen.c 
b/clang/test/CodeGen/aarch64-sve-vector-bits-codegen.c
index bccd328f0ccad..e306f44c27fb3 100644
--- a/clang/test/CodeGen/aarch64-sve-vector-bits-codegen.c
+++ b/clang/test/CodeGen/aarch64-sve-vector-bits-codegen.c
@@ -1,7 +1,11 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -O2 -S -o - %s -mvscale-min=2 -mvscale-max=2 
 | FileCheck %s --check-prefixes=CHECK,CHECK256
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -O2 -S -o - %s -mvscale-min=4 -mvscale-max=4 
 | FileCheck %s --check-prefixes=CHECK,CHECK512
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -O2 -S -o - %s -mvscale-min=8 -mvscale-max=8 
| FileCheck %s --check-prefixes=CHECK,CHECK1024
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -O2 -S -o - %s -mvscale-min=16 
-mvscale-max=16 | FileCheck %s --check-prefixes=CHECK,CHECK2048
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -O2 -S \
+// RUN:   -mllvm -prefer-predicate-over-epilogue=scalar-epilogue -o - %s 
-mvscale-min=2 -mvscale-max=2  | FileCheck %s --check-prefixes=CHECK,CHECK256
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -O2 -S \
+// RUN:   -mllvm -prefer-predicate-over-epilogue=scalar-epilogue -o - %s 
-mvscale-min=4 -mvscale-max=4  | FileCheck %s --check-prefixes=CHECK,CHECK512
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -O2 -S \
+// RUN:   -mllvm -prefer-predicate-over-epilogue=scalar-epilogue -o - %s 
-mvscale-min=8 -mvscale-max=8 | FileCheck %s --check-prefixes=CHECK,CHECK1024
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-fallow-half-arguments-and-returns -O2 -S \
+// RUN:   -m

[PATCH] D129137: [NFC][LoopVectorize] Explicitly disable tail-folding on some SVE tests

2022-07-21 Thread David Sherwood 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 rGceb6c23b708d: [NFC][LoopVectorize] Explicitly disable 
tail-folding on some SVE tests (authored by david-arm).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129137

Files:
  clang/test/CodeGen/aarch64-sve-vector-bits-codegen.c
  
llvm/test/Transforms/LoopVectorize/AArch64/gather-do-not-vectorize-addressing.ll
  llvm/test/Transforms/LoopVectorize/AArch64/i1-reg-usage.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-call.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-reduction-inloop-cond.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-reductions.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalarize-store-with-predication.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-basic-vec.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-epilog-vect.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-fneg.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter-cost.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-illegal-type.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-inductions-unusual-types.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-inductions.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-loads.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-masked-loadstore.ll
  
llvm/test/Transforms/LoopVectorize/AArch64/sve-runtime-check-size-based-threshold.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-select-cmp.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-vector-reverse-mask4.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-vector-reverse.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
  llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll
  llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll

Index: llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse.ll
@@ -5,7 +5,8 @@
 ;  for (int i = N-1; i >= 0; --i)
 ;a[i] = b[i] + 1.0;
 
-; RUN: opt -loop-vectorize -dce  -mtriple aarch64-linux-gnu -S < %s | FileCheck %s
+; RUN: opt -loop-vectorize -dce  -mtriple aarch64-linux-gnu -S \
+; RUN:   -prefer-predicate-over-epilogue=scalar-epilogue < %s | FileCheck %s
 
 define void @vector_reverse_f64(i64 %N, double* %a, double* %b) #0 {
 ; CHECK-LABEL: vector_reverse_f64
Index: llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/vector-reverse-mask4.ll
@@ -11,7 +11,8 @@
 
 ; The test checks if the mask is being correctly created, reverted  and used
 
-; RUN: opt -loop-vectorize -dce -instcombine -mtriple aarch64-linux-gnu -S < %s | FileCheck %s
+; RUN: opt -loop-vectorize -dce -instcombine -mtriple aarch64-linux-gnu -S \
+; RUN:   -prefer-predicate-over-epilogue=scalar-epilogue < %s | FileCheck %s
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 target triple = "aarch64-unknown-linux-gnu"
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -mtriple aarch64-linux-gnu -mattr=+sve -loop-vectorize -dce -instcombine -S < %s | FileCheck %s
+; RUN: opt -mtriple aarch64-linux-gnu -mattr=+sve -loop-vectorize -dce -instcombine -S \
+; RUN:   -prefer-predicate-over-epilogue=scalar-epilogue < %s | FileCheck %s
 
 ; Ensure that we can vectorize loops such as:
 ;   int *ptr = c;
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
@@ -1,6 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ;

[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:504
   llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
-  CGM.getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
+  CGM.getLLVMContext(), Packed ? PackedElems : to_vector(UnpackedElems),
+  Packed);

nikic wrote:
> yurai007 wrote:
> > That's because of "error: conditional expression is ambiguous; 
> > 'llvm::SmallVector' can be converted to 
> > 'ArrayRef' and vice versa". Need to check if there is 
> > easier workaround.
> Would making the ctor explicit help?
Nope :( Making constructor explicit disables implicit conversion so we cannot 
do things like: SmallVector NewMask = Mask; anymore.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130273: [clang][Driver] Handle SPARC -mcpu=native etc.

2022-07-21 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: MaskRay, glaubitz, jrtc27.
ro added a project: clang.
Herald added subscribers: StephenFan, fedor.sergeev, jyknight.
Herald added a project: All.
ro requested review of this revision.

To make use of SPARC support in `getHostCPUName` as implemented by D130272 
, this patch uses it to handle `-mcpu=native` 
and `-mtune=native`.

Tested on `sparcv9-sun-solaris2.11` and checking that those options are passed 
on as `-target-cpu` resp. `-tune-cpu` as expected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130273

Files:
  clang/lib/Driver/ToolChains/Arch/Sparc.cpp
  clang/lib/Driver/ToolChains/Arch/Sparc.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp

Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -12,6 +12,7 @@
 #include "Arch/M68k.h"
 #include "Arch/Mips.h"
 #include "Arch/PPC.h"
+#include "Arch/Sparc.h"
 #include "Arch/SystemZ.h"
 #include "Arch/VE.h"
 #include "Arch/X86.h"
@@ -431,14 +432,14 @@
 
   case llvm::Triple::bpfel:
   case llvm::Triple::bpfeb:
+if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
+  return A->getValue();
+return "";
+
   case llvm::Triple::sparc:
   case llvm::Triple::sparcel:
   case llvm::Triple::sparcv9:
-if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
-  return A->getValue();
-if (T.getArch() == llvm::Triple::sparc && T.isOSSolaris())
-  return "v9";
-return "";
+return sparc::getSparcTargetCPU(D, Args, T);
 
   case llvm::Triple::x86:
   case llvm::Triple::x86_64:
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2219,6 +2219,21 @@
 CmdArgs.push_back("-mfloat-abi");
 CmdArgs.push_back("hard");
   }
+
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
+StringRef Name = A->getValue();
+
+std::string TuneCPU;
+if (Name == "native")
+  TuneCPU = std::string(llvm::sys::getHostCPUName());
+else
+  TuneCPU = std::string(Name);
+
+if (!TuneCPU.empty()) {
+  CmdArgs.push_back("-tune-cpu");
+  CmdArgs.push_back(Args.MakeArgString(TuneCPU));
+}
+  }
 }
 
 void Clang::AddSystemZTargetArgs(const ArgList &Args,
Index: clang/lib/Driver/ToolChains/Arch/Sparc.h
===
--- clang/lib/Driver/ToolChains/Arch/Sparc.h
+++ clang/lib/Driver/ToolChains/Arch/Sparc.h
@@ -28,6 +28,9 @@
 
 FloatABI getSparcFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
+std::string getSparcTargetCPU(const Driver &D, const llvm::opt::ArgList &Args,
+  const llvm::Triple &Triple);
+
 void getSparcTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
 std::vector &Features);
 const char *getSparcAsmModeForCPU(llvm::StringRef Name,
Index: clang/lib/Driver/ToolChains/Arch/Sparc.cpp
===
--- clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -12,6 +12,7 @@
 #include "clang/Driver/Options.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang::driver;
 using namespace clang::driver::tools;
@@ -113,6 +114,28 @@
   return ABI;
 }
 
+std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,
+ const llvm::Triple &Triple) {
+  if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
+StringRef CPUName = A->getValue();
+
+if (CPUName == "native") {
+  std::string CPU = std::string(llvm::sys::getHostCPUName());
+  if (!CPU.empty() && CPU != "generic")
+return CPU;
+  else
+return "";
+}
+
+return std::string(CPUName);
+  }
+
+  if (Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris())
+return "v9";
+  else
+return "";
+}
+
 void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
std::vector &Features) {
   sparc::FloatABI FloatABI = sparc::getSparcFloatABI(D, Args);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-21 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In D129048#3668594 , @philnik wrote:

> Also, please wait for #libc  approval 
> next time.

This, x1000.

We go through the trouble of having excellent pre-commit testing and automatic 
review groups assigned to reviews, please don't bypass that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129048

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


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D129048#3668846 , @ldionne wrote:

> In D129048#3668594 , @philnik wrote:
>
>> Also, please wait for #libc  approval 
>> next time.
>
> This, x1000.
>
> We go through the trouble of having excellent pre-commit testing and 
> automatic review groups assigned to reviews, please don't bypass that.

We certainly will keep this in mind for the future, thanks for pointing it out! 
However, the precommit CI behavior confused multiple Clang contributors (I also 
thought the bot was misconfigured because Clang tests are never run against old 
Clang versions), the output did not clearly identify what was wrong or how to 
address it, and the difficulties with testing this locally are all things the 
libc++ maintainers should also keep in mind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129048

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


[PATCH] D130226: [clang-doc] Default to Standalone executor and improve documentation

2022-07-21 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth accepted this revision.
paulkirth added a comment.
This revision is now accepted and ready to land.

LGTM w/ the caveat that I think we should update the release notes, since we're 
changing the default behavior of a command line tool. I've also left a few 
small suggestions the wording.




Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:188
 
-  if (!Exec) {
-llvm::errs() << toString(Exec.takeError()) << "\n";
+  Example usage for files without flags:
+





Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:192
+
+  Example usage for a project using compile commands database:
+





Comment at: clang-tools-extra/docs/clang-doc.rst:28
 
-By default, the tool will run on all files listed in the given compile commands
-database:
+The tool will process listed files by default:
 





Comment at: clang-tools-extra/docs/clang-doc.rst:34
 
-The tool can also be used on a single file or multiple files if a build path is
-passed with the ``-p`` flag.
+The tool can be also used with compile commands database:
 





Comment at: clang-tools-extra/docs/clang-doc.rst:77
+
+Example usage for files without flags:
+





Comment at: clang-tools-extra/docs/clang-doc.rst:81
+
+Example usage for a project using compile commands database:
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130226

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


[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:504
   llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
-  CGM.getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
+  CGM.getLLVMContext(), Packed ? PackedElems : to_vector(UnpackedElems),
+  Packed);

yurai007 wrote:
> nikic wrote:
> > yurai007 wrote:
> > > That's because of "error: conditional expression is ambiguous; 
> > > 'llvm::SmallVector' can be converted to 
> > > 'ArrayRef' and vice versa". Need to check if there is 
> > > easier workaround.
> > Would making the ctor explicit help?
> Nope :( Making constructor explicit disables implicit conversion so we cannot 
> do things like: SmallVector NewMask = Mask; anymore.
And leaving it implicit hides the fact of possible memory allocation, which is 
not cheap. I think absense of such constructor is by-design.

Making it explicit is making it redundant, because there is already a 
constructor which accepts begin / end, and one that accepts range (note that it 
is explicit!). It won't save on typing, either.

I'm not in favor of this patch, but my word does not count much, so I won't 
block it. I'd suggest you, however, to request review of core maintainers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130279: [clang-doc] Add check for pointer validity

2022-07-21 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth created this revision.
paulkirth added reviewers: phosek, abrachet.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

clang-doc would SEGV when running over the Fuchsia code base.
This patch adds a check to avoid dereferencing potentially null pointers
in the Values vector. These pointers were either never valid or had been
invalidated when the underlying pointer in std::unique_ptr was moved from,
hence making it nullptr within the vector.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130279

Files:
  clang-tools-extra/clang-doc/Representation.cpp


Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -33,7 +33,7 @@
 template 
 llvm::Expected>
 reduce(std::vector> &Values) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no value to reduce");
   std::unique_ptr Merged = std::make_unique(Values[0]->USR);
@@ -95,7 +95,7 @@
 // Dispatch function.
 llvm::Expected>
 mergeInfos(std::vector> &Values) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no info values to merge");
 


Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -33,7 +33,7 @@
 template 
 llvm::Expected>
 reduce(std::vector> &Values) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no value to reduce");
   std::unique_ptr Merged = std::make_unique(Values[0]->USR);
@@ -95,7 +95,7 @@
 // Dispatch function.
 llvm::Expected>
 mergeInfos(std::vector> &Values) {
-  if (Values.empty())
+  if (Values.empty() || !Values[0])
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"no info values to merge");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:504
   llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
-  CGM.getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
+  CGM.getLLVMContext(), Packed ? PackedElems : to_vector(UnpackedElems),
+  Packed);

barannikov88 wrote:
> yurai007 wrote:
> > nikic wrote:
> > > yurai007 wrote:
> > > > That's because of "error: conditional expression is ambiguous; 
> > > > 'llvm::SmallVector' can be converted to 
> > > > 'ArrayRef' and vice versa". Need to check if there is 
> > > > easier workaround.
> > > Would making the ctor explicit help?
> > Nope :( Making constructor explicit disables implicit conversion so we 
> > cannot do things like: SmallVector NewMask = Mask; anymore.
> And leaving it implicit hides the fact of possible memory allocation, which 
> is not cheap. I think absense of such constructor is by-design.
> 
> Making it explicit is making it redundant, because there is already a 
> constructor which accepts begin / end, and one that accepts range (note that 
> it is explicit!). It won't save on typing, either.
> 
> I'm not in favor of this patch, but my word does not count much, so I won't 
> block it. I'd suggest you, however, to request review of core maintainers.
> Nope :( Making constructor explicit disables implicit conversion so we cannot 
> do things like: SmallVector NewMask = Mask; anymore.

I think that's fine. Similar to the existing iterator_range constructor, we 
would require `SmallVector NewMask(Mask)`, which seems like the 
idiomatic way to write it anyway?

> Making it explicit is making it redundant, because there is already a 
> constructor which accepts begin / end, and one that accepts range (note that 
> it is explicit!). It won't save on typing, either.

It is not redundant. It ensures that iterator_range and ArrayRef can be freely 
substituted. Switching iterator_range to ArrayRef currently requires going 
through a lot of SmallVector constructors and replacing them with less readable 
code. The alternative to this change is D129988, which looks like a significant 
regression in code quality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:504
   llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
-  CGM.getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
+  CGM.getLLVMContext(), Packed ? PackedElems : to_vector(UnpackedElems),
+  Packed);

nikic wrote:
> barannikov88 wrote:
> > yurai007 wrote:
> > > nikic wrote:
> > > > yurai007 wrote:
> > > > > That's because of "error: conditional expression is ambiguous; 
> > > > > 'llvm::SmallVector' can be converted to 
> > > > > 'ArrayRef' and vice versa". Need to check if there 
> > > > > is easier workaround.
> > > > Would making the ctor explicit help?
> > > Nope :( Making constructor explicit disables implicit conversion so we 
> > > cannot do things like: SmallVector NewMask = Mask; anymore.
> > And leaving it implicit hides the fact of possible memory allocation, which 
> > is not cheap. I think absense of such constructor is by-design.
> > 
> > Making it explicit is making it redundant, because there is already a 
> > constructor which accepts begin / end, and one that accepts range (note 
> > that it is explicit!). It won't save on typing, either.
> > 
> > I'm not in favor of this patch, but my word does not count much, so I won't 
> > block it. I'd suggest you, however, to request review of core maintainers.
> > Nope :( Making constructor explicit disables implicit conversion so we 
> > cannot do things like: SmallVector NewMask = Mask; anymore.
> 
> I think that's fine. Similar to the existing iterator_range constructor, we 
> would require `SmallVector NewMask(Mask)`, which seems like the 
> idiomatic way to write it anyway?
> 
> > Making it explicit is making it redundant, because there is already a 
> > constructor which accepts begin / end, and one that accepts range (note 
> > that it is explicit!). It won't save on typing, either.
> 
> It is not redundant. It ensures that iterator_range and ArrayRef can be 
> freely substituted. Switching iterator_range to ArrayRef currently requires 
> going through a lot of SmallVector constructors and replacing them with less 
> readable code. The alternative to this change is D129988, which looks like a 
> significant regression in code quality.
Please also consider the fact that this is API breaking change due to this 
"conditional expression is amiguous" error. Many external projects depend on 
LLVM/ADT, and all of them will have to adapt this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:504
   llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
-  CGM.getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
+  CGM.getLLVMContext(), Packed ? PackedElems : to_vector(UnpackedElems),
+  Packed);

barannikov88 wrote:
> nikic wrote:
> > barannikov88 wrote:
> > > yurai007 wrote:
> > > > nikic wrote:
> > > > > yurai007 wrote:
> > > > > > That's because of "error: conditional expression is ambiguous; 
> > > > > > 'llvm::SmallVector' can be converted to 
> > > > > > 'ArrayRef' and vice versa". Need to check if 
> > > > > > there is easier workaround.
> > > > > Would making the ctor explicit help?
> > > > Nope :( Making constructor explicit disables implicit conversion so we 
> > > > cannot do things like: SmallVector NewMask = Mask; anymore.
> > > And leaving it implicit hides the fact of possible memory allocation, 
> > > which is not cheap. I think absense of such constructor is by-design.
> > > 
> > > Making it explicit is making it redundant, because there is already a 
> > > constructor which accepts begin / end, and one that accepts range (note 
> > > that it is explicit!). It won't save on typing, either.
> > > 
> > > I'm not in favor of this patch, but my word does not count much, so I 
> > > won't block it. I'd suggest you, however, to request review of core 
> > > maintainers.
> > > Nope :( Making constructor explicit disables implicit conversion so we 
> > > cannot do things like: SmallVector NewMask = Mask; anymore.
> > 
> > I think that's fine. Similar to the existing iterator_range constructor, we 
> > would require `SmallVector NewMask(Mask)`, which seems like the 
> > idiomatic way to write it anyway?
> > 
> > > Making it explicit is making it redundant, because there is already a 
> > > constructor which accepts begin / end, and one that accepts range (note 
> > > that it is explicit!). It won't save on typing, either.
> > 
> > It is not redundant. It ensures that iterator_range and ArrayRef can be 
> > freely substituted. Switching iterator_range to ArrayRef currently requires 
> > going through a lot of SmallVector constructors and replacing them with 
> > less readable code. The alternative to this change is D129988, which looks 
> > like a significant regression in code quality.
> Please also consider the fact that this is API breaking change due to this 
> "conditional expression is amiguous" error. Many external projects depend on 
> LLVM/ADT, and all of them will have to adapt this change.
> It ensures that iterator_range and ArrayRef can be freely substituted. 
> Switching iterator_range to ArrayRef currently requires going through a lot 
> of SmallVector constructors and replacing them with less readable code. 

Ok, makes sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[clang-tools-extra] 1515490 - [clangd] Mention whether compile flags were inferred in check mode

2022-07-21 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-07-21T17:33:44+02:00
New Revision: 1515490c80fab3d60da58efcfc91155228f7a156

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

LOG: [clangd] Mention whether compile flags were inferred in check mode

That way when looking at logs it's clear whether diagnostics are a
result of compile flags mismatch.

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

Added: 


Modified: 
clang-tools-extra/clangd/tool/Check.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/tool/Check.cpp 
b/clang-tools-extra/clangd/tool/Check.cpp
index 54c7e91ab9815..1fc44fd29ce98 100644
--- a/clang-tools-extra/clangd/tool/Check.cpp
+++ b/clang-tools-extra/clangd/tool/Check.cpp
@@ -111,7 +111,9 @@ class Checker {
 
 if (auto TrueCmd = CDB->getCompileCommand(File)) {
   Cmd = std::move(*TrueCmd);
-  log("Compile command from CDB is: {0}", printArgv(Cmd.CommandLine));
+  log("Compile command {0} is: {1}",
+  Cmd.Heuristic.empty() ? "from CDB" : Cmd.Heuristic,
+  printArgv(Cmd.CommandLine));
 } else {
   Cmd = CDB->getFallbackCommand(File);
   log("Generic fallback command is: {0}", printArgv(Cmd.CommandLine));



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


[PATCH] D130228: [clangd] Mention whether compile flags were inferred in check mode

2022-07-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
kadircet marked an inline comment as done.
Closed by commit rG1515490c80fa: [clangd] Mention whether compile flags were 
inferred in check mode (authored by kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D130228?vs=446383&id=446518#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130228

Files:
  clang-tools-extra/clangd/tool/Check.cpp


Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -111,7 +111,9 @@
 
 if (auto TrueCmd = CDB->getCompileCommand(File)) {
   Cmd = std::move(*TrueCmd);
-  log("Compile command from CDB is: {0}", printArgv(Cmd.CommandLine));
+  log("Compile command {0} is: {1}",
+  Cmd.Heuristic.empty() ? "from CDB" : Cmd.Heuristic,
+  printArgv(Cmd.CommandLine));
 } else {
   Cmd = CDB->getFallbackCommand(File);
   log("Generic fallback command is: {0}", printArgv(Cmd.CommandLine));


Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -111,7 +111,9 @@
 
 if (auto TrueCmd = CDB->getCompileCommand(File)) {
   Cmd = std::move(*TrueCmd);
-  log("Compile command from CDB is: {0}", printArgv(Cmd.CommandLine));
+  log("Compile command {0} is: {1}",
+  Cmd.Heuristic.empty() ? "from CDB" : Cmd.Heuristic,
+  printArgv(Cmd.CommandLine));
 } else {
   Cmd = CDB->getFallbackCommand(File);
   log("Generic fallback command is: {0}", printArgv(Cmd.CommandLine));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-21 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D129048#3668905 , @aaron.ballman 
wrote:

> In D129048#3668846 , @ldionne wrote:
>
>> In D129048#3668594 , @philnik 
>> wrote:
>>
>>> Also, please wait for #libc  approval 
>>> next time.
>>
>> This, x1000.
>>
>> We go through the trouble of having excellent pre-commit testing and 
>> automatic review groups assigned to reviews, please don't bypass that.
>
> We certainly will keep this in mind for the future, thanks for pointing it 
> out! However, the precommit CI behavior confused multiple Clang contributors 
> (I also thought the bot was misconfigured because Clang tests are never run 
> against old Clang versions), the output did not clearly identify what was 
> wrong or how to address it, and the difficulties with testing this locally 
> are all things the libc++ maintainers should also keep in mind.

What can we do to make it easier for Clang contributors to understand the 
libc++ CI?
Maybe we can discuss it on Discord.




Comment at: 
libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.cpp:49
 volatile std::atomic fun;
-// expected-error-re@atomic:* {{static_assert failed due to requirement 
'!is_function::value'{{.*}}Pointer to function isn't allowed}}
+// expected-error-re@atomic:* {{static assertion failed due to requirement 
'!is_function::value'{{.*}}Pointer to function isn't allowed}}
 std::atomic_fetch_add(&fun, 0);

All libc++ tests need a regex accepting both the old and new diagnostic. Since 
we support older Clang versions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129048

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


[PATCH] D130078: [flang][nfc] Rename `AddOtherOptions` as `ForwardOptions`

2022-07-21 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D130078#3667188 , @MaskRay wrote:

> `forwardOptions` will be better if you are renaming it anyway.

I'd rather create a separate patch and update all other methods to follow 
LLVM's style. Any idea why the style is not followed in Clang.h 
?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130078

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


[PATCH] D130261: [clangd] Refactor forwarding call detection logic

2022-07-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:1446
+void bax(Args... args) { foo({args...}, args...); }
+
+void foo() {

ilya-biryukov wrote:
> NIT: maybe test for the case with a single expansion here:
> ```
> foo(Foo(args...), 1);
> foo({args...}, 1);
> ```
> ?
> 
> 
> testing multiple expansions is also interesting, but seems orthogonal to the 
> change being made here.
> E.g. tests for it would probably benefit from more than 2 appearances of 
> `args` and more complicated nesting structures.
> 
> 
this was mostly a "sugar" patch, the tests are part of D130260 but I didn't do 
a good job of splitting the change 😅 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130261

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


[PATCH] D130261: [clangd] Refactor forwarding call detection logic

2022-07-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 446529.
kadircet marked 4 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130261

Files:
  clang-tools-extra/clangd/AST.cpp

Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -791,51 +791,46 @@
 })) {
   return;
 }
-auto OptPackLocation = findPack(Args);
-if (OptPackLocation) {
-  size_t PackLocation = OptPackLocation.value();
-  ArrayRef MatchingParams =
-  Callee->parameters().slice(PackLocation, Parameters.size());
-  // Check whether the function has a parameter pack as the last template
-  // parameter
-  if (const auto *TTPT = getFunctionPackType(Callee)) {
-// In this case: Separate the parameters into head, pack and tail
-auto IsExpandedPack = [&](const ParmVarDecl *P) {
-  return getUnderylingPackType(P) == TTPT;
-};
-ForwardingInfo FI;
-FI.Head = MatchingParams.take_until(IsExpandedPack);
-FI.Pack = MatchingParams.drop_front(FI.Head.size())
-  .take_while(IsExpandedPack);
-FI.Tail = MatchingParams.drop_front(FI.Head.size() + FI.Pack.size());
-FI.PackTarget = Callee;
-Info = FI;
-return;
-  }
-  // Default case: assume all parameters were fully resolved
+auto PackLocation = findPack(Args);
+if (!PackLocation)
+  return;
+ArrayRef MatchingParams =
+Callee->parameters().slice(*PackLocation, Parameters.size());
+// Check whether the function has a parameter pack as the last template
+// parameter
+if (const auto *TTPT = getFunctionPackType(Callee)) {
+  // In this case: Separate the parameters into head, pack and tail
+  auto IsExpandedPack = [&](const ParmVarDecl *P) {
+return getUnderylingPackType(P) == TTPT;
+  };
   ForwardingInfo FI;
-  FI.Head = MatchingParams;
+  FI.Head = MatchingParams.take_until(IsExpandedPack);
+  FI.Pack =
+  MatchingParams.drop_front(FI.Head.size()).take_while(IsExpandedPack);
+  FI.Tail = MatchingParams.drop_front(FI.Head.size() + FI.Pack.size());
+  FI.PackTarget = Callee;
   Info = FI;
+  return;
 }
+// Default case: assume all parameters were fully resolved
+ForwardingInfo FI;
+FI.Head = MatchingParams;
+Info = FI;
   }
 
   // Returns the beginning of the expanded pack represented by Parameters
   // in the given arguments, if it is there.
   llvm::Optional findPack(typename CallExpr::arg_range Args) {
 // find the argument directly referring to the first parameter
-auto FirstMatch = std::find_if(Args.begin(), Args.end(), [&](Expr *Arg) {
-  const auto *RefArg = unwrapArgument(Arg);
-  if (RefArg) {
-if (Parameters.front() == dyn_cast(RefArg->getDecl())) {
-  return true;
-}
+for (auto It = Args.begin(); It != Args.end(); ++It) {
+  const Expr *Arg = *It;
+  if (const auto *RefArg = unwrapForward(Arg)) {
+if (Parameters.front() != RefArg->getDecl())
+  continue;
+return std::distance(Args.begin(), It);
   }
-  return false;
-});
-if (FirstMatch == Args.end()) {
-  return llvm::None;
 }
-return std::distance(Args.begin(), FirstMatch);
+return llvm::None;
   }
 
   static FunctionDecl *getCalleeDeclOrUniqueOverload(CallExpr *E) {
@@ -847,7 +842,7 @@
   }
 }
 // Ignore the callee if the number of arguments is wrong (deal with va_args)
-if (Callee->getNumParams() == E->getNumArgs())
+if (Callee && Callee->getNumParams() == E->getNumArgs())
   return Callee;
 return nullptr;
   }
@@ -873,31 +868,17 @@
 return MatchingDecl;
   }
 
-  // Removes any implicit cast expressions around the given expression.
-  static const Expr *unwrapImplicitCast(const Expr *E) {
-while (const auto *Cast = dyn_cast(E)) {
-  E = Cast->getSubExpr();
-}
-return E;
-  }
-
-  // Maps std::forward(E) to E, nullptr otherwise
-  static const Expr *unwrapForward(const Expr *E) {
+  // Tries to get to the underlying argument by unwrapping implicit nodes and
+  // std::forward.
+  static const DeclRefExpr *unwrapForward(const Expr *E) {
+E = E->IgnoreImplicitAsWritten();
 if (const auto *Call = dyn_cast(E)) {
   const auto Callee = Call->getBuiltinCallee();
   if (Callee == Builtin::BIforward) {
-return Call->getArg(0);
+return dyn_cast(
+Call->getArg(0)->IgnoreImplicitAsWritten());
   }
 }
-return E;
-  }
-
-  // Maps std::forward(DeclRefExpr) to DeclRefExpr, removing any intermediate
-  // implicit casts, nullptr otherwise
-  static const DeclRefExpr *unwrapArgument(const Expr *E) {
-E 

[PATCH] D130261: [clangd] Refactor forwarding call detection logic

2022-07-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130261

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


[clang-tools-extra] b5871df - [clangd] Refactor forwarding call detection logic

2022-07-21 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-07-21T17:58:56+02:00
New Revision: b5871dfaf31873e6172f8a3fcd1e01e54498c811

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

LOG: [clangd] Refactor forwarding call detection logic

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

Added: 


Modified: 
clang-tools-extra/clangd/AST.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index 53adf230beae..44c6f49f55c2 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -791,51 +791,46 @@ class ForwardingCallVisitor
 })) {
   return;
 }
-auto OptPackLocation = findPack(Args);
-if (OptPackLocation) {
-  size_t PackLocation = OptPackLocation.value();
-  ArrayRef MatchingParams =
-  Callee->parameters().slice(PackLocation, Parameters.size());
-  // Check whether the function has a parameter pack as the last template
-  // parameter
-  if (const auto *TTPT = getFunctionPackType(Callee)) {
-// In this case: Separate the parameters into head, pack and tail
-auto IsExpandedPack = [&](const ParmVarDecl *P) {
-  return getUnderylingPackType(P) == TTPT;
-};
-ForwardingInfo FI;
-FI.Head = MatchingParams.take_until(IsExpandedPack);
-FI.Pack = MatchingParams.drop_front(FI.Head.size())
-  .take_while(IsExpandedPack);
-FI.Tail = MatchingParams.drop_front(FI.Head.size() + FI.Pack.size());
-FI.PackTarget = Callee;
-Info = FI;
-return;
-  }
-  // Default case: assume all parameters were fully resolved
+auto PackLocation = findPack(Args);
+if (!PackLocation)
+  return;
+ArrayRef MatchingParams =
+Callee->parameters().slice(*PackLocation, Parameters.size());
+// Check whether the function has a parameter pack as the last template
+// parameter
+if (const auto *TTPT = getFunctionPackType(Callee)) {
+  // In this case: Separate the parameters into head, pack and tail
+  auto IsExpandedPack = [&](const ParmVarDecl *P) {
+return getUnderylingPackType(P) == TTPT;
+  };
   ForwardingInfo FI;
-  FI.Head = MatchingParams;
+  FI.Head = MatchingParams.take_until(IsExpandedPack);
+  FI.Pack =
+  MatchingParams.drop_front(FI.Head.size()).take_while(IsExpandedPack);
+  FI.Tail = MatchingParams.drop_front(FI.Head.size() + FI.Pack.size());
+  FI.PackTarget = Callee;
   Info = FI;
+  return;
 }
+// Default case: assume all parameters were fully resolved
+ForwardingInfo FI;
+FI.Head = MatchingParams;
+Info = FI;
   }
 
   // Returns the beginning of the expanded pack represented by Parameters
   // in the given arguments, if it is there.
   llvm::Optional findPack(typename CallExpr::arg_range Args) {
 // find the argument directly referring to the first parameter
-auto FirstMatch = std::find_if(Args.begin(), Args.end(), [&](Expr *Arg) {
-  const auto *RefArg = unwrapArgument(Arg);
-  if (RefArg) {
-if (Parameters.front() == dyn_cast(RefArg->getDecl())) {
-  return true;
-}
+for (auto It = Args.begin(); It != Args.end(); ++It) {
+  const Expr *Arg = *It;
+  if (const auto *RefArg = unwrapForward(Arg)) {
+if (Parameters.front() != RefArg->getDecl())
+  continue;
+return std::distance(Args.begin(), It);
   }
-  return false;
-});
-if (FirstMatch == Args.end()) {
-  return llvm::None;
 }
-return std::distance(Args.begin(), FirstMatch);
+return llvm::None;
   }
 
   static FunctionDecl *getCalleeDeclOrUniqueOverload(CallExpr *E) {
@@ -847,7 +842,7 @@ class ForwardingCallVisitor
   }
 }
 // Ignore the callee if the number of arguments is wrong (deal with 
va_args)
-if (Callee->getNumParams() == E->getNumArgs())
+if (Callee && Callee->getNumParams() == E->getNumArgs())
   return Callee;
 return nullptr;
   }
@@ -873,31 +868,17 @@ class ForwardingCallVisitor
 return MatchingDecl;
   }
 
-  // Removes any implicit cast expressions around the given expression.
-  static const Expr *unwrapImplicitCast(const Expr *E) {
-while (const auto *Cast = dyn_cast(E)) {
-  E = Cast->getSubExpr();
-}
-return E;
-  }
-
-  // Maps std::forward(E) to E, nullptr otherwise
-  static const Expr *unwrapForward(const Expr *E) {
+  // Tries to get to the underlying argument by unwrapping implicit nodes and
+  // std::forward.
+  static const DeclRefExpr *unwrapForward(const Expr *E) {
+E = E->IgnoreImplicitAsWritten();
 if (const auto *Call = dyn_cast(E)) {
   const auto Callee = Call->getBuiltinCallee();
   if (Callee == Built

[PATCH] D130261: [clangd] Refactor forwarding call detection logic

2022-07-21 Thread Kadir Cetinkaya 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 rGb5871dfaf318: [clangd] Refactor forwarding call detection 
logic (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130261

Files:
  clang-tools-extra/clangd/AST.cpp

Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -791,51 +791,46 @@
 })) {
   return;
 }
-auto OptPackLocation = findPack(Args);
-if (OptPackLocation) {
-  size_t PackLocation = OptPackLocation.value();
-  ArrayRef MatchingParams =
-  Callee->parameters().slice(PackLocation, Parameters.size());
-  // Check whether the function has a parameter pack as the last template
-  // parameter
-  if (const auto *TTPT = getFunctionPackType(Callee)) {
-// In this case: Separate the parameters into head, pack and tail
-auto IsExpandedPack = [&](const ParmVarDecl *P) {
-  return getUnderylingPackType(P) == TTPT;
-};
-ForwardingInfo FI;
-FI.Head = MatchingParams.take_until(IsExpandedPack);
-FI.Pack = MatchingParams.drop_front(FI.Head.size())
-  .take_while(IsExpandedPack);
-FI.Tail = MatchingParams.drop_front(FI.Head.size() + FI.Pack.size());
-FI.PackTarget = Callee;
-Info = FI;
-return;
-  }
-  // Default case: assume all parameters were fully resolved
+auto PackLocation = findPack(Args);
+if (!PackLocation)
+  return;
+ArrayRef MatchingParams =
+Callee->parameters().slice(*PackLocation, Parameters.size());
+// Check whether the function has a parameter pack as the last template
+// parameter
+if (const auto *TTPT = getFunctionPackType(Callee)) {
+  // In this case: Separate the parameters into head, pack and tail
+  auto IsExpandedPack = [&](const ParmVarDecl *P) {
+return getUnderylingPackType(P) == TTPT;
+  };
   ForwardingInfo FI;
-  FI.Head = MatchingParams;
+  FI.Head = MatchingParams.take_until(IsExpandedPack);
+  FI.Pack =
+  MatchingParams.drop_front(FI.Head.size()).take_while(IsExpandedPack);
+  FI.Tail = MatchingParams.drop_front(FI.Head.size() + FI.Pack.size());
+  FI.PackTarget = Callee;
   Info = FI;
+  return;
 }
+// Default case: assume all parameters were fully resolved
+ForwardingInfo FI;
+FI.Head = MatchingParams;
+Info = FI;
   }
 
   // Returns the beginning of the expanded pack represented by Parameters
   // in the given arguments, if it is there.
   llvm::Optional findPack(typename CallExpr::arg_range Args) {
 // find the argument directly referring to the first parameter
-auto FirstMatch = std::find_if(Args.begin(), Args.end(), [&](Expr *Arg) {
-  const auto *RefArg = unwrapArgument(Arg);
-  if (RefArg) {
-if (Parameters.front() == dyn_cast(RefArg->getDecl())) {
-  return true;
-}
+for (auto It = Args.begin(); It != Args.end(); ++It) {
+  const Expr *Arg = *It;
+  if (const auto *RefArg = unwrapForward(Arg)) {
+if (Parameters.front() != RefArg->getDecl())
+  continue;
+return std::distance(Args.begin(), It);
   }
-  return false;
-});
-if (FirstMatch == Args.end()) {
-  return llvm::None;
 }
-return std::distance(Args.begin(), FirstMatch);
+return llvm::None;
   }
 
   static FunctionDecl *getCalleeDeclOrUniqueOverload(CallExpr *E) {
@@ -847,7 +842,7 @@
   }
 }
 // Ignore the callee if the number of arguments is wrong (deal with va_args)
-if (Callee->getNumParams() == E->getNumArgs())
+if (Callee && Callee->getNumParams() == E->getNumArgs())
   return Callee;
 return nullptr;
   }
@@ -873,31 +868,17 @@
 return MatchingDecl;
   }
 
-  // Removes any implicit cast expressions around the given expression.
-  static const Expr *unwrapImplicitCast(const Expr *E) {
-while (const auto *Cast = dyn_cast(E)) {
-  E = Cast->getSubExpr();
-}
-return E;
-  }
-
-  // Maps std::forward(E) to E, nullptr otherwise
-  static const Expr *unwrapForward(const Expr *E) {
+  // Tries to get to the underlying argument by unwrapping implicit nodes and
+  // std::forward.
+  static const DeclRefExpr *unwrapForward(const Expr *E) {
+E = E->IgnoreImplicitAsWritten();
 if (const auto *Call = dyn_cast(E)) {
   const auto Callee = Call->getBuiltinCallee();
   if (Callee == Builtin::BIforward) {
-return Call->getArg(0);
+return dyn_cast(
+Call->getArg(0)->IgnoreImplicitAsWritten());
   }
 }
-return E;
-  }
-
-  // Maps std::forward(DeclRefExpr) to DeclRefExpr, removing any intermediate
-  // i

[PATCH] D130268: [WIP] Add SmallVector constructor to allow creation of SmallVector from ArrayRef of items convertible to type T

2022-07-21 Thread Dawid Jurczak via Phabricator via cfe-commits
yurai007 added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:504
   llvm::StructType *STy = llvm::ConstantStruct::getTypeForElements(
-  CGM.getLLVMContext(), Packed ? PackedElems : UnpackedElems, Packed);
+  CGM.getLLVMContext(), Packed ? PackedElems : to_vector(UnpackedElems),
+  Packed);

barannikov88 wrote:
> barannikov88 wrote:
> > nikic wrote:
> > > barannikov88 wrote:
> > > > yurai007 wrote:
> > > > > nikic wrote:
> > > > > > yurai007 wrote:
> > > > > > > That's because of "error: conditional expression is ambiguous; 
> > > > > > > 'llvm::SmallVector' can be converted to 
> > > > > > > 'ArrayRef' and vice versa". Need to check if 
> > > > > > > there is easier workaround.
> > > > > > Would making the ctor explicit help?
> > > > > Nope :( Making constructor explicit disables implicit conversion so 
> > > > > we cannot do things like: SmallVector NewMask = Mask; 
> > > > > anymore.
> > > > And leaving it implicit hides the fact of possible memory allocation, 
> > > > which is not cheap. I think absense of such constructor is by-design.
> > > > 
> > > > Making it explicit is making it redundant, because there is already a 
> > > > constructor which accepts begin / end, and one that accepts range (note 
> > > > that it is explicit!). It won't save on typing, either.
> > > > 
> > > > I'm not in favor of this patch, but my word does not count much, so I 
> > > > won't block it. I'd suggest you, however, to request review of core 
> > > > maintainers.
> > > > Nope :( Making constructor explicit disables implicit conversion so we 
> > > > cannot do things like: SmallVector NewMask = Mask; anymore.
> > > 
> > > I think that's fine. Similar to the existing iterator_range constructor, 
> > > we would require `SmallVector NewMask(Mask)`, which seems like 
> > > the idiomatic way to write it anyway?
> > > 
> > > > Making it explicit is making it redundant, because there is already a 
> > > > constructor which accepts begin / end, and one that accepts range (note 
> > > > that it is explicit!). It won't save on typing, either.
> > > 
> > > It is not redundant. It ensures that iterator_range and ArrayRef can be 
> > > freely substituted. Switching iterator_range to ArrayRef currently 
> > > requires going through a lot of SmallVector constructors and replacing 
> > > them with less readable code. The alternative to this change is D129988, 
> > > which looks like a significant regression in code quality.
> > Please also consider the fact that this is API breaking change due to this 
> > "conditional expression is amiguous" error. Many external projects depend 
> > on LLVM/ADT, and all of them will have to adapt this change.
> > It ensures that iterator_range and ArrayRef can be freely substituted. 
> > Switching iterator_range to ArrayRef currently requires going through a lot 
> > of SmallVector constructors and replacing them with less readable code. 
> 
> Ok, makes sense.
> Nope :( Making constructor explicit disables implicit conversion so we 
> cannot do things like: SmallVector NewMask = Mask; anymore.
> 
> I think that's fine. Similar to the existing iterator_range constructor, we 
> would require SmallVector NewMask(Mask), which seems like the 
> idiomatic way to write it anyway?

You are right, explicit works when we use brackets instead assignment. I'm 
gonna add it to constructor and adjust rest of patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130268

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


[PATCH] D130260: [clangd] Make forwarding parameter detection logic resilient

2022-07-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 446531.
kadircet added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130260

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1429,6 +1429,35 @@
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, ArgPacksAndConstructors) {
+  assertParameterHints(
+  R"cpp(
+struct Foo{ Foo(); Foo(int x); };
+void foo(Foo a, int b);
+template 
+void bar(Args... args) {
+  foo(args...);
+}
+template 
+void baz(Args... args) { foo($param1[[Foo{args...}]], $param2[[1]]); }
+
+template 
+void bax(Args... args) { foo($param3[[{args...}]], args...); }
+
+void foo() {
+  bar($param4[[Foo{}]], $param5[[42]]);
+  bar($param6[[42]], $param7[[42]]);
+  baz($param8[[42]]);
+  bax($param9[[42]]);
+}
+  )cpp",
+  ExpectedHint{"a: ", "param1"}, ExpectedHint{"b: ", "param2"},
+  ExpectedHint{"a: ", "param3"}, ExpectedHint{"a: ", "param4"},
+  ExpectedHint{"b: ", "param5"}, ExpectedHint{"a: ", "param6"},
+  ExpectedHint{"b: ", "param7"}, ExpectedHint{"x: ", "param8"},
+  ExpectedHint{"b: ", "param9"});
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -786,6 +786,9 @@
   // inspects the given callee with the given args to check whether it
   // contains Parameters, and sets Info accordingly.
   void handleCall(FunctionDecl *Callee, typename CallExpr::arg_range Args) {
+// Skip functions with less parameters, they can't be the target.
+if (Callee->parameters().size() < Parameters.size())
+  return;
 if (std::any_of(Args.begin(), Args.end(), [](const Expr *E) {
   return dyn_cast(E) != nullptr;
 })) {
@@ -823,8 +826,7 @@
   llvm::Optional findPack(typename CallExpr::arg_range Args) {
 // find the argument directly referring to the first parameter
 for (auto It = Args.begin(); It != Args.end(); ++It) {
-  const Expr *Arg = *It;
-  if (const auto *RefArg = unwrapForward(Arg)) {
+  if (const auto *RefArg = unwrapForward(*It)) {
 if (Parameters.front() != RefArg->getDecl())
   continue;
 return std::distance(Args.begin(), It);
@@ -872,6 +874,13 @@
   // std::forward.
   static const DeclRefExpr *unwrapForward(const Expr *E) {
 E = E->IgnoreImplicitAsWritten();
+// There might be an implicit copy/move constructor call on top of the
+// forwarded arg.
+// FIXME: Maybe mark that in the AST as so, this might skip explicit calls
+// too.
+if (const auto *Const = dyn_cast(E))
+  if (Const->getConstructor()->isCopyOrMoveConstructor())
+E = Const->getArg(0)->IgnoreImplicitAsWritten();
 if (const auto *Call = dyn_cast(E)) {
   const auto Callee = Call->getBuiltinCallee();
   if (Callee == Builtin::BIforward) {


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1429,6 +1429,35 @@
   ElementsAre(labelIs(": int"), labelIs(": char")));
 }
 
+TEST(ParameterHints, ArgPacksAndConstructors) {
+  assertParameterHints(
+  R"cpp(
+struct Foo{ Foo(); Foo(int x); };
+void foo(Foo a, int b);
+template 
+void bar(Args... args) {
+  foo(args...);
+}
+template 
+void baz(Args... args) { foo($param1[[Foo{args...}]], $param2[[1]]); }
+
+template 
+void bax(Args... args) { foo($param3[[{args...}]], args...); }
+
+void foo() {
+  bar($param4[[Foo{}]], $param5[[42]]);
+  bar($param6[[42]], $param7[[42]]);
+  baz($param8[[42]]);
+  bax($param9[[42]]);
+}
+  )cpp",
+  ExpectedHint{"a: ", "param1"}, ExpectedHint{"b: ", "param2"},
+  ExpectedHint{"a: ", "param3"}, ExpectedHint{"a: ", "param4"},
+  ExpectedHint{"b: ", "param5"}, ExpectedHint{"a: ", "param6"},
+  ExpectedHint{"b: ", "param7"}, ExpectedHint{"x: ", "param8"},
+  ExpectedHint{"b: ", "param9"});
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ cla

[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-21 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx added a comment.

I've added a few suggestions for more rigorous testing, and raised a concern 
about a bug in this patch that is hiding expected -Warray-bounds warnings in 
certain cases.




Comment at: clang/lib/CodeGen/CGExpr.cpp:888-889
   if (const auto *CAT = dyn_cast(AT)) {
 // FIXME: Sema doesn't treat [1] as a flexible array member if the bound
 // was produced by macro expansion.
+if (StrictFlexArraysLevel >= 2 && CAT->getSize().ugt(0))

I was exploring this difference and during my testing, I ran across what I 
think is a bug in mode 1 behavior of this patch:

https://godbolt.org/z/hj9T4MY61 -fsfa=0, no-warnings: f[0] f[ZERO] f[1] 
warnings: f[ONE] f[5]
https://godbolt.org/z/Ea9MY9jjh -fsfa=1, no-warnings: f[0] f[ZERO] f[5] 
warnings: f[1] f[ONE]  <-- Incorrect behavior?
https://godbolt.org/z/aerMvxs6q -fsfa=2, no-warnings: f[0] f[ZERO] warnings: 
f[1] f[ONE] f[5]

I would think that -Warray-bounds should give a warning for accesses beyond the 
declared size of an array of 5 elements no matter what the 
-fstrict-flex-arrays= mode is.  Have I misunderstood?

Testing with compiler prior to this patch (using 14.0.0, e.g., and not giving 
-fsfa option) gives behavior consistent with -fsfa=0 on trunk.  So it seems 
-Warray-bounds has always treated size>1 trailing arrays as concrete/fixed 
arrays, just as it does with non-trailing arrays.  But I may be missing 
something, of course



Comment at: clang/lib/Sema/SemaChecking.cpp:15801-15803
+  // 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...

Under what circumstances (what compiler options, what example code) would 
size>1 trailing arrays be treated as flexible array members?  I'm not seeing 
that.  -Warray-bounds warns about OOB access on size>1 trailing arrays, and 
always has (with the notable exception of the comment I made above, which I 
think is a bug).



Comment at: clang/test/CodeGen/bounds-checking-fam.c:23
 // CHECK-LABEL: define {{.*}} @{{.*}}test_one{{.*}}(
 int test_one(struct One *p, int i) {
   // CHECK-STRICT-0-NOT: @__ubsan

Should there be a "test_zero" case?  Such as:

```
struct Zero {
   int a[0];
};

int test_zero(struct Zero *p, int i) {
   return p->a[i] + (p->a)[i];
}
```

Likewise, for C99 compilation, should there also be a case with a trailing 
incomplete array?

```
struct Inc {
   int x;
   int a[];
};

int test_inc(struct Inc *p, int i) {
   return p->a[i] + (p->a)[i];
}
```




Comment at: clang/test/SemaCXX/array-bounds.cpp:211-213
+struct foo {
+  char c[ONE]; // expected-note {{array 'c' declared here}}
+};

This may be a bit beyond the scope of this change, but I think there are some 
problems with -Warray-bounds behavior that should be considered here as well, 
having to do with *nesting* of structs that have trailing size=1 arrays.

Consider https://godbolt.org/z/ex6P8bqY9, in which this code:

```
#define LEN 1

typedef struct S1 {
int x;
double y;
int tail[3];
} S1;

typedef struct S {
int   x;
S1s1;
double y;
int   tail[1];
} S;

void fooS(S *s) {
s->tail[2] = 10;
s->tail[5] = 20;
(s->tail)[10] = 200;
s->s1.tail[10] = (s->s1.tail)[10] + 1;
}
```
produces a warning (as you'd expect).  But if you change the size of the 
trailing array in the **nested** struct to 1, you no longer get a warning: 
https://godbolt.org/z/dWET3E9d6

Note also that testing these examples with trunk build repeats the bug I 
mentioned in an earlier comment, where -fsfa=1 causes an expected 
-Warray-bounds warning to be dropped.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126864

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


  1   2   3   >