[clang] a48300a - [clang][OpenMP][DebugInfo] Debug support for TLS variables present in OpenMP consruct

2022-04-23 Thread Alok Kumar Sharma via cfe-commits

Author: Alok Kumar Sharma
Date: 2022-04-23T12:29:32+05:30
New Revision: a48300aee570f8eea4ec0b03e2d176aab648afb0

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

LOG: [clang][OpenMP][DebugInfo] Debug support for TLS variables present in 
OpenMP consruct

In case of OpenMP programs, thread local variables can be present in
any clause pertaining to OpenMP constructs, as we know that compiler
generates artificial functions and in some cases values are passed to
those artificial functions thru parameters. For an example, if thread
local variable is present in copyin clause (testcase attached with the
patch), parameter with same name is generated as parameter to artificial
function. When user inquires the thread Local variable, its debug info
is hidden by the parameter. User never gets the actual TLS variable
when inquires it, instead gets the artificial parameter.

Current patch suppresses the debug info for such artificial parameter to
enable correct debugging of TLS variables.

Reviewed By: aprantl

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

Added: 
clang/test/OpenMP/debug_threadprivate_copyin.c

Modified: 
clang/include/clang/AST/Decl.h
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f93008cdd322d..04101c3218d71 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1633,6 +1633,9 @@ class ImplicitParamDecl : public VarDecl {
 /// Parameter for captured context
 CapturedContext,
 
+/// Parameter for Thread private variable
+ThreadPrivateVar,
+
 /// Other implicit parameter
 Other,
   };

diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index e47450f2ba8fe..0f16c7f50a003 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2442,6 +2442,7 @@ namespace {
 /// for the specified parameter and set up LocalDeclMap.
 void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
unsigned ArgNo) {
+  bool NoDebugInfo = false;
   // FIXME: Why isn't ImplicitParamDecl a ParmVarDecl?
   assert((isa(D) || isa(D)) &&
  "Invalid argument to EmitParmDecl");
@@ -2461,6 +2462,10 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, 
ParamValue Arg,
   setBlockContextParameter(IPD, ArgNo, V);
   return;
 }
+// Suppressing debug info for ThreadPrivateVar parameters, else it hides
+// debug info of TLS variables.
+NoDebugInfo =
+(IPD->getParameterKind() == ImplicitParamDecl::ThreadPrivateVar);
   }
 
   Address DeclPtr = Address::invalid();
@@ -2591,7 +2596,8 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, 
ParamValue Arg,
 
   // Emit debug info for param declarations in non-thunk functions.
   if (CGDebugInfo *DI = getDebugInfo()) {
-if (CGM.getCodeGenOpts().hasReducedDebugInfo() && !CurFuncIsThunk) {
+if (CGM.getCodeGenOpts().hasReducedDebugInfo() && !CurFuncIsThunk &&
+!NoDebugInfo) {
   llvm::DILocalVariable *DILocalVar = DI->EmitDeclareOfArgVariable(
   &D, AllocaPtr.getPointer(), ArgNo, Builder);
   if (const auto *Var = dyn_cast_or_null(&D))

diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index a249ef9d58d97..7c0001594a33e 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -481,7 +481,11 @@ static llvm::Function *emitOutlinedFunctionPrologue(
 if (ArgType->isVariablyModifiedType())
   ArgType = getCanonicalParamType(Ctx, ArgType);
 VarDecl *Arg;
-if (DebugFunctionDecl && (CapVar || I->capturesThis())) {
+if (CapVar && (CapVar->getTLSKind() != clang::VarDecl::TLS_None)) {
+  Arg = ImplicitParamDecl::Create(Ctx, /*DC=*/nullptr, FD->getLocation(),
+  II, ArgType,
+  ImplicitParamDecl::ThreadPrivateVar);
+} else if (DebugFunctionDecl && (CapVar || I->capturesThis())) {
   Arg = ParmVarDecl::Create(
   Ctx, DebugFunctionDecl,
   CapVar ? CapVar->getBeginLoc() : FD->getBeginLoc(),

diff  --git a/clang/test/OpenMP/debug_threadprivate_copyin.c 
b/clang/test/OpenMP/debug_threadprivate_copyin.c
new file mode 100644
index 0..bb0b76d5242a4
--- /dev/null
+++ b/clang/test/OpenMP/debug_threadprivate_copyin.c
@@ -0,0 +1,59 @@
+// This testcase checks emission of debug info for threadprivate variables
+// present in any clause of OpenMP construct.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple 
x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics

[PATCH] D123787: [clang][OpenMP][DebugInfo] Debug support for TLS variables when present in OpenMP consructs

2022-04-23 Thread Alok Kumar Sharma via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa48300aee570: [clang][OpenMP][DebugInfo] Debug support for 
TLS variables present in OpenMP… (authored by alok).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123787

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_threadprivate_copyin.c

Index: clang/test/OpenMP/debug_threadprivate_copyin.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_threadprivate_copyin.c
@@ -0,0 +1,59 @@
+// This testcase checks emission of debug info for threadprivate variables
+// present in any clause of OpenMP construct.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal void @.omp_outlined._debug__(
+// CHECK: call void @llvm.dbg.declare(metadata ptr %.global_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata ptr %.bound_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata ptr %nt.addr
+// CHECK: store ptr %gbl_dynamic_int, ptr %gbl_dynamic_int.addr, align 8
+// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr %gbl_dynamic_int.addr
+// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr %gbl_static_int.addr
+
+extern int printf(const char *, ...);
+extern void omp_set_num_threads(int);
+extern int omp_get_num_threads(void);
+extern int omp_get_thread_num(void);
+
+int gbl_dynamic_int;
+__thread int gbl_static_int;
+
+#pragma omp threadprivate(gbl_dynamic_int)
+
+int main() {
+  int nt = 0;
+  int offset = 10;
+  gbl_dynamic_int = 55;
+  gbl_static_int = 77;
+
+  omp_set_num_threads(4);
+#pragma omp parallel copyin(gbl_dynamic_int, gbl_static_int)
+  {
+int data;
+int tid;
+nt = omp_get_num_threads();
+tid = omp_get_thread_num();
+data = gbl_dynamic_int + gbl_static_int;
+gbl_dynamic_int += 10;
+gbl_static_int += 20;
+#pragma omp barrier
+if (tid == 0)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 1)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 2)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 3)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+  }
+
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -481,7 +481,11 @@
 if (ArgType->isVariablyModifiedType())
   ArgType = getCanonicalParamType(Ctx, ArgType);
 VarDecl *Arg;
-if (DebugFunctionDecl && (CapVar || I->capturesThis())) {
+if (CapVar && (CapVar->getTLSKind() != clang::VarDecl::TLS_None)) {
+  Arg = ImplicitParamDecl::Create(Ctx, /*DC=*/nullptr, FD->getLocation(),
+  II, ArgType,
+  ImplicitParamDecl::ThreadPrivateVar);
+} else if (DebugFunctionDecl && (CapVar || I->capturesThis())) {
   Arg = ParmVarDecl::Create(
   Ctx, DebugFunctionDecl,
   CapVar ? CapVar->getBeginLoc() : FD->getBeginLoc(),
Index: clang/lib/CodeGen/CGDecl.cpp
===
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2442,6 +2442,7 @@
 /// for the specified parameter and set up LocalDeclMap.
 void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
unsigned ArgNo) {
+  bool NoDebugInfo = false;
   // FIXME: Why isn't ImplicitParamDecl a ParmVarDecl?
   assert((isa(D) || isa(D)) &&
  "Invalid argument to EmitParmDecl");
@@ -2461,6 +2462,10 @@
   setBlockContextParameter(IPD, ArgNo, V);
   return;
 }
+// Suppressing debug info for ThreadPrivateVar parameters, else it hides
+// debug info of TLS variables.
+NoDebugInfo =
+(IPD->getParameterKind() == ImplicitParamDecl::ThreadPrivateVar);
   }
 
   Address DeclPtr = Address::invalid();
@@ -2591,7 +2596,8 @@
 
   // Emit debug info for param declarations in non-thunk functions.
   if (CGDebugInfo *DI = getDebugInfo()) {
-if (CGM.getCodeGenOpts().hasReducedDebugInfo() && !CurFuncIsThunk) {

[PATCH] D124320: [clang-tidy] Add createChecks method that also checks for LangaugeOptions

2022-04-23 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added a reviewer: aaron.ballman.
Herald added subscribers: carlosgalvezp, usaxena95, kadircet, arphaman, 
xazax.hun.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This method won't add a check if it isn't supported in the Contexts current 
LanguageOptions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124320

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clangd/ParsedAST.cpp


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -413,10 +413,7 @@
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTContext->setSelfContainedDiags(true);
-CTChecks = CTFactories.createChecks(CTContext.getPointer());
-llvm::erase_if(CTChecks, [&](const auto &Check) {
-  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
-});
+CTChecks = CTFactories.createChecksForLanguage(CTContext.getPointer());
 Preprocessor *PP = &Clang->getPreprocessor();
 for (const auto &Check : CTChecks) {
   Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
Index: clang-tools-extra/clang-tidy/ClangTidyModule.h
===
--- clang-tools-extra/clang-tidy/ClangTidyModule.h
+++ clang-tools-extra/clang-tidy/ClangTidyModule.h
@@ -67,6 +67,10 @@
   std::vector>
   createChecks(ClangTidyContext *Context);
 
+  /// Create instances of checks that are enabled for the current Language.
+  std::vector>
+  createChecksForLanguage(ClangTidyContext *Context);
+
   typedef llvm::StringMap FactoryMap;
   FactoryMap::const_iterator begin() const { return Factories.begin(); }
   FactoryMap::const_iterator end() const { return Factories.end(); }
Index: clang-tools-extra/clang-tidy/ClangTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyModule.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyModule.cpp
@@ -31,6 +31,21 @@
   return Checks;
 }
 
+std::vector>
+ClangTidyCheckFactories::createChecksForLanguage(ClangTidyContext *Context) {
+  std::vector> Checks;
+  auto LO = Context->getLangOpts();
+  for (const auto &Factory : Factories) {
+if (!Context->isCheckEnabled(Factory.getKey()))
+  continue;
+std::unique_ptr Check =
+Factory.getValue()(Factory.getKey(), Context);
+if (Check->isLanguageVersionSupported(LO))
+  Checks.push_back(std::move(Check));
+  }
+  return Checks;
+}
+
 ClangTidyOptions ClangTidyModule::getModuleOptions() {
   return ClangTidyOptions();
 }
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -402,11 +402,7 @@
 Context.setCurrentBuildDirectory(WorkingDir.get());
 
   std::vector> Checks =
-  CheckFactories->createChecks(&Context);
-
-  llvm::erase_if(Checks, [&](std::unique_ptr &Check) {
-return !Check->isLanguageVersionSupported(Context.getLangOpts());
-  });
+  CheckFactories->createChecksForLanguage(&Context);
 
   ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
 


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -413,10 +413,7 @@
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTContext->setSelfContainedDiags(true);
-CTChecks = CTFactories.createChecks(CTContext.getPointer());
-llvm::erase_if(CTChecks, [&](const auto &Check) {
-  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
-});
+CTChecks = CTFactories.createChecksForLanguage(CTContext.getPointer());
 Preprocessor *PP = &Clang->getPreprocessor();
 for (const auto &Check : CTChecks) {
   Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
Index: clang-tools-extra/clang-tidy/ClangTidyModule.h
===
--- clang-tools-extra/clang-tidy/ClangTidyModule.h
+++ clang-tools-extra/clang-tidy/ClangTidyModule.h
@@ -67,6 +67,10 @@
   std::vector>
   createChecks(ClangTidyContext *Context);
 
+  /// Create instances of checks that are enabled for the current Language.
+  std::vector>
+  createChecksForLanguage(ClangTidyContext *Context);
+
   typedef llvm::StringMap FactoryMap;
   FactoryMap::const_iterator begin() const { return Factories.begin(); }
   FactoryMap::const_iterator end(

[PATCH] D124320: [clang-tidy] Add createChecks method that also checks for LangaugeOptions

2022-04-23 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 424694.
njames93 added a comment.

Remove unnecessary copy of LanguageOptions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124320

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.cpp
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang-tools-extra/clangd/ParsedAST.cpp


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -413,10 +413,7 @@
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTContext->setSelfContainedDiags(true);
-CTChecks = CTFactories.createChecks(CTContext.getPointer());
-llvm::erase_if(CTChecks, [&](const auto &Check) {
-  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
-});
+CTChecks = CTFactories.createChecksForLanguage(CTContext.getPointer());
 Preprocessor *PP = &Clang->getPreprocessor();
 for (const auto &Check : CTChecks) {
   Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
Index: clang-tools-extra/clang-tidy/ClangTidyModule.h
===
--- clang-tools-extra/clang-tidy/ClangTidyModule.h
+++ clang-tools-extra/clang-tidy/ClangTidyModule.h
@@ -67,6 +67,10 @@
   std::vector>
   createChecks(ClangTidyContext *Context);
 
+  /// Create instances of checks that are enabled for the current Language.
+  std::vector>
+  createChecksForLanguage(ClangTidyContext *Context);
+
   typedef llvm::StringMap FactoryMap;
   FactoryMap::const_iterator begin() const { return Factories.begin(); }
   FactoryMap::const_iterator end() const { return Factories.end(); }
Index: clang-tools-extra/clang-tidy/ClangTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyModule.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyModule.cpp
@@ -31,6 +31,21 @@
   return Checks;
 }
 
+std::vector>
+ClangTidyCheckFactories::createChecksForLanguage(ClangTidyContext *Context) {
+  std::vector> Checks;
+  const LangOptions &LO = Context->getLangOpts();
+  for (const auto &Factory : Factories) {
+if (!Context->isCheckEnabled(Factory.getKey()))
+  continue;
+std::unique_ptr Check =
+Factory.getValue()(Factory.getKey(), Context);
+if (Check->isLanguageVersionSupported(LO))
+  Checks.push_back(std::move(Check));
+  }
+  return Checks;
+}
+
 ClangTidyOptions ClangTidyModule::getModuleOptions() {
   return ClangTidyOptions();
 }
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -402,11 +402,7 @@
 Context.setCurrentBuildDirectory(WorkingDir.get());
 
   std::vector> Checks =
-  CheckFactories->createChecks(&Context);
-
-  llvm::erase_if(Checks, [&](std::unique_ptr &Check) {
-return !Check->isLanguageVersionSupported(Context.getLangOpts());
-  });
+  CheckFactories->createChecksForLanguage(&Context);
 
   ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
 


Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -413,10 +413,7 @@
 CTContext->setASTContext(&Clang->getASTContext());
 CTContext->setCurrentFile(Filename);
 CTContext->setSelfContainedDiags(true);
-CTChecks = CTFactories.createChecks(CTContext.getPointer());
-llvm::erase_if(CTChecks, [&](const auto &Check) {
-  return !Check->isLanguageVersionSupported(CTContext->getLangOpts());
-});
+CTChecks = CTFactories.createChecksForLanguage(CTContext.getPointer());
 Preprocessor *PP = &Clang->getPreprocessor();
 for (const auto &Check : CTChecks) {
   Check->registerPPCallbacks(Clang->getSourceManager(), PP, PP);
Index: clang-tools-extra/clang-tidy/ClangTidyModule.h
===
--- clang-tools-extra/clang-tidy/ClangTidyModule.h
+++ clang-tools-extra/clang-tidy/ClangTidyModule.h
@@ -67,6 +67,10 @@
   std::vector>
   createChecks(ClangTidyContext *Context);
 
+  /// Create instances of checks that are enabled for the current Language.
+  std::vector>
+  createChecksForLanguage(ClangTidyContext *Context);
+
   typedef llvm::StringMap FactoryMap;
   FactoryMap::const_iterator begin() const { return Factories.begin(); }
   FactoryMap::const_iterator end() const { return Factories.end(); }
Index: clang-tools-extra/clang-tidy/ClangTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyModule.c

[clang] 5996306 - [C++20][Modules][Driver][HU 3/N] Handle foo.h with -fmodule-header and/or C++ invocation.

2022-04-23 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-04-23T09:50:31+01:00
New Revision: 5996306c24badac0e04c1cead1aed4b106a3bdae

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

LOG: [C++20][Modules][Driver][HU 3/N] Handle foo.h with -fmodule-header and/or 
C++ invocation.

Allow an invocation like clang -fmodule-header bar.h (which will be a C++
compilation, but using a header which will be recognised as a C one).

Also  we do not want to produce:
 "treating 'c-header' input as 'c++-header' when in C++ mode"
diagnostics when the user has been specific about the intent.

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/cxx20-header-units-02.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0da079b1deb38..b453e24769571 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2437,7 +2437,9 @@ void Driver::BuildInputs(const ToolChain &TC, 
DerivedArgList &Args,
 types::ID OldTy = Ty;
 Ty = types::lookupCXXTypeForCType(Ty);
 
-if (Ty != OldTy)
+// Do not complain about foo.h, when we are known to be processing
+// it as a C++20 header unit.
+if (Ty != OldTy && !(OldTy == types::TY_CHeader && 
hasHeaderMode()))
   Diag(clang::diag::warn_drv_treating_input_as_cxx)
   << getTypeName(OldTy) << getTypeName(Ty);
   }
@@ -2462,8 +2464,11 @@ void Driver::BuildInputs(const ToolChain &TC, 
DerivedArgList &Args,
 }
 
 // Disambiguate headers that are meant to be header units from those
-// intended to be PCH.
-if (Ty == types::TY_CXXHeader && hasHeaderMode())
+// intended to be PCH.  Avoid missing '.h' cases that are counted as
+// C headers by default - we know we are in C++ mode and we do not
+// want to issue a complaint about compiling things in the wrong mode.
+if ((Ty == types::TY_CXXHeader || Ty == types::TY_CHeader) &&
+hasHeaderMode())
   Ty = CXXHeaderUnitType(CXX20HeaderType);
   } else {
 assert(InputTypeArg && "InputType set w/o InputTypeArg");

diff  --git a/clang/test/Driver/cxx20-header-units-02.cpp 
b/clang/test/Driver/cxx20-header-units-02.cpp
index aab999cda2276..7b7a40f9e831f 100644
--- a/clang/test/Driver/cxx20-header-units-02.cpp
+++ b/clang/test/Driver/cxx20-header-units-02.cpp
@@ -3,6 +3,9 @@
 // RUN: %clang -### -std=c++20 -fmodule-header=user foo.hh  2>&1 | \
 // RUN:   FileCheck -check-prefix=CHECK-USER %s
 
+// RUN: %clang -### -std=c++20 -fmodule-header=user foo.h  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-USER1 %s
+
 // RUN: %clang -### -std=c++20 -fmodule-header=system foo.hh 2>&1 | \
 // RUN:   FileCheck -check-prefix=CHECK-SYS1 %s
 
@@ -19,6 +22,10 @@
 // CHECK-USER-SAME: "-o" "foo.pcm"
 // CHECK-USER-SAME: "-x" "c++-user-header" "foo.hh"
 
+// CHECK-USER1: "-emit-header-unit"
+// CHECK-USER1-SAME: "-o" "foo.pcm"
+// CHECK-USER1-SAME: "-x" "c++-user-header" "foo.h"
+
 // CHECK-SYS1: "-emit-header-unit"
 // CHECK-SYS1-SAME: "-o" "foo.pcm"
 // CHECK-SYS1-SAME: "-x" "c++-system-header" "foo.hh"



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


[PATCH] D121590: [C++20][Modules][Driver][HU 3/N] Handle foo.h with -fmodule-header and/or C++ invocation.

2022-04-23 Thread Iain Sandoe 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 rG5996306c24ba: [C++20][Modules][Driver][HU 3/N] Handle foo.h 
with -fmodule-header and/or C++… (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121590

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cxx20-header-units-02.cpp


Index: clang/test/Driver/cxx20-header-units-02.cpp
===
--- clang/test/Driver/cxx20-header-units-02.cpp
+++ clang/test/Driver/cxx20-header-units-02.cpp
@@ -3,6 +3,9 @@
 // RUN: %clang -### -std=c++20 -fmodule-header=user foo.hh  2>&1 | \
 // RUN:   FileCheck -check-prefix=CHECK-USER %s
 
+// RUN: %clang -### -std=c++20 -fmodule-header=user foo.h  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-USER1 %s
+
 // RUN: %clang -### -std=c++20 -fmodule-header=system foo.hh 2>&1 | \
 // RUN:   FileCheck -check-prefix=CHECK-SYS1 %s
 
@@ -19,6 +22,10 @@
 // CHECK-USER-SAME: "-o" "foo.pcm"
 // CHECK-USER-SAME: "-x" "c++-user-header" "foo.hh"
 
+// CHECK-USER1: "-emit-header-unit"
+// CHECK-USER1-SAME: "-o" "foo.pcm"
+// CHECK-USER1-SAME: "-x" "c++-user-header" "foo.h"
+
 // CHECK-SYS1: "-emit-header-unit"
 // CHECK-SYS1-SAME: "-o" "foo.pcm"
 // CHECK-SYS1-SAME: "-x" "c++-system-header" "foo.hh"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2437,7 +2437,9 @@
 types::ID OldTy = Ty;
 Ty = types::lookupCXXTypeForCType(Ty);
 
-if (Ty != OldTy)
+// Do not complain about foo.h, when we are known to be processing
+// it as a C++20 header unit.
+if (Ty != OldTy && !(OldTy == types::TY_CHeader && 
hasHeaderMode()))
   Diag(clang::diag::warn_drv_treating_input_as_cxx)
   << getTypeName(OldTy) << getTypeName(Ty);
   }
@@ -2462,8 +2464,11 @@
 }
 
 // Disambiguate headers that are meant to be header units from those
-// intended to be PCH.
-if (Ty == types::TY_CXXHeader && hasHeaderMode())
+// intended to be PCH.  Avoid missing '.h' cases that are counted as
+// C headers by default - we know we are in C++ mode and we do not
+// want to issue a complaint about compiling things in the wrong mode.
+if ((Ty == types::TY_CXXHeader || Ty == types::TY_CHeader) &&
+hasHeaderMode())
   Ty = CXXHeaderUnitType(CXX20HeaderType);
   } else {
 assert(InputTypeArg && "InputType set w/o InputTypeArg");


Index: clang/test/Driver/cxx20-header-units-02.cpp
===
--- clang/test/Driver/cxx20-header-units-02.cpp
+++ clang/test/Driver/cxx20-header-units-02.cpp
@@ -3,6 +3,9 @@
 // RUN: %clang -### -std=c++20 -fmodule-header=user foo.hh  2>&1 | \
 // RUN:   FileCheck -check-prefix=CHECK-USER %s
 
+// RUN: %clang -### -std=c++20 -fmodule-header=user foo.h  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-USER1 %s
+
 // RUN: %clang -### -std=c++20 -fmodule-header=system foo.hh 2>&1 | \
 // RUN:   FileCheck -check-prefix=CHECK-SYS1 %s
 
@@ -19,6 +22,10 @@
 // CHECK-USER-SAME: "-o" "foo.pcm"
 // CHECK-USER-SAME: "-x" "c++-user-header" "foo.hh"
 
+// CHECK-USER1: "-emit-header-unit"
+// CHECK-USER1-SAME: "-o" "foo.pcm"
+// CHECK-USER1-SAME: "-x" "c++-user-header" "foo.h"
+
 // CHECK-SYS1: "-emit-header-unit"
 // CHECK-SYS1-SAME: "-o" "foo.pcm"
 // CHECK-SYS1-SAME: "-x" "c++-system-header" "foo.hh"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2437,7 +2437,9 @@
 types::ID OldTy = Ty;
 Ty = types::lookupCXXTypeForCType(Ty);
 
-if (Ty != OldTy)
+// Do not complain about foo.h, when we are known to be processing
+// it as a C++20 header unit.
+if (Ty != OldTy && !(OldTy == types::TY_CHeader && hasHeaderMode()))
   Diag(clang::diag::warn_drv_treating_input_as_cxx)
   << getTypeName(OldTy) << getTypeName(Ty);
   }
@@ -2462,8 +2464,11 @@
 }
 
 // Disambiguate headers that are meant to be header units from those
-// intended to be PCH.
-if (Ty == types::TY_CXXHeader && hasHeaderMode())
+// intended to be PCH.  Avoid missing '.h' cases that are counted as
+// C headers by default - we know we are in C++ mode and we do not
+// want to issue a complaint about compiling things in the wrong mode.
+if ((Ty == types::TY_CXXHeader || Ty == types::TY_CHeader) &&
+hasHeaderMode())
   Ty = CXXHeaderUnitType(CXX20HeaderType);
   } else

[PATCH] D115103: Leak Sanitizer port to Windows

2022-04-23 Thread Clemens Wasser via Phabricator via cfe-commits
clemenswasser updated this revision to Diff 424702.
clemenswasser added a comment.

I have now split the lsan TestCases chages into https://reviews.llvm.org/D124322
and managed to get the lsan+asan TestCases nearly to work. The current problem 
is,
that during the start of the `RunThread` in `StopTheWorld`, we are intercepting 
a call
to `calloc` done by the ucrt in `ucrtbase!DllMainDispatch`, which somehow 
results in a deadlock.
If someone has an idea, how we could avoid/fix this, I would be very happy to 
hear it.


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

https://reviews.llvm.org/D115103

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  compiler-rt/lib/lsan/CMakeLists.txt
  compiler-rt/lib/lsan/lsan.h
  compiler-rt/lib/lsan/lsan_allocator.h
  compiler-rt/lib/lsan/lsan_common.cpp
  compiler-rt/lib/lsan/lsan_common.h
  compiler-rt/lib/lsan/lsan_common_win.cpp
  compiler-rt/lib/lsan/lsan_interceptors.cpp
  compiler-rt/lib/lsan/lsan_win.cpp
  compiler-rt/lib/lsan/lsan_win.h
  compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
  compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_win.cpp
  compiler-rt/test/lsan/lit.common.cfg.py

Index: compiler-rt/test/lsan/lit.common.cfg.py
===
--- compiler-rt/test/lsan/lit.common.cfg.py
+++ compiler-rt/test/lsan/lit.common.cfg.py
@@ -74,12 +74,13 @@
 config.substitutions.append( ("%clangxx_lsan ", build_invocation(clang_lsan_cxxflags)) )
 
 # LeakSanitizer tests are currently supported on
-# Android{aarch64, x86, x86_64}, x86-64 Linux, PowerPC64 Linux, arm Linux, mips64 Linux, s390x Linux and x86_64 Darwin.
+# Windows{x86_64, x86, aarch64, arm}, Android{aarch64, x86, x86_64}, x86-64 Linux, PowerPC64 Linux, arm Linux, mips64 Linux, s390x Linux and x86_64 Darwin.
 supported_android = config.android and config.target_arch in ['x86_64', 'i386', 'aarch64'] and 'android-thread-properties-api' in config.available_features
 supported_linux = (not config.android) and config.host_os == 'Linux' and config.host_arch in ['aarch64', 'x86_64', 'ppc64', 'ppc64le', 'mips64', 'riscv64', 'arm', 'armhf', 'armv7l', 's390x']
 supported_darwin = config.host_os == 'Darwin' and config.target_arch in ['x86_64']
 supported_netbsd = config.host_os == 'NetBSD' and config.target_arch in ['x86_64', 'i386']
-if not (supported_android or supported_linux or supported_darwin or supported_netbsd):
+supported_windows = config.host_os == 'Windows' and config.target_arch in ['x86_64', 'i386', 'aarch64', 'arm']
+if not (supported_android or supported_linux or supported_darwin or supported_netbsd or supported_windows):
   config.unsupported = True
 
 # Don't support Thumb due to broken fast unwinder
Index: compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_win.cpp
===
--- compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_win.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_win.cpp
@@ -19,8 +19,13 @@
 // windows.h needs to be included before tlhelp32.h
 #  include 
 
+#  include "interception/interception.h"
 #  include "sanitizer_stoptheworld.h"
 
+DECLARE_REAL(HANDLE, CreateThread, LPSECURITY_ATTRIBUTES lpThreadAttributes,
+ SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
+ LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
+
 namespace __sanitizer {
 
 namespace {
@@ -163,7 +168,7 @@
   DWORD trace_thread_id;
 
   auto trace_thread =
-  CreateThread(nullptr, 0, RunThread, &arg, 0, &trace_thread_id);
+  REAL(CreateThread)(nullptr, 0, RunThread, &arg, 0, &trace_thread_id);
   CHECK(trace_thread);
 
   WaitForSingleObject(trace_thread, INFINITE);
Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
===
--- compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -485,13 +485,15 @@
 #define SANITIZER_INTERCEPT_MMAP SI_POSIX
 #define SANITIZER_INTERCEPT_MMAP64 SI_LINUX_NOT_ANDROID || SI_SOLARIS
 #define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (SI_GLIBC || SI_ANDROID)
-#define SANITIZER_INTERCEPT_MEMALIGN (!SI_FREEBSD && !SI_MAC && !SI_NETBSD)
+#define SANITIZER_INTERCEPT_MEMALIGN \
+  (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_WINDOWS)
 #define SANITIZER_INTERCEPT___LIBC_MEMALIGN SI_GLIBC
 #define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID)
 #define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64)
 #define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX
 #define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
-#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD)
+#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE \
+  (!SI_MAC && !SI_NETBSD && !SI_WINDOWS)
 #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_WCSCAT SI_POSIX
 #define 

[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-23 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 424711.
vabridgers added a comment.

Update test cases, address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/cast-value-notes.cpp

Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -1,10 +1,30 @@
-// RUN: %clang_analyze_cc1 -std=c++14 \
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
 // RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
-// RUN:  -analyzer-output=text -verify -DDEFAULT_TRIPLE %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-CHECK
+// RUN:  -analyzer-output=text -verify -DX86 -DSUPPRESSED %s 2>&1 | FileCheck %s --check-prefix=X86-CHECK
 //
-// RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -analyzer-config core.NullDereference:SuppressAddressSpaces=true\
+// RUN:  -analyzer-output=text -verify -DX86 -DSUPPRESSED %s 2>&1 | FileCheck %s --check-prefix=X86-CHECK-SUPPRESSED
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -analyzer-config core.NullDereference:SuppressAddressSpaces=false\
+// RUN:  -analyzer-output=text -verify -DX86 -DNOT_SUPPRESSED %s 2>&1 | FileCheck %s --check-prefix=X86-CHECK
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-output=text -verify -DMIPS %s 2>&1
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false\
+// RUN: -analyzer-output=text -verify -DMIPS %s 2>&1
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
 // RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
-// RUN: -analyzer-output=text -verify -DAMDGCN_TRIPLE %s 2>&1 | FileCheck %s -check-prefix=AMDGCN-CHECK
+// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=true\
+// RUN: -analyzer-output=text -verify -DMIPS_SUPPRESSED %s
 
 #include "Inputs/llvm.h"
 
@@ -36,27 +56,51 @@
 
 void clang_analyzer_printState();
 
-#if defined(DEFAULT_TRIPLE)
+#if defined(X86)
 void evalReferences(const Shape &S) {
   const auto &C = dyn_cast(S);
   // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
   clang_analyzer_printState();
-  // DEFAULT-CHECK: "dynamic_types": [
-  // DEFAULT-CHECK-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const class clang::Circle &", "sub_classable": true }
+  // XX86-CHECK:  "dynamic_types": [
+  // XX86-CHECK-NEXT:   { "region": "SymRegion{reg_$0}", "dyn_type": "const class clang::Circle &", "sub_classable": true }
   (void)C;
 }
-#elif defined(AMDGCN_TRIPLE)
-void evalReferences(const Shape &S) {
+#if defined(SUPPRESSED)
+void evalReferences_addrspace(const Shape &S) {
+  const auto &C = dyn_cast(S);
+  clang_analyzer_printState();
+  // X86-CHECK-SUPPRESSED: "dynamic_types": [
+  // X86-CHECK-SUPPRESSED-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const __attribute__((address_space(3))) class clang::Circle &", "sub_classable": true }
+  (void)C;
+}
+#endif
+#if defined(NOT_SUPPRESSED)
+void evalReferences_addrspace(const Shape &S) {
   const auto &C = dyn_cast(S);
+  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-2 {{Dereference of null pointer}}
+  // expected-warning@-3 {{Dereference of null pointer}}
   clang_analyzer_printState();
-  // AMDGCN-CHECK: "dynamic_types": [
-  // AMDGCN-CHECK-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const __attribute__((address_space(3))) class clang::Circle &", "sub_classable": true }
+  // X86-CHECK: "dynamic_types": [
+  // X86-CHECK-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const __attribute__((address_space(3))) class clang::Circle &", "sub_classable": true }
+  (void)C;
+}
+#endif
+#elif defined(MIPS)
+void evalReferences(const Shape &S) {
+  const auto &C = dyn_cast(S);
+  // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
+  // expected-note@-2 {{Dereference of null pointer}}
+  // expected-warning@-3 {{Dereference of null pointer}}
+}
+#if defined(

[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-23 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked an inline comment as done.
vabridgers added a comment.

I believe all comments have been addressed. After discussion with @steakhal, 
we're leaning towards removing the DefaultBool class and refactoring in favor 
of the language native bool type - mainly because DefaultBool doesn't add 
anything. Minimal yet effective is usually better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

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


[PATCH] D122920: [Clang][CodeGen]Fix __builtin_dump_struct missing record type field name

2022-04-23 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2046-2048
 static llvm::Value *dumpRecord(CodeGenFunction &CGF, QualType RType,
LValue RecordLV, CharUnits Align,
+   bool dumpTypeName, llvm::FunctionCallee Func,

rsmith wrote:
> Instead of passing a flag that suppresses the first section of this function, 
> it would be clearer to split this up into two parts:
> 
> 1) A function that dumps a type name (`struct A` or `int` or whatever).
> 2) A function that dumps a struct value (`{x = 1, y = 2}`).
> 
> Then when printing the overall value, you can call (1) then (2), and when 
> printing each field, you can call (1), then print the field name, then call 
> (2) for a struct value (and do whatever else makes sense for other kinds of 
> values).
> Instead of passing a flag that suppresses the first section of this function, 
> it would be clearer to split this up into two parts:
> 
> 1) A function that dumps a type name (`struct A` or `int` or whatever).
> 2) A function that dumps a struct value (`{x = 1, y = 2}`).
> 
> Then when printing the overall value, you can call (1) then (2), and when 
> printing each field, you can call (1), then print the field name, then call 
> (2) for a struct value (and do whatever else makes sense for other kinds of 
> values).

Thanks for your review! I agree with your suggestion, and i try to improve code.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2071
   if (Types.empty()) {
 Types[Context.CharTy] = "%c";
 Types[Context.BoolTy] = "%d";

I have an idea, can we use  analyze_printf::PrintfSpecifier::fixType instead of 
this static DenseMap to find the printf format specifier? what do you all think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122920

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


[PATCH] D124258: [C89/C2x] Change the behavior of implicit int diagnostics

2022-04-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Precommit CI failures are down to just clang-format related ones. However, as 
with the implicit function declaration diagnostic, I expect there to be a long 
tail of failing tests which aren't caught by me locally or by the precommit CI 
bots. My plan is to track the bots closely whenever I do land this and fix up 
breakage as it's noticed. Hopefully it won't be too disruptive, but changing 
diagnostic behavior for ancient extensions like this turns out to be almost 
impossible to get a fully clean commit from in one go. (If someone wants to run 
this patch through their own configuration and report back failures before I 
land, I'm happy to make those fixes now.)




Comment at: clang/docs/ReleaseNotes.rst:168-169
+  ``-Wno-error=implicit-int``, or disabled entirely with ``-Wno-implicit-int``.
+  As of C2x, support for implicit int has been removed, and the warning options
+  will have no effect. Specifying ``-Wimplicit-int`` in C89 mode will now issue
+  warnings instead of being a noop.

rsmith wrote:
> aaron.ballman wrote:
> > rsmith wrote:
> > > Is there some fundamental reason why implicit int is harder to support in 
> > > C2x (as there was for implicit function declarations, because 
> > > unprototyped functions are gone), or are we merely taking the opportunity 
> > > to do this because C2x is new? I find the former more easily defensible 
> > > than the latter, but I suppose the fact that we removed implicit function 
> > > declarations means that C2x is the first really properly breaking change 
> > > that C has had, so maybe now is the time regardless.
> > Purely the latter -- C2x didn't make anything harder here. However, I'd 
> > like to position C23 as "not your grandfather's C" in Clang by 
> > strengthening diagnostics, especially ones related to safety or security 
> > vulnerabilities. Basically, I think it's time to cut ties with as many 
> > dangerous things that have been excised from C as possible. I think 
> > implicit int fits that goal in the same way that implicit function decls do 
> > (namely, the implicit choice can be wrong and you get surprising silent 
> > breakage at runtime if you're lucky).
> > 
> > (FWIW, I'm also hoping to get these sort of changes lumped into Clang 15 so 
> > that the pain of upgrading is more localized to just one release rather 
> > than strung out over several.)
> OK. I wonder our stricter interpretation of the rules in C23 onwards is 
> something we should be calling out in our documentation as policy?
I'd be okay if we did that -- though, to be honest, we might want to review 
more of our developer policies regarding standards conformance in general, not 
just features removed from the language but kept as an extension. For example, 
I've been pretty sad about our inattention to documenting 
implementation-defined behaviors in Clang. "The source is our documentation" is 
cute for a while, but it does our users a disservice just the same, so it'd be 
nice to start setting policy that new implementation-defined stuff needs to be 
explicitly documented properly. I'm guessing we may find other such policy 
tweaks we'd like to make.


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

https://reviews.llvm.org/D124258

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


[clang] 9dc9b21 - [C++20][Modules][Driver][HU 4/N] Add fdirectives-only mode for preprocessing output.

2022-04-23 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-04-23T14:43:07+01:00
New Revision: 9dc9b21488ee2bbf54e20807585a74a17a33fceb

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

LOG: [C++20][Modules][Driver][HU 4/N] Add fdirectives-only mode for 
preprocessing output.

When the -fdirectives-only option is used together with -E, the preprocessor
output reflects evaluation of if/then/else directives.

Thus it preserves macros that are still live after such processing.
This output can be consumed by a second compilation to produce a header unit.

We automatically invoke this (with -E) when we know that the job produces a
header unit so that the preprocessed output reflects the macros that will be
defined when the binary HU is emitted.

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

Added: 
clang/test/Driver/cxx20-fdirectives-only.cpp

Modified: 
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index b453e24769571..2bb6680cf5961 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4303,10 +4303,14 @@ Action *Driver::ConstructPhaseAction(
   OutputTy = types::TY_Dependencies;
 } else {
   OutputTy = Input->getType();
+  // For these cases, the preprocessor is only translating forms, the 
Output
+  // still needs preprocessing.
   if (!Args.hasFlag(options::OPT_frewrite_includes,
 options::OPT_fno_rewrite_includes, false) &&
   !Args.hasFlag(options::OPT_frewrite_imports,
 options::OPT_fno_rewrite_imports, false) &&
+  !Args.hasFlag(options::OPT_fdirectives_only,
+options::OPT_fno_directives_only, false) &&
   !CCGenDiagnostics)
 OutputTy = types::getPreprocessedType(OutputTy);
   assert(OutputTy != types::TY_INVALID &&

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index ddc9559f0d950..0fd639da45ddf 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4594,6 +4594,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (Args.hasArg(options::OPT_rewrite_objc) &&
   !Args.hasArg(options::OPT_g_Group))
 CmdArgs.push_back("-P");
+  else if (JA.getType() == types::TY_PP_CXXHeaderUnit)
+CmdArgs.push_back("-fdirectives-only");
 }
   } else if (isa(JA)) {
 CmdArgs.push_back("-emit-obj");
@@ -6707,6 +6709,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (RewriteImports)
 CmdArgs.push_back("-frewrite-imports");
 
+  if (Args.hasFlag(options::OPT_fdirectives_only,
+   options::OPT_fno_directives_only, false))
+CmdArgs.push_back("-fdirectives-only");
+
   // Enable rewrite includes if the user's asked for it or if we're generating
   // diagnostics.
   // TODO: Once -module-dependency-dir works with -frewrite-includes it'd be

diff  --git a/clang/test/Driver/cxx20-fdirectives-only.cpp 
b/clang/test/Driver/cxx20-fdirectives-only.cpp
new file mode 100644
index 0..96dc4fdaa07ac
--- /dev/null
+++ b/clang/test/Driver/cxx20-fdirectives-only.cpp
@@ -0,0 +1,20 @@
+// Test -fdirectives-only cases.
+
+// We can manullay specify fdirectives-only, for any pre-processor job.
+// RUN: %clang -### -std=c++20 -E -fdirectives-only foo.hh  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-NON-HU %s
+
+// Check that we automatically append -fdirectives-only for header-unit
+// preprocessor jobs.
+// RUN: %clang -### -std=c++20 -E -fmodule-header=user foo.hh  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-HU %s
+
+// CHECK-NON-HU: "-E"
+// CHECK-NON-HU-SAME: "-fdirectives-only"
+// CHECK-NON-HU-SAME: "-o" "-"
+// CHECK-NON-HU-SAME: "-x" "c++-header" "foo.hh"
+
+// CHECK-HU: "-E"
+// CHECK-HU-SAME: "-fdirectives-only"
+// CHECK-HU-SAME: "-o" "-"
+// CHECK-HU-SAME: "-x" "c++-user-header" "foo.hh"



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


[PATCH] D121591: [C++20][Modules][Driver][HU 4/N] Add fdirectives-only mode for preprocessing output.

2022-04-23 Thread Iain Sandoe 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 rG9dc9b21488ee: [C++20][Modules][Driver][HU 4/N] Add 
fdirectives-only mode for preprocessing… (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121591

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cxx20-fdirectives-only.cpp


Index: clang/test/Driver/cxx20-fdirectives-only.cpp
===
--- /dev/null
+++ clang/test/Driver/cxx20-fdirectives-only.cpp
@@ -0,0 +1,20 @@
+// Test -fdirectives-only cases.
+
+// We can manullay specify fdirectives-only, for any pre-processor job.
+// RUN: %clang -### -std=c++20 -E -fdirectives-only foo.hh  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-NON-HU %s
+
+// Check that we automatically append -fdirectives-only for header-unit
+// preprocessor jobs.
+// RUN: %clang -### -std=c++20 -E -fmodule-header=user foo.hh  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-HU %s
+
+// CHECK-NON-HU: "-E"
+// CHECK-NON-HU-SAME: "-fdirectives-only"
+// CHECK-NON-HU-SAME: "-o" "-"
+// CHECK-NON-HU-SAME: "-x" "c++-header" "foo.hh"
+
+// CHECK-HU: "-E"
+// CHECK-HU-SAME: "-fdirectives-only"
+// CHECK-HU-SAME: "-o" "-"
+// CHECK-HU-SAME: "-x" "c++-user-header" "foo.hh"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4594,6 +4594,8 @@
   if (Args.hasArg(options::OPT_rewrite_objc) &&
   !Args.hasArg(options::OPT_g_Group))
 CmdArgs.push_back("-P");
+  else if (JA.getType() == types::TY_PP_CXXHeaderUnit)
+CmdArgs.push_back("-fdirectives-only");
 }
   } else if (isa(JA)) {
 CmdArgs.push_back("-emit-obj");
@@ -6707,6 +6709,10 @@
   if (RewriteImports)
 CmdArgs.push_back("-frewrite-imports");
 
+  if (Args.hasFlag(options::OPT_fdirectives_only,
+   options::OPT_fno_directives_only, false))
+CmdArgs.push_back("-fdirectives-only");
+
   // Enable rewrite includes if the user's asked for it or if we're generating
   // diagnostics.
   // TODO: Once -module-dependency-dir works with -frewrite-includes it'd be
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4303,10 +4303,14 @@
   OutputTy = types::TY_Dependencies;
 } else {
   OutputTy = Input->getType();
+  // For these cases, the preprocessor is only translating forms, the 
Output
+  // still needs preprocessing.
   if (!Args.hasFlag(options::OPT_frewrite_includes,
 options::OPT_fno_rewrite_includes, false) &&
   !Args.hasFlag(options::OPT_frewrite_imports,
 options::OPT_fno_rewrite_imports, false) &&
+  !Args.hasFlag(options::OPT_fdirectives_only,
+options::OPT_fno_directives_only, false) &&
   !CCGenDiagnostics)
 OutputTy = types::getPreprocessedType(OutputTy);
   assert(OutputTy != types::TY_INVALID &&


Index: clang/test/Driver/cxx20-fdirectives-only.cpp
===
--- /dev/null
+++ clang/test/Driver/cxx20-fdirectives-only.cpp
@@ -0,0 +1,20 @@
+// Test -fdirectives-only cases.
+
+// We can manullay specify fdirectives-only, for any pre-processor job.
+// RUN: %clang -### -std=c++20 -E -fdirectives-only foo.hh  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-NON-HU %s
+
+// Check that we automatically append -fdirectives-only for header-unit
+// preprocessor jobs.
+// RUN: %clang -### -std=c++20 -E -fmodule-header=user foo.hh  2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-HU %s
+
+// CHECK-NON-HU: "-E"
+// CHECK-NON-HU-SAME: "-fdirectives-only"
+// CHECK-NON-HU-SAME: "-o" "-"
+// CHECK-NON-HU-SAME: "-x" "c++-header" "foo.hh"
+
+// CHECK-HU: "-E"
+// CHECK-HU-SAME: "-fdirectives-only"
+// CHECK-HU-SAME: "-o" "-"
+// CHECK-HU-SAME: "-x" "c++-user-header" "foo.hh"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4594,6 +4594,8 @@
   if (Args.hasArg(options::OPT_rewrite_objc) &&
   !Args.hasArg(options::OPT_g_Group))
 CmdArgs.push_back("-P");
+  else if (JA.getType() == types::TY_PP_CXXHeaderUnit)
+CmdArgs.push_back("-fdirectives-only");
 }
   } else if (isa(JA)) {
 CmdArgs.push_back("-emit-obj");
@@ -6707,6 +6709,10 @@
   if (RewriteImports)
 CmdArgs.push_back("-frewrite-imports");
 
+  if (Args.hasFlag(options::OPT_fdirectives_only,
+   options::OPT_fno_direc

[PATCH] D122920: [Clang][CodeGen]Fix __builtin_dump_struct missing record type field name

2022-04-23 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 424718.
yihanaa added a comment.

Optimize the code according to @ rsmith's suggestion, and use 
analyze_printf::PrintfSpecifier::fixType instead of this static DenseMap to 
find the printf format specifier.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122920

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dump-struct-builtin.c

Index: clang/test/CodeGen/dump-struct-builtin.c
===
--- clang/test/CodeGen/dump-struct-builtin.c
+++ clang/test/CodeGen/dump-struct-builtin.c
@@ -4,95 +4,148 @@
 #include 
 
 // CHECK: @__const.unit1.a = private unnamed_addr constant %struct.U1A { i16 12 }, align 2
-// CHECK-NEXT: [[STRUCT_STR_U1:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U1A {\0A\00", align 1
-// CHECK-NEXT: [[FIELD_U1:@[0-9]+]] = private unnamed_addr constant [19 x i8] c"short a = %hd\0A\00", align 1
-// CHECK-NEXT: [[END_STRUCT_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
+// CHECK-NEXT: [[STRUCT_STR_U1:@[0-9]+]] = private unnamed_addr constant [12 x i8] c"struct U1A \00", align 1
+// CHECK-NEXT: [[STRUCT_L_BRACE_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"{\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U1:@[0-9]+]] = private unnamed_addr constant [15 x i8] c"short a = \00", align 1
+// CHECK-NEXT: [[FORMAT_U1:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%hd\0A\00", align 1
+// CHECK-NEXT: [[STRUCT_R_BRACE_U1:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit2.a = private unnamed_addr constant %struct.U2A { i16 12 }, align 2
-// CHECK-NEXT: [[STRUCT_STR_U2:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U2A {\0A\00", align 1
-// CHECK-NEXT: [[FIELD_U2:@[0-9]+]] = private unnamed_addr constant [28 x i8] c"unsigned short a = %hu\0A\00", align 1
-// CHECK-NEXT: [[END_STRUCT_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
+// CHECK-NEXT: [[STRUCT_STR_U2:@[0-9]+]] = private unnamed_addr constant [12 x i8] c"struct U2A \00", align 1
+// CHECK-NEXT: [[STRUCT_L_BRACE_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"{\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U2:@[0-9]+]] = private unnamed_addr constant [24 x i8] c"unsigned short a = \00", align 1
+// CHECK-NEXT: [[FORMAT_U2:@[0-9]+]] = private unnamed_addr constant [5 x i8] c"%hu\0A\00", align 1
+// CHECK-NEXT: [[STRUCT_R_BRACE_U2:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit3.a = private unnamed_addr constant %struct.U3A { i32 12 }, align 4
-// CHECK-NEXT: [[STRUCT_STR_U3:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U3A {\0A\00", align 1
-// CHECK-NEXT: [[FIELD_U3:@[0-9]+]] = private unnamed_addr constant [16 x i8] c"int a = %d\0A\00", align 1
-// CHECK-NEXT: [[END_STRUCT_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
+// CHECK-NEXT: [[STRUCT_STR_U3:@[0-9]+]] = private unnamed_addr constant [12 x i8] c"struct U3A \00", align 1
+// CHECK-NEXT: [[STRUCT_L_BRACE_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"{\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U3:@[0-9]+]] = private unnamed_addr constant [13 x i8] c"int a = \00", align 1
+// CHECK-NEXT: [[FORMAT_U3:@[0-9]+]] = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
+// CHECK-NEXT: [[STRUCT_R_BRACE_U3:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit4.a = private unnamed_addr constant %struct.U4A { i32 12 }, align 4
-// CHECK-NEXT: [[STRUCT_STR_U4:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U4A {\0A\00", align 1
-// CHECK-NEXT: [[FIELD_U4:@[0-9]+]] = private unnamed_addr constant [25 x i8] c"unsigned int a = %u\0A\00", align 1
-// CHECK-NEXT: [[END_STRUCT_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
+// CHECK-NEXT: [[STRUCT_STR_U4:@[0-9]+]] = private unnamed_addr constant [12 x i8] c"struct U4A \00", align 1
+// CHECK-NEXT: [[STRUCT_L_BRACE_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"{\0A\00", align 1
+// CHECK-NEXT: [[FIELD_U4:@[0-9]+]] = private unnamed_addr constant [22 x i8] c"unsigned int a = \00", align 1
+// CHECK-NEXT: [[FORMAT_U4:@[0-9]+]] = private unnamed_addr constant [4 x i8] c"%u\0A\00", align 1
+// CHECK-NEXT: [[STRUCT_R_BRACE_U4:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", align 1
 
 // CHECK: @__const.unit5.a = private unnamed_addr constant %struct.U5A { i64 12 }, align 8
-// CHECK-NEXT: [[STRUCT_STR_U5:@[0-9]+]] = private unnamed_addr constant [14 x i8] c"struct U5A {\0A\00", align 1
-// CHECK-NEXT: [[FIELD_U5:@[0-9]+]] = private unnamed_addr constant [18 x i8] c"long a = %ld\0A\00", align 1
-// CHECK-NEXT: [[END_STRUCT_U5:@[0-9]+]] = private unnamed_addr constant [3 x i8] c"}\0A\00", 

[PATCH] D123498: [clang] Adding Platform/Architecture Specific Resource Header Installation Targets

2022-04-23 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added a comment.

See https://github.com/llvm/llvm-project/issues/55002


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123498

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


[PATCH] D123464: [analyzer] Clean checker options from bool to DefaultBool (NFC)

2022-04-23 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 424720.
vabridgers added a comment.

refactor patch to remove DefaultBool, replace with bool as suggested


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123464

Files:
  clang/include/clang/StaticAnalyzer/Core/Checker.h
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  clang/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
@@ -46,7 +46,7 @@
 CK_NumCheckKinds
   };
 
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   void checkPreStmt(const VAArgExpr *VAA, CheckerContext &C) const;
Index: clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -43,7 +43,7 @@
   mutable Optional Val_O_CREAT;
 
 public:
-  DefaultBool CheckMisuse, CheckPortability;
+  bool CheckMisuse = false, CheckPortability = false;
 
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -563,7 +563,7 @@
 CK_StdCLibraryFunctionsTesterChecker,
 CK_NumCheckKinds
   };
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   bool DisplayLoadedSummaries = false;
Index: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -42,7 +42,7 @@
 CK_NumCheckKinds
   };
 
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -48,7 +48,7 @@
 
 public:
   // Whether the checker should model for null dereferences of smart pointers.
-  DefaultBool ModelSmartPtrDereference;
+  bool ModelSmartPtrDereference = false;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
Index: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -78,7 +78,7 @@
 CK_C11LockChecker,
 CK_NumCheckKinds
   };
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
 private:
Index: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -90,7 +90,7 @@
   // find warnings about nullability annotations that they have explicitly
   // added themselves higher priority to fix than warnings on calls to system
   // libraries.
-  DefaultBool NoDiagnoseCallsToSystemHeaders;
+  bool 

[clang] 38822b9 - Revert "[clang] Adding Platform/Architecture Specific Resource Header Installation Targets"

2022-04-23 Thread Ye Luo via cfe-commits

Author: Ye Luo
Date: 2022-04-23T09:32:53-05:00
New Revision: 38822b98fa3b9d740b9a68b0de34296205d20819

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

LOG: Revert "[clang] Adding Platform/Architecture Specific Resource Header 
Installation Targets"

Caused build failure see github issue #55002

This reverts commit 2512a875ccac158bc9b654b09e3347db167e33df.

Added: 


Modified: 
clang/lib/Headers/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index e506ecb7a8c0e..f1106b97bb382 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -1,107 +1,19 @@
-# core_files list contains the headers shared by all platforms.
-# Please consider adding new platform specific headers
-# to platform specific lists below.
-set(core_files
-  builtins.h
-  float.h
-  inttypes.h
-  iso646.h
-  limits.h
-  module.modulemap
-  stdalign.h
-  stdarg.h
-  stdatomic.h
-  stdbool.h
-  stddef.h
-  __stddef_max_align_t.h
-  stdint.h
-  stdnoreturn.h
-  tgmath.h
-  unwind.h
-  varargs.h
-  )
-
-set(arm_common_files
-  # Headers shared by Arm and AArch64
+set(files
+  adxintrin.h
+  altivec.h
+  ammintrin.h
+  amxintrin.h
   arm_acle.h
-  )
-
-set(arm_only_files
   arm_cmse.h
   armintr.h
-  )
-
-set(aarch64_only_files
   arm64intr.h
-  )
-
-set(cuda_files
-  __clang_cuda_builtin_vars.h
-  __clang_cuda_math.h
-  __clang_cuda_cmath.h
-  __clang_cuda_complex_builtins.h
-  __clang_cuda_device_functions.h
-  __clang_cuda_intrinsics.h
-  __clang_cuda_texture_intrinsics.h
-  __clang_cuda_libdevice_declares.h
-  __clang_cuda_math_forward_declares.h
-  __clang_cuda_runtime_wrapper.h
-  )
-
-set(hexagon_files
-  hexagon_circ_brev_intrinsics.h
-  hexagon_protos.h
-  hexagon_types.h
-  hvx_hexagon_protos.h
-  )
-
-set(hip_files
-  __clang_hip_libdevice_declares.h
-  __clang_hip_cmath.h
-  __clang_hip_math.h
-  __clang_hip_runtime_wrapper.h
-  )
-
-set(mips_msa_files
-  msa.h
-  )
-
-set(opencl_files
-  opencl-c.h
-  opencl-c-base.h
-  )
-
-set(ppc_files
-  altivec.h
-  htmintrin.h
-  htmxlintrin.h
-  )
-
-set(systemz_files
-  s390intrin.h
-  vecintrin.h
-  )
-
-set(ve_files
-  velintrin.h
-  velintrin_gen.h
-  velintrin_approx.h
-  )
-
-set(webassembly_files
-  wasm_simd128.h
-  )
-
-set(x86_files
-# Intrinsics
-  adxintrin.h
-  ammintrin.h
-  amxintrin.h
   avx2intrin.h
   avx512bf16intrin.h
-  avx512bitalgintrin.h
   avx512bwintrin.h
+  avx512bitalgintrin.h
+  avx512vlbitalgintrin.h
   avx512cdintrin.h
+  avx512vpopcntdqintrin.h
   avx512dqintrin.h
   avx512erintrin.h
   avx512fintrin.h
@@ -109,55 +21,86 @@ set(x86_files
   avx512ifmaintrin.h
   avx512ifmavlintrin.h
   avx512pfintrin.h
-  avx512vbmi2intrin.h
   avx512vbmiintrin.h
   avx512vbmivlintrin.h
+  avx512vbmi2intrin.h
+  avx512vlvbmi2intrin.h
   avx512vlbf16intrin.h
-  avx512vlbitalgintrin.h
   avx512vlbwintrin.h
   avx512vlcdintrin.h
   avx512vldqintrin.h
   avx512vlfp16intrin.h
   avx512vlintrin.h
-  avx512vlvbmi2intrin.h
-  avx512vlvnniintrin.h
-  avx512vlvp2intersectintrin.h
-  avx512vnniintrin.h
   avx512vp2intersectintrin.h
-  avx512vpopcntdqintrin.h
+  avx512vlvp2intersectintrin.h
   avx512vpopcntdqvlintrin.h
+  avx512vnniintrin.h
+  avx512vlvnniintrin.h
   avxintrin.h
   avxvnniintrin.h
   bmi2intrin.h
   bmiintrin.h
+  builtins.h
+  __clang_cuda_builtin_vars.h
+  __clang_cuda_math.h
+  __clang_cuda_cmath.h
+  __clang_cuda_complex_builtins.h
+  __clang_cuda_device_functions.h
+  __clang_cuda_intrinsics.h
+  __clang_cuda_texture_intrinsics.h
+  __clang_cuda_libdevice_declares.h
+  __clang_cuda_math_forward_declares.h
+  __clang_cuda_runtime_wrapper.h
+  __clang_hip_libdevice_declares.h
+  __clang_hip_cmath.h
+  __clang_hip_math.h
+  __clang_hip_runtime_wrapper.h
   cetintrin.h
+  cet.h
   cldemoteintrin.h
-  clflushoptintrin.h
-  clwbintrin.h
   clzerointrin.h
   crc32intrin.h
+  cpuid.h
+  clflushoptintrin.h
+  clwbintrin.h
   emmintrin.h
   enqcmdintrin.h
   f16cintrin.h
+  float.h
   fma4intrin.h
   fmaintrin.h
   fxsrintrin.h
   gfniintrin.h
+  hexagon_circ_brev_intrinsics.h
+  hexagon_protos.h
+  hexagon_types.h
+  hvx_hexagon_protos.h
   hresetintrin.h
+  htmintrin.h
+  htmxlintrin.h
   ia32intrin.h
   immintrin.h
+  intrin.h
+  inttypes.h
   invpcidintrin.h
+  iso646.h
   keylockerintrin.h
+  limits.h
   lwpintrin.h
   lzcntintrin.h
   mm3dnow.h
   mmintrin.h
+  mm_malloc.h
+  module.modulemap
   movdirintrin.h
+  msa.h
   mwaitxintrin.h
   nmmintrin.h
-  pconfigintrin.h
+  opencl-c.h
+  opencl-c-base.h
   pkuintrin.h
   pmmintrin.h
+  pconfigintrin.h
   popcntintrin.h
   prfchwintrin.h
   ptwriteintrin.h
@@ -165,18 +108,33 @@ set(x86_files
   rtmintrin.h
   serializeintrin.h
   sgxintrin.h
+  s390intrin.h
   shaintrin.h
   smmintrin.h
+  stdalign.h
+  

[PATCH] D123464: [analyzer] Clean checker options from bool to DefaultBool (NFC)

2022-04-23 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

Hi @steakhal, I believe I've addressed the comments. Please have a look and let 
me know if this is what you were after. Best!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123464

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


[PATCH] D124221: Add new builtin __builtin_reflect_struct.

2022-04-23 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:420
+auto *FD = IFD ? IFD->getAnonField() : dyn_cast(D);
+if (!FD || (FD->isUnnamedBitfield() || FD->isAnonymousStructOrUnion()))
+  continue;

erichkeane wrote:
> rsmith wrote:
> > erichkeane wrote:
> > > rsmith wrote:
> > > > erichkeane wrote:
> > > > > rsmith wrote:
> > > > > > erichkeane wrote:
> > > > > > > Losing the unnamed bitfield is unfortunate, and I the 'dump 
> > > > > > > struct' handles.  As is losing the anonymous struct/union.
> > > > > > > 
> > > > > > > Also, how does this handle 'record type' members?  Does the user 
> > > > > > > have to know the inner type already?  If they already know that 
> > > > > > > much information about the type, they wouldn't really need this, 
> > > > > > > right?
> > > > > > If `__builtin_dump_struct` includes unnamed bitfields, that's a bug 
> > > > > > in that builtin.
> > > > > > 
> > > > > > In general, the user function gets given the bases and members with 
> > > > > > the right types, so they can use an overload set or a template to 
> > > > > > dispatch based on that type. See the SemaCXX test for a basic 
> > > > > > example of that.
> > > > > I thought it did?  For the use case I see `__builtin_dump_struct` 
> > > > > having, I would think printing the existence of unnamed bitfields to 
> > > > > be quite useful.
> > > > > 
> > > > > 
> > > > Why? They're not part of the value, they're just padding.
> > > They are lexically part of the type and are part of what makes up the 
> > > 'size' of the thing. I would expect something dumping the type to be as 
> > > consistent lexically as possible.
> > Looks like `__builtin_dump_struct` currently includes them *and* prints a 
> > value (whatever garbage happens to be in those padding bits). That's 
> > obviously a bug.
> O.o! Yeah, printing the value is nonsense.
I think the user should be informed somehow that there is an unnamed bitfield 
here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124221

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


[PATCH] D122920: [Clang][CodeGen]Fix __builtin_dump_struct missing record type field name

2022-04-23 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

Should we use PrintingPolicy.Indentation instead of 4 hardcoded in dumpRecord?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122920

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


[PATCH] D123464: [analyzer] Clean checker options from bool to DefaultBool (NFC)

2022-04-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Good stuff. Update the summary and title, and I think good to go.

In addition to this, we should do something similar with the rest of the 
checker options and initialize them at the declaration. But that is a different 
story.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123464

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


[clang] 3530c35 - [OpenMP] Use CUDA's non-RDC mode when LTO has whole program visibility

2022-04-23 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-04-23T12:42:40-04:00
New Revision: 3530c35c660919b9367f1ac598abfb9a569e7606

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

LOG: [OpenMP] Use CUDA's non-RDC mode when LTO has whole program visibility

When we do LTO we consider ourselves to have whole program visibility if
every single input file we have contains LLVM bitcode. If we have whole
program visibliity then we can create a single image and utilize CUDA's
non-RDC mode by not passing `-c` to `ptxas` and ignoring the `nvlink`
job. This should be faster for some situations and also saves us the
time executing `nvlink`.

Reviewed By: tra

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

Added: 


Modified: 
clang/test/Driver/linker-wrapper.c
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 5ec99f5fe5b03..7920fe8c1a990 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -38,5 +38,5 @@
 // RUN: clang-linker-wrapper --host-triple x86_64-unknown-linux-gnu --dry-run 
-linker-path \
 // RUN:   /usr/bin/ld -- %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=LTO
 
-// LTO: ptxas{{.*}}-m64 -o {{.*}}.cubin -O2 --gpu-name sm_70 -c {{.*}}.s
-// LTO: nvlink{{.*}}-m64 -o {{.*}}.out -arch sm_70 {{.*}}.cubin
+// LTO: ptxas{{.*}}-m64 -o {{.*}}.cubin -O2 --gpu-name sm_70 {{.*}}.s
+// LTO-NOT: nvlink

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index b52dda13ac200..2c14c893c6424 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -595,7 +595,7 @@ extractFromBuffer(std::unique_ptr Buffer,
 // TODO: Move these to a separate file.
 namespace nvptx {
 Expected assemble(StringRef InputFile, Triple TheTriple,
-   StringRef Arch) {
+   StringRef Arch, bool RDC = true) {
   // NVPTX uses the ptxas binary to create device object files.
   Expected PtxasPath = findProgram("ptxas", {CudaBinaryPath});
   if (!PtxasPath)
@@ -626,7 +626,8 @@ Expected assemble(StringRef InputFile, Triple 
TheTriple,
   CmdArgs.push_back(Opt);
   CmdArgs.push_back("--gpu-name");
   CmdArgs.push_back(Arch);
-  CmdArgs.push_back("-c");
+  if (RDC)
+CmdArgs.push_back("-c");
 
   CmdArgs.push_back(InputFile);
 
@@ -933,7 +934,8 @@ bool isValidCIdentifier(StringRef S) {
 }
 
 Error linkBitcodeFiles(SmallVectorImpl &InputFiles,
-   const Triple &TheTriple, StringRef Arch) {
+   const Triple &TheTriple, StringRef Arch,
+   bool &WholeProgram) {
   SmallVector, 4> SavedBuffers;
   SmallVector, 4> BitcodeFiles;
   SmallVector NewInputFiles;
@@ -1009,7 +1011,7 @@ Error linkBitcodeFiles(SmallVectorImpl 
&InputFiles,
   };
 
   // We assume visibility of the whole program if every input file was bitcode.
-  bool WholeProgram = BitcodeFiles.size() == InputFiles.size();
+  WholeProgram = BitcodeFiles.size() == InputFiles.size();
   auto LTOBackend =
   (EmbedBitcode) ? createLTO(TheTriple, Arch, WholeProgram, OutputBitcode)
  : createLTO(TheTriple, Arch, WholeProgram);
@@ -1089,7 +1091,7 @@ Error linkBitcodeFiles(SmallVectorImpl 
&InputFiles,
   // Is we are compiling for NVPTX we need to run the assembler first.
   if (TheTriple.isNVPTX() && !EmbedBitcode) {
 for (auto &File : Files) {
-  auto FileOrErr = nvptx::assemble(File, TheTriple, Arch);
+  auto FileOrErr = nvptx::assemble(File, TheTriple, Arch, !WholeProgram);
   if (!FileOrErr)
 return FileOrErr.takeError();
   File = *FileOrErr;
@@ -1117,10 +1119,11 @@ Error linkDeviceFiles(ArrayRef DeviceFiles,
   for (auto &LinkerInput : LinkerInputMap) {
 DeviceFile &File = LinkerInput.getFirst();
 Triple TheTriple = Triple(File.TheTriple);
+bool WholeProgram = false;
 
 // Run LTO on any bitcode files and replace the input with the result.
-if (Error Err =
-linkBitcodeFiles(LinkerInput.getSecond(), TheTriple, File.Arch))
+if (Error Err = linkBitcodeFiles(LinkerInput.getSecond(), TheTriple,
+ File.Arch, WholeProgram))
   return Err;
 
 // If we are embedding bitcode for JIT, skip the final device linking.
@@ -1130,6 +1133,14 @@ Error linkDeviceFiles(ArrayRef DeviceFiles,
   continue;
 }
 
+// If we performed LTO on NVPTX and had whole program visibility, we can 
use
+// CUDA in non-RDC mode.
+if (WholeProgram && TheTriple.isNVPTX()) {
+  assert(!LinkerInput.getSecond().empty() && "No non-RDC image to embed");

[PATCH] D124292: [OpenMP] Use CUDA's non-RDC mode when LTO has whole program visibility

2022-04-23 Thread Joseph Huber 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 rG3530c35c6609: [OpenMP] Use CUDA's non-RDC mode when LTO 
has whole program visibility (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124292

Files:
  clang/test/Driver/linker-wrapper.c
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -595,7 +595,7 @@
 // TODO: Move these to a separate file.
 namespace nvptx {
 Expected assemble(StringRef InputFile, Triple TheTriple,
-   StringRef Arch) {
+   StringRef Arch, bool RDC = true) {
   // NVPTX uses the ptxas binary to create device object files.
   Expected PtxasPath = findProgram("ptxas", {CudaBinaryPath});
   if (!PtxasPath)
@@ -626,7 +626,8 @@
   CmdArgs.push_back(Opt);
   CmdArgs.push_back("--gpu-name");
   CmdArgs.push_back(Arch);
-  CmdArgs.push_back("-c");
+  if (RDC)
+CmdArgs.push_back("-c");
 
   CmdArgs.push_back(InputFile);
 
@@ -933,7 +934,8 @@
 }
 
 Error linkBitcodeFiles(SmallVectorImpl &InputFiles,
-   const Triple &TheTriple, StringRef Arch) {
+   const Triple &TheTriple, StringRef Arch,
+   bool &WholeProgram) {
   SmallVector, 4> SavedBuffers;
   SmallVector, 4> BitcodeFiles;
   SmallVector NewInputFiles;
@@ -1009,7 +1011,7 @@
   };
 
   // We assume visibility of the whole program if every input file was bitcode.
-  bool WholeProgram = BitcodeFiles.size() == InputFiles.size();
+  WholeProgram = BitcodeFiles.size() == InputFiles.size();
   auto LTOBackend =
   (EmbedBitcode) ? createLTO(TheTriple, Arch, WholeProgram, OutputBitcode)
  : createLTO(TheTriple, Arch, WholeProgram);
@@ -1089,7 +1091,7 @@
   // Is we are compiling for NVPTX we need to run the assembler first.
   if (TheTriple.isNVPTX() && !EmbedBitcode) {
 for (auto &File : Files) {
-  auto FileOrErr = nvptx::assemble(File, TheTriple, Arch);
+  auto FileOrErr = nvptx::assemble(File, TheTriple, Arch, !WholeProgram);
   if (!FileOrErr)
 return FileOrErr.takeError();
   File = *FileOrErr;
@@ -1117,10 +1119,11 @@
   for (auto &LinkerInput : LinkerInputMap) {
 DeviceFile &File = LinkerInput.getFirst();
 Triple TheTriple = Triple(File.TheTriple);
+bool WholeProgram = false;
 
 // Run LTO on any bitcode files and replace the input with the result.
-if (Error Err =
-linkBitcodeFiles(LinkerInput.getSecond(), TheTriple, File.Arch))
+if (Error Err = linkBitcodeFiles(LinkerInput.getSecond(), TheTriple,
+ File.Arch, WholeProgram))
   return Err;
 
 // If we are embedding bitcode for JIT, skip the final device linking.
@@ -1130,6 +1133,14 @@
   continue;
 }
 
+// If we performed LTO on NVPTX and had whole program visibility, we can 
use
+// CUDA in non-RDC mode.
+if (WholeProgram && TheTriple.isNVPTX()) {
+  assert(!LinkerInput.getSecond().empty() && "No non-RDC image to embed");
+  LinkedImages.push_back(LinkerInput.getSecond().front());
+  continue;
+}
+
 auto ImageOrErr = linkDevice(LinkerInput.getSecond(), TheTriple, 
File.Arch);
 if (!ImageOrErr)
   return ImageOrErr.takeError();
Index: clang/test/Driver/linker-wrapper.c
===
--- clang/test/Driver/linker-wrapper.c
+++ clang/test/Driver/linker-wrapper.c
@@ -38,5 +38,5 @@
 // RUN: clang-linker-wrapper --host-triple x86_64-unknown-linux-gnu --dry-run 
-linker-path \
 // RUN:   /usr/bin/ld -- %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=LTO
 
-// LTO: ptxas{{.*}}-m64 -o {{.*}}.cubin -O2 --gpu-name sm_70 -c {{.*}}.s
-// LTO: nvlink{{.*}}-m64 -o {{.*}}.out -arch sm_70 {{.*}}.cubin
+// LTO: ptxas{{.*}}-m64 -o {{.*}}.cubin -O2 --gpu-name sm_70 {{.*}}.s
+// LTO-NOT: nvlink


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -595,7 +595,7 @@
 // TODO: Move these to a separate file.
 namespace nvptx {
 Expected assemble(StringRef InputFile, Triple TheTriple,
-   StringRef Arch) {
+   StringRef Arch, bool RDC = true) {
   // NVPTX uses the ptxas binary to create device object files.
   Expected PtxasPath = findProgram("ptxas", {CudaBinaryPath});
   if (!PtxasPath)
@@ -626,7 +626,8 @@
   CmdArgs.push_back(Opt);
   CmdArgs.push_b

[PATCH] D121078: Replace links to archived mailing lists by links to Discourse forums

2022-04-23 Thread Tanya Lattner via Phabricator via cfe-commits
tonic added a comment.

In D121078#3402469 , @aaron.ballman 
wrote:

> In D121078#3400810 , @SimplyDanny 
> wrote:
>
>> @tonic, can you please have another look?
>
> If @tonic has any additional feedback, we can handle it post-commit at this 
> point. I've gone ahead and committed this on your behalf in 
> a749e3295df4aee18a0ad723875a6501f30ac744 
> .
>
> (Note, I can't close this review because of the "changes requested" state for 
> tonic.)

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121078

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


[PATCH] D121078: Replace links to archived mailing lists by links to Discourse forums

2022-04-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay closed this revision.
MaskRay added a comment.

a749e3295df4aee18a0ad723875a6501f30ac744 
 pushed by 
Aaron does not have a `Differential Revision:` line. Manual closing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121078

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


[clang] 5114db9 - [analyzer] Clean checker options from bool to DefaultBool (NFC)

2022-04-23 Thread via cfe-commits

Author: Vince Bridgers
Date: 2022-04-23T14:47:29-05:00
New Revision: 5114db933dbf2507d613e50372aa62a1108f830c

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

LOG: [analyzer] Clean checker options from bool to DefaultBool (NFC)

A recent review emphasized the preference to use DefaultBool instead of
bool for checker options. This change is a NFC and cleans up some of the
instances where bool was used, and could be changed to DefaultBool.

Reviewed By: steakhal

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/Checker.h
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
clang/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/Checker.h 
b/clang/include/clang/StaticAnalyzer/Core/Checker.h
index fdba49664615e..36a8bcb26bd22 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Checker.h
+++ b/clang/include/clang/StaticAnalyzer/Core/Checker.h
@@ -563,18 +563,6 @@ struct ImplicitNullDerefEvent {
   static int Tag;
 };
 
-/// A helper class which wraps a boolean value set to false by default.
-///
-/// This class should behave exactly like 'bool' except that it doesn't need to
-/// be explicitly initialized.
-struct DefaultBool {
-  bool val;
-  DefaultBool() : val(false) {}
-  /*implicit*/ operator bool&() { return val; }
-  /*implicit*/ operator const bool&() const { return val; }
-  DefaultBool &operator=(bool b) { val = b; return *this; }
-};
-
 } // end ento namespace
 
 } // end clang namespace

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index fbb924550a728..b001288a3d6ba 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -88,11 +88,11 @@ class CStringChecker : public Checker< eval::Call,
   /// The filter is used to filter out the diagnostics which are not enabled by
   /// the user.
   struct CStringChecksFilter {
-DefaultBool CheckCStringNullArg;
-DefaultBool CheckCStringOutOfBounds;
-DefaultBool CheckCStringBufferOverlap;
-DefaultBool CheckCStringNotNullTerm;
-DefaultBool CheckCStringUninitializedRead;
+bool CheckCStringNullArg = false;
+bool CheckCStringOutOfBounds = false;
+bool CheckCStringBufferOverlap = false;
+bool CheckCStringNotNullTerm = false;
+bool CheckCStringUninitializedRead = false;
 
 CheckerNameRef CheckNameCStringNullArg;
 CheckerNameRef CheckNameCStringOutOfBounds;
@@ -2493,4 +2493,4 @@ REGISTER_CHECKER(CStringNullArg)
 REGISTER_CHECKER(CStringOutOfBounds)
 REGISTER_CHECKER(CStringBufferOverlap)
 REGISTER_CHECKER(CStringNotNullTerm)
-REGISTER_CHECKER(CStringUninitializedRead)
\ No newline at end of file
+REGISTER_CHECKER(CStringUninitializedRead)

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
index 3e46e23725169..79225e8e6ca31 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
@@ -73,7 +73,7 @@ class CallAndMessageChecker
 CK_NumCheckKinds
   };
 
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   // The original core.CallAndMessage checker name. This should rather be an
   // array, as seen in MallocChecker and CStringChecker.
   CheckerNameRef OriginalName;

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
index ef0965a70d7e7..18d575041ba74 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -36,20 +36,20 @@ static bool isArc4RandomAvailable(const ASTCon

[PATCH] D123464: [analyzer] Clean checker options from bool to DefaultBool (NFC)

2022-04-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5114db933dbf: [analyzer] Clean checker options from bool to 
DefaultBool (NFC) (authored by vabridgers, committed by einvbri 
).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123464

Files:
  clang/include/clang/StaticAnalyzer/Core/Checker.h
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  clang/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
@@ -46,7 +46,7 @@
 CK_NumCheckKinds
   };
 
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   void checkPreStmt(const VAArgExpr *VAA, CheckerContext &C) const;
Index: clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -43,7 +43,7 @@
   mutable Optional Val_O_CREAT;
 
 public:
-  DefaultBool CheckMisuse, CheckPortability;
+  bool CheckMisuse = false, CheckPortability = false;
 
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -563,7 +563,7 @@
 CK_StdCLibraryFunctionsTesterChecker,
 CK_NumCheckKinds
   };
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   bool DisplayLoadedSummaries = false;
Index: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
@@ -42,7 +42,7 @@
 CK_NumCheckKinds
   };
 
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -48,7 +48,7 @@
 
 public:
   // Whether the checker should model for null dereferences of smart pointers.
-  DefaultBool ModelSmartPtrDereference;
+  bool ModelSmartPtrDereference = false;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
Index: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
@@ -78,7 +78,7 @@
 CK_C11LockChecker,
 CK_NumCheckKinds
   };
-  DefaultBool ChecksEnabled[CK_NumCheckKinds];
+  bool ChecksEnabled[CK_NumCheckKinds] = {false};
   CheckerNameRef CheckNames[CK_NumCheckKinds];
 
 private:
Index: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -90,7 +90,7 @@
   // find warnings about nullability annotations that they have explicitly
   // added themselves higher priority to fix 

[PATCH] D123182: [Concepts] Fix overload resolution bug with constrained candidates

2022-04-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 424747.
royjacobson added a comment.

Rebase after fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+struct A;
+struct B;
+
+template  constexpr bool True = true;
+template  concept C = True;
+
+void f(C auto &, auto &) = delete;
+template  void f(Q &, C auto &);
+
+void g(struct A *ap, struct B *bp) {
+  f(*ap, *bp);
+}
+
+template  struct X {};
+
+template  bool operator==(X, V) = delete;
+templatebool operator==(T, X);
+
+bool h() {
+  return X{} == 0;
+}
+
+namespace PR53640 {
+
+template 
+concept C = true;
+
+template 
+void f(T t) {} // expected-note {{candidate function [with T = int]}}
+
+template 
+void f(const T &t) {} // expected-note {{candidate function [with T = int]}}
+
+int g() {
+  f(0); // expected-error {{call to 'f' is ambiguous}}
+}
+
+struct S {
+  template  explicit S(T) noexcept requires C {} // expected-note {{candidate constructor}}
+  template  explicit S(const T &) noexcept {}   // expected-note {{candidate constructor}}
+};
+
+int h() {
+  S s(4); // expected-error-re {{call to constructor of {{.*}} is ambiguous}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5143,18 +5143,20 @@
 /// candidate with a reversed parameter order. In this case, the corresponding
 /// P/A pairs between FT1 and FT2 are reversed.
 ///
+/// \param AllowOrderingByConstraints If \c is false, don't check whether one
+/// of the templates is more constrained than the other. Default is true.
+///
 /// \returns the more specialized function template. If neither
 /// template is more specialized, returns NULL.
-FunctionTemplateDecl *
-Sema::getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
- FunctionTemplateDecl *FT2,
- SourceLocation Loc,
- TemplatePartialOrderingContext TPOC,
- unsigned NumCallArguments1,
- unsigned NumCallArguments2,
- bool Reversed) {
-
-  auto JudgeByConstraints = [&] () -> FunctionTemplateDecl * {
+FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
+FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
+TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
+unsigned NumCallArguments2, bool Reversed,
+bool AllowOrderingByConstraints) {
+
+  auto JudgeByConstraints = [&]() -> FunctionTemplateDecl * {
+if (!AllowOrderingByConstraints)
+  return nullptr;
 llvm::SmallVector AC1, AC2;
 FT1->getAssociatedConstraints(AC1);
 FT2->getAssociatedConstraints(AC2);
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are different,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are different,
 /// ArgPos will have the parameter index of the first different parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of functions with different number 

[PATCH] D124260: [clang-format] ColumnLimit check for trailing comments alignment acts wrong for multi-byte UTF-8 #47624

2022-04-23 Thread Александр Тулуп via Phabricator via cfe-commits
StailGot updated this revision to Diff 424749.

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

https://reviews.llvm.org/D124260

Files:
  clang/lib/Format/WhitespaceManager.cpp


Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -909,8 +909,8 @@
 
 if (Style.ColumnLimit == 0)
   ChangeMaxColumn = UINT_MAX;
-else if (Style.ColumnLimit >= Changes[i].TokenLength)
-  ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+else if (Style.ColumnLimit >= Changes[i].Tok->ColumnWidth)
+  ChangeMaxColumn = Style.ColumnLimit - Changes[i].Tok->ColumnWidth;
 else
   ChangeMaxColumn = ChangeMinColumn;
 


Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -909,8 +909,8 @@
 
 if (Style.ColumnLimit == 0)
   ChangeMaxColumn = UINT_MAX;
-else if (Style.ColumnLimit >= Changes[i].TokenLength)
-  ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+else if (Style.ColumnLimit >= Changes[i].Tok->ColumnWidth)
+  ChangeMaxColumn = Style.ColumnLimit - Changes[i].Tok->ColumnWidth;
 else
   ChangeMaxColumn = ChangeMinColumn;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 807e418 - [Concepts] Fix overload resolution bug with constrained candidates

2022-04-23 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-04-23T17:24:59-04:00
New Revision: 807e418413a0958ad1ea862093fb262673b2afa1

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

LOG: [Concepts] Fix overload resolution bug with constrained candidates

When doing overload resolution, we have to check that candidates' parameter 
types are equal before trying to find a better candidate through checking which 
candidate is more constrained.
This revision adds this missing check and makes us diagnose those cases as 
ambiguous calls when the types are not equal.

Fixes GitHub issue https://github.com/llvm/llvm-project/issues/53640

Reviewed By: erichkeane

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

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1c86cdc3aca..e78167bad589e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9093bb39e9e86..114725498c982 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,7 +3580,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8749,7 +8750,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of

[PATCH] D123182: [Concepts] Fix overload resolution bug with constrained candidates

2022-04-23 Thread Roy Jacobson 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 rG807e418413a0: [Concepts] Fix overload resolution bug with 
constrained candidates (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- /dev/null
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+struct A;
+struct B;
+
+template  constexpr bool True = true;
+template  concept C = True;
+
+void f(C auto &, auto &) = delete;
+template  void f(Q &, C auto &);
+
+void g(struct A *ap, struct B *bp) {
+  f(*ap, *bp);
+}
+
+template  struct X {};
+
+template  bool operator==(X, V) = delete;
+templatebool operator==(T, X);
+
+bool h() {
+  return X{} == 0;
+}
+
+namespace PR53640 {
+
+template 
+concept C = true;
+
+template 
+void f(T t) {} // expected-note {{candidate function [with T = int]}}
+
+template 
+void f(const T &t) {} // expected-note {{candidate function [with T = int]}}
+
+int g() {
+  f(0); // expected-error {{call to 'f' is ambiguous}}
+}
+
+struct S {
+  template  explicit S(T) noexcept requires C {} // expected-note {{candidate constructor}}
+  template  explicit S(const T &) noexcept {}   // expected-note {{candidate constructor}}
+};
+
+int h() {
+  S s(4); // expected-error-re {{call to constructor of {{.*}} is ambiguous}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5143,18 +5143,20 @@
 /// candidate with a reversed parameter order. In this case, the corresponding
 /// P/A pairs between FT1 and FT2 are reversed.
 ///
+/// \param AllowOrderingByConstraints If \c is false, don't check whether one
+/// of the templates is more constrained than the other. Default is true.
+///
 /// \returns the more specialized function template. If neither
 /// template is more specialized, returns NULL.
-FunctionTemplateDecl *
-Sema::getMoreSpecializedTemplate(FunctionTemplateDecl *FT1,
- FunctionTemplateDecl *FT2,
- SourceLocation Loc,
- TemplatePartialOrderingContext TPOC,
- unsigned NumCallArguments1,
- unsigned NumCallArguments2,
- bool Reversed) {
-
-  auto JudgeByConstraints = [&] () -> FunctionTemplateDecl * {
+FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
+FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
+TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
+unsigned NumCallArguments2, bool Reversed,
+bool AllowOrderingByConstraints) {
+
+  auto JudgeByConstraints = [&]() -> FunctionTemplateDecl * {
+if (!AllowOrderingByConstraints)
+  return nullptr;
 llvm::SmallVector AC1, AC2;
 FT1->getAssociatedConstraints(AC1);
 FT2->getAssociatedConstraints(AC2);
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are different,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are different,
 /// ArgPos will have the parameter index of the first different parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *A

[PATCH] D122841: [analyzer] Add option for AddrSpace in core.NullDereference check

2022-04-23 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 424752.
vabridgers added a comment.

add back amdgcn cases


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122841

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/cast-value-notes.cpp

Index: clang/test/Analysis/cast-value-notes.cpp
===
--- clang/test/Analysis/cast-value-notes.cpp
+++ clang/test/Analysis/cast-value-notes.cpp
@@ -1,10 +1,44 @@
-// RUN: %clang_analyze_cc1 -std=c++14 \
-// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
-// RUN:  -analyzer-output=text -verify -DDEFAULT_TRIPLE %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-CHECK
+// RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-output=text -verify -DX86 -DSUPPRESSED %s 2>&1 | FileCheck %s -check-prefix=X86-CHECK
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -analyzer-config core.NullDereference:SuppressAddressSpaces=false\
+// RUN:  -analyzer-output=text -verify -DX86 -DNOT_SUPPRESSED %s 2>&1 | FileCheck %s -check-prefix=X86-CHECK
 //
 // RUN: %clang_analyze_cc1 -std=c++14 -triple amdgcn-unknown-unknown \
 // RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
-// RUN: -analyzer-output=text -verify -DAMDGCN_TRIPLE %s 2>&1 | FileCheck %s -check-prefix=AMDGCN-CHECK
+// RUN:  -analyzer-config core.NullDereference:SuppressAddressSpaces=true\
+// RUN:  -analyzer-output=text -verify -DX86 -DSUPPRESSED %s 2>&1 | FileCheck %s -check-prefix=X86-CHECK
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -analyzer-output=text -verify -DX86 -DSUPPRESSED %s 2>&1 | FileCheck %s --check-prefix=X86-CHECK
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -analyzer-config core.NullDereference:SuppressAddressSpaces=true\
+// RUN:  -analyzer-output=text -verify -DX86 -DSUPPRESSED %s 2>&1 | FileCheck %s --check-prefix=X86-CHECK-SUPPRESSED
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-unknown \
+// RUN:  -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN:  -analyzer-config core.NullDereference:SuppressAddressSpaces=false\
+// RUN:  -analyzer-output=text -verify -DX86 -DNOT_SUPPRESSED %s 2>&1 | FileCheck %s --check-prefix=X86-CHECK
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-output=text -verify -DMIPS %s 2>&1
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=false\
+// RUN: -analyzer-output=text -verify -DMIPS %s 2>&1
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple mips-unknown-unknown \
+// RUN: -analyzer-checker=core,apiModeling.llvm.CastValue,debug.ExprInspection\
+// RUN: -analyzer-config core.NullDereference:SuppressAddressSpaces=true\
+// RUN: -analyzer-output=text -verify -DMIPS_SUPPRESSED %s
 
 #include "Inputs/llvm.h"
 
@@ -36,27 +70,51 @@
 
 void clang_analyzer_printState();
 
-#if defined(DEFAULT_TRIPLE)
+#if defined(X86)
 void evalReferences(const Shape &S) {
   const auto &C = dyn_cast(S);
   // expected-note@-1 {{Assuming 'S' is not a 'Circle'}}
   // expected-note@-2 {{Dereference of null pointer}}
   // expected-warning@-3 {{Dereference of null pointer}}
   clang_analyzer_printState();
-  // DEFAULT-CHECK: "dynamic_types": [
-  // DEFAULT-CHECK-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const class clang::Circle &", "sub_classable": true }
+  // XX86-CHECK:  "dynamic_types": [
+  // XX86-CHECK-NEXT:   { "region": "SymRegion{reg_$0}", "dyn_type": "const class clang::Circle &", "sub_classable": true }
   (void)C;
 }
-#elif defined(AMDGCN_TRIPLE)
-void evalReferences(const Shape &S) {
+#if defined(SUPPRESSED)
+void evalReferences_addrspace(const Shape &S) {
   const auto &C = dyn_cast(S);
   clang_analyzer_printState();
-  // AMDGCN-CHECK: "dynamic_types": [
-  // AMDGCN-CHECK-NEXT: { "region": "SymRegion{reg_$0}", "dyn_type": "const __attribute__((address_space(3))) class clang::Circle &", "sub_classable": true }
+  // X86-CHECK-SUPPRESSED: "dynamic_types": [
+  // X86-CHECK-SUPPRESSED-NEXT: { "region": "SymRegion{

[PATCH] D124260: [clang-format] ColumnLimit check for trailing comments alignment acts wrong for multi-byte UTF-8 #47624

2022-04-23 Thread Александр Тулуп via Phabricator via cfe-commits
StailGot updated this revision to Diff 424754.

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

https://reviews.llvm.org/D124260

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTestComments.cpp


Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -2856,6 +2856,13 @@
"int a; //\n");
   verifyFormat("/**/   //\n"
"int a; //\n");
+
+  // https://llvm.org/PR48280
+  EXPECT_EQ("int ab; // utf8 🐉\n"
+"int a;  // line\n",
+format("int ab; // long 🐉\n"
+   "int a; // line\n",
+   getLLVMStyleWithColumns(17)));
 }
 
 TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -909,8 +909,8 @@
 
 if (Style.ColumnLimit == 0)
   ChangeMaxColumn = UINT_MAX;
-else if (Style.ColumnLimit >= Changes[i].TokenLength)
-  ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+else if (Style.ColumnLimit >= Changes[i].Tok->ColumnWidth)
+  ChangeMaxColumn = Style.ColumnLimit - Changes[i].Tok->ColumnWidth;
 else
   ChangeMaxColumn = ChangeMinColumn;
 


Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -2856,6 +2856,13 @@
"int a; //\n");
   verifyFormat("/**/   //\n"
"int a; //\n");
+
+  // https://llvm.org/PR48280
+  EXPECT_EQ("int ab; // utf8 🐉\n"
+"int a;  // line\n",
+format("int ab; // long 🐉\n"
+   "int a; // line\n",
+   getLLVMStyleWithColumns(17)));
 }
 
 TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -909,8 +909,8 @@
 
 if (Style.ColumnLimit == 0)
   ChangeMaxColumn = UINT_MAX;
-else if (Style.ColumnLimit >= Changes[i].TokenLength)
-  ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+else if (Style.ColumnLimit >= Changes[i].Tok->ColumnWidth)
+  ChangeMaxColumn = Style.ColumnLimit - Changes[i].Tok->ColumnWidth;
 else
   ChangeMaxColumn = ChangeMinColumn;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124260: [clang-format] ColumnLimit check for trailing comments alignment acts wrong for multi-byte UTF-8 #47624

2022-04-23 Thread Александр Тулуп via Phabricator via cfe-commits
StailGot added a comment.

In D124260#3468773 , 
@HazardyKnusperkeks wrote:

> Hi,
>
> could you please reupload your patch with the full diff context? And please 
> add a regression test.

Done!


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

https://reviews.llvm.org/D124260

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


[clang] f6af446 - Revert "[Concepts] Fix overload resolution bug with constrained candidates"

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T19:35:41-05:00
New Revision: f6af446b6625657b1b9046273f5b33bc1173a97c

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

LOG: Revert "[Concepts] Fix overload resolution bug with constrained candidates"

This reverts commit 807e418413a0958ad1ea862093fb262673b2afa1.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e78167bad589e..3f1c86cdc3aca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,11 +123,6 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
-- Overload resolution for constrained function templates could use the partial
-  order of constraints to select an overload, even if the parameter types of
-  the functions were 
diff erent. It now diagnoses this case correctly as an
-  ambiguous call and an error. Fixes
-  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 114725498c982..9093bb39e9e86 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,8 +3580,7 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr,
-  bool Reversed = false);
+  unsigned *ArgPos = nullptr);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8750,8 +8749,7 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false,
-  bool AllowOrderingByConstraints = true);
+  unsigned NumCallArguments2, bool Reversed = false);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6e45fdfbeb089..1add971a81a02 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,30 +2945,24 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their parameter types. Caller has already checked that
-/// they have same number of parameters.  If the parameters are 
diff erent,
+/// for equality of their argument types. Caller has already checked that
+/// they have same number of arguments.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
-/// If `Reversed` is true, the parameters of `NewType` will be compared in
-/// reverse order. That's useful if one of the functions is being used as a 
C++20
-/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos, bool Reversed) {
-  assert(OldType->getNumParams() == NewType->getNumParams() &&
- "Can't compare parameters of functions with 
diff erent number of "
- "parameters!");
-  for (size_t I = 0; I < OldType->getNumParams(); I++) {
-// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
-size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
-
+  unsigned *ArgPos) {
+  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
+  N = NewType->param_type_begin(),
+  E = OldType->param_type_end();
+   O && (O != E); ++O, ++N) {
 // Ignore address spaces in pointee type. This is to disallow overloading
 // on __ptr32/__ptr64 address spaces

[clang] a0636b5 - Revert "Revert "[Concepts] Fix overload resolution bug with constrained candidates""

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T19:35:50-05:00
New Revision: a0636b5855f5ba1f7033670dc32c956d63baaa51

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

LOG: Revert "Revert "[Concepts] Fix overload resolution bug with constrained 
candidates""

This reverts commit f6af446b6625657b1b9046273f5b33bc1173a97c.

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1c86cdc3aca..e78167bad589e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9093bb39e9e86..114725498c982 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,7 +3580,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8749,7 +8750,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of functions with 
diff erent number of "
+ "parameters!");
+  for (size_t I = 0; I < OldType->getNumParams(); I++) {
+// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
+size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
+
 // Ignore address spaces in pointee type. This is to disallow overloading
 // on __ptr32/__ptr64 addr

[clang] cfc2c59 - Revert "Revert "Revert "[Concepts] Fix overload resolution bug with constrained candidates"""

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T19:36:51-05:00
New Revision: cfc2c5905ec11a501cdfc9502f503ab494c200b6

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

LOG: Revert "Revert "Revert "[Concepts] Fix overload resolution bug with 
constrained candidates"""

This reverts commit a0636b5855f5ba1f7033670dc32c956d63baaa51.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e78167bad589e..3f1c86cdc3aca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,11 +123,6 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
-- Overload resolution for constrained function templates could use the partial
-  order of constraints to select an overload, even if the parameter types of
-  the functions were 
diff erent. It now diagnoses this case correctly as an
-  ambiguous call and an error. Fixes
-  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 114725498c982..9093bb39e9e86 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,8 +3580,7 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr,
-  bool Reversed = false);
+  unsigned *ArgPos = nullptr);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8750,8 +8749,7 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false,
-  bool AllowOrderingByConstraints = true);
+  unsigned NumCallArguments2, bool Reversed = false);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6e45fdfbeb089..1add971a81a02 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,30 +2945,24 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their parameter types. Caller has already checked that
-/// they have same number of parameters.  If the parameters are 
diff erent,
+/// for equality of their argument types. Caller has already checked that
+/// they have same number of arguments.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
-/// If `Reversed` is true, the parameters of `NewType` will be compared in
-/// reverse order. That's useful if one of the functions is being used as a 
C++20
-/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos, bool Reversed) {
-  assert(OldType->getNumParams() == NewType->getNumParams() &&
- "Can't compare parameters of functions with 
diff erent number of "
- "parameters!");
-  for (size_t I = 0; I < OldType->getNumParams(); I++) {
-// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
-size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
-
+  unsigned *ArgPos) {
+  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
+  N = NewType->param_type_begin(),
+  E = OldType->param_type_end();
+   O && (O != E); ++O, ++N) {
 // Ignore address spaces in pointee type. This is to disallow overloading
 // on __ptr32/__p

[clang] d1b73f3 - Reverting accidental git-revert commits.

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T20:11:27-05:00
New Revision: d1b73f3412b389e2e515ee5ce9ec87c127ebcb01

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

LOG: Reverting accidental git-revert commits.

Revert "Revert "[Concepts] Fix overload resolution bug with constrained 
candidates""

This reverts commit f6af446b6625657b1b9046273f5b33bc1173a97c.

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1c86cdc3aca..e78167bad589e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9093bb39e9e86..114725498c982 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,7 +3580,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8749,7 +8750,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of functions with 
diff erent number of "
+ "parameters!");
+  for (size_t I = 0; I < OldType->getNumParams(); I++) {
+// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
+size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
+
 // Ignore address spaces in pointee type. This is to disallow o

[clang] 2d80889 - Reverting accidental git-revert commits.

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T20:11:58-05:00
New Revision: 2d80889b2a9ea693355e4d3e617287591a7f573c

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

LOG: Reverting accidental git-revert commits.

Revert "Revert "Revert "[Concepts] Fix overload resolution bug with constrained 
candidates"""

This reverts commit a0636b5855f5ba1f7033670dc32c956d63baaa51.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e78167bad589e..3f1c86cdc3aca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,11 +123,6 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
-- Overload resolution for constrained function templates could use the partial
-  order of constraints to select an overload, even if the parameter types of
-  the functions were 
diff erent. It now diagnoses this case correctly as an
-  ambiguous call and an error. Fixes
-  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 114725498c982..9093bb39e9e86 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,8 +3580,7 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr,
-  bool Reversed = false);
+  unsigned *ArgPos = nullptr);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8750,8 +8749,7 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false,
-  bool AllowOrderingByConstraints = true);
+  unsigned NumCallArguments2, bool Reversed = false);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6e45fdfbeb089..1add971a81a02 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,30 +2945,24 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their parameter types. Caller has already checked that
-/// they have same number of parameters.  If the parameters are 
diff erent,
+/// for equality of their argument types. Caller has already checked that
+/// they have same number of arguments.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
-/// If `Reversed` is true, the parameters of `NewType` will be compared in
-/// reverse order. That's useful if one of the functions is being used as a 
C++20
-/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos, bool Reversed) {
-  assert(OldType->getNumParams() == NewType->getNumParams() &&
- "Can't compare parameters of functions with 
diff erent number of "
- "parameters!");
-  for (size_t I = 0; I < OldType->getNumParams(); I++) {
-// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
-size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
-
+  unsigned *ArgPos) {
+  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
+  N = NewType->param_type_begin(),
+  E = OldType->param_type_end();
+   O && (O != E); ++O, ++N) {
 // Ignore address spaces in pointee type. This is to d

[clang] afa20af - Reverting accidental git-revert commits.

2022-04-23 Thread Nick Kreeger via cfe-commits

Author: Nick Kreeger
Date: 2022-04-23T20:12:15-05:00
New Revision: afa20aff6ef009889f9b75a2412fea09940eaf61

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

LOG: Reverting accidental git-revert commits.

Revert "Revert "Revert "Revert "[Concepts] Fix overload resolution bug with 
constrained candidates

This reverts commit cfc2c5905ec11a501cdfc9502f503ab494c200b6.

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1c86cdc3aca..e78167bad589e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9093bb39e9e86..114725498c982 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,7 +3580,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8749,7 +8750,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of functions with 
diff erent number of "
+ "parameters!");
+  for (size_t I = 0; I < OldType->getNumParams(); I++) {
+// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
+size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
+
 // Ignore address spaces in pointee type. Thi

[PATCH] D124339: [NFC][Clang][Pragma] Remove unused variables

2022-04-23 Thread Senran Zhang via Phabricator via cfe-commits
zsrkmyn created this revision.
Herald added a project: All.
zsrkmyn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124339

Files:
  clang/lib/Lex/Pragma.cpp


Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1944,8 +1944,6 @@
 static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token 
&Tok,
const char *Pragma,
std::string &MessageString) 
{
-  std::string Macro;
-
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
 PP.Diag(Tok, diag::err_expected) << "(";
@@ -2034,8 +2032,6 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &Tok) override {
-std::string Macro;
-
 PP.Lex(Tok);
 if (Tok.isNot(tok::l_paren)) {
   PP.Diag(Tok, diag::err_expected) << "(";


Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1944,8 +1944,6 @@
 static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token &Tok,
const char *Pragma,
std::string &MessageString) {
-  std::string Macro;
-
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
 PP.Diag(Tok, diag::err_expected) << "(";
@@ -2034,8 +2032,6 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &Tok) override {
-std::string Macro;
-
 PP.Lex(Tok);
 if (Tok.isNot(tok::l_paren)) {
   PP.Diag(Tok, diag::err_expected) << "(";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124339: [NFC][Clang][Pragma] Remove unused variables

2022-04-23 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124339

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


[clang] ae76eb3 - [NFC][Clang][Pragma] Remove unused variables

2022-04-23 Thread Senran Zhang via cfe-commits

Author: Senran Zhang
Date: 2022-04-24T14:50:59+08:00
New Revision: ae76eb32a5988c1f4ebb07e7e5eb9de2b036e194

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

LOG: [NFC][Clang][Pragma] Remove unused variables

Reviewed By: beanz

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

Added: 


Modified: 
clang/lib/Lex/Pragma.cpp

Removed: 




diff  --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index 5a1b999505426..fb4f2dc457581 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -1944,8 +1944,6 @@ struct PragmaRegionHandler : public PragmaHandler {
 static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token 
&Tok,
const char *Pragma,
std::string &MessageString) 
{
-  std::string Macro;
-
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
 PP.Diag(Tok, diag::err_expected) << "(";
@@ -2034,8 +2032,6 @@ struct PragmaFinalHandler : public PragmaHandler {
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &Tok) override {
-std::string Macro;
-
 PP.Lex(Tok);
 if (Tok.isNot(tok::l_paren)) {
   PP.Diag(Tok, diag::err_expected) << "(";



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


[PATCH] D124339: [NFC][Clang][Pragma] Remove unused variables

2022-04-23 Thread Senran Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGae76eb32a598: [NFC][Clang][Pragma] Remove unused variables 
(authored by zsrkmyn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124339

Files:
  clang/lib/Lex/Pragma.cpp


Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1944,8 +1944,6 @@
 static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token 
&Tok,
const char *Pragma,
std::string &MessageString) 
{
-  std::string Macro;
-
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
 PP.Diag(Tok, diag::err_expected) << "(";
@@ -2034,8 +2032,6 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &Tok) override {
-std::string Macro;
-
 PP.Lex(Tok);
 if (Tok.isNot(tok::l_paren)) {
   PP.Diag(Tok, diag::err_expected) << "(";


Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1944,8 +1944,6 @@
 static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token &Tok,
const char *Pragma,
std::string &MessageString) {
-  std::string Macro;
-
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
 PP.Diag(Tok, diag::err_expected) << "(";
@@ -2034,8 +2032,6 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &Tok) override {
-std::string Macro;
-
 PP.Lex(Tok);
 if (Tok.isNot(tok::l_paren)) {
   PP.Diag(Tok, diag::err_expected) << "(";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits