[PATCH] D89670: [clangd] Store the containing symbol for refs

2020-10-18 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
nridge requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

This is needed to implement call hierarchy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89670

Files:
  clang-tools-extra/clangd/index/Ref.h
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h

Index: clang-tools-extra/clangd/index/SymbolCollector.h
===
--- clang-tools-extra/clangd/index/SymbolCollector.h
+++ clang-tools-extra/clangd/index/SymbolCollector.h
@@ -156,7 +156,11 @@
   std::shared_ptr CompletionAllocator;
   std::unique_ptr CompletionTUInfo;
   Options Opts;
-  using SymbolRef = std::pair;
+  struct SymbolRef {
+SourceLocation Loc;
+index::SymbolRoleSet Roles;
+const NamedDecl *Container;
+  };
   // Symbols referenced from the current TU, flushed on finish().
   llvm::DenseSet ReferencedDecls;
   llvm::DenseSet ReferencedMacros;
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -344,7 +344,9 @@
   !isa(ND) &&
   (Opts.RefsInHeaders ||
SM.getFileID(SM.getFileLoc(Loc)) == SM.getMainFileID()))
-DeclRefs[ND].emplace_back(SM.getFileLoc(Loc), Roles);
+DeclRefs[ND].push_back(
+SymbolRef{SM.getFileLoc(Loc), Roles,
+  dyn_cast_or_null(ASTNode.Parent)});
   // Don't continue indexing if this is a mere reference.
   if (IsOnlyRef)
 return true;
@@ -422,7 +424,8 @@
   // Do not store references to main-file macros.
   if ((static_cast(Opts.RefFilter) & Roles) && !IsMainFileOnly &&
   (Opts.RefsInHeaders || SM.getFileID(SpellingLoc) == SM.getMainFileID()))
-MacroRefs[*ID].push_back({Loc, Roles});
+// FIXME: Populate container information for macro references.
+MacroRefs[*ID].push_back({Loc, Roles, /*Container=*/nullptr});
 
   // Collect symbols.
   if (!Opts.CollectMacro)
@@ -579,24 +582,23 @@
 }
 return Found->second;
   };
-  auto CollectRef =
-  [&](SymbolID ID,
-  const std::pair ,
-  bool Spelled = false) {
-auto FileID = SM.getFileID(LocAndRole.first);
-// FIXME: use the result to filter out references.
-shouldIndexFile(FileID);
-if (auto FileURI = GetURI(FileID)) {
-  auto Range =
-  getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
-  Ref R;
-  R.Location.Start = Range.first;
-  R.Location.End = Range.second;
-  R.Location.FileURI = FileURI->c_str();
-  R.Kind = toRefKind(LocAndRole.second, Spelled);
-  Refs.insert(ID, R);
-}
-  };
+  auto CollectRef = [&](SymbolID ID, const SymbolRef ,
+bool Spelled = false) {
+auto FileID = SM.getFileID(LocAndRole.Loc);
+// FIXME: use the result to filter out references.
+shouldIndexFile(FileID);
+if (auto FileURI = GetURI(FileID)) {
+  auto Range = getTokenRange(LocAndRole.Loc, SM, ASTCtx->getLangOpts());
+  Ref R;
+  R.Location.Start = Range.first;
+  R.Location.End = Range.second;
+  R.Location.FileURI = FileURI->c_str();
+  R.Kind = toRefKind(LocAndRole.Roles, Spelled);
+  if (auto RefID = getSymbolID(LocAndRole.Container))
+R.Container = *RefID;
+  Refs.insert(ID, R);
+}
+  };
   // Populate Refs slab from MacroRefs.
   // FIXME: All MacroRefs are marked as Spelled now, but this should be checked.
   for (const auto  : MacroRefs)
@@ -607,7 +609,7 @@
   for (auto  : DeclRefs) {
 if (auto ID = getSymbolID(DeclAndRef.first)) {
   for (auto  : DeclAndRef.second) {
-const auto FileID = SM.getFileID(LocAndRole.first);
+const auto FileID = SM.getFileID(LocAndRole.Loc);
 // FIXME: It's better to use TokenBuffer by passing spelled tokens from
 // the caller of SymbolCollector.
 if (!FilesToTokensCache.count(FileID))
@@ -617,7 +619,7 @@
 // Check if the referenced symbol is spelled exactly the same way the
 // corresponding NamedDecl is. If it is, mark this reference as spelled.
 const auto *IdentifierToken =
-spelledIdentifierTouching(LocAndRole.first, Tokens);
+spelledIdentifierTouching(LocAndRole.Loc, Tokens);
 DeclarationName Name = DeclAndRef.first->getDeclName();
 const auto NameKind = Name.getNameKind();
 bool IsTargetKind = NameKind == DeclarationName::Identifier ||
Index: clang-tools-extra/clangd/index/Serialization.cpp
===
--- clang-tools-extra/clangd/index/Serialization.cpp

[PATCH] D89297: [clangd] Add a TestWorkspace utility

2020-10-18 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a reviewer: kadircet.
nridge added a comment.

Thanks for the suggestions! I implemented them and it seems to be working well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89297

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


[PATCH] D89297: [clangd] Add a TestWorkspace utility

2020-10-18 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 298926.
nridge added a comment.

Rework utility as suggested


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89297

Files:
  clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h
  clang-tools-extra/clangd/unittests/TestWorkspace.h

Index: clang-tools-extra/clangd/unittests/TestWorkspace.h
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TestWorkspace.h
@@ -0,0 +1,101 @@
+//===--- TestWorkspace.h - Utility for writing multi-file tests --*- 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
+//
+//===--===//
+//
+// TestWorkspace builds on TestTU to provide a way to write tests involving
+// several related files with inclusion relationships between them.
+//
+// The tests can exercise both index- and AST-based operations.
+//
+//===-===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
+#define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
+
+#include "TestFS.h"
+#include "TestTU.h"
+#include "index/FileIndex.h"
+#include "index/Index.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+class TestWorkspace {
+public:
+  struct SourceFile {
+std::string Filename;
+std::string Code;
+bool IsMainFile = false;
+  };
+
+  TestWorkspace() {}
+  TestWorkspace(const std::vector ) {
+for (auto  : Inputs) {
+  addInput(Input);
+}
+  }
+
+  void addSource(llvm::StringRef Filename, llvm::StringRef Code) {
+addInput({std::string(Filename), std::string(Code), false});
+  }
+
+  void addMainFile(llvm::StringRef Filename, llvm::StringRef Code) {
+addInput({std::string(Filename), std::string(Code), true});
+  }
+
+  std::unique_ptr index() {
+auto Index = std::make_unique();
+for (const auto  : Inputs) {
+  if (Input.IsMainFile) {
+TU.Code = Input.Code;
+TU.Filename = Input.Filename;
+TU.preamble([&](ASTContext ,
+std::shared_ptr PP,
+const CanonicalIncludes ) {
+  Index->updatePreamble(testPath(Input.Filename), "null", Ctx, PP,
+CanonIncludes);
+});
+ParsedAST MainAST = TU.build();
+Index->updateMain(testPath(Input.Filename), MainAST);
+  }
+}
+return Index;
+  }
+
+  Optional openFile(llvm::StringRef Filename) {
+SourceFile *Input = findFile(Filename);
+if (!Input)
+  return llvm::None;
+TU.Code = Input->Code;
+TU.Filename = std::string(Filename);
+return TU.build();
+  }
+
+private:
+  std::vector Inputs;
+  TestTU TU;
+
+  void addInput(const SourceFile ) {
+Inputs.push_back(Input);
+TU.AdditionalFiles.insert(std::make_pair(Input.Filename, Input.Code));
+  }
+
+  SourceFile *findFile(llvm::StringRef Filename) {
+for (auto  : Inputs)
+  if (Filename == Input.Filename)
+return 
+return nullptr;
+  }
+};
+
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTWORKSPACE_H
Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -79,7 +79,8 @@
   // By default, build() will report Error diagnostics as GTest errors.
   // Suppress this behavior by adding an 'error-ok' comment to the code.
   ParsedAST build() const;
-  std::shared_ptr preamble() const;
+  std::shared_ptr
+  preamble(PreambleParsedCallback PreambleCallback = nullptr) const;
   ParseInputs inputs(MockFS ) const;
   SymbolSlab headerSymbols() const;
   RefSlab headerRefs() const;
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -80,7 +80,8 @@
   }
 }
 
