[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-17 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,132 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr char IgnoreSingleElementAggregatesName[] =
+"IgnoreSingleElementAggregates";
+static constexpr bool IgnoreSingleElementAggregatesDefault = true;
+
+static constexpr char RestrictToPODTypesName[] = "RestrictToPODTypes";
+static constexpr bool RestrictToPODTypesDefault = false;
+
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static constexpr bool IgnoreMacrosDefault = true;
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  if (const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ? &Node : Node.getSyntacticForm()) {
+return llvm::all_of(SyntacticForm->children(), [](auto *InitExpr) {
+  return isa(InitExpr);
+});
+  }
+  return true;
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+} // namespace
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
+  IgnoreMacros(Options.get(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasBaseWithFields =
+  hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(HasBaseWithFields))
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const llvm::DenseMap Designators =
+clang::tooling::getUnwrittenDesignators(SyntacticInitList);
+if (isFullyUnd

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-17 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,43 @@
+//===--- DesignatedInitializers.h ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file provides utilities for designated initializers.
+///
+//===--===//
+
+#include "clang/AST/Expr.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/DenseMap.h"
+
+namespace clang::tooling {
+
+/// Get designators describing the elements of a (syntactic) init list.
+///
+/// Given for example the type
+///
+/// struct S { int i, j; };
+///
+/// and the definition
+///
+/// S s{1, 2};
+///
+/// calling `getDesignators` for the initializer list expression `{1, 2}`
+/// would produce the map `{loc(1): ".i", loc(2): ".j"}`.
+///
+/// It does not produce designators for any explicitly-written nested lists,
+/// e.g. `{1, .j=2}` would only return `{loc(1): ".i"}`.
+///
+/// It also considers structs with fields of record types like
+/// `struct T { S s; };`. In this case, there would be designators of the
+/// form
+/// `.s.i` and `.s.j` in the returned map.
+llvm::DenseMap
+getDesignators(const clang::InitListExpr *Syn);

PiotrZSL wrote:

That's also an option, but i think that clangd link to clang-tidy is 
configurable.

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [llvm] [Documentation] Replace recommonmark by myst-parser (PR #65664)

2024-02-17 Thread Michał Górny via cfe-commits

mgorny wrote:

I'm sorry for being late to the party but what's the rationale for removing 
support for building manpages without myst-parser, that FWICS isn't used for 
manpages at all? I don't see any answer neither in the commit message, nor in 
this thread. It really feels like you've just *shrugged* and removed it without 
any consideration for the prior effort to make things work better.

https://github.com/llvm/llvm-project/pull/65664
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-17 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/81506

>From 52b239153b2fc4f52e889ad2044daa6ed5cbc836 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 12 Feb 2024 17:44:38 +0300
Subject: [PATCH 01/10] Initial implementation

---
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/include/clang/Sema/Sema.h  |  2 +
 clang/lib/Parse/ParseDeclCXX.cpp |  1 +
 clang/lib/Parse/ParseExpr.cpp|  1 +
 clang/lib/Sema/SemaChecking.cpp  |  4 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  3 +
 clang/test/SemaCXX/type-traits.cpp   | 77 
 7 files changed, 89 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..112bfe8b23c2c0 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -520,6 +520,7 @@ TYPE_TRAIT_1(__is_trivially_copyable, IsTriviallyCopyable, 
KEYCXX)
 TYPE_TRAIT_1(__is_union, IsUnion, KEYCXX)
 TYPE_TRAIT_1(__has_unique_object_representations,
  HasUniqueObjectRepresentations, KEYCXX)
+TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible, KEYCXX)
 
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) KEYWORD(__##Trait, KEYCXX)
 #include "clang/Basic/TransformTypeTraits.def"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 851560f759f0e4..ddeba328749653 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14040,6 +14040,8 @@ class Sema final {
   bool SemaValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum);
 
 public:
+  bool SemaIsLayoutCompatible(QualType T1, QualType T2);
+  
   // Used by C++ template instantiation.
   ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
   ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 79928ddb5af599..c9360981c1c1e4 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1717,6 +1717,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_fundamental,
   tok::kw___is_integral,
   tok::kw___is_interface_class,
+  tok::kw___is_layout_compatible,
   tok::kw___is_literal,
   tok::kw___is_lvalue_expr,
   tok::kw___is_lvalue_reference,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 52cebdb6f64bac..db21a7f1e9e368 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1114,6 +1114,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   REVERTIBLE_TYPE_TRAIT(__is_fundamental);
   REVERTIBLE_TYPE_TRAIT(__is_integral);
   REVERTIBLE_TYPE_TRAIT(__is_interface_class);
+  REVERTIBLE_TYPE_TRAIT(__is_layout_compatible);
   REVERTIBLE_TYPE_TRAIT(__is_literal);
   REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr);
   REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference);
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 71e6e7230fc455..8aa744873f3704 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19150,6 +19150,10 @@ static bool isLayoutCompatible(ASTContext &C, QualType 
T1, QualType T2) {
   return false;
 }
 
+bool Sema::SemaIsLayoutCompatible(QualType T1, QualType T2) {
+  return isLayoutCompatible(getASTContext(), T1, T2);
+}
+
 //===--- CHECK: pointer_with_type_tag attribute: datatypes should match //
 
 /// Given a type tag expression find the type tag itself.
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..b279c367342fce 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5922,6 +5922,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait 
BTT, QualType LhsT,
 
 llvm_unreachable("unhandled type trait");
 return false;
+  }
+  case BTT_IsLayoutCompatible: {
+return Self.SemaIsLayoutCompatible(LhsT, RhsT);
   }
 default: llvm_unreachable("not a BTT");
   }
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..f50bedc275359b 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1558,6 +1558,83 @@ void is_standard_layout()
   int t71[F(__is_standard_layout(HasEmptyIndirectBaseAsSecondUnionMember))];
 }
 
+struct CStruct2 {
+  int one;
+  int two;
+};
+
+struct CEmptyStruct2 {};
+
+struct CppEmptyStruct2 : CStruct2 {};
+struct CppStructStandard2 : CEmptyStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByBase2 : CStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByVirt2 : CStruct2 {
+  virtual void method() {}
+};
+struct CppStructNonStandardByMemb2 : CStruct2 {
+  CppStructNonStandardByVirt member;
+};
+struct CppStructNonStandar

[clang] [clang] Implement `__is_layout_compatible` (PR #81506)

2024-02-17 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/81506

>From 52b239153b2fc4f52e889ad2044daa6ed5cbc836 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 12 Feb 2024 17:44:38 +0300
Subject: [PATCH 01/11] Initial implementation

---
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/include/clang/Sema/Sema.h  |  2 +
 clang/lib/Parse/ParseDeclCXX.cpp |  1 +
 clang/lib/Parse/ParseExpr.cpp|  1 +
 clang/lib/Sema/SemaChecking.cpp  |  4 ++
 clang/lib/Sema/SemaExprCXX.cpp   |  3 +
 clang/test/SemaCXX/type-traits.cpp   | 77 
 7 files changed, 89 insertions(+)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..112bfe8b23c2c0 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -520,6 +520,7 @@ TYPE_TRAIT_1(__is_trivially_copyable, IsTriviallyCopyable, 
KEYCXX)
 TYPE_TRAIT_1(__is_union, IsUnion, KEYCXX)
 TYPE_TRAIT_1(__has_unique_object_representations,
  HasUniqueObjectRepresentations, KEYCXX)
+TYPE_TRAIT_2(__is_layout_compatible, IsLayoutCompatible, KEYCXX)
 
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) KEYWORD(__##Trait, KEYCXX)
 #include "clang/Basic/TransformTypeTraits.def"
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 851560f759f0e4..ddeba328749653 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14040,6 +14040,8 @@ class Sema final {
   bool SemaValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum);
 
 public:
+  bool SemaIsLayoutCompatible(QualType T1, QualType T2);
+  
   // Used by C++ template instantiation.
   ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
   ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 79928ddb5af599..c9360981c1c1e4 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1717,6 +1717,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_fundamental,
   tok::kw___is_integral,
   tok::kw___is_interface_class,
+  tok::kw___is_layout_compatible,
   tok::kw___is_literal,
   tok::kw___is_lvalue_expr,
   tok::kw___is_lvalue_reference,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 52cebdb6f64bac..db21a7f1e9e368 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1114,6 +1114,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   REVERTIBLE_TYPE_TRAIT(__is_fundamental);
   REVERTIBLE_TYPE_TRAIT(__is_integral);
   REVERTIBLE_TYPE_TRAIT(__is_interface_class);
+  REVERTIBLE_TYPE_TRAIT(__is_layout_compatible);
   REVERTIBLE_TYPE_TRAIT(__is_literal);
   REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr);
   REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference);
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 71e6e7230fc455..8aa744873f3704 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19150,6 +19150,10 @@ static bool isLayoutCompatible(ASTContext &C, QualType 
T1, QualType T2) {
   return false;
 }
 
