[PATCH] D151867: [Clang][RISCV] Make generic clz/ctz builtins defined for zero on RISCV targets.

2023-06-01 Thread Yunze Zhu(Thead) via Phabricator via cfe-commits
Yunzezhu created this revision.
Yunzezhu added reviewers: asb, craig.topper, kito-cheng.
Yunzezhu added a project: clang.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, kristof.beyls, 
arichardson.
Herald added a project: All.
Yunzezhu requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.

For now llvm intrinsic ctlz/cttz are supported by extension zbb and xtheadbb,
and both extensions support returning well-defined results for zero inputs.
It's possible to set isCLZForZeroUndef flag to false by default on RISCV targets
as ARM and other target does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151867

Files:
  clang/lib/Basic/Targets/RISCV.h
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c

Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
@@ -26,6 +26,32 @@
   return __builtin_riscv_orc_b_64(a);
 }
 
+// RV64ZBB-LABEL: @clz_32_generic(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// RV64ZBB-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
+// RV64ZBB-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// RV64ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
+// RV64ZBB-NEXT:ret i32 [[TMP1]]
+//
+int clz_32_generic(int a) {
+  return __builtin_clz(a);
+}
+
+// RV64ZBB-LABEL: @clz_64_generic(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
+// RV64ZBB-NEXT:store i64 [[A:%.*]], ptr [[A_ADDR]], align 8
+// RV64ZBB-NEXT:[[TMP0:%.*]] = load i64, ptr [[A_ADDR]], align 8
+// RV64ZBB-NEXT:[[TMP1:%.*]] = call i64 @llvm.ctlz.i64(i64 [[TMP0]], i1 false)
+// RV64ZBB-NEXT:[[CAST:%.*]] = trunc i64 [[TMP1]] to i32
+// RV64ZBB-NEXT:[[CONV:%.*]] = sext i32 [[CAST]] to i64
+// RV64ZBB-NEXT:ret i64 [[CONV]]
+//
+long clz_64_generic(long a) {
+  return __builtin_clzl(a);
+}
+
 // RV64ZBB-LABEL: @clz_32(
 // RV64ZBB-NEXT:  entry:
 // RV64ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
@@ -50,6 +76,32 @@
   return __builtin_riscv_clz_64(a);
 }
 
+// RV64ZBB-LABEL: @ctz_32_generic(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// RV64ZBB-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
+// RV64ZBB-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// RV64ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 false)
+// RV64ZBB-NEXT:ret i32 [[TMP1]]
+//
+int ctz_32_generic(int a) {
+  return __builtin_ctz(a);
+}
+
+// RV64ZBB-LABEL: @ctz_64_generic(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[A_ADDR:%.*]] = alloca i64, align 8
+// RV64ZBB-NEXT:store i64 [[A:%.*]], ptr [[A_ADDR]], align 8
+// RV64ZBB-NEXT:[[TMP0:%.*]] = load i64, ptr [[A_ADDR]], align 8
+// RV64ZBB-NEXT:[[TMP1:%.*]] = call i64 @llvm.cttz.i64(i64 [[TMP0]], i1 false)
+// RV64ZBB-NEXT:[[CAST:%.*]] = trunc i64 [[TMP1]] to i32
+// RV64ZBB-NEXT:[[CONV:%.*]] = sext i32 [[CAST]] to i64
+// RV64ZBB-NEXT:ret i64 [[CONV]]
+//
+long ctz_64_generic(long a) {
+  return __builtin_ctzl(a);
+}
+
 // RV64ZBB-LABEL: @ctz_32(
 // RV64ZBB-NEXT:  entry:
 // RV64ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
@@ -14,6 +14,18 @@
   return __builtin_riscv_orc_b_32(a);
 }
 
+// RV32ZBB-LABEL: @clz_32_generic(
+// RV32ZBB-NEXT:  entry:
+// RV32ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// RV32ZBB-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
+// RV32ZBB-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// RV32ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
+// RV32ZBB-NEXT:ret i32 [[TMP1]]
+//
+int clz_32_generic(int a) {
+  return __builtin_clz(a);
+}
+
 // RV32ZBB-LABEL: @clz_32(
 // RV32ZBB-NEXT:  entry:
 // RV32ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
@@ -26,6 +38,18 @@
   return __builtin_riscv_clz_32(a);
 }
 
+// RV32ZBB-LABEL: @ctz_32_generic(
+// RV32ZBB-NEXT:  entry:
+// RV32ZBB-NEXT:[[A_ADDR:%.*]] = alloca i32, align 4
+// RV32ZBB-NEXT:store i32 [[A:%.*]], ptr [[A_ADDR]], align 4
+// RV32ZBB-NEXT:[[TMP0:%.*]] = load i32, ptr [[A_ADDR]], align 4
+// RV32ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 false)
+// RV32ZBB-NEXT:ret i32 [[TMP

[PATCH] D150253: [RISCV] Add Zvfhmin extension for clang.

2023-06-01 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan updated this revision to Diff 527312.
jacquesguan added a comment.

Update dependency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150253

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin-error.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
  clang/test/Sema/riscv-vector-float16-check.c
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -633,6 +633,7 @@
   RVVRequire RequireExt = StringSwitch(RequiredFeature)
   .Case("RV64", RVV_REQ_RV64)
   .Case("FullMultiply", RVV_REQ_FullMultiply)
+  .Case("ZvfhminOrZvfh", RVV_REQ_ZvfhminOrZvfh)
   .Case("Xsfvcp", RVV_REQ_Xsfvcp)
   .Default(RVV_REQ_None);
   assert(RequireExt != RVV_REQ_None && "Unrecognized required feature?");
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- clang/test/Sema/riscv-vector-float16-check.c
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -4,5 +4,5 @@
 // REQUIRES: riscv-registered-target
 #include 
 
-vfloat16m1_t foo() { /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+vfloat16m1_t foo() { /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh or zvfhmin' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
@@ -0,0 +1,27 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v \
+// RUN:   -target-feature +experimental-zvfhmin -disable-O0-optnone  \
+// RUN:   -emit-llvm %s -o - | opt -S -passes=mem2reg | \
+// RUN:   FileCheck --check-prefix=CHECK-ZVFHMIN %s
+
+#include 
+
+// CHECK-ZVFHMIN-LABEL: @test_vfncvt_f_f_w_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vfncvt.f.f.w.nxv4f16.nxv4f32.i64( poison,  [[SRC:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vfncvt_f_f_w_f16m1(vfloat32m2_t src, size_t vl) {
+  return __riscv_vfncvt_f(src, vl);
+}
+
+
+// CHECK-ZVFHMIN-LABEL: @test_vfwcvt_f_f_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vfwcvt.f.f.v.nxv4f32.nxv4f16.i64( poison,  [[SRC:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat32m2_t test_vfwcvt_f_f_v_f16m1(vfloat16m1_t src, size_t vl) {
+  return __riscv_vfwcvt_f(src, vl);
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin-error.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin-error.c
@@ -0,0 +1,24 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v \
+// RUN:   -target-feature +experimental-zvfh -disable-O0-optnone  \
+// RUN:   -emit-llvm %s -o - | opt -S -passes=mem2reg | \
+// RUN:   FileCheck --check-prefix=CHECK-ZVF %s
+
+// RUN: not %clang_cc1 -triple riscv64 -target-feature +v \
+// RUN:   -target-feature +experimental-zvfhmin -emit-llvm-only %s 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=CHECK-ZVFHMIN-ERR
+
+#include 
+
+// CHECK-ZVF-LABEL: @test_vfadd_vv_f16m1(
+// CHECK-ZVF-NEXT:  entry:
+// CHECK-ZVF-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vfadd.nxv4f16.nxv4f16.i64( poison,  [[OP1:%.*]],  [[OP2:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVF-NEXT:ret  [[TMP0]]
+//
+
+// CHECK-ZVFHMIN-ERR: no matching function for call to '__riscv_vfadd'
+
+vfloat16m1_t test_vfadd_vv_f16m1(vfloat16m1_t op1, vfloat16m1_t op2, size_t vl) {
+  return __riscv_vfadd(op1, op2, vl);
+}
Index: clang/lib/Sema/SemaRISCVVectorLookup.cpp
===
--- clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -195,6 +195,8 @@
   const TargetInfo &TI = Context.getTargetInfo();
   bool HasRV64 = TI.hasFeature("64bit");
   bool HasFullMultiply = TI.hasFeature("v");
+  bool HasZvfh = TI.hasFeature("experimental-zvfh");
+

[PATCH] D151720: [clang][ExprConstant] Fix display of syntactically-invalid note for member function calls

2023-06-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

The only additional test I could come up with is one where the `->` is in the 
middle of an lvalue designator, like:

  struct A {
constexpr int foo() { (void)(1/0); return 1;}
  };
  
  struct B {
A aa;
A *a = &aa;
  };
  
  struct C {
B b;
  };
  
  struct D {
C cc;
C *c = &cc;
  };
  
  constexpr D d{};
  static_assert(d.c->b.a->foo() == 1);

but this is printed correctly. The rest of the output LGTM but I'll wait for 
some of the others to maybe chime in.




Comment at: clang/lib/AST/ExprConstant.cpp:1931
+  else
+  Out << ".";
+} else if (const auto *OCE =

Did you `clang-format` these changes? The two if/else body here seems indented 
4 spaces instead  of 2.



Comment at: clang/test/SemaCXX/constant-expression-cxx11.cpp:995
+static_assert(sptr->f(), ""); // expected-error {{constant expression}} 
expected-note {{in call to 'sptr->f()'}}
+static_assert(slref.f(), ""); // expected-error {{constant expression}} 
expected-note {{in call to 'slref.f()'}}
+static_assert(srref.f(), ""); // expected-error {{constant expression}} 
expected-note {{in call to 'srref.f()'}}





Comment at: clang/test/SemaCXX/constant-expression-cxx11.cpp:996
+static_assert(slref.f(), ""); // expected-error {{constant expression}} 
expected-note {{in call to 'slref.f()'}}
+static_assert(srref.f(), ""); // expected-error {{constant expression}} 
expected-note {{in call to 'srref.f()'}}
 static_assert(T(3).f() == 3, "");





Comment at: clang/test/SemaCXX/constexpr-frame-describe.cpp:5
+struct Foo {
+constexpr void zomg() const { (void)(1 / 0); } // expected-error 
{{constant expression}} expected-warning {{division by zero}} expected-note 
2{{division by zero}}
+};





Comment at: clang/test/SemaCXX/constexpr-frame-describe.cpp:11
+constexpr bool operator==(const S&) const { // expected-error {{never 
produces a constant expression}}
+  return 1 / 0; // expected-warning {{division by zero}} expected-note 
3{{division by zero}}
+}




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

https://reviews.llvm.org/D151720

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


[PATCH] D146023: [AMDGPU] Remove Code Object V2

2023-06-01 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146023

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


[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527314.
VitaNuo marked 5 inline comments as done.
VitaNuo added a comment.
Herald added a subscriber: ormris.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,91 @@
+//===--- AnalysisTest.cpp -===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+std::string
+appendPathSystemIndependent(std::initializer_list Segments,
+bool IsAbsolute) {
+  llvm::StringRef Sep = llvm::sys::path::get_separator();
+  llvm::SmallString<32> Path;
+  if (IsAbsolute)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Sep);
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Segment);
+  return std::string{Path};
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(llvm::StringRef AbsolutePath) const override {
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath("foo/baz.h")] = "";
+  Inputs.ExtraFiles["/foo/bar.h"] = "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader(Header{*FM.getFile(testPath("foo.h"))}, HS,
+ MainFile, DummyIncludeSpeller{}));
+  EXPECT_EQ("bar.h", spellHeader(Header{*FM.getFile("bar.h")}, HS, MainFile,
+ DummyIncludeSpeller{}));
+  EXPECT_EQ(appendPathSystemIndependent({"foo", "baz.h"}, false),
+spellHeader(Header{*FM.getFile(testPath("foo/baz.h"))}, HS,
+MainFile, DummyIncludeSpeller{}));
+  EXPECT_EQ(appendPathSystemIndependent({"foo", "bar.h"}, true),
+spellHeader(Header{*FM.getFile("/foo/bar.h")}, HS, MainFile,
+DummyIncludeSpeller{}));
+}
+
+} // namespace
+} // namespace clang::include_cleaner
\ No newline at end of file
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
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===

[clang] 4f0436d - [clang][analyzer] Merge apiModeling.StdCLibraryFunctions and StdCLibraryFunctionArgs checkers into one.

2023-06-01 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-06-01T09:54:35+02:00
New Revision: 4f0436dd1532d7534d77e6fc211a7a50bbdd0c49

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

LOG: [clang][analyzer] Merge apiModeling.StdCLibraryFunctions and 
StdCLibraryFunctionArgs checkers into one.

Main reason for this change is that these checkers were implemented in the same 
class
but had different dependency ordering. (NonNullParamChecker should run before 
StdCLibraryFunctionArgs
to get more special warning about null arguments, but the 
apiModeling.StdCLibraryFunctions was a modeling
checker that should run before other non-modeling checkers. The modeling 
checker changes state in a way
that makes it impossible to detect a null argument by NonNullParamChecker.)
To make it more simple, the modeling part is removed as separate checker and 
can be only used if
checker StdCLibraryFunctions is turned on, that produces the warnings too. 
Modeling the functions
without bug detection (for invalid argument) is not possible. The modeling of 
standard functions
does not happen by default from this change on.

Reviewed By: Szelethus

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

Added: 


Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/PR49642.c
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/analyzer-enabled-checkers.c
clang/test/Analysis/conversion.c
clang/test/Analysis/errno-stdlibraryfunctions-notes.c
clang/test/Analysis/errno-stdlibraryfunctions.c
clang/test/Analysis/std-c-library-functions-POSIX-lookup.c
clang/test/Analysis/std-c-library-functions-POSIX-socket-sockaddr.cpp
clang/test/Analysis/std-c-library-functions-POSIX.c
clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c
clang/test/Analysis/std-c-library-functions-arg-constraints.c
clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
clang/test/Analysis/std-c-library-functions-arg-cstring-dependency.c
clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
clang/test/Analysis/std-c-library-functions-arg-weakdeps.c
clang/test/Analysis/std-c-library-functions-eof.c
clang/test/Analysis/std-c-library-functions-inlined.c
clang/test/Analysis/std-c-library-functions-lookup.c
clang/test/Analysis/std-c-library-functions-lookup.cpp
clang/test/Analysis/std-c-library-functions-path-notes.c
clang/test/Analysis/std-c-library-functions-restrict.c
clang/test/Analysis/std-c-library-functions-restrict.cpp
clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
clang/test/Analysis/std-c-library-functions.c
clang/test/Analysis/std-c-library-functions.cpp
clang/test/Analysis/std-c-library-posix-crash.c
clang/test/Analysis/stream-errno-note.c
clang/test/Analysis/stream-errno.c
clang/test/Analysis/stream-noopen.c
clang/test/Analysis/stream-note.c
clang/test/Analysis/stream-stdlibraryfunctionargs.c
clang/test/Analysis/weak-dependencies.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index e32f9c799240e..6494860915b93 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2421,10 +2421,10 @@ For a more detailed description of configuration 
options, please see the :doc:`u
 alpha.unix
 ^^^
 
-.. _alpha-unix-StdCLibraryFunctionArgs:
+.. _alpha-unix-StdCLibraryFunctions:
 
-alpha.unix.StdCLibraryFunctionArgs (C)
-""
+alpha.unix.StdCLibraryFunctions (C)
+"""
 Check for calls of standard library functions that violate predefined argument
 constraints. For example, it is stated in the C standard that for the ``int
 isalnum(int ch)`` function the behavior is undefined if the value of ``ch`` is
@@ -2457,6 +2457,12 @@ on standard library functions. Preconditions are 
checked, and when they are
 violated, a warning is emitted. Post conditions are added to the analysis, e.g.
 that the return value must be no greater than 255.
 
+For example if an argument to a function must be in between 0 and 255, but the
+value of the argument is unknown, the analyzer will conservatively assume that
+it is in this interval. Similarly, if a function mustn't be called with a null
+pointer and the null value of the argument can not be proven, the analyzer will
+assume that it is non-null.
+
 These are the possible checks on the values passed as function argu

[PATCH] D151225: [clang][analyzer] Merge apiModeling.StdCLibraryFunctions and StdCLibraryFunctionArgs checkers into one.

2023-06-01 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f0436dd1532: [clang][analyzer] Merge 
apiModeling.StdCLibraryFunctions and… (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151225

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/PR49642.c
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/analyzer-enabled-checkers.c
  clang/test/Analysis/conversion.c
  clang/test/Analysis/errno-stdlibraryfunctions-notes.c
  clang/test/Analysis/errno-stdlibraryfunctions.c
  clang/test/Analysis/std-c-library-functions-POSIX-lookup.c
  clang/test/Analysis/std-c-library-functions-POSIX-socket-sockaddr.cpp
  clang/test/Analysis/std-c-library-functions-POSIX.c
  clang/test/Analysis/std-c-library-functions-arg-constraints-note-tags.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-notes.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.cpp
  clang/test/Analysis/std-c-library-functions-arg-cstring-dependency.c
  clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
  clang/test/Analysis/std-c-library-functions-arg-weakdeps.c
  clang/test/Analysis/std-c-library-functions-eof.c
  clang/test/Analysis/std-c-library-functions-inlined.c
  clang/test/Analysis/std-c-library-functions-lookup.c
  clang/test/Analysis/std-c-library-functions-lookup.cpp
  clang/test/Analysis/std-c-library-functions-path-notes.c
  clang/test/Analysis/std-c-library-functions-restrict.c
  clang/test/Analysis/std-c-library-functions-restrict.cpp
  clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
  clang/test/Analysis/std-c-library-functions.c
  clang/test/Analysis/std-c-library-functions.cpp
  clang/test/Analysis/std-c-library-posix-crash.c
  clang/test/Analysis/stream-errno-note.c
  clang/test/Analysis/stream-errno.c
  clang/test/Analysis/stream-noopen.c
  clang/test/Analysis/stream-note.c
  clang/test/Analysis/stream-stdlibraryfunctionargs.c
  clang/test/Analysis/weak-dependencies.c

Index: clang/test/Analysis/weak-dependencies.c
===
--- clang/test/Analysis/weak-dependencies.c
+++ clang/test/Analysis/weak-dependencies.c
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 %s -verify \
-// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
+// RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctions \
 // RUN:   -analyzer-checker=core
 
 typedef __typeof(sizeof(int)) size_t;
Index: clang/test/Analysis/stream-stdlibraryfunctionargs.c
===
--- clang/test/Analysis/stream-stdlibraryfunctionargs.c
+++ clang/test/Analysis/stream-stdlibraryfunctionargs.c
@@ -1,11 +1,11 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctionArgs,debug.ExprInspection \
-// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify=stdargs,any %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctions,debug.ExprInspection \
+// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stdargs,any %s
 
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection \
-// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify=any %s
+// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=any %s
 
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.StdCLibraryFunctionArgs,debug.ExprInspection \
-// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify=stdargs,any %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.StdCLibraryFunctions,debug.ExprInspection \
+// RUN:   -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stdargs,any %s
 
 #include "Inputs/system-header-simulator.h"
 
Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -1,7 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream -analyzer-output text \
 // RUN:   -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctionArgs -analyzer-output text \
-// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true -verify=expected,stdargs %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,alpha.unix.StdCLibraryFunctions -analyzer-output text \
+// RUN:   -analyzer-config alpha.unix.StdC

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

The only thing is the source location, see my comments for details, otherwise 
looks good in general.




Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:116
+  }
+  walkUsed(MainFileDecls, RecordedPreprocessor.MacroReferences, &RecordedPI,
+   *SM,

it is sad that we duplicate the include-cleaner analyse implementation (the 
only difference is that here we record the references for missing-includes), I 
think we should find a way to share the code in the future.

No action required in this patch, can you add a FIXME? 



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:194
+
+diag(Inc.SymRefLocation, "no header providing %0 is directly included")
+<< Spelling

I think we should use the spelling location -- `Inc.SymRefLocation` can be a 
macro location which can points to another file, we intend to show diagnostics 
for main-file only, and walkUsed has some internal logic which guarantees that 
the spelling loc of returned refs is main-file.



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:88
+SourceLocation Loc = D->getLocation();
+if (!SM->isWrittenInMainFile(SM->getSpellingLoc(Loc)))
+  continue;

VitaNuo wrote:
> hokein wrote:
> > We should use the `getExpansionLoc` rather than the `SpellingLoc` here, 
> > otherwise we might miss the case like `TEST_F(WalkUsedTest, 
> > MultipleProviders) {... }` where the decl location is spelled in another 
> > file, but the function body is spelled in main-file.
> > 
> > we should actually use FileLoc of the decl location here (i.e. map it back 
> > to spelling location) as the decl might be introduced by a macro expansion, 
> > but if the spelling of "primary" location belongs to the main file we 
> > should still analyze it (e.g. decls introduced via `TEST` macros)
> 
> > we actually want spelling location, not fileloc
> > sorry for the confusion
> > basically, spelling location will always map to where a name is spelled in 
> > a  > physical file, even if it's part of macro body
> > whereas getFileLoc, will map tokens from macro body to their expansion 
> > locations (i.e. place in a physical file where the macro is invoked)
> 
> These are earlier comments from Kadir on this topic. AFAIU we want the 
> spelling location for `TEST_F(WalkUsedTest, MultipleProviders) {... }` 
> because:
> 
> - for Decls introduced by the `TEST_F` expansion, we would like to analyze 
> them only if they are spelled in the main file.
> - for arguments, their transitive spelling location is where they're written. 
> So if `TEST_F(WalkUsedTest, MultipleProviders) {... }` is written in the main 
> file, the argument locations will be counted.
> 
I think I'm not convinced, see my comments below.

> for Decls introduced by the TEST_F expansion, we would like to analyze them 
> only if they are spelled in the main file.

I think it is true for some cases. For example, a function decl has different 
parts (declarator, and function body), if the declarator is introduced by a 
macro which defined in a header, and the function body is spelled in the 
main-file, we still want to analyze the function body, see a simple example 
below:

```
// foo.h
#define DECLARE(X) void X()

// main.cpp
#include "foo.h"

DECLARE(myfunc) {
   int a;
   ...
}
```

Moreover, we have use `ExpansionLoc` pattern in other places when we collect 
the main-file top-level decl 
([include-cleaner](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/include-cleaner/lib/Record.cpp#L406),
 
[clangd](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/SourceCode.cpp#L422)),
 and I don't see a special reason to change the pattern in the clang-tidy check.



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h:21
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Tooling/Syntax/Tokens.h"
+#include "llvm/Support/Regex.h"

can you cleanup the includes here? looks like there are some unused-includes 
now, at least `Syntax/Tokens.h` from the first glance.



Comment at: clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst:4
+misc-include-cleaner
+==
+

nit: remove extra trailing `==`



Comment at: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp:1
+//===--- IncludeCleanerCheck.cpp - clang-tidy 
-===//
+//

nit: IncludeCleanerTest.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527317.
VitaNuo added a comment.

Update release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,198 @@
+//===--- IncludeCleanerCheck.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+std::string
+appendPathSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Path;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Segment);
+  return std::string{Path};
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  std::string IgnoreHeaders{"bar.h;"};
+  IgnoreHeaders += appendPathSystemIndependent({"foo", ".*"});
+  IgnoreHeaders += ";";
+  IgnoreHeaders += appendPathSystemIndependent({"baz", "qux"});
+  IgnoreHeaders += ";vector";
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{IgnoreHeaders};
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+{{"bar.h", ""},
+ {"vector", ""},
+ {appendPathSystemIndependent({"foo", "qux.h"}), ""},
+ {appendPathSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  std::string IgnoreHeaders{"baz.h;"};
+  IgnoreHeaders += appendPathSystemIndependent({"foo", ".*"

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added inline comments.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h:88
 
+class IncludeSpeller {
+public:

hokein wrote:
> hokein wrote:
> > I think this is an important API (we will create a subclass for our 
> > internal use), probably worth a dedicated `IncludeSpeller.h/.cpp` file. 
> I think it would be nice to have a unittest for it.
> 
> You can create a subclass `TestIncludeSpeller` in the unittest, which 
> implements a dummy  include spelling for a particular absolute file path 
> (e.g. a file path starting with `/include-cleaner-test/`), and verify 
> `spellHeader` API return expected results.
> 
> 
> 
Ok, created the test that tests the `spellHeader` API with a dummy speller. I 
do have to pass the speller object manually, though. If I try to link it via 
`llvm::Registry`, it creates side effects for other test, e.g., 
`AnalysisTest.cpp`, etc., which is undesirable.



Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h:104
+/// order is not specified.
+std::function defaultHeaderMapper();
+

hokein wrote:
> It is unclear to me why we need `defaultHeaderMapper` and the parameter 
> `MapHeader` in `spellHeader` in the header.
> 
> Do we want the caller of `spellHeader` to provide a different HeaderMapper? I 
> don't see a usecase for that -- the current strategy of is to iterate all 
> extension points, if we find the first available one, we just return it; 
> otherwise we use the default fallback (`suggestPathToFileForDiagnostics`). I 
> believe it is enough for `spellHeader` to cover all our cases.
> 
> Plugins might need extra information, e.g. clangd-configs for remapping 
> quotes to > angles (or full path re-writes)
> Reason to push registry to applications and rather take in a functor in 
> >include_cleaner (or just let it be handled by applications completely?)

This is a quote from our sync notes. I believe the idea was that applications 
might want to parametrize mapping somehow. When linking via a strategy, you can 
only provide a class that has a parameterless constructor, though. At least 
that's my understanding.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

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


[clang] 710749f - [clang][Interp] Optionally cast comparison result to non-bool

2023-06-01 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-06-01T10:36:33+02:00
New Revision: 710749f78695b0e00026e5ff7c9f94e08e7b482a

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

LOG: [clang][Interp] Optionally cast comparison result to non-bool

Our comparison opcodes always produce a Boolean value and push it on the
stack. However, the result of such a comparison in C is int, so the
later code expects an integer value on the stack.

Work around this problem by casting the boolean value to int in those
cases. This is not ideal for C however. The comparison is usually
wrapped in a IntegerToBool cast anyway.

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

Added: 
clang/test/AST/Interp/c.c

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index df7c4a72f21a7..1be131be66e3b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -237,19 +237,31 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
   if (!visit(LHS) || !visit(RHS))
 return false;
 
+  // For languages such as C, cast the result of one
+  // of our comparision opcodes to T (which is usually int).
+  auto MaybeCastToBool = [this, T, BO](bool Result) {
+if (!Result)
+  return false;
+if (DiscardResult)
+  return this->emitPop(*T, BO);
+if (T != PT_Bool)
+  return this->emitCast(PT_Bool, *T, BO);
+return true;
+  };
+
   switch (BO->getOpcode()) {
   case BO_EQ:
-return Discard(this->emitEQ(*LT, BO));
+return MaybeCastToBool(this->emitEQ(*LT, BO));
   case BO_NE:
-return Discard(this->emitNE(*LT, BO));
+return MaybeCastToBool(this->emitNE(*LT, BO));
   case BO_LT:
-return Discard(this->emitLT(*LT, BO));
+return MaybeCastToBool(this->emitLT(*LT, BO));
   case BO_LE:
-return Discard(this->emitLE(*LT, BO));
+return MaybeCastToBool(this->emitLE(*LT, BO));
   case BO_GT:
-return Discard(this->emitGT(*LT, BO));
+return MaybeCastToBool(this->emitGT(*LT, BO));
   case BO_GE:
-return Discard(this->emitGE(*LT, BO));
+return MaybeCastToBool(this->emitGE(*LT, BO));
   case BO_Sub:
 if (BO->getType()->isFloatingType())
   return Discard(this->emitSubf(getRoundingMode(BO), BO));
@@ -925,6 +937,15 @@ bool ByteCodeExprGen::visitConditional(
 
   if (!this->visit(Condition))
 return false;
+
+  // C special case: Convert to bool because our jump ops need that.
+  // TODO: We probably want this to be done in visitBool().
+  if (std::optional CondT = classify(Condition->getType());
+  CondT && CondT != PT_Bool) {
+if (!this->emitCast(*CondT, PT_Bool, E))
+  return false;
+  }
+
   if (!this->jumpFalse(LabelFalse))
 return false;
 

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
new file mode 100644
index 0..fe794bb014e7c
--- /dev/null
+++ b/clang/test/AST/Interp/c.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+/// expected-no-diagnostics
+/// ref-no-diagnostics
+
+_Static_assert(1, "");
+_Static_assert(0 != 1, "");
+_Static_assert(1.0 == 1.0, "");
+_Static_assert( (5 > 4) + (3 > 2) == 2, "");
+
+int a = (1 == 1 ? 5 : 3);



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


[PATCH] D151869: [RISCV] Support more builtin for zvfhmin.

2023-06-01 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan created this revision.
jacquesguan added reviewers: craig.topper, asb, luismarques, frasercrmck, 
michaelmaitland.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, apazos, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, 
kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
jacquesguan requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

This patch enables some fp16 vector type builtins that don't use fp arithmetic 
instruction for zvfhmin.
Include following builtins:

  vector load/store,
  vector reinterpret,
  vmerge_vvm,
  vmv_v.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151869

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c

Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
@@ -25,3 +25,208 @@
 vfloat32m2_t test_vfwcvt_f_f_v_f16m1(vfloat16m1_t src, size_t vl) {
   return __riscv_vfwcvt_f(src, vl);
 }
+
+// CHECK-ZVFHMIN-LABEL: @test_vle16_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vle.nxv4f16.i64( poison, ptr [[BASE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vle16_v_f16m1(const _Float16 *base, size_t vl) {
+  return __riscv_vle16_v_f16m1(base, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vse16_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:call void @llvm.riscv.vse.nxv4f16.i64( [[VALUE:%.*]], ptr [[BASE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret void
+//
+void test_vse16_v_f16m1(_Float16 *base, vfloat16m1_t value, size_t vl) {
+  return __riscv_vse16_v_f16m1(base, value, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vlse16_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vlse.nxv4f16.i64( poison, ptr [[BASE:%.*]], i64 [[BSTRIDE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vlse16_v_f16m1(const _Float16 *base, ptrdiff_t bstride, size_t vl) {
+  return __riscv_vlse16_v_f16m1(base, bstride, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vsse16_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:call void @llvm.riscv.vsse.nxv4f16.i64( [[VALUE:%.*]], ptr [[BASE:%.*]], i64 [[BSTRIDE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret void
+//
+void test_vsse16_v_f16m1(_Float16 *base, ptrdiff_t bstride, vfloat16m1_t value, size_t vl) {
+  return __riscv_vsse16_v_f16m1(base, bstride, value, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vluxei32_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vluxei.nxv4f16.nxv4i32.i64( poison, ptr [[BASE:%.*]],  [[BINDEX:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vluxei32_v_f16m1(const _Float16 *base, vuint32m2_t bindex, size_t vl) {
+  return __riscv_vluxei32_v_f16m1(base, bindex, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vsuxei32_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:call void @llvm.riscv.vsuxei.nxv4f16.nxv4i32.i64( [[VALUE:%.*]], ptr [[BASE:%.*]],  [[BINDEX:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret void
+//
+void test_vsuxei32_v_f16m1(_Float16 *base, vuint32m2_t bindex, vfloat16m1_t value, size_t vl) {
+  return __riscv_vsuxei32_v_f16m1(base, bindex, value, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vloxei32_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vloxei.nxv4f16.nxv4i32.i64( poison, ptr [[BASE:%.*]],  [[BINDEX:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vloxei32_v_f16m1(const _Float16 *base, vuint32m2_t bindex, size_t vl) {
+  return __riscv_vloxei32_v_f16m1(base, bindex, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vsoxei32_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:call void @llvm.riscv.vsoxei.nxv4f16.nxv4i32.i64( [[VALUE:%.*]], ptr [[BASE:%.*]],  [[BINDEX:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret void
+//
+void test_vsoxei32_v_f16m1(_Float16 *base, vuint32m2_t bindex, vfloat16m1_t value, size_t vl) {
+  return __riscv_vsoxei32_v_f16m1(base, bindex, value, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vle16ff_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call { , i64 } @llvm.riscv.vleff.nxv4f16.i64( poison, ptr [[BASE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:[[TMP1:%.*]] = extractvalue { , i64 } [[TMP0]], 0
+// CHECK-ZVFHMIN-NEXT:[[TMP2:%.*]] = extractvalue { , i64 } [[TMP0]], 1
+// 

[PATCH] D150670: [InstCombine] Disable generation of fshl/fshr for rotates

2023-06-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 527326.
pmatos added a comment.

Simplify code according to @nikic suggestion. Add tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150670

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  llvm/test/Transforms/InstCombine/fsh.ll


Index: llvm/test/Transforms/InstCombine/fsh.ll
===
--- llvm/test/Transforms/InstCombine/fsh.ll
+++ llvm/test/Transforms/InstCombine/fsh.ll
@@ -440,12 +440,10 @@
   ret <2 x i32> %r
 }
 
-; TODO: Don't let SimplifyDemandedBits split up a rotate - keep the same 
operand.
-
 define i32 @rotl_common_demanded(i32 %a0) {
 ; CHECK-LABEL: @rotl_common_demanded(
 ; CHECK-NEXT:[[X:%.*]] = xor i32 [[A0:%.*]], 2
-; CHECK-NEXT:[[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X]], i32 [[A0]], 
i32 8)
+; CHECK-NEXT:[[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X]], i32 [[X]], i32 
8)
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %x = xor i32 %a0, 2
@@ -456,7 +454,7 @@
 define i33 @rotr_common_demanded(i33 %a0) {
 ; CHECK-LABEL: @rotr_common_demanded(
 ; CHECK-NEXT:[[X:%.*]] = xor i33 [[A0:%.*]], 2
-; CHECK-NEXT:[[R:%.*]] = call i33 @llvm.fshl.i33(i33 [[X]], i33 [[A0]], 
i33 25)
+; CHECK-NEXT:[[R:%.*]] = call i33 @llvm.fshl.i33(i33 [[X]], i33 [[X]], i33 
25)
 ; CHECK-NEXT:ret i33 [[R]]
 ;
   %x = xor i33 %a0, 2
@@ -704,6 +702,26 @@
   ret i32 %t3
 }
 
+define i32 @fsh_andconst_rotate(i32 %a) {
+; CHECK-LABEL: @fsh_andconst_rotate(
+; CHECK-NEXT:[[T2:%.*]] = lshr i32 [[A:%.*]], 16
+; CHECK-NEXT:ret i32 [[T2]]
+;
+  %t1 = and i32 %a, 4294901760 ; 0x
+  %t2 = call i32 @llvm.fshl.i32(i32 %t1, i32 %t1, i32 16)
+  ret i32 %t2
+}
+
+define i32 @fsh_orconst_rotate(i32 %a) {
+; CHECK-LABEL: @fsh_orconst_rotate(
+; CHECK-NEXT:[[T2:%.*]] = call i32 @llvm.fshl.i32(i32 [[A:%.*]], i32 
-268435456, i32 4)
+; CHECK-NEXT:ret i32 [[T2]]
+;
+  %t1 = or i32 %a, 4026531840 ; 0xf000
+  %t2 = call i32 @llvm.fshl.i32(i32 %t1, i32 %t1, i32 4)
+  ret i32 %t2
+}
+
 define <2 x i31> @fshr_mask_args_same_vector(<2 x i31> %a) {
 ; CHECK-LABEL: @fshr_mask_args_same_vector(
 ; CHECK-NEXT:[[T3:%.*]] = shl <2 x i31> [[A:%.*]], 
Index: llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -912,9 +912,24 @@
 
 APInt DemandedMaskLHS(DemandedMask.lshr(ShiftAmt));
 APInt DemandedMaskRHS(DemandedMask.shl(BitWidth - ShiftAmt));
-if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown, Depth + 1) ||
-SimplifyDemandedBits(I, 1, DemandedMaskRHS, RHSKnown, Depth + 1))
-  return I;
+if (I->getOperand(0) != I->getOperand(1)) {
+  if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown,
+   Depth + 1) ||
+  SimplifyDemandedBits(I, 1, DemandedMaskRHS, RHSKnown, Depth + 1))
+return I;
+} else { // fshl is a rotate
+  KnownBits LHSKnown = computeKnownBits(I->getOperand(0), Depth + 1, 
I);
+  if (DemandedMaskLHS.isSubsetOf(LHSKnown.Zero | LHSKnown.One)) {
+replaceOperand(*I, 0, Constant::getIntegerValue(VTy, 
LHSKnown.One));
+return I;
+  }
+
+  KnownBits RHSKnown = computeKnownBits(I->getOperand(1), Depth + 1, 
I);
+  if (DemandedMaskRHS.isSubsetOf(RHSKnown.Zero | RHSKnown.One)) {
+replaceOperand(*I, 1, Constant::getIntegerValue(VTy, 
RHSKnown.One));
+return I;
+  }
+}
 
 Known.Zero = LHSKnown.Zero.shl(ShiftAmt) |
  RHSKnown.Zero.lshr(BitWidth - ShiftAmt);


Index: llvm/test/Transforms/InstCombine/fsh.ll
===
--- llvm/test/Transforms/InstCombine/fsh.ll
+++ llvm/test/Transforms/InstCombine/fsh.ll
@@ -440,12 +440,10 @@
   ret <2 x i32> %r
 }
 
-; TODO: Don't let SimplifyDemandedBits split up a rotate - keep the same operand.
-
 define i32 @rotl_common_demanded(i32 %a0) {
 ; CHECK-LABEL: @rotl_common_demanded(
 ; CHECK-NEXT:[[X:%.*]] = xor i32 [[A0:%.*]], 2
-; CHECK-NEXT:[[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X]], i32 [[A0]], i32 8)
+; CHECK-NEXT:[[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X]], i32 [[X]], i32 8)
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %x = xor i32 %a0, 2
@@ -456,7 +454,7 @@
 define i33 @rotr_common_demanded(i33 %a0) {
 ; CHECK-LABEL: @rotr_common_demanded(
 ; CHECK-NEXT:[[X:%.*]] = xor i33 [[A0:%.*]], 2
-; CHECK-NEXT:[[R:%.*]] = call i33 @llvm.fshl.i33(i33 [[X]], i33 [[A0]], i33 25)
+; CHECK-NEXT:[[R:%.*]] = call i33 @llvm.fshl.i33(i33 [[X]], i33 [[X]], i33 25)
 ; CHECK-NEXT:ret i33 [[R]]
 ;
   %x = xor i33 %a0, 2
@@ -704,

[PATCH] D150670: [InstCombine] Disable generation of fshl/fshr for rotates

2023-06-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

In D150670#4383823 , @nikic wrote:

> Can you please drop all wasm related tests and instead add an InstCombine 
> test for the fsh+and pattern?
>
> It would also be good to have a test where we can fold one side to a 
> constant, but that constant is not zero. We should then consider whether that 
> is profitable or not. (In that case we can't reduce to a simple shift and 
> will reduce to a shift and or with constant instead -- is that better or 
> worse than a rotate?)

I have added the tests. I looked into the output of WebAssembly and it looks 
good. Even in the case of the generation of a non-zero const, Wasm still 
managed to generate a rotate which is generally more profitable, since the 
runtime can be then the one choosing how to implement that depending on the 
hardware. In the general case, I am not sure what the right answer is tbh.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150670

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527329.
VitaNuo marked 6 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,198 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+std::string
+appendPathSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Path;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Segment);
+  return std::string{Path};
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  std::string IgnoreHeaders{"bar.h;"};
+  IgnoreHeaders += appendPathSystemIndependent({"foo", ".*"});
+  IgnoreHeaders += ";";
+  IgnoreHeaders += appendPathSystemIndependent({"baz", "qux"});
+  IgnoreHeaders += ";vector";
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{IgnoreHeaders};
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+{{"bar.h", ""},
+ {"vector", ""},
+ {appendPathSystemIndependent({"foo", "qux.h"}), ""},
+ {appendPathSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  std::string IgnoreHeaders{"baz.h;"};
+  IgnoreHeaders

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the comments!




Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:88
+SourceLocation Loc = D->getLocation();
+if (!SM->isWrittenInMainFile(SM->getSpellingLoc(Loc)))
+  continue;

hokein wrote:
> VitaNuo wrote:
> > hokein wrote:
> > > We should use the `getExpansionLoc` rather than the `SpellingLoc` here, 
> > > otherwise we might miss the case like `TEST_F(WalkUsedTest, 
> > > MultipleProviders) {... }` where the decl location is spelled in another 
> > > file, but the function body is spelled in main-file.
> > > 
> > > we should actually use FileLoc of the decl location here (i.e. map it 
> > > back to spelling location) as the decl might be introduced by a macro 
> > > expansion, but if the spelling of "primary" location belongs to the main 
> > > file we should still analyze it (e.g. decls introduced via `TEST` macros)
> > 
> > > we actually want spelling location, not fileloc
> > > sorry for the confusion
> > > basically, spelling location will always map to where a name is spelled 
> > > in a  > physical file, even if it's part of macro body
> > > whereas getFileLoc, will map tokens from macro body to their expansion 
> > > locations (i.e. place in a physical file where the macro is invoked)
> > 
> > These are earlier comments from Kadir on this topic. AFAIU we want the 
> > spelling location for `TEST_F(WalkUsedTest, MultipleProviders) {... }` 
> > because:
> > 
> > - for Decls introduced by the `TEST_F` expansion, we would like to analyze 
> > them only if they are spelled in the main file.
> > - for arguments, their transitive spelling location is where they're 
> > written. So if `TEST_F(WalkUsedTest, MultipleProviders) {... }` is written 
> > in the main file, the argument locations will be counted.
> > 
> I think I'm not convinced, see my comments below.
> 
> > for Decls introduced by the TEST_F expansion, we would like to analyze them 
> > only if they are spelled in the main file.
> 
> I think it is true for some cases. For example, a function decl has different 
> parts (declarator, and function body), if the declarator is introduced by a 
> macro which defined in a header, and the function body is spelled in the 
> main-file, we still want to analyze the function body, see a simple example 
> below:
> 
> ```
> // foo.h
> #define DECLARE(X) void X()
> 
> // main.cpp
> #include "foo.h"
> 
> DECLARE(myfunc) {
>int a;
>...
> }
> ```
> 
> Moreover, we have use `ExpansionLoc` pattern in other places when we collect 
> the main-file top-level decl 
> ([include-cleaner](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/include-cleaner/lib/Record.cpp#L406),
>  
> [clangd](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/SourceCode.cpp#L422)),
>  and I don't see a special reason to change the pattern in the clang-tidy 
> check.
Is the expansion location of `myfunc` in the main file? If that's the case, we 
need the expansion location indeed.
Otherwise, we need `getFileLoc` to map file locations from macro arguments to 
their spelling (in the main file above) and locations from macro bodies to the 
expansion location.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

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


[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527330.
VitaNuo added a comment.

Update test name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,92 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+std::string
+appendPathSystemIndependent(std::initializer_list Segments,
+bool IsAbsolute) {
+  llvm::StringRef Sep = llvm::sys::path::get_separator();
+  llvm::SmallString<32> Path;
+  if (IsAbsolute)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Sep);
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Segment);
+  return std::string{Path};
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(llvm::StringRef AbsolutePath) const override {
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath("foo/baz.h")] = "";
+  Inputs.ExtraFiles["/foo/bar.h"] = "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader(Header{*FM.getFile(testPath("foo.h"))}, HS,
+ MainFile, DummyIncludeSpeller{}));
+  EXPECT_EQ("bar.h", spellHeader(Header{*FM.getFile("bar.h")}, HS, MainFile,
+ DummyIncludeSpeller{}));
+  EXPECT_EQ(appendPathSystemIndependent({"foo", "baz.h"}, false),
+spellHeader(Header{*FM.getFile(testPath("foo/baz.h"))}, HS,
+MainFile, DummyIncludeSpeller{}));
+  EXPECT_EQ(appendPathSystemIndependent({"foo", "bar.h"}, true),
+spellHeader(Header{*FM.getFile("/foo/bar.h")}, HS, MainFile,
+DummyIncludeSpeller{}));
+}
+
+} // namespace
+} // namespace clang::include_cleaner
\ No newline at end of file
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
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/

[PATCH] D142630: [clang][Interp] Implement virtual function calls

2023-06-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 527331.

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

https://reviews.llvm.org/D142630

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Context.h
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpState.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.h
  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
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 // RUN: %clang_cc1 -verify=ref -std=c++14 %s
+// RUN: %clang_cc1 -verify=ref -std=c++20 %s
 // RUN: %clang_cc1 -verify=ref -triple i686 %s
 
 struct BoolPair {
@@ -380,6 +382,7 @@
 };
 
 namespace DeriveFailures {
+#if __cplusplus < 202002L
   struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
 int Val;
   };
@@ -397,10 +400,12 @@
// ref-note {{declared here}} \
// expected-error {{must be initialized by a constant expression}} \
// expected-note {{in call to 'Derived(12)'}}
+
   static_assert(D.Val == 0, ""); // ref-error {{not an integral 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}}
+#endif
 
   struct AnotherBase {
 int Val;
@@ -488,3 +493,158 @@
   //static_assert(b.a.m == 100, "");
   //static_assert(b.a.f == 100, "");
 }
+
+#if __cplusplus >= 202002L
+namespace VirtualCalls {
+namespace Obvious {
+
+  class A {
+  public:
+constexpr A(){}
+constexpr virtual int foo() {
+  return 3;
+}
+  };
+  class B : public A {
+  public:
+constexpr int foo() override {
+  return 6;
+}
+  };
+
+  constexpr int getFooB(bool b) {
+A *a;
+A myA;
+B myB;
+
+if (b)
+  a = &myA;
+else
+  a = &myB;
+
+return a->foo();
+  }
+  static_assert(getFooB(true) == 3, "");
+  static_assert(getFooB(false) == 6, "");
+}
+
+namespace MultipleBases {
+  class A {
+  public:
+constexpr virtual int getInt() const { return 10; }
+  };
+  class B {
+  public:
+  };
+  class C : public A, public B {
+  public:
+constexpr int getInt() const override { return 20; }
+  };
+
+  constexpr int callGetInt(const A& a) { return a.getInt(); }
+  static_assert(callGetInt(C()) == 20, "");
+  static_assert(callGetInt(A()) == 10, "");
+}
+
+namespace Destructors {
+  class Base {
+  public:
+int i;
+constexpr Base(int &i) : i(i) {i++;}
+constexpr virtual ~Base() {i--;}
+  };
+
+  class Derived : public Base {
+  public:
+constexpr Derived(int &i) : Base(i) {}
+constexpr virtual ~Derived() {i--;}
+  };
+
+  constexpr int test() {
+int i = 0;
+Derived d(i);
+return i;
+  }
+  static_assert(test() == 1);
+}
+
+
+namespace VirtualDtors {
+  class A {
+  public:
+unsigned &v;
+constexpr A(unsigned &v) : v(v) {}
+constexpr virtual ~A() {
+  v |= (1 << 0);
+}
+  };
+  class B : public A {
+  public:
+constexpr B(unsigned &v) : A(v) {}
+constexpr virtual ~B() {
+  v |= (1 << 1);
+}
+  };
+  class C : public B {
+  public:
+constexpr C(unsigned &v) : B(v) {}
+constexpr virtual ~C() {
+  v |= (1 << 2);
+}
+  };
+
+  constexpr bool foo() {
+unsigned a = 0;
+{
+  C c(a);
+}
+return ((a & (1 << 0)) && (a & (1 << 1)) && (a & (1 << 2)));
+  }
+
+  static_assert(foo());
+
+
+};
+
+namespace QualifiedCalls {
+  class A {
+  public:
+  constexpr virtual int foo() const {
+  return 5;
+  }
+  };
+  class B : public A {};
+  class C : public B {
+  public:
+  constexpr int foo() const override {
+  return B::foo(); // B doesn't have a foo(), so this should call A::foo().
+  }
+  constexpr int foo2() const {
+return this->A::foo();
+  }
+  };
+  constexpr C c;
+  static_assert(c.foo() == 5);
+  static_assert(c.foo2() == 5);
+
+
+  struct S {
+int _c = 0;
+virtual constexpr int foo() const { return 1; }
+  };
+
+  struct SS : S {
+int a;
+constexpr SS() {
+  a = S::foo();
+}
+constexpr int foo() const override {
+  return S::foo();
+}
+  };
+
+  constexpr SS ss;
+  static_assert(ss.a == 1);
+}

[PATCH] D142630: [clang][Interp] Implement virtual function calls

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



Comment at: clang/lib/AST/Interp/Interp.h:1560
+  // is the furthest we might go up in the hierarchy.
+  ThisPtr = ThisPtr.getDeclPtr();
+}

tbaeder wrote:
> Just so I don't forget: The assignment to `ThisPtr` here is dead.
Lies. I explained above that it's for the testcase. `ThisPtr` is a reference, 
so this replaces the this pointer on the stack.


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

https://reviews.llvm.org/D142630

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


[PATCH] D142630: [clang][Interp] Implement virtual function calls

2023-06-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 527336.

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

https://reviews.llvm.org/D142630

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Context.h
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpState.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.h
  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
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 -verify %s
 // RUN: %clang_cc1 -verify=ref %s
 // RUN: %clang_cc1 -verify=ref -std=c++14 %s
+// RUN: %clang_cc1 -verify=ref -std=c++20 %s
 // RUN: %clang_cc1 -verify=ref -triple i686 %s
 
 struct BoolPair {
@@ -380,6 +382,7 @@
 };
 
 namespace DeriveFailures {
+#if __cplusplus < 202002L
   struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
 int Val;
   };
@@ -397,10 +400,12 @@
// ref-note {{declared here}} \
// expected-error {{must be initialized by a constant expression}} \
// expected-note {{in call to 'Derived(12)'}}
+
   static_assert(D.Val == 0, ""); // ref-error {{not an integral 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}}
+#endif
 
   struct AnotherBase {
 int Val;
@@ -488,3 +493,158 @@
   //static_assert(b.a.m == 100, "");
   //static_assert(b.a.f == 100, "");
 }
+
+#if __cplusplus >= 202002L
+namespace VirtualCalls {
+namespace Obvious {
+
+  class A {
+  public:
+constexpr A(){}
+constexpr virtual int foo() {
+  return 3;
+}
+  };
+  class B : public A {
+  public:
+constexpr int foo() override {
+  return 6;
+}
+  };
+
+  constexpr int getFooB(bool b) {
+A *a;
+A myA;
+B myB;
+
+if (b)
+  a = &myA;
+else
+  a = &myB;
+
+return a->foo();
+  }
+  static_assert(getFooB(true) == 3, "");
+  static_assert(getFooB(false) == 6, "");
+}
+
+namespace MultipleBases {
+  class A {
+  public:
+constexpr virtual int getInt() const { return 10; }
+  };
+  class B {
+  public:
+  };
+  class C : public A, public B {
+  public:
+constexpr int getInt() const override { return 20; }
+  };
+
+  constexpr int callGetInt(const A& a) { return a.getInt(); }
+  static_assert(callGetInt(C()) == 20, "");
+  static_assert(callGetInt(A()) == 10, "");
+}
+
+namespace Destructors {
+  class Base {
+  public:
+int i;
+constexpr Base(int &i) : i(i) {i++;}
+constexpr virtual ~Base() {i--;}
+  };
+
+  class Derived : public Base {
+  public:
+constexpr Derived(int &i) : Base(i) {}
+constexpr virtual ~Derived() {i--;}
+  };
+
+  constexpr int test() {
+int i = 0;
+Derived d(i);
+return i;
+  }
+  static_assert(test() == 1);
+}
+
+
+namespace VirtualDtors {
+  class A {
+  public:
+unsigned &v;
+constexpr A(unsigned &v) : v(v) {}
+constexpr virtual ~A() {
+  v |= (1 << 0);
+}
+  };
+  class B : public A {
+  public:
+constexpr B(unsigned &v) : A(v) {}
+constexpr virtual ~B() {
+  v |= (1 << 1);
+}
+  };
+  class C : public B {
+  public:
+constexpr C(unsigned &v) : B(v) {}
+constexpr virtual ~C() {
+  v |= (1 << 2);
+}
+  };
+
+  constexpr bool foo() {
+unsigned a = 0;
+{
+  C c(a);
+}
+return ((a & (1 << 0)) && (a & (1 << 1)) && (a & (1 << 2)));
+  }
+
+  static_assert(foo());
+
+
+};
+
+namespace QualifiedCalls {
+  class A {
+  public:
+  constexpr virtual int foo() const {
+  return 5;
+  }
+  };
+  class B : public A {};
+  class C : public B {
+  public:
+  constexpr int foo() const override {
+  return B::foo(); // B doesn't have a foo(), so this should call A::foo().
+  }
+  constexpr int foo2() const {
+return this->A::foo();
+  }
+  };
+  constexpr C c;
+  static_assert(c.foo() == 5);
+  static_assert(c.foo2() == 5);
+
+
+  struct S {
+int _c = 0;
+virtual constexpr int foo() const { return 1; }
+  };
+
+  struct SS : S {
+int a;
+constexpr SS() {
+  a = S::foo();
+}
+constexpr int foo() const override {
+  return S::foo();
+}
+  };
+
+  constexpr SS ss;
+  static_assert(ss.a == 1);
+}

[PATCH] D151863: [x86][MC] Fix movdir64b addressing

2023-06-01 Thread Akshay Khadse via Phabricator via cfe-commits
akshaykhadse updated this revision to Diff 527345.
akshaykhadse added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add CFE tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151863

Files:
  clang/test/CodeGen/ms-inline-asm-64.c
  clang/test/CodeGen/ms-inline-asm.c
  llvm/lib/Target/X86/AsmParser/X86Operand.h
  llvm/test/MC/X86/x86-64-movdir64b-intel.s


Index: llvm/test/MC/X86/x86-64-movdir64b-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-movdir64b-intel.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel 
-output-asm-variant=1 --show-encoding %s | FileCheck %s
+// CHECK: movdir64b rax, zmmword ptr [rax - 4096]
+// CHECK: encoding: [0x66,0x0f,0x38,0xf8,0x80,0x00,0xf0,0xff,0xff]
+  movdir64b rax, zmmword ptr [rax - 4096]
Index: llvm/lib/Target/X86/AsmParser/X86Operand.h
===
--- llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -383,6 +383,8 @@
   bool isMem512_GR16() const {
 if (!isMem512())
   return false;
+if (getMemDisp()->getKind() == llvm::MCExpr::SymbolRef)
+  return true;
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR16RegClassID].contains(getMemBaseReg()))
   return false;
@@ -391,6 +393,8 @@
   bool isMem512_GR32() const {
 if (!isMem512())
   return false;
+if (getMemDisp()->getKind() == llvm::MCExpr::SymbolRef)
+  return true;
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR32RegClassID].contains(getMemBaseReg()) &&
 getMemBaseReg() != X86::EIP)
@@ -404,6 +408,8 @@
   bool isMem512_GR64() const {
 if (!isMem512())
   return false;
+if (getMemDisp()->getKind() == llvm::MCExpr::SymbolRef)
+  return true;
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR64RegClassID].contains(getMemBaseReg()) &&
 getMemBaseReg() != X86::RIP)
Index: clang/test/CodeGen/ms-inline-asm.c
===
--- clang/test/CodeGen/ms-inline-asm.c
+++ clang/test/CodeGen/ms-inline-asm.c
@@ -675,6 +675,13 @@
   // CHECK: call void asm sideeffect inteldialect "add eax, [eax + $$-128]", 
"~{eax},~{flags},~{dirflag},~{fpsr},~{flags}"()
 }
 
+void t47(void) {
+  // CHECK-LABEL: define{{.*}} void @t47
+  int arr[1000];
+  __asm enqcmds eax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "enqcmds eax, zmmword ptr 
$0", "*m,~{flags},~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) 
%arr)
+}
+
 void dot_operator(void){
   // CHECK-LABEL: define{{.*}} void @dot_operator
__asm { mov eax, 3[ebx]A.b}
Index: clang/test/CodeGen/ms-inline-asm-64.c
===
--- clang/test/CodeGen/ms-inline-asm-64.c
+++ clang/test/CodeGen/ms-inline-asm-64.c
@@ -72,3 +72,10 @@
   // CHECK-SAME: jmp ${1:P}
   // CHECK-SAME: "*m,*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(void 
(...)) @bar, ptr elementtype(void (...)) @bar)
 }
+
+void t47(void) {
+  // CHECK-LABEL: define{{.*}} void @t47
+  int arr[1000];
+  __asm enqcmds rax, zmmword ptr [arr]
+  // CHECK: call void asm sideeffect inteldialect "enqcmds rax, zmmword ptr 
$0", "*m,~{flags},~{dirflag},~{fpsr},~{flags}"(ptr elementtype([1000 x i32]) 
%arr)
+}


Index: llvm/test/MC/X86/x86-64-movdir64b-intel.s
===
--- /dev/null
+++ llvm/test/MC/X86/x86-64-movdir64b-intel.s
@@ -0,0 +1,4 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -x86-asm-syntax=intel -output-asm-variant=1 --show-encoding %s | FileCheck %s
+// CHECK: movdir64b rax, zmmword ptr [rax - 4096]
+// CHECK: encoding: [0x66,0x0f,0x38,0xf8,0x80,0x00,0xf0,0xff,0xff]
+  movdir64b rax, zmmword ptr [rax - 4096]
Index: llvm/lib/Target/X86/AsmParser/X86Operand.h
===
--- llvm/lib/Target/X86/AsmParser/X86Operand.h
+++ llvm/lib/Target/X86/AsmParser/X86Operand.h
@@ -383,6 +383,8 @@
   bool isMem512_GR16() const {
 if (!isMem512())
   return false;
+if (getMemDisp()->getKind() == llvm::MCExpr::SymbolRef)
+  return true;
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR16RegClassID].contains(getMemBaseReg()))
   return false;
@@ -391,6 +393,8 @@
   bool isMem512_GR32() const {
 if (!isMem512())
   return false;
+if (getMemDisp()->getKind() == llvm::MCExpr::SymbolRef)
+  return true;
 if (getMemBaseReg() &&
 !X86MCRegisterClasses[X86::GR32RegClassID].contains(getMemBaseReg()) &&
 getMemBaseReg() != X86::EIP)
@@ -404,6 +408,8 @@
   bool isMem512_GR64() const {
 if (!isMem512())
   return false;
+if (getMemDisp()->getKind() == llvm::M

[PATCH] D144164: [clang][Interp] Handle PtrMemOps

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



Comment at: clang/lib/AST/Interp/Context.cpp:122
+  T->isFunctionProtoType() ||
+  T->isSpecificBuiltinType(BuiltinType::BoundMember))
+return PT_FnPtr;

aaron.ballman wrote:
> Do you have test coverage for the bound member case?
I was sure I had, I added this to make some test work... but now I removed it 
and nothing breaks, so I guess I don't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144164

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


[PATCH] D144164: [clang][Interp] Handle PtrMemOps

2023-06-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 527346.

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

https://reviews.llvm.org/D144164

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/literals.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
@@ -646,5 +646,54 @@
   constexpr SS ss;
   static_assert(ss.a == 1);
 }
+
+namespace VirtualFunctionPointers {
+  struct S {
+virtual constexpr int func() const { return 1; }
+  };
+
+  struct Middle : S {
+constexpr Middle(int i) : i(i) {}
+int i;
+  };
+
+  struct Other {
+constexpr Other(int k) : k(k) {}
+int k;
+  };
+
+  struct S2 : Middle, Other {
+int j;
+constexpr S2(int i, int j, int k) : Middle(i), Other(k), j(j) {}
+virtual constexpr int func() const { return i + j + k  + S::func(); }
+  };
+
+  constexpr S s;
+  constexpr decltype(&S::func) foo = &S::func;
+  constexpr int value = (s.*foo)();
+  static_assert(value == 1);
+
+
+  constexpr S2 s2(1, 2, 3);
+  static_assert(s2.i == 1);
+  static_assert(s2.j == 2);
+  static_assert(s2.k == 3);
+
+  constexpr int value2 = s2.func();
+  constexpr int value3 = (s2.*foo)();
+  static_assert(value3 == 7);
+
+  constexpr int dynamicDispatch(const S &s) {
+constexpr decltype(&S::func) SFunc = &S::func;
+
+return (s.*SFunc)();
+  }
+
+  static_assert(dynamicDispatch(s) == 1);
+  static_assert(dynamicDispatch(s2) == 7);
+};
+
+
+
 };
 #endif
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -149,13 +149,10 @@
 // ref-error{{to a function type}}
 
 
-
-  /// FIXME: The following code should be accepted.
   struct S {
 void func();
   };
-  constexpr void (S::*Func)() = &S::func; // expected-error {{must be initialized by a constant expression}} \
-  // expected-error {{interpreter failed to evaluate an expression}}
+  constexpr void (S::*Func)() = &S::func;
   static_assert(sizeof(Func) == sizeof(&S::func), "");
 
 
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1673,6 +1673,9 @@
   if (!F || !F->isConstexpr())
 return false;
 
+  if (F->isVirtual())
+return CallVirt(S, OpPC, F);
+
   return Call(S, OpPC, F);
 }
 
Index: clang/lib/AST/Interp/Context.cpp
===
--- clang/lib/AST/Interp/Context.cpp
+++ clang/lib/AST/Interp/Context.cpp
@@ -78,12 +78,6 @@
 const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
 
 std::optional Context::classify(QualType T) const {
-  if (T->isFunctionPointerType() || T->isFunctionReferenceType())
-return PT_FnPtr;
-
-  if (T->isReferenceType() || T->isPointerType())
-return PT_Ptr;
-
   if (T->isBooleanType())
 return PT_Bool;
 
@@ -123,9 +117,22 @@
   if (T->isFloatingType())
 return PT_Float;
 
+  if (T->isFunctionPointerType() || T->isFunctionReferenceType() ||
+  T->isFunctionProtoType())
+return PT_FnPtr;
+
+  if (T->isReferenceType() || T->isPointerType())
+return PT_Ptr;
+
   if (auto *AT = dyn_cast(T))
 return classify(AT->getValueType());
 
+  if (auto *DT = dyn_cast(T))
+return classify(DT->getUnderlyingType());
+
+  if (auto *DT = dyn_cast(T))
+return classify(DT->getPointeeType());
+
   return {};
 }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -210,13 +210,13 @@
   const Expr *LHS = BO->getLHS();
   const Expr *RHS = BO->getRHS();
 
+  if (BO->isPtrMemOp())
+return this->visit(RHS);
+
   // Typecheck the args.
   std::optional LT = classify(LHS->getType());
   std::optional RT = classify(RHS->getType());
   std::optional T = classify(BO->getType());
-  if (!LT || !RT || !T) {
-return this->bail(BO);
-  }
 
   auto Discard = [this, T, BO](bool Result) {
 if (!Result)
@@ -231,6 +231,9 @@
 return Discard(this->visit(RHS));
   }
 
+  if (!LT || !RT || !T)
+return this->bail(BO);
+
   // Pointer arithmetic special case.
   if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
 if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144457: [clang][Interp] Handle global composite temporaries

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



Comment at: clang/lib/AST/Interp/Pointer.cpp:10
 #include "Pointer.h"
+#include "Boolean.h"
+#include "Context.h"

shafik wrote:
> Are all these headers really needed for the change below?
We access `.toAPValue()` on all of them in the `TYPE_SWITCH` below, so yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144457

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


[PATCH] D151730: [RISCV] Support target attribute for function

2023-06-01 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

Testcase for backend?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151730

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


[clang] 453e02c - [OpenMP] Add support for declare target initializer expressions

2023-06-01 Thread Sandeep Kosuri via cfe-commits

Author: Ritanya B Bharadwaj
Date: 2023-06-01T05:27:23-05:00
New Revision: 453e02ca0903c9f65529d21c513925ab0fdea1e1

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

LOG: [OpenMP] Add support for declare target initializer expressions

Initial support for OpenMP 5.0 declare target "as if" behavior for "initializer 
expressions".
OpenMP 5.0, 2.12.7 declare target.

Reviewed By: Alexey

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

Added: 
clang/test/OpenMP/declare_target_variables_ast_print.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_target_messages.cpp
clang/test/OpenMP/nvptx_target_exceptions_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index afbc895cfd28..d2cb0ef261fb 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11324,6 +11324,11 @@ class Sema final {
   void
   checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
SourceLocation IdLoc = SourceLocation());
+
+  /// Adds OMPDeclareTargetDeclAttr to referenced variables in declare target
+  /// directive.
+  void ActOnOpenMPDeclareTargetInitializer(Decl *D);
+
   /// Finishes analysis of the deferred functions calls that may be declared as
   /// host/nohost during device/host compilation.
   void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d7c595b4201f..b8aba816283d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14476,6 +14476,12 @@ Sema::DeclGroupPtrTy 
Sema::FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS,
 
   for (unsigned i = 0, e = Group.size(); i != e; ++i) {
 if (Decl *D = Group[i]) {
+  // Check if the Decl has been declared in '#pragma omp declare target'
+  // directive and has static storage duration.
+  if (auto *VD = dyn_cast(D);
+  LangOpts.OpenMP && VD && VD->hasAttr() &&
+  VD->hasGlobalStorage())
+ActOnOpenMPDeclareTargetInitializer(D);
   // For declarators, there are some additional syntactic-ish checks we 
need
   // to perform.
   if (auto *DD = dyn_cast(D)) {

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 45cbfa6eeff1..6e83e20d96d5 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -23100,6 +23100,55 @@ void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, 
Decl *D,
   checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D);
 }
 
+/// This class visits every VarDecl that the initializer references and adds
+/// OMPDeclareTargetDeclAttr to each of them.
+class GlobalDeclRefChecker final
+: public StmtVisitor {
+  SmallVector DeclVector;
+  Attr *A;
+
+public:
+  /// A StmtVisitor class function that visits all DeclRefExpr and adds
+  /// OMPDeclareTargetDeclAttr to them.
+  void VisitDeclRefExpr(DeclRefExpr *Node) {
+if (auto *VD = dyn_cast(Node->getDecl())) {
+  VD->addAttr(A);
+  DeclVector.push_back(VD);
+}
+  }
+  /// A function that iterates across each of the Expr's children.
+  void VisitExpr(Expr *Ex) {
+for (auto *Child : Ex->children()) {
+  Visit(Child);
+}
+  }
+  /// A function that keeps a record of all the Decls that are variables, has
+  /// OMPDeclareTargetDeclAttr, and has global storage in the DeclVector. Pop
+  /// each Decl one at a time and use the inherited 'visit' functions to look
+  /// for DeclRefExpr.
+  void declareTargetInitializer(Decl *TD) {
+A = TD->getAttr();
+DeclVector.push_back(cast(TD));
+while (!DeclVector.empty()) {
+  VarDecl *TargetVarDecl = DeclVector.pop_back_val();
+  if (TargetVarDecl->hasAttr() &&
+  TargetVarDecl->hasInit() && TargetVarDecl->hasGlobalStorage()) {
+if (Expr *Ex = TargetVarDecl->getInit())
+  Visit(Ex);
+  }
+}
+  }
+};
+
+/// Adding OMPDeclareTargetDeclAttr to variables with static storage
+/// duration that are referenced in the initializer expression list of
+/// variables with static storage duration in declare target directive.
+void Sema::ActOnOpenMPDeclareTargetInitializer(Decl *TargetDecl) {
+  GlobalDeclRefChecker Checker;
+  if (auto *TargetVarDecl = dyn_cast_or_null(TargetDecl))
+Checker.declareTargetInitializer(TargetDecl);
+}
+
 OMPClause *Sema::ActOnOpenMPToClause(
 ArrayRef MotionModifiers,
 ArrayRef MotionModifiersLoc,

diff  --git a/clang/test/OpenMP/declare_target_messages.cpp 
b/clang/test/OpenMP/declare_target_messages.cpp
index ed011a8c3a59..482d3dc8cff3 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/cla

[PATCH] D146418: Support for OpenMP 5.0 sec 2.12.7 - Declare Target initializer expressions

2023-06-01 Thread 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 rG453e02ca0903: [OpenMP] Add support for declare target 
initializer expressions (authored by RitanyaB, committed by Sandeep Kosuri 
).

Changed prior to commit:
  https://reviews.llvm.org/D146418?vs=526915&id=527351#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146418

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_messages.cpp
  clang/test/OpenMP/declare_target_variables_ast_print.cpp
  clang/test/OpenMP/nvptx_target_exceptions_messages.cpp

Index: clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
===
--- clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
+++ clang/test/OpenMP/nvptx_target_exceptions_messages.cpp
@@ -95,7 +95,7 @@
 int (*D)() = C; // expected-note {{used here}}
 // host-note@-1 {{used here}}
 #pragma omp end declare target
-int foobar3() { throw 1; }
+int foobar3() { throw 1; } // expected-error {{cannot use 'throw' with exceptions disabled}}
 
 // Check no infinite recursion in deferred diagnostic emitter.
 long E = (long)&E;
Index: clang/test/OpenMP/declare_target_variables_ast_print.cpp
===
--- /dev/null
+++ clang/test/OpenMP/declare_target_variables_ast_print.cpp
@@ -0,0 +1,112 @@
+// RUN: %clang_cc1 -w -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK
+// expected-no-diagnostics
+
+static int variable = 100;
+static float variable1 = 200;
+static float variable2 = variable1;
+
+static int var = 1;
+
+static int var1 = 10;
+static int *var2 = &var1;
+static int **ptr1 = &var2;
+
+int arr[2] = {1,2};
+int (*arrptr)[2] = &arr;
+
+class declare{
+  public: int x;
+  void print();
+};
+declare obj1;
+declare *obj2 = &obj1;
+
+struct target{
+  int x;
+  void print();
+};
+static target S;
+
+#pragma omp declare target
+int target_var = variable;
+float target_var1 = variable2;
+int *ptr = &var;
+int ***ptr2 = &ptr1;
+int (**ptr3)[2] = &arrptr;
+declare **obj3 = &obj2;
+target *S1 = &S;
+#pragma omp end declare target
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: static int variable = 100;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static float variable1 = 200;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static float variable2 = variable1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK: #pragma omp declare target
+// CHECK-NEXT: static int var = 1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int var1 = 10;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int *var2 = &var1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int **ptr1 = &var2;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int arr[2] = {1, 2};
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int (*arrptr)[2] = &arr;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: class declare {
+// CHECK-NEXT: public:
+// CHECK-NEXT:  int x;
+// CHECK-NEXT:  void print();
+// CHECK-NEXT: };
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare obj1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare *obj2 = &obj1;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: struct target {
+// CHECK-NEXT:  int x;
+// CHECK-NEXT:  void print();
+// CHECK-NEXT: };
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static target S;
+// CHECK-NEXT: #pragma omp end declare target
+
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int target_var = variable;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: float target_var1 = variable2;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int *ptr = &var;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int ***ptr2 = &ptr1;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: int (**ptr3)[2] = &arrptr;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: declare **obj3 = &obj2;
+// CHECK-NEXT: #pragma omp end declare target
+/

[PATCH] D151876: [NVPTX] Signed char and (unsigned)long overloads of ldg and ldu

2023-06-01 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda created this revision.
jchlanda added a reviewer: tra.
Herald added subscribers: mattd, gchakrabarti, asavonic.
Herald added a project: All.
jchlanda requested review of this revision.
Herald added subscribers: cfe-commits, jholewinski.
Herald added a project: clang.

This is a follow up to:

- https://reviews.llvm.org/rG7258317bade0fd82e257e47b31eee3ad0c6c5305
- https://reviews.llvm.org/rG71b06585857a77691761a7bfd16b5b91454a6894


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151876

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx.c

Index: clang/test/CodeGen/builtins-nvptx.c
===
--- clang/test/CodeGen/builtins-nvptx.c
+++ clang/test/CodeGen/builtins-nvptx.c
@@ -554,10 +554,12 @@
 
 // CHECK-LABEL: nvvm_ldg
 __device__ void nvvm_ldg(const void *p) {
+  // CHECK: call i8 @llvm.nvvm.ldg.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   // CHECK: call i8 @llvm.nvvm.ldg.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   // CHECK: call i8 @llvm.nvvm.ldg.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   __nvvm_ldg_c((const char *)p);
   __nvvm_ldg_uc((const unsigned char *)p);
+  __nvvm_ldg_sc((const signed char *)p);
 
   // CHECK: call i16 @llvm.nvvm.ldg.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call i16 @llvm.nvvm.ldg.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
@@ -590,19 +592,25 @@
   // elements, its alignment is set to number of elements times the alignment of
   // its member: n*alignof(t)."
 
+  // CHECK: call <2 x i8> @llvm.nvvm.ldg.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call <2 x i8> @llvm.nvvm.ldg.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call <2 x i8> @llvm.nvvm.ldg.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   typedef char char2 __attribute__((ext_vector_type(2)));
   typedef unsigned char uchar2 __attribute__((ext_vector_type(2)));
+  typedef signed char schar2 __attribute__((ext_vector_type(2)));
   __nvvm_ldg_c2((const char2 *)p);
   __nvvm_ldg_uc2((const uchar2 *)p);
+  __nvvm_ldg_sc2((const schar2 *)p);
 
+  // CHECK: call <4 x i8> @llvm.nvvm.ldg.global.i.v4i8.p0(ptr {{%[0-9]+}}, i32 4)
   // CHECK: call <4 x i8> @llvm.nvvm.ldg.global.i.v4i8.p0(ptr {{%[0-9]+}}, i32 4)
   // CHECK: call <4 x i8> @llvm.nvvm.ldg.global.i.v4i8.p0(ptr {{%[0-9]+}}, i32 4)
   typedef char char4 __attribute__((ext_vector_type(4)));
   typedef unsigned char uchar4 __attribute__((ext_vector_type(4)));
+  typedef signed char schar4 __attribute__((ext_vector_type(4)));
   __nvvm_ldg_c4((const char4 *)p);
   __nvvm_ldg_uc4((const uchar4 *)p);
+  __nvvm_ldg_sc4((const schar4 *)p);
 
   // CHECK: call <2 x i16> @llvm.nvvm.ldg.global.i.v2i16.p0(ptr {{%[0-9]+}}, i32 4)
   // CHECK: call <2 x i16> @llvm.nvvm.ldg.global.i.v2i16.p0(ptr {{%[0-9]+}}, i32 4)
@@ -632,6 +640,15 @@
   __nvvm_ldg_i4((const int4 *)p);
   __nvvm_ldg_ui4((const uint4 *)p);
 
+  // LP32: call <2 x i32> @llvm.nvvm.ldg.global.i.v2i32.p0(ptr {{%[0-9]+}}, i32 8)
+  // LP32: call <2 x i32> @llvm.nvvm.ldg.global.i.v2i32.p0(ptr {{%[0-9]+}}, i32 8)
+  // LP64: call <2 x i64> @llvm.nvvm.ldg.global.i.v2i64.p0(ptr {{%[0-9]+}}, i32 16)
+  // LP64: call <2 x i64> @llvm.nvvm.ldg.global.i.v2i64.p0(ptr {{%[0-9]+}}, i32 16)
+  typedef long long2 __attribute__((ext_vector_type(2)));
+  typedef unsigned long ulong2 __attribute__((ext_vector_type(2)));
+  __nvvm_ldg_l2((const long2 *)p);
+  __nvvm_ldg_ul2((const ulong2 *)p);
+
   // CHECK: call <2 x i64> @llvm.nvvm.ldg.global.i.v2i64.p0(ptr {{%[0-9]+}}, i32 16)
   // CHECK: call <2 x i64> @llvm.nvvm.ldg.global.i.v2i64.p0(ptr {{%[0-9]+}}, i32 16)
   typedef long long longlong2 __attribute__((ext_vector_type(2)));
@@ -654,10 +671,12 @@
 
 // CHECK-LABEL: nvvm_ldu
 __device__ void nvvm_ldu(const void *p) {
+  // CHECK: call i8 @llvm.nvvm.ldu.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   // CHECK: call i8 @llvm.nvvm.ldu.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   // CHECK: call i8 @llvm.nvvm.ldu.global.i.i8.p0(ptr {{%[0-9]+}}, i32 1)
   __nvvm_ldu_c((const char *)p);
   __nvvm_ldu_uc((const unsigned char *)p);
+  __nvvm_ldu_sc((const signed char *)p);
 
   // CHECK: call i16 @llvm.nvvm.ldu.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call i16 @llvm.nvvm.ldu.global.i.i16.p0(ptr {{%[0-9]+}}, i32 2)
@@ -681,19 +700,25 @@
   // CHECK: call double @llvm.nvvm.ldu.global.f.f64.p0(ptr {{%[0-9]+}}, i32 8)
   __nvvm_ldu_d((const double *)p);
 
+  // CHECK: call <2 x i8> @llvm.nvvm.ldu.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call <2 x i8> @llvm.nvvm.ldu.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   // CHECK: call <2 x i8> @llvm.nvvm.ldu.global.i.v2i8.p0(ptr {{%[0-9]+}}, i32 2)
   typedef char char2 __attribute__((ext_vector_type(2)));
   typedef unsigned char uchar2 __attribute__((ext_vector_type(2)));
+  typedef signed char schar2 __attribute__((ext_vector_type(2)));
   __nvvm_ldu_c2((const char2 *)p);
   __nvvm_ldu_uc2((const uchar2 *)p);
+  __nvvm_ldu_sc

[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-06-01 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 527354.
skatrak added a comment.

Rebase and address reviewer's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

Files:
  flang/include/flang/Lower/OpenMP.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/OpenMP.cpp
  flang/test/Lower/OpenMP/requires-notarget.f90
  flang/test/Lower/OpenMP/requires.f90

Index: flang/test/Lower/OpenMP/requires.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires.f90
@@ -0,0 +1,13 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks the lowering of requires into MLIR
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.requires = #omp
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f
+  !$omp declare target
+end subroutine f
Index: flang/test/Lower/OpenMP/requires-notarget.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-notarget.f90
@@ -0,0 +1,11 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  module attributes {
+!CHECK-NOT:  omp.requires
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
Index: flang/lib/Lower/OpenMP.cpp
===
--- flang/lib/Lower/OpenMP.cpp
+++ flang/lib/Lower/OpenMP.cpp
@@ -2494,14 +2494,14 @@
   converter.bindSymbol(sym, symThreadprivateExv);
 }
 
-void handleDeclareTarget(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- const Fortran::parser::OpenMPDeclareTargetConstruct
- &declareTargetConstruct) {
-  llvm::SmallVector,
-0>
-  symbolAndClause;
+/// Extract the list of function and variable symbols affected by the given
+/// 'declare target' directive and return the intended device type for them.
+static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo(
+Fortran::lower::pft::Evaluation &eval,
+const Fortran::parser::OpenMPDeclareTargetConstruct &declareTargetConstruct,
+SmallVectorImpl> &symbolAndClause) {
+  // Gather the symbols and clauses
   auto findFuncAndVarSyms = [&](const Fortran::parser::OmpObjectList &objList,
 mlir::omp::DeclareTargetCaptureClause clause) {
 for (const auto &ompObject : objList.v) {
@@ -2521,12 +2521,11 @@
 }
   };
 
+  // The default capture type
+  auto deviceType{Fortran::parser::OmpDeviceTypeClause::Type::Any};
   const auto &spec{std::get(
   declareTargetConstruct.t)};
-  auto mod = converter.getFirOpBuilder().getModule();
 
-  // The default capture type
-  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   if (const auto *objectList{
   Fortran::parser::Unwrap(spec.u)}) {
 // Case: declare target(func, var1, var2)
@@ -2562,6 +2561,28 @@
 }
   }
 
+  switch (deviceType) {
+  case Fortran::parser::OmpDeviceTypeClause::Type::Any:
+return mlir::omp::DeclareTargetDeviceType::any;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Host:
+return mlir::omp::DeclareTargetDeviceType::host;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Nohost:
+return mlir::omp::DeclareTargetDeviceType::nohost;
+  }
+}
+
+void genDeclareTarget(Fortran::lower::AbstractConverter &converter,
+  Fortran::lower::pft::Evaluation &eval,
+  const Fortran::parser::OpenMPDeclareTargetConstruct
+  &declareTargetConstruct) {
+  llvm::SmallVector,
+0>
+  symbolAndClause;
+  mlir::omp::DeclareTargetDeviceType deviceType =
+  getDeclareTargetInfo(eval, declareTargetConstruct, symbolAndClause);
+
+  mlir::ModuleOp mod = converter.getFirOpBuilder().getModule();
   for (auto sym : symbolAndClause) {
 auto *op = mod.lookupSymbol(converter.mangleName(std::get<1>(sym)));
 
@@ -2571,32 +2592,19 @@
   converter.getCurrentLocation(),
   "Attempt to apply declare target on unsupproted operation");
 
-mlir::omp::DeclareTargetDeviceType newDeviceType;
-switch (deviceType) {
-case Fortran::parser::OmpDeviceTypeClause::Type::Nohost:
-  newDeviceType = mlir::omp::DeclareTargetDeviceType::nohost;
-  break;
-case Fortran::parser::OmpDeviceTypeClause::Type::Host:
-  newDeviceType = mlir::omp::DeclareTargetDeviceType::host;
-  break;
-case Fortran::parser::OmpDeviceTypeClause::Type::Any:
-  newDeviceType = mlir::omp:

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks, just a few nits. I think it is in a good shape, let's ship it!

Please make sure the premerge-test is happy before landing the patch, the 
windows premerge test is failing now 
(https://buildkite.com/llvm-project/premerge-checks/builds/155660#0188764d-dc9f-4e8f-b489-c7b8f8b0c52a)




Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:88
+SourceLocation Loc = D->getLocation();
+if (!SM->isWrittenInMainFile(SM->getSpellingLoc(Loc)))
+  continue;

VitaNuo wrote:
> hokein wrote:
> > VitaNuo wrote:
> > > hokein wrote:
> > > > We should use the `getExpansionLoc` rather than the `SpellingLoc` here, 
> > > > otherwise we might miss the case like `TEST_F(WalkUsedTest, 
> > > > MultipleProviders) {... }` where the decl location is spelled in 
> > > > another file, but the function body is spelled in main-file.
> > > > 
> > > > we should actually use FileLoc of the decl location here (i.e. map it 
> > > > back to spelling location) as the decl might be introduced by a macro 
> > > > expansion, but if the spelling of "primary" location belongs to the 
> > > > main file we should still analyze it (e.g. decls introduced via `TEST` 
> > > > macros)
> > > 
> > > > we actually want spelling location, not fileloc
> > > > sorry for the confusion
> > > > basically, spelling location will always map to where a name is spelled 
> > > > in a  > physical file, even if it's part of macro body
> > > > whereas getFileLoc, will map tokens from macro body to their expansion 
> > > > locations (i.e. place in a physical file where the macro is invoked)
> > > 
> > > These are earlier comments from Kadir on this topic. AFAIU we want the 
> > > spelling location for `TEST_F(WalkUsedTest, MultipleProviders) {... }` 
> > > because:
> > > 
> > > - for Decls introduced by the `TEST_F` expansion, we would like to 
> > > analyze them only if they are spelled in the main file.
> > > - for arguments, their transitive spelling location is where they're 
> > > written. So if `TEST_F(WalkUsedTest, MultipleProviders) {... }` is 
> > > written in the main file, the argument locations will be counted.
> > > 
> > I think I'm not convinced, see my comments below.
> > 
> > > for Decls introduced by the TEST_F expansion, we would like to analyze 
> > > them only if they are spelled in the main file.
> > 
> > I think it is true for some cases. For example, a function decl has 
> > different parts (declarator, and function body), if the declarator is 
> > introduced by a macro which defined in a header, and the function body is 
> > spelled in the main-file, we still want to analyze the function body, see a 
> > simple example below:
> > 
> > ```
> > // foo.h
> > #define DECLARE(X) void X()
> > 
> > // main.cpp
> > #include "foo.h"
> > 
> > DECLARE(myfunc) {
> >int a;
> >...
> > }
> > ```
> > 
> > Moreover, we have use `ExpansionLoc` pattern in other places when we 
> > collect the main-file top-level decl 
> > ([include-cleaner](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/include-cleaner/lib/Record.cpp#L406),
> >  
> > [clangd](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/SourceCode.cpp#L422)),
> >  and I don't see a special reason to change the pattern in the clang-tidy 
> > check.
> Is the expansion location of `myfunc` in the main file? If that's the case, 
> we need the expansion location indeed.
> Otherwise, we need `getFileLoc` to map file locations from macro arguments to 
> their spelling (in the main file above) and locations from macro bodies to 
> the expansion location.
> Is the expansion location of myfunc in the main file? If that's the case, we 
> need the expansion location indeed.

Right. The expansion location here is a file location which points to the 
main-file. 

Would be nice if you add the above test into the unittest.



Comment at: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp:189-193
+std::optional Replacement =
+HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"), Angled,
+  tooling::IncludeDirective::Include);
+if (!Replacement.has_value())
+  continue;

nit: we can simplify it like 

```
if (auto Replacement = HeaderIncludes.insert(...))
   diag(...);
```



Comment at: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp:27
+namespace test {
+
+std::string

wrap all things into an anonymous namespace to avoid potential ODR violations. 



Comment at: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp:70
+  IgnoreHeaders += appendPathSystemIndependent({"baz", "qux"});
+  IgnoreHeaders += ";vector";
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{IgnoreHeaders};

Instead of using 4 += statements, I think 

[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-06-01 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak marked 2 inline comments as done.
skatrak added a comment.

Thank you for the comments, they should have all been addressed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527359.
VitaNuo added a comment.

Try to fix windows test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,198 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+std::string
+appendPathSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Path;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Segment);
+  return std::string{Path};
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  std::string IgnoreHeaders{"bar.h;"};
+  IgnoreHeaders += "foo/.*";
+  IgnoreHeaders += ";";
+  IgnoreHeaders += "baz/qux";
+  IgnoreHeaders += ";vector";
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{IgnoreHeaders};
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+{{"bar.h", ""},
+ {"vector", ""},
+ {appendPathSystemIndependent({"foo", "qux.h"}), ""},
+ {appendPathSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  std::string IgnoreHeaders{"baz.h;"};
+  IgnoreHeaders += appendPathSystemIndependent({"foo", ".*"});
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"

[clang] a26bd95 - [LinkerWrapper] Fix static library symbol resolution

2023-06-01 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-06-01T06:51:51-05:00
New Revision: a26bd95325f120d9737a0b03c80eabddb56f46db

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

LOG: [LinkerWrapper] Fix static library symbol resolution

The linker wrapper performs its own very basic symbol resolution for the
purpose of supporting standard static library semantics. We do this here
because the Nvidia `nvlink` wrapper does not support static linking and
we have some offloading specific extensions.

Currently, we always place symbols in the "table" even if they aren't
extracted. This caused the logic to fail when many files were used that
referenced the same undefined variable. This patch changes the pass to
only add the symbols to the global "table" if the file is actually
extracted.

Reviewed By: tra

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

Added: 


Modified: 
clang/test/Driver/linker-wrapper-libs.c
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/test/Driver/linker-wrapper-libs.c 
b/clang/test/Driver/linker-wrapper-libs.c
index acb7c38165d04..2073092bdbcf9 100644
--- a/clang/test/Driver/linker-wrapper-libs.c
+++ b/clang/test/Driver/linker-wrapper-libs.c
@@ -12,6 +12,9 @@ int __attribute__((visibility("protected"))) global;
 int __attribute__((visibility("hidden"))) weak;
 #elif defined(HIDDEN)
 int __attribute__((visibility("hidden"))) hidden;
+#elif defined(UNDEFINED)
+extern int sym;
+int baz() { return sym; }
 #else
 extern int sym;
 
@@ -26,7 +29,11 @@ int bar() { return weak; }
 //
 // RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DRESOLVES -o 
%t.nvptx.resolves.bc
 // RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DRESOLVES -o 
%t.amdgpu.resolves.bc
+// RUN: %clang -cc1 %s -triple nvptx64-nvidia-cuda -emit-llvm-bc -DUNDEFINED 
-o %t.nvptx.undefined.bc
+// RUN: %clang -cc1 %s -triple amdgcn-amd-amdhsa -emit-llvm-bc -DUNDEFINED -o 
%t.amdgpu.undefined.bc
 // RUN: clang-offload-packager -o %t-lib.out \
+// RUN:   
--image=file=%t.nvptx.undefined.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
 \
+// RUN:   
--image=file=%t.amdgpu.undefined.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030
 \
 // RUN:   
--image=file=%t.nvptx.resolves.bc,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
 \
 // RUN:   
--image=file=%t.amdgpu.resolves.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030
 // RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o 
-fembed-offload-object=%t-lib.out

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 2d96e0a344e11..0af0f2e371b18 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -1163,20 +1163,21 @@ enum Symbol : uint32_t {
 /// Scan the symbols from a BitcodeFile \p Buffer and record if we need to
 /// extract any symbols from it.
 Expected getSymbolsFromBitcode(MemoryBufferRef Buffer, OffloadKind Kind,
- StringSaver &Saver,
+ bool IsArchive, StringSaver &Saver,
  DenseMap &Syms) {
   Expected IRSymtabOrErr = readIRSymtab(Buffer);
   if (!IRSymtabOrErr)
 return IRSymtabOrErr.takeError();
 
-  bool ShouldExtract = false;
+  bool ShouldExtract = !IsArchive;
+  DenseMap TmpSyms;
   for (unsigned I = 0; I != IRSymtabOrErr->Mods.size(); ++I) {
 for (const auto &Sym : IRSymtabOrErr->TheReader.module_symbols(I)) {
   if (Sym.isFormatSpecific() || !Sym.isGlobal())
 continue;
 
   bool NewSymbol = Syms.count(Sym.getName()) == 0;
-  auto &OldSym = Syms[Saver.save(Sym.getName())];
+  auto OldSym = NewSymbol ? Sym_None : Syms[Sym.getName()];
 
   // We will extract if it defines a currenlty undefined non-weak symbol.
   bool ResolvesStrongReference =
@@ -1192,23 +1193,31 @@ Expected getSymbolsFromBitcode(MemoryBufferRef 
Buffer, OffloadKind Kind,
 
   // Update this symbol in the "table" with the new information.
   if (OldSym & Sym_Undefined && !Sym.isUndefined())
-OldSym = static_cast(OldSym & ~Sym_Undefined);
+TmpSyms[Saver.save(Sym.getName())] =
+static_cast(OldSym & ~Sym_Undefined);
   if (Sym.isUndefined() && NewSymbol)
-OldSym = static_cast(OldSym | Sym_Undefined);
+TmpSyms[Saver.save(Sym.getName())] =
+static_cast(OldSym | Sym_Undefined);
   if (Sym.isWeak())
-OldSym = static_cast(OldSym | Sym_Weak);
+TmpSyms[Saver.save(Sym.getName())] =
+static_cast(OldSym | Sym_Weak);
 }
   }
 
+  // If the file gets extracted we update the table with the new

[PATCH] D151839: [LinkerWrapper] Fix static library symbol resolution

2023-06-01 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa26bd95325f1: [LinkerWrapper] Fix static library symbol 
resolution (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151839

Files:
  clang/test/Driver/linker-wrapper-libs.c
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -1163,20 +1163,21 @@
 /// Scan the symbols from a BitcodeFile \p Buffer and record if we need to
 /// extract any symbols from it.
 Expected getSymbolsFromBitcode(MemoryBufferRef Buffer, OffloadKind Kind,
- StringSaver &Saver,
+ bool IsArchive, StringSaver &Saver,
  DenseMap &Syms) {
   Expected IRSymtabOrErr = readIRSymtab(Buffer);
   if (!IRSymtabOrErr)
 return IRSymtabOrErr.takeError();
 
-  bool ShouldExtract = false;
+  bool ShouldExtract = !IsArchive;
+  DenseMap TmpSyms;
   for (unsigned I = 0; I != IRSymtabOrErr->Mods.size(); ++I) {
 for (const auto &Sym : IRSymtabOrErr->TheReader.module_symbols(I)) {
   if (Sym.isFormatSpecific() || !Sym.isGlobal())
 continue;
 
   bool NewSymbol = Syms.count(Sym.getName()) == 0;
-  auto &OldSym = Syms[Saver.save(Sym.getName())];
+  auto OldSym = NewSymbol ? Sym_None : Syms[Sym.getName()];
 
   // We will extract if it defines a currenlty undefined non-weak symbol.
   bool ResolvesStrongReference =
@@ -1192,23 +1193,31 @@
 
   // Update this symbol in the "table" with the new information.
   if (OldSym & Sym_Undefined && !Sym.isUndefined())
-OldSym = static_cast(OldSym & ~Sym_Undefined);
+TmpSyms[Saver.save(Sym.getName())] =
+static_cast(OldSym & ~Sym_Undefined);
   if (Sym.isUndefined() && NewSymbol)
-OldSym = static_cast(OldSym | Sym_Undefined);
+TmpSyms[Saver.save(Sym.getName())] =
+static_cast(OldSym | Sym_Undefined);
   if (Sym.isWeak())
-OldSym = static_cast(OldSym | Sym_Weak);
+TmpSyms[Saver.save(Sym.getName())] =
+static_cast(OldSym | Sym_Weak);
 }
   }
 
+  // If the file gets extracted we update the table with the new symbols.
+  if (ShouldExtract)
+Syms.insert(std::begin(TmpSyms), std::end(TmpSyms));
+
   return ShouldExtract;
 }
 
 /// Scan the symbols from an ObjectFile \p Obj and record if we need to extract
 /// any symbols from it.
 Expected getSymbolsFromObject(const ObjectFile &Obj, OffloadKind Kind,
-StringSaver &Saver,
+bool IsArchive, StringSaver &Saver,
 DenseMap &Syms) {
-  bool ShouldExtract = false;
+  bool ShouldExtract = !IsArchive;
+  DenseMap TmpSyms;
   for (SymbolRef Sym : Obj.symbols()) {
 auto FlagsOrErr = Sym.getFlags();
 if (!FlagsOrErr)
@@ -1223,7 +1232,7 @@
   return NameOrErr.takeError();
 
 bool NewSymbol = Syms.count(*NameOrErr) == 0;
-auto &OldSym = Syms[Saver.save(*NameOrErr)];
+auto OldSym = NewSymbol ? Sym_None : Syms[*NameOrErr];
 
 // We will extract if it defines a currenlty undefined non-weak symbol.
 bool ResolvesStrongReference = (OldSym & Sym_Undefined) &&
@@ -1240,12 +1249,19 @@
 
 // Update this symbol in the "table" with the new information.
 if (OldSym & Sym_Undefined && !(*FlagsOrErr & SymbolRef::SF_Undefined))
-  OldSym = static_cast(OldSym & ~Sym_Undefined);
+  TmpSyms[Saver.save(*NameOrErr)] =
+  static_cast(OldSym & ~Sym_Undefined);
 if (*FlagsOrErr & SymbolRef::SF_Undefined && NewSymbol)
-  OldSym = static_cast(OldSym | Sym_Undefined);
+  TmpSyms[Saver.save(*NameOrErr)] =
+  static_cast(OldSym | Sym_Undefined);
 if (*FlagsOrErr & SymbolRef::SF_Weak)
-  OldSym = static_cast(OldSym | Sym_Weak);
+  TmpSyms[Saver.save(*NameOrErr)] = static_cast(OldSym | Sym_Weak);
   }
+
+  // If the file gets extracted we update the table with the new symbols.
+  if (ShouldExtract)
+Syms.insert(std::begin(TmpSyms), std::end(TmpSyms));
+
   return ShouldExtract;
 }
 
@@ -1255,18 +1271,19 @@
 ///   1) It defines an undefined symbol in a regular object filie.
 ///   2) It defines a global symbol without hidden visibility that has not
 ///  yet been defined.
-Expected getSymbols(StringRef Image, OffloadKind Kind, StringSaver &Saver,
+Expected getSymbols(StringRef Image, OffloadKind Kind, bool IsArchive,
+  StringSaver &Saver,
   DenseMap &Syms) {
   MemoryBufferRef Buffer = MemoryBufferRef(Image, "");
   switch (identify_magic(Image)) {
   case file_magic:

[PATCH] D151720: [clang][ExprConstant] Fix display of syntactically-invalid note for member function calls

2023-06-01 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 527363.
hazohelet added a comment.

Address comments from @tbaeder

- Add new suggested test case
- NFC stylistic changes in test cases


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

https://reviews.llvm.org/D151720

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/AST/Interp/constexpr-nqueens.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
  clang/test/CXX/temp/temp.param/p8-cxx20.cpp
  clang/test/SemaCXX/constant-expression-cxx11.cpp
  clang/test/SemaCXX/constexpr-frame-describe.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/test/SemaCXX/deduced-return-type-cxx14.cpp

Index: clang/test/SemaCXX/deduced-return-type-cxx14.cpp
===
--- clang/test/SemaCXX/deduced-return-type-cxx14.cpp
+++ clang/test/SemaCXX/deduced-return-type-cxx14.cpp
@@ -296,7 +296,7 @@
   void f() {
 X().f();
 Y().f();
-constexpr int q = Y().f(); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to '&Y()->f()'}}
+constexpr int q = Y().f(); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to 'Y().f()'}}
   }
   struct NonLiteral { ~NonLiteral(); } nl; // cxx14-note {{user-provided destructor}}
   // cxx20_23-note@-1 {{'NonLiteral' is not literal because its destructor is not constexpr}}
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -840,13 +840,13 @@
   copy fail1{good0}; // expected-error {{call to consteval function 'defaulted_special_member_template::copy::copy' is not a constant expression}} \
  expected-note {{in call to 'copy(good0)'}}
   fail1 = good0;  // expected-error {{call to consteval function 'defaulted_special_member_template::copy::operator=' is not a constant expression}} \
- expected-note {{in call to '&fail1->operator=(good0)'}}
+ expected-note {{in call to 'fail1.operator=(good0)'}}
 
   move good1;
   move fail2{static_cast&&>(good1)}; // expected-error {{call to consteval function 'defaulted_special_member_template::move::move' is not a constant expression}} \
expected-note {{in call to 'move(good1)'}}
   fail2 = static_cast&&>(good1);  // expected-error {{call to consteval function 'defaulted_special_member_template::move::operator=' is not a constant expression}} \
-   expected-note {{in call to '&fail2->operator=(good1)'}}
+   expected-note {{in call to 'fail2.operator=(good1)'}}
 }
 } // namespace defaulted_special_member_template
 
Index: clang/test/SemaCXX/constexpr-frame-describe.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constexpr-frame-describe.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+
+struct Foo {
+constexpr void zomg() const { (void)(1 / 0); } // expected-error {{constant expression}} \
+  expected-warning {{division by zero}} \
+  expected-note 2{{division by zero}}
+};
+
+struct S {
+constexpr S() {}
+constexpr bool operator==(const S&) const { // expected-error {{never produces a constant expression}}
+  return 1 / 0; // expected-warning {{division by zero}} \
+   expected-note 3{{division by zero}}
+}
+
+constexpr bool heh() const {
+auto F = new Foo();
+F->zomg(); // expected-note {{in call to 'F->zomg()'}}
+delete F;
+return false;
+}
+};
+
+constexpr S s;
+
+static_assert(s.heh()); // expected-error {{constant expression}} \
+   expected-note {{in call to 's.heh()'}}
+
+constexpr S s2;
+constexpr const S *sptr = &s;
+constexpr const S *sptr2 = &s2;
+static_assert(s == s2); // expected-error {{constant expression}} \
+   expected-note {{in call to 's.operator==(s2)'}}
+static_assert(*sptr == *sptr2); // expected-error {{constant expression}} \
+   expected-note {{in call to '*sptr.operator==(s2)'}}
+
+struct A {
+  constexpr int foo() { (void)(1/0); return 1;} // expected-error {{never produces a constant expression}} \
+   expected-warning {{division by zero}} \
+   expected-note 2{{division by zero}}
+};
+
+struct B {
+  A aa;
+  A *a = &aa;
+};
+
+struct C {
+  B b;
+};
+
+struct D {
+  C cc;
+  C *c = &cc;
+};
+
+constexpr D d{};
+static_assert(d.c->b.a->foo() =

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527369.
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Remove system-independent handling to see behavior on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,218 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+std::string
+appendPathSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Path;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Segment);
+  return std::string{Path};
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  std::string IgnoreHeaders{"bar.h;"};
+  IgnoreHeaders += "foo/.*";
+  IgnoreHeaders += ";";
+  IgnoreHeaders += "baz/qux";
+  IgnoreHeaders += ";vector";
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{IgnoreHeaders};
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {"foo/qux.h", ""},
+   {"baz/qux/qux.h", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  std::string IgnoreHeaders{"baz.h;"};
+  IgnoreHeaders += appendPathSystemIndependent({"foo", ".*"});
+  

[PATCH] D151720: [clang][ExprConstant] Fix display of syntactically-invalid note for member function calls

2023-06-01 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet marked 5 inline comments as done.
hazohelet added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:1931
+  else
+  Out << ".";
+} else if (const auto *OCE =

tbaeder wrote:
> Did you `clang-format` these changes? The two if/else body here seems 
> indented 4 spaces instead  of 2.
Yes, I did run `git clang-format` before uploading. `clang-format` forces 4 
spaces here even when I write 2 spaces.
Precommit CI's `clang-format` also seems to say nothing about the indentation 
here.
(Link: 
https://buildkite.com/llvm-project/premerge-checks/builds/155642#018875b6-df57-4c32-8f54-203e79d4a428)
So I think this might be an internal bug of `clang-format`.


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

https://reviews.llvm.org/D151720

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


[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

thanks, left some comments per our offline discussion.




Comment at: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h:104
+/// order is not specified.
+std::function defaultHeaderMapper();
+

VitaNuo wrote:
> hokein wrote:
> > It is unclear to me why we need `defaultHeaderMapper` and the parameter 
> > `MapHeader` in `spellHeader` in the header.
> > 
> > Do we want the caller of `spellHeader` to provide a different HeaderMapper? 
> > I don't see a usecase for that -- the current strategy of is to iterate all 
> > extension points, if we find the first available one, we just return it; 
> > otherwise we use the default fallback (`suggestPathToFileForDiagnostics`). 
> > I believe it is enough for `spellHeader` to cover all our cases.
> > 
> > Plugins might need extra information, e.g. clangd-configs for remapping 
> > quotes to > angles (or full path re-writes)
> > Reason to push registry to applications and rather take in a functor in 
> > >include_cleaner (or just let it be handled by applications completely?)
> 
> This is a quote from our sync notes. I believe the idea was that applications 
> might want to parametrize mapping somehow. When linking via a strategy, you 
> can only provide a class that has a parameterless constructor, though. At 
> least that's my understanding.
Right. 

As discussed, for extra parameters, we can pass the input parameters via a 
virtual method call. we could pack all parameters into a struct, we could 
refine the interface like :

```
class IncludeSpeller {
public:
   struct Input {
  const Header& HeaderToInsert;
  HeaderSearch &HS;
  const FileEntry* MainFile;
   };
   
   virtual std::string spell(const Input&) = 0;
};
using IncludeSpellerRegistry = llvm::Registry;
std::string spellHeader(const IncludeSpeller::Input& Input);
```


Now for each IncludeSpeller, `Input` provides enough information to implement 
their strategy.
e.g. for our internal one which needs to resolve all symlinks, we can get the 
FileManager from the `HeaderSearch`.



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:96
+// Spelling physical headers allows for various plug-in strategies.
+std::string FinalSpelling = MapHeader(H.physical()->tryGetRealPathName());
+if (!FinalSpelling.empty())

as discussed, `tryGetRealPathName` doesn't guarantee it returns an absolute 
file path, and it is not enough to support our internal use case where we need 
to resolve the symlink (which requires a `FileManager`). 



Comment at: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp:1
+//===--- AnalysisTest.cpp 
-===//
+//

nit: IncludeSpellerTest.cpp



Comment at: 
clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp:60
+RootWithSeparator += llvm::sys::path::get_separator();
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+return AbsolutePath.str();

we miss to check the return value here -- if it is false (the `AbsolutePath` 
doesn't start with the `testRoot()`), then we returns an empty string.

The mental model is that each `IncludeSpeller` subclass only implements their 
strategy for a particular interesting path pattern, if the absolute path 
doesn't match the pattern, we should return an empty string, claiming that 
there is no customization for this `IncludeSpeller`. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

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


[clang] fca2109 - [clang][NFC] Make HeaderSearch::suggestPathToFileForDiagnostics method const.

2023-06-01 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-01T14:42:16+02:00
New Revision: fca2109047964ea884fcd86efe24bc4c4bfb940e

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

LOG: [clang][NFC] Make HeaderSearch::suggestPathToFileForDiagnostics method 
const.

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Lex/HeaderSearch.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index d3ee4963fced9..e2d7f64c360f2 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -867,7 +867,7 @@ class HeaderSearch {
   ///path is relative to a system header directory.
   std::string suggestPathToFileForDiagnostics(const FileEntry *File,
   llvm::StringRef MainFile,
-  bool *IsSystem = nullptr);
+  bool *IsSystem = nullptr) const;
 
   /// Suggest a path by which the specified file could be found, for use in
   /// diagnostics to suggest a #include. Returned path will only contain 
forward
@@ -881,7 +881,7 @@ class HeaderSearch {
   std::string suggestPathToFileForDiagnostics(llvm::StringRef File,
   llvm::StringRef WorkingDir,
   llvm::StringRef MainFile,
-  bool *IsSystem = nullptr);
+  bool *IsSystem = nullptr) const;
 
   void PrintStats();
 

diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index db7e531ed3137..33b25928cc04a 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1919,7 +1919,7 @@ void 
HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir) {
 }
 
 std::string HeaderSearch::suggestPathToFileForDiagnostics(
-const FileEntry *File, llvm::StringRef MainFile, bool *IsSystem) {
+const FileEntry *File, llvm::StringRef MainFile, bool *IsSystem) const {
   // FIXME: We assume that the path name currently cached in the FileEntry is
   // the most appropriate one for this analysis (and that it's spelled the
   // same way as the corresponding header search path).
@@ -1929,7 +1929,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
 
 std::string HeaderSearch::suggestPathToFileForDiagnostics(
 llvm::StringRef File, llvm::StringRef WorkingDir, llvm::StringRef MainFile,
-bool *IsSystem) {
+bool *IsSystem) const {
   using namespace llvm::sys;
 
   llvm::SmallString<32> FilePath = File;



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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527376.
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Remove the regular expression.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,213 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+std::string
+appendPathSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Path;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Segment);
+  return std::string{Path};
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = "bar.h;foo/qux.h;baz/qux;vector";
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {"foo/qux.h", ""},
+   {"baz/qux/qux.h", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  std::string IgnoreHeaders{"baz.h;"};
+  IgnoreHeaders += appendPathSystemIndependent({"foo", ".*"});
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{IgnoreHeaders};
+  std::vector Errors;
+  EXPECT_EQ(PreCode,
+runCheckOnCode(
+P

[PATCH] D147217: [OpenMP][OMPIRBuilder] OpenMPIRBuilder support for requires directive

2023-06-01 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 527380.
skatrak added a comment.

Update with latest main branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147217

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1291,6 +1291,9 @@
 // TODO: set the flags when available
 llvm::OpenMPIRBuilderConfig config(
 isDevice, /* IsTargetCodegen */ false,
+/* OpenMPOffloadMandatory */ false,
+/* HasRequiresReverseOffload */ false,
+/* HasRequiresUnifiedAddress */ false,
 /* HasRequiresUnifiedSharedMemory */ false,
 /* OpenMPOffloadMandatory */ false);
 ompBuilder->setConfig(config);
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -10,12 +10,14 @@
 #include "llvm/Frontend/OpenMP/OMPDeviceConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DIBuilder.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Support/Casting.h"
@@ -5124,7 +5126,7 @@
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
   OMPBuilder.initialize();
-  OpenMPIRBuilderConfig Config(false, false, false, false);
+  OpenMPIRBuilderConfig Config(false, false, false, false, false, false, false);
   OMPBuilder.setConfig(Config);
   F->setName("func");
   IRBuilder<> Builder(BB);
@@ -5178,7 +5180,8 @@
 
 TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.setConfig(OpenMPIRBuilderConfig(true, false, false, false));
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(true, false, false, false, false, false, false));
   OMPBuilder.initialize();
 
   F->setName("func");
@@ -5840,7 +5843,8 @@
 
 TEST_F(OpenMPIRBuilderTest, OffloadEntriesInfoManager) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.setConfig(OpenMPIRBuilderConfig(true, false, false, false));
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(true, false, false, false, false, false, false));
   OffloadEntriesInfoManager &InfoManager = OMPBuilder.OffloadInfoManager;
   TargetRegionEntryInfo EntryInfo("parent", 1, 2, 4, 0);
   InfoManager.initializeTargetRegionEntryInfo(EntryInfo, 0);
@@ -5855,4 +5859,44 @@
   GlobalValue::WeakAnyLinkage);
   EXPECT_TRUE(InfoManager.hasDeviceGlobalVarEntryInfo("gvar"));
 }
+
+TEST_F(OpenMPIRBuilderTest, CreateRegisterRequires) {
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(/*IsEmbedded=*/false,
+/*IsTargetCodegen=*/false,
+/*OpenMPOffloadMandatory=*/false,
+/*HasRequiresReverseOffload=*/true,
+/*HasRequiresUnifiedAddress=*/false,
+/*HasRequiresUnifiedSharedMemory=*/true,
+/*HasRequiresDynamicAllocators=*/false));
+
+  auto FName =
+  OMPBuilder.createPlatformSpecificName({"omp_offloading", "requires_reg"});
+  EXPECT_EQ(FName, ".omp_offloading.requires_reg");
+
+  Function *Fn = OMPBuilder.createRegisterRequires(FName);
+  EXPECT_NE(Fn, nullptr);
+  EXPECT_EQ(FName, Fn->getName());
+
+  EXPECT_EQ(Fn->getSection(), ".text.startup");
+  EXPECT_TRUE(Fn->hasInternalLinkage());
+  EXPECT_TRUE(Fn->hasFnAttribute(Attribute::NoInline));
+  EXPECT_TRUE(Fn->hasFnAttribute(Attribute::NoUnwind));
+  EXPECT_EQ(Fn->size(), 1u);
+
+  BasicBlock *Entry = &Fn->getEntryBlock();
+  EXPECT_FALSE(Entry->empty());
+  EXPECT_EQ(Fn->getReturnType()->getTypeID(), Type::VoidTyID);
+
+  CallInst *Call = &cast(*Entry->begin());
+  EXPECT_EQ(Call->getCalledFunction()->getName(), "__tgt_register_requires");
+  EXPECT_EQ(Call->getNumOperands(), 2u);
+
+  Value *Flags = Call->getArgOperand(0);
+  EXPECT_EQ(cast(Flags)->getSExtValue(),
+OMPBuilder.Config.getRequiresFlags());
+}
 } // namespace
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Fro

[clang-tools-extra] b3e38a1 - [clangd] NFC, remove an unused member in

2023-06-01 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-01T14:53:33+02:00
New Revision: b3e38a174373618ceef07b1b9b327408c7d132e2

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

LOG: [clangd] NFC, remove an unused member in
IncludeStructure::RecordHeaders.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index 344afdba9622a..f1838931f5a4d 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -29,7 +29,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks {
 public:
   RecordHeaders(const CompilerInstance &CI, IncludeStructure *Out)
   : SM(CI.getSourceManager()),
-HeaderInfo(CI.getPreprocessor().getHeaderSearchInfo()), Out(Out) {}
+Out(Out) {}
 
   // Record existing #includes - both written and resolved paths. Only 
#includes
   // in the main file are collected.
@@ -119,7 +119,6 @@ class IncludeStructure::RecordHeaders : public PPCallbacks {
   bool inMainFile() const { return Level == 1; }
 
   const SourceManager &SM;
-  HeaderSearch &HeaderInfo;
   // Set after entering the  file.
   FileID BuiltinFile;
   // Indicates whether  file is part of include stack.



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


[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-06-01 Thread Carlos Eduardo Seo via Phabricator via cfe-commits
cseo added a comment.

In D144654#4381893 , @nickdesaulniers 
wrote:

> In D144654#4380488 , @john.brawn 
> wrote:
>
>> gcc has the same warning so I wasn't expecting this cause to change 
>> problems, but looking more closely at gcc's behaviour it looks like it only 
>> warns for some builtin macros and not others (though glancing over the gcc 
>> source code it's not clear which macros and for what reason).
>>
>> I'll look at this some more and see if I can improve the behaviour.
>
> Based on
> https://lore.kernel.org/llvm/6475a837.170a0220.77d4a.1...@mx.google.com/T/#u
> I think the following macros aren't warned on: https://godbolt.org/z/dfqnG7bae
>
>   #undef __INT32_TYPE__
>   #undef __UINT32_TYPE__
>   #undef __UINTPTR_TYPE__
>   #undef __i386__
>   #undef __UINT64_TYPE__
>   #undef __INT64_TYPE__

glibc build also fails because of

#undef  __OPTIMIZE__


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144654

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


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-06-01 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:11083
 
+  bool CheckLastPrivateForMappedDirectives(ArrayRef Clauses);
+

`checkLastPrivateForMappedDirectives`



Comment at: clang/lib/AST/StmtPrinter.cpp:745-746
+  OpenMPDirectiveKind MappedDirective = Node->getMappedDirective();
+  if (MappedDirective != llvm::omp::OMPD_unknown &&
+  MappedDirective == llvm::omp::OMPD_loop) {
+Indent() << "#pragma omp loop bind(thread)";

Just `MappedDirective == llvm::omp::OMPD_loop`



Comment at: clang/lib/AST/StmtPrinter.cpp:746-748
+  MappedDirective == llvm::omp::OMPD_loop) {
+Indent() << "#pragma omp loop bind(thread)";
+  } else

Remove braces



Comment at: clang/lib/AST/StmtPrinter.cpp:765-766
+  OpenMPDirectiveKind MappedDirective = Node->getMappedDirective();
+  if (MappedDirective != llvm::omp::OMPD_unknown &&
+  MappedDirective == llvm::omp::OMPD_loop) {
+Indent() << "#pragma omp loop bind(parallel)";

Just `MappedDirective == llvm::omp::OMPD_loop`



Comment at: clang/lib/AST/StmtPrinter.cpp:766-768
+  MappedDirective == llvm::omp::OMPD_loop) {
+Indent() << "#pragma omp loop bind(parallel)";
+  } else

Remove braces



Comment at: clang/lib/AST/StmtPrinter.cpp:1005-1006
+  OpenMPDirectiveKind MappedDirective = Node->getMappedDirective();
+  if (MappedDirective != llvm::omp::OMPD_unknown &&
+  MappedDirective == llvm::omp::OMPD_loop) {
+Indent() << "#pragma omp loop bind(teams)";

Just `MappedDirective == llvm::omp::OMPD_loop`



Comment at: clang/lib/AST/StmtPrinter.cpp:1006-1008
+  MappedDirective == llvm::omp::OMPD_loop) {
+Indent() << "#pragma omp loop bind(teams)";
+  } else

Remove braces



Comment at: clang/lib/Sema/SemaOpenMP.cpp:343
+  /// This may also be used in a similar way for other constructs.
+  OpenMPDirectiveKind MappedDirective = OMPD_unknown;
+

I assume it shall be a member of SharingMapType, otherwise there might be 
problems with handling of enclosed constructs.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:646
+  void setCurrentDirective(OpenMPDirectiveKind NewDK) {
+SharingMapTy *Top = (SharingMapTy *)getTopOfStackOrNull();
+assert(Top != NULL &&

Why need a cast here?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:647-648
+SharingMapTy *Top = (SharingMapTy *)getTopOfStackOrNull();
+assert(Top != NULL &&
+   "Before calling setCurrentDirective Top of Stack not to be NULL.");
+// Store the old into MappedDirective & assign argument NewDK to Directive.

use `nullptr` or just `assert(Top &&`



Comment at: clang/lib/Sema/SemaOpenMP.cpp:6140-6201
+  llvm::SmallVector ClausesWithoutBind;
+  bool UseClausesWithoutBind = false;
+
+  // Restricting to "#pragma omp loop bind"
+  if (Kind == OMPD_loop) {
+if (BindKind == OMPC_BIND_unknown) {
+  // Setting the enclosing teams or parallel construct for the loop

Could you outline this new code as a separate function?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:10419
   setFunctionHasBranchProtectedScope();
-  return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount,
-  Clauses, AStmt, B);
+  OMPSimdDirective *tmp = OMPSimdDirective::Create(
+  Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);

tmp is bad name. Give better name and follow LLVM coding style recommendations.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:10461
   setFunctionHasBranchProtectedScope();
-  return OMPForDirective::Create(
+  OMPForDirective *tmp = OMPForDirective::Create(
   Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B,

Same



Comment at: clang/lib/Sema/SemaOpenMP.cpp:10474
 
+  /* Check for syntax of lastprivate */
+  if (DSAStack->getMappedDirective() == OMPD_loop) {

Use c++ style of comments



Comment at: clang/lib/Sema/SemaOpenMP.cpp:10475-10476
+  /* Check for syntax of lastprivate */
+  if (DSAStack->getMappedDirective() == OMPD_loop) {
+if (checkGenericLoopLastprivate(*this, Clauses, OMPD_loop, DSAStack))
+  return StmtError();

`if (DSAStack->getMappedDirective() == OMPD_loop && 
checkGenericLoopLastprivate(*this, Clauses, OMPD_loop, DSAStack))`. Avoid 
structured complexity.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:13993
+
+  /* Check for syntax of lastprivate */
+  if (DSAStack->getMappedDirective() == OMPD_loop) {

Same, c++ 



Comment at: clang/lib/Sema/SemaOpenMP.cpp:13994-13995
+  /* Check for syntax of lastprivate */
+  if

[PATCH] D140690: [compiler-rt][dfsan] Enable loongarch64 and add test support

2023-06-01 Thread Youling Tang via Phabricator via cfe-commits
tangyouling added a comment.

The patch will continue to be updated by @Ami-zhang


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140690

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


[PATCH] D151837: [Clang][Parser] Accept GNU attributes preceding C++ style attributes on templates

2023-06-01 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 527382.
eandrews added a comment.

Thanks for the review! I added a couple more tests.


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

https://reviews.llvm.org/D151837

Files:
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Parser/attr-order.cpp


Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // 
expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // 
expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // 
expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -210,7 +210,15 @@
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(prefixAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  // GNU attributes are applied to the declaration specification while the
+  // standard attributes are applied to the declaration.  We parse the two
+  // attribute sets into different containters so we can apply them during
+  // the regular parsing process.
+  while (MaybeParseCXX11Attributes(prefixAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.is(tok::kw_using)) {
 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, 
TemplateInfo, DeclEnd,
@@ -223,6 +231,9 @@
   // Parse the declaration specifiers, stealing any diagnostics from
   // the template parameters.
   ParsingDeclSpec DS(*this, &DiagsFromTParams);
+  DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
+  DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
+  DS.takeAttributesFrom(DeclSpecAttrs);
 
   ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
  getDeclSpecContextFromDeclaratorContext(Context));


Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -210,7 +210,15 @@
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(prefixAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  // GNU attributes are applied to the declaration specification while the
+  // standard attributes are applied to the declaration.  We parse the two
+  // attribute sets into different containters so we can apply them during
+  // the regular parsing process.
+  while (MaybeParseCXX11Attributes(prefixAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.is(tok::kw_using)) {
 aut

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527384.
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Remove regex and path handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,215 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/StringRef.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = "bar.h;foo/qux.h;baz/qux;vector";
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {"foo/qux.h", ""},
+   {"baz/qux/qux.h", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{"baz.h;foo/qux.h"};
+  std::vector Errors;
+  EXPECT_EQ(PreCode, runCheckOnCode(
+ PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+ {{"bar.h", R"(#pragma once
+  #include "baz.h"
+  #include "foo/qux.h"
+  int bar();
+   )"},
+  {"baz.h", R"(#pragma once
+  int baz();
+   )"},
+  {"foo/q

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527385.
VitaNuo added a comment.

Remove regex and path handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,215 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/StringRef.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = "bar.h;foo/qux.h;baz/qux;vector";
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {"foo/qux.h", ""},
+   {"baz/qux/qux.h", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{"baz.h;foo/qux.h"};
+  std::vector Errors;
+  EXPECT_EQ(PreCode, runCheckOnCode(
+ PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+ {{"bar.h", R"(#pragma once
+  #include "baz.h"
+  #include "foo/qux.h"
+  int bar();
+   )"},
+  {"baz.h", R"(#pragma once
+  int baz();
+   )"},
+  {"foo/qux.h", R"(#pragma once
+  

[PATCH] D151088: [flang][hlfir] Separate -emit-fir and -emit-hlfir for flang-new

2023-06-01 Thread Tom Eccles via Phabricator via cfe-commits
tblah updated this revision to Diff 527386.
tblah added a comment.

Thanks again for review!

Now there are two actions:

- EmitFIR
- EmitHLFIR

EmitHLFIR will assert that lowering was set up to emit HLFIR. EmitFIR will
use the HLFIR to FIR pipeline if lowering was set up to emit HLFIR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151088

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help.f90
  flang/test/HLFIR/flang-experimental-hlfir-flag.f90

Index: flang/test/HLFIR/flang-experimental-hlfir-flag.f90
===
--- flang/test/HLFIR/flang-experimental-hlfir-flag.f90
+++ flang/test/HLFIR/flang-experimental-hlfir-flag.f90
@@ -1,19 +1,38 @@
-! Test -flang-experimental-hlfir flag
-! RUN: %flang_fc1 -flang-experimental-hlfir -emit-fir -o - %s | FileCheck %s
-! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s --check-prefix NO-HLFIR
+! Test -flang-experimental-hlfir, -emit-hlfir, -emit-fir flags
+! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix HLFIR --check-prefix ALL %s
+! RUN: %flang_fc1 -emit-hlfir -flang-experimental-hlfir -o - %s | FileCheck --check-prefix HLFIR --check-prefix ALL %s
+! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s --check-prefix NO-HLFIR --check-prefix ALL
+! RUN: %flang_fc1 -emit-fir -flang-experimental-hlfir -o - %s | FileCheck --check-prefix FIR --check-prefix ALL %s
+
+! | Action  | -flang-experimental-hlfir? | Result  |
+! | === | == | === |
+! | -emit-hlfir | N  | Outputs HLFIR   |
+! | -emit-hlfir | Y  | Outputs HLFIR   |
+! | -emit-fir   | N  | Outputs FIR, using old lowering |
+! | -emit-fir   | Y  | Outputs FIR, lowering via HLFIR |
 
 subroutine test(a, res)
   real :: a(:), res
   res = SUM(a)
 end subroutine
-! CHECK-LABEL: func.func @_QPtest
-! CHECK:   %[[A:.*]]: !fir.box>
-! CHECK:   %[[RES:.*]]: !fir.ref
-! CHECK-DAG: %[[A_VAR:.*]]:2 = hlfir.declare %[[A]]
-! CHECK-DAG: %[[RES_VAR:.*]]:2 = hlfir.declare %[[RES]]
-! CHECK-NEXT:%[[SUM_RES:.*]] = hlfir.sum %[[A_VAR]]#0
-! CHECK-NEXT:hlfir.assign %[[SUM_RES]] to %[[RES_VAR]]#0
-! CHECK-NEXT:return
-! CHECK-NEXT:  }
+! ALL-LABEL: func.func @_QPtest
+! ALL: %[[A:.*]]: !fir.box>
+! ALL: %[[RES:.*]]: !fir.ref
+
+! HLFIR: %[[A_VAR:.*]]:2 = hlfir.declare %[[A]]
+! fir.declare is only generated via the hlfir -> fir lowering
+! FIR:   %[[A_VAR:.*]] = fir.declare %[[A]]
+! NO-HLFIR-NOT:  fir.declare
+
+! HLFIR-DAG: %[[RES_VAR:.*]]:2 = hlfir.declare %[[RES]]
+! FIR:   %[[RES_VAR:.*]] = fir.declare %[[RES]]
+! NO-HLFIR-NOT:  fir.declare
+
+! HLFIR-NEXT:%[[SUM_RES:.*]] = hlfir.sum %[[A_VAR]]#0
+! HLFIR-NEXT:hlfir.assign %[[SUM_RES]] to %[[RES_VAR]]#0
+! FIR-NOT:   hlfir.
+! NO-HLFIR-NOT:  hlfir.
+
+! ALL:   return
+! ALL-NEXT:  }
 
-! NO-HLFIR-NOT: hlfir.
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -94,9 +94,10 @@
 ! HELP-FC1-NEXT:OPTIONS:
 ! HELP-FC1-NEXT: -cpp   Enable predefined and command line preprocessor macros
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-FC1-NEXT: -emit-fir  Build the parse tree, then lower it to FIR
+! HELP-FC1-NEXT: -emit-hlfirBuild the parse tree, then lower it to HLFIR
 ! HELP-FC1-NEXT: -emit-llvm-bc  Build ASTs then convert to LLVM, emit .bc file
 ! HELP-FC1-NEXT: -emit-llvm Use the LLVM representation for assembler and object files
-! HELP-FC1-NEXT: -emit-mlir Build the parse tree, then lower it to MLIR
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -falternative-parameter-statement
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -40,8 +40,10 @@
 return std::make_unique();
   case ParseSyntaxOnly:
 return std::make_unique();
-  case EmitMLIR:
-return std::make_unique();
+  case EmitFIR:
+return std::make_unique();
+  case EmitHLFIR:
+return std::make_unique();
   case EmitLLVM:
 return std::make_unique();
   case EmitLLVMBitcode:
Index: flang/lib/Fron

[clang] 2ccb074 - [clang] NFC, make more HeaderSearch methods const.

2023-06-01 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-01T15:08:55+02:00
New Revision: 2ccb07452d8e1e62c545db2f6faad2bd794572be

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

LOG: [clang] NFC, make more HeaderSearch methods const.

Added: 


Modified: 
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Lex/HeaderSearch.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index e2d7f64c360f..5386b7a5d6d6 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -553,10 +553,10 @@ class HeaderSearch {
   /// macro.
   ///
   /// This routine does not consider the effect of \#import
-  bool isFileMultipleIncludeGuarded(const FileEntry *File);
+  bool isFileMultipleIncludeGuarded(const FileEntry *File) const;
 
   /// Determine whether the given file is known to have ever been \#imported.
-  bool hasFileBeenImported(const FileEntry *File) {
+  bool hasFileBeenImported(const FileEntry *File) const {
 const HeaderFileInfo *FI = getExistingFileInfo(File);
 return FI && FI->isImport;
   }

diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 33b25928cc04..16d64be55842 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1375,7 +1375,7 @@ HeaderSearch::getExistingFileInfo(const FileEntry *FE,
   return HFI;
 }
 
-bool HeaderSearch::isFileMultipleIncludeGuarded(const FileEntry *File) {
+bool HeaderSearch::isFileMultipleIncludeGuarded(const FileEntry *File) const {
   // Check if we've entered this file and found an include guard or #pragma
   // once. Note that we dor't check for #import, because that's not a property
   // of the file itself.



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


[PATCH] D150803: [WebAssembly] Add a new `wasm_async` clang attribute for marking async functions.

2023-06-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Couple of CFE comments, otherwise LGTM.




Comment at: clang/docs/ReleaseNotes.rst:559
 ^^^
+- Added ``attribute((wasm_async))`` to indicate that a function should be used 
with
+  JavaScript Promise Integration (JSPI).

We require underscores to spell it in code, so I figure we should do it here 
too.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7638
+  D->addAttr(::new (S.Context) WebAssemblyAsyncAttr(S.Context, AL));
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
+}

We should probably document that this forces the function to be emitted as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150803

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


[PATCH] D150670: [InstCombine] Disable generation of fshl/fshr for rotates

2023-06-01 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM, let's give it a try. The patch description needs an update though.




Comment at: llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp:920
+return I;
+} else { // fshl is a rotate
+  KnownBits LHSKnown = computeKnownBits(I->getOperand(0), Depth + 1, 
I);

Add some more explanation here, something like:
`// Avoid converting rotate into funnel shift. Only simplify if one operand is 
constant.`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150670

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


[clang] 3ddd186 - [Tooling] NFC, use const HeaderSearch for isSelfContainedHeader.

2023-06-01 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-01T15:17:21+02:00
New Revision: 3ddd18640af186bd46cb36064cf3bbe00b4b5a52

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

LOG: [Tooling] NFC, use const HeaderSearch for isSelfContainedHeader.

Added: 


Modified: 
clang/include/clang/Tooling/Inclusions/HeaderAnalysis.h
clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Inclusions/HeaderAnalysis.h 
b/clang/include/clang/Tooling/Inclusions/HeaderAnalysis.h
index 760b8dd0879c9..84d90c44de070 100644
--- a/clang/include/clang/Tooling/Inclusions/HeaderAnalysis.h
+++ b/clang/include/clang/Tooling/Inclusions/HeaderAnalysis.h
@@ -28,7 +28,7 @@ namespace tooling {
 /// This function can be expensive as it may scan the source code to find out
 /// dont-include-me pattern heuristically.
 bool isSelfContainedHeader(const FileEntry *FE, const SourceManager &SM,
-   HeaderSearch &HeaderInfo);
+   const HeaderSearch &HeaderInfo);
 
 /// This scans the given source code to see if it contains #import(s).
 bool codeContainsImports(llvm::StringRef Code);

diff  --git a/clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp 
b/clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp
index 49d23908d33b7..f83e19f10cbab 100644
--- a/clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp
+++ b/clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp
@@ -67,7 +67,7 @@ llvm::StringRef getFileContents(const FileEntry *FE, const 
SourceManager &SM) {
 } // namespace
 
 bool isSelfContainedHeader(const FileEntry *FE, const SourceManager &SM,
-   HeaderSearch &HeaderInfo) {
+   const HeaderSearch &HeaderInfo) {
   assert(FE);
   if (!HeaderInfo.isFileMultipleIncludeGuarded(FE) &&
   !HeaderInfo.hasFileBeenImported(FE) &&



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


[PATCH] D151088: [flang][hlfir] Separate -emit-fir and -emit-hlfir for flang-new

2023-06-01 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a comment.

Thanks for the updates, LGTM!




Comment at: flang/test/HLFIR/flang-experimental-hlfir-flag.f90:7-12
+! | Action  | -flang-experimental-hlfir? | Result  
|
+! | === | == | === 
|
+! | -emit-hlfir | N  | Outputs HLFIR   
|
+! | -emit-hlfir | Y  | Outputs HLFIR   
|
+! | -emit-fir   | N  | Outputs FIR, using old lowering 
|
+! | -emit-fir   | Y  | Outputs FIR, lowering via HLFIR 
|

This comment is pure gold!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151088

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


[PATCH] D151837: [Clang][Parser] Accept GNU attributes preceding C++ style attributes on templates

2023-06-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This needs a release note, otherwise LGTM!


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

https://reviews.llvm.org/D151837

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527392.
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Add debug statements for windows debugging.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,215 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/StringRef.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = "bar.h;foo/qux.h;baz/qux;vector";
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {"foo/qux.h", ""},
+   {"baz/qux/qux.h", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{"baz.h;foo/qux.h"};
+  std::vector Errors;
+  EXPECT_EQ(PreCode, runCheckOnCode(
+ PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+ {{"bar.h", R"(#pragma once
+  #include "baz.h"
+  #include "foo/qux.h"
+  int bar();
+   )"},
+  {"baz.h", R"(#pragma once
+  int baz();
+   )"},
+ 

[clang-tools-extra] 7de5412 - [include-cleaner] NFC, use const HeaderSearch when possible.

2023-06-01 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-01T15:26:19+02:00
New Revision: 7de541235f24e53af95d481df2bf8b15f6656ad3

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

LOG: [include-cleaner] NFC, use const HeaderSearch when possible.

Added: 


Modified: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
clang-tools-extra/include-cleaner/lib/Record.cpp

Removed: 




diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
index 66916a52046cb..6d764c65a11b2 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -67,7 +67,7 @@ struct AnalysisResults {
 AnalysisResults analyze(llvm::ArrayRef ASTRoots,
 llvm::ArrayRef MacroRefs,
 const Includes &I, const PragmaIncludes *PI,
-const SourceManager &SM, HeaderSearch &HS);
+const SourceManager &SM, const HeaderSearch &HS);
 
 /// Removes unused includes and inserts missing ones in the main file.
 /// Returns the modified main-file code.
@@ -75,7 +75,7 @@ AnalysisResults analyze(llvm::ArrayRef ASTRoots,
 std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
-std::string spellHeader(const Header &H, HeaderSearch &HS,
+std::string spellHeader(const Header &H, const HeaderSearch &HS,
 const FileEntry *Main);
 
 /// Gets all the providers for a symbol by traversing each location.

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 84f1f4cc2cf54..bf50e064e9811 100644
--- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -53,7 +53,7 @@ void walkUsed(llvm::ArrayRef ASTRoots,
   }
 }
 
-std::string spellHeader(const Header &H, HeaderSearch &HS,
+std::string spellHeader(const Header &H, const HeaderSearch &HS,
 const FileEntry *Main) {
   switch (H.kind()) {
   case Header::Physical: {
@@ -73,7 +73,7 @@ std::string spellHeader(const Header &H, HeaderSearch &HS,
 AnalysisResults analyze(llvm::ArrayRef ASTRoots,
 llvm::ArrayRef MacroRefs,
 const Includes &Inc, const PragmaIncludes *PI,
-const SourceManager &SM, HeaderSearch &HS) {
+const SourceManager &SM, const HeaderSearch &HS) {
   const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID());
   llvm::DenseSet Used;
   llvm::StringSet<> Missing;

diff  --git a/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h 
b/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
index 6bfed91b584b3..cd796c2da7b80 100644
--- a/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
+++ b/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h
@@ -63,7 +63,7 @@ std::vector> locateSymbol(const Symbol 
&S);
 void writeHTMLReport(FileID File, const Includes &,
  llvm::ArrayRef Roots,
  llvm::ArrayRef MacroRefs, ASTContext 
&Ctx,
- HeaderSearch &HS, PragmaIncludes *PI,
+ const HeaderSearch &HS, PragmaIncludes *PI,
  llvm::raw_ostream &OS);
 
 } // namespace include_cleaner

diff  --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp 
b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
index c1d1982d4f487..65b82973c4290 100644
--- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
+++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp
@@ -134,7 +134,7 @@ class Reporter {
   llvm::raw_ostream &OS;
   const ASTContext &Ctx;
   const SourceManager &SM;
-  HeaderSearch &HS;
+  const HeaderSearch &HS;
   const include_cleaner::Includes &Includes;
   const PragmaIncludes *PI;
   FileID MainFile;
@@ -208,7 +208,7 @@ class Reporter {
   }
 
 public:
-  Reporter(llvm::raw_ostream &OS, ASTContext &Ctx, HeaderSearch &HS,
+  Reporter(llvm::raw_ostream &OS, ASTContext &Ctx, const HeaderSearch &HS,
const include_cleaner::Includes &Includes, const PragmaIncludes *PI,
FileID MainFile)
   : OS(OS), Ctx(Ctx), SM(Ctx.getSourceManager()), HS(HS),
@@ -513,7 +513,7 @@ class Reporter {
 void writeHTMLReport(FileID File, const include_cleaner::Includes &Includes,
  llvm::ArrayRef Roots

[PATCH] D150670: [InstCombine] Disable generation of fshl/fshr for rotates

2023-06-01 Thread Paulo Matos via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9485d983ac0c: [InstCombine] Disable generation of fshl/fshr 
for rotates (authored by pmatos).

Changed prior to commit:
  https://reviews.llvm.org/D150670?vs=527326&id=527395#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150670

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  llvm/test/Transforms/InstCombine/fsh.ll


Index: llvm/test/Transforms/InstCombine/fsh.ll
===
--- llvm/test/Transforms/InstCombine/fsh.ll
+++ llvm/test/Transforms/InstCombine/fsh.ll
@@ -440,12 +440,10 @@
   ret <2 x i32> %r
 }
 
-; TODO: Don't let SimplifyDemandedBits split up a rotate - keep the same 
operand.
-
 define i32 @rotl_common_demanded(i32 %a0) {
 ; CHECK-LABEL: @rotl_common_demanded(
 ; CHECK-NEXT:[[X:%.*]] = xor i32 [[A0:%.*]], 2
-; CHECK-NEXT:[[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X]], i32 [[A0]], 
i32 8)
+; CHECK-NEXT:[[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X]], i32 [[X]], i32 
8)
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %x = xor i32 %a0, 2
@@ -456,7 +454,7 @@
 define i33 @rotr_common_demanded(i33 %a0) {
 ; CHECK-LABEL: @rotr_common_demanded(
 ; CHECK-NEXT:[[X:%.*]] = xor i33 [[A0:%.*]], 2
-; CHECK-NEXT:[[R:%.*]] = call i33 @llvm.fshl.i33(i33 [[X]], i33 [[A0]], 
i33 25)
+; CHECK-NEXT:[[R:%.*]] = call i33 @llvm.fshl.i33(i33 [[X]], i33 [[X]], i33 
25)
 ; CHECK-NEXT:ret i33 [[R]]
 ;
   %x = xor i33 %a0, 2
@@ -704,6 +702,26 @@
   ret i32 %t3
 }
 
+define i32 @fsh_andconst_rotate(i32 %a) {
+; CHECK-LABEL: @fsh_andconst_rotate(
+; CHECK-NEXT:[[T2:%.*]] = lshr i32 [[A:%.*]], 16
+; CHECK-NEXT:ret i32 [[T2]]
+;
+  %t1 = and i32 %a, 4294901760 ; 0x
+  %t2 = call i32 @llvm.fshl.i32(i32 %t1, i32 %t1, i32 16)
+  ret i32 %t2
+}
+
+define i32 @fsh_orconst_rotate(i32 %a) {
+; CHECK-LABEL: @fsh_orconst_rotate(
+; CHECK-NEXT:[[T2:%.*]] = call i32 @llvm.fshl.i32(i32 [[A:%.*]], i32 
-268435456, i32 4)
+; CHECK-NEXT:ret i32 [[T2]]
+;
+  %t1 = or i32 %a, 4026531840 ; 0xf000
+  %t2 = call i32 @llvm.fshl.i32(i32 %t1, i32 %t1, i32 4)
+  ret i32 %t2
+}
+
 define <2 x i31> @fshr_mask_args_same_vector(<2 x i31> %a) {
 ; CHECK-LABEL: @fshr_mask_args_same_vector(
 ; CHECK-NEXT:[[T3:%.*]] = shl <2 x i31> [[A:%.*]], 
Index: llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -912,9 +912,26 @@
 
 APInt DemandedMaskLHS(DemandedMask.lshr(ShiftAmt));
 APInt DemandedMaskRHS(DemandedMask.shl(BitWidth - ShiftAmt));
-if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown, Depth + 1) ||
-SimplifyDemandedBits(I, 1, DemandedMaskRHS, RHSKnown, Depth + 1))
-  return I;
+if (I->getOperand(0) != I->getOperand(1)) {
+  if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown,
+   Depth + 1) ||
+  SimplifyDemandedBits(I, 1, DemandedMaskRHS, RHSKnown, Depth + 1))
+return I;
+} else { // fshl is a rotate
+// Avoid converting rotate into funnel shift. 
+// Only simplify if one operand is constant.
+  KnownBits LHSKnown = computeKnownBits(I->getOperand(0), Depth + 1, 
I);
+  if (DemandedMaskLHS.isSubsetOf(LHSKnown.Zero | LHSKnown.One)) {
+replaceOperand(*I, 0, Constant::getIntegerValue(VTy, 
LHSKnown.One));
+return I;
+  }
+
+  KnownBits RHSKnown = computeKnownBits(I->getOperand(1), Depth + 1, 
I);
+  if (DemandedMaskRHS.isSubsetOf(RHSKnown.Zero | RHSKnown.One)) {
+replaceOperand(*I, 1, Constant::getIntegerValue(VTy, 
RHSKnown.One));
+return I;
+  }
+}
 
 Known.Zero = LHSKnown.Zero.shl(ShiftAmt) |
  RHSKnown.Zero.lshr(BitWidth - ShiftAmt);


Index: llvm/test/Transforms/InstCombine/fsh.ll
===
--- llvm/test/Transforms/InstCombine/fsh.ll
+++ llvm/test/Transforms/InstCombine/fsh.ll
@@ -440,12 +440,10 @@
   ret <2 x i32> %r
 }
 
-; TODO: Don't let SimplifyDemandedBits split up a rotate - keep the same operand.
-
 define i32 @rotl_common_demanded(i32 %a0) {
 ; CHECK-LABEL: @rotl_common_demanded(
 ; CHECK-NEXT:[[X:%.*]] = xor i32 [[A0:%.*]], 2
-; CHECK-NEXT:[[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X]], i32 [[A0]], i32 8)
+; CHECK-NEXT:[[R:%.*]] = call i32 @llvm.fshl.i32(i32 [[X]], i32 [[X]], i32 8)
 ; CHECK-NEXT:ret i32 [[R]]
 ;
   %x = xor i32 %a0, 2
@@ -456,7 +454,7 @@
 define i33 @rotr_common_demanded(i33 %a0) {
 ; CHECK-LABEL: @rotr_common_demanded(
 ; CHECK-NEXT:[[X:%.*]] = xo

[PATCH] D150670: [InstCombine] Disable generation of fshl/fshr for rotates

2023-06-01 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

Landed, thanks for your patience. Lets hope it sticks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150670

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


[PATCH] D151595: [BOLT][CMake] Redo the build and install targets

2023-06-01 Thread Amir Ayupov via Phabricator via cfe-commits
Amir added a comment.

Merged the PR. Please reland


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151595

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


[clang-tools-extra] ad0543f - [clangd] NFC, use const HeaderSearch when possible.

2023-06-01 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-06-01T15:35:57+02:00
New Revision: ad0543f4ea82ec41c5e854af65758fa8d92d5553

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

LOG: [clangd] NFC, use const HeaderSearch when possible.

Added: 


Modified: 
clang-tools-extra/clangd/index/SymbolCollector.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index a2f8cd2a0cdaf..d1840ff34bfec 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -298,7 +298,7 @@ class SymbolCollector::HeaderFileURICache {
   // importing the header.
   std::optional getFrameworkUmbrellaSpelling(
   llvm::StringRef Framework, SrcMgr::CharacteristicKind HeadersDirKind,
-  HeaderSearch &HS, FrameworkHeaderPath &HeaderPath) {
+  const HeaderSearch &HS, FrameworkHeaderPath &HeaderPath) {
 auto Res = CacheFrameworkToUmbrellaHeaderSpelling.try_emplace(Framework);
 auto *CachedSpelling = &Res.first->second;
 if (!Res.second) {



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


[PATCH] D150221: Add option -fkeep-static-variables to emit all static variables

2023-06-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This seems a little short on tests as well, are there any semantic implications 
here that should be validated?  How does this work with function-local statics? 
 What does the behavior look like in C?

Else, I think @rjmccall felt the strongest about the semantics/design here, so 
I'd like to see him be ok with them before accepting this.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2201-2210
+  if ((CodeGenOpts.KeepStaticConsts || CodeGenOpts.KeepStaticVariables) && D &&
+  isa(D)) {
 const auto *VD = cast(D);
-if (VD->getType().isConstQualified() &&
-VD->getStorageDuration() == SD_Static)
-  addUsedOrCompilerUsedGlobal(GV);
+if (VD->getStorageDuration() == SD_Static) {
+  if (CodeGenOpts.KeepStaticVariables)
+addUsedOrCompilerUsedGlobal(GV);
+  else if (CodeGenOpts.KeepStaticConsts && 
VD->getType().isConstQualified())

hubert.reinterpretcast wrote:
> aaron.ballman wrote:
> > Reformatted with whatever clang-format does for that, as I doubt I have the 
> > formatting correct.
> @qianzhen, I don't think the suggestion was applied/applied correctly.
> 
> There should not be an `isa` followed by `dyn_cast`. That said, I think 
> `dyn_cast_or_null` is perhaps appropriate instead of plain `dyn_cast`. 
> Additionally, `VD` being non-null should be part of the condition.
Note `dyn_cast_or_null` is deprecated, but making the condition:

`if (const auto *VD = dyn_cast_if_present(D))`

is probably the best way to simplify this here.  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150221

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


[clang] d4f0f17 - [z/OS] Disable pr59765-modules-global-ctor-dtor.cppm on z/OS to make it unsupported.

2023-06-01 Thread Zibi Sarbinowski via cfe-commits

Author: Zibi Sarbinowski
Date: 2023-06-01T08:44:30-05:00
New Revision: d4f0f171d7f890abe913023e4439018fd74aa175

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

LOG: [z/OS] Disable pr59765-modules-global-ctor-dtor.cppm on z/OS to make it 
unsupported.

[z/OS] Disable pr59765-modules-global-ctor-dtor.cppm

Reviewed By: SeanP

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

Added: 


Modified: 
clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm

Removed: 




diff  --git a/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm 
b/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
index 1a9384bf0bc9a..9956348f87ff4 100644
--- a/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
+++ b/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
@@ -1,9 +1,9 @@
 // https://github.com/llvm/llvm-project/issues/59765
 // FIXME: Since the signature of the constructors/destructors is
 // 
diff erent in 
diff erent targets. The current CHECK can't work
-// well when targeting or running on AIX.
+// well when targeting or running on AIX and z/OS.
 // It would be better to add the corresponding test for other test.
-// UNSUPPORTED: system-aix
+// UNSUPPORTED: system-zos, system-aix
 //
 // RUN: rm -rf %t
 // RUN: mkdir %t



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


[PATCH] D151828: [z/OS] Disable pr59765-modules-global-ctor-dtor.cppm on z/OS to make it unsupported.

2023-06-01 Thread Zibi Sarbino via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd4f0f171d7f8: [z/OS] Disable 
pr59765-modules-global-ctor-dtor.cppm on z/OS to make it… (authored by zibi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151828

Files:
  clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm


Index: clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
===
--- clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
+++ clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
@@ -1,9 +1,9 @@
 // https://github.com/llvm/llvm-project/issues/59765
 // FIXME: Since the signature of the constructors/destructors is
 // different in different targets. The current CHECK can't work
-// well when targeting or running on AIX.
+// well when targeting or running on AIX and z/OS.
 // It would be better to add the corresponding test for other test.
-// UNSUPPORTED: system-aix
+// UNSUPPORTED: system-zos, system-aix
 //
 // RUN: rm -rf %t
 // RUN: mkdir %t


Index: clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
===
--- clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
+++ clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
@@ -1,9 +1,9 @@
 // https://github.com/llvm/llvm-project/issues/59765
 // FIXME: Since the signature of the constructors/destructors is
 // different in different targets. The current CHECK can't work
-// well when targeting or running on AIX.
+// well when targeting or running on AIX and z/OS.
 // It would be better to add the corresponding test for other test.
-// UNSUPPORTED: system-aix
+// UNSUPPORTED: system-zos, system-aix
 //
 // RUN: rm -rf %t
 // RUN: mkdir %t
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527402.
VitaNuo added a comment.

Remove debug statements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,215 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/StringRef.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = "bar.h;foo/qux.h;baz/qux;vector";
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {"foo/qux.h", ""},
+   {"baz/qux/qux.h", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{"baz.h;foo/qux.h"};
+  std::vector Errors;
+  EXPECT_EQ(PreCode, runCheckOnCode(
+ PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+ {{"bar.h", R"(#pragma once
+  #include "baz.h"
+  #include "foo/qux.h"
+  int bar();
+   )"},
+  {"baz.h", R"(#pragma once
+  int baz();
+   )"},
+  {"foo/qux.h", R"(#pragma once
+ 

[PATCH] D149867: [M68k] Add Clang support for the new M68k_RTD CC

2023-06-01 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz added a comment.

In D149867#4386271 , @jrtc27 wrote:

> I disagree. Being experimental doesn't mean you should do the wrong thing. 
> Reusing stdcall in the frontend is ugly, pollutes non-m68k code paths (doing 
> your own thing _avoids_ that and makes the experimental backend get out of 
> the way, even) and introduces a bug where you can write garbage code and have 
> it compile rather than be rejected like it should be.

Maybe we can get the TLS stuff merged first before dealing with this more 
complex change?


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

https://reviews.llvm.org/D149867

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


[PATCH] D151837: [Clang][Parser] Accept GNU attributes preceding C++ style attributes on templates

2023-06-01 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews updated this revision to Diff 527406.
eandrews added a comment.

Thanks for the review! I've added a release note.


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

https://reviews.llvm.org/D151837

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Parser/attr-order.cpp


Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // 
expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // 
expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // 
expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -210,7 +210,15 @@
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(prefixAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  // GNU attributes are applied to the declaration specification while the
+  // standard attributes are applied to the declaration.  We parse the two
+  // attribute sets into different containters so we can apply them during
+  // the regular parsing process.
+  while (MaybeParseCXX11Attributes(prefixAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.is(tok::kw_using)) {
 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, 
TemplateInfo, DeclEnd,
@@ -223,6 +231,9 @@
   // Parse the declaration specifiers, stealing any diagnostics from
   // the template parameters.
   ParsingDeclSpec DS(*this, &DiagsFromTParams);
+  DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
+  DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
+  DS.takeAttributesFrom(DeclSpecAttrs);
 
   ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
  getDeclSpecContextFromDeclaratorContext(Context));
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -411,6 +411,9 @@
   structs, unions, and scoped enums) were not properly ignored, resulting in
   misleading warning messages. Now, such attribute annotations are correctly
   ignored. (`#61660 `_)
+- GNU attributes preceding C++ style attributes on templates were not properly
+  handled, resulting in compilation error. This has been corrected to match the
+  behaviour exhibited by GCC.
 
 Bug Fixes to C++ Support
 


Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok
Index: clang/lib/Parse/ParseTemplate.cpp

[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-06-01 Thread Fahad Nayyar via Phabricator via cfe-commits
fahadnayyar updated this revision to Diff 527407.
fahadnayyar added a comment.

Rebasing to latest main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/darwin-header-search-libcxx.cpp
  clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp

Index: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
===
--- clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
+++ clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
@@ -1,63 +1,48 @@
 // UNSUPPORTED: system-windows
 
-// General tests that the header search paths for libc++ detected by the driver
-// and passed to CC1 are correct on Darwin platforms.
+// Tests to check that we pass -L /bin/../lib/ to the linker to prioritize the toolchain's libc++.dylib over system's libc++.tbd in all cases.
 
 // Check without a sysroot and without headers alongside the installation
-// (no include path should be added, and no warning or error).
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
-// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-NONE %s
-// CHECK-LIBCXX-NONE: "-cc1"
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-2 %s
 
 // Check with only headers alongside the installation (those should be used).
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
 // RUN: --sysroot="" \
 // RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
-// RUN:   --check-prefix=CHECK-LIBCXX-TOOLCHAIN-1 %s
-// CHECK-LIBCXX-TOOLCHAIN-1: "-cc1"
-// CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
-// CHECK-LIBCXX-TOOLCHAIN-1-NOT: "-internal-isystem" "/usr/include/c++/v1"
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_no_libcxx \
 // RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
 // RUN:   -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \
-// RUN:   --check-prefix=CHECK-LIBCXX-TOOLCHAIN-2 %s
-// CHECK-LIBCXX-TOOLCHAIN-2: "-cc1"
-// CHECK-LIBCXX-TOOLCHAIN-2: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
-// CHECK-LIBCXX-TOOLCHAIN-2-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
 
 // Check with only headers in the sysroot (those should be used).
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
-// RUN:   --check-prefix=CHECK-LIBCXX-SYSROOT-1 %s
-// CHECK-LIBCXX-SYSROOT-1: "-cc1"
-// CHECK-LIBCXX-SYSROOT-1: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
-// CHECK-LIBCXX-SYSROOT-1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
 
 // Check with both headers in the sysroot and headers alongside the installation
-// (the headers in the toolchain should be preferred over the  headers).
-// Ensure that both -isysroot and --sysroot work, and that isysroot has precedence
-// over --sysroot.
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
@@ -65,9 +50,9 @@
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
-// RUN:   --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -std

[PATCH] D150746: [CodeGen]Translating pointer arguments can require an address space cast

2023-06-01 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1630-1632
+LangAS AS = CGM.GetGlobalVarAddressSpace(nullptr);
+QualType Q = Context.getAddrSpaceQualType(Context.VoidPtrTy, AS);
+QualType T = Context.getPointerType(Q);

Does it worth extracting the code as Context.getVTTType() since it is used at 
three locations. Since VTT seems to be immutable, in case we want to put it in 
constant addr space in the future, it will make things easier.


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

https://reviews.llvm.org/D150746

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


[PATCH] D151837: [Clang][Parser] Accept GNU attributes preceding C++ style attributes on templates

2023-06-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

1 suggestion, otherwise LGTM.




Comment at: clang/docs/ReleaseNotes.rst:416
+  handled, resulting in compilation error. This has been corrected to match the
+  behaviour exhibited by GCC.
 




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

https://reviews.llvm.org/D151837

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


[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527412.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,98 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+std::string
+appendPathSystemIndependent(std::initializer_list Segments,
+bool IsAbsolute) {
+  llvm::StringRef Sep = llvm::sys::path::get_separator();
+  llvm::SmallString<32> Path;
+  if (IsAbsolute)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Sep);
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Path, llvm::sys::path::Style::native, Segment);
+  return std::string{Path};
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath("foo/baz.h")] = "";
+  Inputs.ExtraFiles["/foo/bar.h"] = "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  appendPathSystemIndependent({"foo", "baz.h"}, false),
+  spellHeader({Header{*FM.getFile(testPath("foo/baz.h"))}, HS, MainFile}));
+  EXPECT_EQ("\"/foo/bar.h\"",
+spellHeader({Header{*FM.getFile("/foo/bar.h")}, HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
\ No newline at end of file
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
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
=

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked 4 inline comments as done.
VitaNuo added a comment.

Thanks for the comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

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


[PATCH] D150988: [clang][Darwin] Error out when missing requested libarclite library

2023-06-01 Thread Fahad Nayyar via Phabricator via cfe-commits
fahadnayyar accepted this revision.
fahadnayyar added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150988

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


[PATCH] D151595: [BOLT][CMake] Redo the build and install targets

2023-06-01 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf3269a94e729: [BOLT][CMake] Redo the build and install 
targets (authored by phosek).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151595

Files:
  bolt/CMakeLists.txt
  bolt/cmake/modules/AddBOLT.cmake
  bolt/test/CMakeLists.txt
  bolt/tools/CMakeLists.txt
  bolt/tools/bat-dump/CMakeLists.txt
  bolt/tools/driver/CMakeLists.txt
  bolt/tools/heatmap/CMakeLists.txt
  bolt/tools/merge-fdata/CMakeLists.txt
  clang/cmake/caches/Fuchsia-stage2.cmake
  llvm/cmake/modules/AddLLVM.cmake

Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -2121,7 +2121,7 @@
   if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
 add_llvm_install_targets(install-${name}
  DEPENDS ${name} ${dest}
- COMPONENT ${name}
+ COMPONENT ${component}
  SYMLINK ${dest})
   endif()
 endfunction()
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -6,7 +6,7 @@
 
 set(PACKAGE_VENDOR Fuchsia CACHE STRING "")
 
-set(_FUCHSIA_ENABLE_PROJECTS "clang;clang-tools-extra;lld;llvm;polly")
+set(_FUCHSIA_ENABLE_PROJECTS "bolt;clang;clang-tools-extra;lld;llvm;polly")
 set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
 
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
@@ -329,6 +329,7 @@
   CACHE STRING "")
 
 set(LLVM_Toolchain_DISTRIBUTION_COMPONENTS
+  bolt
   clang
   lld
   clang-apply-replacements
Index: bolt/tools/merge-fdata/CMakeLists.txt
===
--- bolt/tools/merge-fdata/CMakeLists.txt
+++ bolt/tools/merge-fdata/CMakeLists.txt
@@ -8,14 +8,8 @@
   DEPENDS
   intrinsics_gen
 )
-set_target_properties(merge-fdata PROPERTIES FOLDER "BOLT")
 
 add_dependencies(bolt merge-fdata)
-install(PROGRAMS
-  ${CMAKE_BINARY_DIR}/bin/merge-fdata
-  DESTINATION ${CMAKE_INSTALL_BINDIR}
-  COMPONENT bolt
-  )
 
 # Emit relocations for BOLT meta test (bolt/test/runtime/meta-merge-fdata.test)
 if (BOLT_INCLUDE_TESTS AND UNIX AND NOT APPLE)
Index: bolt/tools/heatmap/CMakeLists.txt
===
--- bolt/tools/heatmap/CMakeLists.txt
+++ bolt/tools/heatmap/CMakeLists.txt
@@ -17,4 +17,4 @@
   LLVMBOLTUtils
   )
 
-set_target_properties(llvm-bolt-heatmap PROPERTIES FOLDER "BOLT")
+add_dependencies(bolt llvm-bolt-heatmap)
Index: bolt/tools/driver/CMakeLists.txt
===
--- bolt/tools/driver/CMakeLists.txt
+++ bolt/tools/driver/CMakeLists.txt
@@ -30,22 +30,6 @@
 add_bolt_tool_symlink(perf2bolt llvm-bolt)
 add_bolt_tool_symlink(llvm-boltdiff llvm-bolt)
 
-set(BOLT_DEPENDS
-  llvm-bolt
-  perf2bolt
-  llvm-boltdiff
-  )
-
-add_custom_target(bolt DEPENDS ${BOLT_DEPENDS})
-install(PROGRAMS
-  ${CMAKE_BINARY_DIR}/bin/llvm-bolt
-  ${CMAKE_BINARY_DIR}/bin/perf2bolt
-  ${CMAKE_BINARY_DIR}/bin/llvm-boltdiff
-  DESTINATION ${CMAKE_INSTALL_BINDIR}
-  COMPONENT bolt
-  )
-add_llvm_install_targets(install-bolt DEPENDS bolt COMPONENT bolt)
-set_target_properties(bolt PROPERTIES FOLDER "BOLT")
-set_target_properties(install-bolt PROPERTIES FOLDER "BOLT")
+add_dependencies(bolt llvm-bolt)
 
-include_directories( ${BOLT_SOURCE_DIR}/lib )
+include_directories(${BOLT_SOURCE_DIR}/lib)
Index: bolt/tools/bat-dump/CMakeLists.txt
===
--- bolt/tools/bat-dump/CMakeLists.txt
+++ bolt/tools/bat-dump/CMakeLists.txt
@@ -3,7 +3,7 @@
   Support
   )
 
-add_llvm_tool(llvm-bat-dump
+add_bolt_executable(llvm-bat-dump
   bat-dump.cpp
 
   DISABLE_LLVM_LINK_LLVM_DYLIB
@@ -13,5 +13,3 @@
   PRIVATE
   LLVMBOLTProfile
   )
-
-set_target_properties(llvm-bat-dump PROPERTIES FOLDER "BOLT")
Index: bolt/tools/CMakeLists.txt
===
--- bolt/tools/CMakeLists.txt
+++ bolt/tools/CMakeLists.txt
@@ -2,16 +2,6 @@
 "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
 mark_as_advanced(BOLT_TOOLS_INSTALL_DIR)
 
-# Move these macros to AddBolt if such a CMake module is ever created.
-
-macro(add_bolt_tool name)
-  llvm_add_tool(BOLT ${ARGV})
-endmacro()
-
-macro(add_bolt_tool_symlink name)
-  llvm_add_tool_symlink(BOLT ${ARGV})
-endmacro()
-
 add_subdirectory(driver)
 add_subdirectory(llvm-bolt-fuzzer)
 add_subdirectory(bat-dump)
Index: bolt/test/CMakeLists.txt
===
--- bolt/test/CMakeLists.txt
+++ bolt/test/CMakeLists.txt
@@ -37,7 +37,6 @@
   lld
  

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527420.
VitaNuo added a comment.

Remove extra path handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,86 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath("foo/baz.h")] = "";
+  Inputs.ExtraFiles["/foo/bar.h"] = "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  "foo/baz.h",
+  spellHeader({Header{*FM.getFile(testPath("foo/baz.h"))}, HS, MainFile}));
+  EXPECT_EQ("\"/foo/bar.h\"",
+spellHeader({Header{*FM.getFile("/foo/bar.h")}, HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
\ No newline at end of file
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
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -8,10 +8,12 @@
 
 #include "clang-include-cleaner/Analysis.h"
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/IncludeSpeller.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceManager.h"
 #incl

[clang] 2c3c190 - [Clang] Convert some tests to opaque pointers (NFC)

2023-06-01 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-06-01T17:04:48+02:00
New Revision: 2c3c1902a347a2a6d681e8dbe410a2dfe78389bb

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

LOG: [Clang] Convert some tests to opaque pointers (NFC)

Added: 


Modified: 
clang/test/CodeGenObjCXX/property-dot-reference.mm
clang/test/CodeGenObjCXX/property-lvalue-lambda.mm
clang/test/CodeGenObjCXX/property-object-conditional-exp.mm
clang/test/CodeGenObjCXX/property-object-reference-1.mm
clang/test/CodeGenObjCXX/property-object-reference.mm
clang/test/CodeGenObjCXX/property-objects.mm
clang/test/CodeGenObjCXX/property-reference.mm

Removed: 




diff  --git a/clang/test/CodeGenObjCXX/property-dot-reference.mm 
b/clang/test/CodeGenObjCXX/property-dot-reference.mm
index 126676d4f0346..9fb35858219f8 100644
--- a/clang/test/CodeGenObjCXX/property-dot-reference.mm
+++ b/clang/test/CodeGenObjCXX/property-dot-reference.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin10 
-emit-llvm -fexceptions -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -o - 
%s | FileCheck %s
 // rdar://8409336
 
 struct TFENode {
@@ -11,8 +11,8 @@ @interface TNodeIconAndNameCell
 
 @implementation TNodeIconAndNameCell 
 - (const TFENode&) node {
-// CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) 
%struct.TFENode* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
-// CHECK-NEXT: call void @_ZNK7TFENode6GetURLEv(%struct.TFENode* {{[^,]*}} 
%{{.*}})
+// CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) 
ptr @objc_msgSend
+// CHECK-NEXT: call void @_ZNK7TFENode6GetURLEv(ptr {{[^,]*}} %{{.*}})
self.node.GetURL();
 }  // expected-warning {{non-void function does not return a value}}
 @end
@@ -27,12 +27,12 @@ @interface A
 - (const X&) target;
 @end
 void f1(A *a) {
-// CHECK: [[PRP:%.*]] = call noundef nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) %struct.X* bitcast (i8* (i8*, i8*, ...)* 
@objc_msgSend
-// CHECK-NEXT:call void @_Z2f0RK1X(%struct.X* noundef nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) [[PRP]])
+// CHECK: [[PRP:%.*]] = call noundef nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) ptr @objc_msgSend
+// CHECK-NEXT:call void @_Z2f0RK1X(ptr noundef nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) [[PRP]])
   f0(a.target);
 
-// CHECK: [[MSG:%.*]] = call noundef nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) %struct.X* bitcast (i8* (i8*, i8*, ...)* 
@objc_msgSend
-// CHECK-NEXT:call void @_Z2f0RK1X(%struct.X* noundef nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) [[MSG]])
+// CHECK: [[MSG:%.*]] = call noundef nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) ptr @objc_msgSend
+// CHECK-NEXT:call void @_Z2f0RK1X(ptr noundef nonnull align {{[0-9]+}} 
dereferenceable({{[0-9]+}}) [[MSG]])
   f0([a target]);
 }
 
@@ -51,12 +51,12 @@ void test2() {
 void(obj.myGetter);
 }
 // CHECK-LABEL: define{{.*}} void @_Z5test2v()
-// CHECK: call noundef i32 bitcast
-// CHECK: call noundef double bitcast
-// CHECK: call noundef i32 bitcast
-// CHECK: call noundef double bitcast
-// CHECK: call noundef i32 bitcast
-// CHECK: call noundef double bitcast
+// CHECK: call noundef i32
+// CHECK: call noundef double
+// CHECK: call noundef i32
+// CHECK: call noundef double
+// CHECK: call noundef i32
+// CHECK: call noundef double
 
 // PR8751
 int test3(Test2 *obj) { return obj.myProperty; }

diff  --git a/clang/test/CodeGenObjCXX/property-lvalue-lambda.mm 
b/clang/test/CodeGenObjCXX/property-lvalue-lambda.mm
index 1253ae6d45b04..ddb0bf5570926 100644
--- a/clang/test/CodeGenObjCXX/property-lvalue-lambda.mm
+++ b/clang/test/CodeGenObjCXX/property-lvalue-lambda.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -no-opaque-pointers -no-enable-noundef-analysis -fblocks 
-disable-llvm-passes -triple x86_64-apple-darwin10 -std=c++17 -emit-llvm -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -no-enable-noundef-analysis -fblocks -disable-llvm-passes 
-triple x86_64-apple-darwin10 -std=c++17 -emit-llvm -o - %s | FileCheck %s
 
 typedef void (^blk_t)();
 typedef void (*fnptr_t)();
@@ -19,12 +19,12 @@ void t1(X *x) {
   // Check that we call lambda.operator blk_t(), and that we send that result 
to
   // the setter.
 
-  // CHECK: [[CALL:%.*]] = call void ()* 
@"_ZZ2t1P1XENK3$_0cvU13block_pointerFvvEEv"
-  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} void ()* [[CALL]])
+  // CHECK: [[CALL:%.*]] = call ptr @"_ZZ2t1P1XENK3$_0cvU13block_pointerFvvEEv"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} ptr [[CALL]])
   x.blk = [] {};
 
-  // CHECK: [[CALL2:%.*]] = call void ()* @"_ZZ2t1P1XENK3$_1cvPFvvEEv"
-  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} void ()* [[C

[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-01 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10412
+  CGF.Builder.GetInsertPoint());
+  llvm::OpenMPIRBuilder::LocationDescription ompLoc(CodeGenIP);
 

capitalize here?



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:10424
+  llvm::Value *IfCondVal = nullptr;
+  bool CondConstant;
+  if (IfCond) {

I think this can (and should be?) moved into the if in the following line as it 
is not used outside that scope


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150860

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


[clang] 5952664 - [OpenCL] Add CLK_UNORM_INT_101010_2 channel type

2023-06-01 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-06-01T16:21:54+01:00
New Revision: 595266456a3067f522081d6d8069df2a98adfa16

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

LOG: [OpenCL] Add CLK_UNORM_INT_101010_2 channel type

This new channel data type was added in OpenCL C 3.0.

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index fad2f9c0272bf..af3deae892c7c 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -474,6 +474,9 @@ typedef enum memory_order
 #define CLK_HALF_FLOAT0x10DD
 #define CLK_FLOAT 0x10DE
 #define CLK_UNORM_INT24   0x10DF
+#if __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+#define CLK_UNORM_INT_101010_2 0x10E0
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
 
 // Channel order, numbering must be aligned with cl_channel_order in cl.h
 //



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


[PATCH] D151837: [Clang][Parser] Accept GNU attributes preceding C++ style attributes on templates

2023-06-01 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:416
+  handled, resulting in compilation error. This has been corrected to match the
+  behaviour exhibited by GCC.
 

erichkeane wrote:
> 
I'll make this change when I commit the patch. Thanks!


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

https://reviews.llvm.org/D151837

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


[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-06-01 Thread Louis Dionne via Phabricator via cfe-commits
ldionne requested changes to this revision.
ldionne added inline comments.
This revision now requires changes to proceed.



Comment at: clang/test/Driver/darwin-header-search-libcxx.cpp:119
 // RUN: -nostdinc++ \
-// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
+// RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \

Is this change really needed anymore? Why?



Comment at: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp:11
 // RUN: -ccc-install-dir 
%S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
-// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-NONE %s
-// CHECK-LIBCXX-NONE: "-cc1"
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx 
--check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-2 %s
 

I don't see `CHECK-TOOLCHAIN-LIBCXX-LINKING-2` defined anywhere?



Comment at: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp:13
 
 // Check with only headers alongside the installation (those should be used).
 //

Some of these test cases and comments don't make sense for this test -- you 
copy-pasted the test for header search paths and that's fine, but please go 
through it to make sure you make the necessary edits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

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


[PATCH] D151741: [Lex] Only warn on defining or undefining language-defined builtins

2023-06-01 Thread John Brawn via Phabricator via cfe-commits
john.brawn updated this revision to Diff 527432.
john.brawn added a comment.

Put x86 tests in undef-x86.c.


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

https://reviews.llvm.org/D151741

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/undef-x86.c

Index: clang/test/Preprocessor/undef-x86.c
===
--- /dev/null
+++ clang/test/Preprocessor/undef-x86.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple=i386-none-none -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple=i686-none-none -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple=x86_64-none-none -fsyntax-only -verify %s
+
+// Check that we can undefine triple-specific defines without warning
+// expected-no-diagnostics
+#undef __i386
+#undef __i386__
+#undef i386
+#undef __amd64
+#undef __amd64__
+#undef __x86_64
+#undef __x86_64__
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,12 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
+#undef __UINT32_TYPE__
+#undef __UINTPTR_TYPE__
+#undef __UINT64_TYPE__
+#undef __INT64_TYPE__
+#undef __OPTIMIZE__
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@
 MacroName);
 }
 
+static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
+ const MacroInfo *MI,
+ const StringRef MacroName) {
+  // If this is a macro with special handling (like __LINE__) then it's language
+  // defined.
+  if (MI->isBuiltinMacro())
+return true;
+  // Builtin macros are defined in the builtin file
+  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+return false;
+  // C defines macros starting with __STDC, and C++ defines macros starting with
+  // __STDCPP
+  if (MacroName.startswith("__STDC"))
+return true;
+  // C++ defines the __cplusplus macro
+  if (MacroName == "__cplusplus")
+return true;
+  // C++ defines various feature-test macros starting with __cpp
+  if (MacroName.startswith("__cpp"))
+return true;
+  // Anything else isn't language-defined
+  return false;
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {
   const LangOptions &Lang = PP.getLangOpts();
   StringRef Text = II->getName();
@@ -3107,9 +3131,7 @@
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro() ||
-  (SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()) &&
-   !isFeatureTestMacro(MacroNameTok.getIdentifierInfo()->getName(
+  if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3190,11 +3212,8 @@
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
 // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
-// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
-// is an Objective-C builtin macro though.
-if ((MI->isBuiltinMacro() ||
- SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
-!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+// C++ [cpp.predefined]p4, but allow it as an extension.
+if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
   Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
 
 if (MI->isWarnIfUnused())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

2023-06-01 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a reviewer: clang-language-wg.
shafik added a comment.

Adding more reviewers for more visibility.


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

https://reviews.llvm.org/D134334

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


[PATCH] D148474: [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

2023-06-01 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

ping


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

https://reviews.llvm.org/D148474

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


[PATCH] D150746: [CodeGen]Translating pointer arguments can require an address space cast

2023-06-01 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1630-1632
+LangAS AS = CGM.GetGlobalVarAddressSpace(nullptr);
+QualType Q = Context.getAddrSpaceQualType(Context.VoidPtrTy, AS);
+QualType T = Context.getPointerType(Q);

yaxunl wrote:
> Does it worth extracting the code as Context.getVTTType() since it is used at 
> three locations. Since VTT seems to be immutable, in case we want to put it 
> in constant addr space in the future, it will make things easier.
That's not a bad idea. I think it might be profitable to do something like 
`Context.getVTableType()`, since there's actually 2.5 interlinked things here 
(VTT, vtable & vptr), and it makes intuitive to me to base it all around that 
(vptr points to vtbl) etc.


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

https://reviews.llvm.org/D150746

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


[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527435.
VitaNuo added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,86 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath("foo/baz.h")] = "";
+  Inputs.ExtraFiles["/foo/bar.h"] = "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  "foo/baz.h",
+  spellHeader({Header{*FM.getFile(testPath("foo/baz.h"))}, HS, MainFile}));
+  EXPECT_EQ("\"/foo/bar.h\"",
+spellHeader({Header{*FM.getFile("/foo/bar.h")}, HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
\ No newline at end of file
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
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -8,10 +8,12 @@
 
 #include "clang-include-cleaner/Analysis.h"
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/IncludeSpeller.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Fo

[PATCH] D151895: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman.
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/D151895

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,86 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath("foo/baz.h")] = "";
+  Inputs.ExtraFiles["/foo/bar.h"] = "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  "foo/baz.h",
+  spellHeader({Header{*FM.getFile(testPath("foo/baz.h"))}, HS, MainFile}));
+  EXPECT_EQ("\"/foo/bar.h\"",
+spellHeader({Header{*FM.getFile("/foo/bar.h")}, HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
\ No newline at end of file
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
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -8,10 +8,12 @@
 
 #include "clang-include-cleaner/Analysis.h"
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/IncludeSpeller.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/B

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527438.
VitaNuo added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,86 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath("foo/baz.h")] = "";
+  Inputs.ExtraFiles["/foo/bar.h"] = "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  "foo/baz.h",
+  spellHeader({Header{*FM.getFile(testPath("foo/baz.h"))}, HS, MainFile}));
+  EXPECT_EQ("\"/foo/bar.h\"",
+spellHeader({Header{*FM.getFile("/foo/bar.h")}, HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
\ No newline at end of file
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
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -8,10 +8,12 @@
 
 #include "clang-include-cleaner/Analysis.h"
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/IncludeSpeller.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Fo

[PATCH] D151895: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo abandoned this revision.
VitaNuo added a comment.
Herald added a subscriber: ormris.

Created by mistake.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151895

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


[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

2023-06-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

I does think this patch probably makes sense but I agree with Erich that a 
comment is in order.
I'm also wondering whether we can end up in a situation where Tok and 
NextToken() get replaced by a single annotation in which case this would not 
work. I don't think so.


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

https://reviews.llvm.org/D134334

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


[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527446.
VitaNuo added a comment.

Fix windows build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,105 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments,
+bool IsAbsolute) {
+  llvm::SmallString<32> Result;
+  if (IsAbsolute)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native,
+llvm::sys::path::get_separator());
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false))] = "";
+  Inputs.ExtraFiles[appendPathFileSystemIndependent({"foo", "bar.h"}, true)] =
+  "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false),
+  spellHeader({Header{*FM.getFile(testPath(appendPathFileSystemIndependent(
+   {"foo", "baz.h"}, false)))},
+   HS, MainFile}));
+  EXPECT_EQ("\"" + appendPathFileSystemIndependent({"foo", "bar.h"}, true) +
+"\"",
+spellHeader({Header{*FM.getFile(appendPathFileSystemIndependent(
+ {"foo", "bar.h"}, true))},
+ HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
\ No newline at end of file
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-t

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527447.
VitaNuo added a comment.

Add newline at file end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,105 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments,
+bool IsAbsolute) {
+  llvm::SmallString<32> Result;
+  if (IsAbsolute)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native,
+llvm::sys::path::get_separator());
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false))] = "";
+  Inputs.ExtraFiles[appendPathFileSystemIndependent({"foo", "bar.h"}, true)] =
+  "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false),
+  spellHeader({Header{*FM.getFile(testPath(appendPathFileSystemIndependent(
+   {"foo", "baz.h"}, false)))},
+   HS, MainFile}));
+  EXPECT_EQ("\"" + appendPathFileSystemIndependent({"foo", "bar.h"}, true) +
+"\"",
+spellHeader({Header{*FM.getFile(appendPathFileSystemIndependent(
+ {"foo", "bar.h"}, true))},
+ HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cle

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527448.
VitaNuo added a comment.

Add newline at file end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,105 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments,
+bool IsAbsolute) {
+  llvm::SmallString<32> Result;
+  if (IsAbsolute)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native,
+llvm::sys::path::get_separator());
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false))] = "";
+  Inputs.ExtraFiles[appendPathFileSystemIndependent({"foo", "bar.h"}, true)] =
+  "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false),
+  spellHeader({Header{*FM.getFile(testPath(appendPathFileSystemIndependent(
+   {"foo", "baz.h"}, false)))},
+   HS, MainFile}));
+  EXPECT_EQ("\"" + appendPathFileSystemIndependent({"foo", "bar.h"}, true) +
+"\"",
+spellHeader({Header{*FM.getFile(appendPathFileSystemIndependent(
+ {"foo", "bar.h"}, true))},
+ HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cle

[PATCH] D151741: [Lex] Only warn on defining or undefining language-defined builtins

2023-06-01 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

Thanks for the patch!




Comment at: clang/test/Preprocessor/undef-x86.c:2
+// RUN: %clang_cc1 -triple=i386-none-none -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple=i686-none-none -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple=x86_64-none-none -fsyntax-only -verify %s

I don't think i686 adds anything beyond i386, at least for this test they are 
both `-m32`; consider removing this run line.


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

https://reviews.llvm.org/D151741

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


[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527451.
VitaNuo added a comment.

Remove extra include.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,105 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments,
+bool IsAbsolute) {
+  llvm::SmallString<32> Result;
+  if (IsAbsolute)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native,
+llvm::sys::path::get_separator());
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false))] = "";
+  Inputs.ExtraFiles[appendPathFileSystemIndependent({"foo", "bar.h"}, true)] =
+  "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false),
+  spellHeader({Header{*FM.getFile(testPath(appendPathFileSystemIndependent(
+   {"foo", "baz.h"}, false)))},
+   HS, MainFile}));
+  EXPECT_EQ("\"" + appendPathFileSystemIndependent({"foo", "bar.h"}, true) +
+"\"",
+spellHeader({Header{*FM.getFile(appendPathFileSystemIndependent(
+ {"foo", "bar.h"}, true))},
+ HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleane

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527452.
VitaNuo added a comment.

Remove newline at file end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,105 @@
+//===--- IncludeSpellerTest.cpp
+//-===//
+//
+// 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 "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments,
+bool IsAbsolute) {
+  llvm::SmallString<32> Result;
+  if (IsAbsolute)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native,
+llvm::sys::path::get_separator());
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpellerInput &Input) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+bool Result =
+AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator});
+if (!Result)
+  return "";
+return AbsolutePath.str();
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+  Inputs.FileName = testPath("foo.h");
+  Inputs.ExtraFiles["bar.h"] = "";
+  Inputs.ExtraFiles[testPath(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false))] = "";
+  Inputs.ExtraFiles[appendPathFileSystemIndependent({"foo", "bar.h"}, true)] =
+  "";
+  TestAST AST{Inputs};
+
+  auto &FM = AST.fileManager();
+  auto &HS = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("foo.h", spellHeader({Header{*FM.getFile(testPath("foo.h"))}, HS,
+  MainFile}));
+  EXPECT_EQ("\"bar.h\"",
+spellHeader({Header{*FM.getFile("bar.h")}, HS, MainFile}));
+  EXPECT_EQ(
+  appendPathFileSystemIndependent({"foo", "baz.h"}, false),
+  spellHeader({Header{*FM.getFile(testPath(appendPathFileSystemIndependent(
+   {"foo", "baz.h"}, false)))},
+   HS, MainFile}));
+  EXPECT_EQ("\"" + appendPathFileSystemIndependent({"foo", "bar.h"}, true) +
+"\"",
+spellHeader({Header{*FM.getFile(appendPathFileSystemIndependent(
+ {"foo", "bar.h"}, true))},
+ HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-06-01 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527457.
VitaNuo added a comment.

Re-introduce special path handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,233 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Result;
+  for (const auto &Segment : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{llvm::formatv(
+  "bar.h;{0};{1};vector", appendPathFileSystemIndependent({"foo", "qux.h"}),
+  appendPathFileSystemIndependent({"baz", "qux"}))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {appendPathFileSystemIndependent({"foo", "qux.h"}), ""},
+   {appendPathFileSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";
+
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{
+  "baz.h;" + appendPathFileSystemI

[PATCH] D151854: [clang] Use `FileEntryRef` in modular header search (part 1/2)

2023-06-01 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.






Comment at: clang/include/clang/Lex/HeaderSearch.h:763
   /// find this file due to requirements from \p RequestingModule.
-  bool findUsableModuleForHeader(const FileEntry *File,
+  bool findUsableModuleForHeader(OptionalFileEntryRef File,
  const DirectoryEntry *Root,

This should probably be non-Optional. I can't find any calls to this API that 
can pass null, they all pass something that is already being dereferenced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151854

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


[clang] 2129cc1 - [clang][Darwin] Error out when missing requested libarclite library

2023-06-01 Thread Keith Smiley via cfe-commits

Author: Keith Smiley
Date: 2023-06-01T09:32:59-07:00
New Revision: 2129cc1b3a14df5c24e5b2a680f18b88d5af4142

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

LOG: [clang][Darwin] Error out when missing requested libarclite library

Starting with the SDKs provided with Xcode 14.3, this library no longer
exists. Before this change this results in an opaque linker error in the
case that your deployment target is low enough that this library is
added. This produces a more useful error message in that case.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/arclite-link-external-toolchain.c
clang/test/Driver/arclite-link.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index d56708e3ee4fc..d7e59879cfa58 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -619,6 +619,9 @@ def warn_drv_darwin_sdk_invalid_settings : Warning<
   "SDK settings were ignored as 'SDKSettings.json' could not be parsed">,
   InGroup>;
 
+def err_drv_darwin_sdk_missing_arclite : Error<
+  "SDK does not contain 'libarclite' at the path '%0'; try increasing the 
minimum deployment target">;
+
 def err_drv_trivial_auto_var_init_stop_after_missing_dependency : Error<
   "'-ftrivial-auto-var-init-stop-after=*' is used without "
   "'-ftrivial-auto-var-init=zero' or '-ftrivial-auto-var-init=pattern'">;

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 123057a539b5b..922eb8a5eba8e 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1221,6 +1221,9 @@ void DarwinClang::AddLinkARCArgs(const ArgList &Args,
 P += "macosx";
   P += ".a";
 
+  if (!getVFS().exists(P))
+getDriver().Diag(clang::diag::err_drv_darwin_sdk_missing_arclite) << P;
+
   CmdArgs.push_back(Args.MakeArgString(P));
 }
 

diff  --git a/clang/test/Driver/arclite-link-external-toolchain.c 
b/clang/test/Driver/arclite-link-external-toolchain.c
index cc62cd1a48445..8391a8507d8f8 100644
--- a/clang/test/Driver/arclite-link-external-toolchain.c
+++ b/clang/test/Driver/arclite-link-external-toolchain.c
@@ -4,5 +4,8 @@
 // RUN:   -isysroot 
%t.tmpdir/Xcode.app/Contents/Developers/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 \
 // RUN:   %s 2>&1 | FileCheck %s
 
+// CHECK: error: SDK does not contain 'libarclite' at the path '
+// CHECK: .tmpdir/Xcode.app/{{.*}}libarclite_macosx.a';
+// CHECK: try increasing the minimum deployment target
 // CHECK: -lfoo
 // CHECK: .tmpdir/Xcode.app/{{.*}}libarclite_macosx.a

diff  --git a/clang/test/Driver/arclite-link.c 
b/clang/test/Driver/arclite-link.c
index e8cee3e042d3e..595ca0b538eec 100644
--- a/clang/test/Driver/arclite-link.c
+++ b/clang/test/Driver/arclite-link.c
@@ -1,9 +1,13 @@
 // RUN: touch %t.o
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.10 %t.o 2>&1 | FileCheck 
-check-prefix=CHECK-ARCLITE-OSX %s
+// RUN: mkdir -p 
%t.tmpdir/Xcode.app/Contents/Developers/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.10 %t.o \
+// RUN: -isysroot 
%t.tmpdir/Xcode.app/Contents/Developers/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 2>&1 | FileCheck -check-prefix=CHECK-ARCLITE-OSX %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.11 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE 
%s
 // RUN: %clang -### -target i386-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-nostdlib %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOSTDLIB %s
 
+// CHECK-ARCLITE-OSX: .tmpdir/Xcode.app/{{.*}}libarclite_macosx.a';
+// CHECK-ARCLITE-OSX: try increasing the minimum deployment target
 // CHECK-ARCLITE-OSX: -lfoo
 // CHECK-ARCLITE-OSX: libarclite_macosx.a
 // CHECK-ARCLITE-OSX: -framework



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


[PATCH] D150988: [clang][Darwin] Error out when missing requested libarclite library

2023-06-01 Thread Keith Smiley via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2129cc1b3a14: [clang][Darwin] Error out when missing 
requested libarclite library (authored by keith).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150988

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/arclite-link-external-toolchain.c
  clang/test/Driver/arclite-link.c


Index: clang/test/Driver/arclite-link.c
===
--- clang/test/Driver/arclite-link.c
+++ clang/test/Driver/arclite-link.c
@@ -1,9 +1,13 @@
 // RUN: touch %t.o
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.10 %t.o 2>&1 | FileCheck 
-check-prefix=CHECK-ARCLITE-OSX %s
+// RUN: mkdir -p 
%t.tmpdir/Xcode.app/Contents/Developers/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.10 %t.o \
+// RUN: -isysroot 
%t.tmpdir/Xcode.app/Contents/Developers/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 2>&1 | FileCheck -check-prefix=CHECK-ARCLITE-OSX %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.11 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE 
%s
 // RUN: %clang -### -target i386-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-nostdlib %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOSTDLIB %s
 
+// CHECK-ARCLITE-OSX: .tmpdir/Xcode.app/{{.*}}libarclite_macosx.a';
+// CHECK-ARCLITE-OSX: try increasing the minimum deployment target
 // CHECK-ARCLITE-OSX: -lfoo
 // CHECK-ARCLITE-OSX: libarclite_macosx.a
 // CHECK-ARCLITE-OSX: -framework
Index: clang/test/Driver/arclite-link-external-toolchain.c
===
--- clang/test/Driver/arclite-link-external-toolchain.c
+++ clang/test/Driver/arclite-link-external-toolchain.c
@@ -4,5 +4,8 @@
 // RUN:   -isysroot 
%t.tmpdir/Xcode.app/Contents/Developers/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 \
 // RUN:   %s 2>&1 | FileCheck %s
 
+// CHECK: error: SDK does not contain 'libarclite' at the path '
+// CHECK: .tmpdir/Xcode.app/{{.*}}libarclite_macosx.a';
+// CHECK: try increasing the minimum deployment target
 // CHECK: -lfoo
 // CHECK: .tmpdir/Xcode.app/{{.*}}libarclite_macosx.a
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1221,6 +1221,9 @@
 P += "macosx";
   P += ".a";
 
+  if (!getVFS().exists(P))
+getDriver().Diag(clang::diag::err_drv_darwin_sdk_missing_arclite) << P;
+
   CmdArgs.push_back(Args.MakeArgString(P));
 }
 
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -619,6 +619,9 @@
   "SDK settings were ignored as 'SDKSettings.json' could not be parsed">,
   InGroup>;
 
+def err_drv_darwin_sdk_missing_arclite : Error<
+  "SDK does not contain 'libarclite' at the path '%0'; try increasing the 
minimum deployment target">;
+
 def err_drv_trivial_auto_var_init_stop_after_missing_dependency : Error<
   "'-ftrivial-auto-var-init-stop-after=*' is used without "
   "'-ftrivial-auto-var-init=zero' or '-ftrivial-auto-var-init=pattern'">;


Index: clang/test/Driver/arclite-link.c
===
--- clang/test/Driver/arclite-link.c
+++ clang/test/Driver/arclite-link.c
@@ -1,9 +1,13 @@
 // RUN: touch %t.o
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo -mmacosx-version-min=10.10 %t.o 2>&1 | FileCheck -check-prefix=CHECK-ARCLITE-OSX %s
+// RUN: mkdir -p %t.tmpdir/Xcode.app/Contents/Developers/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo -mmacosx-version-min=10.10 %t.o \
+// RUN: -isysroot %t.tmpdir/Xcode.app/Contents/Developers/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk 2>&1 | FileCheck -check-prefix=CHECK-ARCLITE-OSX %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -mmacosx-version-min=10.11 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
 // RUN: %clang -### -target i386-apple-darwin10 -fobjc-link-runtime -mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -nostdlib %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOSTDLIB 

[PATCH] D151852: [clang] NFCI: Use `FileEntryRef` in `ModuleMapCallbacks`

2023-06-01 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added a comment.
This revision is now accepted and ready to land.

Nice simplification!




Comment at: clang/include/clang/Lex/ModuleMap.h:72
   /// \param Header The umbrella header to collect.
-  virtual void moduleMapAddUmbrellaHeader(FileManager *FileMgr,
-  const FileEntry *Header) {}
+  virtual void moduleMapAddUmbrellaHeader(FileEntryRef Header) {}
 };

Doc comment needs update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151852

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


  1   2   3   >