[PATCH] D138651: [CUDA][HIP] Don't diagnose use for __bf16

2022-12-01 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh marked an inline comment as done.
Pierre-vh added inline comments.



Comment at: clang/test/SemaCUDA/amdgpu-bf16.cu:9
+
+__device__ void devicefn() {
+}

tra wrote:
> We should probably also have a case verifying that actual attempt to use 
> `__bf16` in device code is still diagnosed. 
Good catch, it's currently no longer diagnosed.
What can I use in `ConvertDeclSpecToType` to make it diagnose only if the 
current function is a device function? If I understand correctly, LangOpts are 
for the whole TU so I can't use that (e.g. CUDAIsDevice), right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138651

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


[PATCH] D135953: [IncludeCleaner] Introduce decl to location mapping

2022-12-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
kadircet marked 6 inline comments as done.
Closed by commit rGf82f5b0507a2: [include-cleaner] Introduce symbol to location 
mapping (authored by kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D135953?vs=478611&id=479187#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135953

Files:
  clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
  clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -0,0 +1,133 @@
+//===--- LocateSymbolTest.cpp -- 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
+//
+//===--===//
+#include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace clang::include_cleaner {
+namespace {
+using testing::ElementsAre;
+using testing::ElementsAreArray;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
+// A helper for building ASTs and getting decls out of it by name. Example usage
+// looks like:
+//   LocateExample X("void ^foo();");
+//   Decl &Foo = X.findDecl("foo");
+//   X.points(); // returns all the points in annotated test input.
+struct LocateExample {
+private:
+  llvm::Annotations Target;
+  TestAST AST;
+
+public:
+  LocateExample(llvm::StringRef AnnotatedCode)
+  : Target(AnnotatedCode), AST([this] {
+  TestInputs Inputs(Target.code());
+  Inputs.ExtraArgs.push_back("-std=c++17");
+  return Inputs;
+}()) {}
+
+  const Decl &findDecl(llvm::StringRef SymbolName) {
+const NamedDecl *DeclToLocate;
+struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
+  MatchCB(const NamedDecl *&Out) : Out(Out) {}
+  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
+Out = Result.Nodes.getNodeAs("id");
+assert(Out);
+Out = llvm::cast(Out->getCanonicalDecl());
+  }
+  const NamedDecl *&Out;
+} CB(DeclToLocate);
+ast_matchers::MatchFinder Finder;
+Finder.addMatcher(ast_matchers::namedDecl(
+  ast_matchers::unless(ast_matchers::isImplicit()),
+  ast_matchers::hasName(SymbolName))
+  .bind("id"),
+  &CB);
+Finder.matchAST(AST.context());
+if (!DeclToLocate)
+  ADD_FAILURE() << "Couldn't find any decls with name: " << SymbolName;
+assert(DeclToLocate);
+return *DeclToLocate;
+  }
+
+  Macro findMacro(llvm::StringRef Name) {
+auto &PP = AST.preprocessor();
+auto *II = PP.getIdentifierInfo(Name);
+if (!II || !II->hasMacroDefinition()) {
+  ADD_FAILURE() << "Couldn't find any macros with name: " << Name;
+  return {};
+}
+auto MD = PP.getMacroDefinition(II);
+assert(MD.getMacroInfo());
+return {II, MD.getMacroInfo()->getDefinitionLoc()};
+  }
+
+  std::vector points() {
+auto &SM = AST.sourceManager();
+auto FID = SM.getMainFileID();
+auto Offsets = Target.points();
+std::vector Results;
+for (auto &Offset : Offsets)
+  Results.emplace_back(SM.getComposedLoc(FID, Offset));
+return Results;
+  }
+};
+
+TEST(LocateSymbol, Decl) {
+  // Looks for decl with name 'foo' and performs locateSymbol on it.
+  // Expects all the locations in the case to be returned as a location.
+  const llvm::StringLiteral Cases[] = {
+  "struct ^foo; struct ^foo {};",
+  "namespace ns { void ^foo(); void ^foo() {} }",
+  "enum class ^foo; enum class ^foo {};",
+  };
+
+  for (auto &Case : Cases) {
+SCOPED_TRACE(Case);
+LocateExample Test(Case);
+EXPECT_THAT(locateSymbol(Test.findDecl("foo")),
+ElementsAreArray(Test.points()));
+  }
+}
+
+TEST(LocateSymbol, Stdlib) {
+  LocateExample Test("namespace std { struct

[clang-tools-extra] f82f5b0 - [include-cleaner] Introduce symbol to location mapping

2022-12-01 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-12-01T09:46:05+01:00
New Revision: f82f5b0507a25cbef1cf44fa5ef481c786a40473

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

LOG: [include-cleaner] Introduce symbol to location mapping

Creates a one to many mapping, by returning all the possible locations
providing a symbol. Also includes an "is definition" signal for the
location, that can be used for ranking afterwards.

This also takes care of stdlib symbols by having a variant of locations.

Depends on D135859.

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

Added: 
clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp

Modified: 
clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
clang-tools-extra/include-cleaner/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h 
b/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
index 29dbd58886abf..026bb8dd20501 100644
--- a/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
+++ b/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
@@ -24,7 +24,10 @@
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include 
+#include 
 
 namespace clang {
 class ASTContext;
@@ -66,7 +69,6 @@ struct SymbolLocation {
   bool operator==(const SymbolLocation &RHS) const {
 return Storage == RHS.Storage;
   }
-
   SourceLocation physical() const { return std::get(Storage); }
   tooling::stdlib::Symbol standard() const {
 return std::get(Storage);
@@ -91,6 +93,9 @@ void writeHTMLReport(FileID File, const Includes &,
  HeaderSearch &HS, PragmaIncludes *PI,
  llvm::raw_ostream &OS);
 
+/// A set of locations that provides the declaration.
+std::vector locateSymbol(const Symbol &S);
+
 } // namespace include_cleaner
 } // namespace clang
 

diff  --git a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp 
b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
index 03c32e656ee49..cdfe5fda5e95f 100644
--- a/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
+++ b/clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp
@@ -1,4 +1,4 @@
-//===--- LocateSymbol.cpp 
-===//
+//===--- LocateSymbol.cpp - Find locations providing a symbol 
-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,10 +7,28 @@
 
//===--===//
 
 #include "AnalysisInternal.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+#include 
 
 namespace clang::include_cleaner {
+namespace {
+
+std::vector locateDecl(const Decl &D) {
+  std::vector Result;
+  // FIXME: Should we also provide physical locations?
+  if (auto SS = tooling::stdlib::Recognizer()(&D))
+return {SymbolLocation(*SS)};
+  for (auto *Redecl : D.redecls())
+Result.push_back(Redecl->getLocation());
+  return Result;
+}
+
+} // namespace
 
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolLocation &S) {
   switch (S.kind()) {
@@ -28,4 +46,13 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const 
SymbolLocation &S) {
   llvm_unreachable("Unhandled Symbol kind");
 }
 
-} // namespace clang::include_cleaner
\ No newline at end of file
+std::vector locateSymbol(const Symbol &S) {
+  switch (S.kind()) {
+  case Symbol::Declaration:
+return locateDecl(S.declaration());
+  case Symbol::Macro:
+return {SymbolLocation(S.macro().Definition)};
+  }
+}
+
+} // namespace clang::include_cleaner

diff  --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
index 94640c3c2fc1f..d911b5df70c50 100644
--- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -7,6 +7,7 @@ add_custom_target(ClangIncludeCleanerUnitTests)
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
   WalkASTTest.cpp

diff  --git a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
new file mode 100644
index 0..f

[PATCH] D138402: [clang-format] Correctly count a tab's width in a comment

2022-12-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added a comment.

Thanks for unstacking it!




Comment at: clang/unittests/Format/FormatTestComments.cpp:66-67
 const FormatStyle &Style = getLLVMStyle()) {
 EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not 
stable";
 EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }

Similar to what's done in FormatTest.cpp.


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

https://reviews.llvm.org/D138402

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


[PATCH] D138378: [clang-format][NFC] Skip unneeded calculations

2022-12-01 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 479189.
HazardyKnusperkeks added a comment.

Reverted the changes in the switch. We now only have a fast path.

On my machine 4 consecutive runs of the clang format unittests, the last three 
times (as reported by gtest) are:

|   | Before patch | After Patch |
| Run 1 | 12769ms  | 12535ms |
| Run 2 | 13703ms  | 12456ms |
| Run 3 | 13305ms  | 12470ms |
| Avg   | 13259ms  | 12487ms |
|

That would be 6% speedup, more than I'd excpected.

Release Build 32 Bit Windows.


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

https://reviews.llvm.org/D138378

Files:
  clang/lib/Format/WhitespaceManager.cpp


Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -1430,10 +1430,14 @@
   }
   // FIXME: This assert should hold if we computed the column correctly.
   // assert((int)C.StartOfTokenColumn >= C.Spaces);
-  appendIndentText(
-  ReplacementText, C.Tok->IndentLevel, std::max(0, C.Spaces),
-  std::max((int)C.StartOfTokenColumn, C.Spaces) - std::max(0, 
C.Spaces),
-  C.IsAligned);
+  unsigned Spaces = std::max(0, C.Spaces);
+  if (Style.UseTab == FormatStyle::UT_Never) {
+ReplacementText.append(Spaces, ' ');
+  } else {
+appendIndentText(ReplacementText, C.Tok->IndentLevel, Spaces,
+ std::max((int)C.StartOfTokenColumn, C.Spaces) - 
Spaces,
+ C.IsAligned);
+  }
   ReplacementText.append(C.CurrentLinePrefix);
   storeReplacement(C.OriginalWhitespaceRange, ReplacementText);
 }


Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -1430,10 +1430,14 @@
   }
   // FIXME: This assert should hold if we computed the column correctly.
   // assert((int)C.StartOfTokenColumn >= C.Spaces);
-  appendIndentText(
-  ReplacementText, C.Tok->IndentLevel, std::max(0, C.Spaces),
-  std::max((int)C.StartOfTokenColumn, C.Spaces) - std::max(0, C.Spaces),
-  C.IsAligned);
+  unsigned Spaces = std::max(0, C.Spaces);
+  if (Style.UseTab == FormatStyle::UT_Never) {
+ReplacementText.append(Spaces, ' ');
+  } else {
+appendIndentText(ReplacementText, C.Tok->IndentLevel, Spaces,
+ std::max((int)C.StartOfTokenColumn, C.Spaces) - Spaces,
+ C.IsAligned);
+  }
   ReplacementText.append(C.CurrentLinePrefix);
   storeReplacement(C.OriginalWhitespaceRange, ReplacementText);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137487: [clang][Interp] Start implementing builtin functions

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 479201.
tbaeder added a comment.

Split `CallBI` out from `Call`, so we don't need special cases in 
`CheckCallable` etc. for builtin functions.


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

https://reviews.llvm.org/D137487

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/builtins.cpp

Index: clang/test/AST/Interp/builtins.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/builtins.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated %s -S -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+using size_t = decltype(sizeof(int));
+
+namespace std {
+inline constexpr bool is_constant_evaluated() noexcept {
+  return __builtin_is_constant_evaluated();
+}
+} // namespace std
+
+constexpr bool b = std::is_constant_evaluated();
+static_assert(b, "");
+static_assert(std::is_constant_evaluated() , "");
+
+
+bool is_this_constant() {
+  return __builtin_is_constant_evaluated(); // CHECK: ret i1 false
+}
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -165,6 +165,12 @@
   let ChangesPC = 1;
 }
 
+def CallBI : Opcode {
+  let Args = [ArgFunction];
+  let Types = [];
+  let ChangesPC = 1;
+}
+
 //===--===//
 // Frame management
 //===--===//
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- /dev/null
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -0,0 +1,51 @@
+//===--- InterpBuiltin.cpp - Interpreter for the constexpr VM ---*- 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
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/Basic/Builtins.h"
+
+namespace clang {
+namespace interp {
+
+/// This is a slightly simplified version of the Ret() we have in Interp.cpp
+/// If they end up diverging in the future, we should get rid of the code
+/// duplication.
+template ::T>
+static bool Ret(InterpState &S, CodePtr &PC) {
+  S.CallStackDepth--;
+  const T &Ret = S.Stk.pop();
+
+  assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
+  if (!S.checkingPotentialConstantExpression())
+S.Current->popArgs();
+
+  InterpFrame *Caller = S.Current->Caller;
+  assert(Caller);
+
+  PC = S.Current->getRetPC();
+  delete S.Current;
+  S.Current = Caller;
+  S.Stk.push(Ret);
+
+  return true;
+}
+
+bool InterpretBuiltin(InterpState &S, CodePtr PC, unsigned BuiltinID) {
+  switch (BuiltinID) {
+  case Builtin::BI__builtin_is_constant_evaluated:
+S.Stk.push(Boolean::from(S.inConstantContext()));
+Ret(S, PC);
+return true;
+  }
+
+  return false;
+}
+
+} // namespace interp
+} // namespace clang
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -105,6 +105,8 @@
 /// Interpreter entry point.
 bool Interpret(InterpState &S, APValue &Result);
 
+bool InterpretBuiltin(InterpState &S, CodePtr PC, unsigned BuiltinID);
+
 enum class ArithOp { Add, Sub };
 
 //===--===//
@@ -1303,6 +1305,20 @@
   return false;
 }
 
+inline bool CallBI(InterpState &S, CodePtr &PC, const Function *Func) {
+  auto NewFrame = std::make_unique(S, Func, PC);
+
+  InterpFrame *FrameBefore = S.Current;
+  S.Current = NewFrame.get();
+
+  if (InterpretBuiltin(S, PC, Func->getBuiltinID())) {
+NewFrame.release();
+return true;
+  }
+  S.Current = FrameBefore;
+  return false;
+}
+
 //===--===//
 // Read opcode arguments
 //===--===//
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -138,6 +138,8 @@
   // Checks if the funtion alr

[PATCH] D139086: [AArch64] Implement __arm_rsr128/__arm_wsr128

2022-12-01 Thread Sam Elliott via Phabricator via cfe-commits
lenary created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
lenary requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This only contains the SelectionDAG implementation. GlobalISel to
follow.

The broad approach is:

- Introduce new builtins for 128-bit wide instructions.
- Lower these to @llvm.read_register.i128/@llvm.write_register.i128
- Introduce target-specific ISD nodes which have legal operands (two i64s 
rather than an i128). These are named AArch64::{MRRS, MSRR} to match the 
instructions they are for. These are a little complex as they need to match the 
"shape" of what they're replacing or the legaliser complains.
- Select these using the existing tryReadRegister/tryWriteRegister to share the 
MDString parsing code, and introduce additional code to ensure these are 
selected into the right MRRS/MSRR instructions. What makes this hard is 
ensuring that the two i64s end up in an XSeqPair register pair, because 
SelectionDAG doesn't care that much about register classes if it can avoid 
doing so.

The main change to existing code is the reorganisation of
tryReadRegister and tryWriteRegister to try to keep the string parsing
code separate from the instruction creating code.

This also includes the changes to clang to define and use the ACLE
feature macro named `__ARM_FEATURE_SYSREG128`.

Contributors:

  Sam Elliott
  Lucas Prates


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139086

Files:
  clang/include/clang/Basic/BuiltinsAArch64.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/arm_acle.h
  clang/test/CodeGen/arm_acle.c
  clang/test/Preprocessor/aarch64-target-features.c
  llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/test/CodeGen/AArch64/aarch64-sysreg128.ll

Index: llvm/test/CodeGen/AArch64/aarch64-sysreg128.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/aarch64-sysreg128.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple aarch64-mattr=+d128 | FileCheck %s --check-prefixes=CHECK-LE
+; RUN: llc < %s -mtriple aarch64_be -mattr=+d128 | FileCheck %s --check-prefixes=CHECK-BE
+
+define i128 @test_rsr128() #0 {
+; CHECK-LE-LABEL: test_rsr128:
+; CHECK-LE:   // %bb.0: // %entry
+; CHECK-LE-NEXT:mrrs x0, x1, S1_2_C3_C4_5
+; CHECK-LE-NEXT:ret
+;
+; CHECK-BE-LABEL: test_rsr128:
+; CHECK-BE:   // %bb.0: // %entry
+; CHECK-BE-NEXT:mrrs x2, x3, S1_2_C3_C4_5
+; CHECK-BE-NEXT:mov x0, x3
+; CHECK-BE-NEXT:mov x1, x2
+; CHECK-BE-NEXT:ret
+entry:
+  %0 = call i128 @llvm.read_volatile_register.i128(metadata !1)
+  ret i128 %0
+}
+
+declare i128 @llvm.read_volatile_register.i128(metadata) #1
+
+define void @test_wsr128(i128 noundef %v) #0 {
+; CHECK-LE-LABEL: test_wsr128:
+; CHECK-LE:   // %bb.0: // %entry
+; CHECK-LE-NEXT:// kill: def $x1 killed $x1 killed $x0_x1 def $x0_x1
+; CHECK-LE-NEXT:// kill: def $x0 killed $x0 killed $x0_x1 def $x0_x1
+; CHECK-LE-NEXT:msrr S1_2_C3_C4_5, x0, x1
+; CHECK-LE-NEXT:ret
+;
+; CHECK-BE-LABEL: test_wsr128:
+; CHECK-BE:   // %bb.0: // %entry
+; CHECK-BE-NEXT:mov x2, x1
+; CHECK-BE-NEXT:mov x3, x0
+; CHECK-BE-NEXT:msrr S1_2_C3_C4_5, x2, x3
+; CHECK-BE-NEXT:ret
+entry:
+  call void @llvm.write_register.i128(metadata !1, i128 %v)
+  ret void
+}
+
+declare void @llvm.write_register.i128(metadata, i128) #1
+
+attributes #0 = { noinline nounwind }
+attributes #1 = { nounwind }
+
+!1 = !{!"1:2:3:4:5"}
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.h
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.h
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.h
@@ -430,6 +430,12 @@
   // the caller
   ASSERT_ZEXT_BOOL,
 
+  // 128-bit system register accesses
+  // lo64, hi64, chain = MRRS(chain, sysregname)
+  MRRS,
+  // chain = MSRR(chain, sysregname, lo64, hi64)
+  MSRR,
+
   // Strict (exception-raising) floating point comparison
   STRICT_FCMP = ISD::FIRST_TARGET_STRICTFP_OPCODE,
   STRICT_FCMPE,
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -1600,6 +1600,11 @@
   setIndexedStoreAction(im, VT, Legal);
 }
   }
+
+  if (Subtarget->hasD128()) {
+setOperationAction(ISD::READ_REGISTER, MVT::i128, Custom);
+setOperationAction(ISD::WRITE_REGISTER, MVT::i128, Custom);
+  }
 }
 
 bool AArch64TargetLowering::shouldExpandGetActiveLaneMask(EVT ResVT,
@@ -2463,6 +2468,8 @@
 MAKE_CASE(AArch64ISD::MOPS_MEMCOPY)
 MAKE_CASE(AArch64ISD::MOPS_MEMMOVE)
 MAKE_CASE(AA

[clang-tools-extra] bcdf590 - [include-cleaner] Fix build

2022-12-01 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-12-01T11:02:16+01:00
New Revision: bcdf590b81cf8cc1bb7a0e41b67e8b568843

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

LOG: [include-cleaner] Fix build

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
index d911b5df70c5..acab6e2318ce 100644
--- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -20,6 +20,7 @@ target_include_directories(ClangIncludeCleanerTests
 clang_target_link_libraries(ClangIncludeCleanerTests
   PRIVATE
   clangAST
+  clangASTMatchers
   clangBasic
   clangFrontend
   clangLex



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


[PATCH] D139006: [UpdateTestChecks] Match define for labels

2022-12-01 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne added inline comments.



Comment at: 
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/define_after_call.ll.expected:14
+define i32 @b(i32 %arg) {
+; CHECK-LABEL: define {{[^@]+}}@b(
+; CHECK-NEXT:ret i32 [[ARG:%.*]]

arichardson wrote:
> Does this actually fail without the define match? I wouldn't expect it to?
Yes, it fails (which is why I put the opt | FileCheck line into the .test 
script as well).
`CHECK-LABEL: @b(` matches the `call i32 @b(i32 0)` line and and as labels are 
matched before check-lines, then the `CHECK-NEXT: [[VAL:%.*]] = call i32 @b(i32 
0)` line doesn’t find its match anymore (or the ret i32 match, I’m not quite 
sure, but it definitely fails).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139006

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


[PATCH] D136694: [clang][Interp] Check that constructor calls initialize all record fields

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 3 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Interp.cpp:447
+
+if (FieldType->isRecordType()) {
+  Result &= CheckFieldsInitialized(S, OpPC, FieldPtr, 
FieldPtr.getRecord());

aaron.ballman wrote:
> Do we have to worry about static data members, or are those excluded in 
> `fields()`?
They aren't in `RecordDecl::fields()`, so aren't in `Record::fields()` either.



Comment at: clang/lib/AST/Interp/Interp.h:1346-1347
   if (Func->hasThisPointer()) {
+ThisPtr = NewFrame->getThis();
 if (!CheckInvoke(S, PC, NewFrame->getThis())) {
   return false;

aaron.ballman wrote:
> Should we assert that `ThisPtr` is valid?
We could only assert `!isZero()` as far as I understand, but that's part of 
what `CheckInvoke` does.


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

https://reviews.llvm.org/D136694

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


[PATCH] D136694: [clang][Interp] Check that constructor calls initialize all record fields

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 479209.
tbaeder marked 2 inline comments as done.

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

https://reviews.llvm.org/D136694

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -295,13 +295,14 @@
   // ref-note 2{{non-constexpr constructor 'Base' cannot be used in a constant expression}}
   };
 
-  // FIXME: This is currently not being diagnosed with the new constant interpreter.
   constexpr Derived D(12); // ref-error {{must be initialized by a constant expression}} \
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
// expected-error {{must be initialized by a constant expression}}
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
- // ref-note {{initializer of 'D' is not a constant expression}}
+ // ref-note {{initializer of 'D' is not a constant expression}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{read of object outside its lifetime}}
 
   struct AnotherBase {
 int Val;
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -108,3 +108,35 @@
 // ref-note {{declared here}}
 static_assert(!b4); // ref-error {{not an integral constant expression}} \
 // ref-note {{not a constant expression}}
+
+namespace UninitializedFields {
+  class A {
+  public:
+int a; // expected-note {{subobject declared here}} \
+   // ref-note {{subobject declared here}}
+constexpr A() {}
+  };
+  constexpr A a; // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{subobject of type 'int' is not initialized}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{subobject of type 'int' is not initialized}}
+
+
+  class Base {
+  public:
+bool b;
+int a; // expected-note {{subobject declared here}} \
+   // ref-note {{subobject declared here}}
+constexpr Base() : b(true) {}
+  };
+
+  class Derived : public Base {
+  public:
+constexpr Derived() : Base() {} // expected-note {{subobject of type 'int' is not initialized}}
+  };
+
+constexpr Derived D; // expected-error {{must be initialized by a constant expression}} \\
+ // expected-note {{in call to 'Derived()'}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{subobject of type 'int' is not initialized}}
+};
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -64,8 +64,6 @@
 }
 
 InterpFrame::~InterpFrame() {
-  if (Func && Func->isConstructor() && This.isBaseClass())
-This.initialize();
   for (auto &Param : Params)
 S.deallocate(reinterpret_cast(Param.second.get()));
 }
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -91,6 +91,9 @@
 /// Checks if a method is pure virtual.
 bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD);
 
+/// Checks that all fields are initialized after a constructor call.
+bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
+
 /// Checks if Div/Rem operation on LHS and RHS is valid.
 template 
 bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
@@ -1272,8 +1275,10 @@
 
 inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
   auto NewFrame = std::make_unique(S, Func, PC);
+  Pointer ThisPtr;
   if (Func->hasThisPointer()) {
-if (!CheckInvoke(S, PC, NewFrame->getThis())) {
+ThisPtr = NewFrame->getThis();
+if (!CheckInvoke(S, PC, ThisPtr)) {
   return false;
 }
   }
@@ -1291,6 +1296,11 @@
   if (Interpret(S, CallResult)) {
 NewFrame.release(); // Frame was delete'd already.
 assert(S.Current == FrameBefore);
+
+// For constructors, check that all fields have been initialized.
+if (Func->isConstructor() && !CheckCtorCall(S, PC, ThisPtr))
+  return false;
+

[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added a subscriber: kadircet.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139087

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -172,10 +172,12 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); 
}");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); 
}");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived d) { d.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -59,7 +59,11 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record.
+Expr *BE = E->getBase()->IgnoreImpCasts();
+RecordDecl *RD = BE->getType()->getAsRecordDecl();
+report(E->getMemberLoc(), RD);
 return true;
   }
 


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -172,10 +172,12 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); }");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); }");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};",
+   "void fun(Derived d) { d.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -59,7 +59,11 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record.
+Expr *BE = E->getBase()->IgnoreImpCasts();
+RecordDecl *RD = BE->getType()->getAsRecordDecl();
+report(E->getMemberLoc(), RD);
 return true;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-01 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv marked an inline comment as done.
ilinpv added inline comments.



Comment at: compiler-rt/lib/builtins/cpu_model.c:1311
+  // CPU features already initialized.
+  if (__aarch64_cpu_features.features)
+return;

danielkiss wrote:
> I'd add a init value for the declaration to be sure it is properly 
> initialised. 
I reply on __aarch64_cpu_features as global is guaranteed to be initialised to 
0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 479213.
VitaNuo added a comment.

Fix formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,12 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); 
}");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); 
}");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived d) { d.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -59,7 +59,11 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record.
+Expr *BE = E->getBase()->IgnoreImpCasts();
+RecordDecl *RD = BE->getType()->getAsRecordDecl();
+report(E->getMemberLoc(), RD);
 return true;
   }
 


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,12 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); }");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); }");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};",
+   "void fun(Derived d) { d.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -59,7 +59,11 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record.
+Expr *BE = E->getBase()->IgnoreImpCasts();
+RecordDecl *RD = BE->getType()->getAsRecordDecl();
+report(E->getMemberLoc(), RD);
 return true;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139088: [clangd] Log diagnostics if we failed to create a preamble.

2022-12-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Really we want these to be shown to the client, but the path to do so involves
storing them in

Bandaid for https://github.com/clangd/clangd/issues/1408
See https://github.com/clangd/clangd/issues/1399 for motivation


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139088

Files:
  clang-tools-extra/clangd/Preamble.cpp


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -571,6 +571,12 @@
 
   elog("Could not build a preamble for file {0} version {1}: {2}", FileName,
Inputs.Version, BuiltPreamble.getError().message());
+  for (const Diag &D : PreambleDiagnostics.take()) {
+if (D.Severity < DiagnosticsEngine::Error)
+  continue;
+// Not an ideal way to show errors, but better than nothing!
+elog("  error: {0}", D.Message);
+  }
   return nullptr;
 }
 


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -571,6 +571,12 @@
 
   elog("Could not build a preamble for file {0} version {1}: {2}", FileName,
Inputs.Version, BuiltPreamble.getError().message());
+  for (const Diag &D : PreambleDiagnostics.take()) {
+if (D.Severity < DiagnosticsEngine::Error)
+  continue;
+// Not an ideal way to show errors, but better than nothing!
+elog("  error: {0}", D.Message);
+  }
   return nullptr;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-12-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked 4 inline comments as done.
VitaNuo added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:86
   report(UD->getLocation(), TD,
  IsUsed ? RefType::Explicit : RefType::Ambiguous);
 }

kadircet wrote:
> hokein wrote:
> > we should report all references as explicit.
> i think having `Ambiguous` here for unused symbols is fine. we'd like to 
> consider such symbols for the purposes of saying "yeah this include is 
> probably used" but we shouldn't be inserting headers for the unused ones.
> 
> do we have an example for the contrary?
@hokein so what would be the final conclusion then? Should I re-introduce the 
"isUsed" check?



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:136
"using ns::^x; void foo() { x(); }");
-  // We should report unused overloads if main file is a header.
   testWalk(R"cpp(
 namespace ns {

kadircet wrote:
> you can drop this test now, having declaration in a header vs not doesn't 
> make any difference.
sure



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:140
 })cpp",
"// c++-header\n using ns::^x;");
+  testWalk(R"cpp(

hokein wrote:
> I think the `c++-header` is not needed, we can even remove the special 
> `c++-header` logic in `testWalk`.
Ok, removed the header logic from testWalk, too.



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:149
+  // We should report references to templates as ambiguous.
+  testWalk(R"cpp(
+namespace ns {

kadircet wrote:
> sorry if i am being dense but what's the difference we're trying to grasp 
> between this and the next test case exactly?
> i guess it's meant to test the difference between used and non-used template 
> patterns?
Yes, you're right. It probably only made sense before I removed the "isUsed" 
check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

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


[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-12-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 479216.
VitaNuo marked 2 inline comments as done.
VitaNuo added a comment.

Address review comments, remove excessive tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -26,7 +26,6 @@
 namespace {
 
 // Specifies a test of which symbols are referenced by a piece of code.
-// If `// c++-header` is present, treats referencing code as a header file.
 // Target should contain points annotated with the reference kind.
 // Example:
 //   Target:  int $explicit^foo();
@@ -41,8 +40,6 @@
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("target.h");
   Inputs.ExtraArgs.push_back("-std=c++17");
-  if (Referencing.code().contains("// c++-header\n"))
-Inputs.ExtraArgs.push_back("-xc++-header");
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
 
@@ -88,12 +85,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -129,19 +124,27 @@
 }
 
 TEST(WalkAST, Using) {
-  // Make sure we ignore unused overloads.
+  // We should report unused overloads as explicit.
   testWalk(R"cpp(
 namespace ns {
-  void $explicit^x(); void x(int); void x(char);
+  void $explicit^x(); void $explicit^x(int); void $explicit^x(char);
 })cpp",
"using ns::^x; void foo() { x(); }");
-  // We should report unused overloads if main file is a header.
   testWalk(R"cpp(
 namespace ns {
-  void $ambiguous^x(); void $ambiguous^x(int); void $ambiguous^x(char);
+  void $explicit^x(); void $explicit^x(int); void $explicit^x(char);
 })cpp",
-   "// c++-header\n using ns::^x;");
+   "using ns::^x;");
   testWalk("namespace ns { struct S; } using ns::$explicit^S;", "^S *s;");
+
+  // We should report references to templates as explicit.
+  testWalk(R"cpp(
+namespace ns {
+  template
+  class $explicit^Y {};
+}
+)cpp",
+   "using ns::^Y;");
 }
 
 TEST(WalkAST, Namespaces) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -16,7 +16,6 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Casting.h"
 
@@ -27,10 +26,6 @@
 
 class ASTWalker : public RecursiveASTVisitor {
   DeclCallback Callback;
-  // Whether we're traversing declarations coming from a header file.
-  // This helps figure out whether certain symbols can be assumed as unused
-  // (e.g. overloads brought into an implementation file, but not used).
-  bool IsHeader = false;
 
   bool handleTemplateName(SourceLocation Loc, TemplateName TN) {
 // For using-templates, only mark the alias.
@@ -50,8 +45,7 @@
   }
 
 public:
-  ASTWalker(DeclCallback Callback, bool IsHeader)
-  : Callback(Callback), IsHeader(IsHeader) {}
+  ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
   bool VisitDeclRefExpr(DeclRefExpr *DRE) {
 report(DRE->getLocation(), DRE->getFoundDecl());
@@ -81,13 +75,7 @@
   bool VisitUsingDecl(UsingDecl *UD) {
 for (const auto *Shadow : UD->shadows()) {
   auto *TD = Shadow->getTargetDecl();
-  auto IsUsed = TD->isUsed() || TD->isReferenced();
-  // We ignore unused overloads inside implementation files, as the ones in
-  // headers might still be used by the dependents of the header.
-  if (!IsUsed && !IsHeader)
-continue;
-  report(UD->getLocation(), TD,
- IsUsed ? RefType::Explicit : RefType::Ambiguous);
+  report(UD->getLocation(), TD, RefType::Explicit);
 }
 return true;
   }
@@ -151,14 +139,7 @@
 } // namespace
 
 void walkAST(Decl &Root, DeclCallback Callback) {
-  auto &

[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 3 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1127
 return false;
-  if (!this->emitInitGlobal(*T, *I, VD))
+}
+  } else {

aaron.ballman wrote:
> and if we have no `GlobalIndex`?
> 
> Should this instead be:
> ```
> if (auto GlobalIndex = P.getGlobal(VD); !GlobalIndex || 
> !this->emitGetPtrGlobal(*GlobalIndex, VD))
>   return false;
> ```
> 
I mean, that shouldn't happen because the `visitVarDecl` call before would've 
returned `false` in that case.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1161
+  if (VarT) {
+if (!this->visit(Init))
   return false;

aaron.ballman wrote:
> What if `Init` is `nullptr`?
Global variables (or local constexpr ones) must have an initializer, no?


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

https://reviews.llvm.org/D136815

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


[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 479219.

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

https://reviews.llvm.org/D136815

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h

Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -79,7 +79,8 @@
   llvm::Optional getGlobal(const ValueDecl *VD);
 
   /// Returns or creates a global an creates an index to it.
-  llvm::Optional getOrCreateGlobal(const ValueDecl *VD);
+  llvm::Optional getOrCreateGlobal(const ValueDecl *VD,
+ const Expr *Init = nullptr);
 
   /// Returns or creates a dummy value for parameters.
   llvm::Optional getOrCreateDummy(const ParmVarDecl *PD);
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -124,11 +124,12 @@
   return Index;
 }
 
-llvm::Optional Program::getOrCreateGlobal(const ValueDecl *VD) {
+llvm::Optional Program::getOrCreateGlobal(const ValueDecl *VD,
+const Expr *Init) {
   if (auto Idx = getGlobal(VD))
 return Idx;
 
-  if (auto Idx = createGlobal(VD, nullptr)) {
+  if (auto Idx = createGlobal(VD, Init)) {
 GlobalIndices[VD] = *Idx;
 return Idx;
   }
@@ -156,6 +157,7 @@
 
 llvm::Optional Program::createGlobal(const ValueDecl *VD,
const Expr *Init) {
+  assert(!getGlobal(VD));
   bool IsStatic, IsExtern;
   if (auto *Var = dyn_cast(VD)) {
 IsStatic = !Var->hasLocalStorage();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -65,7 +65,6 @@
   bool visitContinueStmt(const ContinueStmt *S);
 
   /// Compiles a variable declaration.
-  bool visitVarDecl(const VarDecl *VD);
 
 private:
   /// Type of the expression returned by the function.
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -207,7 +207,7 @@
   for (auto *D : DS->decls()) {
 // Variable declarator.
 if (auto *VD = dyn_cast(D)) {
-  if (!visitVarDecl(VD))
+  if (!this->visitVarDecl(VD))
 return false;
   continue;
 }
@@ -391,37 +391,6 @@
   return this->jump(*ContinueLabel);
 }
 
-template 
-bool ByteCodeStmtGen::visitVarDecl(const VarDecl *VD) {
-  if (!VD->hasLocalStorage()) {
-// No code generation required.
-return true;
-  }
-
-  // Integers, pointers, primitives.
-  if (Optional T = this->classify(VD->getType())) {
-const Expr *Init = VD->getInit();
-
-unsigned Offset =
-this->allocateLocalPrimitive(VD, *T, VD->getType().isConstQualified());
-// Compile the initializer in its own scope.
-if (Init) {
-  ExprScope Scope(this);
-  if (!this->visit(Init))
-return false;
-
-  return this->emitSetLocal(*T, Offset, VD);
-}
-return true;
-  }
-
-  // Composite types - allocate storage and initialize it.
-  if (Optional Offset = this->allocateLocal(VD))
-return this->visitLocalInitializer(VD->getInit(), *Offset);
-
-  return this->bail(VD);
-}
-
 namespace clang {
 namespace interp {
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -152,6 +152,8 @@
   bool visitArrayInitializer(const Expr *Initializer);
   /// Compiles a record initializer.
   bool visitRecordInitializer(const Expr *Initializer);
+  /// Creates and initializes a variable from the given decl.
+  bool visitVarDecl(const VarDecl *VD);
 
   /// Visits an expression and converts it to a boolean.
   bool visitBool(const Expr *E);
@@ -255,6 +257,12 @@
 return T->getAsCXXRecordDecl();
   }
 
+  /// Returns whether we should create a global variable for the
+  /// given VarDecl.
+  bool ShouldBeGloballyIndexed(const VarDecl *VD) const {
+return !VD->hasLocalStorage() || VD->isConstexpr();
+  }
+
 protected:
   /// Variable to storage mapping.
   llvm::DenseMap Locals;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -854,6 +854,13 @@
   PrimType Ty,
   bool IsC

[clang-tools-extra] fa46e77 - [include-cleaner] Attempt two at fixing buildbots

2022-12-01 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-12-01T11:49:58+01:00
New Revision: fa46e77f17c6b699233e0a9e8b7b207c49738ba6

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

LOG: [include-cleaner] Attempt two at fixing buildbots

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
index acab6e2318ce..11d93f526f3c 100644
--- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  FrontendOpenMP
   Support
   TestingSupport
   )



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


[PATCH] D139090: [clang] Add test for CWG360

2022-12-01 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added a reviewer: clang-language-wg.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

P1787 : "CWG360 is resolved by applying access 
control to using-declarations."
class.access.general#4 
: "When a 
using-declarator is named, access control is applied to it, not to the 
declarations that replace it."


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139090

Files:
  clang/test/CXX/drs/dr3xx.cpp


Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -890,6 +890,33 @@
   };
 }
 
+namespace dr360 { // dr360: yes
+struct A {
+  int foo();
+  int bar();
+
+protected:
+  int baz();
+};
+
+struct B : A {
+private:
+  using A::foo; // #dr360-foo-using-decl
+protected:
+  using A::bar; // #dr360-bar-using-decl
+public:
+  using A::baz; // #dr360-baz-using-decl
+};
+
+int main() {
+  int foo = B().foo(); // expected-error {{is a private member}}
+  // expected-note@#dr360-foo-using-decl {{declared private here}}
+  int bar = B().bar(); // expected-error {{is a protected member}}
+  // expected-note@#dr360-bar-using-decl {{declared protected here}}
+  int baz = B().baz();
+}
+} // namespace dr360
+
 // dr362: na
 // dr363: na
 


Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -890,6 +890,33 @@
   };
 }
 
+namespace dr360 { // dr360: yes
+struct A {
+  int foo();
+  int bar();
+
+protected:
+  int baz();
+};
+
+struct B : A {
+private:
+  using A::foo; // #dr360-foo-using-decl
+protected:
+  using A::bar; // #dr360-bar-using-decl
+public:
+  using A::baz; // #dr360-baz-using-decl
+};
+
+int main() {
+  int foo = B().foo(); // expected-error {{is a private member}}
+  // expected-note@#dr360-foo-using-decl {{declared private here}}
+  int bar = B().bar(); // expected-error {{is a protected member}}
+  // expected-note@#dr360-bar-using-decl {{declared protected here}}
+  int baz = B().baz();
+}
+} // namespace dr360
+
 // dr362: na
 // dr363: na
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139093: [include-cleaner] Use RAV instead of ASTMatchers in LocateSymbolTest

2022-12-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a project: All.
kadircet requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang-tools-extra.

ASTMatchers are pulling in lots of dependencies that we don't really
need for just finding a decl based on name. So use a simple RAV instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139093

Files:
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -9,14 +9,12 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -53,27 +51,23 @@
 }()) {}
 
   const Decl &findDecl(llvm::StringRef SymbolName) {
-const NamedDecl *DeclToLocate;
-struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
-  MatchCB(const NamedDecl *&Out) : Out(Out) {}
-  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
-Out = Result.Nodes.getNodeAs("id");
-assert(Out);
-Out = llvm::cast(Out->getCanonicalDecl());
+struct Visitor : RecursiveASTVisitor {
+  llvm::StringRef NameToFind;
+  const NamedDecl *Out = nullptr;
+  bool VisitNamedDecl(const NamedDecl *ND) {
+if (ND->getName() != NameToFind)
+  return true;
+Out = ND;
+return false;
   }
-  const NamedDecl *&Out;
-} CB(DeclToLocate);
-ast_matchers::MatchFinder Finder;
-Finder.addMatcher(ast_matchers::namedDecl(
-  ast_matchers::unless(ast_matchers::isImplicit()),
-  ast_matchers::hasName(SymbolName))
-  .bind("id"),
-  &CB);
-Finder.matchAST(AST.context());
-if (!DeclToLocate)
+};
+Visitor V;
+V.NameToFind = SymbolName;
+V.TraverseDecl(AST.context().getTranslationUnitDecl());
+if (!V.Out)
   ADD_FAILURE() << "Couldn't find any decls with name: " << SymbolName;
-assert(DeclToLocate);
-return *DeclToLocate;
+assert(V.Out);
+return *V.Out;
   }
 
   Macro findMacro(llvm::StringRef Name) {
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -1,5 +1,4 @@
 set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
   Support
   TestingSupport
   )
@@ -21,7 +20,6 @@
 clang_target_link_libraries(ClangIncludeCleanerTests
   PRIVATE
   clangAST
-  clangASTMatchers
   clangBasic
   clangFrontend
   clangLex


Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -9,14 +9,12 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -53,27 +51,23 @@
 }()) {}
 
   const Decl &findDecl(llvm::StringRef SymbolName) {
-const NamedDecl *DeclToLocate;
-struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
-  MatchCB(const NamedDecl *&Out) : Out(Out) {}
-  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
-Out = Result.Nodes.getNodeAs("id");
-assert(Out);
-Out = llvm::cast(Out->getCanonicalDecl());
+struct Visitor : RecursiveASTVisitor {
+  llvm::StringRef NameToFind;
+  const NamedDecl *Out = nullptr;
+  bool VisitNamedDecl(const NamedDecl

[PATCH] D139090: [clang] Add test for CWG360

2022-12-01 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill updated this revision to Diff 479225.
Endill added a comment.

run make_cxx_dr_status


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

https://reviews.llvm.org/D139090

Files:
  clang/test/CXX/drs/dr3xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2200,7 +2200,7 @@
 https://wg21.link/cwg360";>360
 CD6
 Using-declaration that reduces access
-Unknown
+Yes
   
   
 https://wg21.link/cwg361";>361
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -890,6 +890,33 @@
   };
 }
 
+namespace dr360 { // dr360: yes
+struct A {
+  int foo();
+  int bar();
+
+protected:
+  int baz();
+};
+
+struct B : A {
+private:
+  using A::foo; // #dr360-foo-using-decl
+protected:
+  using A::bar; // #dr360-bar-using-decl
+public:
+  using A::baz; // #dr360-baz-using-decl
+};
+
+int main() {
+  int foo = B().foo(); // expected-error {{is a private member}}
+  // expected-note@#dr360-foo-using-decl {{declared private here}}
+  int bar = B().bar(); // expected-error {{is a protected member}}
+  // expected-note@#dr360-bar-using-decl {{declared protected here}}
+  int baz = B().baz();
+}
+} // namespace dr360
+
 // dr362: na
 // dr363: na
 


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2200,7 +2200,7 @@
 https://wg21.link/cwg360";>360
 CD6
 Using-declaration that reduces access
-Unknown
+Yes
   
   
 https://wg21.link/cwg361";>361
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -890,6 +890,33 @@
   };
 }
 
+namespace dr360 { // dr360: yes
+struct A {
+  int foo();
+  int bar();
+
+protected:
+  int baz();
+};
+
+struct B : A {
+private:
+  using A::foo; // #dr360-foo-using-decl
+protected:
+  using A::bar; // #dr360-bar-using-decl
+public:
+  using A::baz; // #dr360-baz-using-decl
+};
+
+int main() {
+  int foo = B().foo(); // expected-error {{is a private member}}
+  // expected-note@#dr360-foo-using-decl {{declared private here}}
+  int bar = B().bar(); // expected-error {{is a protected member}}
+  // expected-note@#dr360-bar-using-decl {{declared protected here}}
+  int baz = B().baz();
+}
+} // namespace dr360
+
 // dr362: na
 // dr363: na
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-01 Thread Dave Green via Phabricator via cfe-commits
dmgreen added a comment.

I can only comment on the target features part of the patch - I've been hoping 
it would add something similar and looks very useful in its own right.




Comment at: clang/lib/Basic/Targets/AArch64.cpp:63
+  switch (ArchKind) {
+  case llvm::AArch64::ArchKind::ARMV8_8A:
+  case llvm::AArch64::ArchKind::ARMV8_7A:

There can be an 8.9 / 9.4 now.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:1020
 
-  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
+  // Add target and fmv features.
+  for (const auto &Feature : FeaturesVec)

fmv features -> dependant features.
Can you add a comment explaining the two loops? I assume it is because the 
second could be -, turning off features that have been turned on?



Comment at: clang/test/CodeGen/aarch64-targetattr.c:93
 // CHECK: attributes #0 = { {{.*}} "target-features"="+v8.1a,+v8.2a,+v8a" }
-// CHECK: attributes #1 = { {{.*}} "target-features"="+sve,+v8.1a,+v8.2a,+v8a" 
}
-// CHECK: attributes #2 = { {{.*}} 
"target-features"="+sve2,+v8.1a,+v8.2a,+v8a" }
-// CHECK: attributes #4 = { {{.*}} 
"target-features"="+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" }
-// CHECK: attributes #5 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+i8mm,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
-// CHECK: attributes #6 = { {{.*}} "tune-cpu"="cortex-a710" }
-// CHECK: attributes #7 = { {{.*}} "target-cpu"="generic" }
-// CHECK: attributes #8 = { {{.*}} "tune-cpu"="generic" }
-// CHECK: attributes #9 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+crc,+crypto,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+spe,+ssbs"
 "tune-cpu"="cortex-a710" }
-// CHECK: attributes #10 = { {{.*}} "target-features"="+sve" 
"tune-cpu"="cortex-a710" }
-// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+bf16,+crc,+crypto,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+spe,+ssbs,+sve,+sve2"
 }
-// CHECK: attributes #12 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+bf16,+crc,+crypto,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+spe,+ssbs,-sve"
 }
-// CHECK: attributes #13 = { {{.*}} "target-features"="+sve" }
-// CHECK: attributes #14 = { {{.*}} "target-features"="+sve,-sve2" }
-// CHECK: attributes #15 = { {{.*}} "target-features"="+fullfp16" }
-// CHECK: attributes #16 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+crc,+crypto,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+spe,+ssbs,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
-// CHECK: attributes #17 = { {{.*}} "branch-target-enforcement"="true" {{.*}} 
"target-cpu"="neoverse-n1" 
"target-features"="+crc,+crypto,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+spe,+ssbs,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
-// CHECK: attributes #18 = { {{.*}} "target-features"="-neon" }
+// CHECK: attributes #1 = { {{.*}} 
"target-features"="+complxnum,+fp-armv8,+fullfp16,+jsconv,+neon,+sve,+v8.1a,+v8.2a,+v8a"
 }
+// CHECK: attributes #2 = { {{.*}} 
"target-features"="+complxnum,+fp-armv8,+fullfp16,+jsconv,+neon,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }

These updates look good, thanks for the improvements!



Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:107
+AARCH64_ARCH_EXT_NAME("invalid",   AArch64::AEK_INVALID, {},   
   {}, \
+MAX,  "",  
  0)
+AARCH64_ARCH_EXT_NAME("none",  AArch64::AEK_NONE,{},   
   {}, \

This table could maybe be formatted a little more nicely. LLVM's clang format 
style would usually align the `(` and the next line. Perhaps putting the last 
integer before the string can help too.
```
AARCH64_ARCH_EXT_NAME("invalid",   AArch64::AEK_INVALID, {},
  {}, \
  MAX, 0, "")
```
We could alternatively just clang-format the whole thing.



Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:115
+AARCH64_ARCH_EXT_NAME("rdm",   AArch64::AEK_RDM, "+rdm",   
   "-rdm", \
+RDM,  "+rdm,+fp-armv8,+neon,+jsconv,+complxnum",   
 70)
+AARCH64_ARCH_EXT_NAME("crypto",AArch64::AEK_CRYPTO,  "+crypto",
   "-crypto",  \

Should RDM be dependant on +jsconv,+complxnum?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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

[PATCH] D138821: [include-cleaner] Remove filtering from UsingDecl visit.

2022-12-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:86
   report(UD->getLocation(), TD,
  IsUsed ? RefType::Explicit : RefType::Ambiguous);
 }

VitaNuo wrote:
> kadircet wrote:
> > hokein wrote:
> > > we should report all references as explicit.
> > i think having `Ambiguous` here for unused symbols is fine. we'd like to 
> > consider such symbols for the purposes of saying "yeah this include is 
> > probably used" but we shouldn't be inserting headers for the unused ones.
> > 
> > do we have an example for the contrary?
> @hokein so what would be the final conclusion then? Should I re-introduce the 
> "isUsed" check?
oh, right. `Ambiguous` is better, this is similar to OverloadExpr, we can't 
prove that the symbol is used. (sorry, I somewhat had an impression this should 
be explicit).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138821

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


[PATCH] D139093: [include-cleaner] Use RAV instead of ASTMatchers in LocateSymbolTest

2022-12-01 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp:60
+  return true;
+Out = ND;
+return false;

you might want to EXPECT_EQ(Out, nullptr) first to ensure only a single match

(A single match for a name may not generalize well, but the matching would have 
to be made more specific regardless in that case)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139093

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:152
+  case CK_FloatingToIntegral: {
+llvm::RoundingMode RM = getRoundingMode(CE);
+Optional ToT = classify(CE->getType());

sepavloff wrote:
> According to C standard (6.3.1.4p1):
> ```
> When a finite value of real floating type is converted to an integer type 
> other than _Bool, the fractional part is discarded (i.e., the value is 
> truncated toward zero).
> ```
> So the conversion should not depend on rounding mode. The same applies to the 
> conversion to boolean (6.3.1.2p1):
> ```
> When any scalar value is converted to _Bool, the result is 0 if the value 
> compares equal to 0; otherwise, the result is 1.
> ```
> 
So this is a difference between C and C++?



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:617
   case BO_SubAssign:
 if (!this->emitSub(*LT, E))
   return false;

sepavloff wrote:
> This and some subsequent operations also should depend on rounding mode?
Yes, I did `add` as an example, the others will have to follow.



Comment at: clang/lib/AST/Interp/Floating.h:109
+Floating RHS = B;
+if (!A.compatibleWith(B))
+  RHS = B.toSemantics(A, RM);

sepavloff wrote:
> Do we really need this check? In AST operands of addition always have the 
> same type.
In https://godbolt.org/z/s4n75jc4h, the LHS of the `CompoundAssignOperator` is 
float while the RHS is double


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

https://reviews.llvm.org/D134859

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


[PATCH] D139093: [include-cleaner] Use RAV instead of ASTMatchers in LocateSymbolTest

2022-12-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked an inline comment as done.
kadircet added inline comments.



Comment at: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp:60
+  return true;
+Out = ND;
+return false;

sammccall wrote:
> you might want to EXPECT_EQ(Out, nullptr) first to ensure only a single match
> 
> (A single match for a name may not generalize well, but the matching would 
> have to be made more specific regardless in that case)
we expect to see multiple declarations for the same entity anyway though, so 
instead of asserting null, i'll assert same canonical or null.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139093

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


[clang-tools-extra] 4764ee6 - [include-cleaner] Use RAV instead of ASTMatchers in LocateSymbolTest

2022-12-01 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-12-01T12:35:34+01:00
New Revision: 4764ee6055c7ea1cd4818a2a5c496861c371660a

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

LOG: [include-cleaner] Use RAV instead of ASTMatchers in LocateSymbolTest

ASTMatchers are pulling in lots of dependencies that we don't really
need for just finding a decl based on name. So use a simple RAV instead.

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
index 11d93f526f3c..d911b5df70c5 100644
--- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -1,5 +1,4 @@
 set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
   Support
   TestingSupport
   )
@@ -21,7 +20,6 @@ target_include_directories(ClangIncludeCleanerTests
 clang_target_link_libraries(ClangIncludeCleanerTests
   PRIVATE
   clangAST
-  clangASTMatchers
   clangBasic
   clangFrontend
   clangLex

diff  --git a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
index f347db927e27..7d0fd1b56e09 100644
--- a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -9,14 +9,12 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -53,27 +51,25 @@ struct LocateExample {
 }()) {}
 
   const Decl &findDecl(llvm::StringRef SymbolName) {
-const NamedDecl *DeclToLocate;
-struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
-  MatchCB(const NamedDecl *&Out) : Out(Out) {}
-  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
-Out = Result.Nodes.getNodeAs("id");
-assert(Out);
-Out = llvm::cast(Out->getCanonicalDecl());
+struct Visitor : RecursiveASTVisitor {
+  llvm::StringRef NameToFind;
+  const NamedDecl *Out = nullptr;
+  bool VisitNamedDecl(const NamedDecl *ND) {
+if (ND->getName() == NameToFind) {
+  EXPECT_TRUE(Out == nullptr || Out == ND->getCanonicalDecl())
+  << "Found multiple matches for " << NameToFind;
+  Out = cast(ND->getCanonicalDecl());
+}
+return true;
   }
-  const NamedDecl *&Out;
-} CB(DeclToLocate);
-ast_matchers::MatchFinder Finder;
-Finder.addMatcher(ast_matchers::namedDecl(
-  ast_matchers::unless(ast_matchers::isImplicit()),
-  ast_matchers::hasName(SymbolName))
-  .bind("id"),
-  &CB);
-Finder.matchAST(AST.context());
-if (!DeclToLocate)
+};
+Visitor V;
+V.NameToFind = SymbolName;
+V.TraverseDecl(AST.context().getTranslationUnitDecl());
+if (!V.Out)
   ADD_FAILURE() << "Couldn't find any decls with name: " << SymbolName;
-assert(DeclToLocate);
-return *DeclToLocate;
+assert(V.Out);
+return *V.Out;
   }
 
   Macro findMacro(llvm::StringRef Name) {



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


[PATCH] D139093: [include-cleaner] Use RAV instead of ASTMatchers in LocateSymbolTest

2022-12-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
kadircet marked an inline comment as done.
Closed by commit rG4764ee6055c7: [include-cleaner] Use RAV instead of 
ASTMatchers in LocateSymbolTest (authored by kadircet).

Changed prior to commit:
  https://reviews.llvm.org/D139093?vs=479224&id=479229#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139093

Files:
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -9,14 +9,12 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -53,27 +51,25 @@
 }()) {}
 
   const Decl &findDecl(llvm::StringRef SymbolName) {
-const NamedDecl *DeclToLocate;
-struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
-  MatchCB(const NamedDecl *&Out) : Out(Out) {}
-  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
-Out = Result.Nodes.getNodeAs("id");
-assert(Out);
-Out = llvm::cast(Out->getCanonicalDecl());
+struct Visitor : RecursiveASTVisitor {
+  llvm::StringRef NameToFind;
+  const NamedDecl *Out = nullptr;
+  bool VisitNamedDecl(const NamedDecl *ND) {
+if (ND->getName() == NameToFind) {
+  EXPECT_TRUE(Out == nullptr || Out == ND->getCanonicalDecl())
+  << "Found multiple matches for " << NameToFind;
+  Out = cast(ND->getCanonicalDecl());
+}
+return true;
   }
-  const NamedDecl *&Out;
-} CB(DeclToLocate);
-ast_matchers::MatchFinder Finder;
-Finder.addMatcher(ast_matchers::namedDecl(
-  ast_matchers::unless(ast_matchers::isImplicit()),
-  ast_matchers::hasName(SymbolName))
-  .bind("id"),
-  &CB);
-Finder.matchAST(AST.context());
-if (!DeclToLocate)
+};
+Visitor V;
+V.NameToFind = SymbolName;
+V.TraverseDecl(AST.context().getTranslationUnitDecl());
+if (!V.Out)
   ADD_FAILURE() << "Couldn't find any decls with name: " << SymbolName;
-assert(DeclToLocate);
-return *DeclToLocate;
+assert(V.Out);
+return *V.Out;
   }
 
   Macro findMacro(llvm::StringRef Name) {
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -1,5 +1,4 @@
 set(LLVM_LINK_COMPONENTS
-  FrontendOpenMP
   Support
   TestingSupport
   )
@@ -21,7 +20,6 @@
 clang_target_link_libraries(ClangIncludeCleanerTests
   PRIVATE
   clangAST
-  clangASTMatchers
   clangBasic
   clangFrontend
   clangLex


Index: clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp
@@ -9,14 +9,12 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Testing/Support/Annotations.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -53,27 +51,25 @@
 }()) {}
 
   const Decl &findDecl(llvm::StringRef SymbolName) {
-const NamedDecl *DeclToLocate;
-struct MatchCB : public ast_matchers::MatchFinder::MatchCallback {
-  MatchCB(const NamedDecl *&Out) : Out(Out) {}
-  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
-Out = Result.Nodes.getNodeAs("id");
-assert(Out);
-Out = llvm::cast(Out->getCanonicalDecl());
+struct Visitor : Recurs

[PATCH] D138378: [clang-format][NFC] Skip unneeded calculations

2022-12-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

I ran (on macOS Ventura) the release build of clang-format 8627811 
 on the 
entire clang codebase and saw only a 0.12% reduction in runtime, which is what 
I expected.

|   | Run 1   | Run 2   | Run 3   | Average |
| w/o patch | 50.107s | 50.082s | 50.120s | 50.103s |
| w/ patch  | 50.031s | 49.998s | 50.094s | 50.041s |
|




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

https://reviews.llvm.org/D138378

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


[PATCH] D138378: [clang-format][NFC] Skip unneeded calculations

2022-12-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

To my surprise, tools/clang/unittests/Format/FormatTests with the patch ran a 
little bit slower:

|   | Run 1  | Run 2  | Run 3  | Average |
| w/o patch | 2707ms | 2697ms | 2710ms | 2705ms  |
| w/ patch  | 2720ms | 2719ms | 2724ms | 2721ms  |


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

https://reviews.llvm.org/D138378

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


[PATCH] D105584: [MLIR][OpenMP] Distribute Construct Operation

2022-12-01 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

In D105584#3954144 , 
@abidmalikwaterloo wrote:

> In D105584#3917238 , 
> @kiranchandramohan wrote:
>
>> Patch probably needs a rebase. A few more minor things to fix. Looks mostly 
>> ready.
>
> With which branch should I rebase?  I have taken care rest of the comments. 
> Thanks!

Rebase to the main branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105584

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


[PATCH] D139095: [clang] Mark CWG405 as a duplicate of CWG218

2022-12-01 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added a reviewer: clang-language-wg.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139095

Files:
  clang/test/CXX/drs/dr4xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2470,7 +2470,7 @@
 https://wg21.link/cwg405";>405
 CD6
 Unqualified function name lookup
-Unknown
+Duplicate of 218
   
   
 https://wg21.link/cwg406";>406
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -79,6 +79,8 @@
 // dr404: na
 // (NB: also sup 594)
 
+// dr405: dup 218
+
 namespace dr406 { // dr406: yes
   typedef struct {
 static int n; // expected-error {{static data member 'n' not allowed in 
anonymous struct}}


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2470,7 +2470,7 @@
 https://wg21.link/cwg405";>405
 CD6
 Unqualified function name lookup
-Unknown
+Duplicate of 218
   
   
 https://wg21.link/cwg406";>406
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -79,6 +79,8 @@
 // dr404: na
 // (NB: also sup 594)
 
+// dr405: dup 218
+
 namespace dr406 { // dr406: yes
   typedef struct {
 static int n; // expected-error {{static data member 'n' not allowed in anonymous struct}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:65
+Expr *BE = E->getBase()->IgnoreImpCasts();
+RecordDecl *RD = BE->getType()->getAsRecordDecl();
+report(E->getMemberLoc(), RD);

This is not safe, we can get a nullptr if this type is not a normal 
`RecordType`.

I think there are more cases we need to handle:
1) pointer type (`Derived *`)
2) reference type (`Derived &`)
3) a dependent type

For the 3), some code like `std::vector().size()`, it is tricky -- because 
we can't get any decl from a dependent type, we need some heuristics (in clangd 
we have some bits), we don't need to do that in this patch.

In the code implementation, we should add a dedicated `handleType(QualType)` 
helper to handle all these cases, so `VisitMemberExpr`, 
`VisitCXXDependentScopeMemberExpr` callbacks can just dispatch the type to this 
helper.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-01 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added inline comments.



Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:115
+AARCH64_ARCH_EXT_NAME("rdm",   AArch64::AEK_RDM, "+rdm",   
   "-rdm", \
+RDM,  "+rdm,+fp-armv8,+neon,+jsconv,+complxnum",   
 70)
+AARCH64_ARCH_EXT_NAME("crypto",AArch64::AEK_CRYPTO,  "+crypto",
   "-crypto",  \

dmgreen wrote:
> Should RDM be dependant on +jsconv,+complxnum?
I suppose RDM implies simd (+neon) which implies +jsconv,+complxnum


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[clang-tools-extra] 00b9cef - [clangd] Log diagnostics if we failed to create a preamble.

2022-12-01 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-12-01T13:25:15+01:00
New Revision: 00b9cefacbdf0ac764576c52fad6177aea2ed6b8

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

LOG: [clangd] Log diagnostics if we failed to create a preamble.

Really we want these to be shown to the client, but the path to do so involves
storing them in

Bandaid for https://github.com/clangd/clangd/issues/1408
See https://github.com/clangd/clangd/issues/1399 for motivation

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

Added: 


Modified: 
clang-tools-extra/clangd/Preamble.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index 337f71bed9bae..d2b91894f11b4 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -571,6 +571,12 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
 
   elog("Could not build a preamble for file {0} version {1}: {2}", FileName,
Inputs.Version, BuiltPreamble.getError().message());
+  for (const Diag &D : PreambleDiagnostics.take()) {
+if (D.Severity < DiagnosticsEngine::Error)
+  continue;
+// Not an ideal way to show errors, but better than nothing!
+elog("  error: {0}", D.Message);
+  }
   return nullptr;
 }
 



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


[PATCH] D139088: [clangd] Log diagnostics if we failed to create a preamble.

2022-12-01 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG00b9cefacbdf: [clangd] Log diagnostics if we failed to 
create a preamble. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139088

Files:
  clang-tools-extra/clangd/Preamble.cpp


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -571,6 +571,12 @@
 
   elog("Could not build a preamble for file {0} version {1}: {2}", FileName,
Inputs.Version, BuiltPreamble.getError().message());
+  for (const Diag &D : PreambleDiagnostics.take()) {
+if (D.Severity < DiagnosticsEngine::Error)
+  continue;
+// Not an ideal way to show errors, but better than nothing!
+elog("  error: {0}", D.Message);
+  }
   return nullptr;
 }
 


Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -571,6 +571,12 @@
 
   elog("Could not build a preamble for file {0} version {1}: {2}", FileName,
Inputs.Version, BuiltPreamble.getError().message());
+  for (const Diag &D : PreambleDiagnostics.take()) {
+if (D.Severity < DiagnosticsEngine::Error)
+  continue;
+// Not an ideal way to show errors, but better than nothing!
+elog("  error: {0}", D.Message);
+  }
   return nullptr;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f57f086 - [AArch64TargetParser] getArchFeatures -> getArchFeature

2022-12-01 Thread Tomas Matheson via cfe-commits

Author: Tomas Matheson
Date: 2022-12-01T12:50:17Z
New Revision: f57f086714bc7a1399acf05d5ca1d665237cd725

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

LOG: [AArch64TargetParser] getArchFeatures -> getArchFeature

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

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index fb3d0b553542a..c36e942cf46ac 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -810,12 +810,9 @@ ParsedTargetAttr 
AArch64TargetInfo::parseTargetAttr(StringRef Features) const {
 
   // Parse the architecture version, adding the required features to
   // Ret.Features.
-  std::vector FeatureStrs;
-  if (ArchKind == llvm::AArch64::ArchKind::INVALID ||
-  !llvm::AArch64::getArchFeatures(ArchKind, FeatureStrs))
+  if (ArchKind == llvm::AArch64::ArchKind::INVALID)
 continue;
-  for (auto R : FeatureStrs)
-Ret.Features.push_back(R.str());
+  Ret.Features.push_back(llvm::AArch64::getArchFeature(ArchKind).str());
   // Add any extra features, after the +
   SplitAndAddFeatures(Split.second, Ret.Features);
 } else if (Feature.startswith("cpu=")) {

diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 2a5c4718d084a..2a1269316bc75 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -135,8 +135,9 @@ static bool DecodeAArch64Mcpu(const Driver &D, StringRef 
Mcpu, StringRef &CPU,
 Features.push_back("+neon");
   } else {
 ArchKind = llvm::AArch64::parseCPUArch(CPU);
-if (!llvm::AArch64::getArchFeatures(ArchKind, Features))
+if (ArchKind == llvm::AArch64::ArchKind::INVALID)
   return false;
+Features.push_back(llvm::AArch64::getArchFeature(ArchKind));
 
 uint64_t Extension = llvm::AArch64::getDefaultExtensions(CPU, ArchKind);
 if (!llvm::AArch64::getExtensionFeatures(Extension, Features))
@@ -160,9 +161,9 @@ getAArch64ArchFeaturesFromMarch(const Driver &D, StringRef 
March,
   llvm::AArch64::ArchKind ArchKind = llvm::AArch64::parseArch(Split.first);
   if (Split.first == "native")
 ArchKind = 
llvm::AArch64::getCPUArchKind(llvm::sys::getHostCPUName().str());
-  if (ArchKind == llvm::AArch64::ArchKind::INVALID ||
-  !llvm::AArch64::getArchFeatures(ArchKind, Features))
+  if (ArchKind == llvm::AArch64::ArchKind::INVALID)
 return false;
+  Features.push_back(llvm::AArch64::getArchFeature(ArchKind));
 
   // Enable SVE2 by default on Armv9-A.
   // It can still be disabled if +nosve2 is present.

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.h 
b/llvm/include/llvm/Support/AArch64TargetParser.h
index ccee51f6bc1e8..5347c4e1f5e34 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.h
+++ b/llvm/include/llvm/Support/AArch64TargetParser.h
@@ -160,7 +160,7 @@ inline ArchKind &operator--(ArchKind &Kind) {
 
 bool getExtensionFeatures(uint64_t Extensions,
   std::vector &Features);
-bool getArchFeatures(ArchKind AK, std::vector &Features);
+StringRef getArchFeature(ArchKind AK);
 
 StringRef getArchName(ArchKind AK);
 StringRef getSubArch(ArchKind AK);

diff  --git a/llvm/lib/Support/AArch64TargetParser.cpp 
b/llvm/lib/Support/AArch64TargetParser.cpp
index e13b061eabb2d..aecb193e409a8 100644
--- a/llvm/lib/Support/AArch64TargetParser.cpp
+++ b/llvm/lib/Support/AArch64TargetParser.cpp
@@ -80,12 +80,8 @@ StringRef AArch64::resolveCPUAlias(StringRef CPU) {
   .Default(CPU);
 }
 
-bool AArch64::getArchFeatures(AArch64::ArchKind AK,
-  std::vector &Features) {
-  if (AK == ArchKind::INVALID)
-return false;
-  Features.push_back(AArch64ARCHNames[static_cast(AK)].ArchFeature);
-  return true;
+StringRef AArch64::getArchFeature(AArch64::ArchKind AK) {
+  return AArch64ARCHNames[static_cast(AK)].ArchFeature;
 }
 
 StringRef AArch64::getArchName(AArch64::ArchKind AK) {

diff  --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp 
b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index 8556bd7c6d875..53290c6e8c196 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -6889,7 +6889,7 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
 
   // Get the architecture and extension features.
   std::v

[clang] 450de80 - [AArch64] Improve TargetParser API

2022-12-01 Thread Tomas Matheson via cfe-commits

Author: Tomas Matheson
Date: 2022-12-01T12:50:23Z
New Revision: 450de8008bb0ccb5dfc9dd69b6f5b434158772bd

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

LOG: [AArch64] Improve TargetParser API

The TargetParser depends heavily on a collection of macros and enums to tie
together information about architectures, CPUs and extensions. Over time this
has led to some pretty awkward API choices. For example, recently a custom
operator-- has been added to the enum, which effectively turns iteration into
a graph traversal and makes the ordering of the macro calls in the header
significant. More generally there is a lot of string <-> enum conversion
going on. I think this shows the extent to which the current data structures
are constraining us, and the need for a rethink.

Key changes:

 - Get rid of Arch enum, which is used to bind fields together. Instead of
   passing around ArchKind, use the named ArchInfo objects directly or via
   references.

 - The list of all known ArchInfo becomes an array of pointers.

 - ArchKind::operator-- is replaced with ArchInfo::implies(), which defines
   which architectures are predecessors to each other. This allows features
   from predecessor architectures to be added in a more intuitive way.

 - Free functions of the form f(ArchKind) are converted to ArchInfo::f(). Some
   functions become unnecessary and are deleted.

 - Version number and profile are added to the ArchInfo. This makes comparison
   of architectures easier and moves a couple of functions out of clang and
   into AArch64TargetParser.

 - clang::AArch64TargetInfo ArchInfo is initialised to Armv8a not INVALID.

 - AArch64::ArchProfile which is distinct from ARM::ArchProfile

 - Give things sensible names and add some comments.

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

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/include/llvm/Support/VersionTuple.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c36e942cf46ac..edc4fdca26378 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -45,28 +45,6 @@ const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
 #include "clang/Basic/BuiltinsAArch64.def"
 };
 
-static StringRef getArchVersionString(llvm::AArch64::ArchKind Kind) {
-  switch (Kind) {
-  case llvm::AArch64::ArchKind::ARMV9A:
-  case llvm::AArch64::ArchKind::ARMV9_1A:
-  case llvm::AArch64::ArchKind::ARMV9_2A:
-  case llvm::AArch64::ArchKind::ARMV9_3A:
-  case llvm::AArch64::ArchKind::ARMV9_4A:
-return "9";
-  default:
-return "8";
-  }
-}
-
-StringRef AArch64TargetInfo::getArchProfile() const {
-  switch (ArchKind) {
-  case llvm::AArch64::ArchKind::ARMV8R:
-return "R";
-  default:
-return "A";
-  }
-}
-
 AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : TargetInfo(Triple), ABI("aapcs") {
@@ -170,7 +148,7 @@ bool AArch64TargetInfo::validateBranchProtection(StringRef 
Spec, StringRef,
 
 bool AArch64TargetInfo::isValidCPUName(StringRef Name) const {
   return Name == "generic" ||
- llvm::AArch64::parseCPUArch(Name) != llvm::AArch64::ArchKind::INVALID;
+ llvm::AArch64::parseCpu(Name).Arch != llvm::AArch64::INVALID;
 }
 
 bool AArch64TargetInfo::setCPU(const std::string &Name) {
@@ -298,8 +276,10 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   // ACLE predefines. Many can only have one possible value on v8 AArch64.
   Builder.defineMacro("__ARM_ACLE", "200");
-  Builder.defineMacro("__ARM_ARCH", getArchVersionString(ArchKind));
-  Builder.defineMacro("__ARM_ARCH_PROFILE", "'" + getArchProfile() + "'");
+  Builder.defineMacro("__ARM_ARCH",
+  std::to_string(ArchInfo->Version.getMajor()));
+  Builder.defineMacro("__ARM_ARCH_PROFILE",
+  std::string("'") + (char)ArchInfo->Profile + "'");
 
   Builder.defineMacro("__ARM_64BIT_STATE", "1");
   Builder.defineMacro("__ARM_PCS_AAPCS64", "1");
@@ -464,52 +444,34 @@ void AArch64TargetInfo::getTargetDefines(const 
LangOptions &Opts,
   if (HasD128)
 Builder.defineMacro("__ARM_FEATURE_SYSREG128", "1");
 
-  switch (ArchKind) {
-  default:
-break;
-  case llvm::AArch64::ArchKind::ARMV8_1A:
+  if (*ArchInfo == llvm::AArch64::ARMV8_1A)
 getTargetDefinesARMV81A(Opts, Builder);
-  

[PATCH] D138753: [AArch64TargetParser] getArchFeatures -> getArchFeature

2022-12-01 Thread Tomas Matheson 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 rGf57f086714bc: [AArch64TargetParser] getArchFeatures -> 
getArchFeature (authored by tmatheson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138753

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1689,14 +1689,23 @@
 }
 
 TEST(TargetParserTest, AArch64ArchFeatures) {
-  std::vector Features;
-
-  for (auto AK : AArch64::ArchKinds) {
-if (AK == AArch64::ArchKind::INVALID)
-  EXPECT_FALSE(AArch64::getArchFeatures(AK, Features));
-else
-  EXPECT_TRUE(AArch64::getArchFeatures(AK, Features));
-  }
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::INVALID), "+");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8A), "+v8a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_1A), "+v8.1a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_2A), "+v8.2a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_3A), "+v8.3a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_4A), "+v8.4a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_5A), "+v8.5a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_6A), "+v8.6a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_7A), "+v8.7a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_8A), "+v8.8a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8_9A), "+v8.9a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9A), "+v9a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_1A), "+v9.1a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_2A), "+v9.2a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_3A), "+v9.3a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV9_4A), "+v9.4a");
+  EXPECT_EQ(AArch64::getArchFeature(AArch64::ArchKind::ARMV8R), "+v8r");
 }
 
 TEST(TargetParserTest, AArch64ArchV9toV8Conversion) {
Index: llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
===
--- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -6889,7 +6889,7 @@
 
   // Get the architecture and extension features.
   std::vector AArch64Features;
-  AArch64::getArchFeatures(ID, AArch64Features);
+  AArch64Features.push_back(AArch64::getArchFeature(ID));
   AArch64::getExtensionFeatures(AArch64::getDefaultExtensions("generic", ID),
 AArch64Features);
 
Index: llvm/lib/Support/AArch64TargetParser.cpp
===
--- llvm/lib/Support/AArch64TargetParser.cpp
+++ llvm/lib/Support/AArch64TargetParser.cpp
@@ -80,12 +80,8 @@
   .Default(CPU);
 }
 
-bool AArch64::getArchFeatures(AArch64::ArchKind AK,
-  std::vector &Features) {
-  if (AK == ArchKind::INVALID)
-return false;
-  Features.push_back(AArch64ARCHNames[static_cast(AK)].ArchFeature);
-  return true;
+StringRef AArch64::getArchFeature(AArch64::ArchKind AK) {
+  return AArch64ARCHNames[static_cast(AK)].ArchFeature;
 }
 
 StringRef AArch64::getArchName(AArch64::ArchKind AK) {
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -160,7 +160,7 @@
 
 bool getExtensionFeatures(uint64_t Extensions,
   std::vector &Features);
-bool getArchFeatures(ArchKind AK, std::vector &Features);
+StringRef getArchFeature(ArchKind AK);
 
 StringRef getArchName(ArchKind AK);
 StringRef getSubArch(ArchKind AK);
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -135,8 +135,9 @@
 Features.push_back("+neon");
   } else {
 ArchKind = llvm::AArch64::parseCPUArch(CPU);
-if (!llvm::AArch64::getArchFeatures(ArchKind, Features))
+if (ArchKind == llvm::AArch64::ArchKind::INVALID)
   return false;
+Features.push_back(llvm::AArch64::getArchFeature(ArchKind));
 
 uint64_t Extension = llvm::AArch64::getDefaultExtensions(CPU, ArchKind);
 if (!ll

[PATCH] D138792: [AArch64] Improve TargetParser API

2022-12-01 Thread Tomas Matheson 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 rG450de8008bb0: [AArch64] Improve TargetParser API (authored 
by tmatheson).

Changed prior to commit:
  https://reviews.llvm.org/D138792?vs=478617&id=479249#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138792

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/include/llvm/Support/VersionTuple.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -952,11 +952,11 @@
 TEST_P(AArch64CPUTestFixture, testAArch64CPU) {
   ARMCPUTestParams params = GetParam();
 
-  AArch64::ArchKind AK = AArch64::parseCPUArch(params.CPUName);
-  EXPECT_EQ(params.ExpectedArch, AArch64::getArchName(AK));
+  const AArch64::ArchInfo &AI = AArch64::parseCpu(params.CPUName).Arch;
+  EXPECT_EQ(params.ExpectedArch, AI.Name);
 
   uint64_t default_extensions =
-  AArch64::getDefaultExtensions(params.CPUName, AK);
+  AArch64::getDefaultExtensions(params.CPUName, AI);
   EXPECT_PRED_FORMAT2(AssertSameExtensionFlags,
   params.ExpectedFlags, default_extensions);
 }
@@ -1402,14 +1402,14 @@
   // valid, and match the expected 'magic' count.
   EXPECT_EQ(List.size(), NumAArch64CPUArchs);
   for(StringRef CPU : List) {
-EXPECT_NE(AArch64::parseCPUArch(CPU), AArch64::ArchKind::INVALID);
+EXPECT_NE(AArch64::parseCpu(CPU).Arch, AArch64::INVALID);
   }
 }
 
 bool testAArch64Arch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
  unsigned ArchAttr) {
-  AArch64::ArchKind AK = AArch64::parseArch(Arch);
-  return AK != AArch64::ArchKind::INVALID;
+  const AArch64::ArchInfo &AI = AArch64::parseArch(Arch);
+  return AI != AArch64::INVALID;
 }
 
 TEST(TargetParserTest, testAArch64Arch) {
@@ -1445,148 +1445,81 @@
   ARMBuildAttrs::CPUArch::v8_A));
 }
 
-bool testAArch64Extension(StringRef CPUName, AArch64::ArchKind AK,
+bool testAArch64Extension(StringRef CPUName, const AArch64::ArchInfo &AI,
   StringRef ArchExt) {
-  return AArch64::getDefaultExtensions(CPUName, AK) &
+  return AArch64::getDefaultExtensions(CPUName, AI) &
  AArch64::parseArchExt(ArchExt);
 }
 
 TEST(TargetParserTest, testAArch64Extension) {
-  EXPECT_FALSE(testAArch64Extension("cortex-a34",
-AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a35",
-AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a53",
-AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a55",
-AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a55",
-AArch64::ArchKind::INVALID, "fp16"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a55",
-AArch64::ArchKind::INVALID, "fp16fml"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a55",
-AArch64::ArchKind::INVALID, "dotprod"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a57",
-AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a72",
-AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a73",
-AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a75",
-AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a75",
-AArch64::ArchKind::INVALID, "fp16"));
-  EXPECT_FALSE(testAArch64Extension("cortex-a75",
-AArch64::ArchKind::INVALID, "fp16fml"));
-  EXPECT_TRUE(testAArch64Extension("cortex-a75",
-   AArch64::ArchKind::INVALID, "dotprod"));
-  EXPECT_TRUE(testAArch64Extension("cortex-r82",
-   AArch64::ArchKind::INVALID, "ras"));
-  EXPECT_TRUE(testAArch64Extension("cortex-r82",
-   AArch64::ArchKind::INVALID, "fp16"));
-  EXPECT_TRUE(testAArch64Extension("cortex-r82",
-   AArch64::ArchKind::INVALID, "fp16fml"));
-  EXPE

[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:5395-5400
+  // FIXME: Tell the user this is unsupported.
+  if (!Stmts.empty()) {
+unsigned ID = Actions.getDiagnostics().getCustomDiagID(
+DiagnosticsEngine::Error, "Unsupported statement on the global scope");
+Actions.Diag(Stmts.back()->getBeginLoc(), ID);
+  }

v.g.vassilev wrote:
> aaron.ballman wrote:
> > Why is this using a custom diagnostic instead of adding a typical 
> > diagnostic to DiagnosticParseKinds.td?
> I don't have a problem converting this to a DiagnosticParseKind. However, 
> this is a temporary diagnostic and we risk once the FIXME is resolved to 
> leave a stray diagnostic id. 
It's been my experience that there's nothing more permanent than a temporary 
solution, so I'd say we should go with the regular diagnostic. Also, it should 
be worded `unsupported statement at global scope` to fit the usual diagnostic 
wording style.


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

https://reviews.llvm.org/D127284

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


[clang] d1ef4b0 - Revert "[AArch64] Improve TargetParser API"

2022-12-01 Thread Tomas Matheson via cfe-commits

Author: Tomas Matheson
Date: 2022-12-01T13:06:54Z
New Revision: d1ef4b0a8da152fe4282f97c7c49f4930a3c66a2

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

LOG: Revert "[AArch64] Improve TargetParser API"

Buildbots unhappy about constexpr function.

This reverts commit 450de8008bb0ccb5dfc9dd69b6f5b434158772bd.

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/include/llvm/Support/VersionTuple.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index edc4fdca26378..c36e942cf46ac 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -45,6 +45,28 @@ const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
 #include "clang/Basic/BuiltinsAArch64.def"
 };
 
+static StringRef getArchVersionString(llvm::AArch64::ArchKind Kind) {
+  switch (Kind) {
+  case llvm::AArch64::ArchKind::ARMV9A:
+  case llvm::AArch64::ArchKind::ARMV9_1A:
+  case llvm::AArch64::ArchKind::ARMV9_2A:
+  case llvm::AArch64::ArchKind::ARMV9_3A:
+  case llvm::AArch64::ArchKind::ARMV9_4A:
+return "9";
+  default:
+return "8";
+  }
+}
+
+StringRef AArch64TargetInfo::getArchProfile() const {
+  switch (ArchKind) {
+  case llvm::AArch64::ArchKind::ARMV8R:
+return "R";
+  default:
+return "A";
+  }
+}
+
 AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : TargetInfo(Triple), ABI("aapcs") {
@@ -148,7 +170,7 @@ bool AArch64TargetInfo::validateBranchProtection(StringRef 
Spec, StringRef,
 
 bool AArch64TargetInfo::isValidCPUName(StringRef Name) const {
   return Name == "generic" ||
- llvm::AArch64::parseCpu(Name).Arch != llvm::AArch64::INVALID;
+ llvm::AArch64::parseCPUArch(Name) != llvm::AArch64::ArchKind::INVALID;
 }
 
 bool AArch64TargetInfo::setCPU(const std::string &Name) {
@@ -276,10 +298,8 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   // ACLE predefines. Many can only have one possible value on v8 AArch64.
   Builder.defineMacro("__ARM_ACLE", "200");
-  Builder.defineMacro("__ARM_ARCH",
-  std::to_string(ArchInfo->Version.getMajor()));
-  Builder.defineMacro("__ARM_ARCH_PROFILE",
-  std::string("'") + (char)ArchInfo->Profile + "'");
+  Builder.defineMacro("__ARM_ARCH", getArchVersionString(ArchKind));
+  Builder.defineMacro("__ARM_ARCH_PROFILE", "'" + getArchProfile() + "'");
 
   Builder.defineMacro("__ARM_64BIT_STATE", "1");
   Builder.defineMacro("__ARM_PCS_AAPCS64", "1");
@@ -444,34 +464,52 @@ void AArch64TargetInfo::getTargetDefines(const 
LangOptions &Opts,
   if (HasD128)
 Builder.defineMacro("__ARM_FEATURE_SYSREG128", "1");
 
-  if (*ArchInfo == llvm::AArch64::ARMV8_1A)
+  switch (ArchKind) {
+  default:
+break;
+  case llvm::AArch64::ArchKind::ARMV8_1A:
 getTargetDefinesARMV81A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV8_2A)
+break;
+  case llvm::AArch64::ArchKind::ARMV8_2A:
 getTargetDefinesARMV82A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV8_3A)
+break;
+  case llvm::AArch64::ArchKind::ARMV8_3A:
 getTargetDefinesARMV83A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV8_4A)
+break;
+  case llvm::AArch64::ArchKind::ARMV8_4A:
 getTargetDefinesARMV84A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV8_5A)
+break;
+  case llvm::AArch64::ArchKind::ARMV8_5A:
 getTargetDefinesARMV85A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV8_6A)
+break;
+  case llvm::AArch64::ArchKind::ARMV8_6A:
 getTargetDefinesARMV86A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV8_7A)
+break;
+  case llvm::AArch64::ArchKind::ARMV8_7A:
 getTargetDefinesARMV87A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV8_8A)
+break;
+  case llvm::AArch64::ArchKind::ARMV8_8A:
 getTargetDefinesARMV88A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV8_9A)
+break;
+  case llvm::AArch64::ArchKind::ARMV8_9A:
 getTargetDefinesARMV89A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV9A)
+break;
+  case llvm::AArch64::ArchKind::ARMV9A:
 getTargetDefinesARMV9A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV9_1A)
+break;
+  case llvm::AArch64::ArchKind::ARMV9_1A:
 getTargetDefinesARMV91A(Opts, Builder);
-  if (*ArchInfo == llvm::AArch64::ARMV9_2A)
+break;

[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-12-01 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:152
+  case CK_FloatingToIntegral: {
+llvm::RoundingMode RM = getRoundingMode(CE);
+Optional ToT = classify(CE->getType());

tbaeder wrote:
> sepavloff wrote:
> > According to C standard (6.3.1.4p1):
> > ```
> > When a finite value of real floating type is converted to an integer 
> > type other than _Bool, the fractional part is discarded (i.e., the value is 
> > truncated toward zero).
> > ```
> > So the conversion should not depend on rounding mode. The same applies to 
> > the conversion to boolean (6.3.1.2p1):
> > ```
> > When any scalar value is converted to _Bool, the result is 0 if the 
> > value compares equal to 0; otherwise, the result is 1.
> > ```
> > 
> So this is a difference between C and C++?
No, C++ behaves similarly ([conv.fpint]):
```
A prvalue of a floating-point type can be converted to a prvalue of an integer 
type. The conversion truncates;
that is, the fractional part is discarded.
```
and [conv.bool]:
```
A prvalue of arithmetic, unscoped enumeration, pointer, or pointer-to-member 
type can be converted to a
prvalue of type bool. A zero value, null pointer value, or null member pointer 
value is converted to false;
any other value is converted to true.
```
Theses conversions do not depend on rounding mode.




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

https://reviews.llvm.org/D134859

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


[PATCH] D139095: [clang] Mark CWG405 as a duplicate of CWG218

2022-12-01 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

Is it fine that we're marking CWG405 as a duplicate even though it's not 
mentioned as such in official publication?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139095

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-01 Thread Dave Green via Phabricator via cfe-commits
dmgreen added inline comments.



Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:115
+AARCH64_ARCH_EXT_NAME("rdm",   AArch64::AEK_RDM, "+rdm",   
   "-rdm", \
+RDM,  "+rdm,+fp-armv8,+neon,+jsconv,+complxnum",   
 70)
+AARCH64_ARCH_EXT_NAME("crypto",AArch64::AEK_CRYPTO,  "+crypto",
   "-crypto",  \

ilinpv wrote:
> dmgreen wrote:
> > Should RDM be dependant on +jsconv,+complxnum?
> I suppose RDM implies simd (+neon) which implies +jsconv,+complxnum
jsconv and complxnum are 8.3 features, are they not? Or do they somehow mean 
something different here? It would seem strange for neon to depend on them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D139090: [clang] Add test for CWG360

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

LGTM!


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

https://reviews.llvm.org/D139090

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:152
+  case CK_FloatingToIntegral: {
+llvm::RoundingMode RM = getRoundingMode(CE);
+Optional ToT = classify(CE->getType());

sepavloff wrote:
> tbaeder wrote:
> > sepavloff wrote:
> > > According to C standard (6.3.1.4p1):
> > > ```
> > > When a finite value of real floating type is converted to an integer 
> > > type other than _Bool, the fractional part is discarded (i.e., the value 
> > > is truncated toward zero).
> > > ```
> > > So the conversion should not depend on rounding mode. The same applies to 
> > > the conversion to boolean (6.3.1.2p1):
> > > ```
> > > When any scalar value is converted to _Bool, the result is 0 if the 
> > > value compares equal to 0; otherwise, the result is 1.
> > > ```
> > > 
> > So this is a difference between C and C++?
> No, C++ behaves similarly ([conv.fpint]):
> ```
> A prvalue of a floating-point type can be converted to a prvalue of an 
> integer type. The conversion truncates;
> that is, the fractional part is discarded.
> ```
> and [conv.bool]:
> ```
> A prvalue of arithmetic, unscoped enumeration, pointer, or pointer-to-member 
> type can be converted to a
> prvalue of type bool. A zero value, null pointer value, or null member 
> pointer value is converted to false;
> any other value is converted to true.
> ```
> Theses conversions do not depend on rounding mode.
> 
> 
Ah ok, thanks for the explanation. That explains why the current interpeter 
hardcodes `rmTowardZero` there. The rounding mode in 
`Floating::convertToInteger` was unused for that reason.


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

https://reviews.llvm.org/D134859

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 479262.

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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Floating.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/const-fpfeatures.cpp
  clang/test/AST/Interp/floats.cpp
  clang/test/SemaCXX/rounding-math.cpp

Index: clang/test/SemaCXX/rounding-math.cpp
===
--- clang/test/SemaCXX/rounding-math.cpp
+++ clang/test/SemaCXX/rounding-math.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s
 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas
+// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -fexperimental-new-constant-interpreter -Wno-unknown-pragmas
 // rounding-no-diagnostics
 
 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
Index: clang/test/AST/Interp/floats.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/floats.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+constexpr int i = 2;
+constexpr float f = 1.0f;
+static_assert(f == 1.0f, "");
+
+constexpr float f2 = 1u * f;
+static_assert(f2 == 1.0f, "");
+
+constexpr float f3 = 1.5;
+constexpr int i3 = f3;
+static_assert(i3 == 1);
+
+constexpr bool b3 = f3;
+static_assert(b3);
+
+
+static_assert(1.0f + 3u == 4, "");
+static_assert(4.0f / 1.0f == 4, "");
+static_assert(10.0f * false == 0, "");
+
+constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{division by zero}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{division by zero}}
+
+static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+   // expected-error {{invalid argument type 'float' to unary expression}}
+
+/// Initialized by a double.
+constexpr float df = 0.0;
+/// The other way around.
+constexpr double fd = 0.0f;
+
+static_assert(0.0f == -0.0f, "");
+
+const int k = 3 * (1.0f / 3.0f);
+static_assert(k == 1, "");
+
+constexpr bool b = 1.0;
+static_assert(b, "");
+
+constexpr double db = true;
+static_assert(db == 1.0, "");
+
+constexpr float fa[] = {1.0f, 2.0, 1, false};
+constexpr float da[] = {1.0f, 2.0, 1, false};
Index: clang/test/AST/Interp/const-fpfeatures.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/const-fpfeatures.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -std=c++2a -Wno-unknown-pragmas %s -o - | FileCheck %s
+// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -fexperimental-new-constant-interpreter -std=c++2a -Wno-unknown-pragmas %s -o - | FileCheck %s
+
+
+#pragma STDC FENV_ROUND FE_UPWARD
+
+float F1u = 1.0F + 0x0.02p0F;
+float F2u = 1.0F + 0x0.01p0F;
+float F3u = 0x1.01p0;
+// CHECK: @F1u = {{.*}} float 0x3FF02000
+// CHECK: @F2u = {{.*}} float 0x3FF02000
+// CHECK: @F3u = {{.*}} float 0x3FF02000
+
+float FI1u = 0xU;
+// CHECK: @FI1u = {{.*}} float 0x41F0
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
+
+float F1d = 1.0F + 0x0.02p0F;
+float F2d = 1.0F + 0x0.01p0F;
+float F3d = 0x1.01p0;
+
+// CHECK: @F1d = {{.*}} float 0x3FF02000
+// CHECK: @F2d = {{.*}} float 1.00e+00
+// CHECK: @F3d = {{.*}} float 1.00e+00
+
+
+float FI1d = 0xU;
+// CHECK: @FI1d = {{.*}} float 0x41EFE000
+
+// nextUp(1.F) == 0x1.02p0F
+
+constexpr float add_round_down(float x, float y) {
+  #pragma STDC FENV_ROUND FE_DOWNWARD
+  float res = x;
+  res += y;
+  return res;
+}
+
+constexpr float add_round_up(float x, float y) {
+  #pragma STDC FENV_ROUND FE_UPWARD
+  float res = x;
+  res += y;
+  return res;
+}
+
+float V1 = add_round_down(1.0F, 0x0.01p0F);
+float V2 = add_round_up(1.0F, 0x0.01p0F);
+// CHECK: @V1 = {{.*}} float 1.00e+00
+// CHECK: @V2 = {{.*}} float 0x3FF02000
+
+constexpr float add_cast_round_down(float x, double y) {
+  #pragma STDC FENV_ROUND FE_DOWNWARD
+  float res = x;
+  res += y;
+  return res;
+}
+
+constexpr float add_cast_round_up(float

[PATCH] D136176: Implement support for option 'fexcess-precision'.

2022-12-01 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 479264.

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

https://reviews.llvm.org/D136176

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/FPOptions.def
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/X86/fexcess-precision.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fexcess-precision.c

Index: clang/test/Driver/fexcess-precision.c
===
--- /dev/null
+++ clang/test/Driver/fexcess-precision.c
@@ -0,0 +1,34 @@
+// RUN: %clang -### -target i386 -fexcess-precision=fast -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-FAST %s
+// RUN: %clang -### -target i386 -fexcess-precision=standard -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-STD %s
+// RUN: %clang -### -target i386 -fexcess-precision=16 -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang -### -target i386 -fexcess-precision=none -c %s 2>&1  \
+// RUN:   | FileCheck --check-prefix=CHECK-ERR-NONE %s
+
+// RUN: %clang -### -target x86_64 -fexcess-precision=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FAST %s
+// RUN: %clang -### -target x86_64 -fexcess-precision=standard -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-STD %s
+// RUN: %clang -### -target x86_64 -fexcess-precision=16 -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang -### -target x86_64 -fexcess-precision=none -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefixes=CHECK-ERR-NONE %s
+
+// RUN: %clang -### -target aarch64 -fexcess-precision=fast -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK %s
+// RUN: %clang -### -target aarch64 -fexcess-precision=standard -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK %s
+// RUN: %clang -### -target aarch64 -fexcess-precision=16 -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ERR-16 %s
+// RUN: %clang -### -target aarch64 -fexcess-precision=none -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ERR-NONE %s
+
+// CHECK-FAST: "-ffloat16-excess-precision=fast"
+// CHECK-STD: "-ffloat16-excess-precision=standard"
+// CHECK-NONE: "-ffloat16-excess-precision=none"
+// CHECK-ERR-NONE: unsupported argument 'none' to option '-fexcess-precision='
+// CHECK: "-cc1"
+// CHECK-NOT: "-ffloat16-excess-precision=fast"
+// CHECK-ERR-16: unsupported argument '16' to option '-fexcess-precision='
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -398,7 +398,7 @@
 // CHECK-WARNING-DAG: optimization flag '-falign-loops' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-jumps' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-jumps=100' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fexcess-precision=100' is not supported
+// CHECK-WARNING-DAG: unsupported argument '100' to option '-fexcess-precision='
 // CHECK-WARNING-DAG: optimization flag '-fbranch-count-reg' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fno-default-inline' is not supported
Index: clang/test/CodeGen/X86/fexcess-precision.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/fexcess-precision.c
@@ -0,0 +1,286 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffloat16-excess-precision=fast \
+// RUN: -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffloat16-excess-precision=standard \
+// RUN: -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffloat16-excess-precision=none \
+// RUN: -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffloat16-excess-precision=fast \
+// RUN: -emit-llvm -ffp-eval-method=source -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffloat16-excess-precision=standard \
+// RUN: -emit-llvm -ffp-eval-method=source -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffloat16-excess-precision=none \
+// RUN: -emit-llvm -ffp-eval-method=source -o - %s \
+// RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffloat16-excess-precision=fast \
+// RUN: -emit-llvm -ffp-eval-method=double -o - %s \
+/

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2022-12-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 479265.
pmatos added a comment.

Remove unnecessary attribute that lingered around after some refactoring.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/TypeBitCodes.def
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGValue.h
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/builtins-table.c
  clang/test/CodeGen/WebAssembly/table.c
  clang/test/Sema/builtins-wasm.c
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs-and-tables.cpp
  clang/test/SemaCXX/wasm-refs.cpp
  llvm/include/llvm/CodeGen/WasmAddressSpaces.h
  llvm/include/llvm/IR/Type.h
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
  llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
  llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp
@@ -62,8 +62,9 @@
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
 PtrToIntInst *PTI = dyn_cast(&*I);
 IntToPtrInst *ITP = dyn_cast(&*I);
-if (!(PTI && WebAssembly::isRefType(PTI->getPointerOperand()->getType())) &&
-!(ITP && WebAssembly::isRefType(ITP->getDestTy(
+if (!(PTI &&
+  PTI->getPointerOperand()->getType()->isWebAssemblyReferenceType()) &&
+!(ITP && ITP->getDestTy()->isWebAssemblyReferenceType()))
   continue;
 
 UndefValue *U = UndefValue::get(I->getType());
Index: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -1197,7 +1197,7 @@
   // Lastly, if this is a call to a funcref we need to add an instruction
   // table.set to the chain and transform the call.
   if (CLI.CB &&
-  WebAssembly::isFuncrefType(CLI.CB->getCalledOperand()->getType())) {
+  CLI.CB->getCalledOperand()->getType()->isWebAssemblyFuncrefType()) {
 // In the absence of function references proposal where a funcref call is
 // lowered to call_ref, using reference types we generate a table.set to set
 // the funcref to a special table used solely for this purpose, followed by
Index: llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
===
--- llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -46,43 +46,6 @@
   Multivalue = 0x,
 };
 
-enum WasmAddressSpace : unsigned {
-  // Default address space, for pointers to linear memory (stack, heap, data).
-  WASM_ADDRESS_SPACE_DEFAULT = 0,
-  // A non-integral address space for pointers to named objects outside of
-  // linear memory: WebAssembly globals or WebAssembly locals.  Loads and stores
-  // to these pointers are lowered to global.get / global.set or local.get /
-  // local.set, as appropriate.
-  WASM_ADDRESS_SPACE_VAR = 1,
-  // A non-integral address space for externref values
-  WASM_ADDRESS_SPACE_EXTERNREF = 10,
-  // A non-integral address space for funcref values
-  WASM_ADDRESS_SPACE_FUNCREF = 20,
-};
-
-inline bool isDefaultAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_DEFAULT;
-}
-inline bool isWasmVarAddressSpace(unsigned AS) {
-  return AS == WASM_ADDRESS_SPACE_VAR;
-}
-inline bool isValidAddressSpace(unsigned AS) {
-  return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS);
-}
-inline bool isFuncrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
-}
-inline bool isExternrefType(const Type *Ty) {
-  return isa(Ty) &&
- Ty->getPointerAddressSpace(

[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2022-12-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

This is ready for review. 
RFC has been published here: 
https://discourse.llvm.org/t/rfc-webassembly-reference-types-in-clang/66939

Thanks to @tlively and @asb for the reviews.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

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


[PATCH] D139095: [clang] Mark CWG405 as a duplicate of CWG218

2022-12-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D139095#3963334 , @Endill wrote:

> Is it fine that we're marking CWG405 as a duplicate even though it's not 
> mentioned as such in official publication?

I don't think we should mark it as a dup -- we want the status in our tests to 
match the status on the official document, otherwise things get confusing. The 
two issues are very closely related, but they change different words in the 
standard and should be tested independently as best we can. However, comments 
in the test for each DR pointing to the other related DR would be a good idea.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139095

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


[PATCH] D136176: Implement support for option 'fexcess-precision'.

2022-12-01 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:821
+(Precision == LangOptions::ExcessPrecisionKind::FPP_Standard ||
+ Precision == LangOptions::ExcessPrecisionKind::FPP_Fast)) {
   if (Ty->isAnyComplexType()) {

rjmccall wrote:
> zahiraam wrote:
> > zahiraam wrote:
> > > rjmccall wrote:
> > > > rjmccall wrote:
> > > > > Let's make the language option be canonically correct: if the target 
> > > > > doesn't want us to emit `_Float16` with excess precision, we should 
> > > > > either diagnose or ignore the frontend option, but in either case 
> > > > > clients like this should be able to just look at the LangOpt.  We 
> > > > > should do this in the frontend, not the driver.
> > > > > 
> > > > > Also, we have a similar function in the complex emitter, right?
> > > > > 
> > > > > To allow for multiple types with independent excess precision in the 
> > > > > future, please sink the checks down to where we've recognized that 
> > > > > we're dealing with a certain type, like:
> > > > > 
> > > > > ```
> > > > > if (auto *CT = Ty->getAs()) {
> > > > >   QualType ElementType = CT->getElementType();
> > > > >   if (ElementType->isFloat16Type() &&
> > > > >   CGF.getContext().getLangOpts().getFloat16ExcessPrecision() != 
> > > > > LangOptions::ExcessPrecisionKind::FPP_None)
> > > > > return CGF.getContext().getComplexType(CGF.getContext().FloatTy);
> > > > > }
> > > > > ```
> > > > > 
> > > > > You might also consider adding a `useFloat16ExcessPrecision()` 
> > > > > convenience function to LangOpts for this.
> > > > Sorry, I'm waffling about the right way to handle this.  Let me lay out 
> > > > what I'm thinking.
> > > > 
> > > > 1. It's best if, by the time we get into the main compiler operation, 
> > > > there's a single place we can check to ask if a particular type should 
> > > > use excess precision.  This code can actually be relatively hot, so we 
> > > > want it to be cheap to check, and for correctness we want it to be a 
> > > > simple condition.
> > > > 
> > > > 2. I don't like the design of `-fexcess-precision`.  It mashes the 
> > > > handling of all of the types together, and I'd like excess precision 
> > > > for different types to be independently controllable.  In principle, 
> > > > I'd even like excess precision to be specifiable when the target 
> > > > doesn't need it.  It makes sense for the driver to worry about all 
> > > > these poorly-designed options and just give precise controls to the 
> > > > frontend.
> > > > 
> > > > 3. The problem with that is that the driver doesn't have all the 
> > > > information it would need in order to pick the right default.  Or, 
> > > > well, it has the information, but it would have to parse it out of the 
> > > > command line in a way that we currently try to avoid in the driver.  
> > > > For example, to pick the default for `_Float16`, we need to know if 
> > > > AVX512FP16 is enabled in the target, and as far as I know, the first 
> > > > time that anything knows that for sure is after we construct a 
> > > > TargetInfo object in CompilerInstance.
> > > > 
> > > > 4. So I'm leaning back towards the idea that we should just pass 
> > > > `-fexcess-precision` down to the frontend instead of processing it in 
> > > > the driver, and then the frontend can reconcile that option with the 
> > > > precise target info and turn it into a bunch of derived, type-specific 
> > > > language options.  Most of the compiler will at least still be able to 
> > > > consider only those type-specific language options.
> > > > 
> > > > But I'd like to get some driver experts to think about it.
> > > Removing the check 
> > > CGF.getTarget().shouldEmitFloat16WithExcessPrecision()) here is not 
> > > correct as it will perform excess precision for non-x86 architecture.  
> > > So, for now it needs to stay until we decide what needs to be done.
> > > Would it be a good alternative (may be not cheap though) to have 
> > > LangOptions::useFloat16Precision() take a target as argument?
> > > Sorry, I'm waffling about the right way to handle this.  Let me lay out 
> > > what I'm thinking.
> > > 
> > > 1. It's best if, by the time we get into the main compiler operation, 
> > > there's a single place we can check to ask if a particular type should 
> > > use excess precision.  This code can actually be relatively hot, so we 
> > > want it to be cheap to check, and for correctness we want it to be a 
> > > simple condition.
> > May be in LangOptions::useFloat16Precision()? We could also have 
> > LangOptions::useBFloat16Precision and son on?
> > > 
> > > 2. I don't like the design of `-fexcess-precision`.  It mashes the 
> > > handling of all of the types together, and I'd like excess precision for 
> > > different types to be independently controllable.  In principle, I'd even 
> > > like excess precision to be specifiable when the target doesn't need it.  
> > > It makes sense for

[PATCH] D138939: [WIP][clang] adds a way to provide user-oriented reasons

2022-12-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D138939#3958185 , @cjdb wrote:

>> The clang-side interface to this seems a touch clunky, and I fear it'll make 
>> continuing its use/generalizing its use less likely.
>
> Is this w.r.t. the `FormatDiagnostic` being split up, or is it something 
> else? If it's the former: I'll be changing that to `FormatLegacyDiagnostic`, 
> which //almost// gets us back to where we started.

Urgh, I was a bit afraid you'd ask that :D  It is more of a feeling I guess, 
which is perhaps biased by this patch being particularly in the 
diagnostics-handling code.  However, I suspect that over time, you're going to 
want to start switching all these uses of `FormatLegacyReason` over to 
`FormatSarifReason`, and I would want the 'easy way' to be the 'right' way in 
either case.  Having it be a 2-liner, or over-specifying what is otherwise the 
'default' behavior is a bit disconcerting.

In D138939#3958231 , @cjdb wrote:

>> though I find myself wondering if the "FormatDiagnostic" call should stay 
>> the same, and choose the legacy-reason only when a sarif reason doesn't 
>> exist? Or for some level of command line control?
>
> Hmm... isn't this the point of the diagnostic consumers?

I don't have a great feeling of that?  I haven't done much thinking into the 
diagnostics architecture over the years.  That said, the use of when we'd 
choose one vs the other isn't completely clear to me yet.




Comment at: clang/lib/Basic/Diagnostic.cpp:791
 
 /// FormatDiagnostic - Format this diagnostic into a string, substituting the
 /// formal arguments into the %0 slots.  The result is appended onto the Str

Comment no longer matches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138939

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


[PATCH] D138939: [WIP][clang] adds a way to provide user-oriented reasons

2022-12-01 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Maybe `void FormatDiagnostic(SmallVectorImpl &OutStr, DiagnosticMode 
mode)`instead of `void FormatDiagnostic(SmallVectorImpl &OutStr)`?
To make the transition easer and future proof.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138939

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


[PATCH] D138947: [Clang] Adjust assert from Sema::BuildCXXTypeConstructExpr

2022-12-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM with the rewording suggestion applied. Please also add a release note for 
the fix, thank you!


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

https://reviews.llvm.org/D138947

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


[PATCH] D139107: [clangd] Allow to build Clangd without decision forest

2022-12-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.

Make it possible to disable building the decision forest ranking
model for clangd.  To unbreak build of Clangd on PPC32 in gentoo, see
https://bugs.gentoo.org/829602


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139107

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/Features.inc.in
  clang-tools-extra/clangd/Quality.cpp
  clang-tools-extra/clangd/benchmarks/CMakeLists.txt
  clang-tools-extra/clangd/decision-forest/DecisionForest.cpp
  clang-tools-extra/clangd/decision-forest/DecisionForest_disabled.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -209,11 +209,15 @@
 "ranking-model",
 cat(Features),
 desc("Model to use to rank code-completion items"),
-values(clEnumValN(CodeCompleteOptions::Heuristics, "heuristics",
-  "Use hueristics to rank code completion items"),
-   clEnumValN(CodeCompleteOptions::DecisionForest, "decision_forest",
-  "Use Decision Forest model to rank completion items")),
+values(clEnumValN(CodeCompleteOptions::DecisionForest, "decision_forest",
+  "Use Decision Forest model to rank completion items"),
+   clEnumValN(CodeCompleteOptions::Heuristics, "heuristics",
+  "Use hueristics to rank code completion items")),
+#ifdef CLANGD_DECISION_FOREST
 init(CodeCompleteOptions().RankingModel),
+#else
+init(CodeCompleteOptions::Heuristics),
+#endif
 Hidden,
 };
 
@@ -797,6 +801,13 @@
 }
   }
 
+#ifndef CLANGD_DECISION_FOREST
+  if (RankingModel == clangd::CodeCompleteOptions::DecisionForest) {
+llvm::errs() << "Clangd was compiled without decision forest support.\n";
+return 1;
+  }
+#endif
+
   // Setup tracing facilities if CLANGD_TRACE is set. In practice enabling a
   // trace flag in your editor's config is annoying, launching with
   // `CLANGD_TRACE=trace.json vim` is easier.
Index: clang-tools-extra/clangd/decision-forest/DecisionForest_disabled.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/decision-forest/DecisionForest_disabled.cpp
@@ -0,0 +1,26 @@
+//===--- DecisionForest_disabled.cpp -*- 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
+//
+//===--===//
+// Implementation which calls std::abort. Used when completion model is
+// disabled at build time.
+//===--===//
+
+#include "Quality.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+DecisionForestScores
+evaluateDecisionForest(const SymbolQualitySignals &Quality,
+   const SymbolRelevanceSignals &Relevance, float Base) {
+  llvm::errs() << "Clangd was compiled without decision forest support.\n";
+  std::abort();
+}
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/decision-forest/DecisionForest.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/decision-forest/DecisionForest.cpp
@@ -0,0 +1,76 @@
+//===--- DecisionForest.cpp --*- 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
+//
+//===--===//
+// Implementation of evaluateDecisionForest with completion model enabled.
+//===--===//
+
+#include "CompletionModel.h"
+#include "Quality.h"
+#include 
+
+namespace clang::clangd {
+
+DecisionForestScores
+evaluateDecisionForest(const SymbolQualitySignals &Quality,
+   const SymbolRelevanceSignals &Relevance, float Base) {
+  Example E;
+  E.setIsDeprecated(Quality.Deprecated);
+  E.setIsReservedName(Quality.ReservedName);
+  E.setIsImplementationDetail(Quality.ImplementationDetail);
+  E.setNumReferences(Quality.References);
+  E.setSymbolCategory(Quality.Category);
+
+  SymbolRelevanceSignals::DerivedSignals Derived =
+  Re

[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-01 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added inline comments.



Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:115
+AARCH64_ARCH_EXT_NAME("rdm",   AArch64::AEK_RDM, "+rdm",   
   "-rdm", \
+RDM,  "+rdm,+fp-armv8,+neon,+jsconv,+complxnum",   
 70)
+AARCH64_ARCH_EXT_NAME("crypto",AArch64::AEK_CRYPTO,  "+crypto",
   "-crypto",  \

dmgreen wrote:
> ilinpv wrote:
> > dmgreen wrote:
> > > Should RDM be dependant on +jsconv,+complxnum?
> > I suppose RDM implies simd (+neon) which implies +jsconv,+complxnum
> jsconv and complxnum are 8.3 features, are they not? Or do they somehow mean 
> something different here? It would seem strange for neon to depend on them.
Right, last implication is true from 8.3, and wrong before that, thanks for 
spotting that! I will fix that in other places too.

```
FEAT_JSCVT implements the functionality identified by 0b0001.
In Armv8.0, Armv8.1, and Armv8.2, the only permitted value is 0b.
From Armv8.3, if Advanced SIMD or Floating-point is implemented, the only 
permitted value is 0b0001.
From Armv8.3, if Advanced SIMD or Floating-point is not implemented, the only 
permitted value is 0b.

```





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D139107: [clangd] Allow to build Clangd without decision forest

2022-12-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

This seems to build in both modes, but I still need to figure out what to do 
with tests with decision forest off.
Also, maybe there is a way to minimize the use of preprocessor even more.




Comment at: clang-tools-extra/clangd/decision-forest/DecisionForest.cpp:15
+
+namespace clang::clangd {
+

Note to self: split into two namespace declarations for consistency with the 
rest of clangd


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139107

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


[PATCH] D138939: [WIP][clang] adds a way to provide user-oriented reasons

2022-12-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D138939#3963473 , @tschuett wrote:

> Maybe `void FormatDiagnostic(SmallVectorImpl &OutStr, DiagnosticMode 
> mode)`instead of `void FormatDiagnostic(SmallVectorImpl &OutStr)`?
> To make the transition easer and future proof.

I like this idea.  Perhaps with DiagnosticMode being a 3-way enum:

  enum struct DiagnosticMode {
Legacy,
Sarif,  
Default = Legacy
  }

I like the idea in particular, since it makes a command line flag to modify 
"Default" to be whichever the user prefers pretty trivial.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138939

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


[clang] 3f950ad - [clang] Add test for CWG360

2022-12-01 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2022-12-01T17:23:26+03:00
New Revision: 3f950ad58919309882a29bcb4bf6f8db62ffc384

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

LOG: [clang] Add test for CWG360

P1787: "CWG360 is resolved by applying access control to using-declarations."
[[ http://eel.is/c++draft/class.access#general-4.sentence-3 | 
class.access.general#4 ]]: "When a using-declarator is named, access control is 
applied to it, not to the declarations that replace it."

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

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

Added: 


Modified: 
clang/test/CXX/drs/dr3xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp
index 4ae56fcdc93a3..de7f6b9bbf1d1 100644
--- a/clang/test/CXX/drs/dr3xx.cpp
+++ b/clang/test/CXX/drs/dr3xx.cpp
@@ -890,6 +890,33 @@ namespace dr359 { // dr359: yes
   };
 }
 
+namespace dr360 { // dr360: yes
+struct A {
+  int foo();
+  int bar();
+
+protected:
+  int baz();
+};
+
+struct B : A {
+private:
+  using A::foo; // #dr360-foo-using-decl
+protected:
+  using A::bar; // #dr360-bar-using-decl
+public:
+  using A::baz; // #dr360-baz-using-decl
+};
+
+int main() {
+  int foo = B().foo(); // expected-error {{is a private member}}
+  // expected-note@#dr360-foo-using-decl {{declared private here}}
+  int bar = B().bar(); // expected-error {{is a protected member}}
+  // expected-note@#dr360-bar-using-decl {{declared protected here}}
+  int baz = B().baz();
+}
+} // namespace dr360
+
 // dr362: na
 // dr363: na
 

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index cec9fe58cf601..e4d0a24e08c99 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -2200,7 +2200,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg360";>360
 CD6
 Using-declaration that reduces access
-Unknown
+Yes
   
   
 https://wg21.link/cwg361";>361



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


[PATCH] D139090: [clang] Add test for CWG360

2022-12-01 Thread Vlad Serebrennikov 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 rG3f950ad58919: [clang] Add test for CWG360 (authored by 
Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139090

Files:
  clang/test/CXX/drs/dr3xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2200,7 +2200,7 @@
 https://wg21.link/cwg360";>360
 CD6
 Using-declaration that reduces access
-Unknown
+Yes
   
   
 https://wg21.link/cwg361";>361
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -890,6 +890,33 @@
   };
 }
 
+namespace dr360 { // dr360: yes
+struct A {
+  int foo();
+  int bar();
+
+protected:
+  int baz();
+};
+
+struct B : A {
+private:
+  using A::foo; // #dr360-foo-using-decl
+protected:
+  using A::bar; // #dr360-bar-using-decl
+public:
+  using A::baz; // #dr360-baz-using-decl
+};
+
+int main() {
+  int foo = B().foo(); // expected-error {{is a private member}}
+  // expected-note@#dr360-foo-using-decl {{declared private here}}
+  int bar = B().bar(); // expected-error {{is a protected member}}
+  // expected-note@#dr360-bar-using-decl {{declared protected here}}
+  int baz = B().baz();
+}
+} // namespace dr360
+
 // dr362: na
 // dr363: na
 


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2200,7 +2200,7 @@
 https://wg21.link/cwg360";>360
 CD6
 Using-declaration that reduces access
-Unknown
+Yes
   
   
 https://wg21.link/cwg361";>361
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -890,6 +890,33 @@
   };
 }
 
+namespace dr360 { // dr360: yes
+struct A {
+  int foo();
+  int bar();
+
+protected:
+  int baz();
+};
+
+struct B : A {
+private:
+  using A::foo; // #dr360-foo-using-decl
+protected:
+  using A::bar; // #dr360-bar-using-decl
+public:
+  using A::baz; // #dr360-baz-using-decl
+};
+
+int main() {
+  int foo = B().foo(); // expected-error {{is a private member}}
+  // expected-note@#dr360-foo-using-decl {{declared private here}}
+  int bar = B().bar(); // expected-error {{is a protected member}}
+  // expected-note@#dr360-bar-using-decl {{declared protected here}}
+  int baz = B().baz();
+}
+} // namespace dr360
+
 // dr362: na
 // dr363: na
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139090: [clang] Add test for CWG360

2022-12-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/CXX/drs/dr3xx.cpp:908
+public:
+  using A::baz; // #dr360-baz-using-decl
+};

This bookmark isn't necessary, so no reason to have it.  But thank you for 
using these!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139090

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


[PATCH] D138520: [clangd] Make decision forest model optional

2022-12-01 Thread Michał Górny via Phabricator via cfe-commits
mgorny abandoned this revision.
mgorny added a comment.

Closing in favor of D139107 .


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

https://reviews.llvm.org/D138520

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


[PATCH] D139107: [clangd] Allow to build Clangd without decision forest

2022-12-01 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Thanks a lot for doing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139107

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


[PATCH] D137346: [-Wunsafe-buffer-usage] Initial commit - Transition away from raw buffer accesses.

2022-12-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM




Comment at: clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h:34
+// through the handler class.
+void checkUnsafeBufferUsage(const Decl *D, UnsafeBufferUsageHandler &Handler);
+

NoQ wrote:
> aaron.ballman wrote:
> > Do we need the interface to accept a non-const reference?
> It's same as asking whether the `handle...` methods should be const. Roughly 
> similar to whether `MatchFinder::MatchCallback::run()` should be const. I 
> don't see a reason why not, but also "Why say lot word when few word do 
> trick", could have been a lambda.
> 
> As an opposite example, static analyzer's `Checker::check...` callbacks 
> really needed to be const, because carrying mutable state in the checker is 
> often *tempting* but always *terrible*, in a way that's not immediately 
> obvious to beginners.
Hmmm, I may regret this later (I often do when suggesting laxity with `const`), 
but I suppose it's reasonable to leave the interface mutable. I usually prefer 
things to be `const` up front and then relax the restriction later once we have 
a need, but this is a case where relaxing that later would be about as viral as 
adding `const` later.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11731-11732
+// Unsafe buffer usage diagnostics.
+def warn_unsafe_buffer_usage : Warning<"unchecked operation on raw buffer in 
expression">,
+  InGroup>, DefaultIgnore;
 } // end of sema component.

NoQ wrote:
> aaron.ballman wrote:
> > The diagnostic wording isn't wrong, but I am a bit worried about complex 
> > expressions. Consider something like `void func(a, b, c + d, e++, f(&g));` 
> > -- if you got this warning on that line of code, how likely would you be to 
> > spot what caused the diagnostic? I think we need to be sure that issuing 
> > this warning *always* passes in an extra `SourceRange` for the part of the 
> > expression that's caused the issue so users will at least get some 
> > underlined squiggles to help them out.
> Yeah, I agree. Later we'll additionally specialize this warning to be more 
> specific than "expression" (eg. "pointer arithmetic", "array access", etc.).
> 
> Hmm, is there a way to write the .td file entry so that the source range 
> becomes mandatory?
> Hmm, is there a way to write the .td file entry so that the source range 
> becomes mandatory?

Not to my knowledge; we could maybe thread through enough information to assert 
if the diagnostic is called without a source range, but I'm not certain we 
could reasonably get a compile-time error if the range isn't provided.



Comment at: clang/lib/Sema/AnalysisBasedWarnings.cpp:2152-2154
+  void handleUnsafeOperation(const Stmt *Operation) override {
+S.Diag(Operation->getBeginLoc(), diag::warn_unsafe_buffer_usage);
+  }

NoQ wrote:
> aaron.ballman wrote:
> > I think this interface needs an additional `SourceRange` parameter that can 
> > be passed in as a streaming argument, along these lines. This way you'll 
> > get squiggles for the problematic part of the expression.
> `Operation->getSourceRange()` does the trick right? Like this:
> ```
> warning: unchecked operation on raw buffer in expression
> 
>   a[i];
>   
> ```
> I suspect that the Operation is forever going to be the exact thing we want 
> to highlight, there's virtually no reason for it to be anything else.
> 
> Or do you think it'd be better to do it like this?
> ```
> warning: unchecked operation on raw buffer in expression
> 
>   a[i];
>   ~
> ```
> Operation->getSourceRange() does the trick right?

Yup!

> Or do you think it'd be better to do it like this?

I prefer the first form where the whole operation is highlighted instead of 
just an operand of the operation. I think that'll make more sense for 
situations like:
```
a + i;
```
to highlight the whole expression instead of just `a`. It also helpfully means 
I don't have to ask for a test like: `i[a]` and see if we highlight the correct 
"raw buffer" operand. :-D


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

https://reviews.llvm.org/D137346

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


[PATCH] D138117: [clang][docs] Correct floating point option explanations

2022-12-01 Thread KAWASHIMA Takahiro via Phabricator via cfe-commits
kawashima-fj updated this revision to Diff 479275.
kawashima-fj edited the summary of this revision.
kawashima-fj added a comment.

Addressed to @zahiraam's comment


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

https://reviews.llvm.org/D138117

Files:
  clang/docs/UsersManual.rst

Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1437,6 +1437,8 @@
 
* ``-fno-honor-nans``
 
+   * ``-fapprox-func``
+
* ``-fno-math-errno``
 
* ``-ffinite-math-only``
@@ -1449,6 +1451,8 @@
 
* ``-fno-trapping-math``
 
+   * ``-fno-rounding-math``
+
* ``-ffp-contract=fast``
 
Note: ``-ffast-math`` causes ``crtfastmath.o`` to be linked with code. See
@@ -1457,7 +1461,7 @@
 .. option:: -fno-fast-math
 
Disable fast-math mode.  This options disables unsafe floating-point
-   optimizations by preventing the compiler from making any tranformations that
+   optimizations by preventing the compiler from making any transformations that
could affect the results.
 
This option implies:
@@ -1466,7 +1470,7 @@
 
* ``-fhonor-nans``
 
-   * ``-fmath-errno``
+   * ``-fno-approx-func``
 
* ``-fno-finite-math-only``
 
@@ -1476,14 +1480,15 @@
 
* ``-fsigned-zeros``
 
-   * ``-fno-trapping-math``
-
* ``-ffp-contract=on``
 
-   * ``-fdenormal-fp-math=ieee``
+   Also, this option resets following options to their target-dependent defaults.
+
+   * ``-f[no-]math-errno``
+   * ``-fdenormal-fp-math=``
 
There is ambiguity about how ``-ffp-contract``, ``-ffast-math``,
-   and ``-fno-fast-math`` behave in combination. To keep the value of
+   and ``-fno-fast-math`` behave when combined. To keep the value of
``-ffp-contract`` consistent, we define this set of rules:
 
* ``-ffast-math`` sets ``ffp-contract`` to ``fast``.
@@ -1516,7 +1521,8 @@
* ``preserve-sign`` - the sign of a flushed-to-zero number is preserved in the sign of 0
* ``positive-zero`` - denormals are flushed to positive zero
 
-   Defaults to ``ieee``.
+   The default value depends on the target. For most targets, defaults to
+   ``ieee``.
 
 .. option:: -f[no-]strict-float-cast-overflow
 
@@ -1525,6 +1531,7 @@
By default, Clang will not guarantee any particular result in that case.
With the 'no-strict' option, Clang will saturate towards the smallest and
largest representable integer values instead. NaNs will be converted to zero.
+   Defaults to ``-fstrict-float-cast-overflow``.
 
 .. option:: -f[no-]math-errno
 
@@ -1572,11 +1579,19 @@
 
 .. option:: -f[no-]honor-infinities
 
+   Allow floating-point optimizations that assume arguments and results are
+   not +-Inf.
+   Defaults to ``-fhonor-infinities``.
+
If both ``-fno-honor-infinities`` and ``-fno-honor-nans`` are used,
has the same effect as specifying ``-ffinite-math-only``.
 
 .. option:: -f[no-]honor-nans
 
+   Allow floating-point optimizations that assume arguments and results are
+   not NaNs.
+   Defaults to ``-fhonor-nans``.
+
If both ``-fno-honor-infinities`` and ``-fno-honor-nans`` are used,
has the same effect as specifying ``-ffinite-math-only``.
 
@@ -1592,7 +1607,7 @@
 .. option:: -f[no-]signed-zeros
 
Allow optimizations that ignore the sign of floating point zeros.
-   Defaults to ``-fno-signed-zeros``.
+   Defaults to ``-fsigned-zeros``.
 
 .. option:: -f[no-]associative-math
 
@@ -1608,24 +1623,48 @@
 
 .. option:: -f[no-]unsafe-math-optimizations
 
-   Allow unsafe floating-point optimizations. Also implies:
+   Allow unsafe floating-point optimizations.
+   ``-funsafe-math-optimizations`` also implies:
 
+   * ``-fapprox-func``
* ``-fassociative-math``
* ``-freciprocal-math``
-   * ``-fno-signed-zeroes``
-   * ``-fno-trapping-math``.
+   * ``-fno-signed-zeros``
+   * ``-fno-trapping-math``
+   * ``-ffp-contract=fast``
+
+   ``-fno-unsafe-math-optimizations`` implies:
+
+   * ``-fno-approx-func``
+   * ``-fno-associative-math``
+   * ``-fno-reciprocal-math``
+   * ``-fsigned-zeros``
+   * ``-ftrapping-math``
+   * ``-ffp-contract=on``
+   * ``-fdenormal-fp-math=ieee``
+
+   There is ambiguity about how ``-ffp-contract``,
+   ``-funsafe-math-optimizations``, and ``-fno-unsafe-math-optimizations``
+   behave when combined. Explanation in :option:`-fno-fast-math` also applies
+   to these options.
 
Defaults to ``-fno-unsafe-math-optimizations``.
 
 .. option:: -f[no-]finite-math-only
 
Allow floating-point optimizations that assume arguments and results are
-   not NaNs or +-Inf.  This defines the ``__FINITE_MATH_ONLY__`` preprocessor macro.
-   Also implies:
+   not NaNs or +-Inf. ``-ffinite-math-only`` defines the
+   ``__FINITE_MATH_ONLY__`` preprocessor macro.
+   ``-ffinite-math-only`` implies:
 
* ``-fno-honor-infinities``
* ``-fno-honor-nans``
 
+   ``-ffno-inite-math-only`` implies:
+
+   * ``-fhonor-infinities``
+   * ``-fhonor-nans``
+
Defa

[PATCH] D138914: Make evaluation of nested requirement consistent with requires expr.

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

Happy now, thanks!




Comment at: clang/include/clang/AST/ExprConcepts.h:428
+  : Requirement(RK_Nested,
+Constraint && Constraint->isInstantiationDependent(),
+Constraint && 
Constraint->containsUnexpandedParameterPack(),

usaxena95 wrote:
> erichkeane wrote:
> > erichkeane wrote:
> > > I'm a little concerned that we're changing to a situation where the 
> > > constraint in a nested-requirement can be null like this.  The other 
> > > cases it can be null we consider it a 'substitution failure' (see the 1st 
> > > constructor).
> > > 
> > > It seems to me that we perhaps need a different state here for that.
> > I still have this concern, we need to make sure that NestedRequirement is 
> > written to consider this type of failure, it likely needs a separate 
> > constructor that contains information about the failure.  We probably want 
> > at least some sort of stored diagnostic here, sot hat we dont lose the 
> > output we have below.
> NestedRequirement will no more capture a substitution failure. I am planning 
> to remove all references to SubstitutionDiagnostics for it. I have 
> **temporarily** added unreachable tags to the references of 
> SubstitutionDiagnostics. 
> 
> If this looks fine to you then I would move forward with refactoring it to 
> remove all support for SubstitutionDiagnostics in NestedRequirement. WDYT ?
Ok, that works for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138914

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


[PATCH] D139090: [clang] Add test for CWG360

2022-12-01 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/test/CXX/drs/dr3xx.cpp:908
+public:
+  using A::baz; // #dr360-baz-using-decl
+};

erichkeane wrote:
> This bookmark isn't necessary, so no reason to have it.  But thank you for 
> using these!
Nice catch, thank you!
Seems like I should've waited a bit more before committing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139090

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


[PATCH] D139090: [clang] Add test for CWG360

2022-12-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/CXX/drs/dr3xx.cpp:908
+public:
+  using A::baz; // #dr360-baz-using-decl
+};

Endill wrote:
> erichkeane wrote:
> > This bookmark isn't necessary, so no reason to have it.  But thank you for 
> > using these!
> Nice catch, thank you!
> Seems like I should've waited a bit more before committing.
Good catch Erich!

Feel free to fix the comment up with an NFC commit (you don't need anyone to 
review it because there's no functional change).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139090

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


[PATCH] D139013: [include-cleaner] clang-include-cleaner can print/apply edits

2022-12-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks!




Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h:65
+llvm::ArrayRef MacroRefs,
+const Includes &, const PragmaIncludes *PI,
+const SourceManager &SM, HeaderSearch &HS);

nit: name the `Includes` parameter. preferably `MainFileIncludes` (or 
`ProvidedIncludes`)?



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:77
+ bool Satisfied = false;
+ for (const Header &H : Providers) {
+   if (H.kind() == Header::Physical && H.physical() == MainFile)

nit: maybe leave a comment here for skipping `Header`s we've seen before. 
there's a quite good chance that we'll see same provider showing up multiple 
times, skipping processing might be helpful (later on we'll probably need to 
cache the analysis results for diagnostics purposes).



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:111
+if (auto Edit = HI.insert(Insert.trim("<>\""), Insert.starts_with("<"))) {
+  if (PendingInsert && Edit->getOffset() == PendingInsert->getOffset()) {
+PendingInsert = tooling::Replacement(

this logic makes me feel a little bit uneasy, as we're relying on alphabetical 
sorting of `Results.Missing`, which isn't just the filenames but also contains 
`<` or `"` at the beginning.
clang-format has weird include categories but I think it never mixes `"` 
includes with `<` includes. so we're probably safe here.
but it might still be safer to just keep a map of offsets to edits, up to you. 
(having a comment at the very least would be nice)



Comment at: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp:148
+)cpp";
+  Inputs.ExtraFiles["a.h"] = R"cpp(
+#pragma once

nit: you can call guard(Code) here and elsewhere


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139013

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


[PATCH] D136176: Implement support for option 'fexcess-precision'.

2022-12-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: MaskRay.
aaron.ballman added a comment.
Herald added a subscriber: StephenFan.

Adding @MaskRay for driver-specific expertise.




Comment at: clang/lib/CodeGen/CGExprScalar.cpp:821
+(Precision == LangOptions::ExcessPrecisionKind::FPP_Standard ||
+ Precision == LangOptions::ExcessPrecisionKind::FPP_Fast)) {
   if (Ty->isAnyComplexType()) {

zahiraam wrote:
> rjmccall wrote:
> > zahiraam wrote:
> > > zahiraam wrote:
> > > > rjmccall wrote:
> > > > > rjmccall wrote:
> > > > > > Let's make the language option be canonically correct: if the 
> > > > > > target doesn't want us to emit `_Float16` with excess precision, we 
> > > > > > should either diagnose or ignore the frontend option, but in either 
> > > > > > case clients like this should be able to just look at the LangOpt.  
> > > > > > We should do this in the frontend, not the driver.
> > > > > > 
> > > > > > Also, we have a similar function in the complex emitter, right?
> > > > > > 
> > > > > > To allow for multiple types with independent excess precision in 
> > > > > > the future, please sink the checks down to where we've recognized 
> > > > > > that we're dealing with a certain type, like:
> > > > > > 
> > > > > > ```
> > > > > > if (auto *CT = Ty->getAs()) {
> > > > > >   QualType ElementType = CT->getElementType();
> > > > > >   if (ElementType->isFloat16Type() &&
> > > > > >   CGF.getContext().getLangOpts().getFloat16ExcessPrecision() != 
> > > > > > LangOptions::ExcessPrecisionKind::FPP_None)
> > > > > > return 
> > > > > > CGF.getContext().getComplexType(CGF.getContext().FloatTy);
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > You might also consider adding a `useFloat16ExcessPrecision()` 
> > > > > > convenience function to LangOpts for this.
> > > > > Sorry, I'm waffling about the right way to handle this.  Let me lay 
> > > > > out what I'm thinking.
> > > > > 
> > > > > 1. It's best if, by the time we get into the main compiler operation, 
> > > > > there's a single place we can check to ask if a particular type 
> > > > > should use excess precision.  This code can actually be relatively 
> > > > > hot, so we want it to be cheap to check, and for correctness we want 
> > > > > it to be a simple condition.
> > > > > 
> > > > > 2. I don't like the design of `-fexcess-precision`.  It mashes the 
> > > > > handling of all of the types together, and I'd like excess precision 
> > > > > for different types to be independently controllable.  In principle, 
> > > > > I'd even like excess precision to be specifiable when the target 
> > > > > doesn't need it.  It makes sense for the driver to worry about all 
> > > > > these poorly-designed options and just give precise controls to the 
> > > > > frontend.
> > > > > 
> > > > > 3. The problem with that is that the driver doesn't have all the 
> > > > > information it would need in order to pick the right default.  Or, 
> > > > > well, it has the information, but it would have to parse it out of 
> > > > > the command line in a way that we currently try to avoid in the 
> > > > > driver.  For example, to pick the default for `_Float16`, we need to 
> > > > > know if AVX512FP16 is enabled in the target, and as far as I know, 
> > > > > the first time that anything knows that for sure is after we 
> > > > > construct a TargetInfo object in CompilerInstance.
> > > > > 
> > > > > 4. So I'm leaning back towards the idea that we should just pass 
> > > > > `-fexcess-precision` down to the frontend instead of processing it in 
> > > > > the driver, and then the frontend can reconcile that option with the 
> > > > > precise target info and turn it into a bunch of derived, 
> > > > > type-specific language options.  Most of the compiler will at least 
> > > > > still be able to consider only those type-specific language options.
> > > > > 
> > > > > But I'd like to get some driver experts to think about it.
> > > > Removing the check 
> > > > CGF.getTarget().shouldEmitFloat16WithExcessPrecision()) here is not 
> > > > correct as it will perform excess precision for non-x86 architecture.  
> > > > So, for now it needs to stay until we decide what needs to be done.
> > > > Would it be a good alternative (may be not cheap though) to have 
> > > > LangOptions::useFloat16Precision() take a target as argument?
> > > > Sorry, I'm waffling about the right way to handle this.  Let me lay out 
> > > > what I'm thinking.
> > > > 
> > > > 1. It's best if, by the time we get into the main compiler operation, 
> > > > there's a single place we can check to ask if a particular type should 
> > > > use excess precision.  This code can actually be relatively hot, so we 
> > > > want it to be cheap to check, and for correctness we want it to be a 
> > > > simple condition.
> > > May be in LangOptions::useFloat16Precision()? We could also have 
> > > LangOptions::useBFloat16Precision and son on?
> > > > 
> > > > 2. I don't like

[PATCH] D139029: [clang-format] Don't move comments if AlignTrailingComments: Kind: Leave

2022-12-01 Thread Yusuke Kadowaki via Phabricator via cfe-commits
yusuke-kadowaki added a comment.

@mairacanal 
Thank you for the catch!




Comment at: clang/unittests/Format/FormatTestComments.cpp:3101
+  // Allow to keep 2 empty lines
+  Style.MaxEmptyLinesToKeep = 2;
+  EXPECT_EQ("// do not touch\n"

This should probably be reset after this testcase to avoid side effects for 
other test cases.


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

https://reviews.llvm.org/D139029

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


[PATCH] D138822: [clang] Add test for CWG36

2022-12-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.



Comment at: clang/test/CXX/drs/dr0xx.cpp:489
+
+using B::i; // expected-error {{redeclaration of using declaration}}
+using C::i; // expected-error {{redeclaration of using declaration}}

aaron.ballman wrote:
> Endill wrote:
> > aaron.ballman wrote:
> > > Endill wrote:
> > > > erichkeane wrote:
> > > > > Endill wrote:
> > > > > > erichkeane wrote:
> > > > > > > As a nit, I prefer the 'notes' to live next to the error, and use 
> > > > > > > a bookmark line-marker here.  My issue is basically how we have 
> > > > > > > no way of knowing (particularly in template code...) what this 
> > > > > > > diagnoses.
> > > > > > > 
> > > > > > > I would also think a dependent example of this diagnostic would 
> > > > > > > be useful.
> > > > > > >I would also think a dependent example of this diagnostic would be 
> > > > > > >useful.
> > > > > > Do you mean something of this sort: `using D::i`?
> > > > > That is a good example too, but more a case where the using 
> > > > > expression is dependent, so something like: `using Struct::i` 
> > > > > sorta thing
> > > > > I prefer the 'notes' to live next to the error
> > > > done
> > > > 
> > > > > I would also think a dependent example of this diagnostic would be 
> > > > > useful.
> > > > I'm not sure how you wanted it to interact with virtual bases, so I 
> > > > wrote examples both with virtual bases and without
> > > > 
> > > > > use a bookmark line-marker here
> > > > While I'm sympathetic to your concern, and agree that bookmarks allow 
> > > > to order expected errors and notes in the order they would appear for 
> > > > user, searching for `@#` gives only 5 DR tests. If that's the direction 
> > > > we want DR tests to take, we should be explicit about this, because 
> > > > almost all existing tests have to be adjusted.
> > > > While I'm sympathetic to your concern, and agree that bookmarks allow 
> > > > to order expected errors and notes in the order they would appear for 
> > > > user, searching for @# gives only 5 DR tests. If that's the direction 
> > > > we want DR tests to take, we should be explicit about this, because 
> > > > almost all existing tests have to be adjusted.
> > > 
> > > FWIW, we don't have to adjust all the tests -- sometimes bookmarks make 
> > > things more clear, other times they don't help all that much, and it's an 
> > > equivalent test either way. My recommendation is to use bookmarks when 
> > > you think they make sense to use or when a reviewer asks for one. 
> > > Updating other tests can be done with NFC changes if someone sees a 
> > > particular need.
> > > FWIW, we don't have to adjust all the tests -- sometimes bookmarks make 
> > > things more clear, other times they don't help all that much, and it's an 
> > > equivalent test either way. My recommendation is to use bookmarks when 
> > > you think they make sense to use or when a reviewer asks for one. 
> > > Updating other tests can be done with NFC changes if someone sees a 
> > > particular need.
> > 
> > The concern about expected-note comments scattered across a test seems 
> > applicable to any test with more than one expected-warning or 
> > expected-error. If maintainers agree that it should be addressed with 
> > bookmarks, I'll update this patch, and make NFC commits to fix existing 
> > tests.
> > 
> > What I'd like to avoid is introducing even more inconsistencies into DR 
> > tests. Until very recently (before tests for 2565 and 2628), bookmarks have 
> > been used only under `#if __cplusplus`, where you don't have any other 
> > straightforward option (e.g. dr100).
> > The concern about expected-note comments scattered across a test seems 
> > applicable to any test with more than one expected-warning or 
> > expected-error.
> 
> To me, it's less about the number of expected diagnostics and more about 
> locality of the diagnostics. If the warning/error and note are only a few 
> lines away from one another, I (personally) don't use bookmarks because the 
> syntax is a bit novel, especially for newcomers. But if there is quite a bit 
> of space between the warning/error and the note, then I like using bookmarks 
> because it helps me to pair the note with the diagnostic. e.g.,
> ```
> // To me, this is fine.
> int note_goes_here; // expected-note {{the bad thing was declared here}}
> foo(note_goes_here); // expected-warning {{something went wrong with this 
> argument}}
> ```
> ```
> // To me, this is also fine.
> int note_goes_here; // #bad_thing
> // ... lots of code ...
> // ... even more code ...
> foo(note_goes_here); // expected-warning {{something went wrong with this 
> argument}} \
> expected-note@#bad_thing {{the bad thing was declared 
> here}}
> ```
> but it's a value judgment as to what "quite a bit of space" is and whether 
> using the bookmark improves the test or not. So:
> ```
> // To me, this is not really

[PATCH] D139113: Fix a couple additional cases in misc-use-anonymous-namespace only

2022-12-01 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp created this revision.
Herald added a reviewer: njames93.
Herald added a project: All.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

- Do not analyze header files, since we don't want to promote using anonymous 
namespaces there.

- Do not warn about const/constexpr variables, those are implicitly static and 
they don't need to be moved to an anonymous namespace. Warning about redundant 
static in general could be implemented as a standalone check, moving away some 
of the functionality from this check.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139113

Files:
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
  clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t
+// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t -- 
-header-filter=.* -- -I%S/Inputs
+#include "use-anonymous-namespace.h"
 
 static void f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', 
move to anonymous namespace instead [misc-use-anonymous-namespace]
@@ -48,12 +49,16 @@
 
 // OK
 struct Foo {
-  static void f();
-  static int x;
+  static void f8();
+  static int x8;
 };
 
 // OK
 void foo()
 {
-  static int x;
+  static int x9;
 }
+
+// OK
+static const int x10{123};
+static constexpr int x11{123};
Index: 
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
@@ -0,0 +1,3 @@
+// Should not warn here, require anonymous namespaces only in source files
+static int g1{123};
+static void g2(){}
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -39,6 +39,11 @@
 
 template 
 void UseAnonymousNamespaceCheck::processMatch(const T *MatchedDecl) {
+  // Enforce anonymous namespaces only in source files, not headers
+  const SourceManager &SM = MatchedDecl->getASTContext().getSourceManager();
+  if (!SM.isWrittenInMainFile(MatchedDecl->getLocation()))
+return;
+
   StringRef Type = llvm::isa(MatchedDecl) ? "variable" : "function";
   if (isInAnonymousNamespace(MatchedDecl))
 diag(MatchedDecl->getLocation(), "%0 %1 declared 'static' in "
@@ -54,7 +59,8 @@
   Finder->addMatcher(
   functionDecl(isStatic(), unless(isMemberFunction())).bind("func"), this);
   Finder->addMatcher(
-  varDecl(isStatic(), unless(anyOf(isStaticLocal(), isStaticDataMember(
+  varDecl(isStatic(), unless(anyOf(isStaticLocal(), isStaticDataMember(),
+   hasType(isConstQualified()
   .bind("var"),
   this);
 }


Index: clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t
+// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t -- -header-filter=.* -- -I%S/Inputs
+#include "use-anonymous-namespace.h"
 
 static void f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]
@@ -48,12 +49,16 @@
 
 // OK
 struct Foo {
-  static void f();
-  static int x;
+  static void f8();
+  static int x8;
 };
 
 // OK
 void foo()
 {
-  static int x;
+  static int x9;
 }
+
+// OK
+static const int x10{123};
+static constexpr int x11{123};
Index: clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
@@ -0,0 +1,3 @@
+// Should not warn here, require anonymous namespaces only in source files
+static int g1{123};
+static void g2(){}
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespac

[PATCH] D138117: [clang][docs] Correct floating point option explanations

2022-12-01 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam accepted this revision.
zahiraam added a comment.
This revision is now accepted and ready to land.

In D138117#3963560 , @kawashima-fj 
wrote:

> Addressed to @zahiraam's comment

Looks good.


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

https://reviews.llvm.org/D138117

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-12-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 479281.
pmatos added a comment.

Ready for review.

RFC: https://discourse.llvm.org/t/rfc-webassembly-reference-types-in-clang/66939


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp

Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -304,6 +304,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(10)
+  static PointerType *Ty = PointerType::get(C, 10);
+  return Ty;
+}
+
+Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(20)
+  static PointerType *Ty = PointerType::get(C, 20);
+  return Ty;
+}
+
 //===--===//
 //   IntegerType Implementation
 //===--===//
Index: llvm/lib/CodeGen/ValueTypes.cpp
===
--- llvm/lib/CodeGen/ValueTypes.cpp
+++ llvm/lib/CodeGen/ValueTypes.cpp
@@ -204,12 +204,8 @@
   case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
   case MVT::x86amx:  return Type::getX86_AMXTy(Context);
   case MVT::i64x8:   return IntegerType::get(Context, 512);
-  case MVT::externref:
-// pointer to opaque struct in addrspace(10)
-return PointerType::get(StructType::create(Context), 10);
-  case MVT::funcref:
-// pointer to i8 addrspace(20)
-return PointerType::get(Type::getInt8Ty(Context), 20);
+  case MVT::externref: return Type::getWasm_ExternrefTy(Context);
+  case MVT::funcref: return Type::getWasm_FuncrefTy(Context);
   case MVT::v1i1:
 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
   case MVT::v2i1:
Index: llvm/include/llvm/IR/Type.h
===
--- llvm/include/llvm/IR/Type.h
+++ llvm/include/llvm/IR/Type.h
@@ -487,6 +487,8 @@
   static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
+  static Type *getWasm_ExternrefTy(LLVMContext &C);
+  static Type *getWasm_FuncrefTy(LLVMContext &C);
 
   /// Return a pointer to the current type. This is equivalent to
   /// PointerType::get(Foo, AddrSpace).
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1627,6 +1627,8 @@
 #include "clang/Basic/PPCTypes.def"
 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/te

[PATCH] D128440: [WebAssembly] Initial support for reference type funcref in clang

2022-12-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 479282.
pmatos added a comment.

Ready for review.

RFC: https://discourse.llvm.org/t/rfc-webassembly-reference-types-in-clang/66939


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128440

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Format/FormatToken.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/WebAssembly/wasm-funcref.c
  clang/test/SemaTemplate/address_space-dependent.cpp

Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388586)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x7FFFEA>();
+  correct<0x7FFFE9>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/CodeGen/WebAssembly/wasm-funcref.c
===
--- /dev/null
+++ clang/test/CodeGen/WebAssembly/wasm-funcref.c
@@ -0,0 +1,84 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple wasm32 -target-feature +reference-types -o - -emit-llvm %s | FileCheck %s
+
+typedef void (*__funcref funcref_t)();
+typedef int (*__funcref fn_funcref_t)(int);
+typedef int (*fn_t)(int);
+
+// Null funcref builtin call
+// CHECK-LABEL: @get_null(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t get_null() {
+  return __builtin_wasm_ref_null_func();
+}
+
+// Call to null funcref builtin but requires cast since
+// default return value for builtin is a funcref with function type () -> ().
+// CHECK-LABEL: @get_null_ii(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.ref.null.func()
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+fn_funcref_t get_null_ii() {
+  return (fn_funcref_t) __builtin_wasm_ref_null_func();
+}
+
+// Identity function for funcref.
+// CHECK-LABEL: @identity(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:ret ptr addrspace(20) [[TMP0]]
+//
+funcref_t identity(funcref_t fn) {
+  return fn;
+}
+
+void helper(funcref_t);
+
+// Pass funcref ref as an argument to a helper function.
+// CHECK-LABEL: @handle(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FN_ADDR:%.*]] = alloca ptr addrspace(20), align 4
+// CHECK-NEXT:store ptr addrspace(20) [[FN:%.*]], ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(20), ptr [[FN_ADDR]], align 4
+// CHECK-NEXT:call void @helper(ptr addrspace(20) noundef [[TMP0]])
+// CHECK-NEXT:ret i32 0
+//
+int handle(funcref_t fn) {
+  helper(fn);
+  return 0;
+}
+
+// Return funcref from function pointer.
+// CHECK-LABEL: @get_ref(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FNPTR_ADDR:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:store ptr [[FNPTR:%.*]], ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[FNPTR_ADDR]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = addrspacecast ptr [[TM

[PATCH] D139114: [Clang][Sema] Enabled Wshorten-64-to-32 for CompoundAssignment operator. This change enables Wshorten-64-to-32 waring for compound assignment statements which has implicit conversion

2022-12-01 Thread Fahad Nayyar via Phabricator via cfe-commits
fahadnayyar created this revision.
Herald added a project: All.
fahadnayyar requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

...://10466193


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139114

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/conversion-64-32.c

Index: clang/test/Sema/conversion-64-32.c
===
--- clang/test/Sema/conversion-64-32.c
+++ clang/test/Sema/conversion-64-32.c
@@ -17,3 +17,25 @@
 int test2(long v) {
   return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
 }
+
+// rdar://10466193
+void test3(int i, long long ll) {
+  i += ll; // expected-warning {{implicit conversion loses integer precision}}
+  i -= ll; // expected-warning {{implicit conversion loses integer precision}}
+  i *= ll; // expected-warning {{implicit conversion loses integer precision}}
+  i /= ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+void test4(int i, long long ll) {
+  i += i-ll; // expected-warning {{implicit conversion loses integer precision}}
+  i += i+ll; // expected-warning {{implicit conversion loses integer precision}}
+  i -= i-ll; // expected-warning {{implicit conversion loses integer precision}}
+  i -= i+ll; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+void test5(int i, int j, long long ll) {
+  i += (i-j)*ll; // expected-warning {{implicit conversion loses integer precision}}
+  i += (i+j)*ll; // expected-warning {{implicit conversion loses integer precision}}
+  i -= ll/(i-j); // expected-warning {{implicit conversion loses integer precision}}
+  i -= ll/(i-j); // expected-warning {{implicit conversion loses integer precision}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -13374,44 +13374,6 @@
   }
 }
 
-/// Analyze the given compound assignment for the possible losing of
-/// floating-point precision.
-static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
-  assert(isa(E) &&
- "Must be compound assignment operation");
-  // Recurse on the LHS and RHS in here
-  AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
-  AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
-
-  if (E->getLHS()->getType()->isAtomicType())
-S.Diag(E->getOperatorLoc(), diag::warn_atomic_implicit_seq_cst);
-
-  // Now check the outermost expression
-  const auto *ResultBT = E->getLHS()->getType()->getAs();
-  const auto *RBT = cast(E)
-->getComputationResultType()
-->getAs();
-
-  // The below checks assume source is floating point.
-  if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
-
-  // If source is floating point but target is an integer.
-  if (ResultBT->isInteger())
-return DiagnoseImpCast(S, E, E->getRHS()->getType(), E->getLHS()->getType(),
-   E->getExprLoc(), diag::warn_impcast_float_integer);
-
-  if (!ResultBT->isFloatingPoint())
-return;
-
-  // If both source and target are floating points, warn about losing precision.
-  int Order = S.getASTContext().getFloatingTypeSemanticOrder(
-  QualType(ResultBT, 0), QualType(RBT, 0));
-  if (Order < 0 && !S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
-// warn about dropping FP rank.
-DiagnoseImpCast(S, E->getRHS(), E->getLHS()->getType(), E->getOperatorLoc(),
-diag::warn_impcast_float_result_precision);
-}
-
 static std::string PrettyPrintInRange(const llvm::APSInt &Value,
   IntRange Range) {
   if (!Range.Width) return "0";
@@ -14150,6 +14112,49 @@
   }
 }
 
+/// Analyze the given compound assignment for the possible losing of
+/// floating-point precision.
+static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
+  assert(isa(E) &&
+ "Must be compound assignment operation");
+  // Recurse on the LHS and RHS in here
+  AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
+  AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
+
+  if (E->getLHS()->getType()->isAtomicType())
+S.Diag(E->getOperatorLoc(), diag::warn_atomic_implicit_seq_cst);
+
+  // Now check the outermost expression
+  const auto *ResultBT = E->getLHS()->getType()->getAs();
+  const auto *RBT = cast(E)
+->getComputationResultType()
+->getAs();
+
+  // Check for implicit conversion loss of precision form 64-to-32 for compound
+  // statements.
+  if (E->getLHS()->getType()->isIntegerType() && E->getRHS()->getType()->isIntegerType() && !E->isShiftAssignOp())
+CheckImplicitConversion(S, E->getRHS(), E->getType(), E->getRHS()->getExprLoc());
+
+  // The below checks assume source is floating point.
+  if

[PATCH] D139113: Fix a couple additional cases in misc-use-anonymous-namespace only

2022-12-01 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 479284.
carlosgalvezp added a comment.

Fix naming convention


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139113

Files:
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
  clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t
+// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t -- 
-header-filter=.* -- -I%S/Inputs
+#include "use-anonymous-namespace.h"
 
 static void f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', 
move to anonymous namespace instead [misc-use-anonymous-namespace]
@@ -48,12 +49,16 @@
 
 // OK
 struct Foo {
-  static void f();
-  static int x;
+  static void f8();
+  static int v8;
 };
 
 // OK
 void foo()
 {
-  static int x;
+  static int v9;
 }
+
+// OK
+static const int v10{123};
+static constexpr int v11{123};
Index: 
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
===
--- /dev/null
+++ 
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
@@ -0,0 +1,3 @@
+// Should not warn here, require anonymous namespaces only in source files
+static int gv{123};
+static void gf(){}
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -39,6 +39,11 @@
 
 template 
 void UseAnonymousNamespaceCheck::processMatch(const T *MatchedDecl) {
+  // Enforce anonymous namespaces only in source files, not headers
+  const SourceManager &SM = MatchedDecl->getASTContext().getSourceManager();
+  if (!SM.isWrittenInMainFile(MatchedDecl->getLocation()))
+return;
+
   StringRef Type = llvm::isa(MatchedDecl) ? "variable" : "function";
   if (isInAnonymousNamespace(MatchedDecl))
 diag(MatchedDecl->getLocation(), "%0 %1 declared 'static' in "
@@ -54,7 +59,8 @@
   Finder->addMatcher(
   functionDecl(isStatic(), unless(isMemberFunction())).bind("func"), this);
   Finder->addMatcher(
-  varDecl(isStatic(), unless(anyOf(isStaticLocal(), isStaticDataMember(
+  varDecl(isStatic(), unless(anyOf(isStaticLocal(), isStaticDataMember(),
+   hasType(isConstQualified()
   .bind("var"),
   this);
 }


Index: clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/use-anonymous-namespace.cpp
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t
+// RUN: %check_clang_tidy %s misc-use-anonymous-namespace %t -- -header-filter=.* -- -I%S/Inputs
+#include "use-anonymous-namespace.h"
 
 static void f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f1' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]
@@ -48,12 +49,16 @@
 
 // OK
 struct Foo {
-  static void f();
-  static int x;
+  static void f8();
+  static int v8;
 };
 
 // OK
 void foo()
 {
-  static int x;
+  static int v9;
 }
+
+// OK
+static const int v10{123};
+static constexpr int v11{123};
Index: clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/use-anonymous-namespace.h
@@ -0,0 +1,3 @@
+// Should not warn here, require anonymous namespaces only in source files
+static int gv{123};
+static void gf(){}
Index: clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -39,6 +39,11 @@
 
 template 
 void UseAnonymousNamespaceCheck::processMatch(const T *MatchedDecl) {
+  // Enforce anonymous namespaces only in source files, not headers
+  const SourceManager &SM = MatchedDecl->getASTContext().getSourceManager();
+  if (!SM.isWrittenInMainFile(MatchedDecl->getLocation()))
+return;
+
   StringRef Type = llvm::isa(Ma

[PATCH] D137043: [clang] add implicit include for Linux/gnu compatibility

2022-12-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I unfortunately am equally not informed enough to help here.  The code itself 
looks fine to me, but I'm unable to make a value judgement on the change itself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137043

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


[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1127
 return false;
-  if (!this->emitInitGlobal(*T, *I, VD))
+}
+  } else {

tbaeder wrote:
> aaron.ballman wrote:
> > and if we have no `GlobalIndex`?
> > 
> > Should this instead be:
> > ```
> > if (auto GlobalIndex = P.getGlobal(VD); !GlobalIndex || 
> > !this->emitGetPtrGlobal(*GlobalIndex, VD))
> >   return false;
> > ```
> > 
> I mean, that shouldn't happen because the `visitVarDecl` call before would've 
> returned `false` in that case.
The use of an `if` makes it seem like it could fail. Perhaps we should drop the 
`if` and use an `assert`?



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1161
+  if (VarT) {
+if (!this->visit(Init))
   return false;

tbaeder wrote:
> aaron.ballman wrote:
> > What if `Init` is `nullptr`?
> Global variables (or local constexpr ones) must have an initializer, no?
Hmm, I was thinking of:
```
struct S {};
constexpr S s;
```
but now that I think on it, that still has a non-null init expression, so I 
think it's safe for us to assert `Init` is nonnull.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.h:262
+  /// given VarDecl.
+  bool ShouldBeGloballyIndexed(const VarDecl *VD) const {
+return !VD->hasLocalStorage() || VD->isConstexpr();




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

https://reviews.llvm.org/D136815

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


[clang] aa14968 - [PS4/PS5] Canonicalize tests to use 'target=.*-(ps4|ps5)'

2022-12-01 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-12-01T07:21:07-08:00
New Revision: aa149687dc76f304a5228a167f4eebf19e5fb2d7

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

LOG: [PS4/PS5] Canonicalize tests to use 'target=.*-(ps4|ps5)'

This allows grepping for ps4 or ps5 to continue to work.

Added: 


Modified: 
clang/test/Driver/experimental-library-flag.cpp
clang/test/Driver/lld-repro.c
clang/test/Driver/nostdincxx.cpp
clang/test/Modules/crash-vfs-path-traversal.m
clang/test/Preprocessor/lang-std.cpp

Removed: 




diff  --git a/clang/test/Driver/experimental-library-flag.cpp 
b/clang/test/Driver/experimental-library-flag.cpp
index 6f827ccd6275b..eec5df1bd3a77 100644
--- a/clang/test/Driver/experimental-library-flag.cpp
+++ b/clang/test/Driver/experimental-library-flag.cpp
@@ -1,6 +1,6 @@
 // On some platforms, -stdlib=libc++ is currently ignored, so 
-lc++experimental is not added.
 // Once -stdlib=libc++ works on those, this XFAIL can be removed.
-// XFAIL: target={{.*-windows.*}}, target={{.*-ps(4|5)}}
+// XFAIL: target={{.*-windows.*}}, target={{.*-(ps4|ps5)}}
 
 // For some reason, this fails with a core dump on AIX. This needs to be 
investigated.
 // UNSUPPORTED: aix

diff  --git a/clang/test/Driver/lld-repro.c b/clang/test/Driver/lld-repro.c
index 9fc37d98cef6c..9457dd334b5b9 100644
--- a/clang/test/Driver/lld-repro.c
+++ b/clang/test/Driver/lld-repro.c
@@ -1,5 +1,5 @@
 // REQUIRES: lld
-// UNSUPPORTED: target={{.*-ps(4|5)}}
+// UNSUPPORTED: target={{.*-(ps4|ps5)}}
 
 // RUN: echo "-nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error 
-fcrash-diagnostics-dir=%t" \
 // RUN:   | sed -e 's/\\//g' > %t.rsp

diff  --git a/clang/test/Driver/nostdincxx.cpp 
b/clang/test/Driver/nostdincxx.cpp
index 11fd59fab2c29..ef5702a19c037 100644
--- a/clang/test/Driver/nostdincxx.cpp
+++ b/clang/test/Driver/nostdincxx.cpp
@@ -6,4 +6,4 @@
 #include 
 
 // MSVC, PS4, PS5 have C++ headers in the same directory as C headers.
-// UNSUPPORTED: ms-sdk, target={{.*-ps(4|5)}}
+// UNSUPPORTED: ms-sdk, target={{.*-(ps4|ps5)}}

diff  --git a/clang/test/Modules/crash-vfs-path-traversal.m 
b/clang/test/Modules/crash-vfs-path-traversal.m
index 6cd43a440cc94..891c7960f08b1 100644
--- a/clang/test/Modules/crash-vfs-path-traversal.m
+++ b/clang/test/Modules/crash-vfs-path-traversal.m
@@ -1,5 +1,5 @@
 // REQUIRES: crash-recovery, shell
-// UNSUPPORTED: ms-sdk, target={{.*-ps4}}
+// UNSUPPORTED: ms-sdk, target={{.*-(ps4|ps5)}}
 
 // FIXME: Canonicalizing paths to remove relative traversal components
 // currenty fails a unittest on windows and is disable by default.

diff  --git a/clang/test/Preprocessor/lang-std.cpp 
b/clang/test/Preprocessor/lang-std.cpp
index 86aeb9ad45d51..881d38641bc73 100644
--- a/clang/test/Preprocessor/lang-std.cpp
+++ b/clang/test/Preprocessor/lang-std.cpp
@@ -1,4 +1,4 @@
-// UNSUPPORTED: target={{.*-ps(4|5)}}
+// UNSUPPORTED: target={{.*-(ps4|ps5)}}
 /// Test default standards.
 /// PS4/PS5 default to gnu++14.
 



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


[PATCH] D139090: [clang] Add test for CWG360

2022-12-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/CXX/drs/dr3xx.cpp:908
+public:
+  using A::baz; // #dr360-baz-using-decl
+};

aaron.ballman wrote:
> Endill wrote:
> > erichkeane wrote:
> > > This bookmark isn't necessary, so no reason to have it.  But thank you 
> > > for using these!
> > Nice catch, thank you!
> > Seems like I should've waited a bit more before committing.
> Good catch Erich!
> 
> Feel free to fix the comment up with an NFC commit (you don't need anyone to 
> review it because there's no functional change).
Don't worry about it, this is a trivial issue I just saw while 
scrolling/admiring the bookmarks :D  a follow-up review-after-commit patch 
would be fine here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139090

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


[clang] e83f150 - [AArch64] Improve TargetParser API

2022-12-01 Thread Tomas Matheson via cfe-commits

Author: Tomas Matheson
Date: 2022-12-01T15:30:07Z
New Revision: e83f1502f1be7a2a3b9a33f5a73867767e78ba6b

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

LOG: [AArch64] Improve TargetParser API

Re-land with constexpr StringRef::substr():

The TargetParser depends heavily on a collection of macros and enums to tie
together information about architectures, CPUs and extensions. Over time this
has led to some pretty awkward API choices. For example, recently a custom
operator-- has been added to the enum, which effectively turns iteration into
a graph traversal and makes the ordering of the macro calls in the header
significant. More generally there is a lot of string <-> enum conversion
going on. I think this shows the extent to which the current data structures
are constraining us, and the need for a rethink.

Key changes:

 - Get rid of Arch enum, which is used to bind fields together. Instead of
   passing around ArchKind, use the named ArchInfo objects directly or via
   references.

 - The list of all known ArchInfo becomes an array of pointers.

 - ArchKind::operator-- is replaced with ArchInfo::implies(), which defines
   which architectures are predecessors to each other. This allows features
   from predecessor architectures to be added in a more intuitive way.

 - Free functions of the form f(ArchKind) are converted to ArchInfo::f(). Some
   functions become unnecessary and are deleted.

 - Version number and profile are added to the ArchInfo. This makes comparison
   of architectures easier and moves a couple of functions out of clang and
   into AArch64TargetParser.

 - clang::AArch64TargetInfo ArchInfo is initialised to Armv8a not INVALID.

 - AArch64::ArchProfile which is distinct from ARM::ArchProfile

 - Give things sensible names and add some comments.

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

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
llvm/include/llvm/ADT/StringRef.h
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/include/llvm/Support/VersionTuple.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c36e942cf46ac..edc4fdca26378 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -45,28 +45,6 @@ const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
 #include "clang/Basic/BuiltinsAArch64.def"
 };
 
-static StringRef getArchVersionString(llvm::AArch64::ArchKind Kind) {
-  switch (Kind) {
-  case llvm::AArch64::ArchKind::ARMV9A:
-  case llvm::AArch64::ArchKind::ARMV9_1A:
-  case llvm::AArch64::ArchKind::ARMV9_2A:
-  case llvm::AArch64::ArchKind::ARMV9_3A:
-  case llvm::AArch64::ArchKind::ARMV9_4A:
-return "9";
-  default:
-return "8";
-  }
-}
-
-StringRef AArch64TargetInfo::getArchProfile() const {
-  switch (ArchKind) {
-  case llvm::AArch64::ArchKind::ARMV8R:
-return "R";
-  default:
-return "A";
-  }
-}
-
 AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
  const TargetOptions &Opts)
 : TargetInfo(Triple), ABI("aapcs") {
@@ -170,7 +148,7 @@ bool AArch64TargetInfo::validateBranchProtection(StringRef 
Spec, StringRef,
 
 bool AArch64TargetInfo::isValidCPUName(StringRef Name) const {
   return Name == "generic" ||
- llvm::AArch64::parseCPUArch(Name) != llvm::AArch64::ArchKind::INVALID;
+ llvm::AArch64::parseCpu(Name).Arch != llvm::AArch64::INVALID;
 }
 
 bool AArch64TargetInfo::setCPU(const std::string &Name) {
@@ -298,8 +276,10 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   // ACLE predefines. Many can only have one possible value on v8 AArch64.
   Builder.defineMacro("__ARM_ACLE", "200");
-  Builder.defineMacro("__ARM_ARCH", getArchVersionString(ArchKind));
-  Builder.defineMacro("__ARM_ARCH_PROFILE", "'" + getArchProfile() + "'");
+  Builder.defineMacro("__ARM_ARCH",
+  std::to_string(ArchInfo->Version.getMajor()));
+  Builder.defineMacro("__ARM_ARCH_PROFILE",
+  std::string("'") + (char)ArchInfo->Profile + "'");
 
   Builder.defineMacro("__ARM_64BIT_STATE", "1");
   Builder.defineMacro("__ARM_PCS_AAPCS64", "1");
@@ -464,52 +444,34 @@ void AArch64TargetInfo::getTargetDefines(const 
LangOptions &Opts,
   if (HasD128)
 Builder.defineMacro("__ARM_FEATURE_SYSREG128", "1");
 
-  switch (ArchKind) {
-  default:
-break;
-  case llvm::AArch64::ArchKind::ARMV8_1A:
+  if (*Ar

[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 4 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1127
 return false;
-  if (!this->emitInitGlobal(*T, *I, VD))
+}
+  } else {

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > and if we have no `GlobalIndex`?
> > > 
> > > Should this instead be:
> > > ```
> > > if (auto GlobalIndex = P.getGlobal(VD); !GlobalIndex || 
> > > !this->emitGetPtrGlobal(*GlobalIndex, VD))
> > >   return false;
> > > ```
> > > 
> > I mean, that shouldn't happen because the `visitVarDecl` call before 
> > would've returned `false` in that case.
> The use of an `if` makes it seem like it could fail. Perhaps we should drop 
> the `if` and use an `assert`?
What do you think about returning a `tuple(valid, offset)` from `visitVarDecl`? 
Although that might make the call in `ByteCodeStmtGen.cpp` a little awkward.


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

https://reviews.llvm.org/D136815

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


[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 479294.

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

https://reviews.llvm.org/D136815

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h

Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -79,7 +79,8 @@
   llvm::Optional getGlobal(const ValueDecl *VD);
 
   /// Returns or creates a global an creates an index to it.
-  llvm::Optional getOrCreateGlobal(const ValueDecl *VD);
+  llvm::Optional getOrCreateGlobal(const ValueDecl *VD,
+ const Expr *Init = nullptr);
 
   /// Returns or creates a dummy value for parameters.
   llvm::Optional getOrCreateDummy(const ParmVarDecl *PD);
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -124,11 +124,12 @@
   return Index;
 }
 
-llvm::Optional Program::getOrCreateGlobal(const ValueDecl *VD) {
+llvm::Optional Program::getOrCreateGlobal(const ValueDecl *VD,
+const Expr *Init) {
   if (auto Idx = getGlobal(VD))
 return Idx;
 
-  if (auto Idx = createGlobal(VD, nullptr)) {
+  if (auto Idx = createGlobal(VD, Init)) {
 GlobalIndices[VD] = *Idx;
 return Idx;
   }
@@ -156,6 +157,7 @@
 
 llvm::Optional Program::createGlobal(const ValueDecl *VD,
const Expr *Init) {
+  assert(!getGlobal(VD));
   bool IsStatic, IsExtern;
   if (auto *Var = dyn_cast(VD)) {
 IsStatic = !Var->hasLocalStorage();
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -65,7 +65,6 @@
   bool visitContinueStmt(const ContinueStmt *S);
 
   /// Compiles a variable declaration.
-  bool visitVarDecl(const VarDecl *VD);
 
 private:
   /// Type of the expression returned by the function.
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -207,7 +207,7 @@
   for (auto *D : DS->decls()) {
 // Variable declarator.
 if (auto *VD = dyn_cast(D)) {
-  if (!visitVarDecl(VD))
+  if (!this->visitVarDecl(VD))
 return false;
   continue;
 }
@@ -391,37 +391,6 @@
   return this->jump(*ContinueLabel);
 }
 
-template 
-bool ByteCodeStmtGen::visitVarDecl(const VarDecl *VD) {
-  if (!VD->hasLocalStorage()) {
-// No code generation required.
-return true;
-  }
-
-  // Integers, pointers, primitives.
-  if (Optional T = this->classify(VD->getType())) {
-const Expr *Init = VD->getInit();
-
-unsigned Offset =
-this->allocateLocalPrimitive(VD, *T, VD->getType().isConstQualified());
-// Compile the initializer in its own scope.
-if (Init) {
-  ExprScope Scope(this);
-  if (!this->visit(Init))
-return false;
-
-  return this->emitSetLocal(*T, Offset, VD);
-}
-return true;
-  }
-
-  // Composite types - allocate storage and initialize it.
-  if (Optional Offset = this->allocateLocal(VD))
-return this->visitLocalInitializer(VD->getInit(), *Offset);
-
-  return this->bail(VD);
-}
-
 namespace clang {
 namespace interp {
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -152,6 +152,8 @@
   bool visitArrayInitializer(const Expr *Initializer);
   /// Compiles a record initializer.
   bool visitRecordInitializer(const Expr *Initializer);
+  /// Creates and initializes a variable from the given decl.
+  bool visitVarDecl(const VarDecl *VD);
 
   /// Visits an expression and converts it to a boolean.
   bool visitBool(const Expr *E);
@@ -255,6 +257,12 @@
 return T->getAsCXXRecordDecl();
   }
 
+  /// Returns whether we should create a global variable for the
+  /// given VarDecl.
+  bool shouldBeGloballyIndexed(const VarDecl *VD) const {
+return VD->hasGlobalStorage() || VD->isConstexpr();
+  }
+
 protected:
   /// Variable to storage mapping.
   llvm::DenseMap Locals;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -854,6 +854,13 @@
   PrimType Ty,
   bool IsC

[PATCH] D137437: [lit][AIX] Convert clang tests to use 'target={{.*}}-aix{{.*}}'

2022-12-01 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Lacking an LGTM from someone with AIX knowledge, I see there's a bot 
"clang-ppc64-aix" where I can verify that the test results haven't changed. For 
this review the set of tests are mostly UNSUPPORTED, except for three XFAIL.  
I'll let this sit a little while in case someone has an objection, then go 
ahead with that plan.


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

https://reviews.llvm.org/D137437

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


[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1127
 return false;
-  if (!this->emitInitGlobal(*T, *I, VD))
+}
+  } else {

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > and if we have no `GlobalIndex`?
> > > > 
> > > > Should this instead be:
> > > > ```
> > > > if (auto GlobalIndex = P.getGlobal(VD); !GlobalIndex || 
> > > > !this->emitGetPtrGlobal(*GlobalIndex, VD))
> > > >   return false;
> > > > ```
> > > > 
> > > I mean, that shouldn't happen because the `visitVarDecl` call before 
> > > would've returned `false` in that case.
> > The use of an `if` makes it seem like it could fail. Perhaps we should drop 
> > the `if` and use an `assert`?
> What do you think about returning a `tuple(valid, offset)` from 
> `visitVarDecl`? Although that might make the call in `ByteCodeStmtGen.cpp` a 
> little awkward.
H, I don't think I'd like to see a tuple, but seeing an `llvm::ErrorOr<>` 
or a `std::optional<>` might be reasonable. The downside is that the `visit*` 
functions then won't have a uniform return type (can't do `ErrorOr` that 
I'm aware of)


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

https://reviews.llvm.org/D136815

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


[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1127
 return false;
-  if (!this->emitInitGlobal(*T, *I, VD))
+}
+  } else {

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > tbaeder wrote:
> > > > aaron.ballman wrote:
> > > > > and if we have no `GlobalIndex`?
> > > > > 
> > > > > Should this instead be:
> > > > > ```
> > > > > if (auto GlobalIndex = P.getGlobal(VD); !GlobalIndex || 
> > > > > !this->emitGetPtrGlobal(*GlobalIndex, VD))
> > > > >   return false;
> > > > > ```
> > > > > 
> > > > I mean, that shouldn't happen because the `visitVarDecl` call before 
> > > > would've returned `false` in that case.
> > > The use of an `if` makes it seem like it could fail. Perhaps we should 
> > > drop the `if` and use an `assert`?
> > What do you think about returning a `tuple(valid, offset)` from 
> > `visitVarDecl`? Although that might make the call in `ByteCodeStmtGen.cpp` 
> > a little awkward.
> H, I don't think I'd like to see a tuple, but seeing an `llvm::ErrorOr<>` 
> or a `std::optional<>` might be reasonable. The downside is that the `visit*` 
> functions then won't have a uniform return type (can't do `ErrorOr` 
> that I'm aware of)
The way I've seen in the past is to have it be an error-type containing a 
nullptr_t (or some sort of empty/meaningless struct).

So something like:

`ErrorOr`


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

https://reviews.llvm.org/D136815

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


[PATCH] D136694: [clang][Interp] Check that constructor calls initialize all record fields

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

LGTM!




Comment at: clang/lib/AST/Interp/Interp.h:1346-1347
   if (Func->hasThisPointer()) {
+ThisPtr = NewFrame->getThis();
 if (!CheckInvoke(S, PC, NewFrame->getThis())) {
   return false;

tbaeder wrote:
> aaron.ballman wrote:
> > Should we assert that `ThisPtr` is valid?
> We could only assert `!isZero()` as far as I understand, but that's part of 
> what `CheckInvoke` does.
Ah, then no need.


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

https://reviews.llvm.org/D136694

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-01 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 479310.
v.g.vassilev marked 2 inline comments as done.
v.g.vassilev added a comment.

Address comments, fix a fixme.


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

https://reviews.llvm.org/D127284

Files:
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DeclNodes.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Interpreter/disambiguate-decl-stmt.cpp
  clang/test/Interpreter/execute-stmts.cpp
  clang/test/Interpreter/stmt-serialization.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -124,14 +124,8 @@
   auto *PTU1 = R1->TUPart;
   EXPECT_EQ(2U, DeclsSize(PTU1));
 
-  // FIXME: Add support for wrapping and running statements.
   auto R2 = Interp->Parse("var1++; printf(\"var1 value %d\\n\", var1);");
-  EXPECT_FALSE(!!R2);
-  using ::testing::HasSubstr;
-  EXPECT_THAT(DiagnosticsOS.str(),
-  HasSubstr("error: unknown type name 'var1'"));
-  auto Err = R2.takeError();
-  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+  EXPECT_TRUE(!!R2);
 }
 
 TEST(InterpreterTest, UndoCommand) {
Index: clang/test/Interpreter/stmt-serialization.cpp
===
--- /dev/null
+++ clang/test/Interpreter/stmt-serialization.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++20 -fincremental-extensions -fmodules-cache-path=%t \
+// RUN:-x c++ %s -verify
+// expected-no-diagnostics
+
+#pragma clang module build TopLevelStmt
+module TopLevelStmt { module Statements {} }
+#pragma clang module contents
+
+#pragma clang module begin TopLevelStmt.Statements
+extern "C" int printf(const char*,...);
+int i = 0;
+i++;
+#pragma clang module end /*TopLevelStmt.Statements*/
+#pragma clang module endbuild /*TopLevelStmt*/
+
+#pragma clang module import TopLevelStmt.Statements
+
+printf("Value of i is '%d'", i);
Index: clang/test/Interpreter/execute-stmts.cpp
===
--- /dev/null
+++ clang/test/Interpreter/execute-stmts.cpp
@@ -0,0 +1,38 @@
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl -Xcc -Xclang -Xcc  -verify | FileCheck %s
+// RUN: %clang_cc1 -verify -fincremental-extensions -emit-llvm -o -  %s \
+// RUN:   | FileCheck --check-prefix=CODEGEN-CHECK %s
+
+// expected-no-diagnostics
+
+//CODEGEN-CHECK-COUNT-2: define internal void @__stmts__
+//CODEGEN-CHECK-NOT: define internal void @__stmts__
+
+
+extern "C" int printf(const char*,...);
+
+template  T call() { printf("called\n"); return T(); }
+call();
+// CHECK: called
+
+int i = 1;
+++i;
+printf("i = %d\n", i);
+// CHECK: i = 2
+
+namespace Ns { void f(){ i++; } }
+Ns::f();
+
+void g() { ++i; }
+g();
+::g();
+
+printf("i = %d\n", i);
+// CHECK-NEXT: i = 5
+
+for (; i > 4; --i) printf("i = %d\n", i);
+// CHECK-NEXT: i = 5
+
+int j = i; printf("j = %d\n", j);
+// CHECK-NEXT: j = 4
Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- /dev/null
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fincremental-extensions -std=c++20 %s
+// RUN: %clang_cc1 -fsyntax-only -DMS -fms-extensions -verify -fincremental-extensions -std=c++20 %s
+
+// expected-no-diagnostics
+
+extern "C" int printf(const char*,...);
+
+// Decls which are hard to disambiguate
+
+// ParseStatementOrDeclaration returns multiple statements.
+#ifdef MS
+int g_bFlag = 1;
+__if_exists(::g_bFlag) {
+  printf("Entering __if_exists\n");
+  printf("g_bFlag = %d\n", g_bFlag);
+}
+#endif // MS
+
+// Operators.
+struct S1 { operator int(); };
+S1::operator int() { return 0; }
+
+// Dtors
+using I = int;
+I x = 10;
+x.I::~I();
+x = 20;
+
+// Ct

[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-01 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:5395-5400
+  // FIXME: Tell the user this is unsupported.
+  if (!Stmts.empty()) {
+unsigned ID = Actions.getDiagnostics().getCustomDiagID(
+DiagnosticsEngine::Error, "Unsupported statement on the global scope");
+Actions.Diag(Stmts.back()->getBeginLoc(), ID);
+  }

aaron.ballman wrote:
> v.g.vassilev wrote:
> > aaron.ballman wrote:
> > > Why is this using a custom diagnostic instead of adding a typical 
> > > diagnostic to DiagnosticParseKinds.td?
> > I don't have a problem converting this to a DiagnosticParseKind. However, 
> > this is a temporary diagnostic and we risk once the FIXME is resolved to 
> > leave a stray diagnostic id. 
> It's been my experience that there's nothing more permanent than a temporary 
> solution, so I'd say we should go with the regular diagnostic. Also, it 
> should be worded `unsupported statement at global scope` to fit the usual 
> diagnostic wording style.
I took the liberty to address the FIXME. 


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

https://reviews.llvm.org/D127284

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-01 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:13896
+  Diag(var->getLocation(), diag::err_constexpr_var_requires_const_init)
+  << var << Init->getSourceRange();
+  }

efriedma wrote:
> rnk wrote:
> > zahiraam wrote:
> > > efriedma wrote:
> > > > zahiraam wrote:
> > > > > efriedma wrote:
> > > > > > zahiraam wrote:
> > > > > > > efriedma wrote:
> > > > > > > > I don't understand why this diagnostic is necessary.
> > > > > > > Now that the DLLImport variable can be a constant, HasConstInit 
> > > > > > > is returning true (it was before returning false) and when the 
> > > > > > > variable is global a diagnostic should be reported. 
> > > > > > > 
> > > > > > > This:
> > > > > > >   extern int _declspec(dllimport) val;
> > > > > > >   constexpr int& val_ref = val;
> > > > > > > 
> > > > > > > should report a diagnostic, but this:
> > > > > > > 
> > > > > > >   int foo() { 
> > > > > > >  extern int _declspec(dllimport) val; 
> > > > > > >  constexpr int& val_ref = val;
> > > > > > >   }
> > > > > > > 
> > > > > > >  shouldn't report a diagnostic.
> > > > > > MSVC doesn't report a diagnostic for either of your examples?
> > > > > So, these shouldn't fail anymore? 
> > > > > https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/PR19955.cpp#L5
> > > > > https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/PR19955.cpp#L8
> > > > > https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/dllimport-constexpr.cpp#L44
> > > > Right, they shouldn't fail.
> > > > 
> > > > My perspective is that since we're able to give those the expected 
> > > > semantics, we should just do that.  The only reason that "dllimport" is 
> > > > relevant at all is that there isn't a relocation for it, but our plan 
> > > > is to cover that up with a runtime constructor. So the user shouldn't 
> > > > need to know there's trickery behind the scenes unless they disassemble 
> > > > the binary.
> > > Got it! Thanks. Will remove the diagnostic here then. 
> > I worry that some of our users really do care quite a lot about constant 
> > initialization. I think emitting a special runtime initializer may be our 
> > best option (mingw does it through other means), but this is likely to be 
> > disruptive. Chrome has code which runs before CRT initialization to do some 
> > early sandboxing. ASan also competes to initialize shadow memory as early 
> > as possible (search compiler-rt for `.CRT`).
> > 
> > I worry that these users will think, "well, I've used [[constinit]] and 
> > constexpr, so this global should *definitely* be initialized during 
> > startup, and I won't have to worry about init order fiasco problems!", and 
> > then they will be surprised to find that this is not the case. Should we 
> > care? What can we do about this, realistically? Leaving behind this 
> > portability pothole of "dlimport symbols just aren't constexpr" seems 
> > worse. Our current behavior may be unduly influenced by my particular 
> > values: I think constant initialization is really important, I really care 
> > a lot about whether things are relocated or initialized at runtime.
> > 
> > I don't see any good solutions, so please carry on, but if you have any 
> > good ideas, please share. :)
> For the obscure cases where the user actually cares about that sort of thing, 
> we can make -Wglobal-constructors trigger, I guess?  I'm not sure what else 
> we could do that doesn't break the feature.
> 
> --
> 
> It might be worth trying to reach out to Microsoft to figure out a common 
> design for the runtime initialization thing.  MSVC appears to emit broken 
> code in certain cases at the moment.  For example, in the following, "z" is 
> correctly initialized at runtime, but "z2" emits a broken direct reference.
> 
> ```
> _declspec(dllimport) int x;
> constexpr int *y = &x;
> int *z = &x;
> int *z2 = y;
> ```
Thank you for the feedback.

I think these are really corner cases, right? Then maybe it's an acceptable 
solution to use the -Wglobal-constructors? I suggest we proceed with these 
changes?

@efriedma the one thing that's missing is the priority in which these 
constructors are initialized. You said in an earlier comment that they should 
have higher priority than normal global constructors. What priority should be 
given to them?  I see this PrioritizedCXXGlobalInits being filled in 
EmitCXXGlobalVarDeclInitFunc. Or should it be through AddGlobalCtor?  And what 
priority should be given to them? Should it be hard coded (horrible!)? Or 
calculated using OrderGlobalInitsOrStermFinalizers?


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

https://reviews.llvm.org/D137107

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


[PATCH] D127284: [clang-repl] Support statements on global scope in incremental mode.

2022-12-01 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev planned changes to this revision.
v.g.vassilev added a comment.

I screwed up with the last diff. Let me fix it in a bit...


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

https://reviews.llvm.org/D127284

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


[PATCH] D139122: Generalize clang-tidy modernize-pass-by-value

2022-12-01 Thread Martin Bidlingmaier via Phabricator via cfe-commits
mbid created this revision.
Herald added a subscriber: carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
mbid added a comment.
mbid published this revision for review.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Hi Nathan,

Could you have a look at whether something like this looks reasonable? The docs 
of modernize-pass-by-value currently say that a patch that generalizes this 
check is welcome. I'd polish the docs and add some more test cases before merge 
if this looks reasonable overall.

- Martin


Previously, the clang-tidy modernize-pass-by-value check would only fire
for arguments of constructors that are used exactly once and in a member
or base class initializers. This commit generalizes the check to general
functions and usages in the body of the function.

We now consider the control-flow graph of the function. If every
control-flow path must transition through one final usage of a given
parameter, we fire the diagnostic. We additionally require that the
variable is not referenced or pointed to by a local variable in the
function. There are still some false-positives, however, because we do
not try to figure out whether a pointer to the local variable escapes
through other means, e.g. here:

  struct HasStrPtr {
const std::string* str;
  };
  
  void set_ptr(HasStrPtr& has_ptr, const std::string& str) {
has_ptr.str = &str;
  }
  
  // Take argument by value.
  void foo(std::string);
  
  void foo(const std::string& str) {
HasStrPtr obj;
set_ptr(obj, str);
foo(str);
foo(*HasStrPtr.str);
  }

The example looks at first sight like we can std::move in the call to
foo, but this would change the value pointed to by the pointer in
HasStrPtr, so that the semantics of the program change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139122

Files:
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
  clang-tools-extra/docs/clang-tidy/checks/modernize/pass-by-value.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
@@ -11,6 +11,8 @@
   Movable() = default;
   Movable(const Movable &) {}
   Movable(Movable &&) {}
+  Movable& operator=(const Movable&) = default;
+  Movable& operator=(Movable&&) = default;
 };
 
 struct NotMovable {
@@ -19,12 +21,18 @@
   NotMovable(NotMovable &&) = delete;
   int a, b, c;
 };
+
+struct MovableConstructible {
+  MovableConstructible() = default;
+  MovableConstructible(Movable m) {}
+};
+
 }
 
 struct A {
-  A(const Movable &M) : M(M) {}
+  A(const Movable &MM) : M(MM) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass by value and use std::move [modernize-pass-by-value]
-  // CHECK-FIXES: A(Movable M) : M(std::move(M)) {}
+  // CHECK-FIXES: A(Movable MM) : M(std::move(MM)) {}
   Movable M;
 };
 
@@ -36,7 +44,88 @@
   Movable M;
 };
 
-// Test that a parameter with more than one reference to it won't be changed.
+// Tests a single usage in function with trivial control flow graph.
+void straightLineManual(const Movable &m) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: pass by value and use std::move [modernize-pass-by-value]
+  // CHECK-FIXES: void straightLineManual(Movable m) {
+  MovableConstructible mc{m};
+  // CHECK-FIXES: MovableConstructible mc{std::move(m)};
+}
+
+// Tests a unique usage in a return statement.
+Movable automatic(const Movable &m) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: pass by value and use std::move [modernize-pass-by-value]
+  // CHECK-FIXES: Movable automatic(Movable m) {
+  return (m);
+  // CHECK-FIXES: return (m);
+}
+
+// Tests a unique usage in a return statement with an implicit conversion.
+MovableConstructible automaticWithImplicitConversion(const Movable &m) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: pass by value and use std::move [modernize-pass-by-value]
+  // CHECK-FIXES: MovableConstructible automaticWithImplicitConversion(Movable m) {
+  return m;
+  // CHECK-FIXES: return m;
+}
+
+// Tests that we don't emit a diagnostic if the variable is pointed to by a
+// local variable.
+const Movable& pointed(const Movable& m) {
+  // CHECK-FIXES: const Movable& pointed(const Movable& m) {
+  const Movable* ptr = &m;
+  MovableConstructible mc{m};
+  return *ptr;
+}
+
+// Same as `pointed` but with a reference.
+const Movable& referenced(const Movable& m) {
+  // CHECK-FIXES: const Movable& referenced(const Movable& m) {
+  const Movable& ref = m;
+  MovableConstructible mc{m};
+  return ref;
+}
+
+// Tests that we emit a diagnostic for more than one final usages due to `if` blocks.
+MovableConstructible branchingIf(co

[PATCH] D139029: [clang-format] Don't move comments if AlignTrailingComments: Kind: Leave

2022-12-01 Thread Maíra Canal via Phabricator via cfe-commits
mairacanal updated this revision to Diff 479312.
mairacanal added a comment.

Reset `Style.MaxEmptyLinesToKeep` after the test case to avoid side effects for 
other test cases.


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

https://reviews.llvm.org/D139029

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


Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -3062,6 +3062,61 @@
"int d;// comment\n",
Style));
 
+  EXPECT_EQ("// do not touch\n"
+"int a;  // any comments\n"
+"\n"
+"   // comment\n"
+"// comment\n"
+"\n"
+"// comment\n",
+format("// do not touch\n"
+   "int a;  // any comments\n"
+   "\n"
+   "   // comment\n"
+   "// comment\n"
+   "\n"
+   "// comment\n",
+   Style));
+
+  EXPECT_EQ("// do not touch\n"
+"int a;  // any comments\n"
+"\n"
+"   // comment\n"
+"// comment\n"
+"\n"
+"// comment\n",
+format("// do not touch\n"
+   "int a;  // any comments\n"
+   "\n"
+   "\n"
+   "   // comment\n"
+   "// comment\n"
+   "\n"
+   "\n"
+   "// comment\n",
+   Style));
+
+  // Allow to keep 2 empty lines
+  Style.MaxEmptyLinesToKeep = 2;
+  EXPECT_EQ("// do not touch\n"
+"int a;  // any comments\n"
+"\n"
+"\n"
+"   // comment\n"
+"// comment\n"
+"\n"
+"// comment\n",
+format("// do not touch\n"
+   "int a;  // any comments\n"
+   "\n"
+   "\n"
+   "   // comment\n"
+   "// comment\n"
+   "\n"
+   "// comment\n",
+   Style));
+  Style.MaxEmptyLinesToKeep = 1;
+
   // Just format comments normally when leaving exceeds the column limit
   Style.ColumnLimit = 35;
   EXPECT_EQ("int foo = 12345; // comment\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -957,7 +957,8 @@
 if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Leave) {
   auto OriginalSpaces =
   Changes[i].OriginalWhitespaceRange.getEnd().getRawEncoding() -
-  Changes[i].OriginalWhitespaceRange.getBegin().getRawEncoding();
+  Changes[i].OriginalWhitespaceRange.getBegin().getRawEncoding() -
+  Changes[i].Tok->NewlinesBefore;
   unsigned RestoredLineLength = Changes[i].StartOfTokenColumn +
 Changes[i].TokenLength + OriginalSpaces;
   // If leaving comments makes the line exceed the column limit, give up to


Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -3062,6 +3062,61 @@
"int d;// comment\n",
Style));
 
+  EXPECT_EQ("// do not touch\n"
+"int a;  // any comments\n"
+"\n"
+"   // comment\n"
+"// comment\n"
+"\n"
+"// comment\n",
+format("// do not touch\n"
+   "int a;  // any comments\n"
+   "\n"
+   "   // comment\n"
+   "// comment\n"
+   "\n"
+   "// comment\n",
+   Style));
+
+  EXPECT_EQ("// do not touch\n"
+"int a;  // any comments\n"
+"\n"
+"   // comment\n"
+"// comment\n"
+"\n"
+"// comment\n",
+format("// do not touch\n"
+   "int a;  // any comments\n"
+   "\n"
+   "\n"
+   "   // comment\n"
+   "// comment\n"
+   "\n"
+   "\n"
+   "// comment\n",
+   Style));
+
+  // Allow to keep 2 empty lines
+  Style.MaxEmptyLinesToKeep = 2;
+  EXPECT_EQ("// do not touch\n"
+"int a;  // any comments\n"
+"\n"
+"\n"
+"   // comment\n"
+"// comment\n"
+"\n"
+"// comment\n",
+format("// do not touch\n"
+   "int a;  // any comments\n"
+   "\n"

[PATCH] D139087: [include-cleaner] Handle base class member access from derived class.

2022-12-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 479319.
VitaNuo added a comment.

Handle pointer and reference types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139087

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,16 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); 
}");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); 
}");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived d) { d.^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived* d) { d->^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base 
{};",
+   "void fun(Derived& d) { d.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -59,7 +59,18 @@
   }
 
   bool VisitMemberExpr(MemberExpr *E) {
-report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+// Instead of the FieldDecl for MemberExpr, we report the Decl of
+// the corresponding record.
+QualType Type = E->getBase()->IgnoreImpCasts()->getType();
+if (Type->isPointerType()) {
+  QualType PointeeType = Type->getPointeeType();
+  RecordDecl *RecordDecl = PointeeType->getAsRecordDecl();
+  report(E->getMemberLoc(), RecordDecl);
+  return true;
+}
+
+RecordDecl *RecordDecl = Type->getAsRecordDecl();
+report(E->getMemberLoc(), RecordDecl);
 return true;
   }
 


Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -88,12 +88,10 @@
 auto RTStr = llvm::to_string(RT);
 for (auto Expected : Target.points(RTStr))
   if (!llvm::is_contained(ReferencedOffsets[RT], Expected))
-DiagnosePoint("location not marked used with type " + RTStr,
-  Expected);
+DiagnosePoint("location not marked used with type " + RTStr, Expected);
 for (auto Actual : ReferencedOffsets[RT])
   if (!llvm::is_contained(Target.points(RTStr), Actual))
-DiagnosePoint("location unexpectedly used with type " + RTStr,
-  Actual);
+DiagnosePoint("location unexpectedly used with type " + RTStr, Actual);
   }
 
   // If there were any differences, we print the entire referencing code once.
@@ -172,10 +170,16 @@
 }
 
 TEST(WalkAST, MemberExprs) {
-  testWalk("struct S { void $explicit^foo(); };", "void foo() { S{}.^foo(); }");
+  testWalk("struct $explicit^S { void foo(); };", "void foo() { S{}.^foo(); }");
   testWalk(
-  "struct S { void foo(); }; struct X : S { using S::$explicit^foo; };",
+  "struct S { void foo(); }; struct $explicit^X : S { using S::foo; };",
   "void foo() { X{}.^foo(); }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};",
+   "void fun(Derived d) { d.^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};",
+   "void fun(Derived* d) { d->^a; }");
+  testWalk("struct Base { int a; }; struct $explicit^Derived : public Base {};",
+   "void fun(Derived& d) { d.^a; }");
 }
 
 TEST(WalkAST, ConstructExprs) {
Index: clang-tools-extra/inclu

  1   2   3   >