[PATCH] D105877: [Coroutines] Run coroutine passes by default

2021-08-05 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D105877#2924157 , @ChuanqiXu wrote:

> In D105877#2923257 , @nikic wrote:
>
>> I noticed that this change had a measurable impact on `O0` memory usage, 
>> which I wouldn't have expected 
>> (https://llvm-compile-time-tracker.com/compare.php?from=0f9e6451a836886f39137818c4f0cfd69ae31e62=8a1727ba51d262365b0d9fe10fef7e50da7022cd=max-rss).
>>  Any idea what could cause it? Some additional analysis results hanging 
>> around?
>
> CoroElide would require `Alias Analysis` and `DominatorTreeAnalysis`. Before 
> I didn't noticed that since CoroElide would only happen if inline happens. I 
> would try to add guard by optimization level for CoroElide pass.

Sorry I found that CoroElide wouldn't run at O0. So the reason should be the 
construction for call graph as @aeubanks said.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105877

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


[PATCH] D107244: [AIX] Define _ARCH_PPC64 macro for 32-bit

2021-08-05 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm requested changes to this revision.
cebowleratibm added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Basic/Targets/PPC.cpp:260
+  } else if (getTriple().isOSAIX()) {
+// Also define _ARCH_PPC64 for 32-bit on AIX.
+Builder.defineMacro("_ARCH_PPC64");

Suggest:

// The XL compilers on AIX define _ARCH_PPC64 for both 32 and 64-bit modes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107244

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


[PATCH] D107242: [AIX] Define __HOS_AIX__ macro

2021-08-05 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm added inline comments.



Comment at: clang/lib/Basic/Targets/PPC.cpp:306
+  llvm::Triple HostTriple(llvm::sys::getProcessTriple());
+  if (HostTriple.isOSAIX() && getTriple().isOSAIX()) {
+Builder.defineMacro("__HOS_AIX__");

suggest using a temp rather than unnecessarily declaring the local var:

 if (Triple(sys::getProcessTriple()).isOSAIX() ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107242

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


[PATCH] D107242: [AIX] Define __HOS_AIX__ macro

2021-08-05 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm added inline comments.



Comment at: clang/test/Preprocessor/not-host-aix.c:2
+// UNSUPPORTED: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-LINUX %s
+// PPC-LINUX-NOT:#define __HOS_AIX__ 1

this should specify an aix triple.  The test doesn't run on an aix host and any 
other host should not define the macro even with an aix target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107242

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


[PATCH] D107242: [AIX] Define __HOS_AIX__ macro

2021-08-05 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan updated this revision to Diff 364685.
Jake-Egan added a comment.

Only define if AIX is the target and host.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107242

Files:
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/Preprocessor/host-aix.c
  clang/test/Preprocessor/not-host-aix.c


Index: clang/test/Preprocessor/not-host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/not-host-aix.c
@@ -0,0 +1,3 @@
+// UNSUPPORTED: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-LINUX %s
+// PPC-LINUX-NOT:#define __HOS_AIX__ 1
Index: clang/test/Preprocessor/host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/host-aix.c
@@ -0,0 +1,3 @@
+// REQUIRES: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 
-fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix 
PPC-AIX %s
+// PPC-AIX:#define __HOS_AIX__ 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -301,6 +302,11 @@
 Builder.defineMacro("__LONGDOUBLE64");
   }
 
+  llvm::Triple HostTriple(llvm::sys::getProcessTriple());
+  if (HostTriple.isOSAIX() && getTriple().isOSAIX()) {
+Builder.defineMacro("__HOS_AIX__");
+  }
+
   // Define this for elfv2 (64-bit only) or 64-bit darwin.
   if (ABI == "elfv2" ||
   (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))


Index: clang/test/Preprocessor/not-host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/not-host-aix.c
@@ -0,0 +1,3 @@
+// UNSUPPORTED: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-unknown-linux-gnu -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-LINUX %s
+// PPC-LINUX-NOT:#define __HOS_AIX__ 1
Index: clang/test/Preprocessor/host-aix.c
===
--- /dev/null
+++ clang/test/Preprocessor/host-aix.c
@@ -0,0 +1,3 @@
+// REQUIRES: system-aix
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX %s
+// PPC-AIX:#define __HOS_AIX__ 1
Index: clang/lib/Basic/Targets/PPC.cpp
===
--- clang/lib/Basic/Targets/PPC.cpp
+++ clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/Support/Host.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -301,6 +302,11 @@
 Builder.defineMacro("__LONGDOUBLE64");
   }
 
+  llvm::Triple HostTriple(llvm::sys::getProcessTriple());
+  if (HostTriple.isOSAIX() && getTriple().isOSAIX()) {
+Builder.defineMacro("__HOS_AIX__");
+  }
+
   // Define this for elfv2 (64-bit only) or 64-bit darwin.
   if (ABI == "elfv2" ||
   (getTriple().getOS() == llvm::Triple::Darwin && PointerWidth == 64))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107420: [sema] Disallow __builtin_mul_overflow under special condition.

2021-08-05 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

In D107420#2928975 , @craig.topper 
wrote:

> I put up a patch for a simple fix for this in the backend. 
> https://reviews.llvm.org/D107581  The generated code is not optimal, but 
> maybe better than frontend workarounds.

THX for fix! LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107420

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


[PATCH] D107506: [PowerPC][AIX] Warn when using pragma align(packed) on AIX.

2021-08-05 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm added inline comments.



Comment at: clang/test/Sema/aix-pragma-align-packed-warn.c:13
+  short a : 8;  // expected-warning {{#pragma align(packed) may not be 
compatible with objects generated with AIX XL C/C++}}
+  short b : 8;  // expected-warning {{#pragma align(packed) may not be 
compatible with objects generated with AIX XL C/C++}}
+  int c;

It's undesirable to warn for each bitfield member.  Perhaps diagnose this in 
Sema::ActOnTagFinishDefinition?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107506

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


[PATCH] D107610: [AVR][clang] Pass '-fno-use-init-array' to cc1

2021-08-05 Thread Matt Jacobson via Phabricator via cfe-commits
mhjacobson added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107610

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


[PATCH] D107610: [AVR][clang] Pass '-fno-use-init-array' to cc1

2021-08-05 Thread Ben Shi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdae7adda9499: [AVR][clang] Pass 
-fno-use-init-array to cc1 as default (authored by mhjacobson, 
committed by benshi001).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107610

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  clang/test/Driver/avr-toolchain.c


Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -1,7 +1,7 @@
 // A basic clang -cc1 command-line.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr 2>&1 | FileCheck 
-check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "avr"
+// CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr --sysroot 
%S/Inputs/basic_avr_tree 2>&1 | FileCheck -check-prefix CC1A %s
 // CC1A: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" 
{{".*avr/include"}}
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -11,8 +11,8 @@
 
 #include "Gnu.h"
 #include "clang/Driver/InputInfo.h"
-#include "clang/Driver/ToolChain.h"
 #include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
 
 namespace clang {
 namespace driver {
@@ -26,6 +26,11 @@
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildLinker() const override;
 
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -370,6 +370,16 @@
 addSystemInclude(DriverArgs, CC1Args, AVRInc);
 }
 
+void AVRToolChain::addClangTargetOptions(
+const llvm::opt::ArgList , llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const {
+  // By default, use `.ctors` (not `.init_array`), as required by libgcc, which
+  // runs constructors/destructors on AVR.
+  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
+  options::OPT_fno_use_init_array, false))
+CC1Args.push_back("-fno-use-init-array");
+}
+
 Tool *AVRToolChain::buildLinker() const {
   return new tools::AVR::Linker(getTriple(), *this, LinkStdlib);
 }


Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -1,7 +1,7 @@
 // A basic clang -cc1 command-line.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr 2>&1 | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "avr"
+// CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 | FileCheck -check-prefix CC1A %s
 // CC1A: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" {{".*avr/include"}}
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -11,8 +11,8 @@
 
 #include "Gnu.h"
 #include "clang/Driver/InputInfo.h"
-#include "clang/Driver/ToolChain.h"
 #include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
 
 namespace clang {
 namespace driver {
@@ -26,6 +26,11 @@
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildLinker() const override;
 
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -370,6 +370,16 @@
 addSystemInclude(DriverArgs, CC1Args, AVRInc);
 }
 
+void AVRToolChain::addClangTargetOptions(
+const llvm::opt::ArgList , llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const {
+  // By default, use `.ctors` (not `.init_array`), as required by libgcc, which
+  // runs constructors/destructors on AVR.
+  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
+  options::OPT_fno_use_init_array, false))
+

[clang] dae7add - [AVR][clang] Pass '-fno-use-init-array' to cc1 as default

2021-08-05 Thread Ben Shi via cfe-commits

Author: Matt Jacobson
Date: 2021-08-06T10:14:23+08:00
New Revision: dae7adda949993bd96aa50c551dc64ddebba7923

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

LOG: [AVR][clang] Pass '-fno-use-init-array' to cc1 as default

On AVR, '.ctors' is used, not '.init_array'. Make this the default
unless specifically overridden by driver argument.

This matches gcc, and it matches the behavior in (e.g.) the NetBSD
driver (for certain OS variants).

Reviewed by: MaskRay

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AVR.cpp
clang/lib/Driver/ToolChains/AVR.h
clang/test/Driver/avr-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 5b097f9b2ed94..18c6f41e22b1a 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -370,6 +370,16 @@ void AVRToolChain::AddClangSystemIncludeArgs(const ArgList 
,
 addSystemInclude(DriverArgs, CC1Args, AVRInc);
 }
 
+void AVRToolChain::addClangTargetOptions(
+const llvm::opt::ArgList , llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const {
+  // By default, use `.ctors` (not `.init_array`), as required by libgcc, which
+  // runs constructors/destructors on AVR.
+  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
+  options::OPT_fno_use_init_array, false))
+CC1Args.push_back("-fno-use-init-array");
+}
+
 Tool *AVRToolChain::buildLinker() const {
   return new tools::AVR::Linker(getTriple(), *this, LinkStdlib);
 }

diff  --git a/clang/lib/Driver/ToolChains/AVR.h 
b/clang/lib/Driver/ToolChains/AVR.h
index f612aa691182e..2d027957ed766 100644
--- a/clang/lib/Driver/ToolChains/AVR.h
+++ b/clang/lib/Driver/ToolChains/AVR.h
@@ -11,8 +11,8 @@
 
 #include "Gnu.h"
 #include "clang/Driver/InputInfo.h"
-#include "clang/Driver/ToolChain.h"
 #include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
 
 namespace clang {
 namespace driver {
@@ -26,6 +26,11 @@ class LLVM_LIBRARY_VISIBILITY AVRToolChain : public 
Generic_ELF {
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildLinker() const override;
 

diff  --git a/clang/test/Driver/avr-toolchain.c 
b/clang/test/Driver/avr-toolchain.c
index 692063dc2c348..877f650a3d027 100644
--- a/clang/test/Driver/avr-toolchain.c
+++ b/clang/test/Driver/avr-toolchain.c
@@ -1,7 +1,7 @@
 // A basic clang -cc1 command-line.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr 2>&1 | FileCheck 
-check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "avr"
+// CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr --sysroot 
%S/Inputs/basic_avr_tree 2>&1 | FileCheck -check-prefix CC1A %s
 // CC1A: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" 
{{".*avr/include"}}



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


[PATCH] D106737: [clang] [hexagon] Add resource include dir

2021-08-05 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 364665.
bcain retitled this revision from "DRAFT - [clang] [hexagon] Add resource 
include dir" to "[clang] [hexagon] Add resource include dir".
bcain added a comment.
Herald added a subscriber: ormris.

Add a test case, address failing test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106737

Files:
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/test/Driver/hexagon-toolchain-linux.c


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -95,3 +95,15 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK007 %s
 // CHECK007:  "-internal-isystem" 
"{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
+// 
-
+// internal-isystem for linux with and without musl
+// 
-
+// RUN: %clangxx -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK008 %s
+// RUN: %clangxx -### -target hexagon-unknown-linux \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK008 %s
+// CHECK008:  "-internal-isystem" 
"{{.*}}clang{{/|}}{{.*}}{{/|}}include"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -588,21 +588,43 @@
 
 void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList ,
  ArgStringList ) const 
{
-  if (DriverArgs.hasArg(options::OPT_nostdinc) ||
-  DriverArgs.hasArg(options::OPT_nostdlibinc))
+  if (DriverArgs.hasArg(options::OPT_nostdinc))
 return;
 
+  const bool IsELF = !getTriple().isMusl() && !getTriple().isOSLinux();
+  const bool IsLinuxMusl = getTriple().isMusl() && getTriple().isOSLinux();
+
   const Driver  = getDriver();
-  if (!D.SysRoot.empty()) {
+  SmallString<128> ResourceDirInclude(D.ResourceDir);
+  if (!IsELF) {
+llvm::sys::path::append(ResourceDirInclude, "include");
+if (!DriverArgs.hasArg(options::OPT_nobuiltininc) &&
+(!IsLinuxMusl || DriverArgs.hasArg(options::OPT_nostdlibinc)))
+  addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
+  }
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  const bool HasSysRoot = !D.SysRoot.empty();
+  if (HasSysRoot) {
 SmallString<128> P(D.SysRoot);
-if (getTriple().isMusl())
+if (IsLinuxMusl)
   llvm::sys::path::append(P, "usr/include");
 else
   llvm::sys::path::append(P, "include");
+
 addExternCSystemInclude(DriverArgs, CC1Args, P.str());
-return;
+// LOCAL_INCLUDE_DIR
+addSystemInclude(DriverArgs, CC1Args, P + "/usr/local/include");
+// TOOL_INCLUDE_DIR
+AddMultilibIncludeArgs(DriverArgs, CC1Args);
   }
 
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && IsLinuxMusl)
+addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
+
+  if (HasSysRoot)
+return;
   std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(),
   D.PrefixDirs);
   addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include");


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -95,3 +95,15 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK007 %s
 // CHECK007:  "-internal-isystem" "{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
+// -
+// internal-isystem for linux with and without musl
+// -
+// RUN: %clangxx -### -target hexagon-unknown-linux-musl \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK008 %s
+// RUN: %clangxx -### -target hexagon-unknown-linux \
+// RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK008 %s
+// CHECK008:  "-internal-isystem" "{{.*}}clang{{/|}}{{.*}}{{/|}}include"
Index: clang/lib/Driver/ToolChains/Hexagon.cpp
===
--- clang/lib/Driver/ToolChains/Hexagon.cpp
+++ clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -588,21 +588,43 @@
 
 void 

[PATCH] D107611: [ARC] Add codegen for llvm.ctlz intrinsic for the ARC backend

2021-08-05 Thread Thomas Johnson via Phabricator via cfe-commits
thomasjohns updated this revision to Diff 364657.
thomasjohns added a comment.

Fix missing `}` after bad merge. Move CTLZ next to other pseudo instructions.


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

https://reviews.llvm.org/D107611

Files:
  clang/lib/Basic/Targets/ARC.h
  llvm/lib/Target/ARC/ARCExpandPseudos.cpp
  llvm/lib/Target/ARC/ARCISelLowering.cpp
  llvm/lib/Target/ARC/ARCInstrInfo.td
  llvm/test/CodeGen/ARC/ctlz.ll

Index: llvm/test/CodeGen/ARC/ctlz.ll
===
--- /dev/null
+++ llvm/test/CodeGen/ARC/ctlz.ll
@@ -0,0 +1,14 @@
+; RUN: llc -march=arc < %s | FileCheck %s
+
+target triple = "arc"
+
+declare i32 @llvm.ctlz.i32(i32, i1)
+
+; CHECK-LABEL: clz32:
+; CHECK: fls.f   %r0, %r0
+; CHECK: mov.eq  [[R:%r[01]]], 32
+; CHECK: rsub.ne [[R]], [[R]], 31
+define i32 @clz32(i32 %x) {
+  %a = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
+  ret i32 %a
+}
Index: llvm/lib/Target/ARC/ARCInstrInfo.td
===
--- llvm/lib/Target/ARC/ARCInstrInfo.td
+++ llvm/lib/Target/ARC/ARCInstrInfo.td
@@ -133,6 +133,14 @@
  "STB_FAR $dst, $addr",
  [(truncstorei8 GPR32:$dst, AddrModeFar:$addr)]>;
 
+// TODO: Add `Requires<[HasBitScan]>` predicate when available.
+def CTLZ : PseudoInstARC<(outs GPR32:$A),
+ (ins GPR32:$B),
+ "error.fls $A, $B",
+ [(set GPR32:$A, (ctlz i32:$B))]> {
+  let Defs = [STATUS32];
+}
+
 //===--===//
 // Instruction Generation multiclasses.
 // Generate many variants of a single instruction with a single defining
Index: llvm/lib/Target/ARC/ARCISelLowering.cpp
===
--- llvm/lib/Target/ARC/ARCISelLowering.cpp
+++ llvm/lib/Target/ARC/ARCISelLowering.cpp
@@ -135,6 +135,10 @@
 
   // Sign extend inreg
   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Custom);
+
+  // TODO: Predicate with `options.hasBitScan() ? Legal : Expand` when
+  //   the HasBitScan predicate is available.
+  setOperationAction(ISD::CTLZ, MVT::i32, Legal);
 }
 
 const char *ARCTargetLowering::getTargetNodeName(unsigned Opcode) const {
Index: llvm/lib/Target/ARC/ARCExpandPseudos.cpp
===
--- llvm/lib/Target/ARC/ARCExpandPseudos.cpp
+++ llvm/lib/Target/ARC/ARCExpandPseudos.cpp
@@ -13,6 +13,7 @@
 #include "ARCInstrInfo.h"
 #include "ARCRegisterInfo.h"
 #include "ARCSubtarget.h"
+#include "MCTargetDesc/ARCInfo.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -35,6 +36,7 @@
 
 private:
   void ExpandStore(MachineFunction &, MachineBasicBlock::iterator);
+  void ExpandCTLZ(MachineFunction &, MachineBasicBlock::iterator);
 
   const ARCInstrInfo *TII;
 };
@@ -73,10 +75,45 @@
   SI.eraseFromParent();
 }
 
+void ARCExpandPseudos::ExpandCTLZ(MachineFunction ,
+  MachineBasicBlock::iterator SII) {
+  // Expand:
+  //	%R2 = CTLZ %R0, %STATUS
+  // To:
+  //	%R2 = FLS_f_rr %R0, %STATUS
+  //	%R2 = MOV_cc_ru6 %R2, 32, pred:1, %STATUS
+  //	%R2 = RSUB_cc_rru6 %R2, 31, pred:2, %STATUS
+  MachineInstr  = *SII;
+  const MachineOperand  = SI.getOperand(0);
+  assert(Dest.isReg());
+  const MachineOperand  = SI.getOperand(1);
+  assert(Src.isReg());
+  unsigned DestReg = Dest.getReg();
+
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::FLS_f_rr),
+  DestReg)
+  .add(Src)
+  .addReg(ARC::STATUS32, RegState::ImplicitDefine);
+
+  unsigned Ra = MF.getRegInfo().createVirtualRegister(::GPR32RegClass);
+  unsigned Rb = MF.getRegInfo().createVirtualRegister(::GPR32RegClass);
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::MOV_cc_ru6), Ra)
+  .addImm(32)
+  .addImm(ARCCC::EQ)
+  .addReg(DestReg);
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::RSUB_cc_rru6),
+  Rb)
+  .addImm(31)
+  .addImm(ARCCC::NE)
+  .addReg(Ra);
+
+  SI.eraseFromParent();
+}
+
 bool ARCExpandPseudos::runOnMachineFunction(MachineFunction ) {
   const ARCSubtarget *STI = ();
   TII = STI->getInstrInfo();
-  bool ExpandedStore = false;
+  bool Expanded = false;
   for (auto  : MF) {
 MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
 while (MBBI != E) {
@@ -86,7 +123,11 @@
   case ARC::STH_FAR:
   case ARC::STB_FAR:
 ExpandStore(MF, MBBI);
-ExpandedStore = true;
+Expanded = true;
+break;
+  case ARC::CTLZ:
+ExpandCTLZ(MF, MBBI);
+Expanded = true;
 break;
   default:
 break;
@@ -94,7 +135,7 @@
   MBBI = NMBBI;
 }
   }
-  return ExpandedStore;
+  return Expanded;
 }
 
 FunctionPass 

[PATCH] D107611: [ARC] Add codegen for llvm.ctlz intrinsic for the ARC backend

2021-08-05 Thread Thomas Johnson via Phabricator via cfe-commits
thomasjohns added inline comments.



Comment at: llvm/lib/Target/ARC/ARCInstrInfo.td:314
   defm NORMH : ArcUnaryEXT5Inst<0b001000,"normh">;
+
+// TODO: Add `Requires<[HasBitScan]>` predicate when available.

thomasjohns wrote:
> I just realized I made a bad merge here and dropped the `}`. Fixing it now.
I'll also move this pseudo instruction to be next to the other pseudo 
instructions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107611

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


[PATCH] D106401: [CUDA, MemCpyOpt] Add a flag to force-enable memcpyopt and use it for CUDA.

2021-08-05 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

I've updated the patch and added a test to verify that the knob does work as 
expected. Please take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106401

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


[PATCH] D107611: [ARC] Add codegen for llvm.ctlz intrinsic for the ARC backend

2021-08-05 Thread Thomas Johnson via Phabricator via cfe-commits
thomasjohns added inline comments.



Comment at: llvm/lib/Target/ARC/ARCInstrInfo.td:314
   defm NORMH : ArcUnaryEXT5Inst<0b001000,"normh">;
+
+// TODO: Add `Requires<[HasBitScan]>` predicate when available.

I just realized I made a bad merge here and dropped the `}`. Fixing it now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107611

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


[PATCH] D107610: [AVR][clang] Pass '-fno-use-init-array' to cc1

2021-08-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Looks great!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107610

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


[PATCH] D106401: [CUDA, MemCpyOpt] Add a flag to force-enable memcpyopt and use it for CUDA.

2021-08-05 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 364653.
tra added a comment.

Updated post D106769 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106401

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
  llvm/test/Transforms/MemCpyOpt/no-libcalls.ll


Index: llvm/test/Transforms/MemCpyOpt/no-libcalls.ll
===
--- llvm/test/Transforms/MemCpyOpt/no-libcalls.ll
+++ llvm/test/Transforms/MemCpyOpt/no-libcalls.ll
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -S -memcpyopt < %s | FileCheck %s --check-prefixes=CHECK,LIBCALLS
 ; RUN: opt -S -memcpyopt -mtriple=amdgcn-- < %s | FileCheck %s 
--check-prefixes=CHECK,NO-LIBCALLS
+; RUN: opt -S -memcpyopt -mtriple=amdgcn-- -enable-memcpyopt-without-libcalls 
< %s \
+; RUN: | FileCheck %s --check-prefixes=CHECK,LIBCALLS
 
 ; REQUIRES: amdgpu-registered-target
 
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -67,6 +67,10 @@
 
 #define DEBUG_TYPE "memcpyopt"
 
+static cl::opt EnableMemCpyOptWithoutLibcalls(
+"enable-memcpyopt-without-libcalls", cl::init(false), cl::Hidden,
+cl::desc("Enable memcpyopt even when libcalls are disabled"));
+
 static cl::opt
 EnableMemorySSA("enable-memcpyopt-memoryssa", cl::init(true), cl::Hidden,
 cl::desc("Use MemorySSA-backed MemCpyOpt."));
@@ -677,8 +681,9 @@
   // the corresponding libcalls are not available.
   // TODO: We should really distinguish between libcall availability and
   // our ability to introduce intrinsics.
-  if (T->isAggregateType() && TLI->has(LibFunc_memcpy) &&
-  TLI->has(LibFunc_memmove)) {
+  if (T->isAggregateType() &&
+  (EnableMemCpyOptWithoutLibcalls ||
+   (TLI->has(LibFunc_memcpy) && TLI->has(LibFunc_memmove {
 MemoryLocation LoadLoc = MemoryLocation::get(LI);
 
 // We use alias analysis to check if an instruction may store to
@@ -805,7 +810,7 @@
   // this if the corresponding libfunc is not available.
   // TODO: We should really distinguish between libcall availability and
   // our ability to introduce intrinsics.
-  if (!TLI->has(LibFunc_memset))
+  if (!(TLI->has(LibFunc_memset) || EnableMemCpyOptWithoutLibcalls))
 return false;
 
   // There are two cases that are interesting for this code to handle: memcpy
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -685,7 +685,8 @@
  "Only OpenMP or CUDA offloading kinds are supported for NVIDIA 
GPUs.");
 
   if (DeviceOffloadingKind == Action::OFK_Cuda) {
-CC1Args.push_back("-fcuda-is-device");
+CC1Args.append(
+{"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
 
 if (DriverArgs.hasFlag(options::OPT_fcuda_approx_transcendentals,
options::OPT_fno_cuda_approx_transcendentals, 
false))


Index: llvm/test/Transforms/MemCpyOpt/no-libcalls.ll
===
--- llvm/test/Transforms/MemCpyOpt/no-libcalls.ll
+++ llvm/test/Transforms/MemCpyOpt/no-libcalls.ll
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -S -memcpyopt < %s | FileCheck %s --check-prefixes=CHECK,LIBCALLS
 ; RUN: opt -S -memcpyopt -mtriple=amdgcn-- < %s | FileCheck %s --check-prefixes=CHECK,NO-LIBCALLS
+; RUN: opt -S -memcpyopt -mtriple=amdgcn-- -enable-memcpyopt-without-libcalls < %s \
+; RUN: | FileCheck %s --check-prefixes=CHECK,LIBCALLS
 
 ; REQUIRES: amdgpu-registered-target
 
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -67,6 +67,10 @@
 
 #define DEBUG_TYPE "memcpyopt"
 
+static cl::opt EnableMemCpyOptWithoutLibcalls(
+"enable-memcpyopt-without-libcalls", cl::init(false), cl::Hidden,
+cl::desc("Enable memcpyopt even when libcalls are disabled"));
+
 static cl::opt
 EnableMemorySSA("enable-memcpyopt-memoryssa", cl::init(true), cl::Hidden,
 cl::desc("Use MemorySSA-backed MemCpyOpt."));
@@ -677,8 +681,9 @@
   // the corresponding libcalls are not available.
   // TODO: We should really distinguish between libcall availability and
   // our ability to introduce intrinsics.
-  if (T->isAggregateType() && TLI->has(LibFunc_memcpy) &&
-  TLI->has(LibFunc_memmove)) {
+  if 

[PATCH] D107613: [Clang][DiagnosticSemaKinds] combine diagnostic texts

2021-08-05 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added a reviewer: aaron.ballman.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The diagnostic texts for warning on attributes that don't appear on the
initial declaration is generally useful.  We'd like to re-use it in
D106030 , but first let's combine two that 
already are very similar so we
may re-use it a third time in that commit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107613

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
  clang/test/Sema/internal_linkage.c
  clang/test/SemaCXX/internal_linkage.cpp

Index: clang/test/SemaCXX/internal_linkage.cpp
===
--- clang/test/SemaCXX/internal_linkage.cpp
+++ clang/test/SemaCXX/internal_linkage.cpp
@@ -20,9 +20,9 @@
   };
 };
 
-__attribute__((internal_linkage)) void A::f4() {} // expected-error{{'internal_linkage' attribute does not appear on the first declaration of 'f4'}}
+__attribute__((internal_linkage)) void A::f4() {} // expected-error{{'internal_linkage' attribute does not appear on the first declaration}}
 
-__attribute__((internal_linkage)) int A::zz; // expected-error{{'internal_linkage' attribute does not appear on the first declaration of 'zz'}}
+__attribute__((internal_linkage)) int A::zz; // expected-error{{'internal_linkage' attribute does not appear on the first declaration}}
 
 namespace Z __attribute__((internal_linkage)) { // expected-warning{{'internal_linkage' attribute only applies to}}
 }
Index: clang/test/Sema/internal_linkage.c
===
--- clang/test/Sema/internal_linkage.c
+++ clang/test/Sema/internal_linkage.c
@@ -8,7 +8,7 @@
 
 int var4 __attribute__((common)); // expected-note{{previous definition is here}} expected-note{{conflicting attribute is here}}
 int var4 __attribute__((internal_linkage)); // expected-error{{'internal_linkage' and 'common' attributes are not compatible}} \
-// expected-error{{'internal_linkage' attribute does not appear on the first declaration of 'var4'}}
+// expected-error{{'internal_linkage' attribute does not appear on the first declaration}}
 
 int var5 __attribute__((internal_linkage)); // expected-note{{conflicting attribute is here}}
 int var5 __attribute__((common)); // expected-error{{'common' and 'internal_linkage' attributes are not compatible}}
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
@@ -25,7 +25,7 @@
 [[noreturn]] int e() { b2(); } // ok
 
 int f(); // expected-note {{declaration missing '[[noreturn]]' attribute is here}}
-[[noreturn]] int f(); // expected-error {{function declared '[[noreturn]]' after its first declaration}}
+[[noreturn]] int f(); // expected-error {{'noreturn' attribute does not appear on the first declaration}}
 int f();
 
 [[noreturn]] int g();
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -3355,8 +3355,8 @@
 
   if (New->hasAttr() &&
   !Old->hasAttr()) {
-Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)
-<< New->getDeclName();
+Diag(New->getLocation(), diag::err_attribute_missing_on_first_decl)
+<< New->getAttr();
 notePreviousDefinition(Old, New->getLocation());
 New->dropAttr();
   }
@@ -3680,7 +3680,8 @@
 //   attribute.
 const CXX11NoReturnAttr *NRA = New->getAttr();
 if (NRA && !Old->hasAttr()) {
-  Diag(NRA->getLocation(), diag::err_noreturn_missing_on_first_decl);
+  Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl)
+  << NRA;
   Diag(Old->getFirstDecl()->getLocation(),
diag::note_noreturn_missing_first_decl);
 }
@@ -4168,8 +4169,8 @@
 
   if (New->hasAttr() &&
   !Old->hasAttr()) {
-Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)
-<< New->getDeclName();
+Diag(New->getLocation(), diag::err_attribute_missing_on_first_decl)
+<< New->getAttr();
 notePreviousDefinition(Old, New->getLocation());
 New->dropAttr();
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5571,8 +5571,8 @@
 def err_undefined_inline_var : Error<"inline variable %q0 is not defined">;
 def note_used_here : 

[PATCH] D107611: [ARC] Add codegen for llvm.ctlz intrinsic for the ARC backend

2021-08-05 Thread Thomas Johnson via Phabricator via cfe-commits
thomasjohns created this revision.
thomasjohns added a reviewer: marksl.
Herald added a subscriber: hiraditya.
thomasjohns requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

Add a CTLZ pseudo instruction to tablegen and the ability to expand this pseudo 
instruction instruction to ARC assembly code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107611

Files:
  clang/lib/Basic/Targets/ARC.h
  llvm/lib/Target/ARC/ARCExpandPseudos.cpp
  llvm/lib/Target/ARC/ARCISelLowering.cpp
  llvm/lib/Target/ARC/ARCInstrInfo.td
  llvm/test/CodeGen/ARC/ctlz.ll

Index: llvm/test/CodeGen/ARC/ctlz.ll
===
--- /dev/null
+++ llvm/test/CodeGen/ARC/ctlz.ll
@@ -0,0 +1,14 @@
+; RUN: llc -march=arc < %s | FileCheck %s
+
+target triple = "arc"
+
+declare i32 @llvm.ctlz.i32(i32, i1)
+
+; CHECK-LABEL: clz32:
+; CHECK: fls.f   %r0, %r0
+; CHECK: mov.eq  [[R:%r[01]]], 32
+; CHECK: rsub.ne [[R]], [[R]], 31
+define i32 @clz32(i32 %x) {
+  %a = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
+  ret i32 %a
+}
Index: llvm/lib/Target/ARC/ARCInstrInfo.td
===
--- llvm/lib/Target/ARC/ARCInstrInfo.td
+++ llvm/lib/Target/ARC/ARCInstrInfo.td
@@ -311,6 +311,13 @@
 let Predicates=[HasNorm] in {
   defm NORM  : ArcUnaryEXT5Inst<0b01,"norm">;
   defm NORMH : ArcUnaryEXT5Inst<0b001000,"normh">;
+
+// TODO: Add `Requires<[HasBitScan]>` predicate when available.
+def CTLZ : PseudoInstARC<(outs GPR32:$A),
+ (ins GPR32:$B),
+ "error.fls $A, $B",
+ [(set GPR32:$A, (ctlz i32:$B))]> {
+  let Defs = [STATUS32];
 }
 
 // General Unary Instruction fragments.
Index: llvm/lib/Target/ARC/ARCISelLowering.cpp
===
--- llvm/lib/Target/ARC/ARCISelLowering.cpp
+++ llvm/lib/Target/ARC/ARCISelLowering.cpp
@@ -135,6 +135,10 @@
 
   // Sign extend inreg
   setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Custom);
+
+  // TODO: Predicate with `options.hasBitScan() ? Legal : Expand` when
+  //   the HasBitScan predicate is available.
+  setOperationAction(ISD::CTLZ, MVT::i32, Legal);
 }
 
 const char *ARCTargetLowering::getTargetNodeName(unsigned Opcode) const {
Index: llvm/lib/Target/ARC/ARCExpandPseudos.cpp
===
--- llvm/lib/Target/ARC/ARCExpandPseudos.cpp
+++ llvm/lib/Target/ARC/ARCExpandPseudos.cpp
@@ -13,6 +13,7 @@
 #include "ARCInstrInfo.h"
 #include "ARCRegisterInfo.h"
 #include "ARCSubtarget.h"
+#include "MCTargetDesc/ARCInfo.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -35,6 +36,7 @@
 
 private:
   void ExpandStore(MachineFunction &, MachineBasicBlock::iterator);
+  void ExpandCTLZ(MachineFunction &, MachineBasicBlock::iterator);
 
   const ARCInstrInfo *TII;
 };
@@ -73,10 +75,45 @@
   SI.eraseFromParent();
 }
 
+void ARCExpandPseudos::ExpandCTLZ(MachineFunction ,
+  MachineBasicBlock::iterator SII) {
+  // Expand:
+  //	%R2 = CTLZ %R0, %STATUS
+  // To:
+  //	%R2 = FLS_f_rr %R0, %STATUS
+  //	%R2 = MOV_cc_ru6 %R2, 32, pred:1, %STATUS
+  //	%R2 = RSUB_cc_rru6 %R2, 31, pred:2, %STATUS
+  MachineInstr  = *SII;
+  const MachineOperand  = SI.getOperand(0);
+  assert(Dest.isReg());
+  const MachineOperand  = SI.getOperand(1);
+  assert(Src.isReg());
+  unsigned DestReg = Dest.getReg();
+
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::FLS_f_rr),
+  DestReg)
+  .add(Src)
+  .addReg(ARC::STATUS32, RegState::ImplicitDefine);
+
+  unsigned Ra = MF.getRegInfo().createVirtualRegister(::GPR32RegClass);
+  unsigned Rb = MF.getRegInfo().createVirtualRegister(::GPR32RegClass);
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::MOV_cc_ru6), Ra)
+  .addImm(32)
+  .addImm(ARCCC::EQ)
+  .addReg(DestReg);
+  BuildMI(*SI.getParent(), SI, SI.getDebugLoc(), TII->get(ARC::RSUB_cc_rru6),
+  Rb)
+  .addImm(31)
+  .addImm(ARCCC::NE)
+  .addReg(Ra);
+
+  SI.eraseFromParent();
+}
+
 bool ARCExpandPseudos::runOnMachineFunction(MachineFunction ) {
   const ARCSubtarget *STI = ();
   TII = STI->getInstrInfo();
-  bool ExpandedStore = false;
+  bool Expanded = false;
   for (auto  : MF) {
 MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
 while (MBBI != E) {
@@ -86,7 +123,11 @@
   case ARC::STH_FAR:
   case ARC::STB_FAR:
 ExpandStore(MF, MBBI);
-ExpandedStore = true;
+Expanded = true;
+break;
+  case ARC::CTLZ:
+ExpandCTLZ(MF, MBBI);
+Expanded = true;
 break;
   default:
 break;
@@ -94,7 +135,7 @@
   MBBI = NMBBI;
 }
   }
-  return ExpandedStore;
+  return Expanded;
 }
 
 FunctionPass 

[PATCH] D107610: [AVR][clang] Pass '-fno-use-init-array' to cc1

2021-08-05 Thread Matt Jacobson via Phabricator via cfe-commits
mhjacobson created this revision.
mhjacobson added reviewers: benshi001, MaskRay, dylanmckay.
Herald added subscribers: Jim, krytarowski.
mhjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

On AVR, `.ctors` is used, not `.init_array`.  Make this the default unless 
specifically overridden by driver argument.

This matches gcc, and it matches the behavior in (e.g.) the NetBSD driver (for 
certain OS variants).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107610

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  clang/test/Driver/avr-toolchain.c


Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -1,7 +1,7 @@
 // A basic clang -cc1 command-line.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr 2>&1 | FileCheck 
-check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "avr"
+// CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr --sysroot 
%S/Inputs/basic_avr_tree 2>&1 | FileCheck -check-prefix CC1A %s
 // CC1A: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" 
{{".*avr/include"}}
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -11,8 +11,8 @@
 
 #include "Gnu.h"
 #include "clang/Driver/InputInfo.h"
-#include "clang/Driver/ToolChain.h"
 #include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
 
 namespace clang {
 namespace driver {
@@ -26,6 +26,11 @@
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildLinker() const override;
 
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -370,6 +370,16 @@
 addSystemInclude(DriverArgs, CC1Args, AVRInc);
 }
 
+void AVRToolChain::addClangTargetOptions(
+const llvm::opt::ArgList , llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const {
+  // By default, use `.ctors` (not `.init_array`), as required by libgcc, which
+  // runs constructors/destructors on AVR.
+  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
+  options::OPT_fno_use_init_array, false))
+CC1Args.push_back("-fno-use-init-array");
+}
+
 Tool *AVRToolChain::buildLinker() const {
   return new tools::AVR::Linker(getTriple(), *this, LinkStdlib);
 }


Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -1,7 +1,7 @@
 // A basic clang -cc1 command-line.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr 2>&1 | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "avr"
+// CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array"
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 | FileCheck -check-prefix CC1A %s
 // CC1A: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" {{".*avr/include"}}
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -11,8 +11,8 @@
 
 #include "Gnu.h"
 #include "clang/Driver/InputInfo.h"
-#include "clang/Driver/ToolChain.h"
 #include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
 
 namespace clang {
 namespace driver {
@@ -26,6 +26,11 @@
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
 
+  void
+  addClangTargetOptions(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildLinker() const override;
 
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -370,6 +370,16 @@
 addSystemInclude(DriverArgs, CC1Args, AVRInc);
 }
 
+void AVRToolChain::addClangTargetOptions(
+const llvm::opt::ArgList , llvm::opt::ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const {
+  // By default, use `.ctors` (not `.init_array`), as required by libgcc, which
+  // runs 

[PATCH] D107598: [AIX] "aligned" attribute should not decrease type alignment returned by __alignof__

2021-08-05 Thread Steven Wan 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 rGa91916500d67: [AIX] aligned attribute should not 
decrease type alignment returned by… (authored by stevewan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107598

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/Layout/aix-alignof-align-and-pack-attr.cpp


Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | 
\
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" 
zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" 
zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" 
zeroinitializer, align 16
+} // namespace test3
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2478,11 +2478,16 @@
 return ABIAlign;
 
   if (const auto *RT = T->getAs()) {
-if (TI.AlignIsRequired || RT->getDecl()->isInvalidDecl())
+const RecordDecl *RD = RT->getDecl();
+
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment.
+if ((TI.AlignIsRequired && T->getAs() != nullptr) ||
+RD->isInvalidDecl())
   return ABIAlign;
 
 unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+toBits(getASTRecordLayout(RD).PreferredAlignment));
 assert(PreferredAlign >= ABIAlign &&
"PreferredAlign should be at least as large as ABIAlign.");
 return PreferredAlign;


Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" zeroinitializer, align 16
+} // namespace test3
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2478,11 +2478,16 @@
 return ABIAlign;
 
   if (const auto *RT = T->getAs()) {
-if (TI.AlignIsRequired || RT->getDecl()->isInvalidDecl())
+const RecordDecl *RD = RT->getDecl();
+
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment.
+if ((TI.AlignIsRequired && T->getAs() != nullptr) ||
+RD->isInvalidDecl())
   return ABIAlign;
 
 unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+toBits(getASTRecordLayout(RD).PreferredAlignment));
 assert(PreferredAlign >= ABIAlign &&
"PreferredAlign should be at least as large as ABIAlign.");
 return PreferredAlign;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a919165 - [AIX] "aligned" attribute should not decrease type alignment returned by __alignof__

2021-08-05 Thread Steven Wan via cfe-commits

Author: Steven Wan
Date: 2021-08-05T18:18:58-04:00
New Revision: a91916500d67155ca17bfdf3294541f871f90a45

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

LOG: [AIX] "aligned" attribute should not decrease type alignment returned by 
__alignof__

`__alignof__(x)` always returns `ABIAlign` if the "x" is marked 
`__attribute__((aligned()))`. However, the "aligned" attribute should only 
increase the alignment of a struct, or struct member, unless it's used together 
with the "packed" attribute, or used as a part of a typedef, in which case, the 
"aligned" attribute can both increase and decrease alignment.

Reviewed By: sfertile

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

Added: 
clang/test/Layout/aix-alignof-align-and-pack-attr.cpp

Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4ff2aa5307bbe..4c9dc42c5b5dd 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2478,11 +2478,16 @@ unsigned ASTContext::getPreferredTypeAlign(const Type 
*T) const {
 return ABIAlign;
 
   if (const auto *RT = T->getAs()) {
-if (TI.AlignIsRequired || RT->getDecl()->isInvalidDecl())
+const RecordDecl *RD = RT->getDecl();
+
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment.
+if ((TI.AlignIsRequired && T->getAs() != nullptr) ||
+RD->isInvalidDecl())
   return ABIAlign;
 
 unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+toBits(getASTRecordLayout(RD).PreferredAlignment));
 assert(PreferredAlign >= ABIAlign &&
"PreferredAlign should be at least as large as ABIAlign.");
 return PreferredAlign;

diff  --git a/clang/test/Layout/aix-alignof-align-and-pack-attr.cpp 
b/clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
new file mode 100644
index 0..51f3c5a2adc11
--- /dev/null
+++ b/clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | 
\
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" 
zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" 
zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" 
zeroinitializer, align 16
+} // namespace test3



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


[PATCH] D107598: [AIX] "aligned" attribute should not decrease type alignment returned by __alignof__

2021-08-05 Thread Steven Wan via Phabricator via cfe-commits
stevewan updated this revision to Diff 364630.
stevewan added a comment.

Add third test case as suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107598

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/Layout/aix-alignof-align-and-pack-attr.cpp


Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | 
\
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" 
zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" 
zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" 
zeroinitializer, align 16
+} // namespace test3
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2478,11 +2478,16 @@
 return ABIAlign;
 
   if (const auto *RT = T->getAs()) {
-if (TI.AlignIsRequired || RT->getDecl()->isInvalidDecl())
+const RecordDecl *RD = RT->getDecl();
+
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment.
+if ((TI.AlignIsRequired && T->getAs() != nullptr) ||
+RD->isInvalidDecl())
   return ABIAlign;
 
 unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+toBits(getASTRecordLayout(RD).PreferredAlignment));
 assert(PreferredAlign >= ABIAlign &&
"PreferredAlign should be at least as large as ABIAlign.");
 return PreferredAlign;


Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" zeroinitializer, align 16
+} // namespace test3
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2478,11 +2478,16 @@
 return ABIAlign;
 
   if (const auto *RT = T->getAs()) {
-if (TI.AlignIsRequired || RT->getDecl()->isInvalidDecl())
+const RecordDecl *RD = RT->getDecl();
+
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment.
+if ((TI.AlignIsRequired && T->getAs() != nullptr) ||
+RD->isInvalidDecl())
   return ABIAlign;
 
 unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+toBits(getASTRecordLayout(RD).PreferredAlignment));
 assert(PreferredAlign >= ABIAlign &&
"PreferredAlign should be at least as large as ABIAlign.");
 return PreferredAlign;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107598: [AIX] "aligned" attribute should not decrease type alignment returned by __alignof__

2021-08-05 Thread Sean Fertile via Phabricator via cfe-commits
sfertile accepted this revision.
sfertile added a comment.
This revision is now accepted and ready to land.

LGTM, other then 1 small test update.




Comment at: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp:21
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" 
zeroinitializer, align 2
+} // namespace test2

Minor nit: add 
```
namespace test3 {
struct __attribute__((__aligned__(16))) C {
double x;
} c;
```
as a third test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107598

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


[PATCH] D105426: [clangd] WIP: Unused header warnings

2021-08-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 364625.
kbobyrev added a comment.

Exclude std:: namespace handling.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IWYU.cpp
  clang-tools-extra/clangd/IWYU.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/IWYUTests.cpp

Index: clang-tools-extra/clangd/unittests/IWYUTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/IWYUTests.cpp
@@ -0,0 +1,118 @@
+//===--- IWYUTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "IWYU.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::ElementsAreArray;
+
+TEST(IWYU, ReferencedLocations) {
+  struct TestCase {
+std::string HeaderCode;
+std::string MainCode;
+  };
+  TestCase Cases[] = {
+  {
+  "int ^x();",
+  "int y = x();",
+  },
+  {
+  "class ^X;",
+  "X *y;",
+  },
+  {
+  "using ^Integer = int;",
+  "Integer x;",
+  },
+  {
+  "struct ^X{int ^a;}; X ^foo();",
+  "int y = foo().a;",
+  },
+  {
+  "class ^X{}; X ^foo();",
+  "auto bar() { return foo(); }",
+  },
+  {
+  "class ^X; class ^X{}; class ^X;",
+  "X *y;",
+  },
+  {
+  "struct ^X { ^X(int) {} int ^foo(); };",
+  "auto x = X(42); auto y = x.foo();",
+  },
+  {
+  "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
+  "auto b = X::foo();",
+  },
+  {
+  "template  class ^X;",
+  "X *y;",
+  },
+  {
+  "typedef bool ^Y; template  struct ^X {};",
+  "X x;",
+  },
+  {
+  "struct Foo; struct ^Foo{}; typedef Foo ^Bar;",
+  "Bar b;",
+  },
+  {
+  "class ^X{}; X ^getX();",
+  "auto x = getX();",
+  },
+  {
+  "namespace ns { struct ^X; struct ^X {}; }",
+  "using ns::X;",
+  },
+  {
+  "enum ^Color { ^Red = 42, Green = 9000};",
+  "int MyColor = Red;",
+  },
+  {
+  "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
+  "int Lang = X::CXX;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should report the UsingDecl.
+  // This information is not preserved in the AST.
+  // ^
+  "namespace ns { class ^X; }; using ns::X;",
+  "X *y;",
+  }};
+  for (const TestCase  : Cases) {
+TestTU TU;
+TU.Code = T.MainCode;
+Annotations Header(T.HeaderCode);
+TU.HeaderCode = Header.code().str();
+auto AST = TU.build();
+
+std::vector Points;
+for (const auto  : findReferencedLocations(AST).AllLocations) {
+  if (AST.getSourceManager().getBufferName(Loc).endswith(
+  TU.HeaderFilename)) {
+Points.push_back(offsetToPosition(
+TU.HeaderCode, AST.getSourceManager().getFileOffset(Loc)));
+  }
+}
+llvm::sort(Points);
+
+EXPECT_EQ(Points, Header.points()) << T.HeaderCode << "\n---\n"
+   << T.MainCode;
+  }
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -61,6 +61,7 @@
   IndexActionTests.cpp
   IndexTests.cpp
   InlayHintTests.cpp
+  IWYUTests.cpp
   JSONTransportTests.cpp
   LoggerTests.cpp
   LSPBinderTests.cpp
Index: clang-tools-extra/clangd/IWYU.h
===
--- /dev/null
+++ clang-tools-extra/clangd/IWYU.h
@@ -0,0 +1,60 @@
+//===--- IWYU.h - include-what-you-use analysis -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This defines functionality modeled after Include-What-You-Use
+/// (https://include-what-you-use.org/). The variant we implement is not
+/// equivalent to the 

[PATCH] D107125: [Diagnostic] Split 'qualifier on reference type has no effect' out into a new flag

2021-08-05 Thread Luna Kirkby via Phabricator via cfe-commits
lunasorcery marked an inline comment as done.
lunasorcery added a comment.

Yes, that would be "Luna Kirkby "


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

https://reviews.llvm.org/D107125

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


[PATCH] D105426: [clangd] WIP: Unused header warnings

2021-08-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 364615.
kbobyrev added a comment.

Add one more test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IWYU.cpp
  clang-tools-extra/clangd/IWYU.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/IWYUTests.cpp

Index: clang-tools-extra/clangd/unittests/IWYUTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/IWYUTests.cpp
@@ -0,0 +1,118 @@
+//===--- IWYUTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "IWYU.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::ElementsAreArray;
+
+TEST(IWYU, ReferencedLocations) {
+  struct TestCase {
+std::string HeaderCode;
+std::string MainCode;
+  };
+  TestCase Cases[] = {
+  {
+  "int ^x();",
+  "int y = x();",
+  },
+  {
+  "class ^X;",
+  "X *y;",
+  },
+  {
+  "using ^Integer = int;",
+  "Integer x;",
+  },
+  {
+  "struct ^X{int ^a;}; X ^foo();",
+  "int y = foo().a;",
+  },
+  {
+  "class ^X{}; X ^foo();",
+  "auto bar() { return foo(); }",
+  },
+  {
+  "class ^X; class ^X{}; class ^X;",
+  "X *y;",
+  },
+  {
+  "struct ^X { ^X(int) {} int ^foo(); };",
+  "auto x = X(42); auto y = x.foo();",
+  },
+  {
+  "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
+  "auto b = X::foo();",
+  },
+  {
+  "template  class ^X;",
+  "X *y;",
+  },
+  {
+  "typedef bool ^Y; template  struct ^X {};",
+  "X x;",
+  },
+  {
+  "struct Foo; struct ^Foo{}; typedef Foo ^Bar;",
+  "Bar b;",
+  },
+  {
+  "class ^X{}; X ^getX();",
+  "auto x = getX();",
+  },
+  {
+  "namespace ns { struct ^X; struct ^X {}; }",
+  "using ns::X;",
+  },
+  {
+  "enum ^Color { ^Red = 42, Green = 9000};",
+  "int MyColor = Red;",
+  },
+  {
+  "struct ^X { enum ^Language { ^CXX = 42, Python = 9000}; };",
+  "int Lang = X::CXX;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should report the UsingDecl.
+  // This information is not preserved in the AST.
+  // ^
+  "namespace ns { class ^X; }; using ns::X;",
+  "X *y;",
+  }};
+  for (const TestCase  : Cases) {
+TestTU TU;
+TU.Code = T.MainCode;
+Annotations Header(T.HeaderCode);
+TU.HeaderCode = Header.code().str();
+auto AST = TU.build();
+
+std::vector Points;
+for (const auto  : findReferencedLocations(AST).AllLocations) {
+  if (AST.getSourceManager().getBufferName(Loc).endswith(
+  TU.HeaderFilename)) {
+Points.push_back(offsetToPosition(
+TU.HeaderCode, AST.getSourceManager().getFileOffset(Loc)));
+  }
+}
+llvm::sort(Points);
+
+EXPECT_EQ(Points, Header.points()) << T.HeaderCode << "\n---\n"
+   << T.MainCode;
+  }
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -61,6 +61,7 @@
   IndexActionTests.cpp
   IndexTests.cpp
   InlayHintTests.cpp
+  IWYUTests.cpp
   JSONTransportTests.cpp
   LoggerTests.cpp
   LSPBinderTests.cpp
Index: clang-tools-extra/clangd/IWYU.h
===
--- /dev/null
+++ clang-tools-extra/clangd/IWYU.h
@@ -0,0 +1,60 @@
+//===--- IWYU.h - include-what-you-use analysis -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This defines functionality modeled after Include-What-You-Use
+/// (https://include-what-you-use.org/). The variant we implement is not
+/// equivalent to the original tool 

[PATCH] D107506: [PowerPC][AIX] Warn when using pragma align(packed) on AIX.

2021-08-05 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm accepted this revision.
cebowleratibm added a comment.
This revision is now accepted and ready to land.

It would be nice if the diagnostic could be deferred to layout, in case the 
struct is defined but not used in a header, but I understand that #pragma 
pack(1) and #pragma align(packed) become ambiguous at the point of layout.  I 
think this is a reasonable diagnostic given the impact of silently incompatible 
codegen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107506

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


[PATCH] D105426: [clangd] WIP: Unused header warnings

2021-08-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 364610.
kbobyrev added a comment.

Trim the patch even further: the scope is now simply findAllReferences
mechanism. Add more tests and improve functionality (handle using decls and
implicit types).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IWYU.cpp
  clang-tools-extra/clangd/IWYU.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/IWYUTests.cpp

Index: clang-tools-extra/clangd/unittests/IWYUTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/IWYUTests.cpp
@@ -0,0 +1,114 @@
+//===--- IWYUTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "IWYU.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::ElementsAreArray;
+
+TEST(IWYU, ReferencedLocations) {
+  struct TestCase {
+std::string HeaderCode;
+std::string MainCode;
+  };
+  TestCase Cases[] = {
+  {
+  "int ^x();",
+  "int y = x();",
+  },
+  {
+  "class ^X;",
+  "X *y;",
+  },
+  {
+  "using ^Integer = int;",
+  "Integer x;",
+  },
+  {
+  "struct ^X{int ^a;}; X ^foo();",
+  "int y = foo().a;",
+  },
+  {
+  "class ^X{}; X ^foo();",
+  "auto bar() { return foo(); }",
+  },
+  {
+  "class ^X; class ^X{}; class ^X;",
+  "X *y;",
+  },
+  {
+  "struct ^X { ^X(int) {} int ^foo(); };",
+  "auto x = X(42); auto y = x.foo();",
+  },
+  {
+  "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
+  "auto b = X::foo();",
+  },
+  {
+  "template  class ^X;",
+  "X *y;",
+  },
+  {
+  "typedef bool ^Y; template  struct ^X {};",
+  "X x;",
+  },
+  {
+  "struct Foo; struct ^Foo{}; typedef Foo ^Bar;",
+  "Bar b;",
+  },
+  {
+  "class ^X{}; X ^getX();",
+  "auto x = getX();",
+  },
+  {
+  "namespace ns { struct ^X; struct ^X {}; }",
+  "using ns::X;",
+  },
+  {
+  "enum ^Color { ^Red = 42, Green = 9000};",
+  "int MyColor = Red;",
+  },
+  {
+  // FIXME(kirillbobyrev): Should report the UsingDecl.
+  // This information is not preserved in the AST.
+  // ^
+  "namespace ns { class ^X; }; using ns::X;",
+  "X *y;",
+  }};
+  for (const TestCase  : Cases) {
+TestTU TU;
+TU.Code = T.MainCode;
+Annotations Header(T.HeaderCode);
+TU.HeaderCode = Header.code().str();
+auto AST = TU.build();
+
+std::vector Points;
+for (const auto  : findReferencedLocations(AST).AllLocations) {
+  if (AST.getSourceManager().getBufferName(Loc).endswith(
+  TU.HeaderFilename)) {
+Points.push_back(offsetToPosition(
+TU.HeaderCode, AST.getSourceManager().getFileOffset(Loc)));
+  }
+}
+llvm::sort(Points);
+
+EXPECT_EQ(Points, Header.points()) << T.HeaderCode << "\n---\n"
+   << T.MainCode;
+  }
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -61,6 +61,7 @@
   IndexActionTests.cpp
   IndexTests.cpp
   InlayHintTests.cpp
+  IWYUTests.cpp
   JSONTransportTests.cpp
   LoggerTests.cpp
   LSPBinderTests.cpp
Index: clang-tools-extra/clangd/IWYU.h
===
--- /dev/null
+++ clang-tools-extra/clangd/IWYU.h
@@ -0,0 +1,60 @@
+//===--- IWYU.h - include-what-you-use analysis -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This defines functionality modeled after Include-What-You-Use
+/// (https://include-what-you-use.org/). The variant we implement is not
+/// equivalent to 

[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-08-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked 2 inline comments as done.
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/cxx2a-consteval.cpp:612
+static_assert(is_same::value);
+
+} // namespace unevaluated

rsmith wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > cor3ntin wrote:
> > > > cor3ntin wrote:
> > > > > aaron.ballman wrote:
> > > > > > Here's an interesting test case:
> > > > > > ```
> > > > > > #include 
> > > > > > 
> > > > > > struct S {
> > > > > >   virtual void f();
> > > > > > };
> > > > > > 
> > > > > > struct D : S {
> > > > > >   void f() override;
> > > > > > };
> > > > > > 
> > > > > > consteval S *get_s() { return nullptr; }
> > > > > > 
> > > > > > void func() {
> > > > > >   (void)typeid(*get_s());
> > > > > > }
> > > > > > ```
> > > > > > `typeid` still needs to evaluate its operand (due to the 
> > > > > > polymorphic return type of `*get_s()`), and so you should get a 
> > > > > > diagnostic about evaluating the side effects by calling `get_s()`. 
> > > > > > I think this then runs into 
> > > > > > https://eel.is/c++draft/expr.const#13.sentence-3 and we should 
> > > > > > diagnose?
> > > > > Not sure!
> > > > > Also, in the context of this pr, the question is also whether 
> > > > > `decltype(typeid(*get_s()))` should be ill-formed I think
> > > > Actually, I'm reading the wording again and I really don't know anymore.
> > > > `get_s()` is a constant expression, right?
> > > > `*get_s()` is not, I think but is that relevant here
> > > > 
> > > > I played with a bunch of things in the code but the more I look at it 
> > > > the less I'm convinced an action is needed.
> > > The changes to `Sema::CheckForImmediateInvocation()` to check for an 
> > > unevaluated context and https://eel.is/c++draft/expr.const#13.sentence-3 
> > > that say an immediate invocation shall be a constant expression are what 
> > > got me thinking about this code snippet in the first place. I was trying 
> > > to decide whether `isUnevaluatedContext()` is correct or not because with 
> > > `typeid`, it is potentially evaluated (so sometimes it's unevaluated).
> > > 
> > > Interestingly, everyone comes up with a different answer: 
> > > https://godbolt.org/z/TqjGh1he6 and I don't (yet) know who is correct.
> > @rsmith Can you enlighten us here?
> > My take is that `get_s()` is a constant expression and therefore an 
> > immediate invocation. independently of what `*get_s()` does but I'm not 
> > sure if that's a correct reading.  
> > 
> > Thanks a lot!
> There are a few different cases here and I don't think any compiler is 
> getting them all right.
> 
> ```
> struct S {
>   void f();
> };
> struct T {
>   virtual void f();
> };
> 
> consteval S *null_s() { return nullptr; }
> consteval S *make_s() { return new S; }
> consteval T *null_t() { return nullptr; }
> consteval T *make_s() { return new T; }
> 
> void func() {
>   (void)typeid(*null_s()); // #1
>   (void)typeid(*make_s()); // #2
>   (void)typeid(*null_t()); // #3
>   (void)typeid(*make_t()); // #4
> }
> ```
> 
> Here, #3 and #4 pass an lvalue of polymorphic class type to `typeid`, so the 
> arguments to those `typeid`s are potentially evaluated. #1 and #2 pass an 
> lvalue of non-polymorphic class type, so those arguments are unevaluated 
> operands. So we have two immediate invocations: the `null_t()` call and the 
> `make_t()` call.
> 
> Lines #1 and #2 are valid because there's no immediate invocation to check. 
> (Clang and GCC get this wrong and reject #2.)
> Line #3 is valid because the call to `null_t()` is a constant expression. 
> (MSVC gets this wrong for reasons I don't understand.)
> Line #4 is ill-formed because the call to `make_t()` is not a constant 
> expression, because it returns a heap allocation.
> 
> The way we handle `typeid` in general is to parse its operand as an 
> unevaluated operand, and then later `TransformToPotentiallyEvaluated` if we 
> find it's a glvalue of or pointer to polymorphic class type. If you find the 
> above testcase isn't handled correctly, you may need to make some changes in 
> `TransformToPotentiallyEvaluated` to trigger the proper rebuilding. (You 
> might need to force it to transform `CallExpr`s that refer to `consteval` 
> functions even if nothing within them have changed, for example.)
Thanks, this was super useful!

I think clang gets everything right now - I added your scenarios as tests with 
the other typeid tests 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

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


[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-08-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 364606.
cor3ntin added a comment.

- Add tests for typeid

All the tests suggested by Richard pass as expected without having to
modify the implementation of type id itself!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1103,10 +1103,11 @@
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3;>P1073R3
-  No
+  Partial
 

 https://wg21.link/p1937r2;>P1937R2
+Clang 13
   
 
   std::is_constant_evaluated
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -8,7 +8,7 @@
   return i;
 }
 
-consteval constexpr int f2(int i) { 
+consteval constexpr int f2(int i) {
   //expected-error@-1 {{cannot combine}}
   return i;
 }
@@ -195,7 +195,7 @@
 struct A {
   consteval int f(int) {
 // expected-note@-1+ {{declared here}}
-return 0;
+return 0;
   }
 };
 
@@ -239,7 +239,7 @@
   int t = f(i);
 // expected-error@-1 {{is not a constant expression}}
 // expected-note@-2 {{function parameter}}
-  return f(0);  
+  return f(0);
 }
 
 consteval int f_eval(int i) {
@@ -255,7 +255,7 @@
   int t = f(i);
 // expected-error@-1 {{is not a constant expression}}
 // expected-note@-2 {{function parameter}}
-  return f(0);  
+  return f(0);
 };
 
 }
@@ -594,3 +594,21 @@
 }
 
 } // namespace special_ctor
+
+namespace unevaluated {
+
+template  struct is_same { static const bool value = false; };
+template  struct is_same { static const bool value = true; };
+
+long f(); // expected-note {{declared here}}
+auto consteval g(auto a) {
+  return a;
+}
+
+auto e = g(f()); // expected-error {{is not a constant expression}}
+ // expected-note@-1 {{non-constexpr function 'f' cannot be used in a constant expression}}
+
+using T = decltype(g(f()));
+static_assert(is_same::value);
+
+} // namespace unevaluated
Index: clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
===
--- clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
+++ clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // C++ [basic.def.odr]p2:
 //   An expression is potentially evaluated unless it [...] is the
@@ -34,3 +35,33 @@
   // Triggers an error (as it should);
   xpr.g(Poly()); // expected-note{{instantiation of member function}}
 }
+
+#if __cplusplus >= 202002L
+
+namespace unevaluated {
+
+struct S {
+  void f();
+};
+struct T {
+  virtual void f();
+};
+
+consteval S *null_s() { return nullptr; }
+consteval S *make_s() { return new S; }
+consteval T *null_t() { return nullptr; }
+consteval T *make_t() { return new T; }
+
+void func() {
+  (void)typeid(*null_s());
+  (void)typeid(*make_s());
+  (void)typeid(*null_t()); // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
+  (void)typeid(*make_t()); // expected-error {{call to consteval function 'unevaluated::make_t' is not a constant expression}}
+   // expected-note@-1 {{pointer to heap-allocated object is not a constant expression}}
+   // expected-note@-8 {{heap allocation performed here}}
+   // expected-warning@-3 {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
+}
+
+} // namespace unevaluated
+
+#endif
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16585,7 +16585,8 @@
 }
 
 ExprResult Sema::CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl) {
-  if (!E.isUsable() || !Decl || !Decl->isConsteval() || isConstantEvaluated() ||
+  if (isUnevaluatedContext() || !E.isUsable() || !Decl ||
+  !Decl->isConsteval() || isConstantEvaluated() ||
   RebuildingImmediateInvocation)
 return E;
 
@@ -18702,8 +18703,8 @@
   OdrUse = false;
 
   if (auto *FD = dyn_cast(E->getDecl()))
-if (!isConstantEvaluated() && FD->isConsteval() &&
-!RebuildingImmediateInvocation)
+if (!isUnevaluatedContext() && !isConstantEvaluated() &&
+FD->isConsteval() && !RebuildingImmediateInvocation)
   ExprEvalContexts.back().ReferenceToConsteval.insert(E);
   MarkExprReferenced(*this, E->getLocation(), E->getDecl(), E, OdrUse,

[PATCH] D107598: [AIX] "aligned" attribute should not decrease type alignment returned by __alignof__

2021-08-05 Thread Steven Wan via Phabricator via cfe-commits
stevewan added a comment.

This is a split of the query portion from https://reviews.llvm.org/D107394.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107598

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


[PATCH] D107598: [AIX] "aligned" attribute should not decrease type alignment returned by __alignof__

2021-08-05 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 "__alignof__()" operator, when used on a type, always returns the 
`ABIAlign` if the type is marked `__attribute__((aligned()))`. However, the 
"aligned" attribute should only increase the alignment of a struct, or struct 
member, unless it's used together with the "packed" attribute, or used as a 
part of a typedef, in which case, the "aligned" attribute can both increase and 
decrease alignment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107598

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/Layout/aix-alignof-align-and-pack-attr.cpp


Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | 
\
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" 
zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" 
zeroinitializer, align 2
+} // namespace test2
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2478,11 +2478,16 @@
 return ABIAlign;
 
   if (const auto *RT = T->getAs()) {
-if (TI.AlignIsRequired || RT->getDecl()->isInvalidDecl())
+const RecordDecl *RD = RT->getDecl();
+
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment.
+if ((TI.AlignIsRequired && T->getAs() != nullptr) ||
+RD->isInvalidDecl())
   return ABIAlign;
 
 unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+toBits(getASTRecordLayout(RD).PreferredAlignment));
 assert(PreferredAlign >= ABIAlign &&
"PreferredAlign should be at least as large as ABIAlign.");
 return PreferredAlign;


Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===
--- /dev/null
+++ clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN:   FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) C {
+  double x;
+} c;
+
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" zeroinitializer, align 2
+} // namespace test2
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2478,11 +2478,16 @@
 return ABIAlign;
 
   if (const auto *RT = T->getAs()) {
-if (TI.AlignIsRequired || RT->getDecl()->isInvalidDecl())
+const RecordDecl *RD = RT->getDecl();
+
+// When used as part of a typedef, or together with a 'packed' attribute,
+// the 'aligned' attribute can be used to decrease alignment.
+if ((TI.AlignIsRequired && T->getAs() != nullptr) ||
+RD->isInvalidDecl())
   return ABIAlign;
 
 unsigned PreferredAlign = static_cast(
-toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+toBits(getASTRecordLayout(RD).PreferredAlignment));
 assert(PreferredAlign >= ABIAlign &&
"PreferredAlign should be at least as large as ABIAlign.");
 return PreferredAlign;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107595: [clang] fix transformation of template arguments for concept specializations

2021-08-05 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
mizvekov published this revision for review.
mizvekov added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

See PR50864.

This fixes error caused by substitution failures on template arguments
for concept specializations. With this patch, in such cases, the concept
specialization will evaluate to false instead.

As a bonus, we:

- Remove some memory leak as an std::string was being stored in the AST.
- Remove some duplicate implementation of serialization (as string) of 
substitution diagnostics for concepts.
- Fix some cases where we would try to take a SFINAE diagnostic without 
checking if there was one first.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107595

Files:
  clang/include/clang/AST/ASTConcept.h
  clang/include/clang/AST/ExprConcepts.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTConcept.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -169,3 +169,24 @@
   template void f(T, U) = delete;
   void g() { f(0, 0); }
 }
+
+namespace PR50864 {
+  template  concept Valid = T::valid; // expected-note {{evaluated to false}}
+  template  struct A {
+template  void f(U) requires Valid;
+// expected-note@-1 {{candidate template ignored: constraints not satisfied [with U = int]}}
+// expected-note@-2 {{because 'typename T::type' does not satisfy 'Valid'}}
+// expected-note@-3 {{because substituted constraint expression is ill-formed: type 'int' cannot be used prior to '::' because it has no members}}
+template  void f(U) requires Valid;
+// expected-note@-1 {{candidate template ignored: constraints not satisfied [with U = int]}}
+// expected-note@-2 {{does not satisfy 'Valid'}}
+  };
+
+  template struct X { static constexpr bool valid = V; };
+
+  struct T1 : X {};
+  void t1() { A().f(1); } // expected-error {{no matching member function for call to 'f'}}
+
+  struct T2 : X {};
+  void t2() { A().f(1); }
+}
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -409,10 +409,9 @@
   if (E)
 Record.AddStmt(E);
   else {
-auto *Diag = DetailRecord.second.get *>();
-Record.AddSourceLocation(Diag->first);
-Record.AddString(Diag->second);
+auto *Diag = DetailRecord.second.get();
+Record.AddSourceLocation(Diag->Loc);
+Record.AddString(Diag->Msg);
   }
 }
   }
@@ -423,8 +422,8 @@
 ASTRecordWriter ,
 const concepts::Requirement::SubstitutionDiagnostic *D) {
   Record.AddString(D->SubstitutedEntity);
-  Record.AddSourceLocation(D->DiagLoc);
-  Record.AddString(D->DiagMessage);
+  Record.AddSourceLocation(D->Diag.Loc);
+  Record.AddString(D->Diag.Msg);
 }
 
 void ASTStmtWriter::VisitConceptSpecializationExpr(
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3357,25 +3357,6 @@
 return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
   }
 
-  /// Build a new Objective-C boxed expression.
-  ///
-  /// By default, performs semantic analysis to build the new expression.
-  /// Subclasses may override this routine to provide different behavior.
-  ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS,
-  SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
-  NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
-  TemplateArgumentListInfo *TALI) {
-CXXScopeSpec SS;
-SS.Adopt(NNS);
-ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
- ConceptNameInfo,
- FoundDecl,
- NamedConcept, TALI);
-if (Result.isInvalid())
-  return ExprError();
-return Result;
-  }
-
   /// \brief Build a new requires expression.
   ///
   /// By default, performs semantic analysis to build the new expression.
@@ -12271,20 +12252,10 @@
E->getEndLoc());
 }
 
-template
-ExprResult
-TreeTransform::TransformConceptSpecializationExpr(
- ConceptSpecializationExpr *E) {
-  const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
-  TemplateArgumentListInfo 

[PATCH] D106302: Implement P1937 consteval in unevaluated contexts

2021-08-05 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/test/SemaCXX/cxx2a-consteval.cpp:612
+static_assert(is_same::value);
+
+} // namespace unevaluated

cor3ntin wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > cor3ntin wrote:
> > > > aaron.ballman wrote:
> > > > > Here's an interesting test case:
> > > > > ```
> > > > > #include 
> > > > > 
> > > > > struct S {
> > > > >   virtual void f();
> > > > > };
> > > > > 
> > > > > struct D : S {
> > > > >   void f() override;
> > > > > };
> > > > > 
> > > > > consteval S *get_s() { return nullptr; }
> > > > > 
> > > > > void func() {
> > > > >   (void)typeid(*get_s());
> > > > > }
> > > > > ```
> > > > > `typeid` still needs to evaluate its operand (due to the polymorphic 
> > > > > return type of `*get_s()`), and so you should get a diagnostic about 
> > > > > evaluating the side effects by calling `get_s()`. I think this then 
> > > > > runs into https://eel.is/c++draft/expr.const#13.sentence-3 and we 
> > > > > should diagnose?
> > > > Not sure!
> > > > Also, in the context of this pr, the question is also whether 
> > > > `decltype(typeid(*get_s()))` should be ill-formed I think
> > > Actually, I'm reading the wording again and I really don't know anymore.
> > > `get_s()` is a constant expression, right?
> > > `*get_s()` is not, I think but is that relevant here
> > > 
> > > I played with a bunch of things in the code but the more I look at it the 
> > > less I'm convinced an action is needed.
> > The changes to `Sema::CheckForImmediateInvocation()` to check for an 
> > unevaluated context and https://eel.is/c++draft/expr.const#13.sentence-3 
> > that say an immediate invocation shall be a constant expression are what 
> > got me thinking about this code snippet in the first place. I was trying to 
> > decide whether `isUnevaluatedContext()` is correct or not because with 
> > `typeid`, it is potentially evaluated (so sometimes it's unevaluated).
> > 
> > Interestingly, everyone comes up with a different answer: 
> > https://godbolt.org/z/TqjGh1he6 and I don't (yet) know who is correct.
> @rsmith Can you enlighten us here?
> My take is that `get_s()` is a constant expression and therefore an immediate 
> invocation. independently of what `*get_s()` does but I'm not sure if that's 
> a correct reading.  
> 
> Thanks a lot!
There are a few different cases here and I don't think any compiler is getting 
them all right.

```
struct S {
  void f();
};
struct T {
  virtual void f();
};

consteval S *null_s() { return nullptr; }
consteval S *make_s() { return new S; }
consteval T *null_t() { return nullptr; }
consteval T *make_s() { return new T; }

void func() {
  (void)typeid(*null_s()); // #1
  (void)typeid(*make_s()); // #2
  (void)typeid(*null_t()); // #3
  (void)typeid(*make_t()); // #4
}
```

Here, #3 and #4 pass an lvalue of polymorphic class type to `typeid`, so the 
arguments to those `typeid`s are potentially evaluated. #1 and #2 pass an 
lvalue of non-polymorphic class type, so those arguments are unevaluated 
operands. So we have two immediate invocations: the `null_t()` call and the 
`make_t()` call.

Lines #1 and #2 are valid because there's no immediate invocation to check. 
(Clang and GCC get this wrong and reject #2.)
Line #3 is valid because the call to `null_t()` is a constant expression. (MSVC 
gets this wrong for reasons I don't understand.)
Line #4 is ill-formed because the call to `make_t()` is not a constant 
expression, because it returns a heap allocation.

The way we handle `typeid` in general is to parse its operand as an unevaluated 
operand, and then later `TransformToPotentiallyEvaluated` if we find it's a 
glvalue of or pointer to polymorphic class type. If you find the above testcase 
isn't handled correctly, you may need to make some changes in 
`TransformToPotentiallyEvaluated` to trigger the proper rebuilding. (You might 
need to force it to transform `CallExpr`s that refer to `consteval` functions 
even if nothing within them have changed, for example.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106302

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


[PATCH] D107477: [Clang][AST][NFC] Resolve FIXME: Make CXXRecordDecl *Record const.

2021-08-05 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 364584.
gAlfonso-bit added a comment.

Improved patch


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

https://reviews.llvm.org/D107477

Files:
  clang/include/clang/AST/ComparisonCategories.h


Index: clang/include/clang/AST/ComparisonCategories.h
===
--- clang/include/clang/AST/ComparisonCategories.h
+++ clang/include/clang/AST/ComparisonCategories.h
@@ -115,8 +115,7 @@
 public:
   /// The declaration for the comparison category type from the
   /// standard library.
-  // FIXME: Make this const
-  CXXRecordDecl *Record = nullptr;
+  const CXXRecordDecl *Record = nullptr;
 
   /// The Kind of the comparison category type
   ComparisonCategoryType Kind;


Index: clang/include/clang/AST/ComparisonCategories.h
===
--- clang/include/clang/AST/ComparisonCategories.h
+++ clang/include/clang/AST/ComparisonCategories.h
@@ -115,8 +115,7 @@
 public:
   /// The declaration for the comparison category type from the
   /// standard library.
-  // FIXME: Make this const
-  CXXRecordDecl *Record = nullptr;
+  const CXXRecordDecl *Record = nullptr;
 
   /// The Kind of the comparison category type
   ComparisonCategoryType Kind;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12118
 
-TargetLowering::AtomicExpansionKind
-SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
+TargetLowering::AtomicExpansionKind SITargetLowering::reportAtomicExpand(
+AtomicRMWInst *RMW, TargetLowering::AtomicExpansionKind Kind,

Just static, no need to expose it from SITargetLowering. Maybe even a functor 
inside shouldExpandAtomicRMWInIR ifself capturing ORE and RMW to pass less 
arguments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12165
 
-return AtomicExpansionKind::None;
+ORE->emit([&] {
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());

You need to remove all of that now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364574.
gandhi21299 marked 4 inline comments as done.
gandhi21299 added a comment.

requested changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll

Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -16,15 +16,20 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Type-Based Alias Analysis
 ; CHECK-NEXT: Scoped NoAlias Alias Analysis
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -10,13 +10,18 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -44,6 +44,11 @@
 ; GCN-O0-NEXT:Lower OpenCL enqueued blocks
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
+; GCN-O0-NEXT:  Dominator Tree Construction
+; GCN-O0-NEXT:  Natural Loop Information
+; GCN-O0-NEXT:  Lazy Branch Probability Analysis
+; GCN-O0-NEXT:  Lazy Block Frequency Analysis
+; GCN-O0-NEXT:  Optimization Remark Emitter
 ; GCN-O0-NEXT:  Expand Atomic instructions
 ; GCN-O0-NEXT:  Lower constant intrinsics
 ; GCN-O0-NEXT:  Remove unreachable blocks from the CFG
@@ -180,6 +185,11 @@
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
+; GCN-O1-NEXT:  Dominator Tree Construction
+; GCN-O1-NEXT:  Natural Loop Information
+; GCN-O1-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-NEXT:  Optimization Remark Emitter
 ; GCN-O1-NEXT:  Expand Atomic instructions
 ; GCN-O1-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-NEXT:  Dominator Tree Construction
@@ -431,6 +441,11 @@
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
+; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
+; GCN-O1-OPTS-NEXT:  Natural Loop Information
+; GCN-O1-OPTS-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-OPTS-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-OPTS-NEXT:  Optimization Remark Emitter
 ; GCN-O1-OPTS-NEXT:  Expand Atomic instructions
 ; GCN-O1-OPTS-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
@@ -715,6 +730,11 

[PATCH] D106701: [clang] Implement -falign-loops=N (N is a power of 2) for non-LTO

2021-08-05 Thread Fangrui Song 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 rGc38efb4899ea: [clang] Implement -falign-loops=N (N is a 
power of 2) for non-LTO (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D106701?vs=364224=364575#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106701

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/align-loops.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/falign-loops.c

Index: clang/test/Driver/falign-loops.c
===
--- /dev/null
+++ clang/test/Driver/falign-loops.c
@@ -0,0 +1,17 @@
+/// Treat -falign-loops=0 as not specifying the option.
+// RUN: %clang -### -falign-loops=0 %s 2>&1 | FileCheck %s --check-prefix=CHECK_NO
+// RUN: %clang -### -falign-loops=1 %s 2>&1 | FileCheck %s --check-prefix=CHECK_1
+// RUN: %clang -### -falign-loops=4 %s 2>&1 | FileCheck %s --check-prefix=CHECK_4
+/// Only powers of 2 are supported for now.
+// RUN: %clang -### -falign-loops=5 %s 2>&1 | FileCheck %s --check-prefix=CHECK_5
+// RUN: %clang -### -falign-loops=65536 %s 2>&1 | FileCheck %s --check-prefix=CHECK_65536
+// RUN: %clang -### -falign-loops=65537 %s 2>&1 | FileCheck %s --check-prefix=CHECK_65537
+// RUN: %clang -### -falign-loops=a %s 2>&1 | FileCheck %s --check-prefix=CHECK_ERR_A
+
+// CHECK_NO-NOT: "-falign-loops=
+// CHECK_1: "-falign-loops=1"
+// CHECK_4: "-falign-loops=4"
+// CHECK_5: error: alignment is not a power of 2 in '-falign-loops=5'
+// CHECK_65536: "-falign-loops=65536"
+// CHECK_65537: error: invalid integral value '65537' in '-falign-loops=65537'
+// CHECK_ERR_A: error: invalid integral value 'a' in '-falign-loops=a'
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -397,7 +397,6 @@
 // CHECK-WARNING-DAG: optimization flag '-falign-labels' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-labels=100' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-loops' is not supported
-// CHECK-WARNING-DAG: optimization flag '-falign-loops=100' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-jumps' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-jumps=100' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fexcess-precision=100' is not supported
Index: clang/test/CodeGen/align-loops.c
===
--- /dev/null
+++ clang/test/CodeGen/align-loops.c
@@ -0,0 +1,15 @@
+// REQUIRES: x86-registered-target
+/// Check asm because we use llvm::TargetOptions.
+
+// RUN: %clang_cc1 -triple=x86_64 -S %s -falign-loops=8 -O -o - | FileCheck %s --check-prefixes=CHECK,CHECK_8
+// RUN: %clang_cc1 -triple=x86_64 -S %s -falign-loops=32 -O -o - | FileCheck %s --check-prefixes=CHECK,CHECK_32
+
+// CHECK-LABEL: foo:
+// CHECK_8:   .p2align 3, 0x90
+// CHECK_32:  .p2align 5, 0x90
+
+void bar();
+void foo() {
+  for (int i = 0; i < 64; ++i)
+bar();
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4739,6 +4739,22 @@
 CmdArgs.push_back(Args.MakeArgString(std::to_string(FunctionAlignment)));
   }
 
+  // We support -falign-loops=N where N is a power of 2. GCC supports more
+  // forms.
+  if (const Arg *A = Args.getLastArg(options::OPT_falign_loops_EQ)) {
+unsigned Value = 0;
+if (StringRef(A->getValue()).getAsInteger(10, Value) || Value > 65536)
+  TC.getDriver().Diag(diag::err_drv_invalid_int_value)
+  << A->getAsString(Args) << A->getValue();
+else if (Value & Value - 1)
+  TC.getDriver().Diag(diag::err_drv_alignment_not_power_of_two)
+  << A->getAsString(Args) << A->getValue();
+// Treat =0 as unspecified (use the target preference).
+if (Value)
+  CmdArgs.push_back(Args.MakeArgString("-falign-loops=" +
+   Twine(std::min(Value, 65536u;
+  }
+
   llvm::Reloc::Model RelocationModel;
   unsigned PICLevel;
   bool IsPIE;
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -580,6 +580,7 @@
   Options.ValueTrackingVariableLocations =
   CodeGenOpts.ValueTrackingVariableLocations;
   Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex;

[clang] c38efb4 - [clang] Implement -falign-loops=N (N is a power of 2) for non-LTO

2021-08-05 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2021-08-05T12:17:50-07:00
New Revision: c38efb4899eac7b82daaf1320ad79f6271f9648a

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

LOG: [clang] Implement -falign-loops=N (N is a power of 2) for non-LTO

GCC supports multiple forms of -falign-loops=.
-falign-loops= is currently ignored in Clang.

This patch implements the simplest but the most useful form where N is a
power of 2.

The underlying implementation uses a `llvm::TargetOptions` option for now.
Bitcode generation ignores this option.

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

Added: 
clang/test/CodeGen/align-loops.c
clang/test/Driver/falign-loops.c

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index e3202cf887561..73edae63bfc91 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -293,6 +293,8 @@ CODEGENOPT(StackRealignment  , 1, 0) ///< Control whether 
to force stack
  ///< realignment.
 CODEGENOPT(UseInitArray  , 1, 0) ///< Control whether to use .init_array or
  ///< .ctors.
+VALUE_CODEGENOPT(LoopAlignment , 32, 0) ///< Overrides default loop
+///< alignment, if not 0.
 VALUE_CODEGENOPT(StackAlignment, 32, 0) ///< Overrides default stack
 ///< alignment, if not 0.
 VALUE_CODEGENOPT(StackProbeSize, 32, 4096) ///< Overrides default stack

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 78d7ba6b63836..660f7e418b9ea 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -228,6 +228,7 @@ def err_drv_invalid_value : Error<"invalid value '%1' in 
'%0'">;
 def err_drv_invalid_int_value : Error<"invalid integral value '%1' in '%0'">;
 def err_drv_invalid_value_with_suggestion : Error<
 "invalid value '%1' in '%0', expected one of: %2">;
+def err_drv_alignment_not_power_of_two : Error<"alignment is not a power of 2 
in '%0'">;
 def err_drv_invalid_remap_file : Error<
 "invalid option '%0' not of the form ;">;
 def err_drv_invalid_gcc_output_type : Error<

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 4a91e2c20dc58..7549ad43911be 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -399,6 +399,7 @@ ENUM_LANGOPT(ClangABICompat, ClangABI, 4, ClangABI::Latest,
  "with")
 
 COMPATIBLE_VALUE_LANGOPT(FunctionAlignment, 5, 0, "Default alignment for 
functions")
+COMPATIBLE_VALUE_LANGOPT(LoopAlignment, 32, 0, "Default alignment for loops")
 
 LANGOPT(FixedPoint, 1, 0, "fixed point types")
 LANGOPT(PaddingOnUnsignedFixedPoint, 1, 0,

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9f42072a92900..79f541f6b2473 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1087,6 +1087,9 @@ defm access_control : BoolFOption<"access-control",
   PosFlag>;
 def falign_functions : Flag<["-"], "falign-functions">, Group;
 def falign_functions_EQ : Joined<["-"], "falign-functions=">, Group;
+def falign_loops_EQ : Joined<["-"], "falign-loops=">, Group, 
Flags<[CC1Option]>, MetaVarName<"">,
+  HelpText<"N must be a power of two. Align loops to the boundary">,
+  MarshallingInfoInt>;
 def fno_align_functions: Flag<["-"], "fno-align-functions">, Group;
 defm allow_editor_placeholders : BoolFOption<"allow-editor-placeholders",
   LangOpts<"AllowEditorPlaceholders">, DefaultFalse,
@@ -4336,7 +4339,6 @@ def ld_path_EQ : Joined<["--"], "ld-path=">, 
Group;
 defm align_labels : BooleanFFlag<"align-labels">, 
Group;
 def falign_labels_EQ : Joined<["-"], "falign-labels=">, 
Group;
 defm align_loops : BooleanFFlag<"align-loops">, 
Group;
-def falign_loops_EQ : Joined<["-"], "falign-loops=">, 
Group;
 defm align_jumps : BooleanFFlag<"align-jumps">, 
Group;
 def falign_jumps_EQ : Joined<["-"], "falign-jumps=">, 
Group;
 

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 0915255bf88f1..9e4e40a36e056 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ 

[PATCH] D107506: [PowerPC][AIX] Warn when using pragma align(packed) on AIX.

2021-08-05 Thread Sean Fertile via Phabricator via cfe-commits
sfertile added a comment.

Good point Chris. The only difference in layout is related to bitfield members, 
so I have moved the warning to `VerifyBitField` as suggested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107506

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


[PATCH] D107506: [PowerPC][AIX] Warn when using pragma align(packed) on AIX.

2021-08-05 Thread Sean Fertile via Phabricator via cfe-commits
sfertile updated this revision to Diff 364570.
sfertile added a comment.

Only emit diagnostic on bitfield members, which is the only difference in 
align(packed) behaviour XL and clang/xlclang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107506

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/aix-pragma-align-packed-warn.c


Index: clang/test/Sema/aix-pragma-align-packed-warn.c
===
--- /dev/null
+++ clang/test/Sema/aix-pragma-align-packed-warn.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff  -fxl-pragma-pack -verify 
-fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff  -fxl-pragma-pack -verify 
-fsyntax-only %s
+
+#pragma align(packed)
+struct A {
+  short s1;
+  int   : 0;  // expected-warning {{#pragma align(packed) may not be 
compatible with objects generated with AIX XL C/C++}}
+  short s2;
+};
+
+struct B {
+  short a : 8;  // expected-warning {{#pragma align(packed) may not be 
compatible with objects generated with AIX XL C/C++}}
+  short b : 8;  // expected-warning {{#pragma align(packed) may not be 
compatible with objects generated with AIX XL C/C++}}
+  int c;
+};
+#pragma align(reset)
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16701,6 +16701,13 @@
 }
   }
 
+  if (Context.getTargetInfo().getTriple().isOSAIX() &&
+  AlignPackStack.hasValue()) {
+AlignPackInfo APInfo = AlignPackStack.CurrentValue;
+if (APInfo.IsAlignAttr() && APInfo.getAlignMode() == AlignPackInfo::Packed)
+  Diag(FieldLoc, diag::warn_pragma_align_not_xl_compatible);
+  }
+
   return BitWidth;
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -913,6 +913,9 @@
   InGroup;
 def err_pragma_options_align_mac68k_target_unsupported : Error<
   "mac68k alignment pragma is not supported on this target">;
+def warn_pragma_align_not_xl_compatible : Warning<
+  "#pragma align(packed) may not be compatible with objects generated with AIX 
XL C/C++">,
+  InGroup;
 def warn_pragma_pack_invalid_alignment : Warning<
   "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">,
   InGroup;


Index: clang/test/Sema/aix-pragma-align-packed-warn.c
===
--- /dev/null
+++ clang/test/Sema/aix-pragma-align-packed-warn.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff  -fxl-pragma-pack -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff  -fxl-pragma-pack -verify -fsyntax-only %s
+
+#pragma align(packed)
+struct A {
+  short s1;
+  int   : 0;  // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}}
+  short s2;
+};
+
+struct B {
+  short a : 8;  // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}}
+  short b : 8;  // expected-warning {{#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++}}
+  int c;
+};
+#pragma align(reset)
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16701,6 +16701,13 @@
 }
   }
 
+  if (Context.getTargetInfo().getTriple().isOSAIX() &&
+  AlignPackStack.hasValue()) {
+AlignPackInfo APInfo = AlignPackStack.CurrentValue;
+if (APInfo.IsAlignAttr() && APInfo.getAlignMode() == AlignPackInfo::Packed)
+  Diag(FieldLoc, diag::warn_pragma_align_not_xl_compatible);
+  }
+
   return BitWidth;
 }
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -913,6 +913,9 @@
   InGroup;
 def err_pragma_options_align_mac68k_target_unsupported : Error<
   "mac68k alignment pragma is not supported on this target">;
+def warn_pragma_align_not_xl_compatible : Warning<
+  "#pragma align(packed) may not be compatible with objects generated with AIX XL C/C++">,
+  InGroup;
 def warn_pragma_pack_invalid_alignment : Warning<
   "expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">,
   InGroup;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/tools/libclang/libclang.map:1
-/* If you add a symbol to this file, make sure to add it with the correct
- * version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
- * symbols with the version LLVM_14.
- * On platforms where versions scripts are not used, this file will be used to
- * generate a list of exports for libclang.so
- */
-
+# If you add a symbol to this file, make sure to add it with the correct
+# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new

MaskRay wrote:
> ro wrote:
> > MaskRay wrote:
> > > GNU ld doesn't support `#` comments. ld.lld supports it.
> > Drats, I'd have sworn they supported `#' comments, too,
> > especially since the version script syntax originated with
> > Sun and was later adopted by GNU `ld`.
> Confirmed that GNU ld and gold support `#` in version scripts, but not in 
> linker scripts.
> 
> ld.lld supports both.
> 
> Using `#` is fine to me if Solaris ld doesn't support `/*` in GNU version 
> scripts.
Correction: only GNU ld doesn't support `#` in linker scripts.

ld.lld and gold support `#` everywhere.

Filed a GNU ld feature request 
https://sourceware.org/bugzilla/show_bug.cgi?id=28198


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/tools/libclang/libclang.map:1
-/* If you add a symbol to this file, make sure to add it with the correct
- * version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
- * symbols with the version LLVM_14.
- * On platforms where versions scripts are not used, this file will be used to
- * generate a list of exports for libclang.so
- */
-
+# If you add a symbol to this file, make sure to add it with the correct
+# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new

ro wrote:
> MaskRay wrote:
> > GNU ld doesn't support `#` comments. ld.lld supports it.
> Drats, I'd have sworn they supported `#' comments, too,
> especially since the version script syntax originated with
> Sun and was later adopted by GNU `ld`.
Confirmed that GNU ld and gold support `#` in version scripts, but not in 
linker scripts.

ld.lld supports both.

Using `#` is fine to me if Solaris ld doesn't support `/*` in GNU version 
scripts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12155
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "A floating-point atomic instruction with no following use"
+" will generate an unsafe hardware instruction";

gandhi21299 wrote:
> rampitec wrote:
> > I do not understand this message about the use. We are checking the use 
> > below simply because there was no return version of global_atomic_add_f32 
> > on gfx908, so we are forced to expand it.
> right, I forgot to erase that part. How does the following look:
> 
> "A floating-point atomic instruction will generate an unsafe hardware 
> instruction"
> 
> I am not sure what other details I could put in here
In this place it might fail to update memory. But it is difficult to read and 
understand with all of that big ORE->emit blobs all over the place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 marked an inline comment as done.
gandhi21299 added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12155
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "A floating-point atomic instruction with no following use"
+" will generate an unsafe hardware instruction";

rampitec wrote:
> I do not understand this message about the use. We are checking the use below 
> simply because there was no return version of global_atomic_add_f32 on 
> gfx908, so we are forced to expand it.
right, I forgot to erase that part. How does the following look:

"A floating-point atomic instruction will generate an unsafe hardware 
instruction"

I am not sure what other details I could put in here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

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


[PATCH] D105904: [clangd] Support `#pragma mark` in the outline

2021-08-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Thanks! I think it looks good, I've suggested some more simplifications to 
termination detection. If you can delete the rest I'd like to take a final look 
at the rest of the details.




Comment at: clang-tools-extra/clangd/FindSymbols.cpp:680
+// We'll figure out where the Pragmas.front() should go.
+PragmaMarkSymbol P = Pragmas.front();
+Pragmas = Pragmas.drop_front();

nit: std::move



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:712
+ArrayRef NextPragmas = Pragmas;
+while (true) {
+  // We own all children that occur after us.

```
bool TerminatedByNextPragma = false;
for (auto  : Pragmas) {
  // If we hit a pragma outside of Cur, the rest will be outside as well.
  if (!Cur->contains(NextPragma))
   break;

  // NextPragma cannot terminate P if it is nested inside a children, look for 
the next one.
  if (any_of(Cur->children, [](...) { return Child->contains(NextPragma); })
  continue;

  // Pragma owns all the children between P and NextPragma
  auto It = std::partition();
  P.children.assign(make_move_iterator(It), 
make_move_iterator(Cur->children.end()));
  Cur->children.erase(It, ...);
  TerminatedByNextPragma = true;
  break;
}
if(!TerminatedByNextPragma) {
  // P is terminated by the end of current symbol, hence it owns all the 
children after P.
  auto It = std::partition();
  P.children.assign(make_move_iterator(It), 
make_move_iterator(Cur->children.end()));
  Cur->children.erase(It, ...);  
}
// Update the range for P to cover children and append to Cur.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105904

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


[PATCH] D107589: [CMake] Support setting default fused FP contract via CMake

2021-08-05 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: mibintc, andrew.w.kaylor, rjmccall, zahiraam, hans, 
haowei.
Herald added a subscriber: mgorny.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

D74436  changed the default fused FP contract 
which broke several
projects and it may take a while to address those issues. This
change allows setting the default fused FP contract via CMake, so
vendors can change their defaults rather than having to include the
-ffp-contract=off flag in every project to revert to the previous
behavior while the issues that were uncovered by D74436 
 are being
addressed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107589

Files:
  clang/CMakeLists.txt
  clang/cmake/caches/Fuchsia-stage2.cmake
  clang/cmake/caches/Fuchsia.cmake
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/ToolChains/Clang.cpp


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -27,6 +27,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
@@ -2641,7 +2642,7 @@
 
   llvm::DenormalMode DenormalFPMath = DefaultDenormalFPMath;
   llvm::DenormalMode DenormalFP32Math = DefaultDenormalFP32Math;
-  StringRef FPContract = "on";
+  StringRef FPContract = CLANG_DEFAULT_FFP_CONTRACT;
   bool StrictFPModel = false;
 
 
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -32,6 +32,9 @@
 /* Default OpenMP runtime used by -fopenmp. */
 #define CLANG_DEFAULT_OPENMP_RUNTIME "${CLANG_DEFAULT_OPENMP_RUNTIME}"
 
+/* Default fused FP contract */
+#define CLANG_DEFAULT_FFP_CONTRACT "${CLANG_DEFAULT_FFP_CONTRACT}"
+
 /* Default architecture for OpenMP offloading to Nvidia GPUs. */
 #define CLANG_OPENMP_NVPTX_DEFAULT_ARCH "${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}"
 
Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -28,6 +28,7 @@
   set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
 endif()
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
+set(CLANG_DEFAULT_FFP_CONTRACT off CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
 set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -37,6 +37,7 @@
   set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
 endif()
 set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
+set(CLANG_DEFAULT_FFP_CONTRACT off CACHE STRING "")
 set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
 set(CLANG_ENABLE_STATIC_ANALYZER ON CACHE BOOL "")
 set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -335,6 +335,17 @@
   "LLVM_LINK_LLVM_DYLIB=OFF")
 endif()
 
+set(CLANG_DEFAULT_FFP_CONTRACT "on" CACHE STRING
+  "Default fused FP contract (\"fast\", \"on\", \"off\", 
\"fast-honor-pragmas\")")
+if (NOT(CLANG_DEFAULT_FFP_CONTRACT STREQUAL "fast" OR
+CLANG_DEFAULT_FFP_CONTRACT STREQUAL "on" OR
+CLANG_DEFAULT_FFP_CONTRACT STREQUAL "off" OR
+CLANG_DEFAULT_FFP_CONTRACT STREQUAL "fast-honor-pragmas"))
+  message(WARNING "Resetting default fused FP contract")
+  set(CLANG_DEFAULT_RTLIB "on" CACHE STRING
+"Default fused FP contract (\"fast\", \"on\", \"off\", 
\"fast-honor-pragmas\", empty for platform default)" FORCE)
+endif()
+
 # The libdir suffix must exactly match whatever LLVM's configuration used.
 set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")
 


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -27,6 +27,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Distro.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
@@ -2641,7 +2642,7 @@
 
   llvm::DenormalMode DenormalFPMath = DefaultDenormalFPMath;
   llvm::DenormalMode DenormalFP32Math = DefaultDenormalFP32Math;
-  

[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12155
+  OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+  Remark << "A floating-point atomic instruction with no following use"
+" will generate an unsafe hardware instruction";

I do not understand this message about the use. We are checking the use below 
simply because there was no return version of global_atomic_add_f32 on gfx908, 
so we are forced to expand it.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12165
 
-  return RMW->use_empty() ? AtomicExpansionKind::None
-  : AtomicExpansionKind::CmpXChg;
+  if (RMW->use_empty()) {
+if (RMW->getFunction()

That's a lot of churn. Please create a function returning AtomicExpansionKind, 
pass what you are going to return into that function, return that argument from 
the function, and also pass a string for diagnosticts to emit from there. 
Replace returns here with its calls. Like:

`return reportAtomicExpand(AtomicExpansionKind::None, ORE, "Produced HW atomic 
is unsafe and might not update memory");`



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12198
+  Remark
+  << "A floating-point atomic instruction will generate an unsafe"
+ " hardware instruction";

This one might be unsafe not because of the cache it works on, but because it 
might not follow denorm mode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364527.
gandhi21299 added a comment.

added missing newline


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll

Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -16,15 +16,20 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Type-Based Alias Analysis
 ; CHECK-NEXT: Scoped NoAlias Alias Analysis
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -10,13 +10,18 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -44,6 +44,11 @@
 ; GCN-O0-NEXT:Lower OpenCL enqueued blocks
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
+; GCN-O0-NEXT:  Dominator Tree Construction
+; GCN-O0-NEXT:  Natural Loop Information
+; GCN-O0-NEXT:  Lazy Branch Probability Analysis
+; GCN-O0-NEXT:  Lazy Block Frequency Analysis
+; GCN-O0-NEXT:  Optimization Remark Emitter
 ; GCN-O0-NEXT:  Expand Atomic instructions
 ; GCN-O0-NEXT:  Lower constant intrinsics
 ; GCN-O0-NEXT:  Remove unreachable blocks from the CFG
@@ -180,6 +185,11 @@
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
+; GCN-O1-NEXT:  Dominator Tree Construction
+; GCN-O1-NEXT:  Natural Loop Information
+; GCN-O1-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-NEXT:  Optimization Remark Emitter
 ; GCN-O1-NEXT:  Expand Atomic instructions
 ; GCN-O1-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-NEXT:  Dominator Tree Construction
@@ -431,6 +441,11 @@
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
+; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
+; GCN-O1-OPTS-NEXT:  Natural Loop Information
+; GCN-O1-OPTS-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-OPTS-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-OPTS-NEXT:  Optimization Remark Emitter
 ; GCN-O1-OPTS-NEXT:  Expand Atomic instructions
 ; GCN-O1-OPTS-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
@@ -715,6 +730,11 @@
 ; GCN-O2-NEXT:Lower uses of LDS 

[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364525.
gandhi21299 marked an inline comment as done.
gandhi21299 added a comment.

- addressed reviewer feedback and updated test accordingly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/AMDGPU/fp-atomics-remarks-gfx90a.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll

Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -16,15 +16,20 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Type-Based Alias Analysis
 ; CHECK-NEXT: Scoped NoAlias Alias Analysis
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -10,13 +10,18 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -44,6 +44,11 @@
 ; GCN-O0-NEXT:Lower OpenCL enqueued blocks
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
+; GCN-O0-NEXT:  Dominator Tree Construction
+; GCN-O0-NEXT:  Natural Loop Information
+; GCN-O0-NEXT:  Lazy Branch Probability Analysis
+; GCN-O0-NEXT:  Lazy Block Frequency Analysis
+; GCN-O0-NEXT:  Optimization Remark Emitter
 ; GCN-O0-NEXT:  Expand Atomic instructions
 ; GCN-O0-NEXT:  Lower constant intrinsics
 ; GCN-O0-NEXT:  Remove unreachable blocks from the CFG
@@ -180,6 +185,11 @@
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
+; GCN-O1-NEXT:  Dominator Tree Construction
+; GCN-O1-NEXT:  Natural Loop Information
+; GCN-O1-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-NEXT:  Optimization Remark Emitter
 ; GCN-O1-NEXT:  Expand Atomic instructions
 ; GCN-O1-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-NEXT:  Dominator Tree Construction
@@ -431,6 +441,11 @@
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
+; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
+; GCN-O1-OPTS-NEXT:  Natural Loop Information
+; GCN-O1-OPTS-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-OPTS-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-OPTS-NEXT: 

[PATCH] D107294: [clang-tidy] adds warning to suggest users replace symbols with words

2021-08-05 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb marked an inline comment as done.
cjdb added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/AlternativeTokensCheck.h:20-21
+namespace readability {
+/// Flags uses of symbol-based bitwise and logical operators.
+class AlternativeTokensCheck : public ClangTidyCheck {
+public:

whisperity wrote:
> Following from gone thread due to file rename.
> 
> >>! In D107294#2923102, @cjdb wrote:
> > Not sure I'm following you here: are you suggesting I put the contents of 
> > my `rst` file in a comment here?
> 
> Not the entire //RST//, but the one-sentence or first-paragraph "pitch". For 
> example, let's see `bugprone-branch-clone`'s class's doc-comment:
> 
> ```
> /// A check for detecting if/else if/else chains where two or more branches 
> are
> /// Type I clones of each other (that is, they contain identical code), for
> /// detecting switch statements where two or more consecutive branches are
> /// Type I clones of each other, and for detecting conditional operators where
> /// the true and false expressions are Type I clones of each other.
> ///
> /// For the user-facing documentation see:
> /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-branch-clone.html
> class BranchCloneCheck : public ClangTidyCheck {
> ```
> 
> Or another one selected randomly, `performance-no-automatic-move`:
> 
> ```
> /// Finds local variables that cannot be automatically moved due to constness.
> ///
> /// For the user-facing documentation see:
> /// 
> http://clang.llvm.org/extra/clang-tidy/checks/performance-no-automatic-move.html
> class NoAutomaticMoveCheck : public ClangTidyCheck {
> ```
> 
> So there is a one-paragraph summary of the check itself (it could be shorter 
> than here...), and there is a text that's generated from a template (I think 
> `add-new-check.py` sets the new check's files as such when you run it), which 
> basically just links the upstream official website render of your check's 
> documentation HTML.
Thanks for the comprehensive examples!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107294

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


[PATCH] D107294: [clang-tidy] adds warning to suggest users replace symbols with words

2021-08-05 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 364555.
cjdb marked 10 inline comments as done.
cjdb added a comment.

- adds TODOs
- adds asserts
- removes "imported" SourceManager (apparently there was already a pointer in 
`Result`)
- fixes C++ documentation to match opening line of RST doc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107294

Files:
  clang-tools-extra/clang-tidy/readability/AlternativeTokensCheck.cpp
  clang-tools-extra/clang-tidy/readability/AlternativeTokensCheck.h
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/StrictConstCorrectness.h
  clang-tools-extra/clang-tidy/readability/StrictConstCorrectness.kpp
  clang-tools-extra/docs/clang-tidy/checks/readability-alternative-tokens.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-alternative-tokens-no-warn.c
  clang-tools-extra/test/clang-tidy/checkers/readability-alternative-tokens.c
  clang-tools-extra/test/clang-tidy/checkers/readability-alternative-tokens.cpp
  clang/test/Analysis/diagnostics/readability-strict-const-correctness.cpp
  llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/readability/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/readability/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/readability/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/readability/BUILD.gn
@@ -12,6 +12,7 @@
 "//llvm/lib/Support",
   ]
   sources = [
+"AlternativeTokensCheck.cpp",
 "AvoidConstParamsInDecls.cpp",
 "BracesAroundStatementsCheck.cpp",
 "ConstReturnTypeCheck.cpp",
Index: clang/test/Analysis/diagnostics/readability-strict-const-correctness.cpp
===
--- /dev/null
+++ clang/test/Analysis/diagnostics/readability-strict-const-correctness.cpp
@@ -0,0 +1,51 @@
+// RUN: %check_clang_tidm1 %s readabilitm1-strict-const-correctness %t
+int f1()
+{
+  int c1 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'c1' is never modified and can be const-qualified
+  // CHECK-FIXES: int const c1 = 0;
+
+  int m1 = c1;
+  m1 += 5;
+
+  int ca[] = {0, 1};
+  m1 = a[0];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'ca' elements are never modified and can be const-qualified
+  // CHECK-FIXES: int const ca[] = {0, 1};
+
+  int ma[] = {0, 1};
+  ma[0] = 10;
+
+  int& clr = m1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'r1' never modifies its referee and can be const-qualified
+  // CHECK-FIXES: int const& r1 = m1;
+
+  int m2 = c1;
+  int& r2 = m2;
+  r2 = m1;
+
+  int&& rr = 5; // No warning
+
+  int const* c2 = 
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'c2' is never modified and can be const-qualified
+  // CHECK-FIXES: int const* const c2 = 
+
+  int* const c3 = 
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'c3' never modifies its pointee and can be const-qualified
+  // CHECK-FIXES: int const* const c3 = 
+
+  int* c4 = 
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'c4' is never modified and can be const-qualified
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'c4' never modifies its pointee and can be const-qualified
+  // CHECK-FIXES: int const* const c4 = 
+
+  int* pointer_const = 
+  *pointer_const = m2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'pointer_const' is never modified and can be const-qualified
+  // CHECK-FIXES: int* const pointer_const = 
+
+  int* pointee_const = ma;
+  ++pointee_const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: 'pointee_const' never modifies its pointee and can be const-qualified
+  // CHECK-FIXES: int const* pointee_const = 
+}
Index: clang-tools-extra/test/clang-tidy/checkers/readability-alternative-tokens.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-alternative-tokens.cpp
@@ -0,0 +1,244 @@
+// RUN: %check_clang_tidy %s readability-alternative-tokens %t
+
+// A note to the reader: the whitespace in this file is important: `true&`
+// is lexically three tokens, but `trueandfalse` is lexed as a single
+// identifier. This test needs to make sure that the fixit applies whitespace in
+// its change.
+
+// clang-format off
+
+void logical_and()
+{
+  (void)(1&&0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use 'and' for logical conjunctions
+  // CHECK-FIXES: 1 and 0
+
+  (void)(1&& 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use 'and' for logical conjunctions
+  // CHECK-FIXES: 1 and 0
+
+  (void)(1 &&0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use 'and' for logical conjunctions
+  // CHECK-FIXES: 1 and 0
+
+  (void)(1 && 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use 'and' for logical conjunctions
+  // CHECK-FIXES: 1 and 0
+}
+
+void bitwise_and()
+{
+  (void)(0&1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use 'bitand' 

[PATCH] D107492: [clang] Replace asm with __asm__ in cuda header

2021-08-05 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 rG509854b69cea: [clang] Replace asm with __asm__ in cuda 
header (authored by JonChesterfield).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107492

Files:
  clang/lib/Headers/__clang_cuda_device_functions.h

Index: clang/lib/Headers/__clang_cuda_device_functions.h
===
--- clang/lib/Headers/__clang_cuda_device_functions.h
+++ clang/lib/Headers/__clang_cuda_device_functions.h
@@ -34,10 +34,12 @@
   return __nv_brevll(__a);
 }
 #if defined(__cplusplus)
-__DEVICE__ void __brkpt() { asm volatile("brkpt;"); }
+__DEVICE__ void __brkpt() { __asm__ __volatile__("brkpt;"); }
 __DEVICE__ void __brkpt(int __a) { __brkpt(); }
 #else
-__DEVICE__ void __attribute__((overloadable)) __brkpt(void) { asm volatile("brkpt;"); }
+__DEVICE__ void __attribute__((overloadable)) __brkpt(void) {
+  __asm__ __volatile__("brkpt;");
+}
 __DEVICE__ void __attribute__((overloadable)) __brkpt(int __a) { __brkpt(); }
 #endif
 __DEVICE__ unsigned int __byte_perm(unsigned int __a, unsigned int __b,
@@ -507,7 +509,7 @@
 }
 
 // Parameter must have a known integer value.
-#define __prof_trigger(__a) asm __volatile__("pmevent \t%0;" ::"i"(__a))
+#define __prof_trigger(__a) __asm__ __volatile__("pmevent \t%0;" ::"i"(__a))
 __DEVICE__ int __rhadd(int __a, int __b) { return __nv_rhadd(__a, __b); }
 __DEVICE__ unsigned int __sad(int __a, int __b, unsigned int __c) {
   return __nv_sad(__a, __b, __c);
@@ -526,7 +528,7 @@
 __DEVICE__ void __threadfence(void) { __nvvm_membar_gl(); }
 __DEVICE__ void __threadfence_block(void) { __nvvm_membar_cta(); };
 __DEVICE__ void __threadfence_system(void) { __nvvm_membar_sys(); };
-__DEVICE__ void __trap(void) { asm volatile("trap;"); }
+__DEVICE__ void __trap(void) { __asm__ __volatile__("trap;"); }
 __DEVICE__ unsigned int __uAtomicAdd(unsigned int *__p, unsigned int __v) {
   return __nvvm_atom_add_gen_i((int *)__p, __v);
 }
@@ -1051,122 +1053,136 @@
 }
 __DEVICE__ unsigned int __vabs2(unsigned int __a) {
   unsigned int r;
-  asm("vabsdiff2.s32.s32.s32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(0), "r"(0));
+  __asm__("vabsdiff2.s32.s32.s32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(0), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabs4(unsigned int __a) {
   unsigned int r;
-  asm("vabsdiff4.s32.s32.s32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(0), "r"(0));
+  __asm__("vabsdiff4.s32.s32.s32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(0), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabsdiffs2(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vabsdiff2.s32.s32.s32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vabsdiff2.s32.s32.s32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 
 __DEVICE__ unsigned int __vabsdiffs4(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vabsdiff4.s32.s32.s32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vabsdiff4.s32.s32.s32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabsdiffu2(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vabsdiff2.u32.u32.u32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vabsdiff2.u32.u32.u32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabsdiffu4(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vabsdiff4.u32.u32.u32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vabsdiff4.u32.u32.u32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabsss2(unsigned int __a) {
   unsigned int r;
-  asm("vabsdiff2.s32.s32.s32.sat %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(0), "r"(0));
+  __asm__("vabsdiff2.s32.s32.s32.sat %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(0), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabsss4(unsigned int __a) {
   unsigned int r;
-  asm("vabsdiff4.s32.s32.s32.sat %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(0), "r"(0));
+  __asm__("vabsdiff4.s32.s32.s32.sat %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(0), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vadd2(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vadd2.u32.u32.u32 %0,%1,%2,%3;" : "=r"(r) : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vadd2.u32.u32.u32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int 

[clang] 509854b - [clang] Replace asm with __asm__ in cuda header

2021-08-05 Thread Jon Chesterfield via cfe-commits

Author: Jon Chesterfield
Date: 2021-08-05T18:46:57+01:00
New Revision: 509854b69cea0c9261ac21ceb22012a53e7a800b

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

LOG: [clang] Replace asm with __asm__ in cuda header

Asm is a gnu extension for C, so at present -fopenmp -std=c99
and similar fail to compile on nvptx, bug 51344

Changing to `__asm__` or `__asm` works for openmp, all three appear to work
for cuda. Suggesting `__asm__` here as `__asm` is used by MSVC with different
syntax, so this should make for better error diagnostics if the header is
passed to a compiler other than clang.

Reviewed By: tra, emankov

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

Added: 


Modified: 
clang/lib/Headers/__clang_cuda_device_functions.h

Removed: 




diff  --git a/clang/lib/Headers/__clang_cuda_device_functions.h 
b/clang/lib/Headers/__clang_cuda_device_functions.h
index f801e5426aa43..cc4e1a4dd96ad 100644
--- a/clang/lib/Headers/__clang_cuda_device_functions.h
+++ b/clang/lib/Headers/__clang_cuda_device_functions.h
@@ -34,10 +34,12 @@ __DEVICE__ unsigned long long __brevll(unsigned long long 
__a) {
   return __nv_brevll(__a);
 }
 #if defined(__cplusplus)
-__DEVICE__ void __brkpt() { asm volatile("brkpt;"); }
+__DEVICE__ void __brkpt() { __asm__ __volatile__("brkpt;"); }
 __DEVICE__ void __brkpt(int __a) { __brkpt(); }
 #else
-__DEVICE__ void __attribute__((overloadable)) __brkpt(void) { asm 
volatile("brkpt;"); }
+__DEVICE__ void __attribute__((overloadable)) __brkpt(void) {
+  __asm__ __volatile__("brkpt;");
+}
 __DEVICE__ void __attribute__((overloadable)) __brkpt(int __a) { __brkpt(); }
 #endif
 __DEVICE__ unsigned int __byte_perm(unsigned int __a, unsigned int __b,
@@ -507,7 +509,7 @@ __DEVICE__ float __powf(float __a, float __b) {
 }
 
 // Parameter must have a known integer value.
-#define __prof_trigger(__a) asm __volatile__("pmevent \t%0;" ::"i"(__a))
+#define __prof_trigger(__a) __asm__ __volatile__("pmevent \t%0;" ::"i"(__a))
 __DEVICE__ int __rhadd(int __a, int __b) { return __nv_rhadd(__a, __b); }
 __DEVICE__ unsigned int __sad(int __a, int __b, unsigned int __c) {
   return __nv_sad(__a, __b, __c);
@@ -526,7 +528,7 @@ __DEVICE__ float __tanf(float __a) { return 
__nv_fast_tanf(__a); }
 __DEVICE__ void __threadfence(void) { __nvvm_membar_gl(); }
 __DEVICE__ void __threadfence_block(void) { __nvvm_membar_cta(); };
 __DEVICE__ void __threadfence_system(void) { __nvvm_membar_sys(); };
-__DEVICE__ void __trap(void) { asm volatile("trap;"); }
+__DEVICE__ void __trap(void) { __asm__ __volatile__("trap;"); }
 __DEVICE__ unsigned int __uAtomicAdd(unsigned int *__p, unsigned int __v) {
   return __nvvm_atom_add_gen_i((int *)__p, __v);
 }
@@ -1051,122 +1053,136 @@ __DEVICE__ unsigned int __bool2mask(unsigned int __a, 
int shift) {
 }
 __DEVICE__ unsigned int __vabs2(unsigned int __a) {
   unsigned int r;
-  asm("vabs
diff 2.s32.s32.s32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(0), "r"(0));
+  __asm__("vabs
diff 2.s32.s32.s32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(0), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabs4(unsigned int __a) {
   unsigned int r;
-  asm("vabs
diff 4.s32.s32.s32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(0), "r"(0));
+  __asm__("vabs
diff 4.s32.s32.s32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(0), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabs
diff s2(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vabs
diff 2.s32.s32.s32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vabs
diff 2.s32.s32.s32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 
 __DEVICE__ unsigned int __vabs
diff s4(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vabs
diff 4.s32.s32.s32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vabs
diff 4.s32.s32.s32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabs
diff u2(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vabs
diff 2.u32.u32.u32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vabs
diff 2.u32.u32.u32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabs
diff u4(unsigned int __a, unsigned int __b) {
   unsigned int r;
-  asm("vabs
diff 4.u32.u32.u32 %0,%1,%2,%3;"
-  : "=r"(r)
-  : "r"(__a), "r"(__b), "r"(0));
+  __asm__("vabs
diff 4.u32.u32.u32 %0,%1,%2,%3;"
+  : "=r"(r)
+  : "r"(__a), "r"(__b), "r"(0));
   return r;
 }
 __DEVICE__ unsigned int __vabsss2(unsigned int __a) {
   unsigned 

[PATCH] D107420: [sema] Disallow __builtin_mul_overflow under special condition.

2021-08-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D107420#2929115 , @craig.topper 
wrote:

> In D107420#2929039 , @aaron.ballman 
> wrote:
>
>> In D107420#2928975 , @craig.topper 
>> wrote:
>>
>>> I put up a patch for a simple fix for this in the backend. 
>>> https://reviews.llvm.org/D107581  The generated code is not optimal, but 
>>> maybe better than frontend workarounds.
>>
>> Thanks for putting up the backend fix! That's much better than frontend 
>> workarounds.
>
> Looks like I may have opened a small can of worms. In 32-bit mode, a 
> __builtin_mul_overflow of _ExtInt(128) producing a signed result generates a 
> call to _muloti4 which neither compiler-rt or libgcc implement in 32-bit 
> mode. In 64-bit mode only compiler-rt implements _muloti4 for x86-64.

We also lack a proper codegen implementation of 'div' in cases of ints larger 
than 128.  Since `_ExtInt`is now part of the C23 standard (spelled as 
`_BitInt`), we should probably be supporting these as much as we can.  I would 
think we'd have to compose the `_muloti` and `_divoti` calls somehow for those.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107420

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


[PATCH] D107420: [sema] Disallow __builtin_mul_overflow under special condition.

2021-08-05 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D107420#2929039 , @aaron.ballman 
wrote:

> In D107420#2928975 , @craig.topper 
> wrote:
>
>> I put up a patch for a simple fix for this in the backend. 
>> https://reviews.llvm.org/D107581  The generated code is not optimal, but 
>> maybe better than frontend workarounds.
>
> Thanks for putting up the backend fix! That's much better than frontend 
> workarounds.

Looks like I may have opened a small can of worms. In 32-bit mode, a 
__builtin_mul_overflow of _ExtInt(128) producing a signed result generates a 
call to _muloti4 which neither compiler-rt or libgcc implement in 32-bit mode. 
In 64-bit mode only compiler-rt implements _muloti4 for x86-64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107420

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


[PATCH] D107506: [PowerPC][AIX] Warn when using pragma align(packed) on AIX.

2021-08-05 Thread Chris Bowler via Phabricator via cfe-commits
cebowleratibm added inline comments.



Comment at: clang/lib/Sema/SemaAttr.cpp:238
+if (this->Context.getTargetInfo().getTriple().isOSAIX())
+  Diag(PragmaLoc, diag::warn_pragma_align_not_xl_compatible);
 Action = Sema::PSK_Push_Set;

Does this diagnostic need to be emitted for any struct or only structs that 
contain bitfield members?  As it is it will be very verbose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107506

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


[PATCH] D107420: [sema] Disallow __builtin_mul_overflow under special condition.

2021-08-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D107420#2928975 , @craig.topper 
wrote:

> I put up a patch for a simple fix for this in the backend. 
> https://reviews.llvm.org/D107581  The generated code is not optimal, but 
> maybe better than frontend workarounds.

Thanks for putting up the backend fix! That's much better than frontend 
workarounds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107420

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


[PATCH] D74436: Change clang option -ffp-model=precise to select ffp-contract=on

2021-08-05 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor added a comment.

FWIW, fp-contract=on has been the documented default for clang since version 5.

https://releases.llvm.org/5.0.1/tools/clang/docs/ClangCommandLineReference.html#cmdoption-clang-ffp-contract

This change just brought the behavior into conformance with the documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74436

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


[clang] b4c0307 - Fix clang-interpreter build after 2487db1f286222e2501c2fa8e8244eda13f6afc3

2021-08-05 Thread Jon Roelofs via cfe-commits

Author: Jon Roelofs
Date: 2021-08-05T10:05:36-07:00
New Revision: b4c0307d598004cfd96c770d2a4a84a37c838ba9

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

LOG: Fix clang-interpreter build after 2487db1f286222e2501c2fa8e8244eda13f6afc3

Added: 


Modified: 
clang/examples/clang-interpreter/main.cpp

Removed: 




diff  --git a/clang/examples/clang-interpreter/main.cpp 
b/clang/examples/clang-interpreter/main.cpp
index 342d42089472c..a2c50167f6b1c 100644
--- a/clang/examples/clang-interpreter/main.cpp
+++ b/clang/examples/clang-interpreter/main.cpp
@@ -66,7 +66,8 @@ class SimpleJIT {
   SimpleJIT(
   std::unique_ptr TM, DataLayout DL,
   std::unique_ptr ProcessSymbolsGenerator)
-  : TM(std::move(TM)), DL(std::move(DL)) {
+  : ES(cantFail(SelfExecutorProcessControl::Create())), TM(std::move(TM)),
+DL(std::move(DL)) {
 llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
 MainJD.addGenerator(std::move(ProcessSymbolsGenerator));
   }



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


[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-05 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In D107559#2928999 , @ro wrote:

> In D107559#2928851 , @tstellar 
> wrote:
>
>> Is there any kind of comment that is supported by all linkers?
>
> Seems there isn't.  In that case, we could either move the comments to a 
> separate file (`libclang.README`?), strip the comments when using
> Solaris `ld` (a bit ugly), or have two separate version scripts (terrible, 
> bound to diverge).

I think it would be better to move the comments to libclang.README.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D105426: [clangd] WIP: Unused header warnings

2021-08-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 364526.
kbobyrev added a comment.

Trim the patch even further: only extract locations, prune header marking logic
etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105426

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/IWYU.cpp
  clang-tools-extra/clangd/IWYU.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/IWYUTests.cpp

Index: clang-tools-extra/clangd/unittests/IWYUTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/IWYUTests.cpp
@@ -0,0 +1,98 @@
+//===--- IWYUTests.cpp --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Annotations.h"
+#include "IWYU.h"
+#include "TestTU.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::ElementsAreArray;
+
+TEST(IWYU, ReferencedLocations) {
+  struct TestCase {
+std::string HeaderCode;
+std::string MainCode;
+  };
+  TestCase Cases[] = {
+  {
+  "int ^x();",
+  "int y = x();",
+  },
+  {
+  "class ^X;",
+  "X *y;",
+  },
+  {
+  "template  class ^X;",
+  "X *y;",
+  },
+  {
+  "using ^Integer = int;",
+  "Integer x;",
+  },
+  {
+  "struct X{int ^a;}; X ^foo();",
+  "int y = foo().a;",
+  },
+  {
+  "class ^X{}; X ^foo();",
+  "auto bar() { return foo(); }",
+  },
+  {
+  "class ^X; class ^X{}; class ^X;",
+  "X *y;",
+  },
+  {
+  "struct ^X { ^X(int) {} int ^foo(); };",
+  "auto x = X(42); auto y = x.foo();",
+  },
+  {
+  "struct ^X { static bool ^foo(); }; bool X::^foo() {}",
+  "auto b = X::foo();",
+  },
+  {
+  "typedef bool ^Y; template  struct ^X {};",
+  "X x;",
+  },
+  {
+  // FIXME(kirillbobyrev): should report the UsingDecl.
+  // This information is not preserved in the AST.
+  // ^
+  "namespace ns { class ^X; }; using ns::X;",
+  "X *y;",
+  }};
+  for (const TestCase  : Cases) {
+TestTU TU;
+TU.Code = T.MainCode;
+Annotations Header(T.HeaderCode);
+TU.HeaderCode = Header.code().str();
+auto AST = TU.build();
+
+std::vector Points;
+for (const auto  : findReferencedLocations(AST).AllLocations) {
+  if (AST.getSourceManager().getBufferName(Loc).endswith(
+  TU.HeaderFilename)) {
+Points.push_back(offsetToPosition(
+TU.HeaderCode, AST.getSourceManager().getFileOffset(Loc)));
+  }
+}
+llvm::sort(Points);
+
+EXPECT_EQ(Points, Header.points()) << T.HeaderCode << "\n---\n"
+   << T.MainCode;
+  }
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -61,6 +61,7 @@
   IndexActionTests.cpp
   IndexTests.cpp
   InlayHintTests.cpp
+  IWYUTests.cpp
   JSONTransportTests.cpp
   LoggerTests.cpp
   LSPBinderTests.cpp
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "Features.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IWYU.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -601,5 +602,6 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IWYU.h
===
--- /dev/null
+++ clang-tools-extra/clangd/IWYU.h
@@ -0,0 +1,60 @@
+//===--- IWYU.h - include-what-you-use analysis -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This defines functionality modeled after Include-What-You-Use
+/// 

[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-05 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D107559#2928851 , @tstellar wrote:

> Is there any kind of comment that is supported by all linkers?

Seems there isn't.  In that case, we could either move the comments to a 
separate file (`libclang.README`?), strip the comments when using
Solaris `ld` (a bit ugly), or have two separate version scripts (terrible, 
bound to diverge).

In D107559#2928972 , @MaskRay wrote:

> ld.lld, GNU ld, and gold support `/* */`. I am not sure about Solaris ld -z 
> gnu-version-script-compat.

Not sure in which way?  Support for `/* */` comments (no) or need for the 
option?  The latter is explained in `ld(1)`:

  -z gnu-version-script=mapfile
  -z gnu-version-script-compat
  --version-script mapfile
  
  Provides partial support for the GNU version script style  of  map-
  file.  Version  scripts are based on the original Solaris version 1
  symbol definition syntax, with some  extensions.  ld  supports  the
  most  common  such extension, the use of wildcard characters in the
  specified symbol names. Other GNU-specific extensions  may  not  be
  supported.  ld  will  issue  an appropriate error if an unsupported
  extension is encountered.
  
  For convenience in building software  developed  with  GNU  version
  scripts,  the native GNU  --version-script option is accepted as an
  alias for -z gnu-version-script. Due to the partial nature  of  the
  support  for  GNU version scripts, the use of --version-script must
  be explicitly enabled by specifying -z gnu-version-script-compat.




Comment at: clang/tools/libclang/libclang.map:1
-/* If you add a symbol to this file, make sure to add it with the correct
- * version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
- * symbols with the version LLVM_14.
- * On platforms where versions scripts are not used, this file will be used to
- * generate a list of exports for libclang.so
- */
-
+# If you add a symbol to this file, make sure to add it with the correct
+# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new

MaskRay wrote:
> GNU ld doesn't support `#` comments. ld.lld supports it.
Drats, I'd have sworn they supported `#' comments, too,
especially since the version script syntax originated with
Sun and was later adopted by GNU `ld`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D80878: [clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations.

2021-08-05 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

As long as JSON dumper still compiles, it looks good to me. Just have a few 
small nits.




Comment at: clang/include/clang/AST/TextNodeDumper.h:47
+  /// Indicates if we can deserialize declarations from the ExternalASTSource.
+  bool Deserialize = true;
+

Would it be better to make the default value the same as in `ASTNodeTraverser`? 
I.e.,

```lang=c++
  /// Indicates whether we should trigger deserialization of nodes that had
  /// not already been loaded.
  bool Deserialize = false;
```



Comment at: clang/lib/AST/TextNodeDumper.cpp:2031-2034
+  if (!D->hasExternalVisibleStorage() || getDeserialize()) {
+FLAG(hasConstexprDestructor, constexpr);
+  } else
+OS << " maybe_constexpr";

The inconsistency that visually single-statement "if" branch has curly braces 
but "else" branch doesn't is grating. I understand a macro can expand into 
multiple statements but visually it looks like a single statement. Probably I 
would add braces to "else" as well.


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

https://reviews.llvm.org/D80878

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


[PATCH] D107420: [sema] Disallow __builtin_mul_overflow under special condition.

2021-08-05 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I put up a patch for a simple fix for this in the backend. 
https://reviews.llvm.org/D107581  The generated code is not optimal, but maybe 
better than frontend workarounds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107420

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


[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

ld.lld, GNU ld, and gold support `/* */`. I am not sure about Solaris ld -z 
gnu-version-script-compat.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D104285: [analyzer][AST] Retrieve value by direct index from list initialization of constant array declaration.

2021-08-05 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@aaron.ballman Thanks for the review and comments. I'll update it ASAP.




Comment at: clang/include/clang/AST/Expr.h:4959
 
+  /// Return an value-expression under the given index.
+  ///

aaron.ballman wrote:
> 
+1



Comment at: clang/include/clang/AST/Expr.h:4970
+  /// - `this` if there's no expression for the valid index;
+  /// - `nullptr` for invalid index (`i < 0` or `i >= array_size`)
+  ///   or if it is not a list for constant array type.

aaron.ballman wrote:
> `i` cannot be `< 0` because the index here is unsigned anyway.
Aha, I see.



Comment at: clang/include/clang/AST/Expr.h:4973-4975
+  /// This version adapted to treat unsigned integer to distinguish between
+  /// -1 and ULONG_LONG_MAX.
+  const Expr *getExprForConstArrayByRawIndex(int64_t Idx) const;

aaron.ballman wrote:
> I don't think this overload adds enough value -- the indexes are naturally 
> unsigned, and the caller should validate the behavior if the source 
> expression is signed.
Sounds reasonable.



Comment at: clang/lib/AST/Expr.cpp:2354-2358
+  if (!isa(T))
+return nullptr;
+
+  SmallVector Extents =
+  cast(T)->getAllExtents();

aaron.ballman wrote:
> Hmm, generally speaking, you should not cast an arbitrary type to an array 
> type because that won't do the correct thing for qualifiers. Instead, you'd 
> usually use `ASTContext::getAsConstantArrayType()` to get the correct type. 
> However, because you're just getting the array extent, I don't believe that 
> can be impacted. However, `isa` followed by `cast` is a code smell, and that 
> should at least be using a `dyn_cast`.
> 
> @rsmith, do you have thoughts on this?
I'll rewrite this part.


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

https://reviews.llvm.org/D104285

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


[PATCH] D107051: [clang][analyzer] Improve bug report in alpha.security.ReturnPtrRange

2021-08-05 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.

Aside from the inline nit, I think it's good to go.
Let some time for the others to catch up, they might have objections.




Comment at: clang/test/Analysis/return-ptr-range.cpp:17
   return arr; // no-warning
-  } while (0);
-  return ptr; // expected-warning{{Returned pointer value points outside the 
original object (potential buffer overflow)}}
+  }
+  return ptr; // expected-warning{{Returned pointer value points outside the 
original object (potential buffer overflow) [alpha.security.ReturnPtrRange]}}

I don't think we need this extra scope. Same for the others.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107051

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


[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-05 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

Is there any kind of comment that is supported by all linkers?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D107385: Fix signal during the call to checkOpenMPLoop.

2021-08-05 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6b0f35931a44: Fix signal during the call to checkOpenMPLoop. 
(authored by jyu2).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107385

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/teams_distribute_loop_messages.cpp


Index: clang/test/OpenMP/teams_distribute_loop_messages.cpp
===
--- clang/test/OpenMP/teams_distribute_loop_messages.cpp
+++ clang/test/OpenMP/teams_distribute_loop_messages.cpp
@@ -721,4 +721,15 @@
   for (int i = 0; i < 16; ++i)
 ;
 }
+//expected-note@+1 {{candidate function not viable: requires single argument 
'device_Id', but no arguments were provided}}
+int foo(int device_Id) {
+  return 2;
+}
+
+int main() {
+// expected-error@+1 {{no matching function for call to 'foo'}}
+  const int globalWI{ foo() };
+#pragma omp target teams distribute
+  for (int i=0 ; icontainsErrors())
 return true;
   LCDecl = getCanonicalDecl(NewLCDecl);
   LCRef = NewLCRefExpr;
@@ -7365,7 +7365,7 @@
   // State consistency checking to ensure correct usage.
   assert(LCDecl != nullptr && LB != nullptr && UB == nullptr &&
  Step == nullptr && !TestIsLessOp && !TestIsStrictOp);
-  if (!NewUB)
+  if (!NewUB || NewUB->containsErrors())
 return true;
   UB = NewUB;
   if (LessOp)
@@ -7380,7 +7380,7 @@
 bool OpenMPIterationSpaceChecker::setStep(Expr *NewStep, bool Subtract) {
   // State consistency checking to ensure correct usage.
   assert(LCDecl != nullptr && LB != nullptr && Step == nullptr);
-  if (!NewStep)
+  if (!NewStep || NewStep->containsErrors())
 return true;
   if (!NewStep->isValueDependent()) {
 // Check that the step is integer expression.


Index: clang/test/OpenMP/teams_distribute_loop_messages.cpp
===
--- clang/test/OpenMP/teams_distribute_loop_messages.cpp
+++ clang/test/OpenMP/teams_distribute_loop_messages.cpp
@@ -721,4 +721,15 @@
   for (int i = 0; i < 16; ++i)
 ;
 }
+//expected-note@+1 {{candidate function not viable: requires single argument 'device_Id', but no arguments were provided}}
+int foo(int device_Id) {
+  return 2;
+}
+
+int main() {
+// expected-error@+1 {{no matching function for call to 'foo'}}
+  const int globalWI{ foo() };
+#pragma omp target teams distribute
+  for (int i=0 ; icontainsErrors())
 return true;
   LCDecl = getCanonicalDecl(NewLCDecl);
   LCRef = NewLCRefExpr;
@@ -7365,7 +7365,7 @@
   // State consistency checking to ensure correct usage.
   assert(LCDecl != nullptr && LB != nullptr && UB == nullptr &&
  Step == nullptr && !TestIsLessOp && !TestIsStrictOp);
-  if (!NewUB)
+  if (!NewUB || NewUB->containsErrors())
 return true;
   UB = NewUB;
   if (LessOp)
@@ -7380,7 +7380,7 @@
 bool OpenMPIterationSpaceChecker::setStep(Expr *NewStep, bool Subtract) {
   // State consistency checking to ensure correct usage.
   assert(LCDecl != nullptr && LB != nullptr && Step == nullptr);
-  if (!NewStep)
+  if (!NewStep || NewStep->containsErrors())
 return true;
   if (!NewStep->isValueDependent()) {
 // Check that the step is integer expression.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6b0f359 - Fix signal during the call to checkOpenMPLoop.

2021-08-05 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2021-08-05T08:59:35-07:00
New Revision: 6b0f35931a44b0fbd27297f83087d3a4c352e83f

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

LOG: Fix signal during the call to checkOpenMPLoop.

The root problem is a null pointer is accessed during the call to
checkOpenMPLoop, because loop up bound expr is an error expression
due to error diagnostic was emit early.

To fix this, in setLCDeclAndLB, setUB and setStep instead return false,
return true when LB, UB or Step contains Error, so that the checking is
stopped in checkOpenMPLoop.

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/teams_distribute_loop_messages.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index f093e6263e97d..b09bda1138cc6 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -7342,7 +7342,7 @@ bool 
OpenMPIterationSpaceChecker::setLCDeclAndLB(ValueDecl *NewLCDecl,
   // State consistency checking to ensure correct usage.
   assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr &&
  UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp);
-  if (!NewLCDecl || !NewLB)
+  if (!NewLCDecl || !NewLB || NewLB->containsErrors())
 return true;
   LCDecl = getCanonicalDecl(NewLCDecl);
   LCRef = NewLCRefExpr;
@@ -7365,7 +7365,7 @@ bool OpenMPIterationSpaceChecker::setUB(Expr *NewUB,
   // State consistency checking to ensure correct usage.
   assert(LCDecl != nullptr && LB != nullptr && UB == nullptr &&
  Step == nullptr && !TestIsLessOp && !TestIsStrictOp);
-  if (!NewUB)
+  if (!NewUB || NewUB->containsErrors())
 return true;
   UB = NewUB;
   if (LessOp)
@@ -7380,7 +7380,7 @@ bool OpenMPIterationSpaceChecker::setUB(Expr *NewUB,
 bool OpenMPIterationSpaceChecker::setStep(Expr *NewStep, bool Subtract) {
   // State consistency checking to ensure correct usage.
   assert(LCDecl != nullptr && LB != nullptr && Step == nullptr);
-  if (!NewStep)
+  if (!NewStep || NewStep->containsErrors())
 return true;
   if (!NewStep->isValueDependent()) {
 // Check that the step is integer expression.

diff  --git a/clang/test/OpenMP/teams_distribute_loop_messages.cpp 
b/clang/test/OpenMP/teams_distribute_loop_messages.cpp
index 36f3830829c5e..e115d7498017e 100644
--- a/clang/test/OpenMP/teams_distribute_loop_messages.cpp
+++ b/clang/test/OpenMP/teams_distribute_loop_messages.cpp
@@ -721,4 +721,15 @@ void test_nowait() {
   for (int i = 0; i < 16; ++i)
 ;
 }
+//expected-note@+1 {{candidate function not viable: requires single argument 
'device_Id', but no arguments were provided}}
+int foo(int device_Id) {
+  return 2;
+}
+
+int main() {
+// expected-error@+1 {{no matching function for call to 'foo'}}
+  const int globalWI{ foo() };
+#pragma omp target teams distribute
+  for (int i=0 ; ihttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107450: [clang-tidy] Fix wrong and missing warnings in performance-move-const-arg

2021-08-05 Thread gehry via Phabricator via cfe-commits
Sockke added a comment.

Thank you for your reviews, @Quuxplusone, @whisperity, @MTC. I was also 
considering adding new diagnoses to the current check for these special cases, 
but I am not sure how to classify and describe them correctly, and whether they 
need to be added to the new check.
First of all, I want to make sure that the timing of warning and FxiIt in these 
cases is correct? If the above is no problem, I think I need to classify and 
modify the diagnostic information in the next step, is that right?


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

https://reviews.llvm.org/D107450

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


[PATCH] D104344: [modules] Track how headers are included by different modules.

2021-08-05 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104344

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


[PATCH] D106644: [clang][analyzer] Add standard streams to alpha.unix.Stream checker.

2021-08-05 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/ASTLookup.cpp:26
+  // and we have a TypedefDecl with the name 'FILE'.
+  for (Decl *D : LookupRes)
+if (auto *TD = dyn_cast(D))

`Decl *D` -> `const Decl *D`. Same for the other loop.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:225
+
+  Optional FILEType = GetPointer(LookupType("FILE"));
+

You calculate this 3 times now. I mean it's not a big deal, but we could save 
this to do it only once.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:227-236
+  for (Decl *D : LookupRes) {
+D = D->getCanonicalDecl();
+if (!C.getSourceManager().isInSystemHeader(D->getLocation()))
+  continue;
+if (auto *VD = dyn_cast(D)) {
+  if (FILEType && !ACtx.hasSameType(*FILEType, VD->getType()))
+continue;

It will early return and uses one fewer `continue`.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:504
+
+  OrigStdin = findStdStream("stdin", C);
+  OrigStdout = findStdStream("stdout", C);

martong wrote:
> We should be careful, to cache the results (either here, or deeper in the 
> call stack).
> I mean, we certainly don't want to do a lookup of "stdin" every time a 
> function is evaluated. We should do this lazily, only once.
I agree. We should do this only for the first top-level function, instead of 
doing this for every top-level function.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:554
 
+  auto AssumeRetValNotEq = [, , RetVal](SymbolRef StdStream) {
+SVal NotEqS = C.getSValBuilder().evalBinOp(

It might be a personal preference but I think lambdas should be pure in the 
sense that it takes something and produces something else.
Regardless of your choice, the trailing return type would highlight it.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:559-562
+Optional NotEqDef =
+NotEqS.getAs();
+if (!NotEqDef)
+  return;

I think you should be fine with `castAs()`. I'm not expecting this to fail.



Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:555
+C.getSValBuilder().makeSymbolVal(StdStream),
+C.getASTContext().getLogicalOperationType());
+Optional NotEqDef =

`SValBuilder::getConditionType()`, oh they are the same under the hood. We 
should still probably prefer this one instead.
It might worth hoisting `C.getSValBuilder()` to a local variable though.
The symbol for `StdStream` also deserves a separate variable IMO.



Comment at: clang/test/Analysis/stream.c:276-277
+return;
+  if (F != stdin && F != stdout && F != stderr)
+fclose(F); // no warning: the opened file can not be equal to std streams
+}

How about checking this way instead?
```lang=C++
clang_analyzer_eval(F != stdin);  // TRUE
clang_analyzer_eval(F != stdout); // TRUE
clang_analyzer_eval(F != stderr); // TRUE
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106644

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


[PATCH] D106030: [Clang] add support for error+warning fn attrs

2021-08-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:76
+def err_fe_backend_error_attr :
+  Error<"call to %0 declared with attribute error: %1">, BackendInfo;
+def warn_fe_backend_warning_attr :





Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:78
+def warn_fe_backend_warning_attr :
+  Warning<"call to %0 declared with attribute warning: %1">, BackendInfo,
+  InGroup;





Comment at: clang/include/clang/Basic/DiagnosticGroups.td:1205
 def BackendOptimizationFailure : DiagGroup<"pass-failed">;
+def BackendUserDiagnostic : DiagGroup<"user-diagnostic">;
 

nickdesaulniers wrote:
> aaron.ballman wrote:
> > nickdesaulniers wrote:
> > > aaron.ballman wrote:
> > > > nickdesaulniers wrote:
> > > > > aaron.ballman wrote:
> > > > > > nickdesaulniers wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > GCC doesn't seem to support this spelling -- do they have a 
> > > > > > > > different one we should reuse?
> > > > > > > I think these diagnostics don't have corresponding flags in GCC, 
> > > > > > > so they cannot be disabled.
> > > > > > > 
> > > > > > > Without adding this, clang/test/Misc/warning-flags.c would fail, 
> > > > > > > because I was adding a new unnamed warning 
> > > > > > > `warn_fe_backend_user_diagnostic`.  Perhaps I should not be 
> > > > > > > adding this line here, and doing something else?
> > > > > > > 
> > > > > > > That test says we shouldn't be adding new warnings not controlled 
> > > > > > > by flags, but that's very much my intention.
> > > > > > > 
> > > > > > > Though now `-Wno-user-diagnostic` doesn't produce a 
> > > > > > > `-Wunknown-warning-option` diagnostic...
> > > > > > Ah! I think the warning attribute should be controllable via a 
> > > > > > diagnostic flag (we should always be able to disable warnings with 
> > > > > > some sort of flag) and I don't think the error attribute should be 
> > > > > > controllable (an error is an error and should stop translation, 
> > > > > > same as with `#error`).
> > > > > > 
> > > > > > Normally, I'd say "let's use the same flag that controls 
> > > > > > `#warning`" but...
> > > > > > ```
> > > > > > def PoundWarning : DiagGroup<"#warnings">;
> > > > > > ```
> > > > > > That's... not exactly an obvious flag for the warning attribute. So 
> > > > > > I would probably name it `warning-attributes` similar to how we 
> > > > > > have `deprecated-attributes` already.
> > > > > Done, now `-Wno-warning-attributes` doesn't produce 
> > > > > `-Wunknown-warning-option`, but also doesn't disable the diagnostic.  
> > > > > Was there something else I needed to add?
> > > > huh, that sounds suspicious -- you don't need to do anything special 
> > > > for `-Wno-foo` handling, that should be automatically supported via 
> > > > tablegen. I'm not certain why you're not seeing 
> > > > `-Wno-warning-attributes` silencing the warnings.
> > > Ah! Because I was testing `__attribute__((error("")))` not 
> > > `__attribute__((warning("")))`. `-Wno-warning-attributes` only affects 
> > > the latter, not the former.  I should add a test for 
> > > `-Wno-warning-attributes`! Is this something I also need to add 
> > > documentation for?
> > Given that this behavior surprised you, I certainly wouldn't oppose 
> > mentioning it in the documentation, but I also don't think it's strictly 
> > required. That said, I do agree about adding some additional test coverage 
> > for when the warning is disabled.
> > 
> > Just to double-check: do you think this functionality needs an "escape 
> > hatch" for the error case? e.g., should the `error` attribute generate a 
> > warning diagnostic that defaults to being an error, so we have 
> > `-Wno-warning-attributes` to turn off `warning` attribute diagnostics and 
> > `-Wno-error-attributes` to turn off `error` attribute diagnostics?
> Ah, GCC also controls this via `-Wattribute-warning`; let me rename my 
> implementation.
> 
> > do you think this functionality needs an "escape hatch" for the error case?
> 
> No.  If users don't want an error, then they should prefer 
> `__attribute__((warning("")))` to `__attribute__((error("")))`.
Okay, that's fine by me. If we find a need to give API consumers the ability to 
ignore the `error` attribute, we can always add one later.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11172
 
+def err_attribute_removed_on_redeclaration : Error<
+  "'%0' attribute removed from redeclared variable">;

This diagnostic is a bit confusing to me -- should this be a warning about the 
attribute being ignored in this case, rather than an error? Alternatively, 
should this be re-worded to say that the attribute must appear on the first 
declaration? If the latter, we have some diagnostics that could maybe be 
combined into using a `%select` for this: 

[PATCH] D107559: [clang] Fix libclang linking on Solaris

2021-08-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/tools/libclang/libclang.map:1
-/* If you add a symbol to this file, make sure to add it with the correct
- * version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
- * symbols with the version LLVM_14.
- * On platforms where versions scripts are not used, this file will be used to
- * generate a list of exports for libclang.so
- */
-
+# If you add a symbol to this file, make sure to add it with the correct
+# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new

GNU ld doesn't support `#` comments. ld.lld supports it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107559

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


[PATCH] D107051: [clang][analyzer] Improve bug report in alpha.security.ReturnPtrRange

2021-08-05 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 364495.
balazske added a comment.

Fixes in tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107051

Files:
  clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
  clang/test/Analysis/misc-ps-region-store.m
  clang/test/Analysis/return-ptr-range.cpp

Index: clang/test/Analysis/return-ptr-range.cpp
===
--- clang/test/Analysis/return-ptr-range.cpp
+++ clang/test/Analysis/return-ptr-range.cpp
@@ -1,29 +1,39 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.security.ReturnPtrRange -verify %s
-
-int arr[10];
-int *ptr;
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.ReturnPtrRange -analyzer-output text -verify %s
 
 int conjure_index();
 
-int *test_element_index_lifetime() {
-  do {
+namespace test_element_index_lifetime {
+
+int arr[10]; // expected-note{{Original object declared here}} expected-note{{Original object declared here}}
+int *ptr;
+
+int *test_global_ptr() {
+  {
 int x = conjure_index();
-ptr = arr + x;
-if (x != 20)
+ptr = arr + x; // expected-note{{Value assigned to 'ptr'}}
+if (x != 20) // expected-note{{Assuming 'x' is equal to 20}}
+ // expected-note@-1{{Taking false branch}}
   return arr; // no-warning
-  } while (0);
-  return ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+  }
+  return ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow) [alpha.security.ReturnPtrRange]}}
+  // expected-note@-1{{Returned pointer value points outside the original object (potential buffer overflow)}}
+  // expected-note@-2{{Original object 'arr' is an array of 10 'int' objects}}
 }
 
-int *test_element_index_lifetime_with_local_ptr() {
+int *test_local_ptr() {
   int *local_ptr;
-  do {
+  {
 int x = conjure_index();
-local_ptr = arr + x;
-if (x != 20)
+local_ptr = arr + x; // expected-note{{Value assigned to 'local_ptr'}}
+if (x != 20) // expected-note{{Assuming 'x' is equal to 20}}
+ // expected-note@-1{{Taking false branch}}
   return arr; // no-warning
-  } while (0);
-  return local_ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+  }
+  return local_ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow) [alpha.security.ReturnPtrRange]}}
+// expected-note@-1{{Returned pointer value points outside the original object (potential buffer overflow)}}
+// expected-note@-2{{Original object 'arr' is an array of 10 'int' objects}}
+}
+
 }
 
 template 
@@ -55,17 +65,53 @@
 
 template 
 class BadIterable {
-  int buffer[N];
+  int buffer[N]; // expected-note{{Original object declared here}}
   int *start, *finish;
 
 public:
-  BadIterable() : start(buffer), finish(buffer + N) {}
+  BadIterable() : start(buffer), finish(buffer + N) {} // expected-note{{Value assigned to 'iter.finish'}}
 
   int* begin() { return start; }
-  int* end() { return finish + 1; } // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+  int* end() { return finish + 1; } // expected-warning{{Returned pointer value points outside the original object}}
+// expected-note@-1{{Returned pointer value points outside the original object}}
+// expected-note@-2{{Original object 'buffer' is an array of 20 'int' objects, returned pointer points at index 21}}
 };
 
 void use_bad_iterable_object() {
-  BadIterable<20> iter;
-  iter.end();
+  BadIterable<20> iter; // expected-note{{Calling default constructor for 'BadIterable<20>'}}
+// expected-note@-1{{Returning from default constructor for 'BadIterable<20>'}}
+  iter.end(); // expected-note{{Calling 'BadIterable::end'}}
 }
+
+int *test_idx_sym(int I) {
+  static int arr[10]; // expected-note{{Original object declared here}} expected-note{{'arr' initialized here}}
+
+  if (I != 11) // expected-note{{Assuming 'I' is equal to 11}}
+   // expected-note@-1{{Taking false branch}}
+return arr;
+  return arr + I; // expected-warning{{Returned pointer value points outside the original object}}
+  // expected-note@-1{{Returned pointer value points outside the original object}}
+  // expected-note@-2{{Original object 'arr' is an array of 10 'int' objects, returned pointer points at index 11}}
+}
+
+namespace test_array_of_struct {
+
+struct Data {
+  int A;
+  char *B;
+};
+
+Data DataArr[10]; // expected-note{{Original object declared here}}
+
+Data *test_struct_array() {
+  int I = conjure_index();

[PATCH] D107294: [clang-tidy] adds warning to suggest users replace symbols with words

2021-08-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp:133-134
 "readability-uppercase-literal-suffix");
+CheckFactories.registerCheck(
+"readability-use-alternative-tokens");
 CheckFactories.registerCheck(

whisperity wrote:
> cjdb wrote:
> > aaron.ballman wrote:
> > > I think this might be a case where we want the check to either recommend 
> > > using alternative tokens or recommend against using alternative tokens 
> > > via a configuration option (so users can control readability in either 
> > > direction). If you agree that's a reasonable design, then I'd recommend 
> > > we name this `readability-alternative-tokens` to be a bit more generic. 
> > > (Note, we can always do the "don't use alternative tokens" implementation 
> > > in a follow-up patch if you don't want to do that work immediately.)
> > Hrmm I'll do the rename now, but this might be better off as a later 
> > patch. I'd rather focus on getting what I have right (along with my teased 
> > extensions) and then work on the opposite direction. That will (probably) 
> > be an easy slip-in.
> (As someone who's had checkers on review for multiple years I've no hard 
> feelings about the scheduling.)
> 
> But please do add a few `FIXME:` or `TODO:` or `IDEA:` or some similar 
> comments to the code somewhere about the suggested follow-ups. (Just so they 
> don't go away when this review is closed.)
Yeah, I wasn't trying to sign you up for the implementation effort, just making 
sure the name is somewhat more future-proofed. Adding a FIXME comment to the 
code to explain the potential next steps would be a good thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107294

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


[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-08-05 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 364490.
RedDocMD added a comment.

Never gonna give you up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E =
+  // DstPreCall.end();
+  //  I != E; ++I)
+  //   defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call,
+ *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto  : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
-  Pred->getLocationContext(), EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -139,7 +139,7 @@
 
   if (RD->getDeclName().isIdentifier()) {
 StringRef Name = RD->getName();
-return Name == "shared_ptr" || Name == "unique_ptr" || Name == "weak_ptr";
+return llvm::is_contained(STD_PTR_NAMES, Name);
   }
   return false;
 }
@@ -275,6 +275,29 @@
  smartptr::isStdSmartPtr(Call.getArgExpr(1));
 }
 
+ProgramStateRef
+invalidateInnerPointer(const MemRegion *ThisRegion, ProgramStateRef State,
+   const CallEvent , CheckerContext ) {
+  const auto *InnerPtrVal = State->get(ThisRegion);
+  if (InnerPtrVal) {
+State = State->invalidateRegions(*InnerPtrVal, nullptr, C.blockCount(),
+ C.getLocationContext(), true);
+
+const QualType  = getInnerPointerType(Call, C);
+const auto *RD = Type->getAsCXXRecordDecl();
+if (!RD)
+  return State;
+const auto *DD = RD->getDestructor();
+
+const auto InnerDestrCall =
+C.getStateManager().getCallEventManager().getCXXDestructorCall(
+DD, nullptr, InnerPtrVal->getAsRegion(), RD->bases().empty(), State,
+C.getLocationContext());
+InnerDestrCall->invalidateRegions(C.blockCount(), State);
+  }
+  return State;
+}
+
 bool SmartPtrModeling::evalCall(const CallEvent ,
 CheckerContext ) const {
 
@@ -372,6 +395,21 @@
 }
   }
 
+  if (const auto *DC = dyn_cast()) {
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+if (!ThisRegion)
+  return false;
+State = State->remove(ThisRegion);
+State = invalidateInnerPointer(ThisRegion, State, Call, C);
+// This tag is required to prevent later crashes due to the non-addition
+// of new States. Having a tag ensures that the call to addTransition
+// actually adds a new state.
+static SimpleProgramPointTag SPPT("SmartPtrModeling",
+  "on destructor modeling");
+C.addTransition(State, );
+return true;
+  }
+
   if (!ModelSmartPtrDereference)
 return false;
 
@@ -402,10 +440,14 @@
   }));
 } else {
   const auto *TrackingExpr = Call.getArgExpr(0);
-  assert(TrackingExpr->getType()->isPointerType() &&
- "Adding a non pointer value to TrackedRegionMap");
+  if 

[PATCH] D107522: [PowerPC][AIX] attribute aligned cannot decrease align of a vector var.

2021-08-05 Thread Sean Fertile via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sfertile marked an inline comment as done.
Closed by commit rGf888e442bcc5: [PowerPC][AIX] attribute aligned cannot 
decrease align of a vector var. (authored by sfertile).

Changed prior to commit:
  https://reviews.llvm.org/D107522?vs=364436=364489#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107522

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/aix-vector-attr-aligned.c
  clang/test/Sema/aix-attr-aligned-vector-warn.c

Index: clang/test/Sema/aix-attr-aligned-vector-warn.c
===
--- /dev/null
+++ clang/test/Sema/aix-attr-aligned-vector-warn.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-feature +altivec -target-cpu pwr7 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-feature +altivec -target-cpu pwr7 -verify -fsyntax-only %s
+
+int escape(vector int*);
+
+typedef vector int __attribute__((aligned(8))) UnderAlignedVI;
+UnderAlignedVI TypedefedGlobal;
+
+vector int V __attribute__((aligned(8))); // expected-warning {{requested alignment is less than minimum alignment of 16 for type '__vector int' (vector of 4 'int' values)}}
+
+int localTypedefed(void) {
+  UnderAlignedVI TypedefedLocal;
+  return escape(); // expected-warning {{passing 8-byte aligned argument to 16-byte aligned parameter 1 of 'escape' may result in an unaligned pointer access}}
+}
Index: clang/test/CodeGen/aix-vector-attr-aligned.c
===
--- /dev/null
+++ clang/test/CodeGen/aix-vector-attr-aligned.c
@@ -0,0 +1,33 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-feature +altivec -target-cpu pwr7 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-feature +altivec -target-cpu pwr7 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s
+
+typedef vector int __attribute__((aligned(8))) UnderAlignedVI;
+
+vector int g32 __attribute__((aligned(32)));
+vector int g8 __attribute__((aligned(8)));
+UnderAlignedVI TypedefedGlobal;
+
+int escape(vector int*);
+
+int local32(void) {
+  vector int l32 __attribute__((aligned(32)));
+  return escape();
+}
+
+int local8(void) {
+  vector int l8 __attribute__((aligned(8)));
+  return escape();
+}
+
+// CHECK: @g32 = global <4 x i32> zeroinitializer, align 32
+// CHECK: @g8 = global <4 x i32> zeroinitializer, align 16
+// CHECK: @TypedefedGlobal = global <4 x i32> zeroinitializer, align 8
+
+// CHECK-LABEL: @local32
+// CHECK: %l32 = alloca <4 x i32>, align 32
+//
+// CHECK-LABEL: @local8
+// CHECK: %l8 = alloca <4 x i32>, align 16
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -4063,12 +4063,12 @@
 return;
   }
 
-  if (Context.getTargetInfo().isTLSSupported()) {
+  const auto *VD = dyn_cast(D);
+  if (VD && Context.getTargetInfo().isTLSSupported()) {
 unsigned MaxTLSAlign =
 Context.toCharUnitsFromBits(Context.getTargetInfo().getMaxTLSAlign())
 .getQuantity();
-const auto *VD = dyn_cast(D);
-if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD &&
+if (MaxTLSAlign && AlignVal > MaxTLSAlign &&
 VD->getTLSKind() != VarDecl::TLS_None) {
   Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
   << (unsigned)AlignVal << VD << MaxTLSAlign;
@@ -4076,6 +4076,17 @@
 }
   }
 
+  // On AIX, an aligned attribute can not decrease the alignment when applied
+  // to a variable declaration with vector type.
+  if (VD && Context.getTargetInfo().getTriple().isOSAIX()) {
+const Type *Ty = VD->getType().getTypePtr();
+if (Ty->isVectorType() && AlignVal < 16) {
+  Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned)
+  << VD->getType() << 16;
+  return;
+}
+  }
+
   AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI, true, ICE.get());
   AA->setPackExpansion(IsPackExpansion);
   D->addAttr(AA);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2986,6 +2986,8 @@
   "redeclaration has different alignment requirement (%1 vs %0)">;
 def err_alignas_underaligned : Error<
   "requested alignment is less than minimum alignment of %1 for type %0">;
+def warn_aligned_attr_underaligned : Warning,
+  InGroup;
 def err_attribute_sizeless_type : Error<
   "%0 attribute cannot be applied to sizeless type %1">;
 def err_attribute_argument_n_type : Error<

[clang] f888e44 - [PowerPC][AIX] attribute aligned cannot decrease align of a vector var.

2021-08-05 Thread Sean Fertile via cfe-commits

Author: Sean Fertile
Date: 2021-08-05T11:15:12-04:00
New Revision: f888e442bcc547301b58e77667eb261c0391b897

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

LOG: [PowerPC][AIX] attribute aligned cannot decrease align of a vector var.

On AIX an aligned attribute cannot decrease the alignment of a variable
when placed on a variable declaration of vector type.

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

Added: 
clang/test/CodeGen/aix-vector-attr-aligned.c
clang/test/Sema/aix-attr-aligned-vector-warn.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 71e7ffdbe8a08..247f9d715b846 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2986,6 +2986,8 @@ def err_alignas_mismatch : Error<
   "redeclaration has 
diff erent alignment requirement (%1 vs %0)">;
 def err_alignas_underaligned : Error<
   "requested alignment is less than minimum alignment of %1 for type %0">;
+def warn_aligned_attr_underaligned : Warning,
+  InGroup;
 def err_attribute_sizeless_type : Error<
   "%0 attribute cannot be applied to sizeless type %1">;
 def err_attribute_argument_n_type : Error<

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index e5d03d55a5d6f..5098c3900aeb2 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4063,12 +4063,12 @@ void Sema::AddAlignedAttr(Decl *D, const 
AttributeCommonInfo , Expr *E,
 return;
   }
 
-  if (Context.getTargetInfo().isTLSSupported()) {
+  const auto *VD = dyn_cast(D);
+  if (VD && Context.getTargetInfo().isTLSSupported()) {
 unsigned MaxTLSAlign =
 Context.toCharUnitsFromBits(Context.getTargetInfo().getMaxTLSAlign())
 .getQuantity();
-const auto *VD = dyn_cast(D);
-if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD &&
+if (MaxTLSAlign && AlignVal > MaxTLSAlign &&
 VD->getTLSKind() != VarDecl::TLS_None) {
   Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
   << (unsigned)AlignVal << VD << MaxTLSAlign;
@@ -4076,6 +4076,17 @@ void Sema::AddAlignedAttr(Decl *D, const 
AttributeCommonInfo , Expr *E,
 }
   }
 
+  // On AIX, an aligned attribute can not decrease the alignment when applied
+  // to a variable declaration with vector type.
+  if (VD && Context.getTargetInfo().getTriple().isOSAIX()) {
+const Type *Ty = VD->getType().getTypePtr();
+if (Ty->isVectorType() && AlignVal < 16) {
+  Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned)
+  << VD->getType() << 16;
+  return;
+}
+  }
+
   AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI, true, ICE.get());
   AA->setPackExpansion(IsPackExpansion);
   D->addAttr(AA);

diff  --git a/clang/test/CodeGen/aix-vector-attr-aligned.c 
b/clang/test/CodeGen/aix-vector-attr-aligned.c
new file mode 100644
index 0..462fb7a3b019c
--- /dev/null
+++ b/clang/test/CodeGen/aix-vector-attr-aligned.c
@@ -0,0 +1,33 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-feature +altivec 
-target-cpu pwr7 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-feature +altivec 
-target-cpu pwr7 -emit-llvm -o - %s | \
+// RUN:   FileCheck %s
+
+typedef vector int __attribute__((aligned(8))) UnderAlignedVI;
+
+vector int g32 __attribute__((aligned(32)));
+vector int g8 __attribute__((aligned(8)));
+UnderAlignedVI TypedefedGlobal;
+
+int escape(vector int*);
+
+int local32(void) {
+  vector int l32 __attribute__((aligned(32)));
+  return escape();
+}
+
+int local8(void) {
+  vector int l8 __attribute__((aligned(8)));
+  return escape();
+}
+
+// CHECK: @g32 = global <4 x i32> zeroinitializer, align 32
+// CHECK: @g8 = global <4 x i32> zeroinitializer, align 16
+// CHECK: @TypedefedGlobal = global <4 x i32> zeroinitializer, align 8
+
+// CHECK-LABEL: @local32
+// CHECK: %l32 = alloca <4 x i32>, align 32
+//
+// CHECK-LABEL: @local8
+// CHECK: %l8 = alloca <4 x i32>, align 16

diff  --git a/clang/test/Sema/aix-attr-aligned-vector-warn.c 
b/clang/test/Sema/aix-attr-aligned-vector-warn.c
new file mode 100644
index 0..af2e1a89268a2
--- /dev/null
+++ b/clang/test/Sema/aix-attr-aligned-vector-warn.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -target-feature +altivec 
-target-cpu pwr7 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -target-feature +altivec 
-target-cpu pwr7 -verify -fsyntax-only %s
+
+int escape(vector 

[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

2021-08-05 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 364486.
RedDocMD added a comment.

Bug fix in modelling


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Index: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -753,10 +753,13 @@
 *Call, *this);
 
   ExplodedNodeSet DstInvalidated;
-  StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
-  for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E = DstPreCall.end();
-   I != E; ++I)
-defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  // StmtNodeBuilder Bldr(DstPreCall, DstInvalidated, *currBldrCtx);
+  // for (ExplodedNodeSet::iterator I = DstPreCall.begin(), E =
+  // DstPreCall.end();
+  //  I != E; ++I)
+  //   defaultEvalCall(Bldr, *I, *Call, CallOpts);
+  getCheckerManager().runCheckersForEvalCall(DstInvalidated, DstPreCall, *Call,
+ *this, CallOpts);
 
   getCheckerManager().runCheckersForPostCall(Dst, DstInvalidated,
  *Call, *this);
Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -664,14 +664,11 @@
 for (const auto  : EvalCallCheckers) {
   // TODO: Support the situation when the call doesn't correspond
   // to any Expr.
-  ProgramPoint L = ProgramPoint::getProgramPoint(
-  Call.getOriginExpr(), ProgramPoint::PostStmtKind,
-  Pred->getLocationContext(), EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
-CheckerContext C(B, Eng, Pred, L);
+CheckerContext C(B, Eng, Pred, Call.getProgramPoint());
 evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -139,7 +139,7 @@
 
   if (RD->getDeclName().isIdentifier()) {
 StringRef Name = RD->getName();
-return Name == "shared_ptr" || Name == "unique_ptr" || Name == "weak_ptr";
+return llvm::is_contained(STD_PTR_NAMES, Name);
   }
   return false;
 }
@@ -275,6 +275,29 @@
  smartptr::isStdSmartPtr(Call.getArgExpr(1));
 }
 
+std::pair
+invalidateInnerPointer(const MemRegion *ThisRegion, ProgramStateRef State,
+   const CallEvent , CheckerContext ) {
+  const auto *InnerPtrVal = State->get(ThisRegion);
+  if (InnerPtrVal) {
+State = State->invalidateRegions(*InnerPtrVal, nullptr, C.blockCount(),
+ C.getLocationContext(), true);
+
+const QualType  = getInnerPointerType(Call, C);
+const auto *RD = Type->getAsCXXRecordDecl();
+if (!RD)
+  return {State, false};
+const auto *DD = RD->getDestructor();
+
+const auto InnerDestrCall =
+C.getStateManager().getCallEventManager().getCXXDestructorCall(
+DD, nullptr, InnerPtrVal->getAsRegion(), RD->bases().empty(), State,
+C.getLocationContext());
+InnerDestrCall->invalidateRegions(C.blockCount(), State);
+  }
+  return {State, true};
+}
+
 bool SmartPtrModeling::evalCall(const CallEvent ,
 CheckerContext ) const {
 
@@ -372,6 +395,23 @@
 }
   }
 
+  if (const auto *DC = dyn_cast()) {
+const MemRegion *ThisRegion = DC->getCXXThisVal().getAsRegion();
+if (!ThisRegion)
+  return false;
+State = State->remove(ThisRegion);
+bool ShouldGiveUp;
+std::tie(State, ShouldGiveUp) =
+invalidateInnerPointer(ThisRegion, State, Call, C);
+// This tag is required to prevent later crashes due to the non-addition
+// of new States. Having a tag ensures that the call to addTransition
+// actually adds a new state.
+static SimpleProgramPointTag SPPT("SmartPtrModeling",
+  "on destructor modeling");
+C.addTransition(State, );
+return !ShouldGiveUp;
+  }
+
   if (!ModelSmartPtrDereference)
 return false;
 
@@ -402,10 +442,14 @@
   }));
 } else {
   const auto *TrackingExpr = Call.getArgExpr(0);
-  assert(TrackingExpr->getType()->isPointerType() &&
-  

[PATCH] D107051: [clang][analyzer] Improve bug report in alpha.security.ReturnPtrRange

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

In D107051#2928536 , @balazske wrote:

> If the original memory object is not known the static size is not known too. 
> Every pointer with unknown source can point into a bigger data structure.

You are right, but IMO pointers to arrays are so rare that we could probably 
trust them. At least, that was my idea.




Comment at: clang/test/Analysis/return-ptr-range.cpp:11
+int *test_global_ptr() {
+  do { // expected-note{{Loop condition is false.  Exiting loop}}
 int x = conjure_index();

balazske wrote:
> steakhal wrote:
> > I would rather use a simple block `{...}` for opening a scope, but I don't 
> > know why you don't declare `ptr` in the original scope in the first place.
> > People usually use `do {} while(0)` constructs if they want to use `break` 
> > somewhere ~~ like a `goto` OR they implement a macro. You are doing none of 
> > these.
> I do not know why these loops are here but did not change the original code. 
> Should we change it to simple block?
Yes, please. The note for the loop is only noise in its current form.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107051

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


[PATCH] D107558: [clang] [clang-repl] Fix linking against LLVMLineEditor

2021-08-05 Thread Michał Górny 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 rGd99e9461b079: [clang] [clang-repl] Fix linking against 
LLVMLineEditor (authored by mgorny).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107558

Files:
  clang/tools/clang-repl/CMakeLists.txt


Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -1,6 +1,7 @@
 set( LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
   Core
+  LineEditor
   Option
   OrcJIT
   Support
@@ -14,5 +15,4 @@
   clangBasic
   clangInterpreter
   clangTooling
-  LLVMLineEditor
   )


Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -1,6 +1,7 @@
 set( LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
   Core
+  LineEditor
   Option
   OrcJIT
   Support
@@ -14,5 +15,4 @@
   clangBasic
   clangInterpreter
   clangTooling
-  LLVMLineEditor
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d99e946 - [clang] [clang-repl] Fix linking against LLVMLineEditor

2021-08-05 Thread Michał Górny via cfe-commits

Author: Michał Górny
Date: 2021-08-05T16:51:47+02:00
New Revision: d99e9461b07988914cba573800cd1862f277e155

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

LOG: [clang] [clang-repl] Fix linking against LLVMLineEditor

LLVMLineEditor library is part of the LLVM dylib.  Move it into
LLVM_LINK_COMPONENTS to avoid duplicate linking when dylib is being
used.  This fixes building standalone clang against installed LLVM
without static libraries.

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

Added: 


Modified: 
clang/tools/clang-repl/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/clang-repl/CMakeLists.txt 
b/clang/tools/clang-repl/CMakeLists.txt
index ae0e4f39be70f..c2576d7c564d9 100644
--- a/clang/tools/clang-repl/CMakeLists.txt
+++ b/clang/tools/clang-repl/CMakeLists.txt
@@ -1,6 +1,7 @@
 set( LLVM_LINK_COMPONENTS
   ${LLVM_TARGETS_TO_BUILD}
   Core
+  LineEditor
   Option
   OrcJIT
   Support
@@ -14,5 +15,4 @@ clang_target_link_libraries(clang-repl PUBLIC
   clangBasic
   clangInterpreter
   clangTooling
-  LLVMLineEditor
   )



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


[PATCH] D106550: [PowerPC] Allow MMA builtins to accept restrict qualified pointers

2021-08-05 Thread Ahsan Saghir via Phabricator via cfe-commits
saghir updated this revision to Diff 364467.
saghir added a comment.

Addressed review comments. Added another test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106550

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/ppc-pair-mma-types.c


Index: clang/test/Sema/ppc-pair-mma-types.c
===
--- clang/test/Sema/ppc-pair-mma-types.c
+++ clang/test/Sema/ppc-pair-mma-types.c
@@ -333,3 +333,13 @@
   __vector_pair vp = __builtin_vsx_lxvp(ll, v); // expected-error {{passing 
'__vector int' (vector of 4 'int' values) to parameter of incompatible type 
'const __vector_pair *'}}
   __builtin_vsx_stxvp(vp, ll, s);   // expected-error {{passing 
'unsigned short' to parameter of incompatible type 'const __vector_pair *'}}
 }
+
+void testRestrictQualifiedPointer1(int *__restrict acc) {
+  vector float arr[4];
+  __builtin_mma_disassemble_acc((void*)arr, acc); // expected-error {{passing 
'int *restrict' to parameter of incompatible type '__vector_quad *'}}
+}
+
+void testRestrictQualifiedPointer2(__vector_quad *__restrict acc) {
+  vector float arr[4];
+  __builtin_mma_disassemble_acc((void*)arr, acc);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7324,9 +7324,22 @@
 Expr *Arg = TheCall->getArg(ArgNum);
 QualType ArgType = Arg->getType();
 
-if ((ExpectedType->isVoidPointerType() && !ArgType->isPointerType()) ||
-(!ExpectedType->isVoidPointerType() &&
-   ArgType.getCanonicalType() != ExpectedType))
+// Checks if the argument type is valid. Returns true if it is valid
+// and false if it is not valid.
+auto IsValidType = [ArgType, ExpectedType]() {
+  if (ExpectedType->isVoidPointerType() && !ArgType->isPointerType())
+return false;
+  if (!ExpectedType->isVoidPointerType()) {
+if (ArgType.isRestrictQualified() &&
+ArgType.getCanonicalType().getUnqualifiedType() == ExpectedType)
+  return true;
+if (ArgType.getCanonicalType() != ExpectedType)
+  return false;
+  }
+  return true;
+};
+
+if (!IsValidType())
   return Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
  << ArgType << ExpectedType << 1 << 0 << 0;
 


Index: clang/test/Sema/ppc-pair-mma-types.c
===
--- clang/test/Sema/ppc-pair-mma-types.c
+++ clang/test/Sema/ppc-pair-mma-types.c
@@ -333,3 +333,13 @@
   __vector_pair vp = __builtin_vsx_lxvp(ll, v); // expected-error {{passing '__vector int' (vector of 4 'int' values) to parameter of incompatible type 'const __vector_pair *'}}
   __builtin_vsx_stxvp(vp, ll, s);   // expected-error {{passing 'unsigned short' to parameter of incompatible type 'const __vector_pair *'}}
 }
+
+void testRestrictQualifiedPointer1(int *__restrict acc) {
+  vector float arr[4];
+  __builtin_mma_disassemble_acc((void*)arr, acc); // expected-error {{passing 'int *restrict' to parameter of incompatible type '__vector_quad *'}}
+}
+
+void testRestrictQualifiedPointer2(__vector_quad *__restrict acc) {
+  vector float arr[4];
+  __builtin_mma_disassemble_acc((void*)arr, acc);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7324,9 +7324,22 @@
 Expr *Arg = TheCall->getArg(ArgNum);
 QualType ArgType = Arg->getType();
 
-if ((ExpectedType->isVoidPointerType() && !ArgType->isPointerType()) ||
-(!ExpectedType->isVoidPointerType() &&
-   ArgType.getCanonicalType() != ExpectedType))
+// Checks if the argument type is valid. Returns true if it is valid
+// and false if it is not valid.
+auto IsValidType = [ArgType, ExpectedType]() {
+  if (ExpectedType->isVoidPointerType() && !ArgType->isPointerType())
+return false;
+  if (!ExpectedType->isVoidPointerType()) {
+if (ArgType.isRestrictQualified() &&
+ArgType.getCanonicalType().getUnqualifiedType() == ExpectedType)
+  return true;
+if (ArgType.getCanonicalType() != ExpectedType)
+  return false;
+  }
+  return true;
+};
+
+if (!IsValidType())
   return Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
  << ArgType << ExpectedType << 1 << 0 << 0;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107461: [PowerPC] Do not define __PRIVILEGED__

2021-08-05 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added a comment.

> x64 debian > Clang.Driver::ppc-mprivileged-support-check.c

The changed test is failing ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107461

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


[PATCH] D107558: [clang] [clang-repl] Fix linking against LLVMLineEditor

2021-08-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

Thanks!


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

https://reviews.llvm.org/D107558

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


[PATCH] D107051: [clang][analyzer] Improve bug report in alpha.security.ReturnPtrRange

2021-08-05 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

If the original memory object is not known the static size is not known too. 
Every pointer with unknown source can point into a bigger data structure.




Comment at: clang/test/Analysis/return-ptr-range.cpp:11
+int *test_global_ptr() {
+  do { // expected-note{{Loop condition is false.  Exiting loop}}
 int x = conjure_index();

steakhal wrote:
> I would rather use a simple block `{...}` for opening a scope, but I don't 
> know why you don't declare `ptr` in the original scope in the first place.
> People usually use `do {} while(0)` constructs if they want to use `break` 
> somewhere ~~ like a `goto` OR they implement a macro. You are doing none of 
> these.
I do not know why these loops are here but did not change the original code. 
Should we change it to simple block?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107051

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


[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39dac1f7f656: [clang] Add clang builtins support for gfx90a 
(authored by gandhi21299).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx7-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx1030.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx8.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl

Index: clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
@@ -0,0 +1,115 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   %s -S -emit-llvm -o - | FileCheck %s -check-prefix=CHECK
+
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   -S -o - %s | FileCheck -check-prefix=GFX90A %s
+
+typedef half __attribute__((ext_vector_type(2))) half2;
+
+// CHECK-LABEL: test_global_add_f64
+// CHECK: call double @llvm.amdgcn.global.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_global_add_f64$local:
+// GFX90A:  global_atomic_add_f64
+void test_global_add_f64(__global double *addr, double x) {
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fadd_f64(addr, x);
+}
+
+// CHECK-LABEL: test_global_add_half2
+// CHECK: call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p1v2f16.v2f16(<2 x half> addrspace(1)* %{{.*}}, <2 x half> %{{.*}})
+// GFX90A-LABEL:  test_global_add_half2
+// GFX90A:  global_atomic_pk_add_f16 v2, v[0:1], v2, off glc
+void test_global_add_half2(__global half2 *addr, half2 x) {
+  half2 *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fadd_v2f16(addr, x);
+}
+
+// CHECK-LABEL: test_global_global_min_f64
+// CHECK: call double @llvm.amdgcn.global.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_global_global_min_f64$local
+// GFX90A:  global_atomic_min_f64
+void test_global_global_min_f64(__global double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fmin_f64(addr, x);
+}
+
+// CHECK-LABEL: test_global_max_f64
+// CHECK: call double @llvm.amdgcn.global.atomic.fmax.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_global_max_f64$local
+// GFX90A:  global_atomic_max_f64
+void test_global_max_f64(__global double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fmax_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_add_local_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fadd.f64.p3f64.f64(double addrspace(3)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_add_local_f64$local
+// GFX90A:  ds_add_rtn_f64
+void test_flat_add_local_f64(__local double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fadd_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_global_add_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_global_add_f64$local
+// GFX90A:  global_atomic_add_f64
+void test_flat_global_add_f64(__global double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fadd_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_min_flat_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fmin.f64.p0f64.f64(double* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_min_flat_f64$local
+// GFX90A:  flat_atomic_min_f64
+void test_flat_min_flat_f64(__generic double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fmin_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_global_min_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_global_min_f64$local
+// GFX90A:  global_atomic_min_f64
+void test_flat_global_min_f64(__global double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fmin_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_max_flat_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fmax.f64.p0f64.f64(double* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_max_flat_f64$local
+// GFX90A:  flat_atomic_max_f64
+void test_flat_max_flat_f64(__generic double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fmax_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_global_max_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fmax.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_global_max_f64$local
+// GFX90A:  global_atomic_max_f64
+void test_flat_global_max_f64(__global 

[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 added a comment.

I will merge this patch in as soon as the builds are successful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

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


[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 added a comment.

Thanks a lot for the review, I will merge this patch in :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

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


[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-08-05 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec accepted this revision.
rampitec 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/D106909/new/

https://reviews.llvm.org/D106909

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


[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364266.
gandhi21299 added a comment.

- combined tests into a single file
- renamed tests for consistency


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx7-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx1030.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx8.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl

Index: clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
@@ -0,0 +1,115 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   %s -S -emit-llvm -o - | FileCheck %s -check-prefix=CHECK
+
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx90a \
+// RUN:   -S -o - %s | FileCheck -check-prefix=GFX90A %s
+
+typedef half __attribute__((ext_vector_type(2))) half2;
+
+// CHECK-LABEL: test_global_add_f64
+// CHECK: call double @llvm.amdgcn.global.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_global_add_f64$local:
+// GFX90A:  global_atomic_add_f64
+void test_global_add_f64(__global double *addr, double x) {
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fadd_f64(addr, x);
+}
+
+// CHECK-LABEL: test_global_add_half2
+// CHECK: call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p1v2f16.v2f16(<2 x half> addrspace(1)* %{{.*}}, <2 x half> %{{.*}})
+// GFX90A-LABEL:  test_global_add_half2
+// GFX90A:  global_atomic_pk_add_f16 v2, v[0:1], v2, off glc
+void test_global_add_half2(__global half2 *addr, half2 x) {
+  half2 *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fadd_v2f16(addr, x);
+}
+
+// CHECK-LABEL: test_global_global_min_f64
+// CHECK: call double @llvm.amdgcn.global.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_global_global_min_f64$local
+// GFX90A:  global_atomic_min_f64
+void test_global_global_min_f64(__global double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fmin_f64(addr, x);
+}
+
+// CHECK-LABEL: test_global_max_f64
+// CHECK: call double @llvm.amdgcn.global.atomic.fmax.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_global_max_f64$local
+// GFX90A:  global_atomic_max_f64
+void test_global_max_f64(__global double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fmax_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_add_local_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fadd.f64.p3f64.f64(double addrspace(3)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_add_local_f64$local
+// GFX90A:  ds_add_rtn_f64
+void test_flat_add_local_f64(__local double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fadd_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_global_add_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fadd.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_global_add_f64$local
+// GFX90A:  global_atomic_add_f64
+void test_flat_global_add_f64(__global double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fadd_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_min_flat_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fmin.f64.p0f64.f64(double* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_min_flat_f64$local
+// GFX90A:  flat_atomic_min_f64
+void test_flat_min_flat_f64(__generic double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fmin_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_global_min_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fmin.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A:  test_flat_global_min_f64$local
+// GFX90A:  global_atomic_min_f64
+void test_flat_global_min_f64(__global double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fmin_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_max_flat_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fmax.f64.p0f64.f64(double* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_max_flat_f64$local
+// GFX90A:  flat_atomic_max_f64
+void test_flat_max_flat_f64(__generic double *addr, double x){
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fmax_f64(addr, x);
+}
+
+// CHECK-LABEL: test_flat_global_max_f64
+// CHECK: call double @llvm.amdgcn.flat.atomic.fmax.f64.p1f64.f64(double addrspace(1)* %{{.*}}, double %{{.*}})
+// GFX90A-LABEL:  test_flat_global_max_f64$local
+// GFX90A:  global_atomic_max_f64
+void test_flat_global_max_f64(__global double *addr, double x){
+  

[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: llvm/lib/Target/AMDGPU/SIISelLowering.cpp:12146
+OptimizationRemark Remark(DEBUG_TYPE, "Passed", RMW->getFunction());
+Remark << "A floating-point atomic instruction will generate an unsafe"
+  " hardware instruction";

It would not necessarily generate a HW instruction. There are still cases where 
we return CmpXChg.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

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


[PATCH] D106891: [AMDGPU] [Remarks] Emit optimization remarks for FP atomics

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364256.
gandhi21299 added a comment.

- fixed remarks in SIISelLowering for hw instruction generation
- fixed test accordingly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106891

Files:
  clang/test/CodeGenCUDA/fp-atomics-optremarks.cu
  clang/test/CodeGenOpenCL/fp-atomics-optremarks-gfx90a.cl
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/AtomicExpandPass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86ISelLowering.h
  llvm/test/CodeGen/AMDGPU/fp-atomics-remarks-gfx90a.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll

Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -16,15 +16,20 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Type-Based Alias Analysis
 ; CHECK-NEXT: Scoped NoAlias Alias Analysis
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/X86/O0-pipeline.ll
===
--- llvm/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -10,13 +10,18 @@
 ; CHECK-NEXT: Target Pass Configuration
 ; CHECK-NEXT: Machine Module Information
 ; CHECK-NEXT: Target Transform Information
+; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Create Garbage Collector Module Metadata
 ; CHECK-NEXT: Assumption Cache Tracker
-; CHECK-NEXT: Profile summary info
 ; CHECK-NEXT: Machine Branch Probability Analysis
 ; CHECK-NEXT:   ModulePass Manager
 ; CHECK-NEXT: Pre-ISel Intrinsic Lowering
 ; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT:   Dominator Tree Construction 
+; CHECK-NEXT:   Natural Loop Information 
+; CHECK-NEXT:   Lazy Branch Probability Analysis 
+; CHECK-NEXT:   Lazy Block Frequency Analysis 
+; CHECK-NEXT:   Optimization Remark Emitter
 ; CHECK-NEXT:   Expand Atomic instructions
 ; CHECK-NEXT:   Lower AMX intrinsics
 ; CHECK-NEXT:   Lower AMX type for load/store
Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -44,6 +44,11 @@
 ; GCN-O0-NEXT:Lower OpenCL enqueued blocks
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
+; GCN-O0-NEXT:  Dominator Tree Construction
+; GCN-O0-NEXT:  Natural Loop Information
+; GCN-O0-NEXT:  Lazy Branch Probability Analysis
+; GCN-O0-NEXT:  Lazy Block Frequency Analysis
+; GCN-O0-NEXT:  Optimization Remark Emitter
 ; GCN-O0-NEXT:  Expand Atomic instructions
 ; GCN-O0-NEXT:  Lower constant intrinsics
 ; GCN-O0-NEXT:  Remove unreachable blocks from the CFG
@@ -180,6 +185,11 @@
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:FunctionPass Manager
 ; GCN-O1-NEXT:  Infer address spaces
+; GCN-O1-NEXT:  Dominator Tree Construction
+; GCN-O1-NEXT:  Natural Loop Information
+; GCN-O1-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-NEXT:  Optimization Remark Emitter
 ; GCN-O1-NEXT:  Expand Atomic instructions
 ; GCN-O1-NEXT:  AMDGPU Promote Alloca
 ; GCN-O1-NEXT:  Dominator Tree Construction
@@ -431,6 +441,11 @@
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:  Infer address spaces
+; GCN-O1-OPTS-NEXT:  Dominator Tree Construction
+; GCN-O1-OPTS-NEXT:  Natural Loop Information
+; GCN-O1-OPTS-NEXT:  Lazy Branch Probability Analysis
+; GCN-O1-OPTS-NEXT:  Lazy Block Frequency Analysis
+; GCN-O1-OPTS-NEXT:  

[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-08-05 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added inline comments.



Comment at: clang/test/CodeGenOpenCL/builtins-fp-atomics-unsupported-gfx7.cl:8
+}
\ No newline at end of file


Add new line.



Comment at: clang/test/CodeGenOpenCL/unsupported-fadd2f16-gfx908.cl:1
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx908 \

Combine all of these gfx908 error tests into a single file. For example like in 
the builtins-amdgcn-dl-insts-err.cl. It is also better to rename these test 
filenames to follow the existing pattern: builtins-amdgcn-*-err.cl


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

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


[PATCH] D106909: [clang] Add clang builtins support for gfx90a

2021-08-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 364242.
gandhi21299 added a comment.

- added more negative tests
- fixed some tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106909

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx1030.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx8.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx90a.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-unsupported-gfx7.cl
  clang/test/CodeGenOpenCL/unsupported-fadd2f16-gfx908.cl
  clang/test/CodeGenOpenCL/unsupported-fadd32-gfx908.cl
  clang/test/CodeGenOpenCL/unsupported-fadd64-flat-gfx908.cl
  clang/test/CodeGenOpenCL/unsupported-fadd64-gfx908.cl
  clang/test/CodeGenOpenCL/unsupported-fmax64-flat-gfx908.cl
  clang/test/CodeGenOpenCL/unsupported-fmax64-gfx908.cl
  clang/test/CodeGenOpenCL/unsupported-fmin64-flat-gfx908.cl
  clang/test/CodeGenOpenCL/unsupported-fmin64-gfx908.cl

Index: clang/test/CodeGenOpenCL/unsupported-fmin64-gfx908.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/unsupported-fmin64-gfx908.cl
@@ -0,0 +1,8 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   -verify -S -o - %s
+
+void test_global_min_f64(__global double *addr, double x) {
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fmin_f64(addr, x); // expected-error{{'__builtin_amdgcn_global_atomic_fmin_f64' needs target feature gfx90a-insts}}
+}
Index: clang/test/CodeGenOpenCL/unsupported-fmin64-flat-gfx908.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/unsupported-fmin64-flat-gfx908.cl
@@ -0,0 +1,8 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   -verify -S -o - %s
+
+void test_flat_min_f64(__global double *addr, double x) {
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fmin_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fmin_f64' needs target feature gfx90a-insts}}
+}
Index: clang/test/CodeGenOpenCL/unsupported-fmax64-gfx908.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/unsupported-fmax64-gfx908.cl
@@ -0,0 +1,8 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   -verify -S -o - %s
+
+void test_global_max_f64(__global double *addr, double x) {
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fmax_f64(addr, x); // expected-error{{'__builtin_amdgcn_global_atomic_fmax_f64' needs target feature gfx90a-insts}}
+}
Index: clang/test/CodeGenOpenCL/unsupported-fmax64-flat-gfx908.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/unsupported-fmax64-flat-gfx908.cl
@@ -0,0 +1,8 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   -verify -S -o - %s
+
+void test_flat_max_f64(__global double *addr, double x) {
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fmax_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fmax_f64' needs target feature gfx90a-insts}}
+}
Index: clang/test/CodeGenOpenCL/unsupported-fadd64-gfx908.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/unsupported-fadd64-gfx908.cl
@@ -0,0 +1,8 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   -verify -S -o - %s
+
+void test_global_add_f64(__global double *addr, double x) {
+  double *rtn;
+  *rtn = __builtin_amdgcn_global_atomic_fadd_f64(addr, x); // expected-error{{'__builtin_amdgcn_global_atomic_fadd_f64' needs target feature gfx90a-insts}}
+}
Index: clang/test/CodeGenOpenCL/unsupported-fadd64-flat-gfx908.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/unsupported-fadd64-flat-gfx908.cl
@@ -0,0 +1,8 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   -verify -S -o - %s
+
+void test_flat_add_f64(__global double *addr, double x) {
+  double *rtn;
+  *rtn = __builtin_amdgcn_flat_atomic_fadd_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fadd_f64' needs target feature gfx90a-insts}}
+}
Index: clang/test/CodeGenOpenCL/unsupported-fadd32-gfx908.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/unsupported-fadd32-gfx908.cl
@@ -0,0 +1,8 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: 

[PATCH] D106785: [C++4OpenCL] Introduces __remove_address_space utility

2021-08-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


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

https://reviews.llvm.org/D106785

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


  1   2   >