[PATCH] D131808: [clang,flang] Add missing options fsyntax-only in help

2022-08-14 Thread Alexander Malkov via Phabricator via cfe-commits
alexiprof updated this revision to Diff 452487.
alexiprof added a comment.

replase text hint


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131808

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/CommandGuide/clang.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90

Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -42,6 +42,7 @@
 ! HELP-NEXT: -fno-integrated-as  Disable the integrated assembler
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
@@ -119,6 +120,7 @@
 ! HELP-FC1-NEXT: -fno-reformat  Dump the cooked character stream in -E mode
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-FC1-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! HELP-FC1-NEXT: -help  Display available options
 ! HELP-FC1-NEXT: -init-only Only execute frontend initialization
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -44,6 +44,7 @@
 ! CHECK-NEXT: -fno-integrated-as Disable the integrated assembler
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
 ! CHECK-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! CHECK-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2795,7 +2795,8 @@
 def fdriver_only : Flag<["-"], "fdriver-only">, Flags<[NoXarchOption, CoreOption]>,
   Group, HelpText<"Only run the driver.">;
 def fsyntax_only : Flag<["-"], "fsyntax-only">,
-  Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group;
+  Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option,FlangOption]>, Group,
+  HelpText<"Run the preprocessor, parser and semantic analysis stages">;
 def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group;
 def ftemplate_depth_EQ : Joined<["-"], "ftemplate-depth=">, Group;
 def ftemplate_depth_ : Joined<["-"], "ftemplate-depth-">, Group;
@@ -6613,7 +6614,7 @@
 def _SLASH_Zp_flag : CLFlag<"Zp">,
   HelpText<"Set default maximum struct packing alignment to 1">,
   Alias, AliasArgs<["1"]>;
-def _SLASH_Zs : CLFlag<"Zs">, HelpText<"Syntax-check only">,
+def _SLASH_Zs : CLFlag<"Zs">, HelpText<"Run the preprocessor, parser and semantic analysis stages">,
   Alias;
 def _SLASH_openmp_ : CLFlag<"openmp-">,
   HelpText<"Disable OpenMP support">, Alias;
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -3999,7 +3999,7 @@
   /Zl Don't mention any default libraries in the object file
   /Zp Set the default maximum struct packing alignment to 1
   /Zp  Specify the default maximum struct packing alignment
-  /Zs Syntax-check only
+  /Zs Run the preprocessor, parser and semantic analysis stages
 
 OPTIONS:
   -###Print (but do not run) the commands to run for this compilation
@@ -4130,6 +4130,7 @@
   behavior. See user manual for available checks
   -fsplit-lto-unitEnables splitting of the LTO unit.
   -fstandalone-debug  Emit full debug info for all types used by the program
+  -fsyntax-only   Run the preprocessor, parser and semantic analysis stages
   -fwhole-program-vtables Enables whole-program vtable optimization. Requires -flto
   -gcodeview-ghashEmit type record hashes in a .debug$H section
   -gcodeview  Generate CodeView debug information

[PATCH] D131853: [clangd] Add doxygen parsing for Hover

2022-08-14 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders created this revision.
Herald added subscribers: wenlei, usaxena95, kadircet, arphaman, mgorny.
Herald added a project: All.
tom-anders published this revision for review.
Herald added subscribers: cfe-commits, llvm-commits, MaskRay, ilya-biryukov.
Herald added projects: LLVM, clang-tools-extra.

This adds a new class SymbolDocumentation that does basic doxygen
parsing. Currently, it's only consumed by Hover, but in future
patches we'll probably also want to use it in CodeComplete and
SignatureHelp.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131853

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/SymbolDocumentation.cpp
  clang-tools-extra/clangd/SymbolDocumentation.h
  clang-tools-extra/clangd/index/Merge.cpp
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/index/Symbol.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/YAMLSerialization.cpp
  clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp
  clang-tools-extra/clangd/test/index-serialization/Inputs/sample.idx
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/IndexTests.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/clangd/unittests/SymbolDocumentationMatchers.h
  llvm/utils/gn/secondary/clang-tools-extra/clangd/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/BUILD.gn
@@ -117,6 +117,7 @@
 "SemanticHighlighting.cpp",
 "SemanticSelection.cpp",
 "SourceCode.cpp",
+"SymbolDocumentation.cpp"
 "TUScheduler.cpp",
 "TidyProvider.cpp",
 "URI.cpp",
Index: clang-tools-extra/clangd/unittests/SymbolDocumentationMatchers.h
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/SymbolDocumentationMatchers.h
@@ -0,0 +1,51 @@
+//===-- SymbolDocumentationMatchers.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// GMock matchers for the SymbolDocumentation class
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SYMBOLDOCUMENTATION_MATCHERS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SYMBOLDOCUMENTATION_MATCHERS_H
+#include "SymbolDocumentation.h"
+#include "gmock/gmock.h"
+
+namespace clang {
+namespace clangd {
+
+template 
+testing::Matcher>
+matchesDoc(const SymbolDocumentation &Expected) {
+  using namespace ::testing;
+
+  std::vector>> ParamMatchers;
+  for (const auto &P : Expected.Parameters)
+ParamMatchers.push_back(
+AllOf(Field("Name", &ParameterDocumentation::Name, P.Name),
+  Field("Description", &ParameterDocumentation::Description,
+P.Description)));
+
+  return AllOf(
+  Field("Brief", &SymbolDocumentation::Brief, Expected.Brief),
+  Field("Returns", &SymbolDocumentation::Returns, Expected.Returns),
+  Field("Notes", &SymbolDocumentation::Notes,
+ElementsAreArray(Expected.Notes)),
+  Field("Warnings", &SymbolDocumentation::Warnings,
+ElementsAreArray(Expected.Warnings)),
+  Field("Parameters", &SymbolDocumentation::Parameters,
+ElementsAreArray(ParamMatchers)),
+  Field("Description", &SymbolDocumentation::Description,
+Expected.Description),
+  Field("CommentText", &SymbolDocumentation::CommentText,
+Expected.CommentText));
+}
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -50,7 +50,7 @@
   return (arg.Name + arg.Signature).str() == Label;
 }
 MATCHER_P(returnType, D, "") { return arg.ReturnType == D; }
-MATCHER_P(doc, D, "") { return arg.Documentation == D; }
+MATCHER_P(doc, D, "") { return arg.Documentation.CommentText == D; }
 MATCHER_P(snippet, S, "") {
   return (arg.Nam

[PATCH] D129926: [clang-format] Handle constructor invocations after new operator in C# correct

2022-08-14 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

In D129926#3705342 , @MyDeveloperDay 
wrote:

> Can we land this for you?

Yes




Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2869-2870
+  // Handle array initialization syntax
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 

Before the patch, this code mistook lambdas in a constructor call for an 
initialization list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129926

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


[PATCH] D129628: [clang-format] Fix aligning of java-style declarations

2022-08-14 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine added a comment.

I don't have an access to commit the patch by myself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129628

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


[PATCH] D129926: [clang-format] Handle constructor invocations after new operator in C# correct

2022-08-14 Thread Danil Sidoruk via Phabricator via cfe-commits
eoanermine updated this revision to Diff 452513.
eoanermine added a comment.

- Add examples to comments
- Reformat comments right


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129926

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2861,11 +2861,11 @@
 
   if (Style.isCSharp()) {
 do {
-  // Handle constructor invocation
+  // Handle constructor invocation, e.g. `new(field: value)`.
   if (FormatTok->is(tok::l_paren))
 parseParens();
 
-  // Handle array initialization syntax
+  // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`.
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2861,11 +2861,11 @@
 
   if (Style.isCSharp()) {
 do {
-  // Handle constructor invocation
+  // Handle constructor invocation, e.g. `new(field: value)`.
   if (FormatTok->is(tok::l_paren))
 parseParens();
 
-  // Handle array initialization syntax
+  // Handle array initialization syntax, e.g. `new[] {10, 20, 30}`.
   if (FormatTok->is(tok::l_brace))
 parseBracedList();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-08-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added subscribers: steakhal, carlosgalvezp, martong, usaxena95, 
kadircet, arphaman.
Herald added a reviewer: shafik.
Herald added a reviewer: NoQ.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added projects: clang, libc++, clang-tools-extra.
Herald added subscribers: cfe-commits, libcxx-commits.
Herald added a reviewer: libc++.

This is a change to how we represent type subsitution in the AST.
Instead of only storing the replaced type, we track the templated
entity we are substituting, plus an index.
We modify MLTAL to track the templated entity at each level.

Otherwise, it's much more expensive to go from the template parameter back
to the templated entity, and not possible to do in some cases, as when
we instantiate outer templates, parameters might still reference the
original entity.

This also allows us to very cheaply lookup the templated entity we saw in
the naming context and find the corresponding argument it was replaced
from, such as for implementing template specialization resugaring.

Depends on D130308 

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,3 +1,4 @@
 D111283
 D111509
 D130308
+D127695
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -156,9 +156,8 @@
 // CHECK:   |-BuiltinType {{.*}} 'int'
 // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
 // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
-// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack
-// CHECK: |-TemplateTypeParmType {{.*}} 'U' dependent contains_unexpanded_pack depth 1 index 0 pack
-// CHECK: | `-TemplateTypeParm {{.*}} 'U'
+// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U
+// CHECK: |-TypeAliasTemplate {{.*}} 'B'
 // CHECK: `-TemplateArgument pack
 // CHECK:   |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NOT: Subst
Index: clang/test/AST/deduction-guides.cpp
===
--- clang/test/AST/deduction-guides.cpp
+++ clang/test/AST/deduction-guides.cpp
@@ -67,9 +67,8 @@
 // CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived::type_alias' sugar
 // CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base::type_alias' sugar
 // CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
-// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
-// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
+// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar class depth 0 index 0 A
+// CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'Base'
 // CHECK-NEXT: BuiltinType {{.*}} 'int'
 
 // CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (Derived &&, const typename Derived::type_alias &) -> Derived'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -120,12 +120,12 @@
 // CHECK-NEXT: Templ

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

2022-08-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 452519.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,3 +1,4 @@
 D111283
 D111509
 D130308
+D131858
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -156,9 +156,8 @@
 // CHECK:   |-BuiltinType {{.*}} 'int'
 // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
 // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
-// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack
-// CHECK: |-TemplateTypeParmType {{.*}} 'U' dependent contains_unexpanded_pack depth 1 index 0 pack
-// CHECK: | `-TemplateTypeParm {{.*}} 'U'
+// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U
+// CHECK: |-TypeAliasTemplate {{.*}} 'B'
 // CHECK: `-TemplateArgument pack
 // CHECK:   |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NOT: Subst
Index: clang/test/AST/deduction-guides.cpp
===
--- clang/test/AST/deduction-guides.cpp
+++ clang/test/AST/deduction-guides.cpp
@@ -67,9 +67,8 @@
 // CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived::type_alias' sugar
 // CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base::type_alias' sugar
 // CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
-// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
-// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
+// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar class depth 0 index 0 A
+// CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'Base'
 // CHECK-NEXT: BuiltinType {{.*}} 'int'
 
 // CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (Derived &&, const typename Derived::type_alias &) -> Derived'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -120,12 +120,12 @@
 // CHECK-NEXT: TemplateArgument type 'void'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent depth 0 index 0
-// CHECK-NEXT: TemplateTypeParm 0x{{[^ ]*}} 'U'
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent depth 0 index 0
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
+// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
+// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
 } // namespace PR55886
 
 namespace PR56099 {
@@ -136,14 +136,14 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypePar

[clang] 2fd2f26 - [clang][doc] Removes an extra space.

2022-08-14 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2022-08-14T15:16:43+02:00
New Revision: 2fd2f2644b45c6e95b7554c9a9c28daff01fc3cb

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

LOG: [clang][doc] Removes an extra space.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index ffd61ee2a1ae4..d3e1d71fd04b7 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3567,7 +3567,7 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: yaml
 
-  QualifierOrder: ['inline', 'static' , 'type', 'const']
+  QualifierOrder: ['inline', 'static', 'type', 'const']
 
 
 .. code-block:: c++



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


[PATCH] D131859: [clang-tidy] Adds QualifierAlignment to misc-const-correctness.

2022-08-14 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: aaron.ballman, alexfh, JonasToth, LegalizeAdulthood, 
njames93.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The fixit for misc-const-correctness was hard-coded to use east const.
Clang-format has the option to change east const to west const, but
that's not fool-proof.

This adds a option to the checker to select the placement of the const.
The naming is based on clang-format For backwards compatibility the east
const is the default.

Also fixes the documentation; previously it suggested west const is the
default.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131859

Files:
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp
@@ -2,9 +2,11 @@
 // RUN: -config='{CheckOptions: \
 // RUN:  [{key: "misc-const-correctness.AnalyzeValues", value: false},\
 // RUN:   {key: "misc-const-correctness.AnalyzeReferences", value: false},\
+// RUN:   {key: 'misc-const-correctness.QualifierAlignment', value: centre}, \
 // RUN:  ]}' -- -fno-delayed-template-parsing
 
 // CHECK-MESSAGES: warning: The check 'misc-const-correctness' will not perform any analysis because both 'AnalyzeValues' and 'AnalyzeReferences' are false. [clang-tidy-config]
+// CHECK-MESSAGES: warning: invalid configuration value 'centre' for option 'misc-const-correctness.QualifierAlignment' [clang-tidy-config]
 
 void g() {
   int p_local0 = 42;
Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp
@@ -1,10 +1,26 @@
-// RUN: %check_clang_tidy %s misc-const-correctness %t -- \
+// RUN: %check_clang_tidy -check-suffix=RIGHT %s misc-const-correctness %t -- \
 // RUN:   -config="{CheckOptions: [\
 // RUN:   {key: 'misc-const-correctness.TransformValues', value: true},\
 // RUN:   {key: 'misc-const-correctness.WarnPointersAsValues', value: false}, \
 // RUN:   {key: 'misc-const-correctness.TransformPointersAsValues', value: false}, \
 // RUN:   ]}" -- -fno-delayed-template-parsing
 
+// RUN: %check_clang_tidy -check-suffix=RIGHT %s misc-const-correctness %t -- \
+// RUN:   -config="{CheckOptions: [\
+// RUN:   {key: 'misc-const-correctness.TransformValues', value: true},\
+// RUN:   {key: 'misc-const-correctness.WarnPointersAsValues', value: false}, \
+// RUN:   {key: 'misc-const-correctness.TransformPointersAsValues', value: false}, \
+// RUN:   {key: 'misc-const-correctness.QualifierAlignment', value: right}, \
+// RUN:   ]}" -- -fno-delayed-template-parsing
+
+// RUN: %check_clang_tidy -check-suffix=LEFT %s misc-const-correctness %t -- \
+// RUN:   -config="{CheckOptions: [\
+// RUN:   {key: 'misc-const-correctness.TransformValues', value: true},\
+// RUN:   {key: 'misc-const-correctness.WarnPointersAsValues', value: false}, \
+// RUN:   {key: 'misc-const-correctness.TransformPointersAsValues', value: false}, \
+// RUN:   {key: 'misc-const-correctness.QualifierAlignment', value: left}, \
+// RUN:   ]}" -- -fno-delayed-template-parsing
+
 bool global;
 char np_global = 0; // globals can't be known to be const
 
@@ -23,15 +39,17 @@
 
 void some_function(double np_arg0, wchar_t np_arg1) {
   int p_local0 = 2;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
-  // CHECK-FIXES: int const p_local0 = 2;
+  // CHECK-MESSAGES-RIGHT: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
+  // CHECK-FIXES-RIGHT: int const p_local0 = 2;
+  // CHECK-FIXES-LEFT: const int p_local0 = 2;
 }
 
 void nested_scopes() {
   {
 int p_local1 = 42;
-// CHECK-MESSAGES: [[@LINE-1]]:5: warning: variable 'p_local1' of type 'int' can be declared 'const'
-// CHECK-FIXES: int const p_local1 = 42;
+// CHECK-MESSAGES-RIGHT: [[@LINE-1]]:5: warning: variable 'p_local1' of type 'int' can be dec

[PATCH] D131859: [clang-tidy] Adds QualifierAlignment to misc-const-correctness.

2022-08-14 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Shouldn't `east/west` added as aliases?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131859

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


[PATCH] D131859: [clang-tidy] Adds QualifierAlignment to misc-const-correctness.

2022-08-14 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Duplicate of D131386 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131859

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


[PATCH] D131526: [OMPIRBuilder] Add support for safelen clause

2022-08-14 Thread Shraiysh via Phabricator via cfe-commits
shraiysh added a comment.

Minor comments. Thank you for working on this!




Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:625
+  void applySimd(CanonicalLoopInfo *Loop, Value *IfCond, ConstantInt *Simdlen,
+ ConstantInt *Safelen);
 

[nit] Please set the default value of Safelen to nullptr here.



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:1808
+   ConstantInt::get(Type::getInt32Ty(Ctx), 3),
+   /* Safelen */ nullptr);
 

[nit] remove this change after setting default value.



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:1920
+  OMPBuilder.applySimd(CLI, IfCmp, ConstantInt::get(Type::getInt32Ty(Ctx), 3),
+   /* Safelen */ nullptr);
 

[nit] same as above



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp:976
   loop.if_expr() ? moduleTranslation.lookupValue(loop.if_expr()) : nullptr,
-  simdlen);
+  simdlen, nullptr);
 

[nit] same as above


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

https://reviews.llvm.org/D131526

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-08-14 Thread David Rector via Phabricator via cfe-commits
davrec added a comment.

> The second paragraph is talking about 'Canonical nodes', not 'Canonical 
> types'.
>
> A canonical node is a type node for which 'isSugared' method returns false.

Thanks for the clarification, but note that that term is not in general use so 
far as I'm aware.   But instead of defining it and getting into details it 
might be clearer, and certainly would have saved me the most time, for the 
description to simply note that this patch introduces 
`ASTContext::getCommonSugaredType(QualType X, QualType Y, bool Unqualified = 
false)`, and puts it to use in type deduction for binary expressions etc., and 
give an example or two to demonstrate.  (More generally on a large patch I 
prefer a description to give me a few starting points, the primary changes 
which necessitate all the others.)

Re the patch itself: it looks good to me other than a few nits, but this has 
such a broad and deep span (intricate details of the AST + intricate details of 
Sema) it is difficult to give it a final thumbs up - really hoping @rsmith 
might take a final look.  But if time runs out it is definitely worth accepting 
as is and seeing how it goes; the benefits exceed the risks.  I will try to 
take a close look at the other patches on your stack, but the same probably 
applies.  You've done a tremendous amount of work here, very impressive.




Comment at: clang/include/clang/AST/ASTContext.h:2807
 
+  FunctionProtoType::ExceptionSpecInfo
+  getCommonExceptionSpec(FunctionProtoType::ExceptionSpecInfo ESI1,

A clearer name might be `combineExceptionSpecs`, or the original 
`mergeExceptionSpecs`, since this is getting the union of their sets of 
exception specs, whereas getCommon* suggests getting the intersection, e.g. 
getCommonSugaredType is getting the intersection of two "sets" of type sugar in 
a sense.  

Also, please add some brief documentation to the function.



Comment at: clang/include/clang/AST/ASTContext.h:2825
+  // the common sugared type between them.
+  void mergeTypeLists(SmallVectorImpl &Out, ArrayRef X,
+  ArrayRef Y);

Any reason this is public?  Or in the header at all?  Seems like it could be a 
static function in the cpp.



Comment at: clang/lib/AST/ASTContext.cpp:12116
+// If we reach the canonical declaration, then Y is older.
+if (DX->isCanonicalDecl())
+  return Y;

I think "canonical" should be replaced with "first" here and 
`isCanonicalDecl()` with `isFirstDecl()`.  So far as I can tell 
`getCanonicalDecl()` returns `getFirstDecl()` everywhere for now, but that 
could conceivably change, and in any case the goal of this code is to find 
which is older, so "first" would be clearer as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

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


[PATCH] D129160: libclang.so: Make SONAME the same as LLVM version

2022-08-14 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

> Also, this change did not really acheive it's purpose of allowing apps to use 
> newer versions of libclang.so without rebuilding, because a new version of 
> libclang.so requires a new version of libLLVM.so, which does not have a 
> stable ABI.

Could you elaborate on this? If an application uses only `libclang.so`, and 
that is updated to a newer version using a newer `libLLVM.so`, why would the 
application need to be rebuilt? Isn't the C API self-contained?

It was a bit tough to decouple `libclang.so` packaging-wise, but we released it 
like that already and reverting now seems to just obsolete efforts that had 
already happened.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129160

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


[PATCH] D131859: [clang-tidy] Adds QualifierAlignment to misc-const-correctness.

2022-08-14 Thread Mark de Wever via Phabricator via cfe-commits
Mordante abandoned this revision.
Mordante added a comment.

In D131859#3721877 , @njames93 wrote:

> Duplicate of D131386 

Thanks for the information. Can you integrate the additional fixes of this 
patch in yours; specifically the documentation and release notes fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131859

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


[PATCH] D131386: [clang-tidy] Added `ConstAlignment` option to `misc-const-correctness`

2022-08-14 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp:10
 #include "ConstCorrectnessCheck.h"
 #include "../utils/FixItHintUtils.h"
 #include "clang/AST/ASTContext.h"

This is already included in the header.



Comment at: clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp:66
+  ConstAlignment(
+  Options.get("ConstAlignment", utils::fixit::QualifierPolicy::Right)) 
{
   if (AnalyzeValues == false && AnalyzeReferences == false)

I would suggest to use `QualifierAlignment` to match the name in clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131386

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


[PATCH] D129160: libclang.so: Make SONAME the same as LLVM version

2022-08-14 Thread Isuru Fernando via Phabricator via cfe-commits
isuruf added a comment.

> Could you elaborate on this?

Sure. If an application links to `libclang.so` when the application is being 
built, the application will hardcode `libclang.so.13` in it and will look for 
it.
When the SONAME changes to `libclang.so.15` in LLVM 15, the application will 
not be able to use the libclang from LLVM 15 unless the
application was rebuilt with `libclang.so` in LLVM 15.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129160

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


[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-08-14 Thread David Rector via Phabricator via cfe-commits
davrec added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:12218
+CTN,
+NExpX && NExpY ? Optional(std::min(*NExpX, *NExpY)) : None);
+  }

I'm not clear on how `NExpX` could not equal `NExpY` - could you add a test 
which demonstrates this case?



Comment at: clang/lib/AST/ASTContext.cpp:12804
+  return QualType();
+SmallVector As;
+if (getCommonTemplateArguments(Ctx, As, TX->template_arguments(),

Nit: "As" -> "Args", since that's common elsewhere



Comment at: clang/lib/AST/ASTContext.cpp:12872
   }
 
   SplitQualType SX = X.split(), SY = Y.split();

It would be very helpful to incorporate your description and the description 
from D111283 as comments in this function.  E.g. something like the following 
...



Comment at: clang/lib/AST/ASTContext.cpp:12874
   SplitQualType SX = X.split(), SY = Y.split();
-  if (::removeDifferentTopLevelSugar(SX, SY))
-SX.Ty = ::getCommonType(*this, SX.Ty, SY.Ty).getTypePtr();
-
+  Qualifiers QX, QY;
+  auto Xs = ::unwrapSugar(SX, QX), Ys = ::unwrapSugar(SY, QY);

```
// Desugar SX and SY, setting the sugar and qualifiers aside into Xs and Ys/QX 
and QY, 
// until we reach their underlying "canonical nodes".  (Note these are not 
necessarily 
// canonical types, as their child types may still be sugared.)
```



Comment at: clang/lib/AST/ASTContext.cpp:12876
+  auto Xs = ::unwrapSugar(SX, QX), Ys = ::unwrapSugar(SY, QY);
+  if (SX.Ty != SY.Ty) {
+SX.Ty = ::getCommonNonSugarTypeNode(*this, SX.Ty, SY.Ty).getTypePtr();

```
// The canonical nodes differ. Build a common canonical node out of the two, 
// including any sugar shared by their child types.
```



Comment at: clang/lib/AST/ASTContext.cpp:12878
+SX.Ty = ::getCommonNonSugarTypeNode(*this, SX.Ty, SY.Ty).getTypePtr();
+  } else {
+while (!Xs.empty() && !Ys.empty() && Xs.back().Ty == Ys.back().Ty) {

```
// The canonical nodes were identical: we may have desugared too much.
// Add any common sugar back in.
```



Comment at: clang/lib/AST/ASTContext.cpp:12890
+assert(QX == QY);
+
+  while (!Xs.empty() && !Ys.empty()) {

```
// Even though the remaining sugar nodes in Xs and Ys differ, some may be of 
the same
// type class and have common sugar in their child types.  Walk up these nodes, 
// adding in any such sugar.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

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


[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

2022-08-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks building on windows: http://45.33.8.238/win/64423/step_4.txt

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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116203

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


[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-08-14 Thread David Rector via Phabricator via cfe-commits
davrec added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:12767
+Ctx.getQualifiedType(Underlying),
+::getCommonDecl(EX->getOwnedTagDecl(), EY->getOwnedTagDecl()));
+  }

This last argument should probably be omitted/nullptr passed, since
# We probably won't encounter any owned tag decls in the types passed to this 
function;
# Even if we did, it would not necessarily be true that they both have non-null 
owned tag decls, and I don't see any nullptr checks in getCommonDecl; and
# Even if we checked for nullptr there, and say passed the same argument to X 
and Y so EX==EY, and that had an owned tag decl, it is not clear to me it would 
be appropriate to construct a new type with the same owned tag decl as another 
type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

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


[clang] c85abbe - [Sema] Fix a warning

2022-08-14 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-08-14T11:25:19-07:00
New Revision: c85abbe879ef3257de4db862ce249b060cc3d2a4

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

LOG: [Sema] Fix a warning

This patch fixes:

  clang/lib/Sema/SemaType.cpp:9469:3: error: default label in switch
  which covers all enumeration values
  [-Werror,-Wcovered-switch-default]

Added: 


Modified: 
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 5bd0dac50362..fb339fab16a8 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9466,8 +9466,6 @@ QualType Sema::BuildUnaryTransformType(QualType BaseType, 
UTTKind UKind,
 Result = BuiltinChangeSignedness(BaseType, UKind, Loc);
 break;
   }
-  default:
-llvm_unreachable("unknown unary transform type");
   }
 
   return !Result.isNull()



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


[PATCH] D129160: libclang.so: Make SONAME the same as LLVM version

2022-08-14 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D129160#3721943 , @isuruf wrote:

> Sure. If an application links to `libclang.so` when the application is being 
> built, the application will hardcode `libclang.so.13` in it and will look for 
> it.
> When the SONAME changes to `libclang.so.15` in LLVM 15, the application will 
> not be able to use the libclang from LLVM 15 unless the
> application was rebuilt with `libclang.so` in LLVM 15.

That's the problem **after** this change, but what was the problem before the 
change? The commit message (where my quote is from) suggests this wouldn't have 
worked even if we stayed at `libclang.so.13` in LLVM 15.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129160

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


[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

2022-08-14 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

This also broke building with GCC 9 on Ubuntu 20.04:

  [5/225] ASTNodeAPI.json
  FAILED: tools/clang/lib/Tooling/ASTNodeAPI.json
  cd /home/martin/code/llvm-project/llvm/build/tools/clang/lib/Tooling && 
/home/martin/code/llvm-project/llvm/build/bin/clang-ast-dump 
--skip-processing=0 -I 
/home/martin/code/llvm-project/llvm/build/lib/clang/16.0.0/include -I 
/home/martin/code/llvm-project/llvm/tools/clang/include -I 
/home/martin/code/llvm-project/llvm/build/tools/clang/include -I 
/home/martin/code/llvm-project/llvm/build/include -I 
/home/martin/code/llvm-project/llvm/include -I /usr/include/c++/9 -I 
/usr/include/x86_64-linux-gnu/c++/9 -I /usr/include/c++/9/backward -I 
/usr/lib/gcc/x86_64-linux-gnu/9/include -I /usr/local/include -I 
/usr/include/x86_64-linux-gnu -I /usr/include --json-output-path 
/home/martin/code/llvm-project/llvm/build/tools/clang/lib/Tooling/ASTNodeAPI.json
  clang-ast-dump: ../tools/clang/lib/Sema/DeclSpec.cpp:833: bool 
clang::DeclSpec::SetTypeSpecType(clang::DeclSpec::TST, clang::SourceLocation, 
const char*&, unsigned int&, const clang::PrintingPolicy&): Assertion 
`!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) && "rep required for these 
type-spec kinds!"' failed.
  Aborted (core dumped)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116203

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


[PATCH] D131789: [clang-tools-extra] Rewrite prints in python3 compatible way

2022-08-14 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Maybe add the [NFC] tag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131789

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


[PATCH] D116203: [clang] adds unary type transformations as compiler built-ins

2022-08-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Reverted this (and follow-ups) in aacf1a9742f714dd432117d82d19a007289c3dee 
 for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116203

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


[PATCH] D131532: [Sema] Avoid isNullPointerConstant invocation

2022-08-14 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.

Awesome! This makes a measurable improvement in my Linux kernel build times!

Thanks for the patch, and thanks @rtrieu for suggestions that will improve C++ 
code compilation times as well.

I'll commit this for you since you don't yet have commit access.

Let's keep an eye on https://llvm-compile-time-tracker.com/compare.php to see 
how this does.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131532

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


[clang] 333771f - [Sema] Avoid isNullPointerConstant invocation

2022-08-14 Thread Nick Desaulniers via cfe-commits

Author: Justin Stitt
Date: 2022-08-14T13:39:57-07:00
New Revision: 333771f3558c81390a0e5d715ad8d1e419050b66

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

LOG: [Sema] Avoid isNullPointerConstant invocation

DiagnoseNullConversion is needlessly calling isNullPointerConstant which
is an expensive routine due to its calls to a constant evaluator --
which we don't need.

Building the Linux Kernel (x86_64) with this fix has improved build
times by ~2.1%. This is mainly due to the following methods no longer
needing to be called anywhere near as often:
1) ExprConstant::CheckICE (reduced CPU cycles by ~90%)
2) IntExprEvaluator::VisitBinaryOperator (reduced CPU cycles by ~50%)

Reviewed By: rtrieu, nickdesaulniers

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a0ea35e1234f6..bb4ca8c1e4209 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -13355,9 +13355,10 @@ static void DiagnoseNullConversion(Sema &S, Expr *E, 
QualType T,
 return;
 
   // Check for NULL (GNUNull) or nullptr (CXX11_nullptr).
-  const Expr::NullPointerConstantKind NullKind =
-  E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull);
-  if (NullKind != Expr::NPCK_GNUNull && NullKind != Expr::NPCK_CXX11_nullptr)
+  const Expr *NewE = E->IgnoreParenImpCasts();
+  bool IsGNUNullExpr = isa(NewE);
+  bool HasNullPtrType = NewE->getType()->isNullPtrType();
+  if (!IsGNUNullExpr && !HasNullPtrType)
 return;
 
   // Return if target type is a safe conversion.
@@ -13374,7 +13375,7 @@ static void DiagnoseNullConversion(Sema &S, Expr *E, 
QualType T,
   CC = S.SourceMgr.getTopMacroCallerLoc(CC);
 
   // __null is usually wrapped in a macro.  Go up a macro if that is the case.
-  if (NullKind == Expr::NPCK_GNUNull && Loc.isMacroID()) {
+  if (IsGNUNullExpr && Loc.isMacroID()) {
 StringRef MacroName = Lexer::getImmediateMacroNameForDiagnostics(
 Loc, S.SourceMgr, S.getLangOpts());
 if (MacroName == "NULL")
@@ -13386,7 +13387,7 @@ static void DiagnoseNullConversion(Sema &S, Expr *E, 
QualType T,
 return;
 
   S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer)
-  << (NullKind == Expr::NPCK_CXX11_nullptr) << T << SourceRange(CC)
+  << HasNullPtrType << T << SourceRange(CC)
   << FixItHint::CreateReplacement(Loc,
   S.getFixItZeroLiteralForType(T, Loc));
 }



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


[PATCH] D131532: [Sema] Avoid isNullPointerConstant invocation

2022-08-14 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG333771f3558c: [Sema] Avoid isNullPointerConstant invocation 
(authored by justinstitt, committed by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131532

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13355,9 +13355,10 @@
 return;
 
   // Check for NULL (GNUNull) or nullptr (CXX11_nullptr).
-  const Expr::NullPointerConstantKind NullKind =
-  E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull);
-  if (NullKind != Expr::NPCK_GNUNull && NullKind != Expr::NPCK_CXX11_nullptr)
+  const Expr *NewE = E->IgnoreParenImpCasts();
+  bool IsGNUNullExpr = isa(NewE);
+  bool HasNullPtrType = NewE->getType()->isNullPtrType();
+  if (!IsGNUNullExpr && !HasNullPtrType)
 return;
 
   // Return if target type is a safe conversion.
@@ -13374,7 +13375,7 @@
   CC = S.SourceMgr.getTopMacroCallerLoc(CC);
 
   // __null is usually wrapped in a macro.  Go up a macro if that is the case.
-  if (NullKind == Expr::NPCK_GNUNull && Loc.isMacroID()) {
+  if (IsGNUNullExpr && Loc.isMacroID()) {
 StringRef MacroName = Lexer::getImmediateMacroNameForDiagnostics(
 Loc, S.SourceMgr, S.getLangOpts());
 if (MacroName == "NULL")
@@ -13386,7 +13387,7 @@
 return;
 
   S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer)
-  << (NullKind == Expr::NPCK_CXX11_nullptr) << T << SourceRange(CC)
+  << HasNullPtrType << T << SourceRange(CC)
   << FixItHint::CreateReplacement(Loc,
   S.getFixItZeroLiteralForType(T, Loc));
 }


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13355,9 +13355,10 @@
 return;
 
   // Check for NULL (GNUNull) or nullptr (CXX11_nullptr).
-  const Expr::NullPointerConstantKind NullKind =
-  E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull);
-  if (NullKind != Expr::NPCK_GNUNull && NullKind != Expr::NPCK_CXX11_nullptr)
+  const Expr *NewE = E->IgnoreParenImpCasts();
+  bool IsGNUNullExpr = isa(NewE);
+  bool HasNullPtrType = NewE->getType()->isNullPtrType();
+  if (!IsGNUNullExpr && !HasNullPtrType)
 return;
 
   // Return if target type is a safe conversion.
@@ -13374,7 +13375,7 @@
   CC = S.SourceMgr.getTopMacroCallerLoc(CC);
 
   // __null is usually wrapped in a macro.  Go up a macro if that is the case.
-  if (NullKind == Expr::NPCK_GNUNull && Loc.isMacroID()) {
+  if (IsGNUNullExpr && Loc.isMacroID()) {
 StringRef MacroName = Lexer::getImmediateMacroNameForDiagnostics(
 Loc, S.SourceMgr, S.getLangOpts());
 if (MacroName == "NULL")
@@ -13386,7 +13387,7 @@
 return;
 
   S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer)
-  << (NullKind == Expr::NPCK_CXX11_nullptr) << T << SourceRange(CC)
+  << HasNullPtrType << T << SourceRange(CC)
   << FixItHint::CreateReplacement(Loc,
   S.getFixItZeroLiteralForType(T, Loc));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131532: [Sema] Avoid isNullPointerConstant invocation

2022-08-14 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

https://llvm-compile-time-tracker.com/compare.php?from=0299ebc1bdc9fca176ebcacd590c90dc77a47551&to=333771f3558c81390a0e5d715ad8d1e419050b66&stat=cycles
 should be the link, once it gets picked up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131532

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


[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-08-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 452561.
ychen marked 3 inline comments as done.
ychen added a comment.

- address Roy's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -959,7 +959,7 @@
   
   
 https://wg21.link/p2113r0";>P2113R0
-No
+Clang 16
   
 
 
Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -1,10 +1,17 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
-struct A;
-struct B;
-
 template  constexpr bool True = true;
 template  concept C = True;
+template  concept D = C && sizeof(T)>2;
+template  concept E = D && alignof(T)>1;
+
+struct A {};
+template  struct S {};
+template  struct X {};
+
+namespace p6 {
+
+struct B;
 
 void f(C auto &, auto &) = delete;
 template  void f(Q &, C auto &);
@@ -13,14 +20,57 @@
   f(*ap, *bp);
 }
 
-template  struct X {};
-
+#if 0
+// FIXME: [temp.func.order]p6.2.1 is not implemented, matching GCC.
 template  bool operator==(X, V) = delete;
 templatebool operator==(T, X);
 
 bool h() {
   return X{} == 0;
 }
+#endif
+
+template class U, typename... Z> void foo(T, U) = delete;
+template class U, typename... Z> void foo(T, U) = delete;
+template class U, typename... Z> void foo(T, U);
+
+void bar(S s) {
+  foo(0,s);
+}
+
+} // namespace p6
+
+namespace TestConversionFunction {
+struct Y {
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+};
+
+X f() {
+  return Y{}; // expected-error {{conversion from 'Y' to 'X' is ambiguous}}
+}
+}
+
+namespace ClassPartialSpecPartialOrdering {
+template struct Y { Y()=delete; }; // expected-note {{template is declared here}}
+template struct Y {}; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct B{ B()=delete; };
+template struct B { B()=delete; };
+template struct B {};
+
+template class U, typename... Z> struct Some { Some()=delete; };
+template class U, typename... Z> struct Some { Some()=delete; };
+template class U, typename... Z> struct Some {};
+
+void f() {
+  B b;
+  Some c;
+}
+
+template struct Z; // expected-note {{template is declared here}}
+template struct Z; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+}
 
 namespace PR53640 {
 
Index: clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,26 +98,31 @@
   static_assert(is_same_v()), void>); // expected-error {{call to 'bar' is ambiguous}}
 
   template
-  constexpr int goo(int a) requires AtLeast2 && true {
+  constexpr int goo(int a) requires AtLeast2 && true { // expected-note {{candidate function}}
 return 1;
   }
 
   template
-  constexpr int goo(const int b) requires AtLeast2 {
+  constexpr int goo(const int b) requires AtLeast2 { // expected-note {{candidate function}}
 return 2;
   }
 
-  // Only trailing requires clauses of redeclarations are compared for overload resolution.
+  // [temp.func.order] p5
+  //   Since, in a call context, such type deduction considers only parameters
+  //   for which there are explicit call arguments, some parameters are ignored
+  //   (namely, function parameter packs, parameters with default arguments, and
+  //   ellipsis parameters).
   template
-  constexpr int doo(int a, ...) requires AtLeast2 && true { // expected-note {{candidate function}}
+  constexpr int doo(int a, ...) requires AtLeast2 && true {
 return 1;
   }
 
   template
-  constexpr int doo(int b) requires AtLeast2 { // expected-note {{candidate function}}
+  constexpr int doo(int b) requires AtLeast2 {
 return 2;
   }
 
-  static_assert(goo(1) == 1);
-  static_assert(doo(2) == 1); // expected-error {{call to 'doo' is ambiguous}}
+  // By temp.func.order-6.2.2, this is am

[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-08-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5183
   if (!Better1 && !Better2) // Neither is better than the other
-return JudgeByConstraints();
+return nullptr;
+

royjacobson wrote:
> Previously we continued to check by constraints, now we directly return 
> `nullptr`, doesn't this mean we don't perform constraints checks that we've 
> done before? Or was it a bug?
I think this was a bug. By https://eel.is/c++draft/temp.func.order#6, the 
constraints check is performed only when `Better1 && Better2`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

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


[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-08-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D128750#3721441 , @royjacobson 
wrote:

> Some documentation/test nits, and one question, but otherwise LGTM.
> Could you fix the merge conflict? It would be nice to see pre-commit CI 
> results.
>
> Given the complexity of the technical details here, as long as it doesn't 
> unreasonably delay this, please wait for other people to also review it.

Thanks for the review. Sure, I'll wait for more feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

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


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

2022-08-14 Thread David Rector via Phabricator via cfe-commits
davrec added a comment.

It was very good to separate this out, thanks.  Can you can do some TMP 
performance testing, to verify the impacts are negligible before taking 
resugaring into consideration, to allay potential concerns?




Comment at: clang/include/clang/AST/Type.h:1838
 /// metaprogramming we'd prefer to keep it as large as possible.
-/// At the moment it has been left as a non-bitfield since this type
-/// safely fits in 64 bits as an unsigned, so there is no reason to
-/// introduce the performance impact of a bitfield.
-unsigned NumArgs;
+unsigned NumArgs : 16;
   };

I can't imagine that limiting template arg index to 16 bits from 32 could be 
all that limiting, but given the comment in the original have you 
tested/confirmed that this is acceptable?



Comment at: clang/include/clang/AST/Type.h:5010
 
-  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon,
-Optional PackIndex)
-  : Type(SubstTemplateTypeParm, Canon, Canon->getDependence()),
-Replaced(Param) {
-SubstTemplateTypeParmTypeBits.PackIndex = PackIndex ? *PackIndex + 1 : 0;
-  }
+  // The templated entity which owned the substituted type parameter.
+  Decl *ReplacedDecl;

This description is inconsistent with the `getReplacedDecl()` documentation: 
this one says its templated, the other says its a template specialization.  I 
think it is a template or templated decl, correct?  In either case, I think you 
can remove this comment and just be sure `getReplacedDecl()` is documented 
accurately.

Also, I wonder if there is a better name than "ReplacedDecl", since that name 
suggests it should return a `TemplateTypeParmDecl` or similar, when its really 
the template-parameterized declaration that holds the parameter this replaces.  
Maybe "ReplacedParent"?  Or "ReplacedParmParent"?



Comment at: clang/include/clang/AST/Type.h:5075
 
-  SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
-QualType Canon,
+  // The template specialization which owned the substituted type parameter.
+  Decl *ReplacedDecl;

See above



Comment at: clang/lib/AST/ASTStructuralEquivalence.cpp:1061
   return false;
+if (Subst1->getReplacedDecl() != Subst2->getReplacedDecl())
+  return false;

Should this line instead be something like `if !IsStructurallyEquivalent(*this, 
Subst1->getReplacedDecl(), Subst2->getReplacedDecl())`?



Comment at: clang/lib/AST/ASTStructuralEquivalence.cpp:1073
 const auto *Subst2 = cast(T2);
-if (!IsStructurallyEquivalent(Context,
-  QualType(Subst1->getReplacedParameter(), 0),
-  QualType(Subst2->getReplacedParameter(), 0)))
+if (Subst1->getReplacedDecl() != Subst2->getReplacedDecl())
+  return false;

See above



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:1787-1788
   const TemplateTypeParmType *T = TL.getTypePtr();
+  TemplateTypeParmDecl *NewTTPDecl = cast_or_null(
+  TransformDecl(TL.getNameLoc(), T->getDecl()));
+

I don't think this needs to have been moved up here from line 1855; move it 
back down so the comment down there still makes sense


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


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

2022-08-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 452562.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,3 +1,4 @@
 D111283
 D111509
 D130308
+D131858
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -156,9 +156,8 @@
 // CHECK:   |-BuiltinType {{.*}} 'int'
 // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
 // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
-// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack
-// CHECK: |-TemplateTypeParmType {{.*}} 'U' dependent contains_unexpanded_pack depth 1 index 0 pack
-// CHECK: | `-TemplateTypeParm {{.*}} 'U'
+// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U
+// CHECK: |-TypeAliasTemplate {{.*}} 'B'
 // CHECK: `-TemplateArgument pack
 // CHECK:   |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NOT: Subst
Index: clang/test/AST/deduction-guides.cpp
===
--- clang/test/AST/deduction-guides.cpp
+++ clang/test/AST/deduction-guides.cpp
@@ -67,9 +67,8 @@
 // CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived::type_alias' sugar
 // CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base::type_alias' sugar
 // CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
-// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
-// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
+// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar class depth 0 index 0 A
+// CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'Base'
 // CHECK-NEXT: BuiltinType {{.*}} 'int'
 
 // CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (Derived &&, const typename Derived::type_alias &) -> Derived'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -120,12 +120,12 @@
 // CHECK-NEXT: TemplateArgument type 'void'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent depth 0 index 0
-// CHECK-NEXT: TemplateTypeParm 0x{{[^ ]*}} 'U'
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent depth 0 index 0
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
+// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
+// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
 } // namespace PR55886
 
 namespace PR56099 {
@@ -136,14 +136,14 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypePar

[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 452564.
ychen added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/drs/dr6xx.cpp
  clang/test/CodeGen/partial-order-variadic.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -4194,7 +4194,7 @@
 https://wg21.link/cwg692";>692
 C++11
 Partial ordering of variadic class template partial specializations
-No
+Clang 16
   
   
 https://wg21.link/cwg693";>693
@@ -8178,7 +8178,7 @@
 https://wg21.link/cwg1395";>1395
 C++17
 Partial ordering of variadic templates reconsidered
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg1396";>1396
Index: clang/test/CodeGen/partial-order-variadic.cpp
===
--- /dev/null
+++ clang/test/CodeGen/partial-order-variadic.cpp
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14 %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
+
+// CHECK-14: define dso_local void @_ZN24temp_func_order_example31hEi(i32 noundef %i)
+// CHECK-14-NEXT: entry:
+// CHECK-14-NEXT:   %i.addr = alloca i32, align 4
+// CHECK-14-NEXT:   %r = alloca ptr, align 8
+// CHECK-14-NEXT:   store i32 %i, ptr %i.addr, align 4
+// CHECK-14-NEXT:   %call = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN24temp_func_order_example31gIiJEEERiPT_DpT0_(ptr noundef %i.addr)
+// CHECK-14-NEXT:   store ptr %call, ptr %r, align 8
+// CHECK-14-NEXT:   ret void
+
+namespace temp_func_order_example3 {
+  template  int &g(T *, U...);
+  template  void g(T);
+  void h(int i) {
+int &r = g(&i);
+  }
+}
+
+#else
+
+// CHECK: %"struct.temp_deduct_type_example1::A" = type { i8 }
+
+// CHECK: $_ZN25temp_deduct_type_example31fIiJEEEvPT_DpT0_ = comdat any
+
+// CHECK: define dso_local void @_ZN25temp_deduct_type_example11fEv()
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %a = alloca %"struct.temp_deduct_type_example1::A", align 1
+// CHECK-NEXT:   ret void
+
+// CHECK: define weak_odr void @_ZN25temp_deduct_type_example31fIiJEEEvPT_DpT0_(ptr noundef %0)
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %.addr = alloca ptr, align 8
+// CHECK-NEXT:   store ptr %0, ptr %.addr, align 8
+// CHECK-NEXT:   ret void
+
+namespace temp_deduct_type_example1 {
+  template struct A;
+  template struct A {};
+  template struct A;
+  template struct A;
+  void f() { A a; }
+}
+
+namespace temp_deduct_type_example3 {
+  template void f(T*, U...){}
+  template void f(T){}
+  template void f(int*);
+}
+
+#endif
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -1080,19 +1080,18 @@
 }
 
 namespace dr692 { // dr692: no
+  // Also see dr1395.
+
   namespace temp_func_order_example2 {
 template  struct A {};
 template  void f(U, A *p = 0); // expected-note {{candidate}}
 template  int &f(U, A *p = 0); // expected-note {{candidate}}
-template  void g(T, T = T());
-template  void g(T, U...); // expected-error 0-1{{C++11}}
+template  void g(T, T = T()); // expected-note {{candidate}}
+template  void g(T, U...); // expected-note {{candidate}} expected-error 0-1{{C++11}}
 void h() {
   int &r = f(42, (A *)0);
   f(42); // expected-error {{ambiguous}}
-  // FIXME: We should reject this due to ambiguity between the pack and the
-  // default argument. Only parameters with arguments are considered during
-  // partial ordering of function templates.
-  g(42);
+  g(42); // expected-error {{ambiguous}}
 }
   }
 
@@ -1125,20 +1124,16 @@
 template  class S {};
 S s;
 
-// FIXME: This should select the first partial specialization. Deduction of
-// the second from the first should succeed, because we should ignore the
-// trailing pack in A with no corresponding P.
 template struct A; // expected-error 0-1{{C++11}}
-template struct A; // expected-note {{matches}} expected-error 0-1{{C++11}}
-template struct A {}; // expected-note {{matches}}
-template struct A; // expected-error {{ambiguous}}
+template struct A {}; // expected-error 0-1{{C++11}}
+template struct A;
+template struct A;
   }
 
   namespace temp_deduct_type_example3 {
-// FIXME: This should select the first template, as in the case above.
-template void f(T*, U...){} // expected-note {{candidate}} expected-error 0-1{{C++

[clang] 6afcc4a - [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-14 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-14T14:37:40-07:00
New Revision: 6afcc4a459ead8809a0d6d9b4bf7b64bcc13582b

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

LOG: [c++] implements DR692, DR1395 and tentatively DR1432, about partial 
ordering of variadic template partial specialization or function template

DR692 handles two cases: pack expansion (for class/var template) and function 
parameter pack. The former needs DR1432 as a fix, and the latter needs DR1395 
as a fix. However, DR1432 has not yet made a wording change. so I made a 
tentative fix for DR1432 with the same spirit as DR1395.

Reviewed By: aaron.ballman, erichkeane, #clang-language-wg

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

Added: 
clang/test/CodeGen/partial-order-variadic.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6970149444d1..a635b734c47a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,6 +135,9 @@ C2x Feature Support
 C++ Language Changes in Clang
 -
 
+- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=14`` 
option
+  to get the old partial ordering behavior regarding packs.
+
 C++20 Feature Support
 ^
 

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 09e5d7b80127..6836f7c090be 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -55,6 +55,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1100,6 +1101,18 @@ DeduceTemplateArguments(Sema &S,
   return Result;
   }
 
+  // DR692, DR1395
+  // C++0x [temp.deduct.type]p10:
+  // If the parameter-declaration corresponding to P_i ...
+  // During partial ordering, if Ai was originally a function parameter pack:
+  // - if P does not contain a function parameter type corresponding to Ai then
+  //   Ai is ignored;
+  bool ClangABICompat14 = S.Context.getLangOpts().getClangABICompat() <=
+  LangOptions::ClangABI::Ver14;
+  if (!ClangABICompat14 && PartialOrdering && ArgIdx + 1 == NumArgs &&
+  isa(Args[ArgIdx]))
+return Sema::TDK_Success;
+
   // Make sure we don't have any extra arguments.
   if (ArgIdx < NumArgs)
 return Sema::TDK_MiscellaneousDeductionFailure;
@@ -1755,7 +1768,7 @@ static Sema::TemplateDeductionResult 
DeduceTemplateArgumentsByTypeMatch(
   if (auto Result = DeduceTemplateArguments(
   S, TemplateParams, FPP->param_type_begin(), FPP->getNumParams(),
   FPA->param_type_begin(), FPA->getNumParams(), Info, Deduced,
-  TDF & TDF_TopLevelParameterTypeList))
+  TDF & TDF_TopLevelParameterTypeList, PartialOrdering))
 return Result;
 
   if (TDF & TDF_AllowCompatibleFunctionType)
@@ -2422,6 +2435,7 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList 
*TemplateParams,
 static bool isSameTemplateArg(ASTContext &Context,
   TemplateArgument X,
   const TemplateArgument &Y,
+  bool PartialOrdering,
   bool PackExpansionMatchesPack = false) {
   // If we're checking deduced arguments (X) against original arguments (Y),
   // we will have flattened packs to non-expansions in X.
@@ -2463,16 +2477,30 @@ static bool isSameTemplateArg(ASTContext &Context,
 }
 
 case TemplateArgument::Pack:
-  if (X.pack_size() != Y.pack_size())
-return false;
-
-  for (TemplateArgument::pack_iterator XP = X.pack_begin(),
-XPEnd = X.pack_end(),
-   YP = Y.pack_begin();
-   XP != XPEnd; ++XP, ++YP)
-if (!isSameTemplateArg(Context, *XP, *YP, PackExpansionMatchesPack))
+  unsigned PackIterationSize = X.pack_size();
+  if (X.pack_size() != Y.pack_size()) {
+if (!PartialOrdering)
   return false;
 
+// C++0x [temp.deduct.type]p9:
+// During partial ordering, if Ai was originally a pack expansion:
+// - if P does not contain a template argument corresponding to Ai then
+//   Ai is ignored;
+bool XHasMoreArg = X.pack_size() > Y.pack_size();
+if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
+!(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))
+  return false;
+
+if (XHasMoreArg)
+  PackIterationSize = Y.pack_size();
+  }
+
+  ArrayRef XP = X.pack_element

[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-14 Thread Yuanfang Chen 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 rG6afcc4a459ea: [c++] implements DR692, DR1395 and tentatively 
DR1432, about partial ordering… (authored by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/drs/dr6xx.cpp
  clang/test/CodeGen/partial-order-variadic.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -4194,7 +4194,7 @@
 https://wg21.link/cwg692";>692
 C++11
 Partial ordering of variadic class template partial specializations
-No
+Clang 16
   
   
 https://wg21.link/cwg693";>693
@@ -8178,7 +8178,7 @@
 https://wg21.link/cwg1395";>1395
 C++17
 Partial ordering of variadic templates reconsidered
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg1396";>1396
Index: clang/test/CodeGen/partial-order-variadic.cpp
===
--- /dev/null
+++ clang/test/CodeGen/partial-order-variadic.cpp
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14 %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-14
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
+
+// CHECK-14: define dso_local void @_ZN24temp_func_order_example31hEi(i32 noundef %i)
+// CHECK-14-NEXT: entry:
+// CHECK-14-NEXT:   %i.addr = alloca i32, align 4
+// CHECK-14-NEXT:   %r = alloca ptr, align 8
+// CHECK-14-NEXT:   store i32 %i, ptr %i.addr, align 4
+// CHECK-14-NEXT:   %call = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN24temp_func_order_example31gIiJEEERiPT_DpT0_(ptr noundef %i.addr)
+// CHECK-14-NEXT:   store ptr %call, ptr %r, align 8
+// CHECK-14-NEXT:   ret void
+
+namespace temp_func_order_example3 {
+  template  int &g(T *, U...);
+  template  void g(T);
+  void h(int i) {
+int &r = g(&i);
+  }
+}
+
+#else
+
+// CHECK: %"struct.temp_deduct_type_example1::A" = type { i8 }
+
+// CHECK: $_ZN25temp_deduct_type_example31fIiJEEEvPT_DpT0_ = comdat any
+
+// CHECK: define dso_local void @_ZN25temp_deduct_type_example11fEv()
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %a = alloca %"struct.temp_deduct_type_example1::A", align 1
+// CHECK-NEXT:   ret void
+
+// CHECK: define weak_odr void @_ZN25temp_deduct_type_example31fIiJEEEvPT_DpT0_(ptr noundef %0)
+// CHECK-NEXT: entry:
+// CHECK-NEXT:   %.addr = alloca ptr, align 8
+// CHECK-NEXT:   store ptr %0, ptr %.addr, align 8
+// CHECK-NEXT:   ret void
+
+namespace temp_deduct_type_example1 {
+  template struct A;
+  template struct A {};
+  template struct A;
+  template struct A;
+  void f() { A a; }
+}
+
+namespace temp_deduct_type_example3 {
+  template void f(T*, U...){}
+  template void f(T){}
+  template void f(int*);
+}
+
+#endif
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -1080,19 +1080,18 @@
 }
 
 namespace dr692 { // dr692: no
+  // Also see dr1395.
+
   namespace temp_func_order_example2 {
 template  struct A {};
 template  void f(U, A *p = 0); // expected-note {{candidate}}
 template  int &f(U, A *p = 0); // expected-note {{candidate}}
-template  void g(T, T = T());
-template  void g(T, U...); // expected-error 0-1{{C++11}}
+template  void g(T, T = T()); // expected-note {{candidate}}
+template  void g(T, U...); // expected-note {{candidate}} expected-error 0-1{{C++11}}
 void h() {
   int &r = f(42, (A *)0);
   f(42); // expected-error {{ambiguous}}
-  // FIXME: We should reject this due to ambiguity between the pack and the
-  // default argument. Only parameters with arguments are considered during
-  // partial ordering of function templates.
-  g(42);
+  g(42); // expected-error {{ambiguous}}
 }
   }
 
@@ -1125,20 +1124,16 @@
 template  class S {};
 S s;
 
-// FIXME: This should select the first partial specialization. Deduction of
-// the second from the first should succeed, because we should ignore the
-// trailing pack in A with no corresponding P.
 template struct A; // expected-error 0-1{{C++11}}
-template struct A; // expected-note {{matches}} expected-error 0-1{{C++11}}
-template struct A {}; // expected-note {{matches}}
-template struct A; // expected-error {{ambiguous}}
+template struct A {}; // expected-error 0-1{{C++11}}
+template struct A;
+template struct A;
   }
 
   namespace temp_

[PATCH] D131866: [clang] fix frontend crash in auto type templates

2022-08-14 Thread YingChi Long via Phabricator via cfe-commits
inclyc created this revision.
Herald added a project: All.
inclyc added reviewers: mizvekov, aaron.ballman.
inclyc updated this revision to Diff 452566.
inclyc added a comment.
inclyc added subscribers: cfe-commits, clang.
inclyc published this revision for review.
Herald added a project: clang.

improve test case


Reported by https://github.com/llvm/llvm-project/issues/57142

In this case, `AutoTypes.FindNodeOrInsertPos` found appropriate `AT`
value and should return that directly, however before this patch we
assumes that it always get `InsertPos` back and create a new `AT` for
it. In fact `InsertPos` is a nullptr, which causes segmentfault.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131866

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/sugared-auto.cpp


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace with 
`auto`
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void Import(
+const InitFrom auto& C // before this patch clang crashes 
here
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace with `auto`
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void Import(
+const InitFrom auto& C // before this patch clang crashes here
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131866: [clang] fix frontend crash in auto type templates

2022-08-14 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 452567.
inclyc added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131866

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/sugared-auto.cpp


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void Import(
+const InitFrom auto& C // before this patch clang crashes 
here
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void Import(
+const InitFrom auto& C // before this patch clang crashes here
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131866: [clang] fix frontend crash in auto type templates

2022-08-14 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 452568.
inclyc added a comment.

rename


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131866

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/sugared-auto.cpp


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void buggy_func(
+const InitFrom auto& C // before this patch clang crashes 
here
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void buggy_func(
+const InitFrom auto& C // before this patch clang crashes here
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131866: [clang] fix frontend crash in auto type templates

2022-08-14 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 452569.
inclyc added a comment.

update comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131866

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/sugared-auto.cpp


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void buggy_func(
+const InitFrom auto& C // before this patch clang crashes 
here
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void buggy_func(
+const InitFrom auto& C // before this patch clang crashes here
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131866: [clang] fix frontend crash in auto type templates

2022-08-14 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 452571.
inclyc added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131866

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/sugared-auto.cpp


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void buggy_func(
+const InitFrom auto& C // crashed here in #57142
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,39 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+struct true_type {
+  static const bool value = true;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void buggy_func(
+const InitFrom auto& C // crashed here in #57142
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131866: [clang] fix frontend crash in auto type templates

2022-08-14 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 452572.
inclyc added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131866

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/sugared-auto.cpp


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,33 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void buggy_func(
+const InitFrom auto& C // crashed here in #57142
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();


Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -41,3 +41,33 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace issue57142 {
+
+// Should not crash here
+// Reported by https://github.com/llvm/llvm-project/issues/57142
+
+
+// Only crashes if `tuple` is defined outside of the buggy namespace
+namespace outer {
+template  class tuple;
+} // namespace outer
+
+namespace {
+struct false_type {
+  static const bool value = false;
+};
+
+template class, typename>
+struct IsTemplateOf : false_type {};
+
+template class ATemplate>
+concept InitFrom = IsTemplateOf::value;
+
+
+static void buggy_func(
+const InitFrom auto& C // crashed here in #57142
+); 
+} // namespace
+
+} // namespace issue57142
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5732,7 +5732,8 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }
 } else {
   Canon = DeducedType.getCanonicalType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-08-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 452574.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,3 +1,4 @@
 D111283
 D111509
 D130308
+D131858
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -156,9 +156,8 @@
 // CHECK:   |-BuiltinType {{.*}} 'int'
 // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
 // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
-// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack
-// CHECK: |-TemplateTypeParmType {{.*}} 'U' dependent contains_unexpanded_pack depth 1 index 0 pack
-// CHECK: | `-TemplateTypeParm {{.*}} 'U'
+// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U
+// CHECK: |-TypeAliasTemplate {{.*}} 'B'
 // CHECK: `-TemplateArgument pack
 // CHECK:   |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NOT: Subst
Index: clang/test/AST/deduction-guides.cpp
===
--- clang/test/AST/deduction-guides.cpp
+++ clang/test/AST/deduction-guides.cpp
@@ -67,9 +67,8 @@
 // CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived::type_alias' sugar
 // CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base::type_alias' sugar
 // CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
-// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
-// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
+// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar class depth 0 index 0 A
+// CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'Base'
 // CHECK-NEXT: BuiltinType {{.*}} 'int'
 
 // CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (Derived &&, const typename Derived::type_alias &) -> Derived'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -120,12 +120,12 @@
 // CHECK-NEXT: TemplateArgument type 'void'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent depth 0 index 0
-// CHECK-NEXT: TemplateTypeParm 0x{{[^ ]*}} 'U'
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent depth 0 index 0
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
+// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
+// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
 } // namespace PR55886
 
 namespace PR56099 {
@@ -136,14 +136,14 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypePar

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

2022-08-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/include/clang/AST/Type.h:1838
 /// metaprogramming we'd prefer to keep it as large as possible.
-/// At the moment it has been left as a non-bitfield since this type
-/// safely fits in 64 bits as an unsigned, so there is no reason to
-/// introduce the performance impact of a bitfield.
-unsigned NumArgs;
+unsigned NumArgs : 16;
   };

davrec wrote:
> I can't imagine that limiting template arg index to 16 bits from 32 could be 
> all that limiting, but given the comment in the original have you 
> tested/confirmed that this is acceptable?
Not yet, we will begin performance testing soon. But I am not concerned about 
this one, as it's easy to get around this limitation by not using the bitfields.



Comment at: clang/include/clang/AST/Type.h:5010
 
-  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon,
-Optional PackIndex)
-  : Type(SubstTemplateTypeParm, Canon, Canon->getDependence()),
-Replaced(Param) {
-SubstTemplateTypeParmTypeBits.PackIndex = PackIndex ? *PackIndex + 1 : 0;
-  }
+  // The templated entity which owned the substituted type parameter.
+  Decl *ReplacedDecl;

davrec wrote:
> This description is inconsistent with the `getReplacedDecl()` documentation: 
> this one says its templated, the other says its a template specialization.  I 
> think it is a template or templated decl, correct?  In either case, I think 
> you can remove this comment and just be sure `getReplacedDecl()` is 
> documented accurately.
> 
> Also, I wonder if there is a better name than "ReplacedDecl", since that name 
> suggests it should return a `TemplateTypeParmDecl` or similar, when its 
> really the template-parameterized declaration that holds the parameter this 
> replaces.  Maybe "ReplacedParent"?  Or "ReplacedParmParent"?
Well it's the templated entity that owns this substitution. It unfortunately 
can't be just a TemplateDecl because some templated entities do not derive from 
that unfortunately.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:1787-1788
   const TemplateTypeParmType *T = TL.getTypePtr();
+  TemplateTypeParmDecl *NewTTPDecl = cast_or_null(
+  TransformDecl(TL.getNameLoc(), T->getDecl()));
+

davrec wrote:
> I don't think this needs to have been moved up here from line 1855; move it 
> back down so the comment down there still makes sense
Well the comment there does make more sense now, since it was not talking about 
the block of code that got moved here.

But you are right it's not needed anymore, this is left over code from a 
previous approach to the problem, before the changes in this patch made it 
obsolete.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D131866: [clang] fix frontend crash in auto type templates

2022-08-14 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:5735-5736
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))
+  return QualType(AT, 0);
   }

The original code is correct, `AutoTypes.FindNodeOrInsertPos(ID, InsertPos)` 
returning non-null should be impossible here, as we are just refreshing the 
insert position after having possibly invalidated it when we created the 
canonical node.

We had looked for the node before and didn't find it, so finding it just after 
having created the canonical node means this is a canonicalization bug.

I think this could have used an assert on the return value to better explain 
that is going on.

FWIW, someone else already started working on this bug some time ago, and I 
made some comments there which I think explain the problem better: See 
https://reviews.llvm.org/D126172

Might be worth a ping since might have stalled on it though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131866

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


[clang] 6d9cd91 - Use llvm::all_of (NFC)

2022-08-14 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-08-14T16:25:36-07:00
New Revision: 6d9cd9199a6fdeab0412117bcefc28f625510b61

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

LOG: Use llvm::all_of (NFC)

Added: 


Modified: 
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
clang-tools-extra/clangd/URI.cpp
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
lldb/source/Target/Platform.cpp
lldb/source/Utility/Event.cpp
lldb/tools/debugserver/source/RNBRemote.cpp
llvm/lib/Demangle/RustDemangle.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/tools/gold/gold-plugin.cpp
llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp
mlir/lib/Tools/lsp-server-support/Protocol.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 047273946ed54..6e6308d6c7a8d 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -168,7 +168,7 @@ void ClangDocCommentVisitor::visitVerbatimLineComment(
 }
 
 bool ClangDocCommentVisitor::isWhitespaceOnly(llvm::StringRef S) const {
-  return std::all_of(S.begin(), S.end(), isspace);
+  return llvm::all_of(S, isspace);
 }
 
 std::string ClangDocCommentVisitor::getCommandName(unsigned CommandID) const {

diff  --git a/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp 
b/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
index e5424c98a72ae..f8a4d6e95df0a 100644
--- a/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
@@ -38,14 +38,10 @@ static char ValidDatePatternChars[] = {
 // set of reserved characters. See:
 // https://www.unicode.org/reports/tr35/tr35.html#Invalid_Patterns
 bool isValidDatePattern(StringRef Pattern) {
-  for (auto &PatternChar : Pattern) {
-if (isalpha(PatternChar)) {
-  if (!llvm::is_contained(ValidDatePatternChars, PatternChar)) {
-return false;
-  }
-}
-  }
-  return true;
+  return llvm::all_of(Pattern, [](const auto &PatternChar) {
+return !isalpha(PatternChar) ||
+   llvm::is_contained(ValidDatePatternChars, PatternChar);
+  });
 }
 
 // Checks if the string pattern used as a date format specifier contains

diff  --git a/clang-tools-extra/clangd/URI.cpp 
b/clang-tools-extra/clangd/URI.cpp
index c94053cadd2ad..ca65df329aeeb 100644
--- a/clang-tools-extra/clangd/URI.cpp
+++ b/clang-tools-extra/clangd/URI.cpp
@@ -142,7 +142,7 @@ bool isValidScheme(llvm::StringRef Scheme) {
 return false;
   if (!llvm::isAlpha(Scheme[0]))
 return false;
-  return std::all_of(Scheme.begin() + 1, Scheme.end(), [](char C) {
+  return llvm::all_of(llvm::drop_begin(Scheme), [](char C) {
 return llvm::isAlnum(C) || C == '+' || C == '.' || C == '-';
   });
 }

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 61688688b0a73..7dc0fec46d421 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3486,8 +3486,8 @@ unsigned FunctionDecl::getMinRequiredArguments() const {
 bool FunctionDecl::hasOneParamOrDefaultArgs() const {
   return getNumParams() == 1 ||
  (getNumParams() > 1 &&
-  std::all_of(param_begin() + 1, param_end(),
-  [](ParmVarDecl *P) { return P->hasDefaultArg(); }));
+  llvm::all_of(llvm::drop_begin(parameters()),
+   [](ParmVarDecl *P) { return P->hasDefaultArg(); }));
 }
 
 /// The combination of the extern and inline keywords under MSVC forces

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 1d9ec1162bafb..c703d7670abee 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3788,9 +3788,8 @@ class DSAAttrChecker final : public 
StmtVisitor {
   // Variable is used if it has been marked as an array, array
   // section, array shaping or the variable iself.
   return StackComponents.size() == 1 ||
- std::all_of(
- std::next(StackComponents.rbegin()),
- StackComponents.rend(),
+ llvm::all_of(
+ llvm::drop_begin(llvm::reverse(StackComponents)),
  [](const OMPClauseMappableExprCommon::
 MappableComponent &MC) {
return MC.getAssociatedDeclaration() ==

d

[clang-tools-extra] 55f0a87 - [clangd] Use llvm::any_of (NFC)

2022-08-14 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-08-14T16:25:38-07:00
New Revision: 55f0a87ea46ee787dbef425200a718db775ef381

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

LOG: [clangd] Use llvm::any_of (NFC)

Added: 


Modified: 
clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp 
b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index 145d98d57ca83..b0ae42a96ecf4 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -777,12 +777,11 @@ void CanonicalIncludes::addSystemHeadersMapping(const 
LangOptions &Language) {
llvm::sys::path::end(Path)) <= MaxSuffixComponents;
   }));
   // ... and precise.
-  assert(llvm::find_if(SystemHeaderMap->keys(), [](llvm::StringRef Path) {
-   return std::distance(llvm::sys::path::begin(
-Path, llvm::sys::path::Style::posix),
-llvm::sys::path::end(Path)) ==
-  MaxSuffixComponents;
- }) != SystemHeaderMap->keys().end());
+  assert(llvm::any_of(SystemHeaderMap->keys(), [](llvm::StringRef Path) {
+return std::distance(
+   llvm::sys::path::begin(Path, llvm::sys::path::Style::posix),
+   llvm::sys::path::end(Path)) == MaxSuffixComponents;
+  }));
 
   // FIXME: Suffix mapping contains invalid entries for C, so only enable it 
for
   // CPP.



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


[clang] f5a68fe - Use llvm::none_of (NFC)

2022-08-14 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-08-14T16:25:39-07:00
New Revision: f5a68feab30a529280c2912dc464e3a81e276f9a

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

LOG: Use llvm::none_of (NFC)

Added: 


Modified: 
clang-tools-extra/clang-move/Move.cpp
clang-tools-extra/clangd/refactor/Rename.cpp
clang/lib/Frontend/TextDiagnostic.cpp
lld/wasm/SyntheticSections.cpp
llvm/include/llvm/Analysis/RegionInfoImpl.h
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
llvm/include/llvm/Support/GenericDomTreeConstruction.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-move/Move.cpp 
b/clang-tools-extra/clang-move/Move.cpp
index 6419bd3372dce..9e44fe12ecdce 100644
--- a/clang-tools-extra/clang-move/Move.cpp
+++ b/clang-tools-extra/clang-move/Move.cpp
@@ -920,8 +920,7 @@ void ClangMoveTool::onEndOfTranslationUnit() {
   return false;
 }
   };
-  if (std::none_of(UnremovedDeclsInOldHeader.begin(),
-   UnremovedDeclsInOldHeader.end(), IsSupportedKind) &&
+  if (llvm::none_of(UnremovedDeclsInOldHeader, IsSupportedKind) &&
   !Context->Spec.OldHeader.empty()) {
 auto &SM = RemovedDecls[0]->getASTContext().getSourceManager();
 moveAll(SM, Context->Spec.OldHeader, Context->Spec.NewHeader);

diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index 50b5481e4f89b..af454f0a372b5 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -757,12 +757,12 @@ llvm::Expected rename(const RenameInputs 
&RInputs) {
 return StartOffset.takeError();
   if (!EndOffset)
 return EndOffset.takeError();
-  if (llvm::find_if(
+  if (llvm::none_of(
   *MainFileRenameEdit,
   [&StartOffset, &EndOffset](const clang::tooling::Replacement &R) {
 return R.getOffset() == *StartOffset &&
R.getLength() == *EndOffset - *StartOffset;
-  }) == MainFileRenameEdit->end()) {
+  })) {
 return makeError(ReasonToReject::NoSymbolFound);
   }
   RenameResult Result;

diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index ab0dbcef65344..a0e11fa7a7c9a 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -332,8 +332,7 @@ static void selectInterestingSourceRegion(std::string 
&SourceLine,
 return;
 
   // No special characters are allowed in CaretLine.
-  assert(CaretLine.end() ==
- llvm::find_if(CaretLine, [](char c) { return c < ' ' || '~' < c; }));
+  assert(llvm::none_of(CaretLine, [](char c) { return c < ' ' || '~' < c; }));
 
   // Find the slice that we need to display the full caret line
   // correctly.

diff  --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index 1149e206b6b00..bce7c0b722781 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -844,8 +844,7 @@ void ProducersSection::addInfo(const WasmProducerInfo 
&info) {
{std::make_pair(&info.Languages, &languages),
 std::make_pair(&info.Tools, &tools), std::make_pair(&info.SDKs, 
&sDKs)})
 for (auto &producer : *producers.first)
-  if (producers.second->end() ==
-  llvm::find_if(*producers.second,
+  if (llvm::none_of(*producers.second,
 [&](std::pair seen) {
   return seen.first == producer.first;
 }))

diff  --git a/llvm/include/llvm/Analysis/RegionInfoImpl.h 
b/llvm/include/llvm/Analysis/RegionInfoImpl.h
index 561702db37904..9a18e72eebec7 100644
--- a/llvm/include/llvm/Analysis/RegionInfoImpl.h
+++ b/llvm/include/llvm/Analysis/RegionInfoImpl.h
@@ -390,10 +390,10 @@ void RegionBase::transferChildrenTo(RegionT *To) {
 template 
 void RegionBase::addSubRegion(RegionT *SubRegion, bool moveChildren) {
   assert(!SubRegion->parent && "SubRegion already has a parent!");
-  assert(llvm::find_if(*this,
+  assert(llvm::none_of(*this,
[&](const std::unique_ptr &R) {
  return R.get() == SubRegion;
-   }) == children.end() &&
+   }) &&
  "Subregion already exists!");
 
   SubRegion->parent = static_cast(this);

diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h 
b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
index 00c60d05573c3..60abdc5e20033 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -1004,10 +1004,10 @@ class LinkGraph {
 
   /// Create a section with the given name, prot

[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-08-14 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 452579.
ychen added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -959,7 +959,7 @@
   
   
 https://wg21.link/p2113r0";>P2113R0
-No
+Clang 16
   
 
 
Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -1,10 +1,17 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
-struct A;
-struct B;
-
 template  constexpr bool True = true;
 template  concept C = True;
+template  concept D = C && sizeof(T)>2;
+template  concept E = D && alignof(T)>1;
+
+struct A {};
+template  struct S {};
+template  struct X {};
+
+namespace p6 {
+
+struct B;
 
 void f(C auto &, auto &) = delete;
 template  void f(Q &, C auto &);
@@ -13,14 +20,57 @@
   f(*ap, *bp);
 }
 
-template  struct X {};
-
+#if 0
+// FIXME: [temp.func.order]p6.2.1 is not implemented, matching GCC.
 template  bool operator==(X, V) = delete;
 templatebool operator==(T, X);
 
 bool h() {
   return X{} == 0;
 }
+#endif
+
+template class U, typename... Z> void foo(T, U) = delete;
+template class U, typename... Z> void foo(T, U) = delete;
+template class U, typename... Z> void foo(T, U);
+
+void bar(S s) {
+  foo(0,s);
+}
+
+} // namespace p6
+
+namespace TestConversionFunction {
+struct Y {
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+};
+
+X f() {
+  return Y{}; // expected-error {{conversion from 'Y' to 'X' is ambiguous}}
+}
+}
+
+namespace ClassPartialSpecPartialOrdering {
+template struct Y { Y()=delete; }; // expected-note {{template is declared here}}
+template struct Y {}; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct B{ B()=delete; };
+template struct B { B()=delete; };
+template struct B {};
+
+template class U, typename... Z> struct Some { Some()=delete; };
+template class U, typename... Z> struct Some { Some()=delete; };
+template class U, typename... Z> struct Some {};
+
+void f() {
+  B b;
+  Some c;
+}
+
+template struct Z; // expected-note {{template is declared here}}
+template struct Z; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+}
 
 namespace PR53640 {
 
Index: clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,26 +98,31 @@
   static_assert(is_same_v()), void>); // expected-error {{call to 'bar' is ambiguous}}
 
   template
-  constexpr int goo(int a) requires AtLeast2 && true {
+  constexpr int goo(int a) requires AtLeast2 && true { // expected-note {{candidate function}}
 return 1;
   }
 
   template
-  constexpr int goo(const int b) requires AtLeast2 {
+  constexpr int goo(const int b) requires AtLeast2 { // expected-note {{candidate function}}
 return 2;
   }
 
-  // Only trailing requires clauses of redeclarations are compared for overload resolution.
+  // [temp.func.order] p5
+  //   Since, in a call context, such type deduction considers only parameters
+  //   for which there are explicit call arguments, some parameters are ignored
+  //   (namely, function parameter packs, parameters with default arguments, and
+  //   ellipsis parameters).
   template
-  constexpr int doo(int a, ...) requires AtLeast2 && true { // expected-note {{candidate function}}
+  constexpr int doo(int a, ...) requires AtLeast2 && true {
 return 1;
   }
 
   template
-  constexpr int doo(int b) requires AtLeast2 { // expected-note {{candidate function}}
+  constexpr int doo(int b) requires AtLeast2 {
 return 2;
   }
 
-  static_assert(goo(1) == 1);
-  static_assert(doo(2) == 1); // expected-error {{call to 'doo' is ambiguous}}
+  // By temp.func.order-6.2.2, this is ambiguous because parameter a and b have different types.
+

[PATCH] D131526: [OMPIRBuilder] Add support for safelen clause

2022-08-14 Thread Prabhdeep Soni via Phabricator via cfe-commits
psoni2628 added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:625
+  void applySimd(CanonicalLoopInfo *Loop, Value *IfCond, ConstantInt *Simdlen,
+ ConstantInt *Safelen);
 

shraiysh wrote:
> [nit] Please set the default value of Safelen to nullptr here.
Setting a default value for only `Safelen` but not `Simdlen` or `IfCond` is a 
bit inconsistent and could potentially cause confusion in the future. I think 
it would make more sense to set default values for all the clause values. Maybe 
we could this separately in a different patch?



Comment at: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp:3048
+// parameter. Therefore, use safelen only in the absence of simdlen.
+ConstantInt *VectorizeWidth = Simdlen == nullptr ? Safelen : Simdlen;
 addLoopMetadata(

Meinersbur wrote:
> `safelen` should not mean the same as `llvm.loop.vectorize.width`. `safelen` 
> could be unreasonably large to use as SIMD width or a non-power-of-2.
> 
> That being said, it's what `CGStmtOpenMP.cpp` does as well and I don't know 
> any better way.
IMO, this is more of a semantic analysis problem. For example, if it not legal 
to have a `safelen` that is a non-power-of-2, then Clang should not let this 
value proceed from semantic analysis. Maybe we could add a check in 
`clang/lib/Sema/SemaOpenMP.cpp`, and fix the problem for both OMPIRBuilder and 
the existing codegen support in `CGStmtOpenMP.cpp` in a different patch?


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

https://reviews.llvm.org/D131526

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


[PATCH] D131872: [Intrinsics] Add initial support for NonNull attribute

2022-08-14 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov created this revision.
alexander-shaposhnikov added reviewers: nikic, ChuanqiXu.
alexander-shaposhnikov created this object with visibility "All Users".
Herald added a subscriber: pengfei.
Herald added a project: All.
alexander-shaposhnikov requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added projects: clang, LLVM.

Add initial support for NonNull attribute.

Test plan:
1/ ninja check-all
2/ verify that for 
__thread int x;
int main() {

  int* y = &x;
  return *y;

}
(with this patch) clang -O -fsanitize=null -S -emit-llvm -o - 
doesn't emit a  null-pointer check


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131872

Files:
  clang/test/CodeGenCXX/threadlocal_address.cpp
  llvm/include/llvm/IR/Intrinsics.td
  llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
  llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
  llvm/test/CodeGen/X86/threadlocal_address.ll
  llvm/utils/TableGen/CodeGenIntrinsics.h
  llvm/utils/TableGen/CodeGenTarget.cpp
  llvm/utils/TableGen/IntrinsicEmitter.cpp

Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
===
--- llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -700,11 +700,15 @@
 unsigned numAttrs = 0;
 
 // The argument attributes are alreadys sorted by argument index.
+assert(is_sorted(Intrinsic.ArgumentAttributes) &&
+   "Argument attributes are not sorted");
+
 unsigned Ai = 0, Ae = Intrinsic.ArgumentAttributes.size();
 if (Ae) {
   while (Ai != Ae) {
 unsigned AttrIdx = Intrinsic.ArgumentAttributes[Ai].Index;
-
+if (AttrIdx == 0)
+  OS << "  // AttrParam0 corresponds to return value.\n";
 OS << "  const Attribute::AttrKind AttrParam" << AttrIdx << "[]= {";
 ListSeparator LS(",");
 
@@ -721,6 +725,9 @@
   case CodeGenIntrinsic::NoUndef:
 OS << LS << "Attribute::NoUndef";
 break;
+  case CodeGenIntrinsic::NonNull:
+OS << LS << "Attribute::NonNull";
+break;
   case CodeGenIntrinsic::Returned:
 OS << LS << "Attribute::Returned";
 break;
@@ -756,7 +763,8 @@
 OS << LSV << V;
   OS << "};\n";
 }
-
+// AttributeList::ReturnIndex = 0, AttrParam0 corresponds to return
+// value.
 OS << "  AS[" << numAttrs++ << "] = AttributeList::get(C, "
<< AttrIdx << ", AttrParam" << AttrIdx;
 if (!AllValuesAreZero)
Index: llvm/utils/TableGen/CodeGenTarget.cpp
===
--- llvm/utils/TableGen/CodeGenTarget.cpp
+++ llvm/utils/TableGen/CodeGenTarget.cpp
@@ -893,6 +893,9 @@
   } else if (R->isSubClassOf("NoUndef")) {
 unsigned ArgNo = R->getValueAsInt("ArgNo");
 ArgumentAttributes.emplace_back(ArgNo, NoUndef, 0);
+  } else if (R->isSubClassOf("NonNull")) {
+unsigned ArgNo = R->getValueAsInt("ArgNo");
+ArgumentAttributes.emplace_back(ArgNo, NonNull, 0);
   } else if (R->isSubClassOf("Returned")) {
 unsigned ArgNo = R->getValueAsInt("ArgNo");
 ArgumentAttributes.emplace_back(ArgNo, Returned, 0);
Index: llvm/utils/TableGen/CodeGenIntrinsics.h
===
--- llvm/utils/TableGen/CodeGenIntrinsics.h
+++ llvm/utils/TableGen/CodeGenIntrinsics.h
@@ -154,6 +154,7 @@
 NoCapture,
 NoAlias,
 NoUndef,
+NonNull,
 Returned,
 ReadOnly,
 WriteOnly,
Index: llvm/test/CodeGen/X86/threadlocal_address.ll
===
--- llvm/test/CodeGen/X86/threadlocal_address.ll
+++ llvm/test/CodeGen/X86/threadlocal_address.ll
@@ -37,5 +37,5 @@
   ret i32 %3
 }
 
-declare ptr @llvm.threadlocal.address(ptr) nounwind readnone willreturn
-declare ptr addrspace(1) @llvm.threadlocal.address.p1(ptr addrspace(1)) nounwind readnone willreturn
+declare nonnull ptr @llvm.threadlocal.address(ptr nonnull) nounwind readnone willreturn
+declare nonnull ptr addrspace(1) @llvm.threadlocal.address.p1(ptr addrspace(1) nonnull) nounwind readnone willreturn
Index: llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
===
--- llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
+++ llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
@@ -23,7 +23,7 @@
   }
 
   ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
-  declare ptr @llvm.threadlocal.address.p0(ptr) #0
+  declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
 
   attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 
Index: llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
===
--- llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir

[PATCH] D131872: [Intrinsics] Add initial support for NonNull attribute

2022-08-14 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 452590.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131872

Files:
  clang/test/CodeGenCXX/threadlocal_address.cpp
  llvm/include/llvm/IR/Intrinsics.td
  llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
  llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
  llvm/test/CodeGen/X86/threadlocal_address.ll
  llvm/utils/TableGen/CodeGenIntrinsics.h
  llvm/utils/TableGen/CodeGenTarget.cpp
  llvm/utils/TableGen/IntrinsicEmitter.cpp

Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
===
--- llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -700,11 +700,15 @@
 unsigned numAttrs = 0;
 
 // The argument attributes are alreadys sorted by argument index.
+assert(is_sorted(Intrinsic.ArgumentAttributes) &&
+   "Argument attributes are not sorted");
+
 unsigned Ai = 0, Ae = Intrinsic.ArgumentAttributes.size();
 if (Ae) {
   while (Ai != Ae) {
 unsigned AttrIdx = Intrinsic.ArgumentAttributes[Ai].Index;
-
+if (AttrIdx == 0)
+  OS << "  // AttrParam0 corresponds to return value.\n";
 OS << "  const Attribute::AttrKind AttrParam" << AttrIdx << "[]= {";
 ListSeparator LS(",");
 
@@ -721,6 +725,9 @@
   case CodeGenIntrinsic::NoUndef:
 OS << LS << "Attribute::NoUndef";
 break;
+  case CodeGenIntrinsic::NonNull:
+OS << LS << "Attribute::NonNull";
+break;
   case CodeGenIntrinsic::Returned:
 OS << LS << "Attribute::Returned";
 break;
@@ -756,7 +763,8 @@
 OS << LSV << V;
   OS << "};\n";
 }
-
+// AttributeList::ReturnIndex = 0, AttrParam0 corresponds to return
+// value.
 OS << "  AS[" << numAttrs++ << "] = AttributeList::get(C, "
<< AttrIdx << ", AttrParam" << AttrIdx;
 if (!AllValuesAreZero)
Index: llvm/utils/TableGen/CodeGenTarget.cpp
===
--- llvm/utils/TableGen/CodeGenTarget.cpp
+++ llvm/utils/TableGen/CodeGenTarget.cpp
@@ -893,6 +893,9 @@
   } else if (R->isSubClassOf("NoUndef")) {
 unsigned ArgNo = R->getValueAsInt("ArgNo");
 ArgumentAttributes.emplace_back(ArgNo, NoUndef, 0);
+  } else if (R->isSubClassOf("NonNull")) {
+unsigned ArgNo = R->getValueAsInt("ArgNo");
+ArgumentAttributes.emplace_back(ArgNo, NonNull, 0);
   } else if (R->isSubClassOf("Returned")) {
 unsigned ArgNo = R->getValueAsInt("ArgNo");
 ArgumentAttributes.emplace_back(ArgNo, Returned, 0);
Index: llvm/utils/TableGen/CodeGenIntrinsics.h
===
--- llvm/utils/TableGen/CodeGenIntrinsics.h
+++ llvm/utils/TableGen/CodeGenIntrinsics.h
@@ -154,6 +154,7 @@
 NoCapture,
 NoAlias,
 NoUndef,
+NonNull,
 Returned,
 ReadOnly,
 WriteOnly,
Index: llvm/test/CodeGen/X86/threadlocal_address.ll
===
--- llvm/test/CodeGen/X86/threadlocal_address.ll
+++ llvm/test/CodeGen/X86/threadlocal_address.ll
@@ -37,5 +37,5 @@
   ret i32 %3
 }
 
-declare ptr @llvm.threadlocal.address(ptr) nounwind readnone willreturn
-declare ptr addrspace(1) @llvm.threadlocal.address.p1(ptr addrspace(1)) nounwind readnone willreturn
+declare nonnull ptr @llvm.threadlocal.address(ptr nonnull) nounwind readnone willreturn
+declare nonnull ptr addrspace(1) @llvm.threadlocal.address.p1(ptr addrspace(1) nonnull) nounwind readnone willreturn
Index: llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
===
--- llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
+++ llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
@@ -23,7 +23,7 @@
   }
 
   ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
-  declare ptr @llvm.threadlocal.address.p0(ptr) #0
+  declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
 
   attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 
Index: llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
===
--- llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
+++ llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
@@ -33,7 +33,7 @@
   }
 
   ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
-  declare ptr @llvm.threadlocal.address.p0(ptr) #0
+  declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
 
   attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 
Index: llvm/include/llvm/IR/Intrinsics.td
===
--- llvm/include/ll

[PATCH] D131528: [Clang] Restrict non fixed enum to a value outside the range of the enumeration values warning to context requiring a constant expression

2022-08-14 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D131528#3719430 , @ayermolo wrote:

> Was this and previous change intended to capture this case?
>  const enum NumberType neg_one = (enum NumberType) ((enum NumberType) 0 - 
> (enum NumberType) 1);

That was not intended and I plan on fixing that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131528

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


[PATCH] D131528: [Clang] Restrict non fixed enum to a value outside the range of the enumeration values warning to context requiring a constant expression

2022-08-14 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D131528#3719561 , @mstorsjo wrote:

> In D131528#3719414 , @shafik wrote:
>
>> In D131528#3718405 , @mstorsjo 
>> wrote:
>>
>>> In D131528#3716876 , @shafik 
>>> wrote:
>>>
 In D131528#3715841 , @thakis 
 wrote:

> We're also still seeing the diag fire after this: 
> https://ci.chromium.org/p/chromium/builders/ci/ToTLinux
>
> (And we cleaned up our codebase back when it was still an error.)
>
> Our bots have been red since the change to turn this into a warning 
> landed.

 Apologies, my condition was not strict enough, I have put up D131704 
 
>>>
>>> Unfortunately, even after D131704  (with 
>>> both commits), I'm still hitting a couple cases that weren't an error 
>>> before this. With https://martin.st/temp/qt-jit-enum.cpp and 
>>> https://martin.st/temp/protobuf-wire-format.cpp, built with `clang -target 
>>> i686-w64-mingw32 -c qt-jit-enum.cpp -std=c++17 -Wno-user-defined-literals 
>>> -Wno-ignored-attributes` (and same for the other file, although 
>>> `-std=c++17` can be omitted for the protobuf source) I'm still hitting 
>>> errors for things that weren't even warned about before.
>>
>> Thank you for those examples, it is super helpful to receive this feedback 
>> especially with simple reproducers.
>>
>> This is expected, it is constant initialization and I verified that they can 
>> be turned into warning using `-Wno-error=enum-constexpr-conversion`
>
> Ok, but however, before D131307  which 
> allowed to downgrade the error to a warning, these two source examples didn't 
> produce any single warning or error (relating to the enums) at all - and 
> AFAIK the intent of D131307  was to lower 
> the impact of the enum-conversion error, not widen the scope of what it 
> covers - right?

Correct.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131528

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


[PATCH] D131874: [Clang] Tighten restrictions on enum out of range diagnostic to avoid constant initialization

2022-08-14 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik created this revision.
shafik added reviewers: erichkeane, aaron.ballman, thakis, mstorsjo.
Herald added a project: All.
shafik requested review of this revision.

The restrictions added in D131704  were not 
sufficient to avoid all non-constant expression contexts. In particular 
constant initialization cases.

We need to check `EvaluatingDecl` to detect if the variable we are initializing 
is `constexpr` or not.

At this point it looks like this is the remaining case affecting various 
projects with this diagnostic.


https://reviews.llvm.org/D131874

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp


Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2419,6 +2419,13 @@
 
 enum EMaxInt {emaxint1=-1, emaxint2=__INT_MAX__};
 
+enum NumberType {};
+
+E2 testDefaultArgForParam(E2 e2Param = (E2)-1) { // ok, not a constant 
expression context
+  E2 e2LocalInit = e2Param; // ok, not a constant expression context
+  return e2LocalInit;
+}
+
 void testValueInRangeOfEnumerationValues() {
   constexpr E1 x1 = static_cast(-8);
   constexpr E1 x2 = static_cast(8);
@@ -2454,6 +2461,8 @@
   constexpr EMaxInt x19 = static_cast(__INT_MAX__-1);
   constexpr EMaxInt x20 = static_cast((long)__INT_MAX__+1);
   // expected-error@-1 {{integer value 2147483648 is outside the valid range 
of values [-2147483648, 2147483647] for this enumeration type}}
+
+  const NumberType neg_one = (NumberType) ((NumberType) 0 - (NumberType) 1); 
// ok, not a constant expression context
 }
 
 enum SortOrder {
@@ -2470,3 +2479,8 @@
 return;
 }
 }
+
+GH50055::E2 GlobalInitNotCE1 = (GH50055::E2)-1; // ok, not a constant 
expression context
+GH50055::E2 GlobalInitNotCE2 = GH50055::testDefaultArgForParam(); // ok, not a 
constant expression context
+constexpr GH50055::E2 GlobalInitCE = (GH50055::E2)-1;
+// expected-error@-1 {{integer value -1 is outside the valid range of values 
[0, 7] for this enumeration type}}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13536,6 +13536,20 @@
 if (Info.Ctx.getLangOpts().CPlusPlus && Info.InConstantContext &&
 Info.EvalMode == EvalInfo::EM_ConstantExpression &&
 DestType->isEnumeralType()) {
+
+  bool NotConstexprVar = false;
+
+  // We know if we are here that we are in a context that we might require
+  // a constant expression or a context that requires a constant
+  // value. But if we are initializing a value we don't know if it is a
+  // constexpr variable or not. We can check the EvaluatingDecl to 
determine
+  // if it constexpr or not. If not then we don't want to emit a 
diagnostic.
+  if (auto ValD = Info.EvaluatingDecl.dyn_cast()) {
+const VarDecl *VD = dyn_cast_or_null(ValD);
+if (VD && !VD->isConstexpr())
+  NotConstexprVar = true;
+  }
+
   const EnumType *ET = dyn_cast(DestType.getCanonicalType());
   const EnumDecl *ED = ET->getDecl();
   // Check that the value is within the range of the enumeration values.
@@ -13557,12 +13571,14 @@
 
 if (ED->getNumNegativeBits() &&
 (Max.slt(Result.getInt().getSExtValue()) ||
- Min.sgt(Result.getInt().getSExtValue(
-  Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
-   
diag::warn_constexpr_unscoped_enum_out_of_range)
-  << llvm::toString(Result.getInt(),10) << Min.getSExtValue() << 
Max.getSExtValue();
+ Min.sgt(Result.getInt().getSExtValue())) &&
+!NotConstexprVar)
+  Info.Ctx.getDiagnostics().Report(
+  E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range)
+  << llvm::toString(Result.getInt(), 10) << Min.getSExtValue()
+  << Max.getSExtValue();
 else if (!ED->getNumNegativeBits() &&
- Max.ult(Result.getInt().getZExtValue()))
+ Max.ult(Result.getInt().getZExtValue()) && !NotConstexprVar)
   Info.Ctx.getDiagnostics().Report(E->getExprLoc(),

diag::warn_constexpr_unscoped_enum_out_of_range)
<< llvm::toString(Result.getInt(),10) << Min.getZExtValue() << 
Max.getZExtValue();


Index: clang/test/SemaCXX/constant-expression-cxx11.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2419,6 +2419,13 @@
 
 enum EMaxInt {emaxint1=-1, emaxint2=__INT_MAX__};
 
+enum NumberType {};
+
+E2 testDefaultArgForParam(E2 e2Param = (E2)-1) { // ok, not a constant expression context
+  E2 e2LocalInit =

[PATCH] D131345: [RISC-V][HWASAN] Enable HWASAN for RISC-V architecture

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

> It relies on a runtime check: during init runtime makes 
> PR_{SET,GET}_TAGGED_ADDR_CTRL calls and if they're not supported, it fails 
> with an error. So burden of checking if J extension is present is on Linux 
> kernel.

Sounds good to me :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131345

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