[PATCH] D99121: [IR][InstCombine] IntToPtr Produces Typeless Pointer To Byte

2021-03-25 Thread Ruiling, Song via Phabricator via cfe-commits
ruiling added a comment.

>> Sounds we still need a long way to get there? Do we think the patch 
>> acceptable as a short-term solution?
>
> Guess it's a tradeoff. Doesn't look like a load of code/complexity. - but 
> equally, does it provide much value? Or is it enough to know it can 
> eventually be addressed in a more general manner?

I don't have an answer for the second question, but this change would make 
later pass like `ScalarEvolution` can know the two pointers from the same 
integer by `inttoptr` are identical. Then we can merge possible consecutive 
memory access based on such pointers, we observed about 2% overall performance 
improvement for a critical workload.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99121

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


[PATCH] D99319: [RISCV] [2/2] Add intrinsic for Zbr extension

2021-03-25 Thread LevyHsu via Phabricator via cfe-commits
LevyHsu created this revision.
LevyHsu added reviewers: craig.topper, jrtc27, kito-cheng.
LevyHsu added projects: clang, LLVM.
Herald added subscribers: vkmr, frasercrmck, evandro, luismarques, apazos, 
sameer.abuasal, usaxena95, s.egerton, Jim, benna, psnobl, kadircet, jocewei, 
PkmX, arphaman, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, mgorny.
LevyHsu requested review of this revision.
Herald added a subscriber: cfe-commits.
Herald added a project: clang-tools-extra.

Implementation for RISC-V Zbb extension intrinsic.

Head files are included in the second patch in case the name needs to be 
changed.

RV32 / 64:
orc.b


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99319

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_zbb_intrin.h
  clang/lib/Headers/rvintrin.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Headers/rvintrin.c

Index: clang/test/Headers/rvintrin.c
===
--- /dev/null
+++ clang/test/Headers/rvintrin.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple riscv32 -fsyntax-only \
+// RUN:   -target-feature +experimental-zbb %s
+// RUN: %clang_cc1 -triple riscv64 -fsyntax-only \
+// RUN:   -target-feature +experimental-zbb %s
+
+#include 
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3395,13 +3395,28 @@
  CallExpr *TheCall) {
   // CodeGenFunction can also detect this, but this gives a better error
   // message.
+  bool miss_feature_error = false;
+  SmallVector ReqFeatures;
   StringRef Features = Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
-  if (Features.find("experimental-v") != StringRef::npos &&
-  !TI.hasFeature("experimental-v"))
-return Diag(TheCall->getBeginLoc(), diag::err_riscvv_builtin_requires_v)
-   << TheCall->getSourceRange();
-
-  return false;
+  StringRef(Features).split(ReqFeatures, ',');
+  
+  // Check if each required feature is included in TargetInfo
+  for (size_t i = 0; i < ReqFeatures.size(); i++) {
+if (!TI.hasFeature(ReqFeatures[i])) {
+  
+  // Make message like "experimental-zbr" to "Zbr"
+  ReqFeatures[i].consume_front("experimental-");
+  std::string FeatureStr = ReqFeatures[i].str();
+  FeatureStr[0] = std::toupper(FeatureStr[0]);
+  
+  // Error message
+  miss_feature_error = true;
+  Diag(TheCall->getBeginLoc(), diag::err_riscv_builtin_requires_extension)
+  << TheCall->getSourceRange() << StringRef(FeatureStr);
+}
+  }
+
+  return miss_feature_error;
 }
 
 bool Sema::CheckSystemZBuiltinFunctionCall(unsigned BuiltinID,
Index: clang/lib/Headers/rvintrin.h
===
--- /dev/null
+++ clang/lib/Headers/rvintrin.h
@@ -0,0 +1,28 @@
+/* === rvintrin.h --===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __RVINTRIN_H
+#define __RVINTRIN_H
+
+// Long is 32 bit on riscv32 and 64 bit on riscv64 according to calling 
+// convention.
+#define int_xlen_t long
+#define uint_xlen_t unsigned int_xlen_t
+
+#define __DEFAULT_FN_ATTRS \
+  __attribute__((__always_inline__, __artificial__, __nodebug__))
+
+#if defined(__riscv_zbb)
+#include "riscv_zbb_intrin.h"
+#endif
+
+#undef __DEFAULT_FN_ATTRS
+#undef uint_xlen_t
+#undef int_xlen_t
+#endif // __RVINTRIN_H
Index: clang/lib/Headers/riscv_zbb_intrin.h
===
--- /dev/null
+++ clang/lib/Headers/riscv_zbb_intrin.h
@@ -0,0 +1,26 @@
+/* === riscv_zbb_intrin.h --===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __RISCV_ZBB_INTRIN_H
+#define __RISCV_ZBB_INTRIN_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+// Zbb
+static __inline__ int_xlen_t __DEFAULT_FN_ATTRS _rv_orc_b(int_xlen_t rs1) {
+  return __builtin_riscv_orc_b(rs1);
+}
+
+#if defined(__cplusplus)   

[PATCH] D99320: [RISCV] [1/2] Add intrinsic for Zbb extension

2021-03-25 Thread LevyHsu via Phabricator via cfe-commits
LevyHsu created this revision.
LevyHsu added reviewers: craig.topper, jrtc27, kito-cheng.
LevyHsu added projects: clang, LLVM.
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, shiva0217, niosHD, 
sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
LevyHsu requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.

Implementation for RISC-V Zbb extension intrinsic.

Head files are included in the second patch in case the name needs to be 
changed.

RV32 / 64:
orc.b


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99320

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoB.td
  llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
  llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll

Index: llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv64zbb-intrinsic.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-b -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64IB
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbb -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV64IBB
+
+declare i64 @llvm.riscv.orc.b.i64(i64)
+
+define i64 @orcb(i64 %a) nounwind {
+; RV64IB-LABEL: orcb:
+; RV64IB:   # %bb.0:
+; RV64IB-NEXT:orc.b a0, a0
+; RV64IB-NEXT:ret
+;
+; RV64IBB-LABEL: orcb:
+; RV64IBB:   # %bb.0:
+; RV64IBB-NEXT:orc.b a0, a0
+; RV64IBB-NEXT:ret
+  %tmp = call i64 @llvm.riscv.orc.b.i64(i64 %a)
+ ret i64 %tmp
+}
Index: llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rv32zbb-intrinsic.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-b -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV32IB
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s -check-prefix=RV32IBB
+
+declare i32 @llvm.riscv.orc.b.i32(i32)
+
+define i32 @orcb(i32 %a) nounwind {
+; RV32IB-LABEL: orcb:
+; RV32IB:   # %bb.0:
+; RV32IB-NEXT:orc.b a0, a0
+; RV32IB-NEXT:ret
+;
+; RV32IBB-LABEL: orcb:
+; RV32IBB:   # %bb.0:
+; RV32IBB-NEXT:orc.b a0, a0
+; RV32IBB-NEXT:ret
+  %tmp = call i32 @llvm.riscv.orc.b.i32(i32 %a)
+ ret i32 %tmp
+}
Index: llvm/lib/Target/RISCV/RISCVInstrInfoB.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -874,3 +874,7 @@
(SRLIWPat GPR:$rs1, (i64 16,
   (PACKUW GPR:$rs1, GPR:$rs2)>;
 } // Predicates = [HasStdExtZbp, IsRV64]
+
+let Predicates = [HasStdExtZbb] in {
+def : PatGpr;
+} // Predicates = [HasStdExtZbb]
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -825,6 +825,8 @@
 
 /// Generic pattern classes
 
+class PatGpr
+: Pat<(OpNode GPR:$rs1), (Inst GPR:$rs1)>;
 class PatGprGpr
 : Pat<(OpNode GPR:$rs1, GPR:$rs2), (Inst GPR:$rs1, GPR:$rs2)>;
 class PatGprSimm12
Index: llvm/include/llvm/IR/IntrinsicsRISCV.td
===
--- llvm/include/llvm/IR/IntrinsicsRISCV.td
+++ llvm/include/llvm/IR/IntrinsicsRISCV.td
@@ -10,6 +10,20 @@
 //
 //===--===//
 
+//===--===//
+// RISC-V Bitmanip (Bit Manipulation) Extension
+// Zbb extension part
+
+let TargetPrefix = "riscv" in {
+  
+class BitMan_GPR_Intrinsics
+: Intrinsic<[llvm_any_ty], [llvm_any_ty],
+[IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
+  
+def int_riscv_orc_b : BitMan_GPR_Intrinsics;
+
+} // TargetPrefix = "riscv"
+
 //===--===//
 // Atomics
 
Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
@@ -0,0 +1,15 @@
+// NOTE: Assertions have been autogenerated by utils/updat

[PATCH] D99321: [clang] Always execute multi-stage install steps

2021-03-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai created this revision.
smeenai added reviewers: beanz, phosek, tstellar.
Herald added a subscriber: mgorny.
smeenai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We want installs to be executed even if binaries haven't changed, e.g.
so that we can install to multiple places. This is consistent with how
non-multi-stage install targets (e.g. the regular install-distribution
target) behave.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99321

Files:
  clang/CMakeLists.txt


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -867,10 +867,23 @@
 # exclude from main target
 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES 
_EP_${target}_EXCLUDE_FROM_MAIN On)
 
+# Install targets have side effects, so we always want to execute them.
+# "install" is reserved by CMake and can't be used as a step name for
+# ExternalProject_Add_Step, so we can match against "^install-" instead of
+# "^install" to get a tighter match. CMake's installation scripts already
+# skip up-to-date files, so there's no behavior change if you install to 
the
+# same destination multiple times.
+if(target MATCHES "^install-")
+  set(step_always ON)
+else()
+  set(step_always OFF)
+endif()
+
 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
   COMMAND ${CMAKE_COMMAND} --build  --target ${target}
   COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
   DEPENDEES configure
+  ALWAYS ${step_always}
   USES_TERMINAL 1
 )
 


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -867,10 +867,23 @@
 # exclude from main target
 set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
 
+# Install targets have side effects, so we always want to execute them.
+# "install" is reserved by CMake and can't be used as a step name for
+# ExternalProject_Add_Step, so we can match against "^install-" instead of
+# "^install" to get a tighter match. CMake's installation scripts already
+# skip up-to-date files, so there's no behavior change if you install to the
+# same destination multiple times.
+if(target MATCHES "^install-")
+  set(step_always ON)
+else()
+  set(step_always OFF)
+endif()
+
 ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
   COMMAND ${CMAKE_COMMAND} --build  --target ${target}
   COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
   DEPENDEES configure
+  ALWAYS ${step_always}
   USES_TERMINAL 1
 )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99322: [clang] Pass option directly to command. NFC

2021-03-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai created this revision.
smeenai added reviewers: beanz, phosek, tstellar.
Herald added a subscriber: mgorny.
smeenai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This code was written back when LLVM's minimum required CMake version
was 2.8.8, and I assume ExternalProject_Add_Step didn't take this option
at that point. It does now though, so we should just use the option.
Setting the _EP_* property is entirely equivalent (and is in fact how
these commands behave internally), but that also feels like an internal
implementation detail we shouldn't be relying on.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99322

Files:
  clang/CMakeLists.txt


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -864,9 +864,6 @@
 set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all)
   endif()
   foreach(target ${CLANG_BOOTSTRAP_TARGETS})
-# exclude from main target
-set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES 
_EP_${target}_EXCLUDE_FROM_MAIN On)
-
 # Install targets have side effects, so we always want to execute them.
 # "install" is reserved by CMake and can't be used as a step name for
 # ExternalProject_Add_Step, so we can match against "^install-" instead of
@@ -884,6 +881,7 @@
   COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
   DEPENDEES configure
   ALWAYS ${step_always}
+  EXCLUDE_FROM_MAIN ON
   USES_TERMINAL 1
 )
 


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -864,9 +864,6 @@
 set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all)
   endif()
   foreach(target ${CLANG_BOOTSTRAP_TARGETS})
-# exclude from main target
-set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
-
 # Install targets have side effects, so we always want to execute them.
 # "install" is reserved by CMake and can't be used as a step name for
 # ExternalProject_Add_Step, so we can match against "^install-" instead of
@@ -884,6 +881,7 @@
   COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
   DEPENDEES configure
   ALWAYS ${step_always}
+  EXCLUDE_FROM_MAIN ON
   USES_TERMINAL 1
 )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99319: [RISCV] [2/2] Add intrinsic for Zbb extension

2021-03-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Headers/riscv_zbb_intrin.h:18
+// Zbb
+static __inline__ int_xlen_t __DEFAULT_FN_ATTRS _rv_orc_b(int_xlen_t rs1) {
+  return __builtin_riscv_orc_b(rs1);

I think rather than int_xlen_t we want an int32_t version for RV32/RV64 and an 
int64_t version for RV64. I think it is safe to use the 64-bit orc.b 
instruction for int32_t on RV64 since each output byte is only affected by the 
bits in the same input byte. So we can put garbage in the upper 4 bytes and 
ignore the results in the upper bytes.

We couldn't do this for crc32(c) from Zbr.



Comment at: clang/lib/Sema/SemaChecking.cpp:3398
   // message.
+  bool miss_feature_error = false;
+  SmallVector ReqFeatures;

Variable names should start with capital letter and use CamelCase. No 
underscores.



Comment at: clang/lib/Sema/SemaChecking.cpp:3415
+  Diag(TheCall->getBeginLoc(), diag::err_riscv_builtin_requires_extension)
+  << TheCall->getSourceRange() << StringRef(FeatureStr);
+}

Please run clang-format on this line. There are instructions here for running 
clang-format on a patch 
https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99319

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


[PATCH] D99320: [RISCV] [1/2] Add intrinsic for Zbb extension

2021-03-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Please upload the patch using arcanist or using -U99 when generating the 
diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99320

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


[PATCH] D99319: [RISCV] [2/2] Add intrinsic for Zbb extension

2021-03-25 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Headers/riscv_zbb_intrin.h:18
+// Zbb
+static __inline__ int_xlen_t __DEFAULT_FN_ATTRS _rv_orc_b(int_xlen_t rs1) {
+  return __builtin_riscv_orc_b(rs1);

craig.topper wrote:
> I think rather than int_xlen_t we want an int32_t version for RV32/RV64 and 
> an int64_t version for RV64. I think it is safe to use the 64-bit orc.b 
> instruction for int32_t on RV64 since each output byte is only affected by 
> the bits in the same input byte. So we can put garbage in the upper 4 bytes 
> and ignore the results in the upper bytes.
> 
> We couldn't do this for crc32(c) from Zbr.
To do this you'll need to modify ReplaceNodeResults in RISCVISelLowering.cpp to 
detect the this intrinsic. I think there's already handling for some other 
intrinsics in there. Look for INTRINSIC_WO_CHAIN. For this you need to add an 
ANY_EXTEND to the operand, create a new INTRINSIC_WO_CHAIN node with i64 type, 
and truncate the result back to i32.

I think you'll need this in the RISCVTargetLowering constructor when Zbb is 
enabled. We only do it for the V extension right now.
```
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i32, Custom);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99319

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


[PATCH] D99278: [clang][parser] Allow GNU-style attributes in struct declarations

2021-03-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 333226.

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

https://reviews.llvm.org/D99278

Files:
  clang/lib/Parse/ParseDeclCXX.cpp


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1933,7 +1933,8 @@
TemplateParams ? TemplateParams->size() : 0));
   } else {
 if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition)
-  ProhibitAttributes(attrs);
+  ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
+  /* DiagnoseEmptyAttrs=*/true);
 
 if (TUK == Sema::TUK_Definition &&
 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {


Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -1933,7 +1933,8 @@
TemplateParams ? TemplateParams->size() : 0));
   } else {
 if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition)
-  ProhibitAttributes(attrs);
+  ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
+  /* DiagnoseEmptyAttrs=*/true);
 
 if (TUK == Sema::TUK_Definition &&
 TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99321: [clang] Always execute multi-stage install steps

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99321

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


[PATCH] D99182: [NFC] Reordering parameters in getFile and getFileOrSTDIN

2021-03-25 Thread James Henderson via Phabricator via cfe-commits
jhenderson accepted this revision.
jhenderson added a comment.
This revision is now accepted and ready to land.

LGTM, with nit.




Comment at: llvm/lib/Support/MemoryBuffer.cpp:275
+  return getFileAux(
+  Filename, /*MapSize=*/-1, 0, /*IsText=*/false,
+  /*RequiresNullTerminator=*/false, IsVolatile);

Whilst you're modifying, add the named parameter comment for the `0`, so that 
it's not just a magic number.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99182

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


[PATCH] D91466: [WIP][clang][Fuchsia] Support HWASan for Fuchsia

2021-03-25 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

@leonardchan would it be possible to break up this patch into multiple changes:

- Clang driver
- Cache file
- `hwasan_new_delete.cpp`
- `HWAddressSanitizer.cpp`
- `sanitizer_platform_limits_fuchsia.h`
- `sanitizer_symbolizer_markup.cpp`
- the rest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91466

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


[PATCH] D99037: [Matrix] Implement explicit type conversions for matrix types

2021-03-25 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D99037#2649065 , @SaurabhJha wrote:

> Hey @fhahn ,
>
> I realise, as you pointed out before, that we need to do some changes in 
> CodeGen too. I think its going to be more involved so before starting on 
> that, it would be great if you can confirm whether I am on the right path. I 
> will describe what I did, what happened, and what I inferred from that.
>
> I ran this simple cast.
>
>   typedef char cx4x4 __attribute__((matrix_type(4, 4)));
>   typedef int ix4x4 __attribute__((matrix_type(4, 4)));
>   cx4x4 c = (cx4x4) i;
>
> This crashed the compiler with this stack trace.
>
>   clang: /tmp/llvm/lib/IR/Instructions.cpp:2934: static llvm::CastInst 
> *llvm::CastInst::Create(Instruction::CastOps, llvm::Value *, llvm::Type *, 
> const llvm::Twine &, llvm::Instruction *): Assertion `castIsValid(op, S, Ty) 
> && "Invalid cast!"' failed.
>   PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
> backtrace, preprocessed source, and associated run script.
>   Stack dump:
>   0.  Program arguments: /tmp/build/bin/clang -cc1 -internal-isystem 
> /tmp/build/lib/clang/13.0.0/include -nostdsysteminc -fenable-matrix -triple 
> x86_64-apple-darwin /tmp/clang/test/CodeGen/matrix-cast.c -emit-llvm 
> -disable-llvm-passes -o -
>   1.   parser at end of file
>   2.  /tmp/clang/test/CodeGen/matrix-cast.c:15:6: LLVM IR generation of 
> declaration 'cast_char_matrix_to_int_same_size'
>   3.  /tmp/clang/test/CodeGen/matrix-cast.c:15:6: Generating code for 
> declaration 'cast_char_matrix_to_int_same_size'
>#0 0x0972648a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
> /tmp/llvm/lib/Support/Unix/Signals.inc:565:11
>#1 0x0972665b PrintStackTraceSignalHandler(void*) 
> /tmp/llvm/lib/Support/Unix/Signals.inc:632:1
>#2 0x09724c4b llvm::sys::RunSignalHandlers() 
> /tmp/llvm/lib/Support/Signals.cpp:70:5
>#3 0x09726dd1 SignalHandler(int) 
> /tmp/llvm/lib/Support/Unix/Signals.inc:407:1
>#4 0x7ff3d17353c0 __restore_rt 
> (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
>#5 0x7ff3d11e618b raise 
> /build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
>#6 0x7ff3d11c5859 abort 
> /build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
>#7 0x7ff3d11c5729 get_sysdep_segment_value 
> /build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:509:8
>#8 0x7ff3d11c5729 _nl_load_domain 
> /build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:970:34
>#9 0x7ff3d11d6f36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
>   #10 0x08a5c1bf llvm::CastInst::Create(llvm::Instruction::CastOps, 
> llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) 
> /tmp/llvm/lib/IR/Instructions.cpp:2936:11
>   #11 0x06205834 
> llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, 
> llvm::Type*, llvm::Twine const&) /tmp/llvm/include/llvm/IR/IRBuilder.h:2106:52
>   #12 0x061ef472 llvm::IRBuilderBase::CreateBitCast(llvm::Value*, 
> llvm::Type*, llvm::Twine const&) /tmp/llvm/include/llvm/IR/IRBuilder.h:2065:5
>   #13 0x09fb1140 (anonymous 
> namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) 
> /tmp/clang/lib/CodeGen/CGExprScalar.cpp:2069:5
>   #14 0x09fb002e (anonymous 
> namespace)::ScalarExprEmitter::VisitExplicitCastExpr(clang::ExplicitCastExpr*)
>  /tmp/clang/lib/CodeGen/CGExprScalar.cpp:563:5
>   #15 0x09fa8493 clang::StmtVisitorBase namespace)::ScalarExprEmitter, 
> llvm::Value*>::VisitCStyleCastExpr(clang::CStyleCastExpr*) 
> /tmp/build/tools/clang/include/clang/AST/StmtNodes.inc:879:1
>   #16 0x09fa2747 clang::StmtVisitorBase namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) 
> /tmp/build/tools/clang/include/clang/AST/StmtNodes.inc:879:1
>   #17 0x09f976fb (anonymous 
> namespace)::ScalarExprEmitter::Visit(clang::Expr*) 
> /tmp/clang/lib/CodeGen/CGExprScalar.cpp:410:3
>   #18 0x09fa4f82 (anonymous 
> namespace)::ScalarExprEmitter::VisitBinAssign(clang::BinaryOperator const*) 
> /tmp/clang/lib/CodeGen/CGExprScalar.cpp:4168:9
>   #19 0x09fa157d clang::StmtVisitorBase namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) 
> /tmp/clang/include/clang/AST/StmtVisitor.h:72:26
>   #20 0x09f976fb (anonymous 
> namespace)::ScalarExprEmitter::Visit(clang::Expr*) 
> /tmp/clang/lib/CodeGen/CGExprScalar.cpp:410:3
>   #21 0x09f97656 
> clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) 
> /tmp/clang/lib/CodeGen/CGExprScalar.cpp:4757:3
>   #22 0x09e5638c 
> clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, 
> clang::CodeGen::AggValueSlot, bool) /tmp/clang/lib/CodeGen/CGExpr.cpp:218:12
>   #23 0x09e562bd 
> clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) 
> /tmp/clang/lib/CodeGen/CGExpr.cpp:203:19
>   #24 0x09fc3616 
> clang::CodeGen::CodeGenF

[PATCH] D99319: [RISCV] [2/2] Add intrinsic for Zbb extension

2021-03-25 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: clang/lib/Headers/riscv_zbb_intrin.h:18
+// Zbb
+static __inline__ int_xlen_t __DEFAULT_FN_ATTRS _rv_orc_b(int_xlen_t rs1) {
+  return __builtin_riscv_orc_b(rs1);

craig.topper wrote:
> craig.topper wrote:
> > I think rather than int_xlen_t we want an int32_t version for RV32/RV64 and 
> > an int64_t version for RV64. I think it is safe to use the 64-bit orc.b 
> > instruction for int32_t on RV64 since each output byte is only affected by 
> > the bits in the same input byte. So we can put garbage in the upper 4 bytes 
> > and ignore the results in the upper bytes.
> > 
> > We couldn't do this for crc32(c) from Zbr.
> To do this you'll need to modify ReplaceNodeResults in RISCVISelLowering.cpp 
> to detect the this intrinsic. I think there's already handling for some other 
> intrinsics in there. Look for INTRINSIC_WO_CHAIN. For this you need to add an 
> ANY_EXTEND to the operand, create a new INTRINSIC_WO_CHAIN node with i64 
> type, and truncate the result back to i32.
> 
> I think you'll need this in the RISCVTargetLowering constructor when Zbb is 
> enabled. We only do it for the V extension right now.
> ```
> setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i32, Custom);
> ```
In Claire's proposal, there is 3 different version of intrinsic for orc.b:
- _rv_orc_b for int_xlen_t
- _rv32_orc_b for int32_t only
- _rv64_orc_b for int64_t only

https://github.com/riscv/riscv-bitmanip/blob/master/cproofs/rvintrin.h#L989


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99319

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


[clang] d9abcdd - [clang-format] Fix ObjC method indent after f7f9f94b

2021-03-25 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2021-03-25T10:52:08+01:00
New Revision: d9abcdd9f471ab0d986197e94498a5cf90aa12ef

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

LOG: [clang-format] Fix ObjC method indent after f7f9f94b

Commit
https://github.com/llvm/llvm-project/commit/f7f9f94b2e2b4c714bac9036f6b73a3df42daaff
changed the indent of ObjC method arguments from +4 to +2, if the method
occurs after a block statement.  I believe this was unintentional and there
was insufficient ObjC test coverage to catch this.

Example: `clang-format -style=google test.mm`

before:
```
void a(int c) {
  if (c) {
f();
  }
  [
  e:^(fff ) {
f(S, c);
  }];
}
```

after:
```
void a(int c) {
  if (c) {
f();
  }
  [
e:^(fff ) {
  f(S, c);
}];
}
```

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestObjC.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 1404d4a8eaeb..e424fcb34219 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -649,7 +649,6 @@ void UnwrappedLineParser::parseBlock(bool 
MustBeDeclaration, unsigned AddLevels,
 nextToken();
 
   Line->Level = InitialLevel;
-  FormatTok->setBlockKind(BK_Block);
 
   if (PPStartHash == PPEndHash) {
 Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;

diff  --git a/clang/unittests/Format/FormatTestObjC.cpp 
b/clang/unittests/Format/FormatTestObjC.cpp
index c33f93bcf99d..aa27f6ecf93b 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -977,6 +977,19 @@ TEST_F(FormatTestObjC, FormatObjCMethodExpr) {
   "performSelectorOnMainThread:@selector(loadAccessories)\n"
   " withObject:nil\n"
   "  waitUntilDone:false];");
+
+  // The appropriate indentation is used after a block statement.
+  Style.ContinuationIndentWidth = 4;
+  verifyFormat(
+  "void a(int c) {\n"
+  "  if (c) {\n"
+  "f();\n"
+  "  }\n"
+  "  [\n"
+  "  e:^(fff ) {\n"
+  "f(S, c);\n"
+  "  }];\n"
+  "}");
 }
 
 TEST_F(FormatTestObjC, ObjCAt) {



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


[PATCH] D99063: [clang-format] Fix ObjC method indent after f7f9f94b

2021-03-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd9abcdd9f471: [clang-format] Fix ObjC method indent after 
f7f9f94b (authored by krasimir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99063

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


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -977,6 +977,19 @@
   "performSelectorOnMainThread:@selector(loadAccessories)\n"
   " withObject:nil\n"
   "  waitUntilDone:false];");
+
+  // The appropriate indentation is used after a block statement.
+  Style.ContinuationIndentWidth = 4;
+  verifyFormat(
+  "void a(int c) {\n"
+  "  if (c) {\n"
+  "f();\n"
+  "  }\n"
+  "  [\n"
+  "  e:^(fff ) {\n"
+  "f(S, c);\n"
+  "  }];\n"
+  "}");
 }
 
 TEST_F(FormatTestObjC, ObjCAt) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -649,7 +649,6 @@
 nextToken();
 
   Line->Level = InitialLevel;
-  FormatTok->setBlockKind(BK_Block);
 
   if (PPStartHash == PPEndHash) {
 Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -977,6 +977,19 @@
   "performSelectorOnMainThread:@selector(loadAccessories)\n"
   " withObject:nil\n"
   "  waitUntilDone:false];");
+
+  // The appropriate indentation is used after a block statement.
+  Style.ContinuationIndentWidth = 4;
+  verifyFormat(
+  "void a(int c) {\n"
+  "  if (c) {\n"
+  "f();\n"
+  "  }\n"
+  "  [\n"
+  "  e:^(fff ) {\n"
+  "f(S, c);\n"
+  "  }];\n"
+  "}");
 }
 
 TEST_F(FormatTestObjC, ObjCAt) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -649,7 +649,6 @@
 nextToken();
 
   Line->Level = InitialLevel;
-  FormatTok->setBlockKind(BK_Block);
 
   if (PPStartHash == PPEndHash) {
 Line->MatchingOpeningBlockLineIndex = OpeningLineIndex;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98574: [Sparc] Define the same macros for -mcpu=v9 as GCC on Linux and the BSDs

2021-03-25 Thread Rainer Orth via Phabricator via cfe-commits
ro added inline comments.



Comment at: clang/lib/Basic/Targets/Sparc.cpp:246-256
+  if (getTriple().getOS() == llvm::Triple::Linux) {
 Builder.defineMacro("__sparc_v9__");
-Builder.defineMacro("__sparcv9__");
+  } else {
+Builder.defineMacro("__sparcv9");
+// Solaris doesn't need these variants, but the BSDs do.
+if (getTriple().getOS() != llvm::Triple::Solaris) {
+  Builder.defineMacro("__sparc64__");

glaubitz wrote:
> jrtc27 wrote:
> > This doesn't need changing, we can define more things than GCC to keep it 
> > simple.
> Well, my original intent was to match GCC to make sure we're 100% compatible 
> and I would like to keep it that way.
I agree with Jessica here: you're creating a complicated maze for no real gain. 
 Besides, have you checked what `gcc` on the BSDs really does?  They often 
neglect to get their changes upstream and what's in the gcc repo doesn't 
necessarily represent what they actually use.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98574

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


[PATCH] D98574: [Sparc] Define the same macros for -mcpu=v9 as GCC on Linux and the BSDs

2021-03-25 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz marked an inline comment as done.
glaubitz added inline comments.



Comment at: clang/lib/Basic/Targets/Sparc.cpp:246-256
+  if (getTriple().getOS() == llvm::Triple::Linux) {
 Builder.defineMacro("__sparc_v9__");
-Builder.defineMacro("__sparcv9__");
+  } else {
+Builder.defineMacro("__sparcv9");
+// Solaris doesn't need these variants, but the BSDs do.
+if (getTriple().getOS() != llvm::Triple::Solaris) {
+  Builder.defineMacro("__sparc64__");

ro wrote:
> glaubitz wrote:
> > jrtc27 wrote:
> > > This doesn't need changing, we can define more things than GCC to keep it 
> > > simple.
> > Well, my original intent was to match GCC to make sure we're 100% 
> > compatible and I would like to keep it that way.
> I agree with Jessica here: you're creating a complicated maze for no real 
> gain.  Besides, have you checked what `gcc` on the BSDs really does?  They 
> often neglect to get their changes upstream and what's in the gcc repo 
> doesn't necessarily represent what they actually use.
Yes, I have verified that GCC behaves the exact same way as this change and I 
don't see any reason not to mimic the exact same behavior in clang for maximum 
compatibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98574

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


[PATCH] D98574: [Sparc] Define the same macros for -mcpu=v9 as GCC on Linux and the BSDs

2021-03-25 Thread John Paul Adrian Glaubitz via Phabricator via cfe-commits
glaubitz marked an inline comment as done.
glaubitz added inline comments.



Comment at: clang/lib/Basic/Targets/Sparc.cpp:246-256
+  if (getTriple().getOS() == llvm::Triple::Linux) {
 Builder.defineMacro("__sparc_v9__");
-Builder.defineMacro("__sparcv9__");
+  } else {
+Builder.defineMacro("__sparcv9");
+// Solaris doesn't need these variants, but the BSDs do.
+if (getTriple().getOS() != llvm::Triple::Solaris) {
+  Builder.defineMacro("__sparc64__");

glaubitz wrote:
> ro wrote:
> > glaubitz wrote:
> > > jrtc27 wrote:
> > > > This doesn't need changing, we can define more things than GCC to keep 
> > > > it simple.
> > > Well, my original intent was to match GCC to make sure we're 100% 
> > > compatible and I would like to keep it that way.
> > I agree with Jessica here: you're creating a complicated maze for no real 
> > gain.  Besides, have you checked what `gcc` on the BSDs really does?  They 
> > often neglect to get their changes upstream and what's in the gcc repo 
> > doesn't necessarily represent what they actually use.
> Yes, I have verified that GCC behaves the exact same way as this change and I 
> don't see any reason not to mimic the exact same behavior in clang for 
> maximum compatibility.
FWIW, I meant GCC on the various BSDs. I do not think it's a wise idea to have 
clang deviate from what GCC does as only this way we can guarantee that 
everything that compiles with GCC will compile with clang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98574

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


[PATCH] D99158: [RISCV][WIP] Implement intrinsics for P extension

2021-03-25 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:715-732
+if (Subtarget.is64Bit()) {
+  addTypeForP(MVT::v8i8, MVT::i64);
+  addTypeForP(MVT::v4i16, MVT::i64);
+  addTypeForP(MVT::v2i32, MVT::i64);
+} else {
+  addTypeForP(MVT::v4i8, MVT::i32);
+  addTypeForP(MVT::v2i16, MVT::i32);

jrtc27 wrote:
> This seems like it will interact poorly with V if both are present
Indeed. I don't think we've really thought about how both of these could 
co-exist in llvm. I'm not sure they can. We don't have the context to decide 
upon how to lower an operation (to V or P) since we're just given the type.

Do we have to error if both are enabled simultaneously? Maybe if P only expects 
to be lowered via intrinsics we can fudge it. It's not pretty though. I came 
across this issue in a previous architecture where we had a v2i32 (or 
something) able to be lowered both via "scalar" and "vector" instructions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99158

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


[PATCH] D82547: [Debugify] Expose original debug info preservation check as CC1 option

2021-03-25 Thread Jeremy Morse via Phabricator via cfe-commits
jmorse added a comment.

FTR, the patch LGTM. I haven't really been following the development of 
debugify in detail so I have no feeling for whether this is good from a high 
level; if you're confident the mailing list discussion finished with this being 
the right direction, I'd say this is ready to land.


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

https://reviews.llvm.org/D82547

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


[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-03-25 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 333247.
bader added a comment.

[NFC] Align address space map names with AMDGPU target.

Rename SPIRAddrSpaceMap and SYCLAddrSpaceMap to SPIRDefIsPrivMap and 
SPIRDefIsGenMap.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89909

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenSYCL/address-space-cond-op.cpp
  clang/test/CodeGenSYCL/address-space-of-returns.cpp
  clang/test/CodeGenSYCL/address-space-parameter-conversions.cpp
  clang/test/CodeGenSYCL/address-spaces-struct.cpp
  clang/test/CodeGenSYCL/address-spaces.cpp
  clang/test/SemaSYCL/address-space-parameter-conversions.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Support/Triple.cpp

Index: llvm/lib/Support/Triple.cpp
===
--- llvm/lib/Support/Triple.cpp
+++ llvm/lib/Support/Triple.cpp
@@ -247,6 +247,8 @@
   case Musl: return "musl";
   case MuslEABI: return "musleabi";
   case MuslEABIHF: return "musleabihf";
+  case SYCLDevice:
+return "sycldevice";
   case Simulator: return "simulator";
   }
 
@@ -554,6 +556,7 @@
   .StartsWith("itanium", Triple::Itanium)
   .StartsWith("cygnus", Triple::Cygnus)
   .StartsWith("coreclr", Triple::CoreCLR)
+  .StartsWith("sycldevice", Triple::SYCLDevice)
   .StartsWith("simulator", Triple::Simulator)
   .StartsWith("macabi", Triple::MacABI)
   .Default(Triple::UnknownEnvironment);
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -222,8 +222,9 @@
 Itanium,
 Cygnus,
 CoreCLR,
+SYCLDevice,
 Simulator, // Simulator variants of other systems, e.g., Apple's iOS
-MacABI, // Mac Catalyst variant of Apple's iOS deployment target.
+MacABI,// Mac Catalyst variant of Apple's iOS deployment target.
 LastEnvironmentType = MacABI
   };
   enum ObjectFormatType {
@@ -497,6 +498,10 @@
isMacCatalystEnvironment()));
   }
 
+  bool isSYCLDeviceEnvironment() const {
+return getEnvironment() == Triple::SYCLDevice;
+  }
+
   bool isOSNetBSD() const {
 return getOS() == Triple::NetBSD;
   }
Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/address_space-dependent.cpp
@@ -43,7 +43,7 @@
 
 template 
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388593)}}
+  __attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388590)}}
 }
 
 template 
@@ -101,7 +101,7 @@
   car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
   HasASTemplateFields<1> HASTF;
   neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
-  correct<0x71>();
+  correct<0x7FFFED>();
   tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650>' requested here}}
 
   __attribute__((address_space(1))) char *x;
Index: clang/test/SemaSYCL/address-space-parameter-conversions.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/address-space-parameter-conversions.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -fsycl -fsycl-is-device -verify -fsyntax-only -x c++ %s
+
+void bar(int &Data) {}
+void bar2(int &Data) {}
+void bar(__attribute__((opencl_private)) int &Data) {}
+void foo(int *Data) {}
+void foo2(int *Data) {}
+void foo(__attribute__((opencl_private)) int *Data) {}
+
+template 
+void tmpl(T *t) {}
+
+void usages() {
+  __attribute__((opencl_global)) int *GLOB;
+  __attribute__((opencl_private)) int *PRIV;
+  __attribute__((opencl_local)) int *LOC;
+  int *NoAS;
+
+  bar(*GLOB);
+  bar2(*GLOB);
+
+  bar(*PRIV);
+  bar2(*PRIV);
+
+  bar(*NoAS);
+  bar2(*NoAS);
+
+  bar(*LOC);
+  bar2(*LOC);
+
+  foo(GLOB);
+  foo2(GLOB);
+  foo(PRIV);
+  foo2(PRIV);
+  foo(NoAS);
+  foo2(NoAS);
+  foo(LOC);
+  foo2(LOC);
+
+  tmpl(GLOB);
+  tmpl(PRIV);
+  tmpl(NoAS);
+  tmpl(LOC);
+
+  (void)static_cast(GLOB);
+  (void)static_cast(GLOB

[PATCH] D99158: [RISCV][WIP] Implement intrinsics for P extension

2021-03-25 Thread Jim Lin via Phabricator via cfe-commits
Jim added a comment.

In D99158#2645796 , @craig.topper 
wrote:

> What are we gaining from making the intrinsics use vector types if no vector 
> operations are supported other than the intrinsics? Why can't we just use an 
> xlen integer type?

It can support other operations. I will upload a patch for codegen pattern 
later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99158

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


[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-25 Thread EsmeYi via Phabricator via cfe-commits
Esme added a comment.

Thx! @aprantl The motivation of the patch came from the crash of tag name 
mismatching when using DBX under AIX. And modifying the debugger doesn't seem 
to make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[clang] 06411ed - [PowerPC][NFC] Provide legacy names for VSX loads and stores

2021-03-25 Thread Nemanja Ivanovic via cfe-commits

Author: Nemanja Ivanovic
Date: 2021-03-25T06:32:40-05:00
New Revision: 06411edb9fca4a292634511fc7384ffb12651472

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

LOG: [PowerPC][NFC] Provide legacy names for VSX loads and stores

Before we unified the names of the builtins across all the
compilers, there were a number of synonyms between them. There
is code out there that uses XL naming for some of these loads and
stores. This just adds those names.

Added: 


Modified: 
clang/lib/Headers/altivec.h

Removed: 




diff  --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h
index 56328187fff8..81e4cb686d8d 100644
--- a/clang/lib/Headers/altivec.h
+++ b/clang/lib/Headers/altivec.h
@@ -17144,6 +17144,8 @@ vec_revb(vector unsigned __int128 __a) {
 
 /* vec_xl */
 
+#define vec_xld2 vec_xl
+#define vec_xlw4 vec_xl
 typedef vector signed char unaligned_vec_schar __attribute__((aligned(1)));
 typedef vector unsigned char unaligned_vec_uchar __attribute__((aligned(1)));
 typedef vector signed short unaligned_vec_sshort __attribute__((aligned(1)));
@@ -17362,6 +17364,8 @@ vec_xl_zext(ptr
diff _t __offset, const unsigned long long *__pointer) {
 
 /* vec_xst */
 
+#define vec_xstd2 vec_xst
+#define vec_xstw4 vec_xst
 static inline __ATTRS_o_ai void
 vec_xst(vector signed char __vec, ptr
diff _t __offset, signed char *__ptr) {
   *(unaligned_vec_schar *)(__ptr + __offset) = __vec;



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


[PATCH] D99121: [IR][InstCombine] IntToPtr Produces Typeless Pointer To Byte

2021-03-25 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added a comment.

Given that it gives a decent speedup for some important workload, and provided 
it doesn't regress others, I think this should go in then.
It's easy to revert this once opaque pointers arrive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99121

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


[PATCH] D82547: [Debugify] Expose original debug info preservation check as CC1 option

2021-03-25 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added a comment.

Thanks!


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

https://reviews.llvm.org/D82547

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


[PATCH] D99330: [clang-tidy] [test] Tweak a regex pattern to accommodate for quirks in MSYS based grep

2021-03-25 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added a reviewer: rnk.
Herald added a subscriber: xazax.hun.
mstorsjo requested review of this revision.
Herald added a project: clang-tools-extra.

Currently on Windows, 'not' is a regular win32 executable, which
parses command line parameters according to the canonical rules of
the platform. 'grep' can be a tool running either on the regular
win32 runtime, or on the MSYS runtime. If based on the MSYS runtime,
it parses the command line parameters quite significantly differently.

When 'not' invokes 'grep', it quotes the arguments differently than
how lit's TestRunner does, making this particular case of regex
pattern work with MSYS grep when invoked by 'not', but fails if
invoked by TestRunner directly.

(If TestRunner is modified to quote arguments like 'not' does, a
whole bunch of other tests fail instead though.)

In this particular case, TestRunner doesn't quote the argument
^[a-zA-Z0-9_.\-]\+$ as it doesn't believe it needs to. The
'[' char in the argument trigger MSYS's argument globbing [1],
which also causes it to interpret the single backslashes as
escapes, making those backslashes vanish.

If we make TestRunner quote arguments if an argument contains a
backslash (which is what the 'not' executable does, with quoting
logic in llvm/lib/Support/Windows/Process.inc), then arguments with
double backslashes end up shrunk to a single backslash (contrary to
regular windows argument quoting rules), breaking a whole bunch of
other tests.

This was the cause of the revert in
f3dd783b239f5587213d528dc642b599f43452b6 
.

This allows switching 'not' to a lit internal command, making
TestRunner invoke 'grep' directly in this particular test.

The alternative, to making TestRunner's command line flattening
truly reliable, would be to make TestRunner identify if the target
executable is MSYS based (requiring a PE format inspector in python,
checking if an executable links against msys-2.0.dll or similar),
and apply different quoting rules in those cases.

[1] 
https://github.com/msys2/msys2-runtime/blob/msys2-3_1_7-release/winsup/cygwin/dcrt0.cc#L208


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99330

Files:
  clang-tools-extra/test/clang-tidy/infrastructure/validate-check-names.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/validate-check-names.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/validate-check-names.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/validate-check-names.cpp
@@ -1,2 +1,6 @@
 // Check names may only contain alphanumeric characters, '-', '_', and '.'.
-// RUN: clang-tidy -checks=* -list-checks | grep '^' | cut -b5- | not grep 
-v '^[a-zA-Z0-9_.\-]\+$'
+// RUN: clang-tidy -checks=* -list-checks | grep '^' | cut -b5- | not grep 
-v '^[a-zA-Z0-9_.\-]*$'
+
+// Hack: The regex should ideally use \+ instead of * to require at least
+// one char, but if grep is a MSYS based tool, the command line argument
+// can end up misparsed by the MSYS runtime.


Index: clang-tools-extra/test/clang-tidy/infrastructure/validate-check-names.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/validate-check-names.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/validate-check-names.cpp
@@ -1,2 +1,6 @@
 // Check names may only contain alphanumeric characters, '-', '_', and '.'.
-// RUN: clang-tidy -checks=* -list-checks | grep '^' | cut -b5- | not grep -v '^[a-zA-Z0-9_.\-]\+$'
+// RUN: clang-tidy -checks=* -list-checks | grep '^' | cut -b5- | not grep -v '^[a-zA-Z0-9_.\-]*$'
+
+// Hack: The regex should ideally use \+ instead of * to require at least
+// one char, but if grep is a MSYS based tool, the command line argument
+// can end up misparsed by the MSYS runtime.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

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

In D97183#2640559 , @RedDocMD wrote:

> @NoQ, why does the following trigger a null-dereference warning? 
> (https://godbolt.org/z/Kxox8qd16)
>
>   void g(std::unique_ptr a) {
> A *aptr = a.get();
> if (!aptr) {}
> a->foo();
>   }
>
> When `a->foo()` is called, the constraint `!aptr` is no longer valid and so 
> `InnerPointerVal` corresponding to `a` is no longer constrained to be null.
> Am I missing something?

When the if's condition is evaluated, it probably triggered a state split. On 
one path the `aptr` (aka. the inner pointer) will be constrained to `null`.
The only way to be sure is by checking the exploded graph and see where it goes.

---

In D97183#2643671 , @RedDocMD wrote:

> @NoQ, I have taken a different approach this time. I have used a visitor and 
> am storing some more data in the GDM. Together, they distinguish between the 
> following three cases:
>
> 1. If the raw pointer obtained from get() is constrained to null in a path 
> which leads to a Node (and thus State) where a smart-pointer-null-deref bug 
> occurs.
> 2. If the raw pointer was null to begin with (because the smart-pointer was 
> null)
> 3. If the raw pointer was not null to begin with but the smart-ptr became 
> null after that.
>
> Only in the first case should the note be emitted. I have added some more 
> tests to that effect.

All in all, I see where it's going. I don't know, it might be the right thing 
to do. I haven't spent much time on this topic though.
See my inline comments.




Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp:87
+  const ProgramStateRef BugState;
+  llvm::SmallPtrSet DoneExprs;
+

I'm not sure if we should expect 16 unique places where `uptr::get()` called on 
a path. I would guess 4 or 2 is more than enough.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp:106-109
+if (const auto *DS = llvm::dyn_cast(S)) {
+  for (const Decl *D : DS->getDeclGroup()) {
+if (const VarDecl *VD = llvm::dyn_cast(D)) {
+  const Expr *Init = VD->getInit();

So you are trying to find the assignment, where the inner pointer is assigned 
to a variable.
This visitor logic seems to be somewhat convoluted.

What you want to achieve is slightly similar to `FindLastStoreBRVisitor`. You 
should have a look at that.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:460
   SVal InnerPointerVal;
+  const auto *CallExpr = Call.getOriginExpr();
   if (const auto *InnerValPtr = State->get(ThisRegion)) {

Nit: Declare the variable as close to the usage as you can. In the narrowest 
scope as well.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:475-476
+  if (const auto *StmtSet = State->get(ThisRegion)) {
+auto NewStmtSet = StmtSetFactory.add(*StmtSet, CallExpr);
+State = State->set(ThisRegion, NewStmtSet);
+  } else {

Why don't you 'save' the MemRegion only if the inner pointer is not proven to 
be null. This would relieve you from checking it later.

Nit: I don't like such if branches. The last statement is identical, which is a 
code smell.
It's better to think of this as a function taking stuff and producing a State.
An immediately called lambda expression would enclose any local variables and 
it would suggest that the algorithm it implements is self-contained.
I know that I'm the only immediately called lambda expression fan though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D99260: [analyzer] Fix false positives in inner pointer checker (PR49628)

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

I recommend splitting this into two. I would happily accept the part about 
`std::data()`.

IMO `std::addressof()` should be modelled via `evalCall` as a pure function, 
instead of hacking it into the `InnerPtrChecker`.
It is overloaded to accept `const T&` as well, so the comment about 
//"std::addressof function accepts a non-const reference as an argument"// is 
not entirely true.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99260

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


[PATCH] D99182: [NFC] Reordering parameters in getFile and getFileOrSTDIN

2021-03-25 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 333266.
abhina.sreeskantharajan added a comment.

Rebase and fix formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99182

Files:
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/tools/arcmt-test/arcmt-test.cpp
  lld/COFF/Driver.cpp
  lld/COFF/DriverUtils.cpp
  lld/ELF/InputFiles.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
  lldb/unittests/TestingSupport/TestUtilities.cpp
  llvm/include/llvm/Support/MemoryBuffer.h
  llvm/lib/BinaryFormat/Magic.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
  llvm/lib/FuzzMutate/FuzzerCLI.cpp
  llvm/lib/IRReader/IRReader.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Object/Binary.cpp
  llvm/lib/ProfileData/GCOV.cpp
  llvm/lib/Support/MemoryBuffer.cpp
  llvm/lib/TableGen/Main.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cov/gcov.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/tools/llvm-pdbutil/InputFile.cpp
  llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
  llvm/tools/llvm-rc/ResourceFileWriter.cpp
  llvm/tools/llvm-readobj/llvm-readobj.cpp
  llvm/tools/obj2yaml/obj2yaml.cpp
  llvm/tools/sanstats/sanstats.cpp
  llvm/utils/FileCheck/FileCheck.cpp

Index: llvm/utils/FileCheck/FileCheck.cpp
===
--- llvm/utils/FileCheck/FileCheck.cpp
+++ llvm/utils/FileCheck/FileCheck.cpp
@@ -821,9 +821,7 @@
 
   // Read the expected strings from the check file.
   ErrorOr> CheckFileOrErr =
-  MemoryBuffer::getFileOrSTDIN(CheckFilename, /*FileSize=*/-1,
-   /*RequiresNullTerminator=*/true,
-   /*IsText=*/true);
+  MemoryBuffer::getFileOrSTDIN(CheckFilename, /*IsText=*/true);
   if (std::error_code EC = CheckFileOrErr.getError()) {
 errs() << "Could not open check file '" << CheckFilename
<< "': " << EC.message() << '\n';
@@ -845,9 +843,7 @@
 
   // Open the file to check and add it to SourceMgr.
   ErrorOr> InputFileOrErr =
-  MemoryBuffer::getFileOrSTDIN(InputFilename, /*FileSize=*/-1,
-   /*RequiresNullTerminator=*/true,
-   /*IsText=*/true);
+  MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
   if (InputFilename == "-")
 InputFilename = ""; // Overwrite for improved diagnostic messages
   if (std::error_code EC = InputFileOrErr.getError()) {
Index: llvm/tools/sanstats/sanstats.cpp
===
--- llvm/tools/sanstats/sanstats.cpp
+++ llvm/tools/sanstats/sanstats.cpp
@@ -125,8 +125,8 @@
   cl::ParseCommandLineOptions(argc, argv,
   "Sanitizer Statistics Processing Tool");
 
-  ErrorOr> MBOrErr =
-  MemoryBuffer::getFile(ClInputFile, -1, false);
+  ErrorOr> MBOrErr = MemoryBuffer::getFile(
+  ClInputFile, /*IsText=*/false, /*RequiresNullTerminator=*/false);
   if (!MBOrErr) {
 errs() << argv[0] << ": " << ClInputFile << ": "
<< MBOrErr.getError().message() << '\n';
Index: llvm/tools/obj2yaml/obj2yaml.cpp
===
--- llvm/tools/obj2yaml/obj2yaml.cpp
+++ llvm/tools/obj2yaml/obj2yaml.cpp
@@ -36,7 +36,7 @@
 
 static Error dumpInput(StringRef File) {
   ErrorOr> FileOrErr =
-  MemoryBuffer::getFileOrSTDIN(File, /*FileSize=*/-1,
+  MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
   if (std::error_code EC = FileOrErr.getError())
 return errorCodeToError(EC);
Index: llvm/tools/llvm-readobj/llvm-readobj.cpp
===
--- llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -653,7 +653,7 @@
 /// Opens \a File and dumps it.
 static void dumpInput(StringRef File, ScopedPrinter &Writer) {
   ErrorOr> FileOrErr =
-  MemoryBuffer::getFileOrSTDIN(File, /*FileSize=*/-1,
+  MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
   if (std::error_code EC = FileOrErr.getError())
 return reportError(errorCodeToError(EC), File);
Index: llvm/tools/llvm-rc/ResourceFileWriter.cpp
===
--- llvm/tools/llvm-rc/ResourceFileWriter.cpp
+++ llvm/tools/llvm-rc/ResourceFileWriter.cpp
@@ -1524,14 +1524,16 @@
   // properly though, so if using that to append paths below, this early
   // exception case could be removed.)
   if (sys::path::has_root_directory(File))
-return errorOrToExpected(MemoryBuffer::getFile(File, -1, false));
+return errorOrToExpected(MemoryBuffer::getFile(
+F

[PATCH] D99182: [NFC] Reordering parameters in getFile and getFileOrSTDIN

2021-03-25 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan marked an inline comment as done.
abhina.sreeskantharajan added inline comments.



Comment at: llvm/lib/Support/MemoryBuffer.cpp:275
+  return getFileAux(
+  Filename, /*MapSize=*/-1, 0, /*IsText=*/false,
+  /*RequiresNullTerminator=*/false, IsVolatile);

jhenderson wrote:
> Whilst you're modifying, add the named parameter comment for the `0`, so that 
> it's not just a magic number.
Thanks for catching, this is fixed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99182

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-03-25 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked 2 inline comments as done.
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp:87
+  const ProgramStateRef BugState;
+  llvm::SmallPtrSet DoneExprs;
+

steakhal wrote:
> I'm not sure if we should expect 16 unique places where `uptr::get()` called 
> on a path. I would guess 4 or 2 is more than enough.
Ok



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp:106-109
+if (const auto *DS = llvm::dyn_cast(S)) {
+  for (const Decl *D : DS->getDeclGroup()) {
+if (const VarDecl *VD = llvm::dyn_cast(D)) {
+  const Expr *Init = VD->getInit();

steakhal wrote:
> So you are trying to find the assignment, where the inner pointer is assigned 
> to a variable.
> This visitor logic seems to be somewhat convoluted.
> 
> What you want to achieve is slightly similar to `FindLastStoreBRVisitor`. You 
> should have a look at that.
That is what I had done before. @NoQ pointed out why this wouldn't work in a 
previous comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-03-25 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

Let's take a look at compilation output for the following program:

  c++
  void foo(int *p) {}

OpenCL compiler produces following LLVM IR for SPIR target:

  LLVM
  define dso_local spir_func void @_Z3fooPU3AS4i(i32 addrspace(4)* nocapture 
%0) local_unnamed_addr #0 {
ret void
  }

Here is what SYCL device compiler produces:

  LLVM
  define dso_local spir_func void @_Z3fooPi(i32* nocapture %0) 
local_unnamed_addr #0 {
ret void
  }

We would like to get equivalent code produced by both compiler for SPIR target.
Currently SYCL device compiler emits pointer to address space 0 instead of 
expected 4. This lowering is defined by the address space map.
Having multiple maps is not something new to the clang community. Similar 
approach AMDGPU target applies to customize address space mapping for OpenCL 
language 
(https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/AMDGPU.cpp#L354).

I updated address space map names to avoid confusion that mapping change is 
specific to the language mode. Now they use the same naming scheme as AMDGPU 
maps.

Using InferAddressSpace pass is not required for the targets supporting SPIR-V 
with pointers to generic address space, but it can be beneficial to produce 
more efficient native code.

I also created a review request with SYCL design documentation - 
https://reviews.llvm.org/D99190


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89909

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

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



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp:106-109
+if (const auto *DS = llvm::dyn_cast(S)) {
+  for (const Decl *D : DS->getDeclGroup()) {
+if (const VarDecl *VD = llvm::dyn_cast(D)) {
+  const Expr *Init = VD->getInit();

RedDocMD wrote:
> steakhal wrote:
> > So you are trying to find the assignment, where the inner pointer is 
> > assigned to a variable.
> > This visitor logic seems to be somewhat convoluted.
> > 
> > What you want to achieve is slightly similar to `FindLastStoreBRVisitor`. 
> > You should have a look at that.
> That is what I had done before. @NoQ pointed out why this wouldn't work in a 
> previous comment.
Please elaborate on that.
I'm not saying that an already existing visitor would perfectly fit your needs. 
I'm just curious why a //similar// logic would not work for you. You are trying 
to iterate over a bunch of decls and init exprs etc. And there is nothing 
similar to the visitor I mentioned.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D98856: Always emit error for wrong interfaces to scalable vectors, unless cmdline flag is passed.

2021-03-25 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm accepted this revision.
paulwalker-arm added inline comments.



Comment at: llvm/include/llvm/Support/TypeSize.h:30
 
+/// Reports a diagnostic message to indicate a invalid size request has been
+/// done on a scalable vector. This function may not return.

an


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98856

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


[clang] 8420a53 - [Debugify] Expose original debug info preservation check as CC1 option

2021-03-25 Thread Djordje Todorovic via cfe-commits

Author: Djordje Todorovic
Date: 2021-03-25T05:29:42-07:00
New Revision: 8420a5332486c682c1aaddbcb58a571869d19832

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

LOG: [Debugify] Expose original debug info preservation check as CC1 option

In order to test the preservation of the original Debug Info metadata
in your projects, a front end option could be very useful, since users
usually report that a concrete entity (e.g. variable x, or function fn2())
is missing debug info. The [0] is an example of running the utility
on GDB Project.

This depends on: D82546 and D82545.

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

Added: 
clang/test/Driver/verify-debug-info-preservation.c

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/docs/HowToUpdateDebugInfo.rst

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index bbda74044a1c..4c354734dff8 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -70,6 +70,10 @@ CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug 
information for the new
 CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled.
 CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
///< '-g' + 'O>0' level.
+CODEGENOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation verify
+ ///< each (it means check
+ ///< the original debug info
+ ///< metadata preservation).
 CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
  ///< is specified.
 CODEGENOPT(DisableTailCalls  , 1, 0) ///< Do not emit tail calls.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index b38df2da97de..778340b34272 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -190,6 +190,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// The ABI to use for passing floating point arguments.
   std::string FloatABI;
 
+  /// The file to use for dumping bug report by `Debugify` for original
+  /// debug info.
+  std::string DIBugsReportFilePath;
+
   /// The floating-point denormal mode to use.
   llvm::DenormalMode FPDenormalMode = llvm::DenormalMode::getIEEE();
 

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 6f50774d8f1c..5e580cc4fbb7 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -342,6 +342,10 @@ def warn_drv_disabling_vptr_no_rtti_default : Warning<
 def warn_drv_object_size_disabled_O0 : Warning<
   "the object size sanitizer has no effect at -O0, but is explicitly enabled: 
%0">,
   InGroup, DefaultWarnNoWerror;
+def warn_ignoring_verify_debuginfo_preserve_export : Warning<
+  "ignoring -fverify-debuginfo-preserve-export=%0 because "
+  "-fverify-debuginfo-preserve wasn't enabled">,
+  InGroup;
 def err_invalid_branch_protection: Error <
   "invalid branch protection option '%0' in '%1'">;
 def err_invalid_sls_hardening : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a48b922e884a..f4af1a4b10f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4877,6 +4877,18 @@ def fexperimental_debug_variable_locations : Flag<["-"],
 "fexperimental-debug-variable-locations">,
 HelpText<"Use experimental new value-tracking variable locations">,
 MarshallingInfoFlag>;
+def fverify_debuginfo_preserve
+: Flag<["-"], "fverify-debuginfo-preserve">,
+  HelpText<"Enable Debug Info Metadata preservation testing in "
+   "optimizations.">,
+  MarshallingInfoFlag>;
+def fverify_debuginfo_preserve_export
+: Joined<["-"], "fverify-debuginfo-preserve-export=">,
+  MetaVarName<"">,
+  HelpText<"Export debug info (by testing original Debug Info) failures "
+   "into specified (JSON) file (should be abs path as we use "
+   "append mode to insert new JSON objects).">,
+  MarshallingInfoString>;
 // The driver option takes the key as a parameter to the -msign-return-address=
 // and -mbranch-protection= options, but CC1 has a se

[PATCH] D82547: [Debugify] Expose original debug info preservation check as CC1 option

2021-03-25 Thread Djordje Todorovic via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8420a5332486: [Debugify] Expose original debug info 
preservation check as CC1 option (authored by djtodoro).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82547

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/verify-debug-info-preservation.c
  llvm/docs/HowToUpdateDebugInfo.rst

Index: llvm/docs/HowToUpdateDebugInfo.rst
===
--- llvm/docs/HowToUpdateDebugInfo.rst
+++ llvm/docs/HowToUpdateDebugInfo.rst
@@ -376,6 +376,17 @@
 
   $ llvm-original-di-preservation.py sample.json sample.html
 
+Testing of original debug info preservation can be invoked from front-end level
+as follows:
+
+.. code-block:: bash
+
+  # Test each pass.
+  $ clang -Xclang -fverify-debuginfo-preserve -g -O2 sample.c
+
+  # Test each pass and export the issues report into the JSON file.
+  $ clang -Xclang -fverify-debuginfo-preserve -Xclang -fverify-debuginfo-preserve-export=sample.json -g -O2 sample.c
+
 Mutation testing for MIR-level transformations
 --
 
Index: clang/test/Driver/verify-debug-info-preservation.c
===
--- /dev/null
+++ clang/test/Driver/verify-debug-info-preservation.c
@@ -0,0 +1,19 @@
+// We support the CC1 options for testing whether each LLVM pass preserves
+// original debug info.
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=VERIFYDIPRESERVE %s
+
+// VERIFYDIPRESERVE: "-fverify-debuginfo-preserve"
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve \
+// RUN: -Xclang -fverify-debuginfo-preserve-export=%t.json -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=VERIFYDIPRESERVE-JSON-EXPORT %s
+
+// VERIFYDIPRESERVE-JSON-EXPORT: "-fverify-debuginfo-preserve"
+// VERIFYDIPRESERVE-JSON-EXPORT: "-fverify-debuginfo-preserve-export={{.*}}"
+
+// RUN: %clang -g -Xclang -fverify-debuginfo-preserve-export=%t.json %s -S 2>&1 \
+// RUN: | FileCheck --check-prefix=WARN %s
+
+// WARN: warning: ignoring -fverify-debuginfo-preserve-export
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1648,6 +1648,12 @@
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
 
+  if (!Opts.EnableDIPreservationVerify && Opts.DIBugsReportFilePath.size()) {
+Diags.Report(diag::warn_ignoring_verify_debuginfo_preserve_export)
+<< Opts.DIBugsReportFilePath;
+Opts.DIBugsReportFilePath = "";
+  }
+
   Opts.NewStructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa) &&
Args.hasArg(OPT_new_struct_path_tbaa);
   Opts.OptimizeSize = getOptimizationLevelSize(Args);
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -81,6 +81,7 @@
 #include "llvm/Transforms/Scalar/LowerMatrixIntrinsics.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
@@ -945,7 +946,16 @@
   if (TM)
 TheModule->setDataLayout(TM->createDataLayout());
 
-  legacy::PassManager PerModulePasses;
+  DebugifyCustomPassManager PerModulePasses;
+  DebugInfoPerPassMap DIPreservationMap;
+  if (CodeGenOpts.EnableDIPreservationVerify) {
+PerModulePasses.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
+PerModulePasses.setDIPreservationMap(DIPreservationMap);
+
+if (!CodeGenOpts.DIBugsReportFilePath.empty())
+  PerModulePasses.setOrigDIVerifyBugsReportFilePath(
+  CodeGenOpts.DIBugsReportFilePath);
+  }
   PerModulePasses.add(
   createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4877,6 +4877,18 @@
 "fexperimental-debug-variable-locations">,
 HelpText<"Use experimental new value-tracking variable locations">,
 MarshallingInfoFlag>;
+def fverify_debuginfo_preserve
+: Flag<["-"], 

[PATCH] D99121: [IR][InstCombine] IntToPtr Produces Typeless Pointer To Byte

2021-03-25 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D99121#2650146 , @nlopes wrote:

> Given that it gives a decent speedup for some important workload, and 
> provided it doesn't regress others [...]

I think that second point is going to need some evidence (at least in the form 
of transform stats I guess). D96881  is 
another recent attempt to work around pointer types, and it looks like that one 
did regress others. This patch already shows regressions inside InstCombine 
itself, so that's not a great sign.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99121

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


[PATCH] D89909: [SYCL] Implement SYCL address space attributes handling

2021-03-25 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.



> Having multiple maps is not something new to the clang community. Similar 
> approach AMDGPU target applies to customize address space mapping for OpenCL 
> language 
> (https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/AMDGPU.cpp#L354).
>
> I updated address space map names to avoid confusion that mapping change is 
> specific to the language mode. Now they use the same naming scheme as AMDGPU 
> maps.

Well AMDGPU is a specific target in contrast to SPIR. But the question is 
whether the map that has been renamed is only intended for SYCL or can it be 
used for OpenCL or other languages too? My worry is that the original design 
was intended to separate language and target information but somehow it is now 
driven towards tangling them together more and more.

> Using InferAddressSpace pass is not required for the targets supporting 
> SPIR-V with pointers to generic address space, but it can be beneficial to 
> produce more efficient native code.

Ok, that's good to know that it is only intended for optimisations!

> I also created a review request with SYCL design documentation - 
> https://reviews.llvm.org/D99190

Thanks. I will take a look at the address space part. My first impression is 
that it would be good to abstract away from the implementation in clang and 
start from the language semantic that you are trying to get. Perhaps it will be 
easier if I provide concrete questions on the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89909

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


[PATCH] D99190: WIP: [SYCL] Add design document for SYCL mode

2021-03-25 Thread Alexey Bader via Phabricator via cfe-commits
bader updated this revision to Diff 333279.
bader marked 16 inline comments as done.
bader added a comment.

Apply most of the comments from Ronan.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99190

Files:
  clang/docs/SYCLSupport.md
  clang/docs/images/Compiler-HLD.svg
  clang/docs/images/DeviceCodeSplit.svg
  clang/docs/images/DeviceLinkAndWrap.svg
  clang/docs/images/DevicePTXProcessing.svg
  clang/docs/images/SplitCompileAndLink.svg

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


[PATCH] D97183: [analyzer] Add NoteTag for smart-ptr get()

2021-03-25 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked 3 inline comments as done.
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrChecker.cpp:106-109
+if (const auto *DS = llvm::dyn_cast(S)) {
+  for (const Decl *D : DS->getDeclGroup()) {
+if (const VarDecl *VD = llvm::dyn_cast(D)) {
+  const Expr *Init = VD->getInit();

steakhal wrote:
> RedDocMD wrote:
> > steakhal wrote:
> > > So you are trying to find the assignment, where the inner pointer is 
> > > assigned to a variable.
> > > This visitor logic seems to be somewhat convoluted.
> > > 
> > > What you want to achieve is slightly similar to `FindLastStoreBRVisitor`. 
> > > You should have a look at that.
> > That is what I had done before. @NoQ pointed out why this wouldn't work in 
> > a previous comment.
> Please elaborate on that.
> I'm not saying that an already existing visitor would perfectly fit your 
> needs. I'm just curious why a //similar// logic would not work for you. You 
> are trying to iterate over a bunch of decls and init exprs etc. And there is 
> nothing similar to the visitor I mentioned.
Sorry. I should have written it out better.
> So you are trying to find the assignment, where the inner pointer is assigned 
> to a variable.
Yes and no. I am indeed trying to find where the //first// assignment occurred, 
since re-assigning to the pointer obtained from `get()` doesn't give any 
information regarding regarding the smart pointer being null or not. So what 
this visitor does that it goes back to the original assignment to find out what 
SVal was bound to `a.get()`. The Environment doesn't have this info since it is 
garbage collected somewhere on the way. Also accessing this State allows me to 
check whether the SVal was null to begin with.
I don't think `FindLastStoreBRVisitor` does this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97183

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


[PATCH] D99190: WIP: [SYCL] Add design document for SYCL mode

2021-03-25 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

@keryell, thanks for the feedback.

I applied your suggestions with two exceptions:

1. I'm not sure if other back-ends need special processing for kernel function 
parameters we apply for SPIR kernels.
2. I'm looking for suggestions on "OpenCL extensions" clarification.




Comment at: clang/docs/SYCLSupport.md:127
+special `accessor` classes. The "device" side implementation of these classes
+contains pointers to the device memory. As there is no way in OpenCL to pass
+structures with pointers inside as kernel arguments all memory objects shared

keryell wrote:
> To be generalized to non OpenCL case.
@Naghasan, do you know if CUDA has similar limitation?



Comment at: clang/docs/SYCLSupport.md:140
+To facilitate the mapping of SYCL kernel data members to SPIR kernel arguments
+and overcome OpenCL limitations we added the generation of an SPIR kernel
+function inside the compiler. A SPIR kernel function contains the body of the

keryell wrote:
> It is not about overcoming some OpenCL limitations but just to use OpenCL as 
> a back-end.
I replaced "overcome OpenCL limitations" to "use OpenCL as a back-end", but I 
don't see the difference between these two options.



Comment at: clang/docs/SYCLSupport.md:155
+
+// Generated kernel function (expressed using OpenCL extensions)
+__kernel KernelName(global int* a) {

keryell wrote:
> "OpenCL extensions" is probably misleading here and the sentence should be 
> clarified.
"OpenCL extensions" are two keywords: `__kernel` and `global`.

Do you have a suggestion how to improve it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99190

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


[clang] ea61708 - [SystemZ][z/OS] csv files should be text files

2021-03-25 Thread Abhina Sreeskantharajan via cfe-commits

Author: Abhina Sreeskantharajan
Date: 2021-03-25T09:19:15-04:00
New Revision: ea61708c6d07846e13590b14c4dac2b7d543fef9

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

LOG: [SystemZ][z/OS] csv files should be text files

This patch sets the OF_Text flag correctly for the csv file.

Reviewed By: anirudhp

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e70263e6a295..0918ea455811 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4081,7 +4081,8 @@ void Driver::BuildJobs(Compilation &C) const {
 Out.flush();
 std::error_code EC;
 llvm::raw_fd_ostream OS(CCPrintStatReportFilename, EC,
-llvm::sys::fs::OF_Append);
+llvm::sys::fs::OF_Append |
+llvm::sys::fs::OF_Text);
 if (EC)
   return;
 auto L = OS.lock();



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


[PATCH] D99285: [SystemZ][z/OS] csv files should be text files

2021-03-25 Thread Abhina Sree via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGea61708c6d07: [SystemZ][z/OS] csv files should be text files 
(authored by abhina.sreeskantharajan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99285

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4081,7 +4081,8 @@
 Out.flush();
 std::error_code EC;
 llvm::raw_fd_ostream OS(CCPrintStatReportFilename, EC,
-llvm::sys::fs::OF_Append);
+llvm::sys::fs::OF_Append |
+llvm::sys::fs::OF_Text);
 if (EC)
   return;
 auto L = OS.lock();


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4081,7 +4081,8 @@
 Out.flush();
 std::error_code EC;
 llvm::raw_fd_ostream OS(CCPrintStatReportFilename, EC,
-llvm::sys::fs::OF_Append);
+llvm::sys::fs::OF_Append |
+llvm::sys::fs::OF_Text);
 if (EC)
   return;
 auto L = OS.lock();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98747: Thread safety analysis: Don't warn about managed locks on join points

2021-03-25 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D98747#2648943 , @aaronpuchert 
wrote:

> We could probably address all false negatives by introducing a `FactEntry` 
> for "managed locks that might be held", which we introduce on discrepancies 
> at join points. We assume that they're fine for the destructor, but we would 
> warn if there is an explicit lock/unlock. I could start working on this if 
> you think that's a good idea, but it would not only address false negatives 
> introduced in this change, but also false negatives that we've had before.

Hmm, this won't work for back edges, because we can't change the lock set after 
the join point for them.

But I believe we could warn on back edges if a "managed lock that might be 
held" joins with a managed lock that is held or not held right away. If there 
is a path from the loop entry that might acquire or release the lock, then we 
might run into this same path with our lock that might be held. Might not be 
easy to place the diagnostics correctly, but otherwise it seems consistent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98747

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


[PATCH] D99291: [AIX] Support init priority attribute

2021-03-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:574
+  std::string PrioritySuffix = llvm::utostr(Priority);
+  // Priority is always <= 65535 (enforced by sema).
+  PrioritySuffix = std::string(6 - PrioritySuffix.size(), '0') + 
PrioritySuffix;

This isn't quite true -- it's enforced by sema for user code, but not for code 
that identifies itself as a system header. I see that this is existing code 
that's moved around a bit, but we may want to add an assertion here just in 
case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99291

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


[PATCH] D82880: [clang] Handle 128-bits IntegerLiterals in StmtPrinter

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

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82880

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


[clang-tools-extra] 0becc4d - fix readability-braces-around-statements Stmt type dependency

2021-03-25 Thread Aaron Ballman via cfe-commits

Author: Alexander Lanin
Date: 2021-03-25T09:44:41-04:00
New Revision: 0becc4d721d0036e2e38d581bc487e27f78eb8a9

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

LOG: fix readability-braces-around-statements Stmt type dependency

Replaces Token based approach to identify EndLoc of Stmt with AST traversal.
This also improves handling of macros.

Fixes Bugs 22785, 25970 and 35754.

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
clang-tools-extra/clang-tidy/utils/LexerUtils.h

clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
index 1123238c186b..2c78258078ea 100644
--- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "BracesAroundStatementsCheck.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Lex/Lexer.h"
@@ -16,10 +17,9 @@ using namespace clang::ast_matchers;
 namespace clang {
 namespace tidy {
 namespace readability {
-namespace {
 
-tok::TokenKind getTokenKind(SourceLocation Loc, const SourceManager &SM,
-const ASTContext *Context) {
+static tok::TokenKind getTokenKind(SourceLocation Loc, const SourceManager &SM,
+   const ASTContext *Context) {
   Token Tok;
   SourceLocation Beginning =
   Lexer::GetBeginningOfToken(Loc, SM, Context->getLangOpts());
@@ -33,9 +33,9 @@ tok::TokenKind getTokenKind(SourceLocation Loc, const 
SourceManager &SM,
   return Tok.getKind();
 }
 
-SourceLocation forwardSkipWhitespaceAndComments(SourceLocation Loc,
-const SourceManager &SM,
-const ASTContext *Context) {
+static SourceLocation
+forwardSkipWhitespaceAndComments(SourceLocation Loc, const SourceManager &SM,
+ const ASTContext *Context) {
   assert(Loc.isValid());
   for (;;) {
 while (isWhitespace(*SM.getCharacterData(Loc)))
@@ -50,31 +50,15 @@ SourceLocation 
forwardSkipWhitespaceAndComments(SourceLocation Loc,
   }
 }
 
-SourceLocation findEndLocation(SourceLocation LastTokenLoc,
-   const SourceManager &SM,
-   const ASTContext *Context) {
+static SourceLocation findEndLocation(const Stmt &S, const SourceManager &SM,
+  const ASTContext *Context) {
   SourceLocation Loc =
-  Lexer::GetBeginningOfToken(LastTokenLoc, SM, Context->getLangOpts());
-  // Loc points to the beginning of the last (non-comment non-ws) token
-  // before end or ';'.
-  assert(Loc.isValid());
-  bool SkipEndWhitespaceAndComments = true;
-  tok::TokenKind TokKind = getTokenKind(Loc, SM, Context);
-  if (TokKind == tok::NUM_TOKENS || TokKind == tok::semi ||
-  TokKind == tok::r_brace) {
-// If we are at ";" or "}", we found the last token. We could use as well
-// `if (isa(S))`, but it wouldn't work for nested statements.
-SkipEndWhitespaceAndComments = false;
-  }
+  utils::lexer::getUnifiedEndLoc(S, SM, Context->getLangOpts());
+  if (!Loc.isValid())
+return Loc;
 
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, Context->getLangOpts());
-  // Loc points past the last token before end or after ';'.
-  if (SkipEndWhitespaceAndComments) {
-Loc = forwardSkipWhitespaceAndComments(Loc, SM, Context);
-tok::TokenKind TokKind = getTokenKind(Loc, SM, Context);
-if (TokKind == tok::semi)
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, Context->getLangOpts());
-  }
+  // Start searching right after S.
+  Loc = Loc.getLocWithOffset(1);
 
   for (;;) {
 assert(Loc.isValid());
@@ -109,8 +93,6 @@ SourceLocation findEndLocation(SourceLocation LastTokenLoc,
   return Loc;
 }
 
-} // namespace
-
 BracesAroundStatementsCheck::BracesAroundStatementsCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -224,13 +206,6 @@ bool BracesAroundStatementsCheck::checkStmt(
   const SourceManager &SM = *Result.SourceManager;
   const ASTContext *Context = Result.Context;
 
-  // Treat macros.
-  CharSourceRange FileRange = Lexer::makeFileCharRange(
-  CharSourceRange::getTokenRange(S->getSourceRange()), SM,
-  Context->getLangOpts());
-  if (FileRange.isInva

[clang] c83cd8f - [NFC] Reordering parameters in getFile and getFileOrSTDIN

2021-03-25 Thread Abhina Sreeskantharajan via cfe-commits

Author: Abhina Sreeskantharajan
Date: 2021-03-25T09:47:49-04:00
New Revision: c83cd8feef7eb8319131d968bb8c94fdc8dbb6a6

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

LOG: [NFC] Reordering parameters in getFile and getFileOrSTDIN

In future patches I will be setting the IsText parameter frequently so I will 
refactor the args to be in the following order. I have removed the FileSize 
parameter because it is never used.

```
  static ErrorOr>
  getFile(const Twine &Filename, bool IsText = false,
  bool RequiresNullTerminator = true, bool IsVolatile = false);

  static ErrorOr>
  getFileOrSTDIN(const Twine &Filename, bool IsText = false,
 bool RequiresNullTerminator = true);

 static ErrorOr>
 getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
bool IsText, bool RequiresNullTerminator, bool IsVolatile);

  static ErrorOr>
  getFile(const Twine &Filename, bool IsVolatile = false);
```

Reviewed By: jhenderson

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

Added: 


Modified: 
clang/lib/Tooling/JSONCompilationDatabase.cpp
clang/tools/arcmt-test/arcmt-test.cpp
lld/COFF/Driver.cpp
lld/COFF/DriverUtils.cpp
lld/ELF/InputFiles.cpp
lldb/source/Host/common/FileSystem.cpp
lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
lldb/unittests/TestingSupport/TestUtilities.cpp
llvm/include/llvm/Support/MemoryBuffer.h
llvm/lib/BinaryFormat/Magic.cpp
llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
llvm/lib/FuzzMutate/FuzzerCLI.cpp
llvm/lib/IRReader/IRReader.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/Object/Binary.cpp
llvm/lib/ProfileData/GCOV.cpp
llvm/lib/Support/MemoryBuffer.cpp
llvm/lib/TableGen/Main.cpp
llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
llvm/tools/lli/lli.cpp
llvm/tools/llvm-ar/llvm-ar.cpp
llvm/tools/llvm-cov/gcov.cpp
llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
llvm/tools/llvm-pdbutil/InputFile.cpp
llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
llvm/tools/llvm-rc/ResourceFileWriter.cpp
llvm/tools/llvm-readobj/llvm-readobj.cpp
llvm/tools/obj2yaml/obj2yaml.cpp
llvm/tools/sanstats/sanstats.cpp
llvm/utils/FileCheck/FileCheck.cpp

Removed: 




diff  --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp 
b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index 2d8847a7a327..97ba7e411fbb 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -198,7 +198,7 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath,
   JSONCommandLineSyntax Syntax) {
   // Don't mmap: if we're a long-lived process, the build system may overwrite.
   llvm::ErrorOr> DatabaseBuffer =
-  llvm::MemoryBuffer::getFile(FilePath, /*FileSize=*/-1,
+  llvm::MemoryBuffer::getFile(FilePath, /*IsText=*/false,
   /*RequiresNullTerminator=*/true,
   /*IsVolatile=*/true);
   if (std::error_code Result = DatabaseBuffer.getError()) {

diff  --git a/clang/tools/arcmt-test/arcmt-test.cpp 
b/clang/tools/arcmt-test/arcmt-test.cpp
index 778587d4f111..26e123c59d59 100644
--- a/clang/tools/arcmt-test/arcmt-test.cpp
+++ b/clang/tools/arcmt-test/arcmt-test.cpp
@@ -207,15 +207,13 @@ static bool performTransformations(StringRef 
resourcesPath,
 static bool filesCompareEqual(StringRef fname1, StringRef fname2) {
   using namespace llvm;
 
-  ErrorOr> file1 = MemoryBuffer::getFile(
-  fname1, /*FileSize=*/-1, /*RequiresNullTerminator=*/true,
-  /*IsVolatile=*/false, /*IsText=*/true);
+  ErrorOr> file1 =
+  MemoryBuffer::getFile(fname1, /*IsText=*/true);
   if (!file1)
 return false;
 
-  ErrorOr> file2 = MemoryBuffer::getFile(
-  fname2, /*FileSize=*/-1, /*RequiresNullTerminator=*/true,
-  /*IsVolatile=*/false, /*IsText=*/true);
+  ErrorOr> file2 =
+  MemoryBuffer::getFile(fname2, /*IsText=*/true);
   if (!file2)
 return false;
 
@@ -244,9 +242,7 @@ static bool verifyTransformedFiles(ArrayRef 
resultFiles) {
   if (RemappingsFile.empty())
 inputBuf = MemoryBuffer::getSTDIN();
   else
-inputBuf = MemoryBuffer::getFile(RemappingsFile, /*FileSize=*/-1,
- /*RequiresNullTerminator=*/true,
- /*IsVolatile=*/false, /*IsText=*/true);
+inputBuf = MemoryBuffer::getFile(RemappingsFile, /*IsText=*/true);
   if (!inputBuf) {
 errs() << "error: could not read remappings input\n";
 return true;

diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index c5c8d5c0cf90..cf96ecb731a2 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -157,9 +157,8 @@ static std::future 
create

[PATCH] D99182: [NFC] Reordering parameters in getFile and getFileOrSTDIN

2021-03-25 Thread Abhina Sree 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 rGc83cd8feef7e: [NFC] Reordering parameters in getFile and 
getFileOrSTDIN (authored by abhina.sreeskantharajan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99182

Files:
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/tools/arcmt-test/arcmt-test.cpp
  lld/COFF/Driver.cpp
  lld/COFF/DriverUtils.cpp
  lld/ELF/InputFiles.cpp
  lldb/source/Host/common/FileSystem.cpp
  lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
  lldb/unittests/TestingSupport/TestUtilities.cpp
  llvm/include/llvm/Support/MemoryBuffer.h
  llvm/lib/BinaryFormat/Magic.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
  llvm/lib/FuzzMutate/FuzzerCLI.cpp
  llvm/lib/IRReader/IRReader.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/Object/Binary.cpp
  llvm/lib/ProfileData/GCOV.cpp
  llvm/lib/Support/MemoryBuffer.cpp
  llvm/lib/TableGen/Main.cpp
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cov/gcov.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/tools/llvm-pdbutil/InputFile.cpp
  llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
  llvm/tools/llvm-rc/ResourceFileWriter.cpp
  llvm/tools/llvm-readobj/llvm-readobj.cpp
  llvm/tools/obj2yaml/obj2yaml.cpp
  llvm/tools/sanstats/sanstats.cpp
  llvm/utils/FileCheck/FileCheck.cpp

Index: llvm/utils/FileCheck/FileCheck.cpp
===
--- llvm/utils/FileCheck/FileCheck.cpp
+++ llvm/utils/FileCheck/FileCheck.cpp
@@ -821,9 +821,7 @@
 
   // Read the expected strings from the check file.
   ErrorOr> CheckFileOrErr =
-  MemoryBuffer::getFileOrSTDIN(CheckFilename, /*FileSize=*/-1,
-   /*RequiresNullTerminator=*/true,
-   /*IsText=*/true);
+  MemoryBuffer::getFileOrSTDIN(CheckFilename, /*IsText=*/true);
   if (std::error_code EC = CheckFileOrErr.getError()) {
 errs() << "Could not open check file '" << CheckFilename
<< "': " << EC.message() << '\n';
@@ -845,9 +843,7 @@
 
   // Open the file to check and add it to SourceMgr.
   ErrorOr> InputFileOrErr =
-  MemoryBuffer::getFileOrSTDIN(InputFilename, /*FileSize=*/-1,
-   /*RequiresNullTerminator=*/true,
-   /*IsText=*/true);
+  MemoryBuffer::getFileOrSTDIN(InputFilename, /*IsText=*/true);
   if (InputFilename == "-")
 InputFilename = ""; // Overwrite for improved diagnostic messages
   if (std::error_code EC = InputFileOrErr.getError()) {
Index: llvm/tools/sanstats/sanstats.cpp
===
--- llvm/tools/sanstats/sanstats.cpp
+++ llvm/tools/sanstats/sanstats.cpp
@@ -125,8 +125,8 @@
   cl::ParseCommandLineOptions(argc, argv,
   "Sanitizer Statistics Processing Tool");
 
-  ErrorOr> MBOrErr =
-  MemoryBuffer::getFile(ClInputFile, -1, false);
+  ErrorOr> MBOrErr = MemoryBuffer::getFile(
+  ClInputFile, /*IsText=*/false, /*RequiresNullTerminator=*/false);
   if (!MBOrErr) {
 errs() << argv[0] << ": " << ClInputFile << ": "
<< MBOrErr.getError().message() << '\n';
Index: llvm/tools/obj2yaml/obj2yaml.cpp
===
--- llvm/tools/obj2yaml/obj2yaml.cpp
+++ llvm/tools/obj2yaml/obj2yaml.cpp
@@ -36,7 +36,7 @@
 
 static Error dumpInput(StringRef File) {
   ErrorOr> FileOrErr =
-  MemoryBuffer::getFileOrSTDIN(File, /*FileSize=*/-1,
+  MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
   if (std::error_code EC = FileOrErr.getError())
 return errorCodeToError(EC);
Index: llvm/tools/llvm-readobj/llvm-readobj.cpp
===
--- llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -653,7 +653,7 @@
 /// Opens \a File and dumps it.
 static void dumpInput(StringRef File, ScopedPrinter &Writer) {
   ErrorOr> FileOrErr =
-  MemoryBuffer::getFileOrSTDIN(File, /*FileSize=*/-1,
+  MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/false,
/*RequiresNullTerminator=*/false);
   if (std::error_code EC = FileOrErr.getError())
 return reportError(errorCodeToError(EC), File);
Index: llvm/tools/llvm-rc/ResourceFileWriter.cpp
===
--- llvm/tools/llvm-rc/ResourceFileWriter.cpp
+++ llvm/tools/llvm-rc/ResourceFileWriter.cpp
@@ -1524,14 +1524,16 @@
   // properly though, so if using that to append paths below, this early
   // exception case could be removed.)
   if (sys::path::has_root_directory(File))
-

[PATCH] D99338: [clang][parser] Allow GNU-style attributes in enum specifiers

2021-03-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, rsmith.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We are parsing both C++11 and GNU-style attributes here, but the previous 
`ProhibitAttributes()` call was never working for GNU-style attributes.

GNU-style attributes are however expected to be parsed and not diagnosed, for 
example in `clang/test/Sema/ast-print` in the following code:

  // CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 
*EnumWithAttributes2Ptr;
  // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
  // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked 
deprecated here}}
  enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;

This is essentially the same as https://reviews.llvm.org/D99278 and needs 
https://reviews.llvm.org/D97362 to be applied first.

The comment just above this change is a bit confusing since it tries to explain 
that "an elaborated-type-specifier has a much more constrained grammar", but 
does not mention any attributes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99338

Files:
  clang/lib/Parse/ParseDecl.cpp


Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4653,7 +4653,7 @@
   // or opaque-enum-declaration anywhere.
   if (IsElaboratedTypeSpecifier && !getLangOpts().MicrosoftExt &&
   !getLangOpts().ObjC) {
-ProhibitAttributes(attrs);
+ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed, 
/*DiagnoseEmptyAttrs=*/true);
 if (BaseType.isUsable())
   Diag(BaseRange.getBegin(), diag::ext_enum_base_in_type_specifier)
   << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;


Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4653,7 +4653,7 @@
   // or opaque-enum-declaration anywhere.
   if (IsElaboratedTypeSpecifier && !getLangOpts().MicrosoftExt &&
   !getLangOpts().ObjC) {
-ProhibitAttributes(attrs);
+ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed, /*DiagnoseEmptyAttrs=*/true);
 if (BaseType.isUsable())
   Diag(BaseRange.getBegin(), diag::ext_enum_base_in_type_specifier)
   << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96363: Mark output as text if it is really text

2021-03-25 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

Hello! This patch breaks compilation when using `-frewrite-includes` on 
Windows. It adds an extra line with CRLF, which causes compilation failures 
with macros line-breaks:

  $ cat -A hello.cpp
  int foo();^M$
  int bar();^M$
  #define HELLO \^M$
foo(); \^M$
bar();^M$
  ^M$
  int main() {^M$
HELLO^M$
return 0;^M$
  }
  $ clang-cl /E -Xclang -frewrite-includes hello.cpp > test.cpp
  
  $ cat -A test.cpp
  # 1 ""^M^M$
  # 1 "hello.cpp"^M^M$
  int foo();^M^M$
  int bar();^M^M$
  #define HELLO \^M^M$
foo(); \^M^M$
bar();^M^M$
  ^M^M$
  int main() {^M^M$
HELLO^M^M$
return 0;^M^M$
  }^M^M$
  
  $ clang-cl /c test.cpp
  hello.cpp(8,3): error: C++ requires a type specifier for all declarations
foo(); \
^
  hello.cpp(10,3): error: C++ requires a type specifier for all declarations
bar();
^
  2 errors generated.
  
  $ clang-cl /c hello.cpp
  
  $ 

@abhina.sreeskantharajan would you have a chance to take a look please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96363

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


[PATCH] D99337: Don't pass -mllvm to gcc

2021-03-25 Thread Jethro Beekman via Phabricator via cfe-commits
jethrogb created this revision.
jethrogb added reviewers: jyknight, MaskRay.
jethrogb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When forwarding command line options to GCC, don't forward -mllvm.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99337

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/gcc_forward.c


Index: clang/test/Driver/gcc_forward.c
===
--- clang/test/Driver/gcc_forward.c
+++ clang/test/Driver/gcc_forward.c
@@ -1,4 +1,4 @@
-// Check that we don't try to forward -Xclang or -mlinker-version to GCC.
+// Check that we don't try to forward -Xclang, -mlinker-version or -mllvm to 
GCC.
 // PR12920 -- Check also we may not forward W_Group options to GCC.
 //
 // RUN: %clang -target powerpc-unknown-unknown \
@@ -6,6 +6,7 @@
 // RUN:   -Wall -Wdocumentation \
 // RUN:   -Xclang foo-bar \
 // RUN:   -march=x86-64 \
+// RUN:   -mllvm -x86-experimental-lvi-inline-asm-hardening \
 // RUN:   -mlinker-version=10 -### 2> %t
 // RUN: FileCheck < %t %s
 //
@@ -19,12 +20,16 @@
 // CHECK-NOT: "-mlinker-version=10"
 // CHECK-NOT: "-Xclang"
 // CHECK-NOT: "foo-bar"
+// CHECK-NOT: "-mllvm"
+// CHECK-NOT: "-x86-experimental-lvi-inline-asm-hardening"
 // CHECK-NOT: "-Wall"
 // CHECK-NOT: "-Wdocumentation"
 // CHECK: -march
 // CHECK-NOT: "-mlinker-version=10"
 // CHECK-NOT: "-Xclang"
 // CHECK-NOT: "foo-bar"
+// CHECK-NOT: "-mllvm"
+// CHECK-NOT: "-x86-experimental-lvi-inline-asm-hardening"
 // CHECK-NOT: "-Wall"
 // CHECK-NOT: "-Wdocumentation"
 // CHECK: "-o" "a.out"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -41,7 +41,8 @@
   // Don't forward inputs from the original command line.  They are added from
   // InputInfoList.
   return O.getKind() != Option::InputClass &&
- !O.hasFlag(options::DriverOption) && !O.hasFlag(options::LinkerInput);
+ !O.hasFlag(options::DriverOption) && !O.hasFlag(options::LinkerInput) 
&&
+ !O.matches(options::OPT_mllvm);
 }
 
 // Switch CPU names not recognized by GNU assembler to a close CPU that it does


Index: clang/test/Driver/gcc_forward.c
===
--- clang/test/Driver/gcc_forward.c
+++ clang/test/Driver/gcc_forward.c
@@ -1,4 +1,4 @@
-// Check that we don't try to forward -Xclang or -mlinker-version to GCC.
+// Check that we don't try to forward -Xclang, -mlinker-version or -mllvm to GCC.
 // PR12920 -- Check also we may not forward W_Group options to GCC.
 //
 // RUN: %clang -target powerpc-unknown-unknown \
@@ -6,6 +6,7 @@
 // RUN:   -Wall -Wdocumentation \
 // RUN:   -Xclang foo-bar \
 // RUN:   -march=x86-64 \
+// RUN:   -mllvm -x86-experimental-lvi-inline-asm-hardening \
 // RUN:   -mlinker-version=10 -### 2> %t
 // RUN: FileCheck < %t %s
 //
@@ -19,12 +20,16 @@
 // CHECK-NOT: "-mlinker-version=10"
 // CHECK-NOT: "-Xclang"
 // CHECK-NOT: "foo-bar"
+// CHECK-NOT: "-mllvm"
+// CHECK-NOT: "-x86-experimental-lvi-inline-asm-hardening"
 // CHECK-NOT: "-Wall"
 // CHECK-NOT: "-Wdocumentation"
 // CHECK: -march
 // CHECK-NOT: "-mlinker-version=10"
 // CHECK-NOT: "-Xclang"
 // CHECK-NOT: "foo-bar"
+// CHECK-NOT: "-mllvm"
+// CHECK-NOT: "-x86-experimental-lvi-inline-asm-hardening"
 // CHECK-NOT: "-Wall"
 // CHECK-NOT: "-Wdocumentation"
 // CHECK: "-o" "a.out"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -41,7 +41,8 @@
   // Don't forward inputs from the original command line.  They are added from
   // InputInfoList.
   return O.getKind() != Option::InputClass &&
- !O.hasFlag(options::DriverOption) && !O.hasFlag(options::LinkerInput);
+ !O.hasFlag(options::DriverOption) && !O.hasFlag(options::LinkerInput) &&
+ !O.matches(options::OPT_mllvm);
 }
 
 // Switch CPU names not recognized by GNU assembler to a close CPU that it does
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99337: Don't pass -mllvm to gcc

2021-03-25 Thread Jethro Beekman via Phabricator via cfe-commits
jethrogb added inline comments.



Comment at: clang/test/Driver/gcc_forward.c:9
 // RUN:   -march=x86-64 \
+// RUN:   -mllvm -x86-experimental-lvi-inline-asm-hardening \
 // RUN:   -mlinker-version=10 -### 2> %t

This is just something I happen to know you can pass to -mllvm. Open to other 
suggestions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99337

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


[PATCH] D99301: [HIP] add __builtin_get_device_side_mangled_name

2021-03-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 333296.
yaxunl marked 5 inline comments as done.
yaxunl added a comment.

Revised by Artem's comments.


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

https://reviews.llvm.org/D99301

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/Builtins.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Builtins.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCUDA/builtin-mangled-name.cu
  clang/test/SemaCUDA/builtin-mangled-name.cu

Index: clang/test/SemaCUDA/builtin-mangled-name.cu
===
--- /dev/null
+++ clang/test/SemaCUDA/builtin-mangled-name.cu
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-gnu-linux -aux-triple amdgcn-amd-amdhsa \
+// RUN:   -verify -fsyntax-only -x hip %s
+
+#include "Inputs/cuda.h"
+
+__global__ void kern1();
+int y;
+
+void fun1() {
+  int x;
+  const char *p;
+  p = __builtin_get_device_side_mangled_name();
+  // expected-error@-1 {{invalid argument: symbol must be a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(kern1, kern1);
+  // expected-error@-1 {{invalid argument: symbol must be a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(1);
+  // expected-error@-1 {{invalid argument: symbol must be a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(x);
+  // expected-error@-1 {{invalid argument: symbol must be a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(fun1);
+  // expected-error@-1 {{invalid argument: symbol must be a device-side function or global variable}}
+  p = __builtin_get_device_side_mangled_name(y);
+  // expected-error@-1 {{invalid argument: symbol must be a device-side function or global variable}}
+}
Index: clang/test/CodeGenCUDA/builtin-mangled-name.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/builtin-mangled-name.cu
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-gnu-linux -aux-triple amdgcn-amd-amdhsa \
+// RUN:   -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=CHECK,LNX %s 
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -aux-triple amdgcn-amd-amdhsa \
+// RUN:   -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=CHECK,MSVC %s 
+
+#include "Inputs/cuda.h"
+
+namespace X {
+  __global__ void kern1(int *x);
+  __device__ int var1;
+}
+
+// CHECK: @[[STR1:.*]] = {{.*}} c"_ZN1X5kern1EPi\00"
+// CHECK: @[[STR2:.*]] = {{.*}} c"_ZN1X4var1E\00"
+
+// LNX-LABEL: define {{.*}}@_Z4fun1v()
+// MSVC-LABEL: define {{.*}} @"?fun1@@YAPEBDXZ"()
+// CHECK: ret i8* getelementptr inbounds ({{.*}} @[[STR1]], i64 0, i64 0)
+const char *fun1() {
+  return __builtin_get_device_side_mangled_name(X::kern1);
+}
+
+// LNX-LABEL: define {{.*}}@_Z4fun2v()
+// MSVC-LABEL: define {{.*}}@"?fun2@@YAPEBDXZ"()
+// CHECK: ret i8* getelementptr inbounds ({{.*}} @[[STR2]], i64 0, i64 0)
+__host__ __device__ const char *fun2() {
+  return __builtin_get_device_side_mangled_name(X::var1);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1966,6 +1966,26 @@
 
   case Builtin::BI__builtin_matrix_column_major_store:
 return SemaBuiltinMatrixColumnMajorStore(TheCall, TheCallResult);
+
+  case Builtin::BI__builtin_get_device_side_mangled_name: {
+auto Check = [](CallExpr *TheCall) {
+  if (TheCall->getNumArgs() != 1)
+return false;
+  auto *DRE = dyn_cast(TheCall->getArg(0)->IgnoreImpCasts());
+  if (!DRE)
+return false;
+  auto *D = DRE->getDecl();
+  if (!isa(D) && !isa(D))
+return false;
+  return D->hasAttr() || D->hasAttr() ||
+ D->hasAttr() || D->hasAttr();
+};
+if (!Check(TheCall)) {
+  Diag(TheCall->getBeginLoc(),
+   diag::err_hip_invalid_args_builtin_mangled_name);
+  return ExprError();
+}
+  }
   }
 
   // Since the target specific builtins for each arch overlap, only check those
Index: clang/lib/CodeGen/CGCUDANV.cpp
===
--- clang/lib/CodeGen/CGCUDANV.cpp
+++ clang/lib/CodeGen/CGCUDANV.cpp
@@ -12,6 +12,7 @@
 //===--===//
 
 #include "CGCUDARuntime.h"
+#include "CGCXXABI.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/Decl.h"
@@ -260,10 +261,15 @@
   else
 GD = GlobalDecl(ND);
   std::string DeviceSideName;
-  if (DeviceMC->shouldMangleDeclName(ND)) {
+  MangleContext *MC;
+  if (CGM.getLangOpts().CUDAIsDevice)
+MC = &CGM.getCXXABI().getMangleContext();
+  else
+MC = DeviceMC.get();
+  if (MC->should

[PATCH] D99337: Don't pass -mllvm to gcc

2021-03-25 Thread Jethro Beekman via Phabricator via cfe-commits
jethrogb abandoned this revision.
jethrogb added a comment.

Actually I think this is fixed in main (was developing against 11.x).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99337

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


[PATCH] D96363: Mark output as text if it is really text

2021-03-25 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan added a comment.

In D96363#2650460 , @aganea wrote:

> Hello! This patch breaks compilation when using `-frewrite-includes` on 
> Windows. It adds an extra line with CRLF, which causes compilation failures 
> with macros line-breaks:
>
>   $ cat -A hello.cpp
>   int foo();^M$
>   int bar();^M$
>   #define HELLO \^M$
> foo(); \^M$
> bar();^M$
>   ^M$
>   int main() {^M$
> HELLO^M$
> return 0;^M$
>   }
>   $ clang-cl /E -Xclang -frewrite-includes hello.cpp > test.cpp
>   
>   $ cat -A test.cpp
>   # 1 ""^M^M$
>   # 1 "hello.cpp"^M^M$
>   int foo();^M^M$
>   int bar();^M^M$
>   #define HELLO \^M^M$
> foo(); \^M^M$
> bar();^M^M$
>   ^M^M$
>   int main() {^M^M$
> HELLO^M^M$
> return 0;^M^M$
>   }^M^M$
>   
>   $ clang-cl /c test.cpp
>   hello.cpp(8,3): error: C++ requires a type specifier for all declarations
> foo(); \
> ^
>   hello.cpp(10,3): error: C++ requires a type specifier for all declarations
> bar();
> ^
>   2 errors generated.
>   
>   $ clang-cl /c hello.cpp
>   
>   $ 
>
> @abhina.sreeskantharajan would you have a chance to take a look please?

Sure, let me take a look. This change should be non-functional so there might 
be a function usage I missed somewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96363

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


[PATCH] D99189: [RISCV][Clang] Update new overloading rules for RVV intrinsics.

2021-03-25 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 333298.
khchen marked an inline comment as done.
khchen added a comment.

Emit riscv_vector_overloaded.h into riscv_vector.h
Remove riscv_vector_overloaded.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99189

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/Headers/CMakeLists.txt
  clang/test/CodeGen/RISCV/rvv-intrinsics-generic/vadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-generic/vfadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vfadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vle.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vloxei.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vluxei.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vse.c
  clang/utils/TableGen/RISCVVEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h
  llvm/docs/CommandGuide/tblgen.rst
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

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


[PATCH] D99301: [HIP] add __builtin_get_device_side_mangled_name

2021-03-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/Builtins.h:39
   OMP_LANG = 0x80,// builtin requires OpenMP.
+  HIP_LANG = 0x100,   // builtin requires HIP.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.

tra wrote:
> The issue is common for both CUDA and HIP. 
will rename it to CUDA_LANG



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8310
+def err_hip_invalid_args_builtin_mangled_name : Error<
+"invalid argument: expect a device-side function or global variable">;
+

tra wrote:
> Nit. I'd rephrase it in terms of what makes the argument invalid. E.g. 
> `symbol must be a device-side function or global variable`.
will do



Comment at: clang/lib/Basic/Builtins.cpp:78
   bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG;
+  bool HIPUnsupported = !LangOpts.HIP && BuiltinInfo.Langs == HIP_LANG;
   bool CPlusPlusUnsupported =

tra wrote:
> tra wrote:
> > Wow! The density of negations in this function is impressive.
> > 
> > 
> Please enable it for CUDA, too.
will do



Comment at: clang/lib/Sema/SemaChecking.cpp:1980-1983
+  if (!D->hasAttr() && !D->hasAttr() &&
+  !D->hasAttr() && !D->hasAttr())
+return false;
+  return true;

tra wrote:
> ```
>   return D->hasAttr() || D->hasAttr() ||
>   D->hasAttr() || D->hasAttr();
> ```
will do


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

https://reviews.llvm.org/D99301

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


[PATCH] D99292: [flang][driver] Add support for `-cpp/-nocpp`

2021-03-25 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

minor  comments.




Comment at: flang/lib/Frontend/FrontendAction.cpp:73
+  // Include standard macro predefinitions (use the file
+  // extension if the user didn't express any prefernce)
+  if ((invoc.preprocessorOpts().predefs_ == StdMacroPredefs::Include) ||

Nit: prefernce -> preference
below also.



Comment at: flang/lib/Frontend/FrontendOptions.cpp:23
   // TODO: Add Cuda Fortan files (i.e. `*.cuf` and `*.CUF`).
   return suffix == "f77" || suffix == "f90" || suffix == "F90" ||
   suffix == "ff90" || suffix == "f95" || suffix == "F95" ||

Unrelated comment: f77 is probably not free form.



Comment at: flang/lib/Frontend/FrontendOptions.cpp:30
+bool Fortran::frontend::mustBePreprocessed(llvm::StringRef suffix) {
+  return suffix == "F" || suffix == "FOR" || suffix == "FPP" ||
+  suffix == "F90" || suffix == "F95" || suffix == "F03" ||

Consider adding fpp and making it match the behaviour of gfortran as given 
below.

"The preprocessor is automatically invoked if the file extension is .fpp, .FPP, 
.F, .FOR, .FTN, .F90, .F95, .F03 or .F08."
https://gcc.gnu.org/onlinedocs/gfortran/Preprocessing-Options.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99292

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


[clang] 8fbfc92 - Reuse `os` variable in AllocateTarget; NFC

2021-03-25 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-03-25T14:38:02Z
New Revision: 8fbfc92a5cef5e709ca47742e7bf11035607abcc

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

LOG: Reuse `os` variable in AllocateTarget; NFC

Added: 


Modified: 
clang/lib/Basic/Targets.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 793a471194fe..8df5cb7a3a61 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -595,13 +595,13 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
 }
 
   case llvm::Triple::spir: {
-if (Triple.getOS() != llvm::Triple::UnknownOS ||
+if (os != llvm::Triple::UnknownOS ||
 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
   return nullptr;
 return new SPIR32TargetInfo(Triple, Opts);
   }
   case llvm::Triple::spir64: {
-if (Triple.getOS() != llvm::Triple::UnknownOS ||
+if (os != llvm::Triple::UnknownOS ||
 Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
   return nullptr;
 return new SPIR64TargetInfo(Triple, Opts);
@@ -611,7 +611,7 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
 Triple.getVendor() != llvm::Triple::UnknownVendor ||
 !Triple.isOSBinFormatWasm())
   return nullptr;
-switch (Triple.getOS()) {
+switch (os) {
   case llvm::Triple::WASI:
 return new WASITargetInfo(Triple, Opts);
   case llvm::Triple::Emscripten:
@@ -626,7 +626,7 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
 Triple.getVendor() != llvm::Triple::UnknownVendor ||
 !Triple.isOSBinFormatWasm())
   return nullptr;
-switch (Triple.getOS()) {
+switch (os) {
   case llvm::Triple::WASI:
 return new WASITargetInfo(Triple, Opts);
   case llvm::Triple::Emscripten:



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


[PATCH] D98275: [clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy process

2021-03-25 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
njames93 marked an inline comment as done.
Closed by commit rG02d7ef3181dd: [clang-tidy] Fix mpi checks when running 
multiple TUs per clang-tidy process (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98275

Files:
  clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
  clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
  clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
  clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h

Index: clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h
===
--- clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h
+++ clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h
@@ -11,6 +11,7 @@
 
 #include "../ClangTidyCheck.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
 
 namespace clang {
 namespace tidy {
@@ -31,6 +32,8 @@
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
+  void onEndOfTranslationUnit() override;
+
 private:
   /// Check if the buffer type MPI datatype pairs match.
   ///
@@ -41,6 +44,8 @@
   void checkArguments(ArrayRef BufferTypes,
   ArrayRef BufferExprs,
   ArrayRef MPIDatatypes, const LangOptions &LO);
+
+  Optional FuncClassifier;
 };
 
 } // namespace mpi
Index: clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
===
--- clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
+++ clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
@@ -8,7 +8,6 @@
 
 #include "TypeMismatchCheck.h"
 #include "clang/Lex/Lexer.h"
-#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
 #include "clang/Tooling/FixIt.h"
 #include 
 #include 
@@ -241,13 +240,15 @@
 }
 
 void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) {
-  static ento::mpi::MPIFunctionClassifier FuncClassifier(*Result.Context);
   const auto *const CE = Result.Nodes.getNodeAs("CE");
   if (!CE->getDirectCallee())
 return;
 
+  if (!FuncClassifier)
+FuncClassifier.emplace(*Result.Context);
+
   const IdentifierInfo *Identifier = CE->getDirectCallee()->getIdentifier();
-  if (!Identifier || !FuncClassifier.isMPIType(Identifier))
+  if (!Identifier || !FuncClassifier->isMPIType(Identifier))
 return;
 
   // These containers are used, to capture buffer, MPI datatype pairs.
@@ -281,18 +282,18 @@
   };
 
   // Collect all buffer, MPI datatype pairs for the inspected call expression.
-  if (FuncClassifier.isPointToPointType(Identifier)) {
+  if (FuncClassifier->isPointToPointType(Identifier)) {
 AddPair(0, 2);
-  } else if (FuncClassifier.isCollectiveType(Identifier)) {
-if (FuncClassifier.isReduceType(Identifier)) {
+  } else if (FuncClassifier->isCollectiveType(Identifier)) {
+if (FuncClassifier->isReduceType(Identifier)) {
   AddPair(0, 3);
   AddPair(1, 3);
-} else if (FuncClassifier.isScatterType(Identifier) ||
-   FuncClassifier.isGatherType(Identifier) ||
-   FuncClassifier.isAlltoallType(Identifier)) {
+} else if (FuncClassifier->isScatterType(Identifier) ||
+   FuncClassifier->isGatherType(Identifier) ||
+   FuncClassifier->isAlltoallType(Identifier)) {
   AddPair(0, 2);
   AddPair(3, 5);
-} else if (FuncClassifier.isBcastType(Identifier)) {
+} else if (FuncClassifier->isBcastType(Identifier)) {
   AddPair(0, 2);
 }
   }
@@ -331,6 +332,7 @@
   }
 }
 
+void TypeMismatchCheck::onEndOfTranslationUnit() { FuncClassifier.reset(); }
 } // namespace mpi
 } // namespace tidy
 } // namespace clang
Index: clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
===
--- clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
+++ clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
 
 #include "../ClangTidyCheck.h"
+#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
 
 namespace clang {
 namespace tidy {
@@ -30,6 +31,7 @@
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void onEndOfTranslationUnit() override;
 
 private:
   /// Checks for all buffers in an MPI call if they are sufficiently
@@ -41,6 +43,8 @@
 ArrayRef BufferExprs);
 
   enum class IndirectionType : unsigned char { Pointer, Array };
+
+  Optional FuncClassifier;
 };
 
 } // namespace mpi
Index: clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp

[clang-tools-extra] 02d7ef3 - [clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy process

2021-03-25 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-03-25T14:38:37Z
New Revision: 02d7ef3181dd6a043a8ad16d747353dd02cbb5ef

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

LOG: [clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy 
process

Both the mpi-type-mismatch and mpi-buffer-deref check make use of a static 
MPIFunctionClassifier object.
This causes issue as the classifier is initialized with the first ASTContext 
that produces a match.
If the check is enabled on multiple translation units in a single clang-tidy 
process, this classifier won't be reinitialized for each TU. I'm not an expert 
in the MPIFunctionClassifier but I'd imagine this is a source of UB.
It is suspected that this bug may result in the crash caused here: 
https://bugs.llvm.org/show_bug.cgi?id=48985. However even if not the case, this 
should still be addressed.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp
clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp 
b/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
index b108f75fbc7a..ebe9658d8b2b 100644
--- a/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
+++ b/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.cpp
@@ -9,7 +9,6 @@
 #include "BufferDerefCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
 #include "clang/Tooling/FixIt.h"
 
 using namespace clang::ast_matchers;
@@ -23,13 +22,15 @@ void BufferDerefCheck::registerMatchers(MatchFinder 
*Finder) {
 }
 
 void BufferDerefCheck::check(const MatchFinder::MatchResult &Result) {
-  static ento::mpi::MPIFunctionClassifier FuncClassifier(*Result.Context);
   const auto *CE = Result.Nodes.getNodeAs("CE");
   if (!CE->getDirectCallee())
 return;
 
+  if (!FuncClassifier)
+FuncClassifier.emplace(*Result.Context);
+
   const IdentifierInfo *Identifier = CE->getDirectCallee()->getIdentifier();
-  if (!Identifier || !FuncClassifier.isMPIType(Identifier))
+  if (!Identifier || !FuncClassifier->isMPIType(Identifier))
 return;
 
   // These containers are used, to capture the type and expression of a buffer.
@@ -60,18 +61,18 @@ void BufferDerefCheck::check(const MatchFinder::MatchResult 
&Result) {
   // Collect buffer types and argument expressions for all buffers used in the
   // MPI call expression. The number passed to the lambda corresponds to the
   // argument index of the currently verified MPI function call.
-  if (FuncClassifier.isPointToPointType(Identifier)) {
+  if (FuncClassifier->isPointToPointType(Identifier)) {
 AddBuffer(0);
-  } else if (FuncClassifier.isCollectiveType(Identifier)) {
-if (FuncClassifier.isReduceType(Identifier)) {
+  } else if (FuncClassifier->isCollectiveType(Identifier)) {
+if (FuncClassifier->isReduceType(Identifier)) {
   AddBuffer(0);
   AddBuffer(1);
-} else if (FuncClassifier.isScatterType(Identifier) ||
-   FuncClassifier.isGatherType(Identifier) ||
-   FuncClassifier.isAlltoallType(Identifier)) {
+} else if (FuncClassifier->isScatterType(Identifier) ||
+   FuncClassifier->isGatherType(Identifier) ||
+   FuncClassifier->isAlltoallType(Identifier)) {
   AddBuffer(0);
   AddBuffer(3);
-} else if (FuncClassifier.isBcastType(Identifier)) {
+} else if (FuncClassifier->isBcastType(Identifier)) {
   AddBuffer(0);
 }
   }
@@ -126,6 +127,7 @@ void BufferDerefCheck::checkBuffers(ArrayRef 
BufferTypes,
   }
 }
 
+void BufferDerefCheck::onEndOfTranslationUnit() { FuncClassifier.reset(); }
 } // namespace mpi
 } // namespace tidy
 } // namespace clang

diff  --git a/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h 
b/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
index 040e3f790e61..a3be5a8224e0 100644
--- a/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
+++ b/clang-tools-extra/clang-tidy/mpi/BufferDerefCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
 
 #include "../ClangTidyCheck.h"
+#include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
 
 namespace clang {
 namespace tidy {
@@ -30,6 +31,7 @@ class BufferDerefCheck : public ClangTidyCheck {
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void onEndOfTranslationUnit() override;
 
 private:
   //

[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

In D99250#2649507 , @Esme wrote:

> Thx! @aprantl The motivation of the patch came from the crash of tag name 
> mismatching when using DBX under AIX. And modifying the debugger doesn't seem 
> to make sense?

A consumer should not crash when it sees an unexpected value.  This is clearly 
a DBX problem.  It should have some fallback, for example it could do the same 
thing it would do if the language attribute was missing entirely.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[PATCH] D99343: [Analyzer] Infer 0 value when the divisible is 0 (bug fix)

2021-03-25 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: steakhal, NoQ, vsavchenko, Szelethus.
Herald added subscribers: ASDenysPetrov, Charusso, gamesh411, dkrupp, 
donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun, whisperity.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently, we infer 0 if the divisible of the modulo op is 0:

  int a = x < 0; // a can be 0
  int b = a % y; // b is either 1 % sym or 0

However, we don't when the op is / :

  int a = x < 0; // a can be 0
  int b = a / y; // b is either 1 / sym or 0 / sym

This commit fixes the discrepancy.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99343

Files:
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/zero-operands.c


Index: clang/test/Analysis/zero-operands.c
===
--- /dev/null
+++ clang/test/Analysis/zero-operands.c
@@ -0,0 +1,53 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify %s
+
+void clang_analyzer_dump(int);
+
+void test_0_multiplier1(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a * y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_multiplier2(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = y * a;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_modulo(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a % y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 % (reg_${{[[:digit:]]+}})}}
+}
+
+void test_0_divisible(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a / y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 / (reg_${{[[:digit:]]+}})}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -652,6 +652,7 @@
 if (LHSValue == 0)
   return evalCastFromNonLoc(lhs, resultTy);
 return makeSymExprValNN(op, InputLHS, InputRHS, resultTy);
+  case BO_Div:
   case BO_Rem:
 // 0 % x == 0
 if (LHSValue == 0)


Index: clang/test/Analysis/zero-operands.c
===
--- /dev/null
+++ clang/test/Analysis/zero-operands.c
@@ -0,0 +1,53 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify %s
+
+void clang_analyzer_dump(int);
+
+void test_0_multiplier1(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a * y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_multiplier2(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = y * a;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_modulo(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a % y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 % (reg_${{[[:digit:]]+}})}}
+}
+
+void test_0_divisible(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a / y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 / (reg_${{[[:digit:]]+}})}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -652,6 +652,7 @@
 if (LHSValue == 0)
   return evalCastFromNonLoc(lhs, resultTy);
 return makeSymExprValNN(

[PATCH] D99344: [Analyzer] Track RValue expressions

2021-03-25 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: steakhal, NoQ, vsavchenko, Szelethus.
Herald added subscribers: ASDenysPetrov, Charusso, gamesh411, dkrupp, 
donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun, whisperity.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It makes sense to track rvalue expressions in the case of special
concrete integer values. The most notable special value is zero (later
we may find other values). By tracking the origin of 0, we can provide a
better explanation for users e.g. in case of division by 0 warnings.
When the divisor is a product of a multiplication then now we can show
which operand (or both) was (were) zero and why.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99344

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/division-by-zero-track-zero.c
  clang/test/Analysis/division-by-zero-track-zero.cpp
  clang/test/Analysis/nullptr.cpp

Index: clang/test/Analysis/nullptr.cpp
===
--- clang/test/Analysis/nullptr.cpp
+++ clang/test/Analysis/nullptr.cpp
@@ -64,7 +64,7 @@
 
 typedef __INTPTR_TYPE__ intptr_t;
 void zoo1multiply() {
-  char **p = 0; // FIXME-should-be-note:{{'p' initialized to a null pointer value}}
+  char **p = 0; // expected-note{{'p' initialized to a null pointer value}}
   delete *((char **)((intptr_t)p * 2)); // expected-warning{{Dereference of null pointer}}
// expected-note@-1{{Dereference of null pointer}}
 }
Index: clang/test/Analysis/division-by-zero-track-zero.cpp
===
--- /dev/null
+++ clang/test/Analysis/division-by-zero-track-zero.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify %s
+
+namespace test_tracking_of_lhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = p0 * y; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_lhs_multiplier
+
+namespace test_tracking_of_rhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = y * p0; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_rhs_multiplier
+
+namespace test_tracking_of_nested_multiplier {
+  int f(int x, int y, int z) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = y*z*p0; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_nested_multiplier
+
+namespace test_tracking_through_multiple_stmts {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}}
+bool p1 = p0 ? 0 : 1; // expected-note {{'p0' is false}} \
+  // expected-note {{'?' condition is false}}
+bool p2 = 1 - p1; // expected-note {{'p2' initialized to 0}}
+int div = p2 * y; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_through_multiple_stmts
+
+namespace test_tracking_both_lhs_and_rhs {
+  int f(int x, int y) {
+bool p0 = x < 0;   // expected-note {{Assuming 'x' is >= 0}} \
+   // expected-note {{'p0' initialized to 0}}
+bool p1 = y < 0;   // expected-note {{Assuming 'y' is >= 0}} \
+   // expected-note {{'p1' initialized to 0}}
+int div = p0 * p1; // expected-note {{'div' initialized to 0}}
+return 1 / div;// expected-note {{Division by zero}} \
+   // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_both_lhs_and_rhs
+
+namespace test_tracking_of_multiplier_and_parens {
+  int f(int x, int y, int z) {
+bool p0 = x < 0;// expected-note {{Assuming 'x' is >= 0}} \
+// expected-note {{'p0' initialized to 0}}
+int div = y*(z*p0); // expected-note {{'div' initialized to 0}}
+return 1 / div; // expected-note {{Division by zero}} \
+   

[PATCH] D99343: [Analyzer] Infer 0 value when the divisible is 0 (bug fix)

2021-03-25 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/test/Analysis/zero-operands.c:43
+
+void test_0_divisible(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.

Note, this is the test that fails without this fix. 

The preceding tests are here to demonstrate the current functionality with the 
other multiplicative operands and will be good for regression testing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99343

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


[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-25 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 11.
arnamoy10 added a comment.

Updating test case to add `-fsyntax-only` to share with `f18 `


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

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/std2018_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -487,7 +487,8 @@
   options.features.Enable(
   Fortran::common::LanguageFeature::BackslashEscapes, true);
 } else if (arg == "-Mstandard" || arg == "-std=f95" ||
-arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy") {
+arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy" ||
+arg == "-std=f2018" || arg == "-pedantic") {
   driver.warnOnNonstandardUsage = true;
 } else if (arg == "-fopenacc") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenACC);
Index: flang/test/Driver/std2018_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/std2018_wrong.f90
@@ -0,0 +1,12 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,28 @@
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -fsyntax-only -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -47,6 +47,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -96,6 +98,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -47,6 +47,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensions
+! CHECK-NEXT: -std=   Language standard to compile for
 ! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --

[PATCH] D99343: [Analyzer] Infer 0 value when the divisible is 0 (bug fix)

2021-03-25 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.

Looks great!




Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:655
 return makeSymExprValNN(op, InputLHS, InputRHS, resultTy);
+  case BO_Div:
   case BO_Rem:

I think we should either add: `// 0 / x == 0` or modify the comment for `BO_Rem`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99343

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


[PATCH] D99344: [Analyzer] Track RValue expressions

2021-03-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

From the first glance, everything is looking good!  Thanks for addressing this!
But I still need to have a deeper look.




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1932-1933
+bool EnableNullFPSuppression) {
+  if (!E->isRValue())
+return;
+  const ExplodedNode *RVNode = findNodeForExpression(InputNode, E);

I think this should become an assertion and the caller should ensure that `E` 
is actually an r-value



Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1950
+const llvm::APSInt &Zero = BVF.getValue(0, BVF.getContext().IntTy);
+// Do the comparison with the same canonical ASPInt.
+return CI->getValue() == BVF.Convert(CI->getValue(), Zero);

`APSInt`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99344

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


[PATCH] D95745: Support unwinding from inline assembly

2021-03-25 Thread Paul via Phabricator via cfe-commits
cynecx added a comment.

Weekly Ping!


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

https://reviews.llvm.org/D95745

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


[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-25 Thread ChenZheng via Phabricator via cfe-commits
shchenz added a comment.

In D99250#2650561 , @probinson wrote:

> In D99250#2649507 , @Esme wrote:
>
>> Thx! @aprantl The motivation of the patch came from the crash of tag name 
>> mismatching when using DBX under AIX. And modifying the debugger doesn't 
>> seem to make sense?
>
> A consumer should not crash when it sees an unexpected value.  This is 
> clearly a DBX problem.  It should have some fallback, for example it could do 
> the same thing it would do if the language attribute was missing entirely.

Yeah, I totally agree with this! A consumer should be friendly enough to handle 
any unexpected input. The crash is anyhow not a good response.

Back to the DWARF info issue, will it be an issue that a DWARF 5 language value 
be emitted when the compiling option explicitly specifies the DWARF 3 version? 
This time it is `DW_LANG_C_plus_plus_14`. 
We plan to check the DWARF info is generated under the correct DWARF version, 
what if we meet some other issues? A not improper example (NOT exist, just an 
example) is what if we generate constant class DW_AT_high_pc attribute under 
-gdwarf-3? I think we should fix this right? For DWARF 3, DW_AT_high_pc 
attribute should always be a relocatable address.

What you guys think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[PATCH] D99322: [clang] Pass option directly to command. NFC

2021-03-25 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

Woo! Thanks for cleaning up one of my old messes :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99322

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


[PATCH] D99350: [OPENMP]Fix PR49649: The introduction of $ref globals is not always valid.

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

Need to emit the reference in the global address space and the
referenced to static variable should be bitcasted to the generic address
space to be compatible with NVPTX.
Required to avoid early optimization of the static variables


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99350

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_target_codegen.cpp


Index: clang/test/OpenMP/declare_target_codegen.cpp
===
--- clang/test/OpenMP/declare_target_codegen.cpp
+++ clang/test/OpenMP/declare_target_codegen.cpp
@@ -41,10 +41,10 @@
 // CHECK-DAG: @c = external global i32,
 // CHECK-DAG: @globals ={{ hidden | }}global %struct.S zeroinitializer,
 // CHECK-DAG: [[STAT:@.+stat]] = internal global %struct.S zeroinitializer,
-// CHECK-DAG: [[STAT_REF:@.+]] = internal constant %struct.S* [[STAT]]
+// CHECK-DAG: [[STAT_REF:@.+]] = internal constant i8* bitcast (%struct.S* 
[[STAT]] to i8*)
 // CHECK-DAG: @out_decl_target ={{ hidden | }}global i32 0,
 // CHECK-DAG: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* 
@__omp_offloading__{{.+}}_globals_l[[@LINE+84]]_ctor to i8*), i8* bitcast (void 
()* @__omp_offloading__{{.+}}_stat_l[[@LINE+85]]_ctor to i8*)],
-// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast 
(%struct.S** [[STAT_REF]] to i8*)],
+// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast 
(i8** [[STAT_REF]] to i8*)],
 
 // CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}()
 // CHECK-DAG: define {{.*}}void 
@{{.*}}TemplateClass{{.*}}(%class.TemplateClass* {{[^,]*}} %{{.*}})
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10559,11 +10559,13 @@
   std::string RefName = getName({VarName, "ref"});
   if (!CGM.GetGlobalValue(RefName)) {
 llvm::Constant *AddrRef =
-getOrCreateInternalVariable(Addr->getType(), RefName);
+getOrCreateInternalVariable(CGM.VoidPtrTy, RefName);
 auto *GVAddrRef = cast(AddrRef);
 GVAddrRef->setConstant(/*Val=*/true);
 GVAddrRef->setLinkage(llvm::GlobalValue::InternalLinkage);
-GVAddrRef->setInitializer(Addr);
+GVAddrRef->setInitializer(
+llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+Addr, CGM.VoidPtrTy));
 CGM.addCompilerUsedGlobal(GVAddrRef);
   }
 }


Index: clang/test/OpenMP/declare_target_codegen.cpp
===
--- clang/test/OpenMP/declare_target_codegen.cpp
+++ clang/test/OpenMP/declare_target_codegen.cpp
@@ -41,10 +41,10 @@
 // CHECK-DAG: @c = external global i32,
 // CHECK-DAG: @globals ={{ hidden | }}global %struct.S zeroinitializer,
 // CHECK-DAG: [[STAT:@.+stat]] = internal global %struct.S zeroinitializer,
-// CHECK-DAG: [[STAT_REF:@.+]] = internal constant %struct.S* [[STAT]]
+// CHECK-DAG: [[STAT_REF:@.+]] = internal constant i8* bitcast (%struct.S* [[STAT]] to i8*)
 // CHECK-DAG: @out_decl_target ={{ hidden | }}global i32 0,
 // CHECK-DAG: @llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @__omp_offloading__{{.+}}_globals_l[[@LINE+84]]_ctor to i8*), i8* bitcast (void ()* @__omp_offloading__{{.+}}_stat_l[[@LINE+85]]_ctor to i8*)],
-// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (%struct.S** [[STAT_REF]] to i8*)],
+// CHECK-DAG: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i8** [[STAT_REF]] to i8*)],
 
 // CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}()
 // CHECK-DAG: define {{.*}}void @{{.*}}TemplateClass{{.*}}(%class.TemplateClass* {{[^,]*}} %{{.*}})
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10559,11 +10559,13 @@
   std::string RefName = getName({VarName, "ref"});
   if (!CGM.GetGlobalValue(RefName)) {
 llvm::Constant *AddrRef =
-getOrCreateInternalVariable(Addr->getType(), RefName);
+getOrCreateInternalVariable(CGM.VoidPtrTy, RefName);
 auto *GVAddrRef = cast(AddrRef);
 GVAddrRef->setConstant(/*Val=*/true);
 GVAddrRef->setLinkage(llvm::GlobalValue::InternalLinkage);
-GVAddrRef->setInitializer(Addr);
+GVAddrRef->setInitializer(
+llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+Addr, CGM.VoidPtrTy));
 CGM.addCompilerUsedGlobal(GVAddrRef);
   }
 }
_

[PATCH] D99344: [Analyzer] Track RValue expressions

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

I really like it. Looks good.
I'm letting someone else accept this as I've not really touched the 
trackExpression parts.




Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h:119-124
+/// Attempts to add visitors to track an RValue expression back to its point of
+/// origin. Works similarly to trackExpressionValue, but accepts only RValues.
+void trackRValueExpression(const ExplodedNode *N, const Expr *E,
+   PathSensitiveBugReport &R,
+   TrackingKind TKind = TrackingKind::Thorough,
+   bool EnableNullFPSuppression = true);

It is supposed to be called by the `trackExpressionValue()`.
Why do we expose this function then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99344

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


[PATCH] D98300: [TLS] Initialization functions of dynamic TLS variables cannot be in a comdat (fix for PR48030)

2021-03-25 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp added a comment.

ping ...


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

https://reviews.llvm.org/D98300

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


[PATCH] D99086: [clang][Syntax] Optimize expandedTokens for token ranges.

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

Just doc nits - I think maybe there's some confusion on what a token range is.
Code looks good though!




Comment at: clang-tools-extra/clangd/ParsedAST.cpp:426
   syntax::TokenBuffer Tokens = std::move(CollectTokens).consume();
+  // Index expanded tokens to optimize finding expandedToken in token ranges.
+  // Primarily useful for building a SelectionTree.

nit: the first sentence is just repeating the function's doc - I'd just say 
"Makes 
 SelectionTree build much faster"



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:196
 
+  /// Creates an index ExpandedTokens by their SourceLocation for faster
+  /// lookups. This optimizes future calls to `expandedTokens(SourceRange)` for

Hmm, the primary doc (first sentence) should probably be about the effect 
rather than implementation details.

Maybe just "Builds a cache to make expandedToken(SourceRange) faster."?



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:203
   /// Returns the subrange of expandedTokens() corresponding to the closed
-  /// token range R.
+  /// source range R.
+  /// Consider calling indexExpandedTokens() before for faster lookups for

token range was correct and critical to mention here, please revert

It means that R.endLocation() is the last token included in the range. 
Sometimes endLocation() means other things, in closed character range, or an 
half-open token or character range.



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:205
+  /// Consider calling indexExpandedTokens() before for faster lookups for
+  /// 'token ranges'.
   llvm::ArrayRef expandedTokens(SourceRange R) const;

can you drop "for 'token ranges'" here? I'm not sure what it means, and all 
ranges passed in here must be token ranges per contract.



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:379
+  // Index of ExpandedTokens for faster lookups by SourceLocation. This is
+  // useful while finding expanded tokens in a 'token range'.
+  llvm::DenseMap ExpandedTokIndex;

again this comment is confusing. I'd suggest just dropping it - it's fairly 
covered by indexExpandedTokens()'s comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99086

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


Re: [PATCH] D97785: [SystemZ][z/OS] Distinguish between text and binary files on z/OS

2021-03-25 Thread Yvan Roux via cfe-commits
I Abhina,

I think this patch broke Windows on ARM bots, the first failure observed 6
days ago in this build:

https://lab.llvm.org/buildbot/#/builders/65/builds/1245

I don't really get what the problem is, but the issue is related to
tablegen generated file AbstractTypeReader.inc and your patch is the only
one in the set which is touching that area.

Does it ring a bell for you ?

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


[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-25 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

I think there are degrees of compatibility with regard to DWARF, which is 
inherently supposed to be extensible if the extension can be safely ignored by 
a consumer.  This is the "permissive" rule in the standard.

- A new FORM must *never* be used, because that makes it impossible to 
interpret the rest of the CU.
- A new attribute or tag may be used if it can be safely ignored.
- A new constant value for an existing attribute also may be used if it can be 
safely ignored.

For other cases, such as using existing forms/attributes in novel ways, it 
really depends on how we think (or know) consumers will react to it.   
DW_AT_high_pc with a constant value is an excellent example; a debugger would 
not have any obvious reasonable interpretation for that.  On the other hand, 
something like a new language code happens all the time, and there's even a 
range for user-defined language codes.  A debugger must be prepared for unknown 
values, and an unknown value inside the standard-defined range doesn't seem 
like a reason to crash, or even bail out.

If we implemented a "strict DWARF" mode, then in that mode we should be more 
careful about this.  If you are implementing a DWARF verifier, it would be 
reasonable to report using language codes outside the range defined by a given 
DWARF version IMO, but a bug report about that would likely be rejected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[clang] 4c7ebf7 - [flang][driver] Add options for -std=f2018

2021-03-25 Thread Arnamoy Bhattacharyya via cfe-commits

Author: Arnamoy Bhattacharyya
Date: 2021-03-25T13:03:16-04:00
New Revision: 4c7ebf79e923072e8d298134e6ca04618fe4eba9

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

LOG: [flang][driver] Add options for -std=f2018

Reviewed By: awarzynski

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

Added: 
flang/test/Driver/std2018.f90
flang/test/Driver/std2018_wrong.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/tools/f18/f18.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f4af1a4b10f1..8ee3ebf7f2af 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3535,8 +3535,8 @@ def pagezero__size : JoinedOrSeparate<["-"], 
"pagezero_size">;
 def pass_exit_codes : Flag<["-", "--"], "pass-exit-codes">, 
Flags<[Unsupported]>;
 def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, 
Group, Flags<[CC1Option]>,
   MarshallingInfoFlag>;
-def pedantic : Flag<["-", "--"], "pedantic">, Group, 
Flags<[CC1Option]>,
-  MarshallingInfoFlag>;
+def pedantic : Flag<["-", "--"], "pedantic">, Group, 
Flags<[CC1Option,FlangOption,FC1Option]>,
+  HelpText<"Warn on language extensions">, 
MarshallingInfoFlag>;
 def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, 
Flags<[CC1Option]>,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
@@ -3638,7 +3638,7 @@ def static_libgcc : Flag<["-"], "static-libgcc">;
 def static_libstdcxx : Flag<["-"], "static-libstdc++">;
 def static : Flag<["-", "--"], "static">, Group, 
Flags<[NoArgumentUnused]>;
 def std_default_EQ : Joined<["-"], "std-default=">;
-def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>,
+def std_EQ : Joined<["-", "--"], "std=">, 
Flags<[CC1Option,FlangOption,FC1Option]>,
   Group, HelpText<"Language standard to compile for">,
   ValuesCode<[{
 const char *Values =

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 1fa62030b113..bf2a19e7c54a 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -43,7 +43,8 @@ void Flang::AddPreprocessingOptions(const ArgList &Args,
 void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const 
{
   Args.AddAllArgs(CmdArgs,
   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
-   options::OPT_fintrinsic_modules_path});
+   options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
+   options::OPT_std_EQ});
 }
 
 void Flang::ConstructJob(Compilation &C, const JobAction &JA,

diff  --git a/flang/include/flang/Frontend/CompilerInvocation.h 
b/flang/include/flang/Frontend/CompilerInvocation.h
index 3be6f3fc4d40..99050dcdbd7b 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -74,6 +74,8 @@ class CompilerInvocation : public CompilerInvocationBase {
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
+  bool EnableConformanceChecks_ = false;
+
 public:
   CompilerInvocation() = default;
 
@@ -96,6 +98,11 @@ class CompilerInvocation : public CompilerInvocationBase {
   bool &debugModuleDir() { return debugModuleDir_; }
   const bool &debugModuleDir() const { return debugModuleDir_; }
 
+  bool &enableConformanceChecks() { return EnableConformanceChecks_; }
+  const bool &enableConformanceChecks() const {
+return EnableConformanceChecks_;
+  }
+
   Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds() {
 return defaultKinds_;
   }
@@ -111,6 +118,9 @@ class CompilerInvocation : public CompilerInvocationBase {
   llvm::ArrayRef commandLineArgs,
   clang::DiagnosticsEngine &diags);
 
+  // Enables the std=f2018 conformance check
+  void set_EnableConformanceChecks() { EnableConformanceChecks_ = true; }
+
   /// Useful setters
   void SetModuleDir(std::string &moduleDir) { moduleDir_ = moduleDir; }
 

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 69c78bde7ff1..6d0003e79571 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -389,6 +389,26 @@ static void parseDialectArgs(CompilerInvocation &res, 
llvm::opt::ArgList &args,
 res.frontendOpts().features_.Enable(
 Fortran::common::LanguageFeature::OpenMP);
   }
+
+  //-fpedantic
+  if (args.hasArg(clang::driver::options::OPT_pedantic)) {
+res.

[PATCH] D97119: [flang][driver] Add options for -std=f2018

2021-03-25 Thread Arnamoy B 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 rG4c7ebf79e923: [flang][driver] Add options for -std=f2018 
(authored by arnamoy10).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97119

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/std2018.f90
  flang/test/Driver/std2018_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -487,7 +487,8 @@
   options.features.Enable(
   Fortran::common::LanguageFeature::BackslashEscapes, true);
 } else if (arg == "-Mstandard" || arg == "-std=f95" ||
-arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy") {
+arg == "-std=f2003" || arg == "-std=f2008" || arg == "-std=legacy" ||
+arg == "-std=f2018" || arg == "-pedantic") {
   driver.warnOnNonstandardUsage = true;
 } else if (arg == "-fopenacc") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenACC);
Index: flang/test/Driver/std2018_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/std2018_wrong.f90
@@ -0,0 +1,12 @@
+! REQUIRES: new-flang-driver
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang_fc1 -std=90 %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH WRONG
+!-
+! WRONG: Only -std=f2018 is allowed currently.
Index: flang/test/Driver/std2018.f90
===
--- /dev/null
+++ flang/test/Driver/std2018.f90
@@ -0,0 +1,28 @@
+! Ensure argument -std=f2018 works as expected.
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -std=f2018 %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+! RUN: %flang_fc1 -fsyntax-only -pedantic %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-
+! EXPECTED OUTPUT WITHOUT
+!-
+! WITHOUT-NOT: A DO loop should terminate with an END DO or CONTINUE
+
+!-
+! EXPECTED OUTPUT WITH
+!-
+! GIVEN: A DO loop should terminate with an END DO or CONTINUE
+
+subroutine foo2()
+do 01 m=1,2
+  select case (m)
+  case default
+print*, "default", m
+  case (1)
+print*, "start"
+01end select
+end subroutine
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -47,6 +47,8 @@
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -pedantic  Warn on language extensions
+! HELP-NEXT: -std=   Language standard to compile for
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 ! HELP-NEXT: -Xflang   Pass  to the flang compiler
@@ -96,6 +98,8 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -pedantic  Warn on language extensions
+! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -test-io   Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -47,6 +47,8 @@
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -o  Write output to 
+! CHECK-NEXT: -pedantic  Warn on language extensio

[PATCH] D97785: [SystemZ][z/OS] Distinguish between text and binary files on z/OS

2021-03-25 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan added a comment.

In D97785#2650824 , @yroux wrote:

> Hi Abhina,
>
> I think this patch broke Windows on ARM bots, the first failure observed 6
> days ago in this build:
>
> https://lab.llvm.org/buildbot/#/builders/65/builds/1245
>
> I don't really get what the problem is, but the issue is related to
> tablegen generated file AbstractTypeReader.inc and your patch is the only
> one in the set which is touching that area.
>
> Does it ring a bell for you ?
>
> Cheers,
> Yvan

Hi, thanks for bringing this to my attention. Since only Windows seems to have 
this error, it may be caused by my patch. I suspect that setting OF_None 
flag/Binary mode for Windows in getFile() should fix it if that is the case. 
I'll work on a patch to hopefully fix the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97785

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


Re: [PATCH] D97785: [SystemZ][z/OS] Distinguish between text and binary files on z/OS

2021-03-25 Thread Yvan Roux via cfe-commits
On Thu, 25 Mar 2021 at 18:13, Abhina Sree via Phabricator <
revi...@reviews.llvm.org> wrote:

> abhina.sreeskantharajan added a comment.
>
> In D97785#2650824 , @yroux wrote:
>
> > Hi Abhina,
> >
> > I think this patch broke Windows on ARM bots, the first failure observed
> 6
> > days ago in this build:
> >
> > https://lab.llvm.org/buildbot/#/builders/65/builds/1245
> >
> > I don't really get what the problem is, but the issue is related to
> > tablegen generated file AbstractTypeReader.inc and your patch is the only
> > one in the set which is touching that area.
> >
> > Does it ring a bell for you ?
> >
> > Cheers,
> > Yvan
>
> Hi, thanks for bringing this to my attention. Since only Windows seems to
> have this error, it may be caused by my patch. I suspect that setting
> OF_None flag/Binary mode for Windows in getFile() should fix it if that is
> the case. I'll work on a patch to hopefully fix the issue.
>

Ok, great thanks.


>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D97785/new/
>
> https://reviews.llvm.org/D97785
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96363: Mark output as text if it is really text

2021-03-25 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

This is why, in the past, we have taken the direction of opening all files as 
binary files. You have probably noticed all of the changes in this direction 
that you have to work around. I think the best solution here would be to add a 
new `OF_TextNoCrlf` mode that does what you need it to for System/Z, but opens 
the file in binary mode on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96363

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


[PATCH] D99227: [Coroutine][Clang] Force emit lifetime intrinsics for Coroutines

2021-03-25 Thread Xun Li via Phabricator via cfe-commits
lxfind updated this revision to Diff 38.
lxfind added a comment.

Address comments, and fix all tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99227

Files:
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGenCoroutines/coro-alloc.cpp
  clang/test/CodeGenCoroutines/coro-await-resume-eh.cpp
  clang/test/CodeGenCoroutines/coro-await.cpp
  clang/test/CodeGenCoroutines/coro-dest-slot.cpp
  clang/test/CodeGenCoroutines/coro-params.cpp
  clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp
  clang/test/CodeGenCoroutines/coro-unhandled-exception.cpp

Index: clang/test/CodeGenCoroutines/coro-unhandled-exception.cpp
===
--- clang/test/CodeGenCoroutines/coro-unhandled-exception.cpp
+++ clang/test/CodeGenCoroutines/coro-unhandled-exception.cpp
@@ -50,6 +50,8 @@
 // CHECK: [[TRYCONT]]:
 // CHECK-NEXT: br label %[[COROFIN:.+]]
 // CHECK: [[COROFIN]]:
+// CHECK-NEXT: bitcast %"struct.std::experimental::coroutines_v1::suspend_never"* %{{.+}} to i8*
+// CHECK-NEXT: call void @llvm.lifetime.start.p0i8(
 // CHECK-NEXT: call void @"?final_suspend@promise_type@coro_t@@QEAA?AUsuspend_never@coroutines_v1@experimental@std@@XZ"(
 
 // CHECK-LPAD: @_Z1fv(
@@ -69,4 +71,6 @@
 // CHECK-LPAD: [[TRYCONT]]:
 // CHECK-LPAD: br label %[[COROFIN:.+]]
 // CHECK-LPAD: [[COROFIN]]:
+// CHECK-LPAD-NEXT: bitcast %"struct.std::experimental::coroutines_v1::suspend_never"* %{{.+}} to i8*
+// CHECK-LPAD-NEXT: call void @llvm.lifetime.start.p0i8(
 // CHECK-LPAD-NEXT: call void @_ZN6coro_t12promise_type13final_suspendEv(
Index: clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp
===
--- clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp
+++ clang/test/CodeGenCoroutines/coro-symmetric-transfer-01.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -O1 -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -O0 -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s
 
 #include "Inputs/coroutine.h"
 
@@ -50,8 +50,13 @@
 
 // check that the lifetime of the coroutine handle used to obtain the address is contained within single basic block, and hence does not live across suspension points.
 // CHECK-LABEL: final.suspend:
-// CHECK: %[[PTR1:.+]] = bitcast %"struct.std::experimental::coroutines_v1::coroutine_handle.0"* %[[ADDR_TMP:.+]] to i8*
-// CHECK-NEXT:call void @llvm.lifetime.start.p0i8(i64 8, i8* %[[PTR1]])
-// CHECK: call i8* @{{.*address.*}}(%"struct.std::experimental::coroutines_v1::coroutine_handle.0"* {{[^,]*}} %[[ADDR_TMP]])
-// CHECK-NEXT:%[[PTR2:.+]] = bitcast %"struct.std::experimental::coroutines_v1::coroutine_handle.0"* %[[ADDR_TMP]] to i8*
-// CHECK-NEXT:call void @llvm.lifetime.end.p0i8(i64 8, i8* %[[PTR2]])
+// CHECK: %{{.+}} = call token @llvm.coro.save(i8* null)
+// CHECK: %[[HDL_CAST1:.+]] = bitcast %"struct.std::experimental::coroutines_v1::coroutine_handle.0"* %[[HDL:.+]] to i8*
+// CHECK: call void @llvm.lifetime.start.p0i8(i64 8, i8* %[[HDL_CAST1]])
+// CHECK: %[[CALL:.+]] = call i8* @_ZN13detached_task12promise_type13final_awaiter13await_suspendENSt12experimental13coroutines_v116coroutine_handleIS0_EE(
+// CHECK: %[[HDL_CAST2:.+]] = getelementptr inbounds %"struct.std::experimental::coroutines_v1::coroutine_handle.0", %"struct.std::experimental::coroutines_v1::coroutine_handle.0"* %[[HDL]], i32 0, i32 0
+// CHECK: store i8* %[[CALL]], i8** %[[HDL_CAST2]], align 8
+// CHECK: %[[HDL_TRANSFER:.+]] = call i8* @_ZNKSt12experimental13coroutines_v116coroutine_handleIvE7addressEv(%"struct.std::experimental::coroutines_v1::coroutine_handle.0"* nonnull dereferenceable(8) %[[HDL]])
+// CHECK: %[[HDL_CAST3:.+]] = bitcast %"struct.std::experimental::coroutines_v1::coroutine_handle.0"* %[[HDL]] to i8*
+// CHECK: call void @llvm.lifetime.end.p0i8(i64 8, i8* %[[HDL_CAST3]])
+// CHECK: call void @llvm.coro.resume(i8* %[[HDL_TRANSFER]])
Index: clang/test/CodeGenCoroutines/coro-params.cpp
===
--- clang/test/CodeGenCoroutines/coro-params.cpp
+++ clang/test/CodeGenCoroutines/coro-params.cpp
@@ -70,7 +70,11 @@
 
   // CHECK: call i8* @llvm.coro.begin(
   // CHECK: call void @_ZN8MoveOnlyC1EOS_(%struct.MoveOnly* {{[^,]*}} %[[MoCopy]], %struct.MoveOnly* nonnull align 4 dereferenceable(4) %[[MoParam]])
+  // CHECK-NEXT: bitcast %struct.MoveAndCopy* %[[McCopy]] to i8*
+  // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(
   // CHECK-NEXT: call void @_ZN11MoveAndCopyC1EOS_(%struct.MoveAndCopy* {{[^,]*}} %[[McCopy]], %struct.MoveAndCopy* n

[PATCH] D98135: [OpenMP][InstrProfiling] Fix a missing instr profiling counter

2021-03-25 Thread Xun Li via Phabricator via cfe-commits
lxfind added a comment.

@ABataev, wondering if you have a timeline on this?
Missing counters from OMP functions sometimes cause llvm-cov to crash because 
of data inconsistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98135

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


[PATCH] D99353: [driver] Make `clang` warn rather then error on `flang` options

2021-03-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
Herald added a reviewer: sscalpone.
awarzynski requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds extra logic in Driver::ParseArgStrings so that `clang`
(Clang's compiler driver) generates a warning when a Flang-only option
is used. Previously it would throw an error:

- `error: unknown argument: `

and exit immediately. That was flagged as problematic in [1].

The new behaviour is consistent with GCC:

  gcc -c  -ffree-form  file.c
  cc1: warning: command line option ‘-ffree-form’ is valid for Fortran but not 
for C

It allows users to use `clang` as e.g. a linker driver, without worrying
about passing Fortran specific flags to `clang`. These flags are often
embedded in build systems and are hard to extract just for linking.
An issue like this raised in [1]. This patch is an attempt to address
this.

The current approach is a bit verbose. Ideally we should extend the
OptTable API to make accommodating for situations like this easier. In
particular, I'm not sure whether we can add similar logic for Flang.
In this patch we are relying on the `FlangOnlyOption` flag to
identify problematic options. There's no equivalent flag for Clang-only
options. I propose that we address this later, when this becomes a
problem for Flang.

[1] https://reviews.llvm.org/D95460


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99353

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -223,7 +223,6 @@
   InputArgList Args =
   getOpts().ParseArgs(ArgStrings, MissingArgIndex, MissingArgCount,
   IncludedFlagsBitmask, ExcludedFlagsBitmask);
-
   // Check for missing argument error.
   if (MissingArgCount) {
 Diag(diag::err_drv_missing_argument)
@@ -263,20 +262,43 @@
   }
 
   for (const Arg *A : Args.filtered(options::OPT_UNKNOWN)) {
-unsigned DiagID;
+// The default diagnostic when the option is unknow
+unsigned DiagID = diag::err_drv_unknown_argument;
+
+// Try to find a good hint for the user
 auto ArgString = A->getAsString(Args);
 std::string Nearest;
-if (getOpts().findNearest(
-  ArgString, Nearest, IncludedFlagsBitmask, ExcludedFlagsBitmask) > 1) 
{
-  DiagID = IsCLMode() ? diag::warn_drv_unknown_argument_clang_cl
-  : diag::err_drv_unknown_argument;
-  Diags.Report(DiagID) << ArgString;
-} else {
+unsigned Distance = getOpts().findNearest(
+ArgString, Nearest, IncludedFlagsBitmask, ExcludedFlagsBitmask);
+assert(Distance != 0 && "This option should not be 'unknown'");
+
+if (Distance == 1) {
+  // Found a good suggestion - propose that in the diagnostic
   DiagID = IsCLMode()
? diag::warn_drv_unknown_argument_clang_cl_with_suggestion
: diag::err_drv_unknown_argument_with_suggestion;
   Diags.Report(DiagID) << ArgString << Nearest;
+} else {
+  // No good suggestion was found - the diagnostic depends on the mode in
+  // which the driver operates
+  if (IsCLMode())
+// In CL mode just warn the user (MSVC consumes everything anyway)
+DiagID = diag::warn_drv_unknown_argument_clang_cl;
+  else if (!IsFlangMode()) {
+// In non-Flang mode, check whether this is a Flang flag and
+// communicate accordingly.
+ExcludedFlagsBitmask &= ~options::FlangOnlyOption;
+if (getOpts().findNearest(ArgString, Nearest, IncludedFlagsBitmask,
+  ExcludedFlagsBitmask) == 0)
+  DiagID =
+  Diags.getCustomDiagID(clang::DiagnosticsEngine::Warning,
+"command line option ‘%0’ is only valid "
+"in Flang mode (i.e. for Fortran input)");
+  } // TODO: Check whether this is a C-mode flag and report accordingly.
+
+  Diags.Report(DiagID) << ArgString;
 }
+
 ContainsError |= Diags.getDiagnosticLevel(DiagID, SourceLocation()) >
  DiagnosticsEngine::Warning;
   }


Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -223,7 +223,6 @@
   InputArgList Args =
   getOpts().ParseArgs(ArgStrings, MissingArgIndex, MissingArgCount,
   IncludedFlagsBitmask, ExcludedFlagsBitmask);
-
   // Check for missing argument error.
   if (MissingArgCount) {
 Diag(diag::err_drv_missing_argument)
@@ -263,20 +262,43 @@
   }
 
   for (const Arg *A : Args.filtered(options::OPT_UNKNOWN)) {
-unsigned DiagID;
+// The default diagnostic when the option is unknow
+unsigned DiagID = diag::err_drv_unknown_argument;
+
+// Try to find a good hint for the use

[PATCH] D99343: [Analyzer] Infer 0 value when the divisible is 0 (bug fix)

2021-03-25 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added a comment.

Thanks for the review!




Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:655
 return makeSymExprValNN(op, InputLHS, InputRHS, resultTy);
+  case BO_Div:
   case BO_Rem:

vsavchenko wrote:
> I think we should either add: `// 0 / x == 0` or modify the comment for 
> `BO_Rem`
Okay, I added the new comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99343

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


[PATCH] D98638: [RFC][Coroutine] Force stack allocation after await_suspend() call

2021-03-25 Thread Xun Li via Phabricator via cfe-commits
lxfind abandoned this revision.
lxfind added a comment.

Abandoning in favor of D99227 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98638

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


[clang] 015c398 - [Analyzer] Infer 0 value when the divisible is 0 (bug fix)

2021-03-25 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2021-03-25T18:25:06+01:00
New Revision: 015c39882ebc1771713a7523ae76903ebae83288

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

LOG: [Analyzer] Infer 0 value when the divisible is 0 (bug fix)

Currently, we infer 0 if the divisible of the modulo op is 0:
  int a = x < 0; // a can be 0
  int b = a % y; // b is either 1 % sym or 0
However, we don't when the op is / :
  int a = x < 0; // a can be 0
  int b = a / y; // b is either 1 / sym or 0 / sym

This commit fixes the discrepancy.

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

Added: 
clang/test/Analysis/zero-operands.c

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

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index facadaf1225f8..872616fedb4eb 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -652,6 +652,8 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
 if (LHSValue == 0)
   return evalCastFromNonLoc(lhs, resultTy);
 return makeSymExprValNN(op, InputLHS, InputRHS, resultTy);
+  case BO_Div:
+// 0 / x == 0
   case BO_Rem:
 // 0 % x == 0
 if (LHSValue == 0)

diff  --git a/clang/test/Analysis/zero-operands.c 
b/clang/test/Analysis/zero-operands.c
new file mode 100644
index 0..3311c524f8146
--- /dev/null
+++ b/clang/test/Analysis/zero-operands.c
@@ -0,0 +1,53 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify %s
+
+void clang_analyzer_dump(int);
+
+void test_0_multiplier1(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a * y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_multiplier2(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = y * a;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_modulo(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a % y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 % (reg_${{[[:digit:]]+}})}}
+}
+
+void test_0_divisible(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a / y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 / (reg_${{[[:digit:]]+}})}}
+}



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


[PATCH] D99343: [Analyzer] Infer 0 value when the divisible is 0 (bug fix)

2021-03-25 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
martong marked an inline comment as done.
Closed by commit rG015c39882ebc: [Analyzer] Infer 0 value when the divisible is 
0 (bug fix) (authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D99343?vs=08&id=41#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99343

Files:
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/zero-operands.c


Index: clang/test/Analysis/zero-operands.c
===
--- /dev/null
+++ clang/test/Analysis/zero-operands.c
@@ -0,0 +1,53 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify %s
+
+void clang_analyzer_dump(int);
+
+void test_0_multiplier1(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a * y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_multiplier2(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = y * a;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_modulo(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a % y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 % (reg_${{[[:digit:]]+}})}}
+}
+
+void test_0_divisible(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a / y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 / (reg_${{[[:digit:]]+}})}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -652,6 +652,8 @@
 if (LHSValue == 0)
   return evalCastFromNonLoc(lhs, resultTy);
 return makeSymExprValNN(op, InputLHS, InputRHS, resultTy);
+  case BO_Div:
+// 0 / x == 0
   case BO_Rem:
 // 0 % x == 0
 if (LHSValue == 0)


Index: clang/test/Analysis/zero-operands.c
===
--- /dev/null
+++ clang/test/Analysis/zero-operands.c
@@ -0,0 +1,53 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify %s
+
+void clang_analyzer_dump(int);
+
+void test_0_multiplier1(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a * y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_multiplier2(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = y * a;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+
+}
+
+void test_0_modulo(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a % y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 % (reg_${{[[:digit:]]+}})}}
+}
+
+void test_0_divisible(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a / y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 / (reg_${{[[:digit:]]+}})}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -652,6 +652,8 @@
 if (LHSValue == 0)
   return evalCastFromNonLoc(lhs, resultTy);
 return makeSymExprValNN(op, InputLHS, InputRHS, resultTy);
+  case BO_Div:
+// 0 / x == 0
   case BO_Rem:
 // 0 % x == 0
 if (LHSValue == 0)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cg

[PATCH] D99343: [Analyzer] Infer 0 value when the divisible is 0 (bug fix)

2021-03-25 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

Awesome! Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99343

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


[PATCH] D98135: [OpenMP][InstrProfiling] Fix a missing instr profiling counter

2021-03-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D98135#2650914 , @lxfind wrote:

> @ABataev, wondering if you have a timeline on this?
> Missing counters from OMP functions sometimes cause llvm-cov to crash because 
> of data inconsistency.

Cannot answer right now. It would be much easier to fix this if you could 
provide additional info about what tests are exactly failed, what are the 
constructs that do not support it, etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98135

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


[clang-tools-extra] 7f5abb6 - [clangd] Fix a use-after-free

2021-03-25 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-03-25T18:26:17+01:00
New Revision: 7f5abb63733238b89cf5d47116b2af68cda2af4e

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

LOG: [clangd] Fix a use-after-free

Clangd was storing reference to a possibly-dead string in compiled
config. This patch fixes the issue by copying suppression strings from
fragments into compiled Config.

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

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

Added: 


Modified: 
clang-tools-extra/clangd/ConfigCompile.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp 
b/clang-tools-extra/clangd/ConfigCompile.cpp
index 9aed3c4679f5e..8f402ae061535 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -371,7 +371,7 @@ struct FragmentCompiler {
   }
 
   void compile(Fragment::DiagnosticsBlock &&F) {
-std::vector Normalized;
+std::vector Normalized;
 for (const auto &Suppressed : F.Suppress) {
   if (*Suppressed == "*") {
 Out.Apply.push_back([&](const Params &, Config &C) {
@@ -380,15 +380,16 @@ struct FragmentCompiler {
 });
 return;
   }
-  Normalized.push_back(normalizeSuppressedCode(*Suppressed));
+  Normalized.push_back(normalizeSuppressedCode(*Suppressed).str());
 }
 if (!Normalized.empty())
-  Out.Apply.push_back([Normalized](const Params &, Config &C) {
-if (C.Diagnostics.SuppressAll)
-  return;
-for (llvm::StringRef N : Normalized)
-  C.Diagnostics.Suppress.insert(N);
-  });
+  Out.Apply.push_back(
+  [Normalized(std::move(Normalized))](const Params &, Config &C) {
+if (C.Diagnostics.SuppressAll)
+  return;
+for (llvm::StringRef N : Normalized)
+  C.Diagnostics.Suppress.insert(N);
+  });
 
 compile(std::move(F.ClangTidy));
   }



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


[PATCH] D99353: [driver] Make `clang` warn rather then error on `flang` options

2021-03-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a subscriber: protze.joachim.
awarzynski added a comment.

I've not had a chance to add tests yet. I will add them shortly.

@protze.joachim , hopefully this addresses the issues that you raised in 
https://reviews.llvm.org/D95460. Please, could you verify before I update this? 
I want to make sure that this is the right approach. Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99353

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


[PATCH] D99086: [clang][Syntax] Optimize expandedTokens for token ranges.

2021-03-25 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 44.
usaxena95 marked 4 inline comments as done.
usaxena95 added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99086

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/Syntax/TokensTest.cpp


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -106,6 +106,7 @@
   void EndSourceFileAction() override {
 assert(Collector && "BeginSourceFileAction was never called");
 Result = std::move(*Collector).consume();
+Result.indexExpandedTokens();
   }
 
   std::unique_ptr
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -183,7 +183,31 @@
   return Text.substr(Begin, length());
 }
 
+void TokenBuffer::indexExpandedTokens() {
+  // No-op if the index is already created.
+  if (!ExpandedTokIndex.empty())
+return;
+  ExpandedTokIndex.reserve(ExpandedTokens.size());
+  // Index ExpandedTokens for faster lookups by SourceLocation.
+  for (size_t I = 0, E = ExpandedTokens.size(); I != E; ++I)
+ExpandedTokIndex[ExpandedTokens[I].location()] = I;
+}
+
 llvm::ArrayRef TokenBuffer::expandedTokens(SourceRange R) const 
{
+  if (!ExpandedTokIndex.empty()) {
+// Quick lookup if `R` is a token range.
+// This is a huge win since majority of the users use ranges provided by an
+// AST. Ranges in AST are token ranges from expanded token stream.
+const auto B = ExpandedTokIndex.find(R.getBegin());
+const auto E = ExpandedTokIndex.find(R.getEnd());
+if (B != ExpandedTokIndex.end() && E != ExpandedTokIndex.end()) {
+  // Add 1 to End to make a half-open range.
+  return {ExpandedTokens.data() + B->getSecond(),
+  ExpandedTokens.data() + E->getSecond() + 1};
+}
+  }
+  // Slow case. Use `isBeforeInTranslationUnit` to binary search for the
+  // required range.
   return getTokensCovering(expandedTokens(), R, *SourceMgr);
 }
 
Index: clang/include/clang/Tooling/Syntax/Tokens.h
===
--- clang/include/clang/Tooling/Syntax/Tokens.h
+++ clang/include/clang/Tooling/Syntax/Tokens.h
@@ -34,6 +34,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
@@ -192,8 +193,13 @@
 return ExpandedTokens;
   }
 
+  /// Builds a cache to make future calls to expandedToken(SourceRange) faster.
+  /// Creates an index only once. Further calls to it will be no-op.
+  void indexExpandedTokens();
+
   /// Returns the subrange of expandedTokens() corresponding to the closed
   /// token range R.
+  /// Consider calling indexExpandedTokens() before for faster lookups.
   llvm::ArrayRef expandedTokens(SourceRange R) const;
 
   /// Returns the subrange of spelled tokens corresponding to AST node spanning
@@ -366,6 +372,8 @@
   /// same stream as 'clang -E' (excluding the preprocessor directives like
   /// #file, etc.).
   std::vector ExpandedTokens;
+  // Index of ExpandedTokens for faster lookups by SourceLocation.
+  llvm::DenseMap ExpandedTokIndex;
   llvm::DenseMap Files;
   // The value is never null, pointer instead of reference to avoid disabling
   // implicit assignment operator.
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -423,6 +423,8 @@
   // tokens from running the preprocessor inside the checks (only
   // modernize-use-trailing-return-type does that today).
   syntax::TokenBuffer Tokens = std::move(CollectTokens).consume();
+  // Makes SelectionTree build much faster.
+  Tokens.indexExpandedTokens();
   std::vector ParsedDecls = Action->takeTopLevelDecls();
   // AST traversals should exclude the preamble, to avoid performance cliffs.
   Clang->getASTContext().setTraversalScope(ParsedDecls);


Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -106,6 +106,7 @@
   void EndSourceFileAction() override {
 assert(Collector && "BeginSourceFileAction was never called");
 Result = std::move(*Collector).consume();
+Result.indexExpandedTokens();
   }
 
   std::unique_ptr
Index: clang/lib/T

[PATCH] D99250: [DebugInfo] Fix the mismatching of C++ language tags and Dwarf versions.

2021-03-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

My 2c:

I don't have super strong feelings either way about this particular issue.

Yes, I agree a consumer shouldn't crash and probably should handle an unknown 
language code fairly gracefully - but equally it's a loss of quality for a 
conforming DWARFv3 consumer to see a language code it doesn't recognize and 
drop all C++ support it might have/been able to use if it had been given a code 
that existed in v3. (this'd be nicely addressed by separating language code 
from version - then it could warn the user "unknown C++ version, I'll just use 
the latest version I support - so you might not be able to write newer C++ 
features in the expression evaluator, like hyperlambdas or whatever weird 
things exist in future C++")

So it's a tradeoff between consumers that know about newer C++ language codes 
and those that don't. I suspect if you're compiling with DWARFv3 it's because 
you've got consumers who only understand v3 & could benefit from the old code 
(but maybe you have some sample profiler, or crash symbolizer that only 
understands that - which doesn't actually care about the language version - and 
the interactive debugger you use is totally capable of parsing DWARFv5 and 
recognizing all its variety of language codes even when parsing old DWARF).

So... dunno.

In this specific case, I guess then the question is for the user: @Esme: What 
would your DWARF consumer do with an unknown code if it didn't crash? Would the 
user experience be significantly worse/different because it didn't recognize 
the code?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99250

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


[PATCH] D96363: Mark output as text if it is really text

2021-03-25 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan added a comment.

In D96363#2650904 , @rnk wrote:

> This is why, in the past, we have taken the direction of opening all files as 
> binary files. You have probably noticed all of the changes in this direction 
> that you have to work around. I think the best solution here would be to add 
> a new `OF_TextNoCrlf` mode that does what you need it to for System/Z, but 
> opens the file in binary mode on Windows.

Right, adding a new flag like OF_TextNoCrlf is something I can look into as a 
solution. However, if Windows is always using binary mode and has no use for 
OF_Text flag, maybe I can globally set that mode similar to how I set it for 
ToolOutputFiles. I don't think any other platform is affected by the 
binary/text mode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96363

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


[PATCH] D99344: [Analyzer] Track RValue expressions

2021-03-25 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 46.
martong added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99344

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/division-by-zero-track-zero.c
  clang/test/Analysis/division-by-zero-track-zero.cpp
  clang/test/Analysis/nullptr.cpp

Index: clang/test/Analysis/nullptr.cpp
===
--- clang/test/Analysis/nullptr.cpp
+++ clang/test/Analysis/nullptr.cpp
@@ -64,7 +64,7 @@
 
 typedef __INTPTR_TYPE__ intptr_t;
 void zoo1multiply() {
-  char **p = 0; // FIXME-should-be-note:{{'p' initialized to a null pointer value}}
+  char **p = 0; // expected-note{{'p' initialized to a null pointer value}}
   delete *((char **)((intptr_t)p * 2)); // expected-warning{{Dereference of null pointer}}
// expected-note@-1{{Dereference of null pointer}}
 }
Index: clang/test/Analysis/division-by-zero-track-zero.cpp
===
--- /dev/null
+++ clang/test/Analysis/division-by-zero-track-zero.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-output=text \
+// RUN:   -verify %s
+
+namespace test_tracking_of_lhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = p0 * y; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_lhs_multiplier
+
+namespace test_tracking_of_rhs_multiplier {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = y * p0; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_rhs_multiplier
+
+namespace test_tracking_of_nested_multiplier {
+  int f(int x, int y, int z) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}} \
+  // expected-note {{'p0' initialized to 0}}
+int div = y*z*p0; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_nested_multiplier
+
+namespace test_tracking_through_multiple_stmts {
+  int f(int x, int y) {
+bool p0 = x < 0;  // expected-note {{Assuming 'x' is >= 0}}
+bool p1 = p0 ? 0 : 1; // expected-note {{'p0' is false}} \
+  // expected-note {{'?' condition is false}}
+bool p2 = 1 - p1; // expected-note {{'p2' initialized to 0}}
+int div = p2 * y; // expected-note {{'div' initialized to 0}}
+return 1 / div;   // expected-note {{Division by zero}} \
+  // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_through_multiple_stmts
+
+namespace test_tracking_both_lhs_and_rhs {
+  int f(int x, int y) {
+bool p0 = x < 0;   // expected-note {{Assuming 'x' is >= 0}} \
+   // expected-note {{'p0' initialized to 0}}
+bool p1 = y < 0;   // expected-note {{Assuming 'y' is >= 0}} \
+   // expected-note {{'p1' initialized to 0}}
+int div = p0 * p1; // expected-note {{'div' initialized to 0}}
+return 1 / div;// expected-note {{Division by zero}} \
+   // expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_both_lhs_and_rhs
+
+namespace test_tracking_of_multiplier_and_parens {
+  int f(int x, int y, int z) {
+bool p0 = x < 0;// expected-note {{Assuming 'x' is >= 0}} \
+// expected-note {{'p0' initialized to 0}}
+int div = y*(z*p0); // expected-note {{'div' initialized to 0}}
+return 1 / div; // expected-note {{Division by zero}} \
+// expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_multiplier_and_parens
+
+namespace test_tracking_of_divisible {
+  int f(int x, int y) {
+bool p0 = x < 0;// expected-note {{Assuming 'x' is >= 0}} \
+// expected-note {{'p0' initialized to 0}}
+int div = p0 / y;   // expected-note {{'div' initialized to 0}}
+return 1 / div; // expected-note {{Division by zero}} \
+// expected-warning {{Division by zero}}
+  }
+} // namespace test_tracking_of_divisible
+
+namespace test_tracking_of_modulo {
+  int f(int x, int y) {
+bool p0 = x

  1   2   >