[PATCH] D105001: [Clang][RISCV] Support half-precision floating point for RVV intrinsics.

2021-06-29 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added inline comments.



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfadd.c:13
 
+// ASM-NOT: warning
 #include 

craig.topper wrote:
> Do you plan to bring back the ASM check for all tests?
No, I will remove it. This is the first patch to enable half-precision for RVV 
intrinsics. I just added it to ensure the backend could handle it correctly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105001

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


[PATCH] D103668: [PowerPC] Implement trap and conversion builtins for XL compatibility

2021-06-29 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 355129.
Conanap added a comment.

Separated new test cases, rebased for newest changes, different semachecking


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103668

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-conversionfunc.c
  clang/test/CodeGen/builtins-ppc-xlcompat-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-trap.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-conversionfunc.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap-64bit-only.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll
@@ -0,0 +1,139 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+
+; tw
+declare void @llvm.ppc.tw(i32 %a, i32 %b, i32 %c)
+define dso_local void @test__twlgt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlgt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twlgt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 1)
+  ret void
+}
+
+define dso_local void @test__twllt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twllt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twllt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 2)
+  ret void
+}
+
+define dso_local void @test__twne3(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twne3:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twne 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 3)
+  ret void
+}
+
+define dso_local void @test__tweq(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tweq:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tweq 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 4)
+  ret void
+}
+
+define dso_local void @test__twlge(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlge:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 5, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 5)
+  ret void
+}
+
+define dso_local void @test__twlle(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlle:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 6, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 6)
+  ret void
+}
+
+define dso_local void @test__twgt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twgt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twgt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 8)
+  ret void
+}
+
+define dso_local void @test__twge(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twge:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 12, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 12)
+  ret void
+}
+
+define dso_local void @test__twlt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twlt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 16)
+  ret void
+}
+
+define dso_local void @test__twle(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twle:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 20, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 20)
+  ret void
+}
+
+define dso_local void @test__twne24(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twne24:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twne 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 24)
+  ret void
+}
+
+define dso_local void @test__tweq31(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tweq31:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tweq 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 31)
+  ret void
+}
+
+define dso_local void @test__tw_no_match(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tw_no_match:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 13, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 13)
+  ret void
+}
+
+; trap
+declare void @llvm.ppc.trap(i32 %a)
+define dso_local void @test__trap(i32 %a) {
+; CHECK-LABEL: test__trap:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twnei 3, 0
+; CHECK-NEXT:blr
+  call void @llvm.ppc.trap(i32 %a)
+  ret void
+}
Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap-64bit-only.ll
=

[PATCH] D103668: [PowerPC] Implement trap and conversion builtins for XL compatibility

2021-06-29 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 355130.
Conanap marked 3 inline comments as done.
Conanap added a comment.

Removed unneccessary brackets


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103668

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-conversionfunc.c
  clang/test/CodeGen/builtins-ppc-xlcompat-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-trap.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-conversionfunc.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap-64bit-only.ll
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.ll
@@ -0,0 +1,139 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+
+; tw
+declare void @llvm.ppc.tw(i32 %a, i32 %b, i32 %c)
+define dso_local void @test__twlgt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlgt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twlgt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 1)
+  ret void
+}
+
+define dso_local void @test__twllt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twllt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twllt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 2)
+  ret void
+}
+
+define dso_local void @test__twne3(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twne3:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twne 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 3)
+  ret void
+}
+
+define dso_local void @test__tweq(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tweq:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tweq 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 4)
+  ret void
+}
+
+define dso_local void @test__twlge(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlge:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 5, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 5)
+  ret void
+}
+
+define dso_local void @test__twlle(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlle:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 6, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 6)
+  ret void
+}
+
+define dso_local void @test__twgt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twgt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twgt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 8)
+  ret void
+}
+
+define dso_local void @test__twge(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twge:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 12, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 12)
+  ret void
+}
+
+define dso_local void @test__twlt(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twlt:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twlt 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 16)
+  ret void
+}
+
+define dso_local void @test__twle(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twle:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 20, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 20)
+  ret void
+}
+
+define dso_local void @test__twne24(i32 %a, i32 %b) {
+; CHECK-LABEL: test__twne24:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twne 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 24)
+  ret void
+}
+
+define dso_local void @test__tweq31(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tweq31:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tweq 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 31)
+  ret void
+}
+
+define dso_local void @test__tw_no_match(i32 %a, i32 %b) {
+; CHECK-LABEL: test__tw_no_match:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:tw 13, 3, 4
+; CHECK-NEXT:blr
+  call void @llvm.ppc.tw(i32 %a, i32 %b, i32 13)
+  ret void
+}
+
+; trap
+declare void @llvm.ppc.trap(i32 %a)
+define dso_local void @test__trap(i32 %a) {
+; CHECK-LABEL: test__trap:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:twnei 3, 0
+; CHECK-NEXT:blr
+  call void @llvm.ppc.trap(i32 %a)
+  ret void
+}
Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap-64bit-only.ll
==

[PATCH] D103668: [PowerPC] Implement trap and conversion builtins for XL compatibility

2021-06-29 Thread Albion Fung via Phabricator via cfe-commits
Conanap added a comment.

Addressed comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103668

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


[clang] d8faf03 - [X86] Add -mgeneral-regs-only support.

2021-06-29 Thread Tianqing Wang via cfe-commits

Author: Tianqing Wang
Date: 2021-06-29T16:02:51+08:00
New Revision: d8faf03807ac059f669ddea8742dd540e58e45be

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

LOG: [X86] Add -mgeneral-regs-only support.

Reviewed By: pengfei

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

Added: 
clang/test/CodeGen/attr-target-general-regs-only-x86.c
clang/test/Driver/x86-mgeneral-regs-only.c

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/X86.cpp
clang/lib/Driver/ToolChains/Arch/X86.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0122afd2eeada..af004e0c28b54 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3207,8 +3207,8 @@ defm aapcs_bitfield_width : BoolOption<"f", 
"aapcs-bitfield-width",
 " volatile bit-field width is dictated by the field container 
type. (ARM only).">>,
   Group;
 
-def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, 
Group,
-  HelpText<"Generate code which only uses the general purpose registers 
(AArch64 only)">;
+def mgeneral_regs_only : Flag<["-"], "mgeneral-regs-only">, Group,
+  HelpText<"Generate code which only uses the general purpose registers 
(AArch64/x86 only)">;
 def mfix_cortex_a53_835769 : Flag<["-"], "mfix-cortex-a53-835769">,
   Group,
   HelpText<"Workaround Cortex-A53 erratum 835769 (AArch64 only)">;

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 3143a70adf858..9db96c20250f6 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -117,7 +117,20 @@ bool X86TargetInfo::initFeatureMap(
   for (auto &F : CPUFeatures)
 setFeatureEnabled(Features, F, true);
 
-  if (!TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec))
+  std::vector UpdatedFeaturesVec;
+  for (const auto &Feature : FeaturesVec) {
+// Expand general-regs-only to -x86, -mmx and -sse
+if (Feature == "+general-regs-only") {
+  UpdatedFeaturesVec.push_back("-x87");
+  UpdatedFeaturesVec.push_back("-mmx");
+  UpdatedFeaturesVec.push_back("-sse");
+  continue;
+}
+
+UpdatedFeaturesVec.push_back(Feature);
+  }
+
+  if (!TargetInfo::initFeatureMap(Features, Diags, CPU, UpdatedFeaturesVec))
 return false;
 
   // Can't do this earlier because we need to be able to explicitly enable
@@ -126,20 +139,20 @@ bool X86TargetInfo::initFeatureMap(
   // Enable popcnt if sse4.2 is enabled and popcnt is not explicitly disabled.
   auto I = Features.find("sse4.2");
   if (I != Features.end() && I->getValue() &&
-  llvm::find(FeaturesVec, "-popcnt") == FeaturesVec.end())
+  llvm::find(UpdatedFeaturesVec, "-popcnt") == UpdatedFeaturesVec.end())
 Features["popcnt"] = true;
 
   // Additionally, if SSE is enabled and mmx is not explicitly disabled,
   // then enable MMX.
   I = Features.find("sse");
   if (I != Features.end() && I->getValue() &&
-  llvm::find(FeaturesVec, "-mmx") == FeaturesVec.end())
+  llvm::find(UpdatedFeaturesVec, "-mmx") == UpdatedFeaturesVec.end())
 Features["mmx"] = true;
 
   // Enable xsave if avx is enabled and xsave is not explicitly disabled.
   I = Features.find("avx");
   if (I != Features.end() && I->getValue() &&
-  llvm::find(FeaturesVec, "-xsave") == FeaturesVec.end())
+  llvm::find(UpdatedFeaturesVec, "-xsave") == UpdatedFeaturesVec.end())
 Features["xsave"] = true;
 
   return true;
@@ -866,6 +879,7 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) 
const {
   .Case("fma4", true)
   .Case("fsgsbase", true)
   .Case("fxsr", true)
+  .Case("general-regs-only", true)
   .Case("gfni", true)
   .Case("hreset", true)
   .Case("invpcid", true)

diff  --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 94a53f9d9e467..12749c7ec871c 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -213,5 +213,24 @@ void x86::getX86TargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 
   // Now add any that the user explicitly requested on the command line,
   // which may override the defaults.
-  handleTargetFeaturesGroup(Args, Features, options::OPT_m_x86_Features_Group);
+  for (const Arg *A : Args.filtered(options::OPT_m_x86_Features_Group,
+options::OPT_mgeneral_regs_only)) {
+StringRef Name = A->getOption().getName();
+A->claim();
+
+// Skip over "-m".
+assert(Name.startswith("m") && "Invalid feature name.");
+Name = Name.substr(1);
+
+// Replace -mgeneral-regs-only with -x87, -mmx, -sse
+if (A->getOption().getID() == options::OPT_mgeneral_regs_only) {
+ 

[PATCH] D103943: [X86] Add -mgeneral-regs-only support.

2021-06-29 Thread Wang Tianqing 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 rGd8faf03807ac: [X86] Add -mgeneral-regs-only support. 
(authored by tianqing).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103943

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  clang/test/CodeGen/attr-target-general-regs-only-x86.c
  clang/test/Driver/x86-mgeneral-regs-only.c

Index: clang/test/Driver/x86-mgeneral-regs-only.c
===
--- /dev/null
+++ clang/test/Driver/x86-mgeneral-regs-only.c
@@ -0,0 +1,26 @@
+// Test the -mgeneral-regs-only option on x86
+
+// RUN: %clang -target i386-unknown-linux-gnu -mgeneral-regs-only %s -### 2>&1 | FileCheck --check-prefix=CMD %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mgeneral-regs-only %s -### 2>&1 | FileCheck --check-prefix=CMD %s
+// RUN: %clang -target i386-unknown-linux-gnu -mavx2 -mgeneral-regs-only %s -### 2>&1 | FileCheck --check-prefixes=CMD,CMD-BEFORE %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mavx2 -mgeneral-regs-only %s -### 2>&1 | FileCheck --check-prefixes=CMD,CMD-BEFORE %s
+// RUN: %clang -target i386-unknown-linux-gnu -mgeneral-regs-only -mavx2 %s -### 2>&1 | FileCheck --check-prefixes=CMD,CMD-AFTER %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mgeneral-regs-only -mavx2 %s -### 2>&1 | FileCheck --check-prefixes=CMD,CMD-AFTER %s
+
+// RUN: %clang -target i386-unknown-linux-gnu -mgeneral-regs-only -S -emit-llvm %s -o - 2>&1 | FileCheck --check-prefix=IR-GPR %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mgeneral-regs-only -S -emit-llvm %s -o - 2>&1 | FileCheck --check-prefix=IR-GPR %s
+// RUN: %clang -target i386-unknown-linux-gnu -mavx2 -mgeneral-regs-only -S -emit-llvm %s -o - 2>&1 | FileCheck --check-prefix=IR-GPR %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mavx2 -mgeneral-regs-only -S -emit-llvm %s -o - 2>&1 | FileCheck --check-prefix=IR-GPR %s
+// RUN: %clang -target i386-unknown-linux-gnu -mgeneral-regs-only -mavx2 -S -emit-llvm %s -o - 2>&1 | FileCheck --check-prefix=IR-AVX2 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -mgeneral-regs-only -mavx2 -S -emit-llvm %s -o - 2>&1 | FileCheck --check-prefix=IR-AVX2 %s
+
+// CMD-BEFORE: "-target-feature" "+avx2"
+// CMD: "-target-feature" "-x87"
+// CMD: "-target-feature" "-mmx"
+// CMD: "-target-feature" "-sse"
+// CMD-AFTER: "-target-feature" "+avx2"
+
+void foo() { }
+
+// IR-GPR: attributes {{.*}} = { {{.*}} "target-features"="{{.*}}-avx{{.*}}-avx2{{.*}}-avx512f{{.*}}-sse{{.*}}-sse2{{.*}}-ssse3{{.*}}-x87{{.*}}"
+// IR-AVX2: attributes {{.*}} = { {{.*}} "target-features"="{{.*}}+avx{{.*}}+avx2{{.*}}+sse{{.*}}+sse2{{.*}}+ssse3{{.*}}-avx512f{{.*}}-x87{{.*}}"
Index: clang/test/CodeGen/attr-target-general-regs-only-x86.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-target-general-regs-only-x86.c
@@ -0,0 +1,14 @@
+// Test general-regs-only target attribute on x86
+
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: define{{.*}} void @f() [[GPR_ATTRS:#[0-9]+]]
+void __attribute__((target("general-regs-only"))) f() { }
+// CHECK: define{{.*}} void @f_before() [[GPR_ATTRS:#[0-9]+]]
+void __attribute__((target("avx2,general-regs-only"))) f_before() { }
+// CHECK: define{{.*}} void @f_after() [[AVX2_ATTRS:#[0-9]+]]
+void __attribute__((target("general-regs-only,avx2"))) f_after() { }
+
+// CHECK: attributes [[GPR_ATTRS]] = { {{.*}} "target-features"="{{.*}}-avx{{.*}}-avx2{{.*}}-avx512f{{.*}}-sse{{.*}}-sse2{{.*}}-ssse3{{.*}}-x87{{.*}}"
+// CHECK: attributes [[AVX2_ATTRS]] = { {{.*}} "target-features"="{{.*}}+avx{{.*}}+avx2{{.*}}+sse{{.*}}+sse2{{.*}}+ssse3{{.*}}-avx512f{{.*}}-x87{{.*}}"
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -213,5 +213,24 @@
 
   // Now add any that the user explicitly requested on the command line,
   // which may override the defaults.
-  handleTargetFeaturesGroup(Args, Features, options::OPT_m_x86_Features_Group);
+  for (const Arg *A : Args.filtered(options::OPT_m_x86_Features_Group,
+options::OPT_mgeneral_regs_only)) {
+StringRef Name = A->getOption().getName();
+A->claim();
+
+// Skip over "-m".
+assert(Name.startswith("m") && "Invalid feature name.");
+Name = Name.substr(1);
+
+// Replace -mgeneral-regs-only with -x87, -mmx, -sse
+if (A->getOption().getID() == options::OPT_mgeneral_regs_only) {
+  Features.insert(Features.end(), {"-x87", "-mm

[PATCH] D105087: [clang-format] PR49960 clang-format doesn't handle ASI after "return" on JavaScript

2021-06-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: curdeius, HazardyKnusperkeks, mprobst.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.

https://bugs.llvm.org/show_bug.cgi?id=49960

clang-format can mutate legal javascript code due to missing semicolons, but 
clang format pulls the next line into the first causing incorrect grammar.

  function t() {
if (true) return
const v = 42
  }

clang-format result:

  function t() {
if (true)
  return const v = 42
  }

This was already somewhat addressed by the work of @mprobst  in 
https://reviews.llvm.org/rG1dcbbcfc5cf06d2eacc68fbe9b6fc1fb12168d6f back in 
2016, but this revision aims to identify other possible places so clang-format 
wouldn't be quite so destructive as people develop.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105087

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestJS.cpp


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2604,5 +2604,41 @@
   "}\n");
 }
 
+TEST_F(FormatTestJS, ASIAfterReturn) {
+  verifyFormat("if (true) return\n"
+   "const v = 42");
+  verifyFormat("if (true) return\n"
+   "let v = 42");
+  verifyFormat("if (true) return\n"
+   "var v = 42");
+  verifyFormat("if (true) break\n"
+   "let v = 42");
+  verifyFormat("if (true) break\n"
+   "const v = 42");
+  verifyFormat("if (true) break\n"
+   "v = 42");
+  verifyFormat("if (true) continue\n"
+   "let v = 42");
+  verifyFormat("if (true) continue\n"
+   "var v = 42");
+  verifyFormat("if (true) continue\n"
+   "const v = 42");
+  verifyFormat("if (true) yield\n"
+   "let v = 42");
+  verifyFormat("if (true) yield\n"
+   "var v = 42");
+  verifyFormat("if (true) yield\n"
+   "const v = 42");
+
+  verifyFormat("if (true) break\n"
+   "var v = 42");
+  verifyFormat("if (true) return\n"
+   "v = 42");
+  verifyFormat("if (true) continue\n"
+   "v = 42");
+  verifyFormat("if (true) yield\n"
+   "v = 42");
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1006,6 +1006,23 @@
   readToken();
   FormatToken *Next = FormatTok;
 
+  if (Previous->isOneOf(tok::kw_return, tok::kw_break, tok::kw_continue,
+Keywords.kw_yield)) {
+if (Next->isOneOf(Keywords.kw_let, tok::kw_const, Keywords.kw_var))
+  return addUnwrappedLine();
+// Don't go past the end of the file.
+if (!eof()) {
+  if (Next->is(tok::identifier)) {
+// Peek the next token.
+unsigned StoredPosition = Tokens->getPosition();
+FormatToken *NextNext = Tokens->getNextToken();
+Tokens->setPosition(StoredPosition);
+if (NextNext && NextNext->is(tok::equal))
+  return addUnwrappedLine();
+  }
+}
+  }
+
   bool IsOnSameLine =
   CommentsBeforeNextToken.empty()
   ? Next->NewlinesBefore == 0


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2604,5 +2604,41 @@
   "}\n");
 }
 
+TEST_F(FormatTestJS, ASIAfterReturn) {
+  verifyFormat("if (true) return\n"
+   "const v = 42");
+  verifyFormat("if (true) return\n"
+   "let v = 42");
+  verifyFormat("if (true) return\n"
+   "var v = 42");
+  verifyFormat("if (true) break\n"
+   "let v = 42");
+  verifyFormat("if (true) break\n"
+   "const v = 42");
+  verifyFormat("if (true) break\n"
+   "v = 42");
+  verifyFormat("if (true) continue\n"
+   "let v = 42");
+  verifyFormat("if (true) continue\n"
+   "var v = 42");
+  verifyFormat("if (true) continue\n"
+   "const v = 42");
+  verifyFormat("if (true) yield\n"
+   "let v = 42");
+  verifyFormat("if (true) yield\n"
+   "var v = 42");
+  verifyFormat("if (true) yield\n"
+   "const v = 42");
+
+  verifyFormat("if (true) break\n"
+   "var v = 42");
+  verifyFormat("if (true) return\n"
+   "v = 42");
+  verifyFormat("if (true) continue\n"
+   "v = 42");
+  verifyFormat("if (true) yield\n"
+   "v = 42");
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/

[PATCH] D95807: [Coroutines] Add the newly generated SCCs back to the CGSCC work queue after CoroSplit actually happened

2021-06-29 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

> note that we don't really need to run Inliner again on the ramp function 
> after split

This isn't accurate. The inline may run again for ramp function after split and 
it's required by coro elide.

It seems like that we don't need the attribute `CORO_PRESPLIT_ATTR` any more, 
do we? If yes, I think we should remove them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95807

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


[clang] 4d8871a - PR50767: clear non-distinct debuginfo for function with nodebug definition after undecorated declaration

2021-06-29 Thread Jeroen Dobbelaere via cfe-commits

Author: Bruno De Fraine
Date: 2021-06-29T10:26:45+02:00
New Revision: 4d8871a898b30f11c905b27954c18d826c0953c9

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

LOG: PR50767: clear non-distinct debuginfo for function with nodebug definition 
after undecorated declaration

Fix suggested by Yuanfang Chen:

Non-distinct debuginfo is attached to the function due to the undecorated 
declaration. Later, when seeing the function definition and `nodebug` 
attribute, the non-distinct debuginfo should be cleared.

Reviewed By: dblaikie

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

Added: 
clang/test/CodeGen/attr-nodebug2.c

Modified: 
clang/lib/CodeGen/CodeGenFunction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 0ca94657e815..578b8a811817 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1304,8 +1304,14 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, 
llvm::Function *Fn,
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
   // Check if we should generate debug info for this function.
-  if (FD->hasAttr())
-DebugInfo = nullptr; // disable debug info indefinitely for this function
+  if (FD->hasAttr()) {
+// Clear non-distinct debug info that was possibly attached to the function
+// due to an earlier declaration without the nodebug attribute
+if (Fn)
+  Fn->setSubprogram(nullptr);
+// Disable debug info indefinitely for this function
+DebugInfo = nullptr;
+  }
 
   // The function might not have a body if we're generating thunks for a
   // function declaration.

diff  --git a/clang/test/CodeGen/attr-nodebug2.c 
b/clang/test/CodeGen/attr-nodebug2.c
new file mode 100644
index ..fd6eca1f7432
--- /dev/null
+++ b/clang/test/CodeGen/attr-nodebug2.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -debugger-tuning=gdb 
-dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -debug-info-kind=limited -debugger-tuning=gdb 
-dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void t1();
+
+void use() { t1(); }
+
+__attribute__((nodebug)) void t1() {
+  int a = 10;
+  a++;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+// CHECK-LABEL: define{{.*}} void @use()
+// CHECK-SAME:  !dbg
+// CHECK-SAME:  {
+// CHECK:   !dbg
+// CHECK:   }
+
+// PR50767 Function __attribute__((nodebug)) inconsistency causes crash
+// illegal (non-distinct) !dbg metadata was being added to _Z2t1v definition
+
+// CHECK-LABEL: define{{.*}} void @t1()
+// CHECK-NOT:   !dbg
+// CHECK-SAME:  {
+// CHECK-NOT:   !dbg
+// CHECK:   }



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


[PATCH] D104777: PR50767: clear non-distinct debuginfo for function with nodebug definition after undecorated declaration

2021-06-29 Thread Jeroen Dobbelaere via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d8871a898b3: PR50767: clear non-distinct debuginfo for 
function with nodebug definition… (authored by brunodf, committed by 
jeroen.dobbelaere).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104777

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/attr-nodebug2.c


Index: clang/test/CodeGen/attr-nodebug2.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-nodebug2.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -debugger-tuning=gdb 
-dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -debug-info-kind=limited -debugger-tuning=gdb 
-dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void t1();
+
+void use() { t1(); }
+
+__attribute__((nodebug)) void t1() {
+  int a = 10;
+  a++;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+// CHECK-LABEL: define{{.*}} void @use()
+// CHECK-SAME:  !dbg
+// CHECK-SAME:  {
+// CHECK:   !dbg
+// CHECK:   }
+
+// PR50767 Function __attribute__((nodebug)) inconsistency causes crash
+// illegal (non-distinct) !dbg metadata was being added to _Z2t1v definition
+
+// CHECK-LABEL: define{{.*}} void @t1()
+// CHECK-NOT:   !dbg
+// CHECK-SAME:  {
+// CHECK-NOT:   !dbg
+// CHECK:   }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1304,8 +1304,14 @@
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
   // Check if we should generate debug info for this function.
-  if (FD->hasAttr())
-DebugInfo = nullptr; // disable debug info indefinitely for this function
+  if (FD->hasAttr()) {
+// Clear non-distinct debug info that was possibly attached to the function
+// due to an earlier declaration without the nodebug attribute
+if (Fn)
+  Fn->setSubprogram(nullptr);
+// Disable debug info indefinitely for this function
+DebugInfo = nullptr;
+  }
 
   // The function might not have a body if we're generating thunks for a
   // function declaration.


Index: clang/test/CodeGen/attr-nodebug2.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-nodebug2.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -debugger-tuning=gdb -dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -debug-info-kind=limited -debugger-tuning=gdb -dwarf-version=4 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void t1();
+
+void use() { t1(); }
+
+__attribute__((nodebug)) void t1() {
+  int a = 10;
+  a++;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+// CHECK-LABEL: define{{.*}} void @use()
+// CHECK-SAME:  !dbg
+// CHECK-SAME:  {
+// CHECK:   !dbg
+// CHECK:   }
+
+// PR50767 Function __attribute__((nodebug)) inconsistency causes crash
+// illegal (non-distinct) !dbg metadata was being added to _Z2t1v definition
+
+// CHECK-LABEL: define{{.*}} void @t1()
+// CHECK-NOT:   !dbg
+// CHECK-SAME:  {
+// CHECK-NOT:   !dbg
+// CHECK:   }
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1304,8 +1304,14 @@
   QualType ResTy = BuildFunctionArgList(GD, Args);
 
   // Check if we should generate debug info for this function.
-  if (FD->hasAttr())
-DebugInfo = nullptr; // disable debug info indefinitely for this function
+  if (FD->hasAttr()) {
+// Clear non-distinct debug info that was possibly attached to the function
+// due to an earlier declaration without the nodebug attribute
+if (Fn)
+  Fn->setSubprogram(nullptr);
+// Disable debug info indefinitely for this function
+DebugInfo = nullptr;
+  }
 
   // The function might not have a body if we're generating thunks for a
   // function declaration.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99517: Implemented [[clang::musttail]] attribute for guaranteed tail calls.

2021-06-29 Thread David Chisnall via Phabricator via cfe-commits
theraven added a comment.

The error message here is very confusing:

  /home/theraven/snmalloc2/src/mem/../ds/../aal/../ds/defines.h:122:27: error: 
cannot perform a tail call to function 'error' because its signature is 
incompatible with the calling function
[[clang::musttail]] return snmalloc::error(str);
^
  /home/theraven/snmalloc2/src/mem/../ds/../aal/../ds/defines.h:63:16: note: 
target function has different number of parameters (expected 2 but has 1)
[[noreturn]] SNMALLOC_COLD void error(const char* const str);
 ^
  /home/theraven/snmalloc2/src/mem/../ds/../aal/../ds/defines.h:21:25: note: 
expanded from macro 'SNMALLOC_COLD'
  #  define SNMALLOC_COLD __attribute__((cold))
  ^
  /home/theraven/snmalloc2/src/mem/../ds/../aal/../ds/defines.h:122:9: note: 
tail call required by 'musttail' attribute here
[[clang::musttail]] return snmalloc::error(str);
  ^

The caller and callee both have one argument, the error is because the 
enclosing function has two parameters.  The error appears wrong anyway for two 
reasons in this particular context:

- The callee is `[[noreturn]]`, so the stack layout doesn't make any 
difference, anything can be tail called if it's no-return.
- The enclosing function is `always_inline`, so checking its argument-frame 
layout does not give useful information because it's the caller's 
argument-frame layout that matters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

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


[PATCH] D93373: [Flang][Openmp] Upgrade TASKGROUP construct to 5.0.

2021-06-29 Thread Chirag Khandelwal via Phabricator via cfe-commits
AMDChirag added a comment.

@jdoerfert Could you please take a look at this patch as well? (especially for 
the clang part)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93373

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


[PATCH] D69560: [clang-tidy] Add 'bugprone-easily-swappable-parameters' check

2021-06-29 Thread Whisperity via Phabricator via cfe-commits
whisperity marked 2 inline comments as done.
whisperity added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:113-120
+#define FB(Name, K) MIX_##Name = (1ull << (K##ull - 1ull))
+
+  FB(None, 1),  //< Mix between the two parameters is not possible.
+  FB(Trivial, 2),   //< The two mix trivially, and are the exact same type.
+  FB(Canonical, 3), //< The two mix because the types refer to the same
+// CanonicalType, but we do not elaborate as to how.
+

alexfh wrote:
> whisperity wrote:
> > alexfh wrote:
> > > I'd switch to scoped enums (`enum class`), remove the macro, and use 
> > > simpler code like `None = 0x1, Trivial = 0x2, Canonical = 0x4`, etc.
> > `enum class` is a good idea!
> > 
> > Unfortunately, I'm not really sold on the hexa literals... It makes the 
> > code confusing the read, because you have to keep in mind which range the 
> > hexa literals mean, and when there is a shift in position, e.g. if you read 
> > `0x20` you have to count out that okay, that's 2nd position, so at least 
> > 16, so at least the 4th bit, but it is two, so you shift it again to the 
> > right, so in the bit pattern it turns on the 5th bit actually.
> > It makes it very easy to misread or misinterpret things, especially when 
> > trying to work on the source code.
> > (In the last extension patch, the number of elements in the bit mask go up 
> > to the 8th or the 9th bit, I don't remember exactly at the top of my head.)
> > 
> > Compared to this, the current text when read immediately tells you which 
> > "decimal" position you should expect the appropriate bit to be toggled on, 
> > if the flag is there.
> > 
> > Binary literals, on the other hand, would be amazing to use here, sadly 
> > we're only in C++14.
> First of all, do we ever need to know the position of the set bit in these 
> flag enumerators? Isn't it enough that each enumerator has a distinct bit 
> set? If so, there's not much complexity in reading and expanding sequences 
> like `0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 
> 0x0200, ...`.
> However, if that's not to your taste, there's another frequently used style 
> of defining flag enumerations in LLVM: `1 << 0, 1 << 1, 1 << 2, 1 << 3, ...`.
> 
> Either of these is fine, but using macros for this purpose is not necessary 
> and doesn't make the code any easier to read or to modify.
> 
> > Compared to this, the current text when read immediately tells you which 
> > "decimal" position you should expect the appropriate bit to be toggled on, 
> > if the flag is there.
> Do I understand correctly that you need this exclusively for the purpose of 
> reading debug logs? If so, it seems to be better to decode the bits before 
> logging them. See the comment on line 87 above.
Yes, there individual positions themselves don't matter! The only thing that 
matters is that some flags are < than `None` and the rest are `>=`, but that's 
only needed because of the ugly workaround.

I turned the debug printouts to use a manual formatting with "reasonable" 
characters being set (e.g. `T` for `Trivial` or `&` for `reference`). It's much 
more readable and straight-forward, because you actually do not need to know 
the position of the bits themselves, those don't matter.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp:133
+
+  void sanitize() {
+assert(Flags != MIX_Invalid && "sanitize() called on invalid bitvec");

alexfh wrote:
> whisperity wrote:
> > alexfh wrote:
> > > What should this method do and how it should be used? Same for 
> > > Mix::sanitize()
> > Once there are more flags in the bitmask (not just "None" and "Trivial"), 
> > this method deals with sanitising the flags that are toggled on and off by 
> > the recursive descent on the type tree.
> > 
> > For example, if there is a typedef involved (see D95736), it will toggle on 
> > the typedef flag, and start investigating the aliased type. This subsequent 
> > investigation might figure out that the aliased type is trivial, or it is 
> > distinct. In case it is distinct, that level of the recursion will turn on 
> > the "Not mixable" flag. In this case, when the investigation returns 
> > completely, we will have "Typedef" and "None" both turned on. This method 
> > will throw away everything but the "None" bit, so when the data is returned 
> > to the diagnostic-generating part of the check, it will know what to do.
> Thanks for the explanation! But it would be very helpful to have this 
> information in the code, not only in a code review comment.
The full patch stack landed, and this function has a much more elaborated 
implementation (with more comments), I believe. In this patch, there was indeed 
nothing to add here.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-le

[clang] 78d309c - [OpenCL] Fix qualifiers check on binding references to temporaries

2021-06-29 Thread Ole Strohm via cfe-commits

Author: Ole Strohm
Date: 2021-06-29T10:03:57+01:00
New Revision: 78d309ce197c30593450e792b0c2dc7a575f0050

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

LOG: [OpenCL] Fix qualifiers check on binding references to temporaries

Fix the qualifiers check from PR49733.

Fixes: PR49733

Reviewed By: Anastasia

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index f916299e4f560..240188f60592b 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5065,9 +5065,9 @@ static void TryReferenceInitializationCore(Sema &S,
   //than, cv2; otherwise, the program is ill-formed.
   unsigned T1CVRQuals = T1Quals.getCVRQualifiers();
   unsigned T2CVRQuals = T2Quals.getCVRQualifiers();
-  if ((RefRelationship == Sema::Ref_Related &&
-   (T1CVRQuals | T2CVRQuals) != T1CVRQuals) ||
-  !T1Quals.isAddressSpaceSupersetOf(T2Quals)) {
+  if (RefRelationship == Sema::Ref_Related &&
+  ((T1CVRQuals | T2CVRQuals) != T1CVRQuals ||
+   !T1Quals.isAddressSpaceSupersetOf(T2Quals))) {
 
Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
 return;
   }



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


[PATCH] D103962: [C++4OpenCL] Fix qualifiers check on binding references to temporaries

2021-06-29 Thread Ole Strohm 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 rG78d309ce197c: [OpenCL] Fix qualifiers check on binding 
references to temporaries (authored by olestrohm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103962

Files:
  clang/lib/Sema/SemaInit.cpp


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5065,9 +5065,9 @@
   //than, cv2; otherwise, the program is ill-formed.
   unsigned T1CVRQuals = T1Quals.getCVRQualifiers();
   unsigned T2CVRQuals = T2Quals.getCVRQualifiers();
-  if ((RefRelationship == Sema::Ref_Related &&
-   (T1CVRQuals | T2CVRQuals) != T1CVRQuals) ||
-  !T1Quals.isAddressSpaceSupersetOf(T2Quals)) {
+  if (RefRelationship == Sema::Ref_Related &&
+  ((T1CVRQuals | T2CVRQuals) != T1CVRQuals ||
+   !T1Quals.isAddressSpaceSupersetOf(T2Quals))) {
 
Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
 return;
   }


Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5065,9 +5065,9 @@
   //than, cv2; otherwise, the program is ill-formed.
   unsigned T1CVRQuals = T1Quals.getCVRQualifiers();
   unsigned T2CVRQuals = T2Quals.getCVRQualifiers();
-  if ((RefRelationship == Sema::Ref_Related &&
-   (T1CVRQuals | T2CVRQuals) != T1CVRQuals) ||
-  !T1Quals.isAddressSpaceSupersetOf(T2Quals)) {
+  if (RefRelationship == Sema::Ref_Related &&
+  ((T1CVRQuals | T2CVRQuals) != T1CVRQuals ||
+   !T1Quals.isAddressSpaceSupersetOf(T2Quals))) {
 Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
 return;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-29 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.

Really appreciate the unit tests!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

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


[PATCH] D105091: [RISCV] Pass -u to linker correctly.

2021-06-29 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng created this revision.
Herald added subscribers: vkmr, frasercrmck, evandro, luismarques, apazos, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, 
niosHD, sabuasal, simoncook, johnrusso, rbar, asb.
kito-cheng requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

`-u` is a linker option used to pretend a symbol is undefined,
this option are common used for force pull-in weak symbol.

This option should pass to `ld`, and many other toolchain in Clang
like `tools::gnutools` has pass that too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105091

Files:
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/test/Driver/riscv-args.c


Index: clang/test/Driver/riscv-args.c
===
--- clang/test/Driver/riscv-args.c
+++ clang/test/Driver/riscv-args.c
@@ -5,3 +5,9 @@
 // RUN:   --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LD %s
 // CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-T" "a.lds"
+
+// Make sure -u has passed to linker
+// RUN: %clang -### -target riscv32 \
+// RUN:   --gcc-toolchain= -u foo %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-U-LD %s
+// CHECK-U-LD: {{.*}} "-u" "foo"
Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -184,6 +184,7 @@
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
+  Args.AddAllArgs(CmdArgs, options::OPT_u);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
   Args.AddAllArgs(CmdArgs,
   {options::OPT_T_Group, options::OPT_e, options::OPT_s,


Index: clang/test/Driver/riscv-args.c
===
--- clang/test/Driver/riscv-args.c
+++ clang/test/Driver/riscv-args.c
@@ -5,3 +5,9 @@
 // RUN:   --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-LD %s
 // CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-T" "a.lds"
+
+// Make sure -u has passed to linker
+// RUN: %clang -### -target riscv32 \
+// RUN:   --gcc-toolchain= -u foo %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-U-LD %s
+// CHECK-U-LD: {{.*}} "-u" "foo"
Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp
===
--- clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -184,6 +184,7 @@
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
+  Args.AddAllArgs(CmdArgs, options::OPT_u);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
   Args.AddAllArgs(CmdArgs,
   {options::OPT_T_Group, options::OPT_e, options::OPT_s,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-29 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 355152.
vsavchenko added a comment.

Add one more note to `getType` docstring


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/SValTest.cpp

Index: clang/unittests/StaticAnalyzer/SValTest.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -0,0 +1,366 @@
+//===- unittests/StaticAnalyzer/SvalTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CheckerRegistration.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+
+// getType() tests include whole bunch of type comparisons,
+// so when something is wrong, it's good to have gtest telling us
+// what are those types.
+LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
+   const QualType &T) {
+  return OS << T.getAsString();
+}
+
+LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
+   const CanQualType &T) {
+  return OS << QualType{T};
+}
+
+namespace ento {
+namespace {
+
+//===--===//
+//   Testing framework implementation
+//===--===//
+
+/// A simple map from variable names to symbolic values used to init them.
+using SVals = llvm::StringMap;
+
+/// SValCollector is the barebone of all tests.
+///
+/// It is implemented as a checker and reacts to binds, so we find
+/// symbolic values of interest, and to end analysis, where we actually
+/// can test whatever we gathered.
+class SValCollector : public Checker {
+public:
+  void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const {
+// Skip instantly if we finished testing.
+// Also, we care only for binds happening in variable initializations.
+if (Tested || !isa(S))
+  return;
+
+if (const auto *VR = llvm::dyn_cast_or_null(Loc.getAsRegion())) {
+  CollectedSVals[VR->getDescriptiveName(false)] = Val;
+}
+  }
+
+  void checkEndAnalysis(ExplodedGraph &G, BugReporter &B,
+ExprEngine &Engine) const {
+if (!Tested) {
+  test(Engine, Engine.getContext());
+  Tested = true;
+  CollectedSVals.clear();
+}
+  }
+
+  /// Helper function for tests to access bound symbolic values.
+  SVal getByName(StringRef Name) const { return CollectedSVals[Name]; }
+
+private:
+  /// Entry point for tests.
+  virtual void test(ExprEngine &Engine, const ASTContext &Context) const = 0;
+
+  mutable bool Tested = false;
+  mutable SVals CollectedSVals;
+};
+
+// SVAL_TEST is a combined way of providing a short code snippet and
+// to test some programmatic predicates on symbolic values produced by the
+// engine for the actual code.
+//
+// Each test has a NAME.  One can think of it as a name for normal gtests.
+//
+// Each test should provide a CODE snippet.  Code snippets might contain any
+// valid C/C++, but have ONLY ONE defined function.  There are no requirements
+// about function's name or parameters.  It can even be a class method.  The
+// body of the function must contain a set of variable declarations.  Each
+// variable declaration gets bound to a symbolic value, so for the following
+// example:
+//
+// int x = ;
+//
+// `x` will be bound to whatever symbolic value the engine produced for .
+// LIVENESS and REASSIGNMENTS don't affect this binding.
+//
+// During the test the actual values can be accessed via `ge

[PATCH] D104647: [analyzer] Support SVal::getType for pointer-to-member values

2021-06-29 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 355154.
vsavchenko added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104647

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/unittests/StaticAnalyzer/SValTest.cpp

Index: clang/unittests/StaticAnalyzer/SValTest.cpp
===
--- clang/unittests/StaticAnalyzer/SValTest.cpp
+++ clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -361,6 +361,41 @@
   EXPECT_EQ(Context.VoidPtrTy, B.getType(Context));
 }
 
+SVAL_TEST(GetMemberPtrType, R"(
+struct A {
+  int a;
+  struct {
+int b;
+  };
+};
+void foo(int A::*x) {
+  int A::*a = &A::a;
+  int A::*b = &A::b;
+  int A::*c = x;
+}
+)") {
+  SVal A = getByName("a");
+  ASSERT_FALSE(A.getType(Context).isNull());
+  const auto *AMemberPtrTy = dyn_cast(A.getType(Context));
+  ASSERT_NE(AMemberPtrTy, nullptr);
+  EXPECT_EQ(Context.IntTy, AMemberPtrTy->getPointeeType());
+  const auto *ARecordType = dyn_cast(AMemberPtrTy->getClass());
+  ASSERT_NE(ARecordType, nullptr);
+  EXPECT_EQ("A", ARecordType->getDecl()->getName());
+
+  SVal B = getByName("b");
+  ASSERT_FALSE(B.getType(Context).isNull());
+  const auto *BMemberPtrTy = dyn_cast(B.getType(Context));
+  ASSERT_NE(BMemberPtrTy, nullptr);
+  EXPECT_EQ(Context.IntTy, BMemberPtrTy->getPointeeType());
+  const auto *BRecordType = dyn_cast(BMemberPtrTy->getClass());
+  ASSERT_NE(BRecordType, nullptr);
+  EXPECT_EQ("A", BRecordType->getDecl()->getName());
+
+  SVal C = getByName("c");
+  EXPECT_TRUE(C.isUnknown());
+}
+
 } // namespace
 } // namespace ento
 } // namespace clang
Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -180,6 +180,9 @@
   QualType VisitNonLocSymbolVal(nonloc::SymbolVal SV) {
 return Visit(SV.getSymbol());
   }
+  QualType VisitNonLocPointerToMember(nonloc::PointerToMember PTM) {
+return PTM.getType();
+  }
   QualType VisitSymbolicRegion(const SymbolicRegion *SR) {
 return Visit(SR->getSymbol());
   }
@@ -209,21 +212,21 @@
 }
 
 bool nonloc::PointerToMember::isNullMemberPointer() const {
-  return getPTMData().isNull();
+  return getPTMData() == nullptr;
 }
 
 const NamedDecl *nonloc::PointerToMember::getDecl() const {
-  const auto PTMD = this->getPTMData();
-  if (PTMD.isNull())
+  if (!getPTMData())
 return nullptr;
 
-  const NamedDecl *ND = nullptr;
-  if (PTMD.is())
-ND = PTMD.get();
-  else
-ND = PTMD.get()->getDeclaratorDecl();
+  return getPTMData()->getDeclaratorDecl();
+}
 
-  return ND;
+QualType nonloc::PointerToMember::getType() const {
+  if (!getPTMData())
+return {};
+
+  return getPTMData()->getType();
 }
 
 //===--===//
@@ -239,17 +242,11 @@
 }
 
 nonloc::PointerToMember::iterator nonloc::PointerToMember::begin() const {
-  const PTMDataType PTMD = getPTMData();
-  if (PTMD.is())
-return {};
-  return PTMD.get()->begin();
+  return getPTMData()->begin();
 }
 
 nonloc::PointerToMember::iterator nonloc::PointerToMember::end() const {
-  const PTMDataType PTMD = getPTMData();
-  if (PTMD.is())
-return {};
-  return PTMD.get()->end();
+  return getPTMData()->end();
 }
 
 //===--===//
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -236,7 +236,7 @@
   return nonloc::SymbolVal(sym);
 }
 
-DefinedSVal SValBuilder::getMemberPointer(const NamedDecl *ND) {
+DefinedSVal SValBuilder::getMemberPointer(const NamedDecl *ND, QualType T) {
   assert(!ND || isa(ND) || isa(ND) ||
  isa(ND));
 
@@ -250,7 +250,8 @@
   return getFunctionPointer(MD);
   }
 
-  return nonloc::PointerToMember(ND);
+  return nonloc::PointerToMember(
+  ND ? getBasicValueFactory().getPointerToMemberData(ND, T) : nullptr);
 }
 
 DefinedSVal SValBuilder::getFunctionPointer(const FunctionDecl *func) {
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -516,7 +516,7 @@
 continue;
   }
   case CK_NullToMemberPointer: {
-SVal V = svalBuilder.getMemberPointer(nu

[clang] 159024c - [analyzer] Implement getType for SVal

2021-06-29 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-29T12:11:19+03:00
New Revision: 159024ce231502d4d68825c35c3548a14577f0fd

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

LOG: [analyzer] Implement getType for SVal

This commit adds a function to the top-class of SVal hierarchy to
provide type information about the value.  That can be extremely
useful when this is the only piece of information that the user is
actually caring about.

Additionally, this commit introduces a testing framework for writing
unit-tests for symbolic values.

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

Added: 
clang/unittests/StaticAnalyzer/SValTest.cpp

Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
clang/lib/StaticAnalyzer/Core/SVals.cpp
clang/unittests/StaticAnalyzer/CMakeLists.txt

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
index f59b254094db8..bb598af681666 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -52,6 +52,8 @@ class CompoundValData : public llvm::FoldingSetNode {
   iterator begin() const { return L.begin(); }
   iterator end() const { return L.end(); }
 
+  QualType getType() const { return T; }
+
   static void Profile(llvm::FoldingSetNodeID& ID, QualType T,
   llvm::ImmutableList L);
 

diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
index b1c33713febd9..6199c8d8d179c 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -201,6 +201,19 @@ class SVal {
   SymExpr::symbol_iterator symbol_end() const {
 return SymExpr::symbol_end();
   }
+
+  /// Try to get a reasonable type for the given value.
+  ///
+  /// \returns The best approximation of the value type or Null.
+  /// In theory, all symbolic values should be typed, but this function
+  /// is still a WIP and might have a few blind spots.
+  ///
+  /// \note This function should not be used when the user has access to the
+  /// bound expression AST node as well, since AST always has exact types.
+  ///
+  /// \note Loc values are interpreted as pointer rvalues for the purposes of
+  /// this method.
+  QualType getType(const ASTContext &) const;
 };
 
 inline raw_ostream &operator<<(raw_ostream &os, clang::ento::SVal V) {

diff  --git a/clang/lib/StaticAnalyzer/Core/SVals.cpp 
b/clang/lib/StaticAnalyzer/Core/SVals.cpp
index 252596887e4f1..117546e43b1a1 100644
--- a/clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
@@ -21,6 +22,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
 #include "llvm/ADT/Optional.h"
@@ -136,6 +138,63 @@ const MemRegion *SVal::getAsRegion() const {
   return nullptr;
 }
 
+namespace {
+class TypeRetrievingVisitor
+: public FullSValVisitor {
+private:
+  const ASTContext &Context;
+
+public:
+  TypeRetrievingVisitor(const ASTContext &Context) : Context(Context) {}
+
+  QualType VisitLocMemRegionVal(loc::MemRegionVal MRV) {
+return Visit(MRV.getRegion());
+  }
+  QualType VisitLocGotoLabel(loc::GotoLabel GL) {
+return QualType{Context.VoidPtrTy};
+  }
+  template  QualType VisitConcreteInt(ConcreteInt CI) {
+const llvm::APSInt &Value = CI.getValue();
+return Context.getIntTypeForBitwidth(Value.getBitWidth(), 
Value.isSigned());
+  }
+  QualType VisitLocConcreteInt(loc::ConcreteInt CI) {
+return VisitConcreteInt(CI);
+  }
+  QualType VisitNonLocConcreteInt(nonloc::ConcreteInt CI) {
+return VisitConcreteInt(CI);
+  }
+  QualType VisitNonLocLocAsInteger(nonloc::LocAsInteger LI) {
+QualType NestedType = Visit(LI.getLoc());
+if (NestedType.isNull())
+  return NestedType;
+
+return Context.getIntTypeForBitwidth(LI.getNumBits(),
+ 

[PATCH] D105092: [PoC][RISCV] Add the tail policy argument to builtins/intrinsics.

2021-06-29 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai created this revision.
HsiangKai added reviewers: craig.topper, frasercrmck, rogfer01, kito-cheng.
Herald added subscribers: StephenFan, vkmr, dexonsmith, evandro, luismarques, 
apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, 
brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, shiva0217, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
HsiangKai requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

This is a proof-of-concept patch. It does not add the tail policy
argument to all the builtins/intrinsics. This patch uses vadd as an
example to add the tail policy argument.

I added several new classes. There is no need to add these classes in
the target description. I do so just to limit the modification to vadd
only.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105092

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics/vadd-policy.c
  clang/utils/TableGen/RISCVVEmitter.cpp
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
  llvm/test/CodeGen/RISCV/rvv/vadd-policy.ll

Index: llvm/test/CodeGen/RISCV/rvv/vadd-policy.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rvv/vadd-policy.ll
@@ -0,0 +1,65 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs \
+; RUN:   --riscv-no-aliases < %s | FileCheck %s
+
+declare  @llvm.riscv.vadd.nxv8i8.nxv8i8(
+  ,
+  ,
+  i64);
+
+define  @intrinsic_vadd_vv_nxv8i8_nxv8i8_nxv8i8( %0,  %1, i64 %2) nounwind {
+; CHECK-LABEL: intrinsic_vadd_vv_nxv8i8_nxv8i8_nxv8i8:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vsetvli zero, a0, e8, m1, ta, mu
+; CHECK-NEXT:vadd.vv v8, v8, v9
+; CHECK-NEXT:jalr zero, 0(ra)
+entry:
+  %a = call  @llvm.riscv.vadd.nxv8i8.nxv8i8(
+ %0,
+ %1,
+i64 %2)
+
+  ret  %a
+}
+
+declare  @llvm.riscv.vadd.mask.nxv8i8.nxv8i8(
+  ,
+  ,
+  ,
+  ,
+  i64, i64);
+
+define  @intrinsic_vadd_mask_tu( %0,  %1,  %2,  %3, i64 %4) nounwind {
+; CHECK-LABEL: intrinsic_vadd_mask_tu:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vsetivli zero, 3, e8, m1, tu, mu
+; CHECK-NEXT:vadd.vv v8, v9, v10, v0.t
+; CHECK-NEXT:jalr zero, 0(ra)
+entry:
+  %a = call  @llvm.riscv.vadd.mask.nxv8i8.nxv8i8(
+ %0,
+ %1,
+ %2,
+ %3,
+i64 %4, i64 0)
+
+  ret  %a
+}
+
+define  @intrinsic_vadd_mask_ta( %0,  %1,  %2,  %3, i64 %4) nounwind {
+; CHECK-LABEL: intrinsic_vadd_mask_ta:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:vsetivli zero, 3, e8, m1, ta, mu
+; CHECK-NEXT:vadd.vv v8, v9, v10, v0.t
+; CHECK-NEXT:jalr zero, 0(ra)
+entry:
+  %a = call  @llvm.riscv.vadd.mask.nxv8i8.nxv8i8(
+ %0,
+ %1,
+ %2,
+ %3,
+i64 %4, i64 1)
+
+  ret  %a
+}
+
Index: llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
@@ -269,6 +269,36 @@
  VMV0:$vm, GPR:$vl, sew)>;
 }
 
+multiclass VPatBinaryVL_VV_WithPolicy {
+  def : Pat<(result_type (vop
+ (op_type op_reg_class:$rs1),
+ (op_type op_reg_class:$rs2),
+ (mask_type true_mask),
+ VLOpFrag)),
+(!cast(instruction_name#"_VV_"# vlmul.MX)
+ op_reg_class:$rs1,
+ op_reg_class:$rs2,
+ GPR:$vl, sew)>;
+  def : Pat<(result_type (vop
+ (op_type op_reg_class:$rs1),
+ (op_type op_reg_class:$rs2),
+ (mask_type VMV0:$vm),
+ VLOpFrag)),
+(!cast(instruction_name#"_VV_"# vlmul.MX#"_MASK")
+ (result_type (IMPLICIT_DEF)),
+ op_reg_class:$rs1,
+ op_reg_class:$rs2,
+ VMV0:$vm, GPR:$vl, sew, 0)>;
+}
+
 multiclass VPatBinaryVL_XI;
 }
 
+multiclass VPatBinaryVL_XI_WithPolicy {
+  def : Pat<(result_type (vop
+ (vop_type vop_reg_class:$rs1),
+ (vop_type (SplatPatKind (XLenVT xop_kind:$rs2))),
+ (mask_type true_mask),
+ VLOpFrag)),
+(!cast(instruction_name#_#suffix#_# vlmul.MX)
+ vop_reg_class:$rs1,
+ xop_kind:$rs2,
+ GPR:$vl, sew)>;
+  def : Pat<(result_type (vop
+ (vop_type vop_reg_class:$rs1)

[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-29 Thread Valeriy Savchenko 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 rG159024ce2315: [analyzer] Implement getType for SVal 
(authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/unittests/StaticAnalyzer/CMakeLists.txt
  clang/unittests/StaticAnalyzer/SValTest.cpp

Index: clang/unittests/StaticAnalyzer/SValTest.cpp
===
--- /dev/null
+++ clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -0,0 +1,366 @@
+//===- unittests/StaticAnalyzer/SvalTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CheckerRegistration.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
+#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
+#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+
+// getType() tests include whole bunch of type comparisons,
+// so when something is wrong, it's good to have gtest telling us
+// what are those types.
+LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
+   const QualType &T) {
+  return OS << T.getAsString();
+}
+
+LLVM_ATTRIBUTE_UNUSED std::ostream &operator<<(std::ostream &OS,
+   const CanQualType &T) {
+  return OS << QualType{T};
+}
+
+namespace ento {
+namespace {
+
+//===--===//
+//   Testing framework implementation
+//===--===//
+
+/// A simple map from variable names to symbolic values used to init them.
+using SVals = llvm::StringMap;
+
+/// SValCollector is the barebone of all tests.
+///
+/// It is implemented as a checker and reacts to binds, so we find
+/// symbolic values of interest, and to end analysis, where we actually
+/// can test whatever we gathered.
+class SValCollector : public Checker {
+public:
+  void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const {
+// Skip instantly if we finished testing.
+// Also, we care only for binds happening in variable initializations.
+if (Tested || !isa(S))
+  return;
+
+if (const auto *VR = llvm::dyn_cast_or_null(Loc.getAsRegion())) {
+  CollectedSVals[VR->getDescriptiveName(false)] = Val;
+}
+  }
+
+  void checkEndAnalysis(ExplodedGraph &G, BugReporter &B,
+ExprEngine &Engine) const {
+if (!Tested) {
+  test(Engine, Engine.getContext());
+  Tested = true;
+  CollectedSVals.clear();
+}
+  }
+
+  /// Helper function for tests to access bound symbolic values.
+  SVal getByName(StringRef Name) const { return CollectedSVals[Name]; }
+
+private:
+  /// Entry point for tests.
+  virtual void test(ExprEngine &Engine, const ASTContext &Context) const = 0;
+
+  mutable bool Tested = false;
+  mutable SVals CollectedSVals;
+};
+
+// SVAL_TEST is a combined way of providing a short code snippet and
+// to test some programmatic predicates on symbolic values produced by the
+// engine for the actual code.
+//
+// Each test has a NAME.  One can think of it as a name for normal gtests.
+//
+// Each test should provide a CODE snippet.  Code snippets might contain any
+// valid C/C++, but have ONLY ONE defined function.  There are no requirements
+// about function's name or parameters.  It can even be a class method.  The
+// body of the function must contain a set of variable declarations.  Each
+// variable declaration gets bound to a symbolic value, so for the following
+// example:
+//
+// int x = ;
+//
+// `x` will be bound to whatever symbolic value the engine produced for .
+// LIVENESS an

[PATCH] D104915: [OpenCL] Add support of __opencl_c_read_write_images feature macro

2021-06-29 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:10106
 def err_opencl_invalid_read_write : Error<
-  "access qualifier %0 can not be used for %1 %select{|prior to OpenCL version 
2.0}2">;
+  "access qualifier %0 can not be used for %1 %select{|prior to OpenCL C 
version 2.0 or in 3.0 and without __opencl_c_read_write_images feature}2">;
 def err_opencl_multiple_access_qualifiers : Error<

Suggesting a slight rewording:
`prior to OpenCL C version 2.0 or in version 3.0 without 
__opencl_c_read_write_images`



Comment at: clang/lib/Basic/Targets.cpp:746
 
   // Validate that feature macros are set properly for OpenCL C 3.0.
   // In other cases assume that target is always valid.

Maybe we should change this comment to something like:

`// Validate the feature dependencies for OpenCL C 3.0.`

Since it is not exactly about the macros.



Comment at: clang/lib/Basic/Targets.cpp:752
+  bool IsValid = true;
+  // Some features are dependent on other features
+  for (auto &FeaturePair :

Maybe we should comment that the first element of the pair is the feature that 
depends on the feature in the second element?



Comment at: clang/lib/Basic/Targets.cpp:757
+!hasFeatureEnabled(OpenCLFeaturesMap, FeaturePair.second)) {
+  IsValid &= false;
+  Diags.Report(diag::err_opencl_feature_requires)

I guess we don't need the compound assignment here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104915

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


[clang] b284229 - [analyzer] Fix SValTest for LocAsInt test

2021-06-29 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-29T13:01:41+03:00
New Revision: b2842298cebf420ecb3750bf309021a7f37870c1

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

LOG: [analyzer] Fix SValTest for LocAsInt test

Added: 


Modified: 
clang/unittests/StaticAnalyzer/SValTest.cpp

Removed: 




diff  --git a/clang/unittests/StaticAnalyzer/SValTest.cpp 
b/clang/unittests/StaticAnalyzer/SValTest.cpp
index 0956984868384..ea10d69d2804e 100644
--- a/clang/unittests/StaticAnalyzer/SValTest.cpp
+++ b/clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -166,7 +166,7 @@ void foo(int *x) {
   SVal A = getByName("a");
   ASSERT_FALSE(A.getType(Context).isNull());
   // TODO: Turn it into signed long
-  EXPECT_EQ(Context.UnsignedLongTy, A.getType(Context));
+  EXPECT_EQ(Context.getUIntPtrType(), A.getType(Context));
 
   SVal B = getByName("b");
   ASSERT_FALSE(B.getType(Context).isNull());



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


[PATCH] D105097: [clang][AArch64][SVE] Handle PRValue under VLAT <-> VLST cast

2021-06-29 Thread JunMa via Phabricator via cfe-commits
junparser created this revision.
junparser added reviewers: joechrisellis, c-rhodes, efriedma, aeubanks, bsmith.
Herald added subscribers: psnobl, kristof.beyls, tschuett.
junparser requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change fixes the crash that PRValue cannot be handled by
EmitLValue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105097

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c


Index: clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
===
--- clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
+++ clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
@@ -103,3 +103,46 @@
   parr = &arr[0];
   return *parr;
 }
+
+// CHECK-LABEL: @test_cast(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca <16 x i32>, align 16
+// CHECK-NEXT:[[PRED_ADDR:%.*]] = alloca , align 2
+// CHECK-NEXT:[[VEC_ADDR:%.*]] = alloca , align 16
+// CHECK-NEXT:[[XX:%.*]] = alloca <16 x i32>, align 16
+// CHECK-NEXT:[[YY:%.*]] = alloca <16 x i32>, align 16
+// CHECK-NEXT:[[PG:%.*]] = alloca , align 2
+// CHECK-NEXT:[[SAVED_PRVALUE:%.*]] = alloca <16 x i32>, align 64
+// CHECK-NEXT:store  [[PRED:%.*]], * 
[[PRED_ADDR]], align 2
+// CHECK-NEXT:store  [[VEC:%.*]], * 
[[VEC_ADDR]], align 16
+// CHECK-NEXT:store <16 x i32> , <16 x 
i32>* [[XX]], align 16
+// CHECK-NEXT:store <16 x i32> , <16 x 
i32>* [[YY]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load , * 
[[PRED_ADDR]], align 2
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i8>, <8 x i8>* @global_pred, align 2
+// CHECK-NEXT:[[TMP2:%.*]] = load , * 
bitcast (<8 x i8>* @global_pred to *), align 2
+// CHECK-NEXT:[[TMP3:%.*]] = load <16 x i32>, <16 x i32>* [[XX]], align 16
+// CHECK-NEXT:[[TMP4:%.*]] = load <16 x i32>, <16 x i32>* [[YY]], align 16
+// CHECK-NEXT:[[ADD:%.*]] = add <16 x i32> [[TMP3]], [[TMP4]]
+// CHECK-NEXT:store <16 x i32> [[ADD]], <16 x i32>* [[SAVED_PRVALUE]], 
align 64
+// CHECK-NEXT:[[TMP5:%.*]] = bitcast <16 x i32>* [[SAVED_PRVALUE]] to 
*
+// CHECK-NEXT:[[TMP6:%.*]] = load , * 
[[TMP5]], align 64
+// CHECK-NEXT:[[TMP7:%.*]] = call  
@llvm.aarch64.sve.and.z.nxv16i1( [[TMP0]],  
[[TMP2]],  [[TMP6]])
+// CHECK-NEXT:store  [[TMP7]], * 
[[PG]], align 2
+// CHECK-NEXT:[[TMP8:%.*]] = load , * 
[[PG]], align 2
+// CHECK-NEXT:[[TMP9:%.*]] = load <16 x i32>, <16 x i32>* @global_vec, 
align 16
+// CHECK-NEXT:[[CASTSCALABLESVE:%.*]] = call  
@llvm.experimental.vector.insert.nxv4i32.v16i32( undef, <16 x 
i32> [[TMP9]], i64 0)
+// CHECK-NEXT:[[TMP10:%.*]] = load , * 
[[VEC_ADDR]], align 16
+// CHECK-NEXT:[[TMP11:%.*]] = call  
@llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[TMP8]])
+// CHECK-NEXT:[[TMP12:%.*]] = call  
@llvm.aarch64.sve.add.nxv4i32( [[TMP11]],  
[[CASTSCALABLESVE]],  [[TMP10]])
+// CHECK-NEXT:[[CASTFIXEDSVE:%.*]] = call <16 x i32> 
@llvm.experimental.vector.extract.v16i32.nxv4i32( [[TMP12]], 
i64 0)
+// CHECK-NEXT:store <16 x i32> [[CASTFIXEDSVE]], <16 x i32>* [[RETVAL]], 
align 16
+// CHECK-NEXT:[[TMP13:%.*]] = load <16 x i32>, <16 x i32>* [[RETVAL]], 
align 16
+// CHECK-NEXT:[[CASTSCALABLESVE1:%.*]] = call  
@llvm.experimental.vector.insert.nxv4i32.v16i32( undef, <16 x 
i32> [[TMP13]], i64 0)
+// CHECK-NEXT:ret  [[CASTSCALABLESVE1]]
+//
+fixed_int32_t test_cast(svbool_t pred, svint32_t vec) {
+  fixed_int32_t xx = {1, 2, 3, 4};
+  fixed_int32_t yy = {2, 5, 4, 6};
+  svbool_t pg = svand_z(pred, global_pred, xx + yy);
+  return svadd_m(pg, global_vec, vec);
+}
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2111,7 +2111,13 @@
 return EmitLoadOfLValue(DestLV, CE->getExprLoc());
   }
 
-  Address Addr = EmitLValue(E).getAddress(CGF);
+  Address Addr = Address::invalid();
+  if (E->isPRValue() && !isa(E)) {
+Addr = CGF.CreateDefaultAlignTempAlloca(SrcTy, "saved-prvalue");
+LValue LV = CGF.MakeAddrLValue(Addr, E->getType());
+CGF.EmitStoreOfScalar(Src, LV);
+  } else
+Addr = EmitLValue(E).getAddress(CGF);
   Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy));
   LValue DestLV = CGF.MakeAddrLValue(Addr, DestTy);
   DestLV.setTBAAInfo(TBAAAccessInfo::getMayAliasInfo());


Index: clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
===
--- clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
+++ clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
@@ -103,3 +103,46 @@
   parr = &arr[0];
   return *parr;
 }
+
+// CHECK-LABEL: @test_cast(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca <16 x i32>, align 

[PATCH] D104858: [OpenCL][ARM] Fix ICE when compiling a kernel

2021-06-29 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 355166.
Anastasia retitled this revision from "[OpenCL][ARM] Fix ICE when compiling a 
source with the kernel" to "[OpenCL][ARM] Fix ICE when compiling a kernel".
Anastasia edited the summary of this revision.
Anastasia added reviewers: pekka, svenvh.
Anastasia added a subscriber: cfe-commits.

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

https://reviews.llvm.org/D104858

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl


Index: clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl
===
--- clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl
+++ clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl
@@ -1,9 +1,16 @@
 // RUN: %clang_cc1 %s -cl-std=CL1.2 -emit-llvm -triple x86_64-unknown-unknown 
-o - | FileCheck %s
 // RUN: %clang_cc1 %s -cl-std=CL1.2 -emit-llvm -triple amdgcn-unknown-unknown 
-o - | FileCheck -check-prefixes=AMDGCN %s
-// Test that the kernels always use the SPIR calling convention
-// to have unambiguous mapping of arguments to feasibly implement
+// RUN: %clang_cc1 %s -cl-std=CL1.2 -emit-llvm -triple arm -o - | FileCheck 
-check-prefixes=ARM %s
+// RUN: %clang_cc1 %s -cl-std=CL1.2 -emit-llvm -triple aarch64 -o - | 
FileCheck -check-prefixes=AARCH64 %s
+
+// Test that the kernels use the SPIR calling convention for targets that
+// support it.
+// This facilitates unambiguous mapping of arguments to feasibly implement
 // clSetKernelArg().
 
+// ARM-NOT: spir_kernel
+// AARCH64-NOT: spir_kernel
+
 typedef struct int_single {
 int a;
 } int_single;
@@ -21,7 +28,10 @@
 long elementE;
 float elementF;
 short elementG;
+// FIXME: double type should be enabled correctly for Arm CPU.
+#if !defined(__ARM_ARCH)
 double elementH;
+#endif
 } test_struct;
 
 kernel void test_single(int_single input, global int* output) {
@@ -53,7 +63,9 @@
  output[4] = (int)input.elementE;
  output[5] = (int)input.elementF;
  output[6] = (int)input.elementG;
+#if !defined(__ARM_ARCH)
  output[7] = (int)input.elementH;
+#endif
 };
 
 void test_function(int_pair input, global int* output) {
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5523,6 +5523,12 @@
 Fn->addFnAttr("branch-target-enforcement",
   BPI.BranchTargetEnforcement ? "true" : "false");
   }
+
+  unsigned getOpenCLKernelCallingConv() const override {
+// OpenCL kernels use calling convention from the regular functions
+// as there is no special support for threads.
+return llvm::CallingConv::C;
+  }
 };
 
 class WindowsAArch64TargetCodeGenInfo : public AArch64TargetCodeGenInfo {
@@ -6328,6 +6334,12 @@
 B.addStackAlignmentAttr(8);
 Fn->addAttributes(llvm::AttributeList::FunctionIndex, B);
   }
+
+  unsigned getOpenCLKernelCallingConv() const override {
+// OpenCL kernels use calling convention from the regular functions
+// as there is no special support for threads.
+return llvm::CallingConv::C;
+  }
 };
 
 class WindowsARMTargetCodeGenInfo : public ARMTargetCodeGenInfo {


Index: clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl
===
--- clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl
+++ clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl
@@ -1,9 +1,16 @@
 // RUN: %clang_cc1 %s -cl-std=CL1.2 -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s
 // RUN: %clang_cc1 %s -cl-std=CL1.2 -emit-llvm -triple amdgcn-unknown-unknown -o - | FileCheck -check-prefixes=AMDGCN %s
-// Test that the kernels always use the SPIR calling convention
-// to have unambiguous mapping of arguments to feasibly implement
+// RUN: %clang_cc1 %s -cl-std=CL1.2 -emit-llvm -triple arm -o - | FileCheck -check-prefixes=ARM %s
+// RUN: %clang_cc1 %s -cl-std=CL1.2 -emit-llvm -triple aarch64 -o - | FileCheck -check-prefixes=AARCH64 %s
+
+// Test that the kernels use the SPIR calling convention for targets that
+// support it.
+// This facilitates unambiguous mapping of arguments to feasibly implement
 // clSetKernelArg().
 
+// ARM-NOT: spir_kernel
+// AARCH64-NOT: spir_kernel
+
 typedef struct int_single {
 int a;
 } int_single;
@@ -21,7 +28,10 @@
 long elementE;
 float elementF;
 short elementG;
+// FIXME: double type should be enabled correctly for Arm CPU.
+#if !defined(__ARM_ARCH)
 double elementH;
+#endif
 } test_struct;
 
 kernel void test_single(int_single input, global int* output) {
@@ -53,7 +63,9 @@
  output[4] = (int)input.elementE;
  output[5] = (int)input.elementF;
  output[6] = (int)input.elementG;
+#if !defined(__ARM_ARCH)
  output[7] = (int)input.elementH;
+#endif
 };
 
 void test_function(int_pair input, global int* output) {
Index: clang/lib/CodeGen/T

[PATCH] D105099: [clang-format] Add an option to put one constructor initializer per line

2021-06-29 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: djasper, klimek, krasimir, MyDeveloperDay, curdeius, 
HazardyKnusperkeks.
owenpan added a project: clang-format.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

See PR50549 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105099

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5953,6 +5953,28 @@
 
   FormatStyle OnePerLine = getLLVMStyle();
   OnePerLine.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+
+  OnePerLine.ConstructorInitializerAlwaysOnePerLine = true;
+  verifyFormat("MyClass::MyClass()\n"
+   ": a(a),\n"
+   "  b(b),\n"
+   "  c(c) {}",
+   OnePerLine);
+  verifyFormat("MyClass::MyClass()\n"
+   ": a(a), // comment\n"
+   "  b(b),\n"
+   "  c(c) {}",
+   OnePerLine);
+  verifyFormat("MyClass::MyClass(int a)\n"
+   ": b(a),  // comment\n"
+   "  c(a + 1) { // lined up\n"
+   "}",
+   OnePerLine);
+  verifyFormat("Constructor()\n"
+   ": a(b, b, b) {}",
+   OnePerLine);
+  OnePerLine.ConstructorInitializerAlwaysOnePerLine = false;
+
   OnePerLine.AllowAllParametersOfDeclarationOnNextLine = false;
   verifyFormat("SomeClass::Constructor()\n"
": a(aa),\n"
@@ -6319,6 +6341,28 @@
 
   FormatStyle OnePerLine = Style;
   OnePerLine.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+
+  OnePerLine.ConstructorInitializerAlwaysOnePerLine = true;
+  verifyFormat("MyClass::MyClass() :\n"
+   "a(a),\n"
+   "b(b),\n"
+   "c(c) {}",
+   OnePerLine);
+  verifyFormat("MyClass::MyClass() :\n"
+   "a(a), // comment\n"
+   "b(b),\n"
+   "c(c) {}",
+   OnePerLine);
+  verifyFormat("MyClass::MyClass(int a) :\n"
+   "b(a),  // comment\n"
+   "c(a + 1) { // lined up\n"
+   "}",
+   OnePerLine);
+  verifyFormat("Constructor() :\n"
+   "a(b, b, b) {}",
+   OnePerLine);
+  OnePerLine.ConstructorInitializerAlwaysOnePerLine = false;
+
   OnePerLine.AllowAllConstructorInitializersOnNextLine = false;
   verifyFormat("SomeClass::Constructor() :\n"
"a(aa),\n"
@@ -18122,6 +18166,7 @@
   CHECK_PARSE_BOOL(BreakBeforeTernaryOperators);
   CHECK_PARSE_BOOL(BreakStringLiterals);
   CHECK_PARSE_BOOL(CompactNamespaces);
+  CHECK_PARSE_BOOL(ConstructorInitializerAlwaysOnePerLine);
   CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
   CHECK_PARSE_BOOL(DeriveLineEnding);
   CHECK_PARSE_BOOL(DerivePointerAlignment);
@@ -19102,6 +19147,37 @@
 
   Style.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   Style.ConstructorInitializerIndentWidth = 4;
+
+  Style.ConstructorInitializerAlwaysOnePerLine = true;
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  Style.BraceWrapping.SplitEmptyFunction = false;
+  verifyFormat("MyClass::MyClass()\n"
+   ": a(a)\n"
+   ", b(b)\n"
+   ", c(c)\n"
+   "{}",
+   Style);
+  verifyFormat("MyClass::MyClass()\n"
+   ": a(a) // comment\n"
+   ", b(b)\n"
+   ", c(c)\n"
+   "{}",
+   Style);
+  verifyFormat("MyClass::MyClass(int a)\n"
+   ": b(a) // comment\n"
+   ", c(a + 1) // lined up\n"
+   "{}",
+   Style);
+  verifyFormat("Constructor()\n"
+   ": a(b, b, b)\n"
+   "{}",
+   Style);
+  Style.ConstructorInitializerAlwaysOnePerLine = false;
+  Style.BreakBeforeBraces = FormatStyle::BS_Attach;
+  Style.BraceWrapping.AfterFunction = false;
+  Style.BraceWrapping.SplitEmptyFunction = true;
+
   verifyFormat("SomeClass::Constructor() : () {}", Style);
   verifyFormat(
   "SomeClass::Constructor() : a(a), a(a), a(a)\n",
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3739,13 +3739,19 @@
   return Style.BreakBeforeConceptDeclarations;
 return (Style.AlwaysBreakTemplateDeclara

[PATCH] D105101: [analyzer] Make CheckerManager::hasPathSensitiveCheckers() complete again

2021-06-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, vsavchenko, Szelethus, martong.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, 
whisperity.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It turns out that the `CheckerManager::hasPathSensitiveCheckers()` missed 
checking for the `BeginFunctionCheckers`.
It seems like other callbacks are also missing:

- ObjCMessageNilCheckers
- BeginFunctionCheckers
- NewAllocatorCheckers
- PointerEscapeCheckers
- EndOfTranslationUnitCheckers

In this patch, I wanted to use a fold-expression, but until C++17 arrives we 
are left with the old-school method.

When I tried to write a unittest I observed an interesting behavior. I 
subscribed only to the BeginFunction event, it was not fired.
However, when I also defined the PreCall with an empty handler, suddenly both 
fired.
I could add this test demonstrating the issue, but I don't think it would serve 
much value in a long run. I don't expect regressions for this.

However, I think it would be great to enforce the completeness of this list in 
a runtime check.
I could not come up with a solution for this though.

PS: Thank you @szelethus for helping me debugging this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105101

Files:
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp


Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -33,21 +33,21 @@
 using namespace ento;
 
 bool CheckerManager::hasPathSensitiveCheckers() const {
-  return !StmtCheckers.empty()  ||
- !PreObjCMessageCheckers.empty()||
- !PostObjCMessageCheckers.empty()   ||
- !PreCallCheckers.empty()||
- !PostCallCheckers.empty()   ||
- !LocationCheckers.empty()  ||
- !BindCheckers.empty()  ||
- !EndAnalysisCheckers.empty()   ||
- !EndFunctionCheckers.empty()   ||
- !BranchConditionCheckers.empty()   ||
- !LiveSymbolsCheckers.empty()   ||
- !DeadSymbolsCheckers.empty()   ||
- !RegionChangesCheckers.empty() ||
- !EvalAssumeCheckers.empty()||
- !EvalCallCheckers.empty();
+  const auto IfAnyAreNonEmpty = [](const auto &... Callbacks) -> bool {
+bool Result = false;
+// FIXME: Use fold expressions in C++17.
+int Unused[]{0, (Result |= !Callbacks.empty())...};
+static_cast(Unused);
+return Result;
+  };
+  return IfAnyAreNonEmpty(
+  StmtCheckers, PreObjCMessageCheckers, ObjCMessageNilCheckers,
+  PostObjCMessageCheckers, PreCallCheckers, PostCallCheckers,
+  LocationCheckers, BindCheckers, EndAnalysisCheckers,
+  BeginFunctionCheckers, EndFunctionCheckers, BranchConditionCheckers,
+  NewAllocatorCheckers, LiveSymbolsCheckers, DeadSymbolsCheckers,
+  RegionChangesCheckers, PointerEscapeCheckers, EvalAssumeCheckers,
+  EvalCallCheckers, EndOfTranslationUnitCheckers);
 }
 
 void CheckerManager::finishedCheckerRegistration() {


Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -33,21 +33,21 @@
 using namespace ento;
 
 bool CheckerManager::hasPathSensitiveCheckers() const {
-  return !StmtCheckers.empty()  ||
- !PreObjCMessageCheckers.empty()||
- !PostObjCMessageCheckers.empty()   ||
- !PreCallCheckers.empty()||
- !PostCallCheckers.empty()   ||
- !LocationCheckers.empty()  ||
- !BindCheckers.empty()  ||
- !EndAnalysisCheckers.empty()   ||
- !EndFunctionCheckers.empty()   ||
- !BranchConditionCheckers.empty()   ||
- !LiveSymbolsCheckers.empty()   ||
- !DeadSymbolsCheckers.empty()   ||
- !RegionChangesCheckers.empty() ||
- !EvalAssumeCheckers.empty()||
- !EvalCallCheckers.empty();
+  const auto IfAnyAreNonEmpty = [](const auto &... Callbacks) -> bool {
+bool Result = false;
+// FIXME: Use fold expressions in C++17.
+int Unused[]{0, (Result |= !Callbacks.empty())...};
+static_cast(Unused);
+return Result;
+  };
+  return IfAnyAreNonEmpty(
+  StmtCheckers, PreObjCMessageCheckers, ObjCMessageNilCheckers,
+  PostObjCMessageCheckers, PreCallCheckers, PostCallCheckers,
+  LocationCheckers, BindCheckers, EndAnalysisCheckers,
+  BeginFunctionCheckers, EndFunctionCheckers, BranchConditionCheckers,
+  NewAllocatorCheckers, LiveSymbolsCheckers, DeadSymbolsCheckers,
+  Reg

[PATCH] D105052: [clang][darwin] add support for Mac Catalyst availability

2021-06-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:860
+ .Case("maccatalyst", "macCatalyst")
+ .Case("maccatalyst_app_extension", "macCatalyst App Extension")
  .Case("swift", "Swift")

Should this be `(App Extension)` instead (consistent with the other cases)?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2564
+IdentifierInfo *NewII = nullptr;
+auto MinIOSMacVersion = [](const VersionTuple &V) -> VersionTuple {
+  if (V.empty())

Do you need the trailing return type here?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2572-2573
+};
+llvm::function_ref VersionRemapper =
+MinIOSMacVersion;
+if (II->getName() == "ios")

Why do you need a `function_ref` here -- can we not just call 
`MinIOSMacVersion()` instead?


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

https://reviews.llvm.org/D105052

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


[PATCH] D105052: [clang][darwin] add support for Mac Catalyst availability

2021-06-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Btw, the CI failures look to be unrelated to the patch. (It's pretty 
unfortunate how often this is the case lately...)


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

https://reviews.llvm.org/D105052

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


[PATCH] D105112: [clang] Add -fdump-record-layouts-canonical option

2021-06-29 Thread David Tenty via Phabricator via cfe-commits
daltenty created this revision.
daltenty added reviewers: stevewan, dexonsmith.
Herald added a subscriber: dang.
daltenty requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This option implies -fdump-record-layouts but dumps record layout information 
with canonical field types, which can be more useful in certain cases when 
comparing structure layouts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105112

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Layout/dump-canonical.cpp


Index: clang/test/Layout/dump-canonical.cpp
===
--- /dev/null
+++ clang/test/Layout/dump-canonical.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-canonical %s | 
FileCheck %s -check-prefix CANONICAL
+
+typedef long foo_t;
+
+struct a {
+  foo_t x;
+} b;
+
+// CHECK:  0 | foo_t
+// CANONICAL:  0 | long
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -3577,7 +3577,10 @@
 } else {
   PrintOffset(OS, FieldOffset, IndentLevel);
 }
-OS << Field.getType().getAsString() << ' ' << Field << '\n';
+const QualType &FieldType = C.getLangOpts().DumpRecordLayoutsCanonical
+? Field.getType().getCanonicalType()
+: Field.getType();
+OS << FieldType.getAsString() << ' ' << Field << '\n';
   }
 
   // Dump virtual bases.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5381,13 +5381,16 @@
 def fdump_record_layouts_simple : Flag<["-"], "fdump-record-layouts-simple">,
   HelpText<"Dump record layout information in a simple form used for testing">,
   MarshallingInfoFlag>;
+def fdump_record_layouts_canonical : Flag<["-"], 
"fdump-record-layouts-canonical">,
+  HelpText<"Dump record layout information with canonical field types">,
+  MarshallingInfoFlag>;
 def fdump_record_layouts_complete : Flag<["-"], 
"fdump-record-layouts-complete">,
   HelpText<"Dump record layout information for all complete types">,
   MarshallingInfoFlag>;
 def fdump_record_layouts : Flag<["-"], "fdump-record-layouts">,
   HelpText<"Dump record layout information">,
   MarshallingInfoFlag>,
-  ImpliedByAnyOf<[fdump_record_layouts_simple.KeyPath, 
fdump_record_layouts_complete.KeyPath]>;
+  ImpliedByAnyOf<[fdump_record_layouts_simple.KeyPath, 
fdump_record_layouts_complete.KeyPath, fdump_record_layouts_canonical.KeyPath]>;
 def fix_what_you_can : Flag<["-"], "fix-what-you-can">,
   HelpText<"Apply fix-it advice even in the presence of unfixable errors">,
   MarshallingInfoFlag>;
Index: clang/include/clang/Basic/LangOptions.def
===
--- clang/include/clang/Basic/LangOptions.def
+++ clang/include/clang/Basic/LangOptions.def
@@ -265,6 +265,7 @@
 BENIGN_LANGOPT(ElideConstructors , 1, 1, "C++ copy constructor elision")
 BENIGN_LANGOPT(DumpRecordLayouts , 1, 0, "dumping the layout of IRgen'd 
records")
 BENIGN_LANGOPT(DumpRecordLayoutsSimple , 1, 0, "dumping the layout of IRgen'd 
records in a simple form")
+BENIGN_LANGOPT(DumpRecordLayoutsCanonical , 1, 0, "dumping the AST layout of 
records using canonical field types")
 BENIGN_LANGOPT(DumpRecordLayoutsComplete , 1, 0, "dumping the AST layout of 
all complete records")
 BENIGN_LANGOPT(DumpVTableLayouts , 1, 0, "dumping the layouts of emitted 
vtables")
 LANGOPT(NoConstantCFStrings , 1, 0, "no constant CoreFoundation strings")


Index: clang/test/Layout/dump-canonical.cpp
===
--- /dev/null
+++ clang/test/Layout/dump-canonical.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm-only -fdump-record-layouts-canonical %s | FileCheck %s -check-prefix CANONICAL
+
+typedef long foo_t;
+
+struct a {
+  foo_t x;
+} b;
+
+// CHECK:  0 | foo_t
+// CANONICAL:  0 | long
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -3577,7 +3577,10 @@
 } else {
   PrintOffset(OS, FieldOffset, IndentLevel);
 }
-OS << Field.getType().getAsString() << ' ' << Field << '\n';
+const QualType &FieldType = C.getLangOpts().DumpRecordLayoutsCanonical
+? Field.getType().getCanonicalType()
+  

[PATCH] D20689: [clang-tidy] Add 'readability-suspicious-call-argument' check

2021-06-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I think this looks good to me. @alexfh, you had raised questions about this 
meeting the quality bar. I think those concerns are valid in the abstract 
(swapped argument checking requires heuristics), but I'd argue that most 
existing code bases that actually have swapped args finds those bugs in 
production, so the rate of true positives on existing code is often small. I 
see the value from this check coming from checking new code as it's written, as 
part of a CI pipeline for instance. With that in mind, do you still have 
concerns about this check?




Comment at: 
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp:801
+  }
+  llvm_unreachable("Unhandled heuristic kind");
+}

whisperity wrote:
> aaron.ballman wrote:
> > This looks pretty reachable to me in the case where there's no bound.
> I'm not sure if that is the case. I added the `llvm_unreachable` so we don't 
> get a warning about the function not having a return value on every code 
> path. The `switch` covers **all** potential heuristics that are in the check 
> //right now//, but if we add a new heuristic (to the enum) and forget to 
> write it in, we will get a `-Wswitch` warning here. A `default` case doesn't 
> apply here, further developers should be encouraged to wire new heuristics in 
> properly.
Oops, ignore my think-o! I somehow read the switch as switching over 
`Threshold` and not `H` and confused myself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D20689

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


[PATCH] D105101: [analyzer] Make CheckerManager::hasPathSensitiveCheckers() complete again

2021-06-29 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko accepted this revision.
vsavchenko added a comment.
This revision is now accepted and ready to land.

Great!  Thanks for the detailed explanation in your Summary.
I agree that there should be a runtime check, but it doesn't seem viable as 
long as `Checker.h` is organized the way it is organized now.




Comment at: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:40
+int Unused[]{0, (Result |= !Callbacks.empty())...};
+static_cast(Unused);
+return Result;

Maybe we can use `LLVM_ATTRIBUTE_UNUSED` instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105101

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp reopened this revision.
stefanp added a comment.
This revision is now accepted and ready to land.

I'm sorry I missed the asserts requirement.
I will recommit this patch after I add `REQUIRES: asserts`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[PATCH] D105092: [PoC][RISCV] Add the tail policy argument to builtins/intrinsics.

2021-06-29 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:1148
+if (HasPolicy) {
+  ProtoMaskSeq.push_back("z");
+}

maybe the policy argument should be a constant value ("Kz")?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105092

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


[clang] 3dae019 - [analyzer] Make CheckerManager::hasPathSensitiveCheckers() complete again

2021-06-29 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2021-06-29T16:35:07+02:00
New Revision: 3dae01911b6902f00e80eb7ebdc2f55bb28f173e

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

LOG: [analyzer] Make CheckerManager::hasPathSensitiveCheckers() complete again

It turns out that the CheckerManager::hasPathSensitiveCheckers() missed
checking for the BeginFunctionCheckers.
It seems like other callbacks are also missing:
 - ObjCMessageNilCheckers
 - BeginFunctionCheckers
 - NewAllocatorCheckers
 - PointerEscapeCheckers
 - EndOfTranslationUnitCheckers

In this patch, I wanted to use a fold-expression, but until C++17
arrives we are left with the old-school method.

When I tried to write a unittest I observed an interesting behavior. I
subscribed only to the BeginFunction event, it was not fired.
However, when I also defined the PreCall with an empty handler, suddenly
both fired.
I could add this test demonstrating the issue, but I don't think it
would serve much value in a long run. I don't expect regressions for
this.

However, I think it would be great to enforce the completeness of this
list in a runtime check.
I could not come up with a solution for this though.

PS: Thank you @Szelethus for helping me debugging this.

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

Reviewed by: vsavchenko

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/CheckerManager.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp 
b/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
index 86cecf6524f0..e09399a83589 100644
--- a/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -33,21 +33,20 @@ using namespace clang;
 using namespace ento;
 
 bool CheckerManager::hasPathSensitiveCheckers() const {
-  return !StmtCheckers.empty()  ||
- !PreObjCMessageCheckers.empty()||
- !PostObjCMessageCheckers.empty()   ||
- !PreCallCheckers.empty()||
- !PostCallCheckers.empty()   ||
- !LocationCheckers.empty()  ||
- !BindCheckers.empty()  ||
- !EndAnalysisCheckers.empty()   ||
- !EndFunctionCheckers.empty()   ||
- !BranchConditionCheckers.empty()   ||
- !LiveSymbolsCheckers.empty()   ||
- !DeadSymbolsCheckers.empty()   ||
- !RegionChangesCheckers.empty() ||
- !EvalAssumeCheckers.empty()||
- !EvalCallCheckers.empty();
+  const auto IfAnyAreNonEmpty = [](const auto &... Callbacks) -> bool {
+bool Result = false;
+// FIXME: Use fold expressions in C++17.
+LLVM_ATTRIBUTE_UNUSED int Unused[]{0, (Result |= !Callbacks.empty())...};
+return Result;
+  };
+  return IfAnyAreNonEmpty(
+  StmtCheckers, PreObjCMessageCheckers, ObjCMessageNilCheckers,
+  PostObjCMessageCheckers, PreCallCheckers, PostCallCheckers,
+  LocationCheckers, BindCheckers, EndAnalysisCheckers,
+  BeginFunctionCheckers, EndFunctionCheckers, BranchConditionCheckers,
+  NewAllocatorCheckers, LiveSymbolsCheckers, DeadSymbolsCheckers,
+  RegionChangesCheckers, PointerEscapeCheckers, EvalAssumeCheckers,
+  EvalCallCheckers, EndOfTranslationUnitCheckers);
 }
 
 void CheckerManager::finishedCheckerRegistration() {



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


[PATCH] D105101: [analyzer] Make CheckerManager::hasPathSensitiveCheckers() complete again

2021-06-29 Thread Balázs Benics 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 rG3dae01911b69: [analyzer] Make 
CheckerManager::hasPathSensitiveCheckers() complete again (authored by 
steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D105101?vs=355179&id=355227#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105101

Files:
  clang/lib/StaticAnalyzer/Core/CheckerManager.cpp


Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -33,21 +33,20 @@
 using namespace ento;
 
 bool CheckerManager::hasPathSensitiveCheckers() const {
-  return !StmtCheckers.empty()  ||
- !PreObjCMessageCheckers.empty()||
- !PostObjCMessageCheckers.empty()   ||
- !PreCallCheckers.empty()||
- !PostCallCheckers.empty()   ||
- !LocationCheckers.empty()  ||
- !BindCheckers.empty()  ||
- !EndAnalysisCheckers.empty()   ||
- !EndFunctionCheckers.empty()   ||
- !BranchConditionCheckers.empty()   ||
- !LiveSymbolsCheckers.empty()   ||
- !DeadSymbolsCheckers.empty()   ||
- !RegionChangesCheckers.empty() ||
- !EvalAssumeCheckers.empty()||
- !EvalCallCheckers.empty();
+  const auto IfAnyAreNonEmpty = [](const auto &... Callbacks) -> bool {
+bool Result = false;
+// FIXME: Use fold expressions in C++17.
+LLVM_ATTRIBUTE_UNUSED int Unused[]{0, (Result |= !Callbacks.empty())...};
+return Result;
+  };
+  return IfAnyAreNonEmpty(
+  StmtCheckers, PreObjCMessageCheckers, ObjCMessageNilCheckers,
+  PostObjCMessageCheckers, PreCallCheckers, PostCallCheckers,
+  LocationCheckers, BindCheckers, EndAnalysisCheckers,
+  BeginFunctionCheckers, EndFunctionCheckers, BranchConditionCheckers,
+  NewAllocatorCheckers, LiveSymbolsCheckers, DeadSymbolsCheckers,
+  RegionChangesCheckers, PointerEscapeCheckers, EvalAssumeCheckers,
+  EvalCallCheckers, EndOfTranslationUnitCheckers);
 }
 
 void CheckerManager::finishedCheckerRegistration() {


Index: clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -33,21 +33,20 @@
 using namespace ento;
 
 bool CheckerManager::hasPathSensitiveCheckers() const {
-  return !StmtCheckers.empty()  ||
- !PreObjCMessageCheckers.empty()||
- !PostObjCMessageCheckers.empty()   ||
- !PreCallCheckers.empty()||
- !PostCallCheckers.empty()   ||
- !LocationCheckers.empty()  ||
- !BindCheckers.empty()  ||
- !EndAnalysisCheckers.empty()   ||
- !EndFunctionCheckers.empty()   ||
- !BranchConditionCheckers.empty()   ||
- !LiveSymbolsCheckers.empty()   ||
- !DeadSymbolsCheckers.empty()   ||
- !RegionChangesCheckers.empty() ||
- !EvalAssumeCheckers.empty()||
- !EvalCallCheckers.empty();
+  const auto IfAnyAreNonEmpty = [](const auto &... Callbacks) -> bool {
+bool Result = false;
+// FIXME: Use fold expressions in C++17.
+LLVM_ATTRIBUTE_UNUSED int Unused[]{0, (Result |= !Callbacks.empty())...};
+return Result;
+  };
+  return IfAnyAreNonEmpty(
+  StmtCheckers, PreObjCMessageCheckers, ObjCMessageNilCheckers,
+  PostObjCMessageCheckers, PreCallCheckers, PostCallCheckers,
+  LocationCheckers, BindCheckers, EndAnalysisCheckers,
+  BeginFunctionCheckers, EndFunctionCheckers, BranchConditionCheckers,
+  NewAllocatorCheckers, LiveSymbolsCheckers, DeadSymbolsCheckers,
+  RegionChangesCheckers, PointerEscapeCheckers, EvalAssumeCheckers,
+  EvalCallCheckers, EndOfTranslationUnitCheckers);
 }
 
 void CheckerManager::finishedCheckerRegistration() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added a comment.

In D103615#2847047 , @stefanp wrote:

> I'm sorry I missed the asserts requirement.
> I will recommit this patch after I add `REQUIRES: asserts`.

Instead of disabling the tests for non-assert builds, can we just remove the 
`entry:` checks at the beginning of each function? The rest of the IR checks 
should pass since they use a regexp so they should match for either named or 
unnamed instructions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added a comment.

In D103615#2846245 , @dblaikie wrote:

> As mentioned in the reverting commit - these tests fail in non-asserts 
> builds, because they assume named IR instructions (like the named entry BB 
> label), which aren't provided on a non-asserts build (there's a flag to turn 
> them on - but that's probably not the right fix - making the test resilient 
> to non-asserts IR is probably the right fix).
>
> Leaving non-asserts builds broken for 12 hours (maybe I'm the first one to 
> come across/report it - but I'd expect there are some buildbots that would 
> fail, etc) is quite a while - best to be avoided when possible.

This is a bit off topic, but I'm just curious about clang's rationale for 
producing different IR depending on whether asserts are on/off? Seems strange 
and undesirable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[PATCH] D105120: [clang] Fix UB when string.front() is used for the empty string

2021-06-29 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: kadircet, lh123, sammccall, hokein, 
ilya-biryukov.
DmitryPolukhin added projects: clang, clang-tools-extra.
Herald added a subscriber: usaxena95.
DmitryPolukhin requested review of this revision.

Compilation database might have empty string as a command line argument.
But ExpandResponseFilesDatabase::expand doesn't expect this and assumes
that string.front() can be used for any argument. It is undefined behaviour if
string is empty. With debug build mode it causes crash in clangd.

Test Plan: check-clang


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105120

Files:
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105120: [clang] Fix UB when string.front() is used for the empty string

2021-06-29 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 355233.
DmitryPolukhin added a comment.

Replace tab with spaces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105120

Files:
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104952: [hexagon] Add {hvx,}hexagon_{protos,circ_brev...}

2021-06-29 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 355234.
bcain added a comment.

Removed some unavailable instructions.

Added include order fix in hexagon_circ_brev


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104952

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/hexagon_circ_brev_intrinsics.h
  clang/lib/Headers/hexagon_protos.h
  clang/lib/Headers/hexagon_types.h
  clang/lib/Headers/hvx_hexagon_protos.h
  clang/test/Headers/hexagon-audio-headers.c
  clang/test/Headers/hexagon-headers.c
  clang/test/Headers/hexagon-hvx-headers.c

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


[clang] c33ebad - Print default template argument if manually specified in typedef declaration.

2021-06-29 Thread Vassil Vassilev via cfe-commits

Author: Pratyush Das
Date: 2021-06-29T14:57:26Z
New Revision: c33ebad73516ffcf7b00821a430aa6a0199941f0

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

LOG: Print default template argument if manually specified in typedef 
declaration.

If a default template type argument is manually specified to be of the default
type, then it is committed when printing the template.

Differential revision: https://reviews.llvm.org/D103040

Added: 


Modified: 
clang/lib/AST/TypePrinter.cpp
clang/test/SemaTemplate/class-template-id.cpp
clang/test/SemaTemplate/default-arguments-ast-print.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 720cab917a22..47e48506dc96 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1449,8 +1449,7 @@ void TypePrinter::printTemplateId(const 
TemplateSpecializationType *T,
 T->getTemplateName().print(OS, Policy);
   }
 
-  const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : 
nullptr;
-  printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
+  printTemplateArgumentList(OS, T->template_arguments(), Policy);
   spaceBeforePlaceHolder(OS);
 }
 

diff  --git a/clang/test/SemaTemplate/class-template-id.cpp 
b/clang/test/SemaTemplate/class-template-id.cpp
index b32a03e478d9..50cb3ef59ea4 100644
--- a/clang/test/SemaTemplate/class-template-id.cpp
+++ b/clang/test/SemaTemplate/class-template-id.cpp
@@ -9,9 +9,9 @@ A *foo(A *ptr, A const *ptr2, A *ptr3) {
   if (ptr)
 return ptr; // okay
   else if (ptr2)
-return ptr2; // expected-error{{cannot initialize return object of type 
'A *' with an lvalue of type 'const A *'}}
+return ptr2; // expected-error{{cannot initialize return object of type 
'A *' (aka 'A *') with an lvalue of type 'const A 
*'}}
   else {
-return ptr3; // expected-error{{cannot initialize return object of type 
'A *' with an lvalue of type 'A *'}}
+return ptr3; // expected-error{{cannot initialize return object of type 
'A *' (aka 'A *') with an lvalue of type 'A *'}}
   }
 }
 

diff  --git a/clang/test/SemaTemplate/default-arguments-ast-print.cpp 
b/clang/test/SemaTemplate/default-arguments-ast-print.cpp
index 9ed17a79de0d..4623f0a8cdf4 100644
--- a/clang/test/SemaTemplate/default-arguments-ast-print.cpp
+++ b/clang/test/SemaTemplate/default-arguments-ast-print.cpp
@@ -10,3 +10,15 @@ int Foo::method1() {
   // CHECK: int Foo::method1()
   return 10;
 }
+
+int test_typedef() {
+  typedef Foo TypedefArg;
+  // CHECK: typedef Foo TypedefArg;
+  return 10;
+}
+
+int test_typedef2() {
+  typedef Foo TypedefArg;
+  // CHECK: typedef Foo TypedefArg;
+  return 10;
+}



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


[PATCH] D103040: Print default template argument if manually specified in typedef declaration.

2021-06-29 Thread Vassil Vassilev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc33ebad73516: Print default template argument if manually 
specified in typedef declaration. (authored by reikdas, committed by 
v.g.vassilev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103040

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/SemaTemplate/class-template-id.cpp
  clang/test/SemaTemplate/default-arguments-ast-print.cpp


Index: clang/test/SemaTemplate/default-arguments-ast-print.cpp
===
--- clang/test/SemaTemplate/default-arguments-ast-print.cpp
+++ clang/test/SemaTemplate/default-arguments-ast-print.cpp
@@ -10,3 +10,15 @@
   // CHECK: int Foo::method1()
   return 10;
 }
+
+int test_typedef() {
+  typedef Foo TypedefArg;
+  // CHECK: typedef Foo TypedefArg;
+  return 10;
+}
+
+int test_typedef2() {
+  typedef Foo TypedefArg;
+  // CHECK: typedef Foo TypedefArg;
+  return 10;
+}
Index: clang/test/SemaTemplate/class-template-id.cpp
===
--- clang/test/SemaTemplate/class-template-id.cpp
+++ clang/test/SemaTemplate/class-template-id.cpp
@@ -9,9 +9,9 @@
   if (ptr)
 return ptr; // okay
   else if (ptr2)
-return ptr2; // expected-error{{cannot initialize return object of type 
'A *' with an lvalue of type 'const A *'}}
+return ptr2; // expected-error{{cannot initialize return object of type 
'A *' (aka 'A *') with an lvalue of type 'const A 
*'}}
   else {
-return ptr3; // expected-error{{cannot initialize return object of type 
'A *' with an lvalue of type 'A *'}}
+return ptr3; // expected-error{{cannot initialize return object of type 
'A *' (aka 'A *') with an lvalue of type 'A *'}}
   }
 }
 
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1449,8 +1449,7 @@
 T->getTemplateName().print(OS, Policy);
   }
 
-  const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : 
nullptr;
-  printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
+  printTemplateArgumentList(OS, T->template_arguments(), Policy);
   spaceBeforePlaceHolder(OS);
 }
 


Index: clang/test/SemaTemplate/default-arguments-ast-print.cpp
===
--- clang/test/SemaTemplate/default-arguments-ast-print.cpp
+++ clang/test/SemaTemplate/default-arguments-ast-print.cpp
@@ -10,3 +10,15 @@
   // CHECK: int Foo::method1()
   return 10;
 }
+
+int test_typedef() {
+  typedef Foo TypedefArg;
+  // CHECK: typedef Foo TypedefArg;
+  return 10;
+}
+
+int test_typedef2() {
+  typedef Foo TypedefArg;
+  // CHECK: typedef Foo TypedefArg;
+  return 10;
+}
Index: clang/test/SemaTemplate/class-template-id.cpp
===
--- clang/test/SemaTemplate/class-template-id.cpp
+++ clang/test/SemaTemplate/class-template-id.cpp
@@ -9,9 +9,9 @@
   if (ptr)
 return ptr; // okay
   else if (ptr2)
-return ptr2; // expected-error{{cannot initialize return object of type 'A *' with an lvalue of type 'const A *'}}
+return ptr2; // expected-error{{cannot initialize return object of type 'A *' (aka 'A *') with an lvalue of type 'const A *'}}
   else {
-return ptr3; // expected-error{{cannot initialize return object of type 'A *' with an lvalue of type 'A *'}}
+return ptr3; // expected-error{{cannot initialize return object of type 'A *' (aka 'A *') with an lvalue of type 'A *'}}
   }
 }
 
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1449,8 +1449,7 @@
 T->getTemplateName().print(OS, Policy);
   }
 
-  const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : nullptr;
-  printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
+  printTemplateArgumentList(OS, T->template_arguments(), Policy);
   spaceBeforePlaceHolder(OS);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105017: [analyzer] LValueToRValueBitCasts should evaluate to an r-value

2021-06-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 355245.
steakhal marked an inline comment as done.
steakhal added a comment.

Evaluate `LValueToRValueBitCast`s the same way as we evaluate `LValueToRValue` 
casts.
Extended the tests accordingly.

Thanks for the hint @NoQ!
It looks much better now.


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

https://reviews.llvm.org/D105017

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/builtin_bitcast.cpp


Index: clang/test/Analysis/builtin_bitcast.cpp
===
--- /dev/null
+++ clang/test/Analysis/builtin_bitcast.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection
+
+template  void clang_analyzer_dump(T);
+
+__attribute__((always_inline)) static inline constexpr unsigned int 
_castf32_u32(float __A) {
+  return __builtin_bit_cast(unsigned int, __A); // no-warning
+}
+
+void test(int i) {
+  _castf32_u32(42);
+
+  float f = 42;
+
+  // Loading from a floating point value results in unknown,
+  // which later materializes as a conjured value.
+  auto g = __builtin_bit_cast(unsigned int, f);
+  clang_analyzer_dump(g);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g2 = __builtin_bit_cast(unsigned int, 42.0f);
+  clang_analyzer_dump(g2);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g3 = __builtin_bit_cast(unsigned int, i);
+  clang_analyzer_dump(g3);
+  // expected-warning-re@-1 ^reg_\$[0-9]+
+
+  auto g4 = __builtin_bit_cast(unsigned long, &i);
+  clang_analyzer_dump(g4);
+  // expected-warning@-1 {{&i [as 64 bit integer]}}
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -304,7 +304,8 @@
   ExplodedNodeSet dstPreStmt;
   getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
 
-  if (CastE->getCastKind() == CK_LValueToRValue) {
+  if (CastE->getCastKind() == CK_LValueToRValue ||
+  CastE->getCastKind() == CK_LValueToRValueBitCast) {
 for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = 
dstPreStmt.end();
  I!=E; ++I) {
   ExplodedNode *subExprNode = *I;
@@ -332,6 +333,7 @@
 
 switch (CastE->getCastKind()) {
   case CK_LValueToRValue:
+  case CK_LValueToRValueBitCast:
 llvm_unreachable("LValueToRValue casts handled earlier.");
   case CK_ToVoid:
 continue;
@@ -380,7 +382,6 @@
   case CK_Dependent:
   case CK_ArrayToPointerDecay:
   case CK_BitCast:
-  case CK_LValueToRValueBitCast:
   case CK_AddressSpaceConversion:
   case CK_BooleanToSignedIntegral:
   case CK_IntegralToPointer:


Index: clang/test/Analysis/builtin_bitcast.cpp
===
--- /dev/null
+++ clang/test/Analysis/builtin_bitcast.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -verify %s \
+// RUN:   -analyzer-checker=core,debug.ExprInspection
+
+template  void clang_analyzer_dump(T);
+
+__attribute__((always_inline)) static inline constexpr unsigned int _castf32_u32(float __A) {
+  return __builtin_bit_cast(unsigned int, __A); // no-warning
+}
+
+void test(int i) {
+  _castf32_u32(42);
+
+  float f = 42;
+
+  // Loading from a floating point value results in unknown,
+  // which later materializes as a conjured value.
+  auto g = __builtin_bit_cast(unsigned int, f);
+  clang_analyzer_dump(g);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g2 = __builtin_bit_cast(unsigned int, 42.0f);
+  clang_analyzer_dump(g2);
+  // expected-warning-re@-1 ^conj_\$[0-9]+{unsigned int,
+
+  auto g3 = __builtin_bit_cast(unsigned int, i);
+  clang_analyzer_dump(g3);
+  // expected-warning-re@-1 ^reg_\$[0-9]+
+
+  auto g4 = __builtin_bit_cast(unsigned long, &i);
+  clang_analyzer_dump(g4);
+  // expected-warning@-1 {{&i [as 64 bit integer]}}
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -304,7 +304,8 @@
   ExplodedNodeSet dstPreStmt;
   getCheckerManager().runCheckersForPreStmt(dstPreStmt, Pred, CastE, *this);
 
-  if (CastE->getCastKind() == CK_LValueToRValue) {
+  if (CastE->getCastKind() == CK_LValueToRValue ||
+  CastE->getCastKind() == CK_LValueToRValueBitCast) {
 for (ExplodedNodeSet::iterator I = dstPreStmt.begin(), E = dstPreStmt.end();
  I!=E; ++I) {
   ExplodedNode *subExprNode = *I;
@@ -332,6 +333,7 @@
 
 switch (CastE->getCastKind()) {
   case CK_LValueToRValue:
+  case CK_LValueToRValueBitCast:
 llvm_unreachable("LValueToRValue

[PATCH] D105017: [analyzer] LValueToRValueBitCasts should evaluate to an r-value

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



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:543
   case CK_VectorSplat: {
 state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
 continue;

NoQ wrote:
> You didn't start it but that's, ugh, not a great name for the function to 
> handle the new cast.
> 
> I wouldn't mind eliminating the function entirely and inlining the 
> implementation as it actually makes the code easier to read, for once.
I'm going to do that in an NFC follow-up patch.


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

https://reviews.llvm.org/D105017

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


[PATCH] D105017: [analyzer] LValueToRValueBitCasts should evaluate to an r-value

2021-06-29 Thread Balázs Benics via Phabricator via cfe-commits
steakhal marked an inline comment as done.
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:543
   case CK_VectorSplat: {
 state = handleLVectorSplat(state, LCtx, CastE, Bldr, Pred);
 continue;

steakhal wrote:
> NoQ wrote:
> > You didn't start it but that's, ugh, not a great name for the function to 
> > handle the new cast.
> > 
> > I wouldn't mind eliminating the function entirely and inlining the 
> > implementation as it actually makes the code easier to read, for once.
> I'm going to do that in an NFC follow-up patch.
D105125


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

https://reviews.llvm.org/D105017

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


[PATCH] D105099: [clang-format] Add an option to put one constructor initializer per line

2021-06-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Seem similar to D90232: [clang-format] Formatting constructor initializer lists 
by putting them always on different lines (update to D14484) 
 which seems to have got stalled

I sort of feel I prefer the design where we have an enum rather than 
introducing a separate option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105099

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


[PATCH] D105099: [clang-format] Add an option to put one constructor initializer per line

2021-06-29 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

We already have

`AllowAllConstructorInitializersOnNextLine` and 
`ConstructorInitializerAllOnOneLineOrOnePerLine`

Sort of feels like we need to combine them with this,

I should also say I'd quite like this functionality, its just how do we deliver 
it via the options that I think we might want to think about, as I sort of feel 
the 3 options (if we introduced another) are competing with each other.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105099

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


[PATCH] D104617: [clangd] Type hints for structured bindings

2021-06-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Cool!




Comment at: clang-tools-extra/clangd/InlayHints.cpp:40
+// types would be "tuple_element::type".
+TypeHintPolicy.PrintCanonicalTypes = true;
   }

nridge wrote:
> While playing around with this, it did occur to me that in some cases it's 
> more helpful to print sugared types than canonical types, for example in a 
> case like this:
> 
> ```
> template 
> struct SomeLongType {};
> 
> using ShortType = SomeLongType;
> 
> ShortType func();
> 
> auto x = func();  // would prefer "ShortType" as hint
> ```
> 
> However, it turns out that `AutoType` doesn't retain the sugared type to 
> begin with (there's a FIXME about that 
> [here](https://searchfox.org/llvm/rev/e497b12a69604b6d691312a30f6b86da4f18f7f8/clang/include/clang/AST/Type.h#4953)),
>  so setting `PrintCanonicalTypes=true` doesn't actually regress cases like 
> this (they were already printing the canonical type).
This makes sense - can you add a comment with a short version of this?
// Often we'd prefer sugar types for `auto`, but the AST doesn't retain them 
anyway.



Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:466
+  // Hint individual bindings, not the aggregate.
   assertTypeHints(R"cpp(
+// 1. Struct with public fields.

since we have the handy assertTypeHints function, can we split this into 
several separate tests?
(Or one table-driven test so at least the test code + corresponding assertions 
are next to each other)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104617

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


[PATCH] D104056: [clangd][nfc] Show more information in logs when compiler instance prepare fails

2021-06-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM

Sorry about the delay - we got sidetracked into some ideas about whether these 
errors should actually be surfaced to the user as diagnostics instead. But that 
shouldn't block this patch.




Comment at: clang-tools-extra/clangd/ParsedAST.cpp:296
+elog("Failed to prepare a compiler instance: {0}",
+ ASTDiags.getNumErrors()
+ ? static_cast(ASTDiags.take().back()).Message

there's a bunch of logic that determines which diags we actually end up storing.

I'd suggest always calling take() and testing whether the result is empty, 
rather than using getNumErrors() which bypasses all our logic.

Luckily, we do (always?) end up storing the relevant diags here, assuming 
they're errors without a source location attached.
However I don't think we should hard-code that assumption here.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104056

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


[PATCH] D104052: [clang] Fix CallExpr dependence bit may not respecting all its arguments.

2021-06-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Ping - curious about your thoughts here!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104052

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


[PATCH] D105127: Implement P1401R5

2021-06-29 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Support Narrowing conversions to bool in if constexpr condition
under C++23 language mode.

Only if constexpr is implemented as the behavior of static_assert
is already conforming.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105127

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1296,7 +1296,7 @@
 
   Narrowing contextual conversions to bool
   https://wg21.link/P1401R5";>P1401R5
-  No
+  Clang 13
 
 
   Trimming whitespaces before line splicing
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
===
--- clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++1z -verify %s
 // RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
+// RUN: %clang_cc1 -std=c++2b -verify %s
+// RUN: %clang_cc1 -std=c++2b -verify %s -DUNDEFINED
 
 #ifdef UNDEFINED
 // "used but not defined" errors don't get produced if we have more interesting
@@ -40,17 +42,41 @@
 namespace ccce {
   void f() {
 if (5) {}
-if constexpr (5) {} // expected-error {{cannot be narrowed}}
+if constexpr (5) {
+}
   }
   template void g() {
-if constexpr (N) {} // expected-error {{cannot be narrowed}}
+if constexpr (N) {
+}
   }
-  template void g<5>(); // expected-note {{instantiation of}}
+  template void g<5>();
   void h() {
-if constexpr (4.3) {} // expected-error{{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (4.3) {
+}
 constexpr void *p = nullptr;
-if constexpr (p) {} // expected-error{{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (p) {
+}
   }
+
+  void not_constant(int b) {
+if constexpr (bool(b)) {
+} // expected-error {{constexpr if condition is not a constant expression}}
+if constexpr (b) {
+} // expected-error {{constexpr if condition is not a constant expression}}
+  }
+
+#if __cplusplus <= 202002
+  // expected-error@45 {{cannot be narrowed}}
+  // expected-error@48 {{cannot be narrowed}}
+  // expected-note@50  {{instantiation of}}
+  // expected-error@52 {{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+  // expected-error@54 {{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+#else
+  // expected-warning@52 {{implicit conversion from 'double' to 'bool' changes value}}
+#endif
+  // expected-note@58 {{cannot be used in a constant expression}}
+  // expected-note@59 {{cannot be used in a constant expression}}
+  // expected-note@57 2{{declared here}}
 }
 
 namespace generic_lambda {
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3920,11 +3920,21 @@
   // expression, implicitly converted to bool.
   //
   // FIXME: Return this value to the caller so they don't need to recompute it.
-  llvm::APSInt Value(/*BitWidth*/1);
-  return (IsConstexpr && !CondExpr->isValueDependent())
- ? CheckConvertedConstantExpression(CondExpr, Context.BoolTy, Value,
-CCEK_ConstexprIf)
- : PerformContextuallyConvertToBool(CondExpr);
+
+  if ((IsConstexpr && !LangOpts.CPlusPlus2b) && !CondExpr->isValueDependent()) {
+llvm::APSInt Value(/*BitWidth*/ 1);
+return CheckConvertedConstantExpression(CondExpr, Context.BoolTy, Value,
+CCEK_ConstexprIf);
+  }
+  ExprResult E = PerformContextuallyConvertToBool(CondExpr);
+  if (!IsConstexpr || CondExpr->isValueDependent())
+return E;
+
+  llvm::APSInt Cond;
+  E = VerifyIntegerConstantExpression(
+  E.get(), &Cond,
+  diag::err_constexpr_if_condition_expression_is_not_constant);
+  return E;
 }
 
 /// Helper function to determine whether this is the (deprecated) C++
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1487,6 +1487,8 @@
 // C++ declarations
 def err_static_assert_expression_is_not_constant : Error<
   "static_assert expression is not an integral constant expression">;
+def err_constexpr_if_condition_expression_is_not_constant : Error<
+  "constexpr if 

[PATCH] D104601: [Preprocessor] Implement -fnormalize-whitespace.

2021-06-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I'm still mulling over the feature, but I have some nits with the patch while I 
was exploring it. I share the concerns raised by @dblaikie and would add that 
it's very common for implementers to ask developers to run their code through 
`-E` mode to submit preprocessed output in order to reproduce a customer issue 
with the compiler, and I worry that uses of this flag will have unintended 
consequences in that scenario. However, I don't yet have a concrete "this code 
demonstrates the problem I'm worried about" example to discuss, so this worry 
may be unfounded. The "very long line" example mentioned by @dblaikie is sort 
of along these lines (sorry for the bad pun).




Comment at: clang/docs/ClangCommandLineReference.rst:2480
+
+Ignore the whitespace from the input file when emitting preprocessor output. 
It will only contain whitespace when necessary, e.g. to keep two minus signs 
from merging into to an increment operator. Useful with the -P option to 
normlize whitespace such that two files with only formatted changes are equal.
+

You might want to wrap this to 80-col limits.



Comment at: clang/lib/Frontend/PrintPreprocessedOutput.cpp:135
+  /// Ensure that the output stream position is at the beginning of a new line
+  /// and inserts one if it does not.It is intended to ensure that directives
+  /// inserted by the directives not from the input source (such as #line) are





Comment at: clang/lib/Frontend/PrintPreprocessedOutput.cpp:137
+  /// inserted by the directives not from the input source (such as #line) are
+  /// in the first column. To insert newlines the represent the input, use
+  /// MoveToLine(/*...*/, /*RequireStartOfLine=*/true).





Comment at: clang/lib/Frontend/PrintPreprocessedOutput.cpp:174
+  ///on being on the same line, such as directives.
+  void HandleWhitespaceBeforeTok(Token &Tok, bool RequireSpace,
+ bool RequireSameLine);

Can `Tok` be `const Token &` instead?



Comment at: clang/lib/Frontend/PrintPreprocessedOutput.cpp:181
+  /// In these cases the next output will be the first column on the line and
+  /// make it possible to insert indention. The newline is was inserted
+  /// implicitly when at the beginning of the file.





Comment at: clang/lib/Frontend/PrintPreprocessedOutput.cpp:635
+ bool RequireSameLine) 
{
+  // These tokens are not expand to anything and don't need whitespace before
+  // them.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

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


[PATCH] D95807: [Coroutines] Add the newly generated SCCs back to the CGSCC work queue after CoroSplit actually happened

2021-06-29 Thread Xun Li via Phabricator via cfe-commits
lxfind added a comment.

In D95807#2846358 , @ChuanqiXu wrote:

>> note that we don't really need to run Inliner again on the ramp function 
>> after split
>
> This isn't accurate. The inline may run again for ramp function after split 
> and it's required by coro elide.

If there is an inlining opportunity, it should have happened pre-split, right? 
Is there any reason it didn't happen pre-split but only post-split?

> It seems like that we don't need the attribute `CORO_PRESPLIT_ATTR` any more, 
> do we? If yes, I think we should remove them.

It's still needed by the legacy pass manager. I don't want to break that yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95807

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


[PATCH] D105120: [clang] Fix UB when string.front() is used for the empty string

2021-06-29 Thread Dmitry Polukhin via Phabricator via cfe-commits
DmitryPolukhin updated this revision to Diff 355261.
DmitryPolukhin added a comment.

Fix clang-tidy style warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105120

Files:
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto *It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto *It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

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

Is it better to save the actual `ExplodedNode` in the note tag? Then the error 
node of the `BugReport` can be used to search the bug path and check if the 
saved node is encountered. In this way a `NoteTag` could be used and the 
"sequence numbers" would be unnecessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

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


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

2021-06-29 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@chrish_ericsson_atx
Thanks for the new test case. I'll handle it ASAP.

> To be clear, neither this new reproducer nor the one I originally posted fail 
> if commit b30521c28a4d 
>  is 
> reverted.  Is it worth considering reverting that commit until a patch that 
> addresses the original problem and doesn't introduce these new regressions is 
> available?

I don't think we should revert b30521c28a4d 
 because 
it corrects symbol representation in CSA and fixes two bugs: 
https://bugs.llvm.org/show_bug.cgi?id=37503 and 
https://bugs.llvm.org/show_bug.cgi?id=49007. Another point of non-revert is 
that your cases were previously hidden in CSA core and that's good to find 
them. I'm afraid it's a dubious idea to return back old bugs in favor of not 
seeing new ones.


Repository:
  rG LLVM Github Monorepo

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] D105092: [PoC][RISCV] Add the tail policy argument to builtins/intrinsics.

2021-06-29 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:1148
+if (HasPolicy) {
+  ProtoMaskSeq.push_back("z");
+}

khchen wrote:
> maybe the policy argument should be a constant value ("Kz")?
Agreed.



Comment at: llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h:80
+
+  HasPolicyShift = HasVLOpShift + 1,
+  HasPolicyMask = 1 << HasPolicyShift,

This should be HasPolicyOpShift and HasPolicyOpMask to match SEWOp/VLOp naming.



Comment at: llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h:138
 
+static inline bool hasPolicy(uint64_t TSFlags) {
+  return TSFlags & HasPolicyMask;

hasPolicyOp



Comment at: llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp:401
+const MachineOperand &Op = MI.getOperand(NumOperands - 1);
+TailAgnostic = Op.getImm();
+  }

Probably need to mask this to bit 0. `TailAgnostic = Op.getImm() & 1`. As 
written we'll set TailAgnostic if any bit in the immediate is non-zero.



Comment at: llvm/lib/Target/RISCV/RISCVInstrFormats.td:182
+
+  bit HasPolicy = false;
+  let TSFlags{16} = HasPolicy;

HasPolicyOp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105092

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D103615#2847118 , @bmahjour wrote:

> In D103615#2847047 , @stefanp wrote:
>
>> I'm sorry I missed the asserts requirement.
>> I will recommit this patch after I add `REQUIRES: asserts`.
>
> Instead of disabling the tests for non-assert builds, can we just remove the 
> `entry:` checks at the beginning of each function? The rest of the IR checks 
> should pass since they use a regexp so they should match for either named or 
> unnamed instructions.

(generally: disabling the test in non-asserts builds isn't the right path, 
modifying the test so it doesn't depend on asserts IR naming is the right path)

Yes, probably removing the `entry:` check would be sufficient - give it a test 
locally and see how it goes. (it does mean the "CHECK-NEXT" after that (for the 
first instruction) would have to be a plain "CHECK" - so that the test could 
pass both in the presence and absence of the entry label.

In D103615#2847124 , @bmahjour wrote:

> In D103615#2846245 , @dblaikie 
> wrote:
>
>> As mentioned in the reverting commit - these tests fail in non-asserts 
>> builds, because they assume named IR instructions (like the named entry BB 
>> label), which aren't provided on a non-asserts build (there's a flag to turn 
>> them on - but that's probably not the right fix - making the test resilient 
>> to non-asserts IR is probably the right fix).
>>
>> Leaving non-asserts builds broken for 12 hours (maybe I'm the first one to 
>> come across/report it - but I'd expect there are some buildbots that would 
>> fail, etc) is quite a while - best to be avoided when possible.
>
> This is a bit off topic, but I'm just curious about clang's rationale for 
> producing different IR depending on whether asserts are on/off? Seems strange 
> and undesirable to me.

Yeah, seems like a weird choice to me too (though has been around a long time, 
so folks are pretty used to it) - might be worth bringing it up on llvm-dev. I 
think we now have a flag to enable this functionality that works even in 
non-asserts builds (maybe?) so maybe if we just change the default for assert 
builds so it's always opt-in via a flag, then it's consistent between asserts 
and non-asserts builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added a comment.

> (generally: disabling the test in non-asserts builds isn't the right path, 
> modifying the test so it doesn't depend on asserts IR naming is the right 
> path)

Agreed.

> Yes, probably removing the entry: check would be sufficient - give it a test 
> locally and see how it goes. (it does mean the "CHECK-NEXT" after that (for 
> the first instruction) would have to be a plain "CHECK" - so that the test 
> could pass both in the presence and absence of the entry label.

Right.

> Yeah, seems like a weird choice to me too (though has been around a long 
> time, so folks are pretty used to it) - might be worth bringing it up on 
> llvm-dev. I think we now have a flag to enable this functionality that works 
> even in non-asserts builds (maybe?) so maybe if we just change the default 
> for assert builds so it's always opt-in via a flag, then it's consistent 
> between asserts and non-asserts builds.

Do you happen to know what that option is? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[clang] 952944c - [ObjC][ARC] Don't add operand bundle clang.arc.attachedcall to a call if

2021-06-29 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2021-06-29T10:23:01-07:00
New Revision: 952944c12c0aa917e97805e929b5cd4e40866f91

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

LOG: [ObjC][ARC] Don't add operand bundle clang.arc.attachedcall to a call if
the call already has the operand bundle

This bug was causing the call to `replaceAllUsesWith` to crash because
the old call instruction and the new call instruction were the same.

rdar://74957948

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

Added: 
clang/test/CodeGenObjCXX/arc-rv-attr.mm

Modified: 
clang/lib/CodeGen/CGObjC.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 6c36dde1f526d..63429b1d4f653 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -2939,8 +2939,12 @@ static llvm::Value 
*emitARCOperationAfterCall(CodeGenFunction &CGF,
   ValueTransform doAfterCall,
   ValueTransform doFallback) {
   CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
+  auto *callBase = dyn_cast(value);
 
-  if (llvm::CallInst *call = dyn_cast(value)) {
+  if (callBase && llvm::objcarc::hasAttachedCallOpBundle(callBase)) {
+// Fall back if the call base has operand bundle "clang.arc.attachedcall".
+value = doFallback(CGF, value);
+  } else if (llvm::CallInst *call = dyn_cast(value)) {
 // Place the retain immediately following the call.
 CGF.Builder.SetInsertPoint(call->getParent(),
++llvm::BasicBlock::iterator(call));

diff  --git a/clang/test/CodeGenObjCXX/arc-rv-attr.mm 
b/clang/test/CodeGenObjCXX/arc-rv-attr.mm
new file mode 100644
index 0..0f4519bd527d9
--- /dev/null
+++ b/clang/test/CodeGenObjCXX/arc-rv-attr.mm
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc 
-std=c++11 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK
+
+id foo(void);
+
+// CHECK-LABEL: define{{.*}} void @_Z14test_list_initv(
+// CHECK: %[[CALL1:.*]] = call i8* @_Z3foov() [ "clang.arc.attachedcall"(i64 
0) ]
+// CHECK: call i8* @llvm.objc.retain(i8* %[[CALL1]])
+
+void test_list_init() {
+  auto t = id{foo()};
+}



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


[PATCH] D105135: [Internalize] Preserve variables externally initialized.

2021-06-29 Thread Michael Liao via Phabricator via cfe-commits
hliao created this revision.
hliao added reviewers: yaxunl, bogner.
Herald added subscribers: ormris, hiraditya.
hliao requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

- ``externally_initialized`` variables would be initialized or modified 
elsewhere. Particularly, CUDA or HIP may have host code to initialize or modify 
``externally_initialized`` device variables, which may not be explicitly 
referenced on the device side but may still be used through the host side 
interfaces. Not preserving them triggers the elimination of them in the 
GlobalDCE and breaks the user code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105135

Files:
  clang/test/CodeGenCUDA/host-used-device-var.cu
  clang/test/CodeGenCUDA/unused-global-var.cu
  llvm/lib/Transforms/IPO/Internalize.cpp
  llvm/test/Transforms/Internalize/externally-initialized.ll


Index: llvm/test/Transforms/Internalize/externally-initialized.ll
===
--- /dev/null
+++ llvm/test/Transforms/Internalize/externally-initialized.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -internalize -S | FileCheck %s
+; RUN: opt < %s -passes=internalize -S | FileCheck %s
+
+; CHECK: @G0
+; CHECK-NOT: internal
+; CHECK-SAME: global i32
+@G0 = protected externally_initialized global i32 0, align 4
Index: llvm/lib/Transforms/IPO/Internalize.cpp
===
--- llvm/lib/Transforms/IPO/Internalize.cpp
+++ llvm/lib/Transforms/IPO/Internalize.cpp
@@ -101,6 +101,12 @@
   if (GV.hasDLLExportStorageClass())
 return true;
 
+  // As the name suggestes, externally initialized variables need preserving as
+  // they would be initialized elsewhere externally.
+  if (const auto *G = dyn_cast(&GV))
+if (G->isExternallyInitialized())
+  return true;
+
   // Already local, has nothing to do.
   if (GV.hasLocalLinkage())
 return false;
Index: clang/test/CodeGenCUDA/unused-global-var.cu
===
--- clang/test/CodeGenCUDA/unused-global-var.cu
+++ clang/test/CodeGenCUDA/unused-global-var.cu
@@ -17,12 +17,6 @@
 
 // Check unused device/constant variables are eliminated.
 
-// NEGCHK-NOT: @v1
-__device__ int v1;
-
-// NEGCHK-NOT: @v2
-__constant__ int v2;
-
 // NEGCHK-NOT: @_ZL2v3
 constexpr int v3 = 1;
 
Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- clang/test/CodeGenCUDA/host-used-device-var.cu
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -17,12 +17,6 @@
 
 // Check device variables used by neither host nor device functioins are not 
kept.
 
-// DEV-NEG-NOT: @v1
-__device__ int v1;
-
-// DEV-NEG-NOT: @v2
-__constant__ int v2;
-
 // DEV-NEG-NOT: @_ZL2v3
 static __device__ int v3;
 


Index: llvm/test/Transforms/Internalize/externally-initialized.ll
===
--- /dev/null
+++ llvm/test/Transforms/Internalize/externally-initialized.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -internalize -S | FileCheck %s
+; RUN: opt < %s -passes=internalize -S | FileCheck %s
+
+; CHECK: @G0
+; CHECK-NOT: internal
+; CHECK-SAME: global i32
+@G0 = protected externally_initialized global i32 0, align 4
Index: llvm/lib/Transforms/IPO/Internalize.cpp
===
--- llvm/lib/Transforms/IPO/Internalize.cpp
+++ llvm/lib/Transforms/IPO/Internalize.cpp
@@ -101,6 +101,12 @@
   if (GV.hasDLLExportStorageClass())
 return true;
 
+  // As the name suggestes, externally initialized variables need preserving as
+  // they would be initialized elsewhere externally.
+  if (const auto *G = dyn_cast(&GV))
+if (G->isExternallyInitialized())
+  return true;
+
   // Already local, has nothing to do.
   if (GV.hasLocalLinkage())
 return false;
Index: clang/test/CodeGenCUDA/unused-global-var.cu
===
--- clang/test/CodeGenCUDA/unused-global-var.cu
+++ clang/test/CodeGenCUDA/unused-global-var.cu
@@ -17,12 +17,6 @@
 
 // Check unused device/constant variables are eliminated.
 
-// NEGCHK-NOT: @v1
-__device__ int v1;
-
-// NEGCHK-NOT: @v2
-__constant__ int v2;
-
 // NEGCHK-NOT: @_ZL2v3
 constexpr int v3 = 1;
 
Index: clang/test/CodeGenCUDA/host-used-device-var.cu
===
--- clang/test/CodeGenCUDA/host-used-device-var.cu
+++ clang/test/CodeGenCUDA/host-used-device-var.cu
@@ -17,12 +17,6 @@
 
 // Check device variables used by neither host nor device functioins are not kept.
 
-// DEV-NEG-NOT: @v1
-__device__ int v1;
-
-// DEV-NEG-NOT: @v2
-__constant__ int v2;
-
 // DEV-NEG-NOT: @_ZL2v3
 static __device__ int v3;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi

[PATCH] D97824: [ObjC][ARC] Don't add operand bundle `clang.arc.attachedcall` to a call if the call already has the operand bundle

2021-06-29 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG952944c12c0a: [ObjC][ARC] Don't add operand bundle 
clang.arc.attachedcall to a call if (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97824

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/test/CodeGenObjCXX/arc-rv-attr.mm


Index: clang/test/CodeGenObjCXX/arc-rv-attr.mm
===
--- /dev/null
+++ clang/test/CodeGenObjCXX/arc-rv-attr.mm
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc 
-std=c++11 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK
+
+id foo(void);
+
+// CHECK-LABEL: define{{.*}} void @_Z14test_list_initv(
+// CHECK: %[[CALL1:.*]] = call i8* @_Z3foov() [ "clang.arc.attachedcall"(i64 
0) ]
+// CHECK: call i8* @llvm.objc.retain(i8* %[[CALL1]])
+
+void test_list_init() {
+  auto t = id{foo()};
+}
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2939,8 +2939,12 @@
   ValueTransform doAfterCall,
   ValueTransform doFallback) {
   CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
+  auto *callBase = dyn_cast(value);
 
-  if (llvm::CallInst *call = dyn_cast(value)) {
+  if (callBase && llvm::objcarc::hasAttachedCallOpBundle(callBase)) {
+// Fall back if the call base has operand bundle "clang.arc.attachedcall".
+value = doFallback(CGF, value);
+  } else if (llvm::CallInst *call = dyn_cast(value)) {
 // Place the retain immediately following the call.
 CGF.Builder.SetInsertPoint(call->getParent(),
++llvm::BasicBlock::iterator(call));


Index: clang/test/CodeGenObjCXX/arc-rv-attr.mm
===
--- /dev/null
+++ clang/test/CodeGenObjCXX/arc-rv-attr.mm
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc -std=c++11 -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK
+
+id foo(void);
+
+// CHECK-LABEL: define{{.*}} void @_Z14test_list_initv(
+// CHECK: %[[CALL1:.*]] = call i8* @_Z3foov() [ "clang.arc.attachedcall"(i64 0) ]
+// CHECK: call i8* @llvm.objc.retain(i8* %[[CALL1]])
+
+void test_list_init() {
+  auto t = id{foo()};
+}
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -2939,8 +2939,12 @@
   ValueTransform doAfterCall,
   ValueTransform doFallback) {
   CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP();
+  auto *callBase = dyn_cast(value);
 
-  if (llvm::CallInst *call = dyn_cast(value)) {
+  if (callBase && llvm::objcarc::hasAttachedCallOpBundle(callBase)) {
+// Fall back if the call base has operand bundle "clang.arc.attachedcall".
+value = doFallback(CGF, value);
+  } else if (llvm::CallInst *call = dyn_cast(value)) {
 // Place the retain immediately following the call.
 CGF.Builder.SetInsertPoint(call->getParent(),
++llvm::BasicBlock::iterator(call));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104616: [analyzer] Model comparision methods of std::unique_ptr

2021-06-29 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

Sorry for not updating. Was down with fever.
This patch does *not* work now. `operationKindFromOverloadedOperator` is broken 
because the maps don't get populated. I am not entirely sure why this is 
happening.
Will try to fix tomorrow. @NoQ, @vsavchenko, @xazax.hun, @teemperor do you have 
a hunch as to why this may be happening?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104616

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


[clang] aaba371 - [clang][PATCH][nfc] Refactor TargetInfo::adjust to pass DiagnosticsEngine to allow diagnostics on target-unsupported options

2021-06-29 Thread Melanie Blower via cfe-commits

Author: Melanie Blower
Date: 2021-06-29T13:26:23-04:00
New Revision: aaba37187fda7f5a7fdc4c1e6129cbaaa1bbf709

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

LOG: [clang][PATCH][nfc] Refactor TargetInfo::adjust to pass DiagnosticsEngine 
to allow diagnostics on target-unsupported options

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Basic/Targets/PPC.cpp
clang/lib/Basic/Targets/PPC.h
clang/lib/Basic/Targets/SPIR.h
clang/lib/Basic/Targets/WebAssembly.cpp
clang/lib/Basic/Targets/WebAssembly.h
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Interpreter/Interpreter.cpp
clang/tools/clang-import-test/clang-import-test.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index d59bad30e7428..20f6afa76cbb3 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1162,7 +1162,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   /// Apply changes to the target information with respect to certain
   /// language options which change the target configuration and adjust
   /// the language based on the target options where applicable.
-  virtual void adjust(LangOptions &Opts);
+  virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts);
 
   /// Adjust target options based on codegen options.
   virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index e73b4a3a40c74..4c2859e5eda7f 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -346,7 +346,7 @@ bool TargetInfo::isTypeSigned(IntType T) {
 /// Apply changes to the target information with respect to certain
 /// language options which change the target configuration and adjust
 /// the language based on the target options where applicable.
-void TargetInfo::adjust(LangOptions &Opts) {
+void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
   if (Opts.NoBitFieldTypeAlign)
 UseBitFieldTypeAlignment = false;
 

diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 595132e2e70ba..fac786dbcf9e2 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -358,8 +358,8 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
&Triple,
   MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
 }
 
-void AMDGPUTargetInfo::adjust(LangOptions &Opts) {
-  TargetInfo::adjust(Opts);
+void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
+  TargetInfo::adjust(Diags, Opts);
   // ToDo: There are still a few places using default address space as private
   // address space in OpenCL, which needs to be cleaned up, then Opts.OpenCL
   // can be removed from the following line.

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index fe5c61c6ba2bb..244a6e0446905 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -93,7 +93,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public 
TargetInfo {
 
   void setAddressSpaceMap(bool DefaultIsPrivate);
 
-  void adjust(LangOptions &Opts) override;
+  void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
 
   uint64_t getPointerWidthV(unsigned AddrSpace) const override {
 if (isR600(getTriple()))

diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 6860b5e5d02fa..d431dda970222 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -614,10 +614,10 @@ void 
PPCTargetInfo::fillValidCPUList(SmallVectorImpl &Values) const {
   Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
 }
 
-void PPCTargetInfo::adjust(LangOptions &Opts) {
+void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
   if (HasAltivec)
 Opts.AltiVec = 1;
-  TargetInfo::adjust(Opts);
+  TargetInfo::adjust(Diags, Opts);
   if (LongDoubleFormat != &llvm::APFloat::IEEEdouble())
 LongDoubleFormat = Opts.PPCIEEELongDouble
? &llvm::APFloat::IEEEquad()

diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 554f2174fee00..18ee1194c759d 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -89,7 +89

[PATCH] D104729: [clang][PATCH][nfc] Refactor TargetInfo::adjust to pass DiagnosticsEngine to allow diagnostics on target-unsupported options

2021-06-29 Thread Melanie Blower via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaaba37187fda: [clang][PATCH][nfc] Refactor 
TargetInfo::adjust to pass DiagnosticsEngine to… (authored by mibintc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104729

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Interpreter/Interpreter.cpp
  clang/tools/clang-import-test/clang-import-test.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -704,7 +704,7 @@
   if (!instance->hasTarget())
 return nullptr;
 
-  instance->getTarget().adjust(instance->getLangOpts());
+  instance->getTarget().adjust(*diagnostics_engine, instance->getLangOpts());
 
   if (!action->BeginSourceFile(*instance,
instance->getFrontendOpts().Inputs[0]))
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -658,7 +658,8 @@
   //
   // FIXME: We shouldn't need to do this, the target should be immutable once
   // created. This complexity should be lifted elsewhere.
-  m_compiler->getTarget().adjust(m_compiler->getLangOpts());
+  m_compiler->getTarget().adjust(m_compiler->getDiagnostics(),
+		 m_compiler->getLangOpts());
 
   // 6. Set up the diagnostic buffer for reporting errors
 
Index: clang/tools/clang-import-test/clang-import-test.cpp
===
--- clang/tools/clang-import-test/clang-import-test.cpp
+++ clang/tools/clang-import-test/clang-import-test.cpp
@@ -208,7 +208,7 @@
   TargetInfo *TI = TargetInfo::CreateTargetInfo(
   Ins->getDiagnostics(), Ins->getInvocation().TargetOpts);
   Ins->setTarget(TI);
-  Ins->getTarget().adjust(Ins->getLangOpts());
+  Ins->getTarget().adjust(Ins->getDiagnostics(), Ins->getLangOpts());
   Ins->createFileManager();
   Ins->createSourceManager(Ins->getFileManager());
   Ins->createPreprocessor(TU_Complete);
Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -110,7 +110,7 @@
"Initialization failed. "
"Target is missing");
 
-  Clang->getTarget().adjust(Clang->getLangOpts());
+  Clang->getTarget().adjust(Clang->getDiagnostics(), Clang->getLangOpts());
 
   return std::move(Clang);
 }
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -142,7 +142,7 @@
   // Inform the target of the language options.
   // FIXME: We shouldn't need to do this, the target should be immutable once
   // created. This complexity should be lifted elsewhere.
-  getTarget().adjust(getLangOpts());
+  getTarget().adjust(getDiagnostics(), getLangOpts());
 
   // Adjust target options based on codegen options.
   getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
@@ -457,7 +457,7 @@
   getSourceManager(), *HeaderInfo, *this,
   /*IdentifierInfoLookup=*/nullptr,
   /*OwnsHeaderSearch=*/true, TUKind);
-  getTarget().adjust(getLangOpts());
+  getTarget().adjust(getDiagnostics(), getLangOpts());
   PP->Initialize(getTarget(), getAuxTarget());
 
   if (PPOpts.DetailedRecord)
Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -588,7 +588,7 @@
 //
 // FIXME: We shouldn't need to do this, the target should be immutable once
 // created. This complexity should be lifted elsewhere.
-Target->adjust(LangOpt);
+Target->adjust(PP.getDiagnostics(), LangOpt);
 
 // Initialize the preprocessor.
 PP.Initialize(*Target);
Index

[PATCH] D105135: [Internalize] Preserve variables externally initialized.

2021-06-29 Thread Michael Liao via Phabricator via cfe-commits
hliao added inline comments.



Comment at: clang/test/CodeGenCUDA/host-used-device-var.cu:20
 
-// DEV-NEG-NOT: @v1
-__device__ int v1;

BTW, as clang codegen tests, those checks should not rely on middle-end 
optimizations to work correctly.



Comment at: clang/test/CodeGenCUDA/unused-global-var.cu:20
 
-// NEGCHK-NOT: @v1
-__device__ int v1;

BTW, as clang codegen tests, those checks should not rely on middle-end 
optimizations to work correctly.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105135

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D103615#2847704 , @bmahjour wrote:

>> (generally: disabling the test in non-asserts builds isn't the right path, 
>> modifying the test so it doesn't depend on asserts IR naming is the right 
>> path)
>
> Agreed.
>
>> Yes, probably removing the entry: check would be sufficient - give it a test 
>> locally and see how it goes. (it does mean the "CHECK-NEXT" after that (for 
>> the first instruction) would have to be a plain "CHECK" - so that the test 
>> could pass both in the presence and absence of the entry label.
>
> Right.
>
>> Yeah, seems like a weird choice to me too (though has been around a long 
>> time, so folks are pretty used to it) - might be worth bringing it up on 
>> llvm-dev. I think we now have a flag to enable this functionality that works 
>> even in non-asserts builds (maybe?) so maybe if we just change the default 
>> for assert builds so it's always opt-in via a flag, then it's consistent 
>> between asserts and non-asserts builds.
>
> Do you happen to know what that option is? Thanks!

Generally called "discard value names" - clang has `-f{no-}discard-value-names` 
- the various command line tools (opt, llc, etc) have some similar flags with 
spelling more suitable to the various command line syntaxes, etc...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[PATCH] D104946: [AMDGPU] Add builtin functions image_bvh_intersect_ray

2021-06-29 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsAMDGPU.def:221-224
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray, 
"V4UiUifV4fV4fV4fV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_h, 
"V4UiUifV4fV4hV4hV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_l, 
"V4UiWUifV4fV4fV4fV4Ui", "nc", "gfx10-insts")
+TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_lh, 
"V4UiWUifV4fV4hV4hV4Ui", "nc", "gfx10-insts")

yaxunl wrote:
> arsenm wrote:
> > The intrinsic signature suggests the 1st and 4th/5th arguments are 
> > overloadable. How does this handle the various supported types?
> By convention, we do not define overloaded target specific clang builtins. In 
> stead we use postfixes to indicate the types. In this case, we use the 
> following naming convention:
> 
> h - 4/5-th args are half
> d - 4/5-th args are double
> l - first arg is i64
> 
> by default - 1st arg is i32, 4/5-th args are float.
> 
> Currently we are missing functions for 4/5-th args are double. I will add 
> them.
> 
It seems we do not support 4/50th args to be double. So the current definitions 
are all that we support.


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

https://reviews.llvm.org/D104946

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


[PATCH] D105087: [clang-format] PR49960 clang-format doesn't handle ASI after "return" on JavaScript

2021-06-29 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

It's a strange language :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105087

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


[PATCH] D105099: [clang-format] Add an option to put one constructor initializer per line

2021-06-29 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D105099#2847328 , @MyDeveloperDay 
wrote:

> Seem similar to D90232: [clang-format] Formatting constructor initializer 
> lists by putting them always on different lines (update to D14484) 
>  which seems to have got stalled
>
> I sort of feel I prefer the design where we have an enum rather than 
> introducing a separate option.

Yeah I thought, I already saw something like that.

I too think the way with the enum is a better one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105099

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


[PATCH] D105087: [clang-format] PR49960 clang-format doesn't handle ASI after "return" on JavaScript

2021-06-29 Thread Martin Probst via Phabricator via cfe-commits
mprobst added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1015
+if (!eof()) {
+  if (Next->is(tok::identifier)) {
+// Peek the next token.

can you add comments explaining what syntax is being detected here?



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1019
+FormatToken *NextNext = Tokens->getNextToken();
+Tokens->setPosition(StoredPosition);
+if (NextNext && NextNext->is(tok::equal))

parsePPEndIf uses a different method to peek - any opinion on why you're doing 
it differently here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105087

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


[PATCH] D104946: [AMDGPU] Add builtin functions image_bvh_intersect_ray

2021-06-29 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 355309.
yaxunl added a comment.

Add check for ISA. Add comments about argument types.


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

https://reviews.llvm.org/D104946

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-raytracing.cl

Index: clang/test/CodeGenOpenCL/builtins-amdgcn-raytracing.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-raytracing.cl
@@ -0,0 +1,61 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1030 -S \
+// RUN:   -emit-llvm -cl-std=CL2.0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1030 -S \
+// RUN:   -cl-std=CL2.0 -o - %s | FileCheck -check-prefix=ISA %s
+
+// Test llvm.amdgcn.image.bvh.intersect.ray intrinsic.
+
+// The clang builtin functions __builtin_amdgcn_image_bvh_intersect_ray* use
+// postfixes to indicate the types of the 1st, 4th, and 5th arguments.
+// By default, the 1st argument is i32, the 4/5-th arguments are float4.
+// Postfix l indicates the 1st argument is i64 and postfix h indicates
+// the 4/5-th arguments are half4.
+
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef float float4 __attribute__((ext_vector_type(4)));
+typedef double double4 __attribute__((ext_vector_type(4)));
+typedef half half4 __attribute__((ext_vector_type(4)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
+
+// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f32
+// ISA: image_bvh_intersect_ray
+void test_image_bvh_intersect_ray(global uint4* out, uint node_ptr,
+  float ray_extent, float4 ray_origin, float4 ray_dir, float4 ray_inv_dir,
+  uint4 texture_descr)
+{
+  *out = __builtin_amdgcn_image_bvh_intersect_ray(node_ptr, ray_extent,
+   ray_origin, ray_dir, ray_inv_dir, texture_descr);
+}
+
+// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f16
+// ISA: image_bvh_intersect_ray
+void test_image_bvh_intersect_ray_h(global uint4* out, uint node_ptr,
+  float ray_extent, float4 ray_origin, half4 ray_dir, half4 ray_inv_dir,
+  uint4 texture_descr)
+{
+  *out = __builtin_amdgcn_image_bvh_intersect_ray_h(node_ptr, ray_extent,
+   ray_origin, ray_dir, ray_inv_dir, texture_descr);
+}
+
+// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f32
+// ISA: image_bvh_intersect_ray
+void test_image_bvh_intersect_ray_l(global uint4* out, ulong node_ptr,
+  float ray_extent, float4 ray_origin, float4 ray_dir, float4 ray_inv_dir,
+  uint4 texture_descr)
+{
+  *out = __builtin_amdgcn_image_bvh_intersect_ray_l(node_ptr, ray_extent,
+   ray_origin, ray_dir, ray_inv_dir, texture_descr);
+}
+
+// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f16
+// ISA: image_bvh_intersect_ray
+void test_image_bvh_intersect_ray_lh(global uint4* out, ulong node_ptr,
+  float ray_extent, float4 ray_origin, half4 ray_dir, half4 ray_inv_dir,
+  uint4 texture_descr)
+{
+  *out = __builtin_amdgcn_image_bvh_intersect_ray_lh(node_ptr, ray_extent,
+   ray_origin, ray_dir, ray_inv_dir, texture_descr);
+}
+
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15745,6 +15745,23 @@
 CI->setConvergent();
 return CI;
   }
+  case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
+  case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
+  case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
+  case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_lh: {
+llvm::Value *NodePtr = EmitScalarExpr(E->getArg(0));
+llvm::Value *RayExtent = EmitScalarExpr(E->getArg(1));
+llvm::Value *RayOrigin = EmitScalarExpr(E->getArg(2));
+llvm::Value *RayDir = EmitScalarExpr(E->getArg(3));
+llvm::Value *RayInverseDir = EmitScalarExpr(E->getArg(4));
+llvm::Value *TextureDescr = EmitScalarExpr(E->getArg(5));
+
+Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_image_bvh_intersect_ray,
+   {NodePtr->getType(), RayDir->getType()});
+return Builder.CreateCall(F, {NodePtr, RayExtent, RayOrigin, RayDir,
+  RayInverseDir, TextureDescr});
+  }
+
   // amdgcn workitem
   case AMDGPU::BI__builtin_amdgcn_workitem_id_x:
 return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_x, 0, 1024);
Index: clang/include/clang/Basic/BuiltinsAMDGPU.def
===
--- clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -215,6 +215,17 @@
 TARGET_BUILTIN(__builtin_amdgcn_permlanex16, "UiUiUiUiUiIbIb", "nc", "gfx10-insts")
 TARGET_BUILTIN(__builtin_amdgcn_mov_dpp8, "UiUiIUi", "nc", "gfx10-insts")

[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp added a comment.

In D103615#2847650 , @dblaikie wrote:

> In D103615#2847118 , @bmahjour 
> wrote:
>
>> In D103615#2847047 , @stefanp 
>> wrote:
>>
>>> I'm sorry I missed the asserts requirement.
>>> I will recommit this patch after I add `REQUIRES: asserts`.
>>
>> Instead of disabling the tests for non-assert builds, can we just remove the 
>> `entry:` checks at the beginning of each function? The rest of the IR checks 
>> should pass since they use a regexp so they should match for either named or 
>> unnamed instructions.
>
> (generally: disabling the test in non-asserts builds isn't the right path, 
> modifying the test so it doesn't depend on asserts IR naming is the right 
> path)
>
> Yes, probably removing the `entry:` check would be sufficient - give it a 
> test locally and see how it goes. (it does mean the "CHECK-NEXT" after that 
> (for the first instruction) would have to be a plain "CHECK" - so that the 
> test could pass both in the presence and absence of the entry label.

I've removed all of the `entry:` checks and changed for next line to `CHECK:` 
and that seems to be working with assertions off. I will recommit the patch 
like that if this is preferred.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D103615#2847965 , @stefanp wrote:

> In D103615#2847650 , @dblaikie 
> wrote:
>
>> In D103615#2847118 , @bmahjour 
>> wrote:
>>
>>> In D103615#2847047 , @stefanp 
>>> wrote:
>>>
 I'm sorry I missed the asserts requirement.
 I will recommit this patch after I add `REQUIRES: asserts`.
>>>
>>> Instead of disabling the tests for non-assert builds, can we just remove 
>>> the `entry:` checks at the beginning of each function? The rest of the IR 
>>> checks should pass since they use a regexp so they should match for either 
>>> named or unnamed instructions.
>>
>> (generally: disabling the test in non-asserts builds isn't the right path, 
>> modifying the test so it doesn't depend on asserts IR naming is the right 
>> path)
>>
>> Yes, probably removing the `entry:` check would be sufficient - give it a 
>> test locally and see how it goes. (it does mean the "CHECK-NEXT" after that 
>> (for the first instruction) would have to be a plain "CHECK" - so that the 
>> test could pass both in the presence and absence of the entry label.
>
> I've removed all of the `entry:` checks and changed for next line to `CHECK:` 
> and that seems to be working with assertions off. I will recommit the patch 
> like that if this is preferred.

Sounds alright to me


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

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


[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp updated this revision to Diff 355315.
stefanp added a comment.

Updated test cases to avoid failures on non assert builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/vector-compat-pixel-bool-ternary.c
  clang/test/CodeGen/vector-compat-pixel-bool.c
  clang/test/CodeGen/vector-compat-ternary.c
  clang/test/CodeGen/vector-compat.c

Index: clang/test/CodeGen/vector-compat.c
===
--- /dev/null
+++ clang/test/CodeGen/vector-compat.c
@@ -0,0 +1,152 @@
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=mixed -triple powerpc-unknown-unknown -S -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=gcc -triple powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=xl -triple powerpc-unknown-unknown -S -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: %clang -mcpu=pwr8 -faltivec-src-compat=gcc --target=powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang -mcpu=pwr9 -faltivec-src-compat=gcc --target=powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @ui8(
+// CHECK: [[A_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:store <16 x i8> [[A:%.*]], <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <16 x i8> [[B:%.*]], <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <16 x i1> [[CMP]] to <16 x i8>
+// CHECK-NEXT:ret <16 x i8> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector unsigned char ui8(vector unsigned char a, vector unsigned char b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @si8(
+// CHECK: [[A_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:store <16 x i8> [[A:%.*]], <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <16 x i8> [[B:%.*]], <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <16 x i1> [[CMP]] to <16 x i8>
+// CHECK-NEXT:ret <16 x i8> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector signed char si8(vector signed char a, vector signed char b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @ui16(
+// CHECK: [[A_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:store <8 x i16> [[A:%.*]], <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <8 x i16> [[B:%.*]], <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x i16>, <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i16>, <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <8 x i16> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector unsigned short ui16(vector unsigned short a, vector unsigned short b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @si16(
+// CHECK: [[A_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:store <8 x i16> [[A:%.*]], <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <8 x i16> [[B:%.*]], <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x i16>, <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i16>, <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <8 x i16> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector signed short si16(vector signed short a, vector signed short b)

[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp updated this revision to Diff 355320.
stefanp added a comment.

Removed the lines that specified that checks were auto generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/vector-compat-pixel-bool-ternary.c
  clang/test/CodeGen/vector-compat-pixel-bool.c
  clang/test/CodeGen/vector-compat-ternary.c
  clang/test/CodeGen/vector-compat.c

Index: clang/test/CodeGen/vector-compat.c
===
--- /dev/null
+++ clang/test/CodeGen/vector-compat.c
@@ -0,0 +1,152 @@
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=mixed -triple powerpc-unknown-unknown -S -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=gcc -triple powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=xl -triple powerpc-unknown-unknown -S -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: %clang -mcpu=pwr8 -faltivec-src-compat=gcc --target=powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang -mcpu=pwr9 -faltivec-src-compat=gcc --target=powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @ui8(
+// CHECK: [[A_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:store <16 x i8> [[A:%.*]], <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <16 x i8> [[B:%.*]], <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <16 x i1> [[CMP]] to <16 x i8>
+// CHECK-NEXT:ret <16 x i8> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector unsigned char ui8(vector unsigned char a, vector unsigned char b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @si8(
+// CHECK: [[A_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:store <16 x i8> [[A:%.*]], <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <16 x i8> [[B:%.*]], <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <16 x i1> [[CMP]] to <16 x i8>
+// CHECK-NEXT:ret <16 x i8> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector signed char si8(vector signed char a, vector signed char b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @ui16(
+// CHECK: [[A_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:store <8 x i16> [[A:%.*]], <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <8 x i16> [[B:%.*]], <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x i16>, <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i16>, <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <8 x i16> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector unsigned short ui16(vector unsigned short a, vector unsigned short b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @si16(
+// CHECK: [[A_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:store <8 x i16> [[A:%.*]], <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <8 x i16> [[B:%.*]], <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x i16>, <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i16>, <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <8 x i16> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector signed short si16(vector signed short a, vector signed s

[PATCH] D105097: [clang][AArch64][SVE] Handle PRValue under VLAT <-> VLST cast

2021-06-29 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2120
+  } else
+Addr = EmitLValue(E).getAddress(CGF);
   Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy));

I don't think it's legal to use EmitLValue here at all; the emitted IR could 
have side-effects.

Since we have the vector insert/extract intrinsics now, can we just use them 
here instead of going through the load/store dance?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105097

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


[PATCH] D104085: [compiler-rt][hwasan] Setup hwasan thread handling on Fuchsia

2021-06-29 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 355323.
leonardchan added a comment.

Ok. Ready for reviews.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104085

Files:
  compiler-rt/lib/hwasan/CMakeLists.txt
  compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
  compiler-rt/lib/hwasan/hwasan_thread.cpp

Index: compiler-rt/lib/hwasan/hwasan_thread.cpp
===
--- compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -46,7 +46,12 @@
 heap_allocations_ = HeapAllocationsRingBuffer::New(sz);
 
   InitStackAndTls(state);
+#if !SANITIZER_FUCHSIA
+  // Do not initialize the stack ring buffer just yet on Fuchsia. Threads will
+  // be initialized before we enter the thread itself, so we will instead call
+  // this later.
   InitStackRingBuffer(stack_buffer_start, stack_buffer_size);
+#endif
 }
 
 void Thread::InitStackRingBuffer(uptr stack_buffer_start,
Index: compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
===
--- /dev/null
+++ compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
@@ -0,0 +1,159 @@
+//===-- hwasan_fuchsia.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
+//
+//===--===//
+///
+/// \file
+/// This file is a part of HWAddressSanitizer and contains Fuchsia-specific
+/// code.
+///
+//===--===//
+
+#include "sanitizer_common/sanitizer_fuchsia.h"
+#if SANITIZER_FUCHSIA
+
+#include "hwasan.h"
+#include "hwasan_interface_internal.h"
+#include "hwasan_report.h"
+#include "hwasan_thread.h"
+#include "hwasan_thread_list.h"
+
+// This TLS variable contains the location of the stack ring buffer and can be
+// used to always find the hwasan thread object associated with the current
+// running thread.
+SANITIZER_INTERFACE_ATTRIBUTE
+[[gnu::tls_model("initial-exec")]] THREADLOCAL uptr __hwasan_tls;
+
+namespace __hwasan {
+
+// These are known parameters passed to the hwasan runtime on thread creation.
+struct Thread::InitState {
+  uptr stack_bottom, stack_top;
+};
+
+static void FinishThreadInitialization(Thread *thread);
+
+void InitThreads() {
+  // This is the minimal alignment needed for the storage where hwasan threads
+  // and their stack ring buffers are placed. This alignment is necessary so the
+  // stack ring buffer can perform a simple calculation to get the next element
+  // in the RB. The instructions for this calculation are emitted by the
+  // compiler. (Full explanation in hwasan_thread_list.h.)
+  uptr alloc_size = UINT64_C(1) << kShadowBaseAlignment;
+  uptr thread_start = reinterpret_cast(
+  MmapAlignedOrDieOnFatalError(alloc_size, alloc_size, __func__));
+
+  InitThreadList(thread_start, alloc_size);
+
+  // Create the hwasan thread object for the current (main) thread. Stack info
+  // for this thread is known from information passed via
+  // __sanitizer_startup_hook.
+  const Thread::InitState state = {
+  .stack_bottom = __sanitizer::MainThreadStackBase,
+  .stack_top =
+  __sanitizer::MainThreadStackBase + __sanitizer::MainThreadStackSize,
+  };
+  FinishThreadInitialization(hwasanThreadList().CreateCurrentThread(&state));
+}
+
+uptr *GetCurrentThreadLongPtr() { return &__hwasan_tls; }
+
+// This is called from the parent thread before the new thread is created. Here
+// we can propagate known info like the stack bounds to Thread::Init before
+// jumping into the thread. We cannot initialize the stack ring buffer yet since
+// we have not entered the new thread.
+static void *BeforeThreadCreateHook(uptr user_id, bool detached,
+const char *name, uptr stack_bottom,
+uptr stack_size) {
+  const Thread::InitState state = {
+  .stack_bottom = stack_bottom,
+  .stack_top = stack_bottom + stack_size,
+  };
+  return hwasanThreadList().CreateCurrentThread(&state);
+}
+
+// This sets the stack top and bottom according to the InitState passed to
+// CreateCurrentThread above.
+void Thread::InitStackAndTls(uptr stack_buffer_start, uptr stack_buffer_size,
+ const InitState *state) {
+  CHECK_NE(state->stack_bottom, 0);
+  CHECK_NE(state->stack_top, 0);
+  stack_bottom_ = state->stack_bottom;
+  stack_top_ = state->stack_top;
+  tls_end_ = tls_begin_ = 0;
+}
+
+// This is called after creating a new thread with the pointer returned by
+// BeforeThreadCreateHook. We are still in the creating thread and should check
+// if it was actually created correctly.
+static void ThreadCreateHook(void *hook, bool a

[clang] 90dfd05 - [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Stefan Pintilie via cfe-commits

Author: Stefan Pintilie
Date: 2021-06-29T14:07:12-05:00
New Revision: 90dfd059198ed94334f9b1ccfd29b566feb75e8b

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

LOG: [Clang] Add option to handle behaviour of vector bool/vector pixel.

Added the option `-altivec-src-compat=[mixed,gcc,xl]`. The default at this time 
is `mixed`.

The default behavior for clang is for all vector compares to return a scalar 
unless the vectors being
compared are vector bool or vector pixel. In that case the compare returns a
vector. With the gcc case all vector compares return vectors and in the xl case
all vector compares return scalars.

This patch does not change the default behavior of clang.

This option will be used in future patches to implement behaviour compatibility 
for the vector bool/pixel types.

Reviewed By: bmahjour

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

Added: 
clang/test/CodeGen/vector-compat-pixel-bool-ternary.c
clang/test/CodeGen/vector-compat-pixel-bool.c
clang/test/CodeGen/vector-compat-ternary.c
clang/test/CodeGen/vector-compat.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b5b8bc6aa3c57..70a22fd2506a3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7441,6 +7441,12 @@ def warn_deprecated_volatile_structured_binding : 
Warning<
   "volatile qualifier in structured binding declaration is deprecated">,
   InGroup;
 
+def warn_deprecated_altivec_src_compat : Warning<
+  "Current handling of vector bool and vector pixel types in this context are "
+  "deprecated. The default behaviour will soon change to that implied by the "
+  "'-altivec-compat=xl' option">,
+  InGroup>;
+
 def err_catch_incomplete_ptr : Error<
   "cannot catch pointer to incomplete type %0">;
 def err_catch_incomplete_ref : Error<

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index b6d9160f89a00..465bad8d7d112 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -126,6 +126,8 @@ LANGOPT(WritableStrings   , 1, 0, "writable string support")
 LANGOPT(ConstStrings  , 1, 0, "const-qualified string support")
 ENUM_LANGOPT(LaxVectorConversions, LaxVectorConversionKind, 2,
  LaxVectorConversionKind::All, "lax vector conversions")
+ENUM_LANGOPT(AltivecSrcCompat, AltivecSrcCompatKind, 2,
+ AltivecSrcCompatKind::Default, "Altivec source compatibility")
 LANGOPT(ConvergentFunctions, 1, 1, "Assume convergent functions")
 LANGOPT(AltiVec   , 1, 0, "AltiVec-style vector initializers")
 LANGOPT(ZVector   , 1, 0, "System z vector extensions")

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index d618daf3d23c2..d04ce52a550ef 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -244,6 +244,18 @@ class LangOptions : public LangOptionsBase {
 All,
   };
 
+  enum class AltivecSrcCompatKind {
+// All vector compares produce scalars except vector pixel and vector bool.
+// The types vector pixel and vector bool return vector results.
+Mixed,
+// All vector compares produce vector results as in GCC.
+GCC,
+// All vector compares produce scalars as in XL.
+XL,
+// Default clang behaviour.
+Default = Mixed,
+  };
+
   enum class SignReturnAddressScopeKind {
 /// No signing for any function.
 None,

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index af004e0c28b54..301f59207c4a5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3823,6 +3823,18 @@ def u : JoinedOrSeparate<["-"], "u">, Group;
 def v : Flag<["-"], "v">, Flags<[CC1Option, CoreOption]>,
   HelpText<"Show commands to run and use verbose output">,
   MarshallingInfoFlag>;
+def altivec_src_compat : Joined<["-"], "faltivec-src-compat=">,
+  Flags<[CC1Option]>, Group,
+  HelpText<"Source-level compatibility for Altivec vectors (for PowerPC "
+   "targets). This includes results of vector comparison (scalar for "
+   "'xl', vector for 'gcc') as well as behavior when initializing with 
"
+   "a scalar (splatting for 'xl', element zero only for 'gcc'). For "
+   "'mixed', the compatibility is as 'gcc' for 'vecto

[PATCH] D103615: [Clang] Add option to handle behaviour of vector bool/vector pixel.

2021-06-29 Thread Stefan Pintilie 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 rG90dfd059198e: [Clang] Add option to handle behaviour of 
vector bool/vector pixel. (authored by stefanp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103615

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/vector-compat-pixel-bool-ternary.c
  clang/test/CodeGen/vector-compat-pixel-bool.c
  clang/test/CodeGen/vector-compat-ternary.c
  clang/test/CodeGen/vector-compat.c

Index: clang/test/CodeGen/vector-compat.c
===
--- /dev/null
+++ clang/test/CodeGen/vector-compat.c
@@ -0,0 +1,152 @@
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=mixed -triple powerpc-unknown-unknown -S -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=gcc -triple powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+// RUN: not %clang_cc1 -target-feature +altivec -target-feature +vsx \
+// RUN:   -faltivec-src-compat=xl -triple powerpc-unknown-unknown -S -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=ERROR
+// RUN: %clang -mcpu=pwr8 -faltivec-src-compat=gcc --target=powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang -mcpu=pwr9 -faltivec-src-compat=gcc --target=powerpc-unknown-unknown -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: @ui8(
+// CHECK: [[A_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:store <16 x i8> [[A:%.*]], <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <16 x i8> [[B:%.*]], <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <16 x i1> [[CMP]] to <16 x i8>
+// CHECK-NEXT:ret <16 x i8> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector unsigned char ui8(vector unsigned char a, vector unsigned char b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @si8(
+// CHECK: [[A_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <16 x i8>, align 16
+// CHECK-NEXT:store <16 x i8> [[A:%.*]], <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <16 x i8> [[B:%.*]], <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <16 x i8>, <16 x i8>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <16 x i1> [[CMP]] to <16 x i8>
+// CHECK-NEXT:ret <16 x i8> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector signed char si8(vector signed char a, vector signed char b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @ui16(
+// CHECK: [[A_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:store <8 x i16> [[A:%.*]], <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <8 x i16> [[B:%.*]], <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x i16>, <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i16>, <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <8 x i16> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[SEXT]]
+//
+// ERROR: returning 'int' from a function with incompatible result type
+vector unsigned short ui16(vector unsigned short a, vector unsigned short b) {
+  return a == b;
+}
+
+// CHECK-LABEL: @si16(
+// CHECK: [[A_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <8 x i16>, align 16
+// CHECK-NEXT:store <8 x i16> [[A:%.*]], <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:store <8 x i16> [[B:%.*]], <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x i16>, <8 x i16>* [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load <8 x i16>, <8 x i16>* [[B_ADDR]], align 16
+// CHECK-NEXT:[[CMP:%.*]] = icmp eq <8 x i16> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[SEXT:%.*]] = sext <8 x i1> [[CMP]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[SEXT]]
+//
+// ERROR: returning 

[PATCH] D104085: [compiler-rt][hwasan] Setup hwasan thread handling on Fuchsia

2021-06-29 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

Let me know if this should be split up also. I think this might be small and 
and simple enough for one patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104085

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


[PATCH] D105142: RFC: Implementing new mechanism for hard register operands to inline asm as a constraint.

2021-06-29 Thread Anirudh Prasad via Phabricator via cfe-commits
anirudhp created this revision.
Herald added subscribers: pengfei, jfb, tpr.
anirudhp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Relevant RFCs posted here

https://lists.llvm.org/pipermail/llvm-dev/2021-June/151370.html
https://gcc.gnu.org/pipermail/gcc/2021-June/236269.html

- This is put up as an RFC patch to get feedback about the introduction of a 
new inline asm constraint which supports hard register operands
- This is mostly a clang change, since the LLVM IR for the inline assembly 
already supports the {...} syntax which the backend recognizes. This change 
merely completes the loop in terms of introducing a user facing constraint 
which maps to it.

The following design decisions were taken for this patch:

For the Sema side:

- We validate the "{" constraint using a two-phase validation approach. 
Firstly, we check if there is a target dependent implementation to handle the 
{} constraint. If it fails, then we move on to a target agnostic check 
where we parse and validate the {} constraint.
- Why do we do this? Well, there are some targets which already process the 
{...} as a user facing constraint. For example the AMDGPU target. It supports 
syntax of the form {register-name} as well as {register-name[...]}. Moving this 
implementation to the target agnostic side seems to set a precedent, that we 
can keep extending the target agnostic implementation based on new cases for 
certain targets, which would be better served of moving it to the respective 
target.
- In terms of the target agnostic validation, we simply check for the following 
syntax {.*}. The parsed out content within the two curly braces is checked to 
see whether its a "valid GCC register".

For the Clang CodeGen side:

- Most of the work is done in the `AddVariableConstraints` function in 
CGStmt.cpp, which is responsible for emitting the LLVM IR corresponding to the 
usage of an actual register that the backend can use. Coincidentally, the LLVM 
IR is also {...}. As mentioned above, this is essentially mapping the LLVM 
Inline Assembly IR back to a user facing inline asm constraint.
- Within this function we add in logic to check if the constraint is of the 
form [&]{...} in addition to the "register asm" construct.
- A scenario where it was applicable to apply both the "register asm" construct 
and the "hard register inline asm constraint" was diagnosed as an unsupported 
error because there's no way the compiler will know which register the user 
meant. The safest option here is to error out explicitly, and put onus back on 
the user.
- To achieve this, and refactor it in a nice way, most of the logic pertaining 
to the "register asm" construct has been moved into a separate function called 
`ShouldApplyRegisterVariableConstraint` which deduces whether to apply the 
"register asm" construct or not.
- Furthermore, the GCCReg field is set with the "Register" only if the register 
is validated to be a "valid GCC Register" type. To me it doesn't make a lot of 
sense to set GCC Reg to something that might not necessarily be a "valid GCC 
register" as defined by respective targets. Would we have a case where we could 
have a {.*} constraint where the contents inside the curly brace is not a valid 
register? Yes. For example, The x86 target supports the "@cca" constraint, 
which is validated on the Sema side as a valid constraint, and before 
processing is converted to "{@cca}" (via the `convertAsmConstraint` function. 
"@cca" is not a valid "GCC register name". So in these case, we'll simply emit 
the constraint without setting GCCReg (with the assumption that the respective 
backends deal with it appropriately)

Tests:

- Various tests were updated to account for the new behaviour.
- I added a few SystemZ tests because we work on the Z backend, but I have no 
issues adding testing for multiple targets.
- There were a few mentions of "waiting" for the GCC implementation of the same 
to land before the Clang side lands. As mentioned above, the intent to 
implement it on the GCC side has already been put forward via the RFC. I have 
no issues "parking" this implementation until its ready to be merged in. 
However, it might be good to hash out any open questions/concerns in the 
interim.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105142

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/SystemZ/systemz-inline-asm-02.c
  clang/test/CodeGen/SystemZ/systemz-inline-asm.c
  clang/test/CodeGen/aarch64-inline-asm.c
  clang/test/CodeGen/asm-goto.c
  clang/test/CodeGen/ms-intrinsics.c
  clang/test/CodeGen/z-hard-register-inline-asm.c

Index: clang/test/CodeGen/z-hard-register-inline-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/z-hard-register-inline-asm.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple s390x-ibm-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -trip

[PATCH] D105142: RFC: Implementing new mechanism for hard register operands to inline asm as a constraint.

2021-06-29 Thread Anirudh Prasad via Phabricator via cfe-commits
anirudhp updated this revision to Diff 355332.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105142

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/SystemZ/systemz-inline-asm-02.c
  clang/test/CodeGen/SystemZ/systemz-inline-asm.c
  clang/test/CodeGen/aarch64-inline-asm.c
  clang/test/CodeGen/asm-goto.c
  clang/test/CodeGen/ms-intrinsics.c
  clang/test/CodeGen/z-hard-register-inline-asm.c
  clang/test/Sema/z-hard-register-inline-asm.c

Index: clang/test/Sema/z-hard-register-inline-asm.c
===
--- /dev/null
+++ clang/test/Sema/z-hard-register-inline-asm.c
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 %s -triple s390x-ibm-linux -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple s390x-ibm-zos -fsyntax-only -verify
+
+void f1() {
+  int a, b;
+  __asm("lhi %0,5\n"
+: "={r2}"(a)
+:);
+
+  __asm("lgr %0,%1\n"
+: "={r2}"(a)
+: "{r1}"(b));
+
+  __asm("lgr %0,%1\n"
+: "={r2}"(a)
+: "{%r1}"(b));
+
+  __asm("lgr %0,%1\n"
+: "=&{r1}"(a)
+: "{r2}"(b));
+
+  __asm("lhi %0,5\n"
+: "={r2"(a) // expected-error {{invalid output constraint '={r2' in asm}}
+:);
+
+  __asm("lhi %0,5\n"
+: "={r17}"(a) // expected-error {{invalid output constraint '={r17}' in asm}}
+:);
+
+  __asm("lhi %0,5\n"
+: "={}"(a) // expected-error {{invalid output constraint '={}' in asm}}
+:);
+
+  __asm("lhi %0,5\n"
+: "=&{r2"(a) // expected-error {{invalid output constraint '=&{r2' in asm}}
+:);
+
+  __asm("lgr %0,%1\n"
+: "=r"(a)
+: "{r1"(b)); // expected-error {{invalid input constraint '{r1' in asm}}
+
+  __asm("lgr %0,%1\n"
+: "=r"(a)
+: "{}"(b)); // expected-error {{invalid input constraint '{}' in asm}}
+
+  __asm("lgr %0,%1\n"
+: "={r1}"(a)
+: "{r17}"(b)); // expected-error {{invalid input constraint '{r17}' in asm}}
+}
Index: clang/test/CodeGen/z-hard-register-inline-asm.c
===
--- /dev/null
+++ clang/test/CodeGen/z-hard-register-inline-asm.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple s390x-ibm-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -emit-llvm -o - %s | FileCheck %s
+
+void f1() {
+  int a, b;
+  register int c asm("r1");
+  register int d asm("r2");
+
+  // CHECK-COUNT-2: call i32 asm "lhi $0,5\0A", "={r1}"
+  __asm("lhi %0,5\n"
+: "={r1}"(a)
+:
+:);
+  __asm("lhi %0,5\n"
+: "=r"(c)
+:
+:);
+
+  // CHECK-COUNT-2: call i32 asm "lgr $0,$1\0A", "={r1},{r2}"
+  __asm("lgr %0,%1\n"
+: "={r1}"(a)
+: "{r2}"(b)
+:);
+  __asm("lgr %0,%1\n"
+: "=r"(c)
+: "r"(d)
+:);
+
+  // CHECK-COUNT-2: call i32 asm "lgr $0,$1\0A", "={r1},{r2}"
+  __asm("lgr %0,%1\n"
+: "={%r1}"(a)
+: "{%r2}"(b)
+:);
+  __asm("lgr %0,%1\n"
+: "={r1}"(a)
+: "{%r2}"(b)
+:);
+
+  // CHECK-COUNT-2: call i32 asm "lgr $0,$1\0A", "=&{r1},{r2}"
+  __asm("lgr %0,%1\n"
+: "=&{r1}"(a)
+: "{%r2}"(b)
+:);
+  __asm("lgr %0,%1\n"
+: "=&r"(c)
+: "r"(d)
+:);
+}
Index: clang/test/CodeGen/ms-intrinsics.c
===
--- clang/test/CodeGen/ms-intrinsics.c
+++ clang/test/CodeGen/ms-intrinsics.c
@@ -36,12 +36,12 @@
   return __movsb(Dest, Src, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__movsb
-// CHECK-I386:   call { i8*, i8*, i32 } asm sideeffect "rep movsb", "={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* %Src, i32 %Count)
+// CHECK-I386:   call { i8*, i8*, i32 } asm sideeffect "rep movsb", "={di},={si},={cx},{di},{si},{cx},~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* %Src, i32 %Count)
 // CHECK-I386:   ret void
 // CHECK-I386: }
 
 // CHECK-X64-LABEL: define{{.*}} void @test__movsb
-// CHECK-X64:   call { i8*, i8*, i64 } asm sideeffect "rep movsb", "={di},={si},={cx},0,1,2,~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* %Src, i64 %Count)
+// CHECK-X64:   call { i8*, i8*, i64 } asm sideeffect "rep movsb", "={di},={si},={cx},{di},{si},{cx},~{memory},~{dirflag},~{fpsr},~{flags}"(i8* %Dest, i8* %Src, i64 %Count)
 // CHECK-X64:   ret void
 // CHECK-X64: }
 
@@ -49,12 +49,12 @@
   return __stosw(Dest, Data, Count);
 }
 // CHECK-I386-LABEL: define{{.*}} void @test__stosw
-// CHECK-I386:   call { i16*, i32 } asm sideeffect "rep stosw", "={di},={cx},{ax},0,1,~{memory},~{dirflag},~{fpsr},~{flags}"(i16 %Data, i16* %Dest, i32 %Count)
+// CHECK-I386:   call { i16*, i32 } asm sideeffect "rep stosw", "={di},={cx},{ax},{di},{cx},~{memory},~{dirflag},~{fpsr},~{flags}"(i16 %Data, i16* %Dest, i32 %Count)
 // CHECK-I3

[PATCH] D105145: [clang][Fuchsia] Remove relative-vtables multilibs

2021-06-29 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr.
leonardchan added a project: clang.
Herald added a subscriber: mgorny.
leonardchan requested review of this revision.

As of D102374 , relative vtables is enabled 
on Fuchsia by default, so we don't need any of the RV multilibs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105145

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -222,41 +222,15 @@
 set(RUNTIMES_${target}+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE 
BOOL "")
 set(RUNTIMES_${target}+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE 
BOOL "")
 
-set(RUNTIMES_${target}+relative-vtables_LLVM_BUILD_COMPILER_RT OFF CACHE 
BOOL "")
-set(RUNTIMES_${target}+relative-vtables_CMAKE_CXX_FLAGS 
"${FUCHSIA_${target}_COMPILER_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
-
-set(RUNTIMES_${target}+relative-vtables+asan_LLVM_BUILD_COMPILER_RT OFF 
CACHE BOOL "")
-set(RUNTIMES_${target}+relative-vtables+asan_LLVM_USE_SANITIZER "Address" 
CACHE STRING "")
-
set(RUNTIMES_${target}+relative-vtables+asan_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
-
set(RUNTIMES_${target}+relative-vtables+asan_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
-set(RUNTIMES_${target}+relative-vtables+asan_CMAKE_CXX_FLAGS 
"${FUCHSIA_${target}_COMPILER_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
-
-set(RUNTIMES_${target}+relative-vtables+noexcept_LLVM_BUILD_COMPILER_RT 
OFF CACHE BOOL "")
-set(RUNTIMES_${target}+relative-vtables+noexcept_CMAKE_CXX_FLAGS 
"${FUCHSIA_${target}_COMPILER_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
-
set(RUNTIMES_${target}+relative-vtables+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
-set(RUNTIMES_${target}+relative-vtables+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
-
-
set(RUNTIMES_${target}+relative-vtables+asan+noexcept_LLVM_BUILD_COMPILER_RT 
OFF CACHE BOOL "")
-set(RUNTIMES_${target}+relative-vtables+asan+noexcept_LLVM_USE_SANITIZER 
"Address" CACHE STRING "")
-
set(RUNTIMES_${target}+relative-vtables+asan+noexcept_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
-
set(RUNTIMES_${target}+relative-vtables+asan+noexcept_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
 OFF CACHE BOOL "")
-
set(RUNTIMES_${target}+relative-vtables+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS
 OFF CACHE BOOL "")
-
set(RUNTIMES_${target}+relative-vtables+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS 
OFF CACHE BOOL "")
-set(RUNTIMES_${target}+relative-vtables+asan+noexcept_CMAKE_CXX_FLAGS 
"${FUCHSIA_${target}_COMPILER_FLAGS} -Xclang 
-fexperimental-relative-c++-abi-vtables" CACHE STRING "")
-
 # Use .build-id link.
 list(APPEND RUNTIME_BUILD_ID_LINK "${target}")
   endforeach()
 
-  set(LLVM_RUNTIME_MULTILIBS 
"asan;noexcept;compat;asan+noexcept;relative-vtables;relative-vtables+noexcept;relative-vtables+asan;relative-vtables+asan+noexcept"
 CACHE STRING "")
+  set(LLVM_RUNTIME_MULTILIBS "asan;noexcept;compat;asan+noexcept" CACHE STRING 
"")
   set(LLVM_RUNTIME_MULTILIB_asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_compat_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
   set(LLVM_RUNTIME_MULTILIB_asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
-  set(LLVM_RUNTIME_MULTILIB_relative-vtables_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
-  set(LLVM_RUNTIME_MULTILIB_relative-vtables+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
-  set(LLVM_RUNTIME_MULTILIB_relative-vtables+asan_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
-  set(LLVM_RUNTIME_MULTILIB_relative-vtables+asan+noexcept_TARGETS 
"x86_64-unknown-fuchsia;aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -222,41 +222,15 @@
 set(RUNTIMES_${target}+asan+noexcept_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
 set(RUNTIMES_${target}+asan+noexcept_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE BOOL "")
 
-set(RUNTIMES_${target}+relative-vtables_LLVM_BUILD_COMPILER_RT OFF CACHE BOOL "")
-set(RUNTIMES_${target}+relative-vtables_CMAKE_CXX_FLAGS "${FUCHSIA_${ta

[PATCH] D104388: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

2021-06-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

I can't help with C# part either, unfortunately.
I'll chime in if I see something strange, but current patch looks okay to me. I 
let other reviewers (@exv) accept it when they feel it's ok.




Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1793
   // FIXME: Once we have an expression parser in the UnwrappedLineParser,
   // replace this by using parseAssigmentExpression() inside.
   do {

Unrelated nit: typo in parseAssignment.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1797
+  // Fat arrows (=>) have tok::TokenKind tok::equal but TokenType
+  // TT_FatArrow. The always start an expression or a child block if
+  // followed by a curly.

"The*y* always"... ?



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1798
+  // TT_FatArrow. The always start an expression or a child block if
+  // followed by a curly.
   if (FormatTok->is(TT_FatArrow)) {

curly brace?


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

https://reviews.llvm.org/D104388

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


[PATCH] D104388: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

2021-06-29 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe accepted this revision.
jbcoe added a subscriber: krasimir.
jbcoe added a comment.

Some outstanding nits to address but this looks good to me.

With @krasimir I implemented a good fraction of the C# support and am confident 
that these changes are an improvement.


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

https://reviews.llvm.org/D104388

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


[PATCH] D105099: [clang-format] Add an option to put one constructor initializer per line

2021-06-29 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

Formatting part and tests look good to me, but I'd rather see this patch merge 
all related boolean options into one enum.
Just thinking out loud, but is it doable to merge 
AllowAllConstructorInitializersOnNextLine, 
ConstructorInitializerAllOnOneLineOrOnePerLine and this patch's 
ConstructorInitializerAlwaysOnePerLine into e.g. ConstructorInitializerStyle: 
AllowNextLine | NonBinPack==AllOnOneLineOrOnePerLine | OnePerLine. And one 
other enum value for the default case without special handling.
Of course, we'd need to keep that backward compatible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105099

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


[PATCH] D104601: [Preprocessor] Implement -fnormalize-whitespace.

2021-06-29 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 355350.
Meinersbur marked 6 inline comments as done.
Meinersbur added a comment.

- Address review by @aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/PreprocessorOutputOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/test/CXX/lex/lex.pptoken/p3-2a.cpp
  clang/test/Preprocessor/c99-6_10_3_4_p5.c
  clang/test/Preprocessor/c99-6_10_3_4_p6.c
  clang/test/Preprocessor/comment_save.c
  clang/test/Preprocessor/first-line-indent.c
  clang/test/Preprocessor/hash_line.c
  clang/test/Preprocessor/line-directive-output-normcol.c
  clang/test/Preprocessor/line-directive-output.c
  clang/test/Preprocessor/macro_space.c
  clang/test/Preprocessor/normalize-whitespace.c
  clang/test/Preprocessor/print_line_include.c
  clang/test/Preprocessor/stringize_space.c

Index: clang/test/Preprocessor/stringize_space.c
===
--- clang/test/Preprocessor/stringize_space.c
+++ clang/test/Preprocessor/stringize_space.c
@@ -1,16 +1,18 @@
 // RUN: %clang_cc1 -E %s | FileCheck --strict-whitespace %s
+// RUN: %clang_cc1 -E -P -fnormalize-whitespace %s | FileCheck --strict-whitespace %s --check-prefix=NORMWS
 
 #define A(b) -#b  ,  - #b  ,  -# b  ,  - # b
 A()
 
 // CHECK: {{^}}-"" , - "" , -"" , - ""{{$}}
-
+// NORMWS: {{^}}-"",-"",-"",-""
 
 #define t(x) #x
 t(a
 c)
 
 // CHECK: {{^}}"a c"{{$}}
+// NORMWS-SAME: "a c"
 
 #define str(x) #x
 #define f(x) str(-x)
@@ -18,6 +20,7 @@
 1)
 
 // CHECK: {{^}}"-1"
+// NORMWS-SAME: "-1"
 
 #define paste(a,b) str(a&1 | FileCheck %s --strict-whitespace --check-prefix=NORMCOL
+// RUN: %clang_cc1 -E -C -fnormalize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=NORMCCOL
+// RUN: %clang_cc1 -E -P -fnormalize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=NORMWS
+// RUN: %clang_cc1 -E -C -P -fnormalize-whitespace %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=NORMCWS
+
+#define NOT_OMP  omp  something
+#define HASH #
+
+  int  a; /*  span-comment  */
+  int  b  ;   //  line-comment
+  _Pragma  (  "omp  barrier"  ) x //  more line-comments
+  #pragma  omp  nothing  //  another comment
+HASH  pragma  NOT_OMP
+  int  e;// again a line
+  int  f  ;
+
+
+// NORMCOL:  {{^}}# 9 "{{.*}}normalize-whitespace.c"{{$}}
+// NORMCOL:  {{^}}int a;{{$}}
+// NORMCOL-NEXT: {{^}}int b;{{$}}
+// NORMCOL-NEXT: {{^}}#pragma omp barrier{{$}}
+// NORMCOL-NEXT: # 11 "{{.*}}normalize-whitespace.c"
+// NORMCOL-NEXT: {{^}}x{{$}}
+// NORMCOL-NEXT: {{^}}#pragma omp nothing{{$}}
+// NORMCOL-NEXT: {{^ }}#pragma omp something{{$}}
+// NORMCOL-NEXT: {{^}}int e;{{$}}
+// NORMCOL-NEXT: {{^}}int f;{{$}}
+
+// FIXME: Comments after pragmas disappear, even without -fnormalize-whitespace
+// NORMCCOL:  {{^}}# 9 "{{.*}}normalize-whitespace.c"{{$}}
+// NORMCCOL:  {{^}}int a;/*  span-comment  */{{$}}
+// NORMCCOL-NEXT: {{^}}int b;//  line-comment{{$}}
+// NORMCCOL-NEXT: {{^}}#pragma omp barrier{{$}}
+// NORMCCOL-NEXT: # 11 "{{.*}}normalize-whitespace.c"
+// NORMCCOL-NEXT: {{^}}x//  more line-comments{{$}}
+// NORMCCOL-NEXT: {{^}}#pragma omp nothing{{$}}
+// NORMCCOL-NEXT: {{^ }}#pragma omp something{{$}}
+// NORMCCOL-NEXT: {{^}}int e;// again a line{{$}}
+// NORMCCOL-NEXT: {{^}}int f;{{$}}
+
+// NORMWS:  {{^}}int a;int b;{{$}}
+// NORMWS-NEXT: {{^}}#pragma omp barrier{{$}}
+// NORMWS-NEXT: {{^}}x{{$}}
+// NORMWS-NEXT: {{^}}#pragma omp nothing{{$}}
+// NORMWS-NEXT: {{^ }}#pragma omp something int e;int f;{{$}}
+
+// FIXME: Comments after pragmas disappear, even without -fnormalize-whitespace
+// NORMCWS:  {{^}}int a;/*  span-comment  */int b;//  line-comment{{$}}
+// NORMCWS-NEXT: {{^}}#pragma omp barrier{{$}}
+// NORMCWS-NEXT: {{^}}x//  more line-comments{{$}}
+// NORMCWS-NEXT: {{^}}#pragma omp nothing{{$}}
+// NORMCWS-NEXT: {{^ }}#pragma omp something int e;// again a line{{$}}
+// NORMCWS-NEXT: {{^}}int f;
+
Index: clang/test/Preprocessor/macro_space.c
===
--- clang/test/Preprocessor/macro_space.c
+++ clang/test/Preprocessor/macro_space.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -E %s | FileCheck --strict-whitespace %s
+// RUN: %clang_cc1 -E -P -fnormalize-whitespace %s | FileCheck --strict-whitespace %s --check-prefix=NORMWS
 
 #define FOO1()
 #define FOO2(x)x
@@ -13,24 +14,32 @@
 
 TEST(FOO1,)
 // CHECK: FOO1 <> < > <> <> < > <> < > < >
+// NORMWS: FOO1<><><><><><><><>
 
 TEST(FOO2,)
 // CHECK: FOO2 <> < > <> <> < > <> < > < >
+// NORMWS-SAME: FOO2<><><><><><><><>
 
 TEST(FOO3,)
 // CHECK: FOO3 <> < > <> <> < > <> < > < >
+// NORMWS-SAME: FOO3<><><><><><><><>
 
 TEST(FOO4,)
 // CHECK: FOO4 < > < > < > < > < > < > < > 

[PATCH] D104601: [Preprocessor] Implement -fnormalize-whitespace.

2021-06-29 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

In D104601#2847400 , @aaron.ballman 
wrote:

> ... would add that it's very common for implementers to ask developers to run 
> their code through `-E` mode to submit preprocessed output in order to 
> reproduce a customer issue with the compiler, and I worry that uses of this 
> flag will have unintended consequences in that scenario.

Why would one add `-fnormalize-whitespace` for this use case?

> The "very long line" example mentioned by @dblaikie is sort of along these 
> lines (sorry for the bad pun).

I can add a forced line breaks (after/before 80 cols? configurable?) if 
requested.




Comment at: clang/lib/Frontend/PrintPreprocessedOutput.cpp:174
+  ///on being on the same line, such as directives.
+  void HandleWhitespaceBeforeTok(Token &Tok, bool RequireSpace,
+ bool RequireSameLine);

aaron.ballman wrote:
> Can `Tok` be `const Token &` instead?
Note that this is a renamed `bool HandleFirstTokOnLine(Token &Tok)`. Renamed 
because it is now called for every token.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104601

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


[PATCH] D104616: [analyzer] Model comparision methods of std::unique_ptr

2021-06-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I suspect that you might want to include `OperationKinds.def` instead of 
`OperationKinds.h`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104616

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


[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-06-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D104925#2846283 , @balazske wrote:

> I could not find a way to pass the needed information from the BugReport to 
> the `NoteTag`. The "sequence number" (in `EofSeqMap`) is only known when the 
> bug is detected, this should be passed to the `NoteTag` somehow.

You can //capture// it.

That's the whole point of note tags, to have access to all the information from 
both the bug report and the moment of time the event has happened.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

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


[PATCH] D105148: [CMake] Don't use -Bsymbolic-functions for MinGW targets

2021-06-29 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: MaskRay, phosek.
Herald added subscribers: fedor.sergeev, mgorny.
mstorsjo requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

This is an ELF specific option which isn't supported for Windows/MinGW
targets, even if the MinGW linker otherwise uses a ld.bfd like linker
interface.

In llvm-shlib, there's already a separate if statement for

  if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)

but I don't know if the solaris linker supports -Bsymbolic-functions
or not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105148

Files:
  clang/tools/clang-shlib/CMakeLists.txt
  llvm/tools/llvm-shlib/CMakeLists.txt


Index: llvm/tools/llvm-shlib/CMakeLists.txt
===
--- llvm/tools/llvm-shlib/CMakeLists.txt
+++ llvm/tools/llvm-shlib/CMakeLists.txt
@@ -50,11 +50,13 @@
   # Solaris ld does not accept global: *; so there is no way to version 
*all* global symbols
   set(LIB_NAMES 
-Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map
 ${LIB_NAMES})
 endif()
-# Optimize function calls for default visibility definitions to avoid PLT 
and
-# reduce dynamic relocations.
-# Note: for -fno-pic default, the address of a function may be different 
from
-# inside and outside libLLVM.so.
-target_link_options(LLVM PRIVATE LINKER:-Bsymbolic-functions)
+if (NOT MINGW)
+  # Optimize function calls for default visibility definitions to avoid 
PLT and
+  # reduce dynamic relocations.
+  # Note: for -fno-pic default, the address of a function may be different 
from
+  # inside and outside libLLVM.so.
+  target_link_options(LLVM PRIVATE LINKER:-Bsymbolic-functions)
+endif()
   elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
 set(LIB_NAMES -Wl,-all_load ${LIB_NAMES})
   endif()
Index: clang/tools/clang-shlib/CMakeLists.txt
===
--- clang/tools/clang-shlib/CMakeLists.txt
+++ clang/tools/clang-shlib/CMakeLists.txt
@@ -50,6 +50,6 @@
   ${_DEPS})
 # Optimize function calls for default visibility definitions to avoid PLT and
 # reduce dynamic relocations.
-if (NOT APPLE)
+if (NOT APPLE AND NOT MINGW)
   target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
 endif()


Index: llvm/tools/llvm-shlib/CMakeLists.txt
===
--- llvm/tools/llvm-shlib/CMakeLists.txt
+++ llvm/tools/llvm-shlib/CMakeLists.txt
@@ -50,11 +50,13 @@
   # Solaris ld does not accept global: *; so there is no way to version *all* global symbols
   set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
 endif()
-# Optimize function calls for default visibility definitions to avoid PLT and
-# reduce dynamic relocations.
-# Note: for -fno-pic default, the address of a function may be different from
-# inside and outside libLLVM.so.
-target_link_options(LLVM PRIVATE LINKER:-Bsymbolic-functions)
+if (NOT MINGW)
+  # Optimize function calls for default visibility definitions to avoid PLT and
+  # reduce dynamic relocations.
+  # Note: for -fno-pic default, the address of a function may be different from
+  # inside and outside libLLVM.so.
+  target_link_options(LLVM PRIVATE LINKER:-Bsymbolic-functions)
+endif()
   elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
 set(LIB_NAMES -Wl,-all_load ${LIB_NAMES})
   endif()
Index: clang/tools/clang-shlib/CMakeLists.txt
===
--- clang/tools/clang-shlib/CMakeLists.txt
+++ clang/tools/clang-shlib/CMakeLists.txt
@@ -50,6 +50,6 @@
   ${_DEPS})
 # Optimize function calls for default visibility definitions to avoid PLT and
 # reduce dynamic relocations.
-if (NOT APPLE)
+if (NOT APPLE AND NOT MINGW)
   target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104918: [clang-repl] Implement partial translation units and error recovery.

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

I'm (happily) surprised this required so few changes!




Comment at: clang/include/clang/Basic/LangOptions.h:690-691
+
+  /// The translation unit is a partial translation unit, growing 
incrementally.
+  TU_Partial
 };

I don't think this is clear enough about the difference between `TU_Prefix` and 
`TU_Partial`. I think the difference is:

* `TU_Prefix` is an incomplete prefix of a translation unit. Because it's not 
complete, we don't perform (most) finalization steps (eg, template 
instantiation) at the end.
* `TU_Partial` is a complete translation unit that we might nonetheless 
incrementally extend later. Because it is complete (and we might want to 
generate code for it), we do perform template instantiation, but because it 
might be extended later, we don't warn if it declares or uses undefined 
internal-linkage symbols.

I wonder if `TU_Incremental` would be a better name than `TU_Partial`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D104918

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


[PATCH] D105151: [OPENMP]Fix PR50733: unexpected final value of list-item in linear clause in loop construct.

2021-06-29 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added reviewers: mikerice, jdoerfert.
Herald added subscribers: guansong, yaxunl.
ABataev requested review of this revision.
Herald added a project: clang.

Currently the last value of linear is calculated as var = init + num_iters * 
step.
Replaced it with var = var_priv, i.e. original variable gets the value
of the last private copy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105151

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/for_linear_codegen.cpp
  clang/test/OpenMP/for_simd_codegen.cpp
  clang/test/OpenMP/parallel_for_linear_codegen.cpp
  clang/test/OpenMP/parallel_for_simd_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/simd_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp

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


[PATCH] D105017: [analyzer] LValueToRValueBitCasts should evaluate to an r-value

2021-06-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

So it worked out of the box? Great!


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

https://reviews.llvm.org/D105017

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


[PATCH] D105148: [CMake] Don't use -Bsymbolic-functions for MinGW targets

2021-06-29 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.

> but I don't know if the solaris linker supports -Bsymbolic-functions or not.

According to a Solaris "man pages section 1: User Commands", 
-Bsymbolic-functions is supported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105148

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


[PATCH] D105099: [clang-format] Add an option to put one constructor initializer per line

2021-06-29 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D105099#2847332 , @MyDeveloperDay 
wrote:

> We already have
>
> `AllowAllConstructorInitializersOnNextLine` and 
> `ConstructorInitializerAllOnOneLineOrOnePerLine`
>
> Sort of feels like we need to combine them with this,
>
> I should also say I'd quite like this functionality, its just how do we 
> deliver it via the options that I think we might want to think about, as I 
> sort of feel the 3 options (if we introduced another) are competing with each 
> other.

`AllowAllConstructorInitializersOnNextLine` is like a sub-option of 
`ConstructorInitializerAllOnOneLineOrOnePerLine`; it has no effect unless the 
latter is `true`. The new `ConstructorInitializerAlwaysOnePerLine` option, if 
set to `true`, overrides `ConstructorInitializerAllOnOneLineOrOnePerLine` as it 
should with //Always//. I think it would be contrived to combine these options 
in an enum. Is it even practical to do so without breaking the unit tests and 
backward compatibility?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105099

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


[clang] 8d21d54 - [CodeGen] Stop creating fake FunctionDecls when generating IR for

2021-06-29 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2021-06-29T14:22:33-07:00
New Revision: 8d21d5472501460933e78aead04cf59579025ba4

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

LOG: [CodeGen] Stop creating fake FunctionDecls when generating IR for
functions implicitly generated by the compiler

These fake functions would cause clang to crash if the changes proposed
in https://reviews.llvm.org/D98799 were made.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGNonTrivialStruct.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGen/constructor-attribute.c
clang/test/CodeGen/debug-info-oslog.c
clang/test/CodeGenObjC/nontrivial-c-struct-exception.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9579d706b2ae5..2f2d5e6c83d77 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1681,7 +1681,6 @@ llvm::Function 
*CodeGenFunction::generateBuiltinOSLogHelperFunction(
   }
 
   QualType ReturnTy = Ctx.VoidTy;
-  QualType FuncionTy = Ctx.getFunctionType(ReturnTy, ArgTys, {});
 
   // The helper function has linkonce_odr linkage to enable the linker to merge
   // identical functions. To ensure the merging always happens, 'noinline' is
@@ -1701,14 +1700,7 @@ llvm::Function 
*CodeGenFunction::generateBuiltinOSLogHelperFunction(
 Fn->addFnAttr(llvm::Attribute::NoInline);
 
   auto NL = ApplyDebugLocation::CreateEmpty(*this);
-  IdentifierInfo *II = &Ctx.Idents.get(Name);
-  FunctionDecl *FD = FunctionDecl::Create(
-  Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), 
II,
-  FuncionTy, nullptr, SC_PrivateExtern, false, false);
-  // Avoid generating debug location info for the function.
-  FD->setImplicit();
-
-  StartFunction(FD, ReturnTy, Fn, FI, Args);
+  StartFunction(GlobalDecl(), ReturnTy, Fn, FI, Args);
 
   // Create a scope with an artificial location for the body of this function.
   auto AL = ApplyDebugLocation::CreateArtificial(*this);

diff  --git a/clang/lib/CodeGen/CGNonTrivialStruct.cpp 
b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
index 9c6bbbc048b72..ad505fc5a0d4f 100644
--- a/clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ b/clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -472,14 +472,10 @@ template  struct GenFuncBase {
 F->setVisibility(llvm::GlobalValue::HiddenVisibility);
 CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, F, /*IsThunk=*/false);
 CGM.SetLLVMFunctionAttributesForDefinition(nullptr, F);
-IdentifierInfo *II = &Ctx.Idents.get(FuncName);
-FunctionDecl *FD = FunctionDecl::Create(
-Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
-II, Ctx.getFunctionType(Ctx.VoidTy, llvm::None, {}), nullptr,
-SC_PrivateExtern, false, false);
 CodeGenFunction NewCGF(CGM);
 setCGF(&NewCGF);
-CGF->StartFunction(FD, Ctx.VoidTy, F, FI, Args);
+CGF->StartFunction(GlobalDecl(), Ctx.VoidTy, F, FI, Args);
+auto AL = ApplyDebugLocation::CreateArtificial(*CGF);
 std::array Addrs =
 getParamAddrs(std::make_index_sequence{}, Alignments, Args, CGF);
 asDerived().visitStructFields(QT, CharUnits::Zero(), Addrs);

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 183ec7c2842f2..cf277ca347e43 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2611,15 +2611,6 @@ static llvm::Function 
*createGlobalInitOrCleanupFn(CodeGen::CodeGenModule &CGM,
   return GlobalInitOrCleanupFn;
 }
 
-static FunctionDecl *
-createGlobalInitOrCleanupFnDecl(CodeGen::CodeGenModule &CGM, StringRef FnName) 
{
-  ASTContext &Ctx = CGM.getContext();
-  QualType FunctionTy = Ctx.getFunctionType(Ctx.VoidTy, llvm::None, {});
-  return FunctionDecl::Create(
-  Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
-  &Ctx.Idents.get(FnName), FunctionTy, nullptr, SC_Static, false, false);
-}
-
 void CodeGenModule::unregisterGlobalDtorsWithUnAtExit() {
   for (const auto &I : DtorsUsingAtExit) {
 int Priority = I.first;
@@ -2629,13 +2620,11 @@ void CodeGenModule::unregisterGlobalDtorsWithUnAtExit() 
{
 llvm::Function *GlobalCleanupFn =
 createGlobalInitOrCleanupFn(*this, GlobalCleanupFnName);
 
-FunctionDecl *GlobalCleanupFD =
-createGlobalInitOrCleanupFnDecl(*this, GlobalCleanupFnName);
-
 CodeGenFunction CGF(*this);
-CGF.StartFunction(GlobalDecl(GlobalCleanupFD), getContext().VoidTy,
-  GlobalCleanupFn, getTypes().arrangeNullaryFunction(),
-  FunctionArgList(), SourceLocation(), SourceLocation());
+CGF.StartFunction(GlobalDecl(), getContext().VoidTy, GlobalCleanupFn,
+  getTypes().a

  1   2   >