-std::shared_ptr TestTU::preamble() const {
+std::shared_ptr
+TestTU::preamble(PreambleParsedCallback PreambleCallback) const {
   MockFS FS;
   auto Inputs = inputs(FS);
   IgnoreDiagnostics Diags;
@@ -91,8 +92,7 @@
   auto ModuleCacheDeleter = llvm::make_scope_exit(
   std::bind(deleteModuleCache, CI->getHeaderSearchOpts().ModuleCachePath));
   return clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
-  

[PATCH] D89301: [X86] Add user-level interrupt instructions

2020-10-18 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

You need to add test for macro UINTR  in 
clang/test/Preprocessor/predefined-arch-macros.c for SapphireRapids.




Comment at: llvm/docs/ReleaseNotes.rst:117
   the target CPU.
-* Support for ISA HRESET has been added.
+* Support for HRESET and UINTR instructions has been added.
 

Maybe need add to Clang release notes too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89301

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


[PATCH] D89301: [X86] Add user-level interrupt instructions

2020-10-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/X86InstrInfo.td:320
+def X86testui : SDNode<"X86ISD::TESTUI",
+   SDTypeProfile<1, 0, [SDTCisVT<0, i32>]>, 
[SDNPHasChain]>;
 

I think this should have SDNPSideEffect to match the intrinsic and to prevent 
reordering with CLUI/STUI in MachineIR since the TESTUI instruction will 
inherit properties from X86testui being used in its pattern.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89301

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


[PATCH] D89664: [X86] Add missing code in D89102 [X86] Add HRESET instruction.

2020-10-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:770
   FeaturePTWRITE,
+  FeatureHRESET,
   FeatureTSXLDTRK,

Section 1.3 INSTRUCTION SET EXTENSIONS AND FEATURE INTRODUCTION IN INTELĀ®
64 AND IA-32 PROCESSORS  in IntelĀ® Architecture Instruction Set Extensions 
Programming Reference does not show this instruction being supported on 
Sapphire Rapids. Is the documentation incorrect or is this change incorrect?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89664

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


[PATCH] D89664: [X86] Add missing code in D89102 [X86] Add HRESET instruction.

2020-10-18 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: LuoYuanke, FreddyYe, RKSimon, craig.topper.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
pengfei requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89664

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Preprocessor/predefined-arch-macros.c
  llvm/lib/Support/X86TargetParser.cpp
  llvm/lib/Target/X86/X86.td


Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -767,6 +767,7 @@
   FeatureCLDEMOTE,
   FeatureWAITPKG,
   FeaturePTWRITE,
+  FeatureHRESET,
   FeatureTSXLDTRK,
   FeatureENQCMD,
   FeatureSHSTK,
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -204,7 +204,8 @@
 FeaturesICLServer | FeatureAMX_TILE | FeatureAMX_INT8 | FeatureAMX_BF16 |
 FeatureAVX512BF16 | FeatureAVX512VP2INTERSECT | FeatureCLDEMOTE |
 FeatureENQCMD | FeatureMOVDIR64B | FeatureMOVDIRI | FeaturePTWRITE |
-FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureWAITPKG;
+FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureWAITPKG |
+FeatureHRESET;
 
 // Intel Atom processors.
 // Bonnell has feature parity with Core2 and adds MOVBE.
Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -1664,6 +1664,7 @@
 // CHECK_SPR_M32: #define __F16C__ 1
 // CHECK_SPR_M32: #define __FMA__ 1
 // CHECK_SPR_M32: #define __GFNI__ 1
+// CHECK_SPR_M32: #define __HRESET__ 1
 // CHECK_SPR_M32: #define __INVPCID__ 1
 // CHECK_SPR_M32: #define __LZCNT__ 1
 // CHECK_SPR_M32: #define __MMX__ 1
@@ -1733,6 +1734,7 @@
 // CHECK_SPR_M64: #define __F16C__ 1
 // CHECK_SPR_M64: #define __FMA__ 1
 // CHECK_SPR_M64: #define __GFNI__ 1
+// CHECK_SPR_M64: #define __HRESET__ 1
 // CHECK_SPR_M64: #define __INVPCID__ 1
 // CHECK_SPR_M64: #define __LZCNT__ 1
 // CHECK_SPR_M64: #define __MMX__ 1
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -200,6 +200,8 @@
   implies -mtune=. -mtune=generic is the default with no -march or -mtune
   specified.
 
+- Support for ISA HRESET has been added.
+
 Internal API Changes
 
 


Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -767,6 +767,7 @@
   FeatureCLDEMOTE,
   FeatureWAITPKG,
   FeaturePTWRITE,
+  FeatureHRESET,
   FeatureTSXLDTRK,
   FeatureENQCMD,
   FeatureSHSTK,
Index: llvm/lib/Support/X86TargetParser.cpp
===
--- llvm/lib/Support/X86TargetParser.cpp
+++ llvm/lib/Support/X86TargetParser.cpp
@@ -204,7 +204,8 @@
 FeaturesICLServer | FeatureAMX_TILE | FeatureAMX_INT8 | FeatureAMX_BF16 |
 FeatureAVX512BF16 | FeatureAVX512VP2INTERSECT | FeatureCLDEMOTE |
 FeatureENQCMD | FeatureMOVDIR64B | FeatureMOVDIRI | FeaturePTWRITE |
-FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureWAITPKG;
+FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureWAITPKG |
+FeatureHRESET;
 
 // Intel Atom processors.
 // Bonnell has feature parity with Core2 and adds MOVBE.
Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -1664,6 +1664,7 @@
 // CHECK_SPR_M32: #define __F16C__ 1
 // CHECK_SPR_M32: #define __FMA__ 1
 // CHECK_SPR_M32: #define __GFNI__ 1
+// CHECK_SPR_M32: #define __HRESET__ 1
 // CHECK_SPR_M32: #define __INVPCID__ 1
 // CHECK_SPR_M32: #define __LZCNT__ 1
 // CHECK_SPR_M32: #define __MMX__ 1
@@ -1733,6 +1734,7 @@
 // CHECK_SPR_M64: #define __F16C__ 1
 // CHECK_SPR_M64: #define __FMA__ 1
 // CHECK_SPR_M64: #define __GFNI__ 

[PATCH] D89184: Support complex target features combinations

2020-10-18 Thread LiuChen via Phabricator via cfe-commits
LiuChen3 added a comment.

ping?


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

https://reviews.llvm.org/D89184

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


[PATCH] D80488: Teach `-fsanitize=fuzzer` to respect `-static` and `-static-libstdc++` when adding C++ standard libraries.

2020-10-18 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added a reviewer: vitalybuka.
chandlerc marked an inline comment as done.
chandlerc added a comment.

Ping (and adding some sanitizer folks)? I'd really love to stop building with 
this local patch




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:754
+  if (OnlyLibstdcxxStatic)
+CmdArgs.push_back("-Bstatic");
   TC.AddCXXStdlibLibArgs(Args, CmdArgs);

MaskRay wrote:
> This is correct. If GNU ld<2.25 compatibility is not needed, `--push-state`, 
> `-Bstatic`, link, `--pop-state`
I'd prefer to keep this as-is because it matches exactly what the toolchain 
does elsewhere. If we want to drop support for older `ld`s, we should update in 
both places.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80488

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


[clang] 094e9f4 - PR47893: Synthesis of a comparison operator from an 'operator<=>'

2020-10-18 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-10-18T14:15:12-07:00
New Revision: 094e9f4779eb9b5c6a49014f2f80b8cbb833572f

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

LOG: PR47893: Synthesis of a comparison operator from an 'operator<=>'
inherits the SFINAEness of its enclosing context.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaCXX/cxx2a-three-way-comparison.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 92a887964401..67ba2b87e40e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -856,6 +856,7 @@ Optional Sema::isSFINAEContext() 
const {
 case CodeSynthesisContext::DefaultTemplateArgumentInstantiation:
 case CodeSynthesisContext::PriorTemplateArgumentSubstitution:
 case CodeSynthesisContext::DefaultTemplateArgumentChecking:
+case CodeSynthesisContext::RewritingOperatorAsSpaceship:
   // A default template argument instantiation and substitution into
   // template parameters with arguments for prior parameters may or may
   // not be a SFINAE context; look further up the stack.
@@ -874,7 +875,6 @@ Optional Sema::isSFINAEContext() 
const {
 case CodeSynthesisContext::DeclaringSpecialMember:
 case CodeSynthesisContext::DeclaringImplicitEqualityComparison:
 case CodeSynthesisContext::DefiningSynthesizedFunction:
-case CodeSynthesisContext::RewritingOperatorAsSpaceship:
 case CodeSynthesisContext::InitializingStructuredBinding:
 case CodeSynthesisContext::MarkingClassDllexported:
   // This happens in a context unrelated to template instantiation, so

diff  --git a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp 
b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
index 29ae95066e27..353360e052bb 100644
--- a/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
+++ b/clang/test/SemaCXX/cxx2a-three-way-comparison.cpp
@@ -31,3 +31,12 @@ struct B {
 };
 
 int  = B().operator<=>(0);
+
+namespace PR47893 {
+  struct A {
+void operator<=>(const A&) const;
+  };
+  template auto f(T a, T b) -> decltype(a < b) = delete;
+  int (...);
+  int  = f(A(), A());
+}



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


[clang] 79cb179 - PR47870: Properly mangle placeholders for deduced class template

2020-10-18 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-10-18T13:57:41-07:00
New Revision: 79cb179b149b20e7e1bbfd45d1b5e5b055f3b067

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

LOG: PR47870: Properly mangle placeholders for deduced class template
specializations that have no deduced type.

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/CodeGenCXX/cxx1z-class-deduction.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index ed8fc13050c2..26fc7f8ec816 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3668,13 +3668,18 @@ void CXXNameMangler::mangleType(const AutoType *T) {
 }
 
 void CXXNameMangler::mangleType(const DeducedTemplateSpecializationType *T) {
-  // FIXME: This is not the right mangling. We also need to include a scope
-  // here in some cases.
-  QualType D = T->getDeducedType();
-  if (D.isNull())
-mangleUnscopedTemplateName(T->getTemplateName(), nullptr);
-  else
-mangleType(D);
+  QualType Deduced = T->getDeducedType();
+  if (!Deduced.isNull())
+mangleType(Deduced);
+  else if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl())
+mangleName(GlobalDecl(TD));
+  else {
+// For an unresolved template-name, mangle it as if it were a template
+// specialization but leave off the template arguments.
+Out << 'N';
+mangleTemplatePrefix(T->getTemplateName());
+Out << 'E';
+  }
 }
 
 void CXXNameMangler::mangleType(const AtomicType *T) {

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index fc3ff1412219..485cb85f517f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9761,7 +9761,7 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 
   auto TemplateName = DeducedTST->getTemplateName();
   if (TemplateName.isDependent())
-return Context.DependentTy;
+return SubstAutoType(TSInfo->getType(), Context.DependentTy);
 
   // We can only perform deduction for class templates.
   auto *Template =
@@ -9780,7 +9780,7 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
 Diag(TSInfo->getTypeLoc().getBeginLoc(),
  diag::warn_cxx14_compat_class_template_argument_deduction)
 << TSInfo->getTypeLoc().getSourceRange() << 0;
-return Context.DependentTy;
+return SubstAutoType(TSInfo->getType(), Context.DependentTy);
   }
 
   // FIXME: Perform "exact type" matching first, per CWG discussion?

diff  --git a/clang/test/CodeGenCXX/cxx1z-class-deduction.cpp 
b/clang/test/CodeGenCXX/cxx1z-class-deduction.cpp
index 0761f2129b51..8edab748338e 100644
--- a/clang/test/CodeGenCXX/cxx1z-class-deduction.cpp
+++ b/clang/test/CodeGenCXX/cxx1z-class-deduction.cpp
@@ -19,3 +19,24 @@ void f(int *p) {
   // CHECK: @_ZN1AIxEC
   A c = 123LL;
 }
+
+namespace N {
+  template struct B { B(T); };
+}
+using N::B;
+
+struct X {
+  template struct C { C(T); };
+};
+
+// CHECK: @_Z1gIiEDaT_DTcv1AfL0p_E1AIS0_E(
+template auto g(T x, decltype(A(x)), A) {}
+// CHECK: @_Z1hIiEDaT_DTcvN1N1BEfL0p_ENS1_1BIS0_EE(
+template auto h(T x, decltype(B(x)), B) {}
+// CHECK: @_Z1iI1XiEDaT0_DTcvNT_1CEfL0p_ENS2_1CIS1_EE(
+template auto i(T x, decltype(typename U::C(x)), 
typename U::template C) {}
+void test() {
+  g(1, 2, A(3));
+  h(1, 2, B(3));
+  i(1, 2, X::C(3));
+}



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


[PATCH] D89649: Fix __has_unique_object_representations with no_unique_address

2020-10-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

This looks fine as far as it goes, but it doesn't fix all cases of incorrect 
behavior of `__has_unique_object_representations` due to 
`[[no_unique_address]]`. Feel free to either to land this as-is and leave the 
other case to a separate patch, or fix it as a revision of this same change. I 
would expect we'll want to unify the code paths for base classes and non-static 
data members, which might be better done all at once.




Comment at: clang/lib/AST/ASTContext.cpp:2580-2581
   if (!isStructEmpty(Base.getType())) {
 llvm::Optional Size = structHasUniqueObjectRepresentations(
 Context, Base.getType()->castAs()->getDecl());
 if (!Size)

We need to do this for non-empty `[[no_unique_address]]` members of class type 
too, to handle tail padding reuse in cases such as:

```
struct A {
~A();
int a;
char b;
};
struct B {
[[no_unique_address]] A a;
char c[3];
};
static_assert(sizeof(B) == 8, "");
static_assert(__has_unique_object_representations(B), "");
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89649

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


[PATCH] D88227: [clang-format] Add a SpaceAroundPointerQualifiers style option

2020-10-18 Thread Alexander Richardson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9e27f38354e8: [clang-format] Add a 
SpaceAroundPointerQualifiers style option (authored by arichardson).

Changed prior to commit:
  https://reviews.llvm.org/D88227?vs=296689=298887#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88227

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12104,6 +12104,80 @@
NoSpaceStyle);
 }
 
+TEST_F(FormatTest, ConfigurableSpaceAroundPointerQualifiers) {
+  FormatStyle Style = getLLVMStyle();
+
+  Style.PointerAlignment = FormatStyle::PAS_Left;
+  Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
+  verifyFormat("void* const* x = NULL;", Style);
+
+#define verifyQualifierSpaces(Code, Pointers, Qualifiers)  \
+  do { \
+Style.PointerAlignment = FormatStyle::Pointers;\
+Style.SpaceAroundPointerQualifiers = FormatStyle::Qualifiers;  \
+verifyFormat(Code, Style); \
+  } while (false)
+
+  verifyQualifierSpaces("void* const* x = NULL;", PAS_Left, SAPQ_Default);
+  verifyQualifierSpaces("void *const *x = NULL;", PAS_Right, SAPQ_Default);
+  verifyQualifierSpaces("void * const * x = NULL;", PAS_Middle, SAPQ_Default);
+
+  verifyQualifierSpaces("void* const* x = NULL;", PAS_Left, SAPQ_Before);
+  verifyQualifierSpaces("void * const *x = NULL;", PAS_Right, SAPQ_Before);
+  verifyQualifierSpaces("void * const * x = NULL;", PAS_Middle, SAPQ_Before);
+
+  verifyQualifierSpaces("void* const * x = NULL;", PAS_Left, SAPQ_After);
+  verifyQualifierSpaces("void *const *x = NULL;", PAS_Right, SAPQ_After);
+  verifyQualifierSpaces("void * const * x = NULL;", PAS_Middle, SAPQ_After);
+
+  verifyQualifierSpaces("void* const * x = NULL;", PAS_Left, SAPQ_Both);
+  verifyQualifierSpaces("void * const *x = NULL;", PAS_Right, SAPQ_Both);
+  verifyQualifierSpaces("void * const * x = NULL;", PAS_Middle, SAPQ_Both);
+
+#undef verifyQualifierSpaces
+
+  FormatStyle Spaces = getLLVMStyle();
+  Spaces.AttributeMacros.push_back("qualified");
+  Spaces.PointerAlignment = FormatStyle::PAS_Right;
+  Spaces.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
+  verifyFormat("SomeType *volatile *a = NULL;", Spaces);
+  verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  Spaces.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Before;
+  verifyFormat("SomeType * volatile *a = NULL;", Spaces);
+  verifyFormat("SomeType * __attribute__((attr)) *a = NULL;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+
+  // Check that SAPQ_Before doesn't result in extra spaces for PAS_Left.
+  Spaces.PointerAlignment = FormatStyle::PAS_Left;
+  Spaces.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Before;
+  verifyFormat("SomeType* volatile* a = NULL;", Spaces);
+  verifyFormat("SomeType* __attribute__((attr))* a = NULL;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  // However, setting it to SAPQ_After should add spaces after __attribute, etc.
+  Spaces.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_After;
+  verifyFormat("SomeType* volatile * a = NULL;", Spaces);
+  verifyFormat("SomeType* __attribute__((attr)) * a = NULL;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+
+  // PAS_Middle should not have any noticeable changes even for SAPQ_Both
+  Spaces.PointerAlignment = FormatStyle::PAS_Middle;
+  Spaces.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_After;
+  verifyFormat("SomeType * volatile * a = NULL;", Spaces);
+  verifyFormat("SomeType * __attribute__((attr)) * a = NULL;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+  verifyFormat("std::vector x;", Spaces);
+}
+
 TEST_F(FormatTest, AlignConsecutiveMacros) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignConsecutiveAssignments = true;
@@ -14194,6 +14268,16 @@
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: true",
   AllowShortFunctionsOnASingleLine, FormatStyle::SFS_All);
 

[clang] 9e27f38 - [clang-format] Add a SpaceAroundPointerQualifiers style option

2020-10-18 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2020-10-18T18:17:50+01:00
New Revision: 9e27f38354e850346f5f4e895e44ad3346546d9c

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

LOG: [clang-format] Add a SpaceAroundPointerQualifiers style option

Some projects (e.g. FreeBSD) align pointers to the right but expect a
space between the '*' and any pointer qualifiers such as const. To handle
these cases this patch adds a new config option SpaceAroundPointerQualifiers
that can be used to configure whether spaces need to be added before/after
pointer qualifiers.

PointerAlignment = Right
SpaceAroundPointerQualifiers = Default/After:
void *const *x = NULL;
SpaceAroundPointerQualifiers = Before/Both
void * const *x = NULL;

PointerAlignment = Left
SpaceAroundPointerQualifiers = Default/Before:
void* const* x = NULL;
SpaceAroundPointerQualifiers = After/Both
void* const * x = NULL;

PointerAlignment = Middle
SpaceAroundPointerQualifiers = Default/Before/After/Both:
void * const * x = NULL;

Reviewed By: MyDeveloperDay

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0c3ed9f4ab84..ccc59cd6fc19 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2463,6 +2463,46 @@ the configuration (without a prefix: ``Auto``).
  true:  false:
  template  void foo(); vs. template void foo();
 
+**SpaceAroundPointerQualifiers** (``SpaceAroundPointerQualifiersStyle``)
+  Defines in which cases to put a space before or after pointer qualifiers
+
+  Possible values:
+
+  * ``SAPQ_Default`` (in configuration: ``Default``)
+Don't ensure spaces around pointer qualifiers and use PointerAlignment
+instead.
+
+.. code-block:: c++
+
+   PointerAlignment: Left PointerAlignment: Right
+   void* const* x = NULL; vs. void *const *x = NULL;
+
+  * ``SAPQ_Before`` (in configuration: ``Before``)
+Ensure that there is a space before pointer qualifiers.
+
+.. code-block:: c++
+
+   PointerAlignment: Left PointerAlignment: Right
+   void* const* x = NULL; vs. void * const *x = NULL;
+
+  * ``SAPQ_After`` (in configuration: ``After``)
+Ensure that there is a space after pointer qualifiers.
+
+.. code-block:: c++
+
+   PointerAlignment: Left PointerAlignment: Right
+   void* const * x = NULL; vs. void *const *x = NULL;
+
+  * ``SAPQ_Both`` (in configuration: ``Both``)
+Ensure that there is a space both before and after pointer qualifiers.
+
+.. code-block:: c++
+
+   PointerAlignment: Left PointerAlignment: Right
+   void* const * x = NULL; vs. void * const *x = NULL;
+
+
+
 **SpaceBeforeAssignmentOperators** (``bool``)
   If ``false``, spaces will be removed before assignment operators.
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 40d5184f4d0d..587e588525df 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2078,6 +2078,38 @@ struct FormatStyle {
   /// \endcode
   bool SpaceAfterTemplateKeyword;
 
+  /// Different ways to put a space before opening parentheses.
+  enum SpaceAroundPointerQualifiersStyle {
+/// Don't ensure spaces around pointer qualifiers and use PointerAlignment
+/// instead.
+/// \code
+///PointerAlignment: Left PointerAlignment: Right
+///void* const* x = NULL; vs. void *const *x = NULL;
+/// \endcode
+SAPQ_Default,
+/// Ensure that there is a space before pointer qualifiers.
+/// \code
+///PointerAlignment: Left PointerAlignment: Right
+///void* const* x = NULL; vs. void * const *x = NULL;
+/// \endcode
+SAPQ_Before,
+/// Ensure that there is a space after pointer qualifiers.
+/// \code
+///PointerAlignment: Left PointerAlignment: Right
+///void* const * x = NULL; vs. void *const *x = NULL;
+/// \endcode
+SAPQ_After,
+/// Ensure that there is a space both before and after pointer qualifiers.
+/// \code
+///PointerAlignment: Left PointerAlignment: Right
+///void* const * x = NULL; vs. void * const *x = NULL;
+/// \endcode
+SAPQ_Both,
+  };
+
+  ///  Defines in which cases to put a 

[PATCH] D89651: [clang-tidy] Add bugprone-suspicious-memory-comparison check

2020-10-18 Thread Gabor Bencze via Phabricator via cfe-commits
gbencze created this revision.
gbencze added reviewers: aaron.ballman, JonasToth, Charusso.
gbencze added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun, mgorny.
Herald added a project: clang.
gbencze requested review of this revision.

The check warns on suspicious calls to memcmp.
It currently checks for comparing types that do not have unique object 
representations or are non-standard-layout.
Based on
https://wiki.sei.cmu.edu/confluence/display/c/EXP42-C.+Do+not+compare+padding+data
https://wiki.sei.cmu.edu/confluence/display/c/FLP37-C.+Do+not+use+object+representations+to+compare+floating-point+values
and part of
https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions
Add alias cert-exp42-c and cert-flp37-c.

Some tests are currently failing at head, the check depends on D89649 
.
Originally started in D71973 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89651

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousMemoryComparisonCheck.h
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-suspicious-memory-comparison.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-exp42-c.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-flp37-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison-32bits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.c
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-suspicious-memory-comparison.cpp
@@ -0,0 +1,230 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-memory-comparison %t \
+// RUN: -- -- -target x86_64-unknown-unknown
+
+namespace std {
+typedef __SIZE_TYPE__ size_t;
+int memcmp(const void *lhs, const void *rhs, size_t count);
+} // namespace std
+
+namespace sei_cert_example_oop57_cpp {
+class C {
+  int i;
+
+public:
+  virtual void f();
+};
+
+void f(C , C ) {
+  if (!std::memcmp(, , sizeof(C))) {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: comparing object representation
+// of non-standard-layout type 'sei_cert_example_oop57_cpp::C'; consider
+// using a comparison operator instead
+  }
+}
+} // namespace sei_cert_example_oop57_cpp
+
+namespace inner_padding_64bit_only {
+struct S {
+  int x;
+  int *y;
+};
+
+void test() {
+  S a, b;
+  std::memcmp(, , sizeof(S));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of
+  // type 'inner_padding_64bit_only::S' which does not have unique object
+  // representations; consider comparing the values manually
+}
+} // namespace inner_padding_64bit_only
+
+namespace padding_in_base {
+class Base {
+  char c;
+  int i;
+};
+
+class Derived : public Base {};
+
+class Derived2 : public Derived {};
+
+void testDerived() {
+  Derived a, b;
+  std::memcmp(, , sizeof(Base));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of
+  // type 'padding_in_base::Derived' which does not have unique object
+  // representations; consider comparing the values manually
+  std::memcmp(, , sizeof(Derived));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of
+  // type 'padding_in_base::Derived' which does not have unique object
+  // representations; consider comparing the values manually
+}
+
+void testDerived2() {
+  Derived2 a, b;
+  std::memcmp(, , sizeof(Base));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of
+  // type 'padding_in_base::Derived2' which does not have unique object
+  // representations; consider comparing the values manually
+  std::memcmp(, , sizeof(Derived2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: comparing object representation of
+  // type 'padding_in_base::Derived2' which does not have unique object
+  // representations; consider comparing the values manually
+}
+
+} // namespace padding_in_base
+
+namespace no_padding_in_base {
+class Base {
+  int a, b;
+};
+
+class Derived : public Base {};
+
+class Derived2 : public Derived {};
+
+void testDerived() {
+  Derived a, b;
+  std::memcmp(, , sizeof(Base));
+  std::memcmp(, , sizeof(Derived));
+}
+
+void testDerived2() {
+  Derived2 a, b;
+  std::memcmp(, , sizeof(char));
+  std::memcmp(, , sizeof(Base));
+  std::memcmp(, , 

[PATCH] D89649: Fix __has_unique_object_representations with no_unique_address

2020-10-18 Thread Gabor Bencze via Phabricator via cfe-commits
gbencze created this revision.
gbencze added reviewers: rsmith, aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
gbencze requested review of this revision.

Fix incorrect behavior of __has_unique_object_representations when using the 
no_unique_address attribute.

Based on the bug report: https://bugs.llvm.org/show_bug.cgi?id=47722 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89649

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp


Index: clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify 
-std=c++2a %s
+//  expected-no-diagnostics
+
+struct Empty {};
+
+struct A {
+  [[no_unique_address]] Empty e;
+  char x;
+};
+
+static_assert(__has_unique_object_representations(A));
+
+struct B {
+  char x;
+  [[no_unique_address]] Empty e;
+};
+
+static_assert(__has_unique_object_representations(B));
+
+struct C {
+  char x;
+  [[no_unique_address]] Empty e1;
+  [[no_unique_address]] Empty e2;
+};
+
+static_assert(!__has_unique_object_representations(C));
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2602,9 +2602,12 @@
   }
 
   for (const auto *Field : RD->fields()) {
-if (!Field->getType()->isReferenceType() &&
-!Context.hasUniqueObjectRepresentations(Field->getType()))
-  return llvm::None;
+if (!Field->getType()->isReferenceType()) {
+  if (Field->isZeroSize(Context))
+continue;
+  else if (!Context.hasUniqueObjectRepresentations(Field->getType()))
+return llvm::None;
+}
 
 int64_t FieldSizeInBits =
 Context.toBits(Context.getTypeSizeInChars(Field->getType()));


Index: clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/has_unique_object_reps_no_unique_addr.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify -std=c++2a %s
+//  expected-no-diagnostics
+
+struct Empty {};
+
+struct A {
+  [[no_unique_address]] Empty e;
+  char x;
+};
+
+static_assert(__has_unique_object_representations(A));
+
+struct B {
+  char x;
+  [[no_unique_address]] Empty e;
+};
+
+static_assert(__has_unique_object_representations(B));
+
+struct C {
+  char x;
+  [[no_unique_address]] Empty e1;
+  [[no_unique_address]] Empty e2;
+};
+
+static_assert(!__has_unique_object_representations(C));
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2602,9 +2602,12 @@
   }
 
   for (const auto *Field : RD->fields()) {
-if (!Field->getType()->isReferenceType() &&
-!Context.hasUniqueObjectRepresentations(Field->getType()))
-  return llvm::None;
+if (!Field->getType()->isReferenceType()) {
+  if (Field->isZeroSize(Context))
+continue;
+  else if (!Context.hasUniqueObjectRepresentations(Field->getType()))
+return llvm::None;
+}
 
 int64_t FieldSizeInBits =
 Context.toBits(Context.getTypeSizeInChars(Field->getType()));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 389c8d5 - [NFC] Make non-modifying members const.

2020-10-18 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2020-10-18T18:50:21+02:00
New Revision: 389c8d5b20a2ddea84d3b24edd533d5283f96582

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

LOG: [NFC] Make non-modifying members const.

Implementing the likelihood attributes for the iteration statements adds
a new helper function. This function can't be const qualified since
these non-modifying members aren't const qualified.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/CodeGen/CodeGenPGO.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 0a199e9b86ec..441e2c90c02e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -1401,10 +1401,11 @@ class CodeGenFunction : public CodeGenTypeCache {
   CodeGenPGO PGO;
 
   /// Calculate branch weights appropriate for PGO data
-  llvm::MDNode *createProfileWeights(uint64_t TrueCount, uint64_t FalseCount);
-  llvm::MDNode *createProfileWeights(ArrayRef Weights);
+  llvm::MDNode *createProfileWeights(uint64_t TrueCount,
+ uint64_t FalseCount) const;
+  llvm::MDNode *createProfileWeights(ArrayRef Weights) const;
   llvm::MDNode *createProfileWeightsForLoop(const Stmt *Cond,
-uint64_t LoopCount);
+uint64_t LoopCount) const;
 
 public:
   /// Increment the profiler's counter for the given statement by \p StepV.

diff  --git a/clang/lib/CodeGen/CodeGenPGO.cpp 
b/clang/lib/CodeGen/CodeGenPGO.cpp
index be3c50b99f30..c11d99a348d1 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1038,7 +1038,7 @@ static uint32_t scaleBranchWeight(uint64_t Weight, 
uint64_t Scale) {
 }
 
 llvm::MDNode *CodeGenFunction::createProfileWeights(uint64_t TrueCount,
-uint64_t FalseCount) {
+uint64_t FalseCount) const 
{
   // Check for empty weights.
   if (!TrueCount && !FalseCount)
 return nullptr;
@@ -1052,7 +1052,7 @@ llvm::MDNode 
*CodeGenFunction::createProfileWeights(uint64_t TrueCount,
 }
 
 llvm::MDNode *
-CodeGenFunction::createProfileWeights(ArrayRef Weights) {
+CodeGenFunction::createProfileWeights(ArrayRef Weights) const {
   // We need at least two elements to create meaningful weights.
   if (Weights.size() < 2)
 return nullptr;
@@ -1074,8 +1074,9 @@ CodeGenFunction::createProfileWeights(ArrayRef 
Weights) {
   return MDHelper.createBranchWeights(ScaledWeights);
 }
 
-llvm::MDNode *CodeGenFunction::createProfileWeightsForLoop(const Stmt *Cond,
-   uint64_t LoopCount) 
{
+llvm::MDNode *
+CodeGenFunction::createProfileWeightsForLoop(const Stmt *Cond,
+ uint64_t LoopCount) const {
   if (!PGO.haveRegionCounts())
 return nullptr;
   Optional CondCount = PGO.getStmtCount(Cond);

diff  --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h
index dda8c66b6db2..906c5e406d77 100644
--- a/clang/lib/CodeGen/CodeGenPGO.h
+++ b/clang/lib/CodeGen/CodeGenPGO.h
@@ -59,7 +59,7 @@ class CodeGenPGO {
 
   /// Check if an execution count is known for a given statement. If so, return
   /// true and put the value in Count; else return false.
-  Optional getStmtCount(const Stmt *S) {
+  Optional getStmtCount(const Stmt *S) const {
 if (!StmtCountMap)
   return None;
 auto I = StmtCountMap->find(S);



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


[PATCH] D89443: [PowerPC][AIX] Make `__vector [un]signed long` an error

2020-10-18 Thread Hubert Tong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
hubert.reinterpretcast marked an inline comment as done.
Closed by commit rG126094485ab9: [PowerPC][AIX] Make `__vector [un]signed long` 
an error (authored by hubert.reinterpretcast).

Changed prior to commit:
  https://reviews.llvm.org/D89443?vs=298287=298878#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89443

Files:
  clang/lib/Sema/DeclSpec.cpp
  clang/test/Parser/altivec.c
  clang/test/Parser/cxx-altivec.cpp

Index: clang/test/Parser/cxx-altivec.cpp
===
--- clang/test/Parser/cxx-altivec.cpp
+++ clang/test/Parser/cxx-altivec.cpp
@@ -1,6 +1,8 @@
-// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
-// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
 #include 
 
 __vector char vv_c;
@@ -55,19 +57,33 @@
 
 vector int v = (vector int)(-1);
 
+// These should have errors on AIX and warnings otherwise.
+__vector long vv_l; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector signed long vv_sl; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector unsigned long vv_ul;   // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector long int vv_li;// nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector signed long int vv_sli;// nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+__vector unsigned long int vv_uli;  // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector long v_l;// nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector signed long v_sl;// nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector unsigned long v_ul;  // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector long int v_li;   // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector signed long int v_sli;   // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+vector unsigned long int v_uli; // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with '__vector'}}
+
 // These should have warnings.
-__vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
-__vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
-__vector unsigned long vv_ul;   // expected-warning {{Use of 'long' with '__vector' is deprecated}}
-__vector long int vv_li;// expected-warning {{Use of 'long' with '__vector' is deprecated}}
-__vector signed long int vv_sli;// expected-warning {{Use of 'long' with '__vector' is deprecated}}
-__vector unsigned long int vv_uli;  // expected-warning {{Use of 'long' with '__vector' is deprecated}}
-vector long v_l;// expected-warning {{Use of 'long' with '__vector' 

[clang] 1260944 - [PowerPC][AIX] Make `__vector [un]signed long` an error

2020-10-18 Thread Hubert Tong via cfe-commits

Author: Hubert Tong
Date: 2020-10-18T12:39:16-04:00
New Revision: 126094485ab99dac3e6df9c201124d48a1d798ce

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

LOG: [PowerPC][AIX] Make `__vector [un]signed long` an error

The semantics associated with `__vector [un]signed long` are neither
consistently specified nor consistently implemented.

The IBM XL compilers on AIX traditionally treated these as deprecated
aliases for the corresponding `__vector int` type in both 32-bit and
64-bit modes. The newer, Clang-based, IBM XL compilers on AIX make usage
of the previously deprecated types an error. This is also consistent
with IBM XL C/C++ for Linux on Power (on little endian distributions).

In line with the above, this patch upgrades (on AIX) the deprecation of
`__vector long` to become removal.

Reviewed By: ZarkoCA

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

Added: 


Modified: 
clang/lib/Sema/DeclSpec.cpp
clang/test/Parser/altivec.c
clang/test/Parser/cxx-altivec.cpp

Removed: 




diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index a3f770bb00ad..dc37474db9fd 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1196,7 +1196,13 @@ void DeclSpec::Finish(Sema , const PrintingPolicy 
) {
 S.Diag(TSTLoc, diag::err_invalid_vector_float_decl_spec);
 } else if (TypeSpecWidth == TSW_long) {
   // vector long is unsupported for ZVector and deprecated for AltiVec.
-  if (S.getLangOpts().ZVector)
+  // It has also been historically deprecated on AIX (as an alias for
+  // "vector int" in both 32-bit and 64-bit modes). It was then made
+  // unsupported in the Clang-based XL compiler since the deprecated type
+  // has a number of conflicting semantics and continuing to support it
+  // is a disservice to users.
+  if (S.getLangOpts().ZVector ||
+  S.Context.getTargetInfo().getTriple().isOSAIX())
 S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_decl_spec);
   else
 S.Diag(TSWRange.getBegin(),

diff  --git a/clang/test/Parser/altivec.c b/clang/test/Parser/altivec.c
index 769b4dec98fc..e966679be54a 100644
--- a/clang/test/Parser/altivec.c
+++ b/clang/test/Parser/altivec.c
@@ -1,6 +1,8 @@
-// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec 
-fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature 
+altivec -fsyntax-only -verify %s
-// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature 
+altivec -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec 
-fsyntax-only -verify=expected,nonaix %s
+// RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature 
+altivec -fsyntax-only -verify=expected,nonaix %s
+// RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature 
+altivec -fsyntax-only -verify=expected,nonaix %s
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec 
-fsyntax-only -verify=expected,aix %s
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec 
-fsyntax-only -verify=expected,aix %s
 
 __vector char vv_c;
 __vector signed char vv_sc;
@@ -54,19 +56,33 @@ void f_a2(int b, vector int a);
 
 vector int v = (vector int)(-1);
 
+// These should have errors on AIX and warnings otherwise.
+__vector long vv_l; // nonaix-warning {{Use of 'long' with 
'__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with 
'__vector'}}
+__vector signed long vv_sl; // nonaix-warning {{Use of 'long' with 
'__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with 
'__vector'}}
+__vector unsigned long vv_ul;   // nonaix-warning {{Use of 'long' with 
'__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with 
'__vector'}}
+__vector long int vv_li;// nonaix-warning {{Use of 'long' with 
'__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with 
'__vector'}}
+__vector signed long int vv_sli;// nonaix-warning {{Use of 'long' with 
'__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with 
'__vector'}}
+__vector unsigned long int vv_uli;  // nonaix-warning {{Use of 'long' with 
'__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with 
'__vector'}}
+vector long v_l;// nonaix-warning {{Use of 'long' with 
'__vector' is deprecated}}
+// aix-error@-1 {{cannot use 'long' with 
'__vector'}}
+vector signed long v_sl; 

[clang-tools-extra] ce619f6 - [NFC][clang-tidy] Use isInStdNamespace matcher instead of check defined alternatives

2020-10-18 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-10-18T16:02:11+01:00
New Revision: ce619f645f58154fcc1d88e9de81aa7903dd7bc0

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

LOG: [NFC][clang-tidy] Use isInStdNamespace matcher instead of check defined 
alternatives

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
index 02c9e74c7bb0..2b072172792d 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
@@ -35,40 +35,6 @@ static const char AutoPtrOwnershipTransferId[] = 
"AutoPtrOwnershipTransferId";
 /// \endcode
 AST_MATCHER(Expr, isLValue) { return Node.getValueKind() == VK_LValue; }
 
-/// Matches declarations whose declaration context is the C++ standard library
-/// namespace std.
-///
-/// Note that inline namespaces are silently ignored during the lookup since
-/// both libstdc++ and libc++ are known to use them for versioning purposes.
-///
-/// Given:
-/// \code
-///   namespace ns {
-/// struct my_type {};
-/// using namespace std;
-///   }
-///
-///   using std::vector;
-///   using ns:my_type;
-///   using ns::list;
-/// \code
-///
-/// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(isFromStdNamespace(
-/// matches "using std::vector" and "using ns::list".
-AST_MATCHER(Decl, isFromStdNamespace) {
-  const DeclContext *D = Node.getDeclContext();
-
-  while (D->isInlineNamespace())
-D = D->getParent();
-
-  if (!D->isNamespace() || !D->getParent()->isTranslationUnit())
-return false;
-
-  const IdentifierInfo *Info = cast(D)->getIdentifier();
-
-  return (Info && Info->isStr("std"));
-}
-
 } // namespace
 
 ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name,
@@ -82,7 +48,7 @@ void 
ReplaceAutoPtrCheck::storeOptions(ClangTidyOptions::OptionMap ) {
 }
 
 void ReplaceAutoPtrCheck::registerMatchers(MatchFinder *Finder) {
-  auto AutoPtrDecl = recordDecl(hasName("auto_ptr"), isFromStdNamespace());
+  auto AutoPtrDecl = recordDecl(hasName("auto_ptr"), isInStdNamespace());
   auto AutoPtrType = qualType(hasDeclaration(AutoPtrDecl));
 
   //   std::auto_ptr a;
@@ -103,7 +69,7 @@ void ReplaceAutoPtrCheck::registerMatchers(MatchFinder 
*Finder) {
   //   using std::auto_ptr;
   //   ^~~
   Finder->addMatcher(usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(namedDecl(
-   hasName("auto_ptr"), 
isFromStdNamespace()
+   hasName("auto_ptr"), isInStdNamespace()
  .bind(AutoPtrTokenId),
  this);
 

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index 44ae380b63b2..f15b734c55d6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -155,40 +155,6 @@ Matcher hasStdContainerName() {
   return hasAnyName(ContainerNames);
 }
 
-/// Matches declarations whose declaration context is the C++ standard library
-/// namespace std.
-///
-/// Note that inline namespaces are silently ignored during the lookup since
-/// both libstdc++ and libc++ are known to use them for versioning purposes.
-///
-/// Given:
-/// \code
-///   namespace ns {
-/// struct my_type {};
-/// using namespace std;
-///   }
-///
-///   using std::vector;
-///   using ns:my_type;
-///   using ns::list;
-/// \code
-///
-/// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(isFromStdNamespace(
-/// matches "using std::vector" and "using ns::list".
-AST_MATCHER(Decl, isFromStdNamespace) {
-  const DeclContext *D = Node.getDeclContext();
-
-  while (D->isInlineNamespace())
-D = D->getParent();
-
-  if (!D->isNamespace() || !D->getParent()->isTranslationUnit())
-return false;
-
-  const IdentifierInfo *Info = cast(D)->getIdentifier();
-
-  return (Info && Info->isStr("std"));
-}
-
 /// Matches declaration reference or member expressions with explicit template
 /// arguments.
 AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
@@ -202,7 +168,7 @@ AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
 DeclarationMatcher standardIterator() {
   return decl(
   namedDecl(hasStdIteratorName()),
-  hasDeclContext(recordDecl(hasStdContainerName(), isFromStdNamespace(;
+  hasDeclContext(recordDecl(hasStdContainerName(), isInStdNamespace(;
 }
 
 /// Returns a TypeMatcher that matches typedefs for standard iterators
@@ -226,7 +192,7 @@ TypeMatcher iteratorFromUsingDeclaration() {

[clang-tools-extra] 5f88c3b - [clang tidy] Fix SIMDIntrinsicsCheck not storing options

2020-10-18 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-10-18T15:56:39+01:00
New Revision: 5f88c3b6392f54ee0d31f560b1897b8fbc828ee7

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

LOG: [clang tidy] Fix SIMDIntrinsicsCheck not storing options

Added: 


Modified: 
clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp 
b/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
index db9cc8c5a08c..9391670df622 100644
--- a/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
@@ -82,8 +82,8 @@ SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef Name,
   Suggest(Options.get("Suggest", false)) {}
 
 void SIMDIntrinsicsCheck::storeOptions(ClangTidyOptions::OptionMap ) {
-  Options.store(Opts, "Std", "");
-  Options.store(Opts, "Suggest", 0);
+  Options.store(Opts, "Std", Std);
+  Options.store(Opts, "Suggest", Suggest);
 }
 
 void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) {



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


[PATCH] D86559: [Sema, CodeGen] Allow [[likely]] and [[unlikely]] on labels

2020-10-18 Thread Mark de Wever via Phabricator via cfe-commits
Mordante planned changes to this revision.
Mordante added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6454
 
+static bool validateLikelihoodAttr(Sema , Decl *D, const ParsedAttr ) {
+  if (!isa(D)) {

aaron.ballman wrote:
> Mordante wrote:
> > aaron.ballman wrote:
> > > This is entering into somewhat novel territory for attributes, so some of 
> > > this feedback is me thinking out loud.
> > > 
> > > Attr.td lists these two attributes as being a `StmtAttr` and not any kind 
> > > of declaration attribute. We have `DeclOrTypeAttr` for attributes that 
> > > can be applied to declarations or types, but we do not have something 
> > > similar for statement attributes yet. We do have some custom semantic 
> > > handling logic in SemaDeclAttr.cpp for statement attributes, but you 
> > > avoid hitting that code path by adding a `case` for the two likelihood 
> > > attributes. These attributes only apply to label declarations currently, 
> > > and labels cannot be redeclared, so there aren't yet questions about 
> > > whether this is inheritable or not. So we *might* be okay with this, but 
> > > I'm not 100% certain. For instance, I don't recall if the pretty printer 
> > > or AST dumpers will need to distinguish between whether this attribute is 
> > > written on the statement or the declaration (which is itself a bit of an 
> > > interesting question: should the attribute attach only to the statement 
> > > rather than trying to attach to the underlying decl? 
> > > http://eel.is/c++draft/stmt.stmt#stmt.label-1.sentence-2 is ambiguous, 
> > > but I don't think of `case` or `default` labels as being declarations so 
> > > I tend to not think of identifier labels as such either.). There's a part 
> > > of me that wonders if we have a different issue where the attribute is 
> > > trying to attach to the declaration rather than the statement and that 
> > > this should be handled purely as a statement attribute.
> > > 
> > > I'm curious what your thoughts are, but I'd also like to see some 
> > > additional tests for the random other bits that interact with attributes 
> > > like AST dumping and pretty printing to be sure the behavior is 
> > > reasonable.
> > The labels in a switch are indeed different and the code in trunk already 
> > should allow the attribute there. (I'm still busy with the CodeGen patch.)
> > I agree that Standard isn't clear whether the attribute is attached to the 
> > statement or the declaration.
> > 
> > The `LabelDecl` expects a pointer to a `LabelStmt` and not to an 
> > `AttributedStmt`. Since declarations can already have attributes I used 
> > that feature. I just checked and the `LabelDecl` isn't shown in the AST and 
> > so the attributes also aren't shown. I can adjust that.
> > 
> > Another option would be to change the `LabelDecl` and have two overloads of 
> > `setStmt`
> > `void setStmt(LabelStmt *T) { TheStmt = T; }`
> > `void setStmt(AttributedStmt *T) { TheStmt = T; }`
> > Then `TheStmt` needs to be a `Stmt` and an extra getter would be required 
> > to get the generic statement.
> > 
> > I think both solutions aren't trivial changes. Currently the attribute has 
> > no effect on labels so it not being visible isn't a real issue. However I 
> > feel that's not a proper solution. I expect attributes will be used more in 
> > C and C++ in the future. For example, I can imagine a `[[cold]]` attribute 
> > becoming available for labels.
> > 
> > So I'm leaning towards biting the bullet and change the implementation of 
> > `LabelDecl` to allow an `AttributedStmt` instead of a `LabelStmt`.
> > WDYT?
> > Currently the attribute has no effect on labels so it not being visible 
> > isn't a real issue. 
> 
> That's not entirely true though -- we have pretty printing capabilities that 
> will lose the attribute when written on a label, so round-tripping through 
> the pretty printer will fail. But we have quite a few issues with pretty 
> printing attributes as it stands, so I'm not super concerned either.
> 
> > So I'm leaning towards biting the bullet and change the implementation of 
> > LabelDecl to allow an AttributedStmt instead of a LabelStmt.
> > WDYT?
> 
> I'm curious if @rsmith feels the same way, but I think something along those 
> lines makes sense (if not an overload, perhaps a templated function with 
> SFINAE). We'd have to make sure that the attributed statement eventually 
> resolves to a `LabelStmt` once we strip the attributes away, but this would 
> keep the attribute at the statement level rather than making it a declaration 
> one, which I think is more along the lines of what's intended for the 
> likelihood attributes (and probably for hot/cold if we add that support 
> later).
> > Currently the attribute has no effect on labels so it not being visible 
> > isn't a real issue. 
> 
> That's not entirely true though -- we have pretty printing capabilities that 
> will lose the attribute when written on a 

[clang] a2f8407 - [NFC] Fixes a documentation typo.

2020-10-18 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2020-10-18T13:48:48+02:00
New Revision: a2f8407801dcf0c0933f68ab28426928d2ca1fea

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

LOG: [NFC] Fixes a documentation typo.

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index babb7cd05a80..43ca7dd7424f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1902,7 +1902,7 @@ Clang supports the 
``__attribute__((preserve_access_index))``
 attribute for the BPF target. This attribute may be attached to a
 struct or union declaration, where if -g is specified, it enables
 preserving struct or union member access debuginfo indices of this
-struct or union, similar to clang ``__builtin_preserve_acceess_index()``.
+struct or union, similar to clang ``__builtin_preserve_access_index()``.
   }];
 }
 



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


[clang] 2bcda6b - [Sema, CodeGen] Implement [[likely]] and [[unlikely]] in SwitchStmt

2020-10-18 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2020-10-18T13:48:42+02:00
New Revision: 2bcda6bb2896f0f8daf67343edfc64fb226f3e3f

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

LOG: [Sema, CodeGen] Implement [[likely]] and [[unlikely]] in SwitchStmt

This implements the likelihood attribute for the switch statement. Based on the
discussion in D85091 and D86559 it only handles the attribute when placed on
the case labels or the default labels.

It also marks the likelihood attribute as feature complete. There are more QoI
patches in the pipeline.

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

Added: 
clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/AST/Stmt.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/Preprocessor/has_attribute.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0ef03acaa4c..540cf9132605 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,7 +123,9 @@ New Pragmas in Clang
 Attribute Changes in Clang
 --
 
-- ...
+- Added support for the C++20 likelihood attributes ``[[likely]]`` and
+  ``[[unlikely]]``. As an extension they can be used in C++11 and newer.
+  This extension is enabled by default.
 
 Windows Support
 ---

diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 4a6e8182e5a0..c2452f426566 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1177,6 +1177,9 @@ class alignas(void *) Stmt {
   static void EnableStatistics();
   static void PrintStats();
 
+  /// \returns the likelihood of a set of attributes.
+  static Likelihood getLikelihood(ArrayRef Attrs);
+
   /// \returns the likelihood of a statement.
   static Likelihood getLikelihood(const Stmt *S);
 

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 60e7a9d4303b..f58870d76013 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1290,14 +1290,12 @@ def FallThrough : StmtAttr {
 }
 
 def Likely : StmtAttr {
-  // FIXME: Change the date to 201803 once the implementation is finished.
-  let Spellings = [CXX11<"", "likely", 2>, C2x<"clang", "likely">];
+  let Spellings = [CXX11<"", "likely", 201803>, C2x<"clang", "likely">];
   let Documentation = [LikelihoodDocs];
 }
 
 def Unlikely : StmtAttr {
-  // FIXME: Change the date to 201803 once the implementation is finished.
-  let Spellings = [CXX11<"", "unlikely", 2>, C2x<"clang", "unlikely">];
+  let Spellings = [CXX11<"", "unlikely", 201803>, C2x<"clang", "unlikely">];
   let Documentation = [LikelihoodDocs];
 }
 

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index bf190829381c..babb7cd05a80 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1724,13 +1724,23 @@ It isn't allowed to annotate a single statement with 
both ``likely`` and
 statement with the same likelihood attribute will result in a diagnostic and
 the attributes are ignored on both branches.
 
+In a ``switch`` statement it's allowed to annotate multiple ``case`` labels
+or the ``default`` label with the same likelihood attribute. This makes
+* all labels without an attribute have a neutral likelihood,
+* all labels marked ``[[likely]]`` have an equally positive likelihood, and
+* all labels marked ``[[unlikely]]`` have an equally negative likelihood.
+The neutral likelihood is the more likely of path execution than the negative
+likelihood. The positive likelihood is the more likely of path of execution
+than the neutral likelihood.
+
 These attributes have no effect on the generated code when using
 PGO (Profile-Guided Optimization) or at optimization level 0.
 
-In Clang, the attributes will be ignored if they're not placed on the
-substatement of an ``if`` or ``else`` statement. The C++ Standard recommends
-to honor them on every statement in the path of execution, but that can be
-confusing:
+In Clang, the attributes will be ignored if they're not placed on
+* the ``case`` or ``default`` label of a ``switch`` statement,
+* or on the substatement of an ``if`` or ``else`` statement.
+The C++ Standard recommends to honor them on every statement in the
+path of execution, but that can be confusing:
 
 .. code-block:: c++
 
@@ -1759,8 +1769,8 @@ confusing:
   }
 
 
-At the moment the attribute only has effect when used in an ``if`` or ``else``

[PATCH] D89210: [Sema, CodeGen] Implement [[likely]] and [[unlikely]] in SwitchStmt

2020-10-18 Thread Mark de Wever via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Mordante marked 2 inline comments as done.
Closed by commit rG2bcda6bb2896: [Sema, CodeGen] Implement [[likely]] and 
[[unlikely]] in SwitchStmt (authored by Mordante).

Changed prior to commit:
  https://reviews.llvm.org/D89210?vs=298176=298871#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89210

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/Stmt.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
  clang/test/Preprocessor/has_attribute.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -988,7 +988,7 @@
 
   [[likely]] and [[unlikely]] attributes
   https://wg21.link/p0479r5;>P0479R5
-  Clang 12 (partial)
+  Clang 12
 
 
   typename optional in more contexts
Index: clang/test/Preprocessor/has_attribute.cpp
===
--- clang/test/Preprocessor/has_attribute.cpp
+++ clang/test/Preprocessor/has_attribute.cpp
@@ -62,13 +62,13 @@
 // FIXME(201806L) CHECK: ensures: 0
 // FIXME(201806L) CHECK: expects: 0
 // CHECK: fallthrough: 201603L
-// FIXME(201803L) CHECK: likely: 2L
+// CHECK: likely: 201803L
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
 // WINDOWS: no_unique_address: 0
 // CHECK: nodiscard: 201907L
 // CHECK: noreturn: 200809L
-// FIXME(201803L) CHECK: unlikely: 2L
+// CHECK: unlikely: 201803L
 
 // Test for Microsoft __declspec attributes
 
Index: clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/attr-likelihood-switch-branch-weights.cpp
@@ -0,0 +1,194 @@
+// RUN: %clang_cc1 -O1 -disable-llvm-passes -emit-llvm %s -o - -triple=x86_64-linux-gnu | FileCheck %s
+
+extern volatile int i;
+
+void OneCaseL() {
+  // CHECK-LABEL: define{{.*}}OneCaseL
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !6
+  switch (i) {
+[[likely]] case 1: break;
+  }
+}
+
+void OneCaseU() {
+  // CHECK-LABEL: define{{.*}}OneCaseU
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !7
+  switch (i) {
+[[unlikely]] case 1: ++i; break;
+  }
+}
+
+void TwoCasesLN() {
+  // CHECK-LABEL: define{{.*}}TwoCasesLN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !8
+  switch (i) {
+[[likely]] case 1: break;
+case 2: break;
+  }
+}
+
+void TwoCasesUN() {
+  // CHECK-LABEL: define{{.*}}TwoCasesUN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !9
+  switch (i) {
+[[unlikely]] case 1: break;
+case 2: break;
+  }
+}
+
+void TwoCasesLU() {
+  // CHECK-LABEL: define{{.*}}TwoCasesLU
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !10
+  switch (i) {
+[[likely]] case 1: break;
+[[unlikely]] case 2: break;
+  }
+}
+
+void CasesFallthroughNNLN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughNNLN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !11
+  switch (i) {
+case 1:
+case 2:
+[[likely]] case 3:
+case 4: break;
+  }
+}
+
+void CasesFallthroughNNUN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughNNUN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !12
+  switch (i) {
+case 1:
+case 2:
+[[unlikely]] case 3:
+case 4: break;
+  }
+}
+
+void CasesFallthroughRangeSmallLN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughRangeSmallLN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !13
+  switch (i) {
+case 1 ... 5: ++i;
+case 102:
+[[likely]] case 103:
+case 104: break;
+  }
+}
+
+void CasesFallthroughRangeSmallUN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughRangeSmallUN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !14
+  switch (i) {
+case 1 ... 5: ++i;
+case 102:
+[[unlikely]] case 103:
+case 104: break;
+  }
+}
+
+void CasesFallthroughRangeLargeLLN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughRangeLargeLLN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !8
+  // CHECK: caserange
+  // CHECK: br{{.*}} !prof !15
+  switch (i) {
+[[likely]] case 0 ... 64:
+[[likely]] case 1003:
+case 104: break;
+  }
+}
+
+void CasesFallthroughRangeLargeUUN() {
+  // CHECK-LABEL: define{{.*}}CasesFallthroughRangeLargeUUN
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !9
+  // CHECK: caserange
+  // CHECK: br{{.*}} !prof !16
+  switch (i) {
+[[unlikely]] case 0 ... 64:
+[[unlikely]] case 1003:
+case 104: break;
+  }
+}
+
+void OneCaseDefaultL() {
+  // CHECK-LABEL: define{{.*}}OneCaseDefaultL
+  // CHECK: switch
+  // CHECK: {{.*}} !prof !17
+  switch (i) {
+case 1: break;
+ 

[PATCH] D89210: [Sema, CodeGen] Implement [[likely]] and [[unlikely]] in SwitchStmt

2020-10-18 Thread Mark de Wever via Phabricator via cfe-commits
Mordante marked 2 inline comments as done.
Mordante added a comment.

In D89210#2332143 , @aaron.ballman 
wrote:

> LGTM aside from a documentation request, but you may want to wait a few days 
> before committing in case Richard or John have opinions.

Thanks for the review!




Comment at: clang/include/clang/Basic/AttrDocs.td:1815
 
+  switch(i) {
+[[likely]] case 1:// This value is likely

aaron.ballman wrote:
> Can you add a second example that shows what to expect from fallthrough 
> behavior? Perhaps something like:
> ```
> switch (i) {
> [[likely]] case 0: // This value and code path is likely
>   ...
>   [[fallthrough]];
> case 1: // No likelihood attribute, code path is likely due to fallthrough
>   break;
> case 2: // No likelihood attribute, code path is neutral
>   [[fallthrough]];
> [[unlikely]] default: // This value and code path are both unlikely
>   break;
> }
> ```
I've added this example with minor modifications. Note `case 1` is neutral 
since falling through has no effect.



Comment at: clang/lib/CodeGen/CGStmt.cpp:375
+ ArrayRef Attrs) {
+  // clang-format off
   switch (S->getStmtClass()) {

aaron.ballman wrote:
> Mordante wrote:
> > aaron.ballman wrote:
> > > How ugly is the default clang-format formatting for this? If it's not too 
> > > bad, perhaps we just re-format the switch statement as a whole?
> > It looks fine default formatted, I just thought we wanted to keep it 
> > compact. But I've no problem with keeping the code default formatted.
> I tend to prefer whatever the default formatting is just so we don't have 
> formatting comments all over the place (but I'm fine if the unique formatting 
> is important for code readability).
I'll keep that in mind.


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

https://reviews.llvm.org/D89210

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


[PATCH] D89529: [clangd][remote] Add Windows paths support

2020-10-18 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

In D89529#2334517 , @kbobyrev wrote:

> The solution would be to just convert to the POSIX path instead of asserting 
> it.

I have updated the patch according to this advice.
It seems to me it looks more consistent now, thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89529

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


[PATCH] D89529: [clangd][remote] Add Windows paths support

2020-10-18 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX updated this revision to Diff 298869.
ArcsinX added a comment.

Convert `RemoteIndexRoot` and `LocalIndexRoot` to the POSIX style.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89529

Files:
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp


Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -239,10 +239,6 @@
 
   clangd::Symbol::IncludeHeaderWithReferences Header;
   // Add only valid headers.
-  Header.IncludeHeader = Strings.save(
-  URI::createFile("/usr/local/user/home/project/Header.h").toString());
-  Header.References = 21;
-  Sym.IncludeHeaders.push_back(Header);
   Header.IncludeHeader = Strings.save("");
   Header.References = 100;
   Sym.IncludeHeaders.push_back(Header);
@@ -250,7 +246,7 @@
   Header.References = 200;
   Sym.IncludeHeaders.push_back(Header);
 
-  Marshaller ProtobufMarshaller(convert_to_slash("/"), convert_to_slash("/"));
+  Marshaller ProtobufMarshaller(testPath(""), testPath(""));
 
   auto Serialized = ProtobufMarshaller.toProtobuf(Sym);
   ASSERT_TRUE(bool(Serialized));
Index: clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
===
--- clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
+++ clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
@@ -50,20 +50,23 @@
 Marshaller::Marshaller(llvm::StringRef RemoteIndexRoot,
llvm::StringRef LocalIndexRoot)
 : Strings(Arena) {
+  auto PosixSeparator =
+  llvm::sys::path::get_separator(llvm::sys::path::Style::posix);
   if (!RemoteIndexRoot.empty()) {
 assert(llvm::sys::path::is_absolute(RemoteIndexRoot));
-assert(RemoteIndexRoot ==
-   llvm::sys::path::convert_to_slash(RemoteIndexRoot));
-this->RemoteIndexRoot = RemoteIndexRoot.str();
-if (!RemoteIndexRoot.endswith(llvm::sys::path::get_separator()))
-  *this->RemoteIndexRoot += llvm::sys::path::get_separator();
+this->RemoteIndexRoot = llvm::sys::path::convert_to_slash(
+RemoteIndexRoot, llvm::sys::path::Style::windows);
+llvm::StringRef Path(*this->RemoteIndexRoot);
+if (!Path.endswith(PosixSeparator))
+  *this->RemoteIndexRoot += PosixSeparator;
   }
   if (!LocalIndexRoot.empty()) {
 assert(llvm::sys::path::is_absolute(LocalIndexRoot));
-assert(LocalIndexRoot == 
llvm::sys::path::convert_to_slash(LocalIndexRoot));
-this->LocalIndexRoot = LocalIndexRoot.str();
-if (!LocalIndexRoot.endswith(llvm::sys::path::get_separator()))
-  *this->LocalIndexRoot += llvm::sys::path::get_separator();
+this->LocalIndexRoot = llvm::sys::path::convert_to_slash(
+LocalIndexRoot, llvm::sys::path::Style::windows);
+llvm::StringRef Path(*this->LocalIndexRoot);
+if (!Path.endswith(PosixSeparator))
+  *this->LocalIndexRoot += PosixSeparator;
   }
   assert(!RemoteIndexRoot.empty() || !LocalIndexRoot.empty());
 }
@@ -92,6 +95,7 @@
   for (const auto  : Message->proximity_paths()) {
 llvm::SmallString<256> LocalPath = llvm::StringRef(*RemoteIndexRoot);
 llvm::sys::path::append(LocalPath, Path);
+llvm::sys::path::native(LocalPath);
 Result.ProximityPaths.push_back(std::string(LocalPath));
   }
   for (const auto  : Message->preferred_types())
@@ -209,7 +213,7 @@
 llvm::SmallString<256> RelativePath = llvm::StringRef(Path);
 if (llvm::sys::path::replace_path_prefix(RelativePath, *LocalIndexRoot, 
""))
   RPCRequest.add_proximity_paths(llvm::sys::path::convert_to_slash(
-  RelativePath, llvm::sys::path::Style::posix));
+  RelativePath, llvm::sys::path::Style::windows));
   }
   for (const auto  : From.PreferredTypes)
 RPCRequest.add_preferred_types(Type);
@@ -315,12 +319,17 @@
   if (ParsedURI->scheme() != "file")
 return error("Can not use URI schemes other than file, given: '{0}'.", 
URI);
   llvm::SmallString<256> Result = ParsedURI->body();
+  llvm::StringRef Path(Result);
+  // Check for Windows paths (URI=file:///X:/path => Body=/X:/path)
+  if (llvm::sys::path::is_absolute(Path.substr(1),
+   llvm::sys::path::Style::windows))
+Result = Path.drop_front();
   if (!llvm::sys::path::replace_path_prefix(Result, *RemoteIndexRoot, ""))
 return error("File path '{0}' doesn't start with '{1}'.", Result.str(),
  *RemoteIndexRoot);
-  // Make sure the result has UNIX slashes.
-  return llvm::sys::path::convert_to_slash(Result,
-   llvm::sys::path::Style::posix);
+  assert(Result == llvm::sys::path::convert_to_slash(
+   

[PATCH] D49864: [clang-tidy] The script clang-tidy-diff.py doesn't accept 'pass by' options (--)

2020-10-18 Thread Jano Simas via Phabricator via cfe-commits
janosimas updated this revision to Diff 298865.
janosimas added a comment.

Here a diff with the rebased code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D49864

Files:
  clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Index: clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -17,9 +17,9 @@
 detect clang-tidy regressions in the lines touched by a specific patch.
 Example usage for git/svn users:
 
-  git diff -U0 HEAD^ | clang-tidy-diff.py -p1
+  git diff -U0 HEAD^ | clang-tidy-diff.py -strip 1
   svn diff --diff-cmd=diff -x-U0 | \
-  clang-tidy-diff.py -fix -checks=-*,modernize-use-override
+  clang-tidy-diff.py -- -fix -checks=-*,modernize-use-override
 
 """
 
@@ -119,12 +119,13 @@
   parser = argparse.ArgumentParser(description=
'Run clang-tidy against changed files, and '
'output diagnostics only for modified '
-   'lines.')
+   'lines.'
+   '\nclang-tidy arguments should be passed after a \'--\' .')
   parser.add_argument('-clang-tidy-binary', metavar='PATH',
   default='clang-tidy',
   help='path to clang-tidy binary')
-  parser.add_argument('-p', metavar='NUM', default=0,
-  help='strip the smallest prefix containing P slashes')
+  parser.add_argument('-strip', metavar='NUM', default=0,
+  help='strip the smallest prefix containing N slashes')
   parser.add_argument('-regex', metavar='PATTERN', default=None,
   help='custom pattern selecting file paths to check '
   '(case sensitive, overrides -iregex)')
@@ -136,32 +137,14 @@
   help='number of tidy instances to be run in parallel.')
   parser.add_argument('-timeout', type=int, default=None,
   help='timeout per each file in seconds.')
-  parser.add_argument('-fix', action='store_true', default=False,
-  help='apply suggested fixes')
-  parser.add_argument('-checks',
-  help='checks filter, when not specified, use clang-tidy '
-  'default',
-  default='')
-  parser.add_argument('-path', dest='build_path',
-  help='Path used to read a compile command database.')
   if yaml:
 parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes',
 help='Create a yaml file to store suggested fixes in, '
 'which can be applied with clang-apply-replacements.')
-  parser.add_argument('-extra-arg', dest='extra_arg',
-  action='append', default=[],
-  help='Additional argument to append to the compiler '
-  'command line.')
-  parser.add_argument('-extra-arg-before', dest='extra_arg_before',
-  action='append', default=[],
-  help='Additional argument to prepend to the compiler '
-  'command line.')
-  parser.add_argument('-quiet', action='store_true', default=False,
-  help='Run clang-tidy in quiet mode')
   clang_tidy_args = []
   argv = sys.argv[1:]
   if '--' in argv:
-clang_tidy_args.extend(argv[argv.index('--'):])
+clang_tidy_args.extend(argv[argv.index('--')+1:])
 argv = argv[:argv.index('--')]
 
   args = parser.parse_args(argv)
@@ -170,7 +153,7 @@
   filename = None
   lines_by_file = {}
   for line in sys.stdin:
-match = re.search('^\+\+\+\ \"?(.*?/){%s}([^ \t\n\"]*)' % args.p, line)
+match = re.search('^\+\+\+\ \"?(.*?/){%s}([^ \t\n\"]*)' % args.strip, line)
 if match:
   filename = match.group(2)
 if filename is None:
@@ -215,20 +198,6 @@
   # Run a pool of clang-tidy workers.
   start_workers(max_task_count, run_tidy, task_queue, lock, args.timeout)
 
-  # Form the common args list.
-  common_clang_tidy_args = []
-  if args.fix:
-common_clang_tidy_args.append('-fix')
-  if args.checks != '':
-common_clang_tidy_args.append('-checks=' + args.checks)
-  if args.quiet:
-common_clang_tidy_args.append('-quiet')
-  if args.build_path is not None:
-common_clang_tidy_args.append('-p=%s' % args.build_path)
-  for arg in args.extra_arg:
-common_clang_tidy_args.append('-extra-arg=%s' % arg)
-  for arg in args.extra_arg_before:
-common_clang_tidy_args.append('-extra-arg-before=%s' % arg)
 
   for name in lines_by_file:
 line_filter_json = json.dumps(
@@ -244,7 +213,6 @@
   (handle, tmp_name) = tempfile.mkstemp(suffix='.yaml', dir=tmpdir)
   os.close(handle)
   command.append('-export-fixes=' 

[PATCH] D89394: clang/Basic: Stop using SourceManager::getBuffer, NFC

2020-10-18 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

FYI this showed up as a 1% compile-time regression in terms of instructions 
retired for `O0-g` builds: 
https://llvm-compile-time-tracker.com/compare.php?from=32a4ad3b6ce6028a371b028cf06fa5feff9534bf=54c1bcab90102481fe43b73f8547d47446ba2163=instructions

Looking at the diff, it's not really obvious to me what could cause that, 
possibly GCC is just really bad at optimizing Optional.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89394

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