[PATCH] D69786: [X86] Add support for -mvzeroupper and -mno-vzeroupper to match gcc.

2019-11-03 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D69786#1731942 , @davezarzycki 
wrote:

> Actually, wait, what does it mean for a CPU without AVX to have 
> `FeatureInsertVZEROUPPER`?


Means we’ll do vzeroupper insertion if you add -mavx to the command line and 
ymm is used. At minimum we need to have it set for pentium4, x86-64, core2, and 
maybe some others  since those are default CPUs on some platforms and we want 
vzeroupper if someone uses a default cpu and adds -mavx.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69786



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


[PATCH] D69786: [X86] Add support for -mvzeroupper and -mno-vzeroupper to match gcc.

2019-11-03 Thread David Zarzycki via Phabricator via cfe-commits
davezarzycki added a comment.

Actually, wait, what does it mean for a CPU without AVX to have 
`FeatureInsertVZEROUPPER`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69786



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


[PATCH] D69786: [X86] Add support for -mvzeroupper and -mno-vzeroupper to match gcc.

2019-11-03 Thread David Zarzycki via Phabricator via cfe-commits
davezarzycki accepted this revision.
davezarzycki added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks! I'll close my differential proposal then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69786



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


[PATCH] D69764: [clang-format] Add East Const / West Const fixer

2019-11-03 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang/lib/Format/Format.cpp:768
   LLVMStyle.CommentPragmas = "^ IWYU pragma:";
+  LLVMStyle.ConstStyle = FormatStyle::CS_Leave;
   LLVMStyle.CompactNamespaces = false;

Based on code reviews, this should be `CS_West`.


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

https://reviews.llvm.org/D69764



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


[PATCH] D69785: [OpenMP] Introduce the OpenMP-IR-Builder

2019-11-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert marked 5 inline comments as done.
jdoerfert added inline comments.



Comment at: clang/include/clang/Basic/OpenMPKinds.h:29
-  OMPD_unknown
+  OMPD_unknown,
 };
 

These changes do not impact Clang nor do they remove functionality (if 
OPENMP_DIRECTIVE is defined it will work as it did before) but they are 
necessary to make the enum values in Clang and the OpenMPIRBuilder equal.

The reason is that the OPENMP_DIRECTIVE and OPENMP_DIRECTIVE_EXT definitions in 
`OpenMPKinds.def` are interleaved but for the OpenMPIRBuilder I was hoping not 
to separate them logically. So the first three changes adjust Clang towards 
this simpler model that is still as powerful as the old one was but which 
changes the order of the enums.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:3490
+  }
+
   if (!CGF.HaveInsertPoint())

The first extension could be for Clang to communicate the cancellation blocks 
to the OMPBuilder which would allow us there to handle all barriers. Note: 
There is no need for a callback (in the long run) as cancellation points will 
be handled by the OMPBuilder eventually.



Comment at: clang/test/OpenMP/for_firstprivate_codegen.cpp:291
 // CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i32* dereferenceable(4) 
%{{.+}}, [2 x i32]* dereferenceable(8) %{{.+}}, [2 x [[S_INT_TY]]]* 
dereferenceable(8) %{{.+}}, [[S_INT_TY]]* dereferenceable(4) %{{.+}})
+// CHECK: [[GTID_CALL:%.+]] = call i32 @__kmpc_global_thread_num
 // Skip temp vars for loop

All test changes are because we do not check if there is an existing global 
thread ID value available through an argument. See the comment in 
`OpenMPIRBuilder::getThreadID` for further information and a proper way out.



Comment at: llvm/include/llvm/IR/OpenMPIRBuilder.h:36
+#include "llvm/IR/OpenMPKinds.def"
+  };
+

The enum values are equivalent to the ones in Clangs `OpenMPDirectiveKind`, 
they have to be as we convert the latter to the former right now. At some point 
we won't need the latter but for now we should probably put a static assert 
here to verify the first and last enum values are equal.



Comment at: llvm/include/llvm/IR/OpenMPIRBuilder.h:58
+IRBuilder<>::InsertPoint IP;
+  };
+

This struct needs to be extended with source location information in a way not 
tied to Clang. We wan to use that for two purposes: (1) generate `ident_t` with 
actual source locations embedded and (2) tell the IRBuilder to emit debug info 
if requested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69785



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


[PATCH] D69785: [OpenMP] Introduce the OpenMP-IR-Builder

2019-11-03 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert created this revision.
jdoerfert added reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, 
gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim.
Herald added subscribers: cfe-commits, jfb, guansong, bollu, hiraditya, mgorny.
Herald added projects: clang, LLVM.

This is the initial patch for the OpenMP-IR-Builder, as discussed on the
mailing list ([1] and later) and at the US Dev Meeting'19.

The design is similar to D61953  but:

- placed in `llvm/lib/IR/` next to IRBuilder, for lack of a better location.
- in a non-WIP status, with proper documentation and working.
- using a OpenMPKinds.def file to manage lists of directives, runtime 
functions, types, ..., similar to the current Clang implementation.
- restricted to handle only (simple) barriers, to implement most `#pragma omp 
barrier` directives and most implicit barriers.
- properly hooked into Clang to be used if possible.
- compatible with the remaining code generation.

The plan is to have multiple people working on moving logic from Clang
here once the initial scaffolding (=this patch) landed.

[1] 
http://lists.flang-compiler.org/pipermail/flang-dev_lists.flang-compiler.org/2019-May/000197.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69785

Files:
  clang/include/clang/Basic/OpenMPKinds.def
  clang/include/clang/Basic/OpenMPKinds.h
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/OpenMP/for_firstprivate_codegen.cpp
  clang/test/OpenMP/for_linear_codegen.cpp
  clang/test/OpenMP/parallel_copyin_codegen.cpp
  clang/test/OpenMP/sections_codegen.cpp
  llvm/include/llvm/IR/OpenMPIRBuilder.h
  llvm/include/llvm/IR/OpenMPKinds.def
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/IR/OpenMPIRBuilder.cpp

Index: llvm/lib/IR/OpenMPIRBuilder.cpp
===
--- /dev/null
+++ llvm/lib/IR/OpenMPIRBuilder.cpp
@@ -0,0 +1,217 @@
+//===- OpenMPIRBuilder.cpp - Builder for LLVM-IR for OpenMP directives ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+///
+/// This file implements the OpenMPIRBuilder class, which is used as a
+/// convenient way to create LLVM instructions for OpenMP directives.
+///
+//===--===//
+
+#include "llvm/IR/OpenMPIRBuilder.h"
+
+#include "llvm/IR/MDBuilder.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+#define DEBUG_TYPE "openmp-ir-builder"
+
+using namespace llvm;
+
+Function *OpenMPIRBuilder::getRuntimeFunction(RTLFnKind FnID) {
+  Function *Fn = nullptr;
+
+  // Try to find the declation in the module first.
+  switch (FnID) {
+#define OMP_RTL(Enum, Str, IsVarArg, ReturnType, ...)  \
+  case Enum:   \
+Fn = M.getFunction(Str);   \
+break;
+#include "llvm/IR/OpenMPKinds.def"
+  }
+
+  if (!Fn) {
+
+// Create a new declaration if we need one.
+switch (FnID) {
+#define OMP_RTL(Enum, Str, IsVarArg, ReturnType, ...)  \
+  case Enum:   \
+Fn = Function::Create(FunctionType::get(ReturnType,\
+ArrayRef{__VA_ARGS__}, \
+IsVarArg), \
+  GlobalValue::ExternalLinkage, Str, M);   \
+break;
+#include "llvm/IR/OpenMPKinds.def"
+}
+
+assert(Fn && "Failed to create OpenMP runtime function");
+
+LLVMContext  = Fn->getContext();
+// Add attributes to the new declaration.
+switch (FnID) {
+#define OMP_RTL_ATTRS(Enum, FnAttrSet, RetAttrSet, ArgAttrSets)\
+  case Enum:   \
+Fn->setAttributes( \
+AttributeList::get(Ctx, FnAttrSet, RetAttrSet, ArgAttrSets));  \
+break;
+#include "llvm/IR/OpenMPKinds.def"
+default:
+  // Attributes are optional.
+  break;
+}
+  }
+
+  return Fn;
+}
+
+void OpenMPIRBuilder::initialize() {
+  LLVMContext  = M.getContext();
+
+  // Create all simple and struct types exposed by the runtime and remember the
+  // llvm::PointerTypes of them for easy access later.
+  Type *T;
+#define OMP_TYPE(VarName, InitValue) this->VarName = InitValue;
+#define OMP_STRUCT_TYPE(VarName, StructName, ...)  \
+  T = 

[PATCH] D69786: [X86] Add support for -mvzeroupper and -mno-vzeroupper to match gcc.

2019-11-03 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel.
Herald added subscribers: cfe-commits, jfb, hiraditya.
Herald added projects: clang, LLVM.
craig.topper added a reviewer: davezarzycki.

-mvzeroupper will force the vzeroupper insertion pass to run on
CPUs that normally wouldn't. -mno-vzeroupper disables it on CPUs
where it normally runs.

To support this with the default feature handling in clang, we
need a vzeroupper feature flag in X86.td. Since this flag has
the opposite polarity of the fast-partial-ymm-or-zmm-write we
used to use to disable the pass, we now need to add this new
flag to every CPU except KNL/KNM and BTVER2 to keep identical
behavior.

Remove -fast-partial-ymm-or-zmm-write which is no longer used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69786

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Driver/Options.td
  clang/test/Driver/x86-target-features.c
  llvm/docs/ReleaseNotes.rst
  llvm/lib/Target/X86/X86.td
  llvm/lib/Target/X86/X86Subtarget.h
  llvm/lib/Target/X86/X86TargetTransformInfo.h
  llvm/lib/Target/X86/X86VZeroUpper.cpp
  llvm/test/CodeGen/X86/avx-vzeroupper.ll

Index: llvm/test/CodeGen/X86/avx-vzeroupper.ll
===
--- llvm/test/CodeGen/X86/avx-vzeroupper.ll
+++ llvm/test/CodeGen/X86/avx-vzeroupper.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefix=ALL --check-prefix=VZ --check-prefix=AVX
 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mattr=+avx512f | FileCheck %s --check-prefix=ALL --check-prefix=VZ --check-prefix=AVX512
-; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mattr=+avx,+fast-partial-ymm-or-zmm-write | FileCheck %s --check-prefix=ALL --check-prefix=NO-VZ --check-prefix=FAST-ymm-zmm
+; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mattr=+avx,-vzeroupper | FileCheck %s --check-prefix=ALL --check-prefix=NO-VZ --check-prefix=DISABLE-VZ
 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mcpu=bdver2 | FileCheck %s --check-prefix=ALL --check-prefix=NO-VZ --check-prefix=BDVER2
 ; RUN: llc < %s -x86-use-vzeroupper -mtriple=x86_64-unknown-unknown -mcpu=btver2 | FileCheck %s --check-prefix=ALL --check-prefix=NO-VZ --check-prefix=BTVER2
 
@@ -44,18 +44,18 @@
 ; VZ-NEXT:addq $56, %rsp
 ; VZ-NEXT:retq
 ;
-; FAST-ymm-zmm-LABEL: test01:
-; FAST-ymm-zmm:   # %bb.0:
-; FAST-ymm-zmm-NEXT:subq $56, %rsp
-; FAST-ymm-zmm-NEXT:vmovups %ymm2, (%rsp) # 32-byte Spill
-; FAST-ymm-zmm-NEXT:vmovaps {{.*}}(%rip), %xmm0
-; FAST-ymm-zmm-NEXT:callq do_sse
-; FAST-ymm-zmm-NEXT:vmovaps %xmm0, {{.*}}(%rip)
-; FAST-ymm-zmm-NEXT:callq do_sse
-; FAST-ymm-zmm-NEXT:vmovaps %xmm0, {{.*}}(%rip)
-; FAST-ymm-zmm-NEXT:vmovups (%rsp), %ymm0 # 32-byte Reload
-; FAST-ymm-zmm-NEXT:addq $56, %rsp
-; FAST-ymm-zmm-NEXT:retq
+; DISABLE-VZ-LABEL: test01:
+; DISABLE-VZ:   # %bb.0:
+; DISABLE-VZ-NEXT:subq $56, %rsp
+; DISABLE-VZ-NEXT:vmovups %ymm2, (%rsp) # 32-byte Spill
+; DISABLE-VZ-NEXT:vmovaps {{.*}}(%rip), %xmm0
+; DISABLE-VZ-NEXT:callq do_sse
+; DISABLE-VZ-NEXT:vmovaps %xmm0, {{.*}}(%rip)
+; DISABLE-VZ-NEXT:callq do_sse
+; DISABLE-VZ-NEXT:vmovaps %xmm0, {{.*}}(%rip)
+; DISABLE-VZ-NEXT:vmovups (%rsp), %ymm0 # 32-byte Reload
+; DISABLE-VZ-NEXT:addq $56, %rsp
+; DISABLE-VZ-NEXT:retq
 ;
 ; BDVER2-LABEL: test01:
 ; BDVER2:   # %bb.0:
@@ -83,6 +83,7 @@
 ; BTVER2-NEXT:vmovups (%rsp), %ymm0 # 32-byte Reload
 ; BTVER2-NEXT:addq $56, %rsp
 ; BTVER2-NEXT:retq
+; DISABLE-VZ   # %bb.0:
   %tmp = load <4 x float>, <4 x float>* @x, align 16
   %call = tail call <4 x float> @do_sse(<4 x float> %tmp) nounwind
   store <4 x float> %call, <4 x float>* @x, align 16
@@ -100,10 +101,10 @@
 ; VZ-NEXT:vzeroupper
 ; VZ-NEXT:jmp do_sse # TAILCALL
 ;
-; FAST-ymm-zmm-LABEL: test02:
-; FAST-ymm-zmm:   # %bb.0:
-; FAST-ymm-zmm-NEXT:vaddps %xmm1, %xmm0, %xmm0
-; FAST-ymm-zmm-NEXT:jmp do_sse # TAILCALL
+; DISABLE-VZ-LABEL: test02:
+; DISABLE-VZ:   # %bb.0:
+; DISABLE-VZ-NEXT:vaddps %xmm1, %xmm0, %xmm0
+; DISABLE-VZ-NEXT:jmp do_sse # TAILCALL
 ;
 ; BDVER2-LABEL: test02:
 ; BDVER2:   # %bb.0:
@@ -154,34 +155,34 @@
 ; VZ-NEXT:popq %rbx
 ; VZ-NEXT:retq
 ;
-; FAST-ymm-zmm-LABEL: test03:
-; FAST-ymm-zmm:   # %bb.0: # %entry
-; FAST-ymm-zmm-NEXT:pushq %rbx
-; FAST-ymm-zmm-NEXT:subq $16, %rsp
-; FAST-ymm-zmm-NEXT:vaddps %xmm1, %xmm0, %xmm0
-; FAST-ymm-zmm-NEXT:vmovaps %xmm0, (%rsp) # 16-byte Spill
-; FAST-ymm-zmm-NEXT:.p2align 4, 0x90
-; FAST-ymm-zmm-NEXT:  .LBB3_1: # %while.cond
-; FAST-ymm-zmm-NEXT:# =>This Inner Loop Header: Depth=1
-; FAST-ymm-zmm-NEXT:callq foo
-; FAST-ymm-zmm-NEXT:testl %eax, 

[PATCH] D68885: Add a Ranges field to Diagnostic struct

2019-11-03 Thread Joe Turner via Phabricator via cfe-commits
compositeprimes marked 3 inline comments as done.
compositeprimes added a comment.

Sorry for the delay; I got caught up in some other work.

I moved this to https://reviews.llvm.org/D69782 using arc diff.

@gribozavr: I'm not sure how to merge this with the other commit, because it's 
in clang-tidy; do you think you could share how this might be done?

Thanks!




Comment at: include/clang/Tooling/Core/Diagnostic.h:92
+  /// `Message` field, but if `Ranges` is nonempty, they will be preferred
+  /// representation of the source code associated with the diagnostic.
+  ArrayRef Ranges;

gribozavr wrote:
> I don't understand the "preferred" wording here. What do you mean?
> 
> Also, this is a departure from how compiler warnings and ClangTidy messages 
> work. Additional ranges are used to highlight parts of the code relevant to 
> the problem, not to reposition the diagnostic.
Reworded to make this more generic



Comment at: include/clang/Tooling/Core/Diagnostic.h:93
+  /// representation of the source code associated with the diagnostic.
+  ArrayRef Ranges;
 };

alexfh wrote:
> Please add YAML serialization/deserialization code for this. See 
> include/clang/Tooling/DiagnosticsYaml.h
How to I add Yaml support for CharSourceRange? Should I add the relevant 
`template <> struct MappingTraits`, and if so where would this go?


Repository:
  rC Clang

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

https://reviews.llvm.org/D68885



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


[PATCH] D69782: Summary: Instead of dropping all the ranges associated with a Diagnostic when converting them to a ClangTidy error, instead attach them to the ClangTidyError, so they can be consumed b

2019-11-03 Thread Joe Turner via Phabricator via cfe-commits
compositeprimes created this revision.
compositeprimes added reviewers: gribozavr, alexfh.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D69782

Files:
  include/clang/Tooling/Core/Diagnostic.h
  include/clang/Tooling/DiagnosticsYaml.h
  lib/Tooling/Core/Diagnostic.cpp


Index: lib/Tooling/Core/Diagnostic.cpp
===
--- lib/Tooling/Core/Diagnostic.cpp
+++ lib/Tooling/Core/Diagnostic.cpp
@@ -42,9 +42,10 @@
 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
const DiagnosticMessage ,
const SmallVector ,
-   Level DiagLevel, llvm::StringRef BuildDirectory)
+   Level DiagLevel, llvm::StringRef BuildDirectory,
+   ArrayRef Ranges)
 : DiagnosticName(DiagnosticName), Message(Message), Notes(Notes),
-  DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {}
+  DiagLevel(DiagLevel), BuildDirectory(BuildDirectory), Ranges(Ranges) {}
 
 const llvm::StringMap *selectFirstFix(const Diagnostic& D) {
if (!D.Message.Fix.empty())
Index: include/clang/Tooling/DiagnosticsYaml.h
===
--- include/clang/Tooling/DiagnosticsYaml.h
+++ include/clang/Tooling/DiagnosticsYaml.h
@@ -58,11 +58,12 @@
 
 NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic )
 : DiagnosticName(D.DiagnosticName), Message(D.Message), Notes(D.Notes),
-  DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory) {}
+  DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory),
+  Ranges(D.Ranges) {}
 
 clang::tooling::Diagnostic denormalize(const IO &) {
   return clang::tooling::Diagnostic(DiagnosticName, Message, Notes,
-DiagLevel, BuildDirectory);
+DiagLevel, BuildDirectory, Ranges);
 }
 
 std::string DiagnosticName;
@@ -71,6 +72,7 @@
 SmallVector Notes;
 clang::tooling::Diagnostic::Level DiagLevel;
 std::string BuildDirectory;
+ArrayRef Ranges;
   };
 
   static void mapping(IO , clang::tooling::Diagnostic ) {
Index: include/clang/Tooling/Core/Diagnostic.h
===
--- include/clang/Tooling/Core/Diagnostic.h
+++ include/clang/Tooling/Core/Diagnostic.h
@@ -62,7 +62,7 @@
 
   Diagnostic(llvm::StringRef DiagnosticName, const DiagnosticMessage ,
  const SmallVector , Level DiagLevel,
- llvm::StringRef BuildDirectory);
+ llvm::StringRef BuildDirectory, ArrayRef Ranges);
 
   /// Name identifying the Diagnostic.
   std::string DiagnosticName;
@@ -84,6 +84,10 @@
   ///
   /// Note: it is empty in unittest.
   std::string BuildDirectory;
+
+  /// Extra source ranges associated with the diagnostic (in addition to the
+  /// location of the Message above).
+  ArrayRef Ranges;
 };
 
 /// Collection of Diagnostics generated from a single translation unit.


Index: lib/Tooling/Core/Diagnostic.cpp
===
--- lib/Tooling/Core/Diagnostic.cpp
+++ lib/Tooling/Core/Diagnostic.cpp
@@ -42,9 +42,10 @@
 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
const DiagnosticMessage ,
const SmallVector ,
-   Level DiagLevel, llvm::StringRef BuildDirectory)
+   Level DiagLevel, llvm::StringRef BuildDirectory,
+   ArrayRef Ranges)
 : DiagnosticName(DiagnosticName), Message(Message), Notes(Notes),
-  DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {}
+  DiagLevel(DiagLevel), BuildDirectory(BuildDirectory), Ranges(Ranges) {}
 
 const llvm::StringMap *selectFirstFix(const Diagnostic& D) {
if (!D.Message.Fix.empty())
Index: include/clang/Tooling/DiagnosticsYaml.h
===
--- include/clang/Tooling/DiagnosticsYaml.h
+++ include/clang/Tooling/DiagnosticsYaml.h
@@ -58,11 +58,12 @@
 
 NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic )
 : DiagnosticName(D.DiagnosticName), Message(D.Message), Notes(D.Notes),
-  DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory) {}
+  DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory),
+  Ranges(D.Ranges) {}
 
 clang::tooling::Diagnostic denormalize(const IO &) {
   return clang::tooling::Diagnostic(DiagnosticName, Message, Notes,
-DiagLevel, BuildDirectory);
+DiagLevel, BuildDirectory, Ranges);
 }
 
 std::string DiagnosticName;
@@ -71,6 +72,7 @@
 SmallVector Notes;
 clang::tooling::Diagnostic::Level DiagLevel;
 std::string BuildDirectory;
+ArrayRef Ranges;
   };
 
   

[PATCH] D58497: Clear the KnownModules cache if the preprocessor is going away

2019-11-03 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith abandoned this revision.
dexonsmith added a comment.

I just pushed 31e14f41a21f9016050a20f07d5da03db2e8c13e 
, which 
moves KnownModules into ModuleMap as an alternative.

In D58497#1648134 , @rsmith wrote:

> Do we need `KnownModules` at all? It seems to serve a very similar purpose to 
> the `Modules` string map on `ModuleMap`. (The main difference seems to be 
> that `KnownModules` can cache module load failures.) If we can keep only a 
> single data structure tracking this, owned by the `ModuleMap` (which also 
> owns the modules), that should remove the possibility for dangling module 
> pointers.


ModuleMap::Modules only has top-level modules, but KnownModules also indexes 
submodules.  I kept them both.


Repository:
  rC Clang

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

https://reviews.llvm.org/D58497



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


[PATCH] D69498: IR: Invert convergent attribute handling

2019-11-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D69498#1731265 , @mehdi_amini wrote:

> In D69498#1727650 , @dexonsmith 
> wrote:
>
> > In D69498#1723606 , @rjmccall 
> > wrote:
> >
> > > Perhaps there should be a global metadata, or something in the 
> > > increasingly-misnamed "data layout" string, which says that convergence 
> > > is meaningful, and we should only add the attribute in 
> > > appropriately-annotated modules?
> >
> >
> > Just wanted to resurface these alternatives from John.  Given that some 
> > targets want a fundamentally different default from what most frontends 
> > expect, I think we ought to find some way to encode the difference.
>
>
> Just thought about a slight variation on this: what about adding a flag on 
> the datalayout (or a module flag) but not use it in the 
> transformations/analyses, instead use it only when creating Function by 
> always setting the `convergent` attribute when the flag is present? This 
> would require to always have a Module passed to the Function constructor 
> though (the C API already does, we would just need to update the C++ users).
>
> So creating a Function in a Module with this flag would have the convergent 
> attribute set on creation (can be unset explicitly).


That works for me.


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

https://reviews.llvm.org/D69498



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


[clang] 31e14f4 - clang/Modules: Sink CompilerInstance::KnownModules into ModuleMap

2019-11-03 Thread Duncan P. N. Exon Smith via cfe-commits

Author: Duncan P. N. Exon Smith
Date: 2019-11-03T19:57:33-08:00
New Revision: 31e14f41a21f9016050a20f07d5da03db2e8c13e

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

LOG: clang/Modules: Sink CompilerInstance::KnownModules into ModuleMap

Avoid use-after-frees when FrontendAction::BeginSourceFile is called
twice on the same CompilerInstance by sinking
CompilerInstance::KnownModules into ModuleMap.  On the way, rename the
map to CachedModuleLoads.  I considered (but rejected) merging this with
ModuleMap::Modules, since that only has top-level modules and this map
includes submodules.

This is an alternative to https://reviews.llvm.org/D58497.  Thanks to
nemanjai for the detailed analysis of the problem!

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInstance.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index d15bdc4665a3..0ed5c9beac27 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -126,10 +126,6 @@ class CompilerInstance : public ModuleLoader {
 
   std::vector> DependencyCollectors;
 
-  /// The set of top-level modules that has already been loaded,
-  /// along with the module map
-  llvm::DenseMap KnownModules;
-
   /// The set of top-level modules that has already been built on the
   /// fly as part of this overall compilation action.
   std::map BuiltModules;

diff  --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 36e97a16223b..3110ead86010 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -14,17 +14,18 @@
 #ifndef LLVM_CLANG_LEX_MODULEMAP_H
 #define LLVM_CLANG_LEX_MODULEMAP_H
 
+#include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/PointerIntPair.h"
-#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/ADT/Twine.h"
 #include 
@@ -100,6 +101,10 @@ class ModuleMap {
   /// The top-level modules that are known.
   llvm::StringMap Modules;
 
+  /// Module loading cache that includes submodules, indexed by IdentifierInfo.
+  /// nullptr is stored for modules that are known to fail to load.
+  llvm::DenseMap CachedModuleLoads;
+
   /// Shadow modules created while building this module map.
   llvm::SmallVector ShadowModules;
 
@@ -684,6 +689,16 @@ class ModuleMap {
 
   module_iterator module_begin() const { return Modules.begin(); }
   module_iterator module_end()   const { return Modules.end(); }
+
+  /// Cache a module load.  M might be nullptr.
+  void cacheModuleLoad(const IdentifierInfo , Module *M) {
+CachedModuleLoads[] = M;
+  }
+
+  /// Return a cached module load.
+  Module *getCachedModuleLoad(const IdentifierInfo ) {
+return CachedModuleLoads.lookup();
+  }
 };
 
 } // namespace clang

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c409c07ff133..cc3d848c1e02 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1541,12 +1541,9 @@ bool CompilerInstance::loadModuleFile(StringRef 
FileName) {
 }
 
 void registerAll() {
-  for (auto *II : LoadedModules) {
-CI.KnownModules[II] = CI.getPreprocessor()
-  .getHeaderSearchInfo()
-  .getModuleMap()
-  .findModule(II->getName());
-  }
+  ModuleMap  = 
CI.getPreprocessor().getHeaderSearchInfo().getModuleMap();
+  for (auto *II : LoadedModules)
+MM.cacheModuleLoad(*II, MM.findModule(II->getName()));
   LoadedModules.clear();
 }
 
@@ -1635,14 +1632,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
 return LastModuleImportResult;
   }
 
-  clang::Module *Module = nullptr;
-
   // If we don't already have information on this module, load the module now.
-  llvm::DenseMap::iterator Known
-= KnownModules.find(Path[0].first);
-  if (Known != KnownModules.end()) {
-// Retrieve the cached top-level module.
-Module = Known->second;
+  ModuleMap  = getPreprocessor().getHeaderSearchInfo().getModuleMap();
+  clang::Module *Module = MM.getCachedModuleLoad(*Path[0].first);
+  if (Module) {
+// Nothing to do here, we found it.
   } else if (ModuleName 

[PATCH] D64305: [clangd] Add path mappings functionality

2019-11-03 Thread William Wagner via Phabricator via cfe-commits
wwagner19 updated this revision to Diff 227643.
wwagner19 added a comment.
Herald added a subscriber: usaxena95.

Unfortunately, I had to take a bit of a hiatus there, but i'm back a few months 
later with an updated patch incorporating all of @sammccall 's feedback! 
Notably,

- Windows paths are now accounted for, basically we first try to parse a unix 
path, and fall back to windows if possible. After, windows paths are converted 
to forward-slash notation, so the prefix stuff can work.
- Mapping LSP jsonrpc keys is now done, albeit a bit awkward due to no delete 
key/value API
- The lit test is improved, as it no longer relies on background index and 
tests windows client path

As for the validity of this feature, I am well aware of vscode's remote 
feature, but it is still essential for vim/emacs/etc. editors, IMO.

Please take a look when you have a chance, thanks.


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

https://reviews.llvm.org/D64305

Files:
  clang-tools-extra/clangd/PathMapping.cpp
  clang-tools-extra/clangd/PathMapping.h
  clang-tools-extra/clangd/test/Inputs/path-mappings/compile_commands.json
  clang-tools-extra/clangd/test/Inputs/path-mappings/definition.jsonrpc
  clang-tools-extra/clangd/test/Inputs/path-mappings/remote/foo.cpp
  clang-tools-extra/clangd/test/Inputs/path-mappings/remote/foo.h
  clang-tools-extra/clangd/test/Inputs/path-mappings/server/foo.h
  clang-tools-extra/clangd/test/path-mappings.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/PathMappingTests.cpp

Index: clang-tools-extra/clangd/unittests/PathMappingTests.cpp
===
--- clang-tools-extra/clangd/unittests/PathMappingTests.cpp
+++ clang-tools-extra/clangd/unittests/PathMappingTests.cpp
@@ -10,121 +10,200 @@
 #include "llvm/Support/JSON.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-
+#include 
 namespace clang {
 namespace clangd {
 namespace {
 using ::testing::ElementsAre;
-using ::testing::Pair;
-
-TEST(ParsePathMappingTests, ParseFailed) {
-  auto FailedParse = [](const std::vector ) {
-auto Mappings = parsePathMappings(RawMappings);
-if (!Mappings) {
-  consumeError(Mappings.takeError());
-  return true;
-}
-return false;
-  };
+MATCHER_P2(Mapping, ClientPath, ServerPath, "") {
+  return arg.ClientPath == ClientPath && arg.ServerPath == ServerPath;
+}
+
+bool failedParse(llvm::StringRef RawMappings) {
+  llvm::Expected Mappings = parsePathMappings(RawMappings);
+  if (!Mappings) {
+consumeError(Mappings.takeError());
+return true;
+  }
+  return false;
+}
+
+TEST(ParsePathMappingTests, WindowsPath) {
+  // Relative path to C drive
+  EXPECT_TRUE(failedParse(R"(C:a=/root)"));
+  EXPECT_TRUE(failedParse(R"(\C:a=/root)"));
+  // Relative path to current drive.
+  EXPECT_TRUE(failedParse(R"(\a=/root)"));
+  // Absolute paths
+  llvm::Expected ParsedMappings =
+  parsePathMappings(R"(C:\a=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("/C:/a", "/root")));
+  // Absolute UNC path
+  ParsedMappings = parsePathMappings(R"(\\Server\C$=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("//Server/C$", "/root")));
+}
+
+TEST(ParsePathMappingTests, UnixPath) {
+  // Relative unix path
+  EXPECT_TRUE(failedParse("a/b=/root"));
+  // Absolute unix path
+  llvm::Expected ParsedMappings = parsePathMappings("/A/b=/root");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("/A/b", "/root")));
+  // Aboslute unix path w/ backslash
+  ParsedMappings = parsePathMappings(R"(/a/b\\ar=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping(R"(/a/b\\ar)", "/root")));
+}
+
+TEST(ParsePathMappingTests, ImproperFormat) {
   // uneven mappings
-  EXPECT_TRUE(FailedParse({"/home/myuser1|"}));
+  EXPECT_TRUE(failedParse("/home/myuser1="));
   // mappings need to be absolute
-  EXPECT_TRUE(FailedParse({"home/project|/workarea/project"}));
-  // improper delimiter
-  EXPECT_TRUE(FailedParse({"/home||/workarea"}));
+  EXPECT_TRUE(failedParse("home/project=/workarea/project"));
+  // duplicate delimiter
+  EXPECT_TRUE(failedParse("/home==/workarea"));
   // no delimiter
-  EXPECT_TRUE(FailedParse({"/home"}));
+  EXPECT_TRUE(failedParse("/home"));
+  // improper delimiter
+  EXPECT_TRUE(failedParse("/home,/workarea"));
 }
 
-TEST(ParsePathMappingTests, AllowsWindowsAndUnixPaths) {
-  std::vector RawPathMappings = {
-  "/C:/home/project|/workarea/project",
-  "/home/project/.includes|/C:/opt/include"};
+TEST(ParsePathMappingTests, ParsesMultiple) {
+  std::string RawPathMappings =
+  "/home/project=/workarea/project,/home/project/.includes=/opt/include";
   auto Parsed = parsePathMappings(RawPathMappings);
   ASSERT_TRUE(bool(Parsed));
   EXPECT_THAT(*Parsed,
-  

[PATCH] D69781: [analyzer] Add test directory for scan-build

2019-11-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Woohoo, that's much more tests than i made in D55683 
!

Let's hope it works on Windows :/




Comment at: clang/test/Analysis/scan-build/plist_html_output.test:17-18
+CHECK-FILENAMES: index.html
+CHECK-FILENAMES-DAG: report-{{.*}}.html
+CHECK-FILENAMES-DAG: report-{{.*}}.plist
+CHECK-FILENAMES: scanview.css

Clever!


Repository:
  rC Clang

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

https://reviews.llvm.org/D69781



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


[PATCH] D55683: [analyzer] Tests for scan-build?

2019-11-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ abandoned this revision.
NoQ added a comment.

Outdated by D69781 .


Repository:
  rC Clang

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

https://reviews.llvm.org/D55683



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


[PATCH] D69770: Add recoverable string parsing errors to APFloat

2019-11-03 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/Support/APFloat.cpp:273
+  if (p != end)
+return createError("Invalid exponent in exponent");
 

Error message sounds like nonsense 



Comment at: llvm/unittests/ADT/APFloatTest.cpp:1322
+  EXPECT_EQ(convertToErrorFromString("+0x1.1p-"), "Exponent has no digits");
+  EXPECT_EQ(convertToErrorFromString("-0x1.1p-"), "Exponent has no digits");
 }

It’s a gtestism that these operands should be swapped


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69770



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


[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang Tidy's script

2019-11-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 227640.
Charusso marked 2 inline comments as done.
Charusso added a comment.

- Remove `llvm_unreacheable` from error-handling.


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

https://reviews.llvm.org/D69746

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  clang/lib/StaticAnalyzer/Frontend/CMakeLists.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/check_analyzer_fixit.py
  clang/test/Analysis/virtualcall-fixit-remark.cpp
  clang/test/Analysis/virtualcall-fixit.cpp
  clang/test/Analysis/virtualcall-fixits.cpp
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -77,6 +77,11 @@
 if config.clang_staticanalyzer_z3 == '1':
 config.available_features.add('z3')
 
+check_analyzer_fixit_path = os.path.join(
+config.test_source_root, "Analysis", "check_analyzer_fixit.py")
+config.substitutions.append(
+('%check_analyzer_fixit',
+ '%s %s' % (config.python_executable, check_analyzer_fixit_path)))
 
 llvm_config.add_tool_substitutions(tools, tool_dirs)
 
Index: clang/test/Analysis/virtualcall-fixit.cpp
===
--- /dev/null
+++ clang/test/Analysis/virtualcall-fixit.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_analyzer_fixit %s %t \
+// RUN:   -analyzer-checker=core,optin.cplusplus.VirtualCall \
+// RUN:   -analyzer-config optin.cplusplus.VirtualCall:ShowFixIts=true
+
+struct S {
+  virtual void foo();
+  S() {
+foo();
+// expected-warning@-1 {{Call to virtual method 'S::foo' during construction bypasses virtual dispatch}}
+// CHECK-FIXES: S::foo();
+  }
+  ~S();
+};
Index: clang/test/Analysis/check_analyzer_fixit.py
===
--- /dev/null
+++ clang/test/Analysis/check_analyzer_fixit.py
@@ -0,0 +1,137 @@
+#!/usr/bin/env python
+#
+#===- check_analyzer_fixit.py - Static Analyzer test helper ---*- python -*-===#
+#
+# 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 mostly copy-pasted from the Clang Tidy's 'check_clang_tidy.py'
+#  and some parts from the LLVM Lit's 'config.py'.
+#
+#======#
+
+r"""
+Clang Static Analyzer test helper
+=
+
+This script runs the Analyzer in fix-it mode and verify fixes, warnings, notes.
+
+Usage:
+  check_analyzer_fixit.py   [analyzer arguments]
+
+Example:
+  // RUN: %check_analyzer_fixit %s %t -analyzer-checker=core
+"""
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+
+
+def get_process_output(command):
+  try:
+cmd = subprocess.Popen(
+  command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+stdout, stderr = cmd.communicate()
+return (stdout, stderr)
+  except OSError:
+print('Could not run process %s' % command)
+
+
+def get_clang_builtin_include_dir():
+  clang_dir, _ = get_process_output(['clang', '-print-file-name=include'])
+
+  clang_dir = clang_dir.strip()
+  if sys.platform in ['win32']:
+clang_dir = clang_dir.replace('\\', '/')
+
+  return clang_dir
+
+
+def write_file(file_name, text):
+  with open(file_name, 'w') as f:
+f.write(text)
+f.truncate()
+
+
+def run_test_once(args, extra_args):
+  input_file_name = args.input_file_name
+  temp_file_name = args.temp_file_name
+  clang_analyzer_extra_args = extra_args
+
+  file_name_with_extension = input_file_name
+  _, extension = os.path.splitext(file_name_with_extension)
+  if extension not in ['.c', '.hpp', '.m', '.mm']:
+  extension = '.cpp'
+  temp_file_name = temp_file_name + extension
+
+  with open(input_file_name, 'r') as input_file:
+input_text = input_file.read()
+
+  # Remove the contents of the CHECK lines to avoid CHECKs matching on
+  # themselves.  We need to keep the comments to preserve line numbers while
+  # avoiding empty lines which could potentially trigger formatting-related
+  # checks.
+  cleaned_test = re.sub('// *CHECK-[A-Z0-9\-]*:[^\r\n]*', '//', input_text)
+
+  write_file(temp_file_name, cleaned_test)
+
+  original_file_name = temp_file_name + ".orig"
+  write_file(original_file_name, cleaned_test)
+
+  builtin_include_dir = get_clang_builtin_include_dir()
+  args = (['clang', '-cc1', '-internal-isystem', builtin_include_dir,
+   '-nostdsysteminc', '-analyze', '-analyzer-constraints=range',
+   '-analyzer-config', 'apply-fixits=true']
+   + clang_analyzer_extra_args + ['-verify', temp_file_name])
+
+  print('Running ' + 

[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang Tidy's script

2019-11-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:152
+
+  if (llvm::Error Err = Repls.add(Repl))
+llvm_unreachable("An error occured during fix-it replacements");

zinovy.nis wrote:
> Isn't `llvm_unreacheable` too pessimistic? May be use diagnostics instead?
Good idea, thanks! I was too optimistic so `llvm_unreacheable` should never 
fire.


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

https://reviews.llvm.org/D69746



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


[PATCH] D69781: [analyzer] Add test directory for scan-build

2019-11-03 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin created this revision.
dcoughlin added a reviewer: NoQ.
Herald added subscribers: llvm-commits, cfe-commits, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, delcypher, szepet, 
baloghadamsoftware, xazax.hun.
Herald added projects: clang, LLVM.

The static analyzer's scan-build script is critical infrastructure but
is not well tested. To start to address this, add a new test directory under
tests/Analysis for scan-build lit tests and seed it with several tests. The
goal is that future scan-build changes will be accompanied by corresponding
tests.


Repository:
  rC Clang

https://reviews.llvm.org/D69781

Files:
  
clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory1/file1.c
  
clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory2/file2.c
  clang/test/Analysis/scan-build/Inputs/single_null_dereference.c
  clang/test/Analysis/scan-build/exclude_directories.test
  clang/test/Analysis/scan-build/help.test
  clang/test/Analysis/scan-build/html_output.test
  clang/test/Analysis/scan-build/plist_html_output.test
  clang/test/Analysis/scan-build/plist_output.test
  clang/test/lit.cfg.py
  llvm/utils/lit/lit/llvm/config.py

Index: llvm/utils/lit/lit/llvm/config.py
===
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -411,6 +411,7 @@
 ToolSubst('%clang_cpp', command=self.config.clang, extra_args=['--driver-mode=cpp']+additional_flags),
 ToolSubst('%clang_cl', command=self.config.clang, extra_args=['--driver-mode=cl']+additional_flags),
 ToolSubst('%clangxx', command=self.config.clang, extra_args=['--driver-mode=g++']+additional_flags),
+ToolSubst('%scan-build', command='scan-build'),
 ]
 self.add_tool_substitutions(tool_substitutions)
 
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -62,7 +62,7 @@
 
 tools = [
 'c-index-test', 'clang-diff', 'clang-format', 'clang-tblgen', 'opt', 'llvm-ifs',
-ToolSubst('%clang_extdef_map', command=FindTool(
+'scan-build', ToolSubst('%clang_extdef_map', command=FindTool(
 'clang-extdef-mapping'), unresolved='ignore'),
 ]
 
Index: clang/test/Analysis/scan-build/plist_output.test
===
--- /dev/null
+++ clang/test/Analysis/scan-build/plist_output.test
@@ -0,0 +1,20 @@
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -plist -o %t.output_dir %clang %S/Inputs/single_null_dereference.c \
+RUN: | FileCheck %s -check-prefix CHECK-STDOUT
+
+// Test plist output
+
+CHECK-STDOUT: scan-build: Using '{{.*}}' for static analysis
+CHECK-STDOUT: scan-build: Analysis run complete.
+CHECK-STDOUT: scan-build: Analysis results (plist files) deposited in '{{.*}}'
+
+// We expect a single plist file
+RUN: ls %t.output_dir/*/ | FileCheck %s -check-prefix CHECK-FILENAMES
+
+CHECK-FILENAMES: report-{{.*}}.plist
+
+// The report should describe the issue.
+RUN: cat %t.output_dir/*/report-*.plist \
+RUN: | FileCheck %s -check-prefix CHECK-REPORT-PLIST-CONTENTS
+
+CHECK-REPORT-PLIST-CONTENTS: typeDereference of null pointer
Index: clang/test/Analysis/scan-build/plist_html_output.test
===
--- /dev/null
+++ clang/test/Analysis/scan-build/plist_html_output.test
@@ -0,0 +1,20 @@
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -plist-html -o %t.output_dir %clang %S/Inputs/single_null_dereference.c \
+RUN: | FileCheck %s -check-prefix CHECK-STDOUT
+
+// Test combined plist and html output with -plist-html
+
+CHECK-STDOUT: scan-build: Using '{{.*}}' for static analysis
+CHECK-STDOUT: scan-build: Analysis run complete.
+CHECK-STDOUT: scan-build: Analysis results (plist files) deposited in '{{.*}}'
+CHECK-STDOUT: scan-build: 1 bug found.
+CHECK-STDOUT: scan-build: Run 'scan-view {{.*}}' to examine bug reports.
+
+// We expect both html files and the plist files.
+RUN: ls %t.output_dir/*/ | FileCheck %s -check-prefix CHECK-FILENAMES
+
+CHECK-FILENAMES: index.html
+CHECK-FILENAMES-DAG: report-{{.*}}.html
+CHECK-FILENAMES-DAG: report-{{.*}}.plist
+CHECK-FILENAMES: scanview.css
+CHECK-FILENAMES: sorttable.js
Index: clang/test/Analysis/scan-build/html_output.test
===
--- /dev/null
+++ clang/test/Analysis/scan-build/html_output.test
@@ -0,0 +1,30 @@
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir %clang %S/Inputs/single_null_dereference.c \
+RUN: | FileCheck %s -check-prefix CHECK-STDOUT
+
+// Test html output
+
+CHECK-STDOUT: scan-build: Using '{{.*}}' for static analysis
+CHECK-STDOUT: scan-build: 1 bug found.
+CHECK-STDOUT: scan-build: Run 'scan-view {{.*}}' to examine bug reports.
+
+// We expect 

[PATCH] D69764: [clang-format] Add East Const / West Const fixer

2019-11-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

A demo of `clang-format -i --const-style=east *.cpp *.h` being run on 
clang/lib/Format can be see here D69780: [clang-format]  DO NOT COMMIT - Demo 
of East/West Const Fixer on clang-format 


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

https://reviews.llvm.org/D69764



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


[PATCH] D69764: [clang-format] Add East Const / West Const fixer

2019-11-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 227637.
MyDeveloperDay added a comment.

Support for template object const type declarations


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/EastWestConstFixer.cpp
  clang/lib/Format/EastWestConstFixer.h
  clang/lib/Format/Format.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -27,6 +27,10 @@
 
 FormatStyle getGoogleStyle() { return getGoogleStyle(FormatStyle::LK_Cpp); }
 
+#define VERIFYFORMAT(expect, style) verifyFormat(expect, style, __LINE__)
+#define VERIFYFORMAT2(expect, actual, style)   \
+  verifyFormat(expect, actual, style, __LINE__)
+
 class FormatTest : public ::testing::Test {
 protected:
   enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
@@ -66,10 +70,12 @@
   }
 
   void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
-const FormatStyle  = getLLVMStyle()) {
+const FormatStyle  = getLLVMStyle(),
+int line = __LINE__) {
 EXPECT_EQ(Expected.str(), format(Expected, Style))
-<< "Expected code is not stable";
-EXPECT_EQ(Expected.str(), format(Code, Style));
+<< "Expected code is not stable at " << __FILE__ << ":" << line;
+EXPECT_EQ(Expected.str(), format(Code, Style))
+<< " at " << __FILE__ << ":" << line;
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
   // needs to be checked for Objective-C++ as well.
@@ -80,8 +86,9 @@
   }
 
   void verifyFormat(llvm::StringRef Code,
-const FormatStyle  = getLLVMStyle()) {
-verifyFormat(Code, test::messUp(Code), Style);
+const FormatStyle  = getLLVMStyle(),
+int line = __LINE__) {
+verifyFormat(Code, test::messUp(Code), Style, line);
   }
 
   void verifyIncompleteFormat(llvm::StringRef Code,
@@ -12502,6 +12509,11 @@
   CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
 
+  Style.ConstStyle = FormatStyle::CS_West;
+  CHECK_PARSE("ConstStyle: Leave", ConstStyle, FormatStyle::CS_Leave);
+  CHECK_PARSE("ConstStyle: East", ConstStyle, FormatStyle::CS_East);
+  CHECK_PARSE("ConstStyle: West", ConstStyle, FormatStyle::CS_West);
+
   Style.PointerAlignment = FormatStyle::PAS_Middle;
   CHECK_PARSE("PointerAlignment: Left", PointerAlignment,
   FormatStyle::PAS_Left);
@@ -14728,6 +14740,118 @@
"#endif // while");
 }
 
+TEST_F(FormatTest, EastWestConst) {
+  FormatStyle Style = getLLVMStyle();
+
+  // keep the const style unaltered
+  VERIFYFORMAT("const int a;", Style);
+  VERIFYFORMAT("const int *a;", Style);
+  VERIFYFORMAT("const int ", Style);
+  VERIFYFORMAT("const int &", Style);
+  VERIFYFORMAT("int const b;", Style);
+  VERIFYFORMAT("int const *b;", Style);
+  VERIFYFORMAT("int const ", Style);
+  VERIFYFORMAT("int const &", Style);
+  VERIFYFORMAT("int const *b const;", Style);
+  VERIFYFORMAT("int *const c;", Style);
+
+  VERIFYFORMAT("const Foo a;", Style);
+  VERIFYFORMAT("const Foo *a;", Style);
+  VERIFYFORMAT("const Foo ", Style);
+  VERIFYFORMAT("const Foo &", Style);
+  VERIFYFORMAT("Foo const b;", Style);
+  VERIFYFORMAT("Foo const *b;", Style);
+  VERIFYFORMAT("Foo const ", Style);
+  VERIFYFORMAT("Foo const &", Style);
+  VERIFYFORMAT("Foo const *b const;", Style);
+
+  Style.ConstStyle = FormatStyle::CS_East;
+
+  VERIFYFORMAT("int const a;", Style);
+  VERIFYFORMAT("int const *a;", Style);
+  VERIFYFORMAT("int const ", Style);
+  VERIFYFORMAT("int const &", Style);
+  VERIFYFORMAT("int const b;", Style);
+  VERIFYFORMAT("int const *b;", Style);
+  VERIFYFORMAT("int const ", Style);
+  VERIFYFORMAT("int const &", Style);
+  VERIFYFORMAT("int const *b const;", Style);
+  VERIFYFORMAT("int *const c;", Style);
+
+  VERIFYFORMAT("Foo const a;", Style);
+  VERIFYFORMAT("Foo const *a;", Style);
+  VERIFYFORMAT("Foo const ", Style);
+  VERIFYFORMAT("Foo const &", Style);
+  VERIFYFORMAT("Foo const b;", Style);
+  VERIFYFORMAT("Foo const *b;", Style);
+  VERIFYFORMAT("Foo const ", Style);
+  VERIFYFORMAT("Foo const &", Style);
+  VERIFYFORMAT("Foo const *b const;", Style);
+  VERIFYFORMAT("Foo *const b;", Style);
+  VERIFYFORMAT("Foo const *const b;", Style);
+  VERIFYFORMAT("auto const v = get_value();", Style);
+  VERIFYFORMAT("long long const ", Style);
+  VERIFYFORMAT("unsigned char const *a;", Style);
+  VERIFYFORMAT("int main(int const argc, 

[PATCH] D57829: [CUDA][HIP] Disable emitting llvm.linker.options in device compilation

2019-11-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 227636.
yaxunl added a comment.

revised by Artem's comments. Also fix test since linker option only supported 
on windows.


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

https://reviews.llvm.org/D57829

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCUDA/linker-options.cu
  clang/test/Driver/hip-autolink.hip


Index: clang/test/Driver/hip-autolink.hip
===
--- /dev/null
+++ clang/test/Driver/hip-autolink.hip
@@ -0,0 +1,14 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+//
+// RUN: %clang --target=i386-pc-windows-msvc --cuda-gpu-arch=gfx906 -nogpulib \
+// RUN:   --cuda-device-only -x hip %s -### 2>&1 | FileCheck 
--check-prefix=DEV %s
+// RUN: %clang --target=i386-pc-windows-msvc --cuda-gpu-arch=gfx906 -nogpulib \
+// RUN:   --cuda-host-only -x hip %s -### 2>&1 | FileCheck --check-prefix=HOST 
%s
+
+// DEV: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// DEV-SAME: "-fno-autolink"
+
+// HOST: "-cc1" "-triple" "i386-pc-windows-msvc{{.*}}"
+// HOST-NOT: "-fno-autolink"
Index: clang/test/CodeGenCUDA/linker-options.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/linker-options.cu
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -emit-llvm -o - -fcuda-is-device -fms-extensions -x hip %s \
+// RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
+// RUN:   | FileCheck -check-prefix=DEV %s
+// RUN: %clang_cc1 -emit-llvm -o - -fms-extensions -x hip %s -triple \
+// RUN:x86_64-pc-windows-msvc | FileCheck -check-prefix=HOST %s
+
+// DEV-NOT: llvm.linker.options
+// DEV-NOT: llvm.dependent-libraries
+// HOST: lvm.linker.options
+// HOST: "/DEFAULTLIB:libcpmt.lib"
+// HOST: "/FAILIFMISMATCH:\22myLib_version=9\22"
+
+#pragma comment(lib, "libcpmt")
+#pragma detect_mismatch("myLib_version", "9")
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -378,15 +378,20 @@
 CmdArgs.push_back("-fexceptions");
 }
 
-static bool ShouldDisableAutolink(const ArgList , const ToolChain ) {
+static bool ShouldEnableAutolink(const ArgList , const ToolChain ,
+ const JobAction ) {
   bool Default = true;
   if (TC.getTriple().isOSDarwin()) {
 // The native darwin assembler doesn't support the linker_option 
directives,
 // so we disable them if we think the .s file will be passed to it.
 Default = TC.useIntegratedAs();
   }
-  return !Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink,
-   Default);
+  // The linker_option directives are intended for host compilation.
+  if (JA.isDeviceOffloading(Action::OFK_Cuda) ||
+  JA.isDeviceOffloading(Action::OFK_HIP))
+Default = false;
+  return Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink,
+  Default);
 }
 
 static bool ShouldDisableDwarfDirectory(const ArgList ,
@@ -4385,7 +4390,7 @@
   if (ShouldDisableDwarfDirectory(Args, TC))
 CmdArgs.push_back("-fno-dwarf-directory-asm");
 
-  if (ShouldDisableAutolink(Args, TC))
+  if (!ShouldEnableAutolink(Args, TC, JA))
 CmdArgs.push_back("-fno-autolink");
 
   // Add in -fdebug-compilation-dir if necessary.


Index: clang/test/Driver/hip-autolink.hip
===
--- /dev/null
+++ clang/test/Driver/hip-autolink.hip
@@ -0,0 +1,14 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+//
+// RUN: %clang --target=i386-pc-windows-msvc --cuda-gpu-arch=gfx906 -nogpulib \
+// RUN:   --cuda-device-only -x hip %s -### 2>&1 | FileCheck --check-prefix=DEV %s
+// RUN: %clang --target=i386-pc-windows-msvc --cuda-gpu-arch=gfx906 -nogpulib \
+// RUN:   --cuda-host-only -x hip %s -### 2>&1 | FileCheck --check-prefix=HOST %s
+
+// DEV: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// DEV-SAME: "-fno-autolink"
+
+// HOST: "-cc1" "-triple" "i386-pc-windows-msvc{{.*}}"
+// HOST-NOT: "-fno-autolink"
Index: clang/test/CodeGenCUDA/linker-options.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/linker-options.cu
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -emit-llvm -o - -fcuda-is-device -fms-extensions -x hip %s \
+// RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
+// RUN:   | FileCheck -check-prefix=DEV %s
+// RUN: %clang_cc1 -emit-llvm -o - -fms-extensions -x hip %s -triple \
+// RUN:x86_64-pc-windows-msvc | FileCheck -check-prefix=HOST %s
+
+// DEV-NOT: llvm.linker.options
+// DEV-NOT: llvm.dependent-libraries
+// HOST: lvm.linker.options
+// HOST: "/DEFAULTLIB:libcpmt.lib"
+// HOST: "/FAILIFMISMATCH:\22myLib_version=9\22"
+
+#pragma comment(lib, "libcpmt")
+#pragma detect_mismatch("myLib_version", 

[PATCH] D69779: -fmodules-codegen should not emit extern templates

2019-11-03 Thread Luboš Luňák via Phabricator via cfe-commits
llunak created this revision.
llunak added a reviewer: dblaikie.
llunak added a project: clang.
Herald added a subscriber: cfe-commits.

See the test for a testcase. If a header contains 'extern template', then the 
template should be provided somewhere by an explicit instantiation, so it is 
not necessary to generate a copy. Worse (at least with PCH 
-building-pch-with-obj), the current code actually leads to an unresolved 
symbol, because the PCH's object file will not actually contain functions from 
such a template (because of the GVA_AvailableExternally?), but the object file 
for the explicit instantiation will not contain them either because it will be 
blocked by the information provided by the PCH. I don't know if the same 
problem exists with modules (nor I know how to check for sure), all tests pass. 
If the problem is not there for modules, I can make the change PCH-specific.


Repository:
  rC Clang

https://reviews.llvm.org/D69779

Files:
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/PCH/codegen-extern-template.cpp
  clang/test/PCH/codegen-extern-template.h


Index: clang/test/PCH/codegen-extern-template.h
===
--- /dev/null
+++ clang/test/PCH/codegen-extern-template.h
@@ -0,0 +1,16 @@
+// header for codegen-extern-template.cpp
+#pragma once
+
+template< typename T >
+struct A
+{
+   T foo() { return 10;}
+};
+
+extern template struct A< int >;
+
+inline
+int bar(A* p)
+{
+return p->foo();
+}
Index: clang/test/PCH/codegen-extern-template.cpp
===
--- /dev/null
+++ clang/test/PCH/codegen-extern-template.cpp
@@ -0,0 +1,21 @@
+// Build the PCH with extern template.
+// RUN: %clang -x c++-header %S/codegen-extern-template.h -o %t.pch -Xclang 
-building-pch-with-obj -Xclang -fmodules-codegen
+// Build the PCH's object file.
+// RUN: %clang -c %s -include-pch %t.pch -Xclang -building-pch-with-obj 
-Xclang -fmodules-codegen -o %t.1.o
+// Build source with explicit template instantiation.
+// RUN: %clang -c %s -DMAIN -include-pch %t.pch -o %t.2.o
+// There should be no unresolved symbol.
+// RUN: %clang %t.1.o %t.2.o
+// expected-no-diagnostics
+
+#include "codegen-extern-template.h"
+
+#ifdef MAIN
+template struct A< int >;
+int main()
+{
+A< int > a;
+return bar();
+}
+
+#endif
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2412,11 +2412,12 @@
 }
 if (Writer->Context->getLangOpts().ModulesCodegen) {
   // Under -fmodules-codegen, codegen is performed for all non-internal,
-  // non-always_inline functions.
+  // non-always_inline functions, unless they are available elsewhere.
   if (!FD->hasAttr()) {
 if (!Linkage)
   Linkage = Writer->Context->GetGVALinkageForFunction(FD);
-ModulesCodegen = *Linkage != GVA_Internal;
+ModulesCodegen =
+*Linkage != GVA_Internal && *Linkage != GVA_AvailableExternally;
   }
 }
   }


Index: clang/test/PCH/codegen-extern-template.h
===
--- /dev/null
+++ clang/test/PCH/codegen-extern-template.h
@@ -0,0 +1,16 @@
+// header for codegen-extern-template.cpp
+#pragma once
+
+template< typename T >
+struct A
+{
+   T foo() { return 10;}
+};
+
+extern template struct A< int >;
+
+inline
+int bar(A* p)
+{
+return p->foo();
+}
Index: clang/test/PCH/codegen-extern-template.cpp
===
--- /dev/null
+++ clang/test/PCH/codegen-extern-template.cpp
@@ -0,0 +1,21 @@
+// Build the PCH with extern template.
+// RUN: %clang -x c++-header %S/codegen-extern-template.h -o %t.pch -Xclang -building-pch-with-obj -Xclang -fmodules-codegen
+// Build the PCH's object file.
+// RUN: %clang -c %s -include-pch %t.pch -Xclang -building-pch-with-obj -Xclang -fmodules-codegen -o %t.1.o
+// Build source with explicit template instantiation.
+// RUN: %clang -c %s -DMAIN -include-pch %t.pch -o %t.2.o
+// There should be no unresolved symbol.
+// RUN: %clang %t.1.o %t.2.o
+// expected-no-diagnostics
+
+#include "codegen-extern-template.h"
+
+#ifdef MAIN
+template struct A< int >;
+int main()
+{
+A< int > a;
+return bar();
+}
+
+#endif
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2412,11 +2412,12 @@
 }
 if (Writer->Context->getLangOpts().ModulesCodegen) {
   // Under -fmodules-codegen, codegen is performed for all non-internal,
-  // non-always_inline functions.
+  // non-always_inline functions, unless they are available elsewhere.
   if (!FD->hasAttr()) {
 if (!Linkage)
   Linkage = 

[PATCH] D69778: Make -fmodules-codegen and -fmodules-debuginfo work also with precompiled headers

2019-11-03 Thread Luboš Luňák via Phabricator via cfe-commits
llunak created this revision.
llunak added a reviewer: dblaikie.
llunak added a project: clang.
Herald added a subscriber: cfe-commits.

This patch allows to build PCH's (with -building-pch-with-obj and the extra .o 
file) with -fmodules-codegen -fmodules-debuginfo to allow emitting shared code 
into the extra .o file (presumably similarly how modules emit that to wherever 
they emit it). This saves up to 20% of build time here. I can build pretty much 
a complete debug build of LibreOffice with this, with just two minor problems 
(to be sorted out later).

The patch is fairly simple, it basically just duplicates -fmodules checks to 
also alternatively check -building-pch-with-obj.


Repository:
  rC Clang

https://reviews.llvm.org/D69778

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Modules/Inputs/codegen-flags/foo.h
  clang/test/PCH/codegen.cpp

Index: clang/test/PCH/codegen.cpp
===
--- /dev/null
+++ clang/test/PCH/codegen.cpp
@@ -0,0 +1,30 @@
+// This test is the PCH version of Modules/codegen-flags.test . It uses its inputs.
+// The purpose of this test is just verify that the codegen options work with PCH as well.
+// All the codegen functionality should be tested in Modules/.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// REQUIRES: x86-registered-target
+
+// RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++-header -building-pch-with-obj -emit-pch %S/../Modules/Inputs/codegen-flags/foo.h -o %t/foo-cg.pch
+// RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-debuginfo -x c++-header -building-pch-with-obj -emit-pch %S/../Modules/Inputs/codegen-flags/foo.h -o %t/foo-di.pch
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - %s -include-pch %t/foo-cg.pch -building-pch-with-obj -fmodules-codegen | FileCheck --check-prefix=CG %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - %s -include-pch %t/foo-di.pch -building-pch-with-obj -fmodules-debuginfo | FileCheck --check-prefix=DI %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - -include-pch %t/foo-cg.pch %S/../Modules/Inputs/codegen-flags/use.cpp | FileCheck --check-prefix=CG-USE %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - -include-pch %t/foo-di.pch %S/../Modules/Inputs/codegen-flags/use.cpp | FileCheck --check-prefix=DI-USE %s
+
+// CG: define weak_odr void @_Z2f1v
+// CG: DICompileUnit
+// CG-NOT: DICompositeType
+
+// CG-USE: declare void @_Z2f1v
+// CG-USE: DICompileUnit
+// CG-USE: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
+
+// DI-NOT: define
+// DI: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
+
+// DI-USE: define linkonce_odr void @_Z2f1v
+// DI-USE: = !DICompositeType(tag: DW_TAG_structure_type, name: "foo", {{.*}}, flags: DIFlagFwdDecl
Index: clang/test/Modules/Inputs/codegen-flags/foo.h
===
--- clang/test/Modules/Inputs/codegen-flags/foo.h
+++ clang/test/Modules/Inputs/codegen-flags/foo.h
@@ -1,3 +1,4 @@
+#pragma once
 struct foo {
 };
 inline void f1() {
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -990,15 +990,16 @@
 
   if (D->getStorageDuration() == SD_Static) {
 bool ModulesCodegen = false;
-if (Writer.WritingModule &&
-!D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
+if (!D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
 !isa(D)) {
   // When building a C++ Modules TS module interface unit, a strong
   // definition in the module interface is provided by the compilation of
   // that module interface unit, not by its users. (Inline variables are
   // still emitted in module users.)
   ModulesCodegen =
-  (Writer.WritingModule->Kind == Module::ModuleInterfaceUnit &&
+  (((Writer.WritingModule &&
+ Writer.WritingModule->Kind == Module::ModuleInterfaceUnit) ||
+Writer.Context->getLangOpts().BuildingPCHWithObjectFile) &&
Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal);
 }
 Record.push_back(ModulesCodegen);
@@ -2397,9 +2398,11 @@
 
   assert(FD->doesThisDeclarationHaveABody());
   bool ModulesCodegen = false;
-  if (Writer->WritingModule && !FD->isDependentContext()) {
+  if (!FD->isDependentContext()) {
 Optional Linkage;
-if (Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) {
+if ((Writer->WritingModule &&
+ Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) ||
+

[PATCH] D69770: Add recoverable string parsing errors to APFloat

2019-11-03 Thread Ehud Katz via Phabricator via cfe-commits
ekatz created this revision.
ekatz added reviewers: chandlerc, lattner, rsmith.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith, hiraditya, 
nhaehnle, jvesely, arsenm.
Herald added projects: clang, LLVM.

Implementing the APFloat part in PR4745.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69770

Files:
  clang/lib/Lex/LiteralSupport.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/lib/Support/APFloat.cpp
  llvm/lib/Support/StringRef.cpp
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
  llvm/unittests/ADT/APFloatTest.cpp

Index: llvm/unittests/ADT/APFloatTest.cpp
===
--- llvm/unittests/ADT/APFloatTest.cpp
+++ llvm/unittests/ADT/APFloatTest.cpp
@@ -10,8 +10,8 @@
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -20,9 +20,17 @@
 
 using namespace llvm;
 
-static double convertToDoubleFromString(const char *Str) {
+static std::string convertToErrorFromString(StringRef Str) {
   llvm::APFloat F(0.0);
-  F.convertFromString(Str, llvm::APFloat::rmNearestTiesToEven);
+  auto ErrOrStatus =
+  F.convertFromString(Str, llvm::APFloat::rmNearestTiesToEven);
+  EXPECT_TRUE(!ErrOrStatus);
+  return toString(ErrOrStatus.takeError());
+}
+
+static double convertToDoubleFromString(StringRef Str) {
+  llvm::APFloat F(0.0);
+  EXPECT_FALSE(!F.convertFromString(Str, llvm::APFloat::rmNearestTiesToEven));
   return F.convertToDouble();
 }
 
@@ -1147,172 +1155,172 @@
   EXPECT_DEATH(APFloat(APFloat::IEEEsingle(), 0.0f).convertToDouble(), "Float semantics are not IEEEdouble");
   EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), 0.0 ).convertToFloat(),  "Float semantics are not IEEEsingle");
 }
+#endif
+#endif
 
-TEST(APFloatTest, StringDecimalDeath) {
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(),  ""), "Invalid string length");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+"), "String has no digits");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-"), "String has no digits");
+TEST(APFloatTest, StringDecimalError) {
+  EXPECT_EQ(convertToErrorFromString(""), "Invalid string length");
+  EXPECT_EQ(convertToErrorFromString("+"), "String has no digits");
+  EXPECT_EQ(convertToErrorFromString("-"), "String has no digits");
 
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("\0", 1)), "Invalid character in significand");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1\0", 2)), "Invalid character in significand");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1" "\0" "2", 3)), "Invalid character in significand");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1" "\0" "2e1", 5)), "Invalid character in significand");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1e\0", 3)), "Invalid character in exponent");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1e1\0", 4)), "Invalid character in exponent");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1e1" "\0" "2", 5)), "Invalid character in exponent");
+  EXPECT_EQ(convertToErrorFromString(StringRef("\0", 1)), "Invalid character in significand");
+  EXPECT_EQ(convertToErrorFromString(StringRef("1\0", 2)), "Invalid character in significand");
+  EXPECT_EQ(convertToErrorFromString(StringRef("1" "\0" "2", 3)), "Invalid character in significand");
+  EXPECT_EQ(convertToErrorFromString(StringRef("1" "\0" "2e1", 5)), "Invalid character in significand");
+  EXPECT_EQ(convertToErrorFromString(StringRef("1e\0", 3)), "Invalid character in exponent");
+  EXPECT_EQ(convertToErrorFromString(StringRef("1e1\0", 4)), "Invalid character in exponent");
+  EXPECT_EQ(convertToErrorFromString(StringRef("1e1" "\0" "2", 5)), "Invalid character in exponent");
 
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.0f"), "Invalid character in significand");
+  EXPECT_EQ(convertToErrorFromString("1.0f"), "Invalid character in significand");
 
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ".."), "String contains multiple dots");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "..0"), "String contains multiple dots");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.0.0"), "String contains multiple dots");
+  EXPECT_EQ(convertToErrorFromString(".."), "String contains multiple dots");
+  EXPECT_EQ(convertToErrorFromString("..0"), "String contains multiple dots");
+  EXPECT_EQ(convertToErrorFromString("1.0.0"), "String contains multiple dots");
 }
 
-TEST(APFloatTest, StringDecimalSignificandDeath) {
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(),  "."), "Significand has no digits");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+."), "Significand has no digits");
-  EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-."), "Significand has no 

[PATCH] D69769: [Clang][Driver] Don't pun -fuse-ld=lld as -fuse-ld=lld-link with msvc

2019-11-03 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 created this revision.
Herald added subscribers: cfe-commits, mstorsjo.
Herald added a project: clang.

Besides the Mingw toolchain, there is also the CrossWindows toolchain,
which means GNU-style cli but genuine windows headers + libraries. LLD's
MinGW driver is as good a fit as binutil's ld, but there is no easy way
to select it when lld was being rewritten to lld-link.

This makes lld always be the GNU-style one, consistent with the non-msvc
case. It's a small breaking change for Windows, but the only
straightforward way.

It may seem silly to worry about the gnu-style flags, but it is useful
for mixing software designed with MinGW in mind with "real" windows
software that needs a MSVC C++ ABI, C++ threads, etc.

Testing in conjunction with https://github.com/NixOS/nixpkgs/pull/72366,
which might be the first fully automated way to cross compile to
Windows.  I haven't taught Nixpkgs to wrap clang-cl like it wraps clang,
so even for some packages that have separate MSVC and MinGW builds
systems (e.g. zlib, opensll), I seem to be having better luck with the
MinGW-style builds so am going with that.

Backport of D69760  for release 8


Repository:
  rC Clang

https://reviews.llvm.org/D69769

Files:
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/MSVC.cpp
  test/Driver/fuse-ld.c


Index: test/Driver/fuse-ld.c
===
--- test/Driver/fuse-ld.c
+++ test/Driver/fuse-ld.c
@@ -78,8 +78,13 @@
 // RUN: %clang %s -### -fuse-ld=lld \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
-// CHECK-WINDOWS-MSVC-LLD: "{{.*}}lld-link"
-// CHECK-WINDOWS-MSVC-LLD-SAME: "-out:{{.*}}"
+// CHECK-WINDOWS-MSVC-LLD: "{{.*}}ld.lld"
+// CHECK-WINDOWS-MSVC-LLD-SAME: "-o"
+
+// RUN: %clang-cl %s -### -fuse-ld=lld \
+// RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
+// CHECK-cl-WINDOWS-MSVC-LLD: "{{.*}}ld.lld"
+// CHECK-cl-WINDOWS-MSVC-LLD-SAME: "-o"
 
 // RUN: %clang %s -### -fuse-ld=lld-link \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -475,13 +475,10 @@
 
   std::vector Environment;
 
-  // We need to special case some linker paths.  In the case of lld, we need to
-  // translate 'lld' into 'lld-link', and in the case of the regular msvc
+  // We need to special case some linker paths.  In the case of the regular 
msvc
   // linker, we need to use a special search algorithm.
   llvm::SmallString<128> linkPath;
   StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "link");
-  if (Linker.equals_lower("lld"))
-Linker = "lld-link";
 
   if (Linker.equals_lower("link")) {
 // If we're using the MSVC linker, it's not sufficient to just use link
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -4592,8 +4592,8 @@
 break;
   case llvm::Triple::MSVC:
   case llvm::Triple::UnknownEnvironment:
-if (Args.getLastArgValue(options::OPT_fuse_ld_EQ)
-.startswith_lower("bfd"))
+auto linkerFlavor = Args.getLastArgValue(options::OPT_fuse_ld_EQ);
+if (linkerFlavor.startswith_lower("bfd") || 
linkerFlavor.equals_lower("lld"))
   TC = llvm::make_unique(
   *this, Target, Args);
 else


Index: test/Driver/fuse-ld.c
===
--- test/Driver/fuse-ld.c
+++ test/Driver/fuse-ld.c
@@ -78,8 +78,13 @@
 // RUN: %clang %s -### -fuse-ld=lld \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
-// CHECK-WINDOWS-MSVC-LLD: "{{.*}}lld-link"
-// CHECK-WINDOWS-MSVC-LLD-SAME: "-out:{{.*}}"
+// CHECK-WINDOWS-MSVC-LLD: "{{.*}}ld.lld"
+// CHECK-WINDOWS-MSVC-LLD-SAME: "-o"
+
+// RUN: %clang-cl %s -### -fuse-ld=lld \
+// RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
+// CHECK-cl-WINDOWS-MSVC-LLD: "{{.*}}ld.lld"
+// CHECK-cl-WINDOWS-MSVC-LLD-SAME: "-o"
 
 // RUN: %clang %s -### -fuse-ld=lld-link \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -475,13 +475,10 @@
 
   std::vector Environment;
 
-  // We need to special case some linker paths.  In the case of lld, we need to
-  // translate 'lld' into 'lld-link', and in the case of the regular msvc
+  // We need to special case some linker paths.  In the case of the regular msvc
   // linker, we need to use a special search algorithm.
   llvm::SmallString<128> linkPath;
   StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ, 

[PATCH] D69756: [opaque pointer types] Add element type argument to IRBuilder CreatePreserveStructAccessIndex and CreatePreserveArrayAccessIndex

2019-11-03 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG910718bd038c: [opaque pointer types] Add element type 
argument to IRBuilder… (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69756

Files:
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGExpr.cpp
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Instructions.h


Index: llvm/include/llvm/IR/Instructions.h
===
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -1039,11 +1039,6 @@
 
   /// Returns the pointer type returned by the GEP
   /// instruction, which may be a vector of pointers.
-  static Type *getGEPReturnType(Value *Ptr, ArrayRef IdxList) {
-return getGEPReturnType(
-  cast(Ptr->getType()->getScalarType())->getElementType(),
-  Ptr, IdxList);
-  }
   static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
 ArrayRef IdxList) {
 Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -2521,8 +2521,9 @@
 return V;
   }
 
-  Value *CreatePreserveArrayAccessIndex(Value *Base, unsigned Dimension,
-unsigned LastIndex, MDNode *DbgInfo) {
+  Value *CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base,
+unsigned Dimension, unsigned LastIndex,
+MDNode *DbgInfo) {
 assert(isa(Base->getType()) &&
"Invalid Base ptr type for preserve.array.access.index.");
 auto *BaseType = Base->getType();
@@ -2535,7 +2536,7 @@
 IdxList.push_back(LastIndexV);
 
 Type *ResultType =
-GetElementPtrInst::getGEPReturnType(Base, IdxList);
+GetElementPtrInst::getGEPReturnType(ElTy, Base, IdxList);
 
 Module *M = BB->getParent()->getParent();
 Function *FnPreserveArrayAccessIndex = Intrinsic::getDeclaration(
@@ -2569,8 +2570,9 @@
 return Fn;
   }
 
-  Value *CreatePreserveStructAccessIndex(Value *Base, unsigned Index,
- unsigned FieldIndex, MDNode *DbgInfo) 
{
+  Value *CreatePreserveStructAccessIndex(Type *ElTy, Value *Base,
+ unsigned Index, unsigned FieldIndex,
+ MDNode *DbgInfo) {
 assert(isa(Base->getType()) &&
"Invalid Base ptr type for preserve.struct.access.index.");
 auto *BaseType = Base->getType();
@@ -2578,7 +2580,7 @@
 Value *GEPIndex = getInt32(Index);
 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
 Type *ResultType =
-GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
+GetElementPtrInst::getGEPReturnType(ElTy, Base, {Zero, GEPIndex});
 
 Module *M = BB->getParent()->getParent();
 Function *FnPreserveStructAccessIndex = Intrinsic::getDeclaration(
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -3438,7 +3438,8 @@
 llvm::DIType *DbgInfo = nullptr;
 if (arrayType)
   DbgInfo = CGF.getDebugInfo()->getOrCreateStandaloneType(*arrayType, loc);
-eltPtr = CGF.Builder.CreatePreserveArrayAccessIndex(addr.getPointer(),
+eltPtr = CGF.Builder.CreatePreserveArrayAccessIndex(addr.getElementType(),
+addr.getPointer(),
 indices.size() - 1,
 idx, DbgInfo);
   }
Index: clang/lib/CodeGen/CGBuilder.h
===
--- clang/lib/CodeGen/CGBuilder.h
+++ clang/lib/CodeGen/CGBuilder.h
@@ -309,7 +309,7 @@
 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
 auto Offset = CharUnits::fromQuantity(Layout->getElementOffset(Index));
 
-return Address(CreatePreserveStructAccessIndex(Addr.getPointer(),
+return Address(CreatePreserveStructAccessIndex(ElTy, Addr.getPointer(),
Index, FieldIndex, DbgInfo),
Addr.getAlignment().alignmentAtOffset(Offset));
   }


Index: llvm/include/llvm/IR/Instructions.h
===
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -1039,11 +1039,6 @@
 
   /// Returns the pointer type returned by the GEP
   /// instruction, which may be a vector of pointers.
-  static Type *getGEPReturnType(Value *Ptr, ArrayRef IdxList) {
-return 

[clang] 910718b - [opaque pointer types] Add element type argument to IRBuilder CreatePreserveStructAccessIndex and CreatePreserveArrayAccessIndex

2019-11-03 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2019-11-03T10:27:18-08:00
New Revision: 910718bd038cdac1671069594a11f6b26bad9c8b

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

LOG: [opaque pointer types] Add element type argument to IRBuilder 
CreatePreserveStructAccessIndex and CreatePreserveArrayAccessIndex

Summary:
These were the only remaining users of the GetElementPtrInst::getGEPReturnType
method that gets the element type from the pointer type.

Remove that method since its now dead.

Reviewers: jyknight, t.p.northover, arsenm

Reviewed By: arsenm

Subscribers: wdng, arsenm, arphaman, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGExpr.cpp
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/Instructions.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 68c8c641139f..dae3fbbc4b9f 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -309,7 +309,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
 auto Offset = CharUnits::fromQuantity(Layout->getElementOffset(Index));
 
-return Address(CreatePreserveStructAccessIndex(Addr.getPointer(),
+return Address(CreatePreserveStructAccessIndex(ElTy, Addr.getPointer(),
Index, FieldIndex, DbgInfo),
Addr.getAlignment().alignmentAtOffset(Offset));
   }

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index dcd365c8eaf0..99406715cbf8 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3438,7 +3438,8 @@ static Address emitArraySubscriptGEP(CodeGenFunction 
, Address addr,
 llvm::DIType *DbgInfo = nullptr;
 if (arrayType)
   DbgInfo = CGF.getDebugInfo()->getOrCreateStandaloneType(*arrayType, loc);
-eltPtr = CGF.Builder.CreatePreserveArrayAccessIndex(addr.getPointer(),
+eltPtr = CGF.Builder.CreatePreserveArrayAccessIndex(addr.getElementType(),
+addr.getPointer(),
 indices.size() - 1,
 idx, DbgInfo);
   }

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index 05f311d8b72d..f556db7893c4 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2521,8 +2521,9 @@ class IRBuilder : public IRBuilderBase, public Inserter {
 return V;
   }
 
-  Value *CreatePreserveArrayAccessIndex(Value *Base, unsigned Dimension,
-unsigned LastIndex, MDNode *DbgInfo) {
+  Value *CreatePreserveArrayAccessIndex(Type *ElTy, Value *Base,
+unsigned Dimension, unsigned LastIndex,
+MDNode *DbgInfo) {
 assert(isa(Base->getType()) &&
"Invalid Base ptr type for preserve.array.access.index.");
 auto *BaseType = Base->getType();
@@ -2535,7 +2536,7 @@ class IRBuilder : public IRBuilderBase, public Inserter {
 IdxList.push_back(LastIndexV);
 
 Type *ResultType =
-GetElementPtrInst::getGEPReturnType(Base, IdxList);
+GetElementPtrInst::getGEPReturnType(ElTy, Base, IdxList);
 
 Module *M = BB->getParent()->getParent();
 Function *FnPreserveArrayAccessIndex = Intrinsic::getDeclaration(
@@ -2569,8 +2570,9 @@ class IRBuilder : public IRBuilderBase, public Inserter {
 return Fn;
   }
 
-  Value *CreatePreserveStructAccessIndex(Value *Base, unsigned Index,
- unsigned FieldIndex, MDNode *DbgInfo) 
{
+  Value *CreatePreserveStructAccessIndex(Type *ElTy, Value *Base,
+ unsigned Index, unsigned FieldIndex,
+ MDNode *DbgInfo) {
 assert(isa(Base->getType()) &&
"Invalid Base ptr type for preserve.struct.access.index.");
 auto *BaseType = Base->getType();
@@ -2578,7 +2580,7 @@ class IRBuilder : public IRBuilderBase, public Inserter {
 Value *GEPIndex = getInt32(Index);
 Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
 Type *ResultType =
-GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
+GetElementPtrInst::getGEPReturnType(ElTy, Base, {Zero, GEPIndex});
 
 Module *M = BB->getParent()->getParent();
 Function *FnPreserveStructAccessIndex = Intrinsic::getDeclaration(

diff  --git a/llvm/include/llvm/IR/Instructions.h 
b/llvm/include/llvm/IR/Instructions.h
index 

[PATCH] D69760: [Clang][Driver] Don't pun -fuse-ld=lld as -fuse-ld=lld-link with msvc

2019-11-03 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 227621.
Ericson2314 retitled this revision from "Better clang cross windows with 
gnu-style flags" to "Clang][Driver] Don't pun -fuse-ld=lld as -fuse-ld=lld-link 
with msvc".
Ericson2314 edited the summary of this revision.
Ericson2314 added a comment.

Split out some changes into other diffs. 1 we are stacked on, the other 2 are 
independent and not stacked on,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69760

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/fuse-ld.c


Index: clang/test/Driver/fuse-ld.c
===
--- clang/test/Driver/fuse-ld.c
+++ clang/test/Driver/fuse-ld.c
@@ -79,8 +79,13 @@
 // RUN: %clang %s -### -fuse-ld=lld \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
-// CHECK-WINDOWS-MSVC-LLD: "{{.*}}lld-link"
-// CHECK-WINDOWS-MSVC-LLD-SAME: "-out:{{.*}}"
+// CHECK-WINDOWS-MSVC-LLD: "{{.*}}ld.lld"
+// CHECK-WINDOWS-MSVC-LLD-SAME: "-o"
+
+// RUN: %clang-cl %s -### -fuse-ld=lld \
+// RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
+// CHECK-cl-WINDOWS-MSVC-LLD: "{{.*}}ld.lld"
+// CHECK-cl-WINDOWS-MSVC-LLD-SAME: "-o"
 
 // RUN: %clang %s -### -fuse-ld=lld-link \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -490,13 +490,10 @@
 
   std::vector Environment;
 
-  // We need to special case some linker paths.  In the case of lld, we need to
-  // translate 'lld' into 'lld-link', and in the case of the regular msvc
+  // We need to special case some linker paths.  In the case of the regular 
msvc
   // linker, we need to use a special search algorithm.
   llvm::SmallString<128> linkPath;
   StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "link");
-  if (Linker.equals_lower("lld"))
-Linker = "lld-link";
 
   if (Linker.equals_lower("link")) {
 // If we're using the MSVC linker, it's not sufficient to just use link
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4785,8 +4785,8 @@
 break;
   case llvm::Triple::MSVC:
   case llvm::Triple::UnknownEnvironment:
-if (Args.getLastArgValue(options::OPT_fuse_ld_EQ)
-.startswith_lower("bfd"))
+auto linkerFlavor = Args.getLastArgValue(options::OPT_fuse_ld_EQ);
+if (linkerFlavor.startswith_lower("bfd") || 
linkerFlavor.equals_lower("lld")
   TC = std::make_unique(
   *this, Target, Args);
 else


Index: clang/test/Driver/fuse-ld.c
===
--- clang/test/Driver/fuse-ld.c
+++ clang/test/Driver/fuse-ld.c
@@ -79,8 +79,13 @@
 // RUN: %clang %s -### -fuse-ld=lld \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
-// CHECK-WINDOWS-MSVC-LLD: "{{.*}}lld-link"
-// CHECK-WINDOWS-MSVC-LLD-SAME: "-out:{{.*}}"
+// CHECK-WINDOWS-MSVC-LLD: "{{.*}}ld.lld"
+// CHECK-WINDOWS-MSVC-LLD-SAME: "-o"
+
+// RUN: %clang-cl %s -### -fuse-ld=lld \
+// RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD
+// CHECK-cl-WINDOWS-MSVC-LLD: "{{.*}}ld.lld"
+// CHECK-cl-WINDOWS-MSVC-LLD-SAME: "-o"
 
 // RUN: %clang %s -### -fuse-ld=lld-link \
 // RUN: -target i686-unknown-windows-msvc 2>&1 \
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -490,13 +490,10 @@
 
   std::vector Environment;
 
-  // We need to special case some linker paths.  In the case of lld, we need to
-  // translate 'lld' into 'lld-link', and in the case of the regular msvc
+  // We need to special case some linker paths.  In the case of the regular msvc
   // linker, we need to use a special search algorithm.
   llvm::SmallString<128> linkPath;
   StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "link");
-  if (Linker.equals_lower("lld"))
-Linker = "lld-link";
 
   if (Linker.equals_lower("link")) {
 // If we're using the MSVC linker, it's not sufficient to just use link
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4785,8 +4785,8 @@
 break;
   case llvm::Triple::MSVC:
   case llvm::Triple::UnknownEnvironment:
-if (Args.getLastArgValue(options::OPT_fuse_ld_EQ)
-.startswith_lower("bfd"))
+auto linkerFlavor = 

[PATCH] D55326: [Driver] Fix incorrect GNU triplet for PowerPC on SUSE Linux

2019-11-03 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

@jrtc27, @nemanjai: Could you have a look again? I think I answered all your 
questions and wrote a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D55326



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


[PATCH] D69766: [Clang][MSVC] Use GetLinkerPath like the other toolchains for consistency

2019-11-03 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69766

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp


Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -578,7 +578,7 @@
   SkipSettingEnvironment:;
 #endif
   } else {
-linkPath = TC.GetProgramPath(Linker.str().c_str());
+linkPath = TC.GetLinkerPath();
   }
 
   auto LinkCmd = std::make_unique(


Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -578,7 +578,7 @@
   SkipSettingEnvironment:;
 #endif
   } else {
-linkPath = TC.GetProgramPath(Linker.str().c_str());
+linkPath = TC.GetLinkerPath();
   }
 
   auto LinkCmd = std::make_unique(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69764: [clang-format] Add East Const / West Const fixer

2019-11-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: klimek, mitchell-stellar, sammccall, owenpan, 
krasimir.
MyDeveloperDay added a project: clang-format.
Herald added a subscriber: mgorny.
Herald added a project: clang.

Developers these days seem to argue over east vs west const like they used to 
argue over tabs vs whitespace or the various bracing style. These previous 
arguments were mainly eliminated with tools like `clang-format` that allowed 
those rules to become part of your style guide. Anyone who has been using 
clang-format in a large team over the last couple of years knows that we don't 
have those religious arguments any more, and code reviews are more productive.

https://www.youtube.com/watch?v=fv--IKZFVO8
https://mariusbancila.ro/blog/2018/11/23/join-the-east-const-revolution/
https://www.youtube.com/watch?v=z6s6bacI424

The purpose of this revision is to try to do the same for the East/West const 
discussion. Move the debate into the style guide and leave it there!

In addition to the new `ConstStyle: West` or `ConstStyle: East` there is an 
additional command-line argument `--const-style=east/west` which would allow an 
individual developer to switch the source back and forth to their own style for 
editing, and back to the committed style before commit. (you could imagine an 
IDE might offer such a switch)

The revision works by implementing a separate pass of the Annotated lines much 
like the SortIncludes and then create replacements for constant type 
declarations.


Repository:
  rC Clang

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/EastWestConstFixer.cpp
  clang/lib/Format/EastWestConstFixer.h
  clang/lib/Format/Format.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -27,6 +27,10 @@
 
 FormatStyle getGoogleStyle() { return getGoogleStyle(FormatStyle::LK_Cpp); }
 
+#define VERIFYFORMAT(expect, style) verifyFormat(expect, style, __LINE__)
+#define VERIFYFORMAT2(expect, actual, style)   \
+  verifyFormat(expect, actual, style, __LINE__)
+
 class FormatTest : public ::testing::Test {
 protected:
   enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
@@ -66,10 +70,12 @@
   }
 
   void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
-const FormatStyle  = getLLVMStyle()) {
+const FormatStyle  = getLLVMStyle(),
+int line = __LINE__) {
 EXPECT_EQ(Expected.str(), format(Expected, Style))
-<< "Expected code is not stable";
-EXPECT_EQ(Expected.str(), format(Code, Style));
+<< "Expected code is not stable at " << __FILE__ << ":" << line;
+EXPECT_EQ(Expected.str(), format(Code, Style))
+<< " at " << __FILE__ << ":" << line;
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
   // needs to be checked for Objective-C++ as well.
@@ -80,8 +86,9 @@
   }
 
   void verifyFormat(llvm::StringRef Code,
-const FormatStyle  = getLLVMStyle()) {
-verifyFormat(Code, test::messUp(Code), Style);
+const FormatStyle  = getLLVMStyle(),
+int line = __LINE__) {
+verifyFormat(Code, test::messUp(Code), Style, line);
   }
 
   void verifyIncompleteFormat(llvm::StringRef Code,
@@ -12502,6 +12509,11 @@
   CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
 
+  Style.ConstStyle = FormatStyle::CS_West;
+  CHECK_PARSE("ConstStyle: Leave", ConstStyle, FormatStyle::CS_Leave);
+  CHECK_PARSE("ConstStyle: East", ConstStyle, FormatStyle::CS_East);
+  CHECK_PARSE("ConstStyle: West", ConstStyle, FormatStyle::CS_West);
+
   Style.PointerAlignment = FormatStyle::PAS_Middle;
   CHECK_PARSE("PointerAlignment: Left", PointerAlignment,
   FormatStyle::PAS_Left);
@@ -14728,6 +14740,112 @@
"#endif // while");
 }
 
+TEST_F(FormatTest, EastWestConst) {
+  FormatStyle Style = getLLVMStyle();
+
+  // keep the const style unaltered
+  VERIFYFORMAT("const int a;", Style);
+  VERIFYFORMAT("const int *a;", Style);
+  VERIFYFORMAT("const int ", Style);
+  VERIFYFORMAT("const int &", Style);
+  VERIFYFORMAT("int const b;", Style);
+  VERIFYFORMAT("int const *b;", Style);
+  VERIFYFORMAT("int const ", Style);
+  VERIFYFORMAT("int const &", Style);
+  VERIFYFORMAT("int const *b const;", Style);
+  VERIFYFORMAT("int *const c;", Style);
+
+  VERIFYFORMAT("const Foo a;", Style);
+  VERIFYFORMAT("const Foo *a;", Style);
+  VERIFYFORMAT("const Foo 

[PATCH] D69762: [Diagnostics] Try to improve warning message for -Wreturn-type

2019-11-03 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 227611.
xbolva00 added a comment.

Up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69762

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td


Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -576,10 +576,10 @@
   "thread-local storage is not supported for the current target">;
 
 def warn_maybe_falloff_nonvoid_function : Warning<
-  "control may reach end of non-void function">,
+  "not all control paths in this function return a value; non-void function 
must return a value">,
   InGroup;
 def warn_falloff_nonvoid_function : Warning<
-  "control reaches end of non-void function">,
+  "function does not return a value; non-void function must return a value">,
   InGroup;
 def err_maybe_falloff_nonvoid_block : Error<
   "control may reach end of non-void block">;


Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -576,10 +576,10 @@
   "thread-local storage is not supported for the current target">;
 
 def warn_maybe_falloff_nonvoid_function : Warning<
-  "control may reach end of non-void function">,
+  "not all control paths in this function return a value; non-void function must return a value">,
   InGroup;
 def warn_falloff_nonvoid_function : Warning<
-  "control reaches end of non-void function">,
+  "function does not return a value; non-void function must return a value">,
   InGroup;
 def err_maybe_falloff_nonvoid_block : Error<
   "control may reach end of non-void block">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69762: [Diagnostics] Try to improve warning message for -Wreturn-type

2019-11-03 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

I will update tests after we decide on final text.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69762



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


[PATCH] D69763: [Clang][Test]: Remaining "lld-link2" -> "lld-link"

2019-11-03 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

No idea why these are still here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69763

Files:
  clang/test/Driver/windows-cross.c


Index: clang/test/Driver/windows-cross.c
===
--- clang/test/Driver/windows-cross.c
+++ clang/test/Driver/windows-cross.c
@@ -43,30 +43,30 @@
 
 // CHECK-STANDALONE: armv7-windows-itanium-ld" 
"--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-shared" "-Bdynamic" 
"--enable-auto-image-base" "--entry" "_DllMainCRTStartup" 
"--allow-multiple-definition" "-o" "shared.dll" "--out-implib" "shared.lib" 
"{{.*}}.o"
 
-// RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin 
-fuse-ld=lld-link2 -shared -o shared.dll -x c++ %s 2>&1 \
+// RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin 
-fuse-ld=lld-link -shared -o shared.dll -x c++ %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix CHECK-FUSE-LD
 
-// CHECK-FUSE-LD: "{{.*}}lld-link2"
+// CHECK-FUSE-LD: "{{.*}}lld-link"
 
-// RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin 
-fuse-ld=lld-link2 -shared -o shared.dll -fsanitize=address -x c++ %s 2>&1 \
+// RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin 
-fuse-ld=lld-link -shared -o shared.dll -fsanitize=address -x c++ %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix CHECK-SANITIZE-ADDRESS
 
 // CHECK-SANITIZE-ADDRESS: "-fsanitize=address"
 // CHECK-SANITIZE-ADDRESS: "{{.*}}clang_rt.asan_dll_thunk-arm.lib"
 
-// RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin 
-fuse-ld=lld-link2 -o test.exe -fsanitize=address -x c++ %s 2>&1 \
+// RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin 
-fuse-ld=lld-link -o test.exe -fsanitize=address -x c++ %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix CHECK-SANITIZE-ADDRESS-EXE
 
 // CHECK-SANITIZE-ADDRESS-EXE: "-fsanitize=address"
 // CHECK-SANITIZE-ADDRESS-EXE: "{{.*}}clang_rt.asan_dynamic-arm.lib" 
"{{.*}}clang_rt.asan_dynamic_runtime_thunk-arm.lib" "--undefined" 
"__asan_seh_interceptor"
 
-// RUN: %clang -### -target i686-windows-itanium -B 
%S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link2 -o test.exe 
-fsanitize=address -x c++ %s 2>&1 \
+// RUN: %clang -### -target i686-windows-itanium -B 
%S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link -o test.exe 
-fsanitize=address -x c++ %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix CHECK-SANITIZE-ADDRESS-EXE-X86
 
 // CHECK-SANITIZE-ADDRESS-EXE-X86: "-fsanitize=address"
 // CHECK-SANITIZE-ADDRESS-EXE-X86: "{{.*}}clang_rt.asan_dynamic-i386.lib" 
"{{.*}}clang_rt.asan_dynamic_runtime_thunk-i386.lib" "--undefined" 
"___asan_seh_interceptor"
 
-// RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin 
-fuse-ld=lld-link2 -shared -o shared.dll -fsanitize=tsan -x c++ %s 2>&1 \
+// RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin 
-fuse-ld=lld-link -shared -o shared.dll -fsanitize=tsan -x c++ %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix CHECK-SANITIZE-TSAN
 
 // CHECK-SANITIZE-TSAN: error: unsupported argument 'tsan' to option 
'fsanitize='


Index: clang/test/Driver/windows-cross.c
===
--- clang/test/Driver/windows-cross.c
+++ clang/test/Driver/windows-cross.c
@@ -43,30 +43,30 @@
 
 // CHECK-STANDALONE: armv7-windows-itanium-ld" "--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-shared" "-Bdynamic" "--enable-auto-image-base" "--entry" "_DllMainCRTStartup" "--allow-multiple-definition" "-o" "shared.dll" "--out-implib" "shared.lib" "{{.*}}.o"
 
-// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link2 -shared -o shared.dll -x c++ %s 2>&1 \
+// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link -shared -o shared.dll -x c++ %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix CHECK-FUSE-LD
 
-// CHECK-FUSE-LD: "{{.*}}lld-link2"
+// CHECK-FUSE-LD: "{{.*}}lld-link"
 
-// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link2 -shared -o shared.dll -fsanitize=address -x c++ %s 2>&1 \
+// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link 

[PATCH] D69762: [LegacyPassManager] Fixed "null check after derefencing" warning

2019-11-03 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, mehdi_amini.
Herald added projects: clang, LLVM.

The 'RequiredPass' pointer was utilized before it was verified against nullptr. 
Check lines: 1626, 1629.

[Diagnostics] Try to improve warning message for -Wreturn-type


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69762

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  llvm/lib/IR/LegacyPassManager.cpp


Index: llvm/lib/IR/LegacyPassManager.cpp
===
--- llvm/lib/IR/LegacyPassManager.cpp
+++ llvm/lib/IR/LegacyPassManager.cpp
@@ -1626,13 +1626,12 @@
 /// RequiredPass is run on the fly by Pass Manager when P requests it
 /// through getAnalysis interface.
 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
+  assert(RequiredPass && "No required pass?");
   assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
  "Unable to handle Pass that requires lower level Analysis pass");
   assert((P->getPotentialPassManagerType() <
   RequiredPass->getPotentialPassManagerType()) &&
  "Unable to handle Pass that requires lower level Analysis pass");
-  if (!RequiredPass)
-return;
 
   FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
   if (!FPP) {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -576,10 +576,10 @@
   "thread-local storage is not supported for the current target">;
 
 def warn_maybe_falloff_nonvoid_function : Warning<
-  "control may reach end of non-void function">,
+  "not all control paths in this function return a value; non-void function 
must return a value">,
   InGroup;
 def warn_falloff_nonvoid_function : Warning<
-  "control reaches end of non-void function">,
+  "function does not return a value; non-void function must return a value">,
   InGroup;
 def err_maybe_falloff_nonvoid_block : Error<
   "control may reach end of non-void block">;


Index: llvm/lib/IR/LegacyPassManager.cpp
===
--- llvm/lib/IR/LegacyPassManager.cpp
+++ llvm/lib/IR/LegacyPassManager.cpp
@@ -1626,13 +1626,12 @@
 /// RequiredPass is run on the fly by Pass Manager when P requests it
 /// through getAnalysis interface.
 void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
+  assert(RequiredPass && "No required pass?");
   assert(P->getPotentialPassManagerType() == PMT_ModulePassManager &&
  "Unable to handle Pass that requires lower level Analysis pass");
   assert((P->getPotentialPassManagerType() <
   RequiredPass->getPotentialPassManagerType()) &&
  "Unable to handle Pass that requires lower level Analysis pass");
-  if (!RequiredPass)
-return;
 
   FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
   if (!FPP) {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -576,10 +576,10 @@
   "thread-local storage is not supported for the current target">;
 
 def warn_maybe_falloff_nonvoid_function : Warning<
-  "control may reach end of non-void function">,
+  "not all control paths in this function return a value; non-void function must return a value">,
   InGroup;
 def warn_falloff_nonvoid_function : Warning<
-  "control reaches end of non-void function">,
+  "function does not return a value; non-void function must return a value">,
   InGroup;
 def err_maybe_falloff_nonvoid_block : Error<
   "control may reach end of non-void block">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67508: [RISCV] support mutilib in baremetal environment

2019-11-03 Thread Kuan Hsu Chen (Zakk) via Phabricator via cfe-commits
khchen updated this revision to Diff 227606.

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

https://reviews.llvm.org/D67508

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32i/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32i/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32iac/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32iac/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32im/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32im/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imac/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imac/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imafc/ilp32f/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imafc/ilp32f/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imafdc/lp64d/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imafdc/lp64d/crtend.o
  clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/bin/ld
  clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/lib/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/lib/rv32i/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/lib/rv32iac/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/lib/rv32im/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/lib/rv32imac/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/lib/rv32imafc/ilp32f/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/lib/rv64imac/lp64/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk/riscv64-unknown-elf/lib/rv64imafdc/lp64d/crt0.o
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c

Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -14,8 +14,8 @@
 // C-RV64-BAREMETAL-LP64: "--sysroot={{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf"
 // C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib{{/|}}crt0.o"
 // C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtbegin.o"
-// C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib"
 // C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1"
+// C-RV64-BAREMETAL-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/riscv64-unknown-elf/lib"
 // C-RV64-BAREMETAL-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc"
 // C-RV64-BAREMETAL-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
@@ -29,8 +29,8 @@
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../bin{{/|}}riscv64-unknown-elf-ld"
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../riscv64-unknown-elf/lib{{/|}}crt0.o"
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtbegin.o"
-// C-RV64-BAREMETAL-NOSYSROOT-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../riscv64-unknown-elf{{/|}}lib"
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1"
+// C-RV64-BAREMETAL-NOSYSROOT-LP64: "-L{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1/../../../../riscv64-unknown-elf{{/|}}lib"
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "--start-group" "-lc" "-lgloss" "--end-group" "-lgcc"
 // C-RV64-BAREMETAL-NOSYSROOT-LP64: "{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
@@ -46,8 +46,8 @@
 // 

[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang Tidy's script

2019-11-03 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis added inline comments.



Comment at: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:152
+
+  if (llvm::Error Err = Repls.add(Repl))
+llvm_unreachable("An error occured during fix-it replacements");

Isn't `llvm_unreacheable` too pessimistic? May be use diagnostics instead?


Repository:
  rC Clang

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

https://reviews.llvm.org/D69746



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


[PATCH] D67678: PR17164: Change clang's default behavior from -flax-vector-conversions=all to -flax-vector-conversions=integer.

2019-11-03 Thread Kristof Beyls via Phabricator via cfe-commits
kristof.beyls added inline comments.



Comment at: docs/ReleaseNotes.rst:84
+  In a future release of Clang, we intend to change the default to
+  ``-fno-lax-vector-conversions``.
+

rsmith wrote:
> efriedma wrote:
> > kristof.beyls wrote:
> > > efriedma wrote:
> > > > rsmith wrote:
> > > > > efriedma wrote:
> > > > > > And if you want to allow your code to build with both clang-9 and 
> > > > > > clang-10, you have to do version detection in your build scripts?
> > > > > I guess you'd detect whether the compiler supports 
> > > > > `-flax-vector-conversions=all`, and pass that if so, and otherwise 
> > > > > pass `-flax-vector-conversions`. Well, either that or you fix your 
> > > > > code to not rely on lax vector conversions between int and float 
> > > > > vectors. If your code builds with GCC, you did that already (they 
> > > > > never supported lax conversions between float and int vectors, as far 
> > > > > as I can tell).
> > > > > 
> > > > > Do you have a preferred alternative?
> > > > All the alternatives are terrible in their own way:
> > > > 
> > > > 1. This status quo, which breaks compatibility with previous versions 
> > > > of clang
> > > > 2. We could make -flax-vector-conversions mean the same thing as 
> > > > earlier versions of clang.  So the flag wouldn't have the same meaning 
> > > > as gcc's flag.
> > > > 3. Some mix of the previous options: we could wait until there are one 
> > > > or two released versions that support -flax-vector-conversions=all , 
> > > > then change the meaning of -flax-vector-conversions.  But I have no 
> > > > idea how we would decide on a timeline.
> > > > 
> > > > I ran into this issue recently updating our compiler.  That said, the 
> > > > code in question was only using the implicit conversion in a couple 
> > > > places by accident, so it was easy enough to just fix the source.
> > > Maybe adding an entry in the release notes about this change could help 
> > > with making option 1 slightly more palatable?
> > > My guess is that option 1 is the right one for the long term 
> > > (compatibility between gcc and clang so code is more portable between 
> > > both compilers).
> > It probably makes sense to call out the behavior change to 
> > -flax-vector-conversions in the release notes, yes.
> @kristof.beyls Are you looking for more changes to the release notes in 
> addition to what's already in this change? If so, what would you like to see?
@rsmith I'm afraid I reacted to the review comments above and completely missed 
you had already added an entry to the release notes! My apologies.
I think it might still take some time for someone getting a build error who 
then goes through the release notes to easily spot that it's the change to lax 
vector conversions that's making their build fail.
However, I can't think of a much better way to describe this in the release 
notes so that a developer would spot this more easily, unless we'd put a source 
code example of something that now fails by default that didn't before. Putting 
source code examples in the release notes for all changes might make the 
release notes too long/complex?


Repository:
  rC Clang

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

https://reviews.llvm.org/D67678



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


[clang] c96428d - Drop spurious self-include [NFC]

2019-11-03 Thread Aaron Puchert via cfe-commits

Author: Aaron Puchert
Date: 2019-11-03T14:29:59+01:00
New Revision: c96428d2184fe2329e625f6a0dc04daa02ee42c9

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

LOG: Drop spurious self-include [NFC]

This was introduced in D61357, probably by accident.

Added: 


Modified: 
clang/include/clang/Basic/PartialDiagnostic.h

Removed: 




diff  --git a/clang/include/clang/Basic/PartialDiagnostic.h 
b/clang/include/clang/Basic/PartialDiagnostic.h
index ae8de67e8776..799951b82a6c 100644
--- a/clang/include/clang/Basic/PartialDiagnostic.h
+++ b/clang/include/clang/Basic/PartialDiagnostic.h
@@ -16,7 +16,6 @@
 #define LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H
 
 #include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/SmallVector.h"



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


[PATCH] D69520: [libc++] Disallow dynamic -> static span conversions

2019-11-03 Thread Jan Wilken Dörrie via Phabricator via cfe-commits
jdoerrie updated this revision to Diff 227605.
jdoerrie marked 4 inline comments as done.
jdoerrie added a comment.

Addressed Marshall's comments


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

https://reviews.llvm.org/D69520

Files:
  libcxx/include/span
  libcxx/test/std/containers/views/span.cons/span.fail.cpp
  libcxx/test/std/containers/views/span.cons/span.pass.cpp

Index: libcxx/test/std/containers/views/span.cons/span.pass.cpp
===
--- libcxx/test/std/containers/views/span.cons/span.pass.cpp
+++ libcxx/test/std/containers/views/span.cons/span.pass.cpp
@@ -62,48 +62,42 @@
 std::span s4{ vsp0};// a span pointing at volatile int.
 assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
 }
-
-//  dynamic -> static
-{
-std::span s1{  sp};  // a span pointing at int.
-std::span<  volatile int, 0> s2{  sp};  // a span<  volatile int> pointing at int.
-std::span s3{  sp};  // a span pointing at int.
-std::span s4{ vsp};  // a span pointing at volatile int.
-assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
-}
 }
 
 
 template 
 constexpr bool testConstexprSpan()
 {
-std::spans0{};
-std::span s1(s0); // dynamic -> static
-std::spans2(s1); // static -> dynamic
-ASSERT_NOEXCEPT(std::span   {s0});
-ASSERT_NOEXCEPT(std::span{s1});
-ASSERT_NOEXCEPT(std::span   {s1});
-ASSERT_NOEXCEPT(std::span{s0});
-
-return
-s1.data() == nullptr && s1.size() == 0
-&&  s2.data() == nullptr && s2.size() == 0;
+  std::span s0d{};
+  std::span s0s{};
+  std::span s1(s0d);// dynamic -> dynamic
+  std::span s2(s0s); // static -> static
+  std::span s3(s2); // static -> dynamic
+  ASSERT_NOEXCEPT(std::span{s0d});
+  ASSERT_NOEXCEPT(std::span{s0s});
+  ASSERT_NOEXCEPT(std::span{s0s});
+
+  return s1.data() == nullptr && s1.size() == 0
+  && s2.data() == nullptr && s2.size() == 0
+  && s3.data() == nullptr && s3.size() == 0;
 }
 
 
 template 
 void testRuntimeSpan()
 {
-std::spans0{};
-std::span s1(s0); // dynamic -> static
-std::spans2(s1); // static -> dynamic
-ASSERT_NOEXCEPT(std::span   {s0});
-ASSERT_NOEXCEPT(std::span{s1});
-ASSERT_NOEXCEPT(std::span   {s1});
-ASSERT_NOEXCEPT(std::span{s0});
-
-assert(s1.data() == nullptr && s1.size() == 0);
-assert(s2.data() == nullptr && s2.size() == 0);
+  std::span s0d{};
+  std::span s0s{};
+  std::span s1(s0d);// dynamic -> dynamic
+  std::span s2(s0s); // static -> static
+  std::span s3(s2); // static -> dynamic
+  ASSERT_NOEXCEPT(std::span{s0d});
+  ASSERT_NOEXCEPT(std::span{s0s});
+  ASSERT_NOEXCEPT(std::span{s0s});
+
+  assert(s1.data() == nullptr && s1.size() == 0);
+  assert(s2.data() == nullptr && s2.size() == 0);
+  assert(s3.data() == nullptr && s3.size() == 0);
 }
 
 
@@ -112,11 +106,13 @@
 {
 static_assert(std::is_convertible_v, "Bad input types to 'testConversionSpan");
 std::spans0d{};
-std::spans0s{};
-std::span s1(s0d); // dynamic -> static
-std::spans2(s0s); // static -> dynamic
-s1.data() == nullptr && s1.size() == 0
-&&  s2.data() == nullptr && s2.size() == 0;
+std::span s0s{};
+std::span s1(s0d);// dynamic -> dynamic
+std::span s2(s0s); // static -> static
+std::span s3(s0d);// static -> dynamic
+return s1.data() == nullptr && s1.size() == 0
+&& s2.data() == nullptr && s2.size() == 0
+&& s3.data() == nullptr && s3.size() == 0;
 }
 
 struct A{};
Index: libcxx/test/std/containers/views/span.cons/span.fail.cpp
===
--- libcxx/test/std/containers/views/span.cons/span.fail.cpp
+++ libcxx/test/std/containers/views/span.cons/span.fail.cpp
@@ -74,18 +74,34 @@
 std::span<  volatile int> s6{ csp0}; // expected-error {{no matching constructor for initialization of 'std::span'}}
 std::span<  volatile int> s7{cvsp0}; // expected-error {{no matching constructor for initialization of 'std::span'}}
 }
+}
 
-//  Try to remove const and/or volatile (static -> static)
+void checkExtent ()
+{
+std::spanspd;
+std::span sp0;
+std::span sp1{nullptr, 1};
+std::span sp2{nullptr, 2};
+
+//  Try to construct static span with extent 0 from span with different extent
 {
-std::span<   int, 0> s1{ csp}; // expected-error {{no matching constructor for initialization of 'std::span'}}
-std::span<   int, 0> s2{ vsp}; // expected-error {{no matching constructor for initialization of 'std::span'}}
-std::span<   int, 0> s3{cvsp}; // expected-error {{no matching constructor for initialization of 'std::span'}}
+std::span s1{spd}; // expected-error {{no matching constructor for initialization of 'std::span'}}
+std::span s2{sp1}; // expected-error {{no matching constructor 

[PATCH] D69520: [libc++] Disallow dynamic -> static span conversions

2019-11-03 Thread Jan Wilken Dörrie via Phabricator via cfe-commits
jdoerrie added inline comments.



Comment at: libcxx/test/std/containers/views/span.cons/span.fail.cpp:78
-
-//  Try to remove const and/or volatile (static -> static)
-{

mclow.lists wrote:
> Ok. The comment here is wrong; this is testing dynamic -> static.
> 
> However, why are you removing these (failing) tests?
> 
Considering that `Extent == dynamic_extent || Extent == OtherExtent` should be 
checked first I felt these particular tests distracted from the actual root 
cause of the error. I added now a new section that performs explicit Extent 
checks.



Comment at: libcxx/test/std/containers/views/span.cons/span.pass.cpp:80
+
+  return s1.data() == nullptr && s1.size() == 0 && s2.data() == nullptr &&
+ s2.size() == 0 && s3.data() == nullptr && s3.size() == 0;

mclow.lists wrote:
> Please line these up like the other ones were. Makes it easy to see 
> copy-pasta errors:
> ```
> return s1.data() == nullptr && s1.size() == 0 
> && s2.data() == nullptr && s2.size() == 0
> && s3.data() == nullptr && s3.size() == 0;
> ```
FWIW my formatting was performed by `clang-format`. Do you think it's worth 
wrapping this block in

```
// clang-format off
...
// clang-format on
```

so that this doesn't regress in the future?


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

https://reviews.llvm.org/D69520



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


[PATCH] D32164: [clang-tidy] misc-misplaced-widening-cast: Disable checking of implicit widening casts by default

2019-11-03 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.
Herald added subscribers: llvm-commits, gamesh411, Szelethus, rnkovacs.
Herald added a project: LLVM.

The doc wasn't updated :/


Repository:
  rL LLVM

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

https://reviews.llvm.org/D32164



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


[PATCH] D69760: [LLD][MinGW] Support --allow-multiple-definition

2019-11-03 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 created this revision.
Herald added subscribers: llvm-commits, cfe-commits, mstorsjo.
Herald added projects: clang, LLVM.

We want the Clang CrossWindows toolchain to work with ld.lld and ld.bfd
alike, and it uses this, so we need to support this.

[Clang][Test]: Remaining "lld-link2" -> "lld-link"

No idea why these are still here.

[Clang][MSVC] Use GetLinkerPath like the other toolchains for consistency

[Clang][Driver] Don't pun -fuse-ld=lld as -fuse-ld=lld-link with msvc

Besides the Mingw toolchain, there is also the CrossWindows toolchain,
which means GNU-style cli but genuine windows headers + libraries. LLD's
MinGW driver is as good a fit as binutil's ld, but there is no easy way
to select it when lld was being rewritten to lld-link.

This makes lld always be the GNU-style one, consistent with the non-msvc
case. It's a small breaking change for Windows, but the only
straightforward way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69760

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/fuse-ld.c
  clang/test/Driver/windows-cross.c
  lld/MinGW/Driver.cpp
  lld/MinGW/Options.td
  lld/test/MinGW/driver.test

Index: lld/test/MinGW/driver.test
===
--- lld/test/MinGW/driver.test
+++ lld/test/MinGW/driver.test
@@ -40,6 +40,14 @@
 RUN: ld.lld -### foo.o -m i386pep -o bar.exe | FileCheck -check-prefix=OUT %s
 OUT: -out:bar.exe
 
+RUN: ld.lld -### foo.o -m i386pep --allow-multiple-definitions | FileCheck -check-prefix=FORCE_MULTIPLE %s
+RUN: ld.lld -### foo.o -m i386pep --no-allow-multiple-definitions --allow-multiple-definitions | FileCheck -check-prefix=FORCE_MULTIPLE %s
+FORCE_MULTIPLE: -force:multiple
+
+RUN: ld.lld -### foo.o -m i386pep --no-allow-multiple-definitions | FileCheck -check-prefix=NO_FORCE_MULTIPLE %s
+RUN: ld.lld -### foo.o -m i386pep --allow-multiple-definitions --no-allow-multiple-definitions | FileCheck -check-prefix=NO_FORCE_MULTIPLE %s
+NO_FORCE_MULTIPLE-NOT: -force:multiple
+
 RUN: ld.lld -### foo.o -m i386pep --out-implib bar | FileCheck -check-prefix=IMPLIB %s
 RUN: ld.lld -### foo.o -m i386pep --out-implib=bar | FileCheck -check-prefix=IMPLIB %s
 RUN: ld.lld -### foo.o -m i386pep -out-implib bar | FileCheck -check-prefix=IMPLIB %s
Index: lld/MinGW/Options.td
===
--- lld/MinGW/Options.td
+++ lld/MinGW/Options.td
@@ -20,7 +20,13 @@
   HelpText<"Add a directory to the library search path">;
 def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries">;
 def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">;
+
+defm allow_multiple_definition: B<"allow-multiple-definition",
+"Allow multiple definitions",
+"Do not allow multiple definitions (default)">;
+
 def dynamicbase: F<"dynamicbase">, HelpText<"Enable ASLR">;
+
 defm entry: Eq<"entry", "Name of entry point symbol">, MetaVarName<"">;
 def exclude_all_symbols: F<"exclude-all-symbols">,
 HelpText<"Don't automatically export any symbols">;
Index: lld/MinGW/Driver.cpp
===
--- lld/MinGW/Driver.cpp
+++ lld/MinGW/Driver.cpp
@@ -232,6 +232,9 @@
 add("-subsystem:" + StringRef(a->getValue()));
   }
 
+  config->allowMultipleDefinition =
+  if (args.hasFlag(OPT_allow_multiple_definition, OPT_no_allow_multiple_definition, false))
+add("-force:multiple");
   if (auto *a = args.getLastArg(OPT_out_implib))
 add("-implib:" + StringRef(a->getValue()));
   if (auto *a = args.getLastArg(OPT_stack))
Index: clang/test/Driver/windows-cross.c
===
--- clang/test/Driver/windows-cross.c
+++ clang/test/Driver/windows-cross.c
@@ -43,30 +43,30 @@
 
 // CHECK-STANDALONE: armv7-windows-itanium-ld" "--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-shared" "-Bdynamic" "--enable-auto-image-base" "--entry" "_DllMainCRTStartup" "--allow-multiple-definition" "-o" "shared.dll" "--out-implib" "shared.lib" "{{.*}}.o"
 
-// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link2 -shared -o shared.dll -x c++ %s 2>&1 \
+// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link -shared -o shared.dll -x c++ %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix CHECK-FUSE-LD
 
-// CHECK-FUSE-LD: "{{.*}}lld-link2"
+// CHECK-FUSE-LD: "{{.*}}lld-link"
 
-// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link2 -shared -o shared.dll -fsanitize=address -x c++ %s 2>&1 \
+// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link -shared -o shared.dll