[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390149.
lh123 marked 13 inline comments as done.
lh123 added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,8 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
+ bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
@@ -76,7 +77,7 @@
 if (const FunctionType *FT = dyn_cast(Ty)) {
   bool DesugarReturn = false;
   QualType SugarRT = FT->getReturnType();
-  QualType RT = Desugar(Context, SugarRT, DesugarReturn);
+  QualType RT = desugarForDiagnostic(Context, SugarRT, DesugarReturn);
   if (auto nullability = AttributedType::stripOuterNullability(SugarRT)) {
 RT = Context.getAttributedType(
 AttributedType::getNullabilityAttrKind(*nullability), RT, RT);
@@ -87,7 +88,7 @@
   const FunctionProtoType *FPT = dyn_cast(FT);
   if (FPT) {
 for (QualType SugarPT : FPT->param_types()) {
-  QualType PT = Desugar(Context, SugarPT, DesugarArgument);
+  QualType PT = desugarForDiagnostic(Context, SugarPT, DesugarArgument);
   if (auto nullability =
   AttributedType::stripOuterNullability(SugarPT)) {
 PT = Context.getAttributedType(
@@ -115,7 +116,8 @@
 for (unsigned I = 0, N = TST->getNumArgs(); I != N; ++I) {
   const TemplateArgument &Arg = TST->getArg(I);
   if (Arg.getKind() == TemplateArgument::Type)
-Args.push_back(Desugar(Context, Arg.getAsType(), DesugarArgument));
+Args.push_back(desugarForDiagnostic(Context, Arg.getAsType(),
+DesugarArgument));
   else
 Args.push_back(Arg);
 }
@@ -181,24 +183,25 @@
   // If we have a pointer-like type, desugar the pointee as well.
   // FIXME: Handle other pointer-like types.
   if (const PointerType *Ty = QT->getAs()) {
-QT = Context.getPointerType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
-QT = Context.getObjCObjectPointerType(Desugar(Context, Ty->getPointeeType(),
-  ShouldAKA));
+QT = Context.getObjCObjectPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const LValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getLValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getLValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const RValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getRValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getRValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
 if (Ty->getBaseType().getTypePtr() != Ty && !ShouldAKA) {
-  QualType BaseType = Desugar(Context, Ty->getBaseType(), ShouldAKA);
-  QT = Context.getObjCObjectType(BaseType, Ty->getTypeArgsAsWritten(),
- llvm::makeArrayRef(Ty->qual_begin(),
-Ty->getNumProtocols()),
- Ty->isKindOfTypeAsWritten());
+  QualType BaseType =
+  desugarForDiagnostic(Context, Ty->getBaseType(), ShouldAKA);
+  QT = Context.getObjCObjectType(
+  BaseType, Ty->getTypeArgsAsWritten(),
+  llvm::makeArrayRef(Ty->qual_begin(), Ty->getNumProtocols()),
+  Ty->isKindOfTypeAsWritten());
 }
   }
 
@@ -251,7 +254,8 @@
   continue;  // Same canonical types
 std::string CompareS = CompareTy.getAsString(Context.getPrintingPolicy());
 bool ShouldAKA = false;
-QualType CompareDesugar = Desugar(Context, CompareTy, ShouldAKA);
+QualType CompareDesugar =
+desugarForDiagnostic(Context, CompareTy, ShouldAKA);
 std::string CompareDesu

[PATCH] D114665: [clangd] Add a way to enable a.k.a print through config

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 created this revision.
lh123 added reviewers: sammccall, kadircet.
lh123 added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
lh123 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

Currently, a.k.a printing is closed by default.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114665

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -8,6 +8,7 @@
 
 #include "AST.h"
 #include "Annotations.h"
+#include "Config.h"
 #include "Hover.h"
 #include "TestIndex.h"
 #include "TestTU.h"
@@ -2510,7 +2511,9 @@
 // fixed one to make sure tests passes on different platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
 auto AST = TU.build();
-
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
 ASSERT_TRUE(H);
 HoverInfo Expected;
@@ -2873,6 +2876,9 @@
   for (const auto &C : Cases) {
 HoverInfo HI;
 C.Builder(HI);
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 EXPECT_EQ(HI.present().asPlainText(), C.ExpectedRender);
   }
 }
Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -215,6 +215,19 @@
   ASSERT_EQ(Results.size(), 1u);
   EXPECT_THAT(Results[0].Completion.AllScopes, testing::Eq(llvm::None));
 }
+
+TEST(ParseYAML, AKAPrint) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+Hover:
+  AKAPrint: True
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].Hover.AKAPrint, llvm::ValueIs(Val(true)));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -10,6 +10,7 @@
 
 #include "AST.h"
 #include "CodeCompletionStrings.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "ParsedAST.h"
 #include "Selection.h"
@@ -666,7 +667,9 @@
   std::string Result;
   llvm::raw_string_ostream OS(Result);
   OS << PType.Type;
-  if (PType.AKA)
+
+  const Config &Cfg = Config::current();
+  if (PType.AKA && Cfg.Hover.AKAPrint)
 OS << " // aka: " << *PType.AKA;
   OS.flush();
   return Result;
@@ -1240,7 +1243,9 @@
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
   const HoverInfo::PrintedType &T) {
   OS << T.Type;
-  if (T.AKA)
+  
+  const Config &Cfg = Config::current();
+  if (T.AKA && Cfg.Hover.AKAPrint)
 OS << " (aka " << *T.AKA << ")";
   return OS;
 }
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -65,6 +65,7 @@
 Dict.handle("Style", [&](Node &N) { parse(F.Style, N); });
 Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); });
 Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); });
+Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); });
 Dict.parse(N);
 return !(N.failed() || HadError);
   }
@@ -204,6 +205,19 @@
 Dict.parse(N);
   }
 
+  void parse(Fragment::HoverBlock &F, Node &N) {
+DictParser Dict("Hover", this);
+Dict.handle("AKAPrint", [&](Node &N) {
+  if (auto Value = scalarValue(N, "AKAPrint")) {
+if (auto AKAPrint = llvm::yaml::parseBool(**Value))
+  F.AKAPrint = *AKAPrint;
+else
+  warning("AKAPrint should be a boolean", N);
+  }
+});
+Dict.parse(N);
+  }
+
   // Helper for parsing mapping nodes (dictionaries).
   // We don't use YamlIO as we want to control over unknown keys.
   class DictParser {
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -266,6 +266,13 @@
 llvm::Optional> AllScopes;
   };
   CompletionBlock Completion;
+
+  /// Describes hove

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390153.
lh123 added a comment.

format code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,8 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
+ bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
@@ -76,7 +77,7 @@
 if (const FunctionType *FT = dyn_cast(Ty)) {
   bool DesugarReturn = false;
   QualType SugarRT = FT->getReturnType();
-  QualType RT = Desugar(Context, SugarRT, DesugarReturn);
+  QualType RT = desugarForDiagnostic(Context, SugarRT, DesugarReturn);
   if (auto nullability = AttributedType::stripOuterNullability(SugarRT)) {
 RT = Context.getAttributedType(
 AttributedType::getNullabilityAttrKind(*nullability), RT, RT);
@@ -87,7 +88,7 @@
   const FunctionProtoType *FPT = dyn_cast(FT);
   if (FPT) {
 for (QualType SugarPT : FPT->param_types()) {
-  QualType PT = Desugar(Context, SugarPT, DesugarArgument);
+  QualType PT = desugarForDiagnostic(Context, SugarPT, DesugarArgument);
   if (auto nullability =
   AttributedType::stripOuterNullability(SugarPT)) {
 PT = Context.getAttributedType(
@@ -115,7 +116,8 @@
 for (unsigned I = 0, N = TST->getNumArgs(); I != N; ++I) {
   const TemplateArgument &Arg = TST->getArg(I);
   if (Arg.getKind() == TemplateArgument::Type)
-Args.push_back(Desugar(Context, Arg.getAsType(), DesugarArgument));
+Args.push_back(desugarForDiagnostic(Context, Arg.getAsType(),
+DesugarArgument));
   else
 Args.push_back(Arg);
 }
@@ -181,24 +183,25 @@
   // If we have a pointer-like type, desugar the pointee as well.
   // FIXME: Handle other pointer-like types.
   if (const PointerType *Ty = QT->getAs()) {
-QT = Context.getPointerType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
-QT = Context.getObjCObjectPointerType(Desugar(Context, Ty->getPointeeType(),
-  ShouldAKA));
+QT = Context.getObjCObjectPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const LValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getLValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getLValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const RValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getRValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getRValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
 if (Ty->getBaseType().getTypePtr() != Ty && !ShouldAKA) {
-  QualType BaseType = Desugar(Context, Ty->getBaseType(), ShouldAKA);
-  QT = Context.getObjCObjectType(BaseType, Ty->getTypeArgsAsWritten(),
- llvm::makeArrayRef(Ty->qual_begin(),
-Ty->getNumProtocols()),
- Ty->isKindOfTypeAsWritten());
+  QualType BaseType =
+  desugarForDiagnostic(Context, Ty->getBaseType(), ShouldAKA);
+  QT = Context.getObjCObjectType(
+  BaseType, Ty->getTypeArgsAsWritten(),
+  llvm::makeArrayRef(Ty->qual_begin(), Ty->getNumProtocols()),
+  Ty->isKindOfTypeAsWritten());
 }
   }
 
@@ -251,7 +254,8 @@
   continue;  // Same canonical types
 std::string CompareS = CompareTy.getAsString(Context.getPrintingPolicy());
 bool ShouldAKA = false;
-QualType CompareDesugar = Desugar(Context, CompareTy, ShouldAKA);
+QualType CompareDesugar =
+desugarForDiagnostic(Context, CompareTy, ShouldAKA);
 std::string CompareDesugarStr =
 CompareDesugar.getAsString(

[PATCH] D114522: [clangd] Add desugared type to hover

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390154.
lh123 added a comment.

format again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114522

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTDiagnostic.h
  clang/lib/AST/ASTDiagnostic.cpp

Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -26,7 +26,8 @@
 
 // Returns a desugared version of the QualType, and marks ShouldAKA as true
 // whenever we remove significant sugar from the type.
-static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
+QualType clang::desugarForDiagnostic(ASTContext &Context, QualType QT,
+ bool &ShouldAKA) {
   QualifierCollector QC;
 
   while (true) {
@@ -76,7 +77,7 @@
 if (const FunctionType *FT = dyn_cast(Ty)) {
   bool DesugarReturn = false;
   QualType SugarRT = FT->getReturnType();
-  QualType RT = Desugar(Context, SugarRT, DesugarReturn);
+  QualType RT = desugarForDiagnostic(Context, SugarRT, DesugarReturn);
   if (auto nullability = AttributedType::stripOuterNullability(SugarRT)) {
 RT = Context.getAttributedType(
 AttributedType::getNullabilityAttrKind(*nullability), RT, RT);
@@ -87,7 +88,7 @@
   const FunctionProtoType *FPT = dyn_cast(FT);
   if (FPT) {
 for (QualType SugarPT : FPT->param_types()) {
-  QualType PT = Desugar(Context, SugarPT, DesugarArgument);
+  QualType PT = desugarForDiagnostic(Context, SugarPT, DesugarArgument);
   if (auto nullability =
   AttributedType::stripOuterNullability(SugarPT)) {
 PT = Context.getAttributedType(
@@ -115,7 +116,8 @@
 for (unsigned I = 0, N = TST->getNumArgs(); I != N; ++I) {
   const TemplateArgument &Arg = TST->getArg(I);
   if (Arg.getKind() == TemplateArgument::Type)
-Args.push_back(Desugar(Context, Arg.getAsType(), DesugarArgument));
+Args.push_back(desugarForDiagnostic(Context, Arg.getAsType(),
+DesugarArgument));
   else
 Args.push_back(Arg);
 }
@@ -181,24 +183,25 @@
   // If we have a pointer-like type, desugar the pointee as well.
   // FIXME: Handle other pointer-like types.
   if (const PointerType *Ty = QT->getAs()) {
-QT = Context.getPointerType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
-QT = Context.getObjCObjectPointerType(Desugar(Context, Ty->getPointeeType(),
-  ShouldAKA));
+QT = Context.getObjCObjectPointerType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const LValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getLValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getLValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const RValueReferenceType *Ty = QT->getAs()) {
-QT = Context.getRValueReferenceType(Desugar(Context, Ty->getPointeeType(),
-ShouldAKA));
+QT = Context.getRValueReferenceType(
+desugarForDiagnostic(Context, Ty->getPointeeType(), ShouldAKA));
   } else if (const auto *Ty = QT->getAs()) {
 if (Ty->getBaseType().getTypePtr() != Ty && !ShouldAKA) {
-  QualType BaseType = Desugar(Context, Ty->getBaseType(), ShouldAKA);
-  QT = Context.getObjCObjectType(BaseType, Ty->getTypeArgsAsWritten(),
- llvm::makeArrayRef(Ty->qual_begin(),
-Ty->getNumProtocols()),
- Ty->isKindOfTypeAsWritten());
+  QualType BaseType =
+  desugarForDiagnostic(Context, Ty->getBaseType(), ShouldAKA);
+  QT = Context.getObjCObjectType(
+  BaseType, Ty->getTypeArgsAsWritten(),
+  llvm::makeArrayRef(Ty->qual_begin(), Ty->getNumProtocols()),
+  Ty->isKindOfTypeAsWritten());
 }
   }
 
@@ -251,7 +254,8 @@
   continue;  // Same canonical types
 std::string CompareS = CompareTy.getAsString(Context.getPrintingPolicy());
 bool ShouldAKA = false;
-QualType CompareDesugar = Desugar(Context, CompareTy, ShouldAKA);
+QualType CompareDesugar =
+desugarForDiagnostic(Context, CompareTy, ShouldAKA);
 std::string CompareDesugarStr =
 CompareDesugar.getAsString

[PATCH] D114576: [PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET

2021-11-27 Thread Markus Böck via Phabricator via cfe-commits
zero9178 updated this revision to Diff 390156.
zero9178 added a comment.

Alternative implementation of the original patch.

Moves the defining macro from being added to the cc1 command line by the 
driver, to being a builtin macro. This should avoid the issues with clang-tidy.


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

https://reviews.llvm.org/D114576

Files:
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -194,6 +194,7 @@
 // MSEXT:#define _INTEGRAL_MAX_BITS 64
 // MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1
 // MSEXT-NOT:#define _WCHAR_T_DEFINED 1
+// MSEXT:#define _MSVC_EXECUTION_CHARACTER_SET 65001
 //
 //
 // RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < 
/dev/null | FileCheck -match-full-lines -check-prefix MSEXT-CXX %s
Index: clang/lib/Basic/Targets/OSTargets.cpp
===
--- clang/lib/Basic/Targets/OSTargets.cpp
+++ clang/lib/Basic/Targets/OSTargets.cpp
@@ -201,6 +201,14 @@
   }
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001");
 }
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -194,6 +194,7 @@
 // MSEXT:#define _INTEGRAL_MAX_BITS 64
 // MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1
 // MSEXT-NOT:#define _WCHAR_T_DEFINED 1
+// MSEXT:#define _MSVC_EXECUTION_CHARACTER_SET 65001
 //
 //
 // RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix MSEXT-CXX %s
Index: clang/lib/Basic/Targets/OSTargets.cpp
===
--- clang/lib/Basic/Targets/OSTargets.cpp
+++ clang/lib/Basic/Targets/OSTargets.cpp
@@ -201,6 +201,14 @@
   }
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001");
 }
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114665: [clangd] Make a.k.a printing configurable.

2021-11-27 Thread liu hui via Phabricator via cfe-commits
lh123 updated this revision to Diff 390158.
lh123 retitled this revision from "[clangd] Add a way to enable a.k.a print 
through config" to "[clangd] Make a.k.a printing configurable.".
lh123 added a comment.

fix testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114665

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -8,6 +8,7 @@
 
 #include "AST.h"
 #include "Annotations.h"
+#include "Config.h"
 #include "Hover.h"
 #include "TestIndex.h"
 #include "TestTU.h"
@@ -979,6 +980,9 @@
 // fixed one to make sure tests passes on different platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
 auto AST = TU.build();
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 
 auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
 ASSERT_TRUE(H);
@@ -2510,7 +2514,9 @@
 // fixed one to make sure tests passes on different platform.
 TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
 auto AST = TU.build();
-
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
 ASSERT_TRUE(H);
 HoverInfo Expected;
@@ -2873,6 +2879,9 @@
   for (const auto &C : Cases) {
 HoverInfo HI;
 C.Builder(HI);
+Config Cfg;
+Cfg.Hover.AKAPrint = true;
+WithContextValue WithCfg(Config::Key, std::move(Cfg));
 EXPECT_EQ(HI.present().asPlainText(), C.ExpectedRender);
   }
 }
Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -215,6 +215,19 @@
   ASSERT_EQ(Results.size(), 1u);
   EXPECT_THAT(Results[0].Completion.AllScopes, testing::Eq(llvm::None));
 }
+
+TEST(ParseYAML, AKAPrint) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+Hover:
+  AKAPrint: True
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].Hover.AKAPrint, llvm::ValueIs(Val(true)));
+}
 } // namespace
 } // namespace config
 } // namespace clangd
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -10,6 +10,7 @@
 
 #include "AST.h"
 #include "CodeCompletionStrings.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "ParsedAST.h"
 #include "Selection.h"
@@ -159,7 +160,9 @@
   }
   QT.print(OS, PP);
   OS.flush();
-  if (!QT.isNull()) {
+
+  const Config &Cfg = Config::current();
+  if (!QT.isNull() && Cfg.Hover.AKAPrint) {
 bool ShouldAKA = false;
 QualType DesugaredTy = clang::desugarForDiagnostic(ASTCtx, QT, ShouldAKA);
 if (ShouldAKA)
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -65,6 +65,7 @@
 Dict.handle("Style", [&](Node &N) { parse(F.Style, N); });
 Dict.handle("Diagnostics", [&](Node &N) { parse(F.Diagnostics, N); });
 Dict.handle("Completion", [&](Node &N) { parse(F.Completion, N); });
+Dict.handle("Hover", [&](Node &N) { parse(F.Hover, N); });
 Dict.parse(N);
 return !(N.failed() || HadError);
   }
@@ -204,6 +205,19 @@
 Dict.parse(N);
   }
 
+  void parse(Fragment::HoverBlock &F, Node &N) {
+DictParser Dict("Hover", this);
+Dict.handle("AKAPrint", [&](Node &N) {
+  if (auto Value = scalarValue(N, "AKAPrint")) {
+if (auto AKAPrint = llvm::yaml::parseBool(**Value))
+  F.AKAPrint = *AKAPrint;
+else
+  warning("AKAPrint should be a boolean", N);
+  }
+});
+Dict.parse(N);
+  }
+
   // Helper for parsing mapping nodes (dictionaries).
   // We don't use YamlIO as we want to control over unknown keys.
   class DictParser {
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -266,6 +266,13 @@
 llvm::Optional>

[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-27 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 390165.
carlosgalvezp marked 5 inline comments as done.
carlosgalvezp added a comment.

Addressed comments.


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

https://reviews.llvm.org/D114427

Files:
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp
@@ -143,11 +143,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
   // CHECK-FIXES: {{^}}  kZero;
 
-  int b2 = int(b);
-  int b3 = static_cast(b);
-  int b4 = b;
+  int b2 = static_cast(b);
+  int b3 = b;
   double aa = a;
-  (void)b2;
+  (void)aa;
   return (void)g();
 }
 
@@ -321,3 +320,23 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
   // CHECK-FIXES: auto s6 = S(cr);
 }
+
+void functional_casts() {
+  float x = 1.5F;
+  auto y = int(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: C-style casts are discouraged; use static_cast
+  // CHECK-FIXES: auto y = static_cast(x);
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wc++11-narrowing"
+  // This if fine, compiler will warn about implicit conversions with brace initialization
+  auto z = int{x};
+#pragma clang diagnostic pop
+
+  // Functional casts are allowed if S is of class type
+  const char *str = "foo";
+  auto s = S(str);
+
+  // New expressions are not functional casts
+  auto w = new int(x);
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -133,9 +133,11 @@
 Changes in existing checks
 ^^
 
-- Removed default setting `cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors = "true"`,
+- Removed default setting ``cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors = "true"``,
   to match the current state of the C++ Core Guidelines.
 
+- Updated ``google-readability-casting`` to diagnose and fix functional casts, to achieve feature
+  parity with the corresponding ``cpplint.py`` check.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -31,6 +31,11 @@
   unless(isInTemplateInstantiation()))
   .bind("cast"),
   this);
+  Finder->addMatcher(
+  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
+unless(hasDescendant(initListExpr(
+  .bind("cast"),
+  this);
 }
 
 static bool needsConstCast(QualType SourceType, QualType DestType) {
@@ -55,8 +60,39 @@
   return T1.getUnqualifiedType() == T2.getUnqualifiedType();
 }
 
+static clang::CharSourceRange getReplaceRange(const CStyleCastExpr *CastExpr) {
+  return CharSourceRange::getCharRange(
+  CastExpr->getLParenLoc(), CastExpr->getSubExprAsWritten()->getBeginLoc());
+}
+
+static clang::CharSourceRange
+getReplaceRange(const CXXFunctionalCastExpr *CastExpr) {
+  return CharSourceRange::getCharRange(CastExpr->getBeginLoc(),
+   CastExpr->getLParenLoc());
+}
+
+static StringRef getDestTypeString(const SourceManager &SM,
+   const LangOptions &LangOpts,
+   const CStyleCastExpr *CastExpr) {
+  return Lexer::getSourceText(
+  CharSourceRange::getTokenRange(
+  CastExpr->getLParenLoc().getLocWithOffset(1),
+  CastExpr->getRParenLoc().getLocWithOffset(-1)),
+  SM, LangOpts);
+}
+
+static StringRef getDestTypeString(const SourceManager &SM,
+   const LangOptions &LangOpts,
+   const CXXFunctionalCastExpr *CastExpr) {
+  return Lexer::getSourceText(
+  CharSourceRange::getTokenRange(
+  CastExpr->getBeginLoc(),
+  CastExpr->getLParenLoc().getLocWithOffset(-1)),
+  SM, LangOpts);
+}
+
 void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *CastExpr = Result.Nodes.getNodeAs("cast");
+  const auto *CastExpr = Result.Nodes.getNodeAs("cast");
 
   // Ignore casts in macros.
   if (CastExpr->getExprLoc().isMacroID())
@@ -80,8 +116,10 @@
   const QualType SourceType = SourceTypeAsWritten.getCanonicalType();
   const QualType DestType = DestTypeAsWritten.getCanonicalType();
 
-  a

[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-27 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp:99-106
+  CharSourceRange ReplaceRange;
+  if (isa(CastExpr))
+ReplaceRange = CharSourceRange::getCharRange(
+CastExpr->getLParenLoc(),
+CastExpr->getSubExprAsWritten()->getBeginLoc());
+  else if (isa(CastExpr))
+ReplaceRange = CharSourceRange::getCharRange(CastExpr->getBeginLoc(),

salman-javed-nz wrote:
> The majority of `checkExpr()`'s contents are common to both types, 
> `CStyleCastExpr` and `CXXFunctionalCastExpr`.
> Only the `ReplaceRange = CharSourceRange::getCharRange...` and the 
> `DestTypeString = Lexer::getSourceText...` parts change depending on the Expr 
> type.
> 
> What about breaking those two assignments out into their own functions, 
> rather than templating the entire `checkExpr()` function?
> 
> For example, (note: untested code)
> 
> ```lang=cpp
> clang::CharSourceRange GetReplaceRange(const CStyleCastExpr *CastExpr) {
>   return CharSourceRange::getCharRange(
>   CastExpr->getLParenLoc(), 
> CastExpr->getSubExprAsWritten()->getBeginLoc());
> }
> 
> clang::CharSourceRange GetReplaceRange(const CXXFunctionalCastExpr *CastExpr) 
> {
>   return CharSourceRange::getCharRange(CastExpr->getBeginLoc(),
>CastExpr->getLParenLoc());
> }
> 
> ...
> 
> CharSourceRange ReplaceRange =
>   isa(CastExpr)
>   ? GetReplaceRange(dyn_cast(CastExpr))
>   : GetReplaceRange(dyn_cast(CastExpr));
> ```
> 
> Would something like that work?
Thanks for the suggestion, much cleaner! I've made `CastExpr` become a 
`ExplicitCastExpr` instead (which is common base to both cast classes) to be 
able to handle only one object.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:335
+  const char *str = "foo";
+  auto s = S(str);
+}

salman-javed-nz wrote:
> Is a test to check `new int(x)` worth including? I see that the cpplint guys 
> explicitly filter it out of their results.
Sure, even though I think technically it's not a cast. At least it's not shown 
as such in the AST.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-27 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp:122
+  ? getReplaceRange(dyn_cast(CastExpr))
+  : getReplaceRange(dyn_cast(CastExpr));
 

One problem I see here is in the future someone adds a 3rd class of casts - 
then this should become an if-else. That's why I had it like that before, but 
perhaps it's too "defensive" at this point.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114533: LLVM IR should allow bitcast between address spaces with the same size.

2021-11-27 Thread Keno Fischer via Phabricator via cfe-commits
loladiro added a comment.

@jrtc27 is correct. This absolutely must not apply to non-integral address 
spaces. It is not legal for LLVM to introduce additional ptrtoint instructions 
for non-integral address spaces that were not present in the original input IR. 
That doesn't change if the spelling of a ptrtoint/inttoptr pair is changed to 
bitcast. There is a bit of a larger issue here that LLVM IR isn't really rich 
enough to currently describe what operations are legal for the optimizer to 
introduce and what aren't. Every frontend/backend that uses them has their own 
rules that appear obvious for a particular use case, but aren't necessarily 
general. A similar issue applies to commuting GEPs with addrspacecasts. I'm 
wondering if we need something like the datalayout but for describing 
relationships between addrspaces and what things are legal and what are not.


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

https://reviews.llvm.org/D114533

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


[PATCH] D114667: [clangd] Add fixes for clang "include " diagnostics

2021-11-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: nridge.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, MaskRay, ilya-biryukov.
Herald added a reviewer: jdoerfert.
Herald added a project: clang-tools-extra.

Clang doesn't offer these fixes I guess for a couple of reasons:

- where to insert includes is a formatting concern, and clang shouldn't depend 
on clang-format
- the way clang prints diagnostics, we'd show a bunch of basically irrelevant 
context of "this is where we'd want to insert the include"

Maybe it's possible to hack around 1, but 2 is still a concern.
Meanwhile, bolting this onto include-fixer gets the job done.

Fixes https://github.com/clangd/clangd/issues/355
Fixes https://github.com/clangd/clangd/issues/937


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114667

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1034,7 +1034,7 @@
   "Add include \"b.h\" for symbol na::nb::X");
 }
 
-TEST(IncludeFixerTest, NoCrashMemebrAccess) {
+TEST(IncludeFixerTest, NoCrashMemberAccess) {
   Annotations Test(R"cpp(// error-ok
 struct X { int  xyz; };
 void g() { X x; x.$[[xy]]; }
@@ -1206,6 +1206,26 @@
   ElementsAre(Diag(Test.range(), "use of undeclared identifier 'a'")));
 }
 
+TEST(IncludeFixerTest, HeaderNamedInDiag) {
+  Annotations Test(R"cpp(
+$insert[[]]int main() {
+  [[printf]]("");
+}
+  )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ExtraArgs = {"-xc"};
+  auto Index = buildIndexWithSymbol({});
+  TU.ExternalIndex = Index.get();
+
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  ElementsAre(AllOf(
+  Diag(Test.range(), "implicitly declaring library function 'printf' "
+ "with type 'int (const char *, ...)'"),
+  WithFix(Fix(Test.range("insert"), "#include \n",
+  "Include ");
+}
+
 TEST(DiagsInHeaders, DiagInsideHeader) {
   Annotations Main(R"cpp(
 #include [["a.h"]]
Index: clang-tools-extra/clangd/IncludeFixer.h
===
--- clang-tools-extra/clangd/IncludeFixer.h
+++ clang-tools-extra/clangd/IncludeFixer.h
@@ -40,6 +40,7 @@
 IndexRequestLimit(IndexRequestLimit) {}
 
   /// Returns include insertions that can potentially recover the diagnostic.
+  /// If Info describes a note, it will be replaced by any returned fixes.
   std::vector fix(DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) const;
 
@@ -55,6 +56,8 @@
   /// Generates header insertion fixes for all symbols. Fixes are deduplicated.
   std::vector fixesForSymbols(const SymbolSlab &Syms) const;
 
+  std::vector fixMissingHeader(llvm::StringRef Name) const;
+
   struct UnresolvedName {
 std::string Name;   // E.g. "X" in foo::X.
 SourceLocation Loc; // Start location of the unresolved name.
Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -47,6 +47,19 @@
 
 namespace clang {
 namespace clangd {
+namespace {
+llvm::Optional getArgStr(const clang::Diagnostic &Info,
+  unsigned I) {
+  switch (Info.getArgKind(I)) {
+  case DiagnosticsEngine::ak_c_string:
+return llvm::StringRef(Info.getArgCStr(I));
+  case DiagnosticsEngine::ak_std_string:
+return llvm::StringRef(Info.getArgStdStr(I));
+  default:
+return llvm::None;
+  }
+}
+} // namespace
 
 std::vector IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic &Info) const {
@@ -102,7 +115,32 @@
   LastUnresolvedName->Loc == Info.getLocation())
 return fixUnresolvedName();
 }
+break;
+  // Cases where clang explicitly knows which header to include.
+  // (There's no fix provided for boring formatting reasons).
+  case diag::err_implied_std_initializer_list_not_found:
+return fixMissingHeader("");
+  case diag::err_need_header_before_typeid:
+return fixMissingHeader("");
+  case diag::err_need_header_before_ms_uuidof:
+return fixMissingHeader("");
+  case diag::err_need_header_before_placement_new:
+  case diag::err_implicit_coroutine_std_nothrow_type_not_found:
+return fixMissingHeader("");
+  case diag::err_omp_implied_type_not_found:
+  case diag::err_omp_interop_type_not_found:
+return

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-11-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D105177#3156597 , @nridge wrote:

> What is the status of this -- is it ready to be merged?

This works as far as it goes, but it needs someone to wire it up completely: 
build these indexes somewhere that's less blocking than the main thread, 
determine the right one to attach dynamically based on the file language, etc.

The original plan was that Christian would do this as a followup but that's not 
likely to happen. Meanwhile many of the usual suspects are a bit backed up. We 
can definitely land this if you or anyone might want to finish it...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

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


[PATCH] D114213: Compilation Database: Point Bazel users to a solution

2021-11-27 Thread Christopher Sauer via Phabricator via cfe-commits
cpsauer added a comment.

@sammccall (or others), could I ask for your help landing the change now that 
it's approved?

(I think I need to ask someone with commit access to do so, per 
https://llvm.org/docs/Phabricator.html#committing-a-change)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114213

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-27 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz accepted this revision.
salman-javed-nz added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:335
+  const char *str = "foo";
+  auto s = S(str);
+}

carlosgalvezp wrote:
> salman-javed-nz wrote:
> > Is a test to check `new int(x)` worth including? I see that the cpplint 
> > guys explicitly filter it out of their results.
> Sure, even though I think technically it's not a cast. At least it's not 
> shown as such in the AST.
It's not a cast in the AST, but it's nice to document in the unit test that we 
have considered it and that that intend to treat it no differently to how 
cpplint treats it.


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

https://reviews.llvm.org/D114427

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


[PATCH] D114427: [clang-tidy] Warn on functional C-style casts

2021-11-27 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/google-readability-casting.cpp:342
+  auto w = new int(x);
+}

What about
```
template T foo(int i) { return T(i); }
int main() {
foo>(); // valid, OK(!)
foo(); // valid, not OK
}
```
What about
```
struct Widget { Widget(int); };
using T = Widget;
using U = Widget&;
int i = 42;
Widget t = T(i);  // valid, OK?
Widget u = U(i);  // valid C++, should definitely not be OK
```
https://quuxplusone.github.io/blog/2020/01/22/expression-list-in-functional-cast/


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

https://reviews.llvm.org/D114427

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