[clang] 39e3e3a - [NewPM] Redesign of PreserveCFG Checker

2021-04-05 Thread Yevgeny Rouban via cfe-commits

Author: Yevgeny Rouban
Date: 2021-04-06T12:35:49+07:00
New Revision: 39e3e3aa51d628722637c1bfa507f9ec2c532120

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

LOG: [NewPM] Redesign of PreserveCFG Checker

The reason for the NewPM redesign is described in the commit
  cba3e783389a: [NewPM] Disable PreservedCFGChecker ...

The checker introduces an internal custom CFG analysis that tracks
current up-to date CFG snapshot. The analysis is invalidated along
any other CFG related analysis (the key is CFGAnalyses). If the CFG
analysis is not invalidated at a functional pass exit then the checker
asserts that the CFG snapshot taken from this analysis is equals to
a snapshot of the current CFG.

Along the way:
- the function CFG::printDiff() is simplified by removing function
  name calculation. The name is printed by the caller;
- fixed CFG invalidated condition (see CFG::invalidate());
- StandardInstrumentations::registerCallbacks() gets additional
  optional parameter of type FunctionAnalysisManager*, which is
  needed by the checker to get the custom CFG analysis;
- several PM related tests updated to explicitly set
  -verify-cfg-preserved=1 as they need.

This patch is safe to land as the CFGChecker is left switched off
(the options -verify-cfg-preserved is false by default). It will be
switched on by a separate patch to minimize possible reverts.

Reviewed By: skatkov, kuhar

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

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Passes/StandardInstrumentations.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Passes/StandardInstrumentations.cpp
llvm/test/Other/new-pass-manager.ll
llvm/test/Other/new-pm-defaults.ll
llvm/tools/opt/NewPMDriver.cpp
llvm/unittests/IR/PassManagerTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 00d92e7beadd4..7edca6fb30730 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1268,9 +1268,14 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
   PTO.Coroutines = LangOpts.Coroutines;
 
+  LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
+  FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
+  CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
+  ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
+
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(CodeGenOpts.DebugPassManager);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   PassBuilder PB(CodeGenOpts.DebugPassManager, TM.get(), PTO, PGOOpt, );
 
   // Attempt to load pass plugins and register their callbacks with PB.
@@ -1287,11 +1292,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
 #include "llvm/Support/Extension.def"
 
-  LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
-  FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
-  CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
-  ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
-
   // Register the AA manager first so that our version is the one used.
   FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); });
 

diff  --git a/llvm/include/llvm/Passes/StandardInstrumentations.h 
b/llvm/include/llvm/Passes/StandardInstrumentations.h
index d24f3fbbf2e54..6953d0cd1b0a1 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -91,7 +91,16 @@ class PrintPassInstrumentation {
 };
 
 class PreservedCFGCheckerInstrumentation {
-private:
+public:
+  // Keeps sticky poisoned flag for the given basic block once it has been
+  // deleted or RAUWed.
+  struct BBGuard final : public CallbackVH {
+BBGuard(const BasicBlock *BB) : CallbackVH(BB) {}
+void deleted() override { CallbackVH::deleted(); }
+void allUsesReplacedWith(Value *) override { CallbackVH::deleted(); }
+bool isPoisoned() const { return !getValPtr(); }
+  };
+
   // CFG is a map BB -> {(Succ, Multiplicity)}, where BB is a non-leaf basic
   // block, {(Succ, Multiplicity)} set of all pairs of the block's successors
   // and the multiplicity of the edge (BB->Succ). As the mapped sets are
@@ -101,40 +110,34 @@ class PreservedCFGCheckerInstrumentation {
   // in the Graph (BBGuard). That is if any of the block is deleted or RAUWed
   // then the CFG is treated poisoned and no block pointer of the Graph is 
used.
   struct CFG {
-struct BBGuard final : public CallbackVH {
-  BBGuard(const BasicBlock *BB) : CallbackVH(BB) {}
-  void deleted() override { CallbackVH::deleted(); }
-  

[PATCH] D91327: [NewPM] Redesign of PreserveCFG Checker

2021-04-05 Thread Yevgeny Rouban 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 rG39e3e3aa51d6: [NewPM] Redesign of PreserveCFG Checker 
(authored by yrouban).

Changed prior to commit:
  https://reviews.llvm.org/D91327?vs=335221=335405#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91327

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/Other/new-pass-manager.ll
  llvm/test/Other/new-pm-defaults.ll
  llvm/tools/opt/NewPMDriver.cpp
  llvm/unittests/IR/PassManagerTest.cpp

Index: llvm/unittests/IR/PassManagerTest.cpp
===
--- llvm/unittests/IR/PassManagerTest.cpp
+++ llvm/unittests/IR/PassManagerTest.cpp
@@ -827,7 +827,7 @@
   FunctionPassManager FPM(/*DebugLogging*/ true);
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(/*DebugLogging*/ true);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   FAM.registerPass([&] { return PassInstrumentationAnalysis(); });
   FAM.registerPass([&] { return DominatorTreeAnalysis(); });
   FAM.registerPass([&] { return AssumptionAnalysis(); });
@@ -873,7 +873,7 @@
   FunctionPassManager FPM(/*DebugLogging*/ true);
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(/*DebugLogging*/ true);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   FAM.registerPass([&] { return PassInstrumentationAnalysis(); });
   FAM.registerPass([&] { return DominatorTreeAnalysis(); });
   FAM.registerPass([&] { return AssumptionAnalysis(); });
@@ -938,7 +938,7 @@
   FunctionPassManager FPM(/*DebugLogging*/ true);
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(/*DebugLogging*/ true);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   FAM.registerPass([&] { return PassInstrumentationAnalysis(); });
   FAM.registerPass([&] { return DominatorTreeAnalysis(); });
   FAM.registerPass([&] { return AssumptionAnalysis(); });
Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -275,9 +275,14 @@
   P->CSAction = PGOOptions::CSIRUse;
 }
   }
+  LoopAnalysisManager LAM(DebugPM);
+  FunctionAnalysisManager FAM(DebugPM);
+  CGSCCAnalysisManager CGAM(DebugPM);
+  ModuleAnalysisManager MAM(DebugPM);
+
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(DebugPM, VerifyEachPass);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   DebugifyEachInstrumentation Debugify;
   if (DebugifyEach)
 Debugify.registerCallbacks(PIC);
@@ -373,11 +378,6 @@
 }
   }
 
-  LoopAnalysisManager LAM(DebugPM);
-  FunctionAnalysisManager FAM(DebugPM);
-  CGSCCAnalysisManager CGAM(DebugPM);
-  ModuleAnalysisManager MAM(DebugPM);
-
   // Register the AA manager first so that our version is the one used.
   FAM.registerPass([&] { return std::move(AA); });
   // Register our TargetLibraryInfoImpl.
Index: llvm/test/Other/new-pm-defaults.ll
===
--- llvm/test/Other/new-pm-defaults.ll
+++ llvm/test/Other/new-pm-defaults.ll
@@ -7,62 +7,62 @@
 ; Any invalidation that shows up here is a bug, unless we started modifying
 ; the IR, in which case we need to make it immutable harder.
 
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O1,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S  %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S  %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-Os,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-Oz,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify 

[PATCH] D99237: [AVR][clang] Fix wrong calling convention in functions return struct type

2021-04-05 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 335368.

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

https://reviews.llvm.org/D99237

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/avr/struct.c


Index: clang/test/CodeGen/avr/struct.c
===
--- /dev/null
+++ clang/test/CodeGen/avr/struct.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm %s -o - | FileCheck %s
+
+// Structure that is more than 8 bytes.
+struct s10 {
+  int a, b, c, d, e;
+};
+
+// Structure that is less than 8 bytes.
+struct s06 {
+  int a, b, c;
+};
+
+struct s10 foo10(int a, int b, int c) {
+struct s10 a0;
+return a0;
+}
+
+struct s06 foo06(int a, int b, int c) {
+struct s06 a0;
+return a0;
+}
+
+// CHECK: %struct.s10 = type { i16, i16, i16, i16, i16 }
+// CHECK: %struct.s06 = type { i16, i16, i16 }
+// CHECK: define{{.*}} void @foo10(%struct.s10* {{.*}}, i16 %a, i16 %b, i16 %c)
+// CHECK: define{{.*}} %struct.s06 @foo06(i16 %a, i16 %b, i16 %c)
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8087,14 +8087,39 @@
 }
 
 
//===--===//
-// AVR ABI Implementation.
+// AVR ABI Implementation. Documented at
+// https://gcc.gnu.org/wiki/avr-gcc#Calling_Convention
+// https://gcc.gnu.org/wiki/avr-gcc#Reduced_Tiny
 
//===--===//
 
 namespace {
+class AVRABIInfo : public DefaultABIInfo {
+public:
+  AVRABIInfo(CodeGenTypes ) : DefaultABIInfo(CGT) {}
+
+  ABIArgInfo classifyReturnType(QualType Ty) const {
+// A return struct with size less than or equal to 8 bytes is returned
+// directly via registers R18-R25.
+if (isAggregateTypeForABI(Ty) && getContext().getTypeSize(Ty) <= 64)
+  return ABIArgInfo::getDirect();
+else
+  return DefaultABIInfo::classifyReturnType(Ty);
+  }
+
+  // Just copy the original implementation of DefaultABIInfo::computeInfo(),
+  // since DefaultABIInfo::classify{Return,Argument}Type() are not virtual.
+  void computeInfo(CGFunctionInfo ) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+for (auto  : FI.arguments())
+  I.info = classifyArgumentType(I.type);
+  }
+};
+
 class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AVRTargetCodeGenInfo(CodeGenTypes )
-  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule ) const override {


Index: clang/test/CodeGen/avr/struct.c
===
--- /dev/null
+++ clang/test/CodeGen/avr/struct.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple avr -emit-llvm %s -o - | FileCheck %s
+
+// Structure that is more than 8 bytes.
+struct s10 {
+  int a, b, c, d, e;
+};
+
+// Structure that is less than 8 bytes.
+struct s06 {
+  int a, b, c;
+};
+
+struct s10 foo10(int a, int b, int c) {
+struct s10 a0;
+return a0;
+}
+
+struct s06 foo06(int a, int b, int c) {
+struct s06 a0;
+return a0;
+}
+
+// CHECK: %struct.s10 = type { i16, i16, i16, i16, i16 }
+// CHECK: %struct.s06 = type { i16, i16, i16 }
+// CHECK: define{{.*}} void @foo10(%struct.s10* {{.*}}, i16 %a, i16 %b, i16 %c)
+// CHECK: define{{.*}} %struct.s06 @foo06(i16 %a, i16 %b, i16 %c)
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8087,14 +8087,39 @@
 }
 
 //===--===//
