[PATCH] D120289: [clang][dataflow] Add SAT solver interface and implementation

2022-02-21 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/Solver.h:39
+  ///  All elements in `Vals` must be non-null.
+  virtual Result solve(llvm::DenseSet Vals) = 0;
+};

ymandel wrote:
> Which `Result` is expected if the `Solver` gives up, assuming that's allowed 
> in this API.
Added a `TimedOut` result for such cases.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:373
+
+  Solver::Result solve() && {
+size_t I = 0;

ymandel wrote:
> Why this constraint?
That's because `solve` must be called at most once for 
`WatchedLiteralsSolverImpl` - it initializes its data structures in the 
constructor and then mutates them in `solve`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120289

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


[PATCH] D120289: [clang][dataflow] Add SAT solver interface and implementation

2022-02-21 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev updated this revision to Diff 410460.
sgatev marked 6 inline comments as done.
sgatev added a comment.

Address reviewers' comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120289

Files:
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -0,0 +1,274 @@
+//===- unittests/Analysis/FlowSensitive/SolverTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/Solver.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+
+class SolverTest : public ::testing::Test {
+protected:
+  // Checks if the conjunction of `Vals` is satisfiable and returns the
+  // corresponding result.
+  Solver::Result solve(llvm::DenseSet Vals) {
+return WatchedLiteralsSolver().solve(std::move(Vals));
+  }
+
+  // Creates an atomic boolean value.
+  BoolValue *atom() {
+Vals.push_back(std::make_unique());
+return Vals.back().get();
+  }
+
+  // Creates a boolean conjunction value.
+  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean disjunction value.
+  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean negation value.
+  BoolValue *neg(BoolValue *SubVal) {
+Vals.push_back(std::make_unique(*SubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean implication value.
+  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return disj(neg(LeftSubVal), RightSubVal);
+  }
+
+  // Creates a boolean biconditional value.
+  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+  }
+
+private:
+  std::vector> Vals;
+};
+
+TEST_F(SolverTest, Var) {
+  auto X = atom();
+
+  // X
+  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, NegatedVar) {
+  auto X = atom();
+  auto NotX = neg(X);
+
+  // !X
+  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, UnitConflict) {
+  auto X = atom();
+  auto NotX = neg(X);
+
+  // X ^ !X
+  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, DistinctVars) {
+  auto X = atom();
+  auto Y = atom();
+  auto NotY = neg(Y);
+
+  // X ^ !Y
+  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, DoubleNegation) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto NotNotX = neg(NotX);
+
+  // !!X ^ !X
+  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, NegatedDisjunction) {
+  auto X = atom();
+  auto Y = atom();
+  auto XOrY = disj(X, Y);
+  auto NotXOrY = neg(XOrY);
+
+  // !(X v Y) ^ (X v Y)
+  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, NegatedConjunction) {
+  auto X = atom();
+  auto Y = atom();
+  auto XAndY = conj(X, Y);
+  auto NotXAndY = neg(XAndY);
+
+  // !(X ^ Y) ^ (X ^ Y)
+  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, DisjunctionSameVars) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto XOrNotX = disj(X, NotX);
+
+  // X v !X
+  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, ConjunctionSameVarsConflict) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto XAndNotX = conj(X, NotX);
+
+  // X ^ !X
+  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, PureVar) {
+  auto X = atom();
+  auto Y = atom();
+  auto NotX = neg(X);
+  auto NotXOrY = disj(NotX, Y);
+  auto NotY = neg(Y);
+  auto NotXOrNotY = disj(NotX, NotY);
+
+  // (!X v Y) ^ (!X v !Y)
+  EXPECT_EQ(solve({NotXOrY, NotXOrNotY}), Solver::Result::Satisfiable);
+}
+

[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/test/Modules/cxx20-multiple-partitions.cpp:48
+#else
+#error "no TU set"
+#endif

Instead of splitting the file with preprocessor, you could use the `split-file` 
utility (introduced in D83834).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D119599: [clang-format] Add option to align compound assignments like `+=`

2022-02-21 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Nice job! Please let us a bit of time to review that.
Also, I think it would be good to get a reviewer that knows well the yaml 
parts. Or even split it to a separate revision.
And this part needs tests too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119599

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


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D118586#3336933 , @iains wrote:

> In D118586#3336892 , @ChuanqiXu 
> wrote:
>
>> In D118586#3336865 , @iains wrote:
>>
>>> In D118586#3336612 , @ChuanqiXu 
>>> wrote:
>>>
 (May off the patch)
>>>
>>> I am not sure what you mean here.
>>
>> I mean this comment is not related to the patch. So it doesn't mean to block 
>> the patch landing.
>>
 BTW, I know you also work on GCC frontend. I want to consultant what's 
 your opinion to uniform the command line options between Clang and GCC. 
 Now it looks totally different. I feel it would be a problem for clang. 
 Since the command line between clang and gcc are basically compatible so 
 that user who decide to use clang could turn back to use gcc whenever he 
 want. But I am worrying that it would be a harder decision for users if 
 them are going to use clang. Since the cost to use GCC again would be 
 higher.
>>>
>>> We have the same objective: to keep user-facing options and functionality 
>>> the same between clang and GCC (easier for both user and for build systems).
>>> The content of this patch does not alter that. BTW GCC also keeps the 
>>> module name as "Primary:Parition" internally and user-facing output.  //The 
>>> module name in C++20 modules has no fixed mapping to the BMI/CMI filename 
>>> on disk,.//
>>
>> I just tested the behavior of GCC. When I compile a partition interface unit 
>> (let's name is `mod:part`), it would generate a file named `mod-part,gcm` 
>> under the directory `gcm.cache`. So I feel what GCC does here is more 
>> aggressive, it doesn't only choose the separator '-'. It would create an 
>> cache directory by default. (I am not blaming it. I like the style too. 
>> Otherwise, we need to sore CMI to a place by hand). What I want to say here 
>> is that GCC would replace '-' to ':' when maps to the filesystem. I am OK to 
>> not implement this in the series patch. But I hope we could get in consensus 
>> that we should implement this.
>
> I think I am not explaining well enough ...
>
> Please execute "strings  gcm.cache/mod-part,gcm" - you will see that the 
> Module name is "mod:part" in the module file (GCC knows the module as 
> mod:part internally, it is only the on-disk name that is changed).
>
> We //could// choose to use "mod-part.pcm" in our example test cases here, but 
> it would not make any difference to the requirement - the mapping between 
> module name and filename has to be determined by the mechanism that 
> interfaces with the filesystem (we cannot impose that mapping on the module 
> names internally to the compiler - since the mapping is unknown in the 
> general case).
>
> So we would implement a basic interface (in the module loader, I suppose 
> since that is available for jobs without a preprocessor)  that would give 
> pathNameForModuleName(ModuleName) ,... and probably 
> moduleNameForPathName(PathName) ... those would interface to whatever means 
> was used (e.g. ,module mapper, P1184  etc).  
> You could arrange for the default implementation to do the translation you 
> see in GCC (mod:part <=> mod-part.pcm).

Thanks for the detailed explanation. I think we're in consensus now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D118586#3336892 , @ChuanqiXu wrote:

> In D118586#3336865 , @iains wrote:
>
>> In D118586#3336612 , @ChuanqiXu 
>> wrote:
>>
>>> (May off the patch)
>>
>> I am not sure what you mean here.
>
> I mean this comment is not related to the patch. So it doesn't mean to block 
> the patch landing.
>
>>> BTW, I know you also work on GCC frontend. I want to consultant what's your 
>>> opinion to uniform the command line options between Clang and GCC. Now it 
>>> looks totally different. I feel it would be a problem for clang. Since the 
>>> command line between clang and gcc are basically compatible so that user 
>>> who decide to use clang could turn back to use gcc whenever he want. But I 
>>> am worrying that it would be a harder decision for users if them are going 
>>> to use clang. Since the cost to use GCC again would be higher.
>>
>> We have the same objective: to keep user-facing options and functionality 
>> the same between clang and GCC (easier for both user and for build systems).
>> The content of this patch does not alter that. BTW GCC also keeps the module 
>> name as "Primary:Parition" internally and user-facing output.  //The module 
>> name in C++20 modules has no fixed mapping to the BMI/CMI filename on 
>> disk,.//
>
> I just tested the behavior of GCC. When I compile a partition interface unit 
> (let's name is `mod:part`), it would generate a file named `mod-part,gcm` 
> under the directory `gcm.cache`. So I feel what GCC does here is more 
> aggressive, it doesn't only choose the separator '-'. It would create an 
> cache directory by default. (I am not blaming it. I like the style too. 
> Otherwise, we need to sore CMI to a place by hand). What I want to say here 
> is that GCC would replace '-' to ':' when maps to the filesystem. I am OK to 
> not implement this in the series patch. But I hope we could get in consensus 
> that we should implement this.

I think I am not explaining well enough ...

Please execute "strings  gcm.cache/mod-part,gcm" - you will see that the Module 
name is "mod:part" in the module file (GCC knows the module as mod:part 
internally, it is only the on-disk name that is changed).

We //could// choose to use "mod-part.pcm" in our example test cases here, but 
it would not make any difference to the requirement - the mapping between 
module name and filename has to be determined by the mechanism that interfaces 
with the filesystem (we cannot impose that mapping on the module names 
internally to the compiler - since the mapping is unknown in the general case).

So we would implement a basic interface (in the module loader, I suppose since 
that is available for jobs without a preprocessor)  that would give 
pathNameForModuleName(ModuleName) ,... and probably 
moduleNameForPathName(PathName) ... those would interface to whatever means was 
used (e.g. ,module mapper, P1184  etc).  You 
could arrange for the default implementation to do the translation you see in 
GCC (mod:part <=> mod-part.pcm).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D118586#3336865 , @iains wrote:

> In D118586#3336612 , @ChuanqiXu 
> wrote:
>
>> (May off the patch)
>
> I am not sure what you mean here.

I mean this comment is not related to the patch. So it doesn't mean to block 
the patch landing.

>> BTW, I know you also work on GCC frontend. I want to consultant what's your 
>> opinion to uniform the command line options between Clang and GCC. Now it 
>> looks totally different. I feel it would be a problem for clang. Since the 
>> command line between clang and gcc are basically compatible so that user who 
>> decide to use clang could turn back to use gcc whenever he want. But I am 
>> worrying that it would be a harder decision for users if them are going to 
>> use clang. Since the cost to use GCC again would be higher.
>
> We have the same objective: to keep user-facing options and functionality the 
> same between clang and GCC (easier for both user and for build systems).
> The content of this patch does not alter that. BTW GCC also keeps the module 
> name as "Primary:Parition" internally and user-facing output.  //The module 
> name in C++20 modules has no fixed mapping to the BMI/CMI filename on disk,.//

I just tested the behavior of GCC. When I compile a partition interface unit 
(let's name is `mod:part`), it would generate a file named `mod-part,gcm` under 
the directory `gcm.cache`. So I feel what GCC does here is more aggressive, it 
doesn't only choose the separator '-'. It would create an cache directory by 
default. (I am not blaming it. I like the style too. Otherwise, we need to sore 
CMI to a place by hand). What I want to say here is that GCC would replace '-' 
to ':' when maps to the filesystem. I am OK to not implement this in the series 
patch. But I hope we could get in consensus that we should implement this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D111100: enable plugins for clang-tidy

2022-02-21 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

I've proposed a fix for the standalone builds here D120301 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D00

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


[PATCH] D120301: clang-tools-extra: Make test dependency on LLVMHello optional

2022-02-21 Thread Tom Stellard via Phabricator via cfe-commits
tstellar created this revision.
tstellar added a reviewer: vtjnash.
Herald added a subscriber: mgorny.
tstellar requested review of this revision.
Herald added a project: clang-tools-extra.

This fixes clang + clang-tools-extra standalone build after
36892727e4f19a60778e371d78f8fb09d8122c85 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120301

Files:
  clang-tools-extra/test/CMakeLists.txt
  clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
  clang-tools-extra/test/lit.cfg.py
  clang-tools-extra/test/lit.site.cfg.py.in


Index: clang-tools-extra/test/lit.site.cfg.py.in
===
--- clang-tools-extra/test/lit.site.cfg.py.in
+++ clang-tools-extra/test/lit.site.cfg.py.in
@@ -13,6 +13,7 @@
 config.target_triple = "@TARGET_TRIPLE@"
 config.clang_tidy_staticanalyzer = @CLANG_TIDY_ENABLE_STATIC_ANALYZER@
 config.has_plugins = @CLANG_PLUGIN_SUPPORT@ & ~@LLVM_INSTALL_TOOLCHAIN_ONLY@
+config.has_llvm_hello = @LLVM_HAS_LLVM_HELLO@
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
Index: clang-tools-extra/test/lit.cfg.py
===
--- clang-tools-extra/test/lit.cfg.py
+++ clang-tools-extra/test/lit.cfg.py
@@ -155,3 +155,6 @@
 # Plugins (loadable modules)
 if config.has_plugins and config.llvm_plugin_ext:
 config.available_features.add('plugins')
+
+if config.has_llvm_hello:
+config.available_features.add("llvm-hello")
Index: clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
===
--- clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
+++ clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
@@ -1,4 +1,4 @@
-// REQUIRES: plugins
+// REQUIRES: plugins, llvm-hello
 // RUN: clang-tidy -checks='-*,mytest*' --list-checks -load 
%llvmshlibdir/CTTestTidyModule%pluginext -load 
%llvmshlibdir/LLVMHello%pluginext | FileCheck --check-prefix=CHECK-LIST %s
 // CHECK-LIST: Enabled checks:
 // CHECK-LIST-NEXT:mytest1
Index: clang-tools-extra/test/CMakeLists.txt
===
--- clang-tools-extra/test/CMakeLists.txt
+++ clang-tools-extra/test/CMakeLists.txt
@@ -15,10 +15,15 @@
 
 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR 
${LLVM_RUNTIME_OUTPUT_INTDIR})
 
+if (TARGET LLVMHello)
+  set (LLVM_HAS_LLVM_HELLO 1)
+endif()
+
 llvm_canonicalize_cmake_booleans(
   CLANG_TIDY_ENABLE_STATIC_ANALYZER
   CLANG_PLUGIN_SUPPORT
   LLVM_INSTALL_TOOLCHAIN_ONLY
+  LLVM_HAS_LLVM_HELLO
   )
 
 configure_lit_site_cfg(
@@ -97,7 +102,10 @@
   endif()
 
   if(TARGET CTTestTidyModule)
-  list(APPEND CLANG_TOOLS_TEST_DEPS CTTestTidyModule LLVMHello)
+  list(APPEND CLANG_TOOLS_TEST_DEPS CTTestTidyModule)
+  if (TARGET  LLVMHello)
+list(APPEND CLANG_TOOLS_TEST_DEPS CTTestTidyModule)
+  endif()
   target_include_directories(CTTestTidyModule PUBLIC BEFORE 
"${CLANG_TOOLS_SOURCE_DIR}")
   if(CLANG_PLUGIN_SUPPORT AND (WIN32 OR CYGWIN))
 set(LLVM_LINK_COMPONENTS


Index: clang-tools-extra/test/lit.site.cfg.py.in
===
--- clang-tools-extra/test/lit.site.cfg.py.in
+++ clang-tools-extra/test/lit.site.cfg.py.in
@@ -13,6 +13,7 @@
 config.target_triple = "@TARGET_TRIPLE@"
 config.clang_tidy_staticanalyzer = @CLANG_TIDY_ENABLE_STATIC_ANALYZER@
 config.has_plugins = @CLANG_PLUGIN_SUPPORT@ & ~@LLVM_INSTALL_TOOLCHAIN_ONLY@
+config.has_llvm_hello = @LLVM_HAS_LLVM_HELLO@
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
Index: clang-tools-extra/test/lit.cfg.py
===
--- clang-tools-extra/test/lit.cfg.py
+++ clang-tools-extra/test/lit.cfg.py
@@ -155,3 +155,6 @@
 # Plugins (loadable modules)
 if config.has_plugins and config.llvm_plugin_ext:
 config.available_features.add('plugins')
+
+if config.has_llvm_hello:
+config.available_features.add("llvm-hello")
Index: clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
===
--- clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
+++ clang-tools-extra/test/clang-tidy/CTTestTidyModule.cpp
@@ -1,4 +1,4 @@
-// REQUIRES: plugins
+// REQUIRES: plugins, llvm-hello
 // RUN: clang-tidy -checks='-*,mytest*' --list-checks -load %llvmshlibdir/CTTestTidyModule%pluginext -load %llvmshlibdir/LLVMHello%pluginext | FileCheck --check-prefix=CHECK-LIST %s
 // CHECK-LIST: Enabled checks:
 // CHECK-LIST-NEXT:mytest1
Index: clang-tools-extra/test/CMakeLists.txt
===
--- 

[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D118586#3336612 , @ChuanqiXu wrote:

> (May off the patch)

I am not sure what you mean here.

> BTW, I know you also work on GCC frontend. I want to consultant what's your 
> opinion to uniform the command line options between Clang and GCC. Now it 
> looks totally different. I feel it would be a problem for clang. Since the 
> command line between clang and gcc are basically compatible so that user who 
> decide to use clang could turn back to use gcc whenever he want. But I am 
> worrying that it would be a harder decision for users if them are going to 
> use clang. Since the cost to use GCC again would be higher.

We have the same objective: to keep user-facing options and functionality the 
same between clang and GCC (easier for both user and for build systems).
The content of this patch does not alter that. BTW GCC also keeps the module 
name as "Primary:Parition" internally and user-facing output.  //The module 
name in C++20 modules has no fixed mapping to the BMI/CMI filename on disk,.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D120290: [WIP][Clang][OpenMP] Add the codegen support for `atomic compare capture`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 410448.
tianshilei1992 added a comment.

add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120290

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/OpenMP/atomic_compare_codegen.cpp

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


[clang] 8d9eeb0 - [Driver][OpenBSD] Add comments for C++ tests

2022-02-21 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2022-02-22T00:20:46-05:00
New Revision: 8d9eeb03b3e9c800843659f243242f262d7bd786

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

LOG: [Driver][OpenBSD] Add comments for C++ tests

Added: 


Modified: 
clang/test/Driver/openbsd.cpp

Removed: 




diff  --git a/clang/test/Driver/openbsd.cpp b/clang/test/Driver/openbsd.cpp
index 23c365d28e7e..417783b8d5a2 100644
--- a/clang/test/Driver/openbsd.cpp
+++ b/clang/test/Driver/openbsd.cpp
@@ -1,3 +1,4 @@
+// Check libraries used when linking C++
 // RUN: %clangxx %s -### -o %t.o -target amd64-pc-openbsd 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-CXX %s
 // RUN: %clangxx %s -### -o %t.o -target i686-pc-openbsd 2>&1 \
@@ -8,6 +9,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-CXX %s
 // CHECK-CXX: "-lc++" "-lc++abi" "-lpthread" "-lm"
 
+// Check for profiling variants of libraries when linking C++
 // RUN: %clangxx %s -### -pg -o %t.o -target amd64-pc-openbsd 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PG-CXX %s
 // RUN: %clangxx %s -### -pg -o %t.o -target i686-pc-openbsd 2>&1 \



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


[PATCH] D112774: [RISCV] Support k-ext clang intrinsics

2022-02-21 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 410444.
achieveartificialintelligence added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112774

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksh.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c

Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -31,6 +31,17 @@
 // CHECK-NOT: __riscv_zfh
 // CHECK-NOT: __riscv_v
 // CHECK-NOT: __riscv_vector
+// CHECK-NOT: __riscv_zbkc
+// CHECK-NOT: __riscv_zbkx
+// CHECK-NOT: __riscv_zbkb
+// CHECK-NOT: __riscv_zkne
+// CHECK-NOT: __riscv_zknd
+// CHECK-NOT: __riscv_zknh
+// CHECK-NOT: __riscv_zksh
+// CHECK-NOT: __riscv_zksed
+// CHECK-NOT: __riscv_zkr
+// CHECK-NOT: __riscv_zkt
+// CHECK-NOT: __riscv_zk
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
@@ -343,3 +354,58 @@
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkc1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKC-EXT %s
+// CHECK-ZBKC-EXT: __riscv_zbkc
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkx1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKX-EXT %s
+// CHECK-ZBKX-EXT: __riscv_zbkx
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkb1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKB-EXT %s
+// CHECK-ZBKB-EXT: __riscv_zbkb
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknd1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKND-EXT %s
+// CHECK-ZKND-EXT: __riscv_zknd
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkne1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNE-EXT %s
+// CHECK-ZKNE-EXT: __riscv_zkne
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNH-EXT %s
+// CHECK-ZKNH-EXT: __riscv_zknh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSH-EXT %s
+// CHECK-ZKSH-EXT: __riscv_zksh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksed1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSED-EXT %s
+// CHECK-ZKSED-EXT: __riscv_zksed
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkr1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKR-EXT %s
+// CHECK-ZKR-EXT: __riscv_zkr
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkt1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKT-EXT %s
+// CHECK-ZKT-EXT: __riscv_zkt
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izk1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZK-EXT %s
+// CHECK-ZK-EXT: __riscv_zk
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -414,3 +414,47 @@
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv1p0_zvl32b1p0 -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-ZVL-GOODVERS %s
 // RV32-ZVL-GOODVERS: "-target-feature" "+zvl32b"
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbkc1p0 -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBKC %s
+// RV32-ZBKC: 

[clang] 289b725 - [Driver][OpenBSD] Test tweaking and clean up

2022-02-21 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2022-02-21T23:44:53-05:00
New Revision: 289b725051cfb4a7167936db89583aa6b8a12d18

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

LOG: [Driver][OpenBSD] Test tweaking and clean up

Added: 


Modified: 
clang/test/Driver/openbsd.c

Removed: 




diff  --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index da35d0441eb8..04a46f2862e7 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -1,14 +1,10 @@
-// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -### 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-LD %s
-// CHECK-LD: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
-// CHECK-LD: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
-
 // Check for --eh-frame-hdr being passed with static linking
 // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -static %s -### 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-STATIC-EH %s
 // CHECK-LD-STATIC-EH: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-STATIC-EH: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bstatic" 
"-o" "a.out" "{{.*}}rcrt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lcompiler_rt" 
"-lc" "-lcompiler_rt" "{{.*}}crtend.o"
 
+// Check for profiling variants of libraries when linking and -nopie
 // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -pg -pthread %s 
-### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PG %s
 // CHECK-PG: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
@@ -56,7 +52,7 @@
 
 // Check that --sysroot is passed to the linker
 // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -### 2>&1 \
-// RUN:   --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN:   --sysroot=%S/Inputs/basic_openbsd_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SYSROOT %s
 // CHECK-LD-SYSROOT: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
 
@@ -86,11 +82,6 @@
 // CHECK-MIPS64EL: as{{.*}}" "-mabi" "64" "-EL"
 // CHECK-MIPS64EL-PIC: as{{.*}}" "-mabi" "64" "-EL" "-KPIC"
 
-// Check that the integrated assembler is enabled for SPARC
-// RUN: %clang -target sparc64-unknown-openbsd -### -c %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-IAS %s
-// CHECK-IAS-NOT: "-no-integrated-as"
-
 // Check linking against correct startup code when (not) using PIE
 // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -### 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-PIE %s



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


[PATCH] D120217: [clang-format] Add an option to insert braces after control statements

2022-02-21 Thread Owen Pan 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 rG77e60bc42c48: [clang-format] Add option to insert braces 
after control statements (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120217

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19474,6 +19474,7 @@
   CHECK_PARSE_BOOL_FIELD(IndentRequiresClause, "IndentRequires");
   CHECK_PARSE_BOOL(IndentRequiresClause);
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
+  CHECK_PARSE_BOOL(InsertBraces);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
@@ -24300,6 +24301,202 @@
   verifyFormat("template  struct Foo {};", Style);
 }
 
+TEST_F(FormatTest, InsertBraces) {
+  FormatStyle Style = getLLVMStyle();
+  Style.InsertBraces = true;
+
+  verifyFormat("// clang-format off\n"
+   "// comment\n"
+   "if (a) f();\n"
+   "// clang-format on\n"
+   "if (b) {\n"
+   "  g();\n"
+   "}",
+   "// clang-format off\n"
+   "// comment\n"
+   "if (a) f();\n"
+   "// clang-format on\n"
+   "if (b) g();",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  switch (b) {\n"
+   "  case 1:\n"
+   "c = 0;\n"
+   "break;\n"
+   "  default:\n"
+   "c = 1;\n"
+   "  }\n"
+   "}",
+   "if (a)\n"
+   "  switch (b) {\n"
+   "  case 1:\n"
+   "c = 0;\n"
+   "break;\n"
+   "  default:\n"
+   "c = 1;\n"
+   "  }",
+   Style);
+
+  verifyFormat("for (auto node : nodes) {\n"
+   "  if (node) {\n"
+   "break;\n"
+   "  }\n"
+   "}",
+   "for (auto node : nodes)\n"
+   "  if (node)\n"
+   "break;",
+   Style);
+
+  verifyFormat("for (auto node : nodes) {\n"
+   "  if (node)\n"
+   "}",
+   "for (auto node : nodes)\n"
+   "  if (node)",
+   Style);
+
+  verifyFormat("do {\n"
+   "  --a;\n"
+   "} while (a);",
+   "do\n"
+   "  --a;\n"
+   "while (a);",
+   Style);
+
+  verifyFormat("if (i) {\n"
+   "  ++i;\n"
+   "} else {\n"
+   "  --i;\n"
+   "}",
+   "if (i)\n"
+   "  ++i;\n"
+   "else {\n"
+   "  --i;\n"
+   "}",
+   Style);
+
+  verifyFormat("void f() {\n"
+   "  while (j--) {\n"
+   "while (i) {\n"
+   "  --i;\n"
+   "}\n"
+   "  }\n"
+   "}",
+   "void f() {\n"
+   "  while (j--)\n"
+   "while (i)\n"
+   "  --i;\n"
+   "}",
+   Style);
+
+  verifyFormat("f({\n"
+   "  if (a) {\n"
+   "g();\n"
+   "  }\n"
+   "});",
+   "f({\n"
+   "  if (a)\n"
+   "g();\n"
+   "});",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  f();\n"
+   "} else if (b) {\n"
+   "  g();\n"
+   "} else {\n"
+   "  h();\n"
+   "}",
+   "if (a)\n"
+   "  f();\n"
+   "else if (b)\n"
+   "  g();\n"
+   "else\n"
+   "  h();",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  f();\n"
+   "}\n"
+   "// comment\n"
+   "/* comment */",
+   "if (a)\n"
+   "  f();\n"
+   "// comment\n"
+   "/* comment */",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  // foo\n"
+   "  // bar\n"
+   "  f();\n"
+   "}",
+   "if (a)\n"
+   "  // foo\n"
+   "  // bar\n"
+   "  f();",
+   Style);
+
+  verifyFormat("if (a) { // comment\n"
+   

[clang] 77e60bc - [clang-format] Add option to insert braces after control statements

2022-02-21 Thread via cfe-commits

Author: owenca
Date: 2022-02-21T20:16:25-08:00
New Revision: 77e60bc42c48e16d646488d43210b1630cd4db49

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

LOG: [clang-format] Add option to insert braces after control statements

Adds a new option InsertBraces to insert the optional braces after
if, else, for, while, and do in C++.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0cddf022ead3..2cb67fa5492e 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2756,6 +2756,39 @@ the configuration (without a prefix: ``Auto``).
  LngReturnType
  LngFunctionDeclaration();
 
+**InsertBraces** (``Boolean``) :versionbadge:`clang-format 15`
+  Insert braces after control statements (``if``, ``else``, ``for``, ``do``,
+  and ``while``) in C++ unless the control statements are inside macro
+  definitions or the braces would enclose preprocessor directives.
+
+  .. warning:: 
+
+   Setting this option to `true` could lead to incorrect code formatting due
+   to clang-format's lack of complete semantic information. As such, extra
+   care should be taken to review code changes made by this option.
+
+  .. code-block:: c++
+
+false:true:
+
+if (isa(D))vs.  if (isa(D)) {
+  handleFunctionDecl(D);handleFunctionDecl(D);
+else if (isa(D)) } else if (isa(D)) {
+  handleVarDecl(D); handleVarDecl(D);
+else  } else {
+  return;   return;
+  }
+
+while (i--)  vs.  while (i--) {
+  for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
+handleAttr(A);handleAttr(A);
+}
+  }
+
+do   vs.  do {
+  --i;  --i;
+while (i);} while (i);
+
 **InsertTrailingCommas** (``TrailingCommaStyle``) :versionbadge:`clang-format 
12`
   If set to ``TCS_Wrapped`` will insert trailing commas in container
   literals (arrays and objects) that wrap across multiple lines.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 43a2cf98e7c8..499b065fe6e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -188,6 +188,9 @@ clang-format
 
 - Changed ``BreakBeforeConceptDeclarations`` from ``Boolean`` to an enum.
 
+- Option ``InsertBraces`` has been added to insert optional braces after 
control
+  statements.
+
 libclang
 
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index d4a479e7c512..484438306b35 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2571,6 +2571,38 @@ struct FormatStyle {
   /// \version 3.7
   bool IndentWrappedFunctionNames;
 
+  /// Insert braces after control statements (``if``, ``else``, ``for``, 
``do``,
+  /// and ``while``) in C++ unless the control statements are inside macro
+  /// definitions or the braces would enclose preprocessor directives.
+  /// \warning
+  ///  Setting this option to `true` could lead to incorrect code formatting 
due
+  ///  to clang-format's lack of complete semantic information. As such, extra
+  ///  care should be taken to review code changes made by this option.
+  /// \endwarning
+  /// \code
+  ///   false:true:
+  ///
+  ///   if (isa(D))vs.  if (isa(D)) {
+  /// handleFunctionDecl(D);handleFunctionDecl(D);
+  ///   else if (isa(D)) } else if (isa(D)) {
+  /// handleVarDecl(D); handleVarDecl(D);
+  ///   else  } else {
+  /// return;   return;
+  /// }
+  ///
+  ///   while (i--)  vs.  while (i--) {
+  /// for (auto *A : D.attrs()) for (auto *A : D.attrs()) {
+  

[clang] 95fed2b - [Driver][OpenBSD] Pass sysroot to the linker

2022-02-21 Thread Brad Smith via cfe-commits

Author: Brad Smith
Date: 2022-02-21T23:11:13-05:00
New Revision: 95fed2b267ee87e6cba72ebe73f0d6fdab37f995

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

LOG: [Driver][OpenBSD] Pass sysroot to the linker

Added: 


Modified: 
clang/lib/Driver/ToolChains/OpenBSD.cpp
clang/test/Driver/openbsd.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp 
b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index bcd54bedfa89..7f19587f5f82 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -123,6 +123,9 @@ void openbsd::Linker::ConstructJob(Compilation , const 
JobAction ,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
+  if (!D.SysRoot.empty())
+CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
   if (ToolChain.getArch() == llvm::Triple::mips64)
 CmdArgs.push_back("-EB");
   else if (ToolChain.getArch() == llvm::Triple::mips64el)

diff  --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index d6d5ae994e67..da35d0441eb8 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -54,6 +54,12 @@
 // CHECK-MIPS64EL-LD: clang{{.*}}" "-cc1" "-triple" "mips64el-unknown-openbsd"
 // CHECK-MIPS64EL-LD: ld{{.*}}" "-EL" "-e" "__start" "--eh-frame-hdr" 
"-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" 
"{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
 
+// Check that --sysroot is passed to the linker
+// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -### 2>&1 \
+// RUN:   --sysroot=%S/Inputs/basic_netbsd_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-SYSROOT %s
+// CHECK-LD-SYSROOT: ld{{.*}}" "--sysroot=[[SYSROOT:[^"]+]]"
+
 // Check passing options to the assembler for various OpenBSD targets
 // RUN: %clang -target amd64-pc-openbsd -m32 -### -no-integrated-as -c %s 2>&1 
\
 // RUN:   | FileCheck -check-prefix=CHECK-AMD64-M32 %s



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


[PATCH] D120298: [HIP] Support `--default-stream`

2022-02-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: dexonsmith, dang.
yaxunl requested review of this revision.

Introduce `--default-stream={legacy|per-thread}` option to
support per-thread default stream for HIP runtime.

When `--default-stream=per-thread`, HIP kernels are
launched through hipLaunchKernel_spt instead of
hipLaunchKernel. Also `-DHIP_API_PER_THREAD_DEFAULT_STREAM`
is passed to clang -cc1 to enable other per-thread stream
API's.


https://reviews.llvm.org/D120298

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCUDA/Inputs/cuda.h
  clang/test/CodeGenCUDA/kernel-call.cu
  clang/test/Driver/hip-options.hip

Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -14,6 +14,12 @@
 // DEVINIT: clang{{.*}}" "-cc1" {{.*}}"-fgpu-allow-device-init"
 // DEVINIT: clang{{.*}}" "-cc1" {{.*}}"-fgpu-allow-device-init"
 
+// Check --default-stream=per-thread.
+// RUN: %clang -### -nogpuinc -nogpulib --default-stream=per-thread \
+// RUN:   %s 2>&1 | FileCheck -check-prefix=PTH %s
+// PTH: clang{{.*}}" "-cc1" {{.*}}"--default-stream=per-thread"{{.*}}"-DHIP_API_PER_THREAD_DEFAULT_STREAM"
+// PTH: clang{{.*}}" "-cc1" {{.*}}"--default-stream=per-thread"{{.*}}"-DHIP_API_PER_THREAD_DEFAULT_STREAM"
+
 // RUN: %clang -### -x hip -target x86_64-pc-windows-msvc -fms-extensions \
 // RUN:   -mllvm -amdgpu-early-inline-all=true  %s 2>&1 | \
 // RUN:   FileCheck -check-prefix=MLLVM %s
Index: clang/test/CodeGenCUDA/kernel-call.cu
===
--- clang/test/CodeGenCUDA/kernel-call.cu
+++ clang/test/CodeGenCUDA/kernel-call.cu
@@ -5,7 +5,13 @@
 // RUN: %clang_cc1 -x hip -emit-llvm %s -o - \
 // RUN: | FileCheck %s --check-prefixes=HIP-OLD,CHECK
 // RUN: %clang_cc1 -fhip-new-launch-api -x hip -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes=HIP-NEW,CHECK
+// RUN: | FileCheck %s --check-prefixes=HIP-NEW,LEGACY,CHECK
+// RUN: %clang_cc1 -fhip-new-launch-api -x hip -emit-llvm %s -o - \
+// RUN:   --default-stream=legacy \
+// RUN:   | FileCheck %s --check-prefixes=HIP-NEW,LEGACY,CHECK
+// RUN: %clang_cc1 -fhip-new-launch-api -x hip -emit-llvm %s -o - \
+// RUN:   --default-stream=per-thread -DHIP_API_PER_THREAD_DEFAULT_STREAM \
+// RUN:   | FileCheck %s --check-prefixes=HIP-NEW,PTH,CHECK
 
 #include "Inputs/cuda.h"
 
@@ -13,7 +19,8 @@
 // HIP-OLD: call{{.*}}hipSetupArgument
 // HIP-OLD: call{{.*}}hipLaunchByPtr
 // HIP-NEW: call{{.*}}__hipPopCallConfiguration
-// HIP-NEW: call{{.*}}hipLaunchKernel
+// LEGACY: call{{.*}}hipLaunchKernel
+// PTH: call{{.*}}hipLaunchKernel_spt
 // CUDA-OLD: call{{.*}}cudaSetupArgument
 // CUDA-OLD: call{{.*}}cudaLaunch
 // CUDA-NEW: call{{.*}}__cudaPopCallConfiguration
Index: clang/test/CodeGenCUDA/Inputs/cuda.h
===
--- clang/test/CodeGenCUDA/Inputs/cuda.h
+++ clang/test/CodeGenCUDA/Inputs/cuda.h
@@ -35,11 +35,18 @@
 extern "C" hipError_t __hipPushCallConfiguration(dim3 gridSize, dim3 blockSize,
  size_t sharedSize = 0,
  hipStream_t stream = 0);
+#ifndef HIP_API_PER_THREAD_DEFAULT_STREAM
 extern "C" hipError_t hipLaunchKernel(const void *func, dim3 gridDim,
   dim3 blockDim, void **args,
   size_t sharedMem,
   hipStream_t stream);
 #else
+extern "C" hipError_t hipLaunchKernel_spt(const void *func, dim3 gridDim,
+  dim3 blockDim, void **args,
+  size_t sharedMem,
+  hipStream_t stream);
+#endif //HIP_API_PER_THREAD_DEFAULT_STREAM
+#else
 typedef struct cudaStream *cudaStream_t;
 typedef enum cudaError {} cudaError_t;
 extern "C" int cudaConfigureCall(dim3 gridSize, dim3 blockSize,
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6896,8 +6896,16 @@
   CmdArgs.push_back(Args.MakeArgString(Twine("-cuid=") + Twine(CUID)));
   }
 
-  if (IsHIP)
+  if (IsHIP) {
 CmdArgs.push_back("-fcuda-allow-variadic-functions");
+auto DefStream = Args.getLastArgValue(options::OPT_default_stream_EQ);
+if (!DefStream.empty()) {
+  Args.AddLastArg(CmdArgs, options::OPT_default_stream_EQ);
+  if (DefStream == "per-thread")
+CmdArgs.push_back(
+Args.MakeArgString("-DHIP_API_PER_THREAD_DEFAULT_STREAM"));
+}
+  }
 
   if (IsCudaDevice || IsHIPDevice) {
 StringRef InlineThresh =
Index: 

[PATCH] D119541: [RISCV] Fix RISCVTargetInfo::initFeatureMap, add non-ISA features back after implication

2022-02-21 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD marked an inline comment as done.
eopXD added inline comments.



Comment at: clang/test/Driver/riscv-default-features.c:4
+// RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
+// RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
+

rogfer01 wrote:
> I think we may be missing are missing a `RUN` line for this case, right?
Created patch D120297, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119541

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


[PATCH] D120297: [Driver][RISCV] Add missing rv64 test case

2022-02-21 Thread Yueh-Ting Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added a reviewer: rogfer01.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, 
vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, 
Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, 
edward-jones, zzheng, jrtc27, kito-cheng, niosHD, sabuasal, simoncook, 
johnrusso, rbar, asb.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead.
Herald added a project: clang.

Add missing test case. Thanks @rogfer01 for spotting this out.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120297

Files:
  clang/test/Driver/riscv-default-features.c


Index: clang/test/Driver/riscv-default-features.c
===
--- clang/test/Driver/riscv-default-features.c
+++ clang/test/Driver/riscv-default-features.c
@@ -1,4 +1,5 @@
 // RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV32
+// RUN: %clang -target riscv64-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV64
 
 // RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"


Index: clang/test/Driver/riscv-default-features.c
===
--- clang/test/Driver/riscv-default-features.c
+++ clang/test/Driver/riscv-default-features.c
@@ -1,4 +1,5 @@
 // RUN: %clang -target riscv32-unknown-elf -S -emit-llvm %s -o - | FileCheck %s -check-prefix=RV32
+// RUN: %clang -target riscv64-unknown-elf -S -emit-llvm %s -o - | FileCheck %s -check-prefix=RV64
 
 // RV32: "target-features"="+a,+c,+m,+relax,-save-restore"
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,-save-restore"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120296: [Attr] Fix a btf_type_tag AST generation bug

2022-02-21 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song created this revision.
yonghong-song added a reviewer: aaron.ballman.
yonghong-song requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Current ASTContext.getAttributedType() takes attribute kind,
ModifiedType and EquivType as the hash to decide whether an AST node
has been generated or note. But this is not enough for btf_type_tag
as the attribute might have the same ModifiedType and EquivType, but 
still have different string associated with attribute.

For example, for a data structure like below,

  struct map_value {
int __attribute__((btf_type_tag("tag1"))) 
__attribute__((btf_type_tag("tag3"))) *a; 
int __attribute__((btf_type_tag("tag2"))) 
__attribute__((btf_type_tag("tag4"))) *b; 
  };  

The current ASTContext.getAttributedType() will produce
an AST similar to below:

  struct map_value {
int __attribute__((btf_type_tag("tag1"))) 
__attribute__((btf_type_tag("tag3"))) *a; 
int __attribute__((btf_type_tag("tag1"))) 
__attribute__((btf_type_tag("tag3"))) *b; 
  };  

and this is incorrect.

To fix the issue, an optional StringRef parameter is passed to
getAttributedType() so the btf_type_tag string can be part of
the hash. This resolved the issue since the cached btf_type_tag
attributes have empty tag string so there is never a match
between cached entries and the new btf_type_tag.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120296

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/attr-btf_type_tag-similar-type.c

Index: clang/test/CodeGen/attr-btf_type_tag-similar-type.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-btf_type_tag-similar-type.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm -o - %s | FileCheck %s
+
+struct map_value {
+int __attribute__((btf_type_tag("tag1"))) __attribute__((btf_type_tag("tag3"))) *a;
+int __attribute__((btf_type_tag("tag2"))) __attribute__((btf_type_tag("tag4"))) *b;
+};
+
+struct map_value *func(void);
+
+int test(struct map_value *arg)
+{
+return *arg->a;
+}
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "map_value", file: ![[#]], line: [[#]], size: [[#]], elements: ![[L14:[0-9]+]]
+// CHECK: ![[L14]] = !{![[L15:[0-9]+]], ![[L20:[0-9]+]]}
+// CHECK: ![[L15]] = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[L16:[0-9]+]]
+// CHECK: ![[L16]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[#]], size: [[#]], annotations: ![[L17:[0-9]+]]
+// CHECK: ![[L17]] = !{![[L18:[0-9]+]], ![[L19:[0-9]+]]}
+// CHECK: ![[L18]] = !{!"btf_type_tag", !"tag1"}
+// CHECK: ![[L19]] = !{!"btf_type_tag", !"tag3"}
+// CHECK: ![[L20]] = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[L21:[0-9]+]]
+// CHECK: ![[L21:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[#]], size: [[#]], annotations: ![[L22:[0-9]+]]
+// CHECK: ![[L22]] = !{![[L23:[0-9]+]], ![[L24:[0-9]+]]}
+// CHECK: ![[L23]] = !{!"btf_type_tag", !"tag2"}
+// CHECK: ![[L24]] = !{!"btf_type_tag", !"tag4"}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -258,9 +258,11 @@
 /// Get an attributed type for the given attribute, and remember the Attr
 /// object so that we can attach it to the AttributedTypeLoc.
 QualType getAttributedType(Attr *A, QualType ModifiedType,
-   QualType EquivType) {
+   QualType EquivType,
+   StringRef ExtraInfo = StringRef()) {
   QualType T =
-  sema.Context.getAttributedType(A->getKind(), ModifiedType, EquivType);
+  sema.Context.getAttributedType(A->getKind(), ModifiedType, EquivType,
+ ExtraInfo);
   AttrsForTypes.push_back({cast(T.getTypePtr()), A});
   AttrsForTypesSorted = false;
   return T;
@@ -6553,8 +6555,9 @@
 
   ASTContext  = S.Context;
   StringRef BTFTypeTag = StrLiteral->getString();
-  Type = State.getAttributedType(
-  ::new (Ctx) BTFTypeTagAttr(Ctx, Attr, BTFTypeTag), Type, Type);
+  Type =
+  State.getAttributedType(::new (Ctx) BTFTypeTagAttr(Ctx, Attr, BTFTypeTag),
+  Type, Type, BTFTypeTag);
 }
 
 /// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4665,9 +4665,11 @@
 
 QualType ASTContext::getAttributedType(attr::Kind attrKind,
 

[PATCH] D117924: [compiler_rt] Add a seperate runtime for Mac Catalyst

2022-02-21 Thread Byoungchan Lee via Phabricator via cfe-commits
bc-lee abandoned this revision.
bc-lee added a comment.

Closed in favor of https://reviews.llvm.org/D118862 and 
https://reviews.llvm.org/D118875


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117924

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


[PATCH] D120289: [clang][dataflow] Add SAT solver interface and implementation

2022-02-21 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Analysis/FlowSensitive/Solver.h:39
+  ///  All elements in `Vals` must be non-null.
+  virtual Result solve(llvm::DenseSet Vals) = 0;
+};

Which `Result` is expected if the `Solver` gives up, assuming that's allowed in 
this API.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:193
+  // The general strategy of the algorithm implemented below is to map each
+  // sub-values in `Vals` to a unique variable and use these variables in
+  // the resulting CNF expression to avoid exponential blow up. The number of





Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:373
+
+  Solver::Result solve() && {
+size_t I = 0;

Why this constraint?



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:456
+  } else {
+I++;
+  }

nit: `++I`, for consistency?



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:529
+  // Assert the invariant that the watched literal is always the first one
+  // in the clause holds.
+  // FIXME: Consider replacing this with a test case that fails if the





Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:594
+  /// Returns true if and only if all unassigned variables that are forming
+  /// warched literals are active.
+  bool unassignedVarsFormingWatchedLiteralsAreActive() const {




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120289

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


[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

ABataev wrote:
> tianshilei1992 wrote:
> > tianshilei1992 wrote:
> > > ABataev wrote:
> > > > tianshilei1992 wrote:
> > > > > ABataev wrote:
> > > > > > tianshilei1992 wrote:
> > > > > > > tianshilei1992 wrote:
> > > > > > > > tianshilei1992 wrote:
> > > > > > > > > I think the `store` here is redundant. Is it because I'm 
> > > > > > > > > using `CGF.EmitScalarExpr`?
> > > > > > > > Oh, shoot. `load` here, instead of `store`.
> > > > > > > And here. @ABataev 
> > > > > > Yes, because of EmitScalarExpr
> > > > > Can we somehow avoid the `load` here?
> > > > Do you need EmitScalarExpr?
> > > So it is a rvalue scalar here. What alternative do we have then?
> > I have to get it passed to IRBuilder, which accepts a `llvm::Value *`.
> Modify irbuilder to not require it in some cases.
You got me wrong. I need to call a function to convert a rvalue `Express *` to 
`llvm::Value *`. `CGF.EmitScalarExpr` can do it. Actually now I feel the `load` 
here can not be avoided as we want a scalar value instead of a pointer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

(May off the patch)

BTW, I know you also work on GCC frontend. I want to consultant what's your 
opinion to uniform the command line options between Clang and GCC. Now it looks 
totally different. I feel it would be a problem for clang. Since the command 
line between clang and gcc are basically compatible so that user who decide to 
use clang could turn back to use gcc whenever he want. But I am worrying that 
it would be a harder decision for users if them are going to use clang. Since 
the cost to use GCC again would be higher.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

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


[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

tianshilei1992 wrote:
> tianshilei1992 wrote:
> > ABataev wrote:
> > > tianshilei1992 wrote:
> > > > ABataev wrote:
> > > > > tianshilei1992 wrote:
> > > > > > tianshilei1992 wrote:
> > > > > > > tianshilei1992 wrote:
> > > > > > > > I think the `store` here is redundant. Is it because I'm using 
> > > > > > > > `CGF.EmitScalarExpr`?
> > > > > > > Oh, shoot. `load` here, instead of `store`.
> > > > > > And here. @ABataev 
> > > > > Yes, because of EmitScalarExpr
> > > > Can we somehow avoid the `load` here?
> > > Do you need EmitScalarExpr?
> > So it is a rvalue scalar here. What alternative do we have then?
> I have to get it passed to IRBuilder, which accepts a `llvm::Value *`.
Modify irbuilder to not require it in some cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked 3 inline comments as done.
tianshilei1992 added inline comments.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

tianshilei1992 wrote:
> ABataev wrote:
> > tianshilei1992 wrote:
> > > ABataev wrote:
> > > > tianshilei1992 wrote:
> > > > > tianshilei1992 wrote:
> > > > > > tianshilei1992 wrote:
> > > > > > > I think the `store` here is redundant. Is it because I'm using 
> > > > > > > `CGF.EmitScalarExpr`?
> > > > > > Oh, shoot. `load` here, instead of `store`.
> > > > > And here. @ABataev 
> > > > Yes, because of EmitScalarExpr
> > > Can we somehow avoid the `load` here?
> > Do you need EmitScalarExpr?
> So it is a rvalue scalar here. What alternative do we have then?
I have to get it passed to IRBuilder, which accepts a `llvm::Value *`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D118757: [AArch64] Remove unused feature flags from AArch64TargetInfo

2022-02-21 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 updated this revision to Diff 410418.
tyb0807 added a comment.

Revert latest change, as it is likely that people still rely on 
`ARM_FEATURE_CRYPTO`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118757

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h


Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -30,7 +30,6 @@
 
   unsigned FPU;
   bool HasCRC;
-  bool HasCrypto;
   bool HasAES;
   bool HasSHA2;
   bool HasSHA3;
@@ -54,7 +53,6 @@
   bool HasMatmulFP32;
   bool HasLSE;
   bool HasFlagM;
-  bool HasHBC;
   bool HasMOPS;
 
   llvm::AArch64::ArchKind ArchKind;
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -525,7 +525,6 @@
  DiagnosticsEngine ) {
   FPU = FPUMode;
   HasCRC = false;
-  HasCrypto = false;
   HasAES = false;
   HasSHA2 = false;
   HasSHA3 = false;
@@ -548,7 +547,6 @@
   HasMatmulFP64 = false;
   HasMatmulFP32 = false;
   HasLSE = false;
-  HasHBC = false;
   HasMOPS = false;
 
   ArchKind = llvm::AArch64::ArchKind::INVALID;
@@ -599,8 +597,6 @@
 }
 if (Feature == "+crc")
   HasCRC = true;
-if (Feature == "+crypto")
-  HasCrypto = true;
 if (Feature == "+aes")
   HasAES = true;
 if (Feature == "+sha2")
@@ -665,8 +661,6 @@
   HasRandGen = true;
 if (Feature == "+flagm")
   HasFlagM = true;
-if (Feature == "+hbc")
-  HasHBC = true;
 if (Feature == "+mops")
   HasMOPS = true;
   }


Index: clang/lib/Basic/Targets/AArch64.h
===
--- clang/lib/Basic/Targets/AArch64.h
+++ clang/lib/Basic/Targets/AArch64.h
@@ -30,7 +30,6 @@
 
   unsigned FPU;
   bool HasCRC;
-  bool HasCrypto;
   bool HasAES;
   bool HasSHA2;
   bool HasSHA3;
@@ -54,7 +53,6 @@
   bool HasMatmulFP32;
   bool HasLSE;
   bool HasFlagM;
-  bool HasHBC;
   bool HasMOPS;
 
   llvm::AArch64::ArchKind ArchKind;
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -525,7 +525,6 @@
  DiagnosticsEngine ) {
   FPU = FPUMode;
   HasCRC = false;
-  HasCrypto = false;
   HasAES = false;
   HasSHA2 = false;
   HasSHA3 = false;
@@ -548,7 +547,6 @@
   HasMatmulFP64 = false;
   HasMatmulFP32 = false;
   HasLSE = false;
-  HasHBC = false;
   HasMOPS = false;
 
   ArchKind = llvm::AArch64::ArchKind::INVALID;
@@ -599,8 +597,6 @@
 }
 if (Feature == "+crc")
   HasCRC = true;
-if (Feature == "+crypto")
-  HasCrypto = true;
 if (Feature == "+aes")
   HasAES = true;
 if (Feature == "+sha2")
@@ -665,8 +661,6 @@
   HasRandGen = true;
 if (Feature == "+flagm")
   HasFlagM = true;
-if (Feature == "+hbc")
-  HasHBC = true;
 if (Feature == "+mops")
   HasMOPS = true;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118875: [compiler-rt][builtins] build the macOS compiler-rt built-ins with Mac Catalyst support

2022-02-21 Thread Ravi via Phabricator via cfe-commits
ravikandhadai accepted this revision.
ravikandhadai added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks Alex.


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

https://reviews.llvm.org/D118875

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


[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6041
+  llvm::Value *EVal = CGF.EmitScalarExpr(E->IgnoreImpCasts());
+  llvm::Value *DVal = D ? CGF.EmitScalarExpr(D->IgnoreImpCasts()) : nullptr;
+

tianshilei1992 wrote:
> ABataev wrote:
> > tianshilei1992 wrote:
> > > tianshilei1992 wrote:
> > > > Using `D->IgnoreImpCasts()` can make sure to avoid the case that `char` 
> > > > is casted to `int` in binary operation. However, say, if user writes 
> > > > the following code:
> > > > ```
> > > > int x;
> > > > #pragma omp atomic compare
> > > >   x = x > 1.01 ? 1.01 : x;
> > > > ```
> > > > `1.01` here will be casted to `1` by clang, and a warning will be 
> > > > emitted. Because we ignore the implicit cast, in Sema, it is taken as 
> > > > floating point value. However, we already told user that it is casted 
> > > > to `1`, which is a little weird to emit an error then.
> > > @ABataev Here.
> > Sorry, did not understand it was a question. Could you provide a bit more 
> > background, did not quite understand problem?
> I have a better explain in another inline comment in Sema.
If you don't need it, do not call it. Why do you need this rvalue?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:11231
 C = Cond;
-D = CO->getTrueExpr();
+D = CO->getTrueExpr()->IgnoreImpCasts();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {

tianshilei1992 wrote:
> Here we do `D->IgnoreImpCasts()`, as shown in the code. The reason is, if we 
> have two `char`s, say `char a, b`, and when `a > b`, clang also inserts an 
> implicit cast from `char` to `int` for `a` and `b`. We want the actual type 
> here otherwise in the IR builder, the type of `D` doesn't match `X`'s, 
> causing issues.
> However, that `IgnoreImpCasts` here can cause another issue. Let's say we 
> have the following code:
> ```
> int x;
> #pragma omp atomic compare
>   x = x > 1.01 ? 1.01 : x;
> ```
> clang will also insert an implicit cast from floating point value to integer 
> for the scalar value `1.01` (corresponding to `D` in the code), and also 
> emits a warning saying the floating point value has been cast to integer or 
> something like that. Because we have the `IgnoreImpCasts` now, it will fail 
> the type check because `D` now is of floating point type, and we will emit an 
> error to user.
> For users, it might be confusing because on one hand we emit a warning saying 
> the floating point value has been casted, and on the other hand in Sema we 
> tell users it is expected an integer. Users might be thinking, you already 
> cast it to integer, why do you tell me it's a floating point value again?
Yiu have the resulting type from the whole expression. You van do explicit cast 
to this resulting type to avoid problems, if I got it correctly 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120290: [WIP][Clang][OpenMP] Add the codegen support for `atomic compare capture`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, ABataev.
Herald added subscribers: guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch adds the codegen support for `atomic compare capture` in clang.

Depends on D120007  and D118632 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120290

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp

Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -11845,8 +11845,10 @@
   Expr *UE = nullptr;
   Expr *D = nullptr;
   Expr *CE = nullptr;
+  Expr *R = nullptr;
   bool IsXLHSInRHSPart = false;
   bool IsPostfixUpdate = false;
+  bool IsFailOnly = false;
   // OpenMP [2.12.6, atomic Construct]
   // In the next expressions:
   // * x and v (as applicable) are both l-value expressions with scalar type.
@@ -12242,8 +12244,15 @@
 << ErrorInfo.Error << ErrorInfo.NoteRange;
 return StmtError();
   }
-  // TODO: We don't set X, D, E, etc. here because in code gen we will emit
-  // error directly.
+  X = Checker.getX();
+  E = Checker.getE();
+  D = Checker.getD();
+  CE = Checker.getCond();
+  V = Checker.getV();
+  R = Checker.getR();
+  // We reuse IsXLHSInRHSPart to tell if it is in the form 'x ordop expr'.
+  IsXLHSInRHSPart = Checker.isXBinopExpr();
+  IsFailOnly = Checker.isFailOnly();
 } else {
   OpenMPAtomicCompareChecker::ErrorInfoTy ErrorInfo;
   OpenMPAtomicCompareChecker Checker(*this);
@@ -12266,8 +12275,8 @@
   setFunctionHasBranchProtectedScope();
 
   return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt,
-X, V, E, UE, D, CE, IsXLHSInRHSPart,
-IsPostfixUpdate);
+X, V, R, E, UE, D, CE, IsXLHSInRHSPart,
+IsPostfixUpdate, IsFailOnly);
 }
 
 StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef Clauses,
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6019,8 +6019,10 @@
 
 static void emitOMPAtomicCompareExpr(CodeGenFunction ,
  llvm::AtomicOrdering AO, const Expr *X,
+ const Expr *V, const Expr *R,
  const Expr *E, const Expr *D,
  const Expr *CE, bool IsXBinopExpr,
+ bool IsPostfixUpdate, bool IsFailOnly,
  SourceLocation Loc) {
   llvm::OpenMPIRBuilder  =
   CGF.CGM.getOpenMPRuntime().getOMPBuilder();
@@ -6050,17 +6052,26 @@
   XPtr, XPtr->getType()->getPointerElementType(),
   X->getType().isVolatileQualified(),
   X->getType()->hasSignedIntegerRepresentation()};
+  llvm::OpenMPIRBuilder::AtomicOpValue VOpVal{
+  XPtr, XPtr->getType()->getPointerElementType(),
+  X->getType().isVolatileQualified(),
+  X->getType()->hasSignedIntegerRepresentation()};
+  llvm::OpenMPIRBuilder::AtomicOpValue ROpVal{
+  XPtr, XPtr->getType()->getPointerElementType(),
+  X->getType().isVolatileQualified(),
+  X->getType()->hasSignedIntegerRepresentation()};
 
   CGF.Builder.restoreIP(OMPBuilder.createAtomicCompare(
-  CGF.Builder, XOpVal, EVal, DVal, AO, Op, IsXBinopExpr));
+  CGF.Builder, XOpVal, VOpVal, ROpVal, EVal, DVal, AO, Op, IsXBinopExpr,
+  IsPostfixUpdate, IsFailOnly));
 }
 
 static void emitOMPAtomicExpr(CodeGenFunction , OpenMPClauseKind Kind,
   llvm::AtomicOrdering AO, bool IsPostfixUpdate,
-  const Expr *X, const Expr *V, const Expr *E,
-  const Expr *UE, const Expr *D, const Expr *CE,
-  bool IsXLHSInRHSPart, bool IsCompareCapture,
-  SourceLocation Loc) {
+  const Expr *X, const Expr *V, const Expr *R,
+  const Expr *E, const Expr *UE, const Expr *D,
+  const Expr *CE, bool IsXLHSInRHSPart,
+  bool IsFailOnly, SourceLocation Loc) {
   switch (Kind) {
   case OMPC_read:
 emitOMPAtomicReadExpr(CGF, AO, X, V, Loc);
@@ -6077,15 +6088,8 @@
  IsXLHSInRHSPart, Loc);
 break;
   case OMPC_compare: {
-if (IsCompareCapture) {
-  // Emit an error here.
-  unsigned DiagID = 

[PATCH] D120273: [OpenMP] Allow CUDA to be linked with OpenMP using the new driver

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 410414.
jhuber6 added a comment.

Changing after rebasing previous commits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120273

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -162,7 +162,10 @@
 };
 
 namespace llvm {
-/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+/// Helper that allows DeviceFile to be used as a key in a DenseMap. For now we
+/// assume device files with matching architectures and triples but different
+/// offloading kinds should be handlded together, this may not be true in the
+/// future.
 template <> struct DenseMapInfo {
   static DeviceFile getEmptyKey() {
 return {DenseMapInfo::getEmptyKey(),
@@ -193,10 +196,12 @@
   SmallVectorImpl );
 
 static StringRef getDeviceFileExtension(StringRef DeviceTriple,
-bool IsBitcode = false) {
+file_magic magic) {
   Triple TheTriple(DeviceTriple);
-  if (TheTriple.isAMDGPU() || IsBitcode)
+  if (magic == file_magic::bitcode)
 return "bc";
+  if (TheTriple.isNVPTX() && magic == file_magic::unknown)
+return "s";
   if (TheTriple.isNVPTX())
 return "cubin";
   return "o";
@@ -298,8 +303,8 @@
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
-  StringRef DeviceExtension = getDeviceFileExtension(
-  DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
+  StringRef DeviceExtension =
+  getDeviceFileExtension(DeviceTriple, identify_magic(*Contents));
   if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
DeviceTriple + "-" + Arch,
DeviceExtension, TempFile))
@@ -409,8 +414,8 @@
 
 StringRef Contents = CDS->getAsString();
 SmallString<128> TempFile;
-StringRef DeviceExtension = getDeviceFileExtension(
-DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
+StringRef DeviceExtension =
+getDeviceFileExtension(DeviceTriple, identify_magic(Contents));
 if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
  "-" + Arch,
  DeviceExtension, TempFile))
@@ -630,7 +635,8 @@
 
   // Add extracted input files.
   for (StringRef Input : InputFiles)
-CmdArgs.push_back(Input);
+if (Input.endswith(".cubin"))
+  CmdArgs.push_back(Input);
 
   if (sys::ExecuteAndWait(*NvlinkPath, CmdArgs))
 return createStringError(inconvertibleErrorCode(), "'nvlink' failed");
@@ -906,7 +912,22 @@
   return createFileError(File, EC);
 
 file_magic Type = identify_magic((*BufferOrErr)->getBuffer());
-if (Type != file_magic::bitcode) {
+switch (Type) {
+case file_magic::bitcode: {
+  Expected> InputFileOrErr =
+  llvm::lto::InputFile::create(**BufferOrErr);
+  if (!InputFileOrErr)
+return InputFileOrErr.takeError();
+
+  // Save the input file and the buffer associated with its memory.
+  BitcodeFiles.push_back(std::move(*InputFileOrErr));
+  SavedBuffers.push_back(std::move(*BufferOrErr));
+  continue;
+}
+case file_magic::elf_relocatable:
+case file_magic::elf_shared_object:
+case file_magic::macho_object:
+case file_magic::coff_object: {
   Expected> ObjFile =
   ObjectFile::createObjectFile(**BufferOrErr, Type);
   if (!ObjFile)
@@ -924,15 +945,10 @@
 else
   UsedInSharedLib.insert(Saver.save(*Name));
   }
-} else {
-  Expected> InputFileOrErr =
-  llvm::lto::InputFile::create(**BufferOrErr);
-  if (!InputFileOrErr)
-return InputFileOrErr.takeError();
-
-  // Save the input file and the buffer associated with its memory.
-  BitcodeFiles.push_back(std::move(*InputFileOrErr));
-  SavedBuffers.push_back(std::move(*BufferOrErr));
+  continue;
+}
+default:
+  continue;
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120271: [Clang] Add offload kind to embedded offload object

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 410413.
jhuber6 added a comment.

Updating after moving dense map implementation out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120271

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/openmp-offload-gpu.c
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -151,9 +151,11 @@
 
 /// Information for a device offloading file extracted from the host.
 struct DeviceFile {
-  DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
-  : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
+  DeviceFile(StringRef Kind, StringRef TheTriple, StringRef Arch,
+ StringRef Filename)
+  : Kind(Kind), TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
 
+  std::string Kind;
   std::string TheTriple;
   std::string Arch;
   std::string Filename;
@@ -164,11 +166,13 @@
 template <> struct DenseMapInfo {
   static DeviceFile getEmptyKey() {
 return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
 DenseMapInfo::getEmptyKey(),
 DenseMapInfo::getEmptyKey()};
   }
   static DeviceFile getTombstoneKey() {
 return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
 DenseMapInfo::getTombstoneKey(),
 DenseMapInfo::getTombstoneKey()};
   }
@@ -204,12 +208,13 @@
   return sys::path::parent_path(COWPath).str();
 }
 
-/// Extract the device file from the string '-=.bc'.
+/// Extract the device file from the string '--='.
 DeviceFile getBitcodeLibrary(StringRef LibraryStr) {
   auto DeviceAndPath = StringRef(LibraryStr).split('=');
-  auto TripleAndArch = DeviceAndPath.first.rsplit('-');
-  return DeviceFile(TripleAndArch.first, TripleAndArch.second,
-DeviceAndPath.second);
+  auto StringAndArch = DeviceAndPath.first.rsplit('-');
+  auto KindAndTriple = StringAndArch.first.split('-');
+  return DeviceFile(KindAndTriple.first, KindAndTriple.second,
+StringAndArch.second, DeviceAndPath.second);
 }
 
 /// Get a temporary filename suitable for output.
@@ -287,16 +292,17 @@
 
 SmallVector SectionFields;
 Name->split(SectionFields, '.');
-StringRef DeviceTriple = SectionFields[3];
-StringRef Arch = SectionFields[4];
+StringRef Kind = SectionFields[3];
+StringRef DeviceTriple = SectionFields[4];
+StringRef Arch = SectionFields[5];
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
   StringRef DeviceExtension = getDeviceFileExtension(
   DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
-  if (Error Err =
-  createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
-   DeviceExtension, TempFile))
+  if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
+   DeviceTriple + "-" + Arch,
+   DeviceExtension, TempFile))
 return std::move(Err);
 
   Expected> OutputOrErr =
@@ -308,7 +314,7 @@
   if (Error E = Output->commit())
 return std::move(E);
 
-  DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
+  DeviceFiles.emplace_back(Kind, DeviceTriple, Arch, TempFile);
   ToBeStripped.push_back(*Name);
 }
   }
@@ -397,16 +403,17 @@
 
 SmallVector SectionFields;
 GV.getSection().split(SectionFields, '.');
-StringRef DeviceTriple = SectionFields[3];
-StringRef Arch = SectionFields[4];
+StringRef Kind = SectionFields[3];
+StringRef DeviceTriple = SectionFields[4];
+StringRef Arch = SectionFields[5];
 
 StringRef Contents = CDS->getAsString();
 SmallString<128> TempFile;
 StringRef DeviceExtension = getDeviceFileExtension(
 DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
-if (Error Err =
-createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
- DeviceExtension, TempFile))
+if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
+ "-" + Arch,
+ DeviceExtension, TempFile))
   return std::move(Err);
 
 Expected> OutputOrErr =
@@ -418,7 +425,7 @@
 if (Error E = Output->commit())
   return std::move(E);
 
-DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
+DeviceFiles.emplace_back(Kind, DeviceTriple, Arch, TempFile);
 ToBeDeleted.push_back();
   }
 
Index: clang/test/Driver/openmp-offload-gpu.c

[PATCH] D120289: [clang][dataflow] Add SAT solver interface and implementation

2022-02-21 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev created this revision.
sgatev added reviewers: ymandel, xazax.hun, gribozavr2.
Herald added subscribers: tschuett, steakhal, mstorsjo, rnkovacs, mgorny.
sgatev requested review of this revision.
Herald added a project: clang.

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120289

Files:
  clang/include/clang/Analysis/FlowSensitive/Solver.h
  clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -0,0 +1,274 @@
+//===- unittests/Analysis/FlowSensitive/SolverTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/Solver.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+
+class SolverTest : public ::testing::Test {
+protected:
+  // Checks if the conjunction of `Vals` is satisfiable and returns the
+  // corresponding result.
+  Solver::Result solve(llvm::DenseSet Vals) {
+return WatchedLiteralsSolver().solve(std::move(Vals));
+  }
+
+  // Creates an atomic boolean value.
+  BoolValue *atom() {
+Vals.push_back(std::make_unique());
+return Vals.back().get();
+  }
+
+  // Creates a boolean conjunction value.
+  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean disjunction value.
+  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean negation value.
+  BoolValue *neg(BoolValue *SubVal) {
+Vals.push_back(std::make_unique(*SubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean implication value.
+  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return disj(neg(LeftSubVal), RightSubVal);
+  }
+
+  // Creates a boolean biconditional value.
+  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+  }
+
+private:
+  std::vector> Vals;
+};
+
+TEST_F(SolverTest, Var) {
+  auto X = atom();
+
+  // X
+  EXPECT_EQ(solve({X}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, NegatedVar) {
+  auto X = atom();
+  auto NotX = neg(X);
+
+  // !X
+  EXPECT_EQ(solve({NotX}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, UnitConflict) {
+  auto X = atom();
+  auto NotX = neg(X);
+
+  // X ^ !X
+  EXPECT_EQ(solve({X, NotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, DistinctVars) {
+  auto X = atom();
+  auto Y = atom();
+  auto NotY = neg(Y);
+
+  // X ^ !Y
+  EXPECT_EQ(solve({X, NotY}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, DoubleNegation) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto NotNotX = neg(NotX);
+
+  // !!X ^ !X
+  EXPECT_EQ(solve({NotNotX, NotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, NegatedDisjunction) {
+  auto X = atom();
+  auto Y = atom();
+  auto XOrY = disj(X, Y);
+  auto NotXOrY = neg(XOrY);
+
+  // !(X v Y) ^ (X v Y)
+  EXPECT_EQ(solve({NotXOrY, XOrY}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, NegatedConjunction) {
+  auto X = atom();
+  auto Y = atom();
+  auto XAndY = conj(X, Y);
+  auto NotXAndY = neg(XAndY);
+
+  // !(X ^ Y) ^ (X ^ Y)
+  EXPECT_EQ(solve({NotXAndY, XAndY}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, DisjunctionSameVars) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto XOrNotX = disj(X, NotX);
+
+  // X v !X
+  EXPECT_EQ(solve({XOrNotX}), Solver::Result::Satisfiable);
+}
+
+TEST_F(SolverTest, ConjunctionSameVarsConflict) {
+  auto X = atom();
+  auto NotX = neg(X);
+  auto XAndNotX = conj(X, NotX);
+
+  // X ^ !X
+  EXPECT_EQ(solve({XAndNotX}), Solver::Result::Unsatisfiable);
+}
+
+TEST_F(SolverTest, PureVar) {
+  auto X = atom();
+  auto Y = atom();
+  auto NotX = neg(X);
+  auto NotXOrY = disj(NotX, Y);
+  auto NotY = 

[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6041
+  llvm::Value *EVal = CGF.EmitScalarExpr(E->IgnoreImpCasts());
+  llvm::Value *DVal = D ? CGF.EmitScalarExpr(D->IgnoreImpCasts()) : nullptr;
+

ABataev wrote:
> tianshilei1992 wrote:
> > tianshilei1992 wrote:
> > > Using `D->IgnoreImpCasts()` can make sure to avoid the case that `char` 
> > > is casted to `int` in binary operation. However, say, if user writes the 
> > > following code:
> > > ```
> > > int x;
> > > #pragma omp atomic compare
> > >   x = x > 1.01 ? 1.01 : x;
> > > ```
> > > `1.01` here will be casted to `1` by clang, and a warning will be 
> > > emitted. Because we ignore the implicit cast, in Sema, it is taken as 
> > > floating point value. However, we already told user that it is casted to 
> > > `1`, which is a little weird to emit an error then.
> > @ABataev Here.
> Sorry, did not understand it was a question. Could you provide a bit more 
> background, did not quite understand problem?
I have a better explain in another inline comment in Sema.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:11231
 C = Cond;
-D = CO->getTrueExpr();
+D = CO->getTrueExpr()->IgnoreImpCasts();
 if (checkIfTwoExprsAreSame(ContextRef, X, Cond->getLHS())) {

Here we do `D->IgnoreImpCasts()`, as shown in the code. The reason is, if we 
have two `char`s, say `char a, b`, and when `a > b`, clang also inserts an 
implicit cast from `char` to `int` for `a` and `b`. We want the actual type 
here otherwise in the IR builder, the type of `D` doesn't match `X`'s, causing 
issues.
However, that `IgnoreImpCasts` here can cause another issue. Let's say we have 
the following code:
```
int x;
#pragma omp atomic compare
  x = x > 1.01 ? 1.01 : x;
```
clang will also insert an implicit cast from floating point value to integer 
for the scalar value `1.01` (corresponding to `D` in the code), and also emits 
a warning saying the floating point value has been cast to integer or something 
like that. Because we have the `IgnoreImpCasts` now, it will fail the type 
check because `D` now is of floating point type, and we will emit an error to 
user.
For users, it might be confusing because on one hand we emit a warning saying 
the floating point value has been casted, and on the other hand in Sema we tell 
users it is expected an integer. Users might be thinking, you already cast it 
to integer, why do you tell me it's a floating point value again?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120288: [OpenMP] Implement dense map info for device file

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch implements a DenseMap info struct for the device file type.
This is used to help grouping device files that have the same triple and
architecture. Because of this the filename, which will always be unique
for each file, is not used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120288

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -154,12 +154,33 @@
   DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
   : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
 
-  const std::string TheTriple;
-  const std::string Arch;
-  const std::string Filename;
+  std::string TheTriple;
+  std::string Arch;
+  std::string Filename;
+};
 
-  operator std::string() const { return TheTriple + "-" + Arch; }
+namespace llvm {
+/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+template <> struct DenseMapInfo {
+  static DeviceFile getEmptyKey() {
+return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey()};
+  }
+  static DeviceFile getTombstoneKey() {
+return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey()};
+  }
+  static unsigned getHashValue(const DeviceFile ) {
+return DenseMapInfo::getHashValue(I.TheTriple) ^
+   DenseMapInfo::getHashValue(I.Arch);
+  }
+  static bool isEqual(const DeviceFile , const DeviceFile ) {
+return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+  }
 };
+} // namespace llvm
 
 namespace {
 
@@ -1035,28 +1056,28 @@
 Error linkDeviceFiles(ArrayRef DeviceFiles,
   SmallVectorImpl ) {
   // Get the list of inputs for a specific device.
-  StringMap> LinkerInputMap;
+  DenseMap> LinkerInputMap;
   for (auto  : DeviceFiles)
-LinkerInputMap[StringRef(File)].push_back(File.Filename);
+LinkerInputMap[File].push_back(File.Filename);
 
   // Try to link each device toolchain.
   for (auto  : LinkerInputMap) {
-auto TargetFeatures = LinkerInput.getKey().rsplit('-');
-Triple TheTriple(TargetFeatures.first);
-StringRef Arch(TargetFeatures.second);
+DeviceFile  = LinkerInput.getFirst();
+Triple TheTriple = Triple(File.TheTriple);
 
 // Run LTO on any bitcode files and replace the input with the result.
-if (Error Err = linkBitcodeFiles(LinkerInput.getValue(), TheTriple, Arch))
+if (Error Err =
+linkBitcodeFiles(LinkerInput.getSecond(), TheTriple, File.Arch))
   return Err;
 
 // If we are embedding bitcode for JIT, skip the final device linking.
 if (EmbedBitcode) {
-  assert(!LinkerInput.getValue().empty() && "No bitcode image to embed");
-  LinkedImages.push_back(LinkerInput.getValue().front());
+  assert(!LinkerInput.getSecond().empty() && "No bitcode image to embed");
+  LinkedImages.push_back(LinkerInput.getSecond().front());
   continue;
 }
 
-auto ImageOrErr = linkDevice(LinkerInput.getValue(), TheTriple, Arch);
+auto ImageOrErr = linkDevice(LinkerInput.getSecond(), TheTriple, 
File.Arch);
 if (!ImageOrErr)
   return ImageOrErr.takeError();
 


Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -154,12 +154,33 @@
   DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
   : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
 
-  const std::string TheTriple;
-  const std::string Arch;
-  const std::string Filename;
+  std::string TheTriple;
+  std::string Arch;
+  std::string Filename;
+};
 
-  operator std::string() const { return TheTriple + "-" + Arch; }
+namespace llvm {
+/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+template <> struct DenseMapInfo {
+  static DeviceFile getEmptyKey() {
+return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey()};
+  }
+  static DeviceFile getTombstoneKey() {
+return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey()};
+  }
+  static unsigned getHashValue(const DeviceFile ) {
+return DenseMapInfo::getHashValue(I.TheTriple) ^
+   DenseMapInfo::getHashValue(I.Arch);
+  }
+  static bool 

[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

ABataev wrote:
> tianshilei1992 wrote:
> > ABataev wrote:
> > > tianshilei1992 wrote:
> > > > tianshilei1992 wrote:
> > > > > tianshilei1992 wrote:
> > > > > > I think the `store` here is redundant. Is it because I'm using 
> > > > > > `CGF.EmitScalarExpr`?
> > > > > Oh, shoot. `load` here, instead of `store`.
> > > > And here. @ABataev 
> > > Yes, because of EmitScalarExpr
> > Can we somehow avoid the `load` here?
> Do you need EmitScalarExpr?
So it is a rvalue scalar here. What alternative do we have then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120270: [OpenMP] Try to embed offloading objects after codegen

2022-02-21 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG, wait for the other patches though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120270

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


[PATCH] D120270: [OpenMP] Try to embed offloading objects after codegen

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 410405.
jhuber6 added a comment.

Removing unrelated changes and adding test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120270

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Frontend/embed-object.c


Index: clang/test/Frontend/embed-object.c
===
--- /dev/null
+++ clang/test/Frontend/embed-object.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -x c -triple x86_64-unknown-linux-gnu -emit-llvm 
-fembed-offload-object=%S/Inputs/empty.h,section
+
+// CHECK: @[[OBJECT:.+]] = private constant [0 x i8] zeroinitializer, section 
".llvm.offloading.section"
+// CHECK: @llvm.compiler.used = appending global [3 x i8*] [i8* getelementptr 
inbounds ([0 x i8], [0 x i8]* @[[OBJECT1]]], section "llvm.metadata"
+
+void foo(void) {}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -876,6 +877,9 @@
 
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject((), CodeGenOpts, getDiags());
+
   // Set visibility from DLL storage class
   // We do this at the end of LLVM IR generation; after any operation
   // that might affect the DLL storage class or the visibility, and


Index: clang/test/Frontend/embed-object.c
===
--- /dev/null
+++ clang/test/Frontend/embed-object.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -x c -triple x86_64-unknown-linux-gnu -emit-llvm -fembed-offload-object=%S/Inputs/empty.h,section
+
+// CHECK: @[[OBJECT:.+]] = private constant [0 x i8] zeroinitializer, section ".llvm.offloading.section"
+// CHECK: @llvm.compiler.used = appending global [3 x i8*] [i8* getelementptr inbounds ([0 x i8], [0 x i8]* @[[OBJECT1]]], section "llvm.metadata"
+
+void foo(void) {}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -876,6 +877,9 @@
 
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject((), CodeGenOpts, getDiags());
+
   // Set visibility from DLL storage class
   // We do this at the end of LLVM IR generation; after any operation
   // that might affect the DLL storage class or the visibility, and
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

tianshilei1992 wrote:
> ABataev wrote:
> > tianshilei1992 wrote:
> > > tianshilei1992 wrote:
> > > > tianshilei1992 wrote:
> > > > > I think the `store` here is redundant. Is it because I'm using 
> > > > > `CGF.EmitScalarExpr`?
> > > > Oh, shoot. `load` here, instead of `store`.
> > > And here. @ABataev 
> > Yes, because of EmitScalarExpr
> Can we somehow avoid the `load` here?
Do you need EmitScalarExpr?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D118589: [C++20][Modules][6/8] Record direct module imports.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 410404.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118589

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaModule.cpp


Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -513,6 +513,11 @@
 assert(ThisModule && "was expecting a module if building one");
   }
 
+  // In some cases we need to know if an entity was present in a directly-
+  // imported module (as opposed to a transitive import).  This avoids
+  // searching both Imports and Exports.
+  DirectModuleImports.insert(Mod);
+
   return Import;
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -,6 +,9 @@
   /// The global module fragment of the current translation unit.
   clang::Module *GlobalModuleFragment = nullptr;
 
+  /// The modules we imported directly.
+  llvm::SmallPtrSet DirectModuleImports;
+
   /// Namespace definitions that we will export when they finish.
   llvm::SmallPtrSet DeferredExportedNamespaces;
 
@@ -2249,6 +2252,10 @@
 return Entity->getOwningModule();
   }
 
+  bool isModuleDirectlyImported(const Module *M) {
+return DirectModuleImports.contains(M);
+  }
+
   /// Make a merged definition of an existing hidden definition \p ND
   /// visible at the specified location.
   void makeMergedDefinitionVisible(NamedDecl *ND);


Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -513,6 +513,11 @@
 assert(ThisModule && "was expecting a module if building one");
   }
 
+  // In some cases we need to know if an entity was present in a directly-
+  // imported module (as opposed to a transitive import).  This avoids
+  // searching both Imports and Exports.
+  DirectModuleImports.insert(Mod);
+
   return Import;
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -,6 +,9 @@
   /// The global module fragment of the current translation unit.
   clang::Module *GlobalModuleFragment = nullptr;
 
+  /// The modules we imported directly.
+  llvm::SmallPtrSet DirectModuleImports;
+
   /// Namespace definitions that we will export when they finish.
   llvm::SmallPtrSet DeferredExportedNamespaces;
 
@@ -2249,6 +2252,10 @@
 return Entity->getOwningModule();
   }
 
+  bool isModuleDirectlyImported(const Module *M) {
+return DirectModuleImports.contains(M);
+  }
+
   /// Make a merged definition of an existing hidden definition \p ND
   /// visible at the specified location.
   void makeMergedDefinitionVisible(NamedDecl *ND);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 updated this revision to Diff 410403.
tyb0807 added a comment.

Add checks for default ACLE macros for different architecture versions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Preprocessor/aarch64-target-features.c
  clang/test/Preprocessor/arm-target-features.c

Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -938,3 +938,20 @@
 // CHECK-SHA2-NOT: #define __ARM_FEATURE_AES 1
 // CHECK-SHA2-NOT: #define __ARM_FEATURE_CRYPTO 1
 // CHECK-SHA2: #define __ARM_FEATURE_SHA2 1
+
+// == Check default macros for Armv8.1-A and later
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-BEFORE-V83   %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.2-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-BEFORE-V83   %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.3-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.4-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.7-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.8-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv9-a   -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv9.1-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv9.2-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv9.3-a -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-V81-OR-LATER,CHECK-V83-OR-LATER %s
+// CHECK-V83-OR-LATER: __ARM_FEATURE_COMPLEX 1
+// CHECK-V81-OR-LATER: __ARM_FEATURE_QRDMX 1
+// CHECK-BEFORE-V83-NOT: __ARM_FEATURE_COMPLEX 1
Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -294,7 +294,7 @@
 // CHECK-MCPU-CARMEL: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-feature" "+v8.2a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" "+crc" "-target-feature" "+crypto" "-target-feature" "+fullfp16" "-target-feature" "+ras" "-target-feature" "+lse" "-target-feature" "+rdm" "-target-feature" "+sha2" "-target-feature" "+aes"
 
 // RUN: %clang -target x86_64-apple-macosx -arch arm64 -### -c %s 2>&1 | FileCheck --check-prefix=CHECK-ARCH-ARM64 %s
-// CHECK-ARCH-ARM64: "-target-cpu" "apple-m1" "-target-feature" "+v8.5a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" "+crc" "-target-feature" "+crypto" "-target-feature" "+dotprod" "-target-feature" "+fp16fml" "-target-feature" "+ras" "-target-feature" "+lse" "-target-feature" "+rdm" "-target-feature" "+rcpc" "-target-feature" "+zcm" "-target-feature" "+zcz" "-target-feature" "+fullfp16" "-target-feature" "+sha2" "-target-feature" "+aes"
+// CHECK-ARCH-ARM64: "-target-cpu" "apple-m1" "-target-feature" "+v8.5a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" "+crc" "-target-feature" "+crypto" "-target-feature" "+dotprod" "-target-feature" "+fp16fml" "-target-feature" "+ras" "-target-feature" "+lse" "-target-feature" "+rdm" "-target-feature" "+rcpc" "-target-feature" "+zcm" "-target-feature" "+zcz" "-target-feature" "+fullfp16" "-target-feature" "+sm4" "-target-feature" "+sha3" "-target-feature" "+sha2" "-target-feature" "+aes"
 
 // RUN: %clang -target x86_64-apple-macosx -arch arm64_32 -### -c %s 2>&1 | FileCheck --check-prefix=CHECK-ARCH-ARM64_32 %s
 // CHECK-ARCH-ARM64_32: "-target-cpu" "apple-s4" "-target-feature" "+v8.3a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" "+crc" "-target-feature" "+crypto" "-target-feature" "+fullfp16" "-target-feature" "+ras" "-target-feature" "+lse" "-target-feature" 

[PATCH] D119599: [clang-format] Add option to align compound assignments like `+=`

2022-02-21 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 410400.
sstwcw marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119599

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestJS.cpp
  llvm/docs/YamlIO.rst
  llvm/include/llvm/Support/YAMLTraits.h

Index: llvm/include/llvm/Support/YAMLTraits.h
===
--- llvm/include/llvm/Support/YAMLTraits.h
+++ llvm/include/llvm/Support/YAMLTraits.h
@@ -63,6 +63,7 @@
   // static void mapping(IO , T );
   // Optionally may provide:
   // static std::string validate(IO , T );
+  // static void enumInput(IO , T );
   //
   // The optional flow flag will cause generated YAML to use a flow mapping
   // (e.g. { a: 0, b: 1 }):
@@ -446,6 +447,31 @@
   static bool const value = (sizeof(test>(nullptr)) == 1);
 };
 
+// Test if MappingContextTraits::enumInput() is defined on type T.
+template  struct has_MappingEnumInputTraits {
+  using Signature_validate = void (*)(class IO &, T &);
+
+  template 
+  static char test(SameType *);
+
+  template  static double test(...);
+
+  static bool const value =
+  (sizeof(test>(nullptr)) == 1);
+};
+
+// Test if MappingTraits::enumInput() is defined on type T.
+template  struct has_MappingEnumInputTraits {
+  using Signature_validate = void (*)(class IO &, T &);
+
+  template 
+  static char test(SameType *);
+
+  template  static double test(...);
+
+  static bool const value = (sizeof(test>(nullptr)) == 1);
+};
+
 // Test if SequenceTraits is defined on type T.
 template 
 struct has_SequenceMethodTraits
@@ -1061,20 +1087,45 @@
 io.endMapping();
 }
 
+#define MAPPING_COMMON()   \
+  do { \
+if (has_FlowTraits>::value) { \
+  io.beginFlowMapping();   \
+  detail::doMapping(io, Val, Ctx); \
+  io.endFlowMapping(); \
+} else {   \
+  io.beginMapping();   \
+  detail::doMapping(io, Val, Ctx); \
+  io.endMapping(); \
+}  \
+  } while (false)
+
 template 
-std::enable_if_t::value, void>
+std::enable_if_t::value &&
+ has_MappingEnumInputTraits::value,
+ void>
 yamlize(IO , T , bool, Context ) {
-  if (has_FlowTraits>::value) {
-io.beginFlowMapping();
-detail::doMapping(io, Val, Ctx);
-io.endFlowMapping();
-  } else {
-io.beginMapping();
-detail::doMapping(io, Val, Ctx);
-io.endMapping();
+  if (!io.outputting()) {
+io.beginEnumScalar();
+MappingTraits::enumInput(io, Val);
+bool Matched = !io.matchEnumFallback();
+io.endEnumScalar();
+if (Matched)
+  return;
   }
+  MAPPING_COMMON();
 }
 
+template 
+std::enable_if_t::value &&
+ !has_MappingEnumInputTraits::value,
+ void>
+yamlize(IO , T , bool, Context ) {
+  MAPPING_COMMON();
+}
+
+#undef MAPPING_COMMON
+
 template 
 std::enable_if_t::value, void>
 yamlize(IO , T , bool, EmptyContext ) {
Index: llvm/docs/YamlIO.rst
===
--- llvm/docs/YamlIO.rst
+++ llvm/docs/YamlIO.rst
@@ -551,6 +551,43 @@
   }
 };
 
+There are circumstances where we want to allow the entire mapping to be
+read as an enumeration.  For example, say some configuration option
+started as an enumeration.  Then it got more complex so it is now a
+mapping.  But it is necessary to support the old configuration files.
+In that case, add a function ``enumInput`` like for
+``ScalarEnumerationTraits::enumeration``.  Examples:
+
+.. code-block:: c++
+
+template <> struct MappingTraits {
+  static void enumInput(IO , FormatStyle::AlignConsecutiveStyle ) {
+IO.enumCase(Value, "None", FormatStyle::AlignConsecutiveStyle({}));
+IO.enumCase(Value, "Consecutive",
+FormatStyle::AlignConsecutiveStyle({/*.Enabled=*/true}));
+IO.enumCase(Value, "AcrossEmptyLines",
+FormatStyle::AlignConsecutiveStyle(
+{/*.Enabled=*/true, /*.AcrossEmptyLines=*/true}));
+IO.enumCase(Value, "AcrossComments",
+FormatStyle::AlignConsecutiveStyle({/*.Enabled=*/true,
+

[PATCH] D119599: [clang-format] Add option to align compound assignments like `+=`

2022-02-21 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 3 inline comments as done.
sstwcw added a comment.

About the unit tests that failed in B150668 . 
  It looks like they were stopped because they took over 1 minute.  I ran the 
first test on my laptop.  Both this revision and main took about 2 minutes.  
What should I do about it?




Comment at: clang/include/clang/Format/Format.h:157
+  ///   a   &= 2;
+  ///   bbb  = 2;
+  ///

HazardyKnusperkeks wrote:
> HazardyKnusperkeks wrote:
> > sstwcw wrote:
> > > HazardyKnusperkeks wrote:
> > > > sstwcw wrote:
> > > > > HazardyKnusperkeks wrote:
> > > > > > sstwcw wrote:
> > > > > > > HazardyKnusperkeks wrote:
> > > > > > > > curdeius wrote:
> > > > > > > > > I guess it would be complicated to avoid adding an additional 
> > > > > > > > > space here. I mean, it could be:
> > > > > > > > > ```
> > > > > > > > > a  &= 2;
> > > > > > > > > bbb = 2;
> > > > > > > > > ```
> > > > > > > > > And with 3-char operators, there's one more space.
> > > > > > > > That would be awesome, but it should be an option to turn off 
> > > > > > > > or on.
> > > > > > > > But I think this would really be complicated.
> > > > > > > I can do it either way. But I thought without the extra space the 
> > > > > > > formatted code looked ugly, especially when mixing `>>=` and `=`. 
> > > > > > >  Which way do you prefer?
> > > > > > > 
> > > > > > > 
> > > > > > > ```
> > > > > > > a >>= 2;
> > > > > > > bbb = 2;
> > > > > > > ```
> > > > > > I would prefer an option, to be able to do both.
> > > > > > I think I would use the variant which is more compact, but can't 
> > > > > > say for sure until I really have the option and tried it.
> > > > > You mean like a new entry under `AlignConsecutiveStyle` with the 
> > > > > options to align the left ends of the operators and to align the 
> > > > > equal sign with and without padding them to the same length? I don't 
> > > > > want the new option to be merged with `AlignCompound`, because we are 
> > > > > working on adding support for a language that uses both `=` and `<=` 
> > > > > for regular assignments, and maybe someone will want to support a 
> > > > > language that has both `=` and `:=` in the future.
> > > > Yeah. Basing on @MyDeveloperDay 's suggestion:
> > > > ```
> > > > struct AlignConsecutiveStyle {
> > > >   bool Enabled;
> > > >   bool AcrossComments;
> > > >   bool AcrossEmptyLines;
> > > >   bool AlignCompound;
> > > >   bool CompactWhitespace; // This is just a suggestion, I'm open for 
> > > > better names.
> > > > };
> > > > ```
> > > I added the new option. Moving the old options into the struct turned out 
> > > to be too much work for me on a weekend. If you can accept the 
> > > configuration style in the current revision, I will probably move the old 
> > > options into the struct at some later date. By the way, what is the 
> > > purpose of `FormatStyle::operator==`? It looks like it does not 
> > > compare`BraceWrapping`.
> > I can believe that it is too much for a weekend. But I'd like the complete 
> > migration in one patch. There are also other align styles, which currently 
> > use the same enum. And they should keep to use the same type (struct in 
> > this case). Even though there are then some options which are not (yet?) 
> > applicable to them.
> > 
> > We can mark that in the code:
> > ```Whether compound statements ae aligned along with the normal ones. Note 
> > this currently applies only to assignments: Align i.e. ``+=`` with ``=`
> >By the way, what is the purpose of `FormatStyle::operator==`? It looks like 
> >it does not compare`BraceWrapping`.
> This is an oversight, it should do what `bool operator==(const FormatStyle&) 
> const = default;` would do, if we had C++ 20.
> 
> 
In the new version all the alignment options can be read as objects.  The names 
are still ``AlignConsecutiveMacros`` etc.



Comment at: clang/include/clang/Format/Format.h:163
+  /// \endcode
+  bool AlignCompoundAssignments;
+

curdeius wrote:
> sstwcw wrote:
> > curdeius wrote:
> > > HazardyKnusperkeks wrote:
> > > > MyDeveloperDay wrote:
> > > > > This option is not independent of `AlignConsecutiveAssignments` is 
> > > > > it? this will cause confusion when people turn it on without turning 
> > > > > on `AlignConsecutiveAssignments` 
> > > > > 
> > > > > Options have a lifecycle we have noticed
> > > > > 
> > > > > 1) They start as bool
> > > > > 2) They become enums
> > > > > 3) They then end up as a struct of bool
> > > > > 4) Sometimes the struct becomes of enums
> > > > > 
> > > > > Whilst I like what you are doing here I fear we will get bugs where 
> > > > > people say I set AlignCompoundAssignments: true but its doesn't work.
> > > > > 
> > > > > `AlignConsecutiveAssignments` is already gone too far on the enum, it 
> > > > > should be a struct
> > > > > 
> > > > > so rather than
> > > > > 
> > > > > ```
> > > > > enum AlignConsecutiveStyle {
> > 

[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

ABataev wrote:
> tianshilei1992 wrote:
> > tianshilei1992 wrote:
> > > tianshilei1992 wrote:
> > > > I think the `store` here is redundant. Is it because I'm using 
> > > > `CGF.EmitScalarExpr`?
> > > Oh, shoot. `load` here, instead of `store`.
> > And here. @ABataev 
> Yes, because of EmitScalarExpr
Can we somehow avoid the `load` here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6041
+  llvm::Value *EVal = CGF.EmitScalarExpr(E->IgnoreImpCasts());
+  llvm::Value *DVal = D ? CGF.EmitScalarExpr(D->IgnoreImpCasts()) : nullptr;
+

tianshilei1992 wrote:
> tianshilei1992 wrote:
> > Using `D->IgnoreImpCasts()` can make sure to avoid the case that `char` is 
> > casted to `int` in binary operation. However, say, if user writes the 
> > following code:
> > ```
> > int x;
> > #pragma omp atomic compare
> >   x = x > 1.01 ? 1.01 : x;
> > ```
> > `1.01` here will be casted to `1` by clang, and a warning will be emitted. 
> > Because we ignore the implicit cast, in Sema, it is taken as floating point 
> > value. However, we already told user that it is casted to `1`, which is a 
> > little weird to emit an error then.
> @ABataev Here.
Sorry, did not understand it was a question. Could you provide a bit more 
background, did not quite understand problem?



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

tianshilei1992 wrote:
> tianshilei1992 wrote:
> > tianshilei1992 wrote:
> > > I think the `store` here is redundant. Is it because I'm using 
> > > `CGF.EmitScalarExpr`?
> > Oh, shoot. `load` here, instead of `store`.
> And here. @ABataev 
Yes, because of EmitScalarExpr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120270: [OpenMP] Try to embed offloading objects after codegen

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D120270#3336272 , @jdoerfert wrote:

> Can we have a test for this?

Sure.




Comment at: clang/include/clang/CodeGen/BackendUtil.h:48
 
-  void EmbedObject(llvm::Module *M, const CodeGenOptions ,
DiagnosticsEngine );

jdoerfert wrote:
> Seems unrelated, please remove it from this patch.
Yeah this is unrelated somewhat, just felt like changing it after doing another 
pass through. I can probably just commit this separately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120270

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


[PATCH] D120272: [CUDA] Add driver support for compiling CUDA with the new driver

2022-02-21 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Tests?




Comment at: clang/lib/Driver/Driver.cpp:3956
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-  LA->propagateHostOffloadInfo(OffloadKinds,
+  LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
/*BoundArch=*/nullptr);

Everything till here can be a NFC commit, right? Let's split it off



Comment at: clang/lib/Driver/Driver.cpp:4108
+}
+
 Action *Driver::BuildOffloadingActions(Compilation ,

Can we have a doxygen comment explaining what these helpers do?



Comment at: clang/lib/Driver/Driver.cpp:4122
+  const Action::OffloadKind OffloadKinds[] = {
+  Action::OFK_OpenMP, Action::OFK_Cuda, Action::OFK_HIP};
 

With the NFC commit we can probably also include some of this but restricted to 
OFK_OpenMP. Try  to minimize the functional change that one has to think about.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120272

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


[PATCH] D120271: [Clang] Add offload kind to embedded offload object

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D120271#3336277 , @jdoerfert wrote:

> The failing test needs to be adjusted, right?

Yes, forgot about that.




Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:187
+return LHS.OffloadKind == RHS.OffloadKind &&
+   LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+  }

jdoerfert wrote:
> Why not filename in the hash and equal method?
> 
> Can we split this change off into a separate patch please.
The purpose of this implementation is to group device files that share the same 
triple, ect. The filename is unique so it wouldn't be helpful for that purpose.

I could move this to a separate patch, might be find considering I remove the 
OffloadKind from this map in the next patch set so it doesn't need to be tied 
to this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120271

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


[PATCH] D120271: [Clang] Add offload kind to embedded offload object

2022-02-21 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

The failing test needs to be adjusted, right?




Comment at: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:187
+return LHS.OffloadKind == RHS.OffloadKind &&
+   LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+  }

Why not filename in the hash and equal method?

Can we split this change off into a separate patch please.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120271

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


[PATCH] D120270: [OpenMP] Try to embed offloading objects after codegen

2022-02-21 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Can we have a test for this?




Comment at: clang/include/clang/CodeGen/BackendUtil.h:48
 
-  void EmbedObject(llvm::Module *M, const CodeGenOptions ,
DiagnosticsEngine );

Seems unrelated, please remove it from this patch.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:1774
   "could not open '%0' for embedding");
-  Diags.Report(DiagID) << std::get<0>(FilenameAndSection);
   return;

Same as above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120270

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


[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I don't know a good way to automatically reduce examples, I usually do it by 
hand.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120258

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


[PATCH] D120282: [Format] Remove unused LineContainsContinuedForLoopSection. NFC

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: MyDeveloperDay.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120282

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h


Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -419,9 +419,6 @@
   /// The token that needs to be next formatted.
   FormatToken *NextToken;
 
-  /// \c true if this line contains a continued for-loop section.
-  bool LineContainsContinuedForLoopSection;
-
   /// \c true if \p NextToken should not continue this line.
   bool NoContinuation;
 
@@ -468,9 +465,6 @@
   return NextToken < Other.NextToken;
 if (Column != Other.Column)
   return Column < Other.Column;
-if (LineContainsContinuedForLoopSection !=
-Other.LineContainsContinuedForLoopSection)
-  return LineContainsContinuedForLoopSection;
 if (NoContinuation != Other.NoContinuation)
   return NoContinuation;
 if (StartOfLineLevel != Other.StartOfLineLevel)
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -253,7 +253,6 @@
   State.Stack.push_back(ParenState(/*Tok=*/nullptr, FirstIndent, FirstIndent,
/*AvoidBinPacking=*/false,
/*NoLineBreak=*/false));
-  State.LineContainsContinuedForLoopSection = false;
   State.NoContinuation = false;
   State.StartOfStringLiteral = 0;
   State.StartOfLineLevel = 0;
@@ -343,8 +342,6 @@
 return true;
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
-  if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
-return true;
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&


Index: clang/lib/Format/ContinuationIndenter.h
===
--- clang/lib/Format/ContinuationIndenter.h
+++ clang/lib/Format/ContinuationIndenter.h
@@ -419,9 +419,6 @@
   /// The token that needs to be next formatted.
   FormatToken *NextToken;
 
-  /// \c true if this line contains a continued for-loop section.
-  bool LineContainsContinuedForLoopSection;
-
   /// \c true if \p NextToken should not continue this line.
   bool NoContinuation;
 
@@ -468,9 +465,6 @@
   return NextToken < Other.NextToken;
 if (Column != Other.Column)
   return Column < Other.Column;
-if (LineContainsContinuedForLoopSection !=
-Other.LineContainsContinuedForLoopSection)
-  return LineContainsContinuedForLoopSection;
 if (NoContinuation != Other.NoContinuation)
   return NoContinuation;
 if (StartOfLineLevel != Other.StartOfLineLevel)
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -253,7 +253,6 @@
   State.Stack.push_back(ParenState(/*Tok=*/nullptr, FirstIndent, FirstIndent,
/*AvoidBinPacking=*/false,
/*NoLineBreak=*/false));
-  State.LineContainsContinuedForLoopSection = false;
   State.NoContinuation = false;
   State.StartOfStringLiteral = 0;
   State.StartOfLineLevel = 0;
@@ -343,8 +342,6 @@
 return true;
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
-  if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
-return true;
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D118632#3336145 , @ABataev wrote:

> In D118632#3336133 , 
> @tianshilei1992 wrote:
>
>> In D118632#3336094 , @ABataev 
>> wrote:
>>
>>> LG with a nit
>>
>> Actually I got two question in the inline comments. Can you please take a 
>> look?
>
> Could you point me?

Sure.




Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6041
+  llvm::Value *EVal = CGF.EmitScalarExpr(E->IgnoreImpCasts());
+  llvm::Value *DVal = D ? CGF.EmitScalarExpr(D->IgnoreImpCasts()) : nullptr;
+

tianshilei1992 wrote:
> Using `D->IgnoreImpCasts()` can make sure to avoid the case that `char` is 
> casted to `int` in binary operation. However, say, if user writes the 
> following code:
> ```
> int x;
> #pragma omp atomic compare
>   x = x > 1.01 ? 1.01 : x;
> ```
> `1.01` here will be casted to `1` by clang, and a warning will be emitted. 
> Because we ignore the implicit cast, in Sema, it is taken as floating point 
> value. However, we already told user that it is casted to `1`, which is a 
> little weird to emit an error then.
@ABataev Here.



Comment at: clang/test/OpenMP/atomic_compare_codegen.cpp:1990
+// CHECK-NEXT:[[DD:%.*]] = alloca double, align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, i8* [[CE]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw umin i8* [[CX]], i8 [[TMP0]] 
monotonic, align 1

tianshilei1992 wrote:
> tianshilei1992 wrote:
> > I think the `store` here is redundant. Is it because I'm using 
> > `CGF.EmitScalarExpr`?
> Oh, shoot. `load` here, instead of `store`.
And here. @ABataev 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

No apparent differences. Is there a way to automatically reduce it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120258

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


[clang] eec3488 - [CMake][Fuchsia] Disable assertions and analyzer for stage 1

2022-02-21 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2022-02-21T13:31:13-08:00
New Revision: eec3488cf1d84d3503d5a8535b64374b79287bb9

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

LOG: [CMake][Fuchsia] Disable assertions and analyzer for stage 1

We don't need these in the first stage compiler and disabling these
helps a bit with the compile time and runtime performance.

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index a531f9f1c10d8..8e9e44d5917ed 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -6,8 +6,8 @@ set(PACKAGE_VENDOR Fuchsia CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld;llvm;polly" CACHE STRING 
"")
 
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -29,13 +29,14 @@ if(NOT APPLE)
 endif()
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
-set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")



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


[PATCH] D120280: [CMake][Fuchsia] Disable assertions and analyzer for stage 1

2022-02-21 Thread Petr Hosek 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 rGeec3488cf1d8: [CMake][Fuchsia] Disable assertions and 
analyzer for stage 1 (authored by phosek).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120280

Files:
  clang/cmake/caches/Fuchsia.cmake


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -6,8 +6,8 @@
 
 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld;llvm;polly" CACHE STRING 
"")
 
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -29,13 +29,14 @@
 endif()
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
-set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -6,8 +6,8 @@
 
 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld;llvm;polly" CACHE STRING "")
 
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
 set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
 set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
@@ -29,13 +29,14 @@
 endif()
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
-set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
+set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120278: [clang-format] Don't break semi after requires clause regardless of the chosen style

2022-02-21 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius, JohelEGP.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/53818


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120278

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23853,6 +23853,11 @@
"}",
Style);
 
+  verifyFormat("template \n"
+   "int bar(T t)\n"
+   "  requires F;",
+   Style);
+
   Style.IndentRequiresClause = false;
   verifyFormat("template \n"
"requires F\n"
@@ -23873,6 +23878,7 @@
   verifyFormat("template  requires Foo struct Bar {};\n"
"template  requires Foo void bar() {}\n"
"template  void bar() requires Foo {}\n"
+   "template  void bar() requires Foo;\n"
"template  requires Foo Bar(T) -> Bar;",
Style);
 
@@ -23925,6 +23931,9 @@
"void bar()\n"
"requires Foo {}\n"
"template \n"
+   "void bar()\n"
+   "requires Foo;\n"
+   "template \n"
"requires Foo Bar(T) -> Bar;",
Style);
 
@@ -23984,6 +23993,7 @@
"template \n"
"void bar() requires Foo\n"
"{}\n"
+   "template  void bar() requires Foo;\n"
"template  requires Foo\n"
"Bar(T) -> Bar;",
Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3964,7 +3964,7 @@
   return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
 return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
   }
-  if (Left.ClosesRequiresClause) {
+  if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:
 case FormatStyle::RCPS_WithPreceding:


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23853,6 +23853,11 @@
"}",
Style);
 
+  verifyFormat("template \n"
+   "int bar(T t)\n"
+   "  requires F;",
+   Style);
+
   Style.IndentRequiresClause = false;
   verifyFormat("template \n"
"requires F\n"
@@ -23873,6 +23878,7 @@
   verifyFormat("template  requires Foo struct Bar {};\n"
"template  requires Foo void bar() {}\n"
"template  void bar() requires Foo {}\n"
+   "template  void bar() requires Foo;\n"
"template  requires Foo Bar(T) -> Bar;",
Style);
 
@@ -23925,6 +23931,9 @@
"void bar()\n"
"requires Foo {}\n"
"template \n"
+   "void bar()\n"
+   "requires Foo;\n"
+   "template \n"
"requires Foo Bar(T) -> Bar;",
Style);
 
@@ -23984,6 +23993,7 @@
"template \n"
"void bar() requires Foo\n"
"{}\n"
+   "template  void bar() requires Foo;\n"
"template  requires Foo\n"
"Bar(T) -> Bar;",
Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3964,7 +3964,7 @@
   return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
 return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
   }
-  if (Left.ClosesRequiresClause) {
+  if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:
 case FormatStyle::RCPS_WithPreceding:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D118588: [C++20][Modules]5/8] Diagnose wrong import/export for partition CMIs.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 410371.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118588

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-10-3-ex1.cpp
  clang/test/Modules/cxx20-10-3-ex2.cpp
  clang/test/Modules/cxx20-import-diagnostics-a.cpp

Index: clang/test/Modules/cxx20-import-diagnostics-a.cpp
===
--- clang/test/Modules/cxx20-import-diagnostics-a.cpp
+++ clang/test/Modules/cxx20-import-diagnostics-a.cpp
@@ -117,13 +117,13 @@
 
 module B;
 
-import B; // expected-error {{import of module 'B' appears within same top-level module 'B'}}
+import B; // expected-error {{import of module 'B' appears within its own implementation}}
 
 #elif TU == 9
 
 export module B;
 
-import B; // expected-error {{import of module 'B' appears within same top-level module 'B'}}
+import B; // expected-error {{import of module 'B' appears within its own interface}}
 
 #elif TU == 10
 
Index: clang/test/Modules/cxx20-10-3-ex2.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-3-ex2.cpp
@@ -0,0 +1,28 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=0 -x c++ %s \
+// RUN:  -o %t/M.pcm
+
+// RUN: %clang_cc1 -std=c++20 -S -D TU=1 -x c++ %s \
+// RUN:  -fmodule-file=%t/M.pcm -o %t/tu_8.s -verify
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -o %t/M.pcm -verify
+
+#if TU == 0
+export module M;
+
+#elif TU == 1
+module M;
+  // error: cannot import M in its own unit
+import M; // expected-error {{import of module 'M' appears within its own implementation}}
+
+#elif TU == 2
+export module M;
+  // error: cannot import M in its own unit
+import M; // expected-error {{import of module 'M' appears within its own interface}}
+
+#else
+#error "no TU set"
+#endif
Index: clang/test/Modules/cxx20-10-3-ex1.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-3-ex1.cpp
@@ -0,0 +1,36 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/M_PartImpl.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -fmodule-file=%t/M_PartImpl.pcm -o %t/M.pcm -verify
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:  -o %t/M_Part.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=4 -x c++ %s \
+// RUN:  -fmodule-file=%t/M_Part.pcm -o %t/M.pcm
+
+#if TU == 1
+module M:PartImpl;
+
+// expected-no-diagnostics
+#elif TU == 2
+export module M;
+ // error: exported partition :Part is an implementation unit
+export import :PartImpl; // expected-error {{module partition implementations cannot be exported}}
+
+#elif TU == 3
+export module M:Part;
+
+// expected-no-diagnostics
+#elif TU == 4
+export module M;
+export import :Part;
+
+// expected-no-diagnostics
+#else
+#error "no TU set"
+#endif
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -403,10 +403,16 @@
   }
 
   // Diagnose self-import before attempting a load.
+  // [module.import]/9
+  // A module implementation unit of a module M that is not a module partition
+  // shall not contain a module-import-declaration nominating M.
+  // (for an implementation, the module interface is imported implicitly,
+  //  but that's handled in the module decl code).
+
   if (getLangOpts().CPlusPlusModules && isCurrentModulePurview() &&
   getCurrentModule()->Name == ModuleName) {
-Diag(ImportLoc, diag::err_module_self_import)
-<< ModuleName << getLangOpts().CurrentModule;
+Diag(ImportLoc, diag::err_module_self_import_cxx20)
+<< ModuleName << !ModuleScopes.back().ModuleInterface;
 return true;
   }
 
@@ -440,8 +446,7 @@
   // of the same top-level module. Until we do, make it an error rather than
   // silently ignoring the import.
   // FIXME: Should we warn on a redundant import of the current module?
-  if (!getLangOpts().CPlusPlusModules &&
-  Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
+  if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
   (getLangOpts().isCompilingModule() || !getLangOpts().ModulesTS)) {
 Diag(ImportLoc, getLangOpts().isCompilingModule()
 ? diag::err_module_self_import
@@ -482,7 +487,12 @@
   if (!ModuleScopes.empty())
 Context.addModuleInitializer(ModuleScopes.back().Module, Import);
 
-  if (!ModuleScopes.empty() && ModuleScopes.back().ModuleInterface) {
+  // A module (partition) 

[PATCH] D118632: [Clang][OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D118632#3336133 , @tianshilei1992 
wrote:

> In D118632#3336094 , @ABataev wrote:
>
>> LG with a nit
>
> Actually I got two question in the inline comments. Can you please take a 
> look?

Could you point me?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120273: [OpenMP] Allow CUDA to be linked with OpenMP using the new driver

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 410370.
jhuber6 added a comment.

Make sure we don't pass PTX to nvlink.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120273

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -163,7 +163,10 @@
 };
 
 namespace llvm {
-/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+/// Helper that allows DeviceFile to be used as a key in a DenseMap. For now we
+/// assume device files with matching architectures and triples but different
+/// offloading kinds should be handlded together, this may not be true in the
+/// future.
 template <> struct DenseMapInfo {
   static DeviceFile getEmptyKey() {
 return {DenseMapInfo::getEmptyKey(),
@@ -178,13 +181,11 @@
 DenseMapInfo::getTombstoneKey()};
   }
   static unsigned getHashValue(const DeviceFile ) {
-return DenseMapInfo::getHashValue(I.OffloadKind) ^
-   DenseMapInfo::getHashValue(I.TheTriple) ^
+return DenseMapInfo::getHashValue(I.TheTriple) ^
DenseMapInfo::getHashValue(I.Arch);
   }
   static bool isEqual(const DeviceFile , const DeviceFile ) {
-return LHS.OffloadKind == RHS.OffloadKind &&
-   LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
   }
 };
 } // namespace llvm
@@ -196,10 +197,12 @@
   SmallVectorImpl );
 
 static StringRef getDeviceFileExtension(StringRef DeviceTriple,
-bool IsBitcode = false) {
+file_magic magic) {
   Triple TheTriple(DeviceTriple);
-  if (TheTriple.isAMDGPU() || IsBitcode)
+  if (magic == file_magic::bitcode)
 return "bc";
+  if (TheTriple.isNVPTX() && magic == file_magic::unknown)
+return "s";
   if (TheTriple.isNVPTX())
 return "cubin";
   return "o";
@@ -300,8 +303,8 @@
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
-  StringRef DeviceExtension = getDeviceFileExtension(
-  DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
+  StringRef DeviceExtension =
+  getDeviceFileExtension(DeviceTriple, identify_magic(*Contents));
   if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
DeviceTriple + "-" + Arch,
DeviceExtension, TempFile))
@@ -411,8 +414,8 @@
 
 StringRef Contents = CDS->getAsString();
 SmallString<128> TempFile;
-StringRef DeviceExtension = getDeviceFileExtension(
-DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
+StringRef DeviceExtension =
+getDeviceFileExtension(DeviceTriple, identify_magic(Contents));
 if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
  "-" + Arch,
  DeviceExtension, TempFile))
@@ -632,7 +635,8 @@
 
   // Add extracted input files.
   for (StringRef Input : InputFiles)
-CmdArgs.push_back(Input);
+if (Input.endswith(".cubin"))
+  CmdArgs.push_back(Input);
 
   if (sys::ExecuteAndWait(*NvlinkPath, CmdArgs))
 return createStringError(inconvertibleErrorCode(), "'nvlink' failed");
@@ -908,7 +912,22 @@
   return createFileError(File, EC);
 
 file_magic Type = identify_magic((*BufferOrErr)->getBuffer());
-if (Type != file_magic::bitcode) {
+switch (Type) {
+case file_magic::bitcode: {
+  Expected> InputFileOrErr =
+  llvm::lto::InputFile::create(**BufferOrErr);
+  if (!InputFileOrErr)
+return InputFileOrErr.takeError();
+
+  // Save the input file and the buffer associated with its memory.
+  BitcodeFiles.push_back(std::move(*InputFileOrErr));
+  SavedBuffers.push_back(std::move(*BufferOrErr));
+  continue;
+}
+case file_magic::elf_relocatable:
+case file_magic::elf_shared_object:
+case file_magic::macho_object:
+case file_magic::coff_object: {
   Expected> ObjFile =
   ObjectFile::createObjectFile(**BufferOrErr, Type);
   if (!ObjFile)
@@ -926,15 +945,10 @@
 else
   UsedInSharedLib.insert(Saver.save(*Name));
   }
-} else {
-  Expected> InputFileOrErr =
-  llvm::lto::InputFile::create(**BufferOrErr);
-  if (!InputFileOrErr)
-return InputFileOrErr.takeError();
-
-  // Save the input file and the buffer associated with its memory.
-  BitcodeFiles.push_back(std::move(*InputFileOrErr));
-  SavedBuffers.push_back(std::move(*BufferOrErr));
+  continue;
+}
+default:
+  

[PATCH] D118632: [Clang]OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D118632#3336094 , @ABataev wrote:

> LG with a nit

Actually I got two question in the inline comments. Can you please take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks - any chance you can reduce an example where hover works and inlay hints 
do not?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120258

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


[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Trass3r via Phabricator via cfe-commits
Trass3r added a comment.

Looks like this only covers a subset.
I see hints for some generic lambdas but not for others while hovering over 
auto reveals the type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120258

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


[libunwind] 3fa2e66 - [libunwind] Further fix for 32-bit PowerPC processors without AltiVec

2022-02-21 Thread Brad Smith via cfe-commits

Author: George Koehler
Date: 2022-02-21T15:31:23-05:00
New Revision: 3fa2e66c10aadac1d209afadba34d90c9bd95221

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

LOG: [libunwind] Further fix for 32-bit PowerPC processors without AltiVec

https://reviews.llvm.org/D91906 did most of the work necessary to fix libunwind 
on
32-bit PowerPC processors without AltiVec, but there was one more piece 
necessary.

Reviewed By: luporl

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

Added: 


Modified: 
libunwind/src/UnwindRegistersSave.S

Removed: 




diff  --git a/libunwind/src/UnwindRegistersSave.S 
b/libunwind/src/UnwindRegistersSave.S
index 9566bb0335fee..b39489235ce63 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -603,9 +603,11 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   stw 30,128(3)
   stw 31,132(3)
 
+#if defined(__ALTIVEC__)
   // save VRSave register
   mfspr   0, 256
   stw 0, 156(3)
+#endif
   // save CR registers
   mfcr0
   stw 0, 136(3)



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


[PATCH] D99436: [OPENMP]Fix PR49366: crash on VLAs in task untied regions.

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf9c3310d32c6: [OPENMP]Fix PR49366: crash on VLAs in task 
untied regions. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99436

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/OpenMP/task_messages.cpp
  clang/test/OpenMP/taskloop_loop_messages.cpp

Index: clang/test/OpenMP/taskloop_loop_messages.cpp
===
--- clang/test/OpenMP/taskloop_loop_messages.cpp
+++ clang/test/OpenMP/taskloop_loop_messages.cpp
@@ -691,7 +691,7 @@
 
 void test_loop_eh() {
   const int N = 100;
-  float a[N], b[N], c[N];
+  float a[N], b[N], c[N]; // expected-note {{declared here}}
 #pragma omp parallel
 #pragma omp taskloop
   for (int i = 0; i < 10; i++) {
@@ -729,6 +729,13 @@
   void g() { throw 0; }
 };
   }
+// expected-error@+5 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}
+// expected-note@+4 {{read of non-constexpr variable 'c' is not allowed in a constant expression}}
+#pragma omp taskloop untied
+  {
+  for (int i = 0; i < 10; ++i)
+int array[(int)c[0]];
+  }
 }
 
 void test_loop_firstprivate_lastprivate() {
Index: clang/test/OpenMP/task_messages.cpp
===
--- clang/test/OpenMP/task_messages.cpp
+++ clang/test/OpenMP/task_messages.cpp
@@ -173,7 +173,7 @@
   int  = a;
   S sa;
   S  = sa;
-  int r;
+  int r; // expected-note {{declared here}}
 #pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
   foo();
 #pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
@@ -330,6 +330,12 @@
 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
 #pragma omp task mergeable mergeable
   ++r;
+// expected-error@+4 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}}
+// expected-note@+3 {{read of non-const variable 'r' is not allowed in a constant expression}}
+#pragma omp task untied
+  {
+int array[r];
+  }
   volatile omp_event_handle_t evt;
   omp_event_handle_t sevt;
   const omp_event_handle_t cevt = evt;
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2458,6 +2458,9 @@
   } else if (isSFINAEContext()) {
 VLADiag = diag::err_vla_in_sfinae;
 VLAIsError = true;
+  } else if (getLangOpts().OpenMP && isInOpenMPTaskUntiedContext()) {
+VLADiag = diag::err_openmp_vla_in_task_untied;
+VLAIsError = true;
   } else {
 VLADiag = diag::ext_vla;
 VLAIsError = false;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -176,6 +176,7 @@
 bool HasMutipleLoops = false;
 const Decl *PossiblyLoopCounter = nullptr;
 bool NowaitRegion = false;
+bool UntiedRegion = false;
 bool CancelRegion = false;
 bool LoopStart = false;
 bool BodyComplete = false;
@@ -851,6 +852,15 @@
   return Parent->NowaitRegion;
 return false;
   }
+  /// Marks current region as untied (it has a 'untied' clause).
+  void setUntiedRegion(bool IsUntied = true) {
+getTopOfStack().UntiedRegion = IsUntied;
+  }
+  /// Return true if current region is untied.
+  bool isUntiedRegion() const {
+const SharingMapTy *Top = getTopOfStackOrNull();
+return Top ? Top->UntiedRegion : false;
+  }
   /// Marks parent region as cancel region.
   void setParentCancelRegion(bool Cancel = true) {
 if (SharingMapTy *Parent = getSecondOnStackOrNull())
@@ -2158,6 +2168,11 @@
   return DSAStack->getNestingLevel();
 }
 
+bool Sema::isInOpenMPTaskUntiedContext() const {
+  return isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) &&
+ DSAStack->isUntiedRegion();
+}
+
 bool Sema::isInOpenMPTargetExecutionDirective() const {
   return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) &&
   !DSAStack->isClauseParsingMode()) ||
@@ -16232,6 +16247,7 @@
 
 OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc,
  SourceLocation EndLoc) {
+  DSAStack->setUntiedRegion();
   return new (Context) OMPUntiedClause(StartLoc, EndLoc);
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ 

[clang] f9c3310 - [OPENMP]Fix PR49366: crash on VLAs in task untied regions.

2022-02-21 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2022-02-21T12:28:47-08:00
New Revision: f9c3310d32c62b28c10084a0104563aeeecc06ec

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

LOG: [OPENMP]Fix PR49366: crash on VLAs in task untied regions.

We need to capture the local variables into a record in task untied
regions but clang does not support record with VLA data members.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaType.cpp
clang/test/OpenMP/task_messages.cpp
clang/test/OpenMP/taskloop_loop_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1854c8e522b82..11fcd5ff5a323 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10893,6 +10893,8 @@ def err_omp_clause_requires_dispatch_construct : Error<
   "'%0' clause requires 'dispatch' context selector">;
 def err_omp_append_args_with_varargs : Error<
   "'append_args' is not allowed with varargs functions">;
+def err_openmp_vla_in_task_untied : Error<
+  "variable length arrays are not supported in OpenMP tasking regions with 
'untied' clause">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index dfa12ad40b72a..2d47a20711817 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10688,6 +10688,10 @@ class Sema final {
   void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
  const FunctionDecl *Callee,
  SourceLocation Loc);
+
+  /// Return true if currently in OpenMP task with untied clause context.
+  bool isInOpenMPTaskUntiedContext() const;
+
   /// Return true inside OpenMP declare target region.
   bool isInOpenMPDeclareTargetContext() const {
 return !DeclareTargetNesting.empty();

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 43386c1ef8edb..ad8d304ef43c3 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -176,6 +176,7 @@ class DSAStackTy {
 bool HasMutipleLoops = false;
 const Decl *PossiblyLoopCounter = nullptr;
 bool NowaitRegion = false;
+bool UntiedRegion = false;
 bool CancelRegion = false;
 bool LoopStart = false;
 bool BodyComplete = false;
@@ -851,6 +852,15 @@ class DSAStackTy {
   return Parent->NowaitRegion;
 return false;
   }
+  /// Marks current region as untied (it has a 'untied' clause).
+  void setUntiedRegion(bool IsUntied = true) {
+getTopOfStack().UntiedRegion = IsUntied;
+  }
+  /// Return true if current region is untied.
+  bool isUntiedRegion() const {
+const SharingMapTy *Top = getTopOfStackOrNull();
+return Top ? Top->UntiedRegion : false;
+  }
   /// Marks parent region as cancel region.
   void setParentCancelRegion(bool Cancel = true) {
 if (SharingMapTy *Parent = getSecondOnStackOrNull())
@@ -2158,6 +2168,11 @@ unsigned Sema::getOpenMPNestingLevel() const {
   return DSAStack->getNestingLevel();
 }
 
+bool Sema::isInOpenMPTaskUntiedContext() const {
+  return isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) &&
+ DSAStack->isUntiedRegion();
+}
+
 bool Sema::isInOpenMPTargetExecutionDirective() const {
   return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) &&
   !DSAStack->isClauseParsingMode()) ||
@@ -16232,6 +16247,7 @@ OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation 
StartLoc,
 
 OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc,
  SourceLocation EndLoc) {
+  DSAStack->setUntiedRegion();
   return new (Context) OMPUntiedClause(StartLoc, EndLoc);
 }
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 74969749e54ae..35d4c386211e5 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2458,6 +2458,9 @@ QualType Sema::BuildArrayType(QualType T, 
ArrayType::ArraySizeModifier ASM,
   } else if (isSFINAEContext()) {
 VLADiag = diag::err_vla_in_sfinae;
 VLAIsError = true;
+  } else if (getLangOpts().OpenMP && isInOpenMPTaskUntiedContext()) {
+VLADiag = diag::err_openmp_vla_in_task_untied;
+VLAIsError = true;
   } else {
 VLADiag = diag::ext_vla;
 VLAIsError = false;

diff  --git a/clang/test/OpenMP/task_messages.cpp 
b/clang/test/OpenMP/task_messages.cpp
index 13cbfb6c45693..86a3f0d481316 100644
--- a/clang/test/OpenMP/task_messages.cpp
+++ 

[PATCH] D120217: [clang-format] Add an option to insert braces after control statements

2022-02-21 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 410365.
owenpan marked an inline comment as done.
owenpan added a comment.

If the line immediately following `// clang-format off` is a line comment, 
`assert(!Token->Finalized)` will fail. Fixed it and updated the corresponding 
unit test.


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

https://reviews.llvm.org/D120217

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19474,6 +19474,7 @@
   CHECK_PARSE_BOOL_FIELD(IndentRequiresClause, "IndentRequires");
   CHECK_PARSE_BOOL(IndentRequiresClause);
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
+  CHECK_PARSE_BOOL(InsertBraces);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
@@ -24300,6 +24301,202 @@
   verifyFormat("template  struct Foo {};", Style);
 }
 
+TEST_F(FormatTest, InsertBraces) {
+  FormatStyle Style = getLLVMStyle();
+  Style.InsertBraces = true;
+
+  verifyFormat("// clang-format off\n"
+   "// comment\n"
+   "if (a) f();\n"
+   "// clang-format on\n"
+   "if (b) {\n"
+   "  g();\n"
+   "}",
+   "// clang-format off\n"
+   "// comment\n"
+   "if (a) f();\n"
+   "// clang-format on\n"
+   "if (b) g();",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  switch (b) {\n"
+   "  case 1:\n"
+   "c = 0;\n"
+   "break;\n"
+   "  default:\n"
+   "c = 1;\n"
+   "  }\n"
+   "}",
+   "if (a)\n"
+   "  switch (b) {\n"
+   "  case 1:\n"
+   "c = 0;\n"
+   "break;\n"
+   "  default:\n"
+   "c = 1;\n"
+   "  }",
+   Style);
+
+  verifyFormat("for (auto node : nodes) {\n"
+   "  if (node) {\n"
+   "break;\n"
+   "  }\n"
+   "}",
+   "for (auto node : nodes)\n"
+   "  if (node)\n"
+   "break;",
+   Style);
+
+  verifyFormat("for (auto node : nodes) {\n"
+   "  if (node)\n"
+   "}",
+   "for (auto node : nodes)\n"
+   "  if (node)",
+   Style);
+
+  verifyFormat("do {\n"
+   "  --a;\n"
+   "} while (a);",
+   "do\n"
+   "  --a;\n"
+   "while (a);",
+   Style);
+
+  verifyFormat("if (i) {\n"
+   "  ++i;\n"
+   "} else {\n"
+   "  --i;\n"
+   "}",
+   "if (i)\n"
+   "  ++i;\n"
+   "else {\n"
+   "  --i;\n"
+   "}",
+   Style);
+
+  verifyFormat("void f() {\n"
+   "  while (j--) {\n"
+   "while (i) {\n"
+   "  --i;\n"
+   "}\n"
+   "  }\n"
+   "}",
+   "void f() {\n"
+   "  while (j--)\n"
+   "while (i)\n"
+   "  --i;\n"
+   "}",
+   Style);
+
+  verifyFormat("f({\n"
+   "  if (a) {\n"
+   "g();\n"
+   "  }\n"
+   "});",
+   "f({\n"
+   "  if (a)\n"
+   "g();\n"
+   "});",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  f();\n"
+   "} else if (b) {\n"
+   "  g();\n"
+   "} else {\n"
+   "  h();\n"
+   "}",
+   "if (a)\n"
+   "  f();\n"
+   "else if (b)\n"
+   "  g();\n"
+   "else\n"
+   "  h();",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  f();\n"
+   "}\n"
+   "// comment\n"
+   "/* comment */",
+   "if (a)\n"
+   "  f();\n"
+   "// comment\n"
+   "/* comment */",
+   Style);
+
+  verifyFormat("if (a) {\n"
+   "  // foo\n"
+   "  // bar\n"
+   "  f();\n"
+   "}",
+   "if (a)\n"
+   "  // foo\n"
+   "  // bar\n"
+   "  f();",
+   Style);
+
+  verifyFormat("if (a) { // comment\n"
+   

[PATCH] D118632: [Clang]OpenMP] Add the codegen support for `atomic compare`

2022-02-21 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG with a nit




Comment at: clang/include/clang/AST/StmtOpenMP.h:2970
+  }
+  /// Get
+  Expr *getCondExpr() {

Fix comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118632

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


[PATCH] D120266: [clang][CodeGen] Avoid emitting ifuncs with undefined resolvers

2022-02-21 Thread Itay Bookstein via Phabricator via cfe-commits
ibookstein updated this revision to Diff 410360.
ibookstein added a comment.

clang-format + description wording


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120266

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -8,6 +8,7 @@
 #endif // _MSC_VER
 
 // Each version should have an IFunc and an alias.
+// LINUX: @SingleVersion = weak_odr alias void (), void ()* @SingleVersion.ifunc
 // LINUX: @TwoVersions = weak_odr alias void (), void ()* @TwoVersions.ifunc
 // LINUX: @TwoVersionsSameAttr = weak_odr alias void (), void ()* @TwoVersionsSameAttr.ifunc
 // LINUX: @ThreeVersionsSameAttr = weak_odr alias void (), void ()* @ThreeVersionsSameAttr.ifunc
@@ -18,8 +19,8 @@
 // LINUX: @GenericAndPentium = weak_odr alias i32 (i32, double), i32 (i32, double)* @GenericAndPentium.ifunc
 // LINUX: @DispatchFirst = weak_odr alias i32 (), i32 ()* @DispatchFirst.ifunc
 
-// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @SingleVersion.ifunc = weak_odr ifunc void (), void ()* ()* @SingleVersion.resolver
+// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @TwoVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersionsSameAttr.resolver
 // LINUX: @ThreeVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @ThreeVersionsSameAttr.resolver
 // LINUX: @NoSpecifics.ifunc = weak_odr ifunc void (), void ()* ()* @NoSpecifics.resolver
@@ -34,6 +35,21 @@
 // LINUX: define{{.*}} void @SingleVersion.S() #[[S:[0-9]+]]
 // WINDOWS: define dso_local void @SingleVersion.S() #[[S:[0-9]+]]
 
+ATTR(cpu_dispatch(ivybridge))
+void SingleVersion(void);
+// LINUX: define weak_odr void ()* @SingleVersion.resolver()
+// LINUX: call void @__cpu_indicator_init
+// LINUX: ret void ()* @SingleVersion.S
+// LINUX: call void @llvm.trap
+// LINUX: unreachable
+
+// WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
+// WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: call void @SingleVersion.S()
+// WINDOWS-NEXT: ret void
+// WINDOWS: call void @llvm.trap
+// WINDOWS: unreachable
+
 ATTR(cpu_specific(ivybridge))
 void NotCalled(void){}
 // LINUX: define{{.*}} void @NotCalled.S() #[[S]]
@@ -80,6 +96,10 @@
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.S() #[[S]]
 // CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
 
+ATTR(cpu_specific(knl))
+int CpuSpecificNoDispatch(void) { return 1; }
+// CHECK: define {{.*}}i32 @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
+
 void usages(void) {
   SingleVersion();
   // LINUX: @SingleVersion.ifunc()
@@ -93,6 +113,9 @@
   ThreeVersionsSameAttr();
   // LINUX: @ThreeVersionsSameAttr.ifunc()
   // WINDOWS: @ThreeVersionsSameAttr()
+  CpuSpecificNoDispatch();
+  // LINUX: @CpuSpecificNoDispatch.ifunc()
+  // WINDOWS: @CpuSpecificNoDispatch()
 }
 
 // has an extra config to emit!
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -42,6 +42,7 @@
 class Constant;
 class ConstantInt;
 class Function;
+class GlobalIFunc;
 class GlobalValue;
 class DataLayout;
 class FunctionType;
@@ -352,6 +353,10 @@
   /// we properly emit the iFunc.
   std::vector MultiVersionFuncs;
 
+  /// List of multiversion IFuncs we have emitted. Used to downgrade into
+  /// function declarations when we do not emit a definition for the resolver.
+  std::vector MultiVersionIFuncs;
+
   typedef llvm::StringMap > ReplacementsTy;
   ReplacementsTy Replacements;
 
@@ -1555,6 +1560,10 @@
 
   void emitMultiVersionFunctions();
 
+  /// Replace multiversion IFuncs whose resolver is undefined with function
+  /// declarations.
+  void replaceUndefinedMultiVersionIFuncs();
+
   /// Emit any vtables which we deferred and still have a use for.
   void EmitDeferredVTables();
 
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -508,6 +508,7 @@
   applyReplacements();
   checkAliases();
   emitMultiVersionFunctions();
+  replaceUndefinedMultiVersionIFuncs();
   EmitCXXGlobalInitFunc();
   EmitCXXGlobalCleanUpFunc();
   registerGlobalDtorsWithAtExit();
@@ -3289,6 +3290,22 @@
 EmitGlobalFunctionDefinition(GD, GV);
 }
 
+void CodeGenModule::replaceUndefinedMultiVersionIFuncs() {
+  for (llvm::GlobalIFunc *GIF : MultiVersionIFuncs) {
+llvm::Function *Resolver = GIF->getResolverFunction();
+if (!Resolver->isDeclaration())
+  continue;
+
+auto *DeclTy = 

[PATCH] D120273: [OpenMP] Allow CUDA to be linked with OpenMP using the new driver

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield.
Herald added subscribers: guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

After basic support for embedding and handling CUDA files was added to
the new driver, we should be able to call CUDA functions from OpenMP
code. This patch makes the necessary changes to successfuly link in CUDA
programs that were compiled using the new driver. With this patch it
should be possible to compile device-only CUDA code (no kernels) and
call it from OpenMP as follows:

  $ clang++ cuda.cu -fopenmp-new-driver -offload-arch=sm_70 -c
  $ clang++ openmp.cpp cuda.o -fopenmp-new-driver -fopenmp 
-fopenmp-targets=nvptx64 -Xopenmp-target=nvptx64 -march=sm_70

Currently this requires using a host variant to suppress the generation
of a CPU-side fallback call.

Depends on D120272 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120273

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -163,7 +163,10 @@
 };
 
 namespace llvm {
-/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+/// Helper that allows DeviceFile to be used as a key in a DenseMap. For now we
+/// assume device files with matching architectures and triples but different
+/// offloading kinds should be handlded together, this may not be true in the
+/// future.
 template <> struct DenseMapInfo {
   static DeviceFile getEmptyKey() {
 return {DenseMapInfo::getEmptyKey(),
@@ -178,13 +181,11 @@
 DenseMapInfo::getTombstoneKey()};
   }
   static unsigned getHashValue(const DeviceFile ) {
-return DenseMapInfo::getHashValue(I.OffloadKind) ^
-   DenseMapInfo::getHashValue(I.TheTriple) ^
+return DenseMapInfo::getHashValue(I.TheTriple) ^
DenseMapInfo::getHashValue(I.Arch);
   }
   static bool isEqual(const DeviceFile , const DeviceFile ) {
-return LHS.OffloadKind == RHS.OffloadKind &&
-   LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+return LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
   }
 };
 } // namespace llvm
@@ -196,10 +197,12 @@
   SmallVectorImpl );
 
 static StringRef getDeviceFileExtension(StringRef DeviceTriple,
-bool IsBitcode = false) {
+file_magic magic) {
   Triple TheTriple(DeviceTriple);
-  if (TheTriple.isAMDGPU() || IsBitcode)
+  if (magic == file_magic::bitcode)
 return "bc";
+  if (TheTriple.isNVPTX() && magic == file_magic::unknown)
+return "s";
   if (TheTriple.isNVPTX())
 return "cubin";
   return "o";
@@ -300,8 +303,8 @@
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
-  StringRef DeviceExtension = getDeviceFileExtension(
-  DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
+  StringRef DeviceExtension =
+  getDeviceFileExtension(DeviceTriple, identify_magic(*Contents));
   if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
DeviceTriple + "-" + Arch,
DeviceExtension, TempFile))
@@ -411,8 +414,8 @@
 
 StringRef Contents = CDS->getAsString();
 SmallString<128> TempFile;
-StringRef DeviceExtension = getDeviceFileExtension(
-DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
+StringRef DeviceExtension =
+getDeviceFileExtension(DeviceTriple, identify_magic(Contents));
 if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
  "-" + Arch,
  DeviceExtension, TempFile))
@@ -908,7 +911,22 @@
   return createFileError(File, EC);
 
 file_magic Type = identify_magic((*BufferOrErr)->getBuffer());
-if (Type != file_magic::bitcode) {
+switch (Type) {
+case file_magic::bitcode: {
+  Expected> InputFileOrErr =
+  llvm::lto::InputFile::create(**BufferOrErr);
+  if (!InputFileOrErr)
+return InputFileOrErr.takeError();
+
+  // Save the input file and the buffer associated with its memory.
+  BitcodeFiles.push_back(std::move(*InputFileOrErr));
+  SavedBuffers.push_back(std::move(*BufferOrErr));
+  continue;
+}
+case file_magic::elf_relocatable:
+case file_magic::elf_shared_object:
+case file_magic::macho_object:
+case file_magic::coff_object: {
   Expected> ObjFile =
   ObjectFile::createObjectFile(**BufferOrErr, Type);
   if (!ObjFile)
@@ -926,15 +944,10 @@
 else

[PATCH] D120272: [CUDA] Add driver support for compiling CUDA with the new driver

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, tra, yaxunl.
Herald added a subscriber: carlosgalvezp.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch adds the basic support for the clang driver to compile and link CUDA
using the new offloading driver. This requires handling the CUDA offloading kind
and embedding the generated files into the host. This will allow us to link
OpenMP code with CUDA code in the linker wrapper.

Depends on D120270  D120271 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120272

Files:
  clang/include/clang/Driver/Compilation.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp

Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4374,6 +4374,7 @@
   // one input.
   bool IsCuda = JA.isOffloading(Action::OFK_Cuda);
   bool IsCudaDevice = JA.isDeviceOffloading(Action::OFK_Cuda);
+  bool IsCudaHost = JA.isHostOffloading(Action::OFK_Cuda);
   bool IsHIP = JA.isOffloading(Action::OFK_HIP);
   bool IsHIPDevice = JA.isDeviceOffloading(Action::OFK_HIP);
   bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
@@ -4397,6 +4398,7 @@
 
   InputInfoList ModuleHeaderInputs;
   InputInfoList OpenMPHostInputs;
+  InputInfoList CudaHostInputs;
   const InputInfo *CudaDeviceInput = nullptr;
   const InputInfo *OpenMPDeviceInput = nullptr;
   for (const InputInfo  : Inputs) {
@@ -4411,6 +4413,8 @@
 << types::getTypeName(Expected);
   }
   ModuleHeaderInputs.push_back(I);
+} else if (IsCudaHost && Args.hasArg(options::OPT_fopenmp_new_driver)) {
+  CudaHostInputs.push_back(I);
 } else if ((IsCuda || IsHIP) && !CudaDeviceInput) {
   CudaDeviceInput = 
 } else if (IsOpenMPDevice && !OpenMPDeviceInput) {
@@ -6929,6 +6933,7 @@
 auto OpenMPTCs = C.getOffloadToolChains();
 for (auto TI = OpenMPTCs.first, TE = OpenMPTCs.second; TI != TE;
  ++TI, ++InputFile) {
+  assert(InputFile->isFilename() && "Offloading requires a filename");
   const ToolChain *TC = TI->second;
   const ArgList  = C.getArgsForToolChain(TC, "", Action::OFK_OpenMP);
   StringRef File =
@@ -6941,6 +6946,25 @@
   TC->getTripleString() + "." +
   TCArgs.getLastArgValue(options::OPT_march_EQ) + "." + InputName));
 }
+  } else if (IsCudaHost && !CudaHostInputs.empty()) {
+const ToolChain *CudaTC = C.getSingleOffloadToolChain();
+for (const auto  : CudaHostInputs) {
+  assert(InputFile.isFilename() && "Offloading requires a filename");
+  StringRef File =
+  C.getArgs().MakeArgString(CudaTC->getInputFilename(InputFile));
+  StringRef InputName = Clang::getBaseInputStem(Args, Inputs);
+  // The CUDA toolchain should have a bound arch appended to the filename.
+  StringRef Arch = File.split(".").first.rsplit('-').second;
+  // CUDA offloads both the PTX and Cubin so we need a uniqe section name.
+  if (File.endswith(".s"))
+CmdArgs.push_back(Args.MakeArgString(
+"-fembed-offload-object=" + File + "," + "cuda." +
+CudaTC->getTripleString() + "." + Arch + ".ptx." + InputName));
+  else
+CmdArgs.push_back(Args.MakeArgString(
+"-fembed-offload-object=" + File + "," + "cuda." +
+CudaTC->getTripleString() + "." + Arch + "." + InputName));
+}
   }
 
   if (Triple.isAMDGPU()) {
@@ -8189,6 +8213,7 @@
   const Driver  = getToolChain().getDriver();
   const llvm::Triple TheTriple = getToolChain().getTriple();
   auto OpenMPTCRange = C.getOffloadToolChains();
+  auto CudaTCRange = C.getOffloadToolChains();
   ArgStringList CmdArgs;
 
   // Pass the CUDA path to the linker wrapper tool.
@@ -8202,6 +8227,16 @@
   break;
 }
   }
+  for (auto  : llvm::make_range(CudaTCRange.first, CudaTCRange.second)) {
+const ToolChain *TC = I.second;
+if (TC->getTriple().isNVPTX()) {
+  CudaInstallationDetector CudaInstallation(D, TheTriple, Args);
+  if (CudaInstallation.isValid())
+CmdArgs.push_back(Args.MakeArgString(
+"--cuda-path=" + CudaInstallation.getInstallPath()));
+  break;
+}
+  }
 
   // Get the AMDGPU math libraries.
   // FIXME: This method is bad, remove once AMDGPU has a proper math library
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3830,11 +3830,6 @@
   // Builder to be used to build offloading actions.
   OffloadingActionBuilder OffloadBuilder(C, Args, Inputs);
 
-  // Offload kinds active for this compilation.
-  unsigned OffloadKinds = Action::OFK_None;
-  if (C.hasOffloadToolChain())
- 

[PATCH] D120271: [Clang] Add offload kind to embedded offload object

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

This patch adds the offload kind to the embedded section name in
preparation for offloading to different kinda like CUDA or HIP. Also
simplify the key handling by adding a dense map info implementation for
the device file struct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120271

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -151,15 +151,43 @@
 
 /// Information for a device offloading file extracted from the host.
 struct DeviceFile {
-  DeviceFile(StringRef TheTriple, StringRef Arch, StringRef Filename)
-  : TheTriple(TheTriple), Arch(Arch), Filename(Filename) {}
-
-  const std::string TheTriple;
-  const std::string Arch;
-  const std::string Filename;
+  DeviceFile(StringRef OffloadKind, StringRef TheTriple, StringRef Arch,
+ StringRef Filename)
+  : OffloadKind(OffloadKind), TheTriple(TheTriple), Arch(Arch),
+Filename(Filename) {}
+
+  std::string OffloadKind;
+  std::string TheTriple;
+  std::string Arch;
+  std::string Filename;
+};
 
-  operator std::string() const { return TheTriple + "-" + Arch; }
+namespace llvm {
+/// Helper that allows DeviceFile to be used as a key in a DenseMap.
+template <> struct DenseMapInfo {
+  static DeviceFile getEmptyKey() {
+return {DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey(),
+DenseMapInfo::getEmptyKey()};
+  }
+  static DeviceFile getTombstoneKey() {
+return {DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey(),
+DenseMapInfo::getTombstoneKey()};
+  }
+  static unsigned getHashValue(const DeviceFile ) {
+return DenseMapInfo::getHashValue(I.OffloadKind) ^
+   DenseMapInfo::getHashValue(I.TheTriple) ^
+   DenseMapInfo::getHashValue(I.Arch);
+  }
+  static bool isEqual(const DeviceFile , const DeviceFile ) {
+return LHS.OffloadKind == RHS.OffloadKind &&
+   LHS.TheTriple == RHS.TheTriple && LHS.Arch == RHS.Arch;
+  }
 };
+} // namespace llvm
 
 namespace {
 
@@ -187,7 +215,7 @@
 DeviceFile getBitcodeLibrary(StringRef LibraryStr) {
   auto DeviceAndPath = StringRef(LibraryStr).split('=');
   auto TripleAndArch = DeviceAndPath.first.rsplit('-');
-  return DeviceFile(TripleAndArch.first, TripleAndArch.second,
+  return DeviceFile("openmp", TripleAndArch.first, TripleAndArch.second,
 DeviceAndPath.second);
 }
 
@@ -266,16 +294,17 @@
 
 SmallVector SectionFields;
 Name->split(SectionFields, '.');
-StringRef DeviceTriple = SectionFields[3];
-StringRef Arch = SectionFields[4];
+StringRef Kind = SectionFields[3];
+StringRef DeviceTriple = SectionFields[4];
+StringRef Arch = SectionFields[5];
 
 if (Expected Contents = Sec.getContents()) {
   SmallString<128> TempFile;
   StringRef DeviceExtension = getDeviceFileExtension(
   DeviceTriple, identify_magic(*Contents) == file_magic::bitcode);
-  if (Error Err =
-  createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
-   DeviceExtension, TempFile))
+  if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" +
+   DeviceTriple + "-" + Arch,
+   DeviceExtension, TempFile))
 return std::move(Err);
 
   Expected> OutputOrErr =
@@ -287,7 +316,7 @@
   if (Error E = Output->commit())
 return std::move(E);
 
-  DeviceFiles.emplace_back(DeviceTriple, Arch, TempFile);
+  DeviceFiles.emplace_back(Kind, DeviceTriple, Arch, TempFile);
   ToBeStripped.push_back(*Name);
 }
   }
@@ -376,6 +405,7 @@
 
 SmallVector SectionFields;
 GV.getSection().split(SectionFields, '.');
+StringRef Kind = SectionFields[3];
 StringRef DeviceTriple = SectionFields[3];
 StringRef Arch = SectionFields[4];
 
@@ -383,9 +413,9 @@
 SmallString<128> TempFile;
 StringRef DeviceExtension = getDeviceFileExtension(
 DeviceTriple, identify_magic(Contents) == file_magic::bitcode);
-if (Error Err =
-createOutputFile(Prefix + "-device-" + DeviceTriple + "-" + Arch,
- DeviceExtension, TempFile))
+if (Error Err = createOutputFile(Prefix + "-" + Kind + "-" + DeviceTriple +
+ "-" + Arch,
+ DeviceExtension, TempFile))

[PATCH] D120270: [OpenMP] Try to embed offloading objects after codegen

2022-02-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield.
Herald added subscribers: ormris, guansong, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Currently we use the `-fembed-offload-object` option to embed a binary
file into the host as a named section. This is currently only used as a
codegen action, meaning we only handle this option correctly when the
input is a bitcode file. This patch adds the same handling to embed an
offloading object after we complete code generation. This allows us to
embed the object correctly if the input file is source or bitcode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120270

Files:
  clang/include/clang/CodeGen/BackendUtil.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -587,6 +588,9 @@
 EmitModuleLinkOptions();
   }
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject(getModule(), CodeGenOpts, getDiags());
+
   // On ELF we pass the dependent library specifiers directly to the linker
   // without manipulating them. This is in contrast to other platforms where
   // they are mapped to a specific linker option by the compiler. This
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1134,7 +1134,7 @@
 TheModule->setTargetTriple(TargetOpts.Triple);
   }
 
-  EmbedObject(TheModule.get(), CodeGenOpts, Diagnostics);
+  EmbedObject(*TheModule.get(), CodeGenOpts, Diagnostics);
   EmbedBitcode(TheModule.get(), CodeGenOpts, *MainFile);
 
   LLVMContext  = TheModule->getContext();
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1753,7 +1753,7 @@
   CGOpts.CmdArgs);
 }
 
-void clang::EmbedObject(llvm::Module *M, const CodeGenOptions ,
+void clang::EmbedObject(llvm::Module , const CodeGenOptions ,
 DiagnosticsEngine ) {
   if (CGOpts.OffloadObjects.empty())
 return;
@@ -1771,12 +1771,12 @@
 if (std::error_code EC = ObjectOrErr.getError()) {
   auto DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
   "could not open '%0' for embedding");
-  Diags.Report(DiagID) << std::get<0>(FilenameAndSection);
+  Diags.Report(DiagID) << FilenameAndSection.first;
   return;
 }
 
 SmallString<128> SectionName(
-{".llvm.offloading.", std::get<1>(FilenameAndSection)});
-llvm::embedBufferInModule(*M, **ObjectOrErr, SectionName);
+{".llvm.offloading.", FilenameAndSection.second});
+llvm::embedBufferInModule(M, **ObjectOrErr, SectionName);
   }
 }
Index: clang/include/clang/CodeGen/BackendUtil.h
===
--- clang/include/clang/CodeGen/BackendUtil.h
+++ clang/include/clang/CodeGen/BackendUtil.h
@@ -45,7 +45,7 @@
   void EmbedBitcode(llvm::Module *M, const CodeGenOptions ,
 llvm::MemoryBufferRef Buf);
 
-  void EmbedObject(llvm::Module *M, const CodeGenOptions ,
+  void EmbedObject(llvm::Module , const CodeGenOptions ,
DiagnosticsEngine );
 }
 


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -43,6 +43,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
+#include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -587,6 +588,9 @@
 EmitModuleLinkOptions();
   }
 
+  // If there is device offloading code embed it in the host now.
+  EmbedObject(getModule(), CodeGenOpts, getDiags());
+
   // On ELF we pass the dependent library specifiers directly to the linker
   // without manipulating them. This is in contrast to other platforms where
   // they are mapped to a specific linker option by the compiler. This
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- 

[PATCH] D118587: [C++20][Modules][4/8] Handle generation of partition implementation CMIs.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 410348.
iains added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118587

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-10-1-ex1.cpp
  clang/test/Modules/cxx20-10-1-ex2.cpp
  clang/test/Modules/cxx20-import-diagnostics-a.cpp

Index: clang/test/Modules/cxx20-import-diagnostics-a.cpp
===
--- clang/test/Modules/cxx20-import-diagnostics-a.cpp
+++ clang/test/Modules/cxx20-import-diagnostics-a.cpp
@@ -94,9 +94,9 @@
 #elif TU == 6
 
 module;
-// We can only have preprocessor commands here, which could include an include
+// We can only have preprocessor directives here, which permits an include-
 // translated header unit.  However those are identified specifically by the
-// preprocessor; non-preprocessed user code should not contain an import here.
+// preprocessor; non-preprocessed user code should not contain an 'import' here.
 import B; // expected-error {{module imports cannot be in the global module fragment}}
 
 export module D;
Index: clang/test/Modules/cxx20-10-1-ex2.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-1-ex2.cpp
@@ -0,0 +1,60 @@
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/B_Y.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -fmodule-file=%t/B_Y.pcm -o %t/B.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:   -o %t/B_X1.pcm -verify
+
+// Not expected to work yet.
+//  %clang_cc1 -std=c++20 -emit-module-interface -D TU=4 -x c++ %s \
+//   -fmodule-file=%t/B.pcm  -o %t/B_X2.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -D TU=5 -x c++ %s \
+// RUN:  -fmodule-file=%t/B.pcm  -o %t/b_tu5.s
+
+// RUN: %clang_cc1 -std=c++20 -S -D TU=6 -x c++ %s \
+// RUN:  -fmodule-file=%t/B.pcm  -o %t/b_tu6.s -verify
+
+// Not expected to work yet.
+//  %clang_cc1 -std=c++20 -emit-module-interface -D TU=7 -x c++ %s \
+//   -fmodule-file=%t/B_X2.pcm  -o %t/B_X3.pcm -verify
+
+#if TU == 1
+  module B:Y;
+  int y();
+// expected-no-diagnostics
+#elif TU == 2
+  export module B;
+  import :Y;
+  int n = y();
+// expected-no-diagnostics
+#elif TU == 3
+  module B:X1; // does not implicitly import B
+  int  = n;  // expected-error {{use of undeclared identifier }}
+#elif TU == 4
+  module B:X2; // does not implicitly import B
+  import B;
+  int  = n; // OK
+// expected-no-diagnostics
+#elif TU == 5
+  module B; // implicitly imports B
+  int  = n; // OK
+// expected-no-diagnostics
+#elif TU == 6
+  import B;
+  // error, n is module-local and this is not a module.
+  int  = n; // expected-error {{use of undeclared identifier}}
+#elif TU == 7
+  module B:X3; // does not implicitly import B
+  import :X2; // X2 is an implementation so exports nothing.
+  // error: n not visible here.
+  int  = n; // expected-error {{use of undeclared identifier }}
+#else
+#error "no TU set"
+#endif
Index: clang/test/Modules/cxx20-10-1-ex1.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-10-1-ex1.cpp
@@ -0,0 +1,50 @@
+// The example in the standard is not in required build order.
+// revised here
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/A_Internals.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -fmodule-file=%t/A_Internals.pcm -o %t/A_Foo.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:  -fmodule-file=%t/A_Foo.pcm -o %t/A.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj  -D TU=4 -x c++ %s \
+// RUN:  -fmodule-file=%t/A.pcm -o %t/ex1.o
+
+// expected-no-diagnostics
+
+#if TU == 1
+
+module A:Internals;
+int bar();
+
+#elif TU == 2
+
+export module A:Foo;
+
+import :Internals;
+
+export int foo() { return 2 * (bar() + 1); }
+
+#elif TU == 3
+
+export module A;
+export import :Foo;
+export int baz();
+
+#elif TU == 4
+module A;
+
+import :Internals;
+
+int bar() { return baz() - 10; }
+int baz() { return 30; }
+
+#else
+#error "no TU set"
+#endif
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -110,9 +110,24 @@
   // module state;
   ImportState = ModuleImportState::NotACXX20Module;
 
-  // A module implementation unit requires that we are not compiling a module
-  // of any kind. A module interface unit requires that we are not compiling a
-  // module map.
+  bool IsPartition = !Partition.empty();
+  if (IsPartition)
+switch (MDK) {
+case 

[PATCH] D120266: [clang][CodeGen] Avoid emitting ifuncs with undefined resolvers

2022-02-21 Thread Itay Bookstein via Phabricator via cfe-commits
ibookstein created this revision.
ibookstein added reviewers: erichkeane, rsmith, MaskRay.
ibookstein requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The purpose of this change is to fix the following codegen bug:

// main.c
__attribute__((cpu_specific(generic)))
int *foo(void) { static int z; return }
int main() { return *foo() = 5; }

// other.c
__attribute__((cpu_dispatch(generic))) int *foo(void);

// run:
clang main.c other.c -o main; ./main

This will segfault prior to the change, and return the correct
exit code 5 after the change.

The underlying cause is that when a translation unit contains
a cpu_specific function without the corresponding cpu_dispatch
(which is a valid use-case, they can be put into different
translation units), the generated code binds the reference to
foo() against a GlobalIFunc whose resolver is undefined. This
is invalid (the resolver must be defined in the same translation
unit as the ifunc), but historically the LLVM bitcode verifier
did not check that. The generated code then binds against the
resolver rather than the ifunc, so it ends up calling the
resolver rather than the resolvee. In the example above it treats
its return value as an int *, therefore trying to write to program
text.

The root issue at the representation level is that GlobalIFunc,
like GlobalAlias, does not support a "declaration" state. The
object which provides the correct semantics in these cases
is a Function declaration, but unlike Functions, changing a
declaration to a definition in the GlobalIFunc case constitutes
a change of the object type (as opposed to simply emitting code
into the function).

I think this limitation is unlikely to change, so I implemented
the fix by rewriting the generated IR to use a function
declaration instead of an ifunc if the resolver ends up undefined.
This uses takeName + replaceAllUsesWith in similar vein to
other places where the correct IR object type cannot be known
up front locally, like in CodeGenModule::EmitAliasDefinition.
In this case, we don't know whether the translation unit
will contain the cpu_dispatch when generating code for a reference
bound against a cpu_specific symbol.

It is also possible to generate the reference as a Function
declaration first, and 'upgrade' it to a GlobalIFunc once a
cpu_dispatch is encountered, which is somewhat more 'natural'.
That would involve a larger code change, though, so I wanted to
get feedback on the viability of the approach first.

Signed-off-by: Itay Bookstein 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120266

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -8,6 +8,7 @@
 #endif // _MSC_VER
 
 // Each version should have an IFunc and an alias.
+// LINUX: @SingleVersion = weak_odr alias void (), void ()* @SingleVersion.ifunc
 // LINUX: @TwoVersions = weak_odr alias void (), void ()* @TwoVersions.ifunc
 // LINUX: @TwoVersionsSameAttr = weak_odr alias void (), void ()* @TwoVersionsSameAttr.ifunc
 // LINUX: @ThreeVersionsSameAttr = weak_odr alias void (), void ()* @ThreeVersionsSameAttr.ifunc
@@ -18,8 +19,8 @@
 // LINUX: @GenericAndPentium = weak_odr alias i32 (i32, double), i32 (i32, double)* @GenericAndPentium.ifunc
 // LINUX: @DispatchFirst = weak_odr alias i32 (), i32 ()* @DispatchFirst.ifunc
 
-// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @SingleVersion.ifunc = weak_odr ifunc void (), void ()* ()* @SingleVersion.resolver
+// LINUX: @TwoVersions.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersions.resolver
 // LINUX: @TwoVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @TwoVersionsSameAttr.resolver
 // LINUX: @ThreeVersionsSameAttr.ifunc = weak_odr ifunc void (), void ()* ()* @ThreeVersionsSameAttr.resolver
 // LINUX: @NoSpecifics.ifunc = weak_odr ifunc void (), void ()* ()* @NoSpecifics.resolver
@@ -34,6 +35,21 @@
 // LINUX: define{{.*}} void @SingleVersion.S() #[[S:[0-9]+]]
 // WINDOWS: define dso_local void @SingleVersion.S() #[[S:[0-9]+]]
 
+ATTR(cpu_dispatch(ivybridge))
+void SingleVersion(void);
+// LINUX: define weak_odr void ()* @SingleVersion.resolver()
+// LINUX: call void @__cpu_indicator_init
+// LINUX: ret void ()* @SingleVersion.S
+// LINUX: call void @llvm.trap
+// LINUX: unreachable
+
+// WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
+// WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: call void @SingleVersion.S()
+// WINDOWS-NEXT: ret void
+// WINDOWS: call void @llvm.trap
+// WINDOWS: unreachable
+
 ATTR(cpu_specific(ivybridge))
 void NotCalled(void){}
 // LINUX: define{{.*}} void @NotCalled.S() #[[S]]
@@ -80,6 +96,10 @@
 // CHECK: define 

[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian 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 rGe2855e17601e: [Clang][OpenMP] Add Sema support for atomic 
compare capture (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_messages.c
  clang/test/OpenMP/atomic_messages.cpp

Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -928,7 +928,7 @@
 }
 
 int mixed() {
-  int a, b = 0;
+  int a, v, b = 0;
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
 // expected-note@+1 {{'read' clause used here}}
 #pragma omp atomic read write
@@ -957,7 +957,7 @@
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'compare' clause}}
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
-  a = b;
+  { v = a; if (a > b) a = b; }
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -500,4 +500,199 @@
   fx = fe;
   }
 }
+
+void compare_capture(void) {
+  int x = 0;
+  int d = 0;
+  int e = 0;
+  int v = 0;
+  int r = 0;
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected compound statement}}
+#pragma omp atomic compare capture
+  if (x == e) {}
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected exactly one expression statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x = d;
+v = x;
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+bbar();
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x += d;
+  }
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 

[clang] e2855e1 - [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-02-21T14:21:02-05:00
New Revision: e2855e17601e8a193bf07b0533be69dbf85b811c

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

LOG: [Clang][OpenMP] Add Sema support for atomic compare capture

This patch adds Sema support for `atomic compare capture`.

Reviewed By: ABataev

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/atomic_messages.c
clang/test/OpenMP/atomic_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0d301e76c92d..1854c8e522b8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10523,10 +10523,16 @@ def err_omp_atomic_compare : Error<
   " '{x = x == e ? d : x;}', '{x = e == x ? d : x;}', or 'if(expr ordop x) {x 
= expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}',"
   " 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 
'expr', 'e', and 'd' are expressions with scalar type,"
   " and 'ordop' is one of '<' or '>'.">;
+def err_omp_atomic_compare_capture : Error<
+  "the statement for 'atomic compare capture' must be a compound statement of 
form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} 
else {v = x;}}',"
+  " '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = 
x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr 
ordop x) {x = expr;}',"
+  " 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = 
d;}' where 'x', 'r', and 'v' are lvalue expressions with scalar type, 'expr', 
'e', and 'd' are expressions with scalar type,"
+  " and 'ordop' is one of '<' or '>'.">;
 def note_omp_atomic_compare: Note<
   "%select{expected compound statement|expected exactly one expression 
statement|expected assignment statement|expected conditional operator|expect 
result value to be at false expression|"
   "expect binary operator in conditional expression|expect '<', '>' or '==' as 
order operator|expect comparison in a form of 'x == e', 'e == x', 'x ordop 
expr', or 'expr ordop x'|"
-  "expect lvalue for result value|expect scalar value|expect integer 
value|unexpected 'else' statement}0">;
+  "expect lvalue for result value|expect scalar value|expect integer 
value|unexpected 'else' statement|expect '==' operator|expect an assignment 
statement 'v = x'|"
+  "expect a 'if' statement|expect no more than two statements|expect a 
compound statement|expect 'else' statement|expect a form 'r = x == e; if (r) 
...'}0">;
 def err_omp_atomic_several_clauses : Error<
   "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update', 'capture', or 'compare' clause">;
 def err_omp_several_mem_order_clauses : Error<

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index c32609e4e32e..43386c1ef8ed 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -10976,6 +10976,20 @@ class OpenMPAtomicCompareChecker {
 NotInteger,
 /// 'else' statement is not expected.
 UnexpectedElse,
+/// Not an equality operator.
+NotEQ,
+/// Invalid assignment (not v == x).
+InvalidAssignment,
+/// Not if statement
+NotIfStmt,
+/// More than two statements in a compund statement.
+MoreThanTwoStmts,
+/// Not a compound statement.
+NotCompoundStmt,
+/// No else statement.
+NoElse,
+/// Not 'if (r)'.
+InvalidCondition,
 /// No error.
 NoError,
   };
@@ -10999,7 +11013,7 @@ class OpenMPAtomicCompareChecker {
   Expr *getCond() const { return C; }
   bool isXBinopExpr() const { return IsXBinopExpr; }
 
-private:
+protected:
   /// Reference to ASTContext
   ASTContext 
   /// 'x' lvalue part of the source atomic expression.
@@ -11026,6 +11040,35 @@ class OpenMPAtomicCompareChecker {
 
   /// Check if all captured values have right type.
   bool checkType(ErrorInfoTy ) const;
+
+  static bool CheckValue(const Expr *E, ErrorInfoTy ,
+ bool ShouldBeLValue) {
+if (ShouldBeLValue && !E->isLValue()) {
+  ErrorInfo.Error = ErrorTy::XNotLValue;
+  ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
+  ErrorInfo.ErrorRange = ErrorInfo.NoteRange = E->getSourceRange();
+  return false;
+}
+
+if (!E->isInstantiationDependent()) {
+  QualType QTy = E->getType();
+  if (!QTy->isScalarType()) {
+ErrorInfo.Error = ErrorTy::NotScalar;
+ErrorInfo.ErrorLoc = ErrorInfo.NoteLoc = E->getExprLoc();
+ErrorInfo.ErrorRange = ErrorInfo.NoteRange 

[PATCH] D119162: [Pseudo] Token/TokenStream, PP directive parser.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h:49
+/// | `printf("hello, ");
+/// |-+ Conditional -+ Directive #ifndef NDEBUG
+/// | |-+ Code printf("debug\n");

hokein wrote:
> is the `-+ Directive` expected?
Yes, this is `Cond.Branches[0].first`.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h:103
+// FIXME: This approximates std::variant.
+// Switch once we can use C++17.
+class PPStructure::Chunk {

hokein wrote:
> yeah, this should be happened soon, see 
> https://discourse.llvm.org/t/rfc-increasing-the-gcc-and-clang-requirements-to-support-c-17-in-llvm/59983.
I hope so, but I'm not holding my breath.
(It'll happen soon enough that I'm not going to worry about optimizing this 
though)



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Token.h:64
+  /// Zero-based line number.
+  uint32_t Line = 0;
+  /// Width of whitespace before the first token on this line.

hokein wrote:
> nit: mention this is the line number for the start of token, a token can be 
> multiple-line.
> 
> I think the meaning of line number is token-stream-dependent, right? For a 
> lex token-stream, it is raw line number; For a cook token stream, it might 
> take the backslash continued line into account?
> 
> mention this is the line number for the start of token
Done.

> I think the meaning of line number is token-stream-dependent, right? 
This always refers to the original source code - a backslash continued line 
won't reduce the line number. Expanded the comment.




Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Token.h:89
+  uint32_t size() const { return End - Begin; }
+  static Range empty(unsigned Index) { return Range{Index, Index}; }
+};

hokein wrote:
> nit: unsigned -> Token::Index
> 
> I'd probably drop it (looks like only one place using it, inclining it should 
> be fine), the name empty is usually a method checking the Range is empty 
> rather than creating an empty Range.
This will be used in a bunch more places, and inlining it is awkward:
 - often have to extract an expression to a variable to avoid duplicating it
 - it's IMO much less obvious at the callsite the intent is to specify an empty 
range

You're right about the name though, renamed to emptyAt which hopefully avoids 
that association.



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Token.h:130
+assert( != Storage.data() && "start sentinel");
+assert( >= Storage.data() &&  < Storage.data() + Storage.size());
+return  - Tokens.data();

hokein wrote:
> `>=` => `>`, since we have checked above.
I'm not sure why that change would be an improvement, can you elaborate?

The two assertions are that we own the token, and that it's not the start 
sentinel. I think changing the condition makes that less clear.

(Reordered them though, as the start-sentinel assertion seems secondary)



Comment at: clang/include/clang/Tooling/Syntax/Pseudo/Token.h:166
+/// Tokens at the start of an unescaped newline (where a directive may start)
+/// will have StartsPPLine.
+/// "word-like" tokens such as identifiers and keywords will be raw_identifier.

hokein wrote:
> I think it would be clearer to give more details (for example, give some 
> examples) in the comment to clarify -- it took me quite a while to understand 
> "an unescaped newline" (I guess this refers to the backslash continued line?).
> 
> And having a PP in the name seems a little confusing, it somehow indicates 
> this flag  is PP-specific, e.g. for a simple example without any PP structure 
> `int a;` the `int` token has the  `StartsPPLine` being set.
Oops, this sentence didn't make much sense. The point is that the preprocessor 
distinguishes between logical and physical lines:

```
#define X(error) \
  #error // this is not a directive
auto m = X(foo); // string "foo"
```

This concept of "logical line" and the rules around it are specific to the 
preprocessor. The rest of the parser is line-agnostic or uses physical line 
numbers. So I think PP belongs in the name.

Expanded the comment here.



Comment at: clang/lib/Tooling/Syntax/Pseudo/Lex.cpp:65
+
+if (CT.isAtStartOfLine())
+  Tok.setFlag(LexFlags::StartsPPLine);

hokein wrote:
> just want to double-check this is the behavior we want,
> 
> From the clang's token comment:
> ```
> TokenFlags::StartOfLine  // At start of line or only after whitespace
> 
> 
> so the `abc` token will have this flag
> ```
> abc // abc has two leading spaces.
Yes. This matches the logic clang uses (Lexer.cpp:657) to decide whether a hash 
starts a PP directive, which is what this flag is intended to emulate.



Comment at: 

[PATCH] D119162: [Pseudo] Token/TokenStream, PP directive parser.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 410340.
sammccall marked 26 inline comments as done.
sammccall added a comment.
Herald added a subscriber: dexonsmith.

address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119162

Files:
  clang/include/clang/Basic/TokenKinds.h
  clang/include/clang/Tooling/Syntax/Pseudo/Preprocess.h
  clang/include/clang/Tooling/Syntax/Pseudo/Token.h
  clang/lib/Basic/TokenKinds.cpp
  clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt
  clang/lib/Tooling/Syntax/Pseudo/Lex.cpp
  clang/lib/Tooling/Syntax/Pseudo/Preprocess.cpp
  clang/lib/Tooling/Syntax/Pseudo/Token.cpp
  clang/test/Syntax/Inputs/example.c
  clang/test/Syntax/lex.test
  clang/tools/clang-pseudo/ClangPseudo.cpp
  clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt
  clang/unittests/Tooling/Syntax/Pseudo/PreprocessTest.cpp
  clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp

Index: clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp
@@ -0,0 +1,178 @@
+//===--- TokenTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Pseudo/Token.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/TokenKinds.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace syntax {
+namespace pseudo {
+namespace {
+
+using testing::AllOf;
+using testing::ElementsAre;
+using testing::ElementsAreArray;
+using testing::Not;
+
+MATCHER_P2(token, Text, Kind, "") {
+  return arg.Kind == Kind && arg.text() == Text;
+}
+
+MATCHER_P(hasFlag, Flag, "") { return arg.flag(Flag); }
+
+MATCHER_P2(lineIndent, Line, Indent, "") {
+  return arg.Line == (unsigned)Line && arg.Indent == (unsigned)Indent;
+}
+
+TEST(TokenTest, Lex) {
+  LangOptions Opts;
+  std::string Code = R"cpp(
+#include 
+int main() {
+  return 42; // the answer
+}
+  )cpp";
+  TokenStream Raw = lex(Code, Opts);
+  ASSERT_TRUE(Raw.isFinalized());
+  EXPECT_THAT(Raw.tokens(),
+  ElementsAreArray({
+  // Lexing of directives is weird, especially  strings.
+  token("#", tok::hash),
+  token("include", tok::raw_identifier),
+  token("<", tok::less),
+  token("stdio", tok::raw_identifier),
+  token(".", tok::period),
+  token("h", tok::raw_identifier),
+  token(">", tok::greater),
+
+  token("int", tok::raw_identifier),
+  token("main", tok::raw_identifier),
+  token("(", tok::l_paren),
+  token(")", tok::r_paren),
+  token("{", tok::l_brace),
+  token("return", tok::raw_identifier),
+  token("42", tok::numeric_constant),
+  token(";", tok::semi),
+  token("// the answer", tok::comment),
+  token("}", tok::r_brace),
+  }));
+
+  TokenStream Cooked = cook(Raw, Opts);
+  ASSERT_TRUE(Cooked.isFinalized());
+  EXPECT_THAT(Cooked.tokens(),
+  ElementsAreArray({
+  // Cooked identifier types in directives are not meaningful.
+  token("#", tok::hash),
+  token("include", tok::identifier),
+  token("<", tok::less),
+  token("stdio", tok::identifier),
+  token(".", tok::period),
+  token("h", tok::identifier),
+  token(">", tok::greater),
+
+  token("int", tok::kw_int),
+  token("main", tok::identifier),
+  token("(", tok::l_paren),
+  token(")", tok::r_paren),
+  token("{", tok::l_brace),
+  token("return", tok::kw_return),
+  token("42", tok::numeric_constant),
+  token(";", tok::semi),
+  token("// the answer", tok::comment),
+  token("}", tok::r_brace),
+  }));
+  // Check raw tokens point back into original source code.
+  EXPECT_EQ(Raw.tokens().front().text().begin(), [Code.find('#')]);
+}
+
+TEST(TokenTest, LineContinuation) {
+  LangOptions Opts;
+  std::string Code = R"cpp(
+one_\
+token
+two \
+tokens
+  )cpp";
+  TokenStream Raw = lex(Code, Opts);
+  EXPECT_THAT(
+  Raw.tokens(),
+  ElementsAre(AllOf(token("one_\\\ntoken", tok::raw_identifier),
+hasFlag(LexFlags::StartsPPLine),
+

[PATCH] D119199: replace clang LLVM_ENABLE_PLUGINS -> CLANG_PLUGIN_SUPPORT in tests

2022-02-21 Thread Cristian Adam via Phabricator via cfe-commits
cristian.adam added a comment.

`release/14.x` now configures but fails to build on MSVC2019 with `-D 
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON` like at https://reviews.llvm.org/D00

  FAILED: bin/CTTestTidyModule.dll
  cmd.exe /C "cd . && C:\tools\cmake\bin\cmake.exe -E vs_link_dll 
--intdir=tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir 
--rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe 
--mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests  -- 
C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe
 /nologo 
tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir\clang-tidy\CTTestTidyModule.cpp.obj
  /out:bin\CTTestTidyModule.dll /implib:lib\CTTestTidyModule.lib 
/pdb:bin\CTTestTidyModule.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO  
lib\clang-tidy.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib 
ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
  LINK: command 
"C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe
 /nologo 
tools\clang\tools\extra\test\CMakeFiles\CTTestTidyModule.dir\clang-tidy\CTTestTidyModule.cpp.obj
 /out:bin\CTTestTidyModule.dll /implib:lib\CTTestTidyModule.lib 
/pdb:bin\CTTestTidyModule.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO 
lib\clang-tidy.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib 
ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST 
/MANIFESTFILE:bin\CTTestTidyModule.dll.manifest" failed (exit code 1120) with 
the following output:
  CTTestTidyModule.cpp.obj : error LNK2001: unresolved external symbol "class 
clang::ast_matchers::internal::VariadicDynCastAllOfMatcher const 
clang::ast_matchers::translationUnitDecl" 
(?translationUnitDecl@ast_matchers@clang@@3V?$VariadicDynCastAllOfMatcher@VDecl@clang@@VTranslationUnitDecl@2@@internal@12@B)
  bin\CTTestTidyModule.dll : fatal error LNK1120: 1 unresolved externals


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119199

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-02-21 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D120262: [OpenCL] Handle TypeExtensions in OpenCLBuiltinFileEmitter

2022-02-21 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: Anastasia.
svenvh added a project: clang.
Herald added subscribers: Naghasan, ldrumm, yaxunl.
svenvh requested review of this revision.
Herald added a subscriber: cfe-commits.

Until now, any types that had TypeExtensions attached to them were not
guarded with those extensions.  Extend the OpenCLBuiltinFileEmitter
such that all required extensions are emitted for the types of a
builtin function.

The `clang-tblgen -gen-clang-opencl-builtin-tests` emitter will now
produce e.g.:

  #if defined(cl_khr_fp16) && defined(cl_khr_fp64)
  half8 test11802_convert_half8_rtp(double8 arg1) {
return convert_half8_rtp(arg1);
  }
  #endif // TypeExtension


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120262

Files:
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -17,6 +17,7 @@
 #include "TableGenBackends.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -293,6 +294,14 @@
   // was emitted.
   std::string emitVersionGuard(const Record *Builtin);
 
+  // Emit an #if guard for all type extensions required for the given type
+  // strings.
+  std::string
+  emitTypeExtensionGuards(const SmallVectorImpl );
+
+  // Map type strings to type extensions (e.g. "half2" -> "cl_khr_fp16").
+  StringMap TypeExtMap;
+
   // Contains OpenCL builtin functions and related information, stored as
   // Record instances. They are coming from the associated TableGen file.
   RecordKeeper 
@@ -1057,7 +1066,16 @@
 // Insert the Cartesian product of the types and vector sizes.
 for (const auto  : VectorList) {
   for (const auto  : TypeList) {
-ExpandedArg.push_back(getTypeString(Type, Flags, Vector));
+std::string FullType = getTypeString(Type, Flags, Vector);
+ExpandedArg.push_back(FullType);
+
+// If the type requires an extension, add a TypeExtMap entry mapping
+// the full type name to the extension.
+StringRef Ext =
+Arg->getValueAsDef("Extension")->getValueAsString("ExtName");
+if (!Ext.empty() && TypeExtMap.find(FullType) == TypeExtMap.end()) {
+  TypeExtMap.insert({FullType, Ext});
+}
   }
 }
 NumSignatures = std::max(NumSignatures, ExpandedArg.size());
@@ -1141,6 +1159,41 @@
   return OptionalEndif;
 }
 
+std::string OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
+const SmallVectorImpl ) {
+  std::string OptionalEndif;
+  SmallSet ExtSet;
+
+  // Iterate over all types to gather the set of required TypeExtensions.
+  for (const auto  : Signature) {
+StringRef TypeExt = TypeExtMap.lookup(Ty);
+if (!TypeExt.empty()) {
+  // The TypeExtensions are space-separated in the .td file.
+  SmallVector ExtVec;
+  TypeExt.split(ExtVec, " ");
+  for (const auto Ext : ExtVec) {
+ExtSet.insert(Ext);
+  }
+}
+  }
+
+  // Emit the #if when at least one extension is required.
+  if (!ExtSet.empty()) {
+OS << "#if ";
+bool isFirst = true;
+for (const auto Ext : ExtSet) {
+  if (!isFirst)
+OS << " && ";
+  OS << "defined(" << Ext << ")";
+  isFirst = false;
+}
+OS << "\n";
+OptionalEndif = "#endif // TypeExtension\n";
+  }
+
+  return OptionalEndif;
+}
+
 void OpenCLBuiltinTestEmitter::emit() {
   emitSourceFileHeader("OpenCL Builtin exhaustive testing", OS);
 
@@ -1163,6 +1216,8 @@
 std::string OptionalVersionEndif = emitVersionGuard(B);
 
 for (const auto  : FTypes) {
+  std::string OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);
+
   // Emit function declaration.
   OS << Signature[0] << " test" << TestID++ << "_" << Name << "(";
   if (Signature.size() > 1) {
@@ -1189,6 +1244,7 @@
 
   // End of function body.
   OS << "}\n";
+  OS << OptionalTypeExtEndif;
 }
 
 OS << OptionalVersionEndif;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54141: [clang-tidy] add deduplication support for run-clang-tidy.py

2022-02-21 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth abandoned this revision.
JonasToth added a comment.
Herald added a subscriber: mgehre.

won't happen anymore realistically.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D54141

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


[PATCH] D120160: [Clang] Add `-funstable` flag to enable unstable and experimental features

2022-02-21 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver accepted this revision.
zoecarver added a comment.
This revision is now accepted and ready to land.

This looks great, thanks Egor!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120160

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


[PATCH] D119481: run-clang-tidy: Fix infinite loop on windows

2022-02-21 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth accepted this revision.
JonasToth added a comment.
This revision is now accepted and ready to land.

LGTM with a small nit




Comment at: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py:69
   while not os.path.isfile(os.path.join(result, path)):
-if os.path.realpath(result) == '/':
+parent = os.path.dirname(result)
+if result == parent:

please delete the whitespace at the end of the line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119481

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


[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

D120258  is the followup with inlay hints.

It rearranges some of the code from this patch for reuse, and proposes dropping 
support for multiple instantiations yielding the same result, as this 
inevitably pushes complexity into each place this is used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537

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


[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

2022-02-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: nridge, Trass3r.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This takes a similar approach as b9b6938183e 
, and 
shares some code.
The code sharing is limited as inlay hints wants to deduce the type of the
variable rather than the type of the `auto` per-se.

It drops support (in both places) for multiple instantiations yielding the same
type, as this is pretty rare and hard to build a nice API around.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120258

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp

Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -247,7 +247,7 @@
   Visitor.F = Filter;
   Visitor.TraverseDecl(AST.getASTContext().getTranslationUnitDecl());
   if (Visitor.Decls.size() != 1) {
-llvm::errs() << Visitor.Decls.size() << " symbols matched.";
+llvm::errs() << Visitor.Decls.size() << " symbols matched.\n";
 assert(Visitor.Decls.size() == 1);
   }
   return *Visitor.Decls.front();
Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -676,6 +676,15 @@
   ExpectedHint{": int", "var"});
 }
 
+TEST(TypeHints, SinglyInstantiatedTemplate) {
+  assertTypeHints(R"cpp(
+auto $lambda[[x]] = [](auto *$param[[y]]) { return 42; };
+int m = x("foo");
+  )cpp",
+  ExpectedHint{": (lambda)", "lambda"},
+  ExpectedHint{": const char *", "param"});
+}
+
 TEST(DesignatorHints, Basic) {
   assertDesignatorHints(R"cpp(
 struct S { int x, y, z; };
Index: clang-tools-extra/clangd/unittests/ASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -30,6 +30,7 @@
 namespace {
 using testing::Contains;
 using testing::Each;
+using testing::IsEmpty;
 
 TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
   struct Test {
@@ -192,12 +193,12 @@
   R"cpp(
 // Generic lambda instantiated twice, matching deduction.
 struct Foo{};
-using Bar = Foo;
 auto Generic = [](^auto x, auto y) { return 0; };
-int m = Generic(Bar{}, "one");
+int m = Generic(Foo{}, "one");
 int n = Generic(Foo{}, 2);
   )cpp",
-  "struct Foo",
+  // No deduction although both instantiations yield the same result :-(
+  nullptr,
   },
   {
   R"cpp(
@@ -253,6 +254,119 @@
   }
 }
 
+TEST(ClangdAST, GetOnlyInstantiation) {
+  struct {
+const char *Code;
+llvm::StringLiteral NodeType;
+const char *Name;
+  } Cases[] = {
+  {
+  R"cpp(
+template  class X {};
+X x;
+  )cpp",
+  "CXXRecord",
+  "template<> class X {}",
+  },
+  {
+  R"cpp(
+template  T X = T{};
+int y = X;
+  )cpp",
+  "Var",
+  // VarTemplateSpecializationDecl doesn't print as template<>...
+  "char X = char{}",
+  },
+  {
+  R"cpp(
+template  int X(T) { return 42; }
+int y = X("text");
+  )cpp",
+  "Function",
+  "template<> int X(const char *)",
+  },
+  {
+  R"cpp(
+int X(auto *x) { return 42; }
+int y = X("text");
+  )cpp",
+  "Function",
+  "template<> int X(const char *x)",
+  },
+  };
+
+  for (const auto  : Cases) {
+SCOPED_TRACE(Case.Code);
+auto TU = TestTU::withCode(Case.Code);
+TU.ExtraArgs.push_back("-std=c++20");
+auto AST = TU.build();
+AST.getASTContext().getTranslationUnitDecl()->dump();
+PrintingPolicy PP = AST.getASTContext().getPrintingPolicy();
+PP.TerseOutput = true;
+std::string Name;
+if (auto *Result = getOnlyInstantiation(
+const_cast((AST, [&](const NamedDecl ) {
+  return D.getDescribedTemplate() != nullptr &&
+ D.getDeclKindName() == Case.NodeType;
+} {
+  llvm::raw_string_ostream OS(Name);
+  Result->print(OS, PP);
+}
+
+if (Case.Name)
+  

[PATCH] D118586: [C++20][Modules][3/8] Initial handling for module partitions.

2022-02-21 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 410320.
iains added a comment.

rebased, added a multi-partition testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118586

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.unit/p3.cpp
  clang/test/CXX/module/module.unit/p8.cpp
  clang/test/Modules/cxx20-multiple-partitions.cpp
  clang/test/Modules/cxx20-partition-diagnostics-a.cpp

Index: clang/test/Modules/cxx20-partition-diagnostics-a.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-partition-diagnostics-a.cpp
@@ -0,0 +1,18 @@
+// Module Partition diagnostics
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -D TU=1 -x c++ %s -verify
+
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -D TU=2 -x c++ %s -verify
+
+#if TU == 1
+
+import :B; // expected-error {{module partition imports must be within a module purview}}
+
+#elif TU == 2
+module; // expected-error {{missing 'module' declaration at end of global module fragment introduced here}}
+
+import :Part; // expected-error {{module partition imports cannot be in the global module fragment}}
+
+#else
+#error "no TU set"
+#endif
Index: clang/test/Modules/cxx20-multiple-partitions.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-multiple-partitions.cpp
@@ -0,0 +1,49 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=1 -x c++ %s \
+// RUN:  -o %t/A_part1.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=2 -x c++ %s \
+// RUN:  -o %t/A_part2.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=3 -x c++ %s \
+// RUN:  -o %t/A_part3.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -D TU=4 -x c++ %s \
+// RUN:  -fmodule-file=%t/A_part1.pcm -fmodule-file=%t/A_part2.pcm \
+// RUN:  -fmodule-file=%t/A_part3.pcm -o %t/A.pcm
+
+// expected-no-diagnostics
+
+#if TU == 1
+
+export module A:Part1;
+
+int part1();
+
+#elif TU == 2
+
+export module A:Part2;
+
+int part2();
+
+#elif TU == 3
+
+export module A:Part3;
+
+int part3();
+
+#elif TU == 4
+
+export module A;
+
+import :Part1;
+export import :Part2;
+import :Part3;
+
+int foo();
+
+#else
+#error "no TU set"
+#endif
Index: clang/test/CXX/module/module.unit/p8.cpp
===
--- clang/test/CXX/module/module.unit/p8.cpp
+++ clang/test/CXX/module/module.unit/p8.cpp
@@ -12,7 +12,7 @@
 
 #elif MODE == 1
 // expected-no-diagnostics
-module foo;
+module foo; // Implementation, implicitly imports foo.
 #define IMPORTED
 
 #elif MODE == 2
@@ -21,15 +21,15 @@
 #define IMPORTED
 
 #elif MODE == 3
-export module bar;
+export module bar; // A different module
 
 #elif MODE == 4
-module foo:bar; // expected-error {{not yet supported}}
-#define IMPORTED // FIXME
+module foo:bar; // Partition implementation
+//#define IMPORTED (we don't import foo here)
 
 #elif MODE == 5
-export module foo:bar; // expected-error {{not yet supported}} expected-error {{redefinition}} expected-note@* {{loaded from}}
-#define IMPORTED // FIXME
+export module foo:bar; // Partition interface
+//#define IMPORTED  (we don't import foo here)
 
 #endif
 
Index: clang/test/CXX/module/module.unit/p3.cpp
===
--- clang/test/CXX/module/module.unit/p3.cpp
+++ clang/test/CXX/module/module.unit/p3.cpp
@@ -1,4 +1,4 @@
 // RUN: %clang_cc1 -std=c++2a -verify %s
 
-export module foo:bar; // expected-error {{sorry, module partitions are not yet supported}}
-import :baz; // expected-error {{sorry, module partitions are not yet supported}}
+export module foo:bar;
+import :baz; // expected-error {{module 'foo:baz' not found}}
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -54,6 +54,23 @@
   }
 }
 
+// We represent the primary and partition names as 'Paths' which are sections
+// of the hierarchical access path for a clang module.  However for C++20
+// the periods in a name are just another character, and we will need to
+// flatten them into a string.
+static std::string stringFromPath(ModuleIdPath Path) {
+  std::string Name;
+  if (Path.empty())
+return Name;
+
+  for (auto  : Path) {
+if (!Name.empty())
+  Name += ".";
+Name += Piece.first->getName();
+  }
+  return Name;
+}
+
 Sema::DeclGroupPtrTy
 Sema::ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc) {
   if (!ModuleScopes.empty() &&
@@ -80,11 +97,10 @@
   return nullptr;
 }
 
-Sema::DeclGroupPtrTy 

[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:958
   case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
   case llvm::ARM::ArchKind::ARMV8_8A:

tyb0807 wrote:
> SjoerdMeijer wrote:
> > tyb0807 wrote:
> > > SjoerdMeijer wrote:
> > > > I see tests for the crypto stuff, but is there or do we need a test for 
> > > > whatever `getTargetDefinesARMV83A` is setting?
> > > I'm not sure that we need a test for this, as none of the other 
> > > architectures really have this. What do you think @SjoerdMeijer 
> > > @vhscampos ?
> > I am expecting tests for the ACLE macros that this patch defines for v8.7 
> > to be added to `clang/test/Preprocessor/arm-target-features.c`.
> In that case, for consistency, I think we should also add tests for ACLE 
> macros for other versions (v8.4/5/6/8) as well. And for AArch64 too. It 
> sounds a bit out of scope, but it ensures consistency IMHO
The subject says 

> [ARM][AArch64] Add missing v8.x checks

so looks perfect in scope to me. :)




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

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


[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-21 Thread fonz vermund via Phabricator via cfe-commits
fonzvermund added a comment.

http://webonlinegambling.idea.informer.com/
https://webonlinegambling.com/mobile-casinos/
http://playlegalsportsbetting.idea.informer.com/
http://legalsportsbetting.idea.informer.com/
https://sourceforge.net/u/legalsportsbet/profile
https://www.theodysseyonline.com/user/@legalsportsbet
https://www.question2answer.org/qa/user/legalsportsbet


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 410318.
tianshilei1992 added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_messages.c
  clang/test/OpenMP/atomic_messages.cpp

Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -928,7 +928,7 @@
 }
 
 int mixed() {
-  int a, b = 0;
+  int a, v, b = 0;
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
 // expected-note@+1 {{'read' clause used here}}
 #pragma omp atomic read write
@@ -957,7 +957,7 @@
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'compare' clause}}
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
-  a = b;
+  { v = a; if (a > b) a = b; }
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -500,4 +500,199 @@
   fx = fe;
   }
 }
+
+void compare_capture(void) {
+  int x = 0;
+  int d = 0;
+  int e = 0;
+  int v = 0;
+  int r = 0;
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected compound statement}}
+#pragma omp atomic compare capture
+  if (x == e) {}
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected exactly one expression statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x = d;
+v = x;
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+bbar();
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x += d;
+  }
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' 

[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-21 Thread fonz vermund via Phabricator via cfe-commits
fonzvermund added a comment.

https://njonlinecasinos.webgarden.com/casinos/nj-casino-reviews/tropicana-online-casino
http://playlegalsportsbetting.com/borgata-online-casino-pa/
https://casinowatchnj.com/borgata-online-casino/
https://casinowatchnj.com/betmgm-online-casino/
https://casinowatchpa.com/tropicana-online-casino-pa/
https://casinowatchpa.com/betrivers-casino/
https://casinowatchnj.com/
https://playlegalsportsbetting.com/unibet-betting/
https://legal-sportsbetting.com/draftkings-sportsbook-is-live-in-new-york/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:958
   case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
   case llvm::ARM::ArchKind::ARMV8_8A:

SjoerdMeijer wrote:
> tyb0807 wrote:
> > SjoerdMeijer wrote:
> > > I see tests for the crypto stuff, but is there or do we need a test for 
> > > whatever `getTargetDefinesARMV83A` is setting?
> > I'm not sure that we need a test for this, as none of the other 
> > architectures really have this. What do you think @SjoerdMeijer @vhscampos ?
> I am expecting tests for the ACLE macros that this patch defines for v8.7 to 
> be added to `clang/test/Preprocessor/arm-target-features.c`.
In that case, for consistency, I think we should also add tests for ACLE macros 
for other versions (v8.4/5/6/8) as well. And for AArch64 too. It sounds a bit 
out of scope, but it ensures consistency IMHO


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

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


[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-21 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/lib/Headers/opencl-c-base.h:85
+// Internal feature macro to provide subgroup builtins.
+#define __opencl_subgroup_builtins 1
+#endif

I'm in doubt whether we could just reuse `__opencl_c_subgroups` for this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120254

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


[PATCH] D120252: [Clang][OpenMP] Fix wrong form of 'cond-update-stmt' in atomic_ast_print.cpp

2022-02-21 Thread Shilei Tian 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 rG3a3d9ae54592: [Clang][OpenMP] Fix wrong form of 
cond-update-stmt in atomic_ast_print.cpp (authored by 
tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120252

Files:
  clang/test/OpenMP/atomic_ast_print.cpp

Index: clang/test/OpenMP/atomic_ast_print.cpp
===
--- clang/test/OpenMP/atomic_ast_print.cpp
+++ clang/test/OpenMP/atomic_ast_print.cpp
@@ -47,9 +47,9 @@
 #pragma omp atomic compare
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture
   { v = a == b; if (v) a = c; }
 #endif
@@ -76,9 +76,9 @@
 #pragma omp atomic compare seq_cst
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture seq_cst
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare seq_cst capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture seq_cst
   { v = a == b; if (v) a = c; }
 #endif
@@ -105,9 +105,9 @@
 #pragma omp atomic compare acq_rel
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acq_rel
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acq_rel capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acq_rel
   { v = a == b; if (v) a = c; }
 #endif
@@ -134,9 +134,9 @@
 #pragma omp atomic compare acquire
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acquire
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acquire capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acquire
   { v = a == b; if (v) a = c; }
 #endif
@@ -163,9 +163,9 @@
 #pragma omp atomic compare release
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture release
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare release capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture release
   { v = a == b; if (v) a = c; }
 #endif
@@ -192,9 +192,9 @@
 #pragma omp atomic compare relaxed
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture relaxed
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare relaxed capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture relaxed
   { v = a == b; if (v) a = c; }
 #endif
@@ -221,9 +221,9 @@
 #pragma omp atomic compare hint(6)
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture hint(6)
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare hint(6) capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
 #endif
@@ -261,12 +261,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
@@ -304,12 +308,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture seq_cst
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare seq_cst capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture seq_cst
 // CHECK-51-NEXT: {
@@ -347,12 +355,16 @@
 // CHECK-51-NEXT: #pragma omp atomic compare capture acq_rel
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare acq_rel capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < 

[clang] 3a3d9ae - [Clang][OpenMP] Fix wrong form of 'cond-update-stmt' in atomic_ast_print.cpp

2022-02-21 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-02-21T11:40:09-05:00
New Revision: 3a3d9ae545925162ebbe820639cd2fe072ff4dd8

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

LOG: [Clang][OpenMP] Fix wrong form of 'cond-update-stmt' in 
atomic_ast_print.cpp

In `clang/test/OpenMP/atomic_ast_print.cpp` for `atomic compare capture`,
it was using 'cond-expr-stmt' instead of 'cond-update-stmt'. The spec only 
supports
'cond-update-stmt'.

Reviewed By: ABataev

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

Added: 


Modified: 
clang/test/OpenMP/atomic_ast_print.cpp

Removed: 




diff  --git a/clang/test/OpenMP/atomic_ast_print.cpp 
b/clang/test/OpenMP/atomic_ast_print.cpp
index 7502fdc339c2a..201f62ab2117e 100644
--- a/clang/test/OpenMP/atomic_ast_print.cpp
+++ b/clang/test/OpenMP/atomic_ast_print.cpp
@@ -47,9 +47,9 @@ T foo(T argc) {
 #pragma omp atomic compare
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture
   { v = a == b; if (v) a = c; }
 #endif
@@ -76,9 +76,9 @@ T foo(T argc) {
 #pragma omp atomic compare seq_cst
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture seq_cst
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare seq_cst capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture seq_cst
   { v = a == b; if (v) a = c; }
 #endif
@@ -105,9 +105,9 @@ T foo(T argc) {
 #pragma omp atomic compare acq_rel
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acq_rel
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acq_rel capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acq_rel
   { v = a == b; if (v) a = c; }
 #endif
@@ -134,9 +134,9 @@ T foo(T argc) {
 #pragma omp atomic compare acquire
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture acquire
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare acquire capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture acquire
   { v = a == b; if (v) a = c; }
 #endif
@@ -163,9 +163,9 @@ T foo(T argc) {
 #pragma omp atomic compare release
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture release
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare release capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture release
   { v = a == b; if (v) a = c; }
 #endif
@@ -192,9 +192,9 @@ T foo(T argc) {
 #pragma omp atomic compare relaxed
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture relaxed
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare relaxed capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture relaxed
   { v = a == b; if (v) a = c; }
 #endif
@@ -221,9 +221,9 @@ T foo(T argc) {
 #pragma omp atomic compare hint(6)
   { a = a == b ? c : a; }
 #pragma omp atomic compare capture hint(6)
-  { v = a; a = a > b ? b : a; }
+  { v = a; if (a > b) { a = b; } }
 #pragma omp atomic compare hint(6) capture
-  { v = a; a = a < b ? b : a; }
+  { v = a; if (a < b) { a = b; } }
 #pragma omp atomic compare capture hint(6)
   { v = a == b; if (v) a = c; }
 #endif
@@ -261,12 +261,16 @@ T foo(T argc) {
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare capture
 // CHECK-51-NEXT: {
@@ -304,12 +308,16 @@ T foo(T argc) {
 // CHECK-51-NEXT: #pragma omp atomic compare capture seq_cst
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a > b ? b : a;
+// CHECK-51-NEXT: if (a > b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // CHECK-51-NEXT: #pragma omp atomic compare seq_cst capture
 // CHECK-51-NEXT: {
 // CHECK-51-NEXT: v = a;
-// CHECK-51-NEXT: a = a < b ? b : a;
+// CHECK-51-NEXT: if (a < b) {
+// CHECK-51-NEXT: a = b;
+// CHECK-51-NEXT: }
 // CHECK-51-NEXT: }
 // 

[PATCH] D120254: [OpenCL] Align subgroup builtin guards

2022-02-21 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: azabaznov.
Herald added subscribers: Naghasan, ldrumm, yaxunl.
svenvh requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Until now, subgroup builtins are available with `opencl-c.h` when at
least one of `cl_intel_subgroups`, `cl_khr_subgroups`, or
`__opencl_c_subgroups` is defined.  With `-fdeclare-opencl-builtins`,
subgroup builtins are conditionalized on `cl_khr_subgroups` only.

Align `-fdeclare-opencl-builtins` to `opencl-c.h` by introducing the
internal `__opencl_subgroup_builtins` macro.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120254

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/lib/Headers/opencl-c.h
  clang/lib/Sema/OpenCLBuiltins.td
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER 
-cl-ext=-cl_intel_subgroups
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header 
-cl-ext=-cl_intel_subgroups
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header
@@ -79,6 +79,7 @@
 #define cl_khr_subgroup_non_uniform_arithmetic 1
 #define cl_khr_subgroup_clustered_reduce 1
 #define __opencl_c_read_write_images 1
+#define __opencl_subgroup_builtins 1
 #endif
 
 #if (__OPENCL_CPP_VERSION__ == 100 || __OPENCL_C_VERSION__ == 200)
Index: clang/lib/Sema/OpenCLBuiltins.td
===
--- clang/lib/Sema/OpenCLBuiltins.td
+++ clang/lib/Sema/OpenCLBuiltins.td
@@ -83,7 +83,7 @@
 
 // FunctionExtension definitions.
 def FuncExtNone  : FunctionExtension<"">;
-def FuncExtKhrSubgroups  : 
FunctionExtension<"cl_khr_subgroups">;
+def FuncExtKhrSubgroups  : 
FunctionExtension<"__opencl_subgroup_builtins">;
 def FuncExtKhrSubgroupExtendedTypes  : 
FunctionExtension<"cl_khr_subgroup_extended_types">;
 def FuncExtKhrSubgroupNonUniformVote : 
FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
 def FuncExtKhrSubgroupBallot : 
FunctionExtension<"cl_khr_subgroup_ballot">;
Index: clang/lib/Headers/opencl-c.h
===
--- clang/lib/Headers/opencl-c.h
+++ clang/lib/Headers/opencl-c.h
@@ -16282,7 +16282,7 @@
 
 // OpenCL Extension v2.0 s9.17 - Sub-groups
 
-#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || 
defined(__opencl_c_subgroups)
+#if defined(__opencl_subgroup_builtins)
 // Shared Sub Group Functions
 uint__ovld get_sub_group_size(void);
 uint__ovld get_max_sub_group_size(void);
@@ -16381,7 +16381,7 @@
 double  __ovld __conv sub_group_scan_inclusive_max(double x);
 #endif //cl_khr_fp64
 
-#endif //cl_khr_subgroups cl_intel_subgroups __opencl_c_subgroups
+#endif // __opencl_subgroup_builtins
 
 #if defined(cl_khr_subgroup_extended_types)
 char __ovld __conv sub_group_broadcast( char value, uint index );
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -80,6 +80,11 @@
 #define __opencl_c_named_address_space_builtins 1
 #endif // !defined(__opencl_c_generic_address_space)
 
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || 
defined(__opencl_c_subgroups)
+// Internal feature macro to provide subgroup builtins.
+#define __opencl_subgroup_builtins 1
+#endif
+
 // built-in scalar data types:
 
 /**


Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

[PATCH] D120200: [Clang][OpenMP] Add Sema support for atomic compare capture

2022-02-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 410313.
tianshilei1992 added a comment.

fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120200

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/atomic_messages.c
  clang/test/OpenMP/atomic_messages.cpp

Index: clang/test/OpenMP/atomic_messages.cpp
===
--- clang/test/OpenMP/atomic_messages.cpp
+++ clang/test/OpenMP/atomic_messages.cpp
@@ -928,7 +928,7 @@
 }
 
 int mixed() {
-  int a, b = 0;
+  int a, v, b = 0;
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause}}
 // expected-note@+1 {{'read' clause used here}}
 #pragma omp atomic read write
@@ -957,7 +957,7 @@
 // expected-error@+2 {{directive '#pragma omp atomic' cannot contain more than one 'compare' clause}}
 // expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'capture' clause}}
 #pragma omp atomic compare compare capture capture
-  a = b;
+  { v = a; if (a > b) a = b; }
 #endif
   // expected-note@+1 {{in instantiation of function template specialization 'mixed' requested here}}
   return mixed();
Index: clang/test/OpenMP/atomic_messages.c
===
--- clang/test/OpenMP/atomic_messages.c
+++ clang/test/OpenMP/atomic_messages.c
@@ -500,4 +500,199 @@
   fx = fe;
   }
 }
+
+void compare_capture(void) {
+  int x = 0;
+  int d = 0;
+  int e = 0;
+  int v = 0;
+  int r = 0;
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected compound statement}}
+#pragma omp atomic compare capture
+  if (x == e) {}
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+2 {{expected exactly one expression statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x = d;
+v = x;
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+bbar();
+  }
+// omp51-error@+4 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'.}}
+// omp51-note@+3 {{expected assignment statement}}
+#pragma omp atomic compare capture
+  if (x == e) {
+x += d;
+  }
+// omp51-error@+3 {{the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 

[PATCH] D116153: [ARM][AArch64] Add missing v8.x checks

2022-02-21 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/lib/Basic/Targets/ARM.cpp:958
   case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
   case llvm::ARM::ArchKind::ARMV8_8A:

tyb0807 wrote:
> SjoerdMeijer wrote:
> > I see tests for the crypto stuff, but is there or do we need a test for 
> > whatever `getTargetDefinesARMV83A` is setting?
> I'm not sure that we need a test for this, as none of the other architectures 
> really have this. What do you think @SjoerdMeijer @vhscampos ?
I am expecting tests for the ACLE macros that this patch defines for v8.7 to be 
added to `clang/test/Preprocessor/arm-target-features.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116153

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


  1   2   >