[clang] 7fde4e2 - Add some helpers to better check Scope's kind. NFC

2022-04-15 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-04-16T11:31:40+08:00
New Revision: 7fde4e221300dbdefe9cdd70ff59f22f1dc9aee9

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

LOG: Add some helpers to better check Scope's kind. NFC

Signed-off-by: Jun Zhang 

Added: 


Modified: 
clang/include/clang/Sema/Scope.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/IdentifierResolver.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Scope.h 
b/clang/include/clang/Sema/Scope.h
index 5a2d51b63d909..3255bdc8648df 100644
--- a/clang/include/clang/Sema/Scope.h
+++ b/clang/include/clang/Sema/Scope.h
@@ -370,11 +370,15 @@ class Scope {
   }
 
   /// isFunctionScope() - Return true if this scope is a function scope.
-  bool isFunctionScope() const { return (getFlags() & Scope::FnScope); }
+  bool isFunctionScope() const { return getFlags() & Scope::FnScope; }
 
   /// isClassScope - Return true if this scope is a class/struct/union scope.
-  bool isClassScope() const {
-return (getFlags() & Scope::ClassScope);
+  bool isClassScope() const { return getFlags() & Scope::ClassScope; }
+
+  /// Determines whether this scope is between inheritance colon and the real
+  /// class/struct definition.
+  bool isClassInheritanceScope() const {
+return getFlags() & Scope::ClassInheritanceScope;
   }
 
   /// isInCXXInlineMethodScope - Return true if this scope is a C++ inline
@@ -432,6 +436,9 @@ class Scope {
 return getFlags() & Scope::AtCatchScope;
   }
 
+  /// isCatchScope - Return true if this scope is a C++ catch statement.
+  bool isCatchScope() const { return getFlags() & Scope::CatchScope; }
+
   /// isSwitchScope - Return true if this scope is a switch scope.
   bool isSwitchScope() const {
 for (const Scope *S = this; S; S = S->getParent()) {
@@ -475,9 +482,20 @@ class Scope {
 return P && P->isOpenMPLoopDirectiveScope();
   }
 
+  /// Determine whether this scope is a while/do/for statement, which can have
+  /// continue statements embedded into it.
+  bool isContinueScope() const {
+return getFlags() & ScopeFlags::ContinueScope;
+  }
+
   /// Determine whether this scope is a C++ 'try' block.
   bool isTryScope() const { return getFlags() & Scope::TryScope; }
 
+  /// Determine whether this scope is a function-level C++ try or catch scope.
+  bool isFnTryCatchScope() const {
+return getFlags() & ScopeFlags::FnTryCatchScope;
+  }
+
   /// Determine whether this scope is a SEH '__try' block.
   bool isSEHTryScope() const { return getFlags() & Scope::SEHTryScope; }
 
@@ -489,6 +507,10 @@ class Scope {
 return getFlags() & Scope::CompoundStmtScope;
   }
 
+  /// Determine whether this scope is a controlling scope in a
+  /// if/switch/while/for statement.
+  bool isControlScope() const { return getFlags() & Scope::ControlScope; }
+
   /// Returns if rhs has a higher scope depth than this.
   ///
   /// The caller is responsible for calling this only if one of the two scopes

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index ca55fa9311867..233f09213be8c 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4624,8 +4624,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec ,
   TypeResult BaseType;
   SourceRange BaseRange;
 
-  bool CanBeBitfield = (getCurScope()->getFlags() & Scope::ClassScope) &&
-   ScopedEnumKWLoc.isInvalid() && Name;
+  bool CanBeBitfield =
+  getCurScope()->isClassScope() && ScopedEnumKWLoc.isInvalid() && Name;
 
   // Parse the fixed underlying type.
   if (Tok.is(tok::colon)) {
@@ -5021,7 +5021,7 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, Decl 
*EnumDecl) {
 
   // The next token must be valid after an enum definition. If not, a ';'
   // was probably forgotten.
-  bool CanBeBitfield = getCurScope()->getFlags() & Scope::ClassScope;
+  bool CanBeBitfield = getCurScope()->isClassScope();
   if (!isValidAfterTypeSpecifier(CanBeBitfield)) {
 ExpectAndConsume(tok::semi, diag::err_expected_after, "enum");
 // Push this token back into the preprocessor and change our current token
@@ -6753,8 +6753,7 @@ void Parser::ParseFunctionDeclarator(Declarator ,
   // this in C and not C++, where the decls will continue to live in the
   // surrounding context.
   SmallVector DeclsInPrototype;
-  if (getCurScope()->getFlags() & Scope::FunctionDeclarationScope &&
-  !getLangOpts().CPlusPlus) {
+  if (getCurScope()->isFunctionDeclarationScope() && !getLangOpts().CPlusPlus) 
{
 for (Decl *D : 

[clang] 468c7b6 - [test] Test -Werror=foo -Wfoo & -Werror -Wno-error=foo -Wfoo

2022-04-15 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-04-15T20:14:07-07:00
New Revision: 468c7b65e578dd8decc3d7a2f9dce88410503fd1

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

LOG: [test] Test -Werror=foo -Wfoo & -Werror -Wno-error=foo -Wfoo

Clang now matches GCC in the two cases.

D109981 fixed the second case though it did not call out the effect.

Added: 


Modified: 
clang/test/Misc/diag-mapping2.c

Removed: 




diff  --git a/clang/test/Misc/diag-mapping2.c b/clang/test/Misc/diag-mapping2.c
index c3afea94b3701..6914307ff978c 100644
--- a/clang/test/Misc/diag-mapping2.c
+++ b/clang/test/Misc/diag-mapping2.c
@@ -11,9 +11,11 @@
 
 // -Werror can map this one warning to error.
 // RUN: not %clang_cc1 %s -Werror=#warnings 2>&1 | grep "error: foo"
+// RUN: not %clang_cc1 %s -Werror=#warnings -W#warnings 2>&1 | grep "error: 
foo"
 
-// -Wno-error= overrides -Werror.  rdar://3158301
+// -Wno-error= overrides -Werror. -Wno-error applies to a subsequent warning 
of the same name.
 // RUN: %clang_cc1 %s -Werror -Wno-error=#warnings 2>&1 | grep "warning: foo"
+// RUN: %clang_cc1 %s -Werror -Wno-error=#warnings -W#warnings 2>&1 | grep 
"warning: foo"
 
 // -Wno-error overrides -Werror.  PR4715
 // RUN: %clang_cc1 %s -Werror -Wno-error 2>&1 | grep "warning: foo"



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


[PATCH] D123889: [clang-tidy] Improve macro handling in modernize-macro-to-enum

2022-04-15 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

This is an initial pass.  While I believe the code handles other scenarios, I 
still need to add some more test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123889

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


[PATCH] D123889: [clang-tidy] Improve macro handling in modernize-macro-to-enum

2022-04-15 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood created this revision.
LegalizeAdulthood added reviewers: aaron.ballman, klimek.
LegalizeAdulthood added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
LegalizeAdulthood requested review of this revision.

When a macro is undef'ed or used in a preprocessor conditional
expression, we need to remember that macro should it later be
defined in the file to an integral value.  We need to exclude
such macro names from being turned into an enum.

Maintain a blacklist of identifiers that we've seen in an
undef or conditional preprocessor directive.  When the file is
done processing, remove all the blacklisted identifiers from
conversion to an enum.

Fixes #54842


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123889

Files:
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
@@ -181,6 +181,12 @@
 #define USE_IFDEF 1
 #define USE_IFNDEF 1
 
+// Undef'ing first and then defining later should still exclude this macro
+#undef USE_UINT64
+#define USE_UINT64 0
+#undef USE_INT64
+#define USE_INT64 0
+
 #if defined(USE_FOO) && USE_FOO
 extern void foo();
 #else
@@ -243,6 +249,19 @@
 #define IFNDEF3 3
 #endif
 
+// Macros used in conditions are invalidated, even if they look
+// like enums after they are used in conditions.
+#if DEFINED_LATER1
+#endif
+#ifdef DEFINED_LATER2
+#endif
+#ifndef DEFINED_LATER3
+#endif
+
+#define DEFINED_LATER1 1
+#define DEFINED_LATER2 2
+#define DEFINED_LATER3 3
+
 // Sometimes an argument to ifdef can be classified as a keyword token.
 #ifdef __restrict
 #endif
Index: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -193,6 +193,7 @@
   void Endif(SourceLocation Loc, SourceLocation IfLoc) override;
   void PragmaDirective(SourceLocation Loc,
PragmaIntroducerKind Introducer) override;
+  void invalidateExpressionNames();
 
   // After we've seen everything, issue warnings and fix-its.
   void EndOfMainFile() override;
@@ -222,6 +223,7 @@
   void conditionStart(const SourceLocation );
   void checkCondition(SourceRange ConditionRange);
   void checkName(const Token );
+  void rememberExpressionToken(const Token );
   void warnMacroEnum(const EnumMacro ) const;
   void fixEnumMacro(const MacroList ) const;
 
@@ -230,6 +232,7 @@
   const SourceManager 
   SmallVector Enums;
   SmallVector Files;
+  std::vector ExpressionNames;
   FileState *CurrentFile = nullptr;
 };
 
@@ -284,8 +287,9 @@
 }
 
 void MacroToEnumCallbacks::checkName(const Token ) {
-  StringRef Id = getTokenName(MacroNameTok);
+  rememberExpressionToken(MacroNameTok);
 
+  StringRef Id = getTokenName(MacroNameTok);
   llvm::erase_if(Enums, [](const MacroList ) {
 return llvm::any_of(MacroList, [](const EnumMacro ) {
   return getTokenName(Macro.Name) == Id;
@@ -293,6 +297,14 @@
   });
 }
 
+void MacroToEnumCallbacks::rememberExpressionToken(const Token ) {
+  std::string Id = getTokenName(MacroNameTok).str();
+  auto Pos = llvm::lower_bound(ExpressionNames, Id);
+  if (Pos == ExpressionNames.end() || *Pos != Id) {
+ExpressionNames.insert(Pos, Id);
+  }
+}
+
 void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -384,6 +396,8 @@
 void MacroToEnumCallbacks::MacroUndefined(const Token ,
   const MacroDefinition ,
   const MacroDirective *Undef) {
+  rememberExpressionToken(MacroNameTok);
+
   auto MatchesToken = [](const EnumMacro ) {
 return getTokenName(Macro.Name) == getTokenName(MacroNameTok);
   };
@@ -447,7 +461,19 @@
 CurrentFile->GuardScanner = IncludeGuard::IfGuard;
 }
 
+void MacroToEnumCallbacks::invalidateExpressionNames() {
+  for (const std::string  : ExpressionNames) {
+llvm::erase_if(Enums, [Id](const MacroList ) {
+  return llvm::any_of(MacroList, [](const EnumMacro ) {
+return getTokenName(Macro.Name) == Id;
+  });
+});
+  }
+}
+
 void MacroToEnumCallbacks::EndOfMainFile() {
+  invalidateExpressionNames();
+
   for (const MacroList  : Enums) {
 if (MacroList.empty())
   continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123887: [HLSL][clang][Driver] Fix test error for use SmallString::data instead SmallString::c_str.

2022-04-15 Thread Xiang Li via Phabricator via cfe-commits
python3kgae abandoned this revision.
python3kgae added a comment.

Thanks. Close this RP then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123887

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


[PATCH] D123887: [HLSL][clang][Driver] Fix test error for use SmallString::data instead SmallString::c_str.

2022-04-15 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

I already merged a fix to resolve the test errors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123887

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


[PATCH] D122865: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added a comment.

Created new patch to fix the test fail at https://reviews.llvm.org/D123887


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122865

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


[PATCH] D123887: [HLSL][clang][Driver] Fix test error for use SmallString::data instead SmallString::c_str.

2022-04-15 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added a reviewer: wolfgangp.
Herald added a project: All.
python3kgae 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/D123887

Files:
  clang/unittests/Driver/ToolChainTest.cpp


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -472,7 +472,8 @@
   Triple = TC.ComputeEffectiveClangTriple(Args);
   EXPECT_STREQ(Triple.c_str(), "unknown-unknown-shadermodel");
   EXPECT_EQ(Diags.getNumErrors(), 1u);
-  EXPECT_STREQ(DiagConsumer->Errors.back().data(), "invalid profile : 
pss_6_1");
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(),
+   "invalid profile : pss_6_1");
   Diags.Clear();
   DiagConsumer->clear();
 
@@ -481,7 +482,7 @@
   Triple = TC.ComputeEffectiveClangTriple(Args);
   EXPECT_STREQ(Triple.c_str(), "unknown-unknown-shadermodel");
   EXPECT_EQ(Diags.getNumErrors(), 2u);
-  EXPECT_STREQ(DiagConsumer->Errors.back().data(), "invalid profile : ps_6_x");
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(), "invalid profile : 
ps_6_x");
   Diags.Clear();
   DiagConsumer->clear();
 
@@ -490,7 +491,8 @@
   Triple = TC.ComputeEffectiveClangTriple(Args);
   EXPECT_STREQ(Triple.c_str(), "unknown-unknown-shadermodel");
   EXPECT_EQ(Diags.getNumErrors(), 3u);
-  EXPECT_STREQ(DiagConsumer->Errors.back().data(), "invalid profile : 
lib_6_1");
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(),
+   "invalid profile : lib_6_1");
   Diags.Clear();
   DiagConsumer->clear();
 
@@ -499,7 +501,7 @@
   Triple = TC.ComputeEffectiveClangTriple(Args);
   EXPECT_STREQ(Triple.c_str(), "unknown-unknown-shadermodel");
   EXPECT_EQ(Diags.getNumErrors(), 4u);
-  EXPECT_STREQ(DiagConsumer->Errors.back().data(), "invalid profile : foo");
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(), "invalid profile : foo");
   Diags.Clear();
   DiagConsumer->clear();
 }


Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -472,7 +472,8 @@
   Triple = TC.ComputeEffectiveClangTriple(Args);
   EXPECT_STREQ(Triple.c_str(), "unknown-unknown-shadermodel");
   EXPECT_EQ(Diags.getNumErrors(), 1u);
-  EXPECT_STREQ(DiagConsumer->Errors.back().data(), "invalid profile : pss_6_1");
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(),
+   "invalid profile : pss_6_1");
   Diags.Clear();
   DiagConsumer->clear();
 
@@ -481,7 +482,7 @@
   Triple = TC.ComputeEffectiveClangTriple(Args);
   EXPECT_STREQ(Triple.c_str(), "unknown-unknown-shadermodel");
   EXPECT_EQ(Diags.getNumErrors(), 2u);
-  EXPECT_STREQ(DiagConsumer->Errors.back().data(), "invalid profile : ps_6_x");
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(), "invalid profile : ps_6_x");
   Diags.Clear();
   DiagConsumer->clear();
 
@@ -490,7 +491,8 @@
   Triple = TC.ComputeEffectiveClangTriple(Args);
   EXPECT_STREQ(Triple.c_str(), "unknown-unknown-shadermodel");
   EXPECT_EQ(Diags.getNumErrors(), 3u);
-  EXPECT_STREQ(DiagConsumer->Errors.back().data(), "invalid profile : lib_6_1");
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(),
+   "invalid profile : lib_6_1");
   Diags.Clear();
   DiagConsumer->clear();
 
@@ -499,7 +501,7 @@
   Triple = TC.ComputeEffectiveClangTriple(Args);
   EXPECT_STREQ(Triple.c_str(), "unknown-unknown-shadermodel");
   EXPECT_EQ(Diags.getNumErrors(), 4u);
-  EXPECT_STREQ(DiagConsumer->Errors.back().data(), "invalid profile : foo");
+  EXPECT_STREQ(DiagConsumer->Errors.back().c_str(), "invalid profile : foo");
   Diags.Clear();
   DiagConsumer->clear();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120290: [Clang][OpenMP] Add the codegen support for `atomic compare capture`

2022-04-15 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 423198.
tianshilei1992 marked an inline comment as done.
tianshilei1992 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120290

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/OpenMP/atomic_compare_codegen.cpp

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


[PATCH] D123862: [Clang][OpenMP] Use bitfields for flags in `OMPAtomicDirective`

2022-04-15 Thread Shilei Tian 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 rGe8760b51ee0f: [Clang][OpenMP] Use bitfields for flags in 
`OMPAtomicDirective` (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123862

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp


Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2449,8 +2449,8 @@
 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
   VisitStmt(D);
   VisitOMPExecutableDirective(D);
-  D->IsXLHSInRHSPart = Record.readBool();
-  D->IsPostfixUpdate = Record.readBool();
+  D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
+  D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
 }
 
 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
Index: clang/lib/AST/StmtOpenMP.cpp
===
--- clang/lib/AST/StmtOpenMP.cpp
+++ clang/lib/AST/StmtOpenMP.cpp
@@ -875,8 +875,8 @@
   Dir->setUpdateExpr(Exprs.UE);
   Dir->setD(Exprs.D);
   Dir->setCond(Exprs.Cond);
-  Dir->IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart;
-  Dir->IsPostfixUpdate = Exprs.IsPostfixUpdate;
+  Dir->Flags.IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart ? 1 : 0;
+  Dir->Flags.IsPostfixUpdate = Exprs.IsPostfixUpdate ? 1 : 0;
   return Dir;
 }
 
Index: clang/include/clang/AST/StmtOpenMP.h
===
--- clang/include/clang/AST/StmtOpenMP.h
+++ clang/include/clang/AST/StmtOpenMP.h
@@ -2827,25 +2827,28 @@
 class OMPAtomicDirective : public OMPExecutableDirective {
   friend class ASTStmtReader;
   friend class OMPExecutableDirective;
-  /// Used for 'atomic update' or 'atomic capture' constructs. They may
-  /// have atomic expressions of forms
-  /// \code
-  /// x = x binop expr;
-  /// x = expr binop x;
-  /// \endcode
-  /// This field is true for the first form of the expression and false for the
-  /// second. Required for correct codegen of non-associative operations (like
-  /// << or >>).
-  bool IsXLHSInRHSPart = false;
-  /// Used for 'atomic update' or 'atomic capture' constructs. They may
-  /// have atomic expressions of forms
-  /// \code
-  /// v = x; ;
-  /// ; v = x;
-  /// \endcode
-  /// This field is true for the first(postfix) form of the expression and 
false
-  /// otherwise.
-  bool IsPostfixUpdate = false;
+
+  struct FlagTy {
+/// Used for 'atomic update' or 'atomic capture' constructs. They may
+/// have atomic expressions of forms:
+/// \code
+/// x = x binop expr;
+/// x = expr binop x;
+/// \endcode
+/// This field is 1 for the first form of the expression and 0 for the
+/// second. Required for correct codegen of non-associative operations 
(like
+/// << or >>).
+uint8_t IsXLHSInRHSPart : 1;
+/// Used for 'atomic update' or 'atomic capture' constructs. They may
+/// have atomic expressions of forms:
+/// \code
+/// v = x; ;
+/// ; v = x;
+/// \endcode
+/// This field is 1 for the first(postfix) form of the expression and 0
+/// otherwise.
+uint8_t IsPostfixUpdate : 1;
+  } Flags;
 
   /// Build directive with the given start and end location.
   ///
@@ -2956,10 +2959,10 @@
   /// Return true if helper update expression has form
   /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form
   /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
-  bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; }
+  bool isXLHSInRHSPart() const { return Flags.IsXLHSInRHSPart; }
   /// Return true if 'v' expression must be updated to original value of
   /// 'x', false if 'v' must be updated to the new value of 'x'.
-  bool isPostfixUpdate() const { return IsPostfixUpdate; }
+  bool isPostfixUpdate() const { return Flags.IsPostfixUpdate; }
   /// Get 'v' part of the associated expression/statement.
   Expr *getV() {
 return cast_or_null(Data->getChildren()[DataPositionTy::POS_V]);


Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2449,8 +2449,8 @@
 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
   VisitStmt(D);
   VisitOMPExecutableDirective(D);
-  D->IsXLHSInRHSPart = Record.readBool();
-  D->IsPostfixUpdate = Record.readBool();
+  D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
+  D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
 }
 
 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
Index: clang/lib/AST/StmtOpenMP.cpp

[clang] e8760b5 - [Clang][OpenMP] Use bitfields for flags in `OMPAtomicDirective`

2022-04-15 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-04-15T21:34:28-04:00
New Revision: e8760b51ee0f972587cb0af922a3f828ab6926d6

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

LOG: [Clang][OpenMP] Use bitfields for flags in `OMPAtomicDirective`

As suggested in D120290.

Reviewed By: ABataev

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

Added: 


Modified: 
clang/include/clang/AST/StmtOpenMP.h
clang/lib/AST/StmtOpenMP.cpp
clang/lib/Serialization/ASTReaderStmt.cpp

Removed: 




diff  --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 0aa318d84a93f..dfaf8b5a77385 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -2827,25 +2827,28 @@ class OMPOrderedDirective : public 
OMPExecutableDirective {
 class OMPAtomicDirective : public OMPExecutableDirective {
   friend class ASTStmtReader;
   friend class OMPExecutableDirective;
-  /// Used for 'atomic update' or 'atomic capture' constructs. They may
-  /// have atomic expressions of forms
-  /// \code
-  /// x = x binop expr;
-  /// x = expr binop x;
-  /// \endcode
-  /// This field is true for the first form of the expression and false for the
-  /// second. Required for correct codegen of non-associative operations (like
-  /// << or >>).
-  bool IsXLHSInRHSPart = false;
-  /// Used for 'atomic update' or 'atomic capture' constructs. They may
-  /// have atomic expressions of forms
-  /// \code
-  /// v = x; ;
-  /// ; v = x;
-  /// \endcode
-  /// This field is true for the first(postfix) form of the expression and 
false
-  /// otherwise.
-  bool IsPostfixUpdate = false;
+
+  struct FlagTy {
+/// Used for 'atomic update' or 'atomic capture' constructs. They may
+/// have atomic expressions of forms:
+/// \code
+/// x = x binop expr;
+/// x = expr binop x;
+/// \endcode
+/// This field is 1 for the first form of the expression and 0 for the
+/// second. Required for correct codegen of non-associative operations 
(like
+/// << or >>).
+uint8_t IsXLHSInRHSPart : 1;
+/// Used for 'atomic update' or 'atomic capture' constructs. They may
+/// have atomic expressions of forms:
+/// \code
+/// v = x; ;
+/// ; v = x;
+/// \endcode
+/// This field is 1 for the first(postfix) form of the expression and 0
+/// otherwise.
+uint8_t IsPostfixUpdate : 1;
+  } Flags;
 
   /// Build directive with the given start and end location.
   ///
@@ -2956,10 +2959,10 @@ class OMPAtomicDirective : public 
OMPExecutableDirective {
   /// Return true if helper update expression has form
   /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form
   /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
-  bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; }
+  bool isXLHSInRHSPart() const { return Flags.IsXLHSInRHSPart; }
   /// Return true if 'v' expression must be updated to original value of
   /// 'x', false if 'v' must be updated to the new value of 'x'.
-  bool isPostfixUpdate() const { return IsPostfixUpdate; }
+  bool isPostfixUpdate() const { return Flags.IsPostfixUpdate; }
   /// Get 'v' part of the associated expression/statement.
   Expr *getV() {
 return cast_or_null(Data->getChildren()[DataPositionTy::POS_V]);

diff  --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 15e13da27dd84..3535b0620ee50 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -875,8 +875,8 @@ OMPAtomicDirective::Create(const ASTContext , 
SourceLocation StartLoc,
   Dir->setUpdateExpr(Exprs.UE);
   Dir->setD(Exprs.D);
   Dir->setCond(Exprs.Cond);
-  Dir->IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart;
-  Dir->IsPostfixUpdate = Exprs.IsPostfixUpdate;
+  Dir->Flags.IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart ? 1 : 0;
+  Dir->Flags.IsPostfixUpdate = Exprs.IsPostfixUpdate ? 1 : 0;
   return Dir;
 }
 

diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index ed9f1d2b34289..281385ad9e7d9 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2449,8 +2449,8 @@ void 
ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
   VisitStmt(D);
   VisitOMPExecutableDirective(D);
-  D->IsXLHSInRHSPart = Record.readBool();
-  D->IsPostfixUpdate = Record.readBool();
+  D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
+  D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
 }
 
 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D123831: [POC][WIP] Use relative include in extract-api

2022-04-15 Thread Cyndy Ishida via Phabricator via cfe-commits
cishida added a comment.

> we might not always want to transform an absolute path because the resulting 
> relative include name might get remapped in a headermap, for example in test 
> known_files_only_hmap.c. But how does it work with modules where we need 
> relative includes? Is the setup in known_files_only_hmap even valid?

I think, in most cases, this shouldn't matter because if the header path input 
doesn't match the location stored in the header map, they should still have the 
same source content. The same should be true with header search resolution with 
modules & vfsoverlay


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123831

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


[clang] 33b604d - [OpenMP] Fix linting diagnostics in the linker wrapper

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

Author: Joseph Huber
Date: 2022-04-15T21:19:29-04:00
New Revision: 33b604d1c3017a6d09e47384566353efe7bbfe57

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

LOG: [OpenMP] Fix linting diagnostics in the linker wrapper

Summary:
A previous patch had some linter warnings that should've been addressed.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index d202b16516220..e187e57cd22c8 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -308,7 +308,7 @@ Error extractOffloadFiles(StringRef Contents, StringRef 
Prefix,
 createOutputFile(Prefix + "-" + Kind + "-" + Binary.getTriple() +
  "-" + Binary.getArch(),
  Suffix, TempFile))
-  return std::move(Err);
+  return Err;
 
 Expected> OutputOrErr =
 FileOutputBuffer::create(TempFile, Binary.getImage().size());
@@ -318,7 +318,7 @@ Error extractOffloadFiles(StringRef Contents, StringRef 
Prefix,
 std::copy(Binary.getImage().bytes_begin(), Binary.getImage().bytes_end(),
   Output->getBufferStart());
 if (Error E = Output->commit())
-  return std::move(E);
+  return E;
 
 DeviceFiles.emplace_back(Kind, Binary.getTriple(), Binary.getArch(),
  TempFile);



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


[PATCH] D122865: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

@wolfgangp I can't reproduce the failure locally, but I have a guess what's 
going wrong. I _think_ the issue is that the SmallStrings aren't null 
terminated and the cleared allocations aren't zero'd. I pushed a speculative 
fix in rG329abac134a3 
. 
Hopefully that fixes it. If not feel free to revert the changes, @python3kgae 
you'll have to diagnose further issues as I'll be afk all of next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122865

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


[clang] 329abac - Blind stab in the dark to fix a bot failure

2022-04-15 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-15T20:12:59-05:00
New Revision: 329abac134a35acc81bfab30a87130a3c208be2a

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

LOG: Blind stab in the dark to fix a bot failure

*fingers crossed*

Added: 


Modified: 
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index 3d9d266ef3161..a0823f3ba123a 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -375,9 +375,11 @@ TEST(DxcModeTest, TargetProfileValidation) {
   if (DiagLevel == DiagnosticsEngine::Level::Error) {
 Errors.emplace_back();
 Info.FormatDiagnostic(Errors.back());
+Errors.back() += '\0';
   } else {
 Msgs.emplace_back();
 Info.FormatDiagnostic(Msgs.back());
+Msgs.back() += '\0';
   }
 }
 void clear() override {



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


[PATCH] D122865: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

Hi, there seems to be a unit test failure, for example here 
.

/home/buildbot/as-worker-91/clang-with-lto-ubuntu/build/stage1/tools/clang/unittests/Driver/./ClangDriverTests
 --gtest_filter=DxcModeTest.TargetProfileValidation

/home/buildbot/as-worker-91/clang-with-lto-ubuntu/llvm-project/clang/unittests/Driver/ToolChainTest.cpp:484
Expected equality of these values:

  DiagConsumer->Errors.back().data()
Which is: "invalid profile : ps_6_x1"
  "invalid profile : ps_6_x"

/home/buildbot/as-worker-91/clang-with-lto-ubuntu/llvm-project/clang/unittests/Driver/ToolChainTest.cpp:502
Expected equality of these values:

  DiagConsumer->Errors.back().data()
Which is: "invalid profile : foo_6_1"
  "invalid profile : foo"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122865

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


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

2022-04-15 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 rG984a0dc38655: [OpenMP] Use new offloading binary when 
embedding offloading images (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122683

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/openmp-offload-gpu.c
  clang/test/Frontend/embed-object.c
  clang/test/Frontend/embed-object.ll
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  llvm/include/llvm/Object/OffloadBinary.h
  llvm/include/llvm/Transforms/Utils/ModuleUtils.h
  llvm/lib/Transforms/Utils/ModuleUtils.cpp

Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -265,15 +265,15 @@
 }
 
 void llvm::embedBufferInModule(Module , MemoryBufferRef Buf,
-   StringRef SectionName) {
-  // Embed the buffer into the module.
+   StringRef SectionName, Align Alignment) {
+  // Embed the memory buffer into the module.
   Constant *ModuleConstant = ConstantDataArray::get(
   M.getContext(), makeArrayRef(Buf.getBufferStart(), Buf.getBufferSize()));
   GlobalVariable *GV = new GlobalVariable(
-  M, ModuleConstant->getType(), true, GlobalValue::ExternalLinkage,
-  ModuleConstant, SectionName.drop_front());
+  M, ModuleConstant->getType(), true, GlobalValue::PrivateLinkage,
+  ModuleConstant, "llvm.embedded.object");
   GV->setSection(SectionName);
-  GV->setVisibility(GlobalValue::HiddenVisibility);
+  GV->setAlignment(Alignment);
 
   appendToCompilerUsed(M, GV);
 }
Index: llvm/include/llvm/Transforms/Utils/ModuleUtils.h
===
--- llvm/include/llvm/Transforms/Utils/ModuleUtils.h
+++ llvm/include/llvm/Transforms/Utils/ModuleUtils.h
@@ -14,6 +14,7 @@
 #define LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Alignment.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include  // for std::pair
 
@@ -109,7 +110,8 @@
 
 /// Embed the memory buffer \p Buf into the module \p M as a global using the
 /// specified section name.
-void embedBufferInModule(Module , MemoryBufferRef Buf, StringRef SectionName);
+void embedBufferInModule(Module , MemoryBufferRef Buf, StringRef SectionName,
+ Align Alignment = Align(1));
 
 class CallInst;
 namespace VFABI {
Index: llvm/include/llvm/Object/OffloadBinary.h
===
--- llvm/include/llvm/Object/OffloadBinary.h
+++ llvm/include/llvm/Object/OffloadBinary.h
@@ -73,6 +73,7 @@
 
   ImageKind getImageKind() const { return TheEntry->TheImageKind; }
   OffloadKind getOffloadKind() const { return TheEntry->TheOffloadKind; }
+  uint32_t getVersion() const { return TheHeader->Version; }
   uint32_t getFlags() const { return TheEntry->Flags; }
   uint64_t getSize() const { return TheHeader->Size; }
 
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Object/ArchiveWriter.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/OffloadBinary.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
@@ -146,8 +147,8 @@
 static codegen::RegisterCodeGenFlags CodeGenFlags;
 
 /// Magic section string that marks the existence of offloading data. The
-/// section string will be formatted as `.llvm.offloading..`.
-#define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading."
+/// section will contain one or more offloading binaries stored contiguously.
+#define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
 
 /// Information for a device offloading file extracted from the host.
 struct DeviceFile {
@@ -201,16 +202,6 @@
 llvm::errs() << *IC << (std::next(IC) != IE ? " " : "\n");
 }
 
-static StringRef getDeviceFileExtension(StringRef DeviceTriple,
-bool IsBitcode = false) {
-  Triple TheTriple(DeviceTriple);
-  if (TheTriple.isAMDGPU() || IsBitcode)
-return "bc";
-  if (TheTriple.isNVPTX())
-return "cubin";
-  return "o";
-}
-
 std::string getMainExecutable(const char *Name) {
   void *Ptr = (void *)(intptr_t)
   auto COWPath = sys::fs::getMainExecutable(Name, Ptr);
@@ -289,6 +280,55 @@
   GV->setSection("llvm.metadata");
 }
 
+/// Attempts to extract all the embedded device images contained inside the
+/// 

[clang] 984a0dc - [OpenMP] Use new offloading binary when embedding offloading images

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

Author: Joseph Huber
Date: 2022-04-15T20:35:26-04:00
New Revision: 984a0dc386553f28068716a087d65ccf8a92889b

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

LOG: [OpenMP] Use new offloading binary when embedding offloading images

The previous patch introduced the offloading binary format so we can
store some metada along with the binary image. This patch introduces
using this inside the linker wrapper and Clang instead of the previous
method that embedded the metadata in the section name.

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/openmp-offload-gpu.c
clang/test/Frontend/embed-object.c
clang/test/Frontend/embed-object.ll
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
llvm/include/llvm/Object/OffloadBinary.h
llvm/include/llvm/Transforms/Utils/ModuleUtils.h
llvm/lib/Transforms/Utils/ModuleUtils.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 128ca2f5df3c3..59b8895257703 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -276,9 +276,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// CUDA runtime back-end for incorporating them into host-side object file.
   std::string CudaGpuBinaryFileName;
 
-  /// List of filenames and section name pairs passed in using the
-  /// -fembed-offload-object option to embed device-side offloading objects 
into
-  /// the host as a named section. Input passed in as ','
+  /// List of filenames and metadata passed in using the -fembed-offload-object
+  /// option to embed device-side offloading objects into the host as a named
+  /// section. Input passed in as 'filename,kind,triple,arch'.
+  ///
+  /// NOTE: This will need to be expanded whenever we want to pass in more
+  ///   metadata, at some point this should be its own clang tool.
   std::vector OffloadObjects;
 
   /// The name of the file to which the backend should save YAML optimization

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index c78ea45384d72..c53858acb2106 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -39,6 +39,7 @@
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/SubtargetFeature.h"
 #include "llvm/MC/TargetRegistry.h"
+#include "llvm/Object/OffloadBinary.h"
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
@@ -1206,22 +1207,33 @@ void clang::EmbedObject(llvm::Module *M, const 
CodeGenOptions ,
 return;
 
   for (StringRef OffloadObject : CGOpts.OffloadObjects) {
-if (OffloadObject.count(',') != 1)
-  Diags.Report(Diags.getCustomDiagID(
-  DiagnosticsEngine::Error, "Invalid string pair for embedding '%0'"))
-  << OffloadObject;
-auto FilenameAndSection = OffloadObject.split(',');
+SmallVector ObjectFields;
+OffloadObject.split(ObjectFields, ',');
+
+if (ObjectFields.size() != 4) {
+  auto DiagID = Diags.getCustomDiagID(
+  DiagnosticsEngine::Error, "Expected at least four arguments '%0'");
+  Diags.Report(DiagID) << OffloadObject;
+  return;
+}
+
 llvm::ErrorOr> ObjectOrErr =
-llvm::MemoryBuffer::getFileOrSTDIN(FilenameAndSection.first);
+llvm::MemoryBuffer::getFileOrSTDIN(ObjectFields[0]);
 if (std::error_code EC = ObjectOrErr.getError()) {
   auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
   "could not open '%0' for embedding");
-  Diags.Report(DiagID) << FilenameAndSection.first;
+  Diags.Report(DiagID) << ObjectFields[0];
   return;
 }
 
-SmallString<128> SectionName(
-{".llvm.offloading.", FilenameAndSection.second});
-llvm::embedBufferInModule(*M, **ObjectOrErr, SectionName);
+OffloadBinary::OffloadingImage Image{};
+Image.TheImageKind = getImageKind(ObjectFields[0].rsplit(".").second);
+Image.TheOffloadKind = getOffloadKind(ObjectFields[1]);
+Image.StringData = {{"triple", ObjectFields[2]}, {"arch", 
ObjectFields[3]}};
+Image.Image = **ObjectOrErr;
+
+std::unique_ptr OffloadBuffer = OffloadBinary::write(Image);
+llvm::embedBufferInModule(*M, *OffloadBuffer, ".llvm.offloading",
+  Align(OffloadBinary::getAlignment()));
   }
 }

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 8aefcaeed37dc..6e00771ff2acf 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ 

[clang] cac8116 - [OpenMP] Don't manually strip sections in the linker wrapper

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

Author: Joseph Huber
Date: 2022-04-15T20:35:25-04:00
New Revision: cac81161ed1386b32443e13ab513c6a3d081d6a7

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

LOG: [OpenMP] Don't manually strip sections in the linker wrapper

Summary:
The changes in D122987 ensures that the offloading sections always have
the SHF_EXCLUDE flag. This means that we do not need to manually strip
these sections for ELF or COFF targets.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 2dc93ae0988e4..a11174b424203 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -65,7 +65,7 @@ static cl::OptionCategory
 static cl::opt StripSections(
 "strip-sections", cl::ZeroOrMore,
 cl::desc("Strip offloading sections from the host object file."),
-cl::init(true), cl::cat(ClangLinkerWrapperCategory));
+cl::init(false), cl::cat(ClangLinkerWrapperCategory));
 
 static cl::opt LinkerUserPath("linker-path", cl::Required,
cl::desc("Path of linker binary"),



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


[PATCH] D123885: Revert "Revert "Revert "[clang][pp] adds '#pragma include_instead'"""

2022-04-15 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: rsmith, aaron.ballman.
Herald added subscribers: dexonsmith, usaxena95, kadircet, arphaman.
Herald added a project: All.
cjdb requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

> Includes regression test for problem noted by @hans.
> is reverts commit 973de71 
> .
>
> Differential Revision: https://reviews.llvm.org/D106898

Feature implemented as-is is fairly expensive and hasn't been used by
libc++. A potential reimplementation is possible if libc++ become
interested in this feature again.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123885

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/pseudo/lib/Lex.cpp
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Lexer.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/PreprocessorLexer.h
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/PCH/ms-pch-macro-include_instead-regression.c
  clang/test/Preprocessor/Inputs/include_instead/bad-syntax.h
  clang/test/Preprocessor/Inputs/include_instead/file-not-found.h
  clang/test/Preprocessor/Inputs/include_instead/non-system-header.h
  clang/test/Preprocessor/Inputs/include_instead/private-x.h
  clang/test/Preprocessor/Inputs/include_instead/private1.h
  clang/test/Preprocessor/Inputs/include_instead/private2.h
  clang/test/Preprocessor/Inputs/include_instead/private3.h
  clang/test/Preprocessor/Inputs/include_instead/public-after.h
  clang/test/Preprocessor/Inputs/include_instead/public-before.h
  clang/test/Preprocessor/Inputs/include_instead/public-empty.h
  clang/test/Preprocessor/include_instead.cpp
  clang/test/Preprocessor/include_instead_file_not_found.cpp

Index: clang/test/Preprocessor/include_instead_file_not_found.cpp
===
--- clang/test/Preprocessor/include_instead_file_not_found.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -I %S/Inputs %s
-#include 
Index: clang/test/Preprocessor/include_instead.cpp
===
--- clang/test/Preprocessor/include_instead.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -I %S/Inputs %s
-
-#include 
-#include 
-
-#include 
-// expected-error@-1{{header '' is an implementation detail; #include '' instead}}
-
-#include "include_instead/private2.h"
-// expected-error@-1{{header '"include_instead/private2.h"' is an implementation detail; #include either '' or '"include_instead/public-after.h"' instead}}
-
-#include 
-// expected-error@-1{{header '' is an implementation detail; #include one of {'', '', '"include_instead/public-before.h"'} instead}}
-
-#include 
-#include 
Index: clang/test/Preprocessor/Inputs/include_instead/public-empty.h
===
--- clang/test/Preprocessor/Inputs/include_instead/public-empty.h
+++ /dev/null
@@ -1 +0,0 @@
-// This file simply needs to exist.
Index: clang/test/Preprocessor/Inputs/include_instead/public-before.h
===
--- clang/test/Preprocessor/Inputs/include_instead/public-before.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#pragma GCC system_header
-
-#include  // no warning expected
-#include  // no warning expected
-#include  // no warning expected
Index: clang/test/Preprocessor/Inputs/include_instead/public-after.h
===
--- clang/test/Preprocessor/Inputs/include_instead/public-after.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#include 
-#pragma GCC system_header
Index: clang/test/Preprocessor/Inputs/include_instead/private3.h
===
--- clang/test/Preprocessor/Inputs/include_instead/private3.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#pragma GCC system_header
-
-#pragma clang include_instead()
-#pragma clang include_instead()
-#pragma clang include_instead("include_instead/public-before.h")
Index: clang/test/Preprocessor/Inputs/include_instead/private2.h
===
--- clang/test/Preprocessor/Inputs/include_instead/private2.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#pragma GCC system_header
-
-#pragma clang include_instead()
-#pragma clang include_instead("include_instead/public-after.h")
Index: clang/test/Preprocessor/Inputs/include_instead/private1.h
===
--- clang/test/Preprocessor/Inputs/include_instead/private1.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#pragma GCC 

[PATCH] D123884: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 423190.
python3kgae added a comment.

Fix format in Options.td.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123884

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/CodeGen/CGHLSLRuntime.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/HLSL.cpp
  clang/lib/Driver/ToolChains/HLSL.h
  clang/test/CodeGenHLSL/validator_version.hlsl
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -504,4 +504,97 @@
   DiagConsumer->clear();
 }
 
+TEST(DxcModeTest, ValidatorVersionValidation) {
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct SimpleDiagnosticConsumer : public DiagnosticConsumer {
+void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+  const Diagnostic ) override {
+  if (DiagLevel == DiagnosticsEngine::Level::Error) {
+Errors.emplace_back();
+Info.FormatDiagnostic(Errors.back());
+Errors.back().append({0});
+  } else {
+Msgs.emplace_back();
+Info.FormatDiagnostic(Msgs.back());
+Msgs.back().append({0});
+  }
+}
+void clear() override {
+  Msgs.clear();
+  Errors.clear();
+  DiagnosticConsumer::clear();
+}
+std::vector> Msgs;
+std::vector> Errors;
+  };
+
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  InMemoryFileSystem->addFile("foo.hlsl", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+
+  auto *DiagConsumer = new SimpleDiagnosticConsumer;
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer);
+  Driver TheDriver("/bin/clang", "", Diags, "", InMemoryFileSystem);
+  std::unique_ptr C(
+  TheDriver.BuildCompilation({"clang", "--driver-mode=dxc", "foo.hlsl"}));
+  EXPECT_TRUE(C);
+  EXPECT_TRUE(!C->containsError());
+
+  auto  = C->getDefaultToolChain();
+  bool ContainsError = false;
+  auto Args = TheDriver.ParseArgStrings({"-validator-version", "1.1"}, false,
+ContainsError);
+  EXPECT_FALSE(ContainsError);
+  auto DAL = std::make_unique(Args);
+  for (auto *A : Args) {
+DAL->append(A);
+  }
+  auto *TranslatedArgs =
+  TC.TranslateArgs(*DAL, "0", Action::OffloadKind::OFK_None);
+  EXPECT_NE(TranslatedArgs, nullptr);
+  if (TranslatedArgs) {
+auto *A = TranslatedArgs->getLastArg(
+clang::driver::options::OPT_dxil_validator_version);
+EXPECT_NE(A, nullptr);
+if (A) {
+  EXPECT_STREQ(A->getValue(), "1.1");
+}
+  }
+  EXPECT_EQ(Diags.getNumErrors(), 0);
+
+  // Invalid tests.
+  Args = TheDriver.ParseArgStrings({"-validator-version", "0.1"}, false,
+   ContainsError);
+  EXPECT_FALSE(ContainsError);
+  DAL = std::make_unique(Args);
+  for (auto *A : Args) {
+DAL->append(A);
+  }
+  TranslatedArgs = TC.TranslateArgs(*DAL, "0", Action::OffloadKind::OFK_None);
+  EXPECT_EQ(Diags.getNumErrors(), 1);
+  EXPECT_STREQ(DiagConsumer->Errors.back().data(),
+   "invalid validator version : 0.1\nIf validator major version is "
+   "0, minor version must also be 0.");
+  Diags.Clear();
+  DiagConsumer->clear();
+
+  Args = TheDriver.ParseArgStrings({"-validator-version", "1"}, false,
+   ContainsError);
+  EXPECT_FALSE(ContainsError);
+  DAL = std::make_unique(Args);
+  for (auto *A : Args) {
+DAL->append(A);
+  }
+  TranslatedArgs = TC.TranslateArgs(*DAL, "0", Action::OffloadKind::OFK_None);
+  EXPECT_EQ(Diags.getNumErrors(), 2);
+  EXPECT_STREQ(DiagConsumer->Errors.back().data(),
+   "invalid validator version : 1\nFormat of validator version is "
+   "\".\" (ex:\"1.4\").");
+  Diags.Clear();
+  DiagConsumer->clear();
+}
+
 } // end anonymous namespace.
Index: clang/test/CodeGenHLSL/validator_version.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/validator_version.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang -cc1 -S -triple dxil-pc-shadermodel6.3-library -S -emit-llvm -xhlsl -validator-version 1.1 -o - %s | FileCheck %s
+
+// CHECK:!"dx.valver", ![[valver:[0-9]+]]}
+// CHECK:![[valver]] = !{i32 1, i32 1}
+
+float bar(float a, float b);
+
+float foo(float a, float b) {
+  return bar(a, b);
+}
\ No newline at end of file
Index: clang/lib/Driver/ToolChains/HLSL.h

[clang] fc30901 - Extend support for std::move etc to also cover std::as_const and

2022-04-15 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2022-04-15T16:31:39-07:00
New Revision: fc3090109643af8d2da9822d0f99c84742b9c877

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

LOG: Extend support for std::move etc to also cover std::as_const and
std::addressof, plus the libstdc++-specific std::__addressof.

This brings us to parity with the corresponding GCC behavior.

Remove STDBUILTIN macro that ended up not being used.

Added: 


Modified: 
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/Analysis/BodyFarm.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/Analysis/inner-pointer.cpp
clang/test/CodeGenCXX/builtin-std-move.cpp
clang/test/CodeGenCXX/builtins.cpp
clang/test/SemaCXX/builtin-std-move.cpp
clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index c853229f13970..c22957e14de7d 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -103,8 +103,7 @@
 //  V:N: -> requires vectors of at least N bits to be legal
 //  C -> callback behavior: argument N is called with argument
 //  M_0, ..., M_k as payload
-//  z -> this is a C++ standard library function in (possibly-versioned)
-//   namespace std; implied by STDBUILTIN
+//  z -> this is a function in (possibly-versioned) namespace std
 //  FIXME: gcc has nonnull
 
 #if defined(BUILTIN) && !defined(LIBBUILTIN)
@@ -115,10 +114,6 @@
 #  define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
-#if defined(BUILTIN) && !defined(STDBUILTIN)
-#  define STDBUILTIN(ID, TYPE, ATTRS, HEADER) LIBBUILTIN(ID, TYPE, "zf" ATTRS, 
HEADER, CXX_LANG)
-#endif
-
 // Standard libc/libm functions:
 BUILTIN(__builtin_atan2 , "ddd"  , "Fne")
 BUILTIN(__builtin_atan2f, "fff"  , "Fne")
@@ -1551,10 +1546,14 @@ LIBBUILTIN(_Block_object_assign, "vv*vC*iC", "f", 
"Blocks.h", ALL_LANGUAGES)
 LIBBUILTIN(_Block_object_dispose, "vvC*iC", "f", "Blocks.h", ALL_LANGUAGES)
 // FIXME: Also declare NSConcreteGlobalBlock and NSConcreteStackBlock.
 
-// C++11
-STDBUILTIN(move, "v&", "ncTh", "utility")
-STDBUILTIN(move_if_noexcept, "v&", "ncTh", "utility")
-STDBUILTIN(forward, "v&", "ncTh", "utility")
+// C++ standard library builtins in namespace 'std'.
+LIBBUILTIN(addressof, "v*v&", "zfncTh", "memory", CXX_LANG)
+// Synonym for addressof used internally by libstdc++.
+LANGBUILTIN(__addressof, "v*v&", "zfncT", CXX_LANG)
+LIBBUILTIN(as_const, "v&", "zfncTh", "utility", CXX_LANG)
+LIBBUILTIN(forward, "v&", "zfncTh", "utility", CXX_LANG)
+LIBBUILTIN(move, "v&", "zfncTh", "utility", CXX_LANG)
+LIBBUILTIN(move_if_noexcept, "v&", "zfncTh", "utility", CXX_LANG)
 
 // Annotation function
 BUILTIN(__builtin_annotation, "v.", "tn")

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cebd24302f1d1..f71f576f9ff47 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6587,7 +6587,7 @@ def warn_self_move : Warning<
   InGroup, DefaultIgnore;
 
 def err_builtin_move_forward_unsupported : Error<
-  "unsupported signature for '%select{std::move|std::forward}0'">;
+  "unsupported signature for %q0">;
 def err_use_of_unaddressable_function : Error<
   "taking address of non-addressable standard library function">;
 // FIXME: This should also be in -Wc++23-compat once we have it.

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index ce007edca0fc6..410fc8285bb65 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8295,9 +8295,10 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, 
const VarDecl *VD) {
 
 bool LValueExprEvaluator::VisitCallExpr(const CallExpr *E) {
   switch (unsigned BuiltinOp = E->getBuiltinCallee()) {
+  case Builtin::BIas_const:
+  case Builtin::BIforward:
   case Builtin::BImove:
   case Builtin::BImove_if_noexcept:
-  case Builtin::BIforward:
 if (cast(E->getCalleeDecl())->isConstexpr())
   return Visit(E->getArg(0));
 break;
@@ -9084,6 +9085,8 @@ static bool isOneByteCharacterType(QualType T) {
 bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
 unsigned BuiltinOp) {
   switch (BuiltinOp) {
+  case Builtin::BIaddressof:
+  case Builtin::BI__addressof:
   case Builtin::BI__builtin_addressof:
 return evaluateLValue(E->getArg(0), Result);
   case Builtin::BI__builtin_assume_aligned: {

diff  --git 

[PATCH] D123884: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/Driver/Options.td:6701
 
+
 class DXCJoinedOrSeparate : Option<["/", "-"], name,

delete



Comment at: clang/include/clang/Driver/Options.td:6715
+  Group, Flags<[DXCOption, NoXarchOption, CC1Option, HelpHidden]>,
+  HelpText<"Override validator version for module.  Format:  
;Default: DXIL.dll version or current internal version.">,
+  MarshallingInfoString>;

Remove period from the last sentence of HelpText.
Use just one space for sentence separator. See other options for the prevailing 
style stating the format.

I see many dxil related options have violated this and I am going to fix them 
soon.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:843
+  // HLSL related end of code gen work items.
+  if (LangOpts.HLSL) {
+getHLSLRuntime().finishCodeGen();

https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements



Comment at: llvm/test/Transforms/OpenMP/icv_tracking.ll:2
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --function-signature
-; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s
+; RUN: opt -S -openmp-opt-cgscc < %s | FileCheck %s
+; RUN: opt -S -passes=openmp-opt-cgscc < %s | FileCheck %s

`opt -S -foo` tests the new PM as well due to `EnableNewPassManager`.

The old style (inherited from legacy pass manager) run lines are being phased 
out. Don't add new one.


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

https://reviews.llvm.org/D123884

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


[PATCH] D123884: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 423189.
python3kgae edited reviewers, added: steven_wu, JonChesterfield, sscalpone, 
rnk, bogner, MaskRay, dexonsmith, nikic; removed: jdoerfert, sstefan1, baziotis.
python3kgae edited subscribers, added: beanz; removed: mgorny, arphaman, kuter, 
jdoerfert, MaskRay, okura, sstefan1, dexonsmith, ormris.
Herald added a subscriber: StephenFan.

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

https://reviews.llvm.org/D123884

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/CodeGen/CGHLSLRuntime.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/HLSL.cpp
  clang/lib/Driver/ToolChains/HLSL.h
  clang/test/CodeGenHLSL/validator_version.hlsl
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -504,4 +504,97 @@
   DiagConsumer->clear();
 }
 
+TEST(DxcModeTest, ValidatorVersionValidation) {
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct SimpleDiagnosticConsumer : public DiagnosticConsumer {
+void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+  const Diagnostic ) override {
+  if (DiagLevel == DiagnosticsEngine::Level::Error) {
+Errors.emplace_back();
+Info.FormatDiagnostic(Errors.back());
+Errors.back().append({0});
+  } else {
+Msgs.emplace_back();
+Info.FormatDiagnostic(Msgs.back());
+Msgs.back().append({0});
+  }
+}
+void clear() override {
+  Msgs.clear();
+  Errors.clear();
+  DiagnosticConsumer::clear();
+}
+std::vector> Msgs;
+std::vector> Errors;
+  };
+
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  InMemoryFileSystem->addFile("foo.hlsl", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+
+  auto *DiagConsumer = new SimpleDiagnosticConsumer;
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer);
+  Driver TheDriver("/bin/clang", "", Diags, "", InMemoryFileSystem);
+  std::unique_ptr C(
+  TheDriver.BuildCompilation({"clang", "--driver-mode=dxc", "foo.hlsl"}));
+  EXPECT_TRUE(C);
+  EXPECT_TRUE(!C->containsError());
+
+  auto  = C->getDefaultToolChain();
+  bool ContainsError = false;
+  auto Args = TheDriver.ParseArgStrings({"-validator-version", "1.1"}, false,
+ContainsError);
+  EXPECT_FALSE(ContainsError);
+  auto DAL = std::make_unique(Args);
+  for (auto *A : Args) {
+DAL->append(A);
+  }
+  auto *TranslatedArgs =
+  TC.TranslateArgs(*DAL, "0", Action::OffloadKind::OFK_None);
+  EXPECT_NE(TranslatedArgs, nullptr);
+  if (TranslatedArgs) {
+auto *A = TranslatedArgs->getLastArg(
+clang::driver::options::OPT_dxil_validator_version);
+EXPECT_NE(A, nullptr);
+if (A) {
+  EXPECT_STREQ(A->getValue(), "1.1");
+}
+  }
+  EXPECT_EQ(Diags.getNumErrors(), 0);
+
+  // Invalid tests.
+  Args = TheDriver.ParseArgStrings({"-validator-version", "0.1"}, false,
+   ContainsError);
+  EXPECT_FALSE(ContainsError);
+  DAL = std::make_unique(Args);
+  for (auto *A : Args) {
+DAL->append(A);
+  }
+  TranslatedArgs = TC.TranslateArgs(*DAL, "0", Action::OffloadKind::OFK_None);
+  EXPECT_EQ(Diags.getNumErrors(), 1);
+  EXPECT_STREQ(DiagConsumer->Errors.back().data(),
+   "invalid validator version : 0.1\nIf validator major version is "
+   "0, minor version must also be 0.");
+  Diags.Clear();
+  DiagConsumer->clear();
+
+  Args = TheDriver.ParseArgStrings({"-validator-version", "1"}, false,
+   ContainsError);
+  EXPECT_FALSE(ContainsError);
+  DAL = std::make_unique(Args);
+  for (auto *A : Args) {
+DAL->append(A);
+  }
+  TranslatedArgs = TC.TranslateArgs(*DAL, "0", Action::OffloadKind::OFK_None);
+  EXPECT_EQ(Diags.getNumErrors(), 2);
+  EXPECT_STREQ(DiagConsumer->Errors.back().data(),
+   "invalid validator version : 1\nFormat of validator version is "
+   "\".\" (ex:\"1.4\").");
+  Diags.Clear();
+  DiagConsumer->clear();
+}
+
 } // end anonymous namespace.
Index: clang/test/CodeGenHLSL/validator_version.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/validator_version.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang -cc1 -S -triple dxil-pc-shadermodel6.3-library -S -emit-llvm -xhlsl -validator-version 1.1 -o - %s | FileCheck %s
+
+// CHECK:!"dx.valver", ![[valver:[0-9]+]]}

[PATCH] D123884: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added a project: clang.
Herald added subscribers: ormris, dexonsmith, okura, jdoerfert, kuter, 
arphaman, mgorny.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1, MaskRay.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.
Herald added a project: LLVM.

The DXIL validator version option(/validator-version) decide the validator 
version when compile hlsl.
The format is major.minor like 1.0.

In normal case, the value of validator version should be got from DXIL 
validator. Before we got DXIL validator ready for llvm/main, DXIL validator 
version option is added first to set validator version.

It will affect code generation for DXIL, so it is treated as a code gen option.

A new member std::string DxilValidatorVersion is added to clang::CodeGenOptions.

Then CGHLSLRuntime is added to clang::CodeGenModule.
It is used to translate clang::CodeGenOptions::DxilValidatorVersion into a 
ModuleFlag under key "dx.valver" at end of clang code generation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123884

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/CodeGen/CGHLSLRuntime.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/HLSL.cpp
  clang/lib/Driver/ToolChains/HLSL.h
  clang/test/CodeGenHLSL/validator_version.hlsl
  clang/unittests/Driver/ToolChainTest.cpp
  llvm/include/llvm/Transforms/IPO/Attributor.h
  llvm/test/Transforms/Attributor/ArgumentPromotion/2008-02-01-ReturnAttrs.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/2008-07-02-array-indexing.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/2008-09-07-CGUpdate.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll
  
llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/X86/thiscall.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/aggregate-promote.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/alignment.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/alloca-as.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/array.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/attrs.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/basictest.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/byval-2.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/byval.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/chained.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow2.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/crash.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/fp80.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/inalloca.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/live_called_from_dead_2.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/musttail.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/pr32917.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/profile.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/reserve-tbaa.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll
  llvm/test/Transforms/Attributor/ArgumentPromotion/variadic.ll
  llvm/test/Transforms/Attributor/IPConstantProp/2008-06-09-WeakProp.ll
  llvm/test/Transforms/Attributor/IPConstantProp/2009-09-24-byval-ptr.ll
  llvm/test/Transforms/Attributor/IPConstantProp/PR16052.ll
  llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
  llvm/test/Transforms/Attributor/IPConstantProp/PR43857.ll
  llvm/test/Transforms/Attributor/IPConstantProp/arg-count-mismatch.ll
  llvm/test/Transforms/Attributor/IPConstantProp/comdat-ipo.ll
  llvm/test/Transforms/Attributor/IPConstantProp/multiple_callbacks.ll
  llvm/test/Transforms/Attributor/IPConstantProp/musttail-call.ll
  llvm/test/Transforms/Attributor/IPConstantProp/openmp_parallel_for.ll
  llvm/test/Transforms/Attributor/IPConstantProp/pthreads.ll
  llvm/test/Transforms/Attributor/IPConstantProp/recursion.ll
  llvm/test/Transforms/Attributor/IPConstantProp/remove-call-inst.ll
  llvm/test/Transforms/Attributor/IPConstantProp/return-argument.ll
  llvm/test/Transforms/Attributor/IPConstantProp/return-constant.ll
  llvm/test/Transforms/Attributor/IPConstantProp/return-constants.ll
  
llvm/test/Transforms/Attributor/IPConstantProp/solve-after-each-resolving-undefs-for-function.ll
  llvm/test/Transforms/Attributor/IPConstantProp/thread_local_acs.ll
  

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

2022-04-15 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122683

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


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

2022-04-15 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 423176.
jhuber6 added a comment.

Addressing comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122683

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/openmp-offload-gpu.c
  clang/test/Frontend/embed-object.c
  clang/test/Frontend/embed-object.ll
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  llvm/include/llvm/Object/OffloadBinary.h
  llvm/include/llvm/Transforms/Utils/ModuleUtils.h
  llvm/lib/Transforms/Utils/ModuleUtils.cpp

Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -265,15 +265,15 @@
 }
 
 void llvm::embedBufferInModule(Module , MemoryBufferRef Buf,
-   StringRef SectionName) {
-  // Embed the buffer into the module.
+   StringRef SectionName, Align Alignment) {
+  // Embed the memory buffer into the module.
   Constant *ModuleConstant = ConstantDataArray::get(
   M.getContext(), makeArrayRef(Buf.getBufferStart(), Buf.getBufferSize()));
   GlobalVariable *GV = new GlobalVariable(
-  M, ModuleConstant->getType(), true, GlobalValue::ExternalLinkage,
-  ModuleConstant, SectionName.drop_front());
+  M, ModuleConstant->getType(), true, GlobalValue::PrivateLinkage,
+  ModuleConstant, "llvm.embedded.object");
   GV->setSection(SectionName);
-  GV->setVisibility(GlobalValue::HiddenVisibility);
+  GV->setAlignment(Alignment);
 
   appendToCompilerUsed(M, GV);
 }
Index: llvm/include/llvm/Transforms/Utils/ModuleUtils.h
===
--- llvm/include/llvm/Transforms/Utils/ModuleUtils.h
+++ llvm/include/llvm/Transforms/Utils/ModuleUtils.h
@@ -14,6 +14,7 @@
 #define LLVM_TRANSFORMS_UTILS_MODULEUTILS_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Alignment.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include  // for std::pair
 
@@ -109,7 +110,8 @@
 
 /// Embed the memory buffer \p Buf into the module \p M as a global using the
 /// specified section name.
-void embedBufferInModule(Module , MemoryBufferRef Buf, StringRef SectionName);
+void embedBufferInModule(Module , MemoryBufferRef Buf, StringRef SectionName,
+ Align Alignment = Align(1));
 
 class CallInst;
 namespace VFABI {
Index: llvm/include/llvm/Object/OffloadBinary.h
===
--- llvm/include/llvm/Object/OffloadBinary.h
+++ llvm/include/llvm/Object/OffloadBinary.h
@@ -73,6 +73,7 @@
 
   ImageKind getImageKind() const { return TheEntry->TheImageKind; }
   OffloadKind getOffloadKind() const { return TheEntry->TheOffloadKind; }
+  uint32_t getVersion() const { return TheHeader->Version; }
   uint32_t getFlags() const { return TheEntry->Flags; }
   uint64_t getSize() const { return TheHeader->Size; }
 
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Object/ArchiveWriter.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/OffloadBinary.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
@@ -146,8 +147,8 @@
 static codegen::RegisterCodeGenFlags CodeGenFlags;
 
 /// Magic section string that marks the existence of offloading data. The
-/// section string will be formatted as `.llvm.offloading..`.
-#define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading."
+/// section will contain one or more offloading binaries stored contiguously.
+#define OFFLOAD_SECTION_MAGIC_STR ".llvm.offloading"
 
 /// Information for a device offloading file extracted from the host.
 struct DeviceFile {
@@ -201,16 +202,6 @@
 llvm::errs() << *IC << (std::next(IC) != IE ? " " : "\n");
 }
 
-static StringRef getDeviceFileExtension(StringRef DeviceTriple,
-bool IsBitcode = false) {
-  Triple TheTriple(DeviceTriple);
-  if (TheTriple.isAMDGPU() || IsBitcode)
-return "bc";
-  if (TheTriple.isNVPTX())
-return "cubin";
-  return "o";
-}
-
 std::string getMainExecutable(const char *Name) {
   void *Ptr = (void *)(intptr_t)
   auto COWPath = sys::fs::getMainExecutable(Name, Ptr);
@@ -289,6 +280,55 @@
   GV->setSection("llvm.metadata");
 }
 
+/// Attempts to extract all the embedded device images contained inside the
+/// buffer \p Contents. The buffer is expected to contain a valid offloading
+/// binary format.
+Error extractOffloadFiles(StringRef Contents, StringRef Prefix,
+ 

[clang] 2a404cd - [randstruct] Force errors for all platforms

2022-04-15 Thread Bill Wendling via cfe-commits

Author: Bill Wendling
Date: 2022-04-15T15:17:07-07:00
New Revision: 2a404cdfd8bc75de593ce0e15fff0a7a0a18ec1c

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

LOG: [randstruct] Force errors for all platforms

Added: 


Modified: 
clang/test/Sema/init-randomized-struct.c

Removed: 




diff  --git a/clang/test/Sema/init-randomized-struct.c 
b/clang/test/Sema/init-randomized-struct.c
index 87842e1f19e80..7ce19165921e3 100644
--- a/clang/test/Sema/init-randomized-struct.c
+++ b/clang/test/Sema/init-randomized-struct.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only 
-frandomize-layout-seed=1234567890abcdef
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Werror 
-frandomize-layout-seed=1234567890abcdef
 
 // Initializing a randomized structure requires a designated initializer,
 // otherwise the element ordering will be off. The only exceptions to this rule



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


[PATCH] D99893: [WIP] Replace std::forward & std::move by cast expressions during Sema

2022-04-15 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin abandoned this revision.
cor3ntin added a comment.
Herald added a project: All.

Richard committed a better approach so this is no longer needed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99893

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


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

2022-04-15 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/test/Frontend/embed-object.ll:6
+; CHECK: @[[OBJECT:.+]] = private constant [120 x i8] 
c"\10\FF\10\AD{{.*}}\00", section ".llvm.offloading", align 8
+; CHECK: @llvm.compiler.used = appending global [2 x i8*] [i8* @x, i8* 
getelementptr inbounds ([120 x i8], [120 x i8]* @[[OBJECT]], i32 0, i32 0)], 
section "llvm.metadata"
 

Can we salvage the test intention and embed two objects?



Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:311
+
+  assert(Binary.getVersion() == 1 && "Incompatible device image version");
+

This should be a proper conditional and error check.



Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:316
+  StringRef Suffix =
+  getImageKindName(static_cast(Binary.getImageKind()));
 

Why is the cast at the call site not in the callee? Are these casts even 
necessary at all?



Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:469
+  Offset += Binary.getSize();
+}
 ToBeDeleted.push_back();

Isn't this 99% the same as above, from `offset = 0` to the end?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122683

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


[clang] a571f82 - Update test to handle opaque pointers flag flip.

2022-04-15 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2022-04-15T14:51:30-07:00
New Revision: a571f82a50416b767fd3cce0fb5027bb5dfec58c

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

LOG: Update test to handle opaque pointers flag flip.

Added: 


Modified: 
clang/test/CodeGenCXX/builtin-std-move.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/builtin-std-move.cpp 
b/clang/test/CodeGenCXX/builtin-std-move.cpp
index 29107c4e162a8..51498002cd987 100644
--- a/clang/test/CodeGenCXX/builtin-std-move.cpp
+++ b/clang/test/CodeGenCXX/builtin-std-move.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - -std=c++17 %s | 
FileCheck %s --implicit-check-not=@_ZSt4move
+// RUN: %clang_cc1 -no-opaque-pointers -triple=x86_64-linux-gnu -emit-llvm -o 
- -std=c++17 %s | FileCheck %s --implicit-check-not=@_ZSt4move
 
 namespace std {
   template constexpr T &(T ) { return 
static_cast(val); }



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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

  section : increase in bytes for clang built with full debuginfo : %% of total 
binary size
  .debug_loclists   317782  0.0250%
  .debug_abbrev 88590   0.0070%
  .debug_info   100708340.7929%
  .debug_rnglists   143320  0.0113%
  .debug_str_offsets1090516 0.0859%
  .debug_str7789440 0.6132%
  .debug_addr   3611552 0.2843%
  .debug_line   -187964 -0.0148%
  .debug_line_str   20430.0002%


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-15 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D123534#3454354 , @dblaikie wrote:

> This seems like it would significantly introduce debug info size for at least 
> some kinds of code - have you done any size measurements of this change?

With `-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=On`:

- Before the patch: `clang` was 1247264656 bytes
- After the patch: `clang` was 1270191696 bytes (or, a 1.84% increase)

> What does the resulting DWARF look like?

Each string DI ends up looking like a regular global variable (i.e. a 
`DW_TAG_variable` entry in `.debug_info`):

  $ llvm-dwarfdump --debug-info
  0x0032:   DW_TAG_variable
  DW_AT_name  (".str")
  DW_AT_type  (0x003e ".str")
  DW_AT_decl_file ("/tmp/file.c")
  DW_AT_decl_line (3)
  DW_AT_location  (DW_OP_addrx 0x1)
  DW_AT_linkage_name  (".str")

(and obviously an entry in the `.debug_addr` referenced by the `DW_AT_location` 
at index `0x1`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


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

2022-04-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 423169.
royjacobson marked an inline comment as done.
royjacobson added a comment.

Rebase


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 ) {} // 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 

[PATCH] D109239: Add support for floating-option `-ffp-eval-method` and for new `pragma clang fp eval-method`

2022-04-15 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

The updates in `clang/test/Preprocessor` kind of suggest this was an expected 
change, though...


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

https://reviews.llvm.org/D109239

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


[PATCH] D109239: Add support for floating-option `-ffp-eval-method` and for new `pragma clang fp eval-method`

2022-04-15 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

In D109239#3454084 , @zahiraam wrote:

> In D109239#3453770 , @glandium 
> wrote:
>
>> Is it expected that `__FLT_EVAL_METHOD__` is not set at all anymore by 
>> default after this change?
>
> @glandium would you mind giving a reproducer. We might have missed a flow 
> path where the macro is undefined.

`clang -dM -E - < /dev/null | grep __FLT_EVAL_METHOD__`


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

https://reviews.llvm.org/D109239

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


[PATCH] D123345: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

2022-04-15 Thread Richard Smith - zygoloid 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 rG64c045e25b84: Treat `std::move`, `forward`, and 
`move_if_noexcept` as builtins. (authored by rsmith).

Changed prior to commit:
  https://reviews.llvm.org/D123345?vs=423164=423165#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123345

Files:
  clang/docs/CommandGuide/clang.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Basic/Builtins.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Analysis/use-after-move.cpp
  clang/test/CodeGenCXX/builtin-std-move.cpp
  clang/test/CodeGenCXX/microsoft-abi-throw.cpp
  clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
  clang/test/SemaCXX/builtin-std-move.cpp
  clang/test/SemaCXX/unqualified-std-call-fixits.cpp
  clang/test/SemaCXX/unqualified-std-call.cpp
  clang/test/SemaCXX/warn-consumed-analysis.cpp

Index: clang/test/SemaCXX/warn-consumed-analysis.cpp
===
--- clang/test/SemaCXX/warn-consumed-analysis.cpp
+++ clang/test/SemaCXX/warn-consumed-analysis.cpp
@@ -953,12 +953,12 @@
 namespace std {
   void move();
   template
-  void move(T&&);
+  T &(T&);
 
   namespace __1 {
 void move();
 template
-void move(T&&);
+T &(T&);
   }
 }
 
@@ -971,7 +971,7 @@
   void test() {
 x.move();
 std::move();
-std::move(x);
+std::move(x); // expected-warning {{ignoring return value}}
 std::__1::move();
 std::__1::move(x);
   }
Index: clang/test/SemaCXX/unqualified-std-call.cpp
===
--- clang/test/SemaCXX/unqualified-std-call.cpp
+++ clang/test/SemaCXX/unqualified-std-call.cpp
@@ -1,17 +1,17 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s -Wno-unused-value
 
 namespace std {
 
 template 
 void dummy(T &&) {}
 template 
-void move(T &&) {}
+T &(T &) { return x; }
 template 
 void move(T &&, U &&) {}
 
 inline namespace __1 {
 template 
-void forward(T &) {}
+T (T ) { return x; }
 } // namespace __1
 
 struct foo {};
Index: clang/test/SemaCXX/unqualified-std-call-fixits.cpp
===
--- clang/test/SemaCXX/unqualified-std-call-fixits.cpp
+++ clang/test/SemaCXX/unqualified-std-call-fixits.cpp
@@ -6,9 +6,9 @@
 
 namespace std {
 
-void move(auto &) {}
+int &(auto &) { return a; }
 
-void forward(auto ) {}
+int &(auto ) { return a; }
 
 } // namespace std
 
@@ -16,8 +16,8 @@
 
 void f() {
   int i = 0;
-  move(i); // expected-warning {{unqualified call to std::move}}
-  // CHECK: {{^}}  std::
-  forward(i); // expected-warning {{unqualified call to std::forward}}
-  // CHECK: {{^}}  std::
+  (void)move(i); // expected-warning {{unqualified call to std::move}}
+  // CHECK: {{^}}  (void)std::move
+  (void)forward(i); // expected-warning {{unqualified call to std::forward}}
+  // CHECK: {{^}}  (void)std::forward
 }
Index: clang/test/SemaCXX/builtin-std-move.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/builtin-std-move.cpp
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s -DNO_CONSTEXPR
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace std {
+#ifndef NO_CONSTEXPR
+#define CONSTEXPR constexpr
+#else
+#define CONSTEXPR
+#endif
+
+  template CONSTEXPR T &(T ) {
+static_assert(T::moveable, "instantiated move"); // expected-error {{no member named 'moveable' in 'B'}}
+ // expected-error@-1 {{no member named 'moveable' in 'C'}}
+return static_cast(x);
+  }
+
+  // Unrelated move functions are not the builtin.
+  template CONSTEXPR int move(T, T) { return 5; }
+
+  template struct ref { using type = T&; };
+  template struct ref { using type = T&&; };
+
+  template CONSTEXPR auto move_if_noexcept(T ) -> typename ref(x)))>::type {
+static_assert(T::moveable, "instantiated move_if_noexcept"); // expected-error {{no member named 'moveable' in 'B'}}
+return static_cast(x)))>::type>(x);
+  }
+
+  template struct remove_reference { using type = T; };
+  template struct remove_reference { using type = T; };
+  template struct remove_reference { using type = T; };
+
+  template CONSTEXPR T &(typename 

[clang] 64c045e - Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

2022-04-15 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2022-04-15T14:09:45-07:00
New Revision: 64c045e25b8471bbb572bd29159c294a82a86a25

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

LOG: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

We still require these functions to be declared before they can be used,
but don't instantiate their definitions unless their addresses are
taken. Instead, code generation, constant evaluation, and static
analysis are given direct knowledge of their effect.

This change aims to reduce various costs associated with these functions
-- per-instantiation memory costs, compile time and memory costs due to
creating out-of-line copies and inlining them, code size at -O0, and so
on -- so that they are not substantially more expensive than a cast.
Most of these improvements are very small, but I measured a 3% decrease
in -O0 object file size for a simple C++ source file using the standard
library after this change.

We now automatically infer the `const` and `nothrow` attributes on these
now-builtin functions, in particular meaning that we get a warning for
an unused call to one of these functions.

In C++20 onwards, we disallow taking the addresses of these functions,
per the C++20 "addressable function" rule. In earlier language modes, a
compatibility warning is produced but the address can still be taken.

The same infrastructure is extended to the existing MSVC builtin
`__GetExceptionInfo`, which is now only recognized in namespace `std`
like it always should have been.

Reviewed By: aaron.ballman

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

Added: 
clang/test/CodeGenCXX/builtin-std-move.cpp
clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
clang/test/SemaCXX/builtin-std-move.cpp

Modified: 
clang/docs/CommandGuide/clang.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/Builtins.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/Analysis/BodyFarm.cpp
clang/lib/Basic/Builtins.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/Analysis/use-after-move.cpp
clang/test/CodeGenCXX/microsoft-abi-throw.cpp
clang/test/SemaCXX/unqualified-std-call-fixits.cpp
clang/test/SemaCXX/unqualified-std-call.cpp
clang/test/SemaCXX/warn-consumed-analysis.cpp

Removed: 




diff  --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index aec62789a43e6..658a30458043e 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -252,8 +252,24 @@ Language Selection and Mode Options
 
 .. option:: -fno-builtin
 
- Disable special handling and optimizations of builtin functions like
- :c:func:`strlen` and :c:func:`malloc`.
+ Disable special handling and optimizations of well-known library functions,
+ like :c:func:`strlen` and :c:func:`malloc`.
+
+.. option:: -fno-builtin-
+
+ Disable special handling and optimizations for the specific library function.
+ For example, ``-fno-builtin-strlen`` removes any special handling for the
+ :c:func:`strlen` library function.
+
+.. option:: -fno-builtin-std-
+
+ Disable special handling and optimizations for the specific C++ standard
+ library function in namespace ``std``. For example,
+ ``-fno-builtin-std-move_if_noexcept`` removes any special handling for the
+ :cpp:func:`std::move_if_noexcept` library function.
+
+ For C standard library functions that the C++ standard library also provides
+ in namespace ``std``, use :option:`-fno-builtin-\` instead.
 
 .. option:: -fmath-errno
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c72028c718586..b2a5f6c366dd5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -230,7 +230,10 @@ C2x Feature Support
 C++ Language Changes in Clang
 -
 
-- ...
+- Improved ``-O0`` code generation for calls to ``std::move``, 
``std::forward``,
+  and ``std::move_if_noexcept``. These are now treated as compiler builtins and
+  implemented directly, rather than instantiating the definition from the
+  standard library.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 62e82cd36321d..c853229f13970 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -81,7 +81,9 @@
 //   builtin even if type doesn't 

[PATCH] D123874: [Clang][IA] support -generate-unused-section-symbols={yes|no}

2022-04-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> Add support to clang (-Wa,-generate-unused-section-symbols={yes|no}) and 
> llvm-mc.



> This feature might be used by the Linux kernel. 
> https://lore.kernel.org/linux-toolchains/ylluqpk4cwzeh...@hirez.programming.kicks-ass.net/



> This has been supported by GNU binutils since 2.36. 
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1408485ce69f844dcd7ded093a8

AFAICT GNU as never gets an option named `-generate-unused-section-symbols=yes`.
It just has a quirk that interprets nearly all `-g*` options as `-g`, which 
indicates generation of some compile units for ELF symbols with the help of 
`.size` directives.
It's very different from generating unused section symbols.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123874

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


[PATCH] D123345: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

2022-04-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6577-6578
+// FIXME: This should also be in -Wc++23-compat once we have it.
+def warn_use_of_unaddressable_function : Warning<
+  "taking address of non-addressable standard library function">,
+  InGroup;

aaron.ballman wrote:
> aaron.ballman wrote:
> > Thank you for making this one on by default :-)
> Thoughts on this one?
Sorry, I was looking at your comments over email and didn't see the suggestion. 
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123345

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


[PATCH] D123345: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

2022-04-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 423164.
rsmith marked 3 inline comments as done.
rsmith added a comment.

- Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123345

Files:
  clang/docs/CommandGuide/clang.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Basic/Builtins.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Analysis/use-after-move.cpp
  clang/test/CodeGenCXX/builtin-std-move.cpp
  clang/test/CodeGenCXX/microsoft-abi-throw.cpp
  clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
  clang/test/SemaCXX/builtin-std-move.cpp
  clang/test/SemaCXX/unqualified-std-call-fixits.cpp
  clang/test/SemaCXX/unqualified-std-call.cpp
  clang/test/SemaCXX/warn-consumed-analysis.cpp

Index: clang/test/SemaCXX/warn-consumed-analysis.cpp
===
--- clang/test/SemaCXX/warn-consumed-analysis.cpp
+++ clang/test/SemaCXX/warn-consumed-analysis.cpp
@@ -953,12 +953,12 @@
 namespace std {
   void move();
   template
-  void move(T&&);
+  T &(T&);
 
   namespace __1 {
 void move();
 template
-void move(T&&);
+T &(T&);
   }
 }
 
@@ -971,7 +971,7 @@
   void test() {
 x.move();
 std::move();
-std::move(x);
+std::move(x); // expected-warning {{ignoring return value}}
 std::__1::move();
 std::__1::move(x);
   }
Index: clang/test/SemaCXX/unqualified-std-call.cpp
===
--- clang/test/SemaCXX/unqualified-std-call.cpp
+++ clang/test/SemaCXX/unqualified-std-call.cpp
@@ -1,17 +1,17 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall -std=c++11 %s -Wno-unused-value
 
 namespace std {
 
 template 
 void dummy(T &&) {}
 template 
-void move(T &&) {}
+T &(T &) { return x; }
 template 
 void move(T &&, U &&) {}
 
 inline namespace __1 {
 template 
-void forward(T &) {}
+T (T ) { return x; }
 } // namespace __1
 
 struct foo {};
Index: clang/test/SemaCXX/unqualified-std-call-fixits.cpp
===
--- clang/test/SemaCXX/unqualified-std-call-fixits.cpp
+++ clang/test/SemaCXX/unqualified-std-call-fixits.cpp
@@ -6,9 +6,9 @@
 
 namespace std {
 
-void move(auto &) {}
+int &(auto &) { return a; }
 
-void forward(auto ) {}
+int &(auto ) { return a; }
 
 } // namespace std
 
@@ -16,8 +16,8 @@
 
 void f() {
   int i = 0;
-  move(i); // expected-warning {{unqualified call to std::move}}
-  // CHECK: {{^}}  std::
-  forward(i); // expected-warning {{unqualified call to std::forward}}
-  // CHECK: {{^}}  std::
+  (void)move(i); // expected-warning {{unqualified call to std::move}}
+  // CHECK: {{^}}  (void)std::move
+  (void)forward(i); // expected-warning {{unqualified call to std::forward}}
+  // CHECK: {{^}}  (void)std::forward
 }
Index: clang/test/SemaCXX/builtin-std-move.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/builtin-std-move.cpp
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s -DNO_CONSTEXPR
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace std {
+#ifndef NO_CONSTEXPR
+#define CONSTEXPR constexpr
+#else
+#define CONSTEXPR
+#endif
+
+  template CONSTEXPR T &(T ) {
+static_assert(T::moveable, "instantiated move"); // expected-error {{no member named 'moveable' in 'B'}}
+ // expected-error@-1 {{no member named 'moveable' in 'C'}}
+return static_cast(x);
+  }
+
+  // Unrelated move functions are not the builtin.
+  template CONSTEXPR int move(T, T) { return 5; }
+
+  template struct ref { using type = T&; };
+  template struct ref { using type = T&&; };
+
+  template CONSTEXPR auto move_if_noexcept(T ) -> typename ref(x)))>::type {
+static_assert(T::moveable, "instantiated move_if_noexcept"); // expected-error {{no member named 'moveable' in 'B'}}
+return static_cast(x)))>::type>(x);
+  }
+
+  template struct remove_reference { using type = T; };
+  template struct remove_reference { using type = T; };
+  template struct remove_reference { using type = T; };
+
+  template CONSTEXPR T &(typename remove_reference::type ) {
+static_assert(T::moveable, "instantiated forward"); // expected-error {{no member named 'moveable' in 'B'}}
+// 

[PATCH] D123300: [Clang] Enable opaque pointers by default

2022-04-15 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123300

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


[PATCH] D123642: [clang codegen] Assume arguments of __atomic_* are aligned.

2022-04-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D123642#3450129 , @xbolva00 wrote:

> Do you have any comments related to this issue by gcc devs that this is a 
> "known" bug?

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87237#c1, from someone in the GCC 
MAINTAINERS file, suggests that this is either a GCC bug or a GCC documentation 
bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123642

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


[PATCH] D123874: [Clang][IA] support -generate-unused-section-symbols={yes|no}

2022-04-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I wish we don't do this. 
https://sourceware.org/pipermail/binutils/2022-March/119940.html (`RFC: GAS: 
Add option to generate unused section symbols`):

> This problem was fixed in the kernel (and backported by distros to their

kernels if binutils was updated); it's fairly simplistic changes.

> I don't see the need for returning (optionally) to the old behaviour again.  
> I mean, at the time, when 2.36 came out, sure, the patch might have made 
> sense, but now?

LLVM integrated assembler has stayed the current behavior for many years.
Having the feature would only benefit the next major release 15.0.0. Many 
releases before 15.0.0 are still supported, so some conditional compilation is 
needed, making the feature less useful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123874

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


[PATCH] D123300: [Clang] Enable opaque pointers by default

2022-04-15 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D123300#3454215 , @aeubanks wrote:

>   $ cat /tmp/a.ll 
>   target triple = "thumbv8-unknown-linux-gnueabihf"
>   
>   define void @zot() {
>   bb:
> br label %bb1
>   
>   bb1:  ; preds = %bb1, %bb
> %tmp = phi ptr [ null, %bb ], [ %tmp2, %bb1 ]
> store ptr %tmp, ptr %tmp, align 4
> %tmp2 = getelementptr inbounds ptr, ptr %tmp, i32 1
> %tmp3 = icmp eq ptr %tmp2, null
> br i1 %tmp3, label %bb4, label %bb1
>   
>   bb4:  ; preds = %bb1
> ret void
>   }
>   $ opt -passes=loop-vectorize /tmp/a.ll -disable-output
>   # crash

Should be fixed by 73f5d7d0d6ec0e 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123300

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


[PATCH] D123874: [Clang][IA] support -generate-unused-section-symbols={yes|no}

2022-04-15 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added a reviewer: MaskRay.
Herald added subscribers: StephenFan, dexonsmith, hiraditya.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

GNU binutils has added support for explicitly retaining (yes option) or
dropping (no option) STT_SECTION symbols from the symbols table via
assembler option -generate-unused-section-symbols={yes|no}.

Add support to clang (`-Wa,-generate-unused-section-symbols={yes|no}`)
and llvm-mc.

This feature might be used by the Linux kernel.
https://lore.kernel.org/linux-toolchains/ylluqpk4cwzeh...@hirez.programming.kicks-ass.net/
This has been supported by GNU binutils since 2.36.
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1408485ce69f844dcd7ded093a8


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123874

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/as-options.s
  clang/test/Misc/cc1as-keep-section-symbols.s
  clang/tools/driver/cc1as_main.cpp
  llvm/include/llvm/MC/MCAsmInfo.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/test/MC/X86/keep-section-symbols.s
  llvm/tools/llvm-mc/llvm-mc.cpp

Index: llvm/tools/llvm-mc/llvm-mc.cpp
===
--- llvm/tools/llvm-mc/llvm-mc.cpp
+++ llvm/tools/llvm-mc/llvm-mc.cpp
@@ -212,6 +212,10 @@
 static cl::opt NoExecStack("no-exec-stack",
  cl::desc("File doesn't need an exec stack"),
  cl::cat(MCCategory));
+static cl::opt
+KeepSectionSymbols("keep-section-symbols",
+   cl::desc("Do not discard section symbols"),
+   cl::cat(MCCategory));
 
 enum ActionType {
   AC_AsLex,
@@ -401,6 +405,7 @@
   assert(MAI && "Unable to create target asm info!");
 
   MAI->setRelaxELFRelocations(RelaxELFRel);
+  MAI->setKeepSectionSymbols(KeepSectionSymbols);
 
   if (CompressDebugSections != DebugCompressionType::None) {
 if (!zlib::isAvailable()) {
Index: llvm/test/MC/X86/keep-section-symbols.s
===
--- /dev/null
+++ llvm/test/MC/X86/keep-section-symbols.s
@@ -0,0 +1,10 @@
+# RUN: llvm-mc -keep-section-symbols %s -triple x86_64-linux-gnu -filetype=obj -o %t
+# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=CHECK-KEEP
+
+# RUN: llvm-mc %s -triple x86_64-linux-gnu -filetype=obj -o %t
+# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=CHECK-DROP
+
+# CHECK-KEEP: SECTION LOCAL DEFAULT {{[0-9]+}} .text
+# CHECK-DROP-NOT: SECTION LOCAL DEFAULT {{[0-9]+}} .text
+.text
+  nop
Index: llvm/lib/MC/ELFObjectWriter.cpp
===
--- llvm/lib/MC/ELFObjectWriter.cpp
+++ llvm/lib/MC/ELFObjectWriter.cpp
@@ -610,7 +610,10 @@
 return false;
 
   if (Symbol.getType() == ELF::STT_SECTION)
-return false;
+return Layout.getAssembler()
+.getContext()
+.getAsmInfo()
+->getKeepSectionSymbols();
 
   return true;
 }
Index: llvm/include/llvm/MC/MCAsmInfo.h
===
--- llvm/include/llvm/MC/MCAsmInfo.h
+++ llvm/include/llvm/MC/MCAsmInfo.h
@@ -518,6 +518,9 @@
   // X86_64 ELF.
   bool RelaxELFRelocations = true;
 
+  // If true, emit ELF STT_SECTION symbols.
+  bool KeepSectionSymbols = false;
+
   // If true, then the lexer and expression parser will support %neg(),
   // %hi(), and similar unary operators.
   bool HasMipsExpressions = false;
@@ -853,6 +856,8 @@
 
   bool canRelaxRelocations() const { return RelaxELFRelocations; }
   void setRelaxELFRelocations(bool V) { RelaxELFRelocations = V; }
+  bool getKeepSectionSymbols() const { return KeepSectionSymbols; }
+  void setKeepSectionSymbols(bool V) { KeepSectionSymbols = V; }
   bool hasMipsExpressions() const { return HasMipsExpressions; }
   bool needsFunctionDescriptors() const { return NeedsFunctionDescriptors; }
   bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
Index: clang/tools/driver/cc1as_main.cpp
===
--- clang/tools/driver/cc1as_main.cpp
+++ clang/tools/driver/cc1as_main.cpp
@@ -136,6 +136,7 @@
   unsigned NoWarn : 1;
   unsigned IncrementalLinkerCompatible : 1;
   unsigned EmbedBitcode : 1;
+  unsigned KeepSectionSymbols : 1;
 
   /// The name of the relocation model to use.
   std::string RelocationModel;
@@ -300,6 +301,7 @@
   Opts.IncrementalLinkerCompatible =
   Args.hasArg(OPT_mincremental_linker_compatible);
   Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
+  Opts.KeepSectionSymbols = Args.hasArg(OPT_keep_section_symbols);
 
   // EmbedBitcode Option. If -fembed-bitcode is enabled, set the flag.
   // 

[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

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

In D122983#3454632 , @rsmith wrote:

> In D122983#3454508 , @aaron.ballman 
> wrote:
>
>> In D122983#3454494 , @jyknight 
>> wrote:
>>
>>> In D122983#3454406 , 
>>> @aaron.ballman wrote:
>>>
 Out of curiosity -- do you think we should remove the `DefaultIgnore` in 
 C89 mode so that we warn by default there (perhaps as a follow up)? Also, 
 I presume you expect `diag::ext_implicit_lib_function_decl` to behave the 
 same way (warn in C89, warn-as-err in C99 and up) as part of this patch?
>
> I think it would make sense to include the C89 warning in `-Wc99-compat`, but 
> I agree with James that it doesn't seem worthwhile to enable it by default.

Ah, that's a good idea for a follow-up, thanks!

>> I feel a bit more strongly that implicit builtins should be handled the same 
>> as other implicit functions (in terms of `DefaultError` behavior), unless 
>> there's some scenarios I'm not thinking of.
>
> I'm not sure which case you mean by "implicit builtins". Two cases seem 
> relevant:
>
> - `ext_implicit_lib_function_decl`, for things like using `strlen` without 
> including its header; I think that should behave the same as using any other 
> undeclared function name (error by default in C99 onwards, error with no 
> warning flag in C2x onwards even though we would synthesize the correct 
> prototype).

Great, this was the one I was talking about, and that's the approach I'd like 
to take with it. I'll have that in the next revision.

> - `warn_builtin_unknown`, for things like using 
> `__builtin_no_such_builtin_exists()` (a function name starting `__builtin_` 
> that is not a known builtin and hasn't been declared), which is currently a 
> warning-as-error in all language modes; I think that should stay an error by 
> default in all modes, and I'd be happy to see it turn into a harder error 
> (with no warning flag), whether that happens only in C2x onwards, in C99 
> onwards, or in all modes.

Okay, I hadn't touched that one because it was already default error. I'm happy 
to try to turn it into a hard error in a followup patch.

Thanks for the feedback!


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

https://reviews.llvm.org/D122983

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


[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D122983#3454508 , @aaron.ballman 
wrote:

> In D122983#3454494 , @jyknight 
> wrote:
>
>> In D122983#3454406 , 
>> @aaron.ballman wrote:
>>
>>> Out of curiosity -- do you think we should remove the `DefaultIgnore` in 
>>> C89 mode so that we warn by default there (perhaps as a follow up)? Also, I 
>>> presume you expect `diag::ext_implicit_lib_function_decl` to behave the 
>>> same way (warn in C89, warn-as-err in C99 and up) as part of this patch?

I think it would make sense to include the C89 warning in `-Wc99-compat`, but I 
agree with James that it doesn't seem worthwhile to enable it by default.

> I feel a bit more strongly that implicit builtins should be handled the same 
> as other implicit functions (in terms of `DefaultError` behavior), unless 
> there's some scenarios I'm not thinking of.

I'm not sure which case you mean by "implicit builtins". Two cases seem 
relevant:

- `ext_implicit_lib_function_decl`, for things like using `strlen` without 
including its header; I think that should behave the same as using any other 
undeclared function name (error by default in C99 onwards, error with no 
warning flag in C2x onwards even though we would synthesize the correct 
prototype).
- `warn_builtin_unknown`, for things like using 
`__builtin_no_such_builtin_exists()` (a function name starting `__builtin_` 
that is not a known builtin and hasn't been declared), which is currently a 
warning-as-error in all language modes; I think that should stay an error by 
default in all modes, and I'd be happy to see it turn into a harder error (with 
no warning flag), whether that happens only in C2x onwards, in C99 onwards, or 
in all modes.


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

https://reviews.llvm.org/D122983

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


[PATCH] D123682: [clang-tblgen] Automatically document options values

2022-04-15 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@aaron.ballman Any thoughs on the above suggestion? I'd be happy to adopt any 
of those :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123682

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


[PATCH] D121959: [clang] Add missing diagnostics for invalid overloads of multiversion functions in C.

2022-04-15 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.

> This might've caused a regression? 
> (https://github.com/llvm/llvm-project/issues/54892)

@dblaikie, it most definitely did. Note that I'm the author of the patch that 
introduced the regression, the reporter of the regression, and the assignee for 
fixing the regression ;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121959

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


[PATCH] D123345: Treat `std::move`, `forward`, and `move_if_noexcept` as builtins.

2022-04-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D123345#3453037 , @rnk wrote:

> Generally speaking, this sounds like a good idea to me. One time in 2019 I 
> used -ftime-trace+ClangBuildAnalyzer and it told me that std::unique_ptr was 
> the most expensive template 
>  because it is 
> instantiated so much. Those results don't even capture the -O0 object file 
> size impact.
>
> In D123345#3452933 , @rsmith wrote:
>
>> In D123345#3452496 , 
>> @aaron.ballman wrote:
>>
>>> Do you have ideas on how we can improve the debugging checkpoint behavior 
>>> (if at all)?
>>
>> I think we just live with it, like we do for other builtin functions. (There 
>> might be things we can do by emitting inlining info into the debug info. If 
>> we do that, we should presumably do it for all builtin lib functions.)
>
> Honestly, I don't think it's worth the debug info bytes to describe these 
> inlined call sites. Debug info isn't free.

+1 there - and also these operations/intrinsics produce no instructions, so far 
as I understand/know - so for now, LLVM's got to way to represent that anyway 
(there's some talk in DWARF about how to have multiple "states" for a single 
instruction location (so, eg, you could step in/out of an inlined function even 
though you stay at exactly the same instruction))


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123345

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


[PATCH] D121959: [clang] Add missing diagnostics for invalid overloads of multiversion functions in C.

2022-04-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

This might've caused a regression? 
(https://github.com/llvm/llvm-project/issues/54892)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121959

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


[PATCH] D123763: [randstruct] Enforce using a designated init for a randomized struct

2022-04-15 Thread Bill Wendling 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 rGaed923b1246a: [randstruct] Enforce using a designated init 
for a randomized struct (authored by void).

Changed prior to commit:
  https://reviews.llvm.org/D123763?vs=423139=423151#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123763

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/init-randomized-struct.c

Index: clang/test/Sema/init-randomized-struct.c
===
--- /dev/null
+++ clang/test/Sema/init-randomized-struct.c
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -frandomize-layout-seed=1234567890abcdef
+
+// Initializing a randomized structure requires a designated initializer,
+// otherwise the element ordering will be off. The only exceptions to this rule
+// are:
+//
+//- A structure with only one element, and
+//- A structure initialized with "{0}".
+//
+// These are well-defined situations where the field ordering doesn't affect
+// the result.
+
+typedef void (*func_ptr)();
+
+void foo(void);
+void bar(void);
+void baz(void);
+void gaz(void);
+
+struct test {
+  func_ptr a;
+  func_ptr b;
+  func_ptr c;
+  func_ptr d;
+  func_ptr e;
+  func_ptr f;
+  func_ptr g;
+} __attribute__((randomize_layout));
+
+struct test t1 = {}; // This should be fine per WG14 N2900 (in C23) + our extension handling of it in earlier modes
+struct test t2 = { 0 }; // This should also be fine per C99 6.7.8p19
+struct test t3 = { .f = baz, .b = bar, .g = gaz, .a = foo }; // Okay
+struct test t4 = { .a = foo, bar, baz }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
+
+struct other_test {
+  func_ptr a;
+  func_ptr b[3];
+  func_ptr c;
+} __attribute__((randomize_layout));
+
+struct other_test t5 = { .a = foo, .b[0] = foo }; // Okay
+struct other_test t6 = { .a = foo, .b[0] = foo, bar, baz }; // Okay
+struct other_test t7 = { .a = foo, .b = { foo, bar, baz } }; // Okay
+struct other_test t8 = { baz, bar, gaz, foo }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
+struct other_test t9 = { .a = foo, .b[0] = foo, bar, baz, gaz }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
+
+struct empty_test {
+} __attribute__((randomize_layout));
+
+struct empty_test t10 = {}; // Okay
+
+struct degen_test {
+  func_ptr a;
+} __attribute__((randomize_layout));
+
+struct degen_test t11 = { foo }; // Okay
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2123,6 +2123,7 @@
   // worthwhile to skip over the rest of the initializer, though.
   RecordDecl *RD = DeclType->castAs()->getDecl();
   RecordDecl::field_iterator FieldEnd = RD->field_end();
+  size_t NumRecordFields = std::distance(RD->field_begin(), RD->field_end());
   bool CheckForMissingFields =
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
@@ -2172,6 +2173,35 @@
   break;
 }
 
+// Check if this is an initializer of forms:
+//
+//   struct foo f = {};
+//   struct foo g = {0};
+//
+// These are okay for randomized structures. [C99 6.7.8p19]
+//
+// Also, if there is only one element in the structure, we allow something
+// like this, because it's really not randomized in the tranditional sense.
+//
+//   struct foo h = {bar};
+auto IsZeroInitializer = [&](const Expr *I) {
+  if (IList->getNumInits() == 1) {
+if (NumRecordFields == 1)
+  return true;
+if (const auto *IL = dyn_cast(I))
+  return IL->getValue().isZero();
+  }
+  return false;
+};
+
+// Don't allow non-designated initializers on randomized structures.
+if (RD->isRandomized() && !IsZeroInitializer(Init)) {
+  if (!VerifyOnly)
+SemaRef.Diag(InitLoc, diag::err_non_designated_init_used);
+  hadError = true;
+  break;
+}
+
 // We've already initialized a member of a union. We're done.
 if (InitializedSomething && DeclType->isUnionType())
   break;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11602,7 +11602,9 @@
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
 
-// Layout randomization warning.
+// Layout randomization diagnostics.
+def err_non_designated_init_used : Error<
+  "a randomized struct can only be initialized with a designated 

[clang] aed923b - [randstruct] Enforce using a designated init for a randomized struct

2022-04-15 Thread Bill Wendling via cfe-commits

Author: Bill Wendling
Date: 2022-04-15T12:29:32-07:00
New Revision: aed923b1246ac38335b222b89594516fcf0d6385

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

LOG: [randstruct] Enforce using a designated init for a randomized struct

A randomized structure needs to use a designated or default initializer.
Using a non-designated initializer will result in values being assigned
to the wrong fields.

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

Added: 
clang/test/Sema/init-randomized-struct.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a14194d271a71..e79a40d62381f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11602,7 +11602,9 @@ def err_hlsl_pointers_unsupported : Error<
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
 
-// Layout randomization warning.
+// Layout randomization diagnostics.
+def err_non_designated_init_used : Error<
+  "a randomized struct can only be initialized with a designated initializer">;
 def err_cast_from_randomized_struct : Error<
   "casting from randomized structure pointer type %0 to %1">;
 } // end of sema component.

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c3bbefbaaed1b..233be547bf118 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2123,6 +2123,7 @@ void InitListChecker::CheckStructUnionTypes(
   // worthwhile to skip over the rest of the initializer, though.
   RecordDecl *RD = DeclType->castAs()->getDecl();
   RecordDecl::field_iterator FieldEnd = RD->field_end();
+  size_t NumRecordFields = std::distance(RD->field_begin(), RD->field_end());
   bool CheckForMissingFields =
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
@@ -2172,6 +2173,35 @@ void InitListChecker::CheckStructUnionTypes(
   break;
 }
 
+// Check if this is an initializer of forms:
+//
+//   struct foo f = {};
+//   struct foo g = {0};
+//
+// These are okay for randomized structures. [C99 6.7.8p19]
+//
+// Also, if there is only one element in the structure, we allow something
+// like this, because it's really not randomized in the tranditional sense.
+//
+//   struct foo h = {bar};
+auto IsZeroInitializer = [&](const Expr *I) {
+  if (IList->getNumInits() == 1) {
+if (NumRecordFields == 1)
+  return true;
+if (const auto *IL = dyn_cast(I))
+  return IL->getValue().isZero();
+  }
+  return false;
+};
+
+// Don't allow non-designated initializers on randomized structures.
+if (RD->isRandomized() && !IsZeroInitializer(Init)) {
+  if (!VerifyOnly)
+SemaRef.Diag(InitLoc, diag::err_non_designated_init_used);
+  hadError = true;
+  break;
+}
+
 // We've already initialized a member of a union. We're done.
 if (InitializedSomething && DeclType->isUnionType())
   break;

diff  --git a/clang/test/Sema/init-randomized-struct.c 
b/clang/test/Sema/init-randomized-struct.c
new file mode 100644
index 0..87842e1f19e80
--- /dev/null
+++ b/clang/test/Sema/init-randomized-struct.c
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only 
-frandomize-layout-seed=1234567890abcdef
+
+// Initializing a randomized structure requires a designated initializer,
+// otherwise the element ordering will be off. The only exceptions to this rule
+// are:
+//
+//- A structure with only one element, and
+//- A structure initialized with "{0}".
+//
+// These are well-defined situations where the field ordering doesn't affect
+// the result.
+
+typedef void (*func_ptr)();
+
+void foo(void);
+void bar(void);
+void baz(void);
+void gaz(void);
+
+struct test {
+  func_ptr a;
+  func_ptr b;
+  func_ptr c;
+  func_ptr d;
+  func_ptr e;
+  func_ptr f;
+  func_ptr g;
+} __attribute__((randomize_layout));
+
+struct test t1 = {}; // This should be fine per WG14 N2900 (in C23) + our 
extension handling of it in earlier modes
+struct test t2 = { 0 }; // This should also be fine per C99 6.7.8p19
+struct test t3 = { .f = baz, .b = bar, .g = gaz, .a = foo }; // Okay
+struct test t4 = { .a = foo, bar, baz }; // expected-error {{a randomized 
struct can only be initialized with a designated initializer}}
+
+struct other_test {
+  func_ptr a;
+  func_ptr b[3];
+  func_ptr c;
+} __attribute__((randomize_layout));
+
+struct other_test t5 = { .a = foo, .b[0] = foo }; // Okay
+struct other_test t6 = { .a = foo, .b[0] = foo, 

[PATCH] D122865: [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Chris Bieneman 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 rG721651be246e: [HLSL][clang][Driver] Support target profile 
command line option. (authored by python3kgae, committed by beanz).

Changed prior to commit:
  https://reviews.llvm.org/D122865?vs=422677=423149#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122865

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/HLSL.cpp
  clang/lib/Driver/ToolChains/HLSL.h
  clang/lib/Driver/Types.cpp
  clang/test/lit.cfg.py
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -300,6 +300,12 @@
   EXPECT_TRUE(Res.ModeSuffix == "clang-cl");
   EXPECT_STREQ(Res.DriverMode, "--driver-mode=cl");
   EXPECT_FALSE(Res.TargetIsValid);
+
+  Res = ToolChain::getTargetAndModeFromProgramName("clang-dxc");
+  EXPECT_TRUE(Res.TargetPrefix.empty());
+  EXPECT_TRUE(Res.ModeSuffix == "clang-dxc");
+  EXPECT_STREQ(Res.DriverMode, "--driver-mode=dxc");
+  EXPECT_FALSE(Res.TargetIsValid);
 }
 
 TEST(ToolChainTest, CommandOutput) {
@@ -361,4 +367,141 @@
   EXPECT_EQ(getDriverMode(Args[0], llvm::makeArrayRef(Args).slice(1)), "bar");
 }
 
+TEST(DxcModeTest, TargetProfileValidation) {
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct SimpleDiagnosticConsumer : public DiagnosticConsumer {
+void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+  const Diagnostic ) override {
+  if (DiagLevel == DiagnosticsEngine::Level::Error) {
+Errors.emplace_back();
+Info.FormatDiagnostic(Errors.back());
+  } else {
+Msgs.emplace_back();
+Info.FormatDiagnostic(Msgs.back());
+  }
+}
+void clear() override {
+  Msgs.clear();
+  Errors.clear();
+  DiagnosticConsumer::clear();
+}
+std::vector> Msgs;
+std::vector> Errors;
+  };
+
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  InMemoryFileSystem->addFile("foo.hlsl", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+
+  auto *DiagConsumer = new SimpleDiagnosticConsumer;
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagConsumer);
+  Driver TheDriver("/bin/clang", "", Diags, "", InMemoryFileSystem);
+  std::unique_ptr C(
+  TheDriver.BuildCompilation({"clang", "--driver-mode=dxc", "foo.hlsl"}));
+  EXPECT_TRUE(C);
+  EXPECT_TRUE(!C->containsError());
+
+  auto  = C->getDefaultToolChain();
+  bool ContainsError = false;
+  auto Args = TheDriver.ParseArgStrings({"-Tvs_6_0"}, false, ContainsError);
+  EXPECT_FALSE(ContainsError);
+  auto Triple = TC.ComputeEffectiveClangTriple(Args);
+  EXPECT_STREQ(Triple.c_str(), "dxil--shadermodel6.0-vertex");
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+
+  Args = TheDriver.ParseArgStrings({"-Ths_6_1"}, false, ContainsError);
+  EXPECT_FALSE(ContainsError);
+  Triple = TC.ComputeEffectiveClangTriple(Args);
+  EXPECT_STREQ(Triple.c_str(), "dxil--shadermodel6.1-hull");
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+
+  Args = TheDriver.ParseArgStrings({"-Tds_6_2"}, false, ContainsError);
+  EXPECT_FALSE(ContainsError);
+  Triple = TC.ComputeEffectiveClangTriple(Args);
+  EXPECT_STREQ(Triple.c_str(), "dxil--shadermodel6.2-domain");
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+
+  Args = TheDriver.ParseArgStrings({"-Tds_6_2"}, false, ContainsError);
+  EXPECT_FALSE(ContainsError);
+  Triple = TC.ComputeEffectiveClangTriple(Args);
+  EXPECT_STREQ(Triple.c_str(), "dxil--shadermodel6.2-domain");
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+
+  Args = TheDriver.ParseArgStrings({"-Tgs_6_3"}, false, ContainsError);
+  EXPECT_FALSE(ContainsError);
+  Triple = TC.ComputeEffectiveClangTriple(Args);
+  EXPECT_STREQ(Triple.c_str(), "dxil--shadermodel6.3-geometry");
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+
+  Args = TheDriver.ParseArgStrings({"-Tps_6_4"}, false, ContainsError);
+  EXPECT_FALSE(ContainsError);
+  Triple = TC.ComputeEffectiveClangTriple(Args);
+  EXPECT_STREQ(Triple.c_str(), "dxil--shadermodel6.4-pixel");
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+
+  Args = TheDriver.ParseArgStrings({"-Tcs_6_5"}, false, ContainsError);
+  EXPECT_FALSE(ContainsError);
+  Triple = TC.ComputeEffectiveClangTriple(Args);
+  EXPECT_STREQ(Triple.c_str(), "dxil--shadermodel6.5-compute");
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+
+  Args = TheDriver.ParseArgStrings({"-Tms_6_6"}, false, ContainsError);
+  

[clang] 721651b - [HLSL][clang][Driver] Support target profile command line option.

2022-04-15 Thread Chris Bieneman via cfe-commits

Author: Xiang Li
Date: 2022-04-15T14:18:18-05:00
New Revision: 721651be246e26efd767c3ec55c8f06c7b5a9a3d

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

LOG: [HLSL][clang][Driver] Support target profile command line option.

The target profile option(/T) decide the shader model when compile hlsl.
The format is shaderKind_major_minor like ps_6_1.
The shader model is saved as llvm::Triple is clang/llvm like
dxil-unknown-shadermodel6.1-hull.
The main job to support the option is translating ps_6_1 into
shadermodel6.1-pixel.
That is done inside tryParseProfile  at HLSL.cpp.

To integrate the option into clang Driver, a new DriverMode DxcMode is
created. When DxcMode is enabled, OSType for TargetTriple will be
forced into Triple::ShaderModel. And new ToolChain HLSLToolChain will
be created when OSType is Triple::ShaderModel.

In HLSLToolChain, ComputeEffectiveClangTriple is overridden to call
tryParseProfile when targetProfile option is set.

To make test work, Fo option is added and .hlsl is added for active
-xhlsl.

Reviewed By: beanz

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

Patch by: Xiang Li 

Added: 
clang/lib/Driver/ToolChains/HLSL.cpp
clang/lib/Driver/ToolChains/HLSL.h

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/Types.cpp
clang/test/lit.cfg.py
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 64af4c84672fe..cb53804d9e4f8 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -657,4 +657,7 @@ def warn_drv_fjmc_for_elf_only : Warning<
 def err_drv_target_variant_invalid : Error<
   "unsupported '%0' value '%1'; use 'ios-macabi' instead">;
 
+def err_drv_invalid_directx_shader_module : Error<
+  "invalid profile : %0">;
+
 }

diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 6f24f649ea544..b33b64cd9e6a2 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -68,7 +68,8 @@ class Driver {
 GXXMode,
 CPPMode,
 CLMode,
-FlangMode
+FlangMode,
+DXCMode
   } Mode;
 
   enum SaveTempsMode {
@@ -195,6 +196,9 @@ class Driver {
   /// Other modes fall back to calling gcc which in turn calls gfortran.
   bool IsFlangMode() const { return Mode == FlangMode; }
 
+  /// Whether the driver should follow dxc.exe like behavior.
+  bool IsDXCMode() const { return Mode == DXCMode; }
+
   /// Only print tool bindings, don't build any jobs.
   unsigned CCCPrintBindings : 1;
 

diff  --git a/clang/include/clang/Driver/Options.h 
b/clang/include/clang/Driver/Options.h
index 056660192ac5f..f9b9632ee7cbe 100644
--- a/clang/include/clang/Driver/Options.h
+++ b/clang/include/clang/Driver/Options.h
@@ -35,7 +35,8 @@ enum ClangFlags {
   FlangOption = (1 << 14),
   FC1Option = (1 << 15),
   FlangOnlyOption = (1 << 16),
-  Ignored = (1 << 17),
+  DXCOption = (1 << 17),
+  Ignored = (1 << 18),
 };
 
 enum ID {

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 104c8ea8483d1..f454bd038ecf8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -49,6 +49,10 @@ def CC1Option : OptionFlag;
 // CC1AsOption - This option should be accepted by clang -cc1as.
 def CC1AsOption : OptionFlag;
 
+// DXCOption - This is a dxc.exe compatibility option. Options with this flag
+// are made available when the driver is running in DXC compatibility mode.
+def DXCOption : OptionFlag;
+
 // NoDriverOption - This option should not be accepted by the driver.
 def NoDriverOption : OptionFlag;
 
@@ -6686,3 +6690,33 @@ def _SLASH_Ze : CLFlag<"Ze">;
 def _SLASH_Zg : CLFlag<"Zg">;
 def _SLASH_ZI : CLFlag<"ZI">;
 def _SLASH_ZW : CLJoined<"ZW">;
+
+//===--===//
+// clang-dxc Options
+//===--===//
+
+def dxc_Group : OptionGroup<"">, Flags<[DXCOption]>,
+  HelpText<"dxc compatibility options">;
+
+class DXCJoinedOrSeparate : Option<["/", "-"], name,
+  KIND_JOINED_OR_SEPARATE>, Group, Flags<[DXCOption, 
NoXarchOption]>;
+
+def dxc_help : Option<["/", "-", "--"], "help", KIND_JOINED>,
+  Group, Flags<[DXCOption, NoXarchOption]>, Alias,
+  HelpText<"Display available options">;
+
+
+def Fo : DXCJoinedOrSeparate<"Fo">, Alias,
+ 

[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

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

In D122983#3454494 , @jyknight wrote:

> In D122983#3454406 , @aaron.ballman 
> wrote:
>
>> In D122983#3452994 , @rsmith wrote:
>>
>>> I think we should just make this an error by default in C99 onwards;
>>
>> Out of curiosity -- do you think we should remove the `DefaultIgnore` in C89 
>> mode so that we warn by default there (perhaps as a follow up)? Also, I 
>> presume you expect `diag::ext_implicit_lib_function_decl` to behave the same 
>> way (warn in C89, warn-as-err in C99 and up) as part of this patch?
>
> I'm not sure what purpose it'd serve to change -std=c89 to be more strict at 
> this point. It's not the default compilation mode, and the code is actually 
> valid under that standard. IMO, adding such a on-by-default warning there 
> would only serve to annoy folks explicitly trying to build super-old code 
> with a super-old standards version.

Yeah, I was waffling on that one -- my thinking was that it would at least warn 
users that they're using something dangerous and we're going to break them if 
they attempt to upgrade (aka, we treat it as almost-deprecated in C89). But I'm 
fine leaving that one as `DefaultIgnore` too; as you say, if someone is in that 
mode explicitly, this IS a "feature" of that language.

I feel a bit more strongly that implicit builtins should be handled the same as 
other implicit functions (in terms of `DefaultError` behavior), unless there's 
some scenarios I'm not thinking of.


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

https://reviews.llvm.org/D122983

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


[PATCH] D123826: Fix size of flexible array initializers, and re-enable assertions.

2022-04-15 Thread Eli Friedman 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 rG4802edd1ac7a: Fix size of flexible array initializers, and 
re-enable assertions. (authored by efriedma).

Changed prior to commit:
  https://reviews.llvm.org/D123826?vs=422979=423146#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123826

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/flexible-array-init.c
  clang/test/CodeGenCXX/flexible-array-init.cpp

Index: clang/test/CodeGenCXX/flexible-array-init.cpp
===
--- clang/test/CodeGenCXX/flexible-array-init.cpp
+++ clang/test/CodeGenCXX/flexible-array-init.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm-only -verify -DFAIL1 %s
 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm-only -verify -DFAIL2 %s
+// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm-only -verify -DFAIL3 %s
 
 struct A { int x; int y[]; };
 A a = { 1, 7, 11 };
@@ -9,7 +10,7 @@
 A b = { 1, { 13, 15 } };
 // CHECK: @b ={{.*}} global { i32, [2 x i32] } { i32 1, [2 x i32] [i32 13, i32 15] }
 
-int f();
+char f();
 #ifdef FAIL1
 A c = { f(), { f(), f() } }; // expected-error {{cannot compile this flexible array initializer yet}}
 #endif
@@ -18,3 +19,7 @@
   static A d = { f(), { f(), f() } }; // expected-error {{cannot compile this flexible array initializer yet}}
 }
 #endif
+#ifdef FAIL3
+struct B { int x; char y; char z[]; };
+B e = {f(), f(), f(), f()}; // expected-error {{cannot compile this flexible array initializer yet}}
+#endif
Index: clang/test/CodeGen/flexible-array-init.c
===
--- clang/test/CodeGen/flexible-array-init.c
+++ clang/test/CodeGen/flexible-array-init.c
@@ -18,7 +18,5 @@
 struct __attribute((packed, aligned(4))) { char a; int x; char z[]; } e = { 1, 2, { 13, 15, 17, 19 } };
 // CHECK: @e ={{.*}} <{ i8, i32, [4 x i8] }> <{ i8 1, i32 2, [4 x i8] c"\0D\0F\11\13" }>
 
-// FIXME: This global should be 6 bytes, not 8.  Not likely to matter in most
-// cases, but still a bug.
 struct { int x; char y[]; } f = { 1, { 13, 15 } };
-// CHECK: @f ={{.*}} global { i32, [2 x i8] } { i32 1, [2 x i8] c"\0D\0F" }
+// CHECK: @f ={{.*}} global <{ i32, [2 x i8] }> <{ i32 1, [2 x i8] c"\0D\0F" }>
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4615,7 +4615,7 @@
 T = D->getType();
 
   if (getLangOpts().CPlusPlus) {
-if (!InitDecl->getFlexibleArrayInitChars(getContext()).isZero())
+if (InitDecl->hasFlexibleArrayInit(getContext()))
   ErrorUnsupported(D, "flexible array initializer");
 Init = EmitNullConstant(T);
 NeedsGlobalCtor = true;
@@ -4631,17 +4631,12 @@
   if (getLangOpts().CPlusPlus && !NeedsGlobalDtor)
 DelayedCXXInitPosition.erase(D);
 
-#if 0
-  // FIXME: The following check doesn't handle flexible array members
-  // inside tail padding (which don't actually increase the size of
-  // the struct).
 #ifndef NDEBUG
   CharUnits VarSize = getContext().getTypeSizeInChars(ASTTy) +
   InitDecl->getFlexibleArrayInitChars(getContext());
   CharUnits CstSize = CharUnits::fromQuantity(
   getDataLayout().getTypeAllocSize(Init->getType()));
   assert(VarSize == CstSize && "Emitted constant has unexpected size");
-#endif
 #endif
 }
   }
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -439,22 +439,33 @@
 // Can't emit as an array, carry on to emit as a struct.
   }
 
+  // The size of the constant we plan to generate.  This is usually just
+  // the size of the initialized type, but in AllowOversized mode (i.e.
+  // flexible array init), it can be larger.
   CharUnits DesiredSize = Utils.getSize(DesiredTy);
+  if (Size > DesiredSize) {
+assert(AllowOversized && "Elems are oversized");
+DesiredSize = Size;
+  }
+
+  // The natural alignment of an unpacked LLVM struct with the given elements.
   CharUnits Align = CharUnits::One();
   for (llvm::Constant *C : Elems)
 Align = std::max(Align, Utils.getAlignment(C));
+
+  // The natural size of an unpacked LLVM struct with the given elements.
   CharUnits AlignedSize = Size.alignTo(Align);
 
   bool Packed = false;
   ArrayRef UnpackedElems = Elems;
   llvm::SmallVector UnpackedElemStorage;

[clang] 4802edd - Fix size of flexible array initializers, and re-enable assertions.

2022-04-15 Thread Eli Friedman via cfe-commits

Author: Eli Friedman
Date: 2022-04-15T12:09:57-07:00
New Revision: 4802edd1ac7a5aea8c8488b5baec221d722cbdde

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

LOG: Fix size of flexible array initializers, and re-enable assertions.

In D123649, I got the formula for getFlexibleArrayInitChars slightly
wrong: the flexible array elements can be contained in the tail padding
of the struct.  Fix the formula to account for that.

With the fixed formula, we run into another issue: in some cases, we
were emitting extra padding for flexible arrray initializers. Fix
CGExprConstant so it uses a packed struct when necessary, to avoid this
extra padding.

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

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/flexible-array-init.c
clang/test/CodeGenCXX/flexible-array-init.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 5816a91bd0c2d..f93008cdd322d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1591,12 +1591,18 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// kind?
   QualType::DestructionKind needsDestruction(const ASTContext ) const;
 
-  /// If this variable declares a struct with a flexible array member, and
-  /// the flexible array member is initialized with one or more elements,
-  /// compute the number of bytes necessary to store those elements.
+  /// Whether this variable has a flexible array member initialized with one
+  /// or more elements. This can only be called for declarations where
+  /// hasInit() is true.
   ///
   /// (The standard doesn't allow initializing flexible array members; this is
   /// a gcc/msvc extension.)
+  bool hasFlexibleArrayInit(const ASTContext ) const;
+
+  /// If hasFlexibleArrayInit is true, compute the number of additional bytes
+  /// necessary to store those elements. Otherwise, returns zero.
+  ///
+  /// This can only be called for declarations where hasInit() is true.
   CharUnits getFlexibleArrayInitChars(const ASTContext ) const;
 
   // Implement isa/cast/dyncast/etc.

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 915d8db10aca4..050c3ad2dafc6 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -31,6 +31,7 @@
 #include "clang/AST/PrettyDeclStackTrace.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/Randstruct.h"
+#include "clang/AST/RecordLayout.h"
 #include "clang/AST/Redeclarable.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TemplateBase.h"
@@ -2722,6 +2723,21 @@ VarDecl::needsDestruction(const ASTContext ) const {
   return getType().isDestructedType();
 }
 
+bool VarDecl::hasFlexibleArrayInit(const ASTContext ) const {
+  assert(hasInit() && "Expect initializer to check for flexible array init");
+  auto *Ty = getType()->getAs();
+  if (!Ty || !Ty->getDecl()->hasFlexibleArrayMember())
+return false;
+  auto *List = dyn_cast(getInit()->IgnoreParens());
+  if (!List)
+return false;
+  const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
+  auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType());
+  if (!InitTy)
+return false;
+  return InitTy->getSize() != 0;
+}
+
 CharUnits VarDecl::getFlexibleArrayInitChars(const ASTContext ) const {
   assert(hasInit() && "Expect initializer to check for flexible array init");
   auto *Ty = getType()->getAs();
@@ -2730,11 +2746,17 @@ CharUnits VarDecl::getFlexibleArrayInitChars(const 
ASTContext ) const {
   auto *List = dyn_cast(getInit()->IgnoreParens());
   if (!List)
 return CharUnits::Zero();
-  auto FlexibleInit = List->getInit(List->getNumInits() - 1);
+  const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
   auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType());
   if (!InitTy)
 return CharUnits::Zero();
-  return Ctx.getTypeSizeInChars(InitTy);
+  CharUnits FlexibleArraySize = Ctx.getTypeSizeInChars(InitTy);
+  const ASTRecordLayout  = Ctx.getASTRecordLayout(Ty->getDecl());
+  CharUnits FlexibleArrayOffset =
+  Ctx.toCharUnitsFromBits(RL.getFieldOffset(RL.getFieldCount() - 1));
+  if (FlexibleArrayOffset + FlexibleArraySize < RL.getSize())
+return CharUnits::Zero();
+  return FlexibleArrayOffset + FlexibleArraySize - RL.getSize();
 }
 
 MemberSpecializationInfo *VarDecl::getMemberSpecializationInfo() const {

diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 322602606ebe9..e47450f2ba8fe 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -342,7 +342,7 @@ 

[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-15 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D122983#3454406 , @aaron.ballman 
wrote:

> In D122983#3452994 , @rsmith wrote:
>
>> I think we should just make this an error by default in C99 onwards;
>
> Out of curiosity -- do you think we should remove the `DefaultIgnore` in C89 
> mode so that we warn by default there (perhaps as a follow up)? Also, I 
> presume you expect `diag::ext_implicit_lib_function_decl` to behave the same 
> way (warn in C89, warn-as-err in C99 and up) as part of this patch?

I'm not sure what purpose it'd serve to change -std=c89 to be more strict at 
this point. It's not the default compilation mode, and the code is actually 
valid under that standard. IMO, adding such a on-by-default warning there would 
only serve to annoy folks explicitly trying to build super-old code with a 
super-old standards version.


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

https://reviews.llvm.org/D122983

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


[PATCH] D123649: Allow flexible array initialization in C++.

2022-04-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

6cf0b1b3  
was a temporary fix to stop the crash. D123826 
 is the full fix to make the assertion 
actually work correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123649

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


[PATCH] D123763: [randstruct] Enforce using a designated init for a randomized struct

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

LGTM, too.

It may be worthwhile adding a file-level comment at the header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123763

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


[PATCH] D123642: [clang codegen] Assume arguments of __atomic_* are aligned.

2022-04-15 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D123642#3450110 , @efriedma wrote:

>> I disagree with this on principle -- IMO, it is basically a historical bug 
>> in GCC that it ignores the type alignment, and we should NOT try to match 
>> that -- it's dangerous.
>
> gcc has always behaved this way, and I don't see any indication they intend 
> to change it.  I mean, you can call it a bug, but at the end of the day the 
> bug reports will land in our bugtracker, not gcc's.

Have we had many other such bug reports?

On the other hand, I have seen many cases where people wrote code using the 
`__atomic_*` APIs, and pass arguments which are underaligned on some platforms 
(though not the one the code was developed on). Having it be silently 
non-atomic (which is what typically happens with misaligned atomic 
instructions) is just...really nasty.

>> Ask GCC to modify libstdc++ so that `__builtin_addressof` is called 
>> directly, instead of going through `std::__addressof`.
>
> Even if gcc did this today, it would take years to reach people on Linux.

True, but the behavior in the meantime is correct. And given the apparent lack 
of widespread issues, I'm not sure it much matters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123642

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


[PATCH] D123763: [randstruct] Enforce using a designated init for a randomized struct

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

LGTM, thank you for adding some guard rails for this new feature!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123763

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


[PATCH] D123763: [randstruct] Enforce using a designated init for a randomized struct

2022-04-15 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 423139.
void added a comment.

Add tests for empty and single element structs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123763

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/init-randomized-struct.c

Index: clang/test/Sema/init-randomized-struct.c
===
--- /dev/null
+++ clang/test/Sema/init-randomized-struct.c
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -frandomize-layout-seed=1234567890abcdef
+
+typedef void (*func_ptr)();
+
+void foo(void);
+void bar(void);
+void baz(void);
+void gaz(void);
+
+struct test {
+  func_ptr a;
+  func_ptr b;
+  func_ptr c;
+  func_ptr d;
+  func_ptr e;
+  func_ptr f;
+  func_ptr g;
+} __attribute__((randomize_layout));
+
+struct test t1 = {}; // This should be fine per WG14 N2900 (in C23) + our extension handling of it in earlier modes
+struct test t2 = {0}; // This should also be fine per C99 6.7.8p19
+struct test t3 = { .f = baz, .b = bar, .g = gaz, .a = foo }; // Okay
+struct test t4 = { .a = foo, bar, baz }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
+
+struct other_test {
+  func_ptr a;
+  func_ptr b[3];
+  func_ptr c;
+} __attribute__((randomize_layout));
+
+struct other_test t5 = { .a = foo, .b[0] = foo }; // Okay
+struct other_test t6 = { .a = foo, .b[0] = foo, bar, baz }; // Okay
+struct other_test t7 = { .a = foo, .b = { foo, bar, baz } }; // Okay
+struct other_test t8 = { baz, bar, gaz, foo }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
+struct other_test t9 = { .a = foo, .b[0] = foo, bar, baz, gaz }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
+
+struct empty_test {
+} __attribute__((randomize_layout));
+
+struct empty_test t10 = {}; // Okay
+
+struct degen_test {
+  func_ptr a;
+} __attribute__((randomize_layout));
+
+struct degen_test t11 = { foo }; // Okay
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2123,6 +2123,7 @@
   // worthwhile to skip over the rest of the initializer, though.
   RecordDecl *RD = DeclType->castAs()->getDecl();
   RecordDecl::field_iterator FieldEnd = RD->field_end();
+  size_t NumRecordFields = std::distance(RD->field_begin(), RD->field_end());
   bool CheckForMissingFields =
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
   bool HasDesignatedInit = false;
@@ -2172,6 +2173,35 @@
   break;
 }
 
+// Check if this is an initializer of forms:
+//
+//   struct foo f = {};
+//   struct foo g = {0};
+//
+// These are okay for randomized structures. [C99 6.7.8p19]
+//
+// Also, if there is only one element in the structure, we allow something
+// like this, because it's really not randomized in the tranditional sense.
+//
+//   struct foo h = {bar};
+auto IsZeroInitializer = [&](const Expr *I) {
+  if (IList->getNumInits() == 1) {
+if (NumRecordFields == 1)
+  return true;
+if (const auto *IL = dyn_cast(I))
+  return IL->getValue().isZero();
+  }
+  return false;
+};
+
+// Don't allow non-designated initializers on randomized structures.
+if (RD->isRandomized() && !IsZeroInitializer(Init)) {
+  if (!VerifyOnly)
+SemaRef.Diag(InitLoc, diag::err_non_designated_init_used);
+  hadError = true;
+  break;
+}
+
 // We've already initialized a member of a union. We're done.
 if (InitializedSomething && DeclType->isUnionType())
   break;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11602,7 +11602,9 @@
 def err_hlsl_operator_unsupported : Error<
   "the '%select{&|*|->}0' operator is unsupported in HLSL">;
 
-// Layout randomization warning.
+// Layout randomization diagnostics.
+def err_non_designated_init_used : Error<
+  "a randomized struct can only be initialized with a designated initializer">;
 def err_cast_from_randomized_struct : Error<
   "casting from randomized structure pointer type %0 to %1">;
 } // end of sema component.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123862: [Clang][OpenMP] Use bitfields for flags in `OMPAtomicDirective`

2022-04-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123862

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


[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

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

In D122983#3452994 , @rsmith wrote:

> I think we should just make this an error by default in C99 onwards;

Out of curiosity -- do you think we should remove the `DefaultIgnore` in C89 
mode so that we warn by default there (perhaps as a follow up)? Also, I presume 
you expect `diag::ext_implicit_lib_function_decl` to behave the same way (warn 
in C89, warn-as-err in C99 and up) as part of this patch?


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

https://reviews.llvm.org/D122983

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


[PATCH] D123862: [Clang][OpenMP] Use bitfields for flags in `OMPAtomicDirective`

2022-04-15 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D123862#3454380 , @ABataev wrote:

> What about ASTStmtWriter?

It's using accessor function `isXLHSInRHSPart()` and so on.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123862

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


[clang] 8fd3b5d - Fix an edge case in determining is a function has a prototype

2022-04-15 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-04-15T14:04:07-04:00
New Revision: 8fd3b5de3f96300189a2841278e6c7b6654bffc5

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

LOG: Fix an edge case in determining is a function has a prototype

Given the declaration:

  typedef void func_t(unsigned);
  __attribute__((noreturn)) func_t func;

we would incorrectly determine that `func` had no prototype because the
`noreturn` attribute would convert the underlying type directly into a
FunctionProtoType, but the declarator for `func` itself was not one for
a function with a prototype. This adds an additional check for when the
declarator is a type representation for a function with a prototype.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/warn-strict-prototypes.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 76bf67397a6ee..499c70e087898 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8803,15 +8803,21 @@ static FunctionDecl *CreateNewFunctionDecl(Sema 
, Declarator ,
   bool isInline = D.getDeclSpec().isInlineSpecified();
 
   if (!SemaRef.getLangOpts().CPlusPlus) {
-// Determine whether the function was written with a
-// prototype. This true when:
+// Determine whether the function was written with a prototype. This is
+// true when:
 //   - there is a prototype in the declarator, or
 //   - the type R of the function is some kind of typedef or other non-
 // attributed reference to a type name (which eventually refers to a
-// function type).
+// function type). Note, we can't always look at the adjusted type to
+// check this case because attributes may cause a non-function
+// declarator to still have a function type. e.g.,
+//   typedef void func(int a);
+//   __attribute__((noreturn)) func other_func; // This has a prototype
 bool HasPrototype =
-  (D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) ||
-  (!R->getAsAdjusted() && R->isFunctionProtoType());
+(D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) ||
+(D.getDeclSpec().isTypeRep() &&
+ D.getDeclSpec().getRepAsType().get()->isFunctionProtoType()) ||
+(!R->getAsAdjusted() && R->isFunctionProtoType());
 
 NewFD = FunctionDecl::Create(
 SemaRef.Context, DC, D.getBeginLoc(), NameInfo, R, TInfo, SC,

diff  --git a/clang/test/Sema/warn-strict-prototypes.c 
b/clang/test/Sema/warn-strict-prototypes.c
index 4dc7913cd33e7..e2cd4dcddc4c0 100644
--- a/clang/test/Sema/warn-strict-prototypes.c
+++ b/clang/test/Sema/warn-strict-prototypes.c
@@ -80,3 +80,13 @@ void foo13(...) __attribute__((overloadable)) {}
 void foo14(void) {
   foo14_call(); // no-warning
 }
+
+// Ensure that redeclarations involving a typedef type work properly, even if
+// there are function attributes involved in the declaration.
+typedef void foo_t(unsigned val);
+__attribute__((noreturn)) foo_t foo15;
+foo_t foo15; // OK
+void foo15(unsigned val); // OK
+
+foo_t foo16;
+void foo16(unsigned val); // OK



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


[PATCH] D123862: [Clang][OpenMP] Use bitfields for flags in `OMPAtomicDirective`

2022-04-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

What about ASTStmtWriter?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123862

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


[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

2022-04-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

This seems like it would significantly introduce debug info size for at least 
some kinds of code - have you done any size measurements of this change?

What does the resulting DWARF look like?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123534

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


[PATCH] D123763: [randstruct] Enforce using a designated init for a randomized struct

2022-04-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/init-randomized-struct.c:30
+} __attribute__((randomize_layout));
+
+struct other_test t5 = { .a = foo, .b[0] = foo }; // Okay

MaskRay wrote:
> Perhaps test an empty struct with randomize_layout and a struct with one 
> field with randomize_layout?
Good point -- there's really no reason to reject something like:
```
struct degenerate {
  func_ptr a;
};

struct degenerate d= { foo };
```
even though it's not doing a zero initialization.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123763

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


[PATCH] D120290: [Clang][OpenMP] Add the codegen support for `atomic compare capture`

2022-04-15 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked 3 inline comments as done.
tianshilei1992 added inline comments.



Comment at: clang/include/clang/AST/StmtOpenMP.h:2835-2847
   bool IsXLHSInRHSPart = false;
   /// Used for 'atomic update' or 'atomic capture' constructs. They may
   /// have atomic expressions of forms
   /// \code
   /// v = x; ;
   /// ; v = x;
   /// \endcode

tianshilei1992 wrote:
> ABataev wrote:
> > Transform these booleans to bitfields?
> Will do in another patch.
In D123862.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6216
-  KindsEncountered.contains(OMPC_capture)) {
-IsCompareCapture = true;
 Kind = OMPC_compare;

ABataev wrote:
> tianshilei1992 wrote:
> > ABataev wrote:
> > > Can this be fixed in a separate patch?
> > Well, I think it's part of this patch because we can't tell if it's compare 
> > or compare capture before, but now we can. If we really want to do that, we 
> > can have another patch including all changes in this patch related to 
> > `OMPAtomicDirective`.
> Kind of NFC? Would be good
I think we don't need an extra NFC patch for this part because it's not gonna 
be very neat w/o some other code in this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120290

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


[PATCH] D120290: [Clang][OpenMP] Add the codegen support for `atomic compare capture`

2022-04-15 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 423132.
tianshilei1992 added a comment.
Herald added a project: All.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120290

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/OpenMP/atomic_compare_codegen.cpp

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


[PATCH] D123649: Allow flexible array initialization in C++.

2022-04-15 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

For posterity, posting the link to the failure this caused in Linaro's TCWG's 
CI of kernel builds w/ clang: 
https://lore.kernel.org/llvm/906914372.14298.1650022522881@jenkins.jenkins/.

I'm guessing D123826  fixes this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123649

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


[PATCH] D123862: [Clang][OpenMP] Use bitfields for flags in `OMPAtomicDirective`

2022-04-15 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: ABataev, jdoerfert.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123862

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp


Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2449,8 +2449,8 @@
 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
   VisitStmt(D);
   VisitOMPExecutableDirective(D);
-  D->IsXLHSInRHSPart = Record.readBool();
-  D->IsPostfixUpdate = Record.readBool();
+  D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
+  D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
 }
 
 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
Index: clang/lib/AST/StmtOpenMP.cpp
===
--- clang/lib/AST/StmtOpenMP.cpp
+++ clang/lib/AST/StmtOpenMP.cpp
@@ -875,8 +875,8 @@
   Dir->setUpdateExpr(Exprs.UE);
   Dir->setD(Exprs.D);
   Dir->setCond(Exprs.Cond);
-  Dir->IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart;
-  Dir->IsPostfixUpdate = Exprs.IsPostfixUpdate;
+  Dir->Flags.IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart ? 1 : 0;
+  Dir->Flags.IsPostfixUpdate = Exprs.IsPostfixUpdate ? 1 : 0;
   return Dir;
 }
 
Index: clang/include/clang/AST/StmtOpenMP.h
===
--- clang/include/clang/AST/StmtOpenMP.h
+++ clang/include/clang/AST/StmtOpenMP.h
@@ -2827,25 +2827,28 @@
 class OMPAtomicDirective : public OMPExecutableDirective {
   friend class ASTStmtReader;
   friend class OMPExecutableDirective;
-  /// Used for 'atomic update' or 'atomic capture' constructs. They may
-  /// have atomic expressions of forms
-  /// \code
-  /// x = x binop expr;
-  /// x = expr binop x;
-  /// \endcode
-  /// This field is true for the first form of the expression and false for the
-  /// second. Required for correct codegen of non-associative operations (like
-  /// << or >>).
-  bool IsXLHSInRHSPart = false;
-  /// Used for 'atomic update' or 'atomic capture' constructs. They may
-  /// have atomic expressions of forms
-  /// \code
-  /// v = x; ;
-  /// ; v = x;
-  /// \endcode
-  /// This field is true for the first(postfix) form of the expression and 
false
-  /// otherwise.
-  bool IsPostfixUpdate = false;
+
+  struct FlagTy {
+/// Used for 'atomic update' or 'atomic capture' constructs. They may
+/// have atomic expressions of forms:
+/// \code
+/// x = x binop expr;
+/// x = expr binop x;
+/// \endcode
+/// This field is 1 for the first form of the expression and 0 for the
+/// second. Required for correct codegen of non-associative operations 
(like
+/// << or >>).
+uint8_t IsXLHSInRHSPart : 1;
+/// Used for 'atomic update' or 'atomic capture' constructs. They may
+/// have atomic expressions of forms:
+/// \code
+/// v = x; ;
+/// ; v = x;
+/// \endcode
+/// This field is 1 for the first(postfix) form of the expression and 0
+/// otherwise.
+uint8_t IsPostfixUpdate : 1;
+  } Flags;
 
   /// Build directive with the given start and end location.
   ///
@@ -2956,10 +2959,10 @@
   /// Return true if helper update expression has form
   /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form
   /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
-  bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; }
+  bool isXLHSInRHSPart() const { return Flags.IsXLHSInRHSPart; }
   /// Return true if 'v' expression must be updated to original value of
   /// 'x', false if 'v' must be updated to the new value of 'x'.
-  bool isPostfixUpdate() const { return IsPostfixUpdate; }
+  bool isPostfixUpdate() const { return Flags.IsPostfixUpdate; }
   /// Get 'v' part of the associated expression/statement.
   Expr *getV() {
 return cast_or_null(Data->getChildren()[DataPositionTy::POS_V]);


Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2449,8 +2449,8 @@
 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
   VisitStmt(D);
   VisitOMPExecutableDirective(D);
-  D->IsXLHSInRHSPart = Record.readBool();
-  D->IsPostfixUpdate = Record.readBool();
+  D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
+  D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
 }
 
 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
Index: clang/lib/AST/StmtOpenMP.cpp

[PATCH] D123642: [clang codegen] Assume arguments of __atomic_* are aligned.

2022-04-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> Have we verified that this is the rule that GCC uses? Is it true even if e.g. 
> the pointer expression is the address of a variable with a known alignment, 
> or if the pointer has an explicitly-aligned type (e.g. with an aligned 
> typedef)?

As far as I can tell, if the type's size is a power of two, and there's an 
inline atomic sequence available, gcc will use an inline sequence that assumes 
the address is naturally aligned.  Otherwise, it makes the libcall.  I've tried 
a variety of ways of writing the operation; alignment doesn't matter at all, no 
matter what the alignment actually is.

Oddly, `__atomic_is_lock_free`/`__atomic_always_lock_free` do care about the 
alignment, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123642

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


[PATCH] D123300: [Clang] Enable opaque pointers by default

2022-04-15 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

  $ cat /tmp/a.ll 
  target triple = "thumbv8-unknown-linux-gnueabihf"
  
  define void @zot() {
  bb:
br label %bb1
  
  bb1:  ; preds = %bb1, %bb
%tmp = phi ptr [ null, %bb ], [ %tmp2, %bb1 ]
store ptr %tmp, ptr %tmp, align 4
%tmp2 = getelementptr inbounds ptr, ptr %tmp, i32 1
%tmp3 = icmp eq ptr %tmp2, null
br i1 %tmp3, label %bb4, label %bb1
  
  bb4:  ; preds = %bb1
ret void
  }
  $ opt -passes=loop-vectorize /tmp/a.ll -disable-output
  # crash


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123300

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


[PATCH] D123856: [clang][lex] NFCI: Use FileEntryRef in ModuleMap::diagnoseHeaderInclusion()

2022-04-15 Thread Ben Barham via Phabricator via cfe-commits
bnbarham accepted this revision.
bnbarham added a comment.
This revision is now accepted and ready to land.

Shadowing of `FE` almost tripped me up there 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123856

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


[PATCH] D123854: [clang][lex] NFCI: Use DirectoryEntryRef in FrameworkCacheEntry

2022-04-15 Thread Ben Barham via Phabricator via cfe-commits
bnbarham accepted this revision.
bnbarham added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Lex/HeaderSearch.cpp:584
   // If it is known and in some other directory, fail.
-  if (CacheEntry.Directory && CacheEntry.Directory != getFrameworkDir())
+  if (CacheEntry.Directory && *CacheEntry.Directory != getFrameworkDir())
 return None;





Comment at: clang/lib/Lex/HeaderSearch.cpp:607
 // If the framework dir doesn't exist, we fail.
 auto Dir = FileMgr.getDirectory(FrameworkName);
 if (!Dir)

Is the plan to do these ones in later commits? Ie. this just does what's needed 
for `FrameworkCacheEntry`?



Comment at: clang/lib/Lex/HeaderSearch.cpp:1192
 // framework.
 CacheLookup.second.Directory = *Dir;
   }

Don't need the `*`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123854

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


[PATCH] D121984: [RISCV] Moving RVV intrinsic type related util to clang/Support

2022-04-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a reviewer: rsmith.
aaron.ballman added a subscriber: rsmith.
aaron.ballman added a comment.

In D121984#3453976 , @kito-cheng 
wrote:

>> Thank you for the explanation. I still don't think this is really "Support" 
>> material, but I'm also struggling to think of a better place to put it in an 
>> existing directory in Clang aside from Basic, but that would still be a bit 
>> of a layering violation it feels like. So I think I'm convinced that Support 
>> is a reasonable place to put it.
>
> Actually I tried to put that on clang/Basic before, and end up with the 
> clang/Basic is depended on clang-tblgen, and that made clang-tblgen depend on 
> clang/Basic...then CMake report error for circular dependency :P

Yup, that's exactly the issue I was thinking we'd hit. :-)

>> Should it live within a RISCV direction inside of the Support directory? Or 
>> should we use folders like that for host platform support files instead of 
>> target platform support files (as the LLVM Support directory appears to do)?
>
> I saw LLVM/Support are just target specific file on the folder instead of 
> many target folder, I guess there should not be too much target specific 
> files in clang/Support, and we could reorg the folder organization once it 
> getting complicated? What do you think?

Yeah, I think that's likely reasonable.

Giving my LGTM but adding @rsmith in case he has any code owner concerns over 
it. If you don't hear any concerns by Tue of next week, I think you're fine to 
land.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121984

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


[PATCH] D123771: [clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::load*()

2022-04-15 Thread Ben Barham via Phabricator via cfe-commits
bnbarham accepted this revision.
bnbarham added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Lex/HeaderSearch.cpp:1583
+::getTopFrameworkDir(FileMgr, FrameworkName, SubmodulePath);
+assert(TopFrameworkDir && "Could not find the top-most framework dir");
 

jansvoboda11 wrote:
> bnbarham wrote:
> > Can we just return false in this case, or is it definitely always a logic 
> > error?
> I agree returning `false` here would be better, but I wanted to keep this 
> patch as NFC as possible. How about I make that change in a follow-up patch?
Sure. It would have been a segfault before, so I assume it must never happen 
anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123771

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


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

2022-04-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

I'm happy with this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

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


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

2022-04-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 2 inline comments as done.
royjacobson added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:9829
+  bool CanCompareConstraints = false;
+  if (Cand1.Function && Cand2.Function && Cand1.Function->hasPrototype() &&
+  Cand2.Function->hasPrototype()) {

erichkeane wrote:
> royjacobson wrote:
> > erichkeane wrote:
> > > Since the point of this is to just calculate the CanCompareConstraints, I 
> > > think it should be a separate function called below where it is used.  
> > Do you mean as in a separate `Sema` function? Or a local lambda?
> Just a static function is fine, basically its a whole lot of work happening 
> in this function for a single result, so I'm suggesting splitting off the 
> calculation for `CanCompareConstraints` into its own function, so you get:
> 
> `bool CanCompareConstrants = new_function(...);`
Done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

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


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

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

Split the 'can compare constraints' code into a static function.


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 ) {} // 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
@@ -2952,24 +2952,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 

[PATCH] D123826: Fix size of flexible array initializers, and re-enable assertions.

2022-04-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/Decl.cpp:2735
+  const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
+  auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType());
+  if (!InitTy)

efriedma wrote:
> erichkeane wrote:
> > Same here
> You want something like this?
> 
> ```
> if (auto *List = dyn_cast(getInit()->IgnoreParens())) {
>   const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
>   if (auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType())) {
> return InitTy->getSize() != 0;
>   }
> }
> return false;
> ```
ah, shucks, i missed that this was an early exit (that is, I missed the '!').  
Disregard.  LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123826

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


[PATCH] D123826: Fix size of flexible array initializers, and re-enable assertions.

2022-04-15 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/AST/Decl.cpp:2735
+  const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
+  auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType());
+  if (!InitTy)

erichkeane wrote:
> Same here
You want something like this?

```
if (auto *List = dyn_cast(getInit()->IgnoreParens())) {
  const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
  if (auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType())) {
return InitTy->getSize() != 0;
  }
}
return false;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123826

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


[PATCH] D123627: Correctly diagnose prototype redeclaration errors in C

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

In D123627#3452491 , @efriedma wrote:

>> The reason you get the weird behavior with the note pointing to the same 
>> line as the declaration is because rintf() is a predefined builtin: 
>> https://godbolt.org/z/j3W759M7a (note the same lovely diagnostic note 
>> behavior).
>
> It points at the same location, but at least it says "'rintf' is a builtin" 
> (diag::note_previous_builtin_declaration).  The new codepath specifically 
> skips the code which emits that note.

This situation should now be improved in 
c7d4a05228090cb6b1b7f6e5d300f197897ac756 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123627

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


[clang] c7d4a05 - Properly identify builtins in a diagnostic note

2022-04-15 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-04-15T11:46:13-04:00
New Revision: c7d4a05228090cb6b1b7f6e5d300f197897ac756

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

LOG: Properly identify builtins in a diagnostic note

When emitting a "conflicting types" warning for a function declaration,
it's more clear to diagnose the previous declaration specifically as
being a builtin if it one.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/prototype-redecls.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0708e687c5752..76bf67397a6ee 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3256,6 +3256,10 @@ getNoteDiagForInvalidRedeclaration(const T *Old, const T 
*New) {
 PrevDiag = diag::note_previous_definition;
   else if (Old->isImplicit()) {
 PrevDiag = diag::note_previous_implicit_declaration;
+if (const auto *FD = dyn_cast(Old)) {
+  if (FD->getBuiltinID())
+PrevDiag = diag::note_previous_builtin_declaration;
+}
 if (OldLocation.isInvalid())
   OldLocation = New->getLocation();
   } else

diff  --git a/clang/test/Sema/prototype-redecls.c 
b/clang/test/Sema/prototype-redecls.c
index 9b85753cbbb5b..ca3355f79d69a 100644
--- a/clang/test/Sema/prototype-redecls.c
+++ b/clang/test/Sema/prototype-redecls.c
@@ -22,3 +22,10 @@ void derp(x) int x; {}
 void garp(int);
 void garp();
 void garp(x) int x; {}
+
+// Ensure redeclarations that conflict with a builtin use a note which makes it
+// clear that the previous declaration was a builtin.
+float rintf() { // expected-error {{conflicting types for 'rintf'}} \
+   expected-note {{'rintf' is a builtin with type 'float 
(float)'}}
+  return 1.0f;
+}



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


[clang] 52e6a27 - Clean up `OMPAtomicDirective::Create`

2022-04-15 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-04-15T11:41:26-04:00
New Revision: 52e6a27690ca8e5f07cc646716c3736475b7746b

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

LOG: Clean up `OMPAtomicDirective::Create`

Added: 


Modified: 
clang/include/clang/AST/StmtOpenMP.h
clang/lib/AST/StmtOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 28b3567b36556..0aa318d84a93f 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -2889,6 +2889,27 @@ class OMPAtomicDirective : public OMPExecutableDirective 
{
   void setCond(Expr *C) { Data->getChildren()[DataPositionTy::POS_Cond] = C; }
 
 public:
+  struct Expressions {
+/// 'x' part of the associated expression/statement.
+Expr *X = nullptr;
+/// 'v' part of the associated expression/statement.
+Expr *V = nullptr;
+/// 'expr' part of the associated expression/statement.
+Expr *E = nullptr;
+/// UE Helper expression of the form:
+/// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or
+/// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
+Expr *UE = nullptr;
+/// 'd' part of the associated expression/statement.
+Expr *D = nullptr;
+/// Conditional expression in `atomic compare` construct.
+Expr *Cond = nullptr;
+/// True if UE has the first form and false if the second.
+bool IsXLHSInRHSPart;
+/// True if original value of 'x' must be stored in 'v', not an updated 
one.
+bool IsPostfixUpdate;
+  };
+
   /// Creates directive with a list of \a Clauses and 'x', 'v' and 'expr'
   /// parts of the atomic construct (see Section 2.12.6, atomic Construct, for
   /// detailed description of 'x', 'v' and 'expr').
@@ -2898,23 +2919,12 @@ class OMPAtomicDirective : public 
OMPExecutableDirective {
   /// \param EndLoc Ending Location of the directive.
   /// \param Clauses List of clauses.
   /// \param AssociatedStmt Statement, associated with the directive.
-  /// \param X 'x' part of the associated expression/statement.
-  /// \param V 'v' part of the associated expression/statement.
-  /// \param E 'expr' part of the associated expression/statement.
-  /// \param UE Helper expression of the form
-  /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or
-  /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
-  /// \param D 'd' part of the associated expression/statement.
-  /// \param Cond Conditional expression in `atomic compare` construct.
-  /// \param IsXLHSInRHSPart true if \a UE has the first form and false if the
-  /// second.
-  /// \param IsPostfixUpdate true if original value of 'x' must be stored in
-  /// 'v', not an updated one.
-  static OMPAtomicDirective *
-  Create(const ASTContext , SourceLocation StartLoc, SourceLocation EndLoc,
- ArrayRef Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V,
- Expr *E, Expr *UE, Expr *D, Expr *Cond, bool IsXLHSInRHSPart,
- bool IsPostfixUpdate);
+  /// \param Exprs Associated expressions or statements.
+  static OMPAtomicDirective *Create(const ASTContext ,
+SourceLocation StartLoc,
+SourceLocation EndLoc,
+ArrayRef Clauses,
+Stmt *AssociatedStmt, Expressions Exprs);
 
   /// Creates an empty directive with the place for \a NumClauses
   /// clauses.

diff  --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp
index 84a4de00328a8..15e13da27dd84 100644
--- a/clang/lib/AST/StmtOpenMP.cpp
+++ b/clang/lib/AST/StmtOpenMP.cpp
@@ -866,19 +866,17 @@ OMPOrderedDirective 
*OMPOrderedDirective::CreateEmpty(const ASTContext ,
 OMPAtomicDirective *
 OMPAtomicDirective::Create(const ASTContext , SourceLocation StartLoc,
SourceLocation EndLoc, ArrayRef 
Clauses,
-   Stmt *AssociatedStmt, Expr *X, Expr *V, Expr *E,
-   Expr *UE, Expr *D, Expr *Cond, bool IsXLHSInRHSPart,
-   bool IsPostfixUpdate) {
+   Stmt *AssociatedStmt, Expressions Exprs) {
   auto *Dir = createDirective(
   C, Clauses, AssociatedStmt, /*NumChildren=*/6, StartLoc, EndLoc);
-  Dir->setX(X);
-  Dir->setV(V);
-  Dir->setExpr(E);
-  Dir->setUpdateExpr(UE);
-  Dir->setD(D);
-  Dir->setCond(Cond);
-  Dir->IsXLHSInRHSPart = IsXLHSInRHSPart;
-  Dir->IsPostfixUpdate = IsPostfixUpdate;
+  Dir->setX(Exprs.X);
+  Dir->setV(Exprs.V);
+  Dir->setExpr(Exprs.E);
+  Dir->setUpdateExpr(Exprs.UE);
+  Dir->setD(Exprs.D);
+  Dir->setCond(Exprs.Cond);
+  Dir->IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart;
+  Dir->IsPostfixUpdate = 

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

2022-04-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:2967
+ "parameters!");
+  for (FunctionProtoType::param_type_iterator
+   O = OldType->param_type_begin(),

royjacobson wrote:
> erichkeane wrote:
> > Thanks for the clarification on 'Reversed'.  The comment makes it more 
> > clear.
> > 
> > This whole 'for' header is... really tough to mentally parse, even BEFORE 
> > this, and now it is even worse with 'Reversed' involved.  I would prefer 
> > that the iterators be initialized ahead of time.  Additionally, can we use 
> > `reverse_iterator` for the 'NewType' instead of branching on `Reversed` 
> > here?  
> > 
> > Any other suggestions you have to simplify this loop would also be 
> > appreciated.  I might ALSO consider using 'zip' here?
> I made it index based which IMO is easier to understand now.
> 
> I thought reverse_iterator would be annoying because I would need to make the 
> code a template since it's a different type.
> 
> Also - ping about the comment in isBetterOverloadCandidate :)
Ah, right, you'd have 1 reverse iterator on one side of the 'zip'.  Thats 
unfortunate.  I guess this reads well-enough though, iti s definitely an 
improvement.



Comment at: clang/lib/Sema/SemaOverload.cpp:9829
+  bool CanCompareConstraints = false;
+  if (Cand1.Function && Cand2.Function && Cand1.Function->hasPrototype() &&
+  Cand2.Function->hasPrototype()) {

royjacobson wrote:
> erichkeane wrote:
> > Since the point of this is to just calculate the CanCompareConstraints, I 
> > think it should be a separate function called below where it is used.  
> Do you mean as in a separate `Sema` function? Or a local lambda?
Just a static function is fine, basically its a whole lot of work happening in 
this function for a single result, so I'm suggesting splitting off the 
calculation for `CanCompareConstraints` into its own function, so you get:

`bool CanCompareConstrants = new_function(...);`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

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


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

2022-04-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:2967
+ "parameters!");
+  for (FunctionProtoType::param_type_iterator
+   O = OldType->param_type_begin(),

erichkeane wrote:
> Thanks for the clarification on 'Reversed'.  The comment makes it more clear.
> 
> This whole 'for' header is... really tough to mentally parse, even BEFORE 
> this, and now it is even worse with 'Reversed' involved.  I would prefer that 
> the iterators be initialized ahead of time.  Additionally, can we use 
> `reverse_iterator` for the 'NewType' instead of branching on `Reversed` here? 
>  
> 
> Any other suggestions you have to simplify this loop would also be 
> appreciated.  I might ALSO consider using 'zip' here?
I made it index based which IMO is easier to understand now.

I thought reverse_iterator would be annoying because I would need to make the 
code a template since it's a different type.

Also - ping about the comment in isBetterOverloadCandidate :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123182

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


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

2022-04-15 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 423116.
royjacobson marked an inline comment as not done.
royjacobson added a comment.

Update for look inside FunctionParamTypesAreEqual to be index based and simpler.


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 ) {} // 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
@@ -2952,24 +2952,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) {
+  

[PATCH] D123858: [clang][dataflow] Ensure well-formed flow conditions.

2022-04-15 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, sgatev.
Herald added subscribers: tschuett, steakhal, rnkovacs.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Ensure that the expressions associated with terminators are associated with a
value. Otherwise, we can generate degenerate flow conditions, where both
branches share the same condition.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123858

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

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2890,6 +2890,68 @@
   });
 }
 
+TEST_F(TransferTest, OpaqueFlowConditionMergesToOpaqueBool) {
+  std::string Code = R"(
+bool foo();
+
+void target() {
+  bool Bar = true;
+  if (foo())
+Bar = false;
+  (void)0;
+  /*[[p]]*/
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment  = Results[0].second.Env;
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+auto  =
+*cast(Env.getValue(*BarDecl, SkipPast::Reference));
+
+EXPECT_FALSE(Env.flowConditionImplies(BarVal));
+  });
+}
+
+TEST_F(TransferTest, OpaqueFlowConditionInsideBranchMergesToOpaqueBool) {
+  std::string Code = R"(
+bool foo();
+
+void target(bool Cond) {
+  bool Bar = true;
+  if (Cond) {
+if (foo())
+  Bar = false;
+(void)0;
+/*[[p]]*/
+  }
+}
+  )";
+  runDataflow(
+  Code, [](llvm::ArrayRef<
+   std::pair>>
+   Results,
+   ASTContext ) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment  = Results[0].second.Env;
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+auto  =
+*cast(Env.getValue(*BarDecl, SkipPast::Reference));
+
+EXPECT_FALSE(Env.flowConditionImplies(BarVal));
+  });
+}
+
 TEST_F(TransferTest, CorrelatedBranches) {
   std::string Code = R"(
 void target(bool B, bool C) {
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -32,6 +32,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
 
 namespace clang {
 namespace dataflow {
@@ -108,8 +109,32 @@
 
 auto *Val =
 cast_or_null(Env.getValue(Cond, SkipPast::Reference));
-if (Val == nullptr)
-  return;
+// Value merging depends on flow conditions from different environments
+// being mutually exclusive. So, we need *some* value for the condition
+// expression, even if just an atom.
+if (Val == nullptr) {
+  Val = ();
+  QualType Type = Cond.getType();
+  assert(Type->isBooleanType() || Type->isReferenceType());
+  if (Type->isBooleanType()) {
+auto  = Env.createStorageLocation(Cond);
+Env.setStorageLocation(Cond, Loc);
+Env.setValue(Loc, *Val);
+  } else if (auto *CondVal = cast_or_null(
+ Env.getValue(Cond, SkipPast::None))) {
+Env.setValue(CondVal->getPointeeLoc(), *Val);
+  } else {
+QualType PointeeType = Type->castAs()->getPointeeType();
+StorageLocation  = Env.createStorageLocation(PointeeType);
+Env.setValue(PointeeLoc, *Val);
+auto *Loc = Env.getStorageLocation(Cond, SkipPast::None);
+// `Cond` must have been processed already (and so must have an
+// associated location) since it came from the predecessor block.
+assert(Loc != nullptr);
+Env.setValue(*Loc, Env.takeOwnership(
+   std::make_unique(PointeeLoc)));
+  }
+}
 
 // The condition must be inverted for the successor that encompasses the
 // "else" branch, if such exists.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-15 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG04000c2f928a: [clang] Implement Change scope of lambda 
trailing-return-type (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1356,7 +1356,7 @@
 
   Change scope of lambda trailing-return-type
   https://wg21.link/P2036R3;>P2036R3
-  No
+  Clang 15
 
 
   Multidimensional subscript operator
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -95,7 +95,7 @@
 #ifdef AVOID
   auto l4 = [var = param] (int param) { ; }; // no warning
 #else
-  auto l4 = [var = param] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+  auto l4 = [var = param](int param) { ; }; // expected-warning 2{{declaration shadows a local variable}}
 #endif
 
   // Make sure that inner lambdas work as well.
Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -0,0 +1,173 @@
+// RUN: %clang_cc1 -std=c++2b -verify -fsyntax-only %s
+
+template 
+constexpr bool is_same = false;
+
+template 
+constexpr bool is_same = true;
+
+void f() {
+
+  int y;
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  auto ref = [ = y](
+ decltype([&](decltype(x)) { return 0; }) y) {
+return x;
+  };
+}
+
+void test_noexcept() {
+
+  int y;
+
+  static_assert(noexcept([x = 1] noexcept(is_same) {}()));
+  static_assert(noexcept([x = 1] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([y] noexcept(is_same) {}()));
+  static_assert(noexcept([y] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([=] noexcept(is_same) {}()));
+  static_assert(noexcept([=] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([&] noexcept(is_same) {}()));
+  static_assert(noexcept([&] mutable noexcept(is_same) {}()));
+
+  static_assert(noexcept([&] mutable noexcept(!is_same) {}())); // expected-error {{static_assert failed due}}
+}
+
+void test_requires() {
+
+  int x;
+
+  [x = 1]() requires is_same {}
+  ();
+  [x = 1]() mutable requires is_same {}
+  ();
+  [x]() requires is_same {}
+  ();
+  [x]() mutable requires is_same {}
+  ();
+  [=]() requires is_same {}
+  ();
+  [=]() mutable requires is_same {}
+  ();
+  [&]() requires is_same {}
+  ();
+  [&]() mutable requires is_same {}
+  ();
+  []() requires is_same {}
+  ();
+  []() mutable requires is_same {}
+  ();
+
+  [x = 1]() requires is_same {} (); //expected-error {{no matching function for call to object of type}} \
+   // expected-note {{candidate function not viable}} \
+   // expected-note {{'is_same' evaluated to false}}
+  [x = 1]() mutable requires is_same {} (); // expected-error {{no matching function for call to object of type}} \
+ // expected-note {{candidate function not viable}} \
+ // expected-note {{'is_same' evaluated to false}}
+}
+
+void err() {
+  int y, z;// expected-note 2{{declared here}}
+  auto implicit_tpl = [=]( // expected-note {{variable 'y' is captured here}}
+  decltype(
+  [&] { return 0; }) y) { //expected-error{{captured 

[clang] 04000c2 - [clang] Implement Change scope of lambda trailing-return-type

2022-04-15 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-04-15T16:50:52+02:00
New Revision: 04000c2f928a7adc32138a664d167f01b642bef3

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

LOG: [clang] Implement Change scope of lambda trailing-return-type

Implement P2036R3.

Captured variables by copy (explicitely or not), are deduced
correctly at the point we know whether the lambda is mutable,
and ill-formed before that.

Up until now, the entire lambda declaration up to the start of the body would 
be parsed in the parent scope, such that capture would not be available to look 
up.

The scoping is changed to have an outer lambda scope, followed by the lambda 
prototype and body.

The lambda scope is necessary because there may be a template scope between the 
start of the lambda (to which we want to attach the captured variable) and the 
prototype scope.

We also need to introduce a declaration context to attach the captured variable 
to (and several parts of clang assume captures are handled from the call 
operator context), before we know the type of the call operator.

The order of operations is as follow:

* Parse the init capture in the lambda's parent scope

* Introduce a lambda scope

* Create the lambda class and call operator

* Add the init captures to the call operator context and the lambda scope. But 
the variables are not capured yet (because we don't know their type).
Instead, explicit  captures are stored in a temporary map that conserves the 
order of capture (for the purpose of having a stable order in the ast dumps).

* A flag is set on LambdaScopeInfo to indicate that we have not yet injected 
the captures.

* The parameters are parsed (in the parent context, as lambda mangling recurses 
in the parent context, we couldn't mangle a lambda that is attached to the 
context of a lambda whose type is not yet known).

* The lambda qualifiers are parsed, at this point We can switch (for the second 
time) inside the lambda context, unset the flag indicating that we have not 
parsed the lambda qualifiers,
record the lambda is mutable and capture the explicit variables.

* We can parse the rest of the lambda type, transform the lambda and call 
operator's types and also transform the call operator to a template function 
decl where necessary.

At this point, both captures and parameters can be injected in the body's 
scope. When trying to capture an implicit variable, if we are before the 
qualifiers of a lambda, we need to remember that the variables are still in the 
parent's context (rather than in the call operator's).

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

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

Added: 
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Scope.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/Scope.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2497280dfdd6d..c72028c718586 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -255,6 +255,9 @@ C++2b Feature Support
 - Implemented `P2128R6: Multidimensional subscript operator 
`_.
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 - Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
+- Implemented `P2036R3: Change scope of lambda trailing-return-type 
`_.
+  This proposal modifies how variables captured in lambdas can appear in 
trailing return type
+  expressions and how their types are deduced therein, in all C++ language 
versions.
 
 CUDA Language Changes in Clang
 --

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 04a9daa14e05e..c640f7f7ba63f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1799,6 +1799,20 @@ class CXXRecordDecl : public RecordDecl {
 return getLambdaData().MethodTyInfo;
   }
 
+  void setLambdaTypeInfo(TypeSourceInfo *TS) {
+auto *DD = DefinitionData;
+assert(DD && DD->IsLambda 

[PATCH] D109239: Add support for floating-option `-ffp-eval-method` and for new `pragma clang fp eval-method`

2022-04-15 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D109239#3453770 , @glandium wrote:

> Is it expected that `__FLT_EVAL_METHOD__` is not set at all anymore by 
> default after this change?

@glandium would you mind giving a reproducer. We might have missed a flow path 
where the macro is undefined.


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

https://reviews.llvm.org/D109239

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


[clang] 26b0ecb - [clang][deps] NFC: Update documentation

2022-04-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-04-15T16:24:41+02:00
New Revision: 26b0ecb8985b7e76a5ca0965d3d464611eda14f0

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

LOG: [clang][deps] NFC: Update documentation

Added: 


Modified: 
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp 
b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 8b6697f020ab3..7e7747a36f27a 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -145,15 +145,15 @@ static llvm::cl::opt Format(
 // Build tools that want to put the PCM files in a 
diff erent location should use
 // the C++ APIs instead, of which there are two flavors:
 //
-// 1. APIs that generate arguments with paths to modulemap and PCM files via
-//callbacks provided by the client:
-// * ModuleDeps::getCanonicalCommandLine(LookupPCMPath, LookupModuleDeps)
-// * FullDependencies::getAdditionalArgs(LookupPCMPath, LookupModuleDeps)
+// 1. APIs that generate arguments with paths PCM files via a callback provided
+//by the client:
+// * ModuleDeps::getCanonicalCommandLine(LookupPCMPath)
+// * FullDependencies::getCommandLine(LookupPCMPath)
 //
-// 2. APIs that don't generate arguments with paths to modulemap or PCM files
-//and instead expect the client to append them manually after the fact:
+// 2. APIs that don't generate arguments with paths PCM files and instead 
expect
+// the client to append them manually after the fact:
 // * ModuleDeps::getCanonicalCommandLineWithoutModulePaths()
-// * FullDependencies::getAdditionalArgsWithoutModulePaths()
+// * FullDependencies::getCommandLineWithoutModulePaths()
 //
 static llvm::cl::opt GenerateModulesPathArgs(
 "generate-modules-path-args",



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


[clang] 7ed01ba - [clang][deps] NFC: Inline function with single caller

2022-04-15 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-04-15T16:24:40+02:00
New Revision: 7ed01ba88d67a0eb79663547f9ec21d106f7b281

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

LOG: [clang][deps] NFC: Inline function with single caller

Added: 


Modified: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index aee4ddee9707b..3bb44e44187ba 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -56,10 +56,6 @@ struct FullDependencies {
 
   /// Get the full command line, excluding -fmodule-file=" arguments.
   std::vector getCommandLineWithoutModulePaths() const;
-
-  /// Get additional arguments suitable for appending to the original Clang
-  /// command line, excluding "-fmodule-file=" arguments.
-  std::vector getAdditionalArgsWithoutModulePaths() const;
 };
 
 struct FullDependenciesResult {

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
index 55d2c48af41a2..6fd3a83fd3f7b 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -27,9 +27,10 @@ std::vector
 FullDependencies::getCommandLineWithoutModulePaths() const {
   std::vector Args = OriginalCommandLine;
 
-  std::vector AdditionalArgs =
-  getAdditionalArgsWithoutModulePaths();
-  Args.insert(Args.end(), AdditionalArgs.begin(), AdditionalArgs.end());
+  Args.push_back("-fno-implicit-modules");
+  Args.push_back("-fno-implicit-module-maps");
+  for (const PrebuiltModuleDep  : PrebuiltModuleDeps)
+Args.push_back("-fmodule-file=" + PMD.PCMFile);
 
   // This argument is unused in explicit compiles.
   llvm::erase_if(Args, [](const std::string ) {
@@ -42,19 +43,6 @@ FullDependencies::getCommandLineWithoutModulePaths() const {
   return Args;
 }
 
-std::vector
-FullDependencies::getAdditionalArgsWithoutModulePaths() const {
-  std::vector Args{
-  "-fno-implicit-modules",
-  "-fno-implicit-module-maps",
-  };
-
-  for (const PrebuiltModuleDep  : PrebuiltModuleDeps)
-Args.push_back("-fmodule-file=" + PMD.PCMFile);
-
-  return Args;
-}
-
 DependencyScanningTool::DependencyScanningTool(
 DependencyScanningService )
 : Worker(Service) {}



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


[PATCH] D123856: [clang][lex] NFCI: Use FileEntryRef in ModuleMap::diagnoseHeaderInclusion()

2022-04-15 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes uses of the deprecated `DirectoryEntry::getName()` from the 
`ModuleMap::diagnoseHeaderInclusion()` function by using 
`{File,Directory}EntryRef` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123856

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Lex/PPDirectives.cpp


Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -905,7 +905,7 @@
 if (SuggestedModule && !LangOpts.AsmPreprocessor)
   HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
   RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
-  Filename, >getFileEntry());
+  Filename, *FE);
 return FE;
   }
 
@@ -921,7 +921,7 @@
 if (SuggestedModule && !LangOpts.AsmPreprocessor)
   HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
   RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
-  Filename, >getFileEntry());
+  Filename, *FE);
 return FE;
   }
 }
@@ -936,7 +936,7 @@
   if (SuggestedModule && !LangOpts.AsmPreprocessor)
 HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
 RequestingModule, RequestingModuleIsModuleInterface,
-FilenameLoc, Filename, >getFileEntry());
+FilenameLoc, Filename, *FE);
   return FE;
 }
   }
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -473,8 +473,7 @@
 void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
 bool RequestingModuleIsModuleInterface,
 SourceLocation FilenameLoc,
-StringRef Filename,
-const FileEntry *File) {
+StringRef Filename, FileEntryRef File) 
{
   // No errors for indirect modules. This may be a bit of a problem for modules
   // with no source files.
   if (getTopLevelOrNull(RequestingModule) != getTopLevelOrNull(SourceModule))
@@ -542,7 +541,7 @@
 diag::warn_non_modular_include_in_framework_module :
 diag::warn_non_modular_include_in_module;
 Diags.Report(FilenameLoc, DiagID) << RequestingModule->getFullModuleName()
-<< File->getName();
+<< File.getName();
   }
 }
 
Index: clang/include/clang/Lex/ModuleMap.h
===
--- clang/include/clang/Lex/ModuleMap.h
+++ clang/include/clang/Lex/ModuleMap.h
@@ -479,7 +479,7 @@
   void diagnoseHeaderInclusion(Module *RequestingModule,
bool RequestingModuleIsModuleInterface,
SourceLocation FilenameLoc, StringRef Filename,
-   const FileEntry *File);
+   FileEntryRef File);
 
   /// Determine whether the given header is part of a module
   /// marked 'unavailable'.


Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -905,7 +905,7 @@
 if (SuggestedModule && !LangOpts.AsmPreprocessor)
   HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
   RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
-  Filename, >getFileEntry());
+  Filename, *FE);
 return FE;
   }
 
@@ -921,7 +921,7 @@
 if (SuggestedModule && !LangOpts.AsmPreprocessor)
   HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
   RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
-  Filename, >getFileEntry());
+  Filename, *FE);
 return FE;
   }
 }
@@ -936,7 +936,7 @@
   if (SuggestedModule && !LangOpts.AsmPreprocessor)
 HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
 RequestingModule, RequestingModuleIsModuleInterface,
-FilenameLoc, Filename, >getFileEntry());
+FilenameLoc, Filename, *FE);
   return FE;
 }
   }
Index: clang/lib/Lex/ModuleMap.cpp
===
--- clang/lib/Lex/ModuleMap.cpp
+++ clang/lib/Lex/ModuleMap.cpp
@@ -473,8 +473,7 @@
 void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
 bool RequestingModuleIsModuleInterface,
  

  1   2   >