[clang] d69e9f9 - [OpaquePtrs][Clang] Add -opaque-pointers/-no-opaque-pointers cc1 options

2022-04-05 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-04-05T10:15:41+02:00
New Revision: d69e9f9d8978399a9d1f1c1ed62aa661440afcd3

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

LOG: [OpaquePtrs][Clang] Add -opaque-pointers/-no-opaque-pointers cc1 options

This adds cc1 options for enabling and disabling opaque pointers
on the clang side. This is not super useful now (because
-mllvm -opaque-pointers and -Xclang -opaque-pointers have the same
visible effect) but will be important once opaque pointers are
enabled by default in clang. In that case, it will only be
possible to disable them using the cc1 -no-opaque-pointers option.

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

Added: 
clang/test/CodeGen/opaque-pointers-flag.c

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenAction.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 3301e7587d216..720a59ff1bdce 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -469,6 +469,9 @@ CODEGENOPT(SkipRaxSetup, 1, 0)
 ENUM_CODEGENOPT(ZeroCallUsedRegs, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
 5, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip)
 
+/// Whether to use opaque pointers.
+CODEGENOPT(OpaquePointers, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2dc28bab08ca4..bc5aa1a37d0f2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5504,6 +5504,13 @@ defm enable_noundef_analysis : BoolOption<"",
   PosFlag,
   NegFlag,
   BothFlags<[], " analyzing function argument and return types for mandatory 
definedness">>;
+defm opaque_pointers : BoolOption<"",
+  "opaque-pointers",
+  CodeGenOpts<"OpaquePointers">,
+  DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], " opaque pointers">>;
 def discard_value_names : Flag<["-"], "discard-value-names">,
   HelpText<"Discard value names in LLVM IR">,
   MarshallingInfoFlag>;

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 807880fd4fd7a..25f4cbbc700a5 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -983,6 +983,9 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, 
StringRef InFile) {
   if (BA != Backend_EmitNothing && !OS)
 return nullptr;
 
+  if (CI.getCodeGenOpts().OpaquePointers)
+VMContext->enableOpaquePointers();
+
   // Load bitcode modules to link with, if we need to.
   if (LinkModules.empty())
 for (const CodeGenOptions::BitcodeFileToLink &F :

diff  --git a/clang/test/CodeGen/opaque-pointers-flag.c 
b/clang/test/CodeGen/opaque-pointers-flag.c
new file mode 100644
index 0..c4d4bb1619c2e
--- /dev/null
+++ b/clang/test/CodeGen/opaque-pointers-flag.c
@@ -0,0 +1,27 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck %s -check-prefix=TYPED
+// RUN: %clang_cc1 -opaque-pointers -triple x86_64-unknown-unknown -emit-llvm 
%s -o - | FileCheck %s -check-prefix=OPAQUE
+// The current default is typed pointers:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s -check-prefix=TYPED
+
+// TYPED-LABEL: @test(
+// TYPED-NEXT:  entry:
+// TYPED-NEXT:[[P_ADDR:%.*]] = alloca i32*, align 8
+// TYPED-NEXT:store i32* [[P:%.*]], i32** [[P_ADDR]], align 8
+// TYPED-NEXT:[[TMP0:%.*]] = load i32*, i32** [[P_ADDR]], align 8
+// TYPED-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* 
[[TMP0]], i64 1
+// TYPED-NEXT:[[TMP1:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
+// TYPED-NEXT:ret i32 [[TMP1]]
+//
+// OPAQUE-LABEL: @test(
+// OPAQUE-NEXT:  entry:
+// OPAQUE-NEXT:[[P_ADDR:%.*]] = alloca ptr, align 8
+// OPAQUE-NEXT:store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
+// OPAQUE-NEXT:[[TMP0:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// OPAQUE-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 1
+// OPAQUE-NEXT:[[TMP1:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
+// OPAQUE-NEXT:ret i32 [[TMP1]]
+//
+int test(int *p) {
+  return p[1];
+}



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


[PATCH] D123034: [OpaquePtrs][Clang] Add -opaque-pointers/-no-opaque-pointers cc1 options

2022-04-05 Thread Nikita Popov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd69e9f9d8978: [OpaquePtrs][Clang] Add 
-opaque-pointers/-no-opaque-pointers cc1 options (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123034

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/opaque-pointers-flag.c


Index: clang/test/CodeGen/opaque-pointers-flag.c
===
--- /dev/null
+++ clang/test/CodeGen/opaque-pointers-flag.c
@@ -0,0 +1,27 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown 
-emit-llvm %s -o - | FileCheck %s -check-prefix=TYPED
+// RUN: %clang_cc1 -opaque-pointers -triple x86_64-unknown-unknown -emit-llvm 
%s -o - | FileCheck %s -check-prefix=OPAQUE
+// The current default is typed pointers:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s -check-prefix=TYPED
+
+// TYPED-LABEL: @test(
+// TYPED-NEXT:  entry:
+// TYPED-NEXT:[[P_ADDR:%.*]] = alloca i32*, align 8
+// TYPED-NEXT:store i32* [[P:%.*]], i32** [[P_ADDR]], align 8
+// TYPED-NEXT:[[TMP0:%.*]] = load i32*, i32** [[P_ADDR]], align 8
+// TYPED-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* 
[[TMP0]], i64 1
+// TYPED-NEXT:[[TMP1:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
+// TYPED-NEXT:ret i32 [[TMP1]]
+//
+// OPAQUE-LABEL: @test(
+// OPAQUE-NEXT:  entry:
+// OPAQUE-NEXT:[[P_ADDR:%.*]] = alloca ptr, align 8
+// OPAQUE-NEXT:store ptr [[P:%.*]], ptr [[P_ADDR]], align 8
+// OPAQUE-NEXT:[[TMP0:%.*]] = load ptr, ptr [[P_ADDR]], align 8
+// OPAQUE-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr 
[[TMP0]], i64 1
+// OPAQUE-NEXT:[[TMP1:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
+// OPAQUE-NEXT:ret i32 [[TMP1]]
+//
+int test(int *p) {
+  return p[1];
+}
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -983,6 +983,9 @@
   if (BA != Backend_EmitNothing && !OS)
 return nullptr;
 
+  if (CI.getCodeGenOpts().OpaquePointers)
+VMContext->enableOpaquePointers();
+
   // Load bitcode modules to link with, if we need to.
   if (LinkModules.empty())
 for (const CodeGenOptions::BitcodeFileToLink &F :
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5504,6 +5504,13 @@
   PosFlag,
   NegFlag,
   BothFlags<[], " analyzing function argument and return types for mandatory 
definedness">>;
+defm opaque_pointers : BoolOption<"",
+  "opaque-pointers",
+  CodeGenOpts<"OpaquePointers">,
+  DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], " opaque pointers">>;
 def discard_value_names : Flag<["-"], "discard-value-names">,
   HelpText<"Discard value names in LLVM IR">,
   MarshallingInfoFlag>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -469,6 +469,9 @@
 ENUM_CODEGENOPT(ZeroCallUsedRegs, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
 5, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip)
 
+/// Whether to use opaque pointers.
+CODEGENOPT(OpaquePointers, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT


Index: clang/test/CodeGen/opaque-pointers-flag.c
===
--- /dev/null
+++ clang/test/CodeGen/opaque-pointers-flag.c
@@ -0,0 +1,27 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=TYPED
+// RUN: %clang_cc1 -opaque-pointers -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=OPAQUE
+// The current default is typed pointers:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=TYPED
+
+// TYPED-LABEL: @test(
+// TYPED-NEXT:  entry:
+// TYPED-NEXT:[[P_ADDR:%.*]] = alloca i32*, align 8
+// TYPED-NEXT:store i32* [[P:%.*]], i32** [[P_ADDR]], align 8
+// TYPED-NEXT:[[TMP0:%.*]] = load i32*, i32** [[P_ADDR]], align 8
+// TYPED-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[TMP0]], i64 1
+// TYPED-NEXT:[[TMP1:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
+// TYPED-NEXT:ret i32 [[TMP1]]
+//
+// OPAQUE-LABE

[PATCH] D123037: [clang][dataflow] Support integral casts

2022-04-05 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:206
+  // boolean.
+  auto &ExprLoc = Env.createStorageLocation(*S);
+  Env.setStorageLocation(*S, ExprLoc);

Nit: Just `Loc`? I believe that's what we use in other places in this file if 
it's a location for `S`.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:1904
-const auto *FooVal =
-cast(Env.getValue(*FooDecl, SkipPast::None));
-const auto *BarVal =

Why not assert the type of the value in this test and in `IntegralCast` below?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123037

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


[PATCH] D122008: [flang][driver] Add support for generating executables

2022-04-05 Thread Richard Barton via Phabricator via cfe-commits
richard.barton.arm added a comment.

Option 1 for me, let's not delay.

With upstreaming of fir-dev making great progress, we can start to think about 
having a working flang in LLVM 15. For that we would need to have upstreaming 
finished, the driver finished and CMake support finished before end of June. 
The initial user experience work should be focused on LLVM 15. The sooner we 
have the code on main branch, the sooner we can begin the work of shaking out 
the problems. To delay means that flang in LLVM 15 will not be as good as it 
could be.

This patch is orthogonal to the issues discussed on this thread and on the call 
on 4th April. Anyone using flang today is going to see those issues just the 
same with or without this patch as flang will error out before it gets to 
linking. Committing this patch won't change what flang can't do yet but it will 
probably flush out some more issues - perhaps serious ones - for us to fix. I 
don't think we should be scared to receive bug reports. At this stage in 
development, bug reports are surely good for us and the sooner we get them, the 
sooner we can potentially fix the issues.

I think the group of interested users with high quality-level expectations for 
flang are going to be evaluating it on a release rather than at some random 
point on main. I think anyone following along on main is going to have an 
accurate understanding of flang's maturity there and unlikely to be surprised 
by the quality of it. We should consider asking Alex to skip this patch in 
LLVMWeekly, or ask him to message it as we want to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122008

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


[clang] 3ba8548 - [libc++][ranges] Implement ranges::transform

2022-04-05 Thread Nikolas Klauser via cfe-commits

Author: Nikolas Klauser
Date: 2022-04-05T11:06:28+02:00
New Revision: 3ba8548c8e04bb301c4243887362c54bfbd4af8b

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

LOG: [libc++][ranges] Implement ranges::transform

Reviewed By: ldionne, var-const, #libc

Spies: libcxx-commits, mgorny

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

Added: 
clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp
libcxx/include/__algorithm/ranges_transform.h

libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.pass.cpp

Modified: 
libcxx/docs/Status/RangesAlgorithms.csv
libcxx/include/CMakeLists.txt
libcxx/include/algorithm
libcxx/include/module.modulemap
libcxx/test/libcxx/private_headers.verify.cpp
libcxx/test/support/almost_satisfies_types.h

Removed: 




diff  --git 
a/clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp 
b/clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp
new file mode 100644
index 0..1eb0655124cb4
--- /dev/null
+++ b/clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp
@@ -0,0 +1,15 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// REQUIRES: modules-build
+
+// WARNING: This test was generated by 'generate_private_header_tests.py'
+// and should not be edited manually.
+
+// expected-error@*:* {{use of private header from outside its module: 
'__algorithm/ranges_transform.h'}}
+#include <__algorithm/ranges_transform.h>

diff  --git a/libcxx/docs/Status/RangesAlgorithms.csv 
b/libcxx/docs/Status/RangesAlgorithms.csv
index 6dd0118028103..33401e8f41819 100644
--- a/libcxx/docs/Status/RangesAlgorithms.csv
+++ b/libcxx/docs/Status/RangesAlgorithms.csv
@@ -44,7 +44,7 @@ Write,move,Not assigned,n/a,Not started
 Write,move_backward,Not assigned,n/a,Not started
 Write,fill,Not assigned,n/a,Not started
 Write,fill_n,Not assigned,n/a,Not started
-Write,transform,Not assigned,n/a,Not started
+Write,transform,Nikolas Klauser,`D122173 `_,✅
 Write,generate,Not assigned,n/a,Not started
 Write,generate_n,Not assigned,n/a,Not started
 Write,remove_copy,Not assigned,n/a,Not started

diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 7cf305a83511b..30edc3f6b51f1 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -75,6 +75,7 @@ set(files
   __algorithm/ranges_min_element.h
   __algorithm/ranges_mismatch.h
   __algorithm/ranges_swap_ranges.h
+  __algorithm/ranges_transform.h
   __algorithm/remove.h
   __algorithm/remove_copy.h
   __algorithm/remove_copy_if.h

diff  --git a/libcxx/include/__algorithm/ranges_transform.h 
b/libcxx/include/__algorithm/ranges_transform.h
new file mode 100644
index 0..3c13b1b79ff3e
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_transform.h
@@ -0,0 +1,170 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H
+#define _LIBCPP___ALGORITHM_RANGES_TRANSFORM_H
+
+#include <__algorithm/in_in_out_result.h>
+#include <__algorithm/in_out_result.h>
+#include <__concepts/constructible.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/invoke.h>
+#include <__iterator/concepts.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+
+template 
+using unary_transform_result = in_out_result<_Ip, _Op>;
+
+template 
+using binary_transform_result = in_in_out_result<_I1, _I2, _O1>;
+
+namespace __transform {
+struct __fn {
+private:
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr
+  unary_transform_result<_InIter, _OutIter> __unary(_InIter __first, _Sent 
__last,
+_OutIter __result,
+  

[PATCH] D122173: [libc++][ranges] Implement ranges::transform

2022-04-05 Thread Nikolas Klauser via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
philnik marked an inline comment as done.
Closed by commit rG3ba8548c8e04: [libc++][ranges] Implement ranges::transform 
(authored by philnik).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D122173?vs=419955&id=420414#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122173

Files:
  clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp
  libcxx/docs/Status/RangesAlgorithms.csv
  libcxx/include/CMakeLists.txt
  libcxx/include/__algorithm/ranges_transform.h
  libcxx/include/algorithm
  libcxx/include/module.modulemap
  libcxx/test/libcxx/private_headers.verify.cpp
  
libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.pass.cpp
  libcxx/test/support/almost_satisfies_types.h

Index: libcxx/test/support/almost_satisfies_types.h
===
--- libcxx/test/support/almost_satisfies_types.h
+++ libcxx/test/support/almost_satisfies_types.h
@@ -128,4 +128,15 @@
 static_assert(std::semiregular);
 static_assert(!std::sentinel_for>);
 
+class WeaklyIncrementableNotMovable {
+public:
+  using difference_type = long;
+  WeaklyIncrementableNotMovable& operator++();
+  void operator++(int);
+  WeaklyIncrementableNotMovable(const WeaklyIncrementableNotMovable&) = delete;
+};
+
+static_assert(!std::movable);
+static_assert(!std::weakly_incrementable);
+
 #endif // ALMOST_SATISFIES_TYPES_H
Index: libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.pass.cpp
===
--- /dev/null
+++ libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.pass.cpp
@@ -0,0 +1,583 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-has-no-incomplete-ranges
+
+// 
+
+// template S, weakly_incrementable O,
+//  copy_constructible F, class Proj = identity>
+//   requires indirectly_writable>>
+//   constexpr ranges::unary_transform_result
+// ranges::transform(I first1, S last1, O result, F op, Proj proj = {});
+// template
+//   requires indirectly_writable, Proj>>>
+//   constexpr ranges::unary_transform_result, O>
+// ranges::transform(R&& r, O result, F op, Proj proj = {});
+// template S1, input_iterator I2, sentinel_for S2,
+//  weakly_incrementable O, copy_constructible F, class Proj1 = identity,
+//  class Proj2 = identity>
+//   requires indirectly_writable,
+//  projected>>
+//   constexpr ranges::binary_transform_result
+// ranges::transform(I1 first1, S1 last1, I2 first2, S2 last2, O result,
+//   F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
+// template
+//   requires indirectly_writable, Proj1>,
+//  projected, Proj2>>>
+//   constexpr ranges::binary_transform_result, borrowed_iterator_t, O>
+// ranges::transform(R1&& r1, R2&& r2, O result,
+//   F binary_op, Proj1 proj1 = {}, Proj2 proj2 = {});
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "almost_satisfies_types.h"
+
+struct BinaryFunc {
+  int operator()(int, int);
+};
+
+template 
+concept HasTranformR = requires(Range r, int* out) {
+  std::ranges::transform(r, out, std::identity{});
+  std::ranges::transform(r, r, out, BinaryFunc{});
+};
+static_assert(HasTranformR>);
+static_assert(!HasTranformR);
+static_assert(!HasTranformR);
+static_assert(!HasTranformR);
+static_assert(!HasTranformR);
+static_assert(!HasTranformR);
+static_assert(!HasTranformR);
+
+template 
+concept HasTransformIt = requires(It it, Sent sent, int* out) {
+  std::ranges::transform(it, sent, out, std::identity{});
+  std::ranges::transform(it, sent, it, sent, out, BinaryFunc{});
+};
+static_assert(HasTransformIt);
+static_assert(!HasTransformIt);
+static_assert(!HasTransformIt);
+static_assert(!HasTransformIt);
+static_assert(!HasTransformIt, SentinelForNotSemiregular>);
+static_assert(!HasTransformIt, InputRangeNotSentinelEqualityComparableWith>);
+
+template 
+concept HasTransformOut = requires(int* it, int* sent, It out, std::array range) {
+  std::ranges::transform(it, sent, out, std::identity{});
+  std::ranges::transform(it, sent, it, sent, out, BinaryFunc{});
+  std::ranges::transform(range, out, std::id

[clang] ff18b15 - [CodeGen] Avoid unnecessary ConstantExpr cast

2022-04-05 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-04-05T11:28:40+02:00
New Revision: ff18b158edc4719c4b05cd04dceaedcf69a8d9c5

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

LOG: [CodeGen] Avoid unnecessary ConstantExpr cast

With opaque pointers, this is not necessarily a ConstantExpr. And
we don't need one here either, just Constant is sufficient.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index d637ab6ec288d..4d24c33f51d02 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5407,7 +5407,7 @@ CodeGenModule::GetAddrOfConstantCFString(const 
StringLiteral *Literal) {
   auto Fields = Builder.beginStruct(STy);
 
   // Class pointer.
-  Fields.add(cast(CFConstantStringClassRef));
+  Fields.add(cast(CFConstantStringClassRef));
 
   // Flags.
   if (IsSwiftABI) {



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


[clang] 302fe7b - Remove libc++ test from clang lib.

2022-04-05 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2022-04-05T11:33:55+02:00
New Revision: 302fe7b3c40f7b949f3bebb74997bef9bf74d59f

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

LOG: Remove libc++ test from clang lib.

This was added in 3ba8548c8e04bb301c4243887362c54bfbd4af8b

Added: 


Modified: 


Removed: 
clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp



diff  --git 
a/clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp 
b/clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp
deleted file mode 100644
index 1eb0655124cb4..0
--- a/clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-//===--===//
-//
-// 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
-//
-//===--===//
-
-// REQUIRES: modules-build
-
-// WARNING: This test was generated by 'generate_private_header_tests.py'
-// and should not be edited manually.
-
-// expected-error@*:* {{use of private header from outside its module: 
'__algorithm/ranges_transform.h'}}
-#include <__algorithm/ranges_transform.h>



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


[PATCH] D123064: [Clang][C++23][WIP] P2071 Named universal character escapes

2022-04-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 420422.
cor3ntin added a comment.

Add lexing tests, improve diagnostics.
As a drive by, this also fix the handling of `\U{123}` which was a non
diagnosed invalid escape sequence, leading to some assertion failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D123031: [clangd] Use consistent header paths in CanonicalIncludes mappings

2022-04-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 420423.
kbobyrev added a comment.

Switch to stable file UniqueIDs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -986,12 +986,12 @@
 llvm::StringRef Main;
 llvm::StringRef TargetSymbolName;
   } TestCases[] = {
-{
-  R"cpp(
+  {
+  R"cpp(
 struct Foo;
 #define MACRO Foo
   )cpp",
-  R"cpp(
+  R"cpp(
 struct $spelled[[Foo]] {
   $spelled[[Foo]]();
   ~$spelled[[Foo]]();
@@ -999,24 +999,24 @@
 $spelled[[Foo]] Variable1;
 $implicit[[MACRO]] Variable2;
   )cpp",
-  "Foo",
-},
-{
-  R"cpp(
+  "Foo",
+  },
+  {
+  R"cpp(
 class Foo {
 public:
   Foo() = default;
 };
   )cpp",
-  R"cpp(
+  R"cpp(
 void f() { Foo $implicit[[f]]; f = $spelled[[Foo]]();}
   )cpp",
-  "Foo::Foo" /// constructor.
-},
+  "Foo::Foo" /// constructor.
+  },
   };
   CollectorOpts.RefFilter = RefKind::All;
   CollectorOpts.RefsInHeaders = false;
-  for (const auto& T : TestCases) {
+  for (const auto &T : TestCases) {
 Annotations Header(T.Header);
 Annotations Main(T.Main);
 // Reset the file system.
@@ -1578,15 +1578,22 @@
 }
 
 TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
-  CollectorOpts.CollectIncludePath = true;
-  CanonicalIncludes Includes;
-  Includes.addMapping(TestHeaderName, "");
-  CollectorOpts.Includes = &Includes;
   auto IncFile = testPath("test.inc");
   auto IncURI = URI::create(IncFile).toString();
   InMemoryFileSystem->addFile(IncFile, 0,
   llvm::MemoryBuffer::getMemBuffer("class X {};"));
-  runSymbolCollector("#include \"test.inc\"\nclass Y {};", /*Main=*/"",
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  std::string HeaderCode = "#include \"test.inc\"\nclass Y {};";
+  InMemoryFileSystem->addFile(TestHeaderName, 0,
+  llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+  auto File = Files->getFile(TestHeaderName);
+  ASSERT_TRUE(File);
+  CanonicalIncludes Includes;
+  Includes.addMapping(*File, "");
+  CollectorOpts.CollectIncludePath = true;
+  CollectorOpts.Includes = &Includes;
+  runSymbolCollector(HeaderCode, /*Main=*/"",
  /*ExtraArgs=*/{"-I", testRoot()});
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -6,14 +6,27 @@
 //
 //===--===//
 
+#include "TestFS.h"
 #include "index/CanonicalIncludes.h"
+#include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+const FileEntry *
+addFile(llvm::IntrusiveRefCntPtr &FS,
+llvm::IntrusiveRefCntPtr &FM, llvm::StringRef Filename) {
+  FS->addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(""));
+  auto File = FM->getFile(Filename);
+  return *File;
+}
+
 TEST(CanonicalIncludesTest, CStandardLibrary) {
   CanonicalIncludes CI;
   auto Language = LangOptions();
@@ -40,29 +53,47 @@
   // iosfwd declares some symbols it doesn't own.
   EXPECT_EQ("", CI.mapSymbol("std::ostream"));
   // And (for now) we assume it owns the others.
-  EXPECT_EQ("", CI.mapHeader("iosfwd"));
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));
+  const auto *File = addFile(InMemFS, Files, testPath("iosfwd"));
+  EXPECT_EQ("", CI.mapHeader(File));
 }
 
 TEST(CanonicalIncludesTest, PathMapping) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));
+  const auto *Bar = addFile(InMemFS, Files, testPath("foo/bar"));
+  con

[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 420425.
kbobyrev added a comment.

Rebase on top of main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1578,15 +1578,22 @@
 }
 
 TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
-  CollectorOpts.CollectIncludePath = true;
-  CanonicalIncludes Includes;
-  Includes.addMapping(TestHeaderName, "");
-  CollectorOpts.Includes = &Includes;
   auto IncFile = testPath("test.inc");
   auto IncURI = URI::create(IncFile).toString();
   InMemoryFileSystem->addFile(IncFile, 0,
   llvm::MemoryBuffer::getMemBuffer("class X {};"));
-  runSymbolCollector("#include \"test.inc\"\nclass Y {};", /*Main=*/"",
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  std::string HeaderCode = "#include \"test.inc\"\nclass Y {};";
+  InMemoryFileSystem->addFile(TestHeaderName, 0,
+  llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+  auto File = Files->getFile(TestHeaderName);
+  ASSERT_TRUE(File);
+  CanonicalIncludes Includes;
+  Includes.addMapping(*File, "");
+  CollectorOpts.CollectIncludePath = true;
+  CollectorOpts.Includes = &Includes;
+  runSymbolCollector(HeaderCode, /*Main=*/"",
  /*ExtraArgs=*/{"-I", testRoot()});
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -6,14 +6,27 @@
 //
 //===--===//
 
+#include "TestFS.h"
 #include "index/CanonicalIncludes.h"
+#include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+const FileEntry *
+addFile(llvm::IntrusiveRefCntPtr &FS,
+llvm::IntrusiveRefCntPtr &FM, llvm::StringRef Filename) {
+  FS->addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(""));
+  auto File = FM->getFile(Filename);
+  return *File;
+}
+
 TEST(CanonicalIncludesTest, CStandardLibrary) {
   CanonicalIncludes CI;
   auto Language = LangOptions();
@@ -40,29 +53,47 @@
   // iosfwd declares some symbols it doesn't own.
   EXPECT_EQ("", CI.mapSymbol("std::ostream"));
   // And (for now) we assume it owns the others.
-  EXPECT_EQ("", CI.mapHeader("iosfwd"));
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));
+  const auto *File = addFile(InMemFS, Files, testPath("iosfwd"));
+  EXPECT_EQ("", CI.mapHeader(File));
 }
 
 TEST(CanonicalIncludesTest, PathMapping) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));
+  const auto *Bar = addFile(InMemFS, Files, testPath("foo/bar"));
+  const auto *Other = addFile(InMemFS, Files, testPath("foo/baz"));
   // As used for IWYU pragmas.
   CanonicalIncludes CI;
-  CI.addMapping("foo/bar", "");
+  CI.addMapping(Bar, "");
 
-  EXPECT_EQ("", CI.mapHeader("foo/bar"));
-  EXPECT_EQ("", CI.mapHeader("bar/bar"));
+  // We added a mapping for baz.
+  EXPECT_EQ("", CI.mapHeader(Bar));
+  // Other file doesn't have a mapping.
+  EXPECT_EQ("", CI.mapHeader(Other));
 }
 
 TEST(CanonicalIncludesTest, Precedence) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));
+  const auto *File = addFile(InMemFS, Files, testPath("some/path"));
+
   CanonicalIncludes CI;
-  CI.addMapping("some/path", "");
+  CI.addMapping(File, "");
   LangOptions Language;
   Language.CPlusPlus = true;
   CI.addSystemHeadersMapping(Language);
 
   // We added a mapping from some/path to .
-  ASSERT_EQ("", CI.mapHeader("some/path"));
+  ASSERT_EQ("", CI.mapHeader(File));
   // We should have a path from 'bits/stl_vector.h' to ''.
-  ASSERT_EQ("", CI.mapHeader("bits/stl_vector.h"));
+  const auto *S

[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 420426.
kbobyrev added a comment.

Rebase correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1578,15 +1578,22 @@
 }
 
 TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
-  CollectorOpts.CollectIncludePath = true;
-  CanonicalIncludes Includes;
-  Includes.addMapping(TestHeaderName, "");
-  CollectorOpts.Includes = &Includes;
   auto IncFile = testPath("test.inc");
   auto IncURI = URI::create(IncFile).toString();
   InMemoryFileSystem->addFile(IncFile, 0,
   llvm::MemoryBuffer::getMemBuffer("class X {};"));
-  runSymbolCollector("#include \"test.inc\"\nclass Y {};", /*Main=*/"",
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  std::string HeaderCode = "#include \"test.inc\"\nclass Y {};";
+  InMemoryFileSystem->addFile(TestHeaderName, 0,
+  llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+  auto File = Files->getFile(TestHeaderName);
+  ASSERT_TRUE(File);
+  CanonicalIncludes Includes;
+  Includes.addMapping(*File, "");
+  CollectorOpts.CollectIncludePath = true;
+  CollectorOpts.Includes = &Includes;
+  runSymbolCollector(HeaderCode, /*Main=*/"",
  /*ExtraArgs=*/{"-I", testRoot()});
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -6,14 +6,27 @@
 //
 //===--===//
 
+#include "TestFS.h"
 #include "index/CanonicalIncludes.h"
+#include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+const FileEntry *
+addFile(llvm::IntrusiveRefCntPtr &FS,
+llvm::IntrusiveRefCntPtr &FM, llvm::StringRef Filename) {
+  FS->addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(""));
+  auto File = FM->getFile(Filename);
+  return *File;
+}
+
 TEST(CanonicalIncludesTest, CStandardLibrary) {
   CanonicalIncludes CI;
   auto Language = LangOptions();
@@ -40,29 +53,47 @@
   // iosfwd declares some symbols it doesn't own.
   EXPECT_EQ("", CI.mapSymbol("std::ostream"));
   // And (for now) we assume it owns the others.
-  EXPECT_EQ("", CI.mapHeader("iosfwd"));
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));
+  const auto *File = addFile(InMemFS, Files, testPath("iosfwd"));
+  EXPECT_EQ("", CI.mapHeader(File));
 }
 
 TEST(CanonicalIncludesTest, PathMapping) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));
+  const auto *Bar = addFile(InMemFS, Files, testPath("foo/bar"));
+  const auto *Other = addFile(InMemFS, Files, testPath("foo/baz"));
   // As used for IWYU pragmas.
   CanonicalIncludes CI;
-  CI.addMapping("foo/bar", "");
+  CI.addMapping(Bar, "");
 
-  EXPECT_EQ("", CI.mapHeader("foo/bar"));
-  EXPECT_EQ("", CI.mapHeader("bar/bar"));
+  // We added a mapping for baz.
+  EXPECT_EQ("", CI.mapHeader(Bar));
+  // Other file doesn't have a mapping.
+  EXPECT_EQ("", CI.mapHeader(Other));
 }
 
 TEST(CanonicalIncludesTest, Precedence) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));
+  const auto *File = addFile(InMemFS, Files, testPath("some/path"));
+
   CanonicalIncludes CI;
-  CI.addMapping("some/path", "");
+  CI.addMapping(File, "");
   LangOptions Language;
   Language.CPlusPlus = true;
   CI.addSystemHeadersMapping(Language);
 
   // We added a mapping from some/path to .
-  ASSERT_EQ("", CI.mapHeader("some/path"));
+  ASSERT_EQ("", CI.mapHeader(File));
   // We should have a path from 'bits/stl_vector.h' to ''.
-  ASSERT_EQ("", CI.mapHeader("bits/stl_vector.h"));
+  const auto *STLVec

[PATCH] D122774: [clang][extract-api] Add Objective-C Category support

2022-04-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang accepted this revision.
dang 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/D122774/new/

https://reviews.llvm.org/D122774

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


[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.h:38
 public:
-  /// Adds a string-to-string mapping from \p Path to \p CanonicalPath.
-  void addMapping(llvm::StringRef Path, llvm::StringRef CanonicalPath);
+  /// Adds a string-to-string mapping from \p ID to \p CanonicalPath.
+  void addMapping(const FileEntry *Header, llvm::StringRef CanonicalPath);

nit: no longer a string-to-string mapping



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.h:45
   /// Returns the overridden include for for files in \p Header, or "".
-  llvm::StringRef mapHeader(llvm::StringRef Header) const;
+  llvm::StringRef mapHeader(const FileEntry *Header) const;
 

prefer FileEntryRef over FileEntry*, so the name we're looking up is controlled 
by the caller rather than an ~arbitrary choice in case of symlinks



Comment at: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp:1
 //===-- CanonicalIncludesTests.cpp - 
--===//
 //

Can you add a test for the new functionality? that the mapping doesn't depend 
on the name

Use the hard-link function in InMemoryFS to create multiple names with one UID



Comment at: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp:57
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemFS));

why the pointer? can't this just be `FileManager Files(...)`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

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


[clang] 46cfbe5 - [LLVMContext] Replace enableOpaquePointers() with setOpaquePointers()

2022-04-05 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-04-05T12:02:48+02:00
New Revision: 46cfbe561bfd3b35984b3e1662bd2bca4eb9e96d

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

LOG: [LLVMContext] Replace enableOpaquePointers() with setOpaquePointers()

This allows both explicitly enabling and explicitly disabling
opaque pointers, in anticipation of the default switching at some
point.

This also slightly changes the rules by allowing calls if either
the opaque pointer mode has not yet been set (explicitly or
implicitly) or if the value remains unchanged.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenAction.cpp
llvm/include/llvm/IR/LLVMContext.h
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/IR/LLVMContextImpl.cpp
llvm/unittests/IR/ConstantsTest.cpp
llvm/unittests/IR/TypesTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 25f4cbbc700a5..b8ed3534de8be 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -984,7 +984,7 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, 
StringRef InFile) {
 return nullptr;
 
   if (CI.getCodeGenOpts().OpaquePointers)
-VMContext->enableOpaquePointers();
+VMContext->setOpaquePointers(true);
 
   // Load bitcode modules to link with, if we need to.
   if (LinkModules.empty())

diff  --git a/llvm/include/llvm/IR/LLVMContext.h 
b/llvm/include/llvm/IR/LLVMContext.h
index d80d54693258a..73e2326b8fe3e 100644
--- a/llvm/include/llvm/IR/LLVMContext.h
+++ b/llvm/include/llvm/IR/LLVMContext.h
@@ -308,9 +308,11 @@ class LLVMContext {
   /// Whether we've decided on using opaque pointers or typed pointers yet.
   bool hasSetOpaquePointersValue() const;
 
-  /// Enable opaque pointers. Can only be called before creating the first
-  /// pointer type.
-  void enableOpaquePointers() const;
+  /// Set whether opaque pointers are enabled. The method may be called 
multiple
+  /// times, but only with the same value. Note that creating a pointer type or
+  /// otherwise querying the opaque pointer mode performs an implicit set to
+  /// the default value.
+  void setOpaquePointers(bool Enable) const;
 
   /// Whether typed pointers are supported. If false, all pointers are opaque.
   bool supportsTypedPointers() const;

diff  --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 8aac5a66c6232..2a091a9c94f8e 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -860,9 +860,9 @@ lltok::Kind LLLexer::LexIdentifier() {
   TYPEKEYWORD("token", Type::getTokenTy(Context));
 
   if (Keyword == "ptr") {
-// enableOpaquePointers() must be called before creating any pointer types.
+// setOpaquePointers() must be called before creating any pointer types.
 if (!Context.hasSetOpaquePointersValue()) {
-  Context.enableOpaquePointers();
+  Context.setOpaquePointers(true);
 } else if (Context.supportsTypedPointers()) {
   Warning("ptr type is only supported in -opaque-pointers mode");
   return lltok::Error;

diff  --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp 
b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 034fa5832ba84..8a5074941b979 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1884,7 +1884,7 @@ Error BitcodeReader::parseTypeTableBody() {
   if (Record.size() != 1)
 return error("Invalid opaque pointer record");
   if (LLVM_UNLIKELY(!Context.hasSetOpaquePointersValue())) {
-Context.enableOpaquePointers();
+Context.setOpaquePointers(true);
   } else if (Context.supportsTypedPointers())
 return error(
 "Opaque pointers are only supported in -opaque-pointers mode");

diff  --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index f4e917cc89920..c9b0d957aa887 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -355,10 +355,8 @@ bool LLVMContext::hasSetOpaquePointersValue() const {
   return pImpl->hasOpaquePointersValue();
 }
 
-void LLVMContext::enableOpaquePointers() const {
-  assert(pImpl->PointerTypes.empty() && pImpl->ASPointerTypes.empty() &&
- "Must be called before creating any pointer types");
-  pImpl->setOpaquePointers(true);
+void LLVMContext::setOpaquePointers(bool Enable) const {
+  pImpl->setOpaquePointers(Enable);
 }
 
 bool LLVMContext::supportsTypedPointers() const {

diff  --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 1d115e50021b2..ed192275aabed 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -259,4 +259,8 @@ bool LLVMContextImpl::getOpaque

[clang] 4d8a74c - [Test] Use cc1 instead of mllvm -opaque-pointers option (NFC)

2022-04-05 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-04-05T12:04:48+02:00
New Revision: 4d8a74c460eb9ec46f913375c92fa8c2359ddc22

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

LOG: [Test] Use cc1 instead of mllvm -opaque-pointers option (NFC)

Added: 


Modified: 
clang/test/CoverageMapping/ir.c

Removed: 




diff  --git a/clang/test/CoverageMapping/ir.c b/clang/test/CoverageMapping/ir.c
index bd1eeb450d4c9..62276189b98e9 100644
--- a/clang/test/CoverageMapping/ir.c
+++ b/clang/test/CoverageMapping/ir.c
@@ -1,6 +1,6 @@
 // Check the data structures emitted by coverage mapping
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple 
x86_64-apple-macosx10.9 -main-file-name ir.c %s -o - -emit-llvm 
-fprofile-instrument=clang -fcoverage-mapping -mllvm 
-enable-name-compression=false -mllvm -opaque-pointers=0 | FileCheck %s 
-check-prefixes=COMMON,DARWIN
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple 
x86_64-apple-macosx10.9 -main-file-name ir.c %s -o - -emit-llvm 
-fprofile-instrument=clang -fcoverage-mapping -mllvm 
-enable-name-compression=false -mllvm -opaque-pointers=1 | FileCheck %s 
-check-prefixes=COMMON,DARWIN
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple 
x86_64-apple-macosx10.9 -main-file-name ir.c %s -o - -emit-llvm 
-fprofile-instrument=clang -fcoverage-mapping -mllvm 
-enable-name-compression=false -no-opaque-pointers | FileCheck %s 
-check-prefixes=COMMON,DARWIN
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple 
x86_64-apple-macosx10.9 -main-file-name ir.c %s -o - -emit-llvm 
-fprofile-instrument=clang -fcoverage-mapping -mllvm 
-enable-name-compression=false -opaque-pointers | FileCheck %s 
-check-prefixes=COMMON,DARWIN
 // RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple 
x86_64--windows-msvc -main-file-name ir.c %s -o - -emit-llvm 
-fprofile-instrument=clang -fcoverage-mapping -mllvm 
-enable-name-compression=false | FileCheck %s -check-prefixes=COMMON,WINDOWS
 
 static inline void unused(void) {}



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


[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension nvfortran compiler supports using INTENT attributes for non-dummy arguments. For example, for local variables.

2022-04-05 Thread Daniil Dudkin via Phabricator via cfe-commits
unterumarmung created this revision.
Herald added a reviewer: sscalpone.
Herald added projects: Flang, All.
unterumarmung requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, jdoerfert, MaskRay.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

This change adds a -fnon-arg-intent flag that enables such behavior in flang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123113

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Common/Fortran-features.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Semantics/non-arg-intent.f90

Index: flang/test/Semantics/non-arg-intent.f90
===
--- /dev/null
+++ flang/test/Semantics/non-arg-intent.f90
@@ -0,0 +1,5 @@
+!RUN: %flang_fc1 %s -fnon-arg-intent
+function foo() result(res)
+integer, intent(out) :: res
+procedure(), intent(in) :: p1
+end function foo
\ No newline at end of file
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -7,6 +7,7 @@
 ! RUN: -fdefault-integer-8 \
 ! RUN: -fdefault-real-8 \
 ! RUN: -flarge-sizes \
+! RUN: -fnon-arg-intent \
 ! RUN: -mllvm -print-before-all\
 ! RUN: -P \
 ! RUN:   | FileCheck %s
@@ -17,4 +18,5 @@
 ! CHECK: "-fdefault-integer-8"
 ! CHECK: "-fdefault-real-8"
 ! CHECK: "-flarge-sizes"
+! CHECK: "-fnon-arg-intent"
 ! CHECK:  "-mllvm" "-print-before-all"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -42,6 +42,7 @@
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
+! HELP-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
@@ -115,6 +116,7 @@
 ! HELP-FC1-NEXT:Do not use the analyzed objects when unparsing
 ! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-FC1-NEXT: -fno-reformat  Dump the cooked character stream in -E mode
+! HELP-FC1-NEXT: -fnon-arg-intent   Allow use of INTENT attribute not for dummy arguments
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -42,6 +42,7 @@
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! CHECK-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
+! CHECK-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
 ! CHECK-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
Index: flang/lib/Semantics/check-declarations.cpp
===
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -533,8 +533,10 @@
   } else if (symbol.attrs().test(Attr::INTENT_IN) ||
   symbol.attrs().test(Attr::INTENT_OUT) ||
   symbol.attrs().test(Attr::INTENT_INOUT)) {
-messages_.Say("INTENT attributes may apply only to a dummy "
-  "argument"_err_en_US); // C843
+if (!context_.languageFeatures().IsEnabled(
+Fortran::common::LanguageFeature::NonDummyArgumentIntent))
+  messages_.Say("INTENT attributes may apply only to a dummy "
+"argument"_err_en_US); // C843
   } else if (IsOptional(symbol)) {
 messages_.Say("OPTIONAL attribute may apply only to a dummy "
   "argument"_err_en_US); // C849
@@ -766,8 +768,10 @@
   } else if (symbol.attrs().test(Attr::INTENT_IN) ||
   symbol.att

[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension

2022-04-05 Thread Daniil Dudkin via Phabricator via cfe-commits
unterumarmung updated this revision to Diff 420436.
unterumarmung retitled this revision from "[Flang] Add `INTENT` for non-dummy 
arguments extension nvfortran compiler supports using INTENT attributes for 
non-dummy arguments. For example, for local variables." to "[Flang] Add 
`INTENT` for non-dummy arguments extension".
unterumarmung edited the summary of this revision.
unterumarmung added a comment.

Fixed revision description


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123113

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Common/Fortran-features.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Semantics/non-arg-intent.f90

Index: flang/test/Semantics/non-arg-intent.f90
===
--- /dev/null
+++ flang/test/Semantics/non-arg-intent.f90
@@ -0,0 +1,5 @@
+!RUN: %flang_fc1 %s -fnon-arg-intent
+function foo() result(res)
+integer, intent(out) :: res
+procedure(), intent(in) :: p1
+end function foo
\ No newline at end of file
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -7,6 +7,7 @@
 ! RUN: -fdefault-integer-8 \
 ! RUN: -fdefault-real-8 \
 ! RUN: -flarge-sizes \
+! RUN: -fnon-arg-intent \
 ! RUN: -mllvm -print-before-all\
 ! RUN: -P \
 ! RUN:   | FileCheck %s
@@ -17,4 +18,5 @@
 ! CHECK: "-fdefault-integer-8"
 ! CHECK: "-fdefault-real-8"
 ! CHECK: "-flarge-sizes"
+! CHECK: "-fnon-arg-intent"
 ! CHECK:  "-mllvm" "-print-before-all"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -42,6 +42,7 @@
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
+! HELP-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
@@ -115,6 +116,7 @@
 ! HELP-FC1-NEXT:Do not use the analyzed objects when unparsing
 ! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-FC1-NEXT: -fno-reformat  Dump the cooked character stream in -E mode
+! HELP-FC1-NEXT: -fnon-arg-intent   Allow use of INTENT attribute not for dummy arguments
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -42,6 +42,7 @@
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! CHECK-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
+! CHECK-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
 ! CHECK-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
Index: flang/lib/Semantics/check-declarations.cpp
===
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -533,8 +533,10 @@
   } else if (symbol.attrs().test(Attr::INTENT_IN) ||
   symbol.attrs().test(Attr::INTENT_OUT) ||
   symbol.attrs().test(Attr::INTENT_INOUT)) {
-messages_.Say("INTENT attributes may apply only to a dummy "
-  "argument"_err_en_US); // C843
+if (!context_.languageFeatures().IsEnabled(
+Fortran::common::LanguageFeature::NonDummyArgumentIntent))
+  messages_.Say("INTENT attributes may apply only to a dummy "
+"argument"_err_en_US); // C843
   } else if (IsOptional(symbol)) {
 messages_.Say("OPTIONAL attribute may apply only to a dummy "
   

[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang marked 2 inline comments as done.
dang added a comment.

In D123045#3428030 , @QuietMisdreavus 
wrote:

> In D123045#3427992 , @zixuw wrote:
>
>> In D123045#3427699 , 
>> @QuietMisdreavus wrote:
>>
>>> After a quick scan comparing the current output of these symbol graphs with 
>>> the primary library used for reading them 
>>> , the last thing i can spot 
>>> that's "off" is that the "function signature" is currently being serialized 
>>> under a `parameters` field instead of the required `functionSignature`.
>>
>> Hmm, I was looking at the format specification at 
>> https://github.com/apple/swift-docc-symbolkit/blob/0a45209833f4a151212c1aa38e13cfc03b9462e4/openapi.yaml#L307,
>>  and I searched the term `functionSignature` in the spec but found no 
>> property with that name (except for the `FunctionSignature` schema that the 
>> `parameters` property is referring to). But anyway this should be a easy fix.
>
> It seems like the specification and implementation have diverged. The parser 
> in swift-docc-symbolkit is looking for a `functionSignature` field by virtue 
> of how it names its "coding key" 
> .
>  By comparison, here is the functionSignature emitter in the Swift 
> symbol-graph generator 
> .

Yeah we should fix that I will do it as part of this patch since it seems like 
a small change.




Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:510
   Symbols.emplace_back(std::move(*Obj));
+  PathComponentContext.pop_back();
 }

zixuw wrote:
> zixuw wrote:
> > QuietMisdreavus wrote:
> > > zixuw wrote:
> > > > What's the cost/would it worth it to wrap the `emplace_back`s and 
> > > > `pop_back`s of `PathComponentContext` in meaningful APIs like 
> > > > `enterPathComponentContext` and `exitPathComponentContext`?
> > > > That way the code is more self-explanatory and easier to read. It took 
> > > > me some time and mental resources to figure out why the `pop_back` is 
> > > > placed here.
> > > What's the use of having the `emplace_back` call inside 
> > > `serializeAPIRecord` but to pop it outside? It seems like it's easier to 
> > > mess up for new kinds of records.
> > The reason to `emplace_back` the path component inside `serializeAPIRecord` 
> > is that the `pathComponent` field of the `Record` is serialized in there so 
> > you want to include the name of the symbol itself in the path component 
> > list.
> > The `pop_back` is delayed til all other additional serialization for a 
> > specific kind of record, for example `serializeEnumRecord` handles all the 
> > enum cases after processing the enum record itself using 
> > `serializeAPIRecord`. So in order to correctly include the enum name in the 
> > path components of all the enum cases, the enum name has to stay in 
> > `PathComponentContext` until all members are serialized.
> > 
> > This is exactly the reason why I wanted a clearer API to make it easier to 
> > see.
> Hmm now that I thought about this, it seems that it would be easier to 
> understand and avoid bugs if we lift 
> `PathComponentContext.emplace_back`/`enterPathComponentContext` out of 
> `serializeAPIRecord`, because we have access to the record name before that 
> anyway.
> 
> So we establish a pre-condition of `serializeAPIRecord` that the correct path 
> components would be set up in `PathComponentContext` before the call so we 
> could still serialize the field inside that method. And in specific 
> `serialize*Record` methods we push the record name, and pop out at the end.
> 
> This way the push and pop operations would appear in pairs in a single block, 
> saving the confusion and mental work of jumping across functions to see how 
> `PathComponentContext` is evolving.
If you think we should have a specialized API I am happy to do this. I figured 
it was self-explanatory by the name of `PathComponentContext` but it clearly 
isn't so needs addressing. I put the `emplace_back` call in 
`serializeAPIRecord` since all the specific serialization methods call it. I 
thought it would make it impossible to forget to add them. @zixuw is correct in 
the reason why the pop is outside we don't want to pop before we have 
serialized the sub records by agree it is ugly and potentially error prone. I 
can see three ways forward for improving the ergonomics of this since this 
seems to be problematic:
- Provide `serializeAPIRecord` a continuation to serialize the sub records or 
additional fields, that way we can move the pop inside `serializeAPIRecord` I 
am not a fan personally because we get in

[PATCH] D123113: [Flang] Add `INTENT` for non-dummy arguments extension

2022-04-05 Thread Daniil Dudkin via Phabricator via cfe-commits
unterumarmung updated this revision to Diff 420437.
unterumarmung added a comment.

Fixed commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123113

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Common/Fortran-features.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Semantics/non-arg-intent.f90

Index: flang/test/Semantics/non-arg-intent.f90
===
--- /dev/null
+++ flang/test/Semantics/non-arg-intent.f90
@@ -0,0 +1,5 @@
+!RUN: %flang_fc1 %s -fnon-arg-intent
+function foo() result(res)
+integer, intent(out) :: res
+procedure(), intent(in) :: p1
+end function foo
\ No newline at end of file
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -7,6 +7,7 @@
 ! RUN: -fdefault-integer-8 \
 ! RUN: -fdefault-real-8 \
 ! RUN: -flarge-sizes \
+! RUN: -fnon-arg-intent \
 ! RUN: -mllvm -print-before-all\
 ! RUN: -P \
 ! RUN:   | FileCheck %s
@@ -17,4 +18,5 @@
 ! CHECK: "-fdefault-integer-8"
 ! CHECK: "-fdefault-real-8"
 ! CHECK: "-flarge-sizes"
+! CHECK: "-fnon-arg-intent"
 ! CHECK:  "-mllvm" "-print-before-all"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -42,6 +42,7 @@
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
+! HELP-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments
 ! HELP-NEXT: -fopenacc  Enable OpenACC
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
@@ -115,6 +116,7 @@
 ! HELP-FC1-NEXT:Do not use the analyzed objects when unparsing
 ! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! HELP-FC1-NEXT: -fno-reformat  Dump the cooked character stream in -E mode
+! HELP-FC1-NEXT: -fnon-arg-intent   Allow use of INTENT attribute not for dummy arguments
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -42,6 +42,7 @@
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
 ! CHECK-NEXT: -fno-color-diagnostics  Disable colors in diagnostics
+! CHECK-NEXT: -fnon-arg-intent Allow use of INTENT attribute not for dummy arguments
 ! CHECK-NEXT: -fopenacc  Enable OpenACC
 ! CHECK-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
 ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
Index: flang/lib/Semantics/check-declarations.cpp
===
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -533,8 +533,10 @@
   } else if (symbol.attrs().test(Attr::INTENT_IN) ||
   symbol.attrs().test(Attr::INTENT_OUT) ||
   symbol.attrs().test(Attr::INTENT_INOUT)) {
-messages_.Say("INTENT attributes may apply only to a dummy "
-  "argument"_err_en_US); // C843
+if (!context_.languageFeatures().IsEnabled(
+Fortran::common::LanguageFeature::NonDummyArgumentIntent))
+  messages_.Say("INTENT attributes may apply only to a dummy "
+"argument"_err_en_US); // C843
   } else if (IsOptional(symbol)) {
 messages_.Say("OPTIONAL attribute may apply only to a dummy "
   "argument"_err_en_US); // C849
@@ -766,8 +768,10 @@
   } else if (symbol.attrs().test(Attr::INTENT_IN) ||
   symbol.attrs().test(Attr::INTENT_OUT) ||
   symbol.attrs().test(Attr::INTENT_INOUT)) {
-messages_.Say("INTENT attributes may apply only to a dummy "
-  "argument"_err_en_US); // C843
+  

[PATCH] D122173: [libc++][ranges] Implement ranges::transform

2022-04-05 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added inline comments.



Comment at: 
clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp:1-15
+//===--===//
+//
+// 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
+//
+//===--===//

This file doesn't belong in clang/lib. Deleted it in 
302fe7b3c40f7b949f3bebb74997bef9bf74d59f.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122173

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


[clang] 8b63622 - [clang][extract-api] Undefining macros should not result in a crash

2022-04-05 Thread Daniel Grumberg via cfe-commits

Author: Daniel Grumberg
Date: 2022-04-05T11:42:45+01:00
New Revision: 8b63622b9fd9ad2a86487da6098b7a4351d3e8eb

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

LOG: [clang][extract-api] Undefining macros should not result in a crash

This fixes the situation where a undefining a not previously defined
macro resulted in a crash. Before trying to remove a definition from
PendingMacros we first check to see if the macro did indeed have a
previous definition.

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

Added: 


Modified: 
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/test/ExtractAPI/macro_undefined.c

Removed: 




diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index cf95c3d739b60..e4ae0403f260f 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -534,6 +534,11 @@ class MacroCallback : public PPCallbacks {
   // macro definition for it.
   void MacroUndefined(const Token &MacroNameToken, const MacroDefinition &MD,
   const MacroDirective *Undef) override {
+// If this macro wasn't previously defined we don't need to do anything
+// here.
+if (!Undef)
+  return;
+
 llvm::erase_if(PendingMacros, [&MD](const PendingMacro &PM) {
   return MD.getMacroInfo()->getDefinitionLoc() ==
  PM.MD->getMacroInfo()->getDefinitionLoc();

diff  --git a/clang/test/ExtractAPI/macro_undefined.c 
b/clang/test/ExtractAPI/macro_undefined.c
index e04712500ef93..f128a446b6588 100644
--- a/clang/test/ExtractAPI/macro_undefined.c
+++ b/clang/test/ExtractAPI/macro_undefined.c
@@ -19,6 +19,8 @@
 FUNC_GEN(foo)
 FUNC_GEN(bar, const int *, unsigned);
 #undef FUNC_GEN
+// Undefining a not previously defined macro should not result in a crash.
+#undef FOO
 
 //--- reference.output.json.in
 {



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


[PATCH] D123056: [clang][extract-api] Undefining macros should not result in a crash

2022-04-05 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b63622b9fd9: [clang][extract-api] Undefining macros should 
not result in a crash (authored by dang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123056

Files:
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/test/ExtractAPI/macro_undefined.c


Index: clang/test/ExtractAPI/macro_undefined.c
===
--- clang/test/ExtractAPI/macro_undefined.c
+++ clang/test/ExtractAPI/macro_undefined.c
@@ -19,6 +19,8 @@
 FUNC_GEN(foo)
 FUNC_GEN(bar, const int *, unsigned);
 #undef FUNC_GEN
+// Undefining a not previously defined macro should not result in a crash.
+#undef FOO
 
 //--- reference.output.json.in
 {
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -534,6 +534,11 @@
   // macro definition for it.
   void MacroUndefined(const Token &MacroNameToken, const MacroDefinition &MD,
   const MacroDirective *Undef) override {
+// If this macro wasn't previously defined we don't need to do anything
+// here.
+if (!Undef)
+  return;
+
 llvm::erase_if(PendingMacros, [&MD](const PendingMacro &PM) {
   return MD.getMacroInfo()->getDefinitionLoc() ==
  PM.MD->getMacroInfo()->getDefinitionLoc();


Index: clang/test/ExtractAPI/macro_undefined.c
===
--- clang/test/ExtractAPI/macro_undefined.c
+++ clang/test/ExtractAPI/macro_undefined.c
@@ -19,6 +19,8 @@
 FUNC_GEN(foo)
 FUNC_GEN(bar, const int *, unsigned);
 #undef FUNC_GEN
+// Undefining a not previously defined macro should not result in a crash.
+#undef FOO
 
 //--- reference.output.json.in
 {
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -534,6 +534,11 @@
   // macro definition for it.
   void MacroUndefined(const Token &MacroNameToken, const MacroDefinition &MD,
   const MacroDirective *Undef) override {
+// If this macro wasn't previously defined we don't need to do anything
+// here.
+if (!Undef)
+  return;
+
 llvm::erase_if(PendingMacros, [&MD](const PendingMacro &PM) {
   return MD.getMacroInfo()->getDefinitionLoc() ==
  PM.MD->getMacroInfo()->getDefinitionLoc();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123019: [clang][extract-api] Add support for typedefs

2022-04-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:598-605
+  // Typedefs of anonymous types have their entries unified with the underlying
+  // type.
+  bool ShouldDrop = Record.UnderlyingType.Name.empty();
+  // enums declared with `NS_OPTION` have a named enum and a named typedef, 
with
+  // the same name
+  ShouldDrop |= (Record.UnderlyingType.Name == Record.Name);
+  if (ShouldDrop)

zixuw wrote:
> Consider move the should-drop logic into 
> `SymbolGraphSerializer::shouldSkip(const APIRecord &Record) const` so that we 
> have a central place to see and manage which symbols get skipped.
> This would also simplify things here as the filtering will automatically get 
> handled in the following `serializeAPIRecord(Record)` line.
I need to know about it being a `TypedefRecord` so I can access the underlying 
type name, so I would need to attempt to `dyn_cast` in `shouldSkip`. Also this 
logic is specific to typedef records so I would prefer to keep it here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123019

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


[PATCH] D123019: [clang][extract-api] Add support for typedefs

2022-04-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420442.
dang added a comment.

Whitespace changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123019

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp
  clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.h
  clang/test/ExtractAPI/typedef.c
  clang/test/ExtractAPI/typedef_anonymous_record.c
  clang/test/ExtractAPI/typedef_chain.c

Index: clang/test/ExtractAPI/typedef_chain.c
===
--- /dev/null
+++ clang/test/ExtractAPI/typedef_chain.c
@@ -0,0 +1,193 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api --product-name=TypedefChain -target arm64-apple-macosx \
+// RUN: -x objective-c-header %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+typedef int MyInt;
+typedef MyInt MyIntInt;
+typedef MyIntInt MyIntIntInt;
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "TypedefChain",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyInt"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:input.h@T@MyInt"
+  },
+  "kind": {
+"displayName": "Type Alias",
+"identifier": "objective-c.typealias"
+  },
+  "location": {
+"character": 13,
+"line": 1,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyInt"
+  }
+],
+"title": "MyInt"
+  },
+  "type": "c:I"
+},
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:input.h@T@MyInt",
+  "spelling": "MyInt"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyIntInt"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:input.h@T@MyIntInt"
+  },
+  "kind": {
+"displayName": "Type Alias",
+"identifier": "objective-c.typealias"
+  },
+  "location": {
+"character": 15,
+"line": 2,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyIntInt"
+  }
+],
+"title": "MyIntInt"
+  },
+  "type": "c:input.h@T@MyInt"
+},
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:input.h@T@MyIntInt",
+  "spelling": "MyIntInt"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyIntIntInt"
+}
+  ],

[PATCH] D122173: [libc++][ranges] Implement ranges::transform

2022-04-05 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik marked an inline comment as done.
philnik added inline comments.



Comment at: 
clang/lib/ExtractAPI/Serialization/ranges_transform.module.verify.cpp:1-15
+//===--===//
+//
+// 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
+//
+//===--===//

bkramer wrote:
> This file doesn't belong in clang/lib. Deleted it in 
> 302fe7b3c40f7b949f3bebb74997bef9bf74d59f.
Sorry, this must be a weird merge conflict. Thanks for removing it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122173

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


[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:510
   Symbols.emplace_back(std::move(*Obj));
+  PathComponentContext.pop_back();
 }

dang wrote:
> zixuw wrote:
> > zixuw wrote:
> > > QuietMisdreavus wrote:
> > > > zixuw wrote:
> > > > > What's the cost/would it worth it to wrap the `emplace_back`s and 
> > > > > `pop_back`s of `PathComponentContext` in meaningful APIs like 
> > > > > `enterPathComponentContext` and `exitPathComponentContext`?
> > > > > That way the code is more self-explanatory and easier to read. It 
> > > > > took me some time and mental resources to figure out why the 
> > > > > `pop_back` is placed here.
> > > > What's the use of having the `emplace_back` call inside 
> > > > `serializeAPIRecord` but to pop it outside? It seems like it's easier 
> > > > to mess up for new kinds of records.
> > > The reason to `emplace_back` the path component inside 
> > > `serializeAPIRecord` is that the `pathComponent` field of the `Record` is 
> > > serialized in there so you want to include the name of the symbol itself 
> > > in the path component list.
> > > The `pop_back` is delayed til all other additional serialization for a 
> > > specific kind of record, for example `serializeEnumRecord` handles all 
> > > the enum cases after processing the enum record itself using 
> > > `serializeAPIRecord`. So in order to correctly include the enum name in 
> > > the path components of all the enum cases, the enum name has to stay in 
> > > `PathComponentContext` until all members are serialized.
> > > 
> > > This is exactly the reason why I wanted a clearer API to make it easier 
> > > to see.
> > Hmm now that I thought about this, it seems that it would be easier to 
> > understand and avoid bugs if we lift 
> > `PathComponentContext.emplace_back`/`enterPathComponentContext` out of 
> > `serializeAPIRecord`, because we have access to the record name before that 
> > anyway.
> > 
> > So we establish a pre-condition of `serializeAPIRecord` that the correct 
> > path components would be set up in `PathComponentContext` before the call 
> > so we could still serialize the field inside that method. And in specific 
> > `serialize*Record` methods we push the record name, and pop out at the end.
> > 
> > This way the push and pop operations would appear in pairs in a single 
> > block, saving the confusion and mental work of jumping across functions to 
> > see how `PathComponentContext` is evolving.
> If you think we should have a specialized API I am happy to do this. I 
> figured it was self-explanatory by the name of `PathComponentContext` but it 
> clearly isn't so needs addressing. I put the `emplace_back` call in 
> `serializeAPIRecord` since all the specific serialization methods call it. I 
> thought it would make it impossible to forget to add them. @zixuw is correct 
> in the reason why the pop is outside we don't want to pop before we have 
> serialized the sub records by agree it is ugly and potentially error prone. I 
> can see three ways forward for improving the ergonomics of this since this 
> seems to be problematic:
> - Provide `serializeAPIRecord` a continuation to serialize the sub records or 
> additional fields, that way we can move the pop inside `serializeAPIRecord` I 
> am not a fan personally because we get into JS style closure hell if we start 
> doing this...
> - Use a visitor pattern where the visitor would be responsible for managing 
> `PathComponentContext` and do the appropriate push/pops in the `visit` 
> methods. We would need to add a APIRecordVisitor type, and appropriate visit 
> methods for each APIRecord. This would make sense because the records should 
> really know how to visit themselves.
> - Just add a specialized API although it seems it would really easy to forget 
> to remove path components.
> 
> Let me know what you think is the way forward.
Unless we go with the last option, I think this should be a follow up patch 
since it would a structural change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123045

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


[PATCH] D121375: [clang] NFC, move the utility function CompilerInvocation::setLangDefaults to LangOptions.h

2022-04-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

+1 to Duncan's comments, and a couple of nits while here.
Otherwise LG, will be nice to use this without pulling in the grab-bag that is 
Frontend.

In D121375#3428123 , @dexonsmith 
wrote:

> Also, the description doesn't talk about timeline for removing the wrapper. 
> Ideally we wouldn't leave behind the wrapper behind... just long enough that 
> you can migrate the callers and delete the old function in separate 
> incremental commit(s) (or if there are very few callers, all in this commit 
> would be fine, but I'm guessing that's not the case here). Or were you 
> thinking something else?

I only see one usage in-tree (and one more in clspv). And migration is very 
easy. I think you should do it all in this commit.




Comment at: clang/include/clang/Basic/LangOptions.h:517
+/// \param T - The target triple.
+/// \param Includes - The affected list of included files.
+/// \param LangStd - The input language standard.

while here: this param is non-obvious and this comment doesn't clarify much.
Maybe "If the language requires extra headers to be implicitly included, they 
will be appended to this list"



Comment at: clang/include/clang/Basic/LangOptions.h:519-521
+void setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T,
+ std::vector &Includes,
+ LangStandard::Kind LangStd);

dexonsmith wrote:
> I think this would be cleaner as:
> ```
> lang=c++
> class LangOpts {
> // ...
>   void setDefaults(Language Lang, const llvm::Triple &T, ...);
> };
> ```
> Or `setLangDefaults` or `setDefaultsFor` (I don't care about the name, just 
> feel like it makes more sense as a member function if we're updating all the 
> callers anyway).
> 
> Also, you should include a default for `LangStd` or it'll be hard to migrate 
> over callers.
I kind of like the idea that this logic is "layered above" the langopts struct 
itself. On the other hand making it a member makes it more discoverable and 
less surprising that LangOptions is actually an inout param (e.g. 
IncludeDefaultHeader). Either way is fine with me.



Comment at: clang/lib/Basic/LangOptions.cpp:104
+
+  if (LangStd == LangStandard::lang_unspecified) {
+// Based on the base language, pick one.

Pull this out into a separate function `getDefaultLangStandard(Language, const 
Triple&)`? (No need to expose it unless you want to, though I think it'll be 
helpful in future).

It seems bizarre that this depends on the triple, but obviously don't want to 
change that now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121375

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


[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 420446.
aaron.ballman added a comment.

Fixing the clangd include fixer unit tests.


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

https://reviews.llvm.org/D122983

Files:
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.c
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/ARCMT/objcmt-arc-cf-annotations.m
  clang/test/ARCMT/objcmt-arc-cf-annotations.m.result
  clang/test/Analysis/OSAtomic_mac.c
  clang/test/Analysis/ObjCProperties.m
  clang/test/Analysis/PR49642.c
  clang/test/Analysis/diagnostics/no-store-func-path-notes.c
  clang/test/Analysis/misc-ps-region-store.m
  clang/test/Analysis/novoidtypecrash.c
  clang/test/Analysis/plist-macros-with-expansion.c
  clang/test/CodeGen/2002-07-14-MiscTests3.c
  clang/test/CodeGen/2002-07-31-SubregFailure.c
  clang/test/CodeGen/2003-08-18-SigSetJmp.c
  clang/test/CodeGen/2004-11-27-StaticFunctionRedeclare.c
  clang/test/CodeGen/2005-01-02-ConstantInits.c
  clang/test/CodeGen/2005-01-02-VAArgError-ICE.c
  clang/test/CodeGen/2006-01-13-StackSave.c
  clang/test/CodeGen/2006-03-03-MissingInitializer.c
  clang/test/CodeGen/2008-05-12-TempUsedBeforeDef.c
  clang/test/CodeGen/2008-07-30-redef-of-bitcasted-decl.c
  clang/test/CodeGen/2008-08-19-cast-of-typedef.c
  clang/test/CodeGen/2008-10-13-FrontendCrash.c
  clang/test/CodeGen/PowerPC/builtins-ppc-p8vector.c
  clang/test/CodeGen/X86/bmi2-builtins.c
  clang/test/CodeGen/aarch64-mops.c
  clang/test/CodeGen/aarch64-neon-sm4-sm3.c
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGen/attribute_constructor.c
  clang/test/CodeGen/builtins-arm-microsoft.c
  clang/test/CodeGen/builtins-arm-msvc-compat-only.c
  clang/test/CodeGen/cast-emit.c
  clang/test/CodeGen/debug-info-block-vars.c
  clang/test/CodeGen/debug-info-crash.c
  clang/test/CodeGen/decl.c
  clang/test/CodeGen/init-with-member-expr.c
  clang/test/CodeGen/misaligned-param.c
  clang/test/CodeGen/neon-crypto.c
  clang/test/CodeGen/struct-comma.c
  clang/test/CodeGen/variable-array.c
  clang/test/Frontend/warning-mapping-2.c
  clang/test/Headers/arm-cmse-header-ns.c
  clang/test/Import/objc-arc/test-cleanup-object.m
  clang/test/Modules/config_macros.m
  clang/test/Modules/modulemap-locations.m
  clang/test/OpenMP/declare_mapper_messages.c
  clang/test/PCH/chain-macro-override.c
  clang/test/Rewriter/rewrite-foreach-2.m
  clang/test/Rewriter/rewrite-try-catch.m
  clang/test/Sema/__try.c
  clang/test/Sema/aarch64-tme-errors.c
  clang/test/Sema/arm-no-fp16.c
  clang/test/Sema/bitfield.c
  clang/test/Sema/builtin-setjmp.c
  clang/test/Sema/builtins.c
  clang/test/Sema/cxx-as-c.c
  clang/test/Sema/implicit-builtin-decl.c
  clang/test/Sema/implicit-decl.c
  clang/test/Sema/implicit-ms-builtin-decl.c
  clang/test/Sema/typo-correction.c
  clang/test/Sema/vla.c
  clang/test/Sema/warn-strict-prototypes.c
  clang/test/VFS/module_missing_vfs.m

Index: clang/test/VFS/module_missing_vfs.m
===
--- clang/test/VFS/module_missing_vfs.m
+++ clang/test/VFS/module_missing_vfs.m
@@ -1,12 +1,12 @@
 // RUN: rm -rf %t && mkdir -p %t
 // RUN: echo "void funcA(void);" >> %t/a.h
 
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml 2>&1 | FileCheck %s -check-prefix=ERROR
+// RUN: not %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml 2>&1 | FileCheck %s -check-prefix=ERROR
 // ERROR: virtual filesystem overlay file '{{.*}}' not found
 // RUN: find %t/mcp -name "A-*.pcm" | count 1
 
 // RUN: sed -e "s@INPUT_DIR@%{/S:regex_replacement}/Inputs@g" -e "s@OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/MissingVFS/vfsoverlay.yaml > %t/vfs.yaml
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml
+// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml
 // RUN: find %t/mcp -name "A-*.pcm" | count 1
 
 @import A;
Index: clang/test/Sema/warn-strict-prototypes.c
===
--- clang/test/Sema/warn-strict-prototypes.c
+++ clang/test/Sema/warn-strict-prototypes.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -Wno-implicit-function-declaration -verify %s
-// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -Wstrict-prototypes -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple i386-

[clang] b1f610f - [Test] Use cc1 interface in more tests (NFC)

2022-04-05 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-04-05T13:16:24+02:00
New Revision: b1f610fec54a0083f0086788c404484359a1a48e

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

LOG: [Test] Use cc1 interface in more tests (NFC)

There doesn't seem to be any particular reason why these tests use
the driver interface rather than the cc1 interface, which is
typically used in CodeGen tests.

Added: 


Modified: 
clang/test/CodeGen/bpf-attr-preserve-access-index-1.c
clang/test/CodeGen/bpf-attr-preserve-access-index-2.c
clang/test/CodeGen/bpf-attr-preserve-access-index-3.c
clang/test/CodeGen/bpf-attr-preserve-access-index-4.c
clang/test/CodeGen/bpf-attr-preserve-access-index-5.c
clang/test/CodeGen/bpf-attr-preserve-access-index-6.c
clang/test/CodeGen/bpf-attr-preserve-access-index-7.c
clang/test/CodeGen/bpf-attr-preserve-access-index-8.c
clang/test/CodeGen/bpf-inline-asm.c
clang/test/CodeGen/builtin-preserve-access-index-array.c
clang/test/CodeGen/builtin-preserve-access-index-nonptr.c
clang/test/CodeGen/builtin-preserve-access-index-typedef.c
clang/test/CodeGen/builtin-preserve-access-index.c
clang/test/CodeGen/builtins-bpf-preserve-field-info-1.c
clang/test/CodeGen/builtins-bpf-preserve-field-info-2.c
clang/test/CodeGen/builtins-bpf-preserve-field-info-3.c
clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
clang/test/CodeGen/builtinshufflevector2.c
clang/test/CodeGen/mips-constraints-mem.c
clang/test/CodeGen/mips-inline-asm-modifiers.c
clang/test/CodeGen/mips64-nontrivial-return.cpp

Removed: 




diff  --git a/clang/test/CodeGen/bpf-attr-preserve-access-index-1.c 
b/clang/test/CodeGen/bpf-attr-preserve-access-index-1.c
index 956b333f81520..babafeae34d78 100644
--- a/clang/test/CodeGen/bpf-attr-preserve-access-index-1.c
+++ b/clang/test/CodeGen/bpf-attr-preserve-access-index-1.c
@@ -1,5 +1,5 @@
 // REQUIRES: bpf-registered-target
-// RUN: %clang -target bpf -emit-llvm -S -g -Xclang -disable-llvm-passes %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple bpf -emit-llvm -debug-info-kind=limited 
-disable-llvm-passes %s -o - | FileCheck %s
 
 #define __reloc__ __attribute__((preserve_access_index))
 

diff  --git a/clang/test/CodeGen/bpf-attr-preserve-access-index-2.c 
b/clang/test/CodeGen/bpf-attr-preserve-access-index-2.c
index 8fe11e08c833f..1cea1d829e4b9 100644
--- a/clang/test/CodeGen/bpf-attr-preserve-access-index-2.c
+++ b/clang/test/CodeGen/bpf-attr-preserve-access-index-2.c
@@ -1,5 +1,5 @@
 // REQUIRES: bpf-registered-target
-// RUN: %clang -target bpf -emit-llvm -S -g -Xclang -disable-llvm-passes %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple bpf -emit-llvm -debug-info-kind=limited 
-disable-llvm-passes %s -o - | FileCheck %s
 
 #define __reloc__ __attribute__((preserve_access_index))
 

diff  --git a/clang/test/CodeGen/bpf-attr-preserve-access-index-3.c 
b/clang/test/CodeGen/bpf-attr-preserve-access-index-3.c
index f78e0b35c0b51..e917b5bde865c 100644
--- a/clang/test/CodeGen/bpf-attr-preserve-access-index-3.c
+++ b/clang/test/CodeGen/bpf-attr-preserve-access-index-3.c
@@ -1,5 +1,5 @@
 // REQUIRES: bpf-registered-target
-// RUN: %clang -target bpf -emit-llvm -S -g -Xclang -disable-llvm-passes %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple bpf -emit-llvm -debug-info-kind=limited 
-disable-llvm-passes %s -o - | FileCheck %s
 
 #define __reloc__ __attribute__((preserve_access_index))
 

diff  --git a/clang/test/CodeGen/bpf-attr-preserve-access-index-4.c 
b/clang/test/CodeGen/bpf-attr-preserve-access-index-4.c
index 6d3c44328c6ef..c9367e54e4541 100644
--- a/clang/test/CodeGen/bpf-attr-preserve-access-index-4.c
+++ b/clang/test/CodeGen/bpf-attr-preserve-access-index-4.c
@@ -1,5 +1,5 @@
 // REQUIRES: bpf-registered-target
-// RUN: %clang -target bpf -emit-llvm -S -g -Xclang -disable-llvm-passes %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple bpf -emit-llvm -debug-info-kind=limited 
-disable-llvm-passes %s -o - | FileCheck %s
 
 #define __reloc__ __attribute__((preserve_access_index))
 

diff  --git a/clang/test/CodeGen/bpf-attr-preserve-access-index-5.c 
b/clang/test/CodeGen/bpf-attr-preserve-access-index-5.c
index 286916a990e63..10a8cbc5dd61e 100644
--- a/clang/test/CodeGen/bpf-attr-preserve-access-index-5.c
+++ b/clang/test/CodeGen/bpf-attr-preserve-access-index-5.c
@@ -1,5 +1,5 @@
 // REQUIRES: bpf-registered-target
-// RUN: %clang -target bpf -emit-llvm -S -g -Xclang -disable-llvm-passes %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple bpf -emit-llvm -debug-info-kind=limited 
-disable-llvm-passes %s -o - | FileCheck %s
 
 #define __reloc__ __attribute__((preserve_access_index))
 

diff  --git a/clang/test/CodeGen/bpf-attr-preserve-access-index-6.c 
b/clang/test/CodeGen/bpf-attr-preserve-access-in

[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122983#3427518 , @xbolva00 wrote:

> Could you please check that https://github.com/llvm/llvm-test-suite is 
> buildable with your patch?

I gave it a shot just to see, but I'm unable to build it even without my patch:

  F:\source\test-suite-build>cmake --build . --clean-first
  Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  F:\source\test-suite-build\test-suite.sln : Solution file error MSB5004: The 
solution file has two projects named "pa
  thfinder".
  Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
  Copyright (C) Microsoft Corporation. All rights reserved.
  
[TEST_SUITE_HOST_CC] Compiling host source fpcmp.c
'cc' is not recognized as an internal or external command,
operable program or batch file.
  C:\Program Files (x86)\Microsoft Visual 
Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.target
  s(241,5): error MSB8066: Custom build for 
'F:\source\test-suite-build\CMakeFiles\a30a18e8f3bb5de504f740ee3822d8a0\fpc
  
mp.c.o.rule;F:\source\test-suite-build\CMakeFiles\a30a18e8f3bb5de504f740ee3822d8a0\fpcmp.rule;F:\source\test-suite-bu
  ild\CMakeFiles\22099cfe59041de58024b8c82a571139\build-fpcmp.rule' exited with 
code 9009. [F:\source\test-suite-build\
  tools\build-fpcmp.vcxproj]
[TEST_SUITE_HOST_CC] Compiling host source timeit.c
'cc' is not recognized as an internal or external command,
operable program or batch file.
  C:\Program Files (x86)\Microsoft Visual 
Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.target
  s(241,5): error MSB8066: Custom build for 
'F:\source\test-suite-build\CMakeFiles\a30a18e8f3bb5de504f740ee3822d8a0\tim
  
eit.c.o.rule;F:\source\test-suite-build\CMakeFiles\a30a18e8f3bb5de504f740ee3822d8a0\timeit.rule;F:\source\test-suite-
  build\CMakeFiles\22099cfe59041de58024b8c82a571139\build-timeit.rule' exited 
with code 9009. [F:\source\test-suite-bui
  ld\tools\build-timeit.vcxproj]
  cl : command line warning D9025: overriding '/W4' with '/w' 
[F:\source\test-suite-build\MicroBenchmarks\libs\benchmar
  k\third_party\googletest\build\googlemock\gmock_main.vcxproj]
  cl : command line error D8021: invalid numeric argument '/Werror=date-time' 
[F:\source\test-suite-build\MicroBenchmar
  ks\libs\benchmark\third_party\googletest\build\googlemock\gmock_main.vcxproj]
  cl : command line warning D9025: overriding '/W3' with '/w' 
[F:\source\test-suite-build\tools\fpcmp-target.vcxproj]
  cl : command line error D8021: invalid numeric argument '/Werror=date-time' 
[F:\source\test-suite-build\tools\fpcmp-t
  arget.vcxproj]
Generating sqlite test inputs
'TCL_TCLSH-NOTFOUND' is not recognized as an internal or external command,
operable program or batch file.
  C:\Program Files (x86)\Microsoft Visual 
Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.target
  s(241,5): error MSB8066: Custom build for 
'F:\source\test-suite-build\CMakeFiles\47602658443eaf701f82747ba4e9979c\tes
  t15.sql.rule' exited with code 9009. 
[F:\source\test-suite-build\MultiSource\Applications\sqlite3\sqlite_input.vcxpro
  j]
  cl : command line warning D9025: overriding '/W3' with '/w' 
[F:\source\test-suite-build\tools\timeit-target.vcxproj]
  cl : command line error D8021: invalid numeric argument '/Werror=date-time' 
[F:\source\test-suite-build\tools\timeit-
  target.vcxproj]

FWIW, this was how I configured, and that step did not generate any errors for 
me:

  cmake 
-DCMAKE_C_COMPILER=F:\source\llvm-project\llvm\out\build\x64-Debug\bin\clang.exe
 
-DCMAKE_CXX_COMPILER="F:\source\llvm-project\llvm\out\build\x64-Debug\bin\clang++.exe"
 -C..\test-suite\cmake\caches\O3.cmake -DTEST_SUITE_COLLECT_CODE_SIZE=OFF 
..\test-suite

So I'm not certain what's going on there.

In D122983#3427677 , 
@hubert.reinterpretcast wrote:

> In D122983#3426716 , @erichkeane 
> wrote:
>
>> We typically avoid doing -verify in CodeGen (unless the diagnostic is 
>> ACTUALLY in CodeGen) as a matter of business.
>
> I hope that `-verify` and `// expected-no-diagnostics` in CodeGen tests is 
> compatible with the above. I believe it is valuable to confirm that the test 
> itself is not written problematically.

Morally, yes, that's reasonable in CodeGen because you're ensuring you get no 
diagnostics. Practically, that's a convoluted, more expensive, less 
maintainable way to spell `-Werror` for the test. When diagnostics are 
introduced, this pattern encourages people to remove the `// 
expected-no-diagnostics` comment and start adding `// expected-warning {{}}` 
comments. Running the diagnostic verifier also slows down test execution 
because of the extra verification step (which adds up over thousands of tests).


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

[clang] f348ca5 - [Tests] Use %clang_cc1 instead of %clang -cc1 in codegen tests (NFC)

2022-04-05 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-04-05T13:21:44+02:00
New Revision: f348ca51c741580761e7ddefa1a8a0713494c20e

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

LOG: [Tests] Use %clang_cc1 instead of %clang -cc1 in codegen tests (NFC)

Added: 


Modified: 
clang/test/CodeGen/attr-noundef.cpp
clang/test/CodeGen/indirect-noundef.cpp
clang/test/CodeGen/label-array-aggregate-init.c
clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp
clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
clang/test/CodeGenOpenCL/ext-int-shift.cl

Removed: 




diff  --git a/clang/test/CodeGen/attr-noundef.cpp 
b/clang/test/CodeGen/attr-noundef.cpp
index 70b1f864b96ab..2f0e1899f61e3 100644
--- a/clang/test/CodeGen/attr-noundef.cpp
+++ b/clang/test/CodeGen/attr-noundef.cpp
@@ -1,11 +1,11 @@
-// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm %s -o - | 
FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
-// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm %s -o - | 
FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
-// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm 
-fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-INTEL
-// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm 
-fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-AARCH
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm %s -o - | 
FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang_cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm %s -o - | 
FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm 
-fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-INTEL
+// RUN: %clang_cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm 
-fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-AARCH
 
 // no-sanitize-memory-param-retval does NOT conflict with 
enable-noundef-analysis
-// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm 
-fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-INTEL
-// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm 
-fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-INTEL
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm 
-fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-INTEL
+// RUN: %clang_cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm 
-fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-INTEL
 
 // Passing structs by value
 // TODO: No structs may currently be marked noundef

diff  --git a/clang/test/CodeGen/indirect-noundef.cpp 
b/clang/test/CodeGen/indirect-noundef.cpp
index aa03bbfe74d5e..87f1658f4a7f5 100644
--- a/clang/test/CodeGen/indirect-noundef.cpp
+++ b/clang/test/CodeGen/indirect-noundef.cpp
@@ -1,9 +1,9 @@
-// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -o - 
%s | FileCheck %s
-// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm 
-fsanitize-memory-param-retval -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -o - 
%s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm 
-fsanitize-memory-param-retval -o - %s | FileCheck %s
 
 // no-sanitize-memory-param-retval does NOT conflict with 
enable-noundef-analysis
-// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm 
-fno-sanitize-memory-param-retval -o - %s | FileCheck %s
-// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm 
-fno-sanitize-memory-param-retval -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm 
-fno-sanitize-memory-param-retval -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm 
-fno-sanitize-memory-param-retval -o - %s | FileCheck %s
 
 union u1 {
   int val;

diff  --git a/clang/test/CodeGen/label-array-aggregate-init.c 
b/clang/test/CodeGen/label-array-aggregate-init.c
index 48c7e1c727381..cc1571d44d5f4 100644
--- a/clang/test/CodeGen/label-array-aggregate-init.c
+++ b/clang/test/CodeGen/label-array-aggregate-init.c
@@ -1,4 +1,4 @@
-// RUN: %clang -cc1 -triple x86_64-windows-msvc -emit-llvm %s -o - | FileCheck 
%s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm %s -o - | FileCheck 
%s
 
 // CHE

[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-05 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 420451.
dang added a comment.

Address code review feedback:

- Fix the function signature serialization
- Typo fix of "m to ",


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123045

Files:
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/enum.c
  clang/test/ExtractAPI/global_record.c
  clang/test/ExtractAPI/global_record_multifile.c
  clang/test/ExtractAPI/language.c
  clang/test/ExtractAPI/macro_undefined.c
  clang/test/ExtractAPI/macros.c
  clang/test/ExtractAPI/objc_interface.m
  clang/test/ExtractAPI/objc_protocol.m
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- clang/test/ExtractAPI/struct.c
+++ clang/test/ExtractAPI/struct.c
@@ -48,7 +48,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "memberOf",
   "source": "c:@S@Color@FI@Red",
@@ -72,6 +72,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -112,8 +113,10 @@
 "identifier": "c.struct"
   },
   "location": {
-"character": 8,
-"line": 2,
+"position": {
+  "character": 8,
+  "line": 2
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -124,9 +127,13 @@
   }
 ],
 "title": "Color"
-  }
+  },
+  "pathComponents": [
+"Color"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -151,8 +158,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 3,
+"position": {
+  "character": 12,
+  "line": 3
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -163,9 +172,14 @@
   }
 ],
 "title": "Red"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Red"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -190,8 +204,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 4,
+"position": {
+  "character": 12,
+  "line": 4
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -202,9 +218,14 @@
   }
 ],
 "title": "Green"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Green"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -229,8 +250,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 5,
+"position": {
+  "character": 12,
+  "line": 5
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -241,9 +264,14 @@
   }
 ],
 "title": "Blue"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Blue"
+  ]
 },
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "typeIdentifier",
@@ -285,8 +313,10 @@
 "identifier": "c.property"
   },
   "location": {
-"character": 12,
-"line": 7,
+"position": {
+  "character": 12,
+  "line": 7
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -297,7 +327,11 @@
   }
 ],
 "title": "Alpha"
-  }
+  },
+  "pathComponents": [
+"Color",
+"Alpha"
+  ]
 }
   ]
 }
Index: clang/test/ExtractAPI/objc_protocol.m
===
--- clang/test/ExtractAPI/objc_protocol.m
+++ clang/test/ExtractAPI/objc_protocol.m
@@ -45,7 +45,7 @@
   "vendor": "apple"
 }
   },
-  "relationhips": [
+  "relationships": [
 {
   "kind": "conformsTo",
   "source": "c:objc(pl)AnotherProtocol",
@@ -54,6 +54,7 @@
   ],
   "symbols": [
 {
+  "accessLevel": "public",
   "declarationFragments": [
 {
   "kind": "keyword",
@@ -77,8 +78,10 @@
 "identifier": "objective-c.protocol"
   },
   "location": {
-"character": 11,
-"line": 1,
+"position": {
+  "character": 11,
+  "line": 1
+},
 "uri": "file://INPUT_DIR/input.h"
   },
   "names": {
@@ -89,9 +92,13 @@
   }
 ],
 "title": "Protocol"
-  }
+  },
+  "pathComponents": [
+ 

[PATCH] D122954: [clang] Extend target_clones tests to exercise declarations that are not definitions.

2022-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122954#3427676 , @tahonermann 
wrote:

>> but I DO have the opposite problem: Figuring out what the associated tests 
>> are for a patch
>
> I also have that issue, but I don't see the relevance here. The changes in 
> D122958  that fixes the issues revealed by 
> these tests includes the test updates. So that commit reveals exactly which 
> tests are relevant.
>
>> It loses my ability to make sure that your patch covers all of the cases 
>> that are important, and it loses my ability to figure out what the patch is 
>> doing from the test itself.
>
> I'm not following here. There are two distinct issues; a testing gap that is 
> addressed by this review, and a code issue that is addressed by D122958 
> . Addressing these separately is good 
> separation of concerns. Should there be additional tests of declarations that 
> are not definitions? If so, that would be appropriate to discuss in this 
> review?
>
>> this actually disables a LOT of other tests. So in the 'meantime' between 
>> the two patches, we are actually losing test coverage thanks to the 'XFAIL'.
>
> I do see `XFAIL` used for such temporary purposes based on a quick review of 
> `git log`. See commit 9001168cf8b8c85ec9af9b91756b39d2da0130bf 
>  for 
> example. I've used this approach elsewhere for many years.
>
>> I want the patch to be making one logical change so that it remains 
>> manageable to review, but it needs to be completely self-contained 
>> (functional changes, docs, tests, et al) even if that makes the patch a bit 
>> bigger.
>
> I strongly agree; that is exactly why these commits are split as they are. 
> Both this review and D122958  are 
> self-contained.
>
>> This is especially important because it makes it far easier to revert 
>> problematic commits -- if the functional change has an issue, having to 
>> separately revert several other related commits is a burden.
>
> I agree that would be a burden, but it isn't the case here.

I disagree. If I need to roll back D122958 , 
that means I also need to roll back other changes in the stack because they 
rely on the ones in the first patch. Alternatively, if the changes aren't 
related, then use of a patch stack is perhaps not appropriate (then the reviews 
should be independent, not interdependent).

>> It also makes git blame more useful when doing code archeology; you can git 
>> blame a test to get to the functional changes more quickly.
>
> That is exactly what this separation enables. `git blame` on the tests will 
> get you both the change for the testing gap as well as the functional change 
> that fixes the behavior.

Again, I disagree. This separation means when I do a `git blame`, I'll get a 
commit somewhere in the patch stack. Then I have to go look at the review to 
find out there were related commits. (This is not hypothetical -- I've run into 
this frustration a few times in recent history and each time it's been either a 
patch stack or a follow-up commit due to built bot breakage.) It's a minor 
annoyance because I can still find the information I need to find, but it's 
worth keeping in mind.

This may be a cultural thing, but personally, I find patch stacks to be really 
difficult to review when they're as split apart as this one has been. It's not 
that your approach isn't defensible -- you've obviously put thought into this! 
For me, what makes it hard is that I read the code and I go "where's the test 
associated with this change" or "I wonder if they thought about this edge 
case", and with patch stacks like this, that involves an easter egg hunt 
because your thought process to get to the final state may take different paths 
than mine. And when I am looking at a review in the "middle" of the patch 
stack, like this one, it gets even harder. In order to understand the context 
for these test changes, I have to go find four other things first and keep 
*all* of that context in mind. Eventually, what I wind up doing is opening up a 
browser tab for each patch in the stack and tab between them when I need 
context. It's not ideal, but it gets the job done.

In this particular case, the start of the patch stack has functional changes, 
followed by three NFC changes, followed by this change to test cases. If the 
previous three patches truly are NFC, then there's no reason why this change to 
just the tests shouldn't be rolled into the original functional change *or* be 
rolled into the next patch that has functional changes intended to fix this 
test. (From looking at the patch stack, I'd have expected 2-3 reviews, not 7)

This isn't to admonish or discourage you from using patch stacks to help split 
logical things up, but it is to caution against splitting things too much 
be

[PATCH] D122155: Add warning when eval-method is set in the presence of value unsafe floating-point calculations.

2022-04-05 Thread Zahira Ammarguellat via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d165ad7d9b3: In fast-math mode, when unsafe math 
optimizations are enabled, the (authored by zahiraam).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122155

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/test/CodeGen/X86/32bit-behavior.c
  clang/test/Driver/eval-method-with-unsafe-math.c
  clang/test/Sema/eval-method-with-unsafe-math.c

Index: clang/test/Sema/eval-method-with-unsafe-math.c
===
--- /dev/null
+++ clang/test/Sema/eval-method-with-unsafe-math.c
@@ -0,0 +1,56 @@
+// RUN: not %clang_cc1 -fexperimental-strict-floating-point \
+// RUN: -triple x86_64-linux-gnu  \
+// RUN: -verify %s 2>&1 | FileCheck %s --check-prefixes=CHECK-PRGM
+
+// RUN: not %clang_cc1 -fexperimental-strict-floating-point \
+// RUN: -triple x86_64-linux-gnu  -freciprocal-math \
+// RUN: -verify %s 2>&1 | FileCheck %s --check-prefixes=CHECK-RECPR,CHECK-PRGM
+
+// RUN: not %clang_cc1 -fexperimental-strict-floating-point \
+// RUN: -triple x86_64-linux-gnu  -mreassociate \
+// RUN: -verify %s 2>&1 | FileCheck %s --check-prefixes=CHECK-ASSOC,CHECK-PRGM
+
+// RUN: not %clang_cc1 -fexperimental-strict-floating-point \
+// RUN: -triple x86_64-linux-gnu  -fapprox-func \
+// RUN: -verify %s 2>&1 | FileCheck %s --check-prefixes=CHECK-FUNC,CHECK-PRGM
+
+// RUN: not %clang_cc1 -fexperimental-strict-floating-point \
+// RUN: -triple x86_64-linux-gnu -freciprocal-math -mreassociate -verify \
+// RUN: %s 2>&1 | FileCheck %s --check-prefixes=CHECK-ASSOC,CHECK-RECPR,CHECK-PRGM
+
+// RUN: not %clang_cc1 -fexperimental-strict-floating-point \
+// RUN: -triple x86_64-linux-gnu -freciprocal-math -mreassociate -fapprox-func \
+// RUN: -verify %s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=CHECK-FUNC,CHECK-ASSOC,CHECK-RECPR,CHECK-PRGM
+
+// RUN: not %clang_cc1 -fexperimental-strict-floating-point \
+// RUN: -triple x86_64-linux-gnu -ffp-eval-method=source \
+// RUN: -verify %s 2>&1 | FileCheck %s --check-prefixes=CHECK-FFP-OPT,CHECK-PRGM
+
+// expected-no-diagnostics
+
+float f1(float a, float b, float c) {
+  a = b + c;
+  return a * b + c;
+}
+
+float f2(float a, float b, float c) {
+  // CHECK-FFP-OPT: option 'ffp-eval-method' cannot be used with '#pragma clang fp reassociate'
+#pragma clang fp reassociate(on)
+  return (a + b) + c;
+}
+
+float f3(float a, float b, float c) {
+#pragma clang fp reassociate(off)
+  return (a - b) - c;
+}
+
+float f4(float a, float b, float c) {
+#pragma clang fp eval_method(double)
+  // CHECK-FUNC: '#pragma clang fp eval_method' cannot be used with option 'fapprox-func'
+  // CHECK-ASSOC: '#pragma clang fp eval_method' cannot be used with option 'mreassociate'
+  // CHECK-RECPR: '#pragma clang fp eval_method' cannot be used with option 'freciprocal'
+  // CHECK-PRGM: '#pragma clang fp eval_method' cannot be used with '#pragma clang fp reassociate'
+#pragma clang fp reassociate(on)
+  return (a * c) - (b * c);
+}
Index: clang/test/Driver/eval-method-with-unsafe-math.c
===
--- /dev/null
+++ clang/test/Driver/eval-method-with-unsafe-math.c
@@ -0,0 +1,29 @@
+// RUN: not %clang -Xclang -fexperimental-strict-floating-point \
+// RUN: -Xclang -triple -Xclang x86_64-linux-gnu -fapprox-func \
+// RUN: -Xclang -verify -ffp-eval-method=source %s 2>&1  \
+// RUN: | FileCheck %s --check-prefixes=CHECK-FUNC
+
+// RUN: not %clang -Xclang -fexperimental-strict-floating-point \
+// RUN: -Xclang -triple -Xclang x86_64-linux-gnu -Xclang -mreassociate \
+// RUN: -ffp-eval-method=source -Xclang -verify %s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=CHECK-ASSOC
+
+// RUN: not %clang -Xclang -fexperimental-strict-floating-point \
+// RUN: -Xclang -triple -Xclang x86_64-linux-gnu -Xclang -freciprocal-math \
+// RUN: -ffp-eval-method=source -Xclang -verify %s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=CHECK-RECPR
+
+// RUN: not %clang -Xclang -fexperimental-strict-floating-point \
+// RUN: -Xclang -triple -Xclang x86_64-linux-gnu -Xclang -freciprocal-math \
+// RUN: -Xclang -mreassociate -ffp-eval-method=source -Xclang -verify %s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=CHECK-ASSOC,CHECK-RECPR
+
+// RUN: not %clang -Xclang -fexperimental-strict-floating-point \
+// RUN: -Xclang -triple -Xclang x86_64-linux-gnu -Xclang -freciprocal-math \
+// RUN: -Xclang -mreassociate -fapprox-func -ffp-eval-method=source \
+// RUN: -Xclang -verify %s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=CHECK-ASSOC,CHECK-RECPR,CHECK-FUNC
+
+// CHECK-FUNC: (frontend): option 'ffp-eval-method' cannot be used with option 'fapprox-func'
+// CHECK-ASSOC: (frontend): option 'ffp-eval-method' canno

[clang] 4d165ad - In fast-math mode, when unsafe math optimizations are enabled, the

2022-04-05 Thread Zahira Ammarguellat via cfe-commits

Author: Zahira Ammarguellat
Date: 2022-04-05T04:58:19-07:00
New Revision: 4d165ad7d9b3395a59c287ef60542b4de3a4d95a

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

LOG: In fast-math mode, when unsafe math optimizations are enabled, the
compiler is allowed to use optimizations that allow reassociation and
transformations that don’t guaranty accuracy.
For example (x+y)+z is transformed into x+(y+z) . Although
mathematically equivalent, these two expressions may not lead to the
same final result due to errors of summation.
Or x/x is transformed into 1.0 but x could be 0.0, INF or NaN. And so
this transformation also may not lead to the same final result.
Setting the eval method 'ffp-eval-method' or via '#pragma clang fp
eval_method' in this mode, doesn’t have any effect.
This patch adds code to warn the user of this.

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

Added: 
clang/test/Driver/eval-method-with-unsafe-math.c
clang/test/Sema/eval-method-with-unsafe-math.c

Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaAttr.cpp
clang/test/CodeGen/X86/32bit-behavior.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index eacb7e4de0ead..afc166b5d087a 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -48,6 +48,10 @@ def warn_fe_backend_unsupported_fp_exceptions : Warning<
 "overriding currently unsupported use of floating point exceptions "
 "on this target">, InGroup;
 
+def err_incompatible_fp_eval_method_options : Error<
+"option 'ffp-eval-method' cannot be used with option "
+"%select{'fapprox-func'|'mreassociate'|'freciprocal'}0">;
+
 def remark_fe_backend_optimization_remark : Remark<"%0">, BackendInfo,
 InGroup;
 def remark_fe_backend_optimization_remark_missed : Remark<"%0">, BackendInfo,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index aec172c39ed9a..c5171359e7e4c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6491,6 +6491,10 @@ def warn_floatingpoint_eq : Warning<
   "comparing floating point with == or != is unsafe">,
   InGroup>, DefaultIgnore;
 
+def err_setting_eval_method_used_in_unsafe_context : Error <
+  "%select{'#pragma clang fp eval_method'|option 'ffp-eval-method'}0 cannot be 
used with "
+  "%select{option 'fapprox-func'|option 'mreassociate'|option 
'freciprocal'|option 'ffp-eval-method'|'#pragma clang fp reassociate'}1">;
+
 def warn_remainder_division_by_zero : Warning<
   "%select{remainder|division}0 by zero is undefined">,
   InGroup;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f8fd3a2900237..91adacdee3ad7 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -503,6 +503,22 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
 Diags.Report(diag::warn_ignored_hip_only_option)
 << 
Args.getLastArg(OPT_gpu_max_threads_per_block_EQ)->getAsString(Args);
 
+  // When these options are used, the compiler is allowed to apply
+  // optimizations that may affect the final result. For example
+  // (x+y)+z is transformed to x+(y+z) but may not give the same
+  // final result; it's not value safe.
+  // Another example can be to simplify x/x to 1.0 but x could be 0.0, INF
+  // or NaN. Final result may then 
diff er. An error is issued when the eval
+  // method is set with one of these options.
+  if (Args.hasArg(OPT_ffp_eval_method_EQ)) {
+if (LangOpts.ApproxFunc)
+  Diags.Report(diag::err_incompatible_fp_eval_method_options) << 0;
+if (LangOpts.AllowFPReassoc)
+  Diags.Report(diag::err_incompatible_fp_eval_method_options) << 1;
+if (LangOpts.AllowRecip)
+  Diags.Report(diag::err_incompatible_fp_eval_method_options) << 2;
+  }
+
   // -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0.
   // This option should be deprecated for CL > 1.0 because
   // this option was added for compatibility with OpenCL 1.0.

diff  --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 9e94136ce76d0..113b3ac89f463 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -486,6 +486,12 @@ void Sema::ActOnPragmaFPEvalMethod(SourceLocation Loc,
 NewFPFeatures.setFPEvalMethodOverride(LangOptions::FEM_Extended);
 break;
   }
+  if (getLangOpts().ApproxFunc)
+Diag(Loc, diag::err_set

[PATCH] D122808: [clang] Fix warnings when `-Wdeprecated-enum-enum-conversion` is enabled

2022-04-05 Thread Antonio Frighetto via Phabricator via cfe-commits
antoniofrighetto updated this revision to Diff 420458.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

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

https://reviews.llvm.org/D122808

Files:
  clang/include/clang/AST/DeclarationName.h
  llvm/include/llvm/ADT/STLExtras.h


Index: llvm/include/llvm/ADT/STLExtras.h
===
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -203,6 +203,16 @@
 template 
 using TypeAtIndex = std::tuple_element_t>;
 
+/// Helper which adds two underlying types of enumeration type.
+template ,
+  std::underlying_type_t>,
+  typename UT2 = std::enable_if_t,
+  std::underlying_type_t>>
+constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS) {
+  return static_cast(LHS) + static_cast(RHS);
+}
+
 
//===--===//
 // Extra additions to 
 
//===--===//
Index: clang/include/clang/AST/DeclarationName.h
===
--- clang/include/clang/AST/DeclarationName.h
+++ clang/include/clang/AST/DeclarationName.h
@@ -21,6 +21,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include 
@@ -192,6 +193,13 @@
 "The various classes that DeclarationName::Ptr can point to"
 " must be at least aligned to 8 bytes!");
 
+  static_assert(
+  std::is_same,
+   std::underlying_type_t<
+   detail::DeclarationNameExtra::ExtraKind>>::value,
+  "The various enums used to compute values for NameKind should "
+  "all have the same underlying type");
+
 public:
   /// The kind of the name stored in this DeclarationName.
   /// The first 7 enumeration values are stored inline and correspond
@@ -205,15 +213,18 @@
 CXXDestructorName = StoredCXXDestructorName,
 CXXConversionFunctionName = StoredCXXConversionFunctionName,
 CXXOperatorName = StoredCXXOperatorName,
-CXXDeductionGuideName = UncommonNameKindOffset +
-
detail::DeclarationNameExtra::CXXDeductionGuideName,
-CXXLiteralOperatorName =
-UncommonNameKindOffset +
-detail::DeclarationNameExtra::CXXLiteralOperatorName,
-CXXUsingDirective = UncommonNameKindOffset +
-detail::DeclarationNameExtra::CXXUsingDirective,
-ObjCMultiArgSelector = UncommonNameKindOffset +
-   detail::DeclarationNameExtra::ObjCMultiArgSelector
+CXXDeductionGuideName = llvm::addEnumValues(
+UncommonNameKindOffset,
+detail::DeclarationNameExtra::CXXDeductionGuideName),
+CXXLiteralOperatorName = llvm::addEnumValues(
+UncommonNameKindOffset,
+detail::DeclarationNameExtra::CXXLiteralOperatorName),
+CXXUsingDirective =
+llvm::addEnumValues(UncommonNameKindOffset,
+detail::DeclarationNameExtra::CXXUsingDirective),
+ObjCMultiArgSelector =
+llvm::addEnumValues(UncommonNameKindOffset,
+
detail::DeclarationNameExtra::ObjCMultiArgSelector),
   };
 
 private:


Index: llvm/include/llvm/ADT/STLExtras.h
===
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -203,6 +203,16 @@
 template 
 using TypeAtIndex = std::tuple_element_t>;
 
+/// Helper which adds two underlying types of enumeration type.
+template ,
+  std::underlying_type_t>,
+  typename UT2 = std::enable_if_t,
+  std::underlying_type_t>>
+constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS) {
+  return static_cast(LHS) + static_cast(RHS);
+}
+
 //===--===//
 // Extra additions to 
 //===--===//
Index: clang/include/clang/AST/DeclarationName.h
===
--- clang/include/clang/AST/DeclarationName.h
+++ clang/include/clang/AST/DeclarationName.h
@@ -21,6 +21,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include 
@@ -192,6 +193,13 @@
 "The various classes that DeclarationName::Ptr can point to"
 " must be at least aligned to 8 bytes!");
 
+  static_assert(
+  std::is_same

[PATCH] D120662: [clang-offload-bundler] add -input/-output options

2022-04-05 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added subscribers: saiislam, ronlieb.
ronlieb added a comment.

@saiislam  for awareness


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120662

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


[PATCH] D123070: [Driver][NFC] Simplify handling of flags in Options.td

2022-04-05 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a subscriber: jansvoboda11.
awarzynski added a comment.
This revision is now accepted and ready to land.

Thanks for doing this, Emil!

This is a much appreciated clean-up. On quite a few occasions I got confused 
with the nested `let` statements. With this change, everyone should find it 
easier to identify precisely what flags are effectively set for a particular 
option.

> There are probably a developer or two on the clang side that ought to have a 
> say on this.

I agree that we should try to reach as many reviewers as possible. 
@jansvoboda11 was kind enough to review some changes for me in the past. I'll 
also ping Discourse. But I think that you should go ahead with this even there 
no more reviewers :) It's an NFC and a clear improvement compared to what we 
have now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123070

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


[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 420462.
kbobyrev marked 4 inline comments as done.
kbobyrev added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -1578,15 +1578,22 @@
 }
 
 TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
-  CollectorOpts.CollectIncludePath = true;
-  CanonicalIncludes Includes;
-  Includes.addMapping(TestHeaderName, "");
-  CollectorOpts.Includes = &Includes;
   auto IncFile = testPath("test.inc");
   auto IncURI = URI::create(IncFile).toString();
   InMemoryFileSystem->addFile(IncFile, 0,
   llvm::MemoryBuffer::getMemBuffer("class X {};"));
-  runSymbolCollector("#include \"test.inc\"\nclass Y {};", /*Main=*/"",
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  std::string HeaderCode = "#include \"test.inc\"\nclass Y {};";
+  InMemoryFileSystem->addFile(TestHeaderName, 0,
+  llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+  auto File = Files->getFile(TestHeaderName);
+  ASSERT_TRUE(File);
+  CanonicalIncludes Includes;
+  Includes.addMapping((*File)->getLastRef(), "");
+  CollectorOpts.CollectIncludePath = true;
+  CollectorOpts.Includes = &Includes;
+  runSymbolCollector(HeaderCode, /*Main=*/"",
  /*ExtraArgs=*/{"-I", testRoot()});
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -6,14 +6,31 @@
 //
 //===--===//
 
+#include "TestFS.h"
 #include "index/CanonicalIncludes.h"
+#include "clang/Basic/FileEntry.h"
+#include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+FileEntryRef
+addFile(llvm::IntrusiveRefCntPtr &FS,
+FileManager &FM, llvm::StringRef Filename) {
+  FS->addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(""));
+  auto File = FM.getFileRef(Filename);
+  EXPECT_THAT_EXPECTED(File, llvm::Succeeded());
+  return *File;
+}
+
 TEST(CanonicalIncludesTest, CStandardLibrary) {
   CanonicalIncludes CI;
   auto Language = LangOptions();
@@ -40,29 +57,52 @@
   // iosfwd declares some symbols it doesn't own.
   EXPECT_EQ("", CI.mapSymbol("std::ostream"));
   // And (for now) we assume it owns the others.
-  EXPECT_EQ("", CI.mapHeader("iosfwd"));
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  FileManager Files(FileSystemOptions(), InMemFS);
+  auto File = addFile(InMemFS, Files, testPath("iosfwd"));
+  EXPECT_EQ("", CI.mapHeader(File));
 }
 
 TEST(CanonicalIncludesTest, PathMapping) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  FileManager Files(FileSystemOptions(), InMemFS);
+  std::string BarPath = testPath("foo/bar");
+  auto Bar = addFile(InMemFS, Files, BarPath);
+  auto Other = addFile(InMemFS, Files, testPath("foo/baz"));
   // As used for IWYU pragmas.
   CanonicalIncludes CI;
-  CI.addMapping("foo/bar", "");
+  CI.addMapping(Bar, "");
 
-  EXPECT_EQ("", CI.mapHeader("foo/bar"));
-  EXPECT_EQ("", CI.mapHeader("bar/bar"));
+  // We added a mapping for baz.
+  EXPECT_EQ("", CI.mapHeader(Bar));
+  // Other file doesn't have a mapping.
+  EXPECT_EQ("", CI.mapHeader(Other));
+
+  // Add hard link to "foo/bar" and check that it is also mapped to , hence
+  // does not depend on the header name.
+  std::string HardLinkPath = testPath("hard/link");
+  InMemFS->addHardLink(HardLinkPath, BarPath);
+  auto HardLinkFile = Files.getFileRef(HardLinkPath);
+  ASSERT_THAT_EXPECTED(HardLinkFile, llvm::Succeeded());
+  EXPECT_EQ("", CI.mapHeader(*HardLinkFile));
 }
 
 TEST(CanonicalIncludesTest, Precedence) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  FileManager Files(FileSystemOptions(), InMemFS);
+  auto File = addFile(InMemF

[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Just nits




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:359
 if (Entry) {
-  auto PublicHeader = CanonIncludes.mapHeader(Entry->getName());
+  auto PublicHeader = CanonIncludes.mapHeader(Entry->getLastRef());
   if (!PublicHeader.empty()) {

getLastRef().getName() is just the same as Entry->getName().
We should be using SM.getFileEntryRefForID instead.

(Which is actually still not preserving the FERef under the hood, but will 
soon...)



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.h:40
+  /// Adds a file-to-string mapping from \p ID to \p CanonicalPath.
+  void addMapping(const FileEntryRef Header, llvm::StringRef CanonicalPath);
 

no const, FileEntryRef is passed by value (and below)



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:384
 if (Includes) {
-  llvm::StringRef Canonical = Includes->mapHeader(Filename);
+  llvm::StringRef Canonical = Includes->mapHeader(FE->getLastRef());
   if (!Canonical.empty()) {

again, avoid getLastRef



Comment at: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp:26
+FileEntryRef
+addFile(llvm::IntrusiveRefCntPtr &FS,
+FileManager &FM, llvm::StringRef Filename) {

no need to take ownership, just take InMemoryFileSystem&?



Comment at: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp:1593
+  CanonicalIncludes Includes;
+  Includes.addMapping((*File)->getLastRef(), "");
+  CollectorOpts.CollectIncludePath = true;

avoid getLastRef


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

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


[PATCH] D122404: [clang][AArc64][SVE] Add support for comparison operators on SVE types

2022-04-05 Thread David Truby via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4be1ec9fb5ca: [clang][AArc64][SVE] Add support for 
comparison operators on SVE types (authored by DavidTruby).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122404

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-compare-ops.c
  clang/test/Sema/aarch64-sve-vector-compare-ops.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -212,12 +212,6 @@
 
   local_int8 << init_int8; // expected-error {{invalid operands to binary expression}}
   local_int8 >> init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 < init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 == init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 != init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 > init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
 
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -200,12 +200,6 @@
 
   local_int8 << init_int8; // expected-error {{invalid operands to binary expression}}
   local_int8 >> init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 < init_int8;  // expected-error {{invalid operands to binary expression}}
-  local_int8 <= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 == init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 != init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 >= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 > init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}}
 
Index: clang/test/Sema/aarch64-sve-vector-compare-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-compare-ops.c
@@ -0,0 +1,761 @@
+// RUN: %clang_cc1 -verify -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -fsyntax-only %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+void eq(svint8_t i8, svint16_t i16, svint32_t i32, svint64_t i64,
+svuint8_t u8, svuint16_t u16, svuint32_t u32, svuint64_t u64,
+svfloat16_t f16, svfloat32_t f32, svfloat64_t f64,
+svbool_t b) {
+  (void)(i8 == b);   // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == i16); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == i32); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == i64); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == u16); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == u32); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == u64); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == f16); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == f32); // expected-error{{invalid operands to binary expression}}
+  (void)(i8 == f64); // expected-error{{invalid operands to binary expression}}
+
+  (void)(u8 == b);   // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == i16); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == i32); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == i64); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == u16); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == u32); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == u64); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == f16); // expected-error{{invalid operands to binary expression}}
+  (void)(u8 == f32); // expecte

[clang] 4be1ec9 - [clang][AArc64][SVE] Add support for comparison operators on SVE types

2022-04-05 Thread David Truby via cfe-commits

Author: David Truby
Date: 2022-04-05T13:56:27+01:00
New Revision: 4be1ec9fb5ca59fce923d8a5a3fcb3c40a2884de

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

LOG: [clang][AArc64][SVE] Add support for comparison operators on SVE types

Comparison operators on SVE types return a signed integer vector
of the same width as the incoming SVE type. This matches the existing
behaviour for NEON types.

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

Added: 
clang/test/CodeGen/aarch64-sve-vector-compare-ops.c
clang/test/Sema/aarch64-sve-vector-compare-ops.c

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/sizeless-1.c
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c0ad55d52bb31..5ec03391e287b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11976,9 +11976,13 @@ class Sema final {
bool AllowBothBool, bool AllowBoolConversion,
bool AllowBoolOperation, bool ReportInvalid);
   QualType GetSignedVectorType(QualType V);
+  QualType GetSignedSizelessVectorType(QualType V);
   QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
   SourceLocation Loc,
   BinaryOperatorKind Opc);
+  QualType CheckSizelessVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
+  SourceLocation Loc,
+  BinaryOperatorKind Opc);
   QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
   SourceLocation Loc);
 

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index ec9da20f0fbf7..0711c993088bc 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1390,8 +1390,8 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value 
*Src, QualType SrcType,
 
   if (isa(SrcTy) || isa(DstTy)) {
 // Allow bitcast from vector to integer/fp of the same size.
-unsigned SrcSize = SrcTy->getPrimitiveSizeInBits();
-unsigned DstSize = DstTy->getPrimitiveSizeInBits();
+llvm::TypeSize SrcSize = SrcTy->getPrimitiveSizeInBits();
+llvm::TypeSize DstSize = DstTy->getPrimitiveSizeInBits();
 if (SrcSize == DstSize)
   return Builder.CreateBitCast(Src, DstTy, "conv");
 

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index c0a1ffcdb1b44..375bd2ec59c26 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -50,8 +50,10 @@
 #include "clang/Sema/Template.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/SaveAndRestore.h"
+#include "llvm/Support/TypeSize.h"
 
 using namespace clang;
 using namespace sema;
@@ -12153,6 +12155,10 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, 
ExprResult &RHS,
   RHS.get()->getType()->isVectorType())
 return CheckVectorCompareOperands(LHS, RHS, Loc, Opc);
 
+  if (LHS.get()->getType()->isVLSTBuiltinType() ||
+  RHS.get()->getType()->isVLSTBuiltinType())
+return CheckSizelessVectorCompareOperands(LHS, RHS, Loc, Opc);
+
   diagnoseLogicalNotOnLHSofCheck(*this, LHS, RHS, Loc, Opc);
   diagnoseTautologicalComparison(*this, Loc, LHS.get(), RHS.get(), Opc);
 
@@ -12614,6 +12620,18 @@ QualType Sema::GetSignedVectorType(QualType V) {
VectorType::GenericVector);
 }
 
+QualType Sema::GetSignedSizelessVectorType(QualType V) {
+  const BuiltinType *VTy = V->castAs();
+  assert(VTy->isSizelessBuiltinType() && "expected sizeless type");
+
+  const QualType ETy = V->getSveEltType(Context);
+  const auto TypeSize = Context.getTypeSize(ETy);
+
+  const QualType IntTy = Context.getIntTypeForBitwidth(TypeSize, true);
+  const llvm::ElementCount VecSize = Context.getBuiltinVectorTypeInfo(VTy).EC;
+  return Context.getScalableVectorType(IntTy, VecSize.getKnownMinValue());
+}
+
 /// CheckVectorCompareOperands - vector comparisons are a clang extension that
 /// operates on extended vector types.  Instead of producing an IntTy result,
 /// like a scalar comparison, a vector comparison produces a vector of integer
@@ -12680,6 +12698,48 @@ QualType Sema::CheckVectorCompareOperands(ExprResult 
&LHS, ExprResult &RHS,
   return GetSignedVectorType(vType);
 }
 
+QualType Sema::CheckSizelessVectorCompareOperands(ExprResult &LHS,
+  ExprResult &RHS,
+   

[PATCH] D123032: [clang][dataflow] Exclude protobuf types from modeling in the environment.

2022-04-05 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked an inline comment as done.
ymandel added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:513
+  const RecordDecl *RD = BaseTy->getDecl();
+  if (RD->getIdentifier() == nullptr || RD->getName() != "Message")
+return false;

xazax.hun wrote:
> Not sure how often is this invoked but we could reduce the number of string 
> comparisons by caching the identifier ptr and do a pointer comparison.
Good question. It means an extra comparison for each type until the pointer is 
cached (to check if the cache is set) and then, afterwards, 2 comparisons vs 
~10 for the common case where the class name is doesn't match. In the matching 
case, though, it is clearly saving much more.

For proto-heavy code, it seems a win, and a loss otherwise.  But, the question 
is where to put the cache. It seems to me best to move this to be a method on 
DataflowAnalysisContext (since it is a global, not local env, property) and 
make the cached pointer a private member of DAC.

Thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123032

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


[PATCH] D122954: [clang] Extend target_clones tests to exercise declarations that are not definitions.

2022-04-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D122954#3427676 , @tahonermann 
wrote:

>> but I DO have the opposite problem: Figuring out what the associated tests 
>> are for a patch
>
> I also have that issue, but I don't see the relevance here. The changes in 
> D122958  that fixes the issues revealed by 
> these tests includes the test updates. So that commit reveals exactly which 
> tests are relevant.

The only relationship between the two from the web interface is that you tell 
me that, or I go through other links.  If I have to swap tabs between tests and 
code, I lose context, or they get separated.

>> It loses my ability to make sure that your patch covers all of the cases 
>> that are important, and it loses my ability to figure out what the patch is 
>> doing from the test itself.
>
> I'm not following here. There are two distinct issues; a testing gap that is 
> addressed by this review, and a code issue that is addressed by D122958 
> . Addressing these separately is good 
> separation of concerns. Should there be additional tests of declarations that 
> are not definitions? If so, that would be appropriate to discuss in this 
> review?

DURING review the addition of tests that the thing changes/fixes being in the 
same review make the mental load less.

>> this actually disables a LOT of other tests. So in the 'meantime' between 
>> the two patches, we are actually losing test coverage thanks to the 'XFAIL'.
>
> I do see `XFAIL` used for such temporary purposes based on a quick review of 
> `git log`. See commit 9001168cf8b8c85ec9af9b91756b39d2da0130bf 
>  for 
> example. I've used this approach elsewhere for many years.

This XFAIL mechanism is very rarely used in the CFE for this purpose.  It is 
usually more to disable flakey tests or tests that were broken during another 
patch (or even broken thanks to the but not yet fixed. No matter where you've 
used this approach before, your strategy here is both not common in the Clang 
community, AND you have your two reviewers asking you politely to stop.  
Frankly, 'review presentation' is for the comfort of the reviewer, not the 
submitter.

>> I want the patch to be making one logical change so that it remains 
>> manageable to review, but it needs to be completely self-contained 
>> (functional changes, docs, tests, et al) even if that makes the patch a bit 
>> bigger.
>
> I strongly agree; that is exactly why these commits are split as they are. 
> Both this review and D122958  are 
> self-contained.

This one is actually NOT all that self contained (it disables a ton of 
otherwise functioning tests), and D122958  
doesn't include addition lines of the tests that it affects.  It actually 
enables a bunch of tests that worked/behaved correctly even before it. The 
association between them is vague/unclear.

>> This is especially important because it makes it far easier to revert 
>> problematic commits -- if the functional change has an issue, having to 
>> separately revert several other related commits is a burden.
>
> I agree that would be a burden, but it isn't the case here.
>
>> It also makes git blame more useful when doing code archeology; you can git 
>> blame a test to get to the functional changes more quickly.
>
> That is exactly what this separation enables. `git blame` on the tests will 
> get you both the change for the testing gap as well as the functional change 
> that fixes the behavior.

As someone who has done a TON of code archeology, your strategy here makes it 
significantly harder in my experience. Which, in part, is why I'm so against 
it.  From my perspective and experience, this strategy makes Reviews HARDER and 
archeology HARDER with no decernable benefit to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122954

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


[PATCH] D123037: [clang][dataflow] Support integral casts

2022-04-05 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 420483.
ymandel marked an inline comment as done.
ymandel added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123037

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1900,10 +1900,97 @@
 const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooVal =
-cast(Env.getValue(*FooDecl, SkipPast::None));
-const auto *BarVal =
-cast(Env.getValue(*BarDecl, SkipPast::None));
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
+EXPECT_EQ(FooVal, BarVal);
+  });
+}
+
+TEST_F(TransferTest, IntegralCast) {
+  std::string Code = R"(
+void target(int Foo) {
+  long Bar = Foo;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
+EXPECT_EQ(FooVal, BarVal);
+  });
+}
+
+TEST_F(TransferTest, IntegraltoBooleanCast) {
+  std::string Code = R"(
+void target(int Foo) {
+  bool Bar = Foo;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
+  });
+}
+
+TEST_F(TransferTest, IntegralToBooleanCastFromBool) {
+  std::string Code = R"(
+void target(bool Foo) {
+  int Zab = Foo;
+  bool Bar = Zab;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
 EXPECT_EQ(FooVal, BarVal);
   });
 }
@@ -2394,6 +2481,35 @@
   });
 }
 
+// `__builtin_expect` takes and returns a `long` argument, so other types
+// involve casts. This verifies that we identify the input and output in that
+// case.
+TEST_F(TransferTest, BuiltinExpectBoolArg) {
+  std::string Code = R"(
+void target(bool Foo) {
+  bool Bar = __builtin_expect(Foo, true);
+  /*[[p]]*/
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const auto &Env = Results[0].second.Env;
+
+   

[PATCH] D123037: [clang][dataflow] Support integral casts

2022-04-05 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked an inline comment as done.
ymandel added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:1904
-const auto *FooVal =
-cast(Env.getValue(*FooDecl, SkipPast::None));
-const auto *BarVal =

sgatev wrote:
> Why not assert the type of the value in this test and in `IntegralCast` below?
Sure, but went with an ASSERT, since it gives better error messages when it 
fails (rather than cast, which will crash the test).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123037

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


[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

2022-04-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, martong, mgorny.
Herald added a reviewer: shafik.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: ilya-biryukov.
Herald added projects: clang, clang-tools-extra.

This is template version of https://reviews.llvm.org/D114251.

This patch introduces a new sugar template name (UsingTemplateName), which 
stores
the found using-shadow decl and underlying template name. With the new
template name, we can be able to find the using decl that a template
typeloc (TemplateSpecializationTypeLoc) found its underlying template,
which is useful for tooling use cases (include cleaner etc).

This patch merely focuses on adding the node to the AST.
Next steps:

- add ast matchers for matching different kinds of template names.
- update the clangd and other tools to use this new node.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123127

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Tooling/CMakeLists.txt
  clang/test/AST/ast-dump-using-template.cpp
  clang/tools/libclang/CIndex.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -890,6 +890,18 @@
  functionDecl(hasDescendant(usingDecl(hasName("bar");
 }
 
+TEST_P(ImportDecl, ImportUsingTemplate) {
+  MatchVerifier Verifier;
+  testImport("namespace ns { template  struct S {}; }"
+ "template  class T> class X {};"
+ "void declToImport() {"
+ "using ns::S;  X xi; }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ functionDecl(
+ hasDescendant(varDecl(hasTypeLoc(templateSpecializationTypeLoc(
+ hasAnyTemplateArgumentLoc(templateArgumentLoc(;
+}
+
 TEST_P(ImportDecl, ImportUsingEnumDecl) {
   MatchVerifier Verifier;
   testImport("namespace foo { enum bar { baz, toto, quux }; }"
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1472,6 +1472,9 @@
 return Visit(MakeCursorTemplateRef(
 Name.getAsSubstTemplateTemplateParmPack()->getParameterPack(), Loc,
 TU));
+  case TemplateName::UsingTemplate:
+return VisitTemplateName(Name.getAsUsingTemplateName()->getUnderlying(),
+ Loc);
   }
 
   llvm_unreachable("Invalid TemplateName::Kind!");
Index: clang/test/AST/ast-dump-using-template.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-using-template.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -ast-dump %s | FileCheck -strict-whitespace %s
+
+namespace ns {
+template class S {
+ public:
+   S(T);
+};
+}
+using ns::S;
+
+// TemplateName in TemplateSpecializationType.
+template
+using A = S;
+// CHECK:  TypeAliasDecl
+// CHECK-NEXT: `-TemplateSpecializationType {{.*}} 'S' dependent using S
+
+// TemplateName in TemplateArgument.
+template  class T> class X {};
+using B = X;
+// CHECK:  TypeAliasDecl
+// CHECK-NEXT: `-TemplateSpecializationType {{.*}} 'X' sugar X
+// CHECK-NEXT:   |-TemplateArgument using template S
+// CHECK-NEXT: `-RecordType {{.*}} 'X'
+// CHECK-NEXT:   `-ClassTemplateSpecialization {{.*}} 'X'
+
+// TemplateName in DeducedTemplateSpecializationType.
+S DeducedTemplateSpecializationT(123);
+using C = decltype(DeducedTemplateSpecializationT);
+// CHECK:  DecltypeType {{.*}}
+// CHECK-NEXT:  |-DeclRefExpr {{.*}}
+// CHECK-NEXT:  `-DeducedTemplateSpecializationType {{.*}} 'ns::S' sugar using
Index: clang/lib/Tooling/CMakeLists.txt
===
--- clang/lib/Tooling/CMakeLists.txt
+++ clang/lib/Tooling/CMakeLists.txt
@@ -59,7 +59,7 @@
   COMMAND
   $
 # Skip this in debug mode because parsing AST.h is too slow
---skip-processing=${skip_expensive_processing}
+--skip-processing=1
 -I ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION}/include
 -I ${CLANG_SOURCE_DIR}/include
 -I ${LLVM_BINARY_DI

[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 420488.
aaron.ballman added a comment.

Fixing more precommit CI failures. The `ScudoWrappersCTest.MallocInfo` do not 
appear to be caused by this patch, however.


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

https://reviews.llvm.org/D122983

Files:
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-implicits.c
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/ARCMT/objcmt-arc-cf-annotations.m
  clang/test/ARCMT/objcmt-arc-cf-annotations.m.result
  clang/test/Analysis/OSAtomic_mac.c
  clang/test/Analysis/ObjCProperties.m
  clang/test/Analysis/PR49642.c
  clang/test/Analysis/diagnostics/no-store-func-path-notes.c
  clang/test/Analysis/misc-ps-region-store.m
  clang/test/Analysis/novoidtypecrash.c
  clang/test/Analysis/plist-macros-with-expansion.c
  clang/test/CodeGen/2002-07-14-MiscTests3.c
  clang/test/CodeGen/2002-07-31-SubregFailure.c
  clang/test/CodeGen/2003-08-18-SigSetJmp.c
  clang/test/CodeGen/2004-11-27-StaticFunctionRedeclare.c
  clang/test/CodeGen/2005-01-02-ConstantInits.c
  clang/test/CodeGen/2005-01-02-VAArgError-ICE.c
  clang/test/CodeGen/2006-01-13-StackSave.c
  clang/test/CodeGen/2006-03-03-MissingInitializer.c
  clang/test/CodeGen/2008-05-12-TempUsedBeforeDef.c
  clang/test/CodeGen/2008-07-30-redef-of-bitcasted-decl.c
  clang/test/CodeGen/2008-08-19-cast-of-typedef.c
  clang/test/CodeGen/2008-10-13-FrontendCrash.c
  clang/test/CodeGen/PowerPC/builtins-ppc-p8vector.c
  clang/test/CodeGen/X86/bmi2-builtins.c
  clang/test/CodeGen/aarch64-mops.c
  clang/test/CodeGen/aarch64-neon-sm4-sm3.c
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGen/attribute_constructor.c
  clang/test/CodeGen/builtins-arm-microsoft.c
  clang/test/CodeGen/builtins-arm-msvc-compat-only.c
  clang/test/CodeGen/cast-emit.c
  clang/test/CodeGen/debug-info-block-vars.c
  clang/test/CodeGen/debug-info-crash.c
  clang/test/CodeGen/decl.c
  clang/test/CodeGen/init-with-member-expr.c
  clang/test/CodeGen/misaligned-param.c
  clang/test/CodeGen/neon-crypto.c
  clang/test/CodeGen/struct-comma.c
  clang/test/CodeGen/variable-array.c
  clang/test/Frontend/warning-mapping-2.c
  clang/test/Headers/arm-cmse-header-ns.c
  clang/test/Import/objc-arc/test-cleanup-object.m
  clang/test/Modules/config_macros.m
  clang/test/Modules/modulemap-locations.m
  clang/test/OpenMP/declare_mapper_messages.c
  clang/test/PCH/chain-macro-override.c
  clang/test/Rewriter/rewrite-foreach-2.m
  clang/test/Rewriter/rewrite-try-catch.m
  clang/test/Sema/__try.c
  clang/test/Sema/aarch64-tme-errors.c
  clang/test/Sema/arm-no-fp16.c
  clang/test/Sema/bitfield.c
  clang/test/Sema/builtin-setjmp.c
  clang/test/Sema/builtins.c
  clang/test/Sema/cxx-as-c.c
  clang/test/Sema/implicit-builtin-decl.c
  clang/test/Sema/implicit-decl.c
  clang/test/Sema/implicit-ms-builtin-decl.c
  clang/test/Sema/typo-correction.c
  clang/test/Sema/vla.c
  clang/test/Sema/warn-strict-prototypes.c
  clang/test/VFS/module_missing_vfs.m
  compiler-rt/test/safestack/pthread-cleanup.c

Index: compiler-rt/test/safestack/pthread-cleanup.c
===
--- compiler-rt/test/safestack/pthread-cleanup.c
+++ compiler-rt/test/safestack/pthread-cleanup.c
@@ -17,6 +17,8 @@
   return buffer;
 }
 
+extern unsigned sleep(unsigned seconds);
+
 int main(int argc, char **argv)
 {
   int arg = atoi(argv[1]);
Index: clang/test/VFS/module_missing_vfs.m
===
--- clang/test/VFS/module_missing_vfs.m
+++ clang/test/VFS/module_missing_vfs.m
@@ -1,12 +1,12 @@
 // RUN: rm -rf %t && mkdir -p %t
 // RUN: echo "void funcA(void);" >> %t/a.h
 
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml 2>&1 | FileCheck %s -check-prefix=ERROR
+// RUN: not %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml 2>&1 | FileCheck %s -check-prefix=ERROR
 // ERROR: virtual filesystem overlay file '{{.*}}' not found
 // RUN: find %t/mcp -name "A-*.pcm" | count 1
 
 // RUN: sed -e "s@INPUT_DIR@%{/S:regex_replacement}/Inputs@g" -e "s@OUT_DIR@%{/t:regex_replacement}@g" %S/Inputs/MissingVFS/vfsoverlay.yaml > %t/vfs.yaml
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml
+// RUN: %clang_cc1 -std=c99 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/mcp -I %S/Inputs/MissingVFS %s -fsyntax-only -ivfsoverlay %t/vfs.yaml
 // RUN: find %t/mcp -name "A-*.pcm" | count 1
 
 @import A;
Index: clang/test/

[clang] 54c5033 - [clang] Document p1703 not needed

2022-04-05 Thread Nathan Sidwell via cfe-commits

Author: Nathan Sidwell
Date: 2022-04-05T06:54:31-07:00
New Revision: 54c50336e4c11e9c9255d96ae0b55a56cc193ecb

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

LOG: [clang] Document p1703 not needed

We list p1703 as unimplemented, but it is subsumed by p1857.

Reviewed By: tbaeder

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

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 3fcf7a3a27cae..47a6fdb1e4466 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1176,10 +1176,11 @@ C++20 implementation status
   
   
 https://wg21.link/p1811r0";>P1811R0
-No
+No
   
   
 https://wg21.link/p1703r1";>P1703R1
+Subsumed by P1857
   

 https://wg21.link/p1874r1";>P1874R1



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


[PATCH] D123120: [clang] Document p1703 not needed

2022-04-05 Thread Nathan Sidwell via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54c50336e4c1: [clang] Document p1703 not needed (authored by 
urnathan).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D123120?vs=420457&id=420493#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123120

Files:
  clang/www/cxx_status.html


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1176,10 +1176,11 @@
   
   
 https://wg21.link/p1811r0";>P1811R0
-No
+No
   
   
 https://wg21.link/p1703r1";>P1703R1
+Subsumed by P1857
   

 https://wg21.link/p1874r1";>P1874R1


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1176,10 +1176,11 @@
   
   
 https://wg21.link/p1811r0";>P1811R0
-No
+No
   
   
 https://wg21.link/p1703r1";>P1703R1
+Subsumed by P1857
   

 https://wg21.link/p1874r1";>P1874R1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d002495 - [clang][dataflow] Support integral casts

2022-04-05 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-04-05T13:55:32Z
New Revision: d002495b949c1d0d2db22605f134d722a39637fa

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

LOG: [clang][dataflow] Support integral casts

Adds support for implicit casts `CK_IntegralCast` and `CK_IntegralToBoolean`.

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 271167b90030d..a1a6025312db9 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -199,6 +199,22 @@ class TransferVisitor : public 
ConstStmtVisitor {
 assert(SubExpr != nullptr);
 
 switch (S->getCastKind()) {
+case CK_IntegralToBoolean: {
+  // This cast creates a new, boolean value from the integral value. We
+  // model that with a fresh value in the environment, unless it's already 
a
+  // boolean.
+  auto &Loc = Env.createStorageLocation(*S);
+  Env.setStorageLocation(*S, Loc);
+  if (auto *SubExprVal = dyn_cast_or_null(
+  Env.getValue(*SubExpr, SkipPast::Reference)))
+Env.setValue(Loc, *SubExprVal);
+  else
+// FIXME: If integer modeling is added, then update this code to create
+// the boolean based on the integer model.
+Env.setValue(Loc, Env.makeAtomicBoolValue());
+  break;
+}
+
 case CK_LValueToRValue: {
   auto *SubExprVal = Env.getValue(*SubExpr, SkipPast::Reference);
   if (SubExprVal == nullptr)
@@ -209,6 +225,13 @@ class TransferVisitor : public 
ConstStmtVisitor {
   Env.setValue(ExprLoc, *SubExprVal);
   break;
 }
+
+case CK_IntegralCast:
+  // FIXME: This cast creates a new integral value from the
+  // subexpression. But, because we don't model integers, we don't
+  // distinguish between this new value and the underlying one. If integer
+  // modeling is added, then update this code to create a fresh location 
and
+  // value.
 case CK_UncheckedDerivedToBase:
 case CK_ConstructorConversion:
 case CK_UserDefinedConversion:

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 2fa5be182eea5..32beab89a18be 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1900,10 +1900,97 @@ TEST_F(TransferTest, StaticCast) {
 const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooVal =
-cast(Env.getValue(*FooDecl, SkipPast::None));
-const auto *BarVal =
-cast(Env.getValue(*BarDecl, SkipPast::None));
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
+EXPECT_EQ(FooVal, BarVal);
+  });
+}
+
+TEST_F(TransferTest, IntegralCast) {
+  std::string Code = R"(
+void target(int Foo) {
+  long Bar = Foo;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
+EXPECT_EQ(FooVal, BarVal);
+  });
+}
+
+TEST_F(TransferTest, IntegraltoBooleanCast) {
+  std::string Code = R"(
+void target(int Foo) {
+  bool Bar = Foo;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *Fo

[PATCH] D123037: [clang][dataflow] Support integral casts

2022-04-05 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd002495b949c: [clang][dataflow] Support integral casts 
(authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123037

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1900,10 +1900,97 @@
 const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooVal =
-cast(Env.getValue(*FooDecl, SkipPast::None));
-const auto *BarVal =
-cast(Env.getValue(*BarDecl, SkipPast::None));
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
+EXPECT_EQ(FooVal, BarVal);
+  });
+}
+
+TEST_F(TransferTest, IntegralCast) {
+  std::string Code = R"(
+void target(int Foo) {
+  long Bar = Foo;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
+EXPECT_EQ(FooVal, BarVal);
+  });
+}
+
+TEST_F(TransferTest, IntegraltoBooleanCast) {
+  std::string Code = R"(
+void target(int Foo) {
+  bool Bar = Foo;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
+  });
+}
+
+TEST_F(TransferTest, IntegralToBooleanCastFromBool) {
+  std::string Code = R"(
+void target(bool Foo) {
+  int Zab = Foo;
+  bool Bar = Zab;
+  // [[p]]
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, ElementsAre(Pair("p", _)));
+const Environment &Env = Results[0].second.Env;
+
+const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ASSERT_THAT(FooDecl, NotNull());
+
+const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
+ASSERT_THAT(BarDecl, NotNull());
+
+const auto *FooVal = Env.getValue(*FooDecl, SkipPast::None);
+const auto *BarVal = Env.getValue(*BarDecl, SkipPast::None);
+EXPECT_TRUE(isa(FooVal));
+EXPECT_TRUE(isa(BarVal));
 EXPECT_EQ(FooVal, BarVal);
   });
 }
@@ -2394,6 +2481,35 @@
   });
 }
 
+// `__builtin_expect` takes and returns a `long` argument, so other types
+// involve casts. This verifies that we identify the input and output in that
+// case.
+TEST_F(TransferTest, BuiltinExpectBoolArg) {
+  std::string Code = R"(
+void target(bool Foo) {
+  bool Bar = __builtin_expect(Foo, true);
+  /*[[p]]*/
+}
+  )";
+  runDataflow(Code,
+  [](llvm::ArrayRef<
+ std::pair>>
+ Results,
+ ASTContext &ASTCtx) {
+ASSERT_THAT(Results, Elem

[PATCH] D123070: [Driver][NFC] Simplify handling of flags in Options.td

2022-04-05 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.

Thank you for working on this!

I you haven't already, I suggest you test this change by dumping all TableGen 
records in the backend and comparing the before and after. When working on 
`Options.td`, I found it quite easy to introduce small differences that don't 
cause test failures on my machine, but may become observable on other 
configurations.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123070

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


[PATCH] D122661: [Clang] Do not warn on unused lifetime-extending vars with side effects...

2022-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:1893-1894
+const Expr *Init = VD->getInit();
+if (const ExprWithCleanups *Cleanups =
+dyn_cast_or_null(Init))
+  Init = Cleanups->getSubExpr();





Comment at: clang/lib/Sema/SemaDecl.cpp:1901
 if (const TypedefType *TT = Ty->getAs()) {
+  // White-list anything with an __attribute__((unused)) type.
   if (TT->getDecl()->hasAttr())





Comment at: clang/lib/Sema/SemaDecl.cpp:1908-1909
+// extension.
+if (const MaterializeTemporaryExpr *MTE =
+dyn_cast_or_null(Init)) {
+  if (MTE->getExtendingDecl()) {





Comment at: clang/test/SemaCXX/warn-unused-variables.cpp:275-278
+template 
+void foo(T &t) {
+  const auto &extended = S{t};
+}

I think the difference between Clang and GCC here is that GCC only diagnoses 
when this function is instantiated: https://godbolt.org/z/f6ddacT97

How do we behave when we instantiate it?

Also, what happens with the test case as-written in the bug report:
```
struct RAIIWrapper {
RAIIWrapper();
~RAIIWrapper();
};

void foo() {
auto const  guard = RAIIWrapper();
auto const& guard2 = RAIIWrapper();
auto && guard3 = RAIIWrapper();
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122661

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


[PATCH] D122808: [clang] Fix warnings when `-Wdeprecated-enum-enum-conversion` is enabled

2022-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks! This is heading in the right direction. You should also add some test 
coverage to `llvm/unittests/ADT/STLExtrasTests.cpp` for the new interface.




Comment at: llvm/include/llvm/ADT/STLExtras.h:207-211
+template ,
+  std::underlying_type_t>,
+  typename UT2 = std::enable_if_t,
+  std::underlying_type_t>>

Oops, but `is_enum_v<>` is C++17 and up, and we currently still require only 
C++14, so this will have to use the long-hand form (precommit CI was failing 
because of this).


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

https://reviews.llvm.org/D122808

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


[PATCH] D122766: [clang] Use forward slash as the path separator for Windows in __FILE__, __builtin_FILE(), and std::source_location

2022-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122766#3419303 , @hans wrote:

> Maybe Martin or Aaron have opinions here too?

Naively, this seems wrong to me. Yes, Windows sometimes allows you to use 
forward slashes, but that is not the path separator which Windows users are 
most often presented with in terms of documentation, screen shots, presentation 
in Explorer, etc. My feeling is that the default behavior on Windows needs to 
be to use backslashes and not forward slashes. Having an option to canonicalize 
in the other direction would be reasonable, as does differing what the default 
is based on the target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122766

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


[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 420500.
kbobyrev marked 5 inline comments as done.
kbobyrev added a comment.

Fix the test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock-matchers.h"
 #include "gmock/gmock-more-matchers.h"
 #include "gmock/gmock.h"
@@ -1578,15 +1579,22 @@
 }
 
 TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
-  CollectorOpts.CollectIncludePath = true;
-  CanonicalIncludes Includes;
-  Includes.addMapping(TestHeaderName, "");
-  CollectorOpts.Includes = &Includes;
   auto IncFile = testPath("test.inc");
   auto IncURI = URI::create(IncFile).toString();
   InMemoryFileSystem->addFile(IncFile, 0,
   llvm::MemoryBuffer::getMemBuffer("class X {};"));
-  runSymbolCollector("#include \"test.inc\"\nclass Y {};", /*Main=*/"",
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  std::string HeaderCode = "#include \"test.inc\"\nclass Y {};";
+  InMemoryFileSystem->addFile(TestHeaderName, 0,
+  llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+  auto File = Files->getFileRef(TestHeaderName);
+  ASSERT_THAT_EXPECTED(File, llvm::Succeeded());
+  CanonicalIncludes Includes;
+  Includes.addMapping(*File, "");
+  CollectorOpts.CollectIncludePath = true;
+  CollectorOpts.Includes = &Includes;
+  runSymbolCollector(HeaderCode, /*Main=*/"",
  /*ExtraArgs=*/{"-I", testRoot()});
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -6,14 +6,30 @@
 //
 //===--===//
 
+#include "TestFS.h"
 #include "index/CanonicalIncludes.h"
+#include "clang/Basic/FileEntry.h"
+#include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+FileEntryRef addFile(llvm::vfs::InMemoryFileSystem &FS, FileManager &FM,
+ llvm::StringRef Filename) {
+  FS.addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(""));
+  auto File = FM.getFileRef(Filename);
+  EXPECT_THAT_EXPECTED(File, llvm::Succeeded());
+  return *File;
+}
+
 TEST(CanonicalIncludesTest, CStandardLibrary) {
   CanonicalIncludes CI;
   auto Language = LangOptions();
@@ -40,29 +56,52 @@
   // iosfwd declares some symbols it doesn't own.
   EXPECT_EQ("", CI.mapSymbol("std::ostream"));
   // And (for now) we assume it owns the others.
-  EXPECT_EQ("", CI.mapHeader("iosfwd"));
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  FileManager Files(FileSystemOptions(), InMemFS);
+  auto File = addFile(*InMemFS, Files, testPath("iosfwd"));
+  EXPECT_EQ("", CI.mapHeader(File));
 }
 
 TEST(CanonicalIncludesTest, PathMapping) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  FileManager Files(FileSystemOptions(), InMemFS);
+  std::string BarPath = testPath("foo/bar");
+  auto Bar = addFile(*InMemFS, Files, BarPath);
+  auto Other = addFile(*InMemFS, Files, testPath("foo/baz"));
   // As used for IWYU pragmas.
   CanonicalIncludes CI;
-  CI.addMapping("foo/bar", "");
+  CI.addMapping(Bar, "");
 
-  EXPECT_EQ("", CI.mapHeader("foo/bar"));
-  EXPECT_EQ("", CI.mapHeader("bar/bar"));
+  // We added a mapping for baz.
+  EXPECT_EQ("", CI.mapHeader(Bar));
+  // Other file doesn't have a mapping.
+  EXPECT_EQ("", CI.mapHeader(Other));
+
+  // Add hard link to "foo/bar" and check that it is also mapped to , hence
+  // does not depend on the header name.
+  std::string HardLinkPath = testPath("hard/link");
+  InMemFS->addHardLink(HardLinkPath, BarPath);
+  auto HardLinkFile = Files.g

[clang-tools-extra] 3de4d5e - [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2022-04-05T16:27:54+02:00
New Revision: 3de4d5e6dd66165057439c69b6a03e7001ec03e0

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

LOG: [clangd] Use stable keys for CanonicalIncludes mappings

This patch switches CanonicalInclude mappings to use `llvm::sys::fs::UniqueID` 
for a stable file representation because the `FileEntry::getName()` results 
turn out to be changing throughout the lifetime of a program (exposed in 
D120306). This patch makes it possible for D120306 to be re-landed and 
increases overall stability.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/index/CanonicalIncludes.cpp
clang-tools-extra/clangd/index/CanonicalIncludes.h
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp 
b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index ce02f97bb7d8c..3d40219616eca 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -8,7 +8,9 @@
 
 #include "CanonicalIncludes.h"
 #include "Headers.h"
+#include "clang/Basic/FileEntry.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem/UniqueID.h"
 #include "llvm/Support/Path.h"
 #include 
 
@@ -18,18 +20,17 @@ namespace {
 const char IWYUPragma[] = "// IWYU pragma: private, include ";
 } // namespace
 
-void CanonicalIncludes::addMapping(llvm::StringRef Path,
+void CanonicalIncludes::addMapping(FileEntryRef Header,
llvm::StringRef CanonicalPath) {
-  FullPathMapping[Path] = std::string(CanonicalPath);
+  FullPathMapping[Header.getUniqueID()] = std::string(CanonicalPath);
 }
 
 /// The maximum number of path components in a key from StdSuffixHeaderMapping.
 /// Used to minimize the number of lookups in suffix path mappings.
 constexpr int MaxSuffixComponents = 3;
 
-llvm::StringRef CanonicalIncludes::mapHeader(llvm::StringRef Header) const {
-  assert(!Header.empty());
-  auto MapIt = FullPathMapping.find(Header);
+llvm::StringRef CanonicalIncludes::mapHeader(FileEntryRef Header) const {
+  auto MapIt = FullPathMapping.find(Header.getUniqueID());
   if (MapIt != FullPathMapping.end())
 return MapIt->second;
 
@@ -39,10 +40,11 @@ llvm::StringRef 
CanonicalIncludes::mapHeader(llvm::StringRef Header) const {
   int Components = 1;
 
   // FIXME: check that this works on Windows and add tests.
-  for (auto It = llvm::sys::path::rbegin(Header),
-End = llvm::sys::path::rend(Header);
+  auto Filename = Header.getName();
+  for (auto It = llvm::sys::path::rbegin(Filename),
+End = llvm::sys::path::rend(Filename);
It != End && Components <= MaxSuffixComponents; ++It, ++Components) {
-auto SubPath = Header.substr(It->data() - Header.begin());
+auto SubPath = Filename.substr(It->data() - Filename.begin());
 auto MappingIt = StdSuffixHeaderMapping->find(SubPath);
 if (MappingIt != StdSuffixHeaderMapping->end())
   return MappingIt->second;
@@ -66,12 +68,12 @@ collectIWYUHeaderMaps(CanonicalIncludes *Includes) {
PP.getSourceManager(), PP.getLangOpts());
   if (!Text.consume_front(IWYUPragma))
 return false;
+  auto &SM = PP.getSourceManager();
   // We always insert using the spelling from the pragma.
-  if (auto *FE = PP.getSourceManager().getFileEntryForID(
-  PP.getSourceManager().getFileID(Range.getBegin(
-Includes->addMapping(FE->getName(), isLiteralInclude(Text)
-? Text.str()
-: ("\"" + Text + "\"").str());
+  if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
+Includes->addMapping(
+FE->getLastRef(),
+isLiteralInclude(Text) ? Text.str() : ("\"" + Text + "\"").str());
   return false;
 }
 

diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.h 
b/clang-tools-extra/clangd/index/CanonicalIncludes.h
index 747c3f1309573..c3ac9c3b80623 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.h
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.h
@@ -19,9 +19,11 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_CANONICALINCLUDES_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_CANONICALINCLUDES_H
 
+#include "clang/Basic/FileEntry.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem/UniqueID.h"
 #incl

[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3de4d5e6dd66: [clangd] Use stable keys for CanonicalIncludes 
mappings (authored by kbobyrev).

Changed prior to commit:
  https://reviews.llvm.org/D123031?vs=420500&id=420503#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock-matchers.h"
 #include "gmock/gmock-more-matchers.h"
 #include "gmock/gmock.h"
@@ -1578,15 +1579,22 @@
 }
 
 TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
-  CollectorOpts.CollectIncludePath = true;
-  CanonicalIncludes Includes;
-  Includes.addMapping(TestHeaderName, "");
-  CollectorOpts.Includes = &Includes;
   auto IncFile = testPath("test.inc");
   auto IncURI = URI::create(IncFile).toString();
   InMemoryFileSystem->addFile(IncFile, 0,
   llvm::MemoryBuffer::getMemBuffer("class X {};"));
-  runSymbolCollector("#include \"test.inc\"\nclass Y {};", /*Main=*/"",
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  std::string HeaderCode = "#include \"test.inc\"\nclass Y {};";
+  InMemoryFileSystem->addFile(TestHeaderName, 0,
+  llvm::MemoryBuffer::getMemBuffer(HeaderCode));
+  auto File = Files->getFileRef(TestHeaderName);
+  ASSERT_THAT_EXPECTED(File, llvm::Succeeded());
+  CanonicalIncludes Includes;
+  Includes.addMapping(*File, "");
+  CollectorOpts.CollectIncludePath = true;
+  CollectorOpts.Includes = &Includes;
+  runSymbolCollector(HeaderCode, /*Main=*/"",
  /*ExtraArgs=*/{"-I", testRoot()});
   EXPECT_THAT(Symbols,
   UnorderedElementsAre(AllOf(qName("X"), declURI(IncURI),
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -6,14 +6,30 @@
 //
 //===--===//
 
+#include "TestFS.h"
 #include "index/CanonicalIncludes.h"
+#include "clang/Basic/FileEntry.h"
+#include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {
 namespace {
 
+FileEntryRef addFile(llvm::vfs::InMemoryFileSystem &FS, FileManager &FM,
+ llvm::StringRef Filename) {
+  FS.addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(""));
+  auto File = FM.getFileRef(Filename);
+  EXPECT_THAT_EXPECTED(File, llvm::Succeeded());
+  return *File;
+}
+
 TEST(CanonicalIncludesTest, CStandardLibrary) {
   CanonicalIncludes CI;
   auto Language = LangOptions();
@@ -40,29 +56,52 @@
   // iosfwd declares some symbols it doesn't own.
   EXPECT_EQ("", CI.mapSymbol("std::ostream"));
   // And (for now) we assume it owns the others.
-  EXPECT_EQ("", CI.mapHeader("iosfwd"));
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  FileManager Files(FileSystemOptions(), InMemFS);
+  auto File = addFile(*InMemFS, Files, testPath("iosfwd"));
+  EXPECT_EQ("", CI.mapHeader(File));
 }
 
 TEST(CanonicalIncludesTest, PathMapping) {
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  FileManager Files(FileSystemOptions(), InMemFS);
+  std::string BarPath = testPath("foo/bar");
+  auto Bar = addFile(*InMemFS, Files, BarPath);
+  auto Other = addFile(*InMemFS, Files, testPath("foo/baz"));
   // As used for IWYU pragmas.
   CanonicalIncludes CI;
-  CI.addMapping("foo/bar", "");
+  CI.addMapping(Bar, "");
 
-  EXPECT_EQ("", CI.mapHeader("foo/bar"));
-  EXPECT_EQ("", CI.mapHeader("bar/bar"));
+  // We added a mapping for baz.
+  EXPECT_EQ("", CI.mapHeader(Bar));
+  // Other file doesn't have a mapping.
+  EXPECT_EQ("", CI.mapHeader(Other));
+
+  // Add hard link to "foo/bar" and check that it is also mapped to , hence
+  // does not depend on th

[PATCH] D123070: [Driver][NFC] Simplify handling of flags in Options.td

2022-04-05 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.

Looks reasonable to me.

I worry that the closing comments on '}'s might rot since there's no tooling to 
maintain them though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123070

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


[PATCH] D123045: [clang][extract-api] Fix small issues with SymbolGraphSerializer

2022-04-05 Thread Victoria Mitchell via Phabricator via cfe-commits
QuietMisdreavus added inline comments.



Comment at: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp:510
   Symbols.emplace_back(std::move(*Obj));
+  PathComponentContext.pop_back();
 }

dang wrote:
> dang wrote:
> > zixuw wrote:
> > > zixuw wrote:
> > > > QuietMisdreavus wrote:
> > > > > zixuw wrote:
> > > > > > What's the cost/would it worth it to wrap the `emplace_back`s and 
> > > > > > `pop_back`s of `PathComponentContext` in meaningful APIs like 
> > > > > > `enterPathComponentContext` and `exitPathComponentContext`?
> > > > > > That way the code is more self-explanatory and easier to read. It 
> > > > > > took me some time and mental resources to figure out why the 
> > > > > > `pop_back` is placed here.
> > > > > What's the use of having the `emplace_back` call inside 
> > > > > `serializeAPIRecord` but to pop it outside? It seems like it's easier 
> > > > > to mess up for new kinds of records.
> > > > The reason to `emplace_back` the path component inside 
> > > > `serializeAPIRecord` is that the `pathComponent` field of the `Record` 
> > > > is serialized in there so you want to include the name of the symbol 
> > > > itself in the path component list.
> > > > The `pop_back` is delayed til all other additional serialization for a 
> > > > specific kind of record, for example `serializeEnumRecord` handles all 
> > > > the enum cases after processing the enum record itself using 
> > > > `serializeAPIRecord`. So in order to correctly include the enum name in 
> > > > the path components of all the enum cases, the enum name has to stay in 
> > > > `PathComponentContext` until all members are serialized.
> > > > 
> > > > This is exactly the reason why I wanted a clearer API to make it easier 
> > > > to see.
> > > Hmm now that I thought about this, it seems that it would be easier to 
> > > understand and avoid bugs if we lift 
> > > `PathComponentContext.emplace_back`/`enterPathComponentContext` out of 
> > > `serializeAPIRecord`, because we have access to the record name before 
> > > that anyway.
> > > 
> > > So we establish a pre-condition of `serializeAPIRecord` that the correct 
> > > path components would be set up in `PathComponentContext` before the call 
> > > so we could still serialize the field inside that method. And in specific 
> > > `serialize*Record` methods we push the record name, and pop out at the 
> > > end.
> > > 
> > > This way the push and pop operations would appear in pairs in a single 
> > > block, saving the confusion and mental work of jumping across functions 
> > > to see how `PathComponentContext` is evolving.
> > If you think we should have a specialized API I am happy to do this. I 
> > figured it was self-explanatory by the name of `PathComponentContext` but 
> > it clearly isn't so needs addressing. I put the `emplace_back` call in 
> > `serializeAPIRecord` since all the specific serialization methods call it. 
> > I thought it would make it impossible to forget to add them. @zixuw is 
> > correct in the reason why the pop is outside we don't want to pop before we 
> > have serialized the sub records by agree it is ugly and potentially error 
> > prone. I can see three ways forward for improving the ergonomics of this 
> > since this seems to be problematic:
> > - Provide `serializeAPIRecord` a continuation to serialize the sub records 
> > or additional fields, that way we can move the pop inside 
> > `serializeAPIRecord` I am not a fan personally because we get into JS style 
> > closure hell if we start doing this...
> > - Use a visitor pattern where the visitor would be responsible for managing 
> > `PathComponentContext` and do the appropriate push/pops in the `visit` 
> > methods. We would need to add a APIRecordVisitor type, and appropriate 
> > visit methods for each APIRecord. This would make sense because the records 
> > should really know how to visit themselves.
> > - Just add a specialized API although it seems it would really easy to 
> > forget to remove path components.
> > 
> > Let me know what you think is the way forward.
> Unless we go with the last option, I think this should be a follow up patch 
> since it would a structural change.
I'm most a fan of the `APIRecordVisitor` option, but you're right in that that 
would be a rather involved change. Now that you've said that the arrangement is 
for encoding sub-records, it makes sense to me. As an alternative, i think 
moving the `emplace_back` outside of `serializeAPIRecord` is actually my other 
preferred arrangement; without some other way of calculating the path 
components on-the-fly (e.g. walking up DeclContexts) simply having 
`serializeAPIRecord` look at what's there and have the wrapper calls deal with 
setting up its state sounds the most reasonable to me. That way, as @zixuw 
said, the `emplace_back` and `pop_back` calls are at least lexically close to 
each other.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  http

[PATCH] D122766: [clang] Use forward slash as the path separator for Windows in __FILE__, __builtin_FILE(), and std::source_location

2022-04-05 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

> My feeling is that the default behavior on Windows needs to be to use 
> backslashes and not forward slashes.

Okay, how would folks feel about always canonicalizing `__FILE__` etc. to use 
//backslashes// when targeting Windows?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122766

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


[PATCH] D119271: clang: emit allocalign to LLVM for alloc_align attributes

2022-04-05 Thread Augie Fackler via Phabricator via cfe-commits
durin42 planned changes to this revision.
durin42 added a comment.

I have some reworking to do on this after my latest round of llvm-side work 
that I'll try and get out later this week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119271

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


[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D122983#3429060 , @aaron.ballman 
wrote:

> Morally, yes, that's reasonable in CodeGen because you're ensuring you get no 
> diagnostics. Practically, that's a convoluted, more expensive, less 
> maintainable way to spell `-Werror` for the test. When diagnostics are 
> introduced, this pattern encourages people to remove the `// 
> expected-no-diagnostics` comment and start adding `// expected-warning {{}}` 
> comments. Running the diagnostic verifier also slows down test execution 
> because of the extra verification step (which adds up over thousands of 
> tests).

Thanks for the tip. I never thought to use `-Werror` that way.


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

https://reviews.llvm.org/D122983

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


[PATCH] D118804: Revert "[Clang] Propagate guaranteed alignment for malloc and others"

2022-04-05 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.
Herald added a subscriber: StephenFan.
Herald added a project: All.

Are we considering relanding this with smaller alignment for smaller mallocs 
(and friends)?

See: https://github.com/llvm/llvm-project/issues/54747#issuecomment-1088420860


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118804

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


[clang-tools-extra] 012e90b - Reland "[clangd] IncludeCleaner: Add support for IWYU pragma private"

2022-04-05 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2022-04-05T16:57:39+02:00
New Revision: 012e90bb2483888d113368b69933aec0ab6a5041

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

LOG: Reland "[clangd] IncludeCleaner: Add support for IWYU pragma private"

This lands 4cb38bfe76b7ef157485338623c931d04d17b958 again.

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/IncludeCleaner.h
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 44acd34086af9..1e6e3cac8a484 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -12,6 +12,7 @@
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "SourceCode.h"
+#include "index/CanonicalIncludes.h"
 #include "support/Logger.h"
 #include "support/Trace.h"
 #include "clang/AST/ASTContext.h"
@@ -23,6 +24,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 
@@ -303,9 +305,10 @@ ReferencedLocations findReferencedLocations(ParsedAST 
&AST) {
  &AST.getTokens());
 }
 
-ReferencedFiles
-findReferencedFiles(const ReferencedLocations &Locs, const SourceManager &SM,
-llvm::function_ref HeaderResponsible) {
+ReferencedFiles findReferencedFiles(
+const ReferencedLocations &Locs, const SourceManager &SM,
+llvm::function_ref HeaderResponsible,
+llvm::function_ref(FileID)> UmbrellaHeader) {
   std::vector Sorted{Locs.User.begin(), Locs.User.end()};
   llvm::sort(Sorted); // Group by FileID.
   ReferencedFilesBuilder Builder(SM);
@@ -324,33 +327,54 @@ findReferencedFiles(const ReferencedLocations &Locs, 
const SourceManager &SM,
   // non-self-contained FileIDs as used. Perform this on FileIDs rather than
   // HeaderIDs, as each inclusion of a non-self-contained file is distinct.
   llvm::DenseSet UserFiles;
-  for (FileID ID : Builder.Files)
+  llvm::StringSet<> PublicHeaders;
+  for (FileID ID : Builder.Files) {
 UserFiles.insert(HeaderResponsible(ID));
+if (auto PublicHeader = UmbrellaHeader(ID)) {
+  PublicHeaders.insert(*PublicHeader);
+}
+  }
 
   llvm::DenseSet StdlibFiles;
   for (const auto &Symbol : Locs.Stdlib)
 for (const auto &Header : Symbol.headers())
   StdlibFiles.insert(Header);
 
-  return {std::move(UserFiles), std::move(StdlibFiles)};
+  return {std::move(UserFiles), std::move(StdlibFiles),
+  std::move(PublicHeaders)};
 }
 
 ReferencedFiles findReferencedFiles(const ReferencedLocations &Locs,
 const IncludeStructure &Includes,
+const CanonicalIncludes &CanonIncludes,
 const SourceManager &SM) {
-  return findReferencedFiles(Locs, SM, [&SM, &Includes](FileID ID) {
-return headerResponsible(ID, SM, Includes);
-  });
+  return findReferencedFiles(
+  Locs, SM,
+  [&SM, &Includes](FileID ID) {
+return headerResponsible(ID, SM, Includes);
+  },
+  [&SM, &CanonIncludes](FileID ID) -> Optional {
+auto Entry = SM.getFileEntryRefForID(ID);
+if (!Entry)
+  return llvm::None;
+auto PublicHeader = CanonIncludes.mapHeader(*Entry);
+if (PublicHeader.empty())
+  return llvm::None;
+return PublicHeader;
+  });
 }
 
 std::vector
 getUnused(ParsedAST &AST,
-  const llvm::DenseSet &ReferencedFiles) {
+  const llvm::DenseSet &ReferencedFiles,
+  const llvm::StringSet<> &ReferencedPublicHeaders) {
   trace::Span Tracer("IncludeCleaner::getUnused");
   std::vector Unused;
   for (const Inclusion &MFI : AST.getIncludeStructure().MainFileIncludes) {
 if (!MFI.HeaderID)
   continue;
+if (ReferencedPublicHeaders.contains(MFI.Written))
+  continue;
 auto IncludeID = static_cast(*MFI.HeaderID);
 bool Used = ReferencedFiles.contains(IncludeID);
 if (!Used && !mayConsiderUnused(MFI, AST)) {
@@ -400,11 +424,12 @@ std::vector 
computeUnusedIncludes(ParsedAST &AST) {
   const auto &SM = AST.getSourceManager();
 
   auto Refs = findReferencedLocations(AST);
-  auto ReferencedFileIDs = findReferencedFiles(Refs, AST.getIncludeStructure(),
-   AST.getSourceManager());
+  auto ReferencedFiles =
+  findReferencedFiles(Refs, AST.getIncludeStructure(),
+  AST.getCanonicalIncludes(), AST.getSourceManager());
   auto ReferencedHeaders =
-  translateToHeaderIDs(ReferencedFil

[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

2022-04-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This looks pretty good!
The tests in clang are sadly indirect.
I think adding support to clangd's FindTarget would be a small change and would 
allow a fairly direct test, but maybe it will affect a bunch of existing tests 
or possibly have a blast radius. Up to you.




Comment at: clang/include/clang/AST/ASTContext.h:2184
 
+  TemplateName getUsingTemplateName(TemplateName Underlying,
+UsingShadowDecl *USD) const;

nit: there's something of a canonical order in TemplateName::NameKind, I think 
it's useful to follow this as much as possible for consistency when navigating 
in these huge files.
This mostly means placing UsingTemplate code at the bottom of lists of template 
name cases.



Comment at: clang/include/clang/AST/TemplateName.h:29
 class DependentTemplateName;
+class UsingTemplateName;
 class IdentifierInfo;

this list is alpha sorted, please preserve (and below)



Comment at: clang/include/clang/AST/TemplateName.h:411
+public:
+  UsingShadowDecl *getUsingShadowDecl() const { return USD; }
+  TemplateName getUnderlying() const { return UnderlyingTN; }

docs on getUsingShadowDecl and getUnderlying



Comment at: clang/include/clang/AST/TemplateName.h:411
+public:
+  UsingShadowDecl *getUsingShadowDecl() const { return USD; }
+  TemplateName getUnderlying() const { return UnderlyingTN; }

sammccall wrote:
> docs on getUsingShadowDecl and getUnderlying
getFoundDecl() would be consistent with UsingType, and would describe the 
relation between this and the UsingShadowDecl, rather than echoing its type



Comment at: clang/include/clang/AST/TemplateName.h:412
+  UsingShadowDecl *getUsingShadowDecl() const { return USD; }
+  TemplateName getUnderlying() const { return UnderlyingTN; }
+  void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, UnderlyingTN, USD); }

maybe getUnderlyingTemplate? "underlying" acts as an adjective so this feels a 
little ungrammatical



Comment at: clang/include/clang/AST/TemplateName.h:413
+  TemplateName getUnderlying() const { return UnderlyingTN; }
+  void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, UnderlyingTN, USD); }
+  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Underlying,

nit: separate the public API from implementation details with a blank line at 
least



Comment at: clang/include/clang/AST/TemplateName.h:446
   /// that this qualified name refers to.
   TemplateDecl *Template;
 

It seems really unfortunate that this is a `TemplateDecl*` instead of a 
`TemplateName`.

for:
```
template  class x;
namespace a { using ::x; }
a::x<0>;
```
we want `a::x` to include both a QualifiedTemplateName (modelling the a:: 
qualifier) and a UsingTemplateName (modelling the UsingShadowDecl that was 
found).

I'd guess we can change `Template` to be a `TemplateName` internally, and add 
`getTemplate()` while keeping the existing `get[Template]Decl` APIs on top of 
`TemplateName::getAsTemplateDecl()`.
I suppose this could be a separate change (though it'd be nice to know whether 
it's going to work...)

Of course if that changed there's a natural followon to take the qualifier out 
of DependentTemplateName and turn it into a QualifiedTemplateName wrapping a 
DependentTemplateName. (Definitely out of scope for this patch, not sure if 
it's reasonable to expect you to do it at all)



Comment at: clang/lib/AST/ASTContext.cpp:6176
   }
+  case TemplateName::UsingTemplate:
+return getCanonicalTemplateName(

you could also handle this in the QualifiedTemplate/Template case, since the 
decl is guaranteed to be present.



Comment at: clang/lib/AST/ItaniumMangle.cpp:2394
+  TN = TN.getAsUsingTemplateName()->getUnderlying();
+  goto mangleTemplateName;
+}

this seems pretty scary: we have to use a goto here rather than extract a 
function, because the target code also uses goto...

The nontrivial TemplateTemplateParmDecl case isn't possible here. So I suggest 
just calling mangleSourceNameWithAbiTags directly without trying to reuse logic.



Comment at: clang/lib/AST/TemplateName.cpp:107
 return Template;
-
+  if (auto *UTN = Storage.dyn_cast())
+return UTN->getUnderlying().getAsTemplateDecl();

`= getAsUsingTemplateName()`



Comment at: clang/lib/AST/TemplateName.cpp:273
+  } else if (auto *U = getAsUsingTemplateName()) {
+U->getUnderlying().print(OS, Policy);
   } else {

Why is this correct, rather than potentially printing the wrong sugar?

If the reasoning is that that the underlying TemplateName has the same name and 
can't have any unwanted sugar, that seems subtle and deserves a comment.

I think just printing the 

[clang] 09a5eae - [clang-offload-bundler] add -input/-output options

2022-04-05 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2022-04-05T11:13:01-04:00
New Revision: 09a5eae0d1952f53dffd56b9a598215aa1a1487e

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

LOG: [clang-offload-bundler] add -input/-output options

Currently, clang-offload-bundler has -inputs and -outputs options that accept
values with comma as the delimiter. This causes issues with file paths
containing commas, which are valid file paths on Linux.

This add two new options -input and -output, which accept one single file,
and allow multiple instances. This allows arbitrary file paths. The old
-inputs and -outputs options will be kept for backward compatibility, but
are not allowed to be used with -input and -output options for simplicity.
In the future, -inputs and -outputs options will be phasing out.

RFC: 
https://discourse.llvm.org/t/rfc-adding-input-and-output-options-to-clang-offload-bundler/60049

Patch by: Siu Chi Chan

Reviewed by: Yaxun Liu

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/HIPUtility.cpp
clang/test/Driver/clang-offload-bundler-asserts-on.c
clang/test/Driver/clang-offload-bundler.c
clang/test/Driver/fat-archive-unbundle-ext.c
clang/test/Driver/fat_archive_amdgpu.cpp
clang/test/Driver/fat_archive_nvptx.cpp
clang/test/Driver/hip-device-compile.hip
clang/test/Driver/hip-link-bundle-archive.hip
clang/test/Driver/hip-link-save-temps.hip
clang/test/Driver/hip-output-file-name.hip
clang/test/Driver/hip-rdc-device-only.hip
clang/test/Driver/hip-save-temps.hip
clang/test/Driver/hip-toolchain-device-only.hip
clang/test/Driver/hip-toolchain-no-rdc.hip
clang/test/Driver/hip-toolchain-rdc-separate.hip
clang/test/Driver/hip-toolchain-rdc-static-lib.hip
clang/test/Driver/hip-toolchain-rdc.hip
clang/test/Driver/hip-unbundle-preproc.hip
clang/test/Driver/hipspv-toolchain-rdc.hip
clang/test/Driver/hipspv-toolchain.hip
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/openmp-offload.c
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 8c106145fa62b..cbdb463d09682 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8028,8 +8028,10 @@ void OffloadBundler::ConstructJob(Compilation &C, const 
JobAction &JA,
   // The bundling command looks like this:
   // clang-offload-bundler -type=bc
   //   -targets=host-triple,openmp-triple1,openmp-triple2
-  //   -outputs=input_file
-  //   -inputs=unbundle_file_host,unbundle_file_tgt1,unbundle_file_tgt2"
+  //   -output=output_file
+  //   -input=unbundle_file_host
+  //   -input=unbundle_file_tgt1
+  //   -input=unbundle_file_tgt2
 
   ArgStringList CmdArgs;
 
@@ -8090,14 +8092,12 @@ void OffloadBundler::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   // Get bundled file command.
   CmdArgs.push_back(
-  TCArgs.MakeArgString(Twine("-outputs=") + Output.getFilename()));
+  TCArgs.MakeArgString(Twine("-output=") + Output.getFilename()));
 
   // Get unbundled files command.
-  SmallString<128> UB;
-  UB += "-inputs=";
   for (unsigned I = 0; I < Inputs.size(); ++I) {
-if (I)
-  UB += ',';
+SmallString<128> UB;
+UB += "-input=";
 
 // Find ToolChain for this input.
 const ToolChain *CurTC = &getToolChain();
@@ -8112,9 +8112,8 @@ void OffloadBundler::ConstructJob(Compilation &C, const 
JobAction &JA,
 } else {
   UB += CurTC->getInputFilename(Inputs[I]);
 }
+CmdArgs.push_back(TCArgs.MakeArgString(UB));
   }
-  CmdArgs.push_back(TCArgs.MakeArgString(UB));
-
   // All the inputs are encoded as commands.
   C.addCommand(std::make_unique(
   JA, *this, ResponseFileSupport::None(),
@@ -8132,8 +8131,10 @@ void OffloadBundler::ConstructJobMultipleOutputs(
   // The unbundling command looks like this:
   // clang-offload-bundler -type=bc
   //   -targets=host-triple,openmp-triple1,openmp-triple2
-  //   -inputs=input_file
-  //   -outputs=unbundle_file_host,unbundle_file_tgt1,unbundle_file_tgt2"
+  //   -input=input_file
+  //   -output=unbundle_file_host
+  //   -output=unbundle_file_tgt1
+  //   -output=unbundle_file_tgt2
   //   -unbundle
 
   ArgStringList CmdArgs;
@@ -8185,17 +8186,15 @@ void OffloadBundler::ConstructJobMultipleOutputs(
 
   // Get bundled file command.
   CmdArgs.push_back(
-  TCArgs.MakeArgString(Twine("-inputs=") + Input.getFilename()));
+  TCArgs.MakeArgString(Twine("-input=") + Input.getFilename()));
 
   // Get unbundled files command.
-  SmallString<128> UB;
-  UB += "-outputs=

[PATCH] D120662: [clang-offload-bundler] add -input/-output options

2022-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG09a5eae0d195: [clang-offload-bundler] add -input/-output 
options (authored by yaxunl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120662

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/HIPUtility.cpp
  clang/test/Driver/clang-offload-bundler-asserts-on.c
  clang/test/Driver/clang-offload-bundler.c
  clang/test/Driver/fat-archive-unbundle-ext.c
  clang/test/Driver/fat_archive_amdgpu.cpp
  clang/test/Driver/fat_archive_nvptx.cpp
  clang/test/Driver/hip-device-compile.hip
  clang/test/Driver/hip-link-bundle-archive.hip
  clang/test/Driver/hip-link-save-temps.hip
  clang/test/Driver/hip-output-file-name.hip
  clang/test/Driver/hip-rdc-device-only.hip
  clang/test/Driver/hip-save-temps.hip
  clang/test/Driver/hip-toolchain-device-only.hip
  clang/test/Driver/hip-toolchain-no-rdc.hip
  clang/test/Driver/hip-toolchain-rdc-separate.hip
  clang/test/Driver/hip-toolchain-rdc-static-lib.hip
  clang/test/Driver/hip-toolchain-rdc.hip
  clang/test/Driver/hip-unbundle-preproc.hip
  clang/test/Driver/hipspv-toolchain-rdc.hip
  clang/test/Driver/hipspv-toolchain.hip
  clang/test/Driver/openmp-offload-gpu.c
  clang/test/Driver/openmp-offload.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -62,15 +62,26 @@
 // and -help) will be hidden.
 static cl::OptionCategory
 ClangOffloadBundlerCategory("clang-offload-bundler options");
-
 static cl::list
-InputFileNames("inputs", cl::CommaSeparated, cl::OneOrMore,
-   cl::desc("[,...]"),
+InputFileNames("input", cl::ZeroOrMore,
+   cl::desc("Input file."
+" Can be specified multiple times "
+"for multiple input files."),
cl::cat(ClangOffloadBundlerCategory));
 static cl::list
-OutputFileNames("outputs", cl::CommaSeparated,
-cl::desc("[,...]"),
+InputFileNamesDeprecatedOpt("inputs", cl::CommaSeparated, cl::ZeroOrMore,
+cl::desc("[,...] (deprecated)"),
+cl::cat(ClangOffloadBundlerCategory));
+static cl::list
+OutputFileNames("output", cl::ZeroOrMore,
+cl::desc("Output file."
+ " Can be specified multiple times "
+ "for multiple output files."),
 cl::cat(ClangOffloadBundlerCategory));
+static cl::list
+OutputFileNamesDeprecatedOpt("outputs", cl::CommaSeparated, cl::ZeroOrMore,
+ cl::desc("[,...] (deprecated)"),
+ cl::cat(ClangOffloadBundlerCategory));
 static cl::list
 TargetNames("targets", cl::CommaSeparated,
 cl::desc("[-,...]"),
@@ -1384,6 +1395,38 @@
 }
   };
 
+  auto warningOS = [argv]() -> raw_ostream & {
+return WithColor::warning(errs(), StringRef(argv[0]));
+  };
+
+  if (InputFileNames.getNumOccurrences() != 0 &&
+  InputFileNamesDeprecatedOpt.getNumOccurrences() != 0) {
+reportError(createStringError(
+errc::invalid_argument,
+"-inputs and -input cannot be used together, use only -input instead"));
+  }
+  if (InputFileNamesDeprecatedOpt.size()) {
+warningOS() << "-inputs is deprecated, use -input instead\n";
+// temporary hack to support -inputs
+std::vector &s = InputFileNames;
+s.insert(s.end(), InputFileNamesDeprecatedOpt.begin(),
+ InputFileNamesDeprecatedOpt.end());
+  }
+
+  if (OutputFileNames.getNumOccurrences() != 0 &&
+  OutputFileNamesDeprecatedOpt.getNumOccurrences() != 0) {
+reportError(createStringError(errc::invalid_argument,
+  "-outputs and -output cannot be used "
+  "together, use only -output instead"));
+  }
+  if (OutputFileNamesDeprecatedOpt.size()) {
+warningOS() << "-outputs is deprecated, use -output instead\n";
+// temporary hack to support -outputs
+std::vector &s = OutputFileNames;
+s.insert(s.end(), OutputFileNamesDeprecatedOpt.begin(),
+ OutputFileNamesDeprecatedOpt.end());
+  }
+
   if (ListBundleIDs) {
 if (Unbundle) {
   reportError(
@@ -1408,9 +1451,8 @@
   }
 
   if (OutputFileNames.getNumOccurrences() == 0) {
-reportError(createStringError(
-errc::invalid_argument,
-"for the --outputs option: must be specified at least once!"));
+reportError(
+createStringError(errc::invalid_argument, "no output file specified!"));
   }
   if 

[PATCH] D123026: [clang][NFC] Extract the EmitAssemblyHelper::emitLTOSummary method

2022-04-05 Thread Pavel Samolysov via Phabricator via cfe-commits
psamolysov-intel added a comment.

Colleagues, could you review this small non-functional change. After the 
`TargetTruiple` member has been extracted, it becomes clear that there is some 
code duplication in the `BackendUtil.cpp` source file. I think this is a good 
idea to eliminate this code duplication, isn't it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123026

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


[PATCH] D123064: [Clang][C++23][WIP] P2071 Named universal character escapes

2022-04-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 420521.
cor3ntin added a comment.

- Support loose matching
- Modifiy the binary format to make it easier to have a root node


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Lex/Lexer.h
  clang/lib/Lex/Lexer.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/test/Lexer/char-escapes-delimited.c
  clang/test/Parser/cxx11-user-defined-literals.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/ucn-identifiers.c
  llvm/CMakeLists.txt
  llvm/include/llvm/ADT/StringExtras.h
  llvm/include/llvm/Support/ScopedPrinter.h
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/ScopedPrinter.cpp
  llvm/lib/Support/StringExtras.cpp
  llvm/lib/Support/UnicodeNameToCodepoint.cpp
  llvm/lib/Support/UnicodeNameToCodepointGenerated.cpp
  llvm/unittests/Support/UnicodeTest.cpp
  llvm/utils/UnicodeData/CMakeLists.txt
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp

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


[PATCH] D123026: [clang][NFC] Extract the EmitAssemblyHelper::emitLTOSummary method

2022-04-05 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

I'd prefer to keep the setting of the module flags inline here. The main reason 
is that the EnableSplitLTOUnit module flag is also set inline for the ThinLTO 
case just above, and it is easier to see what is going on if they are near each 
other. Suggest making the new emitLTOSummary just about checking the conditions 
for emitting the summary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123026

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


[PATCH] D122661: [Clang] Do not warn on unused lifetime-extending vars with side effects...

2022-04-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 420530.
cor3ntin marked an inline comment as done.
cor3ntin added a comment.

- Address Aaron's comments.
- Add more tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122661

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/warn-unused-variables.cpp

Index: clang/test/SemaCXX/warn-unused-variables.cpp
===
--- clang/test/SemaCXX/warn-unused-variables.cpp
+++ clang/test/SemaCXX/warn-unused-variables.cpp
@@ -154,13 +154,13 @@
 
 #include "Inputs/warn-unused-variables.h"
 
-namespace arrayRecords {
-
 class NonTriviallyDestructible {
 public:
   ~NonTriviallyDestructible() {}
 };
 
+namespace arrayRecords {
+
 struct Foo {
   int x;
   Foo(int x) : x(x) {}
@@ -196,7 +196,7 @@
   bar<2>();
 }
 
-}
+} // namespace arrayRecords
 
 #if __cplusplus >= 201103L
 namespace with_constexpr {
@@ -253,3 +253,44 @@
 }
 }
 #endif
+
+// Ensure we do not warn on lifetime extension
+namespace gh54489 {
+
+void f() {
+  const auto &a = NonTriviallyDestructible();
+  const auto &b = a; // expected-warning {{unused variable 'b'}}
+#if __cplusplus >= 201103L
+  const auto &&c = NonTriviallyDestructible();
+  auto &&d = c; // expected-warning {{unused variable 'd'}}
+#endif
+}
+
+struct S {
+  S() = default;
+  S(const S &) = default;
+  S(int);
+};
+
+template 
+void foo(T &t) {
+  const auto &extended = S{t};
+}
+
+void test_foo() {
+  int i;
+  foo(i);
+}
+
+struct RAIIWrapper {
+  RAIIWrapper();
+  ~RAIIWrapper();
+};
+
+void RAIIWrapperTest() {
+  auto const guard = RAIIWrapper();
+  auto const &guard2 = RAIIWrapper();
+  auto &&guard3 = RAIIWrapper();
+}
+
+} // namespace gh54489
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1889,15 +1889,28 @@
   // Types of valid local variables should be complete, so this should succeed.
   if (const VarDecl *VD = dyn_cast(D)) {
 
-// White-list anything with an __attribute__((unused)) type.
+const Expr *Init = VD->getInit();
+if (const auto *Cleanups = dyn_cast_or_null(Init))
+  Init = Cleanups->getSubExpr();
+
 const auto *Ty = VD->getType().getTypePtr();
 
 // Only look at the outermost level of typedef.
 if (const TypedefType *TT = Ty->getAs()) {
+  // Allow anything marked with __attribute__((unused)).
   if (TT->getDecl()->hasAttr())
 return false;
 }
 
+// Warn for reference variables whose initializtion performs lifetime
+// extension.
+if (const auto *MTE = dyn_cast_or_null(Init)) {
+  if (MTE->getExtendingDecl()) {
+Ty = VD->getType().getNonReferenceType().getTypePtr();
+Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
+  }
+}
+
 // If we failed to complete the type for some reason, or if the type is
 // dependent, don't diagnose the variable.
 if (Ty->isIncompleteType() || Ty->isDependentType())
@@ -1916,10 +1929,7 @@
 if (!RD->hasTrivialDestructor() && !RD->hasAttr())
   return false;
 
-if (const Expr *Init = VD->getInit()) {
-  if (const ExprWithCleanups *Cleanups =
-  dyn_cast(Init))
-Init = Cleanups->getSubExpr();
+if (Init) {
   const CXXConstructExpr *Construct =
 dyn_cast(Init);
   if (Construct && !Construct->isElidable()) {
@@ -1931,10 +1941,16 @@
 
   // Suppress the warning if we don't know how this is constructed, and
   // it could possibly be non-trivial constructor.
-  if (Init->isTypeDependent())
+  if (Init->isTypeDependent()) {
 for (const CXXConstructorDecl *Ctor : RD->ctors())
   if (!Ctor->isTrivial())
 return false;
+  }
+
+  // Suppress the warning if the constructor is unresolved because
+  // its arguments are dependent.
+  if (isa(Init))
+return false;
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119720: [ARM] Pass for Cortex-A57 and Cortex-A72 Fused AES Erratum

2022-04-05 Thread Sam Elliott via Phabricator via cfe-commits
lenary marked 6 inline comments as done.
lenary added a comment.

A few comments before I post the next version of the patch.




Comment at: llvm/lib/Target/ARM/ARMFixCortexA57AES1742098Pass.cpp:145
+  case ARM::VMVNq:
+return CondCodeIsAL(3);
+  // VMOV of 64-bit value between D registers (when condition = al)

lenary wrote:
> dmgreen wrote:
> > Can/should all these use findFirstPredOperandIdx?
> > 
> > And is it worth checking for more instruction? Anything that sets a Q 
> > register, or is that too broad?
> `findFirstPredOperandIdx` doesn't work as lots of these instructions are not 
> marked `isPredicable` in the tablegen. I'm not sure if we want to solve that 
> in this work, or as a follow-up (I'd lean towards follow-up).
> 
> I believe "anything that sets a Q register" is too broad, as we model 
> subregister insertion as setting the the whole register in LLVM, but I'm not 
> sure that micro-architecturally they are actually doing that. This is why 
> I've tried to only add 64- and 128-bit setting instructions rather than ones 
> that are less wide. Originally I also included the `VMOVv2f32` instructions 
> that are now at the bottom of this switch, but I felt that might have been 
> too risky.
I'm wrong about this. The tablegen `isPredicable` is an override, other code 
might also set `isPredicable` to true, so I think `findFirstPredOperandIdx` 
should work too.



Comment at: llvm/lib/Target/ARM/ARMFixCortexA57AES1742098Pass.cpp:200-207
+  case ARM::VMOVv2f32:
+  case ARM::VMOVv4f32:
+  case ARM::VMOVv2i32:
+  case ARM::VMOVv4i32:
+  case ARM::VMOVv4i16:
+  case ARM::VMOVv8i16:
+  case ARM::VMOVv8i8:

dmgreen wrote:
> Are these vmov of an immediate? Are they not safe?
> 
> I was expecting it to be the lanes sets (VSETLNi8) and other scalar 
> instructions that were unsafe.
I have received the information on what is safe and what is not, and the next 
version of the patch will have this correct.



Comment at: llvm/lib/Target/ARM/ARMFixCortexA57AES1742098Pass.cpp:306
+  // fixup at the start of the function.
+  LLVM_DEBUG(dbgs()
+ << "Fixup Planned: Live-In (with safe defining instrs): "

dmgreen wrote:
> lenary wrote:
> > dmgreen wrote:
> > > Can you explain more about the IsLiveIn && UnsafeCount==0 case. Am I 
> > > understanding that correctly that it would be:
> > > ```
> > > function(q0, ...)
> > >   lotsofcode...
> > >   q0 = load
> > >   aes q0
> > > ```
> > > Is there a better way to detect that the live-in doesn't matter in cases 
> > > like that?
> > I don't believe there is, and this comes down to issues with the 
> > `RDA.getGlobalReachingDefs` implementation, which I want to fix/enhance, 
> > but in a follow-up patch.
> > 
> > To start with, this is actually not a problem, as the pass is intended to 
> > be conservative, and we know the clobbers are a no-op at the architectural 
> > level (we insert them for their micro-architectural effects). So code will 
> > still do the right thing, but maybe with a little too much overhead in the 
> > case you showed.
> > 
> > However, this is necessary in some other cases, such as:
> > 
> > ```
> > function(q0)
> >code
> >conditional branch to L2
> > L1:
> >q0 = safe_op(…)
> >branch to L3
> > L2:
> >code without update to q0
> > L3:
> >aes q0
> > ```
> > 
> > In this case, `AllDefs` is a set containing one single defining instruction 
> > for Q0, because there is only one within the function (which is all that 
> > `RDA.getGlobalReachingDefs` can report instructions for).
> > 
> > But in my example, we *need* to protect q0 on the other paths, because the 
> > safe definitions of q0, when considered as a set, do not entirely dominate 
> > the AES use of q0 (this is slightly stretching the conventional definition 
> > of dominance, but think of this as "there exists a path from entry to the 
> > aes, which does not contain any of the safe instructions". Sadly, 
> > MachineDominance doesn't allow us to make this kind of query either!).
> > 
> > In this case though, it is safe to insert the protection at function entry, 
> > because that will (by definition) dominate all the AES uses, and the 
> > protection doesn't need to be dominated by the safe definitions, as we know 
> > they're safe.
> > 
> > I intend to follow-up this initial patch with an enhancement to 
> > ReachingDefAnalysis which will also provide the information that you have a 
> > set of defs inside the function, and also you're live-in, as this is 
> > required info for any conservative pass using the ReachingDefAnalysis. I 
> > felt, however, that given the pass is safe as-is, it was good to proceed 
> > without this enhancement.
> > 
> > 
> > 
> > 
> OK sounds good.
One note is that the exact problem you describe does show up in the tests (in 
`aese_set64_via_ptr`, where the `vldr` is "safe"), so when the pass is 
enhanced

[PATCH] D123032: [clang][dataflow] Exclude protobuf types from modeling in the environment.

2022-04-05 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:513
+  const RecordDecl *RD = BaseTy->getDecl();
+  if (RD->getIdentifier() == nullptr || RD->getName() != "Message")
+return false;

ymandel wrote:
> xazax.hun wrote:
> > Not sure how often is this invoked but we could reduce the number of string 
> > comparisons by caching the identifier ptr and do a pointer comparison.
> Good question. It means an extra comparison for each type until the pointer 
> is cached (to check if the cache is set) and then, afterwards, 2 comparisons 
> vs ~10 for the common case where the class name is doesn't match. In the 
> matching case, though, it is clearly saving much more.
> 
> For proto-heavy code, it seems a win, and a loss otherwise.  But, the 
> question is where to put the cache. It seems to me best to move this to be a 
> method on DataflowAnalysisContext (since it is a global, not local env, 
> property) and make the cached pointer a private member of DAC.
> 
> Thoughts?
I think it might be nice to have a context that is scoped to the translation 
unit rather than a function. We might have other stuff that we want to cache 
here.

An example how the static analyzer is dealing with this: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp#L960

In case we do not want to be lazy and willing to populate the cache eagerly at 
the beginning of the analysis, we would not pay for the extra checks to see if 
the cache is populated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123032

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


[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this breaks tests on Windows: http://45.33.8.238/win/55690/step_9.txt

please take a look, etc :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

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


[PATCH] D123032: [clang][dataflow] Exclude protobuf types from modeling in the environment.

2022-04-05 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:513
+  const RecordDecl *RD = BaseTy->getDecl();
+  if (RD->getIdentifier() == nullptr || RD->getName() != "Message")
+return false;

xazax.hun wrote:
> ymandel wrote:
> > xazax.hun wrote:
> > > Not sure how often is this invoked but we could reduce the number of 
> > > string comparisons by caching the identifier ptr and do a pointer 
> > > comparison.
> > Good question. It means an extra comparison for each type until the pointer 
> > is cached (to check if the cache is set) and then, afterwards, 2 
> > comparisons vs ~10 for the common case where the class name is doesn't 
> > match. In the matching case, though, it is clearly saving much more.
> > 
> > For proto-heavy code, it seems a win, and a loss otherwise.  But, the 
> > question is where to put the cache. It seems to me best to move this to be 
> > a method on DataflowAnalysisContext (since it is a global, not local env, 
> > property) and make the cached pointer a private member of DAC.
> > 
> > Thoughts?
> I think it might be nice to have a context that is scoped to the translation 
> unit rather than a function. We might have other stuff that we want to cache 
> here.
> 
> An example how the static analyzer is dealing with this: 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp#L960
> 
> In case we do not want to be lazy and willing to populate the cache eagerly 
> at the beginning of the analysis, we would not pay for the extra checks to 
> see if the cache is populated.
I'm also fine with not doing caching for now and having a note to consider this 
in the future if it becomes measurable in the profiles. It is probably fine for 
now when we only have a couple of short strings to compare. But I guess the 
number of special cases we handle this way will only increase in the future. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123032

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


[PATCH] D122478: [PowerPC] Add max/min intrinsics to Clang and PPC backend

2022-04-05 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf accepted this revision as: qiucf.
qiucf added a comment.
This revision is now accepted and ready to land.

Looks good to me in my side. Thanks for implementing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122478

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


[PATCH] D123100: [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes

2022-04-05 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi updated this revision to Diff 420545.
akyrtzi added a comment.

Expand type instead of using `auto`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123100

Files:
  bolt/lib/Core/DebugData.cpp
  clang/include/clang/Basic/Module.h
  clang/lib/Serialization/ASTWriter.cpp
  lld/MachO/SyntheticSections.cpp
  llvm/include/llvm/Support/BLAKE3.h
  llvm/include/llvm/Support/HashBuilder.h
  llvm/include/llvm/Support/MD5.h
  llvm/include/llvm/Support/SHA1.h
  llvm/include/llvm/Support/SHA256.h
  llvm/include/llvm/Support/raw_sha1_ostream.h
  llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/DebugInfo/CodeView/TypeHashing.cpp
  llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
  llvm/lib/MC/MCDwarf.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/MC/MCParser/MasmParser.cpp
  llvm/lib/ObjCopy/MachO/MachOWriter.cpp
  llvm/lib/Support/BLAKE3/README.md
  llvm/lib/Support/MD5.cpp
  llvm/lib/Support/SHA1.cpp
  llvm/lib/Support/SHA256.cpp
  llvm/unittests/Support/BLAKE3Test.cpp
  llvm/unittests/Support/HashBuilderTest.cpp
  llvm/unittests/Support/MD5Test.cpp
  llvm/unittests/Support/SHA256.cpp
  llvm/unittests/Support/raw_sha1_ostream_test.cpp
  mlir/lib/Pass/IRPrinting.cpp

Index: mlir/lib/Pass/IRPrinting.cpp
===
--- mlir/lib/Pass/IRPrinting.cpp
+++ mlir/lib/Pass/IRPrinting.cpp
@@ -66,7 +66,7 @@
 ArrayRef(reinterpret_cast(&data), sizeof(T)));
   }
 
-  SmallString<20> hash;
+  std::array hash;
 };
 
 //===--===//
Index: llvm/unittests/Support/raw_sha1_ostream_test.cpp
===
--- llvm/unittests/Support/raw_sha1_ostream_test.cpp
+++ llvm/unittests/Support/raw_sha1_ostream_test.cpp
@@ -14,7 +14,7 @@
 
 using namespace llvm;
 
-static std::string toHex(StringRef Input) {
+static std::string toHex(ArrayRef Input) {
   static const char *const LUT = "0123456789ABCDEF";
   size_t Length = Input.size();
 
@@ -39,7 +39,7 @@
 TEST(sha1_hash_test, Basic) {
   ArrayRef Input((const uint8_t *)"Hello World!", 12);
   std::array Vec = SHA1::hash(Input);
-  std::string Hash = toHex({(const char *)Vec.data(), 20});
+  std::string Hash = toHex(Vec);
   ASSERT_EQ("2EF7BDE608CE5404E97D5F042F95F89F1C232871", Hash);
 }
 
Index: llvm/unittests/Support/SHA256.cpp
===
--- llvm/unittests/Support/SHA256.cpp
+++ llvm/unittests/Support/SHA256.cpp
@@ -20,7 +20,7 @@
 
 namespace {
 
-static std::string toHex(StringRef Input) {
+static std::string toHex(ArrayRef Input) {
   static const char *const LUT = "0123456789abcdef";
   size_t Length = Input.size();
 
Index: llvm/unittests/Support/MD5Test.cpp
===
--- llvm/unittests/Support/MD5Test.cpp
+++ llvm/unittests/Support/MD5Test.cpp
@@ -62,7 +62,7 @@
   std::array Vec = MD5::hash(Input);
   MD5::MD5Result MD5Res;
   SmallString<32> Res;
-  memcpy(MD5Res.Bytes.data(), Vec.data(), Vec.size());
+  memcpy(MD5Res.data(), Vec.data(), Vec.size());
   MD5::stringifyResult(MD5Res, Res);
   EXPECT_EQ(Res, "c3fcd3d76192e4007dfb496cca67e13b");
   EXPECT_EQ(0x3be167ca6c49fb7dULL, MD5Res.high());
@@ -79,10 +79,7 @@
 ReferenceHash.update("abcd");
 MD5::MD5Result ReferenceResult;
 ReferenceHash.final(ReferenceResult);
-StringRef ExpectedResult =
-StringRef(reinterpret_cast(ReferenceResult.Bytes.data()),
-  ReferenceResult.Bytes.size());
-EXPECT_EQ(Hash.result(), ExpectedResult);
+EXPECT_EQ(Hash.result(), ReferenceResult);
   }
 
   Hash.update("xyz");
@@ -93,10 +90,7 @@
 ReferenceHash.update("xyz");
 MD5::MD5Result ReferenceResult;
 ReferenceHash.final(ReferenceResult);
-StringRef ExpectedResult =
-StringRef(reinterpret_cast(ReferenceResult.Bytes.data()),
-  ReferenceResult.Bytes.size());
-EXPECT_EQ(Hash.final(), ExpectedResult);
+EXPECT_EQ(Hash.final(), ReferenceResult);
   }
 }
 } // namespace
Index: llvm/unittests/Support/HashBuilderTest.cpp
===
--- llvm/unittests/Support/HashBuilderTest.cpp
+++ llvm/unittests/Support/HashBuilderTest.cpp
@@ -44,13 +44,15 @@
   HasherTAndEndianness::Endianness>;
 
 template 
-static std::string hashWithBuilder(const Ts &...Args) {
-  return HashBuilder().add(Args...).final().str();
+static typename HashBuilder::template HashResultTy<>
+hashWithBuilder(const Ts &...Args) {
+  return HashBuilder().add(Args...).final();
 }
 
 template 
-static std::string hashRangeWithBuilder(const Ts &...Args) {
-  return HashBuilder().addRange(Args...).final().str();
+static typename HashBuilder::template Has

[PATCH] D123100: [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes

2022-04-05 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added inline comments.



Comment at: bolt/lib/Core/DebugData.cpp:823
 Hasher.update(AbbrevData);
-StringRef Key = Hasher.final();
+auto Hash = Hasher.final();
+StringRef Key((const char *)Hash.data(), Hash.size());

jhenderson wrote:
> Amir wrote:
> > I think it would be more in line with LLVM coding standards to expand 
> > `auto` in this case (and others) – see 
> > https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable.
> >  
> > My understanding is that `auto` is fine where the type is obvious from the 
> > context (is explicitly available on the same line e.g. with casts), is 
> > abstract (T::iterator types), or doesn't matter (e.g. lambdas).
> +1 (also relevant in other places in this patch)
Updated 👍


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123100

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


[clang-tools-extra] 211df73 - Fix the test after D123031

2022-04-05 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2022-04-05T18:21:24+02:00
New Revision: 211df7319af4d97b11f59fbc88bfb7ca27eab785

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

LOG: Fix the test after D123031

Added: 


Modified: 
clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp 
b/clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
index 20e01d31b29a7..0329cdc50cad2 100644
--- a/clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -100,7 +100,10 @@ TEST(CanonicalIncludesTest, Precedence) {
   // We added a mapping from some/path to .
   ASSERT_EQ("", CI.mapHeader(File));
   // We should have a path from 'bits/stl_vector.h' to ''.
-  auto STLVectorFile = addFile(*InMemFS, Files, testPath("bits/stl_vector.h"));
+  // FIXME: The Standrad Library map in CanonicalIncludes expects forward
+  // slashes and Windows would use backward slashes instead, so the headers are
+  // not matched appropriately.
+  auto STLVectorFile = addFile(*InMemFS, Files, "bits/stl_vector.h");
   ASSERT_EQ("", CI.mapHeader(STLVectorFile));
 }
 



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


[PATCH] D123031: [clangd] Use stable keys for CanonicalIncludes mappings

2022-04-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

In D123031#3429801 , @thakis wrote:

> Looks like this breaks tests on Windows: 
> http://45.33.8.238/win/55690/step_9.txt
>
> please take a look, etc :)

Should be fixed in 
https://github.com/llvm/llvm-project/commit/211df7319af4d97b11f59fbc88bfb7ca27eab785


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123031

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


[clang] 357afd9 - [clang-format] Pass return code of git-clang-format by sys.exit()

2022-04-05 Thread via cfe-commits

Author: owenca
Date: 2022-04-05T09:52:01-07:00
New Revision: 357afd952852db0be3f690f8b647bd4b02f38cad

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

LOG: [clang-format] Pass return code of git-clang-format by sys.exit()

Fixes #54758

Added: 


Modified: 
clang/tools/clang-format/git-clang-format

Removed: 




diff  --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 7968c43875744..1d6f216240c1c 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -628,4 +628,4 @@ def convert_string(bytes_input):
 return str(bytes_input)
 
 if __name__ == '__main__':
-  main()
+  sys.exit(main())



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


[PATCH] D123144: FileManager: std::map => BumpPtrAllocator + DenseMap of pointers

2022-04-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a subscriber: dexonsmith.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is both smaller and faster.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123144

Files:
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp

Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -105,10 +105,10 @@
 return;
 
   // Add the virtual directory to the cache.
-  auto UDE = std::make_unique();
+  auto *UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
   UDE->Name = NamedDirEnt.first();
-  NamedDirEnt.second = *UDE.get();
-  VirtualDirectoryEntries.push_back(std::move(UDE));
+  NamedDirEnt.second = *UDE;
+  VirtualDirectoryEntries.push_back(UDE);
 
   // Recursively add the other ancestors.
   addAncestorsAsVirtualDirs(DirName);
@@ -172,14 +172,15 @@
   // same inode (this occurs on Unix-like systems when one dir is
   // symlinked to another, for example) or the same path (on
   // Windows).
-  DirectoryEntry &UDE = UniqueRealDirs[Status.getUniqueID()];
+  DirectoryEntry *&UDE = UniqueRealDirs[Status.getUniqueID()];
 
-  NamedDirEnt.second = UDE;
-  if (UDE.getName().empty()) {
+  if (!UDE) {
 // We don't have this directory yet, add it.  We use the string
 // key from the SeenDirEntries map as the string.
-UDE.Name  = InterndDirName;
+UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
+UDE->Name = InterndDirName;
   }
+  NamedDirEnt.second = *UDE;
 
   return DirectoryEntryRef(NamedDirEnt);
 }
@@ -268,7 +269,10 @@
 
   // It exists.  See if we have already opened a file with the same inode.
   // This occurs when one dir is symlinked to another, for example.
-  FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
+  FileEntry *&UFE = UniqueRealFiles[Status.getUniqueID()];
+  bool ReusingEntry = UFE != nullptr;
+  if (!UFE)
+UFE = new (FilesAlloc.Allocate()) FileEntry();
 
   // FIXME: This should just check `!Status.ExposesExternalVFSPath`, but the
   // else branch also ends up fixing up relative paths to be the actually
@@ -276,7 +280,7 @@
   // be relied on in some clients.
   if (Status.getName() == Filename) {
 // The name matches. Set the FileEntry.
-NamedFileEnt->second = FileEntryRef::MapValue(UFE, DirInfo);
+NamedFileEnt->second = FileEntryRef::MapValue(*UFE, DirInfo);
   } else {
 // We need a redirect. First grab the actual entry we want to return.
 //
@@ -295,11 +299,11 @@
 // API.
 auto &Redirection =
 *SeenFileEntries
- .insert({Status.getName(), FileEntryRef::MapValue(UFE, DirInfo)})
+ .insert({Status.getName(), FileEntryRef::MapValue(*UFE, DirInfo)})
  .first;
 assert(Redirection.second->V.is() &&
"filename redirected to a non-canonical filename?");
-assert(Redirection.second->V.get() == &UFE &&
+assert(Redirection.second->V.get() == UFE &&
"filename from getStatValue() refers to wrong file");
 
 // Cache the redirection in the previously-inserted entry, still available
@@ -311,7 +315,7 @@
   }
 
   FileEntryRef ReturnedRef(*NamedFileEnt);
-  if (UFE.isValid()) { // Already have an entry with this inode, return it.
+  if (ReusingEntry) { // Already have an entry with this inode, return it.
 
 // FIXME: This hack ensures that `getDir()` will use the path that was
 // used to lookup this file, even if we found a file by different path
@@ -322,8 +326,8 @@
 // *and* the redirection hack above is removed. The removal of the latter
 // is required since otherwise the ref will have the exposed external VFS
 // path still.
-if (&DirInfo.getDirEntry() != UFE.Dir && Status.ExposesExternalVFSPath)
-  UFE.Dir = &DirInfo.getDirEntry();
+if (&DirInfo.getDirEntry() != UFE->Dir && Status.ExposesExternalVFSPath)
+  UFE->Dir = &DirInfo.getDirEntry();
 
 // Always update LastRef to the last name by which a file was accessed.
 // FIXME: Neither this nor always using the first reference is correct; we
@@ -332,28 +336,28 @@
 // corresponding FileEntry.
 // FIXME: LastRef should be removed from FileEntry once all clients adopt
 // FileEntryRef.
-UFE.LastRef = ReturnedRef;
+UFE->LastRef = ReturnedRef;
 
 return ReturnedRef;
   }
 
   // Otherwise, we don't have this file yet, add it.
-  UFE.LastRef = ReturnedRef;
-  UFE.Size= Status.getSize();
-  UFE.ModTime = llvm::sys::toTimeT(Status.getLastModificationTime());
-  UFE.Dir = &DirInfo.getDirEntry();
-  UFE.UID = NextFileUID++;
-  UFE.UniqueID = Status.getUniqueID();
-  UFE.IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file;
-  UFE.File = std::move(F);
-  UFE.IsValid = true;
-
-  if (UFE.

[clang] bb3980a - DebugInfo: Don't use enumerators in template names for debug info as they are not canonical

2022-04-05 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-04-05T17:16:42Z
New Revision: bb3980ae9fa7e19540080285f2bf2d960ea802fc

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

LOG: DebugInfo: Don't use enumerators in template names for debug info as they 
are not canonical

Since enumerators may not be available in every translation unit they
can't be reliably used to name entities. (this also makes simplified
template name roundtripping infeasible - since the expected name could
only be rebuilt if the enumeration definition could be found (or only if
it couldn't be found, depending on the context of the original name))

Added: 


Modified: 
clang/include/clang/AST/PrettyPrinter.h
clang/lib/AST/TemplateBase.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/test/tools/llvm-dwarfdump/X86/prettyprint_types.s
llvm/test/tools/llvm-dwarfdump/X86/simplified-template-names.s

Removed: 




diff  --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index 54cb57227f7a0..cb25b2750dd43 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -74,7 +74,8 @@ struct PrintingPolicy {
 SuppressImplicitBase(false), FullyQualifiedName(false),
 PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
 UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false),
-CleanUglifiedParameters(false), EntireContentsOfLargeArray(true) {}
+CleanUglifiedParameters(false), EntireContentsOfLargeArray(true),
+UseEnumerators(true) {}
 
   /// Adjust this printing policy for cases where it's known that we're
   /// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -290,6 +291,10 @@ struct PrintingPolicy {
   /// template parameters, no matter how many elements there are.
   unsigned EntireContentsOfLargeArray : 1;
 
+  /// Whether to print enumerator non-type template parameters with a matching
+  /// enumerator name or via cast of an integer.
+  unsigned UseEnumerators : 1;
+
   /// Callbacks to use to allow the behavior of printing to be customized.
   const PrintingCallbacks *Callbacks = nullptr;
 };

diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 3418401517c84..229a8db21ab63 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -59,15 +59,17 @@ static void printIntegral(const TemplateArgument &TemplArg, 
raw_ostream &Out,
   const Type *T = TemplArg.getIntegralType().getTypePtr();
   const llvm::APSInt &Val = TemplArg.getAsIntegral();
 
-  if (const EnumType *ET = T->getAs()) {
-for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) {
-  // In Sema::CheckTemplateArugment, enum template arguments value are
-  // extended to the size of the integer underlying the enum type.  This
-  // may create a size 
diff erence between the enum value and template
-  // argument value, requiring isSameValue here instead of operator==.
-  if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
-ECD->printQualifiedName(Out, Policy);
-return;
+  if (Policy.UseEnumerators) {
+if (const EnumType *ET = T->getAs()) {
+  for (const EnumConstantDecl *ECD : ET->getDecl()->enumerators()) {
+// In Sema::CheckTemplateArugment, enum template arguments value are
+// extended to the size of the integer underlying the enum type.  This
+// may create a size 
diff erence between the enum value and template
+// argument value, requiring isSameValue here instead of operator==.
+if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
+  ECD->printQualifiedName(Out, Policy);
+  return;
+}
   }
 }
   }

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index beb640375dfba..a37dc81c4bb8f 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -248,6 +248,7 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
   PP.PrintCanonicalTypes = true;
   PP.UsePreferredNames = false;
   PP.AlwaysIncludeTypeForTemplateArgument = true;
+  PP.UseEnumerators = false;
 
   // Apply -fdebug-prefix-map.
   PP.Callbacks = &PrintCB;

diff  --git a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp 
b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
index 00c4361e11ef4..5bf1b54b97708 100644
--- a/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
+++ b/clang/test/CodeGenCXX/debug-info-simple-template-names.cpp
@@ -31,7 +31,7 @@ struct t4 {
 };
   
 t4 v1;
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, na

[PATCH] D123100: [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes

2022-04-05 Thread Amir Ayupov via Phabricator via cfe-commits
Amir accepted this revision.
Amir added a comment.

BOLT changes LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123100

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


[PATCH] D117835: [OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createSections.

2022-04-05 Thread Michael Kruse via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc082ca16f123: [OpenMPIRBuilder] Detect and fix ambiguous 
InsertPoints for createSections. (authored by Meinersbur).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117835

Files:
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/openmp-llvm.mlir

Index: mlir/test/Target/LLVMIR/openmp-llvm.mlir
===
--- mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -1854,6 +1854,9 @@
 
 // CHECK-LABEL: @omp_sections_trivial
 llvm.func @omp_sections_trivial() -> () {
+  // CHECK:   br label %[[ENTRY:[a-zA-Z_.]+]]
+
+  // CHECK: [[ENTRY]]:
   // CHECK:   br label %[[PREHEADER:.*]]
 
   // CHECK: [[PREHEADER]]:
Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -72,6 +72,21 @@
 return allocaInsertPoint;
 
   // Otherwise, insert to the entry block of the surrounding function.
+  // If the current IRBuilder InsertPoint is the function's entry, it cannot
+  // also be used for alloca insertion which would result in insertion order
+  // confusion. Create a new BasicBlock for the Builder and use the entry block
+  // for the allocs.
+  if (builder.GetInsertBlock() ==
+  &builder.GetInsertBlock()->getParent()->getEntryBlock()) {
+assert(builder.GetInsertPoint() == builder.GetInsertBlock()->end() &&
+   "Assuming end of basic block");
+llvm::BasicBlock *entryBB = llvm::BasicBlock::Create(
+builder.getContext(), "entry", builder.GetInsertBlock()->getParent(),
+builder.GetInsertBlock()->getNextNode());
+builder.CreateBr(entryBB);
+builder.SetInsertPoint(entryBB);
+  }
+
   llvm::BasicBlock &funcEntryBlock =
   builder.GetInsertBlock()->getParent()->getEntryBlock();
   return llvm::OpenMPIRBuilder::InsertPointTy(
@@ -255,23 +270,12 @@
   // TODO: Is the Parallel construct cancellable?
   bool isCancellable = false;
 
-  // Ensure that the BasicBlock for the the parallel region is sparate from the
-  // function entry which we may need to insert allocas.
-  if (builder.GetInsertBlock() ==
-  &builder.GetInsertBlock()->getParent()->getEntryBlock()) {
-assert(builder.GetInsertPoint() == builder.GetInsertBlock()->end() &&
-   "Assuming end of basic block");
-llvm::BasicBlock *entryBB =
-llvm::BasicBlock::Create(builder.getContext(), "parallel.entry",
- builder.GetInsertBlock()->getParent(),
- builder.GetInsertBlock()->getNextNode());
-builder.CreateBr(entryBB);
-builder.SetInsertPoint(entryBB);
-  }
+  llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
+  findAllocaInsertPoint(builder, moduleTranslation);
   llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
   builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createParallel(
-  ompLoc, findAllocaInsertPoint(builder, moduleTranslation), bodyGenCB,
-  privCB, finiCB, ifCond, numThreads, pbKind, isCancellable));
+  ompLoc, allocaIP, bodyGenCB, privCB, finiCB, ifCond, numThreads, pbKind,
+  isCancellable));
 
   return bodyGenStatus;
 }
@@ -522,7 +526,6 @@
   SmallVector vecValues =
   moduleTranslation.lookupValues(orderedOp.depend_vec_vars());
 
-  llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
   size_t indexVecValues = 0;
   while (indexVecValues < vecValues.size()) {
 SmallVector storeValues;
@@ -531,9 +534,11 @@
   storeValues.push_back(vecValues[indexVecValues]);
   indexVecValues++;
 }
+llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
+findAllocaInsertPoint(builder, moduleTranslation);
+llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
 builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createOrderedDepend(
-ompLoc, findAllocaInsertPoint(builder, moduleTranslation), numLoops,
-storeValues, ".cnt.addr", isDependSource));
+ompLoc, allocaIP, numLoops, storeValues, ".cnt.addr", isDependSource));
   }
   return success();
 }
@@ -634,10 +639,12 @@
   // called for variables which have destructors/finalizers.
   auto finiCB = [&](InsertPointTy codeGenIP) {};
 
+  llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
+  findAllocaInsertPoint(builder, moduleTranslation);
   llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
   builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createSections(
-  ompLo

[PATCH] D122661: [Clang] Do not warn on unused lifetime-extending vars with side effects...

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

Thanks, the additional test coverage makes it more clear that the changes are 
good. Please add a release note when landing though!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122661

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


[PATCH] D123144: FileManager: std::map => BumpPtrAllocator + DenseMap of pointers

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

thanks! maybe put an NFC in the patch name?




Comment at: clang/lib/Basic/FileManager.cpp:581
 /// do directory look-up instead of file look-up.
-std::error_code
-FileManager::getStatValue(StringRef Path, llvm::vfs::Status &Status,
-  bool isFile, std::unique_ptr *F) {
+std::error_code FileManager::getStatValue(StringRef Path,
+  llvm::vfs::Status &Status,

seems like just formatting change, same for next 2 chunks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123144

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


[PATCH] D123070: [Driver][NFC] Simplify handling of flags in Options.td

2022-04-05 Thread Emil Kieri via Phabricator via cfe-commits
ekieri added a comment.

Thank you all for the support!

@jansvoboda11 , yes, I did that, and will do it again before pushing.

@hans , thanks, that is a valid concern. I was asked to add closing comments on 
an earlier patch though, and I find them particularly useful (when accurate...) 
in this file, which does not use indentation very much. But I am happy to make 
the change if you insist, and welcome others to fill in with their opinions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123070

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


[clang-tools-extra] a0e4ba4 - [clangd] Add support to extract method for ExtractFunction Tweak

2022-04-05 Thread Sam McCall via cfe-commits

Author: Fabio Rossini Sluzala
Date: 2022-04-05T19:49:17+02:00
New Revision: a0e4ba4b4607267d96c3ab8bc1c38f5a09830692

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

LOG: [clangd] Add support to extract method for ExtractFunction Tweak

I miss more automatically refactoring functions when working with already 
running code, so I am making some small addition that I hope help more people.

This works by checking if the function is a method (CXXMethodDecl), then 
collecting information about the function that the code is being extracted, 
looking for the declaration if it is out-of-line, creating the declaration if 
it is necessary and putting the extracted function as a class-method.

This is my first code review request, sorry if I did something wrong.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
index 7bbe0d12dac9f..355c3183edf60 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -56,6 +56,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/LangOptions.h"
@@ -71,6 +72,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/raw_os_ostream.h"
 
 namespace clang {
 namespace clangd {
@@ -88,6 +90,12 @@ enum class ZoneRelative {
   OutsideFunc // Outside EnclosingFunction.
 };
 
+enum FunctionDeclKind {
+  InlineDefinition,
+  ForwardDeclaration,
+  OutOfLineDefinition
+};
+
 // A RootStmt is a statement that's fully selected including all it's children
 // and it's parent is unselected.
 // Check if a node is a root statement.
@@ -237,9 +245,6 @@ const FunctionDecl *findEnclosingFunction(const Node 
*CommonAnc) {
 if (CurNode->ASTNode.get())
   return nullptr;
 if (const FunctionDecl *Func = CurNode->ASTNode.get()) {
-  // FIXME: Support extraction from methods.
-  if (isa(Func))
-return nullptr;
   // FIXME: Support extraction from templated functions.
   if (Func->isTemplated())
 return nullptr;
@@ -343,34 +348,53 @@ struct NewFunction {
   QualType ReturnType;
   std::vector Parameters;
   SourceRange BodyRange;
-  SourceLocation InsertionPoint;
-  const DeclContext *EnclosingFuncContext;
+  SourceLocation DefinitionPoint;
+  llvm::Optional ForwardDeclarationPoint;
+  const CXXRecordDecl *EnclosingClass = nullptr;
+  const NestedNameSpecifier *DefinitionQualifier = nullptr;
+  const DeclContext *SemanticDC = nullptr;
+  const DeclContext *SyntacticDC = nullptr;
+  const DeclContext *ForwardDeclarationSyntacticDC = nullptr;
   bool CallerReturnsValue = false;
+  bool Static = false;
+  ConstexprSpecKind Constexpr = ConstexprSpecKind::Unspecified;
+  bool Const = false;
+
   // Decides whether the extracted function body and the function call need a
   // semicolon after extraction.
   tooling::ExtractionSemicolonPolicy SemicolonPolicy;
-  NewFunction(tooling::ExtractionSemicolonPolicy SemicolonPolicy)
-  : SemicolonPolicy(SemicolonPolicy) {}
+  const LangOptions *LangOpts;
+  NewFunction(tooling::ExtractionSemicolonPolicy SemicolonPolicy,
+  const LangOptions *LangOpts)
+  : SemicolonPolicy(SemicolonPolicy), LangOpts(LangOpts) {}
   // Render the call for this function.
   std::string renderCall() const;
   // Render the definition for this function.
-  std::string renderDefinition(const SourceManager &SM) const;
+  std::string renderDeclaration(FunctionDeclKind K,
+const DeclContext &SemanticDC,
+const DeclContext &SyntacticDC,
+const SourceManager &SM) const;
 
 private:
-  std::string renderParametersForDefinition() const;
+  std::string
+  renderParametersForDeclaration(const DeclContext &Enclosing) const;
   std::string renderParametersForCall() const;
+  std::string renderSpecifiers(FunctionDeclKind K) const;
+  std::string renderQualifiers() const;
+  std::string renderDeclarationName(FunctionDeclKind K) const;
   // Generate the function body.
   std::string getFuncBody(const SourceManager &SM) const;
 };
 
-std::string NewFunction::renderParametersForDefinition() const {
+std::string NewFunction::renderParametersForDeclarat

[PATCH] D122698: [clangd] Add support to extract method for ExtractFunction Tweak

2022-04-05 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0e4ba4b4607: [clangd] Add support to extract method for 
ExtractFunction Tweak (authored by FabioRS, committed by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D122698?vs=420336&id=420576#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122698

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
@@ -114,16 +114,48 @@
   // Don't extract when we need to make a function as a parameter.
   EXPECT_THAT(apply("void f() { [[int a; f();]] }"), StartsWith("fail"));
 
-  // We don't extract from methods for now since they may involve multi-file
-  // edits
-  std::string MethodFailInput = R"cpp(
+  std::string MethodInput = R"cpp(
 class T {
   void f() {
 [[int x;]]
   }
 };
   )cpp";
-  EXPECT_EQ(apply(MethodFailInput), "unavailable");
+  std::string MethodCheckOutput = R"cpp(
+class T {
+  void extracted() {
+int x;
+}
+void f() {
+extracted();
+  }
+};
+  )cpp";
+  EXPECT_EQ(apply(MethodInput), MethodCheckOutput);
+
+  std::string OutOfLineMethodInput = R"cpp(
+class T {
+  void f();
+};
+
+void T::f() {
+  [[int x;]]
+}
+  )cpp";
+  std::string OutOfLineMethodCheckOutput = R"cpp(
+class T {
+  void extracted();
+void f();
+};
+
+void T::extracted() {
+int x;
+}
+void T::f() {
+  extracted();
+}
+  )cpp";
+  EXPECT_EQ(apply(OutOfLineMethodInput), OutOfLineMethodCheckOutput);
 
   // We don't extract from templated functions for now as templates are hard
   // to deal with.
@@ -159,6 +191,333 @@
   EXPECT_EQ(apply(CompoundFailInput), "unavailable");
 }
 
+TEST_F(ExtractFunctionTest, DifferentHeaderSourceTest) {
+  Header = R"cpp(
+class SomeClass {
+  void f();
+};
+  )cpp";
+
+  std::string OutOfLineSource = R"cpp(
+void SomeClass::f() {
+  [[int x;]]
+}
+  )cpp";
+
+  std::string OutOfLineSourceOutputCheck = R"cpp(
+void SomeClass::extracted() {
+int x;
+}
+void SomeClass::f() {
+  extracted();
+}
+  )cpp";
+
+  std::string HeaderOutputCheck = R"cpp(
+class SomeClass {
+  void extracted();
+void f();
+};
+  )cpp";
+
+  llvm::StringMap EditedFiles;
+
+  EXPECT_EQ(apply(OutOfLineSource, &EditedFiles), OutOfLineSourceOutputCheck);
+  EXPECT_EQ(EditedFiles.begin()->second, HeaderOutputCheck);
+}
+
+TEST_F(ExtractFunctionTest, DifferentFilesNestedTest) {
+  Header = R"cpp(
+class T {
+class SomeClass {
+  void f();
+};
+};
+  )cpp";
+
+  std::string NestedOutOfLineSource = R"cpp(
+void T::SomeClass::f() {
+  [[int x;]]
+}
+  )cpp";
+
+  std::string NestedOutOfLineSourceOutputCheck = R"cpp(
+void T::SomeClass::extracted() {
+int x;
+}
+void T::SomeClass::f() {
+  extracted();
+}
+  )cpp";
+
+  std::string NestedHeaderOutputCheck = R"cpp(
+class T {
+class SomeClass {
+  void extracted();
+void f();
+};
+};
+  )cpp";
+
+  llvm::StringMap EditedFiles;
+
+  EXPECT_EQ(apply(NestedOutOfLineSource, &EditedFiles),
+NestedOutOfLineSourceOutputCheck);
+  EXPECT_EQ(EditedFiles.begin()->second, NestedHeaderOutputCheck);
+}
+
+TEST_F(ExtractFunctionTest, ConstexprDifferentHeaderSourceTest) {
+  Header = R"cpp(
+class SomeClass {
+  constexpr void f() const;
+};
+  )cpp";
+
+  std::string OutOfLineSource = R"cpp(
+constexpr void SomeClass::f() const {
+  [[int x;]]
+}
+  )cpp";
+
+  std::string OutOfLineSourceOutputCheck = R"cpp(
+constexpr void SomeClass::extracted() const {
+int x;
+}
+constexpr void SomeClass::f() const {
+  extracted();
+}
+  )cpp";
+
+  std::string HeaderOutputCheck = R"cpp(
+class SomeClass {
+  constexpr void extracted() const;
+constexpr void f() const;
+};
+  )cpp";
+
+  llvm::StringMap EditedFiles;
+
+  EXPECT_EQ(apply(OutOfLineSource, &EditedFiles), OutOfLineSourceOutputCheck);
+  EXPECT_NE(EditedFiles.begin(), EditedFiles.end())
+  << "The header should be edited and receives the declaration of the new "
+ "function";
+
+  if (EditedFiles.begin() != EditedFiles.end()) {
+EXPECT_EQ(EditedFiles.begin()->second, HeaderOutputCheck);
+  }
+}
+
+TEST_F(ExtractFunctionTest, ConstevalDifferentHeaderSourceTest) {
+  ExtraArgs.push_back("--std=c++20");
+  Header = R"cpp(
+class SomeClass {
+  consteval void f() const;
+};
+  )cpp";
+
+  std::string OutOfLineSource = R"cpp(
+consteval void SomeClass::f() const {
+  [[int x;]]
+}
+  )cpp";
+
+  std

[PATCH] D122698: [clangd] Add support to extract method for ExtractFunction Tweak

2022-04-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

You're right about the out-of-line function case. Current version looks great!
I had to rework the logic around merging the edits a little, it wasn't quite 
correct and was hitting assertions (not sure if you were seeing these locally, 
but phabricator is not currently running the clangd tests properly).

Thanks again, landing now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122698

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


[clang] cf1c550 - FileManager: std::map => BumpPtrAllocator + DenseMap of pointers. NFC

2022-04-05 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-04-05T19:54:44+02:00
New Revision: cf1c5507b7259de219c45d601ee3249993263ec1

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

LOG: FileManager: std::map => BumpPtrAllocator + DenseMap of pointers. NFC

This is both smaller and faster.

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

Added: 


Modified: 
clang/include/clang/Basic/FileManager.h
clang/lib/Basic/FileManager.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 974771a8f8f39..d3dc54a6be2ac 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -53,24 +53,26 @@ class FileSystemStatCache;
 class FileManager : public RefCountedBase {
   IntrusiveRefCntPtr FS;
   FileSystemOptions FileSystemOpts;
+  llvm::SpecificBumpPtrAllocator FilesAlloc;
+  llvm::SpecificBumpPtrAllocator DirsAlloc;
 
   /// Cache for existing real directories.
-  std::map UniqueRealDirs;
+  llvm::DenseMap UniqueRealDirs;
 
   /// Cache for existing real files.
-  std::map UniqueRealFiles;
+  llvm::DenseMap UniqueRealFiles;
 
   /// The virtual directories that we have allocated.
   ///
   /// For each virtual file (e.g. foo/bar/baz.cpp), we add all of its parent
   /// directories (foo/ and foo/bar/) here.
-  SmallVector, 4> VirtualDirectoryEntries;
+  SmallVector VirtualDirectoryEntries;
   /// The virtual files that we have allocated.
-  SmallVector, 4> VirtualFileEntries;
+  SmallVector VirtualFileEntries;
 
   /// A set of files that bypass the maps and uniquing.  They can have
   /// conflicting filenames.
-  SmallVector, 0> BypassFileEntries;
+  SmallVector BypassFileEntries;
 
   /// A cache that maps paths to directory entries (either real or
   /// virtual) we have looked up, or an error that occurred when we looked up

diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index d30a5f72b9836..7c2cc582009c3 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -105,10 +105,10 @@ void FileManager::addAncestorsAsVirtualDirs(StringRef 
Path) {
 return;
 
   // Add the virtual directory to the cache.
-  auto UDE = std::make_unique();
+  auto *UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
   UDE->Name = NamedDirEnt.first();
-  NamedDirEnt.second = *UDE.get();
-  VirtualDirectoryEntries.push_back(std::move(UDE));
+  NamedDirEnt.second = *UDE;
+  VirtualDirectoryEntries.push_back(UDE);
 
   // Recursively add the other ancestors.
   addAncestorsAsVirtualDirs(DirName);
@@ -172,14 +172,15 @@ FileManager::getDirectoryRef(StringRef DirName, bool 
CacheFailure) {
   // same inode (this occurs on Unix-like systems when one dir is
   // symlinked to another, for example) or the same path (on
   // Windows).
-  DirectoryEntry &UDE = UniqueRealDirs[Status.getUniqueID()];
+  DirectoryEntry *&UDE = UniqueRealDirs[Status.getUniqueID()];
 
-  NamedDirEnt.second = UDE;
-  if (UDE.getName().empty()) {
+  if (!UDE) {
 // We don't have this directory yet, add it.  We use the string
 // key from the SeenDirEntries map as the string.
-UDE.Name  = InterndDirName;
+UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
+UDE->Name = InterndDirName;
   }
+  NamedDirEnt.second = *UDE;
 
   return DirectoryEntryRef(NamedDirEnt);
 }
@@ -268,7 +269,10 @@ FileManager::getFileRef(StringRef Filename, bool openFile, 
bool CacheFailure) {
 
   // It exists.  See if we have already opened a file with the same inode.
   // This occurs when one dir is symlinked to another, for example.
-  FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
+  FileEntry *&UFE = UniqueRealFiles[Status.getUniqueID()];
+  bool ReusingEntry = UFE != nullptr;
+  if (!UFE)
+UFE = new (FilesAlloc.Allocate()) FileEntry();
 
   // FIXME: This should just check `!Status.ExposesExternalVFSPath`, but the
   // else branch also ends up fixing up relative paths to be the actually
@@ -276,7 +280,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, 
bool CacheFailure) {
   // be relied on in some clients.
   if (Status.getName() == Filename) {
 // The name matches. Set the FileEntry.
-NamedFileEnt->second = FileEntryRef::MapValue(UFE, DirInfo);
+NamedFileEnt->second = FileEntryRef::MapValue(*UFE, DirInfo);
   } else {
 // We need a redirect. First grab the actual entry we want to return.
 //
@@ -295,11 +299,11 @@ FileManager::getFileRef(StringRef Filename, bool 
openFile, bool CacheFailure) {
 // API.
 auto &Redirection =
 *SeenFileEntries
- .insert({Status.getName(), FileEntryRef::MapValue(UFE, DirInfo)})
+ .insert({Status.getName(), FileEntryRef::MapValue(*UFE, DirInfo)})
  .first;
 

[PATCH] D123144: FileManager: std::map => BumpPtrAllocator + DenseMap of pointers

2022-04-05 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rGcf1c5507b725: FileManager: std::map => BumpPtrAllocator + 
DenseMap of pointers. NFC (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D123144?vs=420567&id=420579#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123144

Files:
  clang/include/clang/Basic/FileManager.h
  clang/lib/Basic/FileManager.cpp

Index: clang/lib/Basic/FileManager.cpp
===
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -105,10 +105,10 @@
 return;
 
   // Add the virtual directory to the cache.
-  auto UDE = std::make_unique();
+  auto *UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
   UDE->Name = NamedDirEnt.first();
-  NamedDirEnt.second = *UDE.get();
-  VirtualDirectoryEntries.push_back(std::move(UDE));
+  NamedDirEnt.second = *UDE;
+  VirtualDirectoryEntries.push_back(UDE);
 
   // Recursively add the other ancestors.
   addAncestorsAsVirtualDirs(DirName);
@@ -172,14 +172,15 @@
   // same inode (this occurs on Unix-like systems when one dir is
   // symlinked to another, for example) or the same path (on
   // Windows).
-  DirectoryEntry &UDE = UniqueRealDirs[Status.getUniqueID()];
+  DirectoryEntry *&UDE = UniqueRealDirs[Status.getUniqueID()];
 
-  NamedDirEnt.second = UDE;
-  if (UDE.getName().empty()) {
+  if (!UDE) {
 // We don't have this directory yet, add it.  We use the string
 // key from the SeenDirEntries map as the string.
-UDE.Name  = InterndDirName;
+UDE = new (DirsAlloc.Allocate()) DirectoryEntry();
+UDE->Name = InterndDirName;
   }
+  NamedDirEnt.second = *UDE;
 
   return DirectoryEntryRef(NamedDirEnt);
 }
@@ -268,7 +269,10 @@
 
   // It exists.  See if we have already opened a file with the same inode.
   // This occurs when one dir is symlinked to another, for example.
-  FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
+  FileEntry *&UFE = UniqueRealFiles[Status.getUniqueID()];
+  bool ReusingEntry = UFE != nullptr;
+  if (!UFE)
+UFE = new (FilesAlloc.Allocate()) FileEntry();
 
   // FIXME: This should just check `!Status.ExposesExternalVFSPath`, but the
   // else branch also ends up fixing up relative paths to be the actually
@@ -276,7 +280,7 @@
   // be relied on in some clients.
   if (Status.getName() == Filename) {
 // The name matches. Set the FileEntry.
-NamedFileEnt->second = FileEntryRef::MapValue(UFE, DirInfo);
+NamedFileEnt->second = FileEntryRef::MapValue(*UFE, DirInfo);
   } else {
 // We need a redirect. First grab the actual entry we want to return.
 //
@@ -295,11 +299,11 @@
 // API.
 auto &Redirection =
 *SeenFileEntries
- .insert({Status.getName(), FileEntryRef::MapValue(UFE, DirInfo)})
+ .insert({Status.getName(), FileEntryRef::MapValue(*UFE, DirInfo)})
  .first;
 assert(Redirection.second->V.is() &&
"filename redirected to a non-canonical filename?");
-assert(Redirection.second->V.get() == &UFE &&
+assert(Redirection.second->V.get() == UFE &&
"filename from getStatValue() refers to wrong file");
 
 // Cache the redirection in the previously-inserted entry, still available
@@ -311,7 +315,7 @@
   }
 
   FileEntryRef ReturnedRef(*NamedFileEnt);
-  if (UFE.isValid()) { // Already have an entry with this inode, return it.
+  if (ReusingEntry) { // Already have an entry with this inode, return it.
 
 // FIXME: This hack ensures that `getDir()` will use the path that was
 // used to lookup this file, even if we found a file by different path
@@ -322,8 +326,8 @@
 // *and* the redirection hack above is removed. The removal of the latter
 // is required since otherwise the ref will have the exposed external VFS
 // path still.
-if (&DirInfo.getDirEntry() != UFE.Dir && Status.ExposesExternalVFSPath)
-  UFE.Dir = &DirInfo.getDirEntry();
+if (&DirInfo.getDirEntry() != UFE->Dir && Status.ExposesExternalVFSPath)
+  UFE->Dir = &DirInfo.getDirEntry();
 
 // Always update LastRef to the last name by which a file was accessed.
 // FIXME: Neither this nor always using the first reference is correct; we
@@ -332,28 +336,28 @@
 // corresponding FileEntry.
 // FIXME: LastRef should be removed from FileEntry once all clients adopt
 // FileEntryRef.
-UFE.LastRef = ReturnedRef;
+UFE->LastRef = ReturnedRef;
 
 return ReturnedRef;
   }
 
   // Otherwise, we don't have this file yet, add it.
-  UFE.LastRef = ReturnedRef;
-  UFE.Size= Status.getSize();
-  UFE.ModTime = llvm::sys::toTimeT(Status.getLastModificationTime());
-  UFE.Dir = &DirInfo.getDirEntry();
-  UFE.UID = NextFileUID++;
-  UFE.UniqueID =

[PATCH] D123104: [Modules] Use looked-up filename when looking for module maps

2022-04-05 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir accepted this revision.
benlangmuir added inline comments.



Comment at: clang/include/clang/Lex/HeaderSearch.h:758
+ bool IsSystemHeaderDir,
+ StringRef FileName = "");
 

This parameter could use a comment, even if it just points you to read the 
FIXME in the implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123104

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


[PATCH] D122865: [HLSL][clang][Driver] Support target profile command line option.

2022-04-05 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added reviewers: pow2clk, rnk, bogner, MaskRay, dexonsmith.
beanz added a comment.
Herald added a subscriber: StephenFan.

Looping in a few extra reviewers, also added some comments below.




Comment at: clang/lib/Driver/ToolChains/HLSL.cpp:43
+return false;
+  if (!Version.getMinor())
+return false;

Do we need to verify this or can we just assume if there is no minor version 
specified that the version is 0?



Comment at: clang/lib/Driver/ToolChains/HLSL.cpp:57
+  case Triple::EnvironmentType::Compute: {
+if (isLegalVersion(Version, 4, 0, 1))
+  return true;

Do we actually care if someone sets a compute shader as targeting shader model 
4.8 (a version that doesn't really exist)?

For compatibility with DXC, when targeting DXIL we're going to end up bumping 
older shader model targets up to 6.0 anyways, so I'm not sure it makes sense to 
verify at this level.

I think it is sufficient to just verify that the version is >= the shader model 
that introduced the stage.



Comment at: clang/lib/Driver/ToolChains/HLSL.cpp:62
+
+if (isLegalVersion(Version, 6, 0, MaxShaderModel6Minor))
+  return true;

One down side to this type of version matching is that when new shader model 
versions are introduced all of this code needs to be updated.

If we don't need this in-depth verification we should leave it out. I suspect 
drivers providing runtime verification, and the dxil verification we do later 
means we can leave this off.



Comment at: clang/lib/Driver/ToolChains/HLSL.h:28
+
+  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
+  types::ID InputType) const override;

nit: function names should start with a lowercase letter:

https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122865

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


[PATCH] D119609: [Clang][Sema] Prohibit statement expression in the default argument

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

This should also have a release note that explains the change in behavior, 
since we're now being more restrictive with what programs we accept. Aside from 
the release note and the column wrapping, this LGTM!




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4384
+def err_stmt_expr_in_default_arg : Error<
+  "default %select{argument|non-type template argument}0 may not use a GNU 
statement expression">;
 

You should re-wrap this to the usual 80-col limit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[PATCH] D122955: [clang] NFC: Enhance comments in CodeGen for multiversion function support.

2022-04-05 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann updated this revision to Diff 420586.
tahonermann added a comment.

Reworded a comment to address code review commentary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122955

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -348,8 +348,9 @@
   /// is defined once we get to the end of the of the translation unit.
   std::vector Aliases;
 
-  /// List of multiversion functions that have to be emitted.  Used to make 
sure
-  /// we properly emit the iFunc.
+  /// List of multiversion functions to be emitted. This list is processed in
+  /// conjunction with other deferred symbols and is used to ensure that
+  /// multiversion function resolvers and ifuncs are defined and emitted.
   std::vector MultiVersionFuncs;
 
   typedef llvm::StringMap > ReplacementsTy;
@@ -1466,9 +1467,20 @@
   llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
   ForDefinition_t IsForDefinition = NotForDefinition);
 
+  // References to multiversion functions are resolved through an implicitly
+  // defined resolver function. This function is responsible for creating
+  // the resolver symbol for the provided declaration. The value returned
+  // will be for an ifunc (llvm::GlobalIFunc) if the current target supports
+  // that feature and for a regular function (llvm::GlobalValue) otherwise.
   llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD,
   llvm::Type *DeclTy,
   const FunctionDecl *FD);
+
+  // In scenarios where a function is not known to be a multiversion function
+  // until a later declaration, it is sometimes necessary to change the
+  // previously created mangled name to align with requirements of whatever
+  // multiversion function kind the function is now known to be. This function
+  // is responsible for performing such mangled name updates.
   void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD,
StringRef &CurName);
 
@@ -1561,6 +1573,7 @@
   // registered by the atexit subroutine using unatexit.
   void unregisterGlobalDtorsWithUnAtExit();
 
+  /// Emit deferred multiversion function resolvers and associated variants.
   void emitMultiVersionFunctions();
 
   /// Emit any vtables which we deferred and still have a use for.
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3768,7 +3768,7 @@
 }
 
 if (FD->isMultiVersion()) {
-UpdateMultiVersionNames(GD, FD, MangledName);
+  UpdateMultiVersionNames(GD, FD, MangledName);
   if (!IsForDefinition)
 return GetOrCreateMultiVersionResolver(GD, Ty, FD);
 }
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2723,8 +2723,12 @@
 StringRef getFeatureStr(unsigned Index) const {
   return *(featuresStrs_begin() + Index);
 }
-// 'default' is always moved to the end, so it isn't considered
-// when mangling the index.
+// Given an index into the 'featuresStrs' sequence, compute a unique
+// ID to be used with function name mangling for the associated variant.
+// This mapping is necessary due to a requirement that the mangling ID
+// used for the "default" variant be the largest mangling ID in the
+// variant set. Duplicate variants present in 'featuresStrs' are also
+// assigned their own unique ID (the mapping is bijective).
 unsigned getMangledIndex(unsigned Index) const {
   if (getFeatureStr(Index) == "default")
 return std::count_if(featuresStrs_begin(), featuresStrs_end(),
@@ -2734,9 +2738,10 @@
[](StringRef S) { return S != "default"; });
 }
 
-// True if this is the first of this version to appear in the config 
string.
-// This is used to make sure we don't try to emit this function multiple
-// times.
+// Given an index into the 'featuresStrs' sequence, determine if the
+// index corresponds to the first instance of the named variant. This
+// is used to skip over duplicate variant instances when iterating over
+// 'featuresStrs'.
 bool isFirstOfVersion(unsigned Index) const {
   StringRef FeatureStr(getFeatureStr(Index));
   return 0 == std::count_if(


Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/l

  1   2   3   >