-// AVR ABI Implementation.
+// AVR ABI Implementation. Documented at
+// https://gcc.gnu.org/wiki/avr-gcc#Calling_Convention
+// https://gcc.gnu.org/wiki/avr-gcc#Reduced_Tiny
 //===--===//
 
 namespace {
+class AVRABIInfo : public DefaultABIInfo {
+public:
+  AVRABIInfo(CodeGenTypes ) : DefaultABIInfo(CGT) {}
+
+  ABIArgInfo classifyReturnType(QualType Ty) const {
+// A return struct with size less than or equal to 8 bytes is returned
+// directly via registers R18-R25.
+if (isAggregateTypeForABI(Ty) && getContext().getTypeSize(Ty) <= 64)
+  return ABIArgInfo::getDirect();
+else
+  return DefaultABIInfo::classifyReturnType(Ty);
+  }
+
+  // Just copy the original implementation of DefaultABIInfo::computeInfo(),
+  // since DefaultABIInfo::classify{Return,Argument}Type() are not virtual.
+  void computeInfo(CGFunctionInfo ) const override {
+if (!getCXXABI().classifyReturnType(FI))
+  

[PATCH] D71726: Let clang atomic builtins fetch add/sub support floating point types

2021-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 335366.
yaxunl marked an inline comment as done.
yaxunl added a comment.

Revised by John's comments. Do not allow atomic fetch add with x86_fp80.


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

https://reviews.llvm.org/D71726

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/fp-atomic-ops.c
  clang/test/CodeGenCUDA/amdgpu-atomic-ops.cu
  clang/test/CodeGenOpenCL/atomic-ops.cl
  clang/test/Sema/atomic-ops.c
  clang/test/SemaOpenCL/atomic-ops.cl

Index: clang/test/SemaOpenCL/atomic-ops.cl
===
--- clang/test/SemaOpenCL/atomic-ops.cl
+++ clang/test/SemaOpenCL/atomic-ops.cl
@@ -1,10 +1,13 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only -triple=spir64
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only -triple=amdgcn-amdhsa-amd-opencl
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify=expected,spir \
+// RUN:   -fsyntax-only -triple=spir64
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only \
+// RUN:   -triple=amdgcn-amd-amdhsa
 
 // Basic parsing/Sema tests for __opencl_atomic_*
 
 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
 #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
 typedef __INTPTR_TYPE__ intptr_t;
 typedef int int8 __attribute__((ext_vector_type(8)));
@@ -36,7 +39,7 @@
 
 atomic_int gn;
 void f(atomic_int *i, const atomic_int *ci,
-   atomic_intptr_t *p, atomic_float *d,
+   atomic_intptr_t *p, atomic_float *f, atomic_double *d, atomic_half *h, // expected-error {{unknown type name 'atomic_half'}}
int *I, const int *CI,
intptr_t *P, float *D, struct S *s1, struct S *s2,
global atomic_int *i_g, local atomic_int *i_l, private atomic_int *i_p,
@@ -57,37 +60,38 @@
 
   __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_work_group);
   __opencl_atomic_load(p, memory_order_seq_cst, memory_scope_work_group);
-  __opencl_atomic_load(d, memory_order_seq_cst, memory_scope_work_group);
+  __opencl_atomic_load(f, memory_order_seq_cst, memory_scope_work_group);
   __opencl_atomic_load(ci, memory_order_seq_cst, memory_scope_work_group);
   __opencl_atomic_load(i_c, memory_order_seq_cst, memory_scope_work_group); // expected-error {{address argument to atomic operation must be a pointer to non-constant _Atomic type ('__constant atomic_int *' (aka '__constant _Atomic(int) *') invalid)}}
 
   __opencl_atomic_store(i, 1, memory_order_seq_cst, memory_scope_work_group);
   __opencl_atomic_store(p, 1, memory_order_seq_cst, memory_scope_work_group);
-  (int)__opencl_atomic_store(d, 1, memory_order_seq_cst, memory_scope_work_group); // expected-error {{operand of type 'void' where arithmetic or pointer type is required}}
+  (int)__opencl_atomic_store(f, 1, memory_order_seq_cst, memory_scope_work_group); // expected-error {{operand of type 'void' where arithmetic or pointer type is required}}
 
   int exchange_1 = __opencl_atomic_exchange(i, 1, memory_order_seq_cst, memory_scope_work_group);
   int exchange_2 = __opencl_atomic_exchange(I, 1, memory_order_seq_cst, memory_scope_work_group); // expected-error {{address argument to atomic operation must be a pointer to _Atomic}}
 
   __opencl_atomic_fetch_add(i, 1, memory_order_seq_cst, memory_scope_work_group);
   __opencl_atomic_fetch_add(p, 1, memory_order_seq_cst, memory_scope_work_group);
-  __opencl_atomic_fetch_add(d, 1, memory_order_seq_cst, memory_scope_work_group); // expected-error {{address argument to atomic operation must be a pointer to atomic integer or pointer ('__generic atomic_float *' (aka '__generic _Atomic(float) *') invalid)}}
+  __opencl_atomic_fetch_add(f, 1.0f, memory_order_seq_cst, memory_scope_work_group);
+  __opencl_atomic_fetch_add(d, 1.0, memory_order_seq_cst, memory_scope_work_group);
   __opencl_atomic_fetch_and(i, 1, memory_order_seq_cst, memory_scope_work_group);
   __opencl_atomic_fetch_and(p, 1, memory_order_seq_cst, memory_scope_work_group);
-  __opencl_atomic_fetch_and(d, 1, memory_order_seq_cst, memory_scope_work_group); // expected-error {{address argument to atomic operation must be a pointer to atomic integer ('__generic atomic_float *' (aka '__generic _Atomic(float) *') invalid)}}
+  __opencl_atomic_fetch_and(f, 1, memory_order_seq_cst, memory_scope_work_group); // expected-error {{address argument to atomic operation must be a pointer to atomic integer ('__generic atomic_float *' (aka '__generic _Atomic(float) *') invalid)}}
 
   __opencl_atomic_fetch_min(i, 1, memory_order_seq_cst, memory_scope_work_group);
   __opencl_atomic_fetch_max(i, 1, memory_order_seq_cst, memory_scope_work_group);
-  __opencl_atomic_fetch_min(d, 1, memory_order_seq_cst, memory_scope_work_group); // expected-error {{address argument to atomic operation must be a pointer to atomic integer ('__generic 

[PATCH] D71726: Let clang atomic builtins fetch add/sub support floating point types

2021-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:5011
+!ValType->isFloatingType()) {
+  Diag(ExprRange.getBegin(), 
diag::err_atomic_op_needs_atomic_int_ptr_or_fp)
   << IsC11 << Ptr->getType() << Ptr->getSourceRange();

rjmccall wrote:
> yaxunl wrote:
> > rjmccall wrote:
> > > Does LLVM support atomics on all floating-point types?
> > LLVM IR parser requires atomicrmw value operand must have size of power of 
> > 2, therefore LLVM does not support atomicrmw on x86_fp80 which has size of 
> > 80 bytes. LLVM supports atomicrmw on all other floating-point types 
> > (bfloat, half, float, double, fp128, ppc_fp128).
> Okay.  So this needs to check the underlying FP semantics and disallow 
> atomics on unsupported types.
will do


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

https://reviews.llvm.org/D71726

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


[PATCH] D99893: [WIP] Replace std::forward & std::move by cast expressions during Sema

2021-04-05 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D99893#2669441 , @rjmccall wrote:

> I think a pattern-match in IRGen is probably a much more reasonable 
> alternative if the goal is primarily to avoid the code-generation overheads 
> at -O0 / optimization costs at -O.  You'd still have template 
> instantiation overheads; I don't know how significant those really are.

I agree, this kind of special-casing really goes against the spirit of Clang's 
AST model, and such special-casing seems to fit better in IR generation than in 
the AST representation. The approach in this patch is going to require 
additional complexity in all AST traversals that want to treat function calls 
uniformly, and will break all existing AST matchers looking for `std::move` / 
`std::forward` calls.

Perhaps we could instead treat `std::move` and `std::forward` as builtin 
functions? We could then skip instantiating the definition given that we 
already have a builtin definition, and IR generation is already set up to 
perform custom code generation for built-in functions. That should minimize the 
amount of special-casing and non-uniform AST representation we need here, and 
closely matches how we model other library functions that have well-known 
semantic effects. Note that the "builtin function" approach won't allow us to 
avoid performing overload resolution, but I don't know how important that is 
for what you're trying to achieve here -- and in any case, skipping overload 
resolution seems fraught with problems given that there is another (algorithm) 
overload of `std::move` and that both `std::move` and (especially) 
`std::forward` will reject some calls in overload resolution.

Treating a namespace-`std` function template as a builtin isn't entirely novel; 
we already do this for MSVC's `std::_GetExceptionInfo` (though we don't 
actually handle that properly: we're missing the "namespace `std`" check, at 
least). Treating the builtin definition as overriding an inline library 
definition might be novel, though that doesn't seem like a huge problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99893

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


[PATCH] D90835: [RFC][clang-tidy] Ignore diagnostics due to macro expansion from not-interested headers

2021-04-05 Thread Anton Lunov via Phabricator via cfe-commits
antonl added a comment.

Let me second that this will be a very useful feature. Without enabling some 
clang-tidy checks will be very noisy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90835

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


[PATCH] D99630: phase 01: add new command line flag to enable UAR in 3 modes (always, [runtime], never).

2021-04-05 Thread Kevin Athey via Phabricator via cfe-commits
kda updated this revision to Diff 335362.
kda added a comment.

I think this patch is near completion.
But the new code generated for the 'Always' case is definitely wrong.
I could use some coaching.  I will eventually figure it out, but an interactive 
session would probably help me along.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99630

Files:
  clang/docs/AddressSanitizer.rst
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/Sanitizers.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Basic/Sanitizers.cpp
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  compiler-rt/lib/asan/asan_fake_stack.cpp
  compiler-rt/lib/asan/asan_interface.inc
  compiler-rt/test/asan/TestCases/Posix/stack-use-after-return.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/BinaryFormat/MachO.h"
+#include "llvm/CodeGen/CodeGenPassBuilder.h"
 #include "llvm/IR/Argument.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/BasicBlock.h"
@@ -72,6 +73,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/Instrumentation.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerCommon.h"
+#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include "llvm/Transforms/Utils/ASanStackFrameLayout.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Local.h"
@@ -152,6 +154,8 @@
 const char kAsanHandleNoReturnName[] = "__asan_handle_no_return";
 static const int kMaxAsanStackMallocSizeClass = 10;
 const char kAsanStackMallocNameTemplate[] = "__asan_stack_malloc_";
+const char kAsanStackFlaglessMallocNameTemplate[] =
+"__asan_stack_flagless_malloc_";
 const char kAsanStackFreeNameTemplate[] = "__asan_stack_free_";
 const char kAsanGenPrefix[] = "___asan_gen_";
 const char kODRGenPrefix[] = "__odr_asan_gen_";
@@ -597,13 +601,17 @@
 
 /// AddressSanitizer: instrument the code in module to find memory bugs.
 struct AddressSanitizer {
-  AddressSanitizer(Module , const GlobalsMetadata *GlobalsMD,
-   bool CompileKernel = false, bool Recover = false,
-   bool UseAfterScope = false)
+  AddressSanitizer(
+  Module , const GlobalsMetadata *GlobalsMD, bool CompileKernel = false,
+  bool Recover = false, bool UseAfterScope = false,
+  llvm::AsanDetectStackUseAfterReturnMode DetectStackUseAfterReturnMode =
+  llvm::AsanDetectStackUseAfterReturnMode::Never)
   : CompileKernel(ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan
 : CompileKernel),
 Recover(ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover),
-UseAfterScope(UseAfterScope || ClUseAfterScope), GlobalsMD(*GlobalsMD) {
+UseAfterScope(UseAfterScope || ClUseAfterScope),
+DetectStackUseAfterReturnMode(DetectStackUseAfterReturnMode),
+GlobalsMD(*GlobalsMD) {
 C = &(M.getContext());
 LongSize = M.getDataLayout().getPointerSizeInBits();
 IntptrTy = Type::getIntNTy(*C, LongSize);
@@ -689,6 +697,7 @@
   bool CompileKernel;
   bool Recover;
   bool UseAfterScope;
+  llvm::AsanDetectStackUseAfterReturnMode DetectStackUseAfterReturnMode;
   Type *IntptrTy;
   ShadowMapping Mapping;
   FunctionCallee AsanHandleNoReturnFunc;
@@ -713,11 +722,14 @@
 public:
   static char ID;
 
-  explicit AddressSanitizerLegacyPass(bool CompileKernel = false,
-  bool Recover = false,
-  bool UseAfterScope = false)
+  explicit AddressSanitizerLegacyPass(
+  bool CompileKernel = false, bool Recover = false,
+  bool UseAfterScope = false,
+  llvm::AsanDetectStackUseAfterReturnMode DetectStackUseAfterReturnMode =
+  llvm::AsanDetectStackUseAfterReturnMode::Never)
   : FunctionPass(ID), CompileKernel(CompileKernel), Recover(Recover),
-UseAfterScope(UseAfterScope) {
+UseAfterScope(UseAfterScope),
+DetectStackUseAfterReturnMode(DetectStackUseAfterReturnMode) {
 initializeAddressSanitizerLegacyPassPass(*PassRegistry::getPassRegistry());
   }
 
@@ -736,7 +748,7 @@
 const TargetLibraryInfo *TLI =
 ().getTLI(F);
 AddressSanitizer ASan(*F.getParent(), , CompileKernel, Recover,
-  

[PATCH] D90835: [RFC][clang-tidy] Ignore diagnostics due to macro expansion from not-interested headers

2021-04-05 Thread Wei Yu via Phabricator via cfe-commits
zigwei added a comment.

This is a helpful feature. We had exactly the same problem with both GFLAG and 
GTEST, too.
But I am not sure if HeaderFilterRegex is the right option to control it. Is a 
new filter better for the ignored headers?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90835

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


[PATCH] D99447: [OpenMP] Define omp_is_initial_device() variants in omp.h

2021-04-05 Thread Hansang Bae via Phabricator via cfe-commits
hbae updated this revision to Diff 335347.
hbae added a comment.

Added inline after static to avoid unused function warning.
Added a RUN line to the test to catch unused function warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99447

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/ExprConstant.cpp
  clang/test/OpenMP/is_initial_device.c
  openmp/libomptarget/test/api/is_initial_device.c
  openmp/runtime/src/include/omp.h.var

Index: openmp/runtime/src/include/omp.h.var
===
--- openmp/runtime/src/include/omp.h.var
+++ openmp/runtime/src/include/omp.h.var
@@ -468,6 +468,15 @@
 /* OpenMP 5.1 Display Environment */
 extern void omp_display_env(int verbose);
 
+#   if defined(_OPENMP) && _OPENMP >= 201811
+#pragma omp begin declare variant match(device={kind(host)})
+static inline int omp_is_initial_device(void) { return 1; }
+#pragma omp end declare variant
+#pragma omp begin declare variant match(device={kind(nohost)})
+static inline int omp_is_initial_device(void) { return 0; }
+#pragma omp end declare variant
+#   endif
+
 #   undef __KAI_KMPC_CONVENTION
 #   undef __KMP_IMP
 
Index: openmp/libomptarget/test/api/is_initial_device.c
===
--- /dev/null
+++ openmp/libomptarget/test/api/is_initial_device.c
@@ -0,0 +1,30 @@
+// RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu
+// RUN: %libomptarget-compile-x86_64-pc-linux-gnu -DUNUSED -Wall -Werror
+
+#include 
+#include 
+
+int main() {
+  int errors = 0;
+#ifdef UNUSED
+// Test if it is OK to leave the variants unused in the header
+#else // UNUSED
+  int host = omp_is_initial_device();
+  int device = 1;
+#pragma omp target map(tofrom : device)
+  { device = omp_is_initial_device(); }
+  if (!host) {
+printf("omp_is_initial_device() returned false on host\n");
+errors++;
+  }
+  if (device) {
+printf("omp_is_initial_device() returned true on device\n");
+errors++;
+  }
+#endif // UNUSED
+
+  // CHECK: PASS
+  printf("%s\n", errors ? "FAIL" : "PASS");
+
+  return errors;
+}
Index: clang/test/OpenMP/is_initial_device.c
===
--- clang/test/OpenMP/is_initial_device.c
+++ /dev/null
@@ -1,41 +0,0 @@
-// REQUIRES: powerpc-registered-target
-
-// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-unknown-unknown \
-// RUN:-emit-llvm-bc %s -o %t-ppc-host.bc
-// RUN: %clang_cc1 -verify -fopenmp -x ir -triple powerpc64le-unknown-unknown -emit-llvm \
-// RUN: %t-ppc-host.bc -o - | FileCheck %s -check-prefixes HOST,OUTLINED
-// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown -emit-llvm -fopenmp-is-device \
-// RUN: %s -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s -check-prefixes DEVICE,OUTLINED
-
-// RUN: %clang_cc1 -verify -fopenmp-simd -x c -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-unknown-unknown -emit-llvm-bc %s -o %t-ppc-host.bc
-// RUN: %clang_cc1 -verify -fopenmp-simd -x ir -triple powerpc64le-unknown-unknown -emit-llvm %t-ppc-host.bc -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -fopenmp-simd -x c -triple powerpc64le-unknown-unknown -emit-llvm -fopenmp-is-device %s -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck --check-prefix SIMD-ONLY0 %s
-// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
-
-// expected-no-diagnostics
-int check() {
-  int host = omp_is_initial_device();
-  int device;
-#pragma omp target map(tofrom: device)
-  {
-device = omp_is_initial_device();
-  }
-
-  return host + device;
-}
-
-// The host should get a value of 1:
-// HOST: define{{.*}} @check()
-// HOST: [[HOST:%.*]] = alloca i32
-// HOST: store i32 1, i32* [[HOST]]
-
-// OUTLINED: define{{.*}} @{{.*}}omp_offloading{{.*}}(i32*{{.*}} [[DEVICE_ARGUMENT:%.*]])
-// OUTLINED: [[DEVICE_ADDR_STORAGE:%.*]] = alloca i32*
-// OUTLINED: store i32* [[DEVICE_ARGUMENT]], i32** [[DEVICE_ADDR_STORAGE]]
-// OUTLINED: [[DEVICE_ADDR:%.*]] = load i32*, i32** [[DEVICE_ADDR_STORAGE]]
-
-// The outlined function that is called as fallback also runs on the host:
-// HOST: store i32 1, i32* [[DEVICE_ADDR]]
-
-// The device should get a value of 0:
-// DEVICE: store i32 0, i32* [[DEVICE_ADDR]]
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12010,9 +12010,6 @@
 return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
 Success(0, E) : Error(E);
   }
-  case Builtin::BIomp_is_initial_device:
-// We can decide statically which value the runtime would return if called.
-return Success(Info.getLangOpts().OpenMPIsDevice ? 0 : 1, E);
  

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

2021-04-05 Thread Josh Haberman via Phabricator via cfe-commits
haberman added inline comments.



Comment at: clang/lib/Sema/SemaStmt.cpp:561-568
+  for (const auto *A : Attrs) {
+if (A->getKind() == attr::MustTail) {
+  if (!checkMustTailAttr(SubStmt, *A)) {
+return SubStmt;
+  }
+  setFunctionHasMustTail();
+}

aaron.ballman wrote:
> rsmith wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > haberman wrote:
> > > > > aaron.ballman wrote:
> > > > > > haberman wrote:
> > > > > > > haberman wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > haberman wrote:
> > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > This functionality belongs in SemaStmtAttr.cpp, I think.
> > > > > > > > > > That is where I had originally put it, but that didn't work 
> > > > > > > > > > for templates. The semantic checks can only be performed at 
> > > > > > > > > > instantiation time. `ActOnAttributedStmt` seems to be the 
> > > > > > > > > > right hook point where I can evaluate the semantic checks 
> > > > > > > > > > for both template and non-template functions (with template 
> > > > > > > > > > functions getting checked at instantiation time).
> > > > > > > > > I disagree that `ActOnAttributedStmt()` is the correct place 
> > > > > > > > > for this checking -- template checking should occur when the 
> > > > > > > > > template is instantiated, same as happens for declaration 
> > > > > > > > > attributes. I'd like to see this functionality moved to 
> > > > > > > > > SemaStmtAttr.cpp. Keeping the attribute logic together and 
> > > > > > > > > following the same patterns is what allows us to 
> > > > > > > > > tablegenerate more of the attribute logic. Statement 
> > > > > > > > > attributes are just starting to get more such automation.
> > > > > > > > I tried commenting out this code and adding the following code 
> > > > > > > > into `handleMustTailAttr()` in `SemaStmtAttr.cpp`:
> > > > > > > > 
> > > > > > > > ```
> > > > > > > >   if (!S.checkMustTailAttr(St, MTA))
> > > > > > > > return nullptr;
> > > > > > > > ```
> > > > > > > > 
> > > > > > > > This caused my test cases related to templates to fail. It also 
> > > > > > > > seemed to break test cases related to `JumpDiagnostics`. My 
> > > > > > > > interpretation of this is that `handleMustTailAttr()` is called 
> > > > > > > > during parsing only, and cannot catch errors at template 
> > > > > > > > instantiation time or that require a more complete AST.
> > > > > > > > 
> > > > > > > > What am I missing? Where in SemaStmtAttr.cpp are you suggesting 
> > > > > > > > that I put this check?
> > > > > > > Scratch the part about `JumpDiagnostics`, that was me failing to 
> > > > > > > call `S.setFunctionHasMustTail()`. I added that and now the 
> > > > > > > `JumpDiagnostics` tests pass.
> > > > > > > 
> > > > > > > But the template test cases still fail, and I can't find any hook 
> > > > > > > point in `SemaStmtAttr.cpp` that will let me evaluate these 
> > > > > > > checks at template instantiation time.
> > > > > > I think there's a bit of an architectural mixup, but I'm curious if 
> > > > > > @rsmith agrees before anyone starts doing work to make changes.
> > > > > > 
> > > > > > When transforming declarations, `RebuildWhatever()` calls the 
> > > > > > `ActOnWhatever()` function which calls `ProcessDeclAttributeList()` 
> > > > > > so that attributes are processed. `RebuildAttributedStmt()` 
> > > > > > similarly calls `ActOnAttributedStmt()`. However, 
> > > > > > `ActOnAttributedStmt()` doesn't call `ProcessStmtAttributes()` -- 
> > > > > > the logic is reversed so that `ProcessStmtAttributes()` is what 
> > > > > > calls `ActOnAttributedStmt()`.
> > > > > > 
> > > > > > I think the correct answer is to switch the logic so that 
> > > > > > `ActOnAttributedStmt()` calls `ProcessStmtAttributes()`, then the 
> > > > > > template logic should automatically work.
> > > > > > I think the correct answer is to switch the logic so that 
> > > > > > ActOnAttributedStmt() calls ProcessStmtAttributes()
> > > > > 
> > > > > I think this would require `ProcessStmtAttributes()` to be split into 
> > > > > two separate functions. Currently that function is doing two separate 
> > > > > things:
> > > > > 
> > > > > 1. Translation of `ParsedAttr` into various subclasses of `Attr`.
> > > > > 2. Validation that the attribute is semantically valid.
> > > > > 
> > > > > The function signature for `ActOnAttributedStmt()` uses `Attr` (not 
> > > > > `ParsedAttr`), so (1) must happen during the parse, before 
> > > > > `ActOnAttributedStmt()` is called. But (2) must be deferred until 
> > > > > template instantiation time for some cases, like `musttail`.
> > > > I don't think the signature for `ActOnAttributedStmt()` is correct to 
> > > > use `Attr` instead of `ParsedAttr`. I think it should be `StmtResult 
> > > > ActOnAttributedStmt(const ParsedAttributesViewWithRange , Stmt 
> > > > *SubStmt);` -- this likely requires a fair bit of surgery 

[PATCH] D99903: [Clang][Sema] better -Wcast-function-type diagnose for pointer parameters and parameters with cv-qualifiers

2021-04-05 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen created this revision.
ychen added a reviewer: rsmith.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

1. Skip diagnosing all pointer-like parameters.
2. Replace `Context.hasSameUnqualifiedType` with `Context.hasSimilarType`.
3. Add corresponding tests.




After some thoughts, I think we could add the following extension in the
future (probably under an additional flag such as `-Wcast-function-type=2)
 according to user feedbacks for the reasons: 1) users could use
`void(*)(void)` to explicitly override checks (for example:
https://trac.webkit.org/changeset/231565/webkit); 2) these checks could
hide real bugs that users may want to catch; 3) using `void(*)(void)`
makes following extension worthwhile only when a codebase uses these
patterns on a large scale which seems unlikely.

(GCC does not do the following)

- allow integer promotion (`void(int)` -> `void(char)`)

- allow arbitrary pointer-to-member conversion

- allow parameter counts mismatch

the use pattern is "passing an extra (unwanted) parameter to callbacks"
https://bugs.freedesktop.org/show_bug.cgi?id=107349#c0

Thoughts?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99903

Files:
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/warn-cast-function-type.c
  clang/test/Sema/warn-cast-function-type.m
  clang/test/SemaCXX/warn-cast-function-type.cpp

Index: clang/test/SemaCXX/warn-cast-function-type.cpp
===
--- clang/test/SemaCXX/warn-cast-function-type.cpp
+++ clang/test/SemaCXX/warn-cast-function-type.cpp
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -x c++ %s -fblocks -fsyntax-only -Wcast-function-type -triple x86_64-- -verify
+// RUN: %clang_cc1 -x c++ -std=c++11 %s -fblocks -fsyntax-only -Wcast-function-type -triple x86_64-- -verify
 
-int x(long);
+using nullptr_t = decltype(nullptr);
 
+int x(long);
 typedef int (f1)(long);
 typedef int (f2)(void*);
 typedef int (f3)(...);
@@ -19,13 +20,39 @@
 f6 *f;
 f7 *g;
 
-struct S
-{
-  void foo (int*);
-  void bar (int);
-};
+struct S1 { void foo(int *); };
+struct S2 {};
+
+typedef void (S1::*pmf1)(int);
+typedef float S1::*pm1;
+typedef const float S1::*pm2;
+
+void y(long *);
+typedef void(pf1)(long **);
+typedef void(pf2)(long &);
+typedef void(pf3)(void (^)(long));
+typedef void(pf4)(nullptr_t);
 
-typedef void (S::*mf)(int);
+void z(long &);
+typedef void(pf5)(long **);
+typedef void(pf6)(long &);
+typedef void(pf7)(void (^)(long));
+typedef void(pf8)(nullptr_t);
+
+void u(pm1);
+typedef void(pf9)(pm2);
+typedef void(pf10)(nullptr_t);
+
+pf1 *p1;
+pf2 *p2;
+pf3 *p3;
+pf4 *p4;
+pf5 *p5;
+pf6 *p6;
+pf7 *p7;
+pf8 *p8;
+pf9 *p9;
+pf10 *p10;
 
 void foo() {
   a = (f1 *)x;
@@ -37,11 +64,22 @@
   f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */
   g = (f7 *)x;
 
-  mf p1 = (mf)::foo; /* expected-warning {{cast from 'void (S::*)(int *)' to 'mf' (aka 'void (S::*)(int)') converts to incompatible function type}} */
+  pmf1 pm1 = (pmf1)::foo; /* expected-warning {{cast from 'void (S1::*)(int *)' to 'pmf1' (aka 'void (S1::*)(int)') converts to incompatible function type}} */
 
   f8 f2 = (f8)x; /* expected-warning {{cast from 'int (long)' to 'f8' (aka 'int (&)(long, int)') converts to incompatible function type}} */
   (void)f2;
 
-  int (^y)(long);
-  f = (f6 *)y; /* expected-warning {{cast from 'int (^)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */
+  int (^bb)(long);
+  f = (f6 *)bb; /* expected-warning {{cast from 'int (^)(long)' to 'f6 *' (aka 'int (*)(long, int)') converts to incompatible function type}} */
+
+  p1 = (pf1 *)y;
+  p2 = (pf2 *)y; /* expected-warning {{cast from 'void (*)(long *)' to 'pf2 *' (aka 'void (*)(long &)') converts to incompatible function type}} */
+  p3 = (pf3 *)y;
+  p4 = (pf4 *)y;
+  p5 = (pf5 *)z; /* expected-warning {{cast from 'void (*)(long &)' to 'pf5 *' (aka 'void (*)(long **)') converts to incompatible function type}} */
+  p6 = (pf6 *)z;
+  p7 = (pf7 *)z; /* expected-warning {{cast from 'void (*)(long &)' to 'pf7 *' (aka 'void (*)(void (^)(long))') converts to incompatible function type}} */
+  p8 = (pf8 *)z; /* expected-warning {{cast from 'void (*)(long &)' to 'pf8 *' (aka 'void (*)(nullptr_t)') converts to incompatible function type}} */
+  p9 = (pf9 *)u;
+  p10 = (pf10 *)u;
 }
Index: clang/test/Sema/warn-cast-function-type.m
===
--- /dev/null
+++ clang/test/Sema/warn-cast-function-type.m
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wcast-function-type -verify
+
+// expected-no-diagnostics
+
+int x(long*);
+
+typedef int (f1)(id);
+
+f1 *a;
+
+void foo(void) {
+  a = (f1 *)x;
+}
Index: clang/test/Sema/warn-cast-function-type.c
===
--- 

[PATCH] D99896: Rework the way statement attributes are processed; NFC

2021-04-05 Thread Josh Haberman via Phabricator via cfe-commits
haberman added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:1316
Stmt *SubStmt) {
-return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
+return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
   }

aaron.ballman wrote:
> haberman wrote:
> > aaron.ballman wrote:
> > > erichkeane wrote:
> > > > Am I missing where the attributes themselves are being 
> > > > rebuilt/transformed??  
> > > > 
> > > > 
> > > The transformation happens in 
> > > `TreeTransform::TransformAttributedStmt()` which calls 
> > > `RebuildAttributedStmt()` with the rebuilt attributes.
> > It appears that neither `TransformAttributedStmt()` nor 
> > `RebuildAttributedStmt()` calls `ProcessStmtAttributes()`, either directly 
> > or transitively, so I'm not seeing where we can run instantiation-time 
> > attribute processing logic. What am I missing?
> My thinking is: 
> 
> * From `handleMustTailAttr()` in SemaStmtAttr.cpp, call `CheckMustTailAttr()` 
> to do the shared semantic checking.
> * Add a `TransformMustTailAttr()` to `TreeTransform`, have it call 
> `SemaRef.CheckMustTailAttr()` as well.
I see. My main concern then is that `TransformMustTailAttr()` could get access 
to the `ReturnExpr` to perform the validation. Right now the `MustTailAttr` 
doesn't appear to have any reference to the `ReturnExpr`, and I don't know how 
to give it one.

If there is a solution to this problem, I don't have any objection. My main 
concern is to unblock my change which is a high priority for me and my team.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99896

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


[PATCH] D99896: Rework the way statement attributes are processed; NFC

2021-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit in 978d2edf7aed133616de1eb7f633c263c4b5 
, thanks 
for the really quick reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99896

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


[clang] 9711118 - Rework the way statement attributes are processed; NFC

2021-04-05 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-04-05T17:52:17-04:00
New Revision: 978d2edf7aed133616de1eb7f633c263c4b5

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

LOG: Rework the way statement attributes are processed; NFC

This changes our approach to processing statement attributes to be more
similar to how we process declaration attributes. Namely,
ActOnAttributedStmt() now calls ProcessStmtAttributes() instead of
vice-versa, and there is now an interface split between building an
attributed statement where you already have a list of semantic
attributes and building an attributed statement with attributes from
the parser.

This should make it easier to support statement attributes that are
dependent on a template. In that case, you would add a
TransformFooAttr() function in TreeTransform.h to perform the semantic
checking (morally similar to how Sema::InstantiateAttrs() already works
for declaration attributes) when transforming the semantic attribute at
instantiation time.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaStmtAttr.cpp
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8f6e6baaea62..b8029b670747 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4296,10 +4296,11 @@ class Sema final {
   /// Valid types should not have multiple attributes with 
diff erent CCs.
   const AttributedType *getCallingConvAttributedType(QualType T) const;
 
-  /// Stmt attributes - this routine is the top level dispatcher.
-  StmtResult ProcessStmtAttributes(Stmt *Stmt,
-   const ParsedAttributesView ,
-   SourceRange Range);
+  /// Process the attributes before creating an attributed statement. Returns
+  /// the semantic attributes that have been processed.
+  void ProcessStmtAttributes(Stmt *Stmt,
+ const ParsedAttributesWithRange ,
+ SmallVectorImpl );
 
   void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
ObjCMethodDecl *MethodDecl,
@@ -4638,8 +4639,9 @@ class Sema final {
   StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
 SourceLocation ColonLoc, Stmt *SubStmt);
 
-  StmtResult ActOnAttributedStmt(SourceLocation AttrLoc,
- ArrayRef Attrs,
+  StmtResult BuildAttributedStmt(SourceLocation AttrsLoc,
+ ArrayRef Attrs, Stmt *SubStmt);
+  StmtResult ActOnAttributedStmt(const ParsedAttributesWithRange ,
  Stmt *SubStmt);
 
   class ConditionResult;

diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index bcda3560ce63..d4863d1e3abd 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -120,7 +120,7 @@ Parser::ParseStatementOrDeclaration(StmtVector ,
   if (Attrs.empty() || Res.isInvalid())
 return Res;
 
-  return Actions.ProcessStmtAttributes(Res.get(), Attrs, Attrs.Range);
+  return Actions.ActOnAttributedStmt(Attrs, Res.get());
 }
 
 namespace {
@@ -657,8 +657,7 @@ StmtResult 
Parser::ParseLabeledStatement(ParsedAttributesWithRange ,
   SubStmt = ParseStatementOrDeclarationAfterAttributes(Stmts, StmtCtx,
nullptr, TempAttrs);
   if (!TempAttrs.empty() && !SubStmt.isInvalid())
-SubStmt = Actions.ProcessStmtAttributes(SubStmt.get(), TempAttrs,
-TempAttrs.Range);
+SubStmt = Actions.ActOnAttributedStmt(TempAttrs, SubStmt.get());
 } else {
   Diag(Tok, diag::err_expected_after) << "__attribute__" << tok::semi;
 }
@@ -1144,7 +1143,7 @@ StmtResult Parser::ParseCompoundStatementBody(bool 
isStmtExpr) {
 ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
 R = handleExprStmt(Res, SubStmtCtx);
 if (R.isUsable())
-  R = Actions.ProcessStmtAttributes(R.get(), attrs, attrs.Range);
+  R = Actions.ActOnAttributedStmt(attrs, R.get());
   }
 }
 

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index ceba83bcd814..174679a14f24 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -555,12 +555,22 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl 
*TheDecl,
   return LS;
 }
 
-StmtResult Sema::ActOnAttributedStmt(SourceLocation AttrLoc,
- ArrayRef Attrs,
+StmtResult Sema::BuildAttributedStmt(SourceLocation AttrsLoc,
+

[PATCH] D99896: Rework the way statement attributes are processed; NFC

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



Comment at: clang/lib/Sema/TreeTransform.h:1316
Stmt *SubStmt) {
-return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
+return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
   }

haberman wrote:
> aaron.ballman wrote:
> > erichkeane wrote:
> > > Am I missing where the attributes themselves are being 
> > > rebuilt/transformed??  
> > > 
> > > 
> > The transformation happens in 
> > `TreeTransform::TransformAttributedStmt()` which calls 
> > `RebuildAttributedStmt()` with the rebuilt attributes.
> It appears that neither `TransformAttributedStmt()` nor 
> `RebuildAttributedStmt()` calls `ProcessStmtAttributes()`, either directly or 
> transitively, so I'm not seeing where we can run instantiation-time attribute 
> processing logic. What am I missing?
My thinking is: 

* From `handleMustTailAttr()` in SemaStmtAttr.cpp, call `CheckMustTailAttr()` 
to do the shared semantic checking.
* Add a `TransformMustTailAttr()` to `TreeTransform`, have it call 
`SemaRef.CheckMustTailAttr()` as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99896

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


[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-04-05 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze updated this revision to Diff 335334.
zukatsinadze edited the summary of this revision.
zukatsinadze added a comment.

Gentle ping

- Diff with context
- Added some more tests
- Updated documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
  clang/test/Analysis/cert/env31-c.c
  clang/test/Analysis/cert/env34-c-cert-examples.c
  clang/test/Analysis/cert/env34-c.c

Index: clang/test/Analysis/cert/env34-c.c
===
--- /dev/null
+++ clang/test/Analysis/cert/env34-c.c
@@ -0,0 +1,331 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=alpha.security.cert.env.InvalidPtr\
+// RUN:  -analyzer-output=text -verify -Wno-unused %s
+
+#include "../Inputs/system-header-simulator.h"
+char *getenv(const char *name);
+char *setlocale(int category, const char *locale);
+char *strerror(int errnum);
+
+typedef struct {
+  char * field;
+} lconv;
+lconv *localeconv(void);
+
+typedef struct {
+} tm;
+char *asctime(const tm *timeptr);
+
+int strcmp(const char*, const char*);
+extern void foo(char *e);
+extern char* bar();
+
+
+void getenv_test1() {
+  char *p;
+
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  *p; // no-warning, getenv result was assigned to the same pointer
+}
+
+void getenv_test2() {
+  char *p, *p2;
+
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test3() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  p3 = getenv("VAR3");
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test4() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+  p3 = getenv("VAR3");
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test5() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  p2 = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  p3 = getenv("VAR3");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p2;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test6() {
+  char *p, *p2;
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR3");
+  // expected-note@-1{{previous function call was here}}
+  // expected-note@-2{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+
+  *p2; // no-warning
+
+  p = getenv("VAR4");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p; // no-warning
+  *p2;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test7() {
+  char *p, *p2;
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  foo(p);
+  // expected-warning@-1{{use of invalidated pointer 'p' in a function call}}
+  // expected-note@-2{{use of invalidated pointer 'p' in a function call}}
+}
+
+void getenv_test8() {
+  static const char *array[] = {
+ 0,
+ 0,
+ "/var/tmp",
+ "/usr/tmp",
+ "/tmp",
+ "."
+  };
+
+  if( !array[0] )
+  // expected-note@-1{{Taking true branch}}
+array[0] = getenv("TEMPDIR");
+// expected-note@-1{{previous function call was here}}
+
+  if( !array[1] )
+  // expected-note@-1{{Taking true branch}}
+array[1] = getenv("TMPDIR");
+// expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  

[PATCH] D99901: [Driver][test] Test intended target only

2021-04-05 Thread Jinsong Ji via Phabricator via cfe-commits
jsji created this revision.
jsji added a reviewer: MaskRay.
jsji requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

6fe7de90b9e4e466a5c2baadafd5f72d3203651d 
 changed 
GNU toolchain,
and added new RUN line to test expected behavior.

The change is for GNU toolchain only, so this will fail other toolchain,
eg: AIX.

Update the test with `-target` to test GNU tool chain only.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99901

Files:
  clang/test/Driver/nostdincxx.cpp


Index: clang/test/Driver/nostdincxx.cpp
===
--- clang/test/Driver/nostdincxx.cpp
+++ clang/test/Driver/nostdincxx.cpp
@@ -1,7 +1,7 @@
 // RUN: not %clangxx -nostdinc %s 2>&1 | FileCheck %s
 // RUN: not %clangxx -nostdinc++ %s 2>&1 | FileCheck %s
 // RUN: not %clangxx -nostdlibinc %s 2>&1 | FileCheck %s
-// RUN: not %clangxx -fsyntax-only -nostdinc -nostdinc++ %s 2>&1 | FileCheck 
/dev/null --implicit-check-not=-Wunused-command-line-argument
+// RUN: not %clangxx -target unknown-unknown-gnu -fsyntax-only -nostdinc 
-nostdinc++ %s 2>&1 | FileCheck /dev/null 
--implicit-check-not=-Wunused-command-line-argument
 // CHECK: file not found
 #include  
 


Index: clang/test/Driver/nostdincxx.cpp
===
--- clang/test/Driver/nostdincxx.cpp
+++ clang/test/Driver/nostdincxx.cpp
@@ -1,7 +1,7 @@
 // RUN: not %clangxx -nostdinc %s 2>&1 | FileCheck %s
 // RUN: not %clangxx -nostdinc++ %s 2>&1 | FileCheck %s
 // RUN: not %clangxx -nostdlibinc %s 2>&1 | FileCheck %s
-// RUN: not %clangxx -fsyntax-only -nostdinc -nostdinc++ %s 2>&1 | FileCheck /dev/null --implicit-check-not=-Wunused-command-line-argument
+// RUN: not %clangxx -target unknown-unknown-gnu -fsyntax-only -nostdinc -nostdinc++ %s 2>&1 | FileCheck /dev/null --implicit-check-not=-Wunused-command-line-argument
 // CHECK: file not found
 #include  
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-04-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D99160#2668977 , @djtodoro wrote:

> I think that the Debug Entry Values feature should not be enabled by default 
> for non optimized code, so the `TargetOptions::ShouldEmitDebugEntryValues()` 
> should be patched with checking of optimization level (it should be > 0).

That's currently intended to be already handled by the frontend, right? (clang 
only sets `EnableDebugEntryValues` (which `ShouldEmitDebugEntryValues` checks 
(hmm, it checks under 'or', not 'and', so I'm not sure where the "only above 
-O0" is implemented, but it is implemented somewhere?) if optimizations are 
enabled, yeah?)

Oh, is entry_values actually not conditionalized? It's only the call_site 
support that's currently conditionalized on "above -O0"?

Hmm - If that's the case, and we currently have some cases where entry_values 
are emitted at -O0, I'm not sure /not/ emitting those is the right call either. 
If we believe/have data to show that there are so few useful uses of 
entry_value at -O0 that it's not worth the DWARF size growth to put call_sites 
in at -O0, then I think it might still be worth leaving the entry_values in 
(unless they take up a bunch of extra space) for the cases of mixed 
optimization compilation (-O0 some code you're debugging, but building the rest 
with optimizations).


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

https://reviews.llvm.org/D99160

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


[PATCH] D99898: [clang, test] Fix use of undef FileCheck var

2021-04-05 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre created this revision.
thopre added reviewers: ddunbar, MaskRay, rjmccall, spatel, arsenm, hfinkel, 
void, mcrosier.
thopre requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: clang.

Clang test CodeGen/libcalls.c contains CHECK-NOT directives using a
variable defined in a CHECK directive with a different prefix never
enabled together, therefore causing the variable to be undefined in that
CHECK-NOT.

The intent of the test is to check that some declaration do not have the
same attribute as when compiling the test without -fmath-errno. This
commits instead changes all CHECK-NOT to CHECK directive, checking that
they all use the same attribute. It also adds an extra CHECK-NOT for
that directive to check it does not have the readnone attribute as when
there is no -fmath-errno.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99898

Files:
  clang/test/CodeGen/libcalls.c


Index: clang/test/CodeGen/libcalls.c
===
--- clang/test/CodeGen/libcalls.c
+++ clang/test/CodeGen/libcalls.c
@@ -88,9 +88,9 @@
 // CHECK-NO: declare double @atan(double) [[NUW_RN:#[0-9]+]]
 // CHECK-NO: declare x86_fp80 @atanl(x86_fp80) [[NUW_RN]]
 // CHECK-NO: declare float @atanf(float) [[NUW_RN]]
-// CHECK-YES-NOT: declare double @atan(double) [[NUW_RN]]
-// CHECK-YES-NOT: declare x86_fp80 @atanl(x86_fp80) [[NUW_RN]]
-// CHECK-YES-NOT: declare float @atanf(float) [[NUW_RN]]
+// CHECK-YES: declare double @atan(double) [[NUW_RN:#[0-9]+]]
+// CHECK-YES: declare x86_fp80 @atanl(x86_fp80) [[NUW_RN]]
+// CHECK-YES: declare float @atanf(float) [[NUW_RN]]
 
   double atan2_ = atan2(d, 2);
   long double atan2l_ = atan2l(ld, ld);
@@ -98,9 +98,9 @@
 // CHECK-NO: declare double @atan2(double, double) [[NUW_RN]]
 // CHECK-NO: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) [[NUW_RN]]
 // CHECK-NO: declare float @atan2f(float, float) [[NUW_RN]]
-// CHECK-YES-NOT: declare double @atan2(double, double) [[NUW_RN]]
-// CHECK-YES-NOT: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) [[NUW_RN]]
-// CHECK-YES-NOT: declare float @atan2f(float, float) [[NUW_RN]]
+// CHECK-YES: declare double @atan2(double, double) [[NUW_RN]]
+// CHECK-YES: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) [[NUW_RN]]
+// CHECK-YES: declare float @atan2f(float, float) [[NUW_RN]]
 
   double exp_ = exp(d);
   long double expl_ = expl(ld);
@@ -108,9 +108,9 @@
 // CHECK-NO: declare double @llvm.exp.f64(double) [[NUW_RNI]]
 // CHECK-NO: declare x86_fp80 @llvm.exp.f80(x86_fp80) [[NUW_RNI]]
 // CHECK-NO: declare float @llvm.exp.f32(float) [[NUW_RNI]]
-// CHECK-YES-NOT: declare double @exp(double) [[NUW_RN]]
-// CHECK-YES-NOT: declare x86_fp80 @expl(x86_fp80) [[NUW_RN]]
-// CHECK-YES-NOT: declare float @expf(float) [[NUW_RN]]
+// CHECK-YES: declare double @exp(double) [[NUW_RN]]
+// CHECK-YES: declare x86_fp80 @expl(x86_fp80) [[NUW_RN]]
+// CHECK-YES: declare float @expf(float) [[NUW_RN]]
 
   double log_ = log(d);
   long double logl_ = logl(ld);
@@ -118,10 +118,11 @@
 // CHECK-NO: declare double @llvm.log.f64(double) [[NUW_RNI]]
 // CHECK-NO: declare x86_fp80 @llvm.log.f80(x86_fp80) [[NUW_RNI]]
 // CHECK-NO: declare float @llvm.log.f32(float) [[NUW_RNI]]
-// CHECK-YES-NOT: declare double @log(double) [[NUW_RN]]
-// CHECK-YES-NOT: declare x86_fp80 @logl(x86_fp80) [[NUW_RN]]
-// CHECK-YES-NOT: declare float @logf(float) [[NUW_RN]]
+// CHECK-YES: declare double @log(double) [[NUW_RN]]
+// CHECK-YES: declare x86_fp80 @logl(x86_fp80) [[NUW_RN]]
+// CHECK-YES: declare float @logf(float) [[NUW_RN]]
 }
 
 // CHECK-NO-DAG: attributes [[NUW_RN]] = { nounwind readnone{{.*}} }
+// CHECK-YES-NOT: attributes [[NUW_RN]] = { nounwind readnone{{.*}} }
 // CHECK-NO-DAG: attributes [[NUW_RNI]] = { nofree nosync nounwind readnone 
speculatable willreturn }


Index: clang/test/CodeGen/libcalls.c
===
--- clang/test/CodeGen/libcalls.c
+++ clang/test/CodeGen/libcalls.c
@@ -88,9 +88,9 @@
 // CHECK-NO: declare double @atan(double) [[NUW_RN:#[0-9]+]]
 // CHECK-NO: declare x86_fp80 @atanl(x86_fp80) [[NUW_RN]]
 // CHECK-NO: declare float @atanf(float) [[NUW_RN]]
-// CHECK-YES-NOT: declare double @atan(double) [[NUW_RN]]
-// CHECK-YES-NOT: declare x86_fp80 @atanl(x86_fp80) [[NUW_RN]]
-// CHECK-YES-NOT: declare float @atanf(float) [[NUW_RN]]
+// CHECK-YES: declare double @atan(double) [[NUW_RN:#[0-9]+]]
+// CHECK-YES: declare x86_fp80 @atanl(x86_fp80) [[NUW_RN]]
+// CHECK-YES: declare float @atanf(float) [[NUW_RN]]
 
   double atan2_ = atan2(d, 2);
   long double atan2l_ = atan2l(ld, ld);
@@ -98,9 +98,9 @@
 // CHECK-NO: declare double @atan2(double, double) [[NUW_RN]]
 // CHECK-NO: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) [[NUW_RN]]
 // CHECK-NO: declare float @atan2f(float, float) [[NUW_RN]]
-// CHECK-YES-NOT: declare double @atan2(double, double) [[NUW_RN]]
-// CHECK-YES-NOT: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) 

[PATCH] D99896: Rework the way statement attributes are processed; NFC

2021-04-05 Thread Josh Haberman via Phabricator via cfe-commits
haberman added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:1316
Stmt *SubStmt) {
-return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
+return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
   }

aaron.ballman wrote:
> erichkeane wrote:
> > Am I missing where the attributes themselves are being 
> > rebuilt/transformed??  
> > 
> > 
> The transformation happens in 
> `TreeTransform::TransformAttributedStmt()` which calls 
> `RebuildAttributedStmt()` with the rebuilt attributes.
It appears that neither `TransformAttributedStmt()` nor 
`RebuildAttributedStmt()` calls `ProcessStmtAttributes()`, either directly or 
transitively, so I'm not seeing where we can run instantiation-time attribute 
processing logic. What am I missing?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99896

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


[PATCH] D99896: Rework the way statement attributes are processed; NFC

2021-04-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

SGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99896

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


[PATCH] D99896: Rework the way statement attributes are processed; NFC

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

In D99896#2669471 , @erichkeane wrote:

> It is really sad that the attributes can't 'auto transform' themselves.  
> ParsedAttr could (since it has a union of expressions/identifiers), but we 
> don't really seem to have a good way to do it for Attr.
>
> Could we possibly do some table-gen to auto create the 'simple' ones?  
> Basically, any parameter to an attribute that is an 'expr' gets 
> auto-transformed?  Similar to how we have handleSimpleAttr, we could have 
> TransformSimpleAttr (or, a generated one).

I think that's likely plausible, though as a follow-up. We have enough 
declaration attributes with template instantiation that I'd probably start with 
those and do statement attributes in a second cleanup.




Comment at: clang/lib/Sema/TreeTransform.h:1316
Stmt *SubStmt) {
-return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
+return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
   }

erichkeane wrote:
> Am I missing where the attributes themselves are being rebuilt/transformed??  
> 
> 
The transformation happens in 
`TreeTransform::TransformAttributedStmt()` which calls 
`RebuildAttributedStmt()` with the rebuilt attributes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99896

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


[PATCH] D99896: Rework the way statement attributes are processed; NFC

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

It is really sad that the attributes can't 'auto transform' themselves.  
ParsedAttr could (since it has a union of expressions/identifiers), but we 
don't really seem to have a good way to do it for Attr.

Could we possibly do some table-gen to auto create the 'simple' ones?  
Basically, any parameter to an attribute that is an 'expr' gets 
auto-transformed?  Similar to how we have handleSimpleAttr, we could have 
TransformSimpleAttr (or, a generated one).




Comment at: clang/lib/Sema/TreeTransform.h:1316
Stmt *SubStmt) {
-return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
+return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
   }

Am I missing where the attributes themselves are being rebuilt/transformed??  




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99896

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


[PATCH] D99857: [OpenCL, test] Fix use of undef FileCheck var

2021-04-05 Thread Thomas Preud'homme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG828ec9e9e5da: [OpenCL, test] Fix use of undef FileCheck var 
(authored by thopre).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99857

Files:
  clang/test/CodeGenOpenCL/fpmath.cl


Index: clang/test/CodeGenOpenCL/fpmath.cl
===
--- clang/test/CodeGenOpenCL/fpmath.cl
+++ clang/test/CodeGenOpenCL/fpmath.cl
@@ -9,7 +9,7 @@
   // CHECK: @spscalardiv
   // CHECK: fdiv{{.*}},
   // NODIVOPT: !fpmath ![[MD:[0-9]+]]
-  // DIVOPT-NOT: !fpmath ![[MD:[0-9]+]]
+  // DIVOPT-NOT: !fpmath !{{[0-9]+}}
   return a / b;
 }
 
@@ -17,7 +17,7 @@
   // CHECK: @spvectordiv
   // CHECK: fdiv{{.*}},
   // NODIVOPT: !fpmath ![[MD]]
-  // DIVOPT-NOT: !fpmath ![[MD]]
+  // DIVOPT-NOT: !fpmath !{{[0-9]+}}
   return a / b;
 }
 


Index: clang/test/CodeGenOpenCL/fpmath.cl
===
--- clang/test/CodeGenOpenCL/fpmath.cl
+++ clang/test/CodeGenOpenCL/fpmath.cl
@@ -9,7 +9,7 @@
   // CHECK: @spscalardiv
   // CHECK: fdiv{{.*}},
   // NODIVOPT: !fpmath ![[MD:[0-9]+]]
-  // DIVOPT-NOT: !fpmath ![[MD:[0-9]+]]
+  // DIVOPT-NOT: !fpmath !{{[0-9]+}}
   return a / b;
 }
 
@@ -17,7 +17,7 @@
   // CHECK: @spvectordiv
   // CHECK: fdiv{{.*}},
   // NODIVOPT: !fpmath ![[MD]]
-  // DIVOPT-NOT: !fpmath ![[MD]]
+  // DIVOPT-NOT: !fpmath !{{[0-9]+}}
   return a / b;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 828ec9e - [OpenCL, test] Fix use of undef FileCheck var

2021-04-05 Thread Thomas Preud'homme via cfe-commits

Author: Thomas Preud'homme
Date: 2021-04-05T21:11:39+01:00
New Revision: 828ec9e9e5da8a2e7d1bfa523b9a712658ee6ffc

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

LOG: [OpenCL, test] Fix use of undef FileCheck var

Clang test CodeGenOpenCL/fpmath.cl uses a variable defined in an earlier
CHECK-NOT directive. However, by definition the pattern in that
directive is not supposed to occur so no variable will be defined. This
commit solves the issue by using a regex match with the same regex as in
the definition. It also changes the definition into a regex match since
no variable is going to be defined.

Reviewed By: yaxunl

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

Added: 


Modified: 
clang/test/CodeGenOpenCL/fpmath.cl

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/fpmath.cl 
b/clang/test/CodeGenOpenCL/fpmath.cl
index 36cb8e68ea7c..374b58c9bc04 100644
--- a/clang/test/CodeGenOpenCL/fpmath.cl
+++ b/clang/test/CodeGenOpenCL/fpmath.cl
@@ -9,7 +9,7 @@ float spscalardiv(float a, float b) {
   // CHECK: @spscalardiv
   // CHECK: fdiv{{.*}},
   // NODIVOPT: !fpmath ![[MD:[0-9]+]]
-  // DIVOPT-NOT: !fpmath ![[MD:[0-9]+]]
+  // DIVOPT-NOT: !fpmath !{{[0-9]+}}
   return a / b;
 }
 
@@ -17,7 +17,7 @@ float4 spvectordiv(float4 a, float4 b) {
   // CHECK: @spvectordiv
   // CHECK: fdiv{{.*}},
   // NODIVOPT: !fpmath ![[MD]]
-  // DIVOPT-NOT: !fpmath ![[MD]]
+  // DIVOPT-NOT: !fpmath !{{[0-9]+}}
   return a / b;
 }
 



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


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

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



Comment at: clang/lib/Sema/SemaStmt.cpp:588
+
+  const CallExpr *CE = dyn_cast(Ex->IgnoreUnlessSpelledInSource());
+

haberman wrote:
> rsmith wrote:
> > `IgnoreUnlessSpelledInSource` is a syntactic check that's only really 
> > intended for tooling use cases; I think we want something a bit more 
> > semantic here, so `IgnoreImplicitAsWritten` would be more appropriate.
> > 
> > I think it would be reasonable to also skip "parentheses" here (which we 
> > treat as also including things like C's `_Generic`). Would 
> > `Ex->IgnoreImplicitAsWritten()->IgnoreParens()` work?
> > 
> > If we're going to skip elidable copy construction of the result here (which 
> > I think we should), should we also reflect that in the AST? Perhaps we 
> > should strip the return value down to being just the call expression? I'm 
> > thinking in particular of things like building in C++14 or before with 
> > `-fno-elide-constructors`, where code generation for a by-value return of a 
> > class object will synthesize a local temporary to hold the result, with a 
> > final destination copy emitted after the call. (Testcase: `struct A { 
> > A(const A&); }; A f(); A g() { [[clang::musttail]] return f(); }` with 
> > `-fno-elide-constructors`.)
> `IgnoreImplicitAsWritten()` doesn't skip `ExprWithCleanups`, and per your 
> previous comment I was trying to find a `CallExpr` before doing the check 
> prohibiting `ExprWithCleanups` with side effects.
> 
> I could write some custom ignore logic using `clang::IgnoreExprNodes()` 
> directly.
> 
> > If we're going to skip elidable copy construction of the result here (which 
> > I think we should)
> 
> To clarify, are you suggesting that we allow `musttail` through elidable copy 
> constructors on the return value, even if `-fno-elide-constructors` is set? 
> ie. we consider that `musttail` overrides the `-fno-elide-constructors` 
> option on the command line?
> `IgnoreImplicitAsWritten()` doesn't skip `ExprWithCleanups`

That sounds like a bug. Are you sure? It looks like 
`IgnoreImplicitAsWrittenSingleStep` calls `IgnoreImplicitSingleStep` which 
calls `IgnoreImplicitCastsSingleStep` which skips `FullExpr`, and 
`ExprWithCleanups` is a kind of `FullExpr`.

> To clarify, are you suggesting that we allow `musttail` through elidable copy 
> constructors on the return value, even if `-fno-elide-constructors` is set? 
> ie. we consider that `musttail` overrides the `-fno-elide-constructors` 
> option on the command line?

Yes, I think the `musttail` attribute should override 
`-fno-elide-constructors`, because that's necessary in order to provide the 
tail call the user requested (and the local setting should override the global 
one). This is probably worth adding to the documentation.

(Also, `-fno-elide-constructors` is only supposed to affect code generation, 
not language semantics or program validity, so I think either we should always 
reject if a constructor call is required for the return value, regardless of 
whether it's elidable, or we should never reject in that case, and either way 
this determination should be made independent of the setting of 
`-fno-elide-constructors`. Given that choice, it seems more useful to bias 
towards the common case (`-felide-constructors`).)



Comment at: clang/lib/Sema/SemaStmt.cpp:561-568
+  for (const auto *A : Attrs) {
+if (A->getKind() == attr::MustTail) {
+  if (!checkMustTailAttr(SubStmt, *A)) {
+return SubStmt;
+  }
+  setFunctionHasMustTail();
+}

aaron.ballman wrote:
> aaron.ballman wrote:
> > haberman wrote:
> > > aaron.ballman wrote:
> > > > haberman wrote:
> > > > > haberman wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > haberman wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > This functionality belongs in SemaStmtAttr.cpp, I think.
> > > > > > > > That is where I had originally put it, but that didn't work for 
> > > > > > > > templates. The semantic checks can only be performed at 
> > > > > > > > instantiation time. `ActOnAttributedStmt` seems to be the right 
> > > > > > > > hook point where I can evaluate the semantic checks for both 
> > > > > > > > template and non-template functions (with template functions 
> > > > > > > > getting checked at instantiation time).
> > > > > > > I disagree that `ActOnAttributedStmt()` is the correct place for 
> > > > > > > this checking -- template checking should occur when the template 
> > > > > > > is instantiated, same as happens for declaration attributes. I'd 
> > > > > > > like to see this functionality moved to SemaStmtAttr.cpp. Keeping 
> > > > > > > the attribute logic together and following the same patterns is 
> > > > > > > what allows us to tablegenerate more of the attribute logic. 
> > > > > > > Statement attributes are just starting to get more such 
> > > > > > > automation.
> > > > > > I tried commenting out this code and adding 

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

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



Comment at: clang/lib/Sema/SemaStmt.cpp:561-568
+  for (const auto *A : Attrs) {
+if (A->getKind() == attr::MustTail) {
+  if (!checkMustTailAttr(SubStmt, *A)) {
+return SubStmt;
+  }
+  setFunctionHasMustTail();
+}

aaron.ballman wrote:
> aaron.ballman wrote:
> > haberman wrote:
> > > aaron.ballman wrote:
> > > > haberman wrote:
> > > > > haberman wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > haberman wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > This functionality belongs in SemaStmtAttr.cpp, I think.
> > > > > > > > That is where I had originally put it, but that didn't work for 
> > > > > > > > templates. The semantic checks can only be performed at 
> > > > > > > > instantiation time. `ActOnAttributedStmt` seems to be the right 
> > > > > > > > hook point where I can evaluate the semantic checks for both 
> > > > > > > > template and non-template functions (with template functions 
> > > > > > > > getting checked at instantiation time).
> > > > > > > I disagree that `ActOnAttributedStmt()` is the correct place for 
> > > > > > > this checking -- template checking should occur when the template 
> > > > > > > is instantiated, same as happens for declaration attributes. I'd 
> > > > > > > like to see this functionality moved to SemaStmtAttr.cpp. Keeping 
> > > > > > > the attribute logic together and following the same patterns is 
> > > > > > > what allows us to tablegenerate more of the attribute logic. 
> > > > > > > Statement attributes are just starting to get more such 
> > > > > > > automation.
> > > > > > I tried commenting out this code and adding the following code into 
> > > > > > `handleMustTailAttr()` in `SemaStmtAttr.cpp`:
> > > > > > 
> > > > > > ```
> > > > > >   if (!S.checkMustTailAttr(St, MTA))
> > > > > > return nullptr;
> > > > > > ```
> > > > > > 
> > > > > > This caused my test cases related to templates to fail. It also 
> > > > > > seemed to break test cases related to `JumpDiagnostics`. My 
> > > > > > interpretation of this is that `handleMustTailAttr()` is called 
> > > > > > during parsing only, and cannot catch errors at template 
> > > > > > instantiation time or that require a more complete AST.
> > > > > > 
> > > > > > What am I missing? Where in SemaStmtAttr.cpp are you suggesting 
> > > > > > that I put this check?
> > > > > Scratch the part about `JumpDiagnostics`, that was me failing to call 
> > > > > `S.setFunctionHasMustTail()`. I added that and now the 
> > > > > `JumpDiagnostics` tests pass.
> > > > > 
> > > > > But the template test cases still fail, and I can't find any hook 
> > > > > point in `SemaStmtAttr.cpp` that will let me evaluate these checks at 
> > > > > template instantiation time.
> > > > I think there's a bit of an architectural mixup, but I'm curious if 
> > > > @rsmith agrees before anyone starts doing work to make changes.
> > > > 
> > > > When transforming declarations, `RebuildWhatever()` calls the 
> > > > `ActOnWhatever()` function which calls `ProcessDeclAttributeList()` so 
> > > > that attributes are processed. `RebuildAttributedStmt()` similarly 
> > > > calls `ActOnAttributedStmt()`. However, `ActOnAttributedStmt()` doesn't 
> > > > call `ProcessStmtAttributes()` -- the logic is reversed so that 
> > > > `ProcessStmtAttributes()` is what calls `ActOnAttributedStmt()`.
> > > > 
> > > > I think the correct answer is to switch the logic so that 
> > > > `ActOnAttributedStmt()` calls `ProcessStmtAttributes()`, then the 
> > > > template logic should automatically work.
> > > > I think the correct answer is to switch the logic so that 
> > > > ActOnAttributedStmt() calls ProcessStmtAttributes()
> > > 
> > > I think this would require `ProcessStmtAttributes()` to be split into two 
> > > separate functions. Currently that function is doing two separate things:
> > > 
> > > 1. Translation of `ParsedAttr` into various subclasses of `Attr`.
> > > 2. Validation that the attribute is semantically valid.
> > > 
> > > The function signature for `ActOnAttributedStmt()` uses `Attr` (not 
> > > `ParsedAttr`), so (1) must happen during the parse, before 
> > > `ActOnAttributedStmt()` is called. But (2) must be deferred until 
> > > template instantiation time for some cases, like `musttail`.
> > I don't think the signature for `ActOnAttributedStmt()` is correct to use 
> > `Attr` instead of `ParsedAttr`. I think it should be `StmtResult 
> > ActOnAttributedStmt(const ParsedAttributesViewWithRange , Stmt 
> > *SubStmt);` -- this likely requires a fair bit of surgery to make work 
> > though, which is why I'd like to hear from @rsmith if he agrees with the 
> > approach. In the meantime, I'll play around with this idea locally in more 
> > depth.
> I think my suggestion wasn't quite right, but close. I've got a patch in 
> progress that changes this the way I was thinking it should be changed, but 
> it won't call 

[PATCH] D99896: Rework the way statement attributes are processed; NFC

2021-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, haberman, erichkeane.
aaron.ballman requested review of this revision.
Herald added a project: clang.

This changes our approach to processing statement attributes to be more similar 
to how we process declaration attributes. Namely, `ActOnAttributedStmt()` now 
calls `ProcessStmtAttributes()` instead of vice-versa, and there is now an 
interface split between building an attributed statement where you already have 
a list of semantic attributes and building an attributed statement with 
attributes from the parser.

This should make it easier to support statement attributes that are dependent 
on a template. In that case, you would add a `TransformFooAttr()` function in 
`TreeTransform.h` to perform the semantic checking (morally similar to how 
`Sema::InstantiateAttrs()` already works for declaration attributes) when 
transforming the semantic attribute at instantiation time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99896

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Sema/TreeTransform.h

Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -1311,9 +1311,9 @@
   /// By default, performs semantic analysis to build the new statement.
   /// Subclasses may override this routine to provide different behavior.
   StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
-   ArrayRef Attrs,
+   ArrayRef Attrs,
Stmt *SubStmt) {
-return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
+return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
   }
 
   /// Build a new "if" statement.
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -413,19 +413,13 @@
   }
 }
 
-StmtResult Sema::ProcessStmtAttributes(Stmt *S,
-   const ParsedAttributesView ,
-   SourceRange Range) {
-  SmallVector Attrs;
-  for (const ParsedAttr  : AttrList) {
-if (Attr *a = ProcessStmtAttribute(*this, S, AL, Range))
-  Attrs.push_back(a);
+void Sema::ProcessStmtAttributes(Stmt *S,
+ const ParsedAttributesWithRange ,
+ SmallVectorImpl ) {
+  for (const ParsedAttr  : InAttrs) {
+if (const Attr *A = ProcessStmtAttribute(*this, S, AL, InAttrs.Range))
+  OutAttrs.push_back(A);
   }
 
-  CheckForIncompatibleAttributes(*this, Attrs);
-
-  if (Attrs.empty())
-return S;
-
-  return ActOnAttributedStmt(Range.getBegin(), Attrs, S);
+  CheckForIncompatibleAttributes(*this, OutAttrs);
 }
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -555,12 +555,22 @@
   return LS;
 }
 
-StmtResult Sema::ActOnAttributedStmt(SourceLocation AttrLoc,
- ArrayRef Attrs,
+StmtResult Sema::BuildAttributedStmt(SourceLocation AttrsLoc,
+ ArrayRef Attrs,
  Stmt *SubStmt) {
-  // Fill in the declaration and return it.
-  AttributedStmt *LS = AttributedStmt::Create(Context, AttrLoc, Attrs, SubStmt);
-  return LS;
+  return AttributedStmt::Create(Context, AttrsLoc, Attrs, SubStmt);
+}
+
+StmtResult Sema::ActOnAttributedStmt(const ParsedAttributesWithRange ,
+ Stmt *SubStmt) {
+  SmallVector SemanticAttrs;
+  ProcessStmtAttributes(SubStmt, Attrs, SemanticAttrs);
+  if (!SemanticAttrs.empty())
+return BuildAttributedStmt(Attrs.Range.getBegin(), SemanticAttrs, SubStmt);
+  // If none of the attributes applied, that's fine, we can recover by
+  // returning the substatement directly instead of making an AttributedStmt
+  // with no attributes on it.
+  return SubStmt;
 }
 
 namespace {
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -120,7 +120,7 @@
   if (Attrs.empty() || Res.isInvalid())
 return Res;
 
-  return Actions.ProcessStmtAttributes(Res.get(), Attrs, Attrs.Range);
+  return Actions.ActOnAttributedStmt(Attrs, Res.get());
 }
 
 namespace {
@@ -657,8 +657,7 @@
   SubStmt = ParseStatementOrDeclarationAfterAttributes(Stmts, StmtCtx,
nullptr, TempAttrs);
   if (!TempAttrs.empty() && !SubStmt.isInvalid())
-SubStmt = Actions.ProcessStmtAttributes(SubStmt.get(), TempAttrs,
-

[PATCH] D99879: [clang][cli] Ensure plugin args are generated in deterministic order

2021-04-05 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

also just confirming that this fixes the issue we were seeing in Chrome


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99879

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


[PATCH] D99893: [WIP] Replace std::forward & std::move by cast expressions during Sema

2021-04-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I think a pattern-match in IRGen is probably a much more reasonable alternative 
if the goal is primarily to avoid the code-generation overheads at -O0 / 
optimization costs at -O.  You'd still have template instantiation 
overheads; I don't know how significant those really are.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99893

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


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

2021-04-05 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:1324
+
+if (SrcElementTy->isFloatTy() || SrcElementTy->isDoubleTy()) {
+  QualType DstElementType = 
DstType->castAs()->getElementType();

I think we should support all floating point type here (`isFloatingPointTy`). 
Basically we want the same rules as for integer types (around line 1418). 
Perhaps it would be possible to generalize this code in a separate function 
that takes the LLVM types & the element type/scalar types?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99893: [WIP] Replace std::forward & std::move by cast expressions during Sema

2021-04-05 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

To be noted, this generally goes against the [current] spirit of the AST,
those were calls in the source code, but they won't be represented as such any 
longer,
which is likely not very expected by whatever tool that could be consuming the 
AST.
Though, i'm not sure how much that matters.

I would guess, having clang emit MLIR C++ dialect and not LLVM IR
might allow such transforms without degrading AST,
though i will be surprised if that happens [upstream] soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99893

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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2021-04-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Sorry, it's just been a busy month for me.

In D89490#2539950 , @aguinet wrote:

> In D89490#2516255 , @rjmccall wrote:
>
>> In D89490#2514695 , @aguinet wrote:
>>
 I may be over-reacting to the way the patch seemed to be touching on the 
 C++ ABI in multiple places.  My understanding is that `ms_abi` is just a 
 calling-convention attribute; it's basically "use the (default) calling 
 convention that MSVC would use for this function".  If that's all you 
 want, then this is reasonable, although I am worried about creating a new 
 attribute for every system that Wine chooses to target.
>>>
>>> I literally based this patch on how ms_abi was implemented. It's 
>>> unfortunately more than just teaching clang to change the calling 
>>> convention on LLVM IR functions. The fact that ABI implementations are 
>>> spread all over the place between various places in LLVM is, as far as I 
>>> remember, a known problem discussed many times on llvm-dev, and looks like 
>>> a hard one to fix.
>>
>> Right, I understand that — I've even given an LLVM talk about it.  I was 
>> just confused about your intent because you made some effort to match other 
>> parts of the ABI besides what we might traditionally consider the calling 
>> convention.  I suppose some of those changes could be thought of as 
>> feature-specific calling conventions, but I don't usually think of them that 
>> way.
>
> We could have a long discussion on what do we exactly call a "calling 
> convention" :) IIRC I did implement a few C++ bits, but they could be removed 
> from this patch for further implementation.
>
 About "darwin": technically, every Apple platform has a different ABI.  
 Our current ARM64 platforms do all agree about things like the calling 
 convention, at least if you count newer watches (which use a 32-on-64 ABI 
 in userspace) as not ARM64.  That is not true of other architectures, most 
 notably on ARM32, where the 32-bit iOS ABI is very different from the 
 armv7k Apple Watch ABI; and it is certainly conceivable that Apple might 
 release a new ARM64 platform in the future with a different calling 
 convention.  The more technically correct and future-proof thing would be 
 to use the OS name (or maybe even the triple!) in the attribute, probably 
 as an argument to the attribute, like 
 `__attribute__((target_abi("arm64-apple-ios")))`.
>>>
>>> I'm a bit afraid that `__attribute__((target_abi(XX)))` would conflict with 
>>> the existing `__attribute__((ms_abi))`.
>>
>> They don't *conflict*.  It's a more general scheme than the existing 
>> attribute, but the existing attribute can be thought of as a shorthand for 
>> one case of that more general scheme, so I don't see a problem here.  I 
>> would like to not have to add a new attribute for every OS that Wine decides 
>> to support.
>
> You're right, let me rephrase what I wanted to say: with this, there will be 
> two ways to target the windows ABI. I guess we can be fine with it, but that 
> adds some kind of complexity that needs to be explained to the end user.
>
> There is also the support the equivalent of the `__builtin_ms_va_list` type 
> that needs to be considered, which would make a type that could look like 
> `__builtin_abi_va_list_INSERT_TRIPLE_HERE`, with the fact that we can't have 
> '-' in types. It might be better to do something similar than 
> `ext_vector_type`, and have something like:
>
>   typedef va_list __attribute__((target_abi("arm64-apple-ios"))) 
> arm64_ios_abi_va_list; 

Ah.  That's tricky because `va_list` is not normally abstracted in the compiler 
representation; the target just gives an implicit prefix that's parsed before 
the translation unit, and that defines the `va_list` type.  If you want easy OS 
ABI portability here, you'll need to come up with a way in the source language 
to spell the different `va_list` types and to select which `va_next` 
implementation you want (`va_start` has to match the current function, but 
`va_next` doesn't).  Fortunately we lower `va_next` in the frontend, so LLVM 
only needs to know about `va_start`, and that's always determined by the 
current function.

> Another question I would have with that setup is how much this is 
> "transposed" into the LLVM world. My feeling is that can be, at least as a 
> first implementation, just a "frontend" to assign the darwin or MS calling 
> conventions to functions.

I think it really depends on how far you want to take this.  If you just want 
to control register/stack conventions, then it seems to me that adding LLVM CCs 
that are explicit about which rules to use (and making Clang do its side of the 
lowering properly) is pretty reasonable.  LLVM is already pretty well 
abstracted to be flexible about CCs.  I'm not sure if it's well-abstracted to 

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

2021-04-05 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D99037#2667484 , @SaurabhJha wrote:

> Addressed most of the comments. I couldn't understand "..would also be good 
> to have C++ tests that test casting with matrix types where some of the 
> dimensions are template arguments...". When I tried this
>
> """
> cx4x4 m1;
>
> (void)(ix4x4)m1
> """
>
> it gave me the error
> """
> C-style cast from 'cx4x4' (aka 'char __attribute__((matrix_type(4, 4)))') to 
> 'ix4x4' (aka 'int __attribute__((matrix_type(4, 4)))') is not allowed
> """

Oh, that's interesting, I was assuming the code-paths would be the same. I was 
thinking about C++ specific test cases like

  template 
  using matrix_t = X __attribute__((matrix_type(4, 4)));
  
  matrix_t foo(matrix_t x) {
return (matrix_t)x;
  }

> should I address it as part of this patch?

I don't think we necessarily need to implement them in this patch, unless 
@rjmccall could think of any issues. IMO it would still be good to add tests to 
Sema to ensure we do not crash. We can then just update them once support for 
C++ is added.




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8580
 
+def err_invalid_conversion_between_matrices : Error<
+  "invalid conversion between matrix type%diff{ $ and $|}0,1 of different "

I think in other places we are already using `matrixes`. Would be good to be 
consistent with the existing spelling I think (but I am no English expert)



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8585
+def err_invalid_conversion_between_matrix_and_non_matrix : Error<
+  "invalid conversion between matrix type %0 and non matrix type %1">;
+

I think for other messages we say `... is not allowed`. Perhaps this message 
should be similar? Also I'm not sure about reefing to non-matrix types. We 
might allow at least for conversion between arithmetic types and matrixes 
(broadcast). It might be OK to just drop the `non matrix` part?



Comment at: clang/include/clang/Sema/Sema.h:11707
 
+  // CheckMatrixCast - Check type constraints for matrices.
+  // We allow casting between matrices of the same dimensions i.e. when they

nit: for matrix casts?



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:1316
+
+llvm::Type *SrcElementTy = cast(SrcTy)->getElementType();
+

You could move the code generation part to `MatrixBuilder.h`?



Comment at: clang/lib/Sema/SemaCast.cpp:2916
 
   // Require the operand to be a scalar or vector.
+  if (!SrcType->isScalarType() && !SrcType->isVectorType() &&

fhahn wrote:
> ` ... or a matrix`?
nit: missing comma after `a scalar`.



Comment at: clang/lib/Sema/SemaExpr.cpp:7348
 
+/// Are the two types matrix types and do they have the same dimensions i.e.
+/// and do they both have the same dimensions i.e. do they have the same number

From the comment here it sounds like this function checks if the arguments are 
matrix types, but it asserts. Does the comment need updating?


It looks like the part after `i.e.` needs rewording also, as there's some 
duplication?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

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


[PATCH] D99893: [WIP] Replace std::forward & std::move by cast expressions during Sema

2021-04-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: rsmith, Quuxplusone, rjmccall.
aaron.ballman added a comment.

Adding a few more reviewers for early feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99893

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


[PATCH] D80344: [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1

2021-04-05 Thread Ten Tzen via Phabricator via cfe-commits
tentzen marked 13 inline comments as done.
tentzen added a comment.

hi,  I believe I'd addressed all issues or concerns, and it's rebased to 
up-to-date source in new _main branch now. Does this look good to everyone? If 
I don't hear any objection in a couple of days, I will go ahead make this patch 
in. Again This is just part-1 of Windows SEH feature.  Without new option 
specified, it's a zero-impact change.




Comment at: clang/include/clang/Driver/Options.td:886
   HelpText<"Enable C++ exceptions">, Flags<[CC1Option]>;
+def fasync_exceptions: Flag<["-"], "fasync-exceptions">, Group,
+  HelpText<"Enable EH Asynchronous exceptions">, Flags<[CC1Option]>;

jansvoboda11 wrote:
> Can you rebase and use the new option marshalling infrastructure instead?
> 
> https://clang.llvm.org/docs/InternalsManual.html#adding-new-command-line-option
SEH Async-excception option is implemented the same way as CXX-exception or 
ObjC-exception.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80344

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


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

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



Comment at: clang/lib/Sema/SemaStmt.cpp:561-568
+  for (const auto *A : Attrs) {
+if (A->getKind() == attr::MustTail) {
+  if (!checkMustTailAttr(SubStmt, *A)) {
+return SubStmt;
+  }
+  setFunctionHasMustTail();
+}

aaron.ballman wrote:
> haberman wrote:
> > aaron.ballman wrote:
> > > haberman wrote:
> > > > haberman wrote:
> > > > > aaron.ballman wrote:
> > > > > > haberman wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > This functionality belongs in SemaStmtAttr.cpp, I think.
> > > > > > > That is where I had originally put it, but that didn't work for 
> > > > > > > templates. The semantic checks can only be performed at 
> > > > > > > instantiation time. `ActOnAttributedStmt` seems to be the right 
> > > > > > > hook point where I can evaluate the semantic checks for both 
> > > > > > > template and non-template functions (with template functions 
> > > > > > > getting checked at instantiation time).
> > > > > > I disagree that `ActOnAttributedStmt()` is the correct place for 
> > > > > > this checking -- template checking should occur when the template 
> > > > > > is instantiated, same as happens for declaration attributes. I'd 
> > > > > > like to see this functionality moved to SemaStmtAttr.cpp. Keeping 
> > > > > > the attribute logic together and following the same patterns is 
> > > > > > what allows us to tablegenerate more of the attribute logic. 
> > > > > > Statement attributes are just starting to get more such automation.
> > > > > I tried commenting out this code and adding the following code into 
> > > > > `handleMustTailAttr()` in `SemaStmtAttr.cpp`:
> > > > > 
> > > > > ```
> > > > >   if (!S.checkMustTailAttr(St, MTA))
> > > > > return nullptr;
> > > > > ```
> > > > > 
> > > > > This caused my test cases related to templates to fail. It also 
> > > > > seemed to break test cases related to `JumpDiagnostics`. My 
> > > > > interpretation of this is that `handleMustTailAttr()` is called 
> > > > > during parsing only, and cannot catch errors at template 
> > > > > instantiation time or that require a more complete AST.
> > > > > 
> > > > > What am I missing? Where in SemaStmtAttr.cpp are you suggesting that 
> > > > > I put this check?
> > > > Scratch the part about `JumpDiagnostics`, that was me failing to call 
> > > > `S.setFunctionHasMustTail()`. I added that and now the 
> > > > `JumpDiagnostics` tests pass.
> > > > 
> > > > But the template test cases still fail, and I can't find any hook point 
> > > > in `SemaStmtAttr.cpp` that will let me evaluate these checks at 
> > > > template instantiation time.
> > > I think there's a bit of an architectural mixup, but I'm curious if 
> > > @rsmith agrees before anyone starts doing work to make changes.
> > > 
> > > When transforming declarations, `RebuildWhatever()` calls the 
> > > `ActOnWhatever()` function which calls `ProcessDeclAttributeList()` so 
> > > that attributes are processed. `RebuildAttributedStmt()` similarly calls 
> > > `ActOnAttributedStmt()`. However, `ActOnAttributedStmt()` doesn't call 
> > > `ProcessStmtAttributes()` -- the logic is reversed so that 
> > > `ProcessStmtAttributes()` is what calls `ActOnAttributedStmt()`.
> > > 
> > > I think the correct answer is to switch the logic so that 
> > > `ActOnAttributedStmt()` calls `ProcessStmtAttributes()`, then the 
> > > template logic should automatically work.
> > > I think the correct answer is to switch the logic so that 
> > > ActOnAttributedStmt() calls ProcessStmtAttributes()
> > 
> > I think this would require `ProcessStmtAttributes()` to be split into two 
> > separate functions. Currently that function is doing two separate things:
> > 
> > 1. Translation of `ParsedAttr` into various subclasses of `Attr`.
> > 2. Validation that the attribute is semantically valid.
> > 
> > The function signature for `ActOnAttributedStmt()` uses `Attr` (not 
> > `ParsedAttr`), so (1) must happen during the parse, before 
> > `ActOnAttributedStmt()` is called. But (2) must be deferred until template 
> > instantiation time for some cases, like `musttail`.
> I don't think the signature for `ActOnAttributedStmt()` is correct to use 
> `Attr` instead of `ParsedAttr`. I think it should be `StmtResult 
> ActOnAttributedStmt(const ParsedAttributesViewWithRange , Stmt 
> *SubStmt);` -- this likely requires a fair bit of surgery to make work 
> though, which is why I'd like to hear from @rsmith if he agrees with the 
> approach. In the meantime, I'll play around with this idea locally in more 
> depth.
I think my suggestion wasn't quite right, but close. I've got a patch in 
progress that changes this the way I was thinking it should be changed, but it 
won't call `ActOnAttributedStmt()` when doing template instantiation. Instead, 
it will continue to instantiate attributes explicitly by calling 
`TransformAttr()` and any additional instantiation time checks will 

[PATCH] D99848: [OPENMP51]Initial support for nocontext clause

2021-04-05 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jyu2 marked an inline comment as done and an inline comment as not done.
Closed by commit rG7078ef472250: [OPENMP51]Initial support for nocontext 
clause. (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99848

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/dispatch_ast_print.cpp
  clang/test/OpenMP/dispatch_messages.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -282,6 +282,10 @@
   let clangClass = "OMPNovariantsClause";
   let flangClass = "ScalarLogicalExpr";
 }
+def OMPC_Nocontext : Clause<"nocontext"> {
+  let clangClass = "OMPNocontextClause";
+  let flangClass = "ScalarLogicalExpr";
+}
 def OMPC_Detach : Clause<"detach"> {
   let clangClass = "OMPDetachClause";
 }
@@ -1667,7 +1671,8 @@
 VersionedClause,
 VersionedClause,
 VersionedClause,
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
 }
 def OMP_Unknown : Directive<"unknown"> {
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -730,6 +730,7 @@
 CHECK_SIMPLE_CLAUSE(Init, OMPC_init)
 CHECK_SIMPLE_CLAUSE(Use, OMPC_use)
 CHECK_SIMPLE_CLAUSE(Novariants, OMPC_novariants)
+CHECK_SIMPLE_CLAUSE(Nocontext, OMPC_nocontext)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Allocator, OMPC_allocator)
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2295,6 +2295,10 @@
   Visitor->AddStmt(C->getCondition());
 }
 
+void OMPClauseEnqueue::VisitOMPNocontextClause(const OMPNocontextClause *C) {
+  Visitor->AddStmt(C->getCondition());
+}
+
 void OMPClauseEnqueue::VisitOMPUnifiedAddressClause(
 const OMPUnifiedAddressClause *) {}
 
Index: clang/test/OpenMP/dispatch_messages.cpp
===
--- clang/test/OpenMP/dispatch_messages.cpp
+++ clang/test/OpenMP/dispatch_messages.cpp
@@ -46,6 +46,24 @@
   // expected-error@+1 {{use of undeclared identifier 'x'}}
   #pragma omp dispatch novariants(x)
   disp_call();
+  
+  // expected-error@+1 {{expected '(' after 'nocontext'}}
+  #pragma omp dispatch nocontext
+  disp_call();
+
+  // expected-error@+3 {{expected expression}}
+  // expected-error@+2 {{expected ')'}}
+  // expected-note@+1 {{to match this '('}}
+  #pragma omp dispatch nocontext (
+  disp_call();
+
+  // expected-error@+1 {{cannot contain more than one 'nocontext' clause}}
+  #pragma omp dispatch nocontext(dnum> 4) nocontext(3)
+  disp_call();
+
+  // expected-error@+1 {{use of undeclared identifier 'x'}}
+  #pragma omp dispatch nocontext(x)
+  disp_call();
 }
 
 void testit_two() {
Index: clang/test/OpenMP/dispatch_ast_print.cpp
===
--- clang/test/OpenMP/dispatch_ast_print.cpp
+++ clang/test/OpenMP/dispatch_ast_print.cpp
@@ -51,22 +51,22 @@
 void test_one()
 {
   int aaa, bbb, var;
-  //PRINT: #pragma omp dispatch depend(in : var) nowait novariants(aaa > 5)
+  //PRINT: #pragma omp dispatch depend(in : var) nowait novariants(aaa > 5) nocontext(bbb > 5)
   //DUMP: OMPDispatchDirective
   //DUMP: OMPDependClause
   //DUMP: OMPNowaitClause
   //DUMP: OMPNovariantsClause
-  #pragma omp dispatch depend(in:var) nowait novariants(aaa > 5)
+  #pragma omp dispatch depend(in:var) nowait novariants(aaa > 5) nocontext(bbb > 5)
   foo(aaa, );
 
   int *dp = get_device_ptr();
   int dev = get_device();
-  //PRINT: #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10)
+  //PRINT: #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10) nocontext(dev > 5)
   //DUMP: OMPDispatchDirective
   //DUMP: OMPDeviceClause
   //DUMP: OMPIs_device_ptrClause
   //DUMP: OMPNovariantsClause
-  #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10)
+  #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10) nocontext(dev > 5)
   foo(aaa, dp);
 
   //PRINT: #pragma omp 

[clang] 7078ef4 - [OPENMP51]Initial support for nocontext clause.

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

Author: Jennifer Yu
Date: 2021-04-05T11:45:49-07:00
New Revision: 7078ef47225091a9a42357b9ebf92e83a5665d43

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

LOG: [OPENMP51]Initial support for nocontext clause.

Added basic parsing/sema/serialization support for the 'nocontext' clause.

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

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/dispatch_ast_print.cpp
clang/test/OpenMP/dispatch_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 4d5cdffba8919..11eb453a02060 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7720,6 +7720,75 @@ class OMPNovariantsClause final : public OMPClause,
   }
 };
 
+/// This represents 'nocontext' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp dispatch nocontext(a > 5)
+/// \endcode
+/// In this example directive '#pragma omp dispatch' has simple 'nocontext'
+/// clause with condition 'a > 5'.
+class OMPNocontextClause final : public OMPClause, public OMPClauseWithPreInit 
{
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Condition of the 'if' clause.
+  Stmt *Condition = nullptr;
+
+  /// Set condition.
+  void setCondition(Expr *Cond) { Condition = Cond; }
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+public:
+  /// Build 'nocontext' clause with condition \a Cond.
+  ///
+  /// \param Cond Condition of the clause.
+  /// \param HelperCond Helper condition for the construct.
+  /// \param CaptureRegion Innermost OpenMP region where expressions in this
+  /// clause must be captured.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPNocontextClause(Expr *Cond, Stmt *HelperCond,
+ OpenMPDirectiveKind CaptureRegion, SourceLocation 
StartLoc,
+ SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_nocontext, StartLoc, EndLoc),
+OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
+setPreInitStmt(HelperCond, CaptureRegion);
+  }
+
+  /// Build an empty clause.
+  OMPNocontextClause()
+  : OMPClause(llvm::omp::OMPC_nocontext, SourceLocation(),
+  SourceLocation()),
+OMPClauseWithPreInit(this) {}
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns condition.
+  Expr *getCondition() const { return cast_or_null(Condition); }
+
+  child_range children() { return child_range(,  + 1); }
+
+  const_child_range children() const {
+return const_child_range(,  + 1);
+  }
+
+  child_range used_children();
+  const_child_range used_children() const {
+auto Children = const_cast(this)->used_children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_nocontext;
+  }
+};
+
 /// This represents 'detach' clause in the '#pragma omp task' directive.
 ///
 /// \code

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index cdedbe22f9ed0..8ca7c509776b4 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3226,6 +3226,14 @@ bool 
RecursiveASTVisitor::VisitOMPNovariantsClause(
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPNocontextClause(
+OMPNocontextClause *C) {
+  TRY_TO(VisitOMPClauseWithPreInit(C));
+  TRY_TO(TraverseStmt(C->getCondition()));
+  return true;
+}
+
 template 
 template 
 bool RecursiveASTVisitor::VisitOMPClauseList(T *Node) {

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e0973171be937..8f6e6baaea62b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11014,6 +11014,11 @@ class Sema final {
  SourceLocation 

[PATCH] D99893: [WIP] Replace std::forward & std::move by cast expression

2021-04-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added subscribers: dexonsmith, martong.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99893

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/tools/libclang/CXCursor.cpp

Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -480,6 +480,11 @@
 K = CXCursor_CXXStaticCastExpr;
 break;
 
+  case Stmt::CXXStandardLibraryCastExprClass:
+return MakeCXCursor(
+cast(S)->getOriginalExpression(), Parent,
+TU, RegionOfInterest);
+
   case Stmt::CXXDynamicCastExprClass:
 K = CXCursor_CXXDynamicCastExpr;
 break;
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1720,6 +1720,7 @@
 case Stmt::ImplicitCastExprClass:
 case Stmt::CStyleCastExprClass:
 case Stmt::CXXStaticCastExprClass:
+case Stmt::CXXStandardLibraryCastExprClass:
 case Stmt::CXXDynamicCastExprClass:
 case Stmt::CXXReinterpretCastExprClass:
 case Stmt::CXXConstCastExprClass:
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1652,6 +1652,13 @@
   Code = serialization::EXPR_CXX_STATIC_CAST;
 }
 
+void ASTStmtWriter::VisitCXXStandardLibraryCastExpr(
+CXXStandardLibraryCastExpr *E) {
+  VisitCastExpr(E);
+  VisitExpr(E);
+  Code = serialization::EXPR_CXX_STATIC_CAST;
+}
+
 void ASTStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
   VisitCXXNamedCastExpr(E);
   Code = serialization::EXPR_CXX_DYNAMIC_CAST;
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1143,6 +1143,12 @@
   E->setIsPartOfExplicitCast(Record.readInt());
 }
 
+void ASTStmtReader::VisitCXXStandardLibraryCastExpr(
+CXXStandardLibraryCastExpr *E) {
+  VisitCastExpr(E);
+  E->OriginalExpression = Record.readSubExpr();
+}
+
 void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
   VisitCastExpr(E);
   E->setTypeInfoAsWritten(readTypeSourceInfo());
@@ -2930,6 +2936,13 @@
   /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
   break;
 
+case EXPR_CXX_STL_CAST:
+  S = CXXStandardLibraryCastExpr::CreateEmpty(
+  Context,
+  /*PathSize*/ Record[ASTStmtReader::NumExprFields],
+  /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
+  break;
+
 case EXPR_CSTYLE_CAST:
   S = CStyleCastExpr::CreateEmpty(
   Context,
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -10899,6 +10899,14 @@
   return getDerived().TransformExpr(E->getSubExprAsWritten());
 }
 
+template 
+ExprResult TreeTransform::TransformCXXStandardLibraryCastExpr(
+CXXStandardLibraryCastExpr *E) {
+  // CXXStandardLibraryCastExpr casts are eliminated during transformation,
+  // since they will be recomputed by semantic analysis after transformation.
+  return E;
+}
+
 template
 ExprResult
 TreeTransform::TransformCStyleCastExpr(CStyleCastExpr *E) {
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6443,6 +6443,60 @@
 }
   }
 
+  auto RewriteQualifiedCallsToStandardCastFunction =
+  [&](Expr *Fn) -> ExprResult {
+auto *ULE = dyn_cast_or_null(Fn->IgnoreParens());
+if (ArgExprs.size() != 1 || Expr::hasAnyTypeDependentArguments(ArgExprs) ||
+!ULE || !ULE->getQualifier() ||
+   

[PATCH] D99199: Make -fcrash-diagnostics-dir control the Windows (mini-)dump location

2021-04-05 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


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

https://reviews.llvm.org/D99199

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


[PATCH] D99879: [clang][cli] Ensure plugin args are generated in deterministic order

2021-04-05 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM. Based on git-blame, this was added in 
6c78974b298d619ec11e243fb6fdea0b16f87a66 (https://reviews.llvm.org/D17959) and 
the choice of unordered vs. ordered looks incidental (not motivated by 
performance).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99879

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


[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2021-04-05 Thread Felix Berger via Phabricator via cfe-commits
flx added a comment.

Could someone take a look at this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

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


[PATCH] D71726: Let clang atomic builtins fetch add/sub support floating point types

2021-04-05 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:5011
+!ValType->isFloatingType()) {
+  Diag(ExprRange.getBegin(), 
diag::err_atomic_op_needs_atomic_int_ptr_or_fp)
   << IsC11 << Ptr->getType() << Ptr->getSourceRange();

yaxunl wrote:
> rjmccall wrote:
> > Does LLVM support atomics on all floating-point types?
> LLVM IR parser requires atomicrmw value operand must have size of power of 2, 
> therefore LLVM does not support atomicrmw on x86_fp80 which has size of 80 
> bytes. LLVM supports atomicrmw on all other floating-point types (bfloat, 
> half, float, double, fp128, ppc_fp128).
Okay.  So this needs to check the underlying FP semantics and disallow atomics 
on unsupported types.


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

https://reviews.llvm.org/D71726

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


[PATCH] D98726: [analyzer] Enabling MallocChecker to take up after SmartPtrModelling

2021-04-05 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D98726#2630947 , @RedDocMD wrote:

> @NoQ, regarding https://godbolt.org/z/1EczEW, I don't think there should be a 
> warning since the original pointer may be needed in the caller.

You're absolutely right! I missed this point!

I still think it's worth a few experiments to see if the very presence of 
`unique_ptr` in the code is a good-enough indication that the callee expects 
//unique// ownership. But no, that's definitely not the point of that TODO.

Here's a related example where the caller technically can still rely on keeping 
the pointer but that situation would be even more absurd: 
https://godbolt.org/z/Mnos89ehK - basically the only way for the caller to 
access the raw pointer value before it gets destroyed is from within a 
temporary destructor that precedes the destructor of the `unique_ptr` argument. 
Which is valid but i'm leaning heavily towards still emitting a warning.

Another example: https://godbolt.org/z/on13Kv1q4 - this is definitely 
questionable but probably still deserves experimentation.

Ok so long story short, the only information that we gain about the raw pointer 
on `.release()` is that (assuming the default deleter is used) it's //some// 
memory allocated by `new`. We already knew (no pun intended) that about the raw 
pointer but `.release()` sounds like a good place to re-attach it. We do not 
really gain knowledge that we have to release the value but we can try to see 
what happens if we pretend we do. I guess we could rephrase the TODO to reflect 
that - "experiment with detecting leaks of the raw pointer after .release()" or 
something like that. We also definitely don't gain the knowledge that the value 
is already released (it definitely isn't, despite the method's name).

> But thanks for pointing out the possible leaks due to release! :)
> In the line that you have pointed out, I have thought about the following 
> cases which should have a warning (but currently don't):
>
> - https://godbolt.org/z/dzszWd (leak from explicit new)
> - https://godbolt.org/z/rdbKn3 (leak from `unique_ptr` created from 
> `make_unique`)
> - https://godbolt.org/z/Y6d5qE (use after delete of passed pointer)

In these cases MallocChecker should already be tracking the pointer even before 
it was put into `unique_ptr`. So i guess we should investigate where/why this 
information gets lost. But we shouldn't be re-attaching it; it should be 
already there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98726

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


[PATCH] D99857: [OpenCL, test] Fix use of undef FileCheck var

2021-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl 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/D99857/new/

https://reviews.llvm.org/D99857

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


[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-04-05 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 335293.
varungandhi-apple added a comment.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.

1. Remove '::' when calling static function.
2. Fix bug in function merging around missing musttail.
3. Add off-by-default check in verifier for swifttailcc->swifttailcc tail calls 
that are not marked musttail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

Files:
  clang/lib/AST/ExprCXX.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/IPO/MergeFunctions.cpp

Index: llvm/lib/Transforms/IPO/MergeFunctions.cpp
===
--- llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -713,7 +713,10 @@
 
   CallInst *CI = Builder.CreateCall(F, Args);
   ReturnInst *RI = nullptr;
-  CI->setTailCall();
+  bool isSwiftTailCall = F->getCallingConv() == CallingConv::SwiftTail &&
+ G->getCallingConv() == CallingConv::SwiftTail;
+  CI->setTailCallKind(isSwiftTailCall ? llvm::CallInst::TCK_MustTail
+  : llvm::CallInst::TCK_Tail);
   CI->setCallingConv(F->getCallingConv());
   CI->setAttributes(F->getAttributes());
   if (H->getReturnType()->isVoidTy()) {
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -3288,7 +3288,24 @@
   return Copy;
 }
 
+static cl::opt EnableSwiftTailCCMustTailCheck(
+"enable-swifttailcc-musttail-check", cl::init(false),
+cl::desc("Check that tail calls from swifttailcc functions to"
+ " swifttailcc functions are marked musttail."));
+
 void Verifier::verifyMustTailCall(CallInst ) {
+  if (!CI.isMustTailCall()) {
+if (EnableSwiftTailCCMustTailCheck &&
+CI.getCallingConv() == CallingConv::SwiftTail &&
+CI.getCaller()->getCallingConv() == CallingConv::SwiftTail &&
+isa_and_nonnull(CI.getNextNode())) {
+  Assert(false,
+ "tail call from swifttail->swiftail should be marked musttail",
+ );
+}
+return;
+  }
+
   Assert(!CI.isInlineAsm(), "cannot use musttail call with inline asm", );
 
   // - The caller and callee prototypes must match.  Pointer types of
@@ -3354,9 +3371,7 @@
 
 void Verifier::visitCallInst(CallInst ) {
   visitCallBase(CI);
-
-  if (CI.isMustTailCall())
-verifyMustTailCall(CI);
+  verifyMustTailCall(CI);
 }
 
 void Verifier::visitInvokeInst(InvokeInst ) {
Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -6,3 +6,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -x c++ -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf1{{.*}}(i8* swiftasync

[PATCH] D99811: [TextAPI] move source code files out of subdirectory, NFC

2021-04-05 Thread Cyndy Ishida 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 rG0116d04d04f2: [TextAPI] move source code files out of 
subdirectory, NFC (authored by cishida).

Changed prior to commit:
  https://reviews.llvm.org/D99811?vs=335007=335291#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99811

Files:
  clang/docs/ClangFormattedStatus.rst
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/DriverUtils.cpp
  lld/MachO/InputFiles.cpp
  lld/MachO/InputFiles.h
  lld/lib/ReaderWriter/MachO/File.h
  llvm/include/llvm/Object/TapiFile.h
  llvm/include/llvm/Object/TapiUniversal.h
  llvm/include/llvm/TextAPI/Architecture.def
  llvm/include/llvm/TextAPI/Architecture.h
  llvm/include/llvm/TextAPI/ArchitectureSet.h
  llvm/include/llvm/TextAPI/InterfaceFile.h
  llvm/include/llvm/TextAPI/MachO/Architecture.def
  llvm/include/llvm/TextAPI/MachO/Architecture.h
  llvm/include/llvm/TextAPI/MachO/ArchitectureSet.h
  llvm/include/llvm/TextAPI/MachO/InterfaceFile.h
  llvm/include/llvm/TextAPI/MachO/PackedVersion.h
  llvm/include/llvm/TextAPI/MachO/Platform.h
  llvm/include/llvm/TextAPI/MachO/Symbol.h
  llvm/include/llvm/TextAPI/MachO/Target.h
  llvm/include/llvm/TextAPI/MachO/TextAPIReader.h
  llvm/include/llvm/TextAPI/MachO/TextAPIWriter.h
  llvm/include/llvm/TextAPI/PackedVersion.h
  llvm/include/llvm/TextAPI/Platform.h
  llvm/include/llvm/TextAPI/Symbol.h
  llvm/include/llvm/TextAPI/Target.h
  llvm/include/llvm/TextAPI/TextAPIReader.h
  llvm/include/llvm/TextAPI/TextAPIWriter.h
  llvm/lib/Object/TapiUniversal.cpp
  llvm/lib/TextAPI/Architecture.cpp
  llvm/lib/TextAPI/ArchitectureSet.cpp
  llvm/lib/TextAPI/CMakeLists.txt
  llvm/lib/TextAPI/InterfaceFile.cpp
  llvm/lib/TextAPI/MachO/Architecture.cpp
  llvm/lib/TextAPI/MachO/ArchitectureSet.cpp
  llvm/lib/TextAPI/MachO/InterfaceFile.cpp
  llvm/lib/TextAPI/MachO/PackedVersion.cpp
  llvm/lib/TextAPI/MachO/Platform.cpp
  llvm/lib/TextAPI/MachO/Symbol.cpp
  llvm/lib/TextAPI/MachO/Target.cpp
  llvm/lib/TextAPI/MachO/TextAPIContext.h
  llvm/lib/TextAPI/MachO/TextStub.cpp
  llvm/lib/TextAPI/MachO/TextStubCommon.cpp
  llvm/lib/TextAPI/MachO/TextStubCommon.h
  llvm/lib/TextAPI/PackedVersion.cpp
  llvm/lib/TextAPI/Platform.cpp
  llvm/lib/TextAPI/Symbol.cpp
  llvm/lib/TextAPI/Target.cpp
  llvm/lib/TextAPI/TextAPIContext.h
  llvm/lib/TextAPI/TextStub.cpp
  llvm/lib/TextAPI/TextStubCommon.cpp
  llvm/lib/TextAPI/TextStubCommon.h
  llvm/tools/llvm-ifs/llvm-ifs.cpp
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
  llvm/tools/llvm-lipo/llvm-lipo.cpp
  llvm/unittests/TextAPI/TextStubHelpers.h
  llvm/unittests/TextAPI/TextStubV1Tests.cpp
  llvm/unittests/TextAPI/TextStubV2Tests.cpp
  llvm/unittests/TextAPI/TextStubV3Tests.cpp
  llvm/unittests/TextAPI/TextStubV4Tests.cpp

Index: llvm/unittests/TextAPI/TextStubV4Tests.cpp
===
--- llvm/unittests/TextAPI/TextStubV4Tests.cpp
+++ llvm/unittests/TextAPI/TextStubV4Tests.cpp
@@ -7,9 +7,9 @@
 //===---===/
 
 #include "TextStubHelpers.h"
-#include "llvm/TextAPI/MachO/InterfaceFile.h"
-#include "llvm/TextAPI/MachO/TextAPIReader.h"
-#include "llvm/TextAPI/MachO/TextAPIWriter.h"
+#include "llvm/TextAPI/InterfaceFile.h"
+#include "llvm/TextAPI/TextAPIReader.h"
+#include "llvm/TextAPI/TextAPIWriter.h"
 #include "gtest/gtest.h"
 #include 
 #include 
Index: llvm/unittests/TextAPI/TextStubV3Tests.cpp
===
--- llvm/unittests/TextAPI/TextStubV3Tests.cpp
+++ llvm/unittests/TextAPI/TextStubV3Tests.cpp
@@ -6,9 +6,9 @@
 //
 //===---===/
 #include "TextStubHelpers.h"
-#include "llvm/TextAPI/MachO/InterfaceFile.h"
-#include "llvm/TextAPI/MachO/TextAPIReader.h"
-#include "llvm/TextAPI/MachO/TextAPIWriter.h"
+#include "llvm/TextAPI/InterfaceFile.h"
+#include "llvm/TextAPI/TextAPIReader.h"
+#include "llvm/TextAPI/TextAPIWriter.h"
 #include "gtest/gtest.h"
 #include 
 #include 
Index: llvm/unittests/TextAPI/TextStubV2Tests.cpp
===
--- llvm/unittests/TextAPI/TextStubV2Tests.cpp
+++ llvm/unittests/TextAPI/TextStubV2Tests.cpp
@@ -6,9 +6,9 @@
 //
 //===---===/
 #include "TextStubHelpers.h"
-#include "llvm/TextAPI/MachO/InterfaceFile.h"
-#include "llvm/TextAPI/MachO/TextAPIReader.h"
-#include "llvm/TextAPI/MachO/TextAPIWriter.h"
+#include "llvm/TextAPI/InterfaceFile.h"
+#include "llvm/TextAPI/TextAPIReader.h"
+#include "llvm/TextAPI/TextAPIWriter.h"
 #include "gtest/gtest.h"
 #include 
 #include 
Index: llvm/unittests/TextAPI/TextStubV1Tests.cpp
===

[clang] 0116d04 - [TextAPI] move source code files out of subdirectory, NFC

2021-04-05 Thread Cyndy Ishida via cfe-commits

Author: Cyndy Ishida
Date: 2021-04-05T10:24:42-07:00
New Revision: 0116d04d04f20e9ae62ba847075840c3cb298080

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

LOG: [TextAPI] move source code files out of subdirectory, NFC

TextAPI/ELF has moved out into InterfaceStubs, so theres no longer a
need to seperate out TextAPI between formats.

Reviewed By: ributzka, int3, #lld-macho

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

Added: 
llvm/include/llvm/TextAPI/Architecture.def
llvm/include/llvm/TextAPI/Architecture.h
llvm/include/llvm/TextAPI/ArchitectureSet.h
llvm/include/llvm/TextAPI/InterfaceFile.h
llvm/include/llvm/TextAPI/PackedVersion.h
llvm/include/llvm/TextAPI/Platform.h
llvm/include/llvm/TextAPI/Symbol.h
llvm/include/llvm/TextAPI/Target.h
llvm/include/llvm/TextAPI/TextAPIReader.h
llvm/include/llvm/TextAPI/TextAPIWriter.h
llvm/lib/TextAPI/Architecture.cpp
llvm/lib/TextAPI/ArchitectureSet.cpp
llvm/lib/TextAPI/InterfaceFile.cpp
llvm/lib/TextAPI/PackedVersion.cpp
llvm/lib/TextAPI/Platform.cpp
llvm/lib/TextAPI/Symbol.cpp
llvm/lib/TextAPI/Target.cpp
llvm/lib/TextAPI/TextAPIContext.h
llvm/lib/TextAPI/TextStub.cpp
llvm/lib/TextAPI/TextStubCommon.cpp
llvm/lib/TextAPI/TextStubCommon.h

Modified: 
clang/docs/ClangFormattedStatus.rst
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/DriverUtils.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
lld/lib/ReaderWriter/MachO/File.h
llvm/include/llvm/Object/TapiFile.h
llvm/include/llvm/Object/TapiUniversal.h
llvm/lib/Object/TapiUniversal.cpp
llvm/lib/TextAPI/CMakeLists.txt
llvm/tools/llvm-ifs/llvm-ifs.cpp
llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
llvm/tools/llvm-lipo/llvm-lipo.cpp
llvm/unittests/TextAPI/TextStubHelpers.h
llvm/unittests/TextAPI/TextStubV1Tests.cpp
llvm/unittests/TextAPI/TextStubV2Tests.cpp
llvm/unittests/TextAPI/TextStubV3Tests.cpp
llvm/unittests/TextAPI/TextStubV4Tests.cpp

Removed: 
llvm/include/llvm/TextAPI/MachO/Architecture.def
llvm/include/llvm/TextAPI/MachO/Architecture.h
llvm/include/llvm/TextAPI/MachO/ArchitectureSet.h
llvm/include/llvm/TextAPI/MachO/InterfaceFile.h
llvm/include/llvm/TextAPI/MachO/PackedVersion.h
llvm/include/llvm/TextAPI/MachO/Platform.h
llvm/include/llvm/TextAPI/MachO/Symbol.h
llvm/include/llvm/TextAPI/MachO/Target.h
llvm/include/llvm/TextAPI/MachO/TextAPIReader.h
llvm/include/llvm/TextAPI/MachO/TextAPIWriter.h
llvm/lib/TextAPI/MachO/Architecture.cpp
llvm/lib/TextAPI/MachO/ArchitectureSet.cpp
llvm/lib/TextAPI/MachO/InterfaceFile.cpp
llvm/lib/TextAPI/MachO/PackedVersion.cpp
llvm/lib/TextAPI/MachO/Platform.cpp
llvm/lib/TextAPI/MachO/Symbol.cpp
llvm/lib/TextAPI/MachO/Target.cpp
llvm/lib/TextAPI/MachO/TextAPIContext.h
llvm/lib/TextAPI/MachO/TextStub.cpp
llvm/lib/TextAPI/MachO/TextStubCommon.cpp
llvm/lib/TextAPI/MachO/TextStubCommon.h



diff  --git a/clang/docs/ClangFormattedStatus.rst 
b/clang/docs/ClangFormattedStatus.rst
index 108351c169313..a936a8fd727d8 100644
--- a/clang/docs/ClangFormattedStatus.rst
+++ b/clang/docs/ClangFormattedStatus.rst
@@ -3854,7 +3854,7 @@ tree in terms of conformance to :doc:`ClangFormat` as of: 
December 04, 2020 17:5
  - `2`
  - `1`
  - :part:`66%`
-   * - llvm/include/llvm/TextAPI/MachO
+   * - llvm/include/llvm/TextAPI
  - `9`
  - `8`
  - `1`
@@ -4749,7 +4749,7 @@ tree in terms of conformance to :doc:`ClangFormat` as of: 
December 04, 2020 17:5
  - `3`
  - `0`
  - :good:`100%`
-   * - llvm/lib/TextAPI/MachO
+   * - llvm/lib/TextAPI
  - `11`
  - `8`
  - `3`

diff  --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index c629c842a1944..5c9faa8c7328a 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -16,9 +16,9 @@
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Support/GlobPattern.h"
 #include "llvm/Support/VersionTuple.h"
-#include "llvm/TextAPI/MachO/Architecture.h"
-#include "llvm/TextAPI/MachO/Platform.h"
-#include "llvm/TextAPI/MachO/Target.h"
+#include "llvm/TextAPI/Architecture.h"
+#include "llvm/TextAPI/Platform.h"
+#include "llvm/TextAPI/Target.h"
 
 #include 
 

diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index d0666d6ea3df9..2a65c44f5433f 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -43,7 +43,7 @@
 #include "llvm/Support/TarWriter.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TimeProfiler.h"
-#include "llvm/TextAPI/MachO/PackedVersion.h"
+#include "llvm/TextAPI/PackedVersion.h"
 
 #include 
 

diff  --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index fe1585fab42b9..064a509f47c8f 

[PATCH] D69726: [analyzer] DynamicSize: Store the dynamic size

2021-04-05 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Cool, thanks!

Debug facility NFC: 
https://reviews.llvm.org/rG89d210fe1a7a1c6cbf926df0595b6f107bc491d5
`size` -> `extent` conversion: 
https://reviews.llvm.org/rG9b3df78b4c2ab7a7063e532165492e1ffa38d401




Comment at: clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp:294
+
+  SmallString<128> Msg;
+  llvm::raw_svector_ostream Out(Msg);

NoQ wrote:
> 128 is too much imho :)
I am totally fine with 128, but let us use 64 then:
https://developer.apple.com/documentation/authenticationservices/asauthorizationcontrollerpresentationcontextproviding


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69726

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


[clang] 9b3df78 - [analyzer] DynamicSize: Rename 'size' to 'extent'

2021-04-05 Thread via cfe-commits

Author: Charusso
Date: 2021-04-05T19:20:43+02:00
New Revision: 9b3df78b4c2ab7a7063e532165492e1ffa38d401

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

LOG: [analyzer] DynamicSize: Rename 'size' to 'extent'

Added: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h
clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/CheckPlacementNew.cpp
clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
clang/lib/StaticAnalyzer/Core/CMakeLists.txt
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/lib/StaticAnalyzer/Core/MemRegion.cpp
clang/lib/StaticAnalyzer/Core/RegionStore.cpp

Removed: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
clang/lib/StaticAnalyzer/Core/DynamicSize.cpp



diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h
new file mode 100644
index ..cfd7aa9664b6
--- /dev/null
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h
@@ -0,0 +1,59 @@
+//===- DynamicExtent.h - Dynamic extent related APIs *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines APIs that track and query dynamic extent information.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICEXTENT_H
+#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICEXTENT_H
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
+
+namespace clang {
+namespace ento {
+
+/// \returns The stored dynamic extent for the region \p MR.
+DefinedOrUnknownSVal getDynamicExtent(ProgramStateRef State,
+  const MemRegion *MR, SValBuilder );
+
+/// \returns The element extent of the type \p Ty.
+DefinedOrUnknownSVal getElementExtent(QualType Ty, SValBuilder );
+
+/// \returns The stored element count of the region \p MR.
+DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State,
+const MemRegion *MR,
+SValBuilder , QualType Ty);
+
+/// Set the dynamic extent \p Extent of the region \p MR.
+ProgramStateRef setDynamicExtent(ProgramStateRef State, const MemRegion *MR,
+ DefinedOrUnknownSVal Extent, SValBuilder 
);
+
+/// Get the dynamic extent for a symbolic value that represents a buffer. If
+/// there is an offsetting to the underlying buffer we consider that too.
+/// Returns with an SVal that represents the extent, this is Unknown if the
+/// engine cannot deduce the extent.
+/// E.g.
+///   char buf[3];
+///   (buf); // extent is 3
+///   (buf + 1); // extent is 2
+///   (buf + 3); // extent is 0
+///   (buf + 4); // extent is -1
+///
+///   char *bufptr;
+///   (bufptr) // extent is unknown
+SVal getDynamicExtentWithOffset(ProgramStateRef State, SVal BufV);
+
+} // namespace ento
+} // namespace clang
+
+#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICEXTENT_H

diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
deleted file mode 100644
index bad6a19cb9ff..
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
+++ /dev/null
@@ -1,59 +0,0 @@
-//===- DynamicSize.h - Dynamic size related APIs *- C++ 

[clang] 89d210f - [analyzer] DynamicSize: Debug facility

2021-04-05 Thread via cfe-commits

Author: Charusso
Date: 2021-04-05T19:17:52+02:00
New Revision: 89d210fe1a7a1c6cbf926df0595b6f107bc491d5

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

LOG: [analyzer] DynamicSize: Debug facility

This patch adds two debug functions to ExprInspectionChecker to dump out
the dynamic extent and element count of symbolic values:
dumpExtent(), dumpElementCount().

Added: 
clang/test/Analysis/memory-model.cpp

Modified: 
clang/docs/analyzer/developer-docs/DebugChecks.rst
clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
clang/test/Analysis/expr-inspection.cpp

Removed: 




diff  --git a/clang/docs/analyzer/developer-docs/DebugChecks.rst 
b/clang/docs/analyzer/developer-docs/DebugChecks.rst
index 45985a1dfd79..29ab6c89488f 100644
--- a/clang/docs/analyzer/developer-docs/DebugChecks.rst
+++ b/clang/docs/analyzer/developer-docs/DebugChecks.rst
@@ -297,6 +297,19 @@ ExprInspection checks
   return n;
 }
 
+- ``clang_analyzer_dumpExtent(a single argument of any type)``
+- ``clang_analyzer_dumpElementCount(a single argument of any type)``
+
+  Dumps out the extent and the element count of the argument.
+
+  Example usage::
+
+void array() {
+  int a[] = {1, 3};
+  clang_analyzer_dumpExtent(a);   // expected-warning {{8 S64b}}
+  clang_analyzer_dumpElementCount(a); // expected-warning {{2 S64b}}
+}
+
 Statistics
 ==
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index c0167b53ae26..242815d937df 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -22,8 +22,8 @@ using namespace clang;
 using namespace ento;
 
 namespace {
-class ExprInspectionChecker : public Checker {
+class ExprInspectionChecker
+: public Checker {
   mutable std::unique_ptr BT;
 
   // These stats are per-analysis, not per-branch, hence they shouldn't
@@ -44,6 +44,8 @@ class ExprInspectionChecker : public Checker ExprVal = None) const;
-  ExplodedNode *reportBug(llvm::StringRef Msg, BugReporter ,
-  ExplodedNode *N,
+  ExplodedNode *reportBug(llvm::StringRef Msg, BugReporter , ExplodedNode 
*N,
   Optional ExprVal = None) const;
 
+  const Expr *getArgExpr(const CallExpr *CE, CheckerContext ) const;
+  const MemRegion *getArgRegion(const CallExpr *CE, CheckerContext ) const;
+
 public:
   bool evalCall(const CallEvent , CheckerContext ) const;
   void checkDeadSymbols(SymbolReaper , CheckerContext ) const;
   void checkEndAnalysis(ExplodedGraph , BugReporter ,
 ExprEngine ) const;
 };
-}
+} // namespace
 
 REGISTER_SET_WITH_PROGRAMSTATE(MarkedSymbols, SymbolRef)
 REGISTER_MAP_WITH_PROGRAMSTATE(DenotedSymbols, SymbolRef, const StringLiteral 
*)
@@ -90,6 +94,10 @@ bool ExprInspectionChecker::evalCall(const CallEvent ,
 ::analyzerWarnOnDeadSymbol)
   .StartsWith("clang_analyzer_explain",
   ::analyzerExplain)
+  .Case("clang_analyzer_dumpExtent",
+::analyzerDumpExtent)
+  .Case("clang_analyzer_dumpElementCount",
+::analyzerDumpElementCount)
   .StartsWith("clang_analyzer_dump",
   ::analyzerDump)
   .Case("clang_analyzer_getExtent",
@@ -131,7 +139,7 @@ static const char *getArgumentValueString(const CallExpr 
*CE,
 
   ProgramStateRef StTrue, StFalse;
   std::tie(StTrue, StFalse) =
-State->assume(AssertionVal.castAs());
+  State->assume(AssertionVal.castAs());
 
   if (StTrue) {
 if (StFalse)
@@ -155,8 +163,7 @@ ExplodedNode 
*ExprInspectionChecker::reportBug(llvm::StringRef Msg,
 }
 
 ExplodedNode *ExprInspectionChecker::reportBug(llvm::StringRef Msg,
-   BugReporter ,
-   ExplodedNode *N,
+   BugReporter , ExplodedNode 
*N,
Optional ExprVal) const {
   if (!N)
 return nullptr;
@@ -172,6 +179,30 @@ ExplodedNode 
*ExprInspectionChecker::reportBug(llvm::StringRef Msg,
   return N;
 }
 
+const Expr *ExprInspectionChecker::getArgExpr(const CallExpr *CE,
+  CheckerContext ) const {
+  if (CE->getNumArgs() == 0) {
+reportBug("Missing argument", C);
+return nullptr;
+  }
+  return CE->getArg(0);
+}
+
+const MemRegion *ExprInspectionChecker::getArgRegion(const CallExpr *CE,
+ CheckerContext ) const {
+  const Expr *Arg = getArgExpr(CE, C);
+  if (!Arg)
+return nullptr;
+
+  const MemRegion *MR = 

[PATCH] D69726: [analyzer] DynamicSize: Store the dynamic size

2021-04-05 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Charusso marked an inline comment as done.
Closed by commit rGdf64f471d1e2: [analyzer] DynamicSize: Store the dynamic size 
(authored by Charusso).

Changed prior to commit:
  https://reviews.llvm.org/D69726?vs=319940=335284#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69726

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
  clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/explain-svals.cpp

Index: clang/test/Analysis/explain-svals.cpp
===
--- clang/test/Analysis/explain-svals.cpp
+++ clang/test/Analysis/explain-svals.cpp
@@ -54,7 +54,7 @@
   int *x = new int[ext];
   clang_analyzer_explain(x); // expected-warning-re^pointer to element of type 'int' with index 0 of heap segment that starts at symbol of type 'int \*' conjured at statement 'new int \[ext\]'$
   // Sic! What gets computed is the extent of the element-region.
-  clang_analyzer_explain(clang_analyzer_getExtent(x)); // expected-warning-re^signed 32-bit integer '4'$
+  clang_analyzer_explain(clang_analyzer_getExtent(x)); // expected-warning-re^\(argument 'ext'\) \* 4$
   delete[] x;
 }
 
Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -28,6 +28,7 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
@@ -729,13 +730,6 @@
 // MemRegionManager methods.
 //===--===//
 
-static DefinedOrUnknownSVal getTypeSize(QualType Ty, ASTContext ,
-  SValBuilder ) {
-  CharUnits Size = Ctx.getTypeSizeInChars(Ty);
-  QualType SizeTy = SVB.getArrayIndexType();
-  return SVB.makeIntVal(Size.getQuantity(), SizeTy);
-}
-
 DefinedOrUnknownSVal MemRegionManager::getStaticSize(const MemRegion *MR,
  SValBuilder ) const {
   const auto *SR = cast(MR);
@@ -766,7 +760,7 @@
 if (Ty->isIncompleteType())
   return UnknownVal();
 
-return getTypeSize(Ty, Ctx, SVB);
+return getElementSize(Ty, SVB);
   }
   case MemRegion::FieldRegionKind: {
 // Force callers to deal with bitfields explicitly.
@@ -774,7 +768,7 @@
   return UnknownVal();
 
 QualType Ty = cast(SR)->getDesugaredValueType(Ctx);
-DefinedOrUnknownSVal Size = getTypeSize(Ty, Ctx, SVB);
+DefinedOrUnknownSVal Size = getElementSize(Ty, SVB);
 
 // A zero-length array at the end of a struct often stands for dynamically
 // allocated extra memory.
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -18,6 +18,7 @@
 #include "clang/Analysis/ConstructionContext.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/Statistic.h"
@@ -689,16 +690,30 @@
 
 // See if we need to conjure a heap pointer instead of
 // a regular unknown pointer.
-bool IsHeapPointer = false;
-if (const auto *CNE = dyn_cast(E))
-  if (CNE->getOperatorNew()->isReplaceableGlobalAllocationFunction()) {
-// FIXME: Delegate this to evalCall in MallocChecker?
-IsHeapPointer = true;
+const auto *CNE = dyn_cast(E);
+if (CNE && CNE->getOperatorNew()->isReplaceableGlobalAllocationFunction()) {
+  R = svalBuilder.getConjuredHeapSymbolVal(E, LCtx, Count);
+  const MemRegion *MR = R.getAsRegion()->StripCasts();
+
+  // Store the extent of the allocated object(s).
+  SVal ElementCount;
+  if (const Expr *SizeExpr = CNE->getArraySize().getValueOr(nullptr)) {
+ElementCount = State->getSVal(SizeExpr, LCtx);
+  } else {
+ElementCount = svalBuilder.makeIntVal(1, /*IsUnsigned=*/true);
   

[clang] df64f47 - [analyzer] DynamicSize: Store the dynamic size

2021-04-05 Thread via cfe-commits

Author: Charusso
Date: 2021-04-05T19:04:53+02:00
New Revision: df64f471d1e26fc1e9e2f9cdcfc77c063fe55b56

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

LOG: [analyzer] DynamicSize: Store the dynamic size

This patch introduces a way to store the size.

Reviewed By: NoQ

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/lib/StaticAnalyzer/Core/MemRegion.cpp
clang/test/Analysis/explain-svals.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
index 398f9b6ac33a..bad6a19cb9ff 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
@@ -22,15 +22,21 @@
 namespace clang {
 namespace ento {
 
-/// Get the stored dynamic size for the region \p MR.
+/// \returns The stored dynamic size for the region \p MR.
 DefinedOrUnknownSVal getDynamicSize(ProgramStateRef State, const MemRegion *MR,
 SValBuilder );
 
-/// Get the stored element count of the region \p MR.
+/// \returns The element size of the type \p Ty.
+DefinedOrUnknownSVal getElementSize(QualType Ty, SValBuilder );
+
+/// \returns The stored element count of the region \p MR.
 DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State,
 const MemRegion *MR,
-SValBuilder ,
-QualType ElementTy);
+SValBuilder , QualType Ty);
+
+/// Set the dynamic size \p Size of the region \p MR.
+ProgramStateRef setDynamicSize(ProgramStateRef State, const MemRegion *MR,
+   DefinedOrUnknownSVal Size, SValBuilder );
 
 /// Get the dynamic size for a symbolic value that represents a buffer. If
 /// there is an offsetting to the underlying buffer we consider that too.
@@ -45,7 +51,7 @@ DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef 
State,
 ///
 ///   char *bufptr;
 ///   (bufptr) // size is unknown
-SVal getDynamicSizeWithOffset(ProgramStateRef State, const SVal );
+SVal getDynamicSizeWithOffset(ProgramStateRef State, SVal BufV);
 
 } // namespace ento
 } // namespace clang

diff  --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index 233ce57c3ac9..31f9b14f7eeb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -92,12 +92,8 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent ,
 if (Size.isUndef())
   return true; // Return true to model purity.
 
-SValBuilder& svalBuilder = C.getSValBuilder();
-DefinedOrUnknownSVal DynSize = getDynamicSize(state, R, svalBuilder);
-DefinedOrUnknownSVal DynSizeMatchesSizeArg =
-svalBuilder.evalEQ(state, DynSize, 
Size.castAs());
-state = state->assume(DynSizeMatchesSizeArg, true);
-assert(state && "The region should not have any previous constraints");
+state = setDynamicSize(state, R, Size.castAs(),
+   C.getSValBuilder());
 
 C.addTransition(state->BindExpr(CE, LCtx, loc::MemRegionVal(R)));
 return true;

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index f117d5505ecb..7eafdaa97bb4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -509,10 +509,6 @@ class MallocChecker
   ProgramStateRef State,
   AllocationFamily Family);
 
-  LLVM_NODISCARD
-  static ProgramStateRef addExtentSize(CheckerContext , const CXXNewExpr *NE,
-   ProgramStateRef State, SVal Target);
-
   // Check if this malloc() for special flags. At present that means M_ZERO or
   // __GFP_ZERO (in which case, treat it like calloc).
   LLVM_NODISCARD
@@ -1424,7 +1420,6 @@ MallocChecker::processNewAllocation(const 
CXXAllocatorCall ,
   // existing binding.
   SVal Target = Call.getObjectUnderConstruction();
   State = MallocUpdateRefState(C, NE, State, Family, Target);
-  State = 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-04-05 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 rG7416e8a8431a: [flang][driver] Add options for -Werror 
(authored by arnamoy10).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98657

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/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror_parse.f
  flang/test/Driver/werror_scan.f
  flang/test/Driver/werror_sema.f90
  flang/test/Driver/werror_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -511,8 +511,14 @@
 } else if (arg == "-fopenmp") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenMP);
   predefinitions.emplace_back("_OPENMP", "201511");
-} else if (arg == "-Werror") {
-  driver.warningsAreErrors = true;
+} else if (arg.find("-W") != std::string::npos) {
+  if (arg == "-Werror")
+driver.warningsAreErrors = true;
+  else {
+// Only -Werror is supported currently
+llvm::errs() << "Only `-Werror` is supported currently.\n";
+return EXIT_FAILURE;
+  }
 } else if (arg == "-ed") {
   options.features.Enable(Fortran::common::LanguageFeature::OldDebugLines);
 } else if (arg == "-E") {
Index: flang/test/Driver/werror_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/werror_wrong.f90
@@ -0,0 +1,9 @@
+! Ensure that only argument -Werror is supported.
+
+! RUN: not %flang_fc1 -fsyntax-only -Wall %s  2>&1 | FileCheck %s --check-prefix=WRONG
+! RUN: not %flang_fc1 -fsyntax-only -WX %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH -W
+!-
+! WRONG: Only `-Werror` is supported currently.
Index: flang/test/Driver/werror_sema.f90
===
--- /dev/null
+++ flang/test/Driver/werror_sema.f90
@@ -0,0 +1,31 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAndSemaAction, particularly for Semantic warnings/errors.
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+
+
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/werror_scan.f
===
--- /dev/null
+++ flang/test/Driver/werror_scan.f
@@ -0,0 +1,25 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAction
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -E -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-parsing-log -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-provenance -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not 

[clang] 7416e8a - [flang][driver] Add options for -Werror

2021-04-05 Thread Arnamoy Bhattacharyya via cfe-commits

Author: Arnamoy Bhattacharyya
Date: 2021-04-05T12:47:52-04:00
New Revision: 7416e8a8431a0f2711be9d16e111d1781b74df96

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

LOG: [flang][driver] Add options for -Werror

With the option given, warnings are treated as error.

Reviewed By: awarzynski

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

Added: 
flang/test/Driver/werror_parse.f
flang/test/Driver/werror_scan.f
flang/test/Driver/werror_sema.f90
flang/test/Driver/werror_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/lib/Frontend/FrontendActions.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 64d658b2bfd9..38977cc0b874 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -746,7 +746,7 @@ def Wundef_prefix_EQ : CommaJoined<["-"], 
"Wundef-prefix=">, Group>;
 def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
-def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, 
CoreOption]>,
+def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, 
CoreOption, FC1Option, FlangOption]>,
   MetaVarName<"">, HelpText<"Enable the specified warning">;
 def Xanalyzer : Separate<["-"], "Xanalyzer">,
   HelpText<"Pass  to the static analyzer">, MetaVarName<"">,

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index bf2a19e7c54a..73dbeacf2563 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -44,7 +44,7 @@ void Flang::AddOtherOptions(const ArgList , 
ArgStringList ) const {
   Args.AddAllArgs(CmdArgs,
   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
-   options::OPT_std_EQ});
+   options::OPT_std_EQ, options::OPT_W_Joined});
 }
 
 void Flang::ConstructJob(Compilation , const JobAction ,

diff  --git a/flang/include/flang/Frontend/CompilerInvocation.h 
b/flang/include/flang/Frontend/CompilerInvocation.h
index 99050dcdbd7b..529f15e3c886 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -71,6 +71,8 @@ class CompilerInvocation : public CompilerInvocationBase {
 
   bool debugModuleDir_ = false;
 
+  bool warnAsErr_ = false;
+
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
@@ -98,6 +100,9 @@ class CompilerInvocation : public CompilerInvocationBase {
   bool () { return debugModuleDir_; }
   const bool () const { return debugModuleDir_; }
 
+  bool () { return warnAsErr_; }
+  const bool () const { return warnAsErr_; }
+
   bool () { return EnableConformanceChecks_; }
   const bool () const {
 return EnableConformanceChecks_;
@@ -126,6 +131,8 @@ class CompilerInvocation : public CompilerInvocationBase {
 
   void SetDebugModuleDir(bool flag) { debugModuleDir_ = flag; }
 
+  void SetWarnAsErr(bool flag) { warnAsErr_ = flag; }
+
   /// Set the Fortran options to predifined defaults. These defaults are
   /// consistend with f18/f18.cpp.
   // TODO: We should map frontendOpts_ to parserOpts_ instead. For that, we

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 3bd541e40c0f..ce7392cf3d76 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -350,6 +350,26 @@ static void parseSemaArgs(CompilerInvocation , 
llvm::opt::ArgList ,
   }
 }
 
+/// Parses all diagnostics related arguments and populates the variables
+/// options accordingly.
+static void parseDiagArgs(CompilerInvocation , llvm::opt::ArgList ,
+clang::DiagnosticsEngine ) {
+  // -Werror option
+  // TODO: Currently throws a Diagnostic for anything other than -W,
+  // this has to change when other -W's are supported.
+  if (args.hasArg(clang::driver::options::OPT_W_Joined)) {
+if (args.getLastArgValue(clang::driver::options::OPT_W_Joined)
+.equals("error")) {
+  res.SetWarnAsErr(true);
+} else {
+  const unsigned diagID =
+  diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+  "Only `-Werror` is supported currently.");
+  diags.Report(diagID);
+}
+  }
+}
+
 /// Parses all Dialect 

[PATCH] D99601: [-Wcompletion-handler] Don't recognize init methods as conventional

2021-04-05 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/CalledOnceCheck.cpp:1017
+  static bool isInitMethod(Selector MethodSelector) {
+return MethodSelector.getNameForSlot(0).startswith_lower(INIT_PREFIX);
+  }

You can formally check whether it's an init method by querying its 
`ObjCMethodFamily`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99601

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


[PATCH] D99181: [analyzer] Fix crash on spaceship operator (PR47511)

2021-04-05 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp:169-171
+  } else if (B->getOpcode() == BinaryOperatorKind::BO_Cmp) {
+// We can't reason about C++20 spaceship operator yet.
+return;

steakhal wrote:
> What a madness, we deal with every binary operator kind here O.O
> 
> Why do we get Undefined here? If we don't model something - theoretically - 
> we should get Unknown.
> I'm confused.
Yes we should get `Unknown`. We should only return `Undefined` when there's 
undefined behavior in the program. Sounds like returning `nullptr` from 
`BasicValueFactory` causes `SValBuilder` to produce `Undefined` instead. I 
believe this needs to be fixed in `SValBuilder` instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99181

___
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-04-05 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> It does make sense to split these in two, but I'm not so sure about 
> `evalCall`.

`evalCall` should work great for this purpose but definitely not in this 
checker. Also this checker would still exercise its `checkPostCall` so it would 
still need to be silenced even if `evalCall` is implemented.




Comment at: clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp:234
+  ObjRegion =
+  dyn_cast_or_null(Call.getArgSVal(0).getAsRegion());
 }

This will crash if someone overloads `std::data` with 0 arguments because your 
`CallDescription`s don't require a specific number of arguments. (They're not 
allowed to do that, yes, but we're still not allowed to crash.)


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] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2021-04-05 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

In D99484#2668225 , @Ericson2314 wrote:

> Additionally, I have cleaned up the `polly` code so that I need not change it
> so much, and it should still work with absolute or relative paths quite
> flexibly.

Looks fine to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

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


[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2021-04-05 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 335157.
Ericson2314 added a comment.

Don't use CMAKE_INTALL_LIBDIR or convert compiler-rt for now

These steps were suggested by @compnerd, IIUC. The compiler-rt stuff is in flux
because I am now skeptical whether `COMPILER_RT_INSTALL_PATH` can now be so
easily removed (see D99755 ).

Additionally, I have cleaned up the `polly` code so that I need not change it
so much, and it should still work with absolute or relative paths quite
flexibly. If `COMPILER_RT_INSTALL_PATH` or equivalent functionality is in fact
needed (i.e D99755  must be abandoned), I 
think the same method I am now using
for polly could also work there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

Files:
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/find-all-symbols/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/modularize/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/modules/AddClang.cmake
  clang/tools/c-index-test/CMakeLists.txt
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-rename/CMakeLists.txt
  clang/tools/libclang/CMakeLists.txt
  clang/tools/scan-build/CMakeLists.txt
  clang/tools/scan-view/CMakeLists.txt
  clang/utils/hmaptool/CMakeLists.txt
  flang/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/tools/f18/CMakeLists.txt
  flang/tools/flang-driver/CMakeLists.txt
  libc/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/cmake/Modules/HandleLibCXXABI.cmake
  libcxx/include/CMakeLists.txt
  libcxx/src/CMakeLists.txt
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/src/CMakeLists.txt
  lld/CMakeLists.txt
  lld/cmake/modules/AddLLD.cmake
  lld/tools/lld/CMakeLists.txt
  lldb/CMakeLists.txt
  lldb/cmake/modules/AddLLDB.cmake
  lldb/cmake/modules/LLDBConfig.cmake
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/AddSphinxTarget.cmake
  llvm/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/LLVMInstallSymlink.cmake
  llvm/docs/CMake.rst
  llvm/examples/Bye/CMakeLists.txt
  llvm/include/llvm/CMakeLists.txt
  llvm/tools/llvm-config/BuildVariables.inc.in
  llvm/tools/llvm-config/llvm-config.cpp
  llvm/tools/lto/CMakeLists.txt
  llvm/tools/opt-viewer/CMakeLists.txt
  llvm/tools/remarks-shlib/CMakeLists.txt
  mlir/CMakeLists.txt
  mlir/cmake/modules/AddMLIR.cmake
  openmp/CMakeLists.txt
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/plugins/ve/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/multiplex/CMakeLists.txt
  polly/CMakeLists.txt
  polly/cmake/CMakeLists.txt
  polly/lib/External/CMakeLists.txt
  pstl/CMakeLists.txt

Index: pstl/CMakeLists.txt
===
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -7,6 +7,8 @@
 #===--===##
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
 string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
@@ -81,15 +83,15 @@
 install(EXPORT ParallelSTLTargets
 FILE ParallelSTLTargets.cmake
 NAMESPACE pstl::
-DESTINATION lib/cmake/ParallelSTL)
+DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ParallelSTL)
 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake"
   "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
-DESTINATION lib/cmake/ParallelSTL)
+DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ParallelSTL)
 install(DIRECTORY include/
-DESTINATION include
+DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
 PATTERN "*.in" EXCLUDE)
 install(FILES "${PSTL_CONFIG_SITE_PATH}"
-DESTINATION include)
+DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
 
 add_custom_target(install-pstl
   COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL)
Index: polly/lib/External/CMakeLists.txt
===
--- polly/lib/External/CMakeLists.txt
+++ polly/lib/External/CMakeLists.txt
@@ -275,7 +275,7 @@
 install(DIRECTORY
   ${ISL_SOURCE_DIR}/include/
   ${ISL_BINARY_DIR}/include/
-  DESTINATION include/polly
+  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly
   FILES_MATCHING
   PATTERN "*.h"
   PATTERN "CMakeFiles" EXCLUDE
Index: polly/cmake/CMakeLists.txt

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

2021-04-05 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:294-297
+// TODO: This currently doesn't work as information about aliases is
+// lost when generating "unknown" options.
+if (auto Alias = A->getAlias())
+  ExpectedDistance = 1;

This is how we could deal with aliased options, but currently `A->getAlias()` 
always returns `nullptr`.


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] D99353: [driver] Make `clang` warn rather then error on `flang` options

2021-04-05 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 335275.
awarzynski added a comment.

Add more reviewers and remove unrelated changes (apologies for the noise!)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99353

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/flang-only-option-diags.c
  clang/test/Driver/flang-only-options.c

Index: clang/test/Driver/flang-only-options.c
===
--- /dev/null
+++ clang/test/Driver/flang-only-options.c
@@ -0,0 +1,70 @@
+// Verifies that Flang options marked as `FlangOnlyOption` are corectly recognised and warned about by Clang.
+//
+// TODO: Add aliases (once working)
+
+// RUN: %clang -fsyntax-only \
+// SKIP:  -Xflang \ This option is currently parsed by Clang as OPT_X_Flang (i.e. `-X flang` rather than `-Xflang`)
+// RUN:   -ffree-form \
+// RUN:   -ffixed-form \
+// RUN:   -module-dir \
+// RUN:   -ffixed-line-length=1 \
+// RUN:   -fopenacc \
+// RUN:   -fdefault-double-8 \
+// RUN:   -fdefault-integer-8 \
+// RUN:   -fdefault-real-8 \
+// RUN:   -flarge-sizes \
+// RUN:   -fbackslash \
+// RUN:   -fno-backslash \
+// RUN:   -fxor-operator \
+// RUN:   -fno-xor-operator \
+// RUN:   -flogical-abbreviations \
+// RUN:   -fno-logical-abbreviations \
+// RUN:   -fimplicit-none \
+// RUN:   -fno-implicit-none \
+// RUN:   -falternative-parameter-statement \
+// RUN:   -fintrinsic-modules-path \
+// RUN:   -test-io \
+// RUN:   -fdebug-unparse \
+// RUN:   -fdebug-unparse-with-symbols \
+// RUN:   -fdebug-dump-symbols \
+// RUN:   -fdebug-dump-parse-tree \
+// RUN:   -fdebug-dump-provenance \
+// RUN:   -fdebug-dump-parsing-log \
+// RUN:   -fdebug-measure-parse-tree \
+// RUN:   -fdebug-pre-fir-tree \
+// RUN:   -fdebug-module-writer \
+// RUN:   -fget-symbols-sources \
+// RUN: %s 2>&1 | FileCheck %s
+
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-ffree-form' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-ffixed-form' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-module-dir' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-ffixed-line-length=1' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fopenacc' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fdefault-double-8' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fdefault-integer-8' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fdefault-real-8' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-flarge-sizes' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fbackslash' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fno-backslash' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fxor-operator' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fno-xor-operator' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-flogical-abbreviations' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fno-logical-abbreviations' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fimplicit-none' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fno-implicit-none' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-falternative-parameter-statement' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fintrinsic-modules-path' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-test-io' is only valid in Flang mode (i.e. for Fortran input) 

[PATCH] D99683: [HIP] Support ThinLTO

2021-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D99683#2669080 , @tejohnson wrote:

> In D99683#2669047 , @yaxunl wrote:
>
>> In D99683#2664674 , @tejohnson 
>> wrote:
>>
>>> I haven't looked extensively yet, but why import noinline functions? Also, 
>>> please add a patch description.
>>
>> AMDGPU backend does not support linking of object files containing external 
>> symbols, i.e. one object file calling a function defined in another object 
>> file. Therefore the LLVM module passed to AMDGPU backend needs to contain 
>> definitions of all callees, even if a callee has noinline attribute. To 
>> support backends like this, the function importer needs to be able to import 
>> functions with noinline attribute. Therefore we add an LLVM option for 
>> allowing that, which is off by default. We have comments at line 70 of 
>> HIP.cpp about this.
>
> How does a non-LTO build work, or is (full) LTO currently required? Because 
> with ThinLTO we only import functions that are externally defined but 
> referenced in the current module. Also, when ThinLTO imports functions it 
> makes them available_externally, which means they are dropped and made 
> external symbols again after inlining. So anything imported but not inlined 
> will go back to being an external symbol.

AMDGPU backend by default uses full LTO for linking. It does not support 
non-LTO linking. Currently, it inlines all functions except kernels. However we 
want to be able to be able not to inline all functions. Is it OK to add an LLVM 
option to mark imported functions as linkonce_odr so that AMDGPU backend can 
keep the definitions of the imported functions?


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

https://reviews.llvm.org/D99683

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


[PATCH] D99811: [TextAPI] move source code files out of subdirectory, NFC

2021-04-05 Thread Juergen Ributzka via Phabricator via cfe-commits
ributzka accepted this revision.
ributzka added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99811

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


[PATCH] D99848: [OPENMP51]Initial support for nocontext clause

2021-04-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99848

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


[PATCH] D99848: [OPENMP51]Initial support for nocontext clause

2021-04-05 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:14908
   llvm::MapVector Captures;
+  ValExpr = tryBuildCapture(*this, ValExpr, Captures).get();
   HelperValStmt = buildPreInits(Context, Captures);

ABataev wrote:
> This must be fixed in a separate patch
Okay I will submit separate patch for this.  Thanks. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99848

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


[PATCH] D99848: [OPENMP51]Initial support for nocontext clause

2021-04-05 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 335272.
jyu2 added a comment.

Fix formatting problem and address Alexey's comment.  Thanks Alexey for the 
review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99848

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/OpenMP/dispatch_ast_print.cpp
  clang/test/OpenMP/dispatch_messages.cpp
  clang/tools/libclang/CIndex.cpp
  flang/lib/Semantics/check-omp-structure.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td

Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===
--- llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -282,6 +282,10 @@
   let clangClass = "OMPNovariantsClause";
   let flangClass = "ScalarLogicalExpr";
 }
+def OMPC_Nocontext : Clause<"nocontext"> {
+  let clangClass = "OMPNocontextClause";
+  let flangClass = "ScalarLogicalExpr";
+}
 def OMPC_Detach : Clause<"detach"> {
   let clangClass = "OMPDetachClause";
 }
@@ -1667,7 +1671,8 @@
 VersionedClause,
 VersionedClause,
 VersionedClause,
-VersionedClause
+VersionedClause,
+VersionedClause
   ];
 }
 def OMP_Unknown : Directive<"unknown"> {
Index: flang/lib/Semantics/check-omp-structure.cpp
===
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -730,6 +730,7 @@
 CHECK_SIMPLE_CLAUSE(Init, OMPC_init)
 CHECK_SIMPLE_CLAUSE(Use, OMPC_use)
 CHECK_SIMPLE_CLAUSE(Novariants, OMPC_novariants)
+CHECK_SIMPLE_CLAUSE(Nocontext, OMPC_nocontext)
 
 CHECK_REQ_SCALAR_INT_CLAUSE(Allocator, OMPC_allocator)
 CHECK_REQ_SCALAR_INT_CLAUSE(Grainsize, OMPC_grainsize)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2295,6 +2295,10 @@
   Visitor->AddStmt(C->getCondition());
 }
 
+void OMPClauseEnqueue::VisitOMPNocontextClause(const OMPNocontextClause *C) {
+  Visitor->AddStmt(C->getCondition());
+}
+
 void OMPClauseEnqueue::VisitOMPUnifiedAddressClause(
 const OMPUnifiedAddressClause *) {}
 
Index: clang/test/OpenMP/dispatch_messages.cpp
===
--- clang/test/OpenMP/dispatch_messages.cpp
+++ clang/test/OpenMP/dispatch_messages.cpp
@@ -46,6 +46,24 @@
   // expected-error@+1 {{use of undeclared identifier 'x'}}
   #pragma omp dispatch novariants(x)
   disp_call();
+  
+  // expected-error@+1 {{expected '(' after 'nocontext'}}
+  #pragma omp dispatch nocontext
+  disp_call();
+
+  // expected-error@+3 {{expected expression}}
+  // expected-error@+2 {{expected ')'}}
+  // expected-note@+1 {{to match this '('}}
+  #pragma omp dispatch nocontext (
+  disp_call();
+
+  // expected-error@+1 {{cannot contain more than one 'nocontext' clause}}
+  #pragma omp dispatch nocontext(dnum> 4) nocontext(3)
+  disp_call();
+
+  // expected-error@+1 {{use of undeclared identifier 'x'}}
+  #pragma omp dispatch nocontext(x)
+  disp_call();
 }
 
 void testit_two() {
Index: clang/test/OpenMP/dispatch_ast_print.cpp
===
--- clang/test/OpenMP/dispatch_ast_print.cpp
+++ clang/test/OpenMP/dispatch_ast_print.cpp
@@ -51,22 +51,22 @@
 void test_one()
 {
   int aaa, bbb, var;
-  //PRINT: #pragma omp dispatch depend(in : var) nowait novariants(aaa > 5)
+  //PRINT: #pragma omp dispatch depend(in : var) nowait novariants(aaa > 5) nocontext(bbb > 5)
   //DUMP: OMPDispatchDirective
   //DUMP: OMPDependClause
   //DUMP: OMPNowaitClause
   //DUMP: OMPNovariantsClause
-  #pragma omp dispatch depend(in:var) nowait novariants(aaa > 5)
+  #pragma omp dispatch depend(in:var) nowait novariants(aaa > 5) nocontext(bbb > 5)
   foo(aaa, );
 
   int *dp = get_device_ptr();
   int dev = get_device();
-  //PRINT: #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10)
+  //PRINT: #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10) nocontext(dev > 5)
   //DUMP: OMPDispatchDirective
   //DUMP: OMPDeviceClause
   //DUMP: OMPIs_device_ptrClause
   //DUMP: OMPNovariantsClause
-  #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10)
+  #pragma omp dispatch device(dev) is_device_ptr(dp) novariants(dev > 10) nocontext(dev > 5)
   foo(aaa, dp);
 
   //PRINT: #pragma omp dispatch
Index: clang/lib/Serialization/ASTWriter.cpp

[PATCH] D99683: [HIP] Support ThinLTO

2021-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 335268.
yaxunl marked 4 inline comments as done.
yaxunl edited the summary of this revision.
yaxunl added a comment.
Herald added a subscriber: tpr.

Revise by Artem's comments. Add patch description.


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

https://reviews.llvm.org/D99683

Files:
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-options.hip
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/test/Transforms/FunctionImport/Inputs/noinline.ll
  llvm/test/Transforms/FunctionImport/noinline.ll

Index: llvm/test/Transforms/FunctionImport/noinline.ll
===
--- /dev/null
+++ llvm/test/Transforms/FunctionImport/noinline.ll
@@ -0,0 +1,23 @@
+; Do setup work for all below tests: generate bitcode and combined index
+; RUN: opt -module-summary %s -o %t.main.bc
+; RUN: opt -module-summary %p/Inputs/noinline.ll -o %t.inputs.noinline.bc
+; RUN: llvm-lto -thinlto -o %t.summary %t.main.bc %t.inputs.noinline.bc
+
+; Attempt the import now, ensure below that file containing noinline
+; is not imported by default but imported with -import-noinline.
+
+; RUN: opt -function-import -summary-file %t.summary.thinlto.bc %t.main.bc -S 2>&1 \
+; RUN:   | FileCheck -check-prefix=NOIMPORT %s
+; RUN: opt -function-import -import-noinline -summary-file %t.summary.thinlto.bc \
+; RUN:   %t.main.bc -S 2>&1 | FileCheck -check-prefix=IMPORT %s
+
+define i32 @main() #0 {
+entry:
+  %f = alloca i64, align 8
+  call void @foo(i64* %f)
+  ret i32 0
+}
+
+; NOIMPORT: declare void @foo(i64*)
+; IMPORT: define available_externally void @foo
+declare void @foo(i64*) #1
Index: llvm/test/Transforms/FunctionImport/Inputs/noinline.ll
===
--- /dev/null
+++ llvm/test/Transforms/FunctionImport/Inputs/noinline.ll
@@ -0,0 +1,8 @@
+define void @foo(i64* %v) #0 {
+entry:
+  %v.addr = alloca i64*, align 8
+  store i64* %v, i64** %v.addr, align 8
+  ret void
+}
+
+attributes #0 = { noinline }
\ No newline at end of file
Index: llvm/lib/Transforms/IPO/FunctionImport.cpp
===
--- llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -84,6 +84,10 @@
 "import-cutoff", cl::init(-1), cl::Hidden, cl::value_desc("N"),
 cl::desc("Only import first N functions if N>=0 (default -1)"));
 
+static cl::opt
+ImportNoInline("import-noinline", cl::init(false), cl::Hidden,
+   cl::desc("Import functions with noinline attribute"));
+
 static cl::opt
 ImportInstrFactor("import-instr-evolution-factor", cl::init(0.7),
   cl::Hidden, cl::value_desc("x"),
@@ -240,7 +244,7 @@
 }
 
 // Don't bother importing if we can't inline it anyway.
-if (Summary->fflags().NoInline) {
+if (Summary->fflags().NoInline && !ImportNoInline) {
   Reason = FunctionImporter::ImportFailureReason::NoInline;
   return false;
 }
Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -51,3 +51,12 @@
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=CTA %s
 // CTA: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-mconstructor-aliases"
 // CTA-NOT: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-mconstructor-aliases"
+
+// Check -foffload-lto=thin translated correctly.
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --cuda-gpu-arch=gfx906 -fgpu-rdc -foffload-lto=thin %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=THINLTO %s
+// THINLTO-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-flto-unit"
+// THINLTO: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-flto-unit"
+// THINLTO: lld{{.*}}"-plugin-opt=mcpu=gfx906" "-plugin-opt=thinlto" "-plugin-opt=-import-instr-limit=10" "-plugin-opt=-import-noinline"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -49,8 +49,8 @@
   auto  = getToolChain();
   auto  = TC.getDriver();
   assert(!Inputs.empty() && "Must have at least one input.");
-  addLTOOptions(TC, Args, LldArgs, Output, Inputs[0],
-D.getLTOMode() == LTOK_Thin);
+  bool IsThinLTO = D.getLTOMode(/*IsOffload=*/true) == LTOK_Thin;
+  addLTOOptions(TC, Args, LldArgs, Output, Inputs[0], IsThinLTO);
 
   // Extract all the -m options
   std::vector Features;
@@ -66,6 +66,14 @@
   if (!Features.empty())
 LldArgs.push_back(Args.MakeArgString(MAttrString));
 
+  // ToDo: Remove these 

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

2021-04-05 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 335270.
awarzynski added a comment.
Herald added subscribers: jansvoboda11, dang.

Refine the behaviour when using diag options and add tests

- `-Werror` will now elevate the warning generated here to an error. This is 
consistent with `gcc`. To this end I had to create a new diagnostic in 
DiagnosticDriverKinds.td.
- Added tests for the logic implemented here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99353

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/flang-only-option-diags.c
  clang/test/Driver/flang-only-options.c

Index: clang/test/Driver/flang-only-options.c
===
--- /dev/null
+++ clang/test/Driver/flang-only-options.c
@@ -0,0 +1,70 @@
+// Verifies that Flang options marked as `FlangOnlyOption` are corectly recognised and warned about by Clang.
+//
+// TODO: Add aliases (once working)
+
+// RUN: %clang -fsyntax-only \
+// SKIP:  -Xflang \ This option is currently parsed by Clang as OPT_X_Flang (i.e. `-X flang` rather than `-Xflang`)
+// RUN:   -ffree-form \
+// RUN:   -ffixed-form \
+// RUN:   -module-dir \
+// RUN:   -ffixed-line-length=1 \
+// RUN:   -fopenacc \
+// RUN:   -fdefault-double-8 \
+// RUN:   -fdefault-integer-8 \
+// RUN:   -fdefault-real-8 \
+// RUN:   -flarge-sizes \
+// RUN:   -fbackslash \
+// RUN:   -fno-backslash \
+// RUN:   -fxor-operator \
+// RUN:   -fno-xor-operator \
+// RUN:   -flogical-abbreviations \
+// RUN:   -fno-logical-abbreviations \
+// RUN:   -fimplicit-none \
+// RUN:   -fno-implicit-none \
+// RUN:   -falternative-parameter-statement \
+// RUN:   -fintrinsic-modules-path \
+// RUN:   -test-io \
+// RUN:   -fdebug-unparse \
+// RUN:   -fdebug-unparse-with-symbols \
+// RUN:   -fdebug-dump-symbols \
+// RUN:   -fdebug-dump-parse-tree \
+// RUN:   -fdebug-dump-provenance \
+// RUN:   -fdebug-dump-parsing-log \
+// RUN:   -fdebug-measure-parse-tree \
+// RUN:   -fdebug-pre-fir-tree \
+// RUN:   -fdebug-module-writer \
+// RUN:   -fget-symbols-sources \
+// RUN: %s 2>&1 | FileCheck %s
+
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-ffree-form' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-ffixed-form' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-module-dir' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-ffixed-line-length=1' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fopenacc' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fdefault-double-8' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fdefault-integer-8' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fdefault-real-8' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-flarge-sizes' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fbackslash' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fno-backslash' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fxor-operator' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fno-xor-operator' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-flogical-abbreviations' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fno-logical-abbreviations' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fimplicit-none' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-fno-implicit-none' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// CHECK: clang-{{[0-9]+}}: warning: command line option '-falternative-parameter-statement' is only valid in Flang mode (i.e. for Fortran input) [-Wunknown-argument]
+// 

[PATCH] D99683: [HIP] Support ThinLTO

2021-04-05 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D99683#2669047 , @yaxunl wrote:

> In D99683#2664674 , @tejohnson wrote:
>
>> I haven't looked extensively yet, but why import noinline functions? Also, 
>> please add a patch description.
>
> AMDGPU backend does not support linking of object files containing external 
> symbols, i.e. one object file calling a function defined in another object 
> file. Therefore the LLVM module passed to AMDGPU backend needs to contain 
> definitions of all callees, even if a callee has noinline attribute. To 
> support backends like this, the function importer needs to be able to import 
> functions with noinline attribute. Therefore we add an LLVM option for 
> allowing that, which is off by default. We have comments at line 70 of 
> HIP.cpp about this.

How does a non-LTO build work, or is (full) LTO currently required? Because 
with ThinLTO we only import functions that are externally defined but 
referenced in the current module. Also, when ThinLTO imports functions it makes 
them available_externally, which means they are dropped and made external 
symbols again after inlining. So anything imported but not inlined will go back 
to being an external symbol.


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

https://reviews.llvm.org/D99683

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


[PATCH] D98738: [clang-tidy] performance-* checks: Match AllowedTypes against qualified type names when they contain "::".

2021-04-05 Thread Felix Berger via Phabricator via cfe-commits
flx marked 2 inline comments as done.
flx added a comment.

Thanks for the comments, PTAL!




Comment at: clang-tools-extra/clang-tidy/utils/Matchers.h:79
+llvm::Regex Regex;
+bool MatchQualifiedName = false;
+  };

ymandel wrote:
> Worth a comment i think.
Done by adding comments to each match mode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98738

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


[PATCH] D98738: [clang-tidy] performance-* checks: Match AllowedTypes against qualified type names when they contain "::".

2021-04-05 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 335267.
flx marked an inline comment as done.
flx added a comment.

Create a NameMatcher class that handles matching against the best name variant
(unqualified, qualified, fully qualified) of the NamedDecl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98738

Files:
  clang-tools-extra/clang-tidy/utils/Matchers.h
  clang-tools-extra/docs/clang-tidy/checks/performance-for-range-copy.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
  
clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-value-param.rst
  
clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy-allowed-types.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy-allowed-types.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy-allowed-types.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy-allowed-types.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy %s performance-for-range-copy %t -- \
-// RUN: -config="{CheckOptions: [{key: performance-for-range-copy.AllowedTypes, value: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$'}]}" \
+// RUN: -config="{CheckOptions: [{key: performance-for-range-copy.AllowedTypes, value: '[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;qualified::Type;::fully::QualifiedType'}]}" \
 // RUN: -- -fno-delayed-template-parsing
 
 template 
@@ -63,6 +63,18 @@
 
 typedef SomeComplexTemplate NotTooComplexRef;
 
+namespace qualified {
+struct Type {
+  ~Type();
+};
+} // namespace qualified
+
+namespace fully {
+struct QualifiedType {
+  ~QualifiedType();
+};
+} // namespace fully
+
 void negativeSmartPointer() {
   for (auto P : View>()) {
 auto P2 = P;
@@ -124,3 +136,23 @@
 auto R2 = R;
   }
 }
+
+void negativeQualified() {
+  for (auto Q : View>()) {
+auto Q2 = Q;
+  }
+  using qualified::Type;
+  for (auto Q : View>()) {
+auto Q2 = Q;
+  }
+}
+
+void negativeFullyQualified() {
+  for (auto Q : View>()) {
+auto Q2 = Q;
+  }
+  using fully::QualifiedType;
+  for (auto Q : View>()) {
+auto Q2 = Q;
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-value-param.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-value-param.rst
+++ clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-value-param.rst
@@ -66,4 +66,7 @@
 
A semicolon-separated list of names of types allowed to be passed by value.
Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches every type
-   with suffix `Ref`, `ref`, `Reference` and `reference`. The default is empty.
+   with suffix `Ref`, `ref`, `Reference` and `reference`. The default is
+   empty. If a name in the list contains the sequence `::` it is matched against
+   the qualified typename (i.e. `namespace::Type`, otherwise it is matched
+   against only the type name (i.e. `Type`).
Index: clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
+++ clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
@@ -43,5 +43,7 @@
 
A semicolon-separated list of names of types allowed to be initialized by
copying. Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches
-   every type with suffix `Ref`, `ref`, `Reference` and `reference`. The
-   default is empty.
+   every type with suffix `Ref`, `ref`, `Reference` and `reference`. The default
+   is empty. If a name in the list contains the sequence `::` it is matched
+   against the qualified typename (i.e. `namespace::Type`, otherwise it is
+   matched against only the type name (i.e. `Type`).
Index: clang-tools-extra/docs/clang-tidy/checks/performance-for-range-copy.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/performance-for-range-copy.rst
+++ clang-tools-extra/docs/clang-tidy/checks/performance-for-range-copy.rst
@@ -31,4 +31,6 @@
A semicolon-separated list of names of types allowed to be copied in each
iteration. Regular expressions are accepted, e.g. `[Rr]ef(erence)?$` matches
every type with suffix `Ref`, `ref`, `Reference` and `reference`. The default
-   is empty.
+   is empty. If a name in the list contains the sequence `::` it is matched
+   against the qualified typename (i.e. `namespace::Type`, otherwise it is
+   matched against only the type name (i.e. `Type`).
Index: clang-tools-extra/clang-tidy/utils/Matchers.h
===
--- 

[PATCH] D99683: [HIP] Support ThinLTO

2021-04-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 4 inline comments as done.
yaxunl added a comment.

In D99683#2664674 , @tejohnson wrote:

> I haven't looked extensively yet, but why import noinline functions? Also, 
> please add a patch description.

AMDGPU backend does not support linking of object files containing external 
symbols, i.e. one object file calling a function defined in another object 
file. Therefore the LLVM module passed to AMDGPU backend needs to contain 
definitions of all callees, even if a callee has noinline attribute. To support 
backends like this, the function importer needs to be able to import functions 
with noinline attribute. Therefore we add an LLVM option for allowing that, 
which is off by default. We have comments at line 70 of HIP.cpp about this.

Will add a patch description.




Comment at: clang/include/clang/Driver/Options.td:1904-1907
+def foffload_lto : Flag<["-"], "foffload-lto">, Flags<[CoreOption]>, 
Group,
+  HelpText<"Enable LTO in 'full' mode for offload compilation">;
+def fno_offload_lto : Flag<["-"], "fno-offload-lto">, Flags<[CoreOption]>, 
Group,
+  HelpText<"Disable LTO mode (default) for offload compilation">;

tra wrote:
> Should it be `BoolFOption` ? 
Yes. will fix



Comment at: clang/lib/Driver/Driver.cpp:623
 
+  llvm::errs() << LTOName << '\n';
   LTOMode = llvm::StringSwitch(LTOName)

tra wrote:
> Leftover debug printout?
will remove



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4420
 
-// Device-side jobs do not support LTO.
-bool isDeviceOffloadAction = !(JA.isDeviceOffloading(Action::OFK_None) ||
-   JA.isDeviceOffloading(Action::OFK_Host));
-
-if (D.isUsingLTO() && !isDeviceOffloadAction) {
+// Device-side jobs do not support LTO, except AMDGPU
+if (IsUsingLTO && (!IsDeviceOffloadAction || Triple.isAMDGPU())) {

tra wrote:
> Nit: rephrase it as `Only AMDGPU supports device-side LTO` ?
will do



Comment at: llvm/test/Transforms/FunctionImport/noinline.ll:4
+; RUN: opt -module-summary %p/Inputs/noinline.ll -o %t2.bc
+; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
+

tra wrote:
> I'd add a meaningful suffix to the binaries we'll use to run the checks on. 
> E.g `%t3` -> `%t.lto.bc`, `%t2` -> `%t.inputs.noinline.bc`, `%t` -> 
> `%t.main.bc`.
will rename %t and %t2 as suggested. However, llvm-lto will postfix the output 
file name with .thinlto.bc, therefore I would rename %t3 -> %t.summary


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

https://reviews.llvm.org/D99683

___
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-04-05 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Hi @protze.joachim , thank you for testing this so thoroughly!

In D99353#2656215 , @protze.joachim 
wrote:

> I tested with `-Werror`:
>
>   $ flang -fopenmp test-f77.f -ffree-form -c
>   $ clang -fopenmp test-f77.o -ffree-form -lgfortran -Werror && echo $?
>   clang-13: warning: command line option ‘-ffree-form’ is only valid in Flang 
> mode (i.e. for Fortran input)
>   clang-13: error: argument unused during compilation: '-ffree-form' 
> [-Werror,-Wunused-command-line-argument]
>
> Since `-Werror` only raises the second warning, 
> `-Wno-error=unused-command-line-argument` allows to successfully compile with 
> `-Werror`.

I think that `-Werror` should also elevate the first warning to an error. This 
can be fixed by creating a definition for the diagnostic in 
clang/include/clang/Basic/DiagnosticDriverKinds.td.

> I also tested with `-ffixed-form` and `-ffixed-line-length-132`. The latter 
> doesn't work, while `-ffixed-line-length=132` works.

Tl;Dr I haven't figured yet how to make this work for options that are aliases.
**Longer version:**
This is caused by the fact that `ffixed-line-length-132` is an alias 

 for `ffixed-line-length=132`. When parsing options, the OptTable API will skip 
unknown options (e.g. options marked with `FlangOnlyOption` when in Clang mode) 
and represent them internally as OPT_UNKNOWN 
.
 This happens in Optable.cpp 
.
 Options that are "unknown" contain no information, so it's impossible to check 
their aliases (or whether they alias some other option). This is problematic as 
options/args are converted to their unaliased forms when created (see here 
).

Btw, how important are these aliases for 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] D99661: [SemaObjC] Fix a -Wbridge-cast false-positive

2021-04-05 Thread Erik Pilkington 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 rG803b79221edf: [SemaObjC] Fix a -Wbridge-cast false-positive 
(authored by erik.pilkington).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99661

Files:
  clang/lib/Sema/SemaExprObjC.cpp
  clang/test/SemaObjCXX/bridge-cast-redecl.mm


Index: clang/test/SemaObjCXX/bridge-cast-redecl.mm
===
--- /dev/null
+++ clang/test/SemaObjCXX/bridge-cast-redecl.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=gnu++17 -verify %s
+
+// expected-no-diagnostics
+
+typedef const struct __CFString * CFStringRef;
+
+extern "C" {
+  typedef const struct __attribute__((objc_bridge(NSString))) __CFString * 
CFStringRef;
+  typedef struct __attribute__((objc_bridge_mutable(NSMutableString))) 
__CFString * CFMutableStringRef;
+}
+
+@interface NSString @end
+@interface NSMutableString : NSString @end
+
+void CFStringGetLength(CFStringRef theString);
+
+int main() {
+  CFStringGetLength((__bridge CFStringRef)(NSString *)0);
+}
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -3847,9 +3847,12 @@
   QualType QT = TDNDecl->getUnderlyingType();
   if (QT->isPointerType()) {
 QT = QT->getPointeeType();
-if (const RecordType *RT = QT->getAs())
-  if (RecordDecl *RD = RT->getDecl()->getMostRecentDecl())
-return RD->getAttr();
+if (const RecordType *RT = QT->getAs()) {
+  for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
+if (auto *attr = Redecl->getAttr())
+  return attr;
+  }
+}
   }
   return nullptr;
 }


Index: clang/test/SemaObjCXX/bridge-cast-redecl.mm
===
--- /dev/null
+++ clang/test/SemaObjCXX/bridge-cast-redecl.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=gnu++17 -verify %s
+
+// expected-no-diagnostics
+
+typedef const struct __CFString * CFStringRef;
+
+extern "C" {
+  typedef const struct __attribute__((objc_bridge(NSString))) __CFString * CFStringRef;
+  typedef struct __attribute__((objc_bridge_mutable(NSMutableString))) __CFString * CFMutableStringRef;
+}
+
+@interface NSString @end
+@interface NSMutableString : NSString @end
+
+void CFStringGetLength(CFStringRef theString);
+
+int main() {
+  CFStringGetLength((__bridge CFStringRef)(NSString *)0);
+}
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -3847,9 +3847,12 @@
   QualType QT = TDNDecl->getUnderlyingType();
   if (QT->isPointerType()) {
 QT = QT->getPointeeType();
-if (const RecordType *RT = QT->getAs())
-  if (RecordDecl *RD = RT->getDecl()->getMostRecentDecl())
-return RD->getAttr();
+if (const RecordType *RT = QT->getAs()) {
+  for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
+if (auto *attr = Redecl->getAttr())
+  return attr;
+  }
+}
   }
   return nullptr;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 803b792 - [SemaObjC] Fix a -Wbridge-cast false-positive

2021-04-05 Thread Erik Pilkington via cfe-commits

Author: Erik Pilkington
Date: 2021-04-05T11:41:40-04:00
New Revision: 803b79221edfc2517e6bfc373e5f55609565b0e4

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

LOG: [SemaObjC] Fix a -Wbridge-cast false-positive

Clang used to emit a bad -Wbridge-cast diagnostic on the cast in the attached
test. This was because, after 09abecef7, struct __CFString was not added to
lookup, so the objc_bridge attribute wasn't getting duplicated onto the most
recent declaration, causing us to fail to find it in getObjCBridgeAttr. This
patch fixes this by instead walking through the redeclarations to find an
appropriate bridge attribute. rdar://72823399

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

Added: 
clang/test/SemaObjCXX/bridge-cast-redecl.mm

Modified: 
clang/lib/Sema/SemaExprObjC.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index f5456ee0711e5..71c150027cdd6 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3847,9 +3847,12 @@ static inline T *getObjCBridgeAttr(const TypedefType 
*TD) {
   QualType QT = TDNDecl->getUnderlyingType();
   if (QT->isPointerType()) {
 QT = QT->getPointeeType();
-if (const RecordType *RT = QT->getAs())
-  if (RecordDecl *RD = RT->getDecl()->getMostRecentDecl())
-return RD->getAttr();
+if (const RecordType *RT = QT->getAs()) {
+  for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
+if (auto *attr = Redecl->getAttr())
+  return attr;
+  }
+}
   }
   return nullptr;
 }

diff  --git a/clang/test/SemaObjCXX/bridge-cast-redecl.mm 
b/clang/test/SemaObjCXX/bridge-cast-redecl.mm
new file mode 100644
index 0..c640e52922938
--- /dev/null
+++ b/clang/test/SemaObjCXX/bridge-cast-redecl.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -std=gnu++17 -verify %s
+
+// expected-no-diagnostics
+
+typedef const struct __CFString * CFStringRef;
+
+extern "C" {
+  typedef const struct __attribute__((objc_bridge(NSString))) __CFString * 
CFStringRef;
+  typedef struct __attribute__((objc_bridge_mutable(NSMutableString))) 
__CFString * CFMutableStringRef;
+}
+
+@interface NSString @end
+@interface NSMutableString : NSString @end
+
+void CFStringGetLength(CFStringRef theString);
+
+int main() {
+  CFStringGetLength((__bridge CFStringRef)(NSString *)0);
+}



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


[PATCH] D99160: [X86][FastISEL] Support DW_TAG_call_site_parameter with FastISEL

2021-04-05 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added a comment.

I think that the Debug Entry Values feature should not be enabled by default 
for non optimized code, so the `TargetOptions::ShouldEmitDebugEntryValues()` 
should be patched with checking of optimization level (it should be > 0).


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

https://reviews.llvm.org/D99160

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


[PATCH] D99199: Make -fcrash-diagnostics-dir control the Windows (mini-)dump location

2021-04-05 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Ping.


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

https://reviews.llvm.org/D99199

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


[PATCH] D98657: [flang][driver] Add options for -Werror

2021-04-05 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski accepted this revision.
awarzynski added a comment.
This revision is now accepted and ready to land.

LGTM, thank you for addressing my comments!


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

https://reviews.llvm.org/D98657

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


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

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



Comment at: clang/lib/Sema/SemaStmt.cpp:561-568
+  for (const auto *A : Attrs) {
+if (A->getKind() == attr::MustTail) {
+  if (!checkMustTailAttr(SubStmt, *A)) {
+return SubStmt;
+  }
+  setFunctionHasMustTail();
+}

haberman wrote:
> aaron.ballman wrote:
> > haberman wrote:
> > > haberman wrote:
> > > > aaron.ballman wrote:
> > > > > haberman wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > This functionality belongs in SemaStmtAttr.cpp, I think.
> > > > > > That is where I had originally put it, but that didn't work for 
> > > > > > templates. The semantic checks can only be performed at 
> > > > > > instantiation time. `ActOnAttributedStmt` seems to be the right 
> > > > > > hook point where I can evaluate the semantic checks for both 
> > > > > > template and non-template functions (with template functions 
> > > > > > getting checked at instantiation time).
> > > > > I disagree that `ActOnAttributedStmt()` is the correct place for this 
> > > > > checking -- template checking should occur when the template is 
> > > > > instantiated, same as happens for declaration attributes. I'd like to 
> > > > > see this functionality moved to SemaStmtAttr.cpp. Keeping the 
> > > > > attribute logic together and following the same patterns is what 
> > > > > allows us to tablegenerate more of the attribute logic. Statement 
> > > > > attributes are just starting to get more such automation.
> > > > I tried commenting out this code and adding the following code into 
> > > > `handleMustTailAttr()` in `SemaStmtAttr.cpp`:
> > > > 
> > > > ```
> > > >   if (!S.checkMustTailAttr(St, MTA))
> > > > return nullptr;
> > > > ```
> > > > 
> > > > This caused my test cases related to templates to fail. It also seemed 
> > > > to break test cases related to `JumpDiagnostics`. My interpretation of 
> > > > this is that `handleMustTailAttr()` is called during parsing only, and 
> > > > cannot catch errors at template instantiation time or that require a 
> > > > more complete AST.
> > > > 
> > > > What am I missing? Where in SemaStmtAttr.cpp are you suggesting that I 
> > > > put this check?
> > > Scratch the part about `JumpDiagnostics`, that was me failing to call 
> > > `S.setFunctionHasMustTail()`. I added that and now the `JumpDiagnostics` 
> > > tests pass.
> > > 
> > > But the template test cases still fail, and I can't find any hook point 
> > > in `SemaStmtAttr.cpp` that will let me evaluate these checks at template 
> > > instantiation time.
> > I think there's a bit of an architectural mixup, but I'm curious if @rsmith 
> > agrees before anyone starts doing work to make changes.
> > 
> > When transforming declarations, `RebuildWhatever()` calls the 
> > `ActOnWhatever()` function which calls `ProcessDeclAttributeList()` so that 
> > attributes are processed. `RebuildAttributedStmt()` similarly calls 
> > `ActOnAttributedStmt()`. However, `ActOnAttributedStmt()` doesn't call 
> > `ProcessStmtAttributes()` -- the logic is reversed so that 
> > `ProcessStmtAttributes()` is what calls `ActOnAttributedStmt()`.
> > 
> > I think the correct answer is to switch the logic so that 
> > `ActOnAttributedStmt()` calls `ProcessStmtAttributes()`, then the template 
> > logic should automatically work.
> > I think the correct answer is to switch the logic so that 
> > ActOnAttributedStmt() calls ProcessStmtAttributes()
> 
> I think this would require `ProcessStmtAttributes()` to be split into two 
> separate functions. Currently that function is doing two separate things:
> 
> 1. Translation of `ParsedAttr` into various subclasses of `Attr`.
> 2. Validation that the attribute is semantically valid.
> 
> The function signature for `ActOnAttributedStmt()` uses `Attr` (not 
> `ParsedAttr`), so (1) must happen during the parse, before 
> `ActOnAttributedStmt()` is called. But (2) must be deferred until template 
> instantiation time for some cases, like `musttail`.
I don't think the signature for `ActOnAttributedStmt()` is correct to use 
`Attr` instead of `ParsedAttr`. I think it should be `StmtResult 
ActOnAttributedStmt(const ParsedAttributesViewWithRange , Stmt 
*SubStmt);` -- this likely requires a fair bit of surgery to make work though, 
which is why I'd like to hear from @rsmith if he agrees with the approach. In 
the meantime, I'll play around with this idea locally in more depth.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517

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


[PATCH] D98657: [flang][driver] Add options for -Werror

2021-04-05 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 335255.
arnamoy10 added a comment.

Adding newline at the end of a test case.


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

https://reviews.llvm.org/D98657

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/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror_parse.f
  flang/test/Driver/werror_scan.f
  flang/test/Driver/werror_sema.f90
  flang/test/Driver/werror_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -511,8 +511,14 @@
 } else if (arg == "-fopenmp") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenMP);
   predefinitions.emplace_back("_OPENMP", "201511");
-} else if (arg == "-Werror") {
-  driver.warningsAreErrors = true;
+} else if (arg.find("-W") != std::string::npos) {
+  if (arg == "-Werror")
+driver.warningsAreErrors = true;
+  else {
+// Only -Werror is supported currently
+llvm::errs() << "Only `-Werror` is supported currently.\n";
+return EXIT_FAILURE;
+  }
 } else if (arg == "-ed") {
   options.features.Enable(Fortran::common::LanguageFeature::OldDebugLines);
 } else if (arg == "-E") {
Index: flang/test/Driver/werror_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/werror_wrong.f90
@@ -0,0 +1,9 @@
+! Ensure that only argument -Werror is supported.
+
+! RUN: not %flang_fc1 -fsyntax-only -Wall %s  2>&1 | FileCheck %s --check-prefix=WRONG
+! RUN: not %flang_fc1 -fsyntax-only -WX %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH -W
+!-
+! WRONG: Only `-Werror` is supported currently.
Index: flang/test/Driver/werror_sema.f90
===
--- /dev/null
+++ flang/test/Driver/werror_sema.f90
@@ -0,0 +1,31 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAndSemaAction, particularly for Semantic warnings/errors.
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+
+
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/werror_scan.f
===
--- /dev/null
+++ flang/test/Driver/werror_scan.f
@@ -0,0 +1,25 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAction
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -E -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-parsing-log -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-provenance -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-measure-parse-tree -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: %flang_fc1 -fsyntax-only -E %s  2>&1 | 

[PATCH] D98657: [flang][driver] Add options for -Werror

2021-04-05 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 updated this revision to Diff 335246.
arnamoy10 added a comment.

1. Separated test cases to check prescan, parse and sema differently.
2. Diagnostics is thrown when anything other that `error` is given for `-W`.  
This behaviour is reflected in `f18


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

https://reviews.llvm.org/D98657

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/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/werror_parse.f
  flang/test/Driver/werror_scan.f
  flang/test/Driver/werror_sema.f90
  flang/test/Driver/werror_wrong.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -511,8 +511,14 @@
 } else if (arg == "-fopenmp") {
   options.features.Enable(Fortran::common::LanguageFeature::OpenMP);
   predefinitions.emplace_back("_OPENMP", "201511");
-} else if (arg == "-Werror") {
-  driver.warningsAreErrors = true;
+} else if (arg.find("-W") != std::string::npos) {
+  if (arg == "-Werror")
+driver.warningsAreErrors = true;
+  else {
+// Only -Werror is supported currently
+llvm::errs() << "Only `-Werror` is supported currently.\n";
+return EXIT_FAILURE;
+  }
 } else if (arg == "-ed") {
   options.features.Enable(Fortran::common::LanguageFeature::OldDebugLines);
 } else if (arg == "-E") {
Index: flang/test/Driver/werror_wrong.f90
===
--- /dev/null
+++ flang/test/Driver/werror_wrong.f90
@@ -0,0 +1,9 @@
+! Ensure that only argument -Werror is supported.
+
+! RUN: not %flang_fc1 -fsyntax-only -Wall %s  2>&1 | FileCheck %s --check-prefix=WRONG
+! RUN: not %flang_fc1 -fsyntax-only -WX %s  2>&1 | FileCheck %s --check-prefix=WRONG
+
+!-
+! EXPECTED OUTPUT WITH -W
+!-
+! WRONG: Only `-Werror` is supported currently.
\ No newline at end of file
Index: flang/test/Driver/werror_sema.f90
===
--- /dev/null
+++ flang/test/Driver/werror_sema.f90
@@ -0,0 +1,31 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAndSemaAction, particularly for Semantic warnings/errors.
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-unparse %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -Werror -fdebug-dump-symbols %s  2>&1 | FileCheck %s --check-prefix=WITH
+
+
+! RUN: %flang_fc1 -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-parse-tree %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse-with-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-unparse %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols %s  2>&1 | FileCheck %s --allow-empty --check-prefix=WITHOUT
+
+!-
+! EXPECTED OUTPUT WITH -Werror
+!-
+! WITH: Semantic errors in
+
+!-
+! EXPECTED OUTPUT WITHOUT -Werror
+!-
+! WITHOUT-NOT: Semantic errors in
+
+PROGRAM werror
+REAL, DIMENSION(20, 10) :: A
+FORALL (J=1:N)  A(I, I) = 1
+END PROGRAM werror
Index: flang/test/Driver/werror_scan.f
===
--- /dev/null
+++ flang/test/Driver/werror_scan.f
@@ -0,0 +1,25 @@
+! Ensure argument -Werror work as expected, this file checks for the functional correctness for
+! actions that extend the PrescanAction
+! Multiple RUN lines are added to make sure that the behavior is consistent across multiple actions.
+
+! RUN: not %flang_fc1 -fsyntax-only -E -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-parsing-log -Werror %s  2>&1 | FileCheck %s --check-prefix=WITH
+! RUN: not %flang_fc1 -fsyntax-only -fdebug-dump-provenance -Werror %s  2>&1 | FileCheck %s 

[PATCH] D70094: [clang-tidy] new altera ID dependent backward branch check

2021-04-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp:200
+  if (isa(Loop))
+return DO_LOOP; // loop_type = 0;
+  else if (isa(Loop))

Is loop ID is not enough? Why does comment with numerical code used? Same below.



Comment at: 
clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h:1
+//===--- IdDependentBackwardBranchCheck.h - 
clang-tidy-===//
+//

Please add space after clang-tidy and language code. See other checks as 
example.



Comment at: 
clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h:36
+: FieldDeclaration(Declaration), Location(Location), Message(Message) 
{}
+IdDependencyRecord() {}
+const VarDecl *VariableDeclaration;

Please use `= default;`


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

https://reviews.llvm.org/D70094

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


[PATCH] D99848: [OPENMP51]Initial support for nocontext clause

2021-04-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Formatting




Comment at: clang/lib/Sema/SemaOpenMP.cpp:14908
   llvm::MapVector Captures;
+  ValExpr = tryBuildCapture(*this, ValExpr, Captures).get();
   HelperValStmt = buildPreInits(Context, Captures);

This must be fixed in a separate patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99848

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


[PATCH] D99426: [SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag instead of OF_Text

2021-04-05 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan added a comment.

Is there any more feedback on this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99426

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


[PATCH] D91327: [NewPM] Redesign of PreserveCFG Checker

2021-04-05 Thread Serguei Katkov via Phabricator via cfe-commits
skatkov accepted this revision.
skatkov added a comment.
This revision is now accepted and ready to land.

with two nits.




Comment at: llvm/include/llvm/Passes/StandardInstrumentations.h:422
+  // Register all the standard instrumentation callbacks. If \p FAM is nullptr
+  // then PreservedCFGChecker is not registeredenabled.
+  void registerCallbacks(PassInstrumentationCallbacks ,

yrouban wrote:
> fix registeredenabled
Not Done.



Comment at: llvm/lib/Passes/StandardInstrumentations.cpp:1079
+const auto *F = any_cast(IR);
+FAM.getResult(*const_cast(F));
+  });

Add a comment that you caches the CFG before pass.


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

https://reviews.llvm.org/D91327

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


[PATCH] D99830: [DebugInfo, CallSites, test] Fix use of undef FileCheck var

2021-04-05 Thread Thomas Preud'homme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4dd3e0feca92: [DebugInfo, CallSites, test] Fix use of undef 
FileCheck var (authored by thopre).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99830

Files:
  clang/test/CodeGen/debug-info-extern-call.c


Index: clang/test/CodeGen/debug-info-extern-call.c
===
--- clang/test/CodeGen/debug-info-extern-call.c
+++ clang/test/CodeGen/debug-info-extern-call.c
@@ -21,8 +21,7 @@
 // RUN: %clang -g -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm %s -o 
- \
 // RUN:   | FileCheck %s -check-prefix=NO-DECLS-FOR-EXTERN
 
-// DECLS-FOR-EXTERN-NOT: !DICompileUnit({{.*}}retainedTypes: 
![[RETTYPES:[0-9]+]]
-// DECLS-FOR-EXTERN-NOT: ![[RETTYPES]] = !{
+// DECLS-FOR-EXTERN-NOT: !DICompileUnit({{.*}}retainedTypes: !{{[0-9]+}}
 // DECLS-FOR-EXTERN: !DISubprogram(name: "fn1"
 // DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "memcmp"
 // DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "__some_reserved_name"


Index: clang/test/CodeGen/debug-info-extern-call.c
===
--- clang/test/CodeGen/debug-info-extern-call.c
+++ clang/test/CodeGen/debug-info-extern-call.c
@@ -21,8 +21,7 @@
 // RUN: %clang -g -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm %s -o - \
 // RUN:   | FileCheck %s -check-prefix=NO-DECLS-FOR-EXTERN
 
-// DECLS-FOR-EXTERN-NOT: !DICompileUnit({{.*}}retainedTypes: ![[RETTYPES:[0-9]+]]
-// DECLS-FOR-EXTERN-NOT: ![[RETTYPES]] = !{
+// DECLS-FOR-EXTERN-NOT: !DICompileUnit({{.*}}retainedTypes: !{{[0-9]+}}
 // DECLS-FOR-EXTERN: !DISubprogram(name: "fn1"
 // DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "memcmp"
 // DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "__some_reserved_name"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4dd3e0f - [DebugInfo, CallSites, test] Fix use of undef FileCheck var

2021-04-05 Thread Thomas Preud'homme via cfe-commits

Author: Thomas Preud'homme
Date: 2021-04-05T11:39:24+01:00
New Revision: 4dd3e0feca9295c615f06f9f96f1e7ccdd63bb3d

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

LOG: [DebugInfo, CallSites, test] Fix use of undef FileCheck var

Clang test CodeGen/debug-info-extern-call.c tries to check for the
absence of a sequence of instructions with several CHECK-NOT with one of
those directives using a variable defined in another. However CHECK-NOT
are checked independently so that is using a variable defined in a
pattern that should not occur in the input.

This commit removes the CHECK-NOT for the retained line attribute
definition since the CHECK-NOT on the compile unit will already check
that there is no retained lines.

Reviewed By: djtodoro

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

Added: 


Modified: 
clang/test/CodeGen/debug-info-extern-call.c

Removed: 




diff  --git a/clang/test/CodeGen/debug-info-extern-call.c 
b/clang/test/CodeGen/debug-info-extern-call.c
index 7ba115ad2ec9e..f9abb93efe865 100644
--- a/clang/test/CodeGen/debug-info-extern-call.c
+++ b/clang/test/CodeGen/debug-info-extern-call.c
@@ -21,8 +21,7 @@
 // RUN: %clang -g -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm %s -o 
- \
 // RUN:   | FileCheck %s -check-prefix=NO-DECLS-FOR-EXTERN
 
-// DECLS-FOR-EXTERN-NOT: !DICompileUnit({{.*}}retainedTypes: 
![[RETTYPES:[0-9]+]]
-// DECLS-FOR-EXTERN-NOT: ![[RETTYPES]] = !{
+// DECLS-FOR-EXTERN-NOT: !DICompileUnit({{.*}}retainedTypes: !{{[0-9]+}}
 // DECLS-FOR-EXTERN: !DISubprogram(name: "fn1"
 // DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "memcmp"
 // DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "__some_reserved_name"



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


[PATCH] D89490: Introduce __attribute__((darwin_abi))

2021-04-05 Thread Adrien Guinet via Phabricator via cfe-commits
aguinet added a comment.

@rjmccall @mstorsjo @aaron.ballman any advice on what to do next? Should I 
bring this discussion back to llvm-dev?

I don't want this to justs stall here. I would like to have a clear decision on 
why it is or it is not a good idea to merge this in LLVM.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89490

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


[PATCH] D97462: [clang][cli] Round-trip cc1 arguments in assert builds

2021-04-05 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

In D97462#298 , @dexonsmith wrote:

> In D97462#2666485 , @jansvoboda11 
> wrote:
>
>> Thanks for reporting that. D99606  fixes 
>> one aspect of `-plugin-arg`, but it seems the order of generation is 
>> non-deterministic (most likely related to the underlying storage, 
>> `std::unordered_map`). I can look into it early next week, but I think 
>> simple sort in the generation code should do the trick.
>
> Can/should it just be changed to a `std::map`?

Yes, that that works as well. Fixed in D99879 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97462

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


[PATCH] D99879: [clang][cli] Ensure plugin args are generated in deterministic order

2021-04-05 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, akhuang.
Herald added a subscriber: mgrang.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The '-plugin-arg' command-line arguments are not being generated in 
deterministic order.

This patch changes the storage from `std::unordered_map` to `std::map` to 
enforce ordering.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99879

Files:
  clang/include/clang/Frontend/FrontendOptions.h
  clang/unittests/Frontend/CompilerInvocationTest.cpp


Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -877,4 +877,15 @@
 ShowIncludesDestination::Stdout);
   ASSERT_TRUE(Invocation.getDependencyOutputOpts().ShowHeaderIncludes);
 }
+
+TEST_F(CommandLineTest, PluginArgsRoundTripDeterminism) {
+  const char *Args[] = {
+  "-plugin-arg-blink-gc-plugin", "no-members-in-stack-allocated",
+  "-plugin-arg-find-bad-constructs", "checked-ptr-as-trivial-member",
+  "-plugin-arg-find-bad-constructs", "check-ipc",
+  // Enable round-trip to ensure '-plugin-arg' generation is deterministic.
+  "-round-trip-args"};
+
+  ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
+}
 } // anonymous namespace
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -16,9 +16,9 @@
 #include "clang/Serialization/ModuleFileExtension.h"
 #include "llvm/ADT/StringRef.h"
 #include 
+#include 
 #include 
 #include 
-#include 
 #include 
 
 namespace llvm {
@@ -404,7 +404,7 @@
   std::string ActionName;
 
   /// Args to pass to the plugins
-  std::unordered_map> PluginArgs;
+  std::map> PluginArgs;
 
   /// The list of plugin actions to run in addition to the normal action.
   std::vector AddPluginActions;


Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -877,4 +877,15 @@
 ShowIncludesDestination::Stdout);
   ASSERT_TRUE(Invocation.getDependencyOutputOpts().ShowHeaderIncludes);
 }
+
+TEST_F(CommandLineTest, PluginArgsRoundTripDeterminism) {
+  const char *Args[] = {
+  "-plugin-arg-blink-gc-plugin", "no-members-in-stack-allocated",
+  "-plugin-arg-find-bad-constructs", "checked-ptr-as-trivial-member",
+  "-plugin-arg-find-bad-constructs", "check-ipc",
+  // Enable round-trip to ensure '-plugin-arg' generation is deterministic.
+  "-round-trip-args"};
+
+  ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
+}
 } // anonymous namespace
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -16,9 +16,9 @@
 #include "clang/Serialization/ModuleFileExtension.h"
 #include "llvm/ADT/StringRef.h"
 #include 
+#include 
 #include 
 #include 
-#include 
 #include 
 
 namespace llvm {
@@ -404,7 +404,7 @@
   std::string ActionName;
 
   /// Args to pass to the plugins
-  std::unordered_map> PluginArgs;
+  std::map> PluginArgs;
 
   /// The list of plugin actions to run in addition to the normal action.
   std::vector AddPluginActions;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D99501: ignore -flto= options recognized by GCC

2021-04-05 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Tests missing.
This somehow wasn't sent to cfe-commits list


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99501

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


[PATCH] D99501: ignore -flto= options recognized by GCC

2021-04-05 Thread Sylvestre Ledru 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 rG162848654842: ignore -flto= options recognized by GCC 
(authored by sylvestre.ledru).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99501

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4155,6 +4155,8 @@
 defm branch_count_reg : BooleanFFlag<"branch-count-reg">, 
Group;
 defm default_inline : BooleanFFlag<"default-inline">, 
Group;
 defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, 
Group;
+def : Flag<["-"], "flto=auto">, Group;
+def : Flag<["-"], "flto=jobserver">, 
Group;
 defm float_store : BooleanFFlag<"float-store">, 
Group;
 defm friend_injection : BooleanFFlag<"friend-injection">, 
Group;
 defm function_attribute_list : BooleanFFlag<"function-attribute-list">, 
Group;


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4155,6 +4155,8 @@
 defm branch_count_reg : BooleanFFlag<"branch-count-reg">, Group;
 defm default_inline : BooleanFFlag<"default-inline">, Group;
 defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, Group;
+def : Flag<["-"], "flto=auto">, Group;
+def : Flag<["-"], "flto=jobserver">, Group;
 defm float_store : BooleanFFlag<"float-store">, Group;
 defm friend_injection : BooleanFFlag<"friend-injection">, Group;
 defm function_attribute_list : BooleanFFlag<"function-attribute-list">, Group;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1628486 - ignore -flto= options recognized by GCC

2021-04-05 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2021-04-05T11:54:17+02:00
New Revision: 1628486548420f85b3467026d54663d1516404f5

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

LOG: ignore -flto= options recognized by GCC

as requested in https://bugs.llvm.org/show_bug.cgi?id=49553, submitting the 
proposed changes to just ignore the -flto= options which are recognized by GCC 
("auto" and "jobserver").

GCC supports -flto= to select the parallelity for LTO 
builds. LLVM also has -flto-jobs=, which only seems to have a meaning when 
used with -flto=thin?

The attached patch just ignores the values "auto" and "jobserver". that doesn't 
change anything in functionality.  Another option would be to map these values 
to either "thin" or "full", maybe in presence of the -ffat-lto-objects option?

-flto= could also be translated to -flto-jobs=.

Reviewed By: tejohnson

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a6583acd9ecb..64d658b2bfd9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4155,6 +4155,8 @@ defm reorder_blocks : BooleanFFlag<"reorder-blocks">, 
Group, 
Group;
 defm default_inline : BooleanFFlag<"default-inline">, 
Group;
 defm fat_lto_objects : BooleanFFlag<"fat-lto-objects">, 
Group;
+def : Flag<["-"], "flto=auto">, Group;
+def : Flag<["-"], "flto=jobserver">, 
Group;
 defm float_store : BooleanFFlag<"float-store">, 
Group;
 defm friend_injection : BooleanFFlag<"friend-injection">, 
Group;
 defm function_attribute_list : BooleanFFlag<"function-attribute-list">, 
Group;



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


[PATCH] D91327: [NewPM] Redesign of PreserveCFG Checker

2021-04-05 Thread Yevgeny Rouban via Phabricator via cfe-commits
yrouban updated this revision to Diff 335221.
yrouban marked 2 inline comments as done.
yrouban added a comment.

Addressed comments.
Some tests were moved a separate patch (D99878 
).


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

https://reviews.llvm.org/D91327

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/Other/new-pass-manager.ll
  llvm/test/Other/new-pm-defaults.ll
  llvm/tools/opt/NewPMDriver.cpp
  llvm/unittests/IR/PassManagerTest.cpp

Index: llvm/unittests/IR/PassManagerTest.cpp
===
--- llvm/unittests/IR/PassManagerTest.cpp
+++ llvm/unittests/IR/PassManagerTest.cpp
@@ -827,7 +827,7 @@
   FunctionPassManager FPM(/*DebugLogging*/ true);
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(/*DebugLogging*/ true);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   FAM.registerPass([&] { return PassInstrumentationAnalysis(); });
   FAM.registerPass([&] { return DominatorTreeAnalysis(); });
   FAM.registerPass([&] { return AssumptionAnalysis(); });
@@ -873,7 +873,7 @@
   FunctionPassManager FPM(/*DebugLogging*/ true);
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(/*DebugLogging*/ true);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   FAM.registerPass([&] { return PassInstrumentationAnalysis(); });
   FAM.registerPass([&] { return DominatorTreeAnalysis(); });
   FAM.registerPass([&] { return AssumptionAnalysis(); });
@@ -938,7 +938,7 @@
   FunctionPassManager FPM(/*DebugLogging*/ true);
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(/*DebugLogging*/ true);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   FAM.registerPass([&] { return PassInstrumentationAnalysis(); });
   FAM.registerPass([&] { return DominatorTreeAnalysis(); });
   FAM.registerPass([&] { return AssumptionAnalysis(); });
Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -275,9 +275,14 @@
   P->CSAction = PGOOptions::CSIRUse;
 }
   }
+  LoopAnalysisManager LAM(DebugPM);
+  FunctionAnalysisManager FAM(DebugPM);
+  CGSCCAnalysisManager CGAM(DebugPM);
+  ModuleAnalysisManager MAM(DebugPM);
+
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(DebugPM, VerifyEachPass);
-  SI.registerCallbacks(PIC);
+  SI.registerCallbacks(PIC, );
   DebugifyEachInstrumentation Debugify;
   if (DebugifyEach)
 Debugify.registerCallbacks(PIC);
@@ -373,11 +378,6 @@
 }
   }
 
-  LoopAnalysisManager LAM(DebugPM);
-  FunctionAnalysisManager FAM(DebugPM);
-  CGSCCAnalysisManager CGAM(DebugPM);
-  ModuleAnalysisManager MAM(DebugPM);
-
   // Register the AA manager first so that our version is the one used.
   FAM.registerPass([&] { return std::move(AA); });
   // Register our TargetLibraryInfoImpl.
Index: llvm/test/Other/new-pm-defaults.ll
===
--- llvm/test/Other/new-pm-defaults.ll
+++ llvm/test/Other/new-pm-defaults.ll
@@ -7,62 +7,62 @@
 ; Any invalidation that shows up here is a bug, unless we started modifying
 ; the IR, in which case we need to make it immutable harder.
 
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O1,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S  %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S  %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-Os,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='default' -S %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-Oz,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
 ; RUN: -passes='lto-pre-link' -S %s 2>&1 \
 ; RUN: | FileCheck %s 

[PATCH] D99877: [Clang] Allow processing of attributes on statements by plugins

2021-04-05 Thread Josh Junon via Phabricator via cfe-commits
Qix- created this revision.
Qix- added a reviewer: aaron.ballman.
Qix- added a project: clang.
Qix- requested review of this revision.
Herald added a subscriber: cfe-commits.

Pretty cut and dry; currently plugins can create attributes for declarations 
but any that are not recognized produce a diagnostic, leaving no hook for 
plugins to react to them.

This adds a quick check to the attribute to see if the implementation would 
like to handle it first, akin to how declarations are handled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99877

Files:
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/Sema/SemaStmtAttr.cpp


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -430,11 +430,12 @@
   case ParsedAttr::AT_Unlikely:
 return handleUnlikely(S, St, A, Range);
   default:
-// N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
-// declaration attribute is not written on a statement, but this code is
-// needed for attributes in Attr.td that do not list any subjects.
-S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
-<< A << St->getBeginLoc();
+if (A.getInfo().handleStmtAttribute(S, St, A) == 
ParsedAttrInfo::NotHandled)
+  // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
+  // declaration attribute is not written on a statement, but this code is
+  // needed for attributes in Attr.td that do not list any subjects.
+  S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
+  << A << St->getBeginLoc();
 return nullptr;
   }
 }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -117,6 +117,13 @@
const ParsedAttr ) const {
 return NotHandled;
   }
+  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to 
this
+  /// Stmt then do so and return either AttributeApplied if it was applied or
+  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
+  virtual AttrHandling handleStmtAttribute(Sema , Stmt *St,
+   const ParsedAttr ) const {
+return NotHandled;
+  }

   static const ParsedAttrInfo (const AttributeCommonInfo );
 };


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -430,11 +430,12 @@
   case ParsedAttr::AT_Unlikely:
 return handleUnlikely(S, St, A, Range);
   default:
-// N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
-// declaration attribute is not written on a statement, but this code is
-// needed for attributes in Attr.td that do not list any subjects.
-S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
-<< A << St->getBeginLoc();
+if (A.getInfo().handleStmtAttribute(S, St, A) == ParsedAttrInfo::NotHandled)
+  // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
+  // declaration attribute is not written on a statement, but this code is
+  // needed for attributes in Attr.td that do not list any subjects.
+  S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
+  << A << St->getBeginLoc();
 return nullptr;
   }
 }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -117,6 +117,13 @@
const ParsedAttr ) const {
 return NotHandled;
   }
+  /// If this ParsedAttrInfo knows how to handle this ParsedAttr applied to this
+  /// Stmt then do so and return either AttributeApplied if it was applied or
+  /// AttributeNotApplied if it wasn't. Otherwise return NotHandled.
+  virtual AttrHandling handleStmtAttribute(Sema , Stmt *St,
+   const ParsedAttr ) const {
+return NotHandled;
+  }

   static const ParsedAttrInfo (const AttributeCommonInfo );
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-04-05 Thread Saurabh Jha via Phabricator via cfe-commits
SaurabhJha updated this revision to Diff 335216.
SaurabhJha added a comment.

Move back CK_MatrixCast definition to to just above CK_VectorSplat. The Matrix 
CodeGen is passing again but SemaOpenCL/sampler tests are failing again


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99037

Files:
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGen/matrix-cast.c
  clang/test/Sema/matrix-cast.c

Index: clang/test/Sema/matrix-cast.c
===
--- /dev/null
+++ clang/test/Sema/matrix-cast.c
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -fenable-matrix -fsyntax-only %s -verify
+
+typedef char cx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix4x4 __attribute__((matrix_type(4, 4)));
+typedef short sx4x4 __attribute__((matrix_type(4, 4)));
+typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+typedef int vec __attribute__((vector_size(4)));
+typedef struct test_struct {
+} test_struct;
+
+void f1() {
+  cx4x4 m1;
+  ix4x4 m2;
+  sx4x4 m3;
+  ix5x5 m4;
+  fx5x5 m5;
+  int i;
+  vec v;
+  test_struct *s;
+
+  m2 = (ix4x4)m1;
+  m3 = (sx4x4)m2;
+  m4 = (ix5x5)m3; // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and 'sx4x4' \
+(aka 'short __attribute__((matrix_type(4, 4)))') of different size}}
+  m5 = (ix5x5)m4; // expected-error {{assigning to 'fx5x5' (aka \
+'float __attribute__((matrix_type(5, 5)))') from incompatible type 'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))')}}
+  i = (int)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  m4 = (ix5x5)i;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'int'}}
+  v = (vec)m4;// expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  m4 = (ix5x5)v;  // expected-error {{invalid conversion between matrix type \
+'ix5x5' (aka 'int __attribute__((matrix_type(5, 5)))') and non matrix type \
+'vec' (vector of 1 'int' value)}}
+  s = (test_struct *)m3; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+  m3 = (sx4x4)s; // expected-error {{invalid conversion between matrix type \
+'sx4x4' (aka 'short __attribute__((matrix_type(4, 4)))') and non matrix type \
+'test_struct *' (aka 'struct test_struct *')}}
+
+  m4 = (ix5x5)m5;
+}
+
+typedef float float2_8x8 __attribute__((matrix_type(8, 8)));
+typedef double double_10x10 __attribute__((matrix_type(10, 10)));
+typedef double double_8x8 __attribute__((matrix_type(8, 8)));
+typedef signed int signed_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_12x12 __attribute__((matrix_type(12, 12)));
+typedef unsigned int unsigned_int_10x10 __attribute__((matrix_type(10, 10)));
+
+void f2() {
+  float2_8x8 m1;
+  double_10x10 m2;
+  double_8x8 m3;
+  signed_int_12x12 m4;
+  unsigned_int_12x12 m5;
+  unsigned_int_10x10 m6;
+  float f;
+
+  m2 = (double_10x10)m1; // expected-error {{invalid conversion between matrix type \
+'double_10x10' (aka 'double __attribute__((matrix_type(10, 10)))') and 'float2_8x8' \
+(aka 'float __attribute__((matrix_type(8, 8)))') of different size}}
+  m3 = (double_8x8)m1;
+
+  m5 = (unsigned_int_12x12)m4;
+  m4 = (signed_int_12x12)m5;
+  m6 = (unsigned_int_10x10)m4; // expected-error {{invalid conversion between matrix type \
+'unsigned_int_10x10' (aka 'unsigned int __attribute__((matrix_type(10, 10)))') and 'signed_int_12x12' \
+(aka 'int __attribute__((matrix_type(12, 12)))') of different size}}
+  f = (float)m4;   // expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix type \
+'float'}}
+  m4 = (signed_int_12x12)f;// expected-error {{invalid conversion between matrix type \
+'signed_int_12x12' (aka 'int __attribute__((matrix_type(12, 12)))') and non matrix type \
+'float'}}
+}
\ No newline at end of file
Index: clang/test/CodeGen/matrix-cast.c