+bool Sema::SemaIsLayoutCompatible(QualType T1, QualType T2) {
+  return isLayoutCompatible(getASTContext(), T1, T2);
+}
+
 //===--- CHECK: pointer_with_type_tag attribute: datatypes should match //
 
 /// Given a type tag expression find the type tag itself.
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..b279c367342fce 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5922,6 +5922,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait 
BTT, QualType LhsT,
 
 llvm_unreachable("unhandled type trait");
 return false;
+  }
+  case BTT_IsLayoutCompatible: {
+return Self.SemaIsLayoutCompatible(LhsT, RhsT);
   }
 default: llvm_unreachable("not a BTT");
   }
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 5659594577111e..f50bedc275359b 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1558,6 +1558,83 @@ void is_standard_layout()
   int t71[F(__is_standard_layout(HasEmptyIndirectBaseAsSecondUnionMember))];
 }
 
+struct CStruct2 {
+  int one;
+  int two;
+};
+
+struct CEmptyStruct2 {};
+
+struct CppEmptyStruct2 : CStruct2 {};
+struct CppStructStandard2 : CEmptyStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByBase2 : CStruct2 {
+  int three;
+  int four;
+};
+struct CppStructNonStandardByVirt2 : CStruct2 {
+  virtual void method() {}
+};
+struct CppStructNonStandardByMemb2 : CStruct2 {
+  CppStructNonStandardByVirt member;
+};
+struct CppStructNonStandar

[clang-tools-extra] [clangd] don't lower severity of clang-tidy modernize-* checks to remarks (PR #75706)

2024-02-17 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti closed 
https://github.com/llvm/llvm-project/pull/75706
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] don't lower severity of clang-tidy modernize-* checks to remarks (PR #75706)

2024-02-17 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

I'm closing this because it is not a good way to solve this. IMO, a good 
approach would be to let users write the diagnostic severity they want to have 
for all or for specific diagnostics groups in their clangd config file (like 
described above). I've opened clangd/clangd#1937 to discuss how to move forward 
with a better plan.

https://github.com/llvm/llvm-project/pull/75706
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Simplify err_init_conversion_failed diagnostic message for const variables (PR #82109)

2024-02-17 Thread Artem Tyurin via cfe-commits

https://github.com/agentcooper created 
https://github.com/llvm/llvm-project/pull/82109

Fixes #73399.

I initially tried to create a new `EntityKind` enum case to represent constants 
as it makes it easier to use `Entity.getKind()` with the diagnostic message. 
But in the end I've decided against it, as the new case needs to be handled in 
many places and feels error-prone.

>From 114a6b7a5c1b9993e06d49bfd0c377baaef2d7cb Mon Sep 17 00:00:00 2001
From: Artem Tyurin 
Date: Sat, 17 Feb 2024 15:16:17 +0100
Subject: [PATCH 1/2] [clang][Sema] Simplify err_init_conversion_failed
 diagnostic message for const variables

---
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Sema/SemaInit.cpp   | 22 ++-
 .../SemaCXX/constant-expression-cxx11.cpp |  2 +-
 .../SemaCXX/err_init_conversion_failed.cpp| 11 ++
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..1c9a69167c28d1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2204,7 +2204,7 @@ def err_destructor_template : Error<
 
 // C++ initialization
 def err_init_conversion_failed : Error<
-  "cannot initialize %select{a variable|a parameter|template parameter|"
+  "cannot initialize %select{a constant|a variable|a parameter|template 
parameter|"
   "return object|statement expression result|an "
   "exception object|a member subobject|an array element|a new value|a value|a "
   "base class|a constructor delegation|a vector element|a block element|a "
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b6de06464cd6f3..c1846d9a80c8f2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9804,12 +9804,22 @@ bool InitializationSequence::Diagnose(Sema &S,
 
   case FK_ConversionFailed: {
 QualType FromType = OnlyArg->getType();
-PartialDiagnostic PDiag = S.PDiag(diag::err_init_conversion_failed)
-  << (int)Entity.getKind()
-  << DestType
-  << OnlyArg->isLValue()
-  << FromType
-  << Args[0]->getSourceRange();
+
+// NOTE: need to be in sync with err_init_conversion_failed
+const auto TotalSpecialKinds = 1;
+
+PartialDiagnostic PDiag = S.PDiag(diag::err_init_conversion_failed);
+if (Entity.getKind() == InitializedEntity::EK_Variable &&
+DestType.isConstQualified()) {
+  QualType NonConstDestType = DestType;
+  NonConstDestType.removeLocalConst();
+  PDiag << 0 /* a constant */
+<< NonConstDestType;
+} else {
+  PDiag << (TotalSpecialKinds + (int)Entity.getKind()) << DestType;
+}
+PDiag << OnlyArg->isLValue() << FromType << Args[0]->getSourceRange();
+
 S.HandleFunctionTypeMismatch(PDiag, FromType, DestType);
 S.Diag(Kind.getLocation(), PDiag);
 emitBadConversionNotes(S, Entity, Args[0]);
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 9e2ae07cbe4c9c..19ab0cc27cc015 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -901,7 +901,7 @@ static_assert((Derived*)(Base*)pb1 == (Derived*)pok2, "");
 
 // Core issue 903: we do not perform constant evaluation when checking for a
 // null pointer in C++11. Just check for an integer literal with value 0.
-constexpr Base *nullB = 42 - 6 * 7; // expected-error {{cannot initialize a 
variable of type 'Base *const' with an rvalue of type 'int'}}
+constexpr Base *nullB = 42 - 6 * 7; // expected-error {{cannot initialize a 
constant of type 'Base *' with an rvalue of type 'int'}}
 constexpr Base *nullB1 = 0;
 static_assert((Bottom*)nullB == 0, "");
 static_assert((Derived*)nullB1 == 0, "");
diff --git a/clang/test/SemaCXX/err_init_conversion_failed.cpp 
b/clang/test/SemaCXX/err_init_conversion_failed.cpp
index e31f215b4528cb..107ba1bbf51969 100644
--- a/clang/test/SemaCXX/err_init_conversion_failed.cpp
+++ b/clang/test/SemaCXX/err_init_conversion_failed.cpp
@@ -59,3 +59,14 @@ void test_15() {
   // expected-error-re@-1{{cannot initialize a member subobject of type 'void 
(template_test::S::*)(const int &){{( __attribute__\(\(thiscall\)\))?}}' with 
an rvalue of type 'void (template_test::S::*)(int){{( 
__attribute__\(\(thiscall\)\))?}}': type mismatch at 1st parameter ('const int 
&' vs 'int')}}
 }
 }
+
+void test_16() {
+  const int a = (void)0;
+  // expected-error@-1{{cannot initialize a constant of type 'int'}}
+
+  int* const c = (void)0;
+  // expected-error@-1{{cannot initialize a constant of type 'int *'}}
+
+  const int* b = (void)0;
+  // expected-error@-1{{cannot initialize a variable of type 'const int *'}}
+}
\ No newline at end of file

>From b430a73246ef66e5a48bdb73fbd0fc8a8aba0752 Mon Sep 17 00:00:00 2001
From: Artem Tyurin 
Date: Sat, 17 Feb 2024 15:18:23 +0100
Subject

[clang] [clang][Sema] Simplify err_init_conversion_failed diagnostic message for const variables (PR #82109)

2024-02-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Artem Tyurin (agentcooper)


Changes

Fixes #73399.

I initially tried to create a new `EntityKind` enum case to represent constants 
as it makes it easier to use `Entity.getKind()` with the diagnostic message. 
But in the end I've decided against it, as the new case needs to be handled in 
many places and feels error-prone.

---
Full diff: https://github.com/llvm/llvm-project/pull/82109.diff


4 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (+16-6) 
- (modified) clang/test/SemaCXX/constant-expression-cxx11.cpp (+1-1) 
- (modified) clang/test/SemaCXX/err_init_conversion_failed.cpp (+11) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..1c9a69167c28d1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2204,7 +2204,7 @@ def err_destructor_template : Error<
 
 // C++ initialization
 def err_init_conversion_failed : Error<
-  "cannot initialize %select{a variable|a parameter|template parameter|"
+  "cannot initialize %select{a constant|a variable|a parameter|template 
parameter|"
   "return object|statement expression result|an "
   "exception object|a member subobject|an array element|a new value|a value|a "
   "base class|a constructor delegation|a vector element|a block element|a "
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b6de06464cd6f3..c1846d9a80c8f2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9804,12 +9804,22 @@ bool InitializationSequence::Diagnose(Sema &S,
 
   case FK_ConversionFailed: {
 QualType FromType = OnlyArg->getType();
-PartialDiagnostic PDiag = S.PDiag(diag::err_init_conversion_failed)
-  << (int)Entity.getKind()
-  << DestType
-  << OnlyArg->isLValue()
-  << FromType
-  << Args[0]->getSourceRange();
+
+// NOTE: need to be in sync with err_init_conversion_failed
+const auto TotalSpecialKinds = 1;
+
+PartialDiagnostic PDiag = S.PDiag(diag::err_init_conversion_failed);
+if (Entity.getKind() == InitializedEntity::EK_Variable &&
+DestType.isConstQualified()) {
+  QualType NonConstDestType = DestType;
+  NonConstDestType.removeLocalConst();
+  PDiag << 0 /* a constant */
+<< NonConstDestType;
+} else {
+  PDiag << (TotalSpecialKinds + (int)Entity.getKind()) << DestType;
+}
+PDiag << OnlyArg->isLValue() << FromType << Args[0]->getSourceRange();
+
 S.HandleFunctionTypeMismatch(PDiag, FromType, DestType);
 S.Diag(Kind.getLocation(), PDiag);
 emitBadConversionNotes(S, Entity, Args[0]);
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 9e2ae07cbe4c9c..19ab0cc27cc015 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -901,7 +901,7 @@ static_assert((Derived*)(Base*)pb1 == (Derived*)pok2, "");
 
 // Core issue 903: we do not perform constant evaluation when checking for a
 // null pointer in C++11. Just check for an integer literal with value 0.
-constexpr Base *nullB = 42 - 6 * 7; // expected-error {{cannot initialize a 
variable of type 'Base *const' with an rvalue of type 'int'}}
+constexpr Base *nullB = 42 - 6 * 7; // expected-error {{cannot initialize a 
constant of type 'Base *' with an rvalue of type 'int'}}
 constexpr Base *nullB1 = 0;
 static_assert((Bottom*)nullB == 0, "");
 static_assert((Derived*)nullB1 == 0, "");
diff --git a/clang/test/SemaCXX/err_init_conversion_failed.cpp 
b/clang/test/SemaCXX/err_init_conversion_failed.cpp
index e31f215b4528cb..359d840070f2c4 100644
--- a/clang/test/SemaCXX/err_init_conversion_failed.cpp
+++ b/clang/test/SemaCXX/err_init_conversion_failed.cpp
@@ -59,3 +59,14 @@ void test_15() {
   // expected-error-re@-1{{cannot initialize a member subobject of type 'void 
(template_test::S::*)(const int &){{( __attribute__\(\(thiscall\)\))?}}' with 
an rvalue of type 'void (template_test::S::*)(int){{( 
__attribute__\(\(thiscall\)\))?}}': type mismatch at 1st parameter ('const int 
&' vs 'int')}}
 }
 }
+
+void test_16() {
+  const int a = (void)0;
+  // expected-error@-1{{cannot initialize a constant of type 'int'}}
+
+  int* const c = (void)0;
+  // expected-error@-1{{cannot initialize a constant of type 'int *'}}
+
+  const int* b = (void)0;
+  // expected-error@-1{{cannot initialize a variable of type 'const int *'}}
+}

``




https://github.com/llvm/llvm-project/pull/82109
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-17 Thread Mark de Wever via cfe-commits

mordante wrote:

@kaz7 ping, can you have a look at the patch, I really like to reland this 
patch.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-17 Thread Saleem Abdulrasool via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+&Opts](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

compnerd wrote:

Might be nice to take `const llvm::opt::Arg &` instead. It also feels unsafe as 
we do not know if the argument has a value before you get it - you should do a 
`A->hasValue()` or assert it perhaps?

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-17 Thread Saleem Abdulrasool via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,

compnerd wrote:

I think that `Prefix` or `Expand` would both be better than `Convert`. We 
aren't really converting this.

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-17 Thread Saleem Abdulrasool via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+&Opts](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

compnerd wrote:

This feels double indented?

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-17 Thread Evan Wilde via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+&Opts](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

etcwilde wrote:

I just followed the whims of `git clang-format` here. ¯\\\_(ツ)\_/¯

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-17 Thread Evan Wilde via cfe-commits


@@ -3229,16 +3244,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
 IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
 
 bool IsFramework = A->getOption().matches(OPT_F);
-std::string Path = A->getValue();
-
-if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {
-  SmallString<32> Buffer;
-  llvm::sys::path::append(Buffer, Opts.Sysroot,
-  llvm::StringRef(A->getValue()).substr(1));
-  Path = std::string(Buffer);
-}
-
-Opts.AddPath(Path, Group, IsFramework,
+Opts.AddPath(ConvertHeaderPath(A, IsFramework), Group, IsFramework,

etcwilde wrote:

I had considered doing something like checking whether the first character is 
an `=` and if the sysroot option is set and passing `true` to `IgnoreSysRoot` 
when that's the case. It unfortunately does not match behavior. I don't know 
how useful it is, but `--sysroot /foo/bar -isystem=baz` will result in the 
searchpath `/foo/barbaz` in gcc. (that's actually a good testcase, I should add 
that).

Given that we still need to strip the leading `=` from the searchpath with 
`-isystem` though not with `-iwithsysroot`, and that we want to match the `-I=` 
behavior, I decided to stick with this to minimize the impact of the patch. I 
could try to hunt down all of the places where the `UserEntries` list is 
iterated and ensure that they're doing the appropriate sysroot prefixing for 
the corresponding flags.

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5023fd0 - [NFC] Trim trailing whitespace

2024-02-17 Thread Danny Mösch via cfe-commits

Author: Danny Mösch
Date: 2024-02-17T19:37:39+01:00
New Revision: 5023fd09b43e9b7eee390a8552db7ebce6e2b15c

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

LOG: [NFC] Trim trailing whitespace

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 23c756babedbd9..a11f224170d5a6 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -287,7 +287,7 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   // clang-format off
   auto CallArgMatcher = callExpr(
 forEachArgumentWithParamType(
-  InnerMatcher, 
+  InnerMatcher,
   isAnyPointer() /* array also decays to pointer type*/),
 unless(callee(
   functionDecl(hasAttr(attr::UnsafeBufferUsage);



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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-17 Thread Danny Mösch via cfe-commits


@@ -0,0 +1,43 @@
+//===--- DesignatedInitializers.h ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file provides utilities for designated initializers.
+///
+//===--===//
+
+#include "clang/AST/Expr.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/DenseMap.h"
+
+namespace clang::tooling {
+
+/// Get designators describing the elements of a (syntactic) init list.
+///
+/// Given for example the type
+///
+/// struct S { int i, j; };
+///
+/// and the definition
+///
+/// S s{1, 2};
+///
+/// calling `getDesignators` for the initializer list expression `{1, 2}`
+/// would produce the map `{loc(1): ".i", loc(2): ".j"}`.
+///
+/// It does not produce designators for any explicitly-written nested lists,
+/// e.g. `{1, .j=2}` would only return `{loc(1): ".i"}`.
+///
+/// It also considers structs with fields of record types like
+/// `struct T { S s; };`. In this case, there would be designators of the
+/// form
+/// `.s.i` and `.s.j` in the returned map.
+llvm::DenseMap
+getDesignators(const clang::InitListExpr *Syn);

SimplyDanny wrote:

As I understand it, the base of clang-tidy is always linked into Clangd, but 
linking in all the checks can be disabled. `clangTidyUtils` is another library 
anyway and would need to be linked into Clangd separately if the files are 
moved to `clang-tools-extra/clang-tidy/utils`.

I have done so in 
https://github.com/llvm/llvm-project/pull/80541/commits/df24916e9dd25b3f8b7dc03dcb782e689ea1af37.
 Please let me know if this looks correct to you.

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add support for sysroot-relative system header search paths (PR #82084)

2024-02-17 Thread Saleem Abdulrasool via cfe-commits


@@ -3218,6 +3218,21 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
   bool IsIndexHeaderMap = false;
   bool IsSysrootSpecified =
   Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
+
+  // Expand a leading `=` to the sysroot if one was passed (and it's not a
+  // framework flag).
+  auto ConvertHeaderPath = [IsSysrootSpecified,
+&Opts](const llvm::opt::Arg *A,
+   bool IsFramework = false) -> std::string {
+if (IsSysrootSpecified && !IsFramework && A->getValue()[0] == '=') {

compnerd wrote:

🤷‍♂️ clang-format does what clang-format wants.

https://github.com/llvm/llvm-project/pull/82084
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] [llvm] [openmp] [libc] Rework the GPU build to be a regular target (PR #81921)

2024-02-17 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/81921

>From 63e4205a9f5cc3ea8a4ce0730b01d78b6c9bde42 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 13 Feb 2024 21:08:02 -0600
Subject: [PATCH] [libc] Rework the GPU build to be a regular target

Summary:
This is a massive patch because it reworks the entire build and
everything that depends on it. This is not split up because various bots
would fail otherwise. I will attempt to describe the necessary changes
here.

This patch completely reworks how the GPU build is built and targeted.
Previously, we used a standard runtimes build and handled both NVPTX and
AMDGPU in a single build via multi-targeting. This added a lot of
divergence in the build system and prevented us from doing various
things like building for the CPU / GPU at the same time, or exporting
the startup libraries or running tests without a full rebuild.

The new appraoch is to handle the GPU builds as strict cross-compiling
runtimes. The first step required
https://github.com/llvm/llvm-project/pull/81557 to allow the `LIBC`
target to build for the GPU without touching the other targets. This
means that the GPU uses all the same handling as the other builds in
`libc`.

The new expected way to build the GPU libc is with
`LLVM_LIBC_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda`.

The second step was reworking how we generated the embedded GPU library
by moving it into the library install step. Where we previously had one
`libcgpu.a` we now have `libcgpu-amdgpu.a` and `libcgpu-nvptx.a`. This
patch includes the necessary clang / OpenMP changes to make that not
break the bots when this lands.

We unfortunately still require that the NVPTX target has an `internal`
target for tests. This is because the NVPTX target needs to do LTO for
the provided version (The offloading toolchain can handle it) but cannot
use it for the native toolchain which is used for making tests.

This approach is vastly suprerior in every way, allowing us to treat the
GPU as a standard cross-compiling target. We can now install the GPU
utilities to do things like use the offload tests and other fun things.

Depends on https://github.com/llvm/llvm-project/pull/81557
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  37 +-
 clang/test/Driver/openmp-offload-gpu.c|  14 +-
 libc/CMakeLists.txt   |  20 +-
 .../cmake/modules/LLVMLibCArchitectures.cmake |  28 +-
 libc/cmake/modules/LLVMLibCCheckMPFR.cmake|   2 +-
 .../modules/LLVMLibCCompileOptionRules.cmake  | 104 ++
 libc/cmake/modules/LLVMLibCHeaderRules.cmake  |   2 +-
 libc/cmake/modules/LLVMLibCLibraryRules.cmake | 141 +--
 libc/cmake/modules/LLVMLibCObjectRules.cmake  | 348 --
 libc/cmake/modules/LLVMLibCTestRules.cmake|  67 ++--
 .../modules/prepare_libc_gpu_build.cmake  |  99 ++---
 libc/include/CMakeLists.txt   |   6 +-
 libc/lib/CMakeLists.txt   |  42 ++-
 libc/src/__support/File/CMakeLists.txt|   2 +-
 libc/src/__support/GPU/CMakeLists.txt |   2 +-
 libc/src/__support/OSUtil/CMakeLists.txt  |   2 +-
 libc/src/__support/RPC/CMakeLists.txt |   2 +-
 libc/src/math/CMakeLists.txt  |  16 +-
 libc/src/math/gpu/vendor/CMakeLists.txt   |   1 -
 libc/src/stdio/CMakeLists.txt |   2 +-
 libc/src/stdlib/CMakeLists.txt|   4 +-
 libc/src/string/CMakeLists.txt|  12 +-
 libc/startup/gpu/CMakeLists.txt   |  35 +-
 libc/startup/gpu/amdgpu/CMakeLists.txt|  13 -
 libc/startup/gpu/nvptx/CMakeLists.txt |   9 -
 libc/test/CMakeLists.txt  |   6 +-
 libc/test/IntegrationTest/CMakeLists.txt  |  16 -
 libc/test/UnitTest/CMakeLists.txt |   6 +-
 libc/test/src/__support/CMakeLists.txt|  49 +--
 libc/test/src/__support/CPP/CMakeLists.txt|   2 +-
 libc/test/src/__support/File/CMakeLists.txt   |   2 +-
 libc/test/src/errno/CMakeLists.txt|   2 +-
 libc/test/src/math/CMakeLists.txt |  20 +-
 libc/test/src/math/smoke/CMakeLists.txt   |   8 +-
 libc/test/src/stdio/CMakeLists.txt|   2 +-
 libc/test/src/stdlib/CMakeLists.txt   |   6 +-
 libc/test/utils/UnitTest/CMakeLists.txt   |   2 +-
 libc/utils/CMakeLists.txt |   2 +-
 libc/utils/MPFRWrapper/CMakeLists.txt |   2 +-
 libc/utils/gpu/CMakeLists.txt |   4 +-
 libc/utils/gpu/loader/CMakeLists.txt  |  48 ++-
 libc/utils/gpu/loader/amdgpu/CMakeLists.txt   |   6 +-
 libc/utils/gpu/loader/nvptx/CMakeLists.txt|  10 +-
 libc/utils/gpu/server/CMakeLists.txt  |   9 +
 llvm/CMakeLists.txt   |   8 +
 llvm/cmake/modules/HandleLLVMOptions.cmake|   7 +
 llvm/runtimes/CMakeLists.txt  |   6 +-
 openmp/libomptarget/CMakeLists.txt|   9 +-
 .../plugins-nextgen/common/CMakeLists.txt |   

[clang] [libc] [llvm] [openmp] [libc] Rework the GPU build to be a regular target (PR #81921)

2024-02-17 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

Tested this one a few machines and it works as expected after some final tweaks.

FYI @jplehr and @Artem-B, this will change the CMake configuration required for 
building and testing on the build bots. The new expected way to test each one 
respectively would be the following
```
-DLLVM_LIBC_RUNTIME_TARGETS=amdgcn-amd-amdhsa;nvptx64-nvidia-cuda
ninja check-libc-amdgcn-amd-amdhsa
ninja check-libc-nvptx64-nvidia-cuda
```
I think specifically there are two CMake issues that might make this annoying. 
I would like to be able to just do `ninja check-libc` and have it check all of 
them, but for the bots it's likely enough to just check specifically which one 
we're interested in.

https://github.com/llvm/llvm-project/pull/81921
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-17 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/81420

From 34f24456bfe44720e72119c847ab54b181977361 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 11 Feb 2024 17:04:12 +0100
Subject: [PATCH] [clang-tidy] Add fix-its to `avoid-return-with-void-value`
 check

---
 .../AvoidReturnWithVoidValueCheck.cpp | 31 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../avoid-return-with-void-value.cpp  | 14 +++--
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
index e3400f614fa564..46d8108b63af51 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
@@ -10,16 +10,17 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 
-static constexpr auto IgnoreMacrosName = "IgnoreMacros";
-static constexpr auto IgnoreMacrosDefault = true;
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static const bool IgnoreMacrosDefault = true;
 
-static constexpr auto StrictModeName = "StrictMode";
-static constexpr auto StrictModeDefault = true;
+static constexpr char StrictModeName[] = "StrictMode";
+static const bool StrictModeDefault = true;
 
 AvoidReturnWithVoidValueCheck::AvoidReturnWithVoidValueCheck(
 StringRef Name, ClangTidyContext *Context)
@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const StringRef ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const std::optional NextToken =
+  Lexer::findNextToken(VoidReturn->getRetValue()->getEndLoc(),
+   *Result.SourceManager, getLangOpts()))
+SemicolonPos = NextToken->getEndLoc();
+  std::string Replacement = (ReturnExpr + "; return;").str();
+  if (!SurroundingBlock)
+Replacement = "{" + Replacement + "}";
   diag(VoidReturn->getBeginLoc(), "return statement within a void function "
-  "should not have a specified return value");
+  "should not have a specified return value")
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(),
+SemicolonPos),
+ Replacement);
 }
 
 void AvoidReturnWithVoidValueCheck::storeOptions(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 737ea9ba6d44f7..f0a5d6ebf1eb26 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,10 @@ Changes in existing checks
   ` check to also remove any trailing
   whitespace when deleting the ``virtual`` keyword.
 
+- Improved :doc:`readability-avoid-return-with-void-value
+  ` check by adding
+  fix-its.
+
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly
   emit warnings for static data member with an in-class initializer.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
index f00407c99ce570..0d269ceee82bc9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
@@ -12,14 +12,18 @@ void f2() {
 return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f1(); return;
 }
 
 void f3(bool b) {
 if (b) return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a 
void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: if (b) 

[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)

2024-02-17 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/81190

>From 586ee65c5e820365a6fd150d7f246fbfa679ec3e Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Thu, 8 Feb 2024 11:08:59 -0500
Subject: [PATCH] [HLSL] Implementation of dot intrinsic This change implements
 #70073

HLSL has a dot intrinsic defined here:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-dot

The intrinsic itself is defined as a HLSL_LANG LangBuiltin in Builtins.td.
This is used to associate all the dot product typdef defined hlsl_intrinsics.h
with a single intrinsic check in CGBuiltin.cpp & SemaChecking.cpp.

In IntrinsicsDirectX.td we define the llvmIR for the dot product.
A few goals were in mind for this IR. First it should operate on only
vectors. Second the return type should be the vector element type. Third
the second parameter vector should be of the same size as the first
parameter. Finally `a dot b` should be the same as `b dot a`.

In CGBuiltin.cpp hlsl has built on top of existing clang intrinsics via 
EmitBuiltinExpr. Dot
product though is language specific intrinsic and so is guarded behind 
getLangOpts().HLSL.
The call chain looks like this: EmitBuiltinExpr -> EmitHLSLBuiltinExp

EmitHLSLBuiltinExp dot product intrinsics makes a destinction
between vectors and scalars. This is because HLSL supports dot product on 
scalars which simplifies down to multiply.

Sema.h & SemaChecking.cpp saw the addition of CheckHLSLBuiltinFunctionCall, a 
language specific semantic validation that can be expanded for other hlsl 
specific intrinsics.
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/include/clang/Sema/Sema.h   |   1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  49 
 clang/lib/CodeGen/CodeGenFunction.h   |   1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  92 
 clang/lib/Sema/SemaChecking.cpp   |  84 ++-
 clang/test/CodeGenHLSL/builtins/dot.hlsl  | 216 ++
 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl  |  46 
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   5 +
 10 files changed, 497 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/dot.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index df74026c5d2d50..771c4f5d4121f4 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4524,6 +4524,12 @@ def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void*(unsigned char)";
 }
 
+def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_dot"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6e3cebc311eeb9..46f5424038d8b0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10267,6 +10267,8 @@ def err_vec_builtin_non_vector : Error<
  "first two arguments to %0 must be vectors">;
 def err_vec_builtin_incompatible_vector : Error<
   "first two arguments to %0 must have the same type">;
+def err_vec_builtin_incompatible_size : Error<
+  "first two arguments to %0 must have the same size">;
 def err_vsx_builtin_nonconstant_argument : Error<
   "argument %0 to %1 must be a 2-bit unsigned literal (i.e. 0, 1, 2 or 3)">;
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e9cd42ae777df5..3557db56905ff8 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14055,6 +14055,7 @@ class Sema final {
   bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
CallExpr *TheCall);
   bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
+  bool CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
   bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum);
   bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
  CallExpr *TheCall);
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d454ccc1dd8613..4bad41a9be214e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -44,6 +44,7 @@
 #include "llvm/IR/IntrinsicsAMDGPU.h"
 #include "llvm/IR/IntrinsicsARM.h"
 #include "llvm/IR/IntrinsicsBPF.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/IntrinsicsHexagon.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
 #include "llvm/IR/IntrinsicsPowerPC.h"
@@ -5982,6 +5983,10 @@ RValue CodeGenFunction::EmitBuiltinE

[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-17 Thread David Tellenbach via cfe-commits

https://github.com/dtellenbach created 
https://github.com/llvm/llvm-project/pull/82141

Fix an issue that produces a wrong coverage mapping when using binary 
conditional operators as show in the example below.

Before this patch:

```
1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  0|  return x;   <-- Not covered
5|  1|}
```

After this patch:

```
1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  1|  return x;   <-- Covered
5|  1|}
```

>From f8e11fed8b4b6b0cc359e2915e4f2f32c3f08bb5 Mon Sep 17 00:00:00 2001
From: David Tellenbach 
Date: Sat, 17 Feb 2024 15:16:39 -0800
Subject: [PATCH] [clang][CodeCoverage] Fix CoverageMapping for binary
 conditionals ops

Fix an issue that produces a wrong coverage mapping when using binary
conditional operators as show in the example below.

Before this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  0|  return x;   <-- Not covered
5|  1|}

After this patch:

1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  1|  return x;   <-- Covered
5|  1|}
---
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  2 ++
 .../CoverageMapping/conditional-operator.c| 25 +++
 2 files changed, 27 insertions(+)
 create mode 100644 clang/test/CoverageMapping/conditional-operator.c

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index c10d85ea89ee61..d8fa69d825b8d6 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1942,6 +1942,8 @@ struct CounterCoverageMappingBuilder
 
   extendRegion(E->getTrueExpr());
   OutCount = propagateCounts(TrueCount, E->getTrueExpr());
+} else {
+  OutCount = TrueCount;
 }
 
 extendRegion(E->getFalseExpr());
diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
new file mode 100644
index 00..5f3eb9c03e79fb
--- /dev/null
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   binary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+4]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  File 0, [[@LINE+2]]:13 -> [[@LINE+2]]:14 = (#0 - #1)
+int binary_conditional(int x) {
+  x = x ? : 4;
+  int y = x;
+  return y;
+}
+
+// CHECK-LABEL:   tenary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
+// CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
+// CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
+int tenary_conditional(int x) {
+  x = x ? x : 4;
+  int y = x;
+  return y;
+}

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


[clang] [clang][CodeCoverage] Fix CoverageMapping for binary conditionals ops (PR #82141)

2024-02-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: David Tellenbach (dtellenbach)


Changes

Fix an issue that produces a wrong coverage mapping when using binary 
conditional operators as show in the example below.

Before this patch:

```
1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  0|  return x;   <-- Not covered
5|  1|}
```

After this patch:

```
1|  1|int binary_cond(int x) {
2|  1|  x = x ?: 4;
3|  1|  int y = 0;
4|  1|  return x;   <-- Covered
5|  1|}
```

---
Full diff: https://github.com/llvm/llvm-project/pull/82141.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+2) 
- (added) clang/test/CoverageMapping/conditional-operator.c (+25) 


``diff
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index c10d85ea89ee61..d8fa69d825b8d6 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1942,6 +1942,8 @@ struct CounterCoverageMappingBuilder
 
   extendRegion(E->getTrueExpr());
   OutCount = propagateCounts(TrueCount, E->getTrueExpr());
+} else {
+  OutCount = TrueCount;
 }
 
 extendRegion(E->getFalseExpr());
diff --git a/clang/test/CoverageMapping/conditional-operator.c 
b/clang/test/CoverageMapping/conditional-operator.c
new file mode 100644
index 00..5f3eb9c03e79fb
--- /dev/null
+++ b/clang/test/CoverageMapping/conditional-operator.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   binary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+4]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+3]]:7 -> [[@LINE+3]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  File 0, [[@LINE+2]]:13 -> [[@LINE+2]]:14 = (#0 - #1)
+int binary_conditional(int x) {
+  x = x ? : 4;
+  int y = x;
+  return y;
+}
+
+// CHECK-LABEL:   tenary_conditional:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:31 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+6]]:7 -> [[@LINE+6]]:8 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+5]]:7 -> [[@LINE+5]]:8 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+4]]:10 -> [[@LINE+4]]:11 = #1
+// CHECK-NEXT:  File 0, [[@LINE+3]]:11 -> [[@LINE+3]]:12 = #1
+// CHECK-NEXT:  File 0, [[@LINE+2]]:15 -> [[@LINE+2]]:16 = (#0 - #1)
+int tenary_conditional(int x) {
+  x = x ? x : 4;
+  int y = x;
+  return y;
+}

``




https://github.com/llvm/llvm-project/pull/82141
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-02-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@sam-mccall ping~. Let's see if we can make it in clang19.

https://github.com/llvm/llvm-project/pull/66462
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clangd] Fix C++20 modules crash (PR #81919)

2024-02-17 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 requested changes to this pull request.

This is not wanted. While we have a policy to revert patches if the patches 
break existing codes, the C++20 modules support in clangd is literally broken: 
https://github.com/clangd/clangd/issues/1293

Also the ability to skip ODR checks is an important feature to modules. So I 
don't think we should revert this now.

Also I don't understand why it can make clangd to crash. A test will be helpful 
for us to understand what happened.

https://github.com/llvm/llvm-project/pull/81919
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [RFC][flang][runtime] Add FortranFloat128Math wrapper library. (PR #81971)

2024-02-17 Thread Steve Scalpone via cfe-commits


@@ -657,10 +657,61 @@ static llvm::cl::opt
 "instead of libm complex operations"),
  llvm::cl::init(false));
 
+/// Return a string containing the given Fortran intrinsic name
+/// with the type of its arguments specified in funcType
+/// surrounded by the given prefix/suffix.
+static std::string
+prettyPrintIntrinsicName(fir::FirOpBuilder &builder, mlir::Location loc,
+ llvm::StringRef prefix, llvm::StringRef name,
+ llvm::StringRef suffix, mlir::FunctionType funcType) {
+  std::string output = prefix.str();
+  llvm::raw_string_ostream sstream(output);
+  if (name == "pow") {
+assert(funcType.getNumInputs() == 2 && "power operator has two arguments");
+std::string displayName{" ** "};
+sstream << numericMlirTypeToFortran(builder, funcType.getInput(0), loc,
+displayName)
+<< displayName
+<< numericMlirTypeToFortran(builder, funcType.getInput(1), loc,
+displayName);
+  } else {
+sstream << name.upper() << "(";
+if (funcType.getNumInputs() > 0)
+  sstream << numericMlirTypeToFortran(builder, funcType.getInput(0), loc,
+  name);
+for (mlir::Type argType : funcType.getInputs().drop_front()) {
+  sstream << ", " << numericMlirTypeToFortran(builder, argType, loc, name);
+}
+sstream << ")";
+  }
+  sstream << suffix;
+  return output;
+}
+
+// Generate a call to the Fortran runtime library providing
+// support for 128-bit float math via a third-party library.
+// If the compiler is built without FLANG_RUNTIME_F128_MATH_LIB,
+// this function will report an error.
+static mlir::Value genLibF128Call(fir::FirOpBuilder &builder,
+  mlir::Location loc,
+  const MathOperation &mathOp,
+  mlir::FunctionType libFuncType,
+  llvm::ArrayRef args) {
+#ifndef FLANG_RUNTIME_F128_MATH_LIB
+  std::string message = prettyPrintIntrinsicName(
+  builder, loc, "compiler is built without support for '", mathOp.key, "'",

sscalpone wrote:

OK for this message to use a form with "not yet implemented:"?

https://github.com/llvm/llvm-project/pull/81971
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-17 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.


https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [docs] [C++20] [Modules] Ideas for transitioning to modules (PR #80687)

2024-02-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I'd like to land this in 2 weeks if no more comments come in.

https://github.com/llvm/llvm-project/pull/80687
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fixes to readability-implicit-bool-conversion (PR #72050)

2024-02-17 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.


https://github.com/llvm/llvm-project/pull/72050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -173,19 +173,36 @@ static bool ResumeStmtCanThrow(const Stmt *S) {
   return false;
 }
 
+static bool AwaitSuspendStmtCanThrow(const Stmt *S) {
+  return ResumeStmtCanThrow(S);
+}
+
 // Emit suspend expression which roughly looks like:
 //
 //   auto && x = CommonExpr();
 //   if (!x.await_ready()) {
 //  llvm_coro_save();
-//  x.await_suspend(...); (*)
+//  llvm_coro_await_suspend(&x, frame, wrapper) (*)
 //  llvm_coro_suspend(); (**)
 //   }
 //   x.await_resume();
 //
 // where the result of the entire expression is the result of x.await_resume()
 //
-//   (*) If x.await_suspend return type is bool, it allows to veto a suspend:
+//   (*) llvm_coro_await_suspend_{void, bool, handle} is lowered to
+//  wrapper(&x, frame) when it's certain not to interfere with
+//  coroutine transform. await_suspend expression is
+//  asynchronous to the coroutine body and not all analyses
+//  and transformations can handle it correctly at the moment.
+//
+//  Wrapper function encapsulates x.await_suspend(...) call and looks like:
+//
+//  auto __await_suspend_wrapper(auto& awaiter, void* frame) {
+//std::coroutine_handle<> handle(frame);
+//return awaiter.await_suspend(handle);
+//  }
+//
+//  If x.await_suspend return type is bool, it allows to veto a suspend:

ChuanqiXu9 wrote:

```suggestion
//(**) If x.await_suspend return type is bool, it allows to veto a suspend:
```

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -232,16 +250,74 @@ static LValueOrRValue 
emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
   auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
   auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
 
+  const auto AwaitSuspendCanThrow =
+  AwaitSuspendStmtCanThrow(S.getSuspendExpr());
+
+  auto SuspendWrapper = CodeGenFunction(CGF.CGM).generateAwaitSuspendWrapper(
+  CGF.CurFn->getName(), Prefix, S);
+
+  llvm::CallBase *SuspendRet = nullptr;
+
   CGF.CurCoro.InSuspendBlock = true;
-  auto *SuspendRet = CGF.EmitScalarExpr(S.getSuspendExpr());
+
+  assert(CGF.CurCoro.Data && CGF.CurCoro.Data->CoroBegin &&
+ "expected to be called in coroutine context");
+
+  SmallVector SuspendIntrinsicCallArgs;
+  SuspendIntrinsicCallArgs.push_back(
+  CGF.getOrCreateOpaqueLValueMapping(S.getOpaqueValue()).getPointer(CGF));
+
+  SuspendIntrinsicCallArgs.push_back(CGF.CurCoro.Data->CoroBegin);
+  SuspendIntrinsicCallArgs.push_back(SuspendWrapper);
+
+  const auto SuspendReturnType = S.getSuspendReturnType();
+  llvm::Intrinsic::ID IID;

ChuanqiXu9 wrote:

```suggestion
  llvm::Intrinsic::ID AwaitSuspendIID;
```

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -232,16 +250,74 @@ static LValueOrRValue 
emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
   auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
   auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
 
+  const auto AwaitSuspendCanThrow =
+  AwaitSuspendStmtCanThrow(S.getSuspendExpr());
+
+  auto SuspendWrapper = CodeGenFunction(CGF.CGM).generateAwaitSuspendWrapper(
+  CGF.CurFn->getName(), Prefix, S);
+
+  llvm::CallBase *SuspendRet = nullptr;
+
   CGF.CurCoro.InSuspendBlock = true;
-  auto *SuspendRet = CGF.EmitScalarExpr(S.getSuspendExpr());
+
+  assert(CGF.CurCoro.Data && CGF.CurCoro.Data->CoroBegin &&
+ "expected to be called in coroutine context");
+
+  SmallVector SuspendIntrinsicCallArgs;
+  SuspendIntrinsicCallArgs.push_back(
+  CGF.getOrCreateOpaqueLValueMapping(S.getOpaqueValue()).getPointer(CGF));
+
+  SuspendIntrinsicCallArgs.push_back(CGF.CurCoro.Data->CoroBegin);
+  SuspendIntrinsicCallArgs.push_back(SuspendWrapper);
+
+  const auto SuspendReturnType = S.getSuspendReturnType();
+  llvm::Intrinsic::ID IID;
+
+  switch (SuspendReturnType) {
+  case CoroutineSuspendExpr::SuspendVoid:
+IID = llvm::Intrinsic::coro_await_suspend_void;
+break;
+  case CoroutineSuspendExpr::SuspendBool:
+IID = llvm::Intrinsic::coro_await_suspend_bool;
+break;
+  case CoroutineSuspendExpr::SuspendHandle:
+IID = llvm::Intrinsic::coro_await_suspend_handle;
+break;
+  }
+
+  llvm::Function *AwaitSuspendIntrinsic = CGF.CGM.getIntrinsic(IID);
+  // FIXME: add call attributes?
+  if (AwaitSuspendCanThrow)
+SuspendRet =
+CGF.EmitCallOrInvoke(AwaitSuspendIntrinsic, SuspendIntrinsicCallArgs);
+  else
+SuspendRet = CGF.EmitNounwindRuntimeCall(AwaitSuspendIntrinsic,
+ SuspendIntrinsicCallArgs);

ChuanqiXu9 wrote:

Do we really need to do this? I feel `EmitCallOrInvoke` is sufficient. LLVM is 
able to propagate `nounwind` in trivial cases.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -338,6 +414,71 @@ static QualType getCoroutineSuspendExprReturnType(const 
ASTContext &Ctx,
 }
 #endif
 
+llvm::Function *
+CodeGenFunction::generateAwaitSuspendWrapper(Twine const &CoroName,
+ Twine const &SuspendPointName,
+ CoroutineSuspendExpr const &S) {
+  std::string FuncName = "__await_suspend_wrapper_";
+  FuncName += CoroName.str();
+  FuncName += '_';
+  FuncName += SuspendPointName.str();

ChuanqiXu9 wrote:

I feel it is better to concat the name of the awaiter instead of the coroutines 
and suspend number.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -167,6 +167,47 @@ class CoroCloner {
 
 } // end anonymous namespace
 
+// FIXME:
+// Lower the intrinisc earlier if coroutine frame doesn't escape

ChuanqiXu9 wrote:

```suggestion
// Lower the intrinisc in CoroEarly phase if coroutine frame doesn't escape
```

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -380,66 +380,7 @@ static Expr *maybeTailCall(Sema &S, QualType RetType, Expr 
*E,
   // __builtin_coro_resume so that the cleanup code are not inserted in-between
   // the resume call and return instruction, which would interfere with the
   // musttail call contract.
-  JustAddress = S.MaybeCreateExprWithCleanups(JustAddress);
-  return S.BuildBuiltinCallExpr(Loc, Builtin::BI__builtin_coro_resume,
-JustAddress);
-}
-
-/// The await_suspend call performed by co_await is essentially asynchronous
-/// to the execution of the coroutine. Inlining it normally into an unsplit
-/// coroutine can cause miscompilation because the coroutine CFG misrepresents
-/// the true control flow of the program: things that happen in the
-/// await_suspend are not guaranteed to happen prior to the resumption of the
-/// coroutine, and things that happen after the resumption of the coroutine
-/// (including its exit and the potential deallocation of the coroutine frame)
-/// are not guaranteed to happen only after the end of await_suspend.
-///
-/// See https://github.com/llvm/llvm-project/issues/56301 and
-/// https://reviews.llvm.org/D157070 for the example and the full discussion.
-///
-/// The short-term solution to this problem is to mark the call as uninlinable.
-/// But we don't want to do this if the call is known to be trivial, which is
-/// very common.
-///
-/// The long-term solution may introduce patterns like:
-///
-///  call @llvm.coro.await_suspend(ptr %awaiter, ptr %handle,
-///ptr @awaitSuspendFn)
-///
-/// Then it is much easier to perform the safety analysis in the middle end.
-/// If it is safe to inline the call to awaitSuspend, we can replace it in the
-/// CoroEarly pass. Otherwise we could replace it in the CoroSplit pass.
-static void tryMarkAwaitSuspendNoInline(Sema &S, OpaqueValueExpr *Awaiter,
-CallExpr *AwaitSuspend) {
-  // The method here to extract the awaiter decl is not precise.
-  // This is intentional. Since it is hard to perform the analysis in the
-  // frontend due to the complexity of C++'s type systems.
-  // And we prefer to perform such analysis in the middle end since it is
-  // easier to implement and more powerful.
-  CXXRecordDecl *AwaiterDecl =
-  Awaiter->getType().getNonReferenceType()->getAsCXXRecordDecl();
-
-  if (AwaiterDecl && AwaiterDecl->field_empty())
-return;
-
-  FunctionDecl *FD = AwaitSuspend->getDirectCallee();
-
-  assert(FD);
-
-  // If the `await_suspend()` function is marked as `always_inline` explicitly,
-  // we should give the user the right to control the codegen.
-  if (FD->hasAttr() || FD->hasAttr())
-return;
-
-  // This is problematic if the user calls the await_suspend standalone. But on
-  // the on hand, it is not incorrect semantically since inlining is not part
-  // of the standard. On the other hand, it is relatively rare to call
-  // the await_suspend function standalone.
-  //
-  // And given we've already had the long-term plan, the current workaround
-  // looks relatively tolerant.
-  FD->addAttr(
-  NoInlineAttr::CreateImplicit(S.getASTContext(), FD->getLocation()));
+  return S.MaybeCreateExprWithCleanups(JustAddress);

ChuanqiXu9 wrote:

We also need to update the comments of the function after this patch. Also I 
feel like the above fixme can be removed.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -2013,6 +2104,10 @@ splitCoroutine(Function &F, SmallVectorImpl 
&Clones,
   buildCoroutineFrame(F, Shape, MaterializableCallback);
   replaceFrameSizeAndAlignment(Shape);
 
+  IRBuilder<> Builder(M.getContext());

ChuanqiXu9 wrote:

```suggestion
  IRBuilder<> Builder(F.getContext());
```

then we can get rid of `Module`.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

Thanks. This looks much better now.

Given the CoroAwaitSuspendInst is lowered before splitting coroutines, I think 
we don't need to handle it specially in `CoroSplit` any more.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -5038,6 +5038,8 @@ class CoroutineSuspendExpr : public Expr {
   OpaqueValueExpr *OpaqueValue = nullptr;
 
 public:
+  enum SuspendReturnType { SuspendVoid, SuspendBool, SuspendHandle };

ChuanqiXu9 wrote:

nit: Add a comment to explain that the return type of coroutines can only be 
one of them. Also I prefer `enum class` style.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -1396,9 +1478,18 @@ static bool simplifySuspendPoint(CoroSuspendInst 
*Suspend,
   if (!SubFn)
 return false;
 
-  // Does not refer to the current coroutine, we cannot do anything with it.
-  if (SubFn->getFrame() != CoroBegin)
-return false;
+  auto Frame = SubFn->getFrame();
+
+  // Check that frame directly always refers to the current coroutine,
+  // either directly or via wrapper
+  if (Frame != CoroBegin) {
+auto *AWS = dyn_cast(Frame);
+if (!AWS)
+  return false;

ChuanqiXu9 wrote:

Since we've lowered all `CoroAwaitSuspendInst` before invoking 
`splitCoroutine`. We shouldn't see `CoroAwaitSuspendInst` here, right?

Then we can remove  isSimpleWrapper too.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -232,16 +250,74 @@ static LValueOrRValue 
emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
   auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
   auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
 
+  const auto AwaitSuspendCanThrow =
+  AwaitSuspendStmtCanThrow(S.getSuspendExpr());
+
+  auto SuspendWrapper = CodeGenFunction(CGF.CGM).generateAwaitSuspendWrapper(
+  CGF.CurFn->getName(), Prefix, S);
+
+  llvm::CallBase *SuspendRet = nullptr;

ChuanqiXu9 wrote:

Let's sink the definitions to the uses.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-02-17 Thread Chuanqi Xu via cfe-commits


@@ -5097,6 +5099,22 @@ class CoroutineSuspendExpr : public Expr {
 return static_cast(SubExprs[SubExpr::Operand]);
   }
 
+  SuspendReturnType getSuspendReturnType() const {
+auto *SuspendExpr = getSuspendExpr();
+assert(SuspendExpr);
+
+auto SuspendType = SuspendExpr->getType();
+
+if (SuspendType->isVoidType())
+  return SuspendReturnType::SuspendVoid;
+if (SuspendType->isBooleanType())
+  return SuspendReturnType::SuspendBool;
+if (SuspendType->isVoidPointerType())
+  return SuspendReturnType::SuspendHandle;
+
+llvm_unreachable("Unexpected await_suspend expression return type");

ChuanqiXu9 wrote:

```suggestion
return SuspendReturnType::SuspendHandle;
```

the `void pointer type` part looks odd.

https://github.com/llvm/llvm-project/pull/79712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-02-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

(This is another example that the github review can't work well with the 
reverted patches...)

@mordante I think you can add `// REQUIRES: x86-registered-target` to the test 
if @kaz7 can't respond quickly. It will skip the test on targets other than 
x86. And it should keep the CI green and enable us to backport this clang18.

We can still improve this later.

https://github.com/llvm/llvm-project/pull/76451
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-02-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@iains @mizvekov ping~

https://github.com/llvm/llvm-project/pull/75894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> [do not merge] [runtime-cxxmodules] Rework our lazy template specialization 
> deserialization mechanism root-project/root#14495

>From https://github.com/root-project/root/pull/14495, I see there is new reply 
>saying the testing is actually fine. Do you think we still need to split the 
>patch?

https://github.com/llvm/llvm-project/pull/76774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-17 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > [do not merge] [runtime-cxxmodules] Rework our lazy template specialization 
> > deserialization mechanism 
> > [root-project/root#14495](https://github.com/root-project/root/pull/14495)
> 
> From 
> [root-project/root#14495](https://github.com/root-project/root/pull/14495), I 
> see there is new reply saying the testing is actually fine. Do you think we 
> still need to split the patch?

That comment was concerning the version of the patch that had the lazy template 
deserialization turned off by default. Yes, I still think that this patch 
should implement tha on-disk hash table on top of D41416

https://github.com/llvm/llvm-project/pull/76774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Define SwiftInfo for RISCVTargetCodeGenInfo (PR #82152)

2024-02-17 Thread Kuba Mracek via cfe-commits

https://github.com/kubamracek created 
https://github.com/llvm/llvm-project/pull/82152

For Embedded Swift, let's unblock building for RISC-V boards (e.g. ESP32-C6). 
This isn't trying to add full RISC-V support to Swift / Embedded Swift, it's 
just fixing the immediate blocker (not having SwiftInfo defined blocks all 
compilations).

>From b8e8c6e2531db93fb2a4cd08149c9204cb997d53 Mon Sep 17 00:00:00 2001
From: Kuba Mracek 
Date: Sat, 17 Feb 2024 22:26:21 -0800
Subject: [PATCH] [clang] Define SwiftInfo for RISCVTargetCodeGenInfo

---
 clang/lib/CodeGen/Targets/RISCV.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp 
b/clang/lib/CodeGen/Targets/RISCV.cpp
index dec6540230a60f..9a79424c4612ce 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -529,7 +529,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
   RISCVTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen,
  unsigned FLen, bool EABI)
   : TargetCodeGenInfo(
-std::make_unique(CGT, XLen, FLen, EABI)) {}
+std::make_unique(CGT, XLen, FLen, EABI)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &CGM) const override {

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


[clang] [clang] Define SwiftInfo for RISCVTargetCodeGenInfo (PR #82152)

2024-02-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang
@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang-codegen

Author: Kuba (Brecka) Mracek (kubamracek)


Changes

For Embedded Swift, let's unblock building for RISC-V boards (e.g. ESP32-C6). 
This isn't trying to add full RISC-V support to Swift / Embedded Swift, it's 
just fixing the immediate blocker (not having SwiftInfo defined blocks all 
compilations).

---
Full diff: https://github.com/llvm/llvm-project/pull/82152.diff


1 Files Affected:

- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+4-1) 


``diff
diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp 
b/clang/lib/CodeGen/Targets/RISCV.cpp
index dec6540230a60f..9a79424c4612ce 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -529,7 +529,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
   RISCVTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, unsigned XLen,
  unsigned FLen, bool EABI)
   : TargetCodeGenInfo(
-std::make_unique(CGT, XLen, FLen, EABI)) {}
+std::make_unique(CGT, XLen, FLen, EABI)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &CGM) const override {

``




https://github.com/llvm/llvm-project/pull/82152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > > [do not merge] [runtime-cxxmodules] Rework our lazy template 
> > > specialization deserialization mechanism 
> > > [root-project/root#14495](https://github.com/root-project/root/pull/14495)
> > 
> > 
> > From 
> > [root-project/root#14495](https://github.com/root-project/root/pull/14495), 
> > I see there is new reply saying the testing is actually fine. Do you think 
> > we still need to split the patch?
> 
> That comment was concerning the version of the patch that had the lazy 
> template deserialization turned off by default. Yes, I still think that this 
> patch should implement tha on-disk hash table on top of D41416

OK. And would you like to send a PR for D41416? I've already fixed the issue 
mentioned in the review page. Then I'd like to send small and incremental 
patches on that.

https://github.com/llvm/llvm-project/pull/76774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-17 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > > > [do not merge] [runtime-cxxmodules] Rework our lazy template 
> > > > specialization deserialization mechanism 
> > > > [root-project/root#14495](https://github.com/root-project/root/pull/14495)
> > > 
> > > 
> > > From 
> > > [root-project/root#14495](https://github.com/root-project/root/pull/14495),
> > >  I see there is new reply saying the testing is actually fine. Do you 
> > > think we still need to split the patch?
> > 
> > 
> > That comment was concerning the version of the patch that had the lazy 
> > template deserialization turned off by default. Yes, I still think that 
> > this patch should implement tha on-disk hash table on top of D41416
> 
> OK. And would you like to send a PR for D41416? I've already fixed the issue 
> mentioned in the review page. Then I'd like to send small and incremental 
> patches on that.

Do you mean that I should open a PR for D41416 and you will apply your patch 
there? I have no problem if we do everything here as part of this PR. This way 
we will have the full history of how this was born in one place ;)

https://github.com/llvm/llvm-project/pull/76774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1ecbab5 - [C++20] [Modules] Don't import non-inline function bodies even if it is marked as always_inline

2024-02-17 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-02-18T15:15:28+08:00
New Revision: 1ecbab56dcbb78268c8d19af34a50591f90b12a0

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

LOG: [C++20] [Modules] Don't import non-inline function bodies even if it is 
marked as always_inline

Close https://github.com/llvm/llvm-project/issues/80949

Previously, I thought the always-inline function can be an exception to
enable optimizations as much as possible. However, it looks like it
breaks the ABI requirement we discussed later. So it looks better to not
import non-inline function bodies at all even if the function bodies are
marked as always_inline.

It doesn't produce regressions in some degree since the always_inline
still works in the same TU.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/module-funcs-from-imports.cppm

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c984260b082cd1..836cd34a16c0a1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3985,8 +3985,7 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
   // behavior may break ABI compatibility of the current unit.
   if (const Module *M = F->getOwningModule();
   M && M->getTopLevelModule()->isNamedModule() &&
-  getContext().getCurrentNamedModule() != M->getTopLevelModule() &&
-  !F->hasAttr())
+  getContext().getCurrentNamedModule() != M->getTopLevelModule())
 return false;
 
   if (F->hasAttr())

diff  --git a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm 
b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
index 33cdf437110a9e..8d04328eaf3fea 100644
--- a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
+++ b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
@@ -53,11 +53,11 @@ int use() {
 return exported_func() + always_inline_func();
 }
 
-// Checks that none of the function (except the always_inline_func) in the 
importees
+// Checks that none of the function in the importees
 // are generated in the importer's code.
 // CHECK-O0: define{{.*}}_Z3usev(
 // CHECK-O0: declare{{.*}}_ZW1M13exported_funcv(
-// CHECK-O0: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv(
+// CHECK-O0: declare{{.*}}_ZW1M18always_inline_funcv(
 // CHECK-O0-NOT: func_in_gmf
 // CHECK-O0-NOT: func_in_gmf_not_called
 // CHECK-O0-NOT: non_exported_func
@@ -68,7 +68,7 @@ int use() {
 // O0 to keep consistent ABI.
 // CHECK-O1: define{{.*}}_Z3usev(
 // CHECK-O1: declare{{.*}}_ZW1M13exported_funcv(
-// CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv(
+// CHECK-O1: declare{{.*}}_ZW1M18always_inline_funcv(
 // CHECK-O1-NOT: func_in_gmf
 // CHECK-O1-NOT: func_in_gmf_not_called
 // CHECK-O1-NOT: non_exported_func



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


[clang] [clang] Define SwiftInfo for RISCVTargetCodeGenInfo (PR #82152)

2024-02-17 Thread Visoiu Mistrih Francis via cfe-commits

https://github.com/francisvm approved this pull request.


https://github.com/llvm/llvm-project/pull/82152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-02-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > > > > [do not merge] [runtime-cxxmodules] Rework our lazy template 
> > > > > specialization deserialization mechanism 
> > > > > [root-project/root#14495](https://github.com/root-project/root/pull/14495)
> > > > 
> > > > 
> > > > From 
> > > > [root-project/root#14495](https://github.com/root-project/root/pull/14495),
> > > >  I see there is new reply saying the testing is actually fine. Do you 
> > > > think we still need to split the patch?
> > > 
> > > 
> > > That comment was concerning the version of the patch that had the lazy 
> > > template deserialization turned off by default. Yes, I still think that 
> > > this patch should implement tha on-disk hash table on top of D41416
> > 
> > 
> > OK. And would you like to send a PR for D41416? I've already fixed the 
> > issue mentioned in the review page. Then I'd like to send small and 
> > incremental patches on that.
> 
> Do you mean that I should open a PR for D41416 and you will apply your patch 
> there? I have no problem if we do everything here as part of this PR. This 
> way we will have the full history of how this was born in one place ;)

Yeah, and please create a branch under llvm/llvm-project directly. Then I can 
perform stacked PR on that.

https://github.com/llvm/llvm-project/pull/76774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Define SwiftInfo for RISCVTargetCodeGenInfo (PR #82152)

2024-02-17 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

Can this be tested? I don't know what the affects are.

https://github.com/llvm/llvm-project/pull/82152
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits