[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2021-11-10 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: rsmith, aaron.ballman, erichkeane, urnathan, 
hubert.reinterpretcast.
ChuanqiXu added a project: clang.
Herald added a subscriber: dexonsmith.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

This fixes: https://bugs.llvm.org/show_bug.cgi?id=52281 and 
https://godbolt.org/z/81f3ocjfW.

This patch introduces a new kind of `ModuleOwnershipKind` as 
`ReachableWhenImported`. This intended the status for reachable described at: 
https://eel.is/c++draft/module.reach#3.

Note that this patch is not intended to support all semantics about reachable 
semantics.

An important feature not included in this patch is discarding declaration in 
global module fragment. See https://eel.is/c++draft/module.global.frag#3 and 
https://eel.is/c++draft/module.global.frag#4. This feature is important since 
it would cut off many unused declarations so that user could import a large 
module without worrying it would be too heavy. And I think this is related to 
the bug https://bugs.llvm.org/show_bug.cgi?id=52342 mentioned @rsmith .

But after all, I think it is not easy to implement in one shot. So this patch 
didn't contain that feature. In other words, now all the declarations in the 
global module fragment are reachable even they could be reduced. But this is 
not worse than the current situation. So I think it may not be unacceptable.

Test Plan: check-all and https://godbolt.org/z/81f3ocjfW.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113545

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/CXX/module/module.interface/p2.cpp
  clang/test/CXX/module/module.reach/Inputs/p5-A.cppm
  clang/test/CXX/module/module.reach/p5.cpp
  clang/test/Modules/Inputs/Reachability-Private/Private.cppm
  clang/test/Modules/Inputs/Reachability-func-default-arg/func_default_arg.cppm
  clang/test/Modules/Inputs/Reachability-func-ret/func_ret.cppm
  
clang/test/Modules/Inputs/Reachability-template-default-arg/template_default_arg.cppm
  clang/test/Modules/Inputs/Reachability-using-templates/mod-templates.cppm
  clang/test/Modules/Inputs/Reachability-using/mod.cppm
  clang/test/Modules/Reachability-Private.cpp
  clang/test/Modules/Reachability-func-default-arg.cpp
  clang/test/Modules/Reachability-func-ret.cpp
  clang/test/Modules/Reachability-template-default-arg.cpp
  clang/test/Modules/Reachability-using-templates.cpp
  clang/test/Modules/Reachability-using.cpp
  clang/test/SemaCXX/compare-modules-cxx2a.cpp

Index: clang/test/SemaCXX/compare-modules-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-modules-cxx2a.cpp
+++ clang/test/SemaCXX/compare-modules-cxx2a.cpp
@@ -1,3 +1,4 @@
+// This tests the unused declaration in global module fragment should be discarded.
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -I%S/Inputs %s -fno-modules-error-recovery
 
 #pragma clang module build compare
Index: clang/test/Modules/Reachability-using.cpp
===
--- /dev/null
+++ clang/test/Modules/Reachability-using.cpp
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/Reachability-using/mod.cppm --precompile -o %t/mod.pcm
+// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -c
+// expected-no-diagnostics
+import mod;
+void foo() {
+  u v{};
+}
Index: clang/test/Modules/Reachability-using-templates.cpp
===
--- /dev/null
+++ clang/test/Modules/Reachability-using-templates.cpp
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/Reachability-using-templates/mod-templates.cppm --precompile -o %t/mod.templates.pcm
+// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -c
+// expected-no-diagnostics
+import mod.templates;
+void foo() {
+  u v{};
+}
Index: clang/test/Modules/Reachability-template-default-arg.cpp
===
--- /dev/null
+++ clang/test/Modules/Reachability-template-default-arg.cpp
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/Reachability-template-default-arg/template_default_arg.cppm --precompile -o %t/template_default_arg.pcm
+// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -c -Xclang -verify
+
+import template_default_arg;
+void bar() {
+  A<> a0;
+  A a1; // expected-error {{declaration of 't' must 

[PATCH] D112941: [clang] Add support for the new pointer authentication builtins.

2021-11-10 Thread Kristof Beyls via Phabricator via cfe-commits
kristof.beyls added inline comments.



Comment at: clang/include/clang/Driver/Options.td:2865-2872
+let Group = f_Group in {
+  let Flags = [CC1Option] in {
+def fptrauth_intrinsics : Flag<["-"], "fptrauth-intrinsics">,
+  HelpText<"Enable pointer-authentication intrinsics">;
+  }
+  def fno_ptrauth_intrinsics : Flag<["-"], "fno-ptrauth-intrinsics">;
+}

bruno wrote:
> ab wrote:
> > rjmccall wrote:
> > > kristof.beyls wrote:
> > > > My impression is that generally for `__builtin_XXX` intrinsics, there 
> > > > are no compiler flags to make them available or remove their 
> > > > availability.
> > > > Is there a good reason why a command line option is needed for the 
> > > > `__builtin_ptrauth` intrinsics, but not (IIUC) for most or any other 
> > > > existing `__builtin_XXX` intrinsic?
> > > > If there is no good reason, it seems better to me to not have a command 
> > > > line option so there is better consistency across all `__builtin_XXX` 
> > > > intrinsics?
> > > > 
> > > > (after having read more of the patch): my impression has changed now 
> > > > that the f(no-)ptrauth-intrinsics flag rather selects whether the 
> > > > ptrauth intrinsics get lowered to PAuth hardware instructions, or to 
> > > > "regular" instructions emulating the behavior of authenticated 
> > > > pointers. If that is correct (and assuming it's a useful option to 
> > > > have), I would guess a different name for the command line option could 
> > > > be less misleading. As is, it suggests this selects whether ptrauth_ 
> > > > intrinsics are available or not. If instead, as I'm guessing above, 
> > > > this selects whether ptrauth_ intrinsics get lowered to PAuth 
> > > > instructions or not, maybe something like '-femulate-ptrauth' would 
> > > > describe the effect of the command line switch a bit better?
> > > The ptrauth features were implemented gradually, beginning with the 
> > > intrinsics.  Originally we needed a way to enable the intrinsics feature 
> > > without relying on target information.  We do still need a way to enable 
> > > them without necessarily enabling automatic type/qualifier-based pointer 
> > > authentication.  I don't know if we need to be able to *disable* them 
> > > when the target supports them; I agree that that would be a little 
> > > strange.
> > > 
> > > If not, we could just enable the intrinsics whenever either the target 
> > > says they're okay or software emulation (a separate, experimental 
> > > feature) is enabled.  The AArch64 target has a `+pauth` target feature.  
> > > However, I don't know if `-arch arm64e` actually adds that feature on 
> > > Apple targets.  Also, the `HasPAuth` field in the clang `TargetInfo` does 
> > > not appear to be properly initialized to `false` when `+pauth` *isn't* 
> > > present; fortunately, that field never used.
> > > 
> > > I'm not sure if it would actually be okay to remove the 
> > > `-fptrauth-intrinsics` driver option if we just enabled the intrinsics 
> > > based on the target feature.  That does feel cleaner, but unfortunately, 
> > > we at Apple probably have explicit uses of the option that we'd have to 
> > > clean up before we could remove the option.  We could treat that as an 
> > > Apple problem and keep it out of the open source tree, though, and maybe 
> > > remove the option altogether someday.
> > > 
> > > Ahmed, thoughts?
> > Hmm, I agree it would be strange to need to disable the intrinsics, but we 
> > do also gate the various higher-level qualifiers (and intrinsics) on 
> > `ptrauth_intrinsics`.  So, in `ptrauth.h` (and in various users) the 
> > feature now really means "we're in a 'ptrauth-aware' environment".  And it 
> > does make more sense to keep that separate from "we're running on a CPU 
> > that theoretically could support ptrauth".  It comes down to what 
> > "ptrauth-aware" really means, and that's probably also an Apple problem, 
> > and all current users of `ptrauth_intrinsics` should use something like 
> > `__arm64e__` instead.
> > 
> > That still means there's no equivalent for other targets and/or software 
> > emulation, but that seems okay: `ptrauth.h` already needs changes to be 
> > usable from anywhere other than arm64e (cf. the discussion about keys), and 
> > we can cross that bridge when we get there.
> > 
> > (One could argue that all the language-feature-specific qualifiers and 
> > intrinsics should be gated on the appropriate ptrauth_whatever feature, but 
> > the qualifiers are often used in precisely the glue/runtime code that 
> > doesn't build in the appropriate mode, so doesn't have the feature enabled.)
> > 
> > 
> > So, concretely, we could:
> > - continue gating these plain intrinsics on `ptrauth_intrinsics` in 
> > ptrauth.h (IIRC there's an ACLE feature macro but it's specific to return 
> > address signing and BTI defaults; I'll check)
> > - enable the feature when `+pauth`
> > - replace all other uses of `ptrauth_intrinsics` with `__arm64e__

[clang-tools-extra] 164ee45 - [NFC][clang-tidy] Fixup documentation file names for 'readability-container-data-pointer'

2021-11-10 Thread via cfe-commits

Author: Whisperity
Date: 2021-11-10T10:25:54+01:00
New Revision: 164ee457a04daf727ead99b43ad490ea05523652

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

LOG: [NFC][clang-tidy] Fixup documentation file names for 
'readability-container-data-pointer'

Added: 

clang-tools-extra/docs/clang-tidy/checks/readability-container-data-pointer.rst

Modified: 
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 
clang-tools-extra/docs/clang-tidy/checks/readability-data-pointer.rst



diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0019f574802f..b73ea44a82bf 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -95,20 +95,22 @@ New checks
   Finds virtual classes whose destructor is neither public and virtual nor
   protected and non-virtual.
 
-- New :doc:`readability-identifier-length
-  ` check.
+- New :doc:`misc-misleading-identifier 
` check.
 
-  Reports identifiers whose names are too short. Currently checks local
-  variables and function parameters only.
+  Reports identifier with unicode right-to-left characters.
 
-- New :doc:`readability-data-pointer 
` check.
+- New :doc:`readability-container-data-pointer
+  ` check.
 
   Finds cases where code could use ``data()`` rather than the address of the
   element at index 0 in a container.
 
-- New :doc:`misc-misleading-identifier 
` check.
+- New :doc:`readability-identifier-length
+  ` check.
+
+  Reports identifiers whose names are too short. Currently checks local
+  variables and function parameters only.
 
-  Reports identifier with unicode right-to-left characters.
 
 New check aliases
 ^

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 80a9639c2ddd..a99dd310bb01 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -288,6 +288,7 @@ Clang-Tidy Checks
`readability-avoid-const-params-in-decls 
`_,
`readability-braces-around-statements 
`_, "Yes"
`readability-const-return-type `_, "Yes"
+   `readability-container-data-pointer 
`_, "Yes"
`readability-container-size-empty 
`_, "Yes"
`readability-convert-member-functions-to-static 
`_,
`readability-delete-null-pointer `_, 
"Yes"

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability-data-pointer.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability-container-data-pointer.rst
similarity index 77%
rename from 
clang-tools-extra/docs/clang-tidy/checks/readability-data-pointer.rst
rename to 
clang-tools-extra/docs/clang-tidy/checks/readability-container-data-pointer.rst
index 4855e4b42b43..fc5d0a5ec747 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability-data-pointer.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability-container-data-pointer.rst
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - readability-data-pointer
+.. title:: clang-tidy - readability-container-data-pointer
 
-readability-data-pointer
-
+readability-container-data-pointer
+==
 
 Finds cases where code could use ``data()`` rather than the address of the
 element at index 0 in a container. This pattern is commonly used to materialize



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


[PATCH] D108893: clang-tidy: introduce readability-containter-data-pointer check

2021-11-10 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D108893#3118389 , @whisperity 
wrote:

> In D108893#3111674 , @steakhal 
> wrote:
>
>> It seems like the checker is documented as `readability-data-pointer` but in 
>> the tests it reports issues under the `readability-container-data-pointer` 
>> name.
>> Shouldn't they be the same? I think it will confuse the users.
>
> Sounds like a typo or an intermittent rebase or rename missing something. 
> Definitely should be consistent.

@steakhal Fixed in rG164ee457a04daf727ead99b43ad490ea05523652 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108893

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


[PATCH] D113256: [AArch64][ARM] Enablement of Cortex-A710 Support

2021-11-10 Thread Dave Green via Phabricator via cfe-commits
dmgreen added inline comments.



Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:181
+  AArch64::AEK_SVE2BITPERM | AArch64::AEK_BF16))
 AARCH64_CPU_NAME("cortex-a78c", ARMV8_2A, FK_CRYPTO_NEON_FP_ARMV8, false,
  (AArch64::AEK_FP16 | AArch64::AEK_DOTPROD | AArch64::AEK_RCPC 
|

I would go after this, it being a a78-like cpu it's probably worth keeping the 
two together.



Comment at: llvm/include/llvm/Support/AArch64TargetParser.def:159-160
   AArch64::AEK_RCPC | AArch64::AEK_SSBS))
+AARCH64_CPU_NAME("cortex-a710", ARMV9A, FK_NEON_FP_ARMV8, false,
+ (AArch64::AEK_MTE | AArch64::AEK_PAUTH | AArch64::AEK_FLAGM |
+  AArch64::AEK_SB | AArch64::AEK_I8MM | AArch64::AEK_FP16FML |

dmgreen wrote:
> lenary wrote:
> > dmgreen wrote:
> > > Natural order would be better I think, where the new A710 is added after 
> > > the A78.
> > > 
> > > FlagM should already be included as a part of 8.4, so isn't needed here.
> > > Should BFloat16 be added?
> > > FlagM should already be included as a part of 8.4, so isn't needed here.
> > 
> > FlagM is not part of the `AARCH64_ARCH("armv9-a", ARMV9A ...)`  definition, 
> > nor part of the equivalents for armv8.4a and armv8.5a, so it was added 
> > explicitly here.
> > 
> > > Should BFloat16 be added?
> > 
> > Yes
> > 
> > 
> > 
> FeatureFlagM is included in HasV8_4aOps. So should already be included (much 
> like something like dotprod).
> 
> Why AEK_FLAGM isn't part of ARMV8_4A I don't know. And why we have two maps 
> for the same set of information...
I think that AEK_FLAGM should be included in architecture that is 8.4+. Then it 
shouldn't be needed here.
Perhaps lets do that as a separate commit though.



Comment at: llvm/include/llvm/Support/ARMTargetParser.def:315
+  ARM::AEK_I8MM))
 ARM_CPU_NAME("cortex-a78c", ARMV8_2A, FK_CRYPTO_NEON_FP_ARMV8, false,
  ARM::AEK_FP16 | ARM::AEK_DOTPROD)

Ditto and same in other places.



Comment at: llvm/lib/Target/AArch64/AArch64Subtarget.cpp:87
 PrefFunctionLogAlignment = 4;
-VScaleForTuning = 1;
 break;

Make sure you keep this in. It looks like it might have been removed by 
accident.



Comment at: llvm/unittests/Support/TargetParserTest.cpp:278
  "8-A"),
+ARMCPUTestParams("cortex-a710", "armv9-a", "neon-fp-armv8",
+ ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |

Ordering.


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

https://reviews.llvm.org/D113256

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


[clang] 2a48b69 - [IR] In ConstantFoldShuffleVectorInstruction use zeroinitializer for splats of 0

2021-11-10 Thread David Sherwood via cfe-commits

Author: David Sherwood
Date: 2021-11-10T09:42:58Z
New Revision: 2a48b6993a973e0ab2331e8c11dbd6e6100e2cfe

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

LOG: [IR] In ConstantFoldShuffleVectorInstruction use zeroinitializer for 
splats of 0

When creating a splat of 0 for scalable vectors we tend to create them
with using a combination of shufflevector and insertelement, i.e.

shufflevector ( insertelement ( poison, i32 
0, i32 0),
poison,  zeroinitializer)

However, for the case of a zero splat we can actually just replace the
above with zeroinitializer instead. This makes the IR a lot simpler and
easier to read. I have changed ConstantFoldShuffleVectorInstruction to
use zeroinitializer when creating a splat of integer 0 or FP +0.0 values.

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

Added: 


Modified: 
clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
llvm/lib/IR/ConstantFold.cpp
llvm/test/Bitcode/vscale-round-trip.ll
llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-basic-vec.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-select-cmp.ll
llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
llvm/test/Transforms/LoopVectorize/scalable-inductions.ll
llvm/test/Transforms/LoopVectorize/scalable-reduction-inloop.ll

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c 
b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
index 3c13080e14f70..1cd9ef1f1a277 100644
--- a/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
+++ b/clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
@@ -568,7 +568,7 @@ svfloat64_t test_svdupq_n_f64(float64_t x0, float64_t x1)
 // CHECK-NEXT:[[TMP16:%.*]] = call  
@llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
 // CHECK-NEXT:[[TMP17:%.*]] = call  
@llvm.experimental.vector.insert.nxv16i8.v16i8( undef, <16 x 
i8> [[TMP15]], i64 0)
 // CHECK-NEXT:[[TMP18:%.*]] = call  
@llvm.aarch64.sve.dupq.lane.nxv16i8( [[TMP17]], i64 0)
-// CHECK-NEXT:[[TMP19:%.*]] = call  
@llvm.aarch64.sve.cmpne.wide.nxv16i8( [[TMP16]],  [[TMP18]],  shufflevector ( 
insertelement ( poison, i64 0, i32 0),  
poison,  zeroinitializer))
+// CHECK-NEXT:[[TMP19:%.*]] = call  
@llvm.aarch64.sve.cmpne.wide.nxv16i8( [[TMP16]],  [[TMP18]],  zeroinitializer)
 // CHECK-NEXT:ret  [[TMP19]]
 //
 // CPP-CHECK-LABEL: @_Z16test_svdupq_n_b8(
@@ -608,7 +608,7 @@ svfloat64_t test_svdupq_n_f64(float64_t x0, float64_t x1)
 // CPP-CHECK-NEXT:[[TMP16:%.*]] = call  
@llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
 // CPP-CHECK-NEXT:[[TMP17:%.*]] = call  
@llvm.experimental.vector.insert.nxv16i8.v16i8( undef, <16 x 
i8> [[TMP15]], i64 0)
 // CPP-CHECK-NEXT:[[TMP18:%.*]] = call  
@llvm.aarch64.sve.dupq.lane.nxv16i8( [[TMP17]], i64 0)
-// CPP-CHECK-NEXT:[[TMP19:%.*]] = call  
@llvm.aarch64.sve.cmpne.wide.nxv16i8( [[TMP16]],  [[TMP18]],  shufflevector ( 
insertelement ( poison, i64 0, i32 0),  
poison,  zeroinitializer))
+// CPP-CHECK-NEXT:[[TMP19:%.*]] = call  
@llvm.aarch64.sve.cmpne.wide.nxv16i8( [[TMP16]],  [[TMP18]],  zeroinitializer)
 // CPP-CHECK-NEXT:ret  [[TMP19]]
 //
 svbool_t test_svdupq_n_b8(bool x0, bool x1, bool x2, bool x3,
@@ -641,7 +641,7 @@ svbool_t test_svdupq_n_b8(bool x0, bool x1, bool x2, bool 
x3,
 // CHECK-NEXT:[[TMP16:%.*]] = call  
@llvm.aarch64.sve.ptrue.nxv8i1(i32 31)
 // CHECK-NEXT:[[TMP17:%.*]] = call  
@llvm.experimental.vector.insert.nxv8i16.v8i16( undef, <8 x 
i16> [[TMP15]], i64 0)
 // CHECK-NEXT:[[TMP18:%.*]] = call  
@llvm.aarch64.sve.dupq.lane.nxv8i16( [[TMP17]], i64 0)
-// CHECK-NEXT:[[TMP19:%.*]] = call  
@llvm.aarch64.sve.cmpne.wide.nxv8i16( [[TMP16]],  [[TMP18]],  shufflevector ( 
insertelement ( poison, i64 0, i32 0),  
poison,  zeroinitializer))
+// CHECK-NEXT:[[TMP19:%.*]] = call  
@llvm.aarch64.sve.cmpne.wide.nxv8i16( [[TMP16]],  [[TMP18]],  zeroinitializer)
 // CHECK-NEXT:[[TMP20:%.*]] = call  
@llvm.aarch64.sve.convert.to.svbool.nxv8i1( [[TMP19]])
 // CHECK-NEXT:ret  [[TMP20]]
 //
@@ -666,7 +666,7 @@ svbool_t test_svdupq_n_b8(bool x0, bool x1, bool x2, bool 
x3,
 // CPP-CHECK-NEXT:[[TMP16:%.*]] = call  
@llvm.aarch64.sve.ptrue.nxv8i1(i32 31)
 // CPP-CHECK-NEXT:[[TMP17:%.*]] = call  
@llvm.experimental.vector.insert.nxv8i16.v8i16( undef, <8 x 
i16> [[TMP15]], i64 0)
 // CPP-CHECK-NEXT:[[TMP18:%.*]] = call  
@llvm.aarch64.sve.dupq.lane.nxv8i16( [[TMP17]], i64 0)
-// CPP-CHECK-NEXT:[[TMP19:%.*]] = call  
@llvm.aarch64.sve.cmpne.wide.nxv8i16( [[TMP16]],  [[TM

[PATCH] D113394: [IR] In ConstantFoldShuffleVectorInstruction use zeroinitializer for splats of 0

2021-11-10 Thread David Sherwood via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
david-arm marked an inline comment as done.
Closed by commit rG2a48b6993a97: [IR] In ConstantFoldShuffleVectorInstruction 
use zeroinitializer for splats of 0 (authored by david-arm).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D113394?vs=385764&id=386094#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113394

Files:
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  llvm/lib/IR/ConstantFold.cpp
  llvm/test/Bitcode/vscale-round-trip.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-basic-vec.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-select-cmp.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
  llvm/test/Transforms/LoopVectorize/scalable-inductions.ll
  llvm/test/Transforms/LoopVectorize/scalable-reduction-inloop.ll

Index: llvm/test/Transforms/LoopVectorize/scalable-reduction-inloop.ll
===
--- llvm/test/Transforms/LoopVectorize/scalable-reduction-inloop.ll
+++ llvm/test/Transforms/LoopVectorize/scalable-reduction-inloop.ll
@@ -7,8 +7,8 @@
 ; CHECK-LABEL: @reduction_add_trunc(
 ; CHECK:   vector.body:
 ; CHECK-NEXT:[[INDEX:%.*]] = phi i32 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
-; CHECK-NEXT:[[VEC_PHI:%.*]] = phi  [ insertelement ( shufflevector ( insertelement ( poison, i32 0, i32 0),  poison,  zeroinitializer), i32 255, i32 0), %vector.ph ], [ [[TMP34:%.*]], %vector.body ]
-; CHECK-NEXT:[[VEC_PHI1:%.*]] = phi  [ shufflevector ( insertelement ( poison, i32 0, i32 0),  poison,  zeroinitializer), %vector.ph ], [ [[TMP36:%.*]], %vector.body ]
+; CHECK-NEXT:[[VEC_PHI:%.*]] = phi  [ insertelement ( zeroinitializer, i32 255, i32 0), %vector.ph ], [ [[TMP34:%.*]], %vector.body ]
+; CHECK-NEXT:[[VEC_PHI1:%.*]] = phi  [ zeroinitializer, %vector.ph ], [ [[TMP36:%.*]], %vector.body ]
 ; CHECK: [[TMP14:%.*]] = and  [[VEC_PHI]], shufflevector ( insertelement ( poison, i32 255, i32 0),  poison,  zeroinitializer)
 ; CHECK-NEXT:[[TMP15:%.*]] = and  [[VEC_PHI1]], shufflevector ( insertelement ( poison, i32 255, i32 0),  poison,  zeroinitializer)
 ; CHECK: [[WIDE_LOAD:%.*]] = load , *
Index: llvm/test/Transforms/LoopVectorize/scalable-inductions.ll
===
--- llvm/test/Transforms/LoopVectorize/scalable-inductions.ll
+++ llvm/test/Transforms/LoopVectorize/scalable-inductions.ll
@@ -143,7 +143,7 @@
 ; CHECK:  %[[STEPVEC:.*]] = call  @llvm.experimental.stepvector.nxv4i32()
 ; CHECK-NEXT: %[[TMP1:.*]] = uitofp  %[[STEPVEC]] to 
 ; CHECK-NEXT: %[[TMP2:.*]] = fmul  %[[TMP1]], shufflevector ( insertelement ( poison, float 2.00e+00, i32 0),  poison,  zeroinitializer)
-; CHECK-NEXT: %[[INDINIT:.*]] = fadd  %[[TMP2]], shufflevector ( insertelement ( poison, float 0.00e+00, i32 0),  poison,  zeroinitializer)
+; CHECK-NEXT: %[[INDINIT:.*]] = fadd  %[[TMP2]], zeroinitializer
 ; CHECK-NEXT: %[[VSCALE:.*]] = call i32 @llvm.vscale.i32()
 ; CHECK-NEXT: %[[TMP3:.*]] = shl i32 %8, 2
 ; CHECK-NEXT: %[[TMP4:.*]] = uitofp i32 %[[TMP3]] to float
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
@@ -47,7 +47,7 @@
 ; CHECK-NEXT:[[TMP6:%.*]] = call  @llvm.experimental.stepvector.nxv2i64()
 ; CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement  poison, i64 [[INDEX]], i32 0
 ; CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector  [[DOTSPLATINSERT]],  poison,  zeroinitializer
-; CHECK-NEXT:[[TMP7:%.*]] = add  shufflevector ( insertelement ( poison, i64 0, i32 0),  poison,  zeroinitializer), [[TMP6]]
+; CHECK-NEXT:[[TMP7:%.*]] = add  zeroinitializer, [[TMP6]]
 ; CHECK-NEXT:[[TMP8:%.*]] = add  [[DOTSPLAT]], [[TMP7]]
 ; CHECK-NEXT:[[NEXT_GEP4:%.*]] = getelementptr i8, i8* [[START_2]],  [[TMP8]]
 ; CHECK-NEXT:[[TMP9:%.*]] = add i64 [[INDEX]], 0
@@ -126,7 +126,7 @@
 ; CHECK-NEXT:[[TMP5:%.*]] = call  @llvm.experimental.stepvector.nxv2i64()
 ; CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement  poison, i64 [[INDEX1]], i32 0
 ; CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector  [[DOTSPLATINSERT]],  poison,  zeroinitializer
-; CHECK-NEXT:[[TMP6:%.*]] = add  shufflevector ( insertelement ( poison, i64 0, i32 0),  poison,  zeroinitializer), [[TMP5]]
+; CHECK-NEXT:[[TMP6:%.*]] = add  zeroinitializer, [[TMP5]]
 ; CHECK-NEXT:[[TMP7:%.*]] = add  [[DOTSPLAT]

[PATCH] D112663: [clang-repl] Allow Interpreter::getSymbolAddress to take a mangled name.

2021-11-10 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 386098.
v.g.vassilev marked 4 inline comments as done.
v.g.vassilev added a comment.

Address comments and fix the windows bot failure.


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

https://reviews.llvm.org/D112663

Files:
  clang/include/clang/CodeGen/ModuleBuilder.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -14,8 +14,13 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+
+#include "llvm/Support/TargetSelect.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -123,4 +128,116 @@
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 }
 
+static std::string MangleName(NamedDecl *ND) {
+  ASTContext &C = ND->getASTContext();
+  std::unique_ptr MangleC(C.createMangleContext());
+  std::string mangledName;
+  llvm::raw_string_ostream RawStr(mangledName);
+  MangleC->mangleName(ND, RawStr);
+  return RawStr.str();
+}
+
+struct LLVMInitRAII {
+  LLVMInitRAII() {
+llvm::InitializeNativeTarget();
+llvm::InitializeNativeTargetAsmPrinter();
+  }
+  ~LLVMInitRAII() { llvm::llvm_shutdown(); }
+} LLVMInit;
+
+TEST(IncrementalProcessing, FindMangledNameSymbol) {
+
+  std::unique_ptr Interp = createInterpreter();
+
+  auto &PTU(cantFail(Interp->Parse("int f(const char*) {return 0;}")));
+  EXPECT_EQ(1U, DeclsSize(PTU.TUPart));
+  auto R1DeclRange = PTU.TUPart->decls();
+
+  NamedDecl *FD = cast(*R1DeclRange.begin());
+  // Lower the PTU
+  if (llvm::Error Err = Interp->Execute(PTU)) {
+// We cannot execute on the platform.
+consumeError(std::move(Err));
+return;
+  }
+
+  std::string MangledName = MangleName(FD);
+  auto Addr = cantFail(Interp->getSymbolAddress(MangledName));
+  EXPECT_NE(0U, Addr);
+  GlobalDecl GD(FD);
+  EXPECT_EQ(Addr, cantFail(Interp->getSymbolAddress(GD)));
+}
+
+static void *AllocateObject(TypeDecl *TD, Interpreter &Interp) {
+  std::string Name = TD->getQualifiedNameAsString();
+  const clang::Type *RDTy = TD->getTypeForDecl();
+  clang::ASTContext &C = Interp.getCompilerInstance()->getASTContext();
+  size_t Size = C.getTypeSize(RDTy);
+  void *Addr = malloc(Size);
+
+  // Tell the interpreter to call the default ctor with this memory. Synthesize:
+  // new (loc) ClassName;
+  static unsigned Counter = 0;
+  std::stringstream SS;
+  SS << "auto _v" << Counter++ << " = "
+ << "new ((void*)"
+ // Windows needs us to prefix the hexadecimal value of a pointer with '0x'.
+ << std::hex << std::showbase << (size_t)Addr << ")" << Name << "();";
+
+  auto R = Interp.ParseAndExecute(SS.str());
+  if (!R)
+return nullptr;
+
+  return Addr;
+}
+
+static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) {
+  Sema &SemaRef = Interp.getCompilerInstance()->getSema();
+  ASTContext &C = SemaRef.getASTContext();
+  DeclarationName DeclName = &C.Idents.get(Name);
+  LookupResult R(SemaRef, DeclName, SourceLocation(), Sema::LookupOrdinaryName);
+  SemaRef.LookupName(R, SemaRef.TUScope);
+  assert(!R.empty());
+  return R.getFoundDecl();
+}
+
+TEST(IncrementalProcessing, InstantiateTemplate) {
+  // FIXME: We cannot yet handle delayed template parsing. If we run with
+  // -fdelayed-template-parsing we try adding the newly created decl to the
+  // active PTU which causes an assert.
+  std::vector Args = {"-fno-delayed-template-parsing"};
+  std::unique_ptr Interp = createInterpreter(Args);
+
+  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
+   "extern \"C\" int printf(const char*,...);"
+   "class A {};"
+   "struct B {"
+   "  template"
+   "  int callme(T) { return 42; }"
+   "};"));
+  auto &PTU = llvm::cantFail(Interp->Parse("auto _t = &B::callme;"));
+  auto PTUDeclRange = PTU.TUPart->decls();
+  EXPECT_EQ(1, std::distance(PTUDeclRange.begin(), PTUDeclRange.end()));
+
+  // Lower the PTU
+  if (llvm::Error Err = Interp->Execute(PTU)) {
+// We cannot execute on the platform.
+consumeError(std::move(Err));
+return;
+  }
+
+  TypeDecl *TD = cast(LookupSingleName(*Interp, "A"));
+  voi

[PATCH] D112663: [clang-repl] Allow Interpreter::getSymbolAddress to take a mangled name.

2021-11-10 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/unittests/Interpreter/IncrementalProcessingTest.cpp:20
 #include "clang/Sema/Sema.h"
+#include "clang/Sema/TemplateDeduction.h"
 #include "llvm/ADT/Triple.h"

rsmith wrote:
> Given that this file is unchanged, do we need the new includes?
A leftover from some other experiments. Thanks!


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

https://reviews.llvm.org/D112663

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


[PATCH] D110833: [clang-format] Refactor SpaceBeforeParens to add options

2021-11-10 Thread C. Rayroud via Phabricator via cfe-commits
crayroud closed this revision.
crayroud added a comment.

git revision: 6facafe7da59eb02e8c1519670b503efda2f4b58 



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

https://reviews.llvm.org/D110833

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


[PATCH] D113555: [clangd] Mark macros from preamble for code completion

2021-11-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: usaxena95, nridge.
Herald added a subscriber: arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

If the main file is a header, mark the marcos defined in its preamble
section as code-completion ready.

Fixes https://github.com/clangd/clangd/issues/921.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113555

Files:
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp


Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -727,6 +727,19 @@
   EXPECT_THAT(MT.child("f3").children(), ElementsAre(Pair("relations", _)));
   EXPECT_THAT(MT.child("f3").total(), Gt(0U));
 }
+
+TEST(FileIndexTest, MacrosFromMainFile) {
+  FileIndex Idx;
+  TestTU TU;
+  TU.Code = "#pragma once\n#define FOO";
+  TU.Filename = "foo.h";
+  auto AST = TU.build();
+  Idx.updateMain(testPath(TU.Filename), AST);
+
+  auto &FooSymbol = findSymbol(runFuzzyFind(Idx, ""), "FOO");
+  EXPECT_TRUE(FooSymbol.Flags & Symbol::IndexedForCodeCompletion);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -564,6 +564,10 @@
 S.SymInfo.Lang = index::SymbolLanguage::C;
 S.Origin = Opts.Origin;
 S.CanonicalDeclaration = R.Location;
+if (!HeaderFileURIs->getIncludeHeader(SM.getMainFileID()).empty()) {
+  S.Flags |= Symbol::IndexedForCodeCompletion;
+  S.Flags |= Symbol::VisibleOutsideFile;
+}
 Symbols.insert(S);
   }
 }


Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -727,6 +727,19 @@
   EXPECT_THAT(MT.child("f3").children(), ElementsAre(Pair("relations", _)));
   EXPECT_THAT(MT.child("f3").total(), Gt(0U));
 }
+
+TEST(FileIndexTest, MacrosFromMainFile) {
+  FileIndex Idx;
+  TestTU TU;
+  TU.Code = "#pragma once\n#define FOO";
+  TU.Filename = "foo.h";
+  auto AST = TU.build();
+  Idx.updateMain(testPath(TU.Filename), AST);
+
+  auto &FooSymbol = findSymbol(runFuzzyFind(Idx, ""), "FOO");
+  EXPECT_TRUE(FooSymbol.Flags & Symbol::IndexedForCodeCompletion);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -564,6 +564,10 @@
 S.SymInfo.Lang = index::SymbolLanguage::C;
 S.Origin = Opts.Origin;
 S.CanonicalDeclaration = R.Location;
+if (!HeaderFileURIs->getIncludeHeader(SM.getMainFileID()).empty()) {
+  S.Flags |= Symbol::IndexedForCodeCompletion;
+  S.Flags |= Symbol::VisibleOutsideFile;
+}
 Symbols.insert(S);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113558: [clang-tidy] Fix cppcoreguidelines-virtual-base-class-destructor in macros

2021-11-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: aaron.ballman, njames93, alexfh, mgartmann, 
whisperity.
Herald added subscribers: carlosgalvezp, martong, shchenz, rnkovacs, kbarton, 
xazax.hun, nemanjai.
steakhal requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The `cppcoreguidelines-virtual-base-class-destructor` checker crashed on this 
example:

  #define DECLARE(CLASS) \
  class CLASS {  \
  protected: \
virtual ~CLASS();\
  }
  DECLARE(Foo); // no-crash

The checker will hit the following assertion:

  clang-tidy: llvm/include/llvm/ADT/Optional.h:196: T 
&llvm::optional_detail::OptionalStorage::getValue() & [T = 
clang::Token]: Assertion `hasVal' failed."

It turns out, `Lexer::findNextToken()` returned `llvm::None` within the 
`getVirtualKeywordRange()` function when the `VirtualEndLoc` SourceLocation 
represents a macro expansion.
To prevent this from happening, I decided to propagate the `llvm::None` further 
up and only create the removal of `virtual` if the `getVirtualKeywordRange()` 
succeeds.

I considered an alternative fix for this issue:
I could have checked the `Destructor.getLocation().isMacroID()` before doing 
any Fixit calculation inside the `check()` function.
In contrast to this approach my patch will preserve the diagnostics and drop 
the fixits only if it would have crashed.


https://reviews.llvm.org/D113558

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -270,3 +270,53 @@
 DerivedFromTemplateNonVirtualBaseStruct2Typedef 
InstantiationWithPublicNonVirtualBaseStruct2;
 
 } // namespace Bugzilla_51912
+
+namespace macro_tests {
+#define CONCAT(x, y) x##y
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar1' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar1 {
+protected:
+  CONCAT(vir, tual) CONCAT(~Foo, Bar1()); // no-fixit
+};
+
+// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar2' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual
+class FooBar2 {
+protected:
+  virtual CONCAT(~Foo, Bar2()); // no-fixit
+};
+
+// CHECK-MESSAGES: :[[@LINE+6]]:7: warning: destructor of 'FooBar3' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+5]]:7: note: make it protected and non-virtual
+// CHECK-FIXES:  class FooBar3 {
+// CHECK-FIXES-NEXT: protected:
+// CHECK-FIXES-NEXT:   ~FooBar3();
+// CHECK-FIXES-NEXT: };
+class FooBar3 {
+protected:
+  CONCAT(vir, tual) ~FooBar3();
+};
+
+// CHECK-MESSAGES: :[[@LINE+6]]:7: warning: destructor of 'FooBar4' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+5]]:7: note: make it protected and non-virtual
+// CHECK-FIXES:  class FooBar4 {
+// CHECK-FIXES-NEXT: protected:
+// CHECK-FIXES-NEXT:   ~CONCAT(Foo, Bar4());
+// CHECK-FIXES-NEXT: };
+class FooBar4 {
+protected:
+  CONCAT(vir, tual) ~CONCAT(Foo, Bar4());
+};
+
+// CHECK-MESSAGES: :[[@LINE+3]]:7: warning: destructor of 'FooBar5' is 
protected and virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+2]]:7: note: make it protected and non-virtual
+#define XMACRO(COLUMN1, COLUMN2) COLUMN1 COLUMN2
+class FooBar5 {
+protected:
+  XMACRO(CONCAT(vir, tual), ~CONCAT(Foo, Bar5());) // no-crash, no-fixit
+};
+#undef XMACRO
+#undef CONCAT
+} // namespace macro_tests
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -46,9 +46,12 @@
   this);
 }
 
-static CharSourceRange
+static Optional
 getVirtualKeywordRange(const CXXDestructorDecl &Destructor,
const SourceManager &SM, const LangOptions &LangOpts) {
+  if (Destructor.getLocation().isMacroID())
+return None;
+
   SourceLocation VirtualBeginLoc = Destructor.getBeginLoc();
   SourceLocation VirtualEndLoc = VirtualBeginLoc.getLocWithOffset(
   Lexer::MeasureTokenLength(VirtualBeginLoc, SM, LangOpts));
@@ -190,8 +193,10 @@
   Fix = FixItHint::CreateInsertion(Destructor->getLocation(), "virtual ");

[PATCH] D113538: OpenMP: Start calling setTargetAttributes for generated kernels

2021-11-10 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added reviewers: tianshilei1992, ye-luo, jhuber6.
JonChesterfield added a comment.

That seems important. What was the symptom of failing to set these? We may now 
be redundantly setting some, e.g. 
I think convergent is set somewhere else before this patch.

Added a few people who may be able to run the patch against nvptx to check for 
regressions. If there isn't already a nvptx attribute test we should commit one 
before this patch so we can see the change. If there is already one, then we 
haven't changed it here and all is good.


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

https://reviews.llvm.org/D113538

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


[PATCH] D107994: Making the code compliant to the documentation about Floating Point support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT (FMA is enabled).

2021-11-10 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 386124.

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

https://reviews.llvm.org/D107994

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/ffp-contract-option.c
  clang/test/CodeGen/ffp-model.c
  clang/test/CodeGen/ppc-emmintrin.c
  clang/test/CodeGen/ppc-xmmintrin.c
  clang/test/Driver/fp-model.c
  clang/test/Misc/ffp-contract.c

Index: clang/test/Misc/ffp-contract.c
===
--- /dev/null
+++ clang/test/Misc/ffp-contract.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -O3 -ffp-contract=fast -triple=aarch64-apple-darwin \
+// RUN: -S -o - %s | FileCheck --check-prefix=CHECK-FMADD %s
+// REQUIRES: aarch64-registered-target
+
+float fma_test1(float a, float b, float c) {
+  // CHECK-FMADD: fmadd
+  float x = a * b;
+  float y = x + c;
+  return y;
+}
Index: clang/test/Driver/fp-model.c
===
--- clang/test/Driver/fp-model.c
+++ clang/test/Driver/fp-model.c
@@ -99,7 +99,7 @@
 // RUN: %clang -### -nostdinc -ffp-model=precise -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPM-PRECISE %s
 // CHECK-FPM-PRECISE: "-cc1"
-// CHECK-FPM-PRECISE: "-ffp-contract=fast"
+// CHECK-FPM-PRECISE: "-ffp-contract=on"
 // CHECK-FPM-PRECISE: "-fno-rounding-math"
 
 // RUN: %clang -### -nostdinc -ffp-model=strict -c %s 2>&1 \
Index: clang/test/CodeGen/ppc-xmmintrin.c
===
--- clang/test/CodeGen/ppc-xmmintrin.c
+++ clang/test/CodeGen/ppc-xmmintrin.c
@@ -2,11 +2,11 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang -S -emit-llvm -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 // RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
Index: clang/test/CodeGen/ppc-emmintrin.c
===
--- clang/test/CodeGen/ppc-emmintrin.c
+++ clang/test/CodeGen/ppc-emmintrin.c
@@ -2,9 +2,9 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang -S -emit-llvm -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:  -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN:  -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 
 // CHECK-BE-DAG: @_mm_movemask_pd.perm_mask = internal constant <4 x i32> , align 16
 // CHECK-BE-DAG: @_mm_shuffle_epi32.permute_selectors = internal constant [4 x i32] [i32 66051, i32 67438087, i32 134810123, i32 202182159], align 4
Index: clang/test/CodeGen/ffp-model.c
===
--- /dev/null
+++ clang/test/CodeGen/ffp-model.c
@@ -0,0 +1,52 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -S -emit-llvm -ffp-model=fast -emit-llvm %s -o - \
+// RUN: | FileCheck %s \
+// RUN: --check-prefixes=CHECK,CHECK-FAST --strict-whitespace
+
+// RUN: %clang -S -emit-llvm -ffp-model=precise %s -o - \
+// RUN: | FileCheck %s \
+// RUN: --check-prefixes=CHECK,CHECK-PRECISE --strict-whitespace
+
+// RUN: %clang -S -emit-llvm -ffp-model=strict %s -o - \
+// RUN: -target x86_64 | FileCheck %s \
+// RUN: --check-prefixes=CHECK,CHECK-STRICT --strict-whitespace
+
+// RUN: %clang -S -emit-llvm -ffp-model=strict -ffast-math \
+// RUN: -target x8

[PATCH] D107994: Making the code compliant to the documentation about Floating Point support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT (FMA is enabled).

2021-11-10 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/test/CodeGen/ffp-model.c:4
+// RUN: | FileCheck %s \
+// RUN: --check-prefixes=CHECK,CHECK-FAST --strict-whitespace
+

andrew.w.kaylor wrote:
> Why did you add the strict-whitespace option?
Because on some targets, the IR generated for the define is "define {{.*}}float 
@mymuladd" and on and some others it is 
"define {{.*}} float @mymuladd" (space between {{.*}} and float.


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

https://reviews.llvm.org/D107994

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


[clang] 4fb0805 - [clang-repl] Allow Interpreter::getSymbolAddress to take a mangled name.

2021-11-10 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2021-11-10T12:52:05Z
New Revision: 4fb0805c6525b13e50067b9ddfe8677a0b7b2d7c

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

LOG: [clang-repl] Allow Interpreter::getSymbolAddress to take a mangled name.

Added: 


Modified: 
clang/include/clang/CodeGen/ModuleBuilder.h
clang/include/clang/Interpreter/Interpreter.h
clang/lib/CodeGen/ModuleBuilder.cpp
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/lib/Interpreter/IncrementalExecutor.h
clang/lib/Interpreter/IncrementalParser.cpp
clang/lib/Interpreter/IncrementalParser.h
clang/lib/Interpreter/Interpreter.cpp
clang/unittests/Interpreter/CMakeLists.txt
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/include/clang/CodeGen/ModuleBuilder.h 
b/clang/include/clang/CodeGen/ModuleBuilder.h
index f9d056ed8b1ea..26587e73bf6c7 100644
--- a/clang/include/clang/CodeGen/ModuleBuilder.h
+++ b/clang/include/clang/CodeGen/ModuleBuilder.h
@@ -74,6 +74,10 @@ class CodeGenerator : public ASTConsumer {
   /// This may return null if there was no matching declaration.
   const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
 
+  /// Given a global declaration, return a mangled name for this declaration
+  /// which has been added to this code generator via a Handle method.
+  llvm::StringRef GetMangledName(GlobalDecl GD);
+
   /// Return the LLVM address of the given global entity.
   ///
   /// \param isForDefinition If true, the caller intends to define the

diff  --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 9f5b64ce21243..2dc0fd5963a2f 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -16,6 +16,8 @@
 
 #include "clang/Interpreter/PartialTranslationUnit.h"
 
+#include "clang/AST/GlobalDecl.h"
+
 #include "llvm/ExecutionEngine/JITSymbol.h"
 #include "llvm/Support/Error.h"
 
@@ -66,8 +68,20 @@ class Interpreter {
   return Execute(*PTU);
 return llvm::Error::success();
   }
+
+  /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses
+  /// the CodeGenModule's internal mangling cache to avoid recomputing the
+  /// mangled name.
+  llvm::Expected getSymbolAddress(GlobalDecl GD) const;
+
+  /// \returns the \c JITTargetAddress of a given name as written in the IR.
+  llvm::Expected
+  getSymbolAddress(llvm::StringRef IRName) const;
+
+  /// \returns the \c JITTargetAddress of a given name as written in the object
+  /// file.
   llvm::Expected
-  getSymbolAddress(llvm::StringRef UnmangledName) const;
+  getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
 };
 } // namespace clang
 

diff  --git a/clang/lib/CodeGen/ModuleBuilder.cpp 
b/clang/lib/CodeGen/ModuleBuilder.cpp
index b63f756ca2884..f6642a79e1e48 100644
--- a/clang/lib/CodeGen/ModuleBuilder.cpp
+++ b/clang/lib/CodeGen/ModuleBuilder.cpp
@@ -122,6 +122,10 @@ namespace {
   return D;
 }
 
+llvm::StringRef GetMangledName(GlobalDecl GD) {
+  return Builder->getMangledName(GD);
+}
+
 llvm::Constant *GetAddrOfGlobal(GlobalDecl global, bool isForDefinition) {
   return Builder->GetAddrOfGlobal(global, 
ForDefinition_t(isForDefinition));
 }
@@ -325,6 +329,10 @@ const Decl 
*CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
 
+llvm::StringRef CodeGenerator::GetMangledName(GlobalDecl GD) {
+  return static_cast(this)->GetMangledName(GD);
+}
+
 llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global,
bool isForDefinition) {
   return static_cast(this)

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 230b49167f347..705235aafa070 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -61,8 +61,11 @@ llvm::Error IncrementalExecutor::runCtors() const {
 }
 
 llvm::Expected
-IncrementalExecutor::getSymbolAddress(llvm::StringRef UnmangledName) const {
-  auto Sym = Jit->lookup(UnmangledName);
+IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
+  SymbolNameKind NameKind) const {
+  auto Sym = (NameKind == LinkerName) ? Jit->lookupLinkerMangled(Name)
+  : Jit->lookup(Name);
+
   if (!Sym)
 return Sym.takeError();
   return Sym->getAddress();

diff  --git a/clang/lib/Interpreter/IncrementalExecutor.h 
b/clang/lib/Interpreter/IncrementalExecutor.h
index b626ebedcdc30..24447994d5f1d 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.h
+++ b/clang/lib/Interpreter/Increm

[PATCH] D113538: OpenMP: Start calling setTargetAttributes for generated kernels

2021-11-10 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D113538#3121062 , @JonChesterfield 
wrote:

> That seems important. What was the symptom of failing to set these? We may 
> now be redundantly setting some, e.g. 
> I think convergent is set somewhere else before this patch.

A bunch of missing attributes on the kernel. The one I noticed was not setting 
amdgpu-implicitarg-num-bytes (although D112488 
 avoids needing to do that), but we have a 
few other attributes that simply wouldn't be set. I'm fighting with some 
divergence between upstream and the internal branches with these attributes. In 
particular, the internal branch is hacking on the generic attributes for 
openmp, and also redundantly (and incorrectly) setting 
amdgpu-flat-work-group-size to the invalid range 257,257.

convergent isn't a target attribute and isn't the target's responsibility to 
add.


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

https://reviews.llvm.org/D113538

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


[PATCH] D113538: OpenMP: Start calling setTargetAttributes for generated kernels

2021-11-10 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 386137.
arsenm added a comment.

Also test non-kernel


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

https://reviews.llvm.org/D113538

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/OpenMP/amdgcn-attributes.cpp

Index: clang/test/OpenMP/amdgcn-attributes.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn-attributes.cpp
@@ -0,0 +1,43 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=DEFAULT,ALL %s
+// RUN: %clang_cc1 -target-cpu gfx900 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=CPU,ALL %s
+
+// RUN: %clang_cc1 -menable-no-nans -mno-amdgpu-ieee -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=NOIEEE,ALL %s
+// RUN: %clang_cc1 -munsafe-fp-atomics -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=UNSAFEATOMIC,ALL %s
+
+// expected-no-diagnostics
+
+#define N 100
+
+int callable(int);
+
+// Check that the target attributes are set on the generated kernel
+int func() {
+  // ALL-LABEL: amdgpu_kernel void @__omp_offloading{{.*}} #0
+
+  int arr[N];
+
+#pragma omp target
+  for (int i = 0; i < N; i++) {
+arr[i] = callable(arr[i]);
+  }
+
+  return arr[0];
+}
+
+int callable(int x) {
+  // ALL-LABEL: @_Z8callablei(i32 %x) #1
+  return x + 1;
+}
+
+  // DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-implicitarg-num-bytes"="56" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+  // CPU: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-implicitarg-num-bytes"="56" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst" }
+  // NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-ieee"="false" "amdgpu-implicitarg-num-bytes"="56" "frame-pointer"="none" "min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+  // UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-implicitarg-num-bytes"="56" "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+
+// DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+// CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst" }
+// NOIEEE: attributes #1 = { convergent mustprogress noinline nounwind optnone "amdgpu-ieee"="false" "frame-pointer"="none" "min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+// UNSAFEATOMIC: attributes #1 = { convergent mustprogress noinline nounwind optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9143,6 +9143,10 @@
 public:
   AMDGPUTargetCodeGenInfo(CodeGenTypes &CGT)
   : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  void setFunctionDeclAttributes(const FunctionDecl *FD, llvm::Function *F,
+ CodeGenModule &CGM) const;
+
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
   unsigned getOpenCLKernelCallingConv() const override;
@@ -9182,36 +9186,13 @@
cast(D)->getType()->isC

[PATCH] D112915: [clang][modules] Track number of includes per submodule

2021-11-10 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 386139.
jansvoboda11 added a comment.

Store only direct includes in the PCM (compared to transitive stored 
previously), use InputFile ID (instead of full filesystem path).

Also: add test of transitive includes, fix bug in 
`VisibleModuleSet::setVisible`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112915

Files:
  clang/include/clang/Lex/ExternalPreprocessorSource.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/Basic/Module.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/import-submodule-visibility.c

Index: clang/test/Modules/import-submodule-visibility.c
===
--- /dev/null
+++ clang/test/Modules/import-submodule-visibility.c
@@ -0,0 +1,99 @@
+// This test checks that imports of headers that appeared in a different submodule than
+// what is imported by the current TU don't affect the compilation.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- A.framework/Headers/A.h
+#include "Textual.h"
+//--- A.framework/Modules/module.modulemap
+framework module A { header "A.h" }
+
+//--- B.framework/Headers/B1.h
+#include "Textual.h"
+//--- B.framework/Headers/B2.h
+//--- B.framework/Modules/module.modulemap
+framework module B {
+  module B1 { header "B1.h" }
+  module B2 { header "B2.h" }
+}
+
+//--- C/C.h
+#include "Textual.h"
+//--- C/module.modulemap
+module C { header "C.h" }
+
+//--- D/D1.h
+#include "Textual.h"
+//--- D/D2.h
+//--- D/module.modulemap
+module D {
+  module D1 { header "D1.h" }
+  module D2 { header "D2.h" }
+}
+
+//--- E/E1.h
+#include "E2.h"
+//--- E/E2.h
+#include "Textual.h"
+//--- E/module.modulemap
+module E {
+  module E1 { header "E1.h" }
+  module E2 { header "E2.h" }
+}
+
+//--- Textual.h
+#define MACRO_TEXTUAL 1
+
+//--- test.c
+
+#ifdef A
+//
+#endif
+
+#ifdef B
+#import 
+#endif
+
+#ifdef C
+//
+#endif
+
+#ifdef D
+#import "D/D2.h"
+#endif
+
+#ifdef E
+#import "E/E1.h"
+#endif
+
+#import "Textual.h"
+
+static int x = MACRO_TEXTUAL;
+
+// Specifying the PCM file on the command line (without actually importing "A") should not
+// prevent "Textual.h" to be included in the TU.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/A.framework/Modules/module.modulemap -fmodule-name=A -o %t/A.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DA -fmodule-file=%t/A.pcm
+
+// Specifying the PCM file on the command line and importing "B2" in the source does not
+// prevent "Textual.h" to be included in the TU.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/B.framework/Modules/module.modulemap -fmodule-name=B -o %t/B.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DB -iframework %t -fmodule-file=%t/B.pcm
+
+// Module-only version of the test with framework A.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/C/module.modulemap -fmodule-name=C -o %t/C.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DC -fmodule-file=%t/C.pcm
+
+// Module-only version of the test with framework B.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/D/module.modulemap -fmodule-name=D -o %t/D.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DD -fmodule-file=%t/D.pcm
+
+// Transitively imported, but not exported.
+//
+// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/E/module.modulemap -fmodule-name=E -o %t/E.pcm
+// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test.c -DE -fmodule-file=%t/E.pcm
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1696,7 +1696,7 @@
 std::pair
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 4 + 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1728,7 +1728,6 @@
   | (Data.HFI.DirInfo << 1)
   | Data.HFI.IndexHeaderMapHeader;
   LE.write(Flags);
-  LE.write(Data.HFI.NumIncludes);
 
   if (!Data.HFI.ControllingMacro)
 LE.write(Data.HFI.ControllingMacroID);
@@ -2171,6 +2170,42 @@
   return false;
 }
 
+void ASTWriter::addIncludedFiles(
+const llvm::DenseMap &Files,
+RecordDataImpl &Record

[PATCH] D112492: [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4290-4293
-  // Do not set COMDAT attribute for CUDA/HIP stub functions to prevent
-  // them being "merged" by the COMDAT Folding linker optimization.
-  if (D.hasAttr())
-return false;

rnk wrote:
> rnk wrote:
> > tra wrote:
> > > This was added in D63277 specifically to deal with comdat-related issue 
> > > on windows. 
> > > 
> > > We do need to have unique addresses for each kernel stub. Placing stubs 
> > > into comdat may allow them to be merged into one and that would be a 
> > > problem.
> > > https://docs.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=vs-2019
> > >  
> > > 
> > > @rnk,@kpyzhov -- how do we make sure that identical functions are placed 
> > > in comdat (needed for templates) but do not get comdat-folded with 
> > > `/OPT:ICF`? 
> > > 
> > These are readonly global variables. I believe MSVC's ICF implementation 
> > changed behavior here a few times over the years. I think the current state 
> > is that they don't merge such globals. If you are using LLD, you can use 
> > safe ICF to avoid merging such globals.
> > 
> > @zequanwu reviewed the state of ICF in LLD in the last year, so he may know 
> > more about the current status, and he may be more helpful if you have more 
> > questions.
> > 
> > Finally, you could mark these globals as mutable if you really want to 
> > block ICF. That will work reliably with any linker.
> Broadly, I think this change is correct. If I had reviewed D63277, I probably 
> would have objected to it and not approved it.
These symbols are for kernel stub functions. How do I mark them as mutable? 


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

https://reviews.llvm.org/D112492

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


[PATCH] D112680: [OpenMP] Lower printf to __llvm_omp_vprintf

2021-11-10 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield updated this revision to Diff 386156.
JonChesterfield added a comment.

- regen test file using the better './llvm/utils/update_cc_test_checks.py 
--llvm-bin=/home/amd/llvm-install/bin 
clang/test/OpenMP/nvptx_target_printf_codegen.c', now passing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112680

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
  openmp/libomptarget/test/mapping/data_member_ref.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
  openmp/libomptarget/test/mapping/lambda_by_value.cpp
  openmp/libomptarget/test/mapping/ompx_hold/struct.c
  openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
  openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp
  openmp/libomptarget/test/offloading/bug50022.cpp
  openmp/libomptarget/test/offloading/host_as_target.c
  openmp/libomptarget/test/unified_shared_memory/api.c
  openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
  openmp/libomptarget/test/unified_shared_memory/close_modifier.c
  openmp/libomptarget/test/unified_shared_memory/shared_update.c

Index: openmp/libomptarget/test/unified_shared_memory/shared_update.c
===
--- openmp/libomptarget/test/unified_shared_memory/shared_update.c
+++ openmp/libomptarget/test/unified_shared_memory/shared_update.c
@@ -2,9 +2,8 @@
 
 // REQUIRES: unified_shared_memory
 
-// amdgcn does not have printf definition
-// XFAIL: amdgcn-amd-amdhsa
-// XFAIL: amdgcn-amd-amdhsa-newRTL
+// amdgpu runtime crash
+// UNSUPPORTED: amdgcn-amd-amdhsa
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_modifier.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_modifier.c
+++ openmp/libomptarget/test/unified_shared_memory/close_modifier.c
@@ -3,9 +3,9 @@
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// amdgcn does not have printf definition
-// XFAIL: amdgcn-amd-amdhsa
-// XFAIL: amdgcn-amd-amdhsa-newRTL
+// amdgpu runtime crash
+// UNSUPPORTED: amdgcn-amd-amdhsa
+
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
+++ openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
@@ -3,7 +3,7 @@
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// Fails on amdgcn with error: GPU Memory Error
+// Fails on amdgpu with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
 // XFAIL: amdgcn-amd-amdhsa-newRTL
 
Index: openmp/libomptarget/test/unified_shared_memory/api.c
===
--- openmp/libomptarget/test/unified_shared_memory/api.c
+++ openmp/libomptarget/test/unified_shared_memory/api.c
@@ -2,7 +2,7 @@
 // XFAIL: nvptx64-nvidia-cuda
 // XFAIL: nvptx64-nvidia-cuda-newRTL
 
-// Fails on amdgcn with error: GPU Memory Error
+// Fails on amdgpu with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
 // XFAIL: amdgcn-amd-amdhsa-newRTL
 
Index: openmp/libomptarget/test/offloading/host_as_target.c
===
--- openmp/libomptarget/test/offloading/host_as_target.c
+++ openmp/libomptarget/test/offloading/host_as_target.c
@@ -7,7 +7,7 @@
 
 // RUN: %libomptarget-compile-run-and-check-generic
 
-// amdgcn does not have printf definition
+// amdgpu does not have a working printf definition
 // XFAIL: amdgcn-amd-amdhsa
 // XFAIL: amdgcn-amd-amdhsa-newRTL
 
Index: openmp/libomptarget/test/offloading/bug50022.cpp
===
--- openmp/libomptarget/test/offloading/bug50022.cpp
+++ openmp/libomptarget/test/offloading/bug50022.cpp
@@ -1,8 +1,5 @@
 // RUN: %libomptarget-compilexx-and-run-generic
 
-// UNSUPPORTED: amdgcn-amd-amdhsa
-// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
-
 #include 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug49021.cpp
===
--- openmp/libomptarget/test/offloading/bug49021.cpp
+++ openmp/libomptarget/test/offloading/bug49021.cpp
@@ -1,8 +1,7 @@
 // RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
 
-// Wrong results on amdg

[PATCH] D113570: [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, arphaman.
adamcz requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

The call to getTypeSizeInChars() is replaced with
getTypeSizeInCharsIfKnown(), which does not crash on forward declared
structs. This only affects printing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113570

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/APValue.cpp


Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)&bar;
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "&bar");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)&bar;
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "&bar");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 27177b8 - [OpenMP] Lower printf to __llvm_omp_vprintf

2021-11-10 Thread Jon Chesterfield via cfe-commits

Author: Jon Chesterfield
Date: 2021-11-10T15:30:56Z
New Revision: 27177b82d4ca4451f288168fc1e06c0736afbdaf

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

LOG: [OpenMP] Lower printf to __llvm_omp_vprintf

Extension of D112504. Lower amdgpu printf to `__llvm_omp_vprintf`
which takes the same const char*, void* arguments as cuda vprintf and also
passes the size of the void* alloca which will be needed by a non-stub
implementation of `__llvm_omp_vprintf` for amdgpu.

This removes the amdgpu link error on any printf in a target region in favour
of silently compiling code that doesn't print anything to stdout.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGGPUBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/OpenMP/nvptx_target_printf_codegen.c
openmp/libomptarget/DeviceRTL/include/Debug.h
openmp/libomptarget/DeviceRTL/src/Debug.cpp
openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip
openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
openmp/libomptarget/test/mapping/data_member_ref.cpp
openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
openmp/libomptarget/test/mapping/lambda_by_value.cpp
openmp/libomptarget/test/mapping/ompx_hold/struct.c
openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
openmp/libomptarget/test/offloading/bug49021.cpp
openmp/libomptarget/test/offloading/bug50022.cpp
openmp/libomptarget/test/offloading/host_as_target.c
openmp/libomptarget/test/unified_shared_memory/api.c
openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
openmp/libomptarget/test/unified_shared_memory/close_modifier.c
openmp/libomptarget/test/unified_shared_memory/shared_update.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index fab21e5b588a5..18e429cf3efd2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5106,11 +5106,16 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 return RValue::get(Builder.CreateFPExt(HalfVal, Builder.getFloatTy()));
   }
   case Builtin::BIprintf:
-if (getTarget().getTriple().isNVPTX())
-  return EmitNVPTXDevicePrintfCallExpr(E, ReturnValue);
-if (getTarget().getTriple().getArch() == Triple::amdgcn &&
-getLangOpts().HIP)
-  return EmitAMDGPUDevicePrintfCallExpr(E, ReturnValue);
+if (getTarget().getTriple().isNVPTX() ||
+getTarget().getTriple().isAMDGCN()) {
+  if (getLangOpts().OpenMPIsDevice)
+return EmitOpenMPDevicePrintfCallExpr(E);
+  if (getTarget().getTriple().isNVPTX())
+return EmitNVPTXDevicePrintfCallExpr(E);
+  if (getTarget().getTriple().isAMDGCN() && getLangOpts().HIP)
+return EmitAMDGPUDevicePrintfCallExpr(E);
+}
+
 break;
   case Builtin::BI__builtin_canonicalize:
   case Builtin::BI__builtin_canonicalizef:

diff  --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index 43192c587e262..fdd2fa18bb4a0 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -21,13 +21,14 @@
 using namespace clang;
 using namespace CodeGen;
 
-static llvm::Function *GetVprintfDeclaration(llvm::Module &M) {
+namespace {
+llvm::Function *GetVprintfDeclaration(llvm::Module &M) {
   llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
 llvm::Type::getInt8PtrTy(M.getContext())};
   llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
   llvm::Type::getInt32Ty(M.getContext()), ArgTypes, false);
 
-  if (auto* F = M.getFunction("vprintf")) {
+  if (auto *F = M.getFunction("vprintf")) {
 // Our CUDA system header declares vprintf with the right signature, so
 // nobody else should have been able to declare vprintf with a bogus
 // signature.
@@ -41,6 +42,28 @@ static llvm::Function *GetVprintfDeclaration(llvm::Module 
&M) {
   VprintfFuncType, llvm::GlobalVariable::ExternalLinkage, "vprintf", &M);
 }
 
+llvm::Function *GetOpenMPVprintfDeclaration(CodeGenModule &CGM) {
+  const char *Name = "__llvm_omp_vprintf";
+  llvm::Module &M = CGM.getModule();
+  llvm::Type *ArgTypes[] = {llvm::Type::getInt8PtrTy(M.getContext()),
+llvm::Type::getInt8PtrTy(M.getContext()),
+llvm::Type::getInt32Ty(M.getContext())};
+  llvm::FunctionType *VprintfFuncType = llvm::FunctionType::get(
+  llvm::Type::getInt32Ty(M.getContext()), ArgTy

[PATCH] D112680: [OpenMP] Lower printf to __llvm_omp_vprintf

2021-11-10 Thread Jon Chesterfield 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 rG27177b82d4ca: [OpenMP] Lower printf to __llvm_omp_vprintf 
(authored by JonChesterfield).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112680

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
  openmp/libomptarget/test/mapping/data_member_ref.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_default_mappers.cpp
  openmp/libomptarget/test/mapping/declare_mapper_nested_mappers.cpp
  openmp/libomptarget/test/mapping/lambda_by_value.cpp
  openmp/libomptarget/test/mapping/ompx_hold/struct.c
  openmp/libomptarget/test/mapping/ptr_and_obj_motion.c
  openmp/libomptarget/test/mapping/reduction_implicit_map.cpp
  openmp/libomptarget/test/offloading/bug49021.cpp
  openmp/libomptarget/test/offloading/bug50022.cpp
  openmp/libomptarget/test/offloading/host_as_target.c
  openmp/libomptarget/test/unified_shared_memory/api.c
  openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
  openmp/libomptarget/test/unified_shared_memory/close_modifier.c
  openmp/libomptarget/test/unified_shared_memory/shared_update.c

Index: openmp/libomptarget/test/unified_shared_memory/shared_update.c
===
--- openmp/libomptarget/test/unified_shared_memory/shared_update.c
+++ openmp/libomptarget/test/unified_shared_memory/shared_update.c
@@ -2,9 +2,8 @@
 
 // REQUIRES: unified_shared_memory
 
-// amdgcn does not have printf definition
-// XFAIL: amdgcn-amd-amdhsa
-// XFAIL: amdgcn-amd-amdhsa-newRTL
+// amdgpu runtime crash
+// UNSUPPORTED: amdgcn-amd-amdhsa
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_modifier.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_modifier.c
+++ openmp/libomptarget/test/unified_shared_memory/close_modifier.c
@@ -3,9 +3,9 @@
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// amdgcn does not have printf definition
-// XFAIL: amdgcn-amd-amdhsa
-// XFAIL: amdgcn-amd-amdhsa-newRTL
+// amdgpu runtime crash
+// UNSUPPORTED: amdgcn-amd-amdhsa
+
 
 #include 
 #include 
Index: openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
===
--- openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
+++ openmp/libomptarget/test/unified_shared_memory/close_enter_exit.c
@@ -3,7 +3,7 @@
 // REQUIRES: unified_shared_memory
 // UNSUPPORTED: clang-6, clang-7, clang-8, clang-9
 
-// Fails on amdgcn with error: GPU Memory Error
+// Fails on amdgpu with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
 // XFAIL: amdgcn-amd-amdhsa-newRTL
 
Index: openmp/libomptarget/test/unified_shared_memory/api.c
===
--- openmp/libomptarget/test/unified_shared_memory/api.c
+++ openmp/libomptarget/test/unified_shared_memory/api.c
@@ -2,7 +2,7 @@
 // XFAIL: nvptx64-nvidia-cuda
 // XFAIL: nvptx64-nvidia-cuda-newRTL
 
-// Fails on amdgcn with error: GPU Memory Error
+// Fails on amdgpu with error: GPU Memory Error
 // XFAIL: amdgcn-amd-amdhsa
 // XFAIL: amdgcn-amd-amdhsa-newRTL
 
Index: openmp/libomptarget/test/offloading/host_as_target.c
===
--- openmp/libomptarget/test/offloading/host_as_target.c
+++ openmp/libomptarget/test/offloading/host_as_target.c
@@ -7,7 +7,7 @@
 
 // RUN: %libomptarget-compile-run-and-check-generic
 
-// amdgcn does not have printf definition
+// amdgpu does not have a working printf definition
 // XFAIL: amdgcn-amd-amdhsa
 // XFAIL: amdgcn-amd-amdhsa-newRTL
 
Index: openmp/libomptarget/test/offloading/bug50022.cpp
===
--- openmp/libomptarget/test/offloading/bug50022.cpp
+++ openmp/libomptarget/test/offloading/bug50022.cpp
@@ -1,8 +1,5 @@
 // RUN: %libomptarget-compilexx-and-run-generic
 
-// UNSUPPORTED: amdgcn-amd-amdhsa
-// UNSUPPORTED: amdgcn-amd-amdhsa-newRTL
-
 #include 
 #include 
 #include 
Index: openmp/libomptarget/test/offloading/bug49021.cpp
===
--- openmp/libomptarget/test/offloading/bug49021.cpp
+++ openmp/libomptarget/test/offloading/bug49021.cpp
@@ -1,8 +1,7 @@
 // RUN: %libomptarget-compilexx-generic -O3 && %libomptarget-run-generic
 
-// Wrong results on amdgcn
-// UNSUPPORTED: amdgcn

[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D113517#3120030 , @rsmith wrote:

> What's the motivation for this change? I believe the current behavior is 
> still conforming: `set_unexpected` is no longer (officially) part of the 
> standard library (though it still exists as a zombie name), and the default 
> `unexpected` handler calls `terminate`, so calling `unexpected` rather than 
> `terminate` should have the same effect, except in non-conforming programs 
> that call `std::set_unexpected` anyway (and for such programs, calling 
> `unexpected` seems like the behavior the programmer would expect). Do we 
> generate better code if we call `terminate` rather than `unexpected`?

Today: no, we don't.

But, I'm planning to propose further changes to improve noexcept codegen in 
Clang -- which is currently quite bad, compared to what it should be, because 
it's effectively following the same rules as legacy throw(). This change allows 
those future optimizations to apply to throw() as well, in C++17 mode, which is 
the desirable outcome.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

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


[PATCH] D113570: [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

2021-11-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113570

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


[PATCH] D113256: [AArch64][ARM] Enablement of Cortex-A710 Support

2021-11-10 Thread Mubashar Ahmad via Phabricator via cfe-commits
mubashar_ updated this revision to Diff 386165.
mubashar_ marked 5 inline comments as done.
mubashar_ added a comment.

Placement of Cortex-A710 items changed to order specified by previous comments.


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

https://reviews.llvm.org/D113256

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arm-cortex-cpus.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMSubtarget.cpp
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -309,6 +309,13 @@
  ARM::AEK_DSP | ARM::AEK_CRC | ARM::AEK_RAS |
  ARM::AEK_FP16 | ARM::AEK_DOTPROD,
  "8.2-A"),
+ARMCPUTestParams("cortex-a710", "armv9-a", "neon-fp-armv8",
+ ARM::AEK_SEC | ARM::AEK_MP | ARM::AEK_VIRT |
+ ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB |
+ ARM::AEK_DSP | ARM::AEK_CRC | ARM::AEK_RAS |
+ ARM::AEK_DOTPROD | ARM::AEK_FP16FML |
+ ARM::AEK_BF16 | ARM::AEK_I8MM | ARM::AEK_SB,
+ "9-A"),
 ARMCPUTestParams("cortex-a77", "armv8.2-a", "crypto-neon-fp-armv8",
  ARM::AEK_CRC | ARM::AEK_SEC | ARM::AEK_MP |
  ARM::AEK_VIRT | ARM::AEK_HWDIVARM |
@@ -386,7 +393,7 @@
  ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP,
  "7-S")));
 
-static constexpr unsigned NumARMCPUArchs = 86;
+static constexpr unsigned NumARMCPUArchs = 87;
 
 TEST(TargetParserTest, testARMCPUArchList) {
   SmallVector List;
@@ -984,6 +991,17 @@
  AArch64::AEK_FP16 | AArch64::AEK_DOTPROD |
  AArch64::AEK_RCPC | AArch64::AEK_SSBS,
  "8.2-A"),
+ARMCPUTestParams("cortex-a710", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_SVE2 |
+ AArch64::AEK_DOTPROD | AArch64::AEK_MTE |
+ AArch64::AEK_FP16FML | AArch64::AEK_SVE2BITPERM |
+ AArch64::AEK_PAUTH | AArch64::AEK_FLAGM |
+ AArch64::AEK_SB | AArch64::AEK_I8MM |
+ AArch64::AEK_BF16,
+ "9-A"),
 ARMCPUTestParams(
 "neoverse-v1", "armv8.4-a", "crypto-neon-fp-armv8",
 AArch64::AEK_RAS | AArch64::AEK_SVE | AArch64::AEK_SSBS |
@@ -1208,7 +1226,7 @@
  AArch64::AEK_LSE | AArch64::AEK_RDM,
  "8.2-A")));
 
-static constexpr unsigned NumAArch64CPUArchs = 51;
+static constexpr unsigned NumAArch64CPUArchs = 52;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/ARM/ARMSubtarget.h
===
--- llvm/lib/Target/ARM/ARMSubtarget.h
+++ llvm/lib/Target/ARM/ARMSubtarget.h
@@ -65,6 +65,7 @@
 CortexA77,
 CortexA78,
 CortexA78C,
+CortexA710,
 CortexA8,
 CortexA9,
 CortexM3,
Index: llvm/lib/Target/ARM/ARMSubtarget.cpp
===
--- llvm/lib/Target/ARM/ARMSubtarget.cpp
+++ llvm/lib/Target/ARM/ARMSubtarget.cpp
@@ -295,6 +295,7 @@
   case CortexA77:
   case CortexA78:
   case CortexA78C:
+  case CortexA710:
   case CortexR4:
   case CortexR4F:
   case CortexR5:
Index: llvm/lib/Target/ARM/ARM.td
===
--- llvm/lib/Target/ARM/ARM.td
+++ llvm/lib/Target/ARM/ARM.td
@@ -636,6 +636,8 @@
"Cortex-A78 ARM processors", []>;
 def ProcA78C: SubtargetFeature<"a78c", "ARMProcFamily", "CortexA78C",
"Cortex-A78C ARM processors", []>;
+def ProcA710: SubtargetFeature<"cortex-a710", "ARMProcFamily",
+   "CortexA710", "Cortex-A710 ARM processors", []>;
 def ProcX1  : SubtargetFeature<"cortex-x1", "ARMProcFamily", "CortexX1",
"Cortex-X1 ARM processors", []>;
 
@@ -1380,6 +1382,14 

[PATCH] D113299: [NFC] Inclusive Language: change master to main for .chm files

2021-11-10 Thread Quinn Pham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc3b15b71ce00: [NFC] Inclusive Language: change master to 
main for .chm files (authored by quinnp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113299

Files:
  clang-tools-extra/docs/doxygen.cfg.in
  clang/docs/doxygen.cfg.in
  flang/docs/doxygen.cfg.in
  lldb/docs/doxygen.cfg.in
  llvm/docs/doxygen.cfg.in
  mlir/docs/doxygen.cfg.in
  openmp/docs/doxygen.cfg.in
  openmp/runtime/doc/doxygen/config
  polly/docs/doxygen.cfg.in

Index: polly/docs/doxygen.cfg.in
===
--- polly/docs/doxygen.cfg.in
+++ polly/docs/doxygen.cfg.in
@@ -1220,7 +1220,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: openmp/runtime/doc/doxygen/config
===
--- openmp/runtime/doc/doxygen/config
+++ openmp/runtime/doc/doxygen/config
@@ -1048,7 +1048,7 @@
 
 # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
 # controls if a separate .chi index file is generated (YES) or that
-# it should be included in the master .chm file (NO).
+# it should be included in the main .chm file (NO).
 
 GENERATE_CHI   = NO
 
Index: openmp/docs/doxygen.cfg.in
===
--- openmp/docs/doxygen.cfg.in
+++ openmp/docs/doxygen.cfg.in
@@ -1220,7 +1220,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: mlir/docs/doxygen.cfg.in
===
--- mlir/docs/doxygen.cfg.in
+++ mlir/docs/doxygen.cfg.in
@@ -1220,7 +1220,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: llvm/docs/doxygen.cfg.in
===
--- llvm/docs/doxygen.cfg.in
+++ llvm/docs/doxygen.cfg.in
@@ -1220,7 +1220,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: lldb/docs/doxygen.cfg.in
===
--- lldb/docs/doxygen.cfg.in
+++ lldb/docs/doxygen.cfg.in
@@ -916,7 +916,7 @@
 
 # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
 # controls if a separate .chi index file is generated (YES) or that
-# it should be included in the master .chm file (NO).
+# it should be included in the main .chm file (NO).
 
 GENERATE_CHI   = NO
 
Index: flang/docs/doxygen.cfg.in
===
--- flang/docs/doxygen.cfg.in
+++ flang/docs/doxygen.cfg.in
@@ -1222,7 +1222,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: clang/docs/doxygen.cfg.in
===
--- clang/docs/doxygen.cfg.in
+++ clang/docs/doxygen.cfg.in
@@ -1219,7 +1219,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi index file is generated (
-# YES) or that it should be included in the master .chm file ( NO).
+# YES) or that it should be included in the main .chm file ( NO).
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTMLHELP is set to YES.
 
Index: clang-tools-extra/docs/doxygen.cfg.in
===
--- clang-tools-extra/docs/doxygen.cfg.in
+++ clang-tools-extra/docs/doxygen.cfg.in
@@ -1230,7 +1230,7 @@
 HHC_LOCATION   =
 
 # The GENERATE_CHI flag controls if a separate .chi

[PATCH] D111443: [Driver] Fix ToolChain::getSanitizerArgs

2021-11-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

@eugenis Any further changes needed? Thanks.


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

https://reviews.llvm.org/D111443

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


[clang] 7a2b1bd - [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

2021-11-10 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-11-10T17:17:00+01:00
New Revision: 7a2b1bdb4c8a099ebc38b7f802988244ad21fcc0

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

LOG: [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

The call to getTypeSizeInChars() is replaced with
getTypeSizeInCharsIfKnown(), which does not crash on forward declared
structs. This only affects printing.

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/lib/AST/APValue.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 2e33ce4c5d101..53df965fef2fa 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@ TEST(Hover, SpaceshipTemplateNoCrash) {
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)&bar;
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "&bar");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 9a9233bc1ea74..ef333c7711663 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@ void APValue::printPretty(raw_ostream &Out, const 
PrintingPolicy &Policy,
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";



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


[PATCH] D113570: [clang] Do not crash in APValue::prettyPrint() on forward-decl structs.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a2b1bdb4c8a: [clang] Do not crash in APValue::prettyPrint() 
on forward-decl structs. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113570

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/APValue.cpp


Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)&bar;
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "&bar");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -700,7 +700,9 @@
 if (!hasLValuePath()) {
   // No lvalue path: just print the offset.
   CharUnits O = getLValueOffset();
-  CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : CharUnits::Zero();
+  CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
+  CharUnits::Zero())
+: CharUnits::Zero();
   if (!O.isZero()) {
 if (IsReference)
   Out << "*(";
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2963,6 +2963,20 @@
   EXPECT_EQ(HI->Documentation, "Foo bar baz");
 }
 
+TEST(Hover, ForwardStructNoCrash) {
+  Annotations T(R"cpp(
+  struct Foo;
+  int bar;
+  auto baz = (Fo^o*)&bar;
+)cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto HI = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(HI);
+  EXPECT_EQ(*HI->Value, "&bar");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

Peanut gallery says: It seems like `Proto->canThrow()` is already returning the 
correct answer for C++17-and-later: a function declared `throw()` cannot throw. 
So from the POV of C++17-and-later, this could be a simple patch:

  - if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
  + if (Proto->canThrow() == CT_Cannot) {

and the only reason we can't do this is because C++14-and-earlier needs a 
different behavior.

Meanwhile, it looks as if every other use of `isNoexceptExceptionSpec` (or its 
inverse `isDynamicExceptionSpec`) is related to pretty-printing the exception 
specification, and isn't used for semantics at all.
Perhaps a cleaner way to preserve the current special case for 
C++14-and-earlier is to add a "language version" parameter to `canThrow`, 
and/or introduce an `isEssentiallyNoexcept()` helper:

  - if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
  + if (Proto->isEssentiallyNoexcept(getLangOpts())) {


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

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


[PATCH] D112914: Misleading identifier detection

2021-11-10 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

@serge-sans-paille Still failing on 
https://lab.llvm.org/buildbot/#/builders/139/builds/12974


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112914

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


[PATCH] D112914: Misleading identifier detection

2021-11-10 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp:3
+
+#include 
+

@serge-sans-paille Any chance you can remove the include and just forward 
declare printf()?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112914

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


[PATCH] D112492: [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

I did an experiment regarding the ICF issue and it seems not to affect kernel 
stub.

  #include "hip/hip_runtime.h"
  
  template
  void bar(T x) { }
  
  template
  __global__ void foo(T x) {}
  
  int main() {
foo<<<1,1>>>(1);
printf("%p\n", foo);
printf("%p\n", foo);
printf("%p\n", bar);
printf("%p\n", bar);
  }

If I pass `-Wl,/opt:noicf`, I got

  7FF622A01100
  7FF622A01170
  7FF622A01360
  7FF622A01370

By default, I got

  7FF693521100
  7FF693521170
  7FF693521360
  7FF693521360

This indicates bar and bar are folded but kernel stubs are not 
folded.

I also tried `-Wl,/opt:icf=10`, and kernel stubs are still not folded.

For HIP, since the kernel stub passes a unique kernel symbol to the internal 
kernel launching API, you may think the kernel stubs are not folded because 
they are not identical.

To imitate the CUDA case, where the address of kernel stub function itself is 
passed to the internal kernel launching API, I used the original patch of this 
review, where the kernel stub function passes the address of itself to the 
internal kernel launching API, therefore in a sense, the kernel stubs are all 
the same. Still, the kernel stubs are not folded.

Looking at the assembly of the kernel stub function:

  ; foo
  .seh_proc "??$foo@H@@YAXH@Z"
  # %bb.0:
  pushq   %rsi
  .seh_pushreg %rsi
  pushq   %rdi
  .seh_pushreg %rdi
  subq$120, %rsp
  .seh_stackalloc 120
  .seh_endprologue
  movl%ecx, 60(%rsp)
  leaq60(%rsp), %rax
  movq%rax, 64(%rsp)
  leaq104(%rsp), %rsi
  leaq88(%rsp), %rdi
  leaq80(%rsp), %r8
  leaq72(%rsp), %r9
  movq%rsi, %rcx
  movq%rdi, %rdx
  callq   __hipPopCallConfiguration
  movq80(%rsp), %rax
  movq72(%rsp), %rcx
  movq%rcx, 40(%rsp)
  movq%rax, 32(%rsp)
  leaq"??$foo@H@@YAXH@Z"(%rip), %rcx
  leaq64(%rsp), %r9
  movq%rsi, %rdx
  movq%rdi, %r8
  callq   hipLaunchKernel
  nop
  addq$120, %rsp
  popq%rdi
  popq%rsi
  retq
  .seh_endproc
  
  ; foo
  .seh_proc "??$foo@M@@YAXM@Z"
  # %bb.0:
  pushq   %rsi
  .seh_pushreg %rsi
  pushq   %rdi
  .seh_pushreg %rdi
  subq$120, %rsp
  .seh_stackalloc 120
  .seh_endprologue
  movss   %xmm0, 60(%rsp)
  leaq60(%rsp), %rax
  movq%rax, 64(%rsp)
  leaq104(%rsp), %rsi
  leaq88(%rsp), %rdi
  leaq80(%rsp), %r8
  leaq72(%rsp), %r9
  movq%rsi, %rcx
  movq%rdi, %rdx
  callq   __hipPopCallConfiguration
  movq80(%rsp), %rax
  movq72(%rsp), %rcx
  movq%rcx, 40(%rsp)
  movq%rax, 32(%rsp)
  leaq"??$foo@M@@YAXM@Z"(%rip), %rcx
  leaq64(%rsp), %r9
  movq%rsi, %rdx
  movq%rdi, %r8
  callq   hipLaunchKernel
  nop
  addq$120, %rsp
  popq%rdi
  popq%rsi
  retq
  .seh_endproc

I think they are not folded because link.exe is smart enough to treat them as 
not identical comdat functions. I think we may stop worrying about the ICF 
foading kernel stubs.


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

https://reviews.llvm.org/D112492

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


[clang] 4860f6c - [OpenMP] Fix: opposite attributes could be set by -fno-inline

2021-11-10 Thread Igor Kirillov via cfe-commits

Author: Igor Kirillov
Date: 2021-11-10T16:48:09Z
New Revision: 4860f6cb25bd20b0fc2f20403602526df650d7ed

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

LOG: [OpenMP] Fix: opposite attributes could be set by -fno-inline

After the changes introduced by D106799 it is possible to tag
outlined function with both AlwaysInline and NoInline attributes using
-fno-inline command line options.
This issue is similiar to D107649.

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/parallel_if_codegen_PR51349.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 3dbebc5d3296..2cf01939d9b6 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -518,8 +518,10 @@ static llvm::Function *emitOutlinedFunctionPrologue(
   F->setDoesNotRecurse();
 
   // Always inline the outlined function if optimizations are enabled.
-  if (CGM.getCodeGenOpts().OptimizationLevel != 0)
+  if (CGM.getCodeGenOpts().OptimizationLevel != 0) {
+F->removeFnAttr(llvm::Attribute::NoInline);
 F->addFnAttr(llvm::Attribute::AlwaysInline);
+  }
 
   // Generate the function.
   CGF.StartFunction(CD, Ctx.VoidTy, F, FuncInfo, TargetArgs,
@@ -5364,8 +5366,6 @@ static llvm::Function 
*emitOutlinedOrderedFunction(CodeGenModule &CGM,
   CGF.CapturedStmtInfo = &CapStmtInfo;
   llvm::Function *Fn = CGF.GenerateOpenMPCapturedStmtFunction(*S, Loc);
   Fn->setDoesNotRecurse();
-  if (CGM.getCodeGenOpts().OptimizationLevel != 0)
-Fn->addFnAttr(llvm::Attribute::AlwaysInline);
   return Fn;
 }
 

diff  --git a/clang/test/OpenMP/parallel_if_codegen_PR51349.cpp 
b/clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
index a00b5ec95ca0..982156054e45 100644
--- a/clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
+++ b/clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
@@ -1,5 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --include-generated-funcs
 // RUN: %clang_cc1 -x c++ -O1 -fopenmp-version=45 -disable-llvm-optzns -verify 
-fopenmp -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s 
--check-prefix=CHECK
+// RUN: %clang_cc1 -x c++ -O1 -fopenmp-version=45 -disable-llvm-optzns -verify 
-fopenmp -triple x86_64-unknown-linux -emit-llvm -fno-inline %s -o - | 
FileCheck %s --check-prefix=CHECK-NOINLINE
 // expected-no-diagnostics
 
 #ifndef HEADER
@@ -8,6 +9,8 @@
 void foo() {
 #pragma omp parallel if(0)
   ;
+#pragma omp parallel
+  ;
 }
 
 #endif
@@ -23,6 +26,7 @@ void foo() {
 // CHECK-NEXT:store i32 0, i32* [[DOTBOUND_ZERO_ADDR]], align 4
 // CHECK-NEXT:call void @.omp_outlined.(i32* [[DOTTHREADID_TEMP_]], i32* 
[[DOTBOUND_ZERO_ADDR]]) #[[ATTR2:[0-9]+]]
 // CHECK-NEXT:call void @__kmpc_end_serialized_parallel(%struct.ident_t* 
@[[GLOB1]], i32 [[TMP0]])
+// CHECK-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))
 // CHECK-NEXT:ret void
 //
 //
@@ -36,3 +40,52 @@ void foo() {
 // CHECK-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], 
align 8, !tbaa [[TBAA7]]
 // CHECK-NEXT:ret void
 //
+//
+// CHECK: Function Attrs: alwaysinline norecurse nounwind
+// CHECK-LABEL: define {{[^@]+}}@.omp_outlined..1
+// CHECK-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias 
[[DOTBOUND_TID_:%.*]]) #[[ATTR3:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** 
[[DOTGLOBAL_TID__ADDR]], align 8, !tbaa [[TBAA7]]
+// CHECK-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], 
align 8, !tbaa [[TBAA7]]
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-NOINLINE: Function Attrs: mustprogress noinline nounwind
+// CHECK-NOINLINE-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-NOINLINE-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NOINLINE-NEXT:  entry:
+// CHECK-NOINLINE-NEXT:[[DOTTHREADID_TEMP_:%.*]] = alloca i32, align 4
+// CHECK-NOINLINE-NEXT:[[DOTBOUND_ZERO_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NOINLINE-NEXT:[[TMP0:%.*]] = call i32 
@__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
+// CHECK-NOINLINE-NEXT:call void 
@__kmpc_serialized_parallel(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NOINLINE-NEXT:store i32 [[TMP0]], i32* [[DOTTHREADID_TEMP_]], 
align 4, !tbaa [[TBAA3:![0-9]+]]
+// CHECK-NOINLINE-NEXT:store i32 0, i32* [[DOTBOUND_ZERO

[PATCH] D112645: [OpenMP] Fix: opposite attributes could be set by -fno-inline

2021-11-10 Thread Igor Kirillov 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 rG4860f6cb25bd: [OpenMP] Fix: opposite attributes could be set 
by -fno-inline (authored by igor.kirillov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112645

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/parallel_if_codegen_PR51349.cpp

Index: clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
===
--- clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
+++ clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
@@ -1,5 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --check-attributes --include-generated-funcs
 // RUN: %clang_cc1 -x c++ -O1 -fopenmp-version=45 -disable-llvm-optzns -verify -fopenmp -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -x c++ -O1 -fopenmp-version=45 -disable-llvm-optzns -verify -fopenmp -triple x86_64-unknown-linux -emit-llvm -fno-inline %s -o - | FileCheck %s --check-prefix=CHECK-NOINLINE
 // expected-no-diagnostics
 
 #ifndef HEADER
@@ -8,6 +9,8 @@
 void foo() {
 #pragma omp parallel if(0)
   ;
+#pragma omp parallel
+  ;
 }
 
 #endif
@@ -23,6 +26,7 @@
 // CHECK-NEXT:store i32 0, i32* [[DOTBOUND_ZERO_ADDR]], align 4
 // CHECK-NEXT:call void @.omp_outlined.(i32* [[DOTTHREADID_TEMP_]], i32* [[DOTBOUND_ZERO_ADDR]]) #[[ATTR2:[0-9]+]]
 // CHECK-NEXT:call void @__kmpc_end_serialized_parallel(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))
 // CHECK-NEXT:ret void
 //
 //
@@ -36,3 +40,52 @@
 // CHECK-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8, !tbaa [[TBAA7]]
 // CHECK-NEXT:ret void
 //
+//
+// CHECK: Function Attrs: alwaysinline norecurse nounwind
+// CHECK-LABEL: define {{[^@]+}}@.omp_outlined..1
+// CHECK-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOTBOUND_TID_:%.*]]) #[[ATTR3:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8, !tbaa [[TBAA7]]
+// CHECK-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8, !tbaa [[TBAA7]]
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-NOINLINE: Function Attrs: mustprogress noinline nounwind
+// CHECK-NOINLINE-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-NOINLINE-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NOINLINE-NEXT:  entry:
+// CHECK-NOINLINE-NEXT:[[DOTTHREADID_TEMP_:%.*]] = alloca i32, align 4
+// CHECK-NOINLINE-NEXT:[[DOTBOUND_ZERO_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NOINLINE-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
+// CHECK-NOINLINE-NEXT:call void @__kmpc_serialized_parallel(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NOINLINE-NEXT:store i32 [[TMP0]], i32* [[DOTTHREADID_TEMP_]], align 4, !tbaa [[TBAA3:![0-9]+]]
+// CHECK-NOINLINE-NEXT:store i32 0, i32* [[DOTBOUND_ZERO_ADDR]], align 4
+// CHECK-NOINLINE-NEXT:call void @.omp_outlined.(i32* [[DOTTHREADID_TEMP_]], i32* [[DOTBOUND_ZERO_ADDR]]) #[[ATTR2:[0-9]+]]
+// CHECK-NOINLINE-NEXT:call void @__kmpc_end_serialized_parallel(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
+// CHECK-NOINLINE-NEXT:call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))
+// CHECK-NOINLINE-NEXT:ret void
+//
+//
+// CHECK-NOINLINE: Function Attrs: noinline norecurse nounwind
+// CHECK-NOINLINE-LABEL: define {{[^@]+}}@.omp_outlined.
+// CHECK-NOINLINE-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOTBOUND_TID_:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-NOINLINE-NEXT:  entry:
+// CHECK-NOINLINE-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NOINLINE-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
+// CHECK-NOINLINE-NEXT:store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8, !tbaa [[TBAA7:![0-9]+]]
+// CHECK-NOINLINE-NEXT:store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8, !tbaa [[TBAA7]]
+// CHECK-NOINLINE-NEXT:ret void
+//
+//
+// CHECK-NOINLINE: Function Attrs: alwaysinline norecurse nounwind
+// CHECK-NOINLINE-LABEL: define {{[^@]+}}@.omp_outlined..1
+// CHECK-NOINLINE-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOT

[PATCH] D112431: [ARM][clang] Define feature test macro for the PACBTI-M extension

2021-11-10 Thread Ties Stuij via Phabricator via cfe-commits
stuij updated this revision to Diff 386195.
stuij added a comment.

addressing review comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112431

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  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
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s 
-o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s 
-o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.h
===
--- clang/lib/Basic/Targets/ARM.h
+++ clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasPAC)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
+  if (HasBTI)
+Builder.defineMacro("__ARM_FEATURE_BTI", "1");
+
   if (HasBFloat16) {
 Builder.defineMacro("__ARM_FEATURE_BF16", "1");
 Builder.defineMacro("__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", "1");


Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -896,6 +896,13 @@
 // CHECK-PAC-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 5
 // CHECK-PAC-BKEY-LEAF: #define __ARM_FEATURE_PAC_DEFAULT 6
 
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-NOBTI-EXT,CHECK-NOPAC-EXT %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv7-m+pacbti -x c -E -dM %s -o - | FileCheck --check-prefixes=CHECK-PACBTI-EXT %s
+// CHECK-NOBTI-EXT-NOT: #define __ARM_FEATURE_BTI 1
+// CHECK-NOPAC-EXT-NOT: #define __ARM_FEATURE_PAUTH 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_BTI 1
+// CHECK-PACBTI-EXT: #define __ARM_FEATURE_PAUTH 1
+
 // == Check BFloat16 Extensions.
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.6-a+bf16 -x c -E -dM %s -o - 2>&1 | FileCheck -check-prefix=CHECK-BFLOAT %s
 // CHECK-BFLOAT: #define __ARM_BF16_FORMAT_ALTERNATIVE 1
Index: clang/lib/Basic/Targets/ARM.h
===
--- clang/lib/Basic/Targets/ARM.h
+++ clang/lib/Basic/Targets/ARM.h
@@ -79,6 +79,8 @@
   unsigned DotProd : 1;
   unsigned HasMatMul : 1;
   unsigned FPRegsDisabled : 1;
+  unsigned HasPAC : 1;
+  unsigned HasBTI : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -465,6 +465,8 @@
   HWDiv = 0;
   DotProd = 0;
   HasMatMul = 0;
+  HasPAC = 0;
+  HasBTI = 0;
   HasFloat16 = true;
   ARMCDECoprocMask = 0;
   HasBFloat16 = false;
@@ -547,6 +549,9 @@
   HasBFloat16 = true;
 } else if (Feature == "-fpregs") {
   FPRegsDisabled = true;
+} else if (Feature == "+pacbti") {
+  HasPAC = 1;
+  HasBTI = 1;
 }
   }
 
@@ -890,6 +895,12 @@
   if (HasMatMul)
 Builder.defineMacro("__ARM_FEATURE_MATMUL_INT8", "1");
 
+  if (HasPAC)
+Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
+
+  if (HasBTI)
+Bu

[PATCH] D110927: [analyzer] Access stored value of a constant array through a pointer to another type

2021-11-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D110927#3118936 , @ASDenysPetrov 
wrote:

>> You could have a parameter, and take its address to accomplish your 
>> reinterpret casts and type puns.
>
> Do you mean: ...
> If so, IMO it doesn't matter.

I see. Sorry about the confusion I caused.

In D110927#3115795 , @ASDenysPetrov 
wrote:

> Does anyone know how to check the status of`-fno-strict-aliasing` flag from 
> CSA side?

I think I know.
Within the `AnalysisConsumer::AnalysisConsumer()` you have access to the 
`CompilerInstance` object. Using that you can acquire the 
`CI.getCodeGenOpts().RelaxedAliasing` bool member, which represents exactly 
what we need, according to the 
`clang/include/clang/Basic/CodeGenOptions.def:211`:

  CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.

I think you should simply save a `const` reference to the `CodeGenOptions` 
object from the `AnalysisConsumer`.




Comment at: clang/test/Analysis/initialization.cpp:295-299
+void glob_cast_opposite_sign1() {
+  auto *ptr = (unsigned int *)glob_arr2;
+  auto x1 = ptr[0]; // no-warning
+  auto x2 = ptr[1]; // expected-warning{{garbage or undefined}}
+}

ASDenysPetrov wrote:
> steakhal wrote:
> > I think it's not correct.
> > 
> > `glob_arr2` refers to an object of dynamic type `int[2]`.
> > And the pointer decayed from it is `int *`, which has //similar type// to 
> > `unsigned *` what you are using to access the memory.
> > Since they are //similar//, this operation should work for all the valid 
> > indices, thus `ptr[0]`, `ptr[1]`, `ptr[2]`, `ptr[3]` should all be valid.
> > 
> > 
> > glob_arr2 refers to an object of dynamic type int[2].
> `glob_arr2` has an extent of 4.
> > And the pointer decayed from it is int *, which has similar type to 
> > unsigned * what you are using to access the memory.
> Yes, they are the same and it perfectly suits to 
> http://eel.is/c++draft/basic.lval#11 . But still you can't access other 
> element then the first one according to 
> http://eel.is/c++draft/basic.compound#3 : //For purposes of pointer 
> arithmetic ([expr.add]) and comparison ([expr.rel], [expr.eq]), [...] an 
> object of type T that is not an array element is considered to belong to an 
> array with one element of type T. //
> `unsigned int` and `int` are different types according to 
> http://eel.is/c++draft/basic.fundamental#2 . The object of type `unsigned 
> int` is NOT an array, beacuse there is no array of type `unsigned int`. Hence 
> you can only only access the first and a single element of type `unsigned 
> int`.
> 
Yes, `glob_arr` has 4 elements, sorry for this typo.

---
I disagree with the second part though. It seems like gcc disagrees as well: 
https://godbolt.org/z/5o7ozvPar
```lang=C++
auto foo(unsigned (&p)[4], int (&q)[4]) {
p[0] = 2;
q[0] = 1;
return p[0]; // memory read! thus, p and q can alias according to g++.
}
```
`gcc` still thinks that `p` and `q` can refer to the same memory region even if 
the `-fstrict-aliasing` flag is present.
In other circumstances, it would produce a `mov eax, 2` instead of a memory 
load if `p` and `q` cannot alias.


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

https://reviews.llvm.org/D110927

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


[clang] 48bb5f4 - [clang] Add early exit when checking for const init of arrays.

2021-11-10 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-11-10T18:11:21+01:00
New Revision: 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3

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

LOG: [clang] Add early exit when checking for const init of arrays.

Before this commit, on code like:

  struct S { ... };
  S arr[1000];

while checking if arr is constexpr, clang would reserve memory for
arr before running constructor for S. If S turned out to not have a
valid constexpr c-tor, clang would still try to initialize each element
(and, in case the c-tor was trivial, even skipping the constexpr step
limit), only to discard that whole APValue later, since the first
element generated a diagnostic.

With this change, we start by allocating just 1 element in the array to
try out the c-tor and take an early exit if any diagnostics are
generated, avoiding possibly large memory allocation and a lot of work
initializing to-be-discarded APValues.

Fixes 51712 and 51843.

In the future we may want to be smarter about large possibly-constexrp
arrays and maybe make the allocation lazy.

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

Added: 
clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp

Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fa0d22064f0eb..a6da3d3fbea2d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10596,28 +10596,55 @@ bool ArrayExprEvaluator::VisitCXXConstructExpr(const 
CXXConstructExpr *E,
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned N = CAT->getSize().getZExtValue();
+unsigned FinalSize = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), N, N);
-
-if (HadZeroInit)
-  for (unsigned I = 0; I != N; ++I)
-Value->getArrayInitializedElt(I) = Filler;
+*Value = APValue(APValue::UninitArray(), 0, FinalSize);
+if (FinalSize == 0)
+  return true;
 
-// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-for (unsigned I = 0; I != N; ++I)
-  if (!VisitCXXConstructExpr(E, ArrayElt, 
&Value->getArrayInitializedElt(I),
- CAT->getElementType()) ||
-  !HandleLValueArrayAdjustment(Info, E, ArrayElt,
-   CAT->getElementType(), 1))
-return false;
+// We do the whole initialization in two passes, first for just one 
element,
+// then for the whole array. It's possible we may find out we can't do 
const
+// init in the first pass, in which case we avoid allocating a potentially
+// large array. We don't do more passes because expanding array requires
+// copying the data, which is wasteful.
+for (const unsigned N : {1u, FinalSize}) {
+  unsigned OldElts = Value->getArrayInitializedElts();
+  if (OldElts == N)
+break;
+
+  // Expand the array to appropriate size.
+  APValue NewValue(APValue::UninitArray(), N, FinalSize);
+  for (unsigned I = 0; I < OldElts; ++I)
+NewValue.getArrayInitializedElt(I).swap(
+Value->getArrayInitializedElt(I));
+  Value->swap(NewValue);
+
+  if (HadZeroInit)
+for (unsigned I = OldElts; I < N; ++I)
+  Value->getArrayInitializedElt(I) = Filler;
+
+  // Initialize the elements.
+  for (unsigned I = OldElts; I < N; ++I) {
+if (!VisitCXXConstructExpr(E, ArrayElt,
+   &Value->getArrayInitializedElt(I),
+   CAT->getElementType()) ||
+!HandleLValueArrayAdjustment(Info, E, ArrayElt,
+ CAT->getElementType(), 1))
+  return false;
+// When checking for const initilization any diagnostic is considered
+// an error.
+if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
+!Info.keepEvaluatingAfterFailure())
+  return false;
+  }
+}
 
 return true;
   }

diff  --git a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp 
b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
new file mode 100644
index 0..4504c0caed55f
--- /dev/null
+++ b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -0,0 +1,11 @@
+// REQUIRES: shell
+// UNSUPPORTED: win32
+// RUN: ulimit -v 1048576
+// RUN: %clang_cc1 -std=c++11 -fs

[PATCH] D113120: [clang] Add early exit when checking for const init of arrays.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG48bb5f4cbe8d: [clang] Add early exit when checking for const 
init of arrays. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113120

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -0,0 +1,11 @@
+// REQUIRES: shell
+// UNSUPPORTED: win32
+// RUN: ulimit -v 1048576
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// This used to require too much memory and crash with OOM.
+struct {
+  int a, b, c, d;
+} arr[1<<30];
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,28 +10596,55 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned N = CAT->getSize().getZExtValue();
+unsigned FinalSize = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), N, N);
-
-if (HadZeroInit)
-  for (unsigned I = 0; I != N; ++I)
-Value->getArrayInitializedElt(I) = Filler;
+*Value = APValue(APValue::UninitArray(), 0, FinalSize);
+if (FinalSize == 0)
+  return true;
 
-// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-for (unsigned I = 0; I != N; ++I)
-  if (!VisitCXXConstructExpr(E, ArrayElt, 
&Value->getArrayInitializedElt(I),
- CAT->getElementType()) ||
-  !HandleLValueArrayAdjustment(Info, E, ArrayElt,
-   CAT->getElementType(), 1))
-return false;
+// We do the whole initialization in two passes, first for just one 
element,
+// then for the whole array. It's possible we may find out we can't do 
const
+// init in the first pass, in which case we avoid allocating a potentially
+// large array. We don't do more passes because expanding array requires
+// copying the data, which is wasteful.
+for (const unsigned N : {1u, FinalSize}) {
+  unsigned OldElts = Value->getArrayInitializedElts();
+  if (OldElts == N)
+break;
+
+  // Expand the array to appropriate size.
+  APValue NewValue(APValue::UninitArray(), N, FinalSize);
+  for (unsigned I = 0; I < OldElts; ++I)
+NewValue.getArrayInitializedElt(I).swap(
+Value->getArrayInitializedElt(I));
+  Value->swap(NewValue);
+
+  if (HadZeroInit)
+for (unsigned I = OldElts; I < N; ++I)
+  Value->getArrayInitializedElt(I) = Filler;
+
+  // Initialize the elements.
+  for (unsigned I = OldElts; I < N; ++I) {
+if (!VisitCXXConstructExpr(E, ArrayElt,
+   &Value->getArrayInitializedElt(I),
+   CAT->getElementType()) ||
+!HandleLValueArrayAdjustment(Info, E, ArrayElt,
+ CAT->getElementType(), 1))
+  return false;
+// When checking for const initilization any diagnostic is considered
+// an error.
+if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
+!Info.keepEvaluatingAfterFailure())
+  return false;
+  }
+}
 
 return true;
   }


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -0,0 +1,11 @@
+// REQUIRES: shell
+// UNSUPPORTED: win32
+// RUN: ulimit -v 1048576
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// This used to require too much memory and crash with OOM.
+struct {
+  int a, b, c, d;
+} arr[1<<30];
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,28 +10596,55 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned N = CAT->getSize().getZExtValue();
+unsigned FinalSize = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit 

[PATCH] D113575: Add `isInitCapture` and `forEachLambdaCapture` matchers.

2021-11-10 Thread James King via Phabricator via cfe-commits
jcking1034 created this revision.
jcking1034 added reviewers: ymandel, tdl-g, aaron.ballman, fowles.
jcking1034 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This contributes follow-up work from https://reviews.llvm.org/D112491, which
allows for increased control over the matching of lambda captures. This also
updates the documentation for the `lambdaCapture` matcher.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113575

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -4769,6 +4769,36 @@
 cxxConstructorDecl(forEachConstructorInitializer(cxxCtorInitializer();
 }
 
+TEST(ForEachLambdaCapture, MatchesCaptures) {
+  EXPECT_TRUE(matches(
+  "int main() { int x, y; auto f = [x, y]() { return x + y; }; }",
+  lambdaExpr(forEachLambdaCapture(lambdaCapture())), langCxx11OrLater()));
+  auto matcher = lambdaExpr(forEachLambdaCapture(
+  lambdaCapture(capturesVar(varDecl(hasType(isInteger().bind("LC")));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "int main() { int x, y; float z; auto f = [=]() { return x + y + z; }; }",
+  matcher, std::make_unique>("LC", 2)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "int main() { int x, y; float z; auto f = [x, y, z]() { return x + y + "
+  "z; }; }",
+  matcher, std::make_unique>("LC", 2)));
+}
+
+TEST(ForEachLambdaCapture, IgnoreUnlessSpelledInSource) {
+  auto matcher =
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   lambdaExpr(forEachLambdaCapture(
+   lambdaCapture(capturesVar(varDecl(hasType(isInteger()
+   .bind("LC";
+  EXPECT_TRUE(
+  notMatches("int main() { int x, y; auto f = [=]() { return x + y; }; }",
+ matcher, langCxx11OrLater()));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "int main() { int x, y; float z; auto f = [=, &y]() { return x + y + z; "
+  "}; }",
+  matcher, std::make_unique>("LC", 1)));
+}
+
 TEST(HasConditionVariableStatement, DoesNotMatchCondition) {
   EXPECT_TRUE(notMatches(
 "void x() { if(true) {} }",
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1439,6 +1439,22 @@
   EXPECT_TRUE(notMatches("int X;", M));
 }
 
+TEST_P(ASTMatchersTest, IsInitCapture) {
+  if (!GetParam().isCXX11OrLater()) {
+return;
+  }
+  auto M = varDecl(hasName("vd"), isInitCapture());
+  EXPECT_TRUE(notMatches(
+  "int main() { int vd = 3; auto f = [vd]() { return vd; }; }", M));
+
+  if (!GetParam().isCXX14OrLater()) {
+return;
+  }
+  EXPECT_TRUE(matches("int main() { auto f = [vd=3]() { return vd; }; }", M));
+  EXPECT_TRUE(matches(
+  "int main() { int x = 3; auto f = [vd=x]() { return vd; }; }", M));
+}
+
 TEST_P(ASTMatchersTest, StorageDuration) {
   StringRef T =
   "void f() { int x; static int y; } int a;static int b;extern int c;";
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -246,6 +246,7 @@
   REGISTER_MATCHER(forEachArgumentWithParamType);
   REGISTER_MATCHER(forEachConstructorInitializer);
   REGISTER_MATCHER(forEachDescendant);
+  REGISTER_MATCHER(forEachLambdaCapture);
   REGISTER_MATCHER(forEachOverridden);
   REGISTER_MATCHER(forEachSwitchCase);
   REGISTER_MATCHER(forField);
@@ -424,6 +425,7 @@
   REGISTER_MATCHER(isImplicit);
   REGISTER_MATCHER(isInStdNamespace);
   REGISTER_MATCHER(isInTemplateInstantiation);
+  REGISTER_MATCHER(isInitCapture);
   REGISTER_MATCHER(isInline);
   REGISTER_MATCHER(isInstanceMessage);
   REGISTER_MATCHER(isInstanceMethod);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4205,6 +4205,45 @@
   InnerMatcher.matches(*Initializer, Finder, Builder));
 }
 
+/// Matches a variable serving as the implicit variable for a lambda init-
+/// capture.
+///
+/// Example matches x (matcher = varDecl(isInitCapture()))
+/// \code
+/// auto f = [x=3]() { return x; };
+/// \endcode
+AST_MATCHER(VarDecl, isInitCapture) { return Node.isInitCapture(); }
+
+/// Matches each lambda capture in

[PATCH] D51650: Implement target_clones multiversioning

2021-11-10 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss added a comment.

Thanks for the rebase!

Looks got to me,

`-march` may make the default same as one of the clone, in this case maybe we 
don't need to create two versions of the function. This could be solved later 
IMHO.




Comment at: clang/lib/Sema/SemaDecl.cpp:10662
+  return false;
+  break;
+}




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

https://reviews.llvm.org/D51650

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


[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

2021-11-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Very solid patch!




Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:98
   QualType PointeeTy = CastToTy->getPointeeType();
   QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
 

You only use `CanonPointeeTy.getLocalUnqualifiedType()` all the places. Spell 
it once and reuse it everywhere.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:104
 
-  // Handle casts from compatible types.
-  if (R->isBoundable())
+  const auto IsSameRegionType = [&Ctx, CanonPointeeTy](const MemRegion *R) {
 if (const auto *TR = dyn_cast(R)) {

For me at least, a name like `IsSameRegionType()` would imply a function with 
two parameters.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:115
+  // Handle casts from compatible types.
+  if (R->isBoundable() && IsSameRegionType(R))
+return R;

BTW do you know what `isBoundable()` is? I'm just curious.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:184
+// Edge case: we are at 0 bytes off the beginning of baseR. We
 // check to see if type we are casting to is the same as the base
+// region. If so, just return the base region.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113480

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


[PATCH] D51650: Implement target_clones multiversioning

2021-11-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 386205.
erichkeane marked an inline comment as done.
erichkeane added a comment.

For the rest of multiversioning we count on the optimizer to remove variants 
made irrelevant, but I'm not sure opt can do anything like that yet :)  But nit 
made.


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

https://reviews.llvm.org/D51650

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-target-clones.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-cpuspecific.c
  clang/test/Sema/attr-target-clones.c

Index: clang/test/Sema/attr-target-clones.c
===
--- /dev/null
+++ clang/test/Sema/attr-target-clones.c
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify %s
+
+// expected-error@+1 {{'target_clones' multiversioning requires a default target}}
+void __attribute__((target_clones("sse4.2", "arch=sandybridge")))
+no_default(void);
+
+// expected-error@+2 {{'target_clones' and 'target' attributes are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void __attribute__((target("sse4.2"), target_clones("arch=sandybridge")))
+ignored_attr(void);
+// expected-error@+2 {{'target' and 'target_clones' attributes are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void __attribute__((target_clones("arch=sandybridge,default"), target("sse4.2")))
+ignored_attr2(void);
+
+int redecl(void);
+int __attribute__((target_clones("sse4.2", "default"))) redecl(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2", "default"))) redecl2(void);
+int __attribute__((target_clones("sse4.2", "default"))) redecl2(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2", "default"))) redecl3(void);
+int redecl3(void);
+
+int __attribute__((target_clones("sse4.2", "arch=atom", "default"))) redecl4(void);
+// expected-error@+3 {{'target_clones' attribute does not match previous declaration}}
+// expected-note@-2 {{previous declaration is here}}
+int __attribute__((target_clones("sse4.2", "arch=sandybridge", "default")))
+redecl4(void) { return 1; }
+
+int __attribute__((target("sse4.2"))) redef2(void) { return 1; }
+// expected-error@+2 {{multiversioning attributes cannot be combined}}
+// expected-note@-2 {{previous declaration is here}}
+int __attribute__((target_clones("sse4.2", "default"))) redef2(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2,default"))) redef3(void) { return 1; }
+// expected-error@+2 {{redefinition of 'redef3'}}
+// expected-note@-2 {{previous definition is here}}
+int __attribute__((target_clones("sse4.2,default"))) redef3(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2,default"))) redef4(void) { return 1; }
+// expected-error@+2 {{redefinition of 'redef4'}}
+// expected-note@-2 {{previous definition is here}}
+int __attribute__((target_clones("sse4.2,default"))) redef4(void) { return 1; }
+
+// Duplicates are allowed, however they alter name mangling.
+// expected-warning@+2 {{mixing 'target_clones' specifier mechanisms is permitted for GCC compatibility}}
+// expected-warning@+1 2 {{version list contains duplicate entries}}
+int __attribute__((target_clones("arch=atom,arch=atom", "arch=atom,default")))
+dupes(void) { return 1; }
+
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("")))
+empty_target_1(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones(",default")))
+empty_target_2(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default,")))
+empty_target_3(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default, ,avx2")))
+empty_target_4(void);
+
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default,avx2", "")))
+empty_target_5(void);
+
+// expected-warning@+1 {{version list contains duplicate entries}}
+void __attribute__((target_clones("default", "default")))
+dupe_default(void);
+
+// expected-warning@+1 {{version list contains duplicate entries}}
+void __attribute__((target_clones("avx2,avx2,default")))
+dupe_normal(void);
+
+// expected-error@+2 {{'target_clones' and 'target_clones' attributes are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void __attribute__((target_

[PATCH] D113555: [clangd] Mark macros from preamble for code completion

2021-11-10 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 accepted this revision.
usaxena95 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:567
 S.CanonicalDeclaration = R.Location;
+if (!HeaderFileURIs->getIncludeHeader(SM.getMainFileID()).empty()) {
+  S.Flags |= Symbol::IndexedForCodeCompletion;

Please add a comment about this (maybe similar to the parch description)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113555

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


[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

2021-11-10 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:98
   QualType PointeeTy = CastToTy->getPointeeType();
   QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
 

steakhal wrote:
> You only use `CanonPointeeTy.getLocalUnqualifiedType()` all the places. Spell 
> it once and reuse it everywhere.
Make sense!



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:104
 
-  // Handle casts from compatible types.
-  if (R->isBoundable())
+  const auto IsSameRegionType = [&Ctx, CanonPointeeTy](const MemRegion *R) {
 if (const auto *TR = dyn_cast(R)) {

steakhal wrote:
> For me at least, a name like `IsSameRegionType()` would imply a function with 
> two parameters.
I'll carry `CanonPointeeTy` out.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:115
+  // Handle casts from compatible types.
+  if (R->isBoundable() && IsSameRegionType(R))
+return R;

steakhal wrote:
> BTW do you know what `isBoundable()` is? I'm just curious.
I've looked for information about it. It's poor, I'd say there is nothing of 
it. I'm curious as well.



Comment at: clang/lib/StaticAnalyzer/Core/Store.cpp:184
+// Edge case: we are at 0 bytes off the beginning of baseR. We
 // check to see if type we are casting to is the same as the base
+// region. If so, just return the base region.

steakhal wrote:
> 
+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113480

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


[PATCH] D112914: Misleading identifier detection

2021-11-10 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp:3
+
+#include 
+

RKSimon wrote:
> @serge-sans-paille Any chance you can remove the include and just forward 
> declare printf()?
Sure, I'll prepare a patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112914

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


[PATCH] D113583: [clang] Fix armv7-quick build by hardcoding -triple=x86_64 in OOM test.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: kadircet.
Herald added a subscriber: kristof.beyls.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The test was added in 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3 
 and it
creates a very large array, which is too large for ARM. Making the array
smaller is not a good option, since we would need a very low ulimit and
could then hit it for other reasons.

Should fix the https://lab.llvm.org/buildbot/#/builders/171/builds/5851
failure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113583

Files:
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112492: [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I think the key is the self-reference in the LEA instruction:

>   ; foo
>   .seh_proc "??$foo@H@@YAXH@Z"
>   ...
>   leaq"??$foo@H@@YAXH@Z"(%rip), %rcx
>   ...
>   ; foo
>   .seh_proc "??$foo@M@@YAXM@Z"
>   ...
>   leaq"??$foo@M@@YAXM@Z"(%rip), %rcx
>
> I think they are not folded because link.exe is smart enough to treat them as 
> not identical comdat functions. I think we may stop worrying about the ICF 
> foading kernel stubs.

It sounds like the behavior may have changed since D63277 
 was landed, and maybe we don't need it 
anymore.


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

https://reviews.llvm.org/D112492

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


[clang] 581a6a8 - [clang] Fix armv7-quick build by hardcoding -triple=x86_64 in OOM test.

2021-11-10 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-11-10T19:24:06+01:00
New Revision: 581a6a8118f55d2662e180880558db95f808b0dc

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

LOG: [clang] Fix armv7-quick build by hardcoding -triple=x86_64 in OOM test.

The test was added in 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3 and it
creates a very large array, which is too large for ARM. Making the array
smaller is not a good option, since we would need a very low ulimit and
could then hit it for other reasons.

Should fix the https://lab.llvm.org/buildbot/#/builders/171/builds/5851
failure.

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

Added: 


Modified: 
clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp 
b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
index 4504c0caed55..1bbc1b5c863c 100644
--- a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.



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


[PATCH] D113583: [clang] Fix armv7-quick build by hardcoding -triple=x86_64 in OOM test.

2021-11-10 Thread Adam Czachorowski 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 rG581a6a8118f5: [clang] Fix armv7-quick build by hardcoding 
-triple=x86_64 in OOM test. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113583

Files:
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
@@ -1,7 +1,7 @@
 // REQUIRES: shell
 // UNSUPPORTED: win32
 // RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
 // expected-no-diagnostics
 
 // This used to require too much memory and crash with OOM.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

2021-11-10 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 386226.
ASDenysPetrov added a comment.

Updated according to comments.


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

https://reviews.llvm.org/D113480

Files:
  clang/lib/StaticAnalyzer/Core/Store.cpp
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -68,8 +68,7 @@
 void glob_invalid_index4() {
   const int *ptr = glob_arr4[1];
   int idx = -42;
-  // FIXME: Should warn {{garbage or undefined}}.
-  auto x = ptr[idx]; // no-warning
+  auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
 }
 
 int const glob_arr5[4][2] = {{1}, 3, 4, 5};
@@ -86,16 +85,11 @@
 
 void glob_ptr_index2() {
   int const *ptr = glob_arr5[1];
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(ptr[0] == 3); // expected-warning{{UNKNOWN}}
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(ptr[1] == 4); // expected-warning{{UNKNOWN}}
-  // FIXME: Should be UNDEFINED.
-  clang_analyzer_eval(ptr[2] == 5); // expected-warning{{UNKNOWN}}
-  // FIXME: Should be UNDEFINED.
-  clang_analyzer_eval(ptr[3] == 0); // expected-warning{{UNKNOWN}}
-  // FIXME: Should be UNDEFINED.
-  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(ptr[0] == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 4); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 5); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[3] == 0); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{UNDEFINED}}
 }
 
 void glob_invalid_index5() {
@@ -106,8 +100,7 @@
 void glob_invalid_index6() {
   int const *ptr = &glob_arr5[1][0];
   int idx = 42;
-  // FIXME: Should warn {{garbage or undefined}}.
-  auto x = ptr[idx]; // no-warning
+  auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
 }
 
 extern const int glob_arr_no_init[10];
Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -96,18 +96,24 @@
   // already be handled.
   QualType PointeeTy = CastToTy->getPointeeType();
   QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
+  CanonPointeeTy = CanonPointeeTy.getLocalUnqualifiedType();
 
   // Handle casts to void*.  We just pass the region through.
-  if (CanonPointeeTy.getLocalUnqualifiedType() == Ctx.VoidTy)
+  if (CanonPointeeTy == Ctx.VoidTy)
 return R;
 
-  // Handle casts from compatible types.
-  if (R->isBoundable())
+  const auto IsSameRegionType = [&Ctx](const MemRegion *R, QualType OtherTy) {
 if (const auto *TR = dyn_cast(R)) {
   QualType ObjTy = Ctx.getCanonicalType(TR->getValueType());
-  if (CanonPointeeTy == ObjTy)
-return R;
+  if (OtherTy == ObjTy.getLocalUnqualifiedType())
+return true;
 }
+return false;
+  };
+
+  // Handle casts from compatible types.
+  if (R->isBoundable() && IsSameRegionType(R, CanonPointeeTy))
+return R;
 
   // Process region cast according to the kind of the region being cast.
   switch (R->getKind()) {
@@ -174,16 +180,11 @@
   CharUnits off = rawOff.getOffset();
 
   if (off.isZero()) {
-// Edge case: we are at 0 bytes off the beginning of baseR.  We
-// check to see if type we are casting to is the same as the base
-// region.  If so, just return the base region.
-if (const auto *TR = dyn_cast(baseR)) {
-  QualType ObjTy = Ctx.getCanonicalType(TR->getValueType());
-  QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
-  if (CanonPointeeTy == ObjTy)
-return baseR;
-}
-
+// Edge case: we are at 0 bytes off the beginning of baseR. We check to
+// see if the type we are casting to is the same as the type of the base
+// region. If so, just return the base region.
+if (IsSameRegionType(baseR, CanonPointeeTy))
+  return baseR;
 // Otherwise, create a new ElementRegion at offset 0.
 return MakeElementRegion(cast(baseR), PointeeTy);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113575: Add `isInitCapture` and `forEachLambdaCapture` matchers.

2021-11-10 Thread Matt Kulukundis via Phabricator via cfe-commits
fowles added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:4224
+/// float z;
+/// auto f = [=]() { return x + y + z; };
+///   }

it would be nice to be able to do something like

```
int main() {
  int x, y;
  float z;
  auto f = [=, z]() { return x+ y + z; };
}
```

`lambdaExpr(forEachLambdaCapture(isImplicit())` matches `x` and `y` but not `z`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113575

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


[PATCH] D113585: [clang-tidy] Fix false positive in `bugprone-throw-keyword-missing` check

2021-11-10 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff created this revision.
fwolff added reviewers: steveire, alexfh, Eugene.Zelenko.
fwolff added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
fwolff requested review of this revision.
Herald added a subscriber: cfe-commits.

Fixes PR#52400. The tests for `bugprone-throw-keyword-missing` actually already 
contain exceptions as class members, but not as members with initializers, 
which was probably just an oversight.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113585

Files:
  clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -118,6 +118,7 @@
 
 class CtorInitializerListTest {
   RegularException exc;
+  RegularException exc2{};
 
   CtorInitializerListTest() : exc(RegularException()) {}
 
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -26,7 +26,7 @@
   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
   unless(anyOf(hasAncestor(stmt(
anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-   hasAncestor(varDecl()),
+   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
allOf(hasAncestor(CtorInitializerList),
  unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-throw-keyword-missing.cpp
@@ -118,6 +118,7 @@
 
 class CtorInitializerListTest {
   RegularException exc;
+  RegularException exc2{};
 
   CtorInitializerListTest() : exc(RegularException()) {}
 
Index: clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -26,7 +26,7 @@
   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
   unless(anyOf(hasAncestor(stmt(
anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
-   hasAncestor(varDecl()),
+   hasAncestor(decl(anyOf(varDecl(), fieldDecl(,
allOf(hasAncestor(CtorInitializerList),
  unless(hasAncestor(cxxCatchStmt()))
   .bind("temporary-exception-not-thrown"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113499: [clang-tidy] Reduce false positives for `bugprone-infinite-loop` with dependent expressions

2021-11-10 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff updated this revision to Diff 386244.
fwolff added a comment.

The test failed on Windows. I don't have a machine to reproduce this, but maybe 
adding `-fno-delayed-template-parsing` helps.


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

https://reviews.llvm.org/D113499

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s bugprone-infinite-loop %t \
-// RUN:   -- -- -fexceptions -fblocks
+// RUN:   -- -- -fexceptions -fblocks 
-fno-delayed-template-parsing
 
 void simple_infinite_loop1() {
   int i = 0;
@@ -622,3 +622,31 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (size) are updated in the loop body 
[bugprone-infinite-loop]
   }
 }
+
+template 
+int some_template_fn() { return 1; }
+
+template 
+void test_dependent_condition() {
+  const int error = some_template_fn();
+  do {
+  } while (false && error == 0);
+
+  const int val = some_template_fn();
+  for (; !(val == 0 || true);) {
+  }
+
+  const int val2 = some_template_fn();
+  for (; !(val2 == 0 || false);) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (val2) are updated in the loop body 
[bugprone-infinite-loop]
+  }
+
+  const int val3 = some_template_fn();
+  do {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (val3) are updated in the loop body 
[bugprone-infinite-loop]
+  } while (1, (true) && val3 == 1);
+
+  const int val4 = some_template_fn();
+  do {
+  } while (1, (false) && val4 == 1);
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -117,12 +117,31 @@
   return Result;
 }
 
-static bool isKnownFalse(const Expr &Cond, const ASTContext &Ctx) {
-  if (Cond.isValueDependent())
+static bool isKnown(const Expr &Cond, const ASTContext &Ctx, const bool Value) 
{
+  if (Cond.isValueDependent()) {
+if (const auto *BinOp = dyn_cast(&Cond)) {
+  // Conjunctions (disjunctions) can still be handled if at least one
+  // conjunct (disjunct) is known to be false (true).
+  if (!Value && BinOp->getOpcode() == BO_LAnd)
+return isKnown(*BinOp->getLHS(), Ctx, false) ||
+   isKnown(*BinOp->getRHS(), Ctx, false);
+  if (Value && BinOp->getOpcode() == BO_LOr)
+return isKnown(*BinOp->getLHS(), Ctx, true) ||
+   isKnown(*BinOp->getRHS(), Ctx, true);
+  if (BinOp->getOpcode() == BO_Comma)
+return isKnown(*BinOp->getRHS(), Ctx, Value);
+} else if (const auto *UnOp = dyn_cast(&Cond)) {
+  if (UnOp->getOpcode() == UO_LNot)
+return isKnown(*UnOp->getSubExpr(), Ctx, !Value);
+} else if (const auto *Paren = dyn_cast(&Cond))
+  return isKnown(*Paren->getSubExpr(), Ctx, Value);
+else if (const auto *ImplCast = dyn_cast(&Cond))
+  return isKnown(*ImplCast->getSubExpr(), Ctx, Value);
 return false;
+  }
   bool Result = false;
   if (Cond.EvaluateAsBooleanCondition(Result, Ctx))
-return !Result;
+return Result == Value;
   return false;
 }
 
@@ -144,7 +163,7 @@
   const auto *LoopStmt = Result.Nodes.getNodeAs("loop-stmt");
   const auto *Func = Result.Nodes.getNodeAs("func");
 
-  if (isKnownFalse(*Cond, *Result.Context))
+  if (isKnown(*Cond, *Result.Context, false))
 return;
 
   bool ShouldHaveConditionVariables = true;


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s bugprone-infinite-loop %t \
-// RUN:   -- -- -fexceptions -fblocks
+// RUN:   -- -- -fexceptions -fblocks -fno-delayed-template-parsing
 
 void simple_infinite_loop1() {
   int i = 0;
@@ -622,3 +622,31 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (size) are updated in the loop body [bugprone-infinite-loop]
   }
 }
+
+template 
+int some_template_fn() { return 1; }
+
+template 
+void test_dependent_condition() {
+  const int error = some_template_fn();
+  do {
+  } while (false && error == 0);
+
+  const int val = some_template_fn();
+

[PATCH] D113518: [clang] Create delegating constructors even in templates

2021-11-10 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp requested changes to this revision.
carlosgalvezp added a comment.
This revision now requires changes to proceed.

Amazing, thanks a lot for fixing this long-standing issue! I have a couple 
comments. I'm not familiar at all with the Sema part so someone that knows 
should look at it :)




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:374
 {
   PositiveSelfInitialization() : PositiveSelfInitialization() {}
 };

Not really sure what this test is meant to do. Why would it call the destructor 
of the own class in it's own constructor? Looks very strange to me.

If anything, the constructor should call the constructor of the base:

PositiveSelfInitialization() : NegativeAggregateType()

What do you think?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:555
+// Check that a delegating constructor in a template does not trigger false 
positives (PR#37902).
+template 
+struct TemplateWithDelegatingCtor {

typename T?

Not sure if it makes a difference



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:559
+  TemplateWithDelegatingCtor() : X{} {};
+  TemplateWithDelegatingCtor(int) : TemplateWithDelegatingCtor(){};
+};

Could you add another test where X is initialized via NSDMI instead of in the 
constructor initializer list?

int X{};
TemplateWithDelegatingCtor() = default;
TemplateWithDelegatingCtor(int) : TemplateWithDelegatingCtor() {}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113518

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


[PATCH] D113518: [clang] Create delegating constructors even in templates

2021-11-10 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Also, what's with the pre-merge test, is it related?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113518

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


[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

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

In D113517#3121455 , @jyknight wrote:

> This change allows those future optimizations to apply to throw() as well, in 
> C++17 mode, which is the desirable outcome.

I see. It seems inconsistent that `throw(X)` would still call `unexpected` but 
that `throw()` would call `terminate`, but I suppose in the `throw()` case 
there is really not much interesting that an `unexpected_handler` can do other 
than (take some logging action and) terminate the program -- in particular, it 
can't do exception translation. So maybe the inconsistency is not a big deal, 
and it's more important to get the better code generation, especially given how 
rare `throw(X)` is compared to `throw()`. OK, I think I'm convinced that this 
is the best direction.




Comment at: clang/lib/CodeGen/CGException.cpp:480-487
+  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
+  // as noexcept. In earlier standards, it is handled separately, below.
+  if ((getLangOpts().CPlusPlus17 || EST != EST_DynamicNone) &&
+  Proto->canThrow() == CT_Cannot) {
 // noexcept functions are simple terminate scopes.
 if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
   EHStack.pushTerminate();

Maybe the logic would be clearer if we swap the terminate and unexpected cases:
```
if  (EST == EST_Dynamic || (!getLangOpts().CPlusPlus17 && EST == 
EST_DynamicNone)) {
  // Prepare to call unexpected
} else if (Proto->canThrow() == CT_Cannot) {
  // Prepare to call terminate
}
```
This would keep the syntactic checks of `EST` separated from the semantic 
checks of `canThrow`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

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


[PATCH] D113126: [OpenMP][NFCI] Embed the source location string size in the ident_t

2021-11-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 386255.
jdoerfert added a comment.
Herald added a subscriber: asavonic.

update tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113126

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/barrier_codegen.cpp
  clang/test/OpenMP/for_codegen.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/parallel_num_threads_codegen.cpp
  clang/test/OpenMP/parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/parallel_proc_bind_primary_codegen.cpp
  clang/test/OpenMP/sections_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp
===
--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -1589,8 +1589,10 @@
 &F.getEntryBlock(), F.getEntryBlock().begin()));
   // Create a fallback location if non was found.
   // TODO: Use the debug locations of the calls instead.
-  Constant *Loc = OMPInfoCache.OMPBuilder.getOrCreateDefaultSrcLocStr();
-  Ident = OMPInfoCache.OMPBuilder.getOrCreateIdent(Loc);
+  uint32_t SrcLocStrSize;
+  Constant *Loc =
+  OMPInfoCache.OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize);
+  Ident = OMPInfoCache.OMPBuilder.getOrCreateIdent(Loc, SrcLocStrSize);
 }
 return Ident;
   }
@@ -3216,8 +3218,11 @@
   OpenMPIRBuilder::LocationDescription Loc(
   InsertPointTy(ParentBB, ParentBB->end()), DL);
   OMPInfoCache.OMPBuilder.updateToLocation(Loc);
-  auto *SrcLocStr = OMPInfoCache.OMPBuilder.getOrCreateSrcLocStr(Loc);
-  Value *Ident = OMPInfoCache.OMPBuilder.getOrCreateIdent(SrcLocStr);
+  uint32_t SrcLocStrSize;
+  auto *SrcLocStr =
+  OMPInfoCache.OMPBuilder.getOrCreateSrcLocStr(Loc, SrcLocStrSize);
+  Value *Ident =
+  OMPInfoCache.OMPBuilder.getOrCreateIdent(SrcLocStr, SrcLocStrSize);
   BranchInst::Create(RegionCheckTidBB, ParentBB)->setDebugLoc(DL);
 
   // Add check for Tid in RegionCheckTidBB
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -21,7 +21,9 @@
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/IR/CFG.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/PassManager.h"
@@ -37,6 +39,7 @@
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "llvm/Transforms/Utils/UnrollLoop.h"
 
+#include 
 #include 
 
 #define DEBUG_TYPE "openmp-ir-builder"
@@ -255,19 +258,21 @@
   return GV;
 }
 
-Value *OpenMPIRBuilder::getOrCreateIdent(Constant *SrcLocStr,
- IdentFlag LocFlags,
- unsigned Reserve2Flags) {
+Constant *OpenMPIRBuilder::getOrCreateIdent(Constant *SrcLocStr,
+uint32_t SrcLocStrSize,
+IdentFlag LocFlags,
+unsigned Reserve2Flags) {
   // Enable "C-mode".
   LocFlags |= OMP_IDENT_FLAG_KMPC;
 
-  Value *&Ident =
+  Constant *&Ident =
   IdentMap[{SrcLocStr, uint64_t(LocFlags) << 31 | Reserve2Flags}];
   if (!Ident) {
 Constant *I32Null = ConstantInt::getNullValue(Int32);
-Constant *IdentData[] = {
-I32Null, ConstantInt::get(Int32, uint32_t(LocFlags)),
-ConstantInt::get(Int32, Reserve2Flags), I32Null, SrcLocStr};
+Constant *IdentData[] = {I32Null,
+ ConstantInt::get(Int32, uint32_t(LocFlags)),
+ ConstantInt::get(Int32, Reserve2Flags),
+ ConstantInt::get(Int32, SrcLocStrSize), SrcLocStr};
 Constant *Initializer =
 ConstantStruct::get(OpenMPIRBuilder::Ident, IdentData);
 
@@ -290,10 +295,12 @@
 }
   }
 
-  return Builder.CreatePointerCast(Ident, IdentPtr);
+  return ConstantExpr::getPointerBitCastOrAddrSpaceCast(Ident, IdentPtr);
 }
 
-Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(StringRef LocStr) {
+Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(StringRef LocStr,
+uint32_t &SrcLocStrSize) {
+  SrcLocStrSize = LocStr.size();
   Constant *&SrcLocStr = SrcLocStrMap[LocStr];
   if (!SrcLocStr) {
 Constant *Initializer =
@@ -314,8 +321,8 @@
 
 Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(StringRef FunctionName,
 StringRef FileName,
-unsigned Line,
- 

[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

2021-11-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.
This revision is now accepted and ready to land.

Please clang-format the patch to reflow the touched comment. Given that's done, 
you are good to go.
Also, wait a couple days before committing to give chance to the rest of the 
reviewers to have a look.


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

https://reviews.llvm.org/D113480

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


[PATCH] D64454: [clang-tidy] Adding static analyzer check to list of clang-tidy checks

2021-11-10 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added subscribers: njames93, whisperity, steakhal.
steakhal added a comment.
Herald added subscribers: carlosgalvezp, manas, ASDenysPetrov.
Herald added a project: clang-tools-extra.

It seems like the list got pretty outdated by the time.
Do you think we should really refer to the clang-analyzer checks in this list? 
What about simply referring to the clangsa docs instead?
I fear, this will be a constant problem in the future.

That being said, a specific grep-like test would suffice to ensure it's always 
updated, but I would be surprised as a clang static analyzer developer that I 
need to run the clang-tools-extra tests besides the clang-analysis ones.
It would cause build bot breakages all the time - and just as many revert 
commits by choosing that direction.

WDYT? @aaron.ballman @njames93 @whisperity


Repository:
  rL LLVM

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

https://reviews.llvm.org/D64454

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


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr updated this revision to Diff 386262.
mcgrathr added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr" "-z" 
"rel"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -61,6 +61,8 @@
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
   }
 
   if (!D.SysRoot.empty())


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr" "-z" "rel"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -61,6 +61,8 @@
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
   }
 
   if (!D.SysRoot.empty())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Driver/ToolChains/Fuchsia.cpp:64-65
 CmdArgs.push_back("--pack-dyn-relocs=relr");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
   }

Super minor nit, but I'd prefer moving this two lines up to keep all the `-z` 
options together.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

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


[PATCH] D112915: [clang][modules] Track number of includes per submodule

2021-11-10 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

Implementation looks a lot cleaner!

I'd still like to drop NumIncludes first if possible because I think it'll be 
easier to reason about without this extra layer of complexity. Also, that'd 
mitigate the potential regression in `.pcm` size.

(Note: I'd be more comfortable with @vsapsai and/or @rsmith reviewing the 
overall direction; I just jumped in for the implementation details.)




Comment at: clang/include/clang/Lex/HeaderSearch.h:133-139
-
-  /// Determine whether this is a non-default header file info, e.g.,
-  /// it corresponds to an actual header we've included or tried to include.
-  bool isNonDefault() const {
-return isImport || isPragmaOnce || NumIncludes || ControllingMacro ||
-  ControllingMacroID;
-  }

Looks like this is already dead code? If so, please separate out and commit 
ahead of time (e.g., now).



Comment at: clang/include/clang/Serialization/ModuleFile.h:399
+  /// include information.
+  llvm::StringMap> SubmoduleIncludedFiles;
+

Each StringMapEntry is going to have a pretty big allocation here, for a 512B 
vector. Given that it doesn't need to be after creation, it'd be more efficient 
to use this pattern:
```
lang=c++
llvm::StringMap> SubmoduleIncludedFiles;
SpecificBumpPtrAlloc SubmoduleIncludedFilesAlloc;

// later
MutableArrayRef Files(SubmoduleIncludedFiles.Allocate(Record.size()), 
Record.size());
llvm::copy(Record, Files.begin());
SubmoduleIncludedFiles[Key] = Files;
```

That said, I feel like this should just be:
```
lang=c++
DenseMap SubmoduleIncludedFiles;
```
The key can point at the name of the submodule, which must already exist 
somewhere without needing a StringMap to create a new copy of it. The value is 
a lazily deserialized blob.



Comment at: clang/lib/Lex/Preprocessor.cpp:1323
+auto &ModNumIncludes = SubmoduleIncludeStates[M].NumIncludes;
+for (unsigned UID = 0; UID <= ModNumIncludes.maxUID(); ++UID) {
+  CurSubmoduleIncludeState->NumIncludes[UID] += ModNumIncludes[UID];

jansvoboda11 wrote:
> dexonsmith wrote:
> > jansvoboda11 wrote:
> > > Iterating over all FileEntries is probably not very efficient, as 
> > > Volodymyr mentioned. Thinking about how to make this more efficient...
> > My suggestion above to drop FileEntryMap in favour of a simple DenseMap 
> > would help a bit, just iterating through the files actually included by the 
> > submodules.
> > 
> > Further, I wonder if "num-includes"/file/submodule (`unsigned`) is actually 
> > useful, vs. "was-included"/file/submodule (`bool`). The only observer I see 
> > is `HeaderSearch::PrintStats()` but maybe I missed something?
> > 
> > If I'm right and we can switch to `bool`, then NumIncludes becomes a 
> > `DenseSet IncludedFiles` (or `DenseSet` for UIDs). 
> > (BTW, I also wondered if you could rotate the map, using File as the outer 
> > key, and then use bitsets for the sbumodules, but I doubt this is better, 
> > since most files are only included by a few submodules, right?)
> > 
> > Then you can just do a set union here. Also simplifies bitcode 
> > serialization.
> > 
> > (If a `bool`/set is sufficient, then I'd suggest landing that 
> > first/separately, before adding the per-submodule granularity in this 
> > patch.)
> For each file, we need to have three distinct states: not included at all, 
> included exactly once (`firstTimeLexingFile`), included more than once. This 
> means we can't use a single `DenseSet`.
> 
> But we could use a `DenseMap`, where "not included at all" can be 
> expressed as being absent from the map, exactly once as having `true` in the 
> map and more than once as having `false` in the map. Alternatively, we could 
> use two `DenseSet` instances to encode the same, but I don't think having two 
> lookups per file to determine stuff is efficient.
> 
> I can look into this in a follow-up patch.
Seems like a DenseSet could still be used by having HeaderInfo pass back the 
WasInserted bit from the insertion to the preprocessor, and threading it 
through to Preprocessor::HandleEndOfFile (the only caller of 
FirstTimeLexingFile):
```
lang=c++
bool IsFirst = Set.insert(Key).second;
```
The threading doesn't seem too hard. Looking at main:
- Preprocessor::HandleHeaderIncludeOrImport calls 
HeaderInfo::ShouldEnterIncludeFile. This does the `++FI.NumIncludes` (going 
from 0 to 1). Instead, it could be `IsFirst = !FI.WasIncluded; FI.WasIncluded = 
true;`, then return `IsFirst` somehow. (Then your patch can pull `IsFirst` from 
the `insert().second`).
- Preprocessor::HandleHeaderIncludeOrImport calls 
Preprocessor::EnterSourceFile. This creates a new Lexer for that file. 
`IsFirst` can be stored on that Lexer.
- Preprocessor::HandleEndOfFile calls FirstTimeLexingFile. Instead, it can 
check the new accessor `CurLexer->isFirstTimeLexing()`.

> I can look into this in a follow-up patch.

Follow-up might be okay, but it

[clang-tools-extra] 26d195d - Replace include by forward declaration in test case

2021-11-10 Thread via cfe-commits

Author: serge-sans-paille
Date: 2021-11-10T20:34:05+01:00
New Revision: 26d195d8b332d8615b7bd0ab9657bcf244f6b112

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

LOG: Replace include by forward declaration in test case

This should fix the remaining buildbot issue for the misleading identifier
detection pass.

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp
index cb036f96dfee1..fdd0886eb3851 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-misleading-identifier.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s misc-misleading-identifier %t
 
-#include 
+int printf(const char *format, ...);
 
 // CHECK-MESSAGES: :[[#@LINE+1]]:1: warning: identifier has right-to-left 
codepoints [misc-misleading-identifier]
 short int א = (short int)0;



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


[PATCH] D113120: [clang] Add early exit when checking for const init of arrays.

2021-11-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

The test is failing on non-arm macs: http://45.33.8.238/mac/38601/step_7.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113120

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


[PATCH] D113120: [clang] Add early exit when checking for const init of arrays.

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added a comment.

Sorry for trouble, I will revert this for now.

It's only the test that's causing the problem, the fix is fine, as far as I can 
tell. Still, better revert the whole thing for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113120

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


[PATCH] D113599: Revert "[clang] Add early exit when checking for const init of arrays."

2021-11-10 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz created this revision.
adamcz added a reviewer: kadircet.
Herald added a subscriber: kristof.beyls.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts commit 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3 
.

Several breakages, including ARM (fixed later, but not sufficient) and
MSan (to be diagnosed later).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113599

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned FinalSize = CAT->getSize().getZExtValue();
+unsigned N = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), 0, FinalSize);
-if (FinalSize == 0)
-  return true;
+*Value = APValue(APValue::UninitArray(), N, N);
+
+if (HadZeroInit)
+  for (unsigned I = 0; I != N; ++I)
+Value->getArrayInitializedElt(I) = Filler;
 
+// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-// We do the whole initialization in two passes, first for just one 
element,
-// then for the whole array. It's possible we may find out we can't do 
const
-// init in the first pass, in which case we avoid allocating a potentially
-// large array. We don't do more passes because expanding array requires
-// copying the data, which is wasteful.
-for (const unsigned N : {1u, FinalSize}) {
-  unsigned OldElts = Value->getArrayInitializedElts();
-  if (OldElts == N)
-break;
-
-  // Expand the array to appropriate size.
-  APValue NewValue(APValue::UninitArray(), N, FinalSize);
-  for (unsigned I = 0; I < OldElts; ++I)
-NewValue.getArrayInitializedElt(I).swap(
-Value->getArrayInitializedElt(I));
-  Value->swap(NewValue);
-
-  if (HadZeroInit)
-for (unsigned I = OldElts; I < N; ++I)
-  Value->getArrayInitializedElt(I) = Filler;
-
-  // Initialize the elements.
-  for (unsigned I = OldElts; I < N; ++I) {
-if (!VisitCXXConstructExpr(E, ArrayElt,
-   &Value->getArrayInitializedElt(I),
-   CAT->getElementType()) ||
-!HandleLValueArrayAdjustment(Info, E, ArrayElt,
- CAT->getElementType(), 1))
-  return false;
-// When checking for const initilization any diagnostic is considered
-// an error.
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-!Info.keepEvaluatingAfterFailure())
-  return false;
-  }
-}
+for (unsigned I = 0; I != N; ++I)
+  if (!VisitCXXConstructExpr(E, ArrayElt, 
&Value->getArrayInitializedElt(I),
+ CAT->getElementType()) ||
+  !HandleLValueArrayAdjustment(Info, E, ArrayElt, 
CAT->getElementType(),
+   1))
+return false;
 
 return true;
   }


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(T

[clang] 6d09aae - Revert "[clang] Add early exit when checking for const init of arrays."

2021-11-10 Thread Adam Czachorowski via cfe-commits

Author: Adam Czachorowski
Date: 2021-11-10T20:59:35+01:00
New Revision: 6d09aaecdfe51e13fc64d539aa7c9a790de341d7

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

LOG: Revert "[clang] Add early exit when checking for const init of arrays."

This reverts commit 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3.

Several breakages, including ARM (fixed later, but not sufficient) and
MSan (to be diagnosed later).

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

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 
clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp



diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index a6da3d3fbea2d..fe96db9ca918e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@ bool ArrayExprEvaluator::VisitCXXConstructExpr(const 
CXXConstructExpr *E,
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned FinalSize = CAT->getSize().getZExtValue();
+unsigned N = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), 0, FinalSize);
-if (FinalSize == 0)
-  return true;
+*Value = APValue(APValue::UninitArray(), N, N);
+
+if (HadZeroInit)
+  for (unsigned I = 0; I != N; ++I)
+Value->getArrayInitializedElt(I) = Filler;
 
+// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-// We do the whole initialization in two passes, first for just one 
element,
-// then for the whole array. It's possible we may find out we can't do 
const
-// init in the first pass, in which case we avoid allocating a potentially
-// large array. We don't do more passes because expanding array requires
-// copying the data, which is wasteful.
-for (const unsigned N : {1u, FinalSize}) {
-  unsigned OldElts = Value->getArrayInitializedElts();
-  if (OldElts == N)
-break;
-
-  // Expand the array to appropriate size.
-  APValue NewValue(APValue::UninitArray(), N, FinalSize);
-  for (unsigned I = 0; I < OldElts; ++I)
-NewValue.getArrayInitializedElt(I).swap(
-Value->getArrayInitializedElt(I));
-  Value->swap(NewValue);
-
-  if (HadZeroInit)
-for (unsigned I = OldElts; I < N; ++I)
-  Value->getArrayInitializedElt(I) = Filler;
-
-  // Initialize the elements.
-  for (unsigned I = OldElts; I < N; ++I) {
-if (!VisitCXXConstructExpr(E, ArrayElt,
-   &Value->getArrayInitializedElt(I),
-   CAT->getElementType()) ||
-!HandleLValueArrayAdjustment(Info, E, ArrayElt,
- CAT->getElementType(), 1))
-  return false;
-// When checking for const initilization any diagnostic is considered
-// an error.
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-!Info.keepEvaluatingAfterFailure())
-  return false;
-  }
-}
+for (unsigned I = 0; I != N; ++I)
+  if (!VisitCXXConstructExpr(E, ArrayElt, 
&Value->getArrayInitializedElt(I),
+ CAT->getElementType()) ||
+  !HandleLValueArrayAdjustment(Info, E, ArrayElt, 
CAT->getElementType(),
+   1))
+return false;
 
 return true;
   }

diff  --git a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp 
b/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
deleted file mode 100644
index 1bbc1b5c863c0..0
--- a/clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-



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


[PATCH] D113599: Revert "[clang] Add early exit when checking for const init of arrays."

2021-11-10 Thread Adam Czachorowski 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 rG6d09aaecdfe5: Revert "[clang] Add early exit when 
checking for const init of arrays." (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113599

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned FinalSize = CAT->getSize().getZExtValue();
+unsigned N = CAT->getSize().getZExtValue();
 
 // Preserve the array filler if we had prior zero-initialization.
 APValue Filler =
   HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller()
  : APValue();
 
-*Value = APValue(APValue::UninitArray(), 0, FinalSize);
-if (FinalSize == 0)
-  return true;
+*Value = APValue(APValue::UninitArray(), N, N);
+
+if (HadZeroInit)
+  for (unsigned I = 0; I != N; ++I)
+Value->getArrayInitializedElt(I) = Filler;
 
+// Initialize the elements.
 LValue ArrayElt = Subobject;
 ArrayElt.addArray(Info, E, CAT);
-// We do the whole initialization in two passes, first for just one 
element,
-// then for the whole array. It's possible we may find out we can't do 
const
-// init in the first pass, in which case we avoid allocating a potentially
-// large array. We don't do more passes because expanding array requires
-// copying the data, which is wasteful.
-for (const unsigned N : {1u, FinalSize}) {
-  unsigned OldElts = Value->getArrayInitializedElts();
-  if (OldElts == N)
-break;
-
-  // Expand the array to appropriate size.
-  APValue NewValue(APValue::UninitArray(), N, FinalSize);
-  for (unsigned I = 0; I < OldElts; ++I)
-NewValue.getArrayInitializedElt(I).swap(
-Value->getArrayInitializedElt(I));
-  Value->swap(NewValue);
-
-  if (HadZeroInit)
-for (unsigned I = OldElts; I < N; ++I)
-  Value->getArrayInitializedElt(I) = Filler;
-
-  // Initialize the elements.
-  for (unsigned I = OldElts; I < N; ++I) {
-if (!VisitCXXConstructExpr(E, ArrayElt,
-   &Value->getArrayInitializedElt(I),
-   CAT->getElementType()) ||
-!HandleLValueArrayAdjustment(Info, E, ArrayElt,
- CAT->getElementType(), 1))
-  return false;
-// When checking for const initilization any diagnostic is considered
-// an error.
-if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() &&
-!Info.keepEvaluatingAfterFailure())
-  return false;
-  }
-}
+for (unsigned I = 0; I != N; ++I)
+  if (!VisitCXXConstructExpr(E, ArrayElt, 
&Value->getArrayInitializedElt(I),
+ CAT->getElementType()) ||
+  !HandleLValueArrayAdjustment(Info, E, ArrayElt, 
CAT->getElementType(),
+   1))
+return false;
 
 return true;
   }


Index: clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
===
--- clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// REQUIRES: shell
-// UNSUPPORTED: win32
-// RUN: ulimit -v 1048576
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64 %s
-// expected-no-diagnostics
-
-// This used to require too much memory and crash with OOM.
-struct {
-  int a, b, c, d;
-} arr[1<<30];
-
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -10596,55 +10596,28 @@
   bool HadZeroInit = Value->hasValue();
 
   if (const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(Type)) {
-unsigned FinalSize = CAT->getSize().

[PATCH] D107994: Making the code compliant to the documentation about Floating Point support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT (FMA is enabled).

2021-11-10 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 386279.
zahiraam marked 2 inline comments as done.

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

https://reviews.llvm.org/D107994

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/ffp-contract-option.c
  clang/test/CodeGen/ffp-model.c
  clang/test/CodeGen/ppc-emmintrin.c
  clang/test/CodeGen/ppc-xmmintrin.c
  clang/test/Driver/fp-model.c
  clang/test/Misc/ffp-contract.c

Index: clang/test/Misc/ffp-contract.c
===
--- /dev/null
+++ clang/test/Misc/ffp-contract.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -O3 -ffp-contract=fast -triple=aarch64-apple-darwin \
+// RUN: -S -o - %s | FileCheck --check-prefix=CHECK-FMADD %s
+// REQUIRES: aarch64-registered-target
+
+float fma_test1(float a, float b, float c) {
+  // CHECK-FMADD: fmadd
+  float x = a * b;
+  float y = x + c;
+  return y;
+}
Index: clang/test/Driver/fp-model.c
===
--- clang/test/Driver/fp-model.c
+++ clang/test/Driver/fp-model.c
@@ -99,7 +99,7 @@
 // RUN: %clang -### -nostdinc -ffp-model=precise -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FPM-PRECISE %s
 // CHECK-FPM-PRECISE: "-cc1"
-// CHECK-FPM-PRECISE: "-ffp-contract=fast"
+// CHECK-FPM-PRECISE: "-ffp-contract=on"
 // CHECK-FPM-PRECISE: "-fno-rounding-math"
 
 // RUN: %clang -### -nostdinc -ffp-model=strict -c %s 2>&1 \
Index: clang/test/CodeGen/ppc-xmmintrin.c
===
--- clang/test/CodeGen/ppc-xmmintrin.c
+++ clang/test/CodeGen/ppc-xmmintrin.c
@@ -2,11 +2,11 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang -S -emit-llvm -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 // RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN: -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
Index: clang/test/CodeGen/ppc-emmintrin.c
===
--- clang/test/CodeGen/ppc-emmintrin.c
+++ clang/test/CodeGen/ppc-emmintrin.c
@@ -2,9 +2,9 @@
 // REQUIRES: powerpc-registered-target
 
 // RUN: %clang -S -emit-llvm -target powerpc64-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:  -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
+// RUN:  -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
 // RUN: %clang -S -emit-llvm -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
-// RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
+// RUN:   -ffp-contract=off -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
 
 // CHECK-BE-DAG: @_mm_movemask_pd.perm_mask = internal constant <4 x i32> , align 16
 // CHECK-BE-DAG: @_mm_shuffle_epi32.permute_selectors = internal constant [4 x i32] [i32 66051, i32 67438087, i32 134810123, i32 202182159], align 4
Index: clang/test/CodeGen/ffp-model.c
===
--- /dev/null
+++ clang/test/CodeGen/ffp-model.c
@@ -0,0 +1,48 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -S -emit-llvm -ffp-model=fast -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-FAST
+
+// RUN: %clang -S -emit-llvm -ffp-model=precise %s -o - \
+// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-PRECISE
+
+// RUN: %clang -S -emit-llvm -ffp-model=strict %s -o - \
+// RUN: -target x86_64 | FileCheck %s --check-prefixes=CHECK,CHECK-STRICT
+
+// RUN: %clang -S -emit-llvm -ffp-model=strict -ffast-math \
+// RUN: -target x86_64 %s -o - | FileCheck %s \
+// RUN: --check-pre

[PATCH] D107994: Making the code compliant to the documentation about Floating Point support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT (FMA is enabled).

2021-11-10 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In D107994#3115589 , @thakis wrote:

> This fixes tests on macOS, but I don't know if the space is there 
> intentionally to check for presence of any attributes:
>
>   % git diff
>   diff --git a/clang/test/CodeGen/ffp-contract-option.c 
> b/clang/test/CodeGen/ffp-contract-option.c
>   index 04d23d5f90b7..327722f56f4e 100644
>   --- a/clang/test/CodeGen/ffp-contract-option.c
>   +++ b/clang/test/CodeGen/ffp-contract-option.c
>   @@ -63,7 +63,7 @@
>// RUN: --check-prefixes=CHECK,CHECK-FPC-ON
>   
>float mymuladd(float x, float y, float z) {
>   -  // CHECK: define {{.*}} float @mymuladd(float noundef %x, float noundef 
> %y, float noundef %z)
>   +  // CHECK: define{{.*}} float @mymuladd(float noundef %x, float noundef 
> %y, float noundef %z)
>  return x * y + z;
>  // expected-warning{{overriding '-ffp-contract=fast' option with 
> '-ffp-contract=on'}}
>   
>   diff --git a/clang/test/CodeGen/ffp-model.c b/clang/test/CodeGen/ffp-model.c
>   index ee0eedb2718f..98d31106a119 100644
>   --- a/clang/test/CodeGen/ffp-model.c
>   +++ b/clang/test/CodeGen/ffp-model.c
>   @@ -19,7 +19,7 @@
>// RUN: --check-prefixes CHECK,CHECK-FAST1
>   
>float mymuladd(float x, float y, float z) {
>   -  // CHECK: define {{.*}} float @mymuladd(float noundef %x, float noundef 
> %y, float noundef %z)
>   +  // CHECK: define{{.*}} float @mymuladd(float noundef %x, float noundef 
> %y, float noundef %z)
>  return x * y + z;
>  // CHECK-FAST: fmul fast float
>
> If this is the right fix, please land it. Else I'll revert again in 30 min or 
> so; bots have been broken for hours by now.






Comment at: clang/test/CodeGen/ffp-model.c:4
+// RUN: | FileCheck %s \
+// RUN: --check-prefixes=CHECK,CHECK-FAST --strict-whitespace
+

zahiraam wrote:
> andrew.w.kaylor wrote:
> > Why did you add the strict-whitespace option?
> Because on some targets, the IR generated for the define is "define 
> {{.*}}float @mymuladd" and on and some others it is 
> "define {{.*}} float @mymuladd" (space between {{.*}} and float.
I was trying to fix the issue with the define function check. 
With this run command:

// RUN: %clang -S -emit-llvm -fno-fast-math -emit-llvm -target 
x86_64-apple-macosx10.11 %s -o -
I get this IR:

define float @mymuladd(float noundef %x, float noundef %y, float noundef %z)

This wouldn't be represented by

// CHECK: define {{.*}} float @mymuladd

but by

// CHECK: define{{.*}} float @mymuladd

or

// CHECK: define {{.*}}float @mymuladd 
But I get replacing with // CHECK: define{{.*}} float @mymuladd
Should solve the issue. Right?


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

https://reviews.llvm.org/D107994

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


[PATCH] D109128: [VFS] Use original path when falling back to external FS

2021-11-10 Thread Keith Smiley via Phabricator via cfe-commits
keith added a comment.

@JDevlieghere can you take another pass?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109128

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


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr updated this revision to Diff 386293.
mcgrathr marked an inline comment as done.
mcgrathr added a comment.

reordered switches


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr added a comment.

Reordered the switches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

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


[PATCH] D107994: Making the code compliant to the documentation about Floating Point support default values for C/C++. FPP-MODEL=PRECISE enables FFP-CONTRACT (FMA is enabled).

2021-11-10 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor accepted this revision.
andrew.w.kaylor added a comment.

lgtm


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

https://reviews.llvm.org/D107994

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


[PATCH] D113480: [analyzer] Fix region cast between the same types with different qualifiers.

2021-11-10 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@steakhal Thank you!

> Please clang-format the patch to reflow the touched comment. Given that's 
> done, you are good to go.

The comment is OK. `clang-format` doesn't complain on it.

> Also, wait a couple days before committing to give chance to the rest of the 
> reviewers to have a look.

Sure.


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

https://reviews.llvm.org/D113480

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


[PATCH] D113518: [clang] Create delegating constructors even in templates

2021-11-10 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff updated this revision to Diff 386297.

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

https://reviews.llvm.org/D113518

Files:
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
  clang/lib/Sema/SemaDeclCXX.cpp


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -4496,6 +4496,8 @@
   // (broken) code in a non-template! SetCtorInitializers does not expect this.
   bool Dependent = CurContext->isDependentContext() &&
(BaseType->isDependentType() || Init->isTypeDependent());
+  bool Delegating = Context.hasSameUnqualifiedType(
+  QualType(ClassDecl->getTypeForDecl(), 0), BaseType);
 
   SourceRange InitRange = Init->getSourceRange();
   if (EllipsisLoc.isValid()) {
@@ -4519,8 +4521,7 @@
   const CXXBaseSpecifier *DirectBaseSpec = nullptr;
   const CXXBaseSpecifier *VirtualBaseSpec = nullptr;
   if (!Dependent) {
-if (Context.hasSameUnqualifiedType(QualType(ClassDecl->getTypeForDecl(),0),
-   BaseType))
+if (Delegating)
   return BuildDelegatingInitializer(BaseTInfo, Init, ClassDecl);
 
 FindBaseInitializer(*this, ClassDecl, BaseType, DirectBaseSpec,
@@ -4548,10 +4549,14 @@
   if (Dependent) {
 DiscardCleanupsInEvaluationContext();
 
-return new (Context) CXXCtorInitializer(Context, BaseTInfo,
-/*IsVirtual=*/false,
-InitRange.getBegin(), Init,
-InitRange.getEnd(), EllipsisLoc);
+if (!Delegating)
+  return new (Context)
+  CXXCtorInitializer(Context, BaseTInfo,
+ /*IsVirtual=*/false, InitRange.getBegin(), Init,
+ InitRange.getEnd(), EllipsisLoc);
+else
+  return new (Context) CXXCtorInitializer(
+  Context, BaseTInfo, InitRange.getBegin(), Init, InitRange.getEnd());
   }
 
   // C++ [base.class.init]p2:
@@ -5063,14 +5068,16 @@
   memcpy(initializer, &Initializer, sizeof (CXXCtorInitializer*));
   Constructor->setCtorInitializers(initializer);
 
-  if (CXXDestructorDecl *Dtor = LookupDestructor(Constructor->getParent())) {
-MarkFunctionReferenced(Initializer->getSourceLocation(), Dtor);
-DiagnoseUseOfDecl(Dtor, Initializer->getSourceLocation());
-  }
+  if (!Constructor->isDependentContext()) {
+if (CXXDestructorDecl *Dtor = LookupDestructor(Constructor->getParent())) {
+  MarkFunctionReferenced(Initializer->getSourceLocation(), Dtor);
+  DiagnoseUseOfDecl(Dtor, Initializer->getSourceLocation());
+}
 
-  DelegatingCtorDecls.push_back(Constructor);
+DelegatingCtorDecls.push_back(Constructor);
 
-  DiagnoseUninitializedFields(*this, Constructor);
+DiagnoseUninitializedFields(*this, Constructor);
+  }
 
   return false;
 }
Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -372,8 +372,6 @@
 class PositiveSelfInitialization : NegativeAggregateType
 {
   PositiveSelfInitialization() : PositiveSelfInitialization() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize 
these bases: NegativeAggregateType
-  // CHECK-FIXES: PositiveSelfInitialization() : NegativeAggregateType(), 
PositiveSelfInitialization() {}
 };
 
 class PositiveIndirectMember {
@@ -552,3 +550,18 @@
   int A;
   // CHECK-FIXES-NOT: int A{};
 };
+
+// Check that a delegating constructor in a template does not trigger false 
positives (PR#37902).
+template 
+struct TemplateWithDelegatingCtor {
+  int X;
+  TemplateWithDelegatingCtor() : X{} {};
+  TemplateWithDelegatingCtor(int) : TemplateWithDelegatingCtor(){};
+};
+
+template 
+struct TemplateWithDelegatingCtorNSDMI {
+  int X{};
+  TemplateWithDelegatingCtorNSDMI() = default;
+  TemplateWithDelegatingCtorNSDMI(int) : TemplateWithDelegatingCtorNSDMI() {}
+};


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -4496,6 +4496,8 @@
   // (broken) code in a non-template! SetCtorInitializers does not expect this.
   bool Dependent = CurContext->isDependentContext() &&
(BaseType->isDependentType() || Init->isTypeDependent());
+  bool Delegating = Context.hasSameUnqualifiedType(
+  QualType(ClassDecl->getTypeForDecl(), 0), BaseType);
 
   SourceRange InitRange = Init->getSourceRange();
   if (EllipsisLoc.isValid()) {
@@ -4519,8 +4521,7 @@
   const CXXBaseSpecifier *DirectBaseSpec = nullptr;
   const CXXBaseSpecifier *Virt

[PATCH] D113126: [OpenMP][NFCI] Embed the source location string size in the ident_t

2021-11-10 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

I'm not convinced. `std::strlen` can do the job. Can you explain more why need 
it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113126

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


[PATCH] D106674: Runtime for Interop directive

2021-11-10 Thread Ravi Narayanaswamy via Phabricator via cfe-commits
RaviNarayanaswamy accepted this revision.
RaviNarayanaswamy added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106674

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


[PATCH] D113518: [clang] Create delegating constructors even in templates

2021-11-10 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff marked 2 inline comments as done.
fwolff added a comment.

Thanks for your review @carlosgalvezp! I have addressed your inline comments. 
I'm not sure about the failing test, but it looks like a regression test 
internal to libFuzzer? Maybe it goes away with the rebuild.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:374
 {
   PositiveSelfInitialization() : PositiveSelfInitialization() {}
 };

carlosgalvezp wrote:
> Not really sure what this test is meant to do. Why would it call the 
> destructor of the own class in it's own constructor? Looks very strange to me.
> 
> If anything, the constructor should call the constructor of the base:
> 
> PositiveSelfInitialization() : NegativeAggregateType()
> 
> What do you think?
The comment above talks about a "pathological template", so my guess is that 
this checks that clang-tidy doesn't crash for this input. The only reason why I 
had to touch this test at all is that the constructor is now treated as a 
delegating constructor, which suppresses the warning.


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

https://reviews.llvm.org/D113518

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


[clang] ff11f0a - [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath via cfe-commits

Author: Roland McGrath
Date: 2021-11-10T13:31:22-08:00
New Revision: ff11f0aa5de1fffaec5f0dde53fad2ba333116b1

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

LOG: [Clang] Pass -z rel to linker for Fuchsia

Fuchsia already supports the more compact relocation format.
Make it the default.

Reviewed By: phosek

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index ee79007fe9a61..b8570fce9eb7d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 

diff  --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index 926594da95c3a..ecf811d9401ba 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"



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


[PATCH] D113136: [Clang] Pass -z rel to linker for Fuchsia

2021-11-10 Thread Roland McGrath 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 rGff11f0aa5de1: [Clang] Pass -z rel to linker for Fuchsia 
(authored by mcgrathr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113136

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" 
"rodynamic" "-z" "separate-loadable-segments" "-z" "rel" 
"--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -35,7 +35,7 @@
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-NOT: "-fcommon"
-// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "--pack-dyn-relocs=relr"
+// CHECK: {{.*}}ld.lld{{.*}}" "-z" "max-page-size=4096" "-z" "now" "-z" "rodynamic" "-z" "separate-loadable-segments" "-z" "rel" "--pack-dyn-relocs=relr"
 // CHECK: "--sysroot=[[SYSROOT]]"
 // CHECK: "-pie"
 // CHECK: "--build-id"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -60,6 +60,8 @@
 CmdArgs.push_back("rodynamic");
 CmdArgs.push_back("-z");
 CmdArgs.push_back("separate-loadable-segments");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("rel");
 CmdArgs.push_back("--pack-dyn-relocs=relr");
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112647: [clang-apply-replacements] Correctly handle relative paths

2021-11-10 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Overall, looks good to me. But, I'd like to get a more experienced reviewer to 
confirm they're comfortable with the new behavior.




Comment at: 
clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:159
 // automatically canonicalized.
+auto &WorkingDir = SM.getFileManager().getFileSystemOpts().WorkingDir;
+auto PrevWorkingDir = WorkingDir;

avogelsgesang wrote:
> ymandel wrote:
> > Why are you capturing this as a reference? This is a subtle and IMO error 
> > prone pattern, since it's not obvious in the code below that you're 
> > mutating a deeply nested element of the filesystem.  Can  you instead use a 
> > local variable and just set this right before you need it?
> > Why are you capturing this as a reference?
> 
> Mostly to keep the code shorter. Otherwise, I would have to write
> 
> ```
> auto PrevWorkingDir = SM.getFileManager().getFileSystemOpts().WorkingDir;
> if (buildDir)
>   SM.getFileManager().getFileSystemOpts().WorkingDir = *buildDir;
> // [...]
> WorkingDir = SM.getFileManager().getFileSystemOpts().WorkingDir;
> ```
> 
> which isn't really DRY.
> 
> > Can you instead use a local variable and just set this right before you 
> > need it?
> 
> I think I don't understand the alternative you are proposing here. Can you 
> provide an example?
What you wrote is what I had in mind, though the last line, i think, would be:
`SM.getFileManager().getFileSystemOpts().WorkingDir = PrevWorkingDir;`
?

That said, I see your point.  The problem is not in your code so much as in the 
underlying (lack of) API for setting and restoring the working directory. 
Honestly, the need to manually restore bothers me more than the reference, now 
that I consider it in more detail. Perhaps another reviewer will have a better 
suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112647

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


[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-11-10 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

It seems to have been fixed in rG3c47c5ca13b8a502de3272e8105548715947b7a8 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[PATCH] D112492: [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Yaxun Liu 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 rG80072fde61d4: [CUDA][HIP] Allow comdat for kernels (authored 
by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112492

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/kernel-stub-name.cu
  clang/test/CodeGenCUDA/usual-deallocators.cu

Index: clang/test/CodeGenCUDA/usual-deallocators.cu
===
--- clang/test/CodeGenCUDA/usual-deallocators.cu
+++ clang/test/CodeGenCUDA/usual-deallocators.cu
@@ -109,7 +109,7 @@
 }
 
 // Make sure that we've generated the kernel used by A::~A.
-// DEVICE-LABEL: define dso_local void @_Z1fIiEvT_
+// DEVICE-LABEL: define void @_Z1fIiEvT_
 
 // Make sure we've picked deallocator for the correct side of compilation.
 
Index: clang/test/CodeGenCUDA/kernel-stub-name.cu
===
--- clang/test/CodeGenCUDA/kernel-stub-name.cu
+++ clang/test/CodeGenCUDA/kernel-stub-name.cu
@@ -2,16 +2,35 @@
 
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
 // RUN: -fcuda-include-gpubinary %t -o - -x hip\
-// RUN:   | FileCheck %s
+// RUN:   | FileCheck -check-prefixes=CHECK,GNU %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
+// RUN: -fcuda-include-gpubinary %t -o - -x hip\
+// RUN:   | FileCheck -check-prefix=NEG %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
+// RUN: %t -o - -x hip\
+// RUN:   | FileCheck -check-prefixes=CHECK,MSVC %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
+// RUN: %t -o - -x hip\
+// RUN:   | FileCheck -check-prefix=NEG %s
 
 #include "Inputs/cuda.h"
 
-// Kernel handles
+// Check kernel handles are emitted for non-MSVC target but not for MSVC target.
 
-// CHECK: @[[HCKERN:ckernel]] = constant void ()* @__device_stub__ckernel, align 8
-// CHECK: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant void ()* @_ZN2ns23__device_stub__nskernelEv, align 8
-// CHECK: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant void ()* @_Z25__device_stub__kernelfuncIiEvv, align 8
-// CHECK: @[[HDKERN:_Z11kernel_declv]] = external constant void ()*, align 8
+// GNU: @[[HCKERN:ckernel]] = constant void ()* @[[CSTUB:__device_stub__ckernel]], align 8
+// GNU: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant void ()* @[[NSSTUB:_ZN2ns23__device_stub__nskernelEv]], align 8
+// GNU: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant void ()* @[[TSTUB:_Z25__device_stub__kernelfuncIiEvv]], comdat, align 8
+// GNU: @[[HDKERN:_Z11kernel_declv]] = external constant void ()*, align 8
+
+// MSVC: @[[HCKERN:ckernel]] = dso_local constant void ()* @[[CSTUB:__device_stub__ckernel]], align 8
+// MSVC: @[[HNSKERN:"\?nskernel@ns@@YAXXZ.*"]] = dso_local constant void ()* @[[NSSTUB:"\?nskernel@ns@@YAXXZ"]], align 8
+// MSVC: @[[HTKERN:"\?\?\$kernelfunc@H@@YAXXZ.*"]] = linkonce_odr dso_local constant void ()* @[[TSTUB:"\?\?\$kernelfunc@H@@YAXXZ.*"]], comdat, align 8
+// MSVC: @[[HDKERN:"\?kernel_decl@@YAXXZ.*"]] = external dso_local constant void ()*, align 8
 
 extern "C" __global__ void ckernel() {}
 
@@ -24,10 +43,10 @@
 
 __global__ void kernel_decl();
 
-void (*kernel_ptr)();
-void *void_ptr;
+extern "C" void (*kernel_ptr)();
+extern "C" void *void_ptr;
 
-void launch(void *kern);
+extern "C" void launch(void *kern);
 
 // Device side kernel names
 
@@ -37,21 +56,22 @@
 
 // Non-template kernel stub functions
 
-// CHECK: define{{.*}}@[[CSTUB:__device_stub__ckernel]]
+// CHECK: define{{.*}}@[[CSTUB]]
 // CHECK: call{{.*}}@hipLaunchByPtr{{.*}}@[[HCKERN]]
-// CHECK: define{{.*}}@[[NSSTUB:_ZN2ns23__device_stub__nskernelEv]]
-// CHECK: call{{.*}}@hipLaunchByPtr{{.*}}@[[HNSKERN]]
 
+// CHECK: define{{.*}}@[[NSSTUB]]
+// CHECK: call{{.*}}@hipLaunchByPtr{{.*}}@[[HNSKERN]]
 
-// Check kernel stub is used for triple chevron
+// Check kernel stub is called for triple chevron.
 
-// CHECK-LABEL: define{{.*}}@_Z4fun1v()
+// CHECK-LABEL: define{{.*}}@fun1()
 // CHECK: call void @[[CSTUB]]()
 // CHECK: call void @[[NSSTUB]]()
-// CHECK: call void @[[TSTUB:_Z25__device_stub__kernelfuncIiEvv]]()
-// CHECK: call void @[[DSTUB:_Z26__device_stub__kernel_declv]]()
+// CHECK: call void @[[TSTUB]]()
+// GNU: call void @[[DSTUB:_Z26__device_stub__kernel_declv]]()
+// MSVC: call void @[[DSTUB:"\?kernel_decl@@YAXXZ"]]()
 
-void fun1(void) {
+extern "C" void fun1(void) {
   ckernel<<<1, 1>>>();
   ns::nskernel<<<1, 1>>>();
   kernelfunc<<<1, 1>>>();
@@ -67,28 +87,28 @@
 
 // CHECK: declare{{.*}}@[[DSTUB]]
 
-// Check kernel handle is used for passing the kernel as a fun

[clang] 80072fd - [CUDA][HIP] Allow comdat for kernels

2021-11-10 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-11-10T16:42:23-05:00
New Revision: 80072fde61d40a4e8a9da673476730d34a483fa2

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

LOG: [CUDA][HIP] Allow comdat for kernels

Two identical instantiations of a template function can be emitted by two TU's
with linkonce_odr linkage without causing duplicate symbols in linker. MSVC
also requires these symbols be in comdat sections. Linux does not require
the symbols in comdat sections to be merged by linker but by default
clang puts them in comdat sections.

If a template kernel is instantiated identically in two TU's. MSVC requires
that them to be in comdat sections, otherwise MSVC linker will diagnose them as
duplicate symbols. However, currently clang does not put instantiated template
kernels in comdat sections, which causes link error for MSVC.

This patch allows putting instantiated template kernels into comdat sections.

Reviewed by: Artem Belevich, Reid Kleckner

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

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCUDA/kernel-stub-name.cu
clang/test/CodeGenCUDA/usual-deallocators.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 69499672bd861..a1b4431ca8c43 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1147,6 +1147,7 @@ llvm::GlobalValue 
*CGNVCUDARuntime::getKernelHandle(llvm::Function *F,
   Var->setAlignment(CGM.getPointerAlign().getAsAlign());
   Var->setDSOLocal(F->isDSOLocal());
   Var->setVisibility(F->getVisibility());
+  CGM.maybeSetTrivialComdat(*GD.getDecl(), *Var);
   KernelHandles[F] = Var;
   KernelStubs[Var] = F;
   return Var;

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index d36cff82f9dde..a4c60f0c50c2d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4308,11 +4308,6 @@ static bool shouldBeInCOMDAT(CodeGenModule &CGM, const 
Decl &D) {
   if (!CGM.supportsCOMDAT())
 return false;
 
-  // Do not set COMDAT attribute for CUDA/HIP stub functions to prevent
-  // them being "merged" by the COMDAT Folding linker optimization.
-  if (D.hasAttr())
-return false;
-
   if (D.hasAttr())
 return true;
 

diff  --git a/clang/test/CodeGenCUDA/kernel-stub-name.cu 
b/clang/test/CodeGenCUDA/kernel-stub-name.cu
index 460dd6010e835..8e82c3612e323 100644
--- a/clang/test/CodeGenCUDA/kernel-stub-name.cu
+++ b/clang/test/CodeGenCUDA/kernel-stub-name.cu
@@ -2,16 +2,35 @@
 
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
 // RUN: -fcuda-include-gpubinary %t -o - -x hip\
-// RUN:   | FileCheck %s
+// RUN:   | FileCheck -check-prefixes=CHECK,GNU %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
+// RUN: -fcuda-include-gpubinary %t -o - -x hip\
+// RUN:   | FileCheck -check-prefix=NEG %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
+// RUN: %t -o - -x hip\
+// RUN:   | FileCheck -check-prefixes=CHECK,MSVC %s
+
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm %s \
+// RUN: -aux-triple amdgcn-amd-amdhsa -fcuda-include-gpubinary \
+// RUN: %t -o - -x hip\
+// RUN:   | FileCheck -check-prefix=NEG %s
 
 #include "Inputs/cuda.h"
 
-// Kernel handles
+// Check kernel handles are emitted for non-MSVC target but not for MSVC 
target.
 
-// CHECK: @[[HCKERN:ckernel]] = constant void ()* @__device_stub__ckernel, 
align 8
-// CHECK: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant void ()* 
@_ZN2ns23__device_stub__nskernelEv, align 8
-// CHECK: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant void ()* 
@_Z25__device_stub__kernelfuncIiEvv, align 8
-// CHECK: @[[HDKERN:_Z11kernel_declv]] = external constant void ()*, align 8
+// GNU: @[[HCKERN:ckernel]] = constant void ()* 
@[[CSTUB:__device_stub__ckernel]], align 8
+// GNU: @[[HNSKERN:_ZN2ns8nskernelEv]] = constant void ()* 
@[[NSSTUB:_ZN2ns23__device_stub__nskernelEv]], align 8
+// GNU: @[[HTKERN:_Z10kernelfuncIiEvv]] = linkonce_odr constant void ()* 
@[[TSTUB:_Z25__device_stub__kernelfuncIiEvv]], comdat, align 8
+// GNU: @[[HDKERN:_Z11kernel_declv]] = external constant void ()*, align 8
+
+// MSVC: @[[HCKERN:ckernel]] = dso_local constant void ()* 
@[[CSTUB:__device_stub__ckernel]], align 8
+// MSVC: @[[HNSKERN:"\?nskernel@ns@@YAXXZ.*"]] = dso_local constant void ()* 
@[[NSSTUB:"\?nskernel@ns@@YAXXZ"]], align 8
+// MSVC: @[[HTKERN:"\?\?\$kernelfunc@H@@YAXXZ.*"]] = linkonce_odr dso_local 
constant void ()* @[[TSTUB:"\?\?\$kernelfunc@H@@YAXXZ.*"]], comdat, align 8
+// MSVC: @[[HDKERN:"\?kernel_decl@@YA

[PATCH] D111443: [Driver] Fix ToolChain::getSanitizerArgs

2021-11-10 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added inline comments.



Comment at: clang/lib/Driver/ToolChain.cpp:124
+  }
+  return SanitizerArgs(*this, JobArgs, /*DiagnoseErrors=*/false);
 }

SanitizerArgs SanArgs(*this, JobArgs, !SanitizerArgsChecked);
SanitizerArgsChecked = true;
return SanArgs;




Comment at: clang/lib/Driver/ToolChains/FreeBSD.cpp:471
+bool FreeBSD::isPIEDefault(const llvm::opt::ArgList &Args) const {
+  return getSanitizerArgs(Args).requiresPIE();
+}

it looks like we do a lot of sanitizerargs recomputing. Is it worth it to try 
and cache it?


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

https://reviews.llvm.org/D111443

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


[clang] 4b3881e - Emit hidden hostcall argument for sanitized kernels

2021-11-10 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-11-10T17:05:57-05:00
New Revision: 4b3881e9f319b6c4ec69160f16a49c128ffbd7dd

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

LOG: Emit hidden hostcall argument for sanitized kernels

this patch - https://reviews.llvm.org/D110337 changes the way how hostcall
hidden argument is emitted for printf, but the sanitized kernels also use
hostcall buffer to report a error for invalid memory access, which is not
handled by the above patch and it leads to vdi runtime error:

Device::callbackQueue aborting with error : HSA_STATUS_ERROR_MEMORY_FAULT:
Agent attempted to access an inaccessible address. code: 0x2b

Patch by: Praveen Velliengiri

Reviewed by: Yaxun Liu, Matt Arsenault

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

Added: 
llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCUDA/amdgpu-asan.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index a4c60f0c50c2d..c28c2e2e85d89 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -565,6 +565,7 @@ void CodeGenModule::Release() {
 "__amdgpu_device_library_preserve_asan_functions_ptr", nullptr,
 llvm::GlobalVariable::NotThreadLocal);
 addCompilerUsedGlobal(Var);
+getModule().addModuleFlag(llvm::Module::Override, "amdgpu_hostcall", 1);
   }
 
   emitLLVMUsed();

diff  --git a/clang/test/CodeGenCUDA/amdgpu-asan.cu 
b/clang/test/CodeGenCUDA/amdgpu-asan.cu
index e392b9617cdd9..d63e3cf12a74c 100644
--- a/clang/test/CodeGenCUDA/amdgpu-asan.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-asan.cu
@@ -9,12 +9,12 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
 // RUN:   -mlink-bitcode-file %t.asanrtl.bc -x hip \
-// RUN:   | FileCheck -check-prefix=ASAN %s
+// RUN:   | FileCheck -check-prefixes=ASAN,MFCHECK %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
 // RUN:   -O3 -mlink-bitcode-file %t.asanrtl.bc -x hip \
-// RUN:   | FileCheck -check-prefix=ASAN %s
+// RUN:   | FileCheck -check-prefixes=ASAN,MFCHECK %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -x hip \
@@ -27,5 +27,8 @@
 // ASAN-DAG: @llvm.compiler.used = 
{{.*}}@__amdgpu_device_library_preserve_asan_functions_ptr
 // ASAN-DAG: define weak void @__asan_report_load1(i64 %{{.*}})
 
+// MFCHECK: !llvm.module.flags = !{![[FLAG1:[0-9]+]], ![[FLAG2:[0-9]+]]}
+// MFCHECK: ![[FLAG1]] = !{i32 4, !"amdgpu_hostcall", i32 1}
+
 // CHECK-NOT: @__amdgpu_device_library_preserve_asan_functions
 // CHECK-NOT: @__asan_report_load1

diff  --git a/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll 
b/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
new file mode 100644
index 0..5b63af45bbe92
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
@@ -0,0 +1,54 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 
--amdhsa-code-object-version=3 -amdgpu-dump-hsa-metadata 
-amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck  %s
+
+; CHECK:  ---
+; CHECK:  amdhsa.kernels:
+; CHECK:- .args:
+; CHECK-NEXT:   - .name:   a
+; CHECK-NEXT: .offset: 0
+; CHECK-NEXT: .size:   1
+; CHECK-NEXT: .type_name:  char
+; CHECK-NEXT: .value_kind: by_value
+; CHECK-NEXT:   - .offset: 8
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_x
+; CHECK-NEXT:   - .offset: 16
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_y
+; CHECK-NEXT:   - .offset: 24
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_z
+; CHECK-NEXT:   - .address_space:  global
+; CHECK-NEXT: .offset: 32
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_hostcall_buffer
+; CHECK:  .language:   OpenCL C
+; CHECK-NEXT: .language_version:
+; CHECK-NEXT:   - 2
+; CHECK-NEXT:   - 0
+; CHECK:  .name:   test_kernel
+; CHECK:  .symbol: test_kernel.kd
+
+define amdgpu_kernel void @test_kernel(i8 %a) #0
+!kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3
+!kernel_arg_base_type !3 !kernel_arg_type_qual !4 {
+  ret void
+}
+
+; CHECK:  amdhsa.version:
+; CHECK-NEXT: - 1
+;

[PATCH] D112820: Emit hidden hostcall argument for sanitized kernels.

2021-11-10 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b3881e9f319: Emit hidden hostcall argument for sanitized 
kernels (authored by yaxunl).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112820

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/amdgpu-asan.cu
  llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll


Index: llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
@@ -0,0 +1,54 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 
--amdhsa-code-object-version=3 -amdgpu-dump-hsa-metadata 
-amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck  %s
+
+; CHECK:  ---
+; CHECK:  amdhsa.kernels:
+; CHECK:- .args:
+; CHECK-NEXT:   - .name:   a
+; CHECK-NEXT: .offset: 0
+; CHECK-NEXT: .size:   1
+; CHECK-NEXT: .type_name:  char
+; CHECK-NEXT: .value_kind: by_value
+; CHECK-NEXT:   - .offset: 8
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_x
+; CHECK-NEXT:   - .offset: 16
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_y
+; CHECK-NEXT:   - .offset: 24
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_global_offset_z
+; CHECK-NEXT:   - .address_space:  global
+; CHECK-NEXT: .offset: 32
+; CHECK-NEXT: .size:   8
+; CHECK-NEXT: .value_kind: hidden_hostcall_buffer
+; CHECK:  .language:   OpenCL C
+; CHECK-NEXT: .language_version:
+; CHECK-NEXT:   - 2
+; CHECK-NEXT:   - 0
+; CHECK:  .name:   test_kernel
+; CHECK:  .symbol: test_kernel.kd
+
+define amdgpu_kernel void @test_kernel(i8 %a) #0
+!kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !3
+!kernel_arg_base_type !3 !kernel_arg_type_qual !4 {
+  ret void
+}
+
+; CHECK:  amdhsa.version:
+; CHECK-NEXT: - 1
+; CHECK-NEXT: - 0
+
+attributes #0 = { sanitize_address "amdgpu-implicitarg-num-bytes"="48" }
+
+!1 = !{i32 0}
+!2 = !{!"none"}
+!3 = !{!"char"}
+!4 = !{!""}
+
+!opencl.ocl.version = !{!90}
+!90 = !{i32 2, i32 0}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 4, !"amdgpu_hostcall", i32 1}
+
+; CHECK: AMDGPU HSA Metadata Parser Test: PASS
Index: clang/test/CodeGenCUDA/amdgpu-asan.cu
===
--- clang/test/CodeGenCUDA/amdgpu-asan.cu
+++ clang/test/CodeGenCUDA/amdgpu-asan.cu
@@ -9,12 +9,12 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
 // RUN:   -mlink-bitcode-file %t.asanrtl.bc -x hip \
-// RUN:   | FileCheck -check-prefix=ASAN %s
+// RUN:   | FileCheck -check-prefixes=ASAN,MFCHECK %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
 // RUN:   -O3 -mlink-bitcode-file %t.asanrtl.bc -x hip \
-// RUN:   | FileCheck -check-prefix=ASAN %s
+// RUN:   | FileCheck -check-prefixes=ASAN,MFCHECK %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -x hip \
@@ -27,5 +27,8 @@
 // ASAN-DAG: @llvm.compiler.used = 
{{.*}}@__amdgpu_device_library_preserve_asan_functions_ptr
 // ASAN-DAG: define weak void @__asan_report_load1(i64 %{{.*}})
 
+// MFCHECK: !llvm.module.flags = !{![[FLAG1:[0-9]+]], ![[FLAG2:[0-9]+]]}
+// MFCHECK: ![[FLAG1]] = !{i32 4, !"amdgpu_hostcall", i32 1}
+
 // CHECK-NOT: @__amdgpu_device_library_preserve_asan_functions
 // CHECK-NOT: @__asan_report_load1
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -565,6 +565,7 @@
 "__amdgpu_device_library_preserve_asan_functions_ptr", nullptr,
 llvm::GlobalVariable::NotThreadLocal);
 addCompilerUsedGlobal(Var);
+getModule().addModuleFlag(llvm::Module::Override, "amdgpu_hostcall", 1);
   }
 
   emitLLVMUsed();


Index: llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-present-v3-asan.ll
@@ -0,0 +1,54 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 --amdhsa-code-object-version=3 -amdgpu-dump-hsa-metadata -amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck  %s
+
+; CHECK: 

[PATCH] D113614: Disable clang-repl tests failing due to lack of 64-bit XCOFF support.

2021-11-10 Thread Steven Wan via Phabricator via cfe-commits
stevewan created this revision.
stevewan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The following interpreter tests failed on AIX because 64-bit XCOFF object files 
are currently not supported on AIX. This patch disables the tests on AIX.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113614

Files:
  clang/unittests/Interpreter/InterpreterTest.cpp


Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -145,7 +145,11 @@
   ~LLVMInitRAII() { llvm::llvm_shutdown(); }
 } LLVMInit;
 
+#ifdef _AIX
+TEST(IncrementalProcessing, DISABLED_FindMangledNameSymbol) {
+#else
 TEST(IncrementalProcessing, FindMangledNameSymbol) {
+#endif
 
   std::unique_ptr Interp = createInterpreter();
 
@@ -201,7 +205,11 @@
   return R.getFoundDecl();
 }
 
+#ifdef _AIX
+TEST(IncrementalProcessing, DISABLED_InstantiateTemplate) {
+#else
 TEST(IncrementalProcessing, InstantiateTemplate) {
+#endif
   // FIXME: We cannot yet handle delayed template parsing. If we run with
   // -fdelayed-template-parsing we try adding the newly created decl to the
   // active PTU which causes an assert.


Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -145,7 +145,11 @@
   ~LLVMInitRAII() { llvm::llvm_shutdown(); }
 } LLVMInit;
 
+#ifdef _AIX
+TEST(IncrementalProcessing, DISABLED_FindMangledNameSymbol) {
+#else
 TEST(IncrementalProcessing, FindMangledNameSymbol) {
+#endif
 
   std::unique_ptr Interp = createInterpreter();
 
@@ -201,7 +205,11 @@
   return R.getFoundDecl();
 }
 
+#ifdef _AIX
+TEST(IncrementalProcessing, DISABLED_InstantiateTemplate) {
+#else
 TEST(IncrementalProcessing, InstantiateTemplate) {
+#endif
   // FIXME: We cannot yet handle delayed template parsing. If we run with
   // -fdelayed-template-parsing we try adding the newly created decl to the
   // active PTU which causes an assert.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D113517#3122217 , @rsmith wrote:

> In D113517#3121455 , @jyknight 
> wrote:
>
>> This change allows those future optimizations to apply to throw() as well, 
>> in C++17 mode, which is the desirable outcome.
>
> I see. It seems inconsistent that `throw(X)` would still call `unexpected` 
> but that `throw()` would call `terminate`, but I suppose in the `throw()` 
> case there is really not much interesting that an `unexpected_handler` can do 
> other than (take some logging action and) terminate the program -- in 
> particular, it can't do exception translation. So maybe the inconsistency is 
> not a big deal, and it's more important to get the better code generation, 
> especially given how rare `throw(X)` is compared to `throw()`. OK, I think 
> I'm convinced that this is the best direction.

Well, "throw(X)" is not even permitted by C++17. In Clang, we allow that it 
only if you turn off the default-error warning option. Given that, I'm not too 
worried about it keeping the legacy behavior, while "throw()" gets the new 
behavior.




Comment at: clang/lib/CodeGen/CGException.cpp:480-487
+  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
+  // as noexcept. In earlier standards, it is handled separately, below.
+  if ((getLangOpts().CPlusPlus17 || EST != EST_DynamicNone) &&
+  Proto->canThrow() == CT_Cannot) {
 // noexcept functions are simple terminate scopes.
 if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
   EHStack.pushTerminate();

rsmith wrote:
> Maybe the logic would be clearer if we swap the terminate and unexpected 
> cases:
> ```
> if  (EST == EST_Dynamic || (!getLangOpts().CPlusPlus17 && EST == 
> EST_DynamicNone)) {
>   // Prepare to call unexpected
> } else if (Proto->canThrow() == CT_Cannot) {
>   // Prepare to call terminate
> }
> ```
> This would keep the syntactic checks of `EST` separated from the semantic 
> checks of `canThrow`.
Agreed, that's better. I'll make that change and submit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

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


[clang] fddc4e4 - Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2021-11-10T17:40:16-05:00
New Revision: fddc4e41164e2fd152605362639eb3255cc75212

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

LOG: Correct handling of the 'throw()' exception specifier in C++17.

Per C++17 [except.spec], 'throw()' has become equivalent to
'noexcept', and should therefore call std::terminate, not
std::unexpected.

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

Added: 


Modified: 
clang/lib/CodeGen/CGException.cpp
clang/test/CXX/except/except.spec/p9-dynamic.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 9f65e9eb120cf..aff9c77d53c78 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -477,11 +477,11 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 return;
 
   ExceptionSpecificationType EST = Proto->getExceptionSpecType();
-  if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
-// noexcept functions are simple terminate scopes.
-if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
-  EHStack.pushTerminate();
-  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
+  // as noexcept. In earlier standards, it is handled in this block, along with
+  // 'throw(X...)'.
+  if (EST == EST_Dynamic ||
+  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
 // TODO: Revisit exception specifications for the MS ABI.  There is a way 
to
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
@@ -521,6 +521,10 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 /*ForEH=*/true);
   Filter->setFilter(I, EHType);
 }
+  } else if (Proto->canThrow() == CT_Cannot) {
+// noexcept functions are simple terminate scopes.
+if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
+  EHStack.pushTerminate();
   }
 }
 
@@ -580,10 +584,8 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
 return;
 
   ExceptionSpecificationType EST = Proto->getExceptionSpecType();
-  if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot &&
-  !EHStack.empty() /* possible empty when under async exceptions */) {
-EHStack.popTerminate();
-  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+  if (EST == EST_Dynamic ||
+  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
 // TODO: Revisit exception specifications for the MS ABI.  There is a way 
to
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
@@ -599,6 +601,10 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
 EHFilterScope &filterScope = cast(*EHStack.begin());
 emitFilterDispatchBlock(*this, filterScope);
 EHStack.popFilter();
+  } else if (Proto->canThrow() == CT_Cannot &&
+  /* possible empty when under async exceptions */
+ !EHStack.empty()) {
+EHStack.popTerminate();
   }
 }
 

diff  --git a/clang/test/CXX/except/except.spec/p9-dynamic.cpp 
b/clang/test/CXX/except/except.spec/p9-dynamic.cpp
index 1e7b29479fbdb..ccba71767729e 100644
--- a/clang/test/CXX/except/except.spec/p9-dynamic.cpp
+++ b/clang/test/CXX/except/except.spec/p9-dynamic.cpp
@@ -1,12 +1,26 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s --check-prefixes=CHECK,CHECK-PRE17
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -std=c++17 
-Wno-dynamic-exception-spec -emit-llvm -o - -fcxx-exceptions -fexceptions | 
FileCheck %s --check-prefixes=CHECK,CHECK-17
 
 void external();
 
+// CHECK-LABEL: _Z6targetv(
+// CHECK: invoke void @_Z8externalv()
+// CHECK:  landingpad { i8*, i32 }
+// CHECK-NEXT:   filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
+// CHECK:  call void @__cxa_call_unexpected
 void target() throw(int)
 {
-  // CHECK: invoke void @_Z8externalv()
   external();
 }
-// CHECK:  landingpad { i8*, i32 }
-// CHECK-NEXT:   filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
-// CHECK:  call void @__cxa_call_unexpected
+
+// CHECK-LABEL: _Z7target2v(
+// CHECK: invoke void @_Z8externalv()
+// CHECK:landingpad { i8*, i32 }
+// CHECK-PRE17-NEXT:   filter [0 x i8*] zeroinitializer
+// CHECK-17-NEXT:  catch i8* null
+// CHECK-PRE17:  call void @__cxa_call_unexpected
+// CHECK-17: call void @__clang_call_terminate
+void target2(

[PATCH] D113517: Correct handling of the 'throw()' exception specifier in C++17.

2021-11-10 Thread James Y Knight via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfddc4e41164e: Correct handling of the 'throw()' 
exception specifier in C++17. (authored by jyknight).

Changed prior to commit:
  https://reviews.llvm.org/D113517?vs=385971&id=386326#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113517

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CXX/except/except.spec/p9-dynamic.cpp


Index: clang/test/CXX/except/except.spec/p9-dynamic.cpp
===
--- clang/test/CXX/except/except.spec/p9-dynamic.cpp
+++ clang/test/CXX/except/except.spec/p9-dynamic.cpp
@@ -1,12 +1,26 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - 
-fcxx-exceptions -fexceptions | FileCheck %s --check-prefixes=CHECK,CHECK-PRE17
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -std=c++17 
-Wno-dynamic-exception-spec -emit-llvm -o - -fcxx-exceptions -fexceptions | 
FileCheck %s --check-prefixes=CHECK,CHECK-17
 
 void external();
 
+// CHECK-LABEL: _Z6targetv(
+// CHECK: invoke void @_Z8externalv()
+// CHECK:  landingpad { i8*, i32 }
+// CHECK-NEXT:   filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
+// CHECK:  call void @__cxa_call_unexpected
 void target() throw(int)
 {
-  // CHECK: invoke void @_Z8externalv()
   external();
 }
-// CHECK:  landingpad { i8*, i32 }
-// CHECK-NEXT:   filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
-// CHECK:  call void @__cxa_call_unexpected
+
+// CHECK-LABEL: _Z7target2v(
+// CHECK: invoke void @_Z8externalv()
+// CHECK:landingpad { i8*, i32 }
+// CHECK-PRE17-NEXT:   filter [0 x i8*] zeroinitializer
+// CHECK-17-NEXT:  catch i8* null
+// CHECK-PRE17:  call void @__cxa_call_unexpected
+// CHECK-17: call void @__clang_call_terminate
+void target2() throw()
+{
+  external();
+}
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -477,11 +477,11 @@
 return;
 
   ExceptionSpecificationType EST = Proto->getExceptionSpecType();
-  if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot) {
-// noexcept functions are simple terminate scopes.
-if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
-  EHStack.pushTerminate();
-  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+  // In C++17 and later, 'throw()' aka EST_DynamicNone is treated the same way
+  // as noexcept. In earlier standards, it is handled in this block, along with
+  // 'throw(X...)'.
+  if (EST == EST_Dynamic ||
+  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
 // TODO: Revisit exception specifications for the MS ABI.  There is a way 
to
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
@@ -521,6 +521,10 @@
 /*ForEH=*/true);
   Filter->setFilter(I, EHType);
 }
+  } else if (Proto->canThrow() == CT_Cannot) {
+// noexcept functions are simple terminate scopes.
+if (!getLangOpts().EHAsynch) // -EHa: HW exception still can occur
+  EHStack.pushTerminate();
   }
 }
 
@@ -580,10 +584,8 @@
 return;
 
   ExceptionSpecificationType EST = Proto->getExceptionSpecType();
-  if (isNoexceptExceptionSpec(EST) && Proto->canThrow() == CT_Cannot &&
-  !EHStack.empty() /* possible empty when under async exceptions */) {
-EHStack.popTerminate();
-  } else if (EST == EST_Dynamic || EST == EST_DynamicNone) {
+  if (EST == EST_Dynamic ||
+  (EST == EST_DynamicNone && !getLangOpts().CPlusPlus17)) {
 // TODO: Revisit exception specifications for the MS ABI.  There is a way 
to
 // encode these in an object file but MSVC doesn't do anything with it.
 if (getTarget().getCXXABI().isMicrosoft())
@@ -599,6 +601,10 @@
 EHFilterScope &filterScope = cast(*EHStack.begin());
 emitFilterDispatchBlock(*this, filterScope);
 EHStack.popFilter();
+  } else if (Proto->canThrow() == CT_Cannot &&
+  /* possible empty when under async exceptions */
+ !EHStack.empty()) {
+EHStack.popTerminate();
   }
 }
 


Index: clang/test/CXX/except/except.spec/p9-dynamic.cpp
===
--- clang/test/CXX/except/except.spec/p9-dynamic.cpp
+++ clang/test/CXX/except/except.spec/p9-dynamic.cpp
@@ -1,12 +1,26 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s --check-prefixes=CHECK,CHECK

[PATCH] D113126: [OpenMP][NFCI] Embed the source location string size in the ident_t

2021-11-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D113126#3122659 , @tianshilei1992 
wrote:

> I'm not convinced. `std::strlen` can do the job. Can you explain more why 
> need it?

Because the ident_t is on the device and you want to grab it from the host.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113126

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


[PATCH] D113623: [OpenMP][FIX] Pass the num_threads value directly to parallel_51

2021-11-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert created this revision.
jdoerfert added reviewers: jhuber6, ggeorgakoudis, tianshilei1992, grokos, 
jdenny.
Herald added subscribers: asavonic, guansong, bollu, yaxunl.
jdoerfert requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added projects: clang, OpenMP.

The problem with the old scheme is that we would need to keep track of
the "next region" and reset the num_threads value after it. The new RT
doesn't do it and an assertion is triggered. The old RT doesn't do it
either, I haven't tested it but I assume a num_threads clause might
impact multiple parallel regions "accidentally". Further, in SPMD mode
num_threads was simply ignored, for some reason beyond me.

In any case, parallel_51 is designed to take the clause value directly,
so let's do that instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113623

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
  openmp/libomptarget/deviceRTLs/common/omptarget.h
  openmp/libomptarget/deviceRTLs/common/omptargeti.h
  openmp/libomptarget/deviceRTLs/common/src/parallel.cu
  openmp/libomptarget/deviceRTLs/interface.h

Index: openmp/libomptarget/deviceRTLs/interface.h
===
--- openmp/libomptarget/deviceRTLs/interface.h
+++ openmp/libomptarget/deviceRTLs/interface.h
@@ -220,8 +220,6 @@
 
 // parallel
 EXTERN int32_t __kmpc_global_thread_num(kmp_Ident *loc);
-EXTERN void __kmpc_push_num_threads(kmp_Ident *loc, int32_t global_tid,
-int32_t num_threads);
 NOINLINE EXTERN uint8_t __kmpc_parallel_level();
 
 // proc bind
@@ -445,7 +443,8 @@
   bool RequiresFullRuntime);
 EXTERN void __kmpc_target_deinit(ident_t *Ident, int8_t Mode,
  bool RequiresFullRuntime);
-EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn);
+EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn,
+   int32_t NumThreadsClause);
 EXTERN bool __kmpc_kernel_parallel(void **WorkFn);
 EXTERN void __kmpc_kernel_end_parallel();
 
Index: openmp/libomptarget/deviceRTLs/common/src/parallel.cu
===
--- openmp/libomptarget/deviceRTLs/common/src/parallel.cu
+++ openmp/libomptarget/deviceRTLs/common/src/parallel.cu
@@ -73,7 +73,8 @@
 }
 
 // This routine is always called by the team master..
-EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn) {
+EXTERN void __kmpc_kernel_prepare_parallel(void *WorkFn,
+   kmp_int32 NumThreadsClause) {
   PRINT0(LD_IO, "call to __kmpc_kernel_prepare_parallel\n");
 
   omptarget_nvptx_workFn = WorkFn;
@@ -92,9 +93,6 @@
 return;
   }
 
-  uint16_t &NumThreadsClause =
-  omptarget_nvptx_threadPrivateContext->NumThreadsForNextParallel(threadId);
-
   uint16_t NumThreads =
   determineNumberOfThreads(NumThreadsClause, nThreads, threadLimit);
 
@@ -255,16 +253,6 @@
 // push params
 
 
-EXTERN void __kmpc_push_num_threads(kmp_Ident *loc, int32_t tid,
-int32_t num_threads) {
-  PRINT(LD_IO, "call kmpc_push_num_threads %d\n", num_threads);
-  ASSERT0(LT_FUSSY, isRuntimeInitialized(),
-  "Runtime must be initialized.");
-  tid = GetLogicalThreadIdInBlock();
-  omptarget_nvptx_threadPrivateContext->NumThreadsForNextParallel(tid) =
-  num_threads;
-}
-
 // Do nothing. The host guarantees we started the requested number of
 // teams and we only need inspection of gridDim.
 
@@ -304,11 +292,7 @@
 return;
   }
 
-  // Handle the num_threads clause.
-  if (num_threads != -1)
-__kmpc_push_num_threads(ident, global_tid, num_threads);
-
-  __kmpc_kernel_prepare_parallel((void *)wrapper_fn);
+  __kmpc_kernel_prepare_parallel((void *)wrapper_fn, num_threads);
 
   if (nargs) {
 void **GlobalArgs;
Index: openmp/libomptarget/deviceRTLs/common/omptargeti.h
===
--- openmp/libomptarget/deviceRTLs/common/omptargeti.h
+++ openmp/libomptarget/deviceRTLs/common/omptargeti.h
@@ -158,8 +158,6 @@
   // levelOneTaskDescr is init when starting the parallel region
   // top task descr is NULL (team master version will be fixed separately)
   topTaskDescr[tid] = NULL;
-  // no num threads value has been pushed
-  nextRegion.tnum[tid] = 0;
   // the following don't need to be init here; they are init whe

[PATCH] D113614: Disable clang-repl tests failing due to lack of 64-bit XCOFF support.

2021-11-10 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan accepted this revision.
Jake-Egan added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113614

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


[clang] 9303c7d - [AIX] Define WCHAR_T_TYPE as unsigned int on 64-bit AIX for wchar.c test

2021-11-10 Thread Jake Egan via cfe-commits

Author: Jake Egan
Date: 2021-11-10T20:46:57-05:00
New Revision: 9303c7da39678dbcf3397da4944bb9b4c6e1ac65

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

LOG: [AIX] Define WCHAR_T_TYPE as unsigned int on 64-bit AIX for wchar.c test

The default wchar type on 64-bit AIX is `unsigned int`, so this patch sets 
`WCHAR_T_TYPE` to `unsigned int` rather than `int`.

This patch follows similar reasoning to D110428 except for 64-bit.

Reviewed By: daltenty

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

Added: 


Modified: 
clang/test/Sema/wchar.c

Removed: 




diff  --git a/clang/test/Sema/wchar.c b/clang/test/Sema/wchar.c
index fff12442ed543..2c88f8db52487 100644
--- a/clang/test/Sema/wchar.c
+++ b/clang/test/Sema/wchar.c
@@ -14,7 +14,7 @@ typedef __WCHAR_TYPE__ wchar_t;
   #else
 #define WCHAR_T_TYPE unsigned int
   #endif
-#elif defined(__arm) || defined(__MVS__)
+#elif defined(__arm) || defined(__MVS__) || (defined(_AIX) && 
defined(__64BIT__))
   #define WCHAR_T_TYPE unsigned int
 #elif defined(__sun)
   #if defined(__LP64__)



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


[PATCH] D113428: [AIX] Define WCHAR_T_TYPE as unsigned int on 64-bit AIX for wchar.c test

2021-11-10 Thread Jake Egan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9303c7da3967: [AIX] Define WCHAR_T_TYPE as unsigned int on 
64-bit AIX for wchar.c test (authored by Jake-Egan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113428

Files:
  clang/test/Sema/wchar.c


Index: clang/test/Sema/wchar.c
===
--- clang/test/Sema/wchar.c
+++ clang/test/Sema/wchar.c
@@ -14,7 +14,7 @@
   #else
 #define WCHAR_T_TYPE unsigned int
   #endif
-#elif defined(__arm) || defined(__MVS__)
+#elif defined(__arm) || defined(__MVS__) || (defined(_AIX) && 
defined(__64BIT__))
   #define WCHAR_T_TYPE unsigned int
 #elif defined(__sun)
   #if defined(__LP64__)


Index: clang/test/Sema/wchar.c
===
--- clang/test/Sema/wchar.c
+++ clang/test/Sema/wchar.c
@@ -14,7 +14,7 @@
   #else
 #define WCHAR_T_TYPE unsigned int
   #endif
-#elif defined(__arm) || defined(__MVS__)
+#elif defined(__arm) || defined(__MVS__) || (defined(_AIX) && defined(__64BIT__))
   #define WCHAR_T_TYPE unsigned int
 #elif defined(__sun)
   #if defined(__LP64__)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >