[PATCH] D45059: [clang-tidy] Add check to catch comparisons in TEMP_FAILURE_RETRY

2018-04-02 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

LGTM, but @aaron.ballman, @alexfh or someone else should review it before 
comitting.


https://reviews.llvm.org/D45059



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


[PATCH] D45168: [clang-format/ObjC] Do not insert space after opening brace of ObjC dict literal

2018-04-02 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


Repository:
  rC Clang

https://reviews.llvm.org/D45168



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


[PATCH] D45169: [clang-format/ObjC] Do not detect "[]" as ObjC method expression

2018-04-02 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good. I like option 2 :).


Repository:
  rC Clang

https://reviews.llvm.org/D45169



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


[PATCH] D45126: Xray, OpenBSD support

2018-04-02 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris accepted this revision.
dberris added a comment.
This revision is now accepted and ready to land.

LGTM -- at some point, it would be good to refactor all these flag settings to 
a single place. Maybe file a bug so that we can track that issue on XRay? If 
you can't do it now, I'd be happy to do it later on.


Repository:
  rC Clang

https://reviews.llvm.org/D45126



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


[PATCH] D41168: [X86] Lowering X86 avx512 sqrt intrinsics to IR

2018-04-02 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:8901
   }
-
+  case X86::BI__builtin_ia32_sqrtsd_round_mask:
+  case X86::BI__builtin_ia32_sqrtss_round_mask: {

What about __builtin_ia32_sqrtsd and __builtin_ia32_sqrtss?


Repository:
  rC Clang

https://reviews.llvm.org/D41168



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


[PATCH] D41168: [X86] Lowering X86 avx512 sqrt intrinsics to IR

2018-04-02 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:8904
+unsigned CC = cast(Ops[4])->getZExtValue();
+// Support only if the rounding mode is 4 (AKA CUR_DIRECTION), otherwise 
keep the intrinsic.
+if (CC != 4) {

80 columns?



Comment at: lib/CodeGen/CGBuiltin.cpp:8907
+  return nullptr;
+}
+llvm::Value *C0 = llvm::ConstantInt::get(SizeTy, 0);

Drop the curly braces



Comment at: lib/CodeGen/CGBuiltin.cpp:8909
+llvm::Value *C0 = llvm::ConstantInt::get(SizeTy, 0);
+Value *A = Builder.CreateExtractElement(Ops[0], C0, "extract");
+Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());

There's a signature for CreateExtractElement that takes a uint64_t for the 
index. No need to create a ConstantInt explicitly



Comment at: lib/CodeGen/CGBuiltin.cpp:8930
+// Support only if the rounding mode is 4 (AKA CUR_DIRECTION), otherwise 
keep the intrinsic.
+if (CC != 4) {
+  return nullptr;

Drop the curly braces


Repository:
  rC Clang

https://reviews.llvm.org/D41168



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


[PATCH] D44970: [XRay][clang] Add flag to choose instrumentation bundles

2018-04-02 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris updated this revision to Diff 140735.
dberris added a comment.

- fixup: Fix tests for better coverage of settings


https://reviews.llvm.org/D44970

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/XRayArgs.h
  clang/include/clang/Frontend/CodeGenOptions.def
  clang/include/clang/Frontend/CodeGenOptions.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/XRayArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/xray-instrumentation-bundles.cpp

Index: clang/test/CodeGen/xray-instrumentation-bundles.cpp
===
--- /dev/null
+++ clang/test/CodeGen/xray-instrumentation-bundles.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fxray-instrument -fxray-instrumentation-bundle=none -x c++ \
+// RUN: -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes CHECK,NOFUNCTION,NOCUSTOM %s
+// RUN: %clang_cc1 -fxray-instrument \
+// RUN: -fxray-instrumentation-bundle=function-extents -x c++ \
+// RUN: -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes CHECK,FUNCTION,NOCUSTOM %s
+// RUN: %clang_cc1 -fxray-instrument \
+// RUN: -fxray-instrumentation-bundle=custom-only -x c++ \
+// RUN: -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes CHECK,NOFUNCTION,CUSTOM %s
+
+// CHECK: define void @_Z16alwaysInstrumentv() #[[ALWAYSATTR:[0-9]+]] {
+[[clang::xray_always_instrument]] void alwaysInstrument() {
+  static constexpr char kPhase[] = "always";
+  __xray_customevent(kPhase, 6);
+  // CUSTOM: call void @llvm.xray.customevent(i8*{{.*}}, i32 6)
+  // NOCUSTOM-NOT: call void @llvm.xray.customevent(i8*{{.*}}, i32 6)
+}
+
+// FUNCTION: attributes #[[ALWAYSATTR]] = {{.*}} "function-instrument"="xray-always" {{.*}}
+// NOFUNCTION-NOT: attributes #[[ALWAYSATTR]] = {{.*}} "function-instrument"="xray-always" {{.*}}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -446,6 +446,23 @@
   }
 }
 
+static CodeGenOptions::XRayInstrumentationPointBundle
+parseXRayInstrumentationBundle(Arg *A, ArgList &Args, DiagnosticsEngine &D) {
+  StringRef V = A->getValue();
+  auto Bundle =  llvm::StringSwitch(V)
+  .Case("all", CodeGenOptions::XRayInstrumentationPointBundle::XRay_All)
+  .Case("none", CodeGenOptions::XRayInstrumentationPointBundle::XRay_None)
+  .Case("function-extents",
+CodeGenOptions::XRayInstrumentationPointBundle::XRay_Function)
+  .Case("custom-only",
+CodeGenOptions::XRayInstrumentationPointBundle::XRay_CustomOnly)
+  .Default(CodeGenOptions::XRayInstrumentationPointBundle::XRay_All);
+  if (Bundle == CodeGenOptions::XRayInstrumentationPointBundle::XRay_All &&
+  !V.empty() && V != "all")
+D.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << V;
+  return Bundle;
+}
+
 // Set the profile kind for fprofile-instrument.
 static void setPGOInstrumentor(CodeGenOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) {
@@ -821,11 +838,18 @@
   Args.hasArg(OPT_finstrument_functions_after_inlining);
   Opts.InstrumentFunctionEntryBare =
   Args.hasArg(OPT_finstrument_function_entry_bare);
-  Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
+
+  Opts.XRayInstrumentFunctions =
+  Args.hasArg(OPT_fxray_instrument);
   Opts.XRayAlwaysEmitCustomEvents =
   Args.hasArg(OPT_fxray_always_emit_customevents);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
+
+  if (auto A = Args.getLastArg(OPT_fxray_instrumentation_bundle))
+Opts.setXRayInstrumentationBundle(
+parseXRayInstrumentationBundle(A, Args, Diags));
+
   Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
   Opts.CallFEntry = Args.hasArg(OPT_mfentry);
   Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
Index: clang/lib/Driver/XRayArgs.cpp
===
--- clang/lib/Driver/XRayArgs.cpp
+++ clang/lib/Driver/XRayArgs.cpp
@@ -27,6 +27,8 @@
 constexpr char XRayInstrumentOption[] = "-fxray-instrument";
 constexpr char XRayInstructionThresholdOption[] =
 "-fxray-instruction-threshold=";
+constexpr char XRayInstrumentationBundleOption[] =
+"-fxray-instrumentation-bundle=";
 } // namespace
 
 XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
@@ -50,10 +52,10 @@
 << (std::string(XRayInstrumentOption) + " on " + Triple.str());
   }
 } else if (Triple.getOS() == llvm::Triple::FreeBSD) {
-if (Triple.getArch() != llvm::Triple::x86_64) {
-  D.Diag(diag::err_

[PATCH] D44970: [XRay][clang] Add flag to choose instrumentation bundles

2018-04-02 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris added inline comments.



Comment at: clang/include/clang/Frontend/CodeGenOptions.h:110
 
+  enum XRayInstrumentationPointBundle {
+XRay_All, // Always emit all the instrumentation points.

pelikan wrote:
> To me, this feels like a bitfield would be a better match.
> All = Function | Custom
> None = 0
Thought about that, but the ergonomics from the user-side isn't as good. Having 
to know about which kinds of sleds specifically to enable seems much harder to 
explain. Using bundles that we control from the beginning keeps this much 
simpler.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:3248
+// custom events.
+{
+  auto XRayBundle = CGM.getCodeGenOpts().getXRayInstrumentationBundle();

echristo wrote:
> I'd probably spell this code like the block above it rather than this.
The codegen options don't work like pointers, and we can't use C++17 if 
initialisers yet. Would have loved this to be:

```
if (auto XRayBundle = ...; XRayBundle == ... || XRayBundle == ...)
  return RValue::getIgnored();
```

Removed the scoping instead.



Comment at: clang/lib/Driver/XRayArgs.cpp:62
+  << (std::string(XRayInstrumentOption) +
+  " on non-supported target OS");
 }

pelikan wrote:
> I would also print the triple.  Something like:
> 
> "-fomit-bugs is not supported on target win64-ppc-none"
> 
> will be much more informative, especially when you collect logs from build 
> machines on lots of architectures (like Linux distro/BSD package builders do).
Probably not today. Good idea though, could be a different patch.


https://reviews.llvm.org/D44970



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


[PATCH] D44970: [XRay][clang] Add flag to choose instrumentation bundles

2018-04-02 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris updated this revision to Diff 140731.
dberris marked 8 inline comments as done.
dberris added a comment.

- fixup: address comments


https://reviews.llvm.org/D44970

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/XRayArgs.h
  clang/include/clang/Frontend/CodeGenOptions.def
  clang/include/clang/Frontend/CodeGenOptions.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Driver/XRayArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/xray-instrumentation-bundles.cpp

Index: clang/test/CodeGen/xray-instrumentation-bundles.cpp
===
--- /dev/null
+++ clang/test/CodeGen/xray-instrumentation-bundles.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fxray-instrument -fxray-instrumentation-bundle=none -x c++ \
+// RUN: -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN: | FileCheck %s
+// RUN: %clang_cc1 -fxray-instrument \
+// RUN: -fxray-instrumentation-bundle=function-extents -x c++ \
+// RUN: -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN: | FileCheck %s
+// RUN: %clang_cc1 -fxray-instrument \
+// RUN: -fxray-instrumentation-bundle=none -x c++ \
+// RUN: -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes CHECK,DISABLE %s
+
+// CHECK-LABEL: alwaysInstrument
+[[clang::xray_always_instrument]] void alwaysInstrument() {
+  static constexpr char kPhase[] = "always";
+  __xray_customevent(kPhase, 6);
+  // CHECK-NOT: call void @llvm.xray.customevent(i8*{{.*}}, i32 6)
+  // DISABLE-NOT: call void @llvm.xray.customevent(i8*{{.*}}, i32 6)
+}
+
+// DISABLE-NOT: function-instrument=always
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -446,6 +446,23 @@
   }
 }
 
+static CodeGenOptions::XRayInstrumentationPointBundle
+parseXRayInstrumentationBundle(Arg *A, ArgList &Args, DiagnosticsEngine &D) {
+  StringRef V = A->getValue();
+  auto Bundle =  llvm::StringSwitch(V)
+  .Case("all", CodeGenOptions::XRayInstrumentationPointBundle::XRay_All)
+  .Case("none", CodeGenOptions::XRayInstrumentationPointBundle::XRay_None)
+  .Case("function-extents",
+CodeGenOptions::XRayInstrumentationPointBundle::XRay_Function)
+  .Case("custom-only",
+CodeGenOptions::XRayInstrumentationPointBundle::XRay_CustomOnly)
+  .Default(CodeGenOptions::XRayInstrumentationPointBundle::XRay_All);
+  if (Bundle == CodeGenOptions::XRayInstrumentationPointBundle::XRay_All &&
+  !V.empty() && V != "all")
+D.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << V;
+  return Bundle;
+}
+
 // Set the profile kind for fprofile-instrument.
 static void setPGOInstrumentor(CodeGenOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) {
@@ -821,11 +838,20 @@
   Args.hasArg(OPT_finstrument_functions_after_inlining);
   Opts.InstrumentFunctionEntryBare =
   Args.hasArg(OPT_finstrument_function_entry_bare);
-  Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
   Opts.XRayAlwaysEmitCustomEvents =
   Args.hasArg(OPT_fxray_always_emit_customevents);
   Opts.XRayInstructionThreshold =
   getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
+
+  if (auto A = Args.getLastArg(OPT_fxray_instrumentation_bundle))
+Opts.setXRayInstrumentationBundle(
+parseXRayInstrumentationBundle(A, Args, Diags));
+
+  Opts.XRayInstrumentFunctions =
+  Args.hasArg(OPT_fxray_instrument) &&
+  Opts.getXRayInstrumentationBundle() !=
+  CodeGenOptions::XRayInstrumentationPointBundle::XRay_None;
+
   Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
   Opts.CallFEntry = Args.hasArg(OPT_mfentry);
   Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
Index: clang/lib/Driver/XRayArgs.cpp
===
--- clang/lib/Driver/XRayArgs.cpp
+++ clang/lib/Driver/XRayArgs.cpp
@@ -27,6 +27,8 @@
 constexpr char XRayInstrumentOption[] = "-fxray-instrument";
 constexpr char XRayInstructionThresholdOption[] =
 "-fxray-instruction-threshold=";
+constexpr char XRayInstrumentationBundleOption[] =
+"-fxray-instrumentation-bundle=";
 } // namespace
 
 XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
@@ -50,10 +52,10 @@
 << (std::string(XRayInstrumentOption) + " on " + Triple.str());
   }
 } else if (Triple.getOS() == llvm::Triple::FreeBSD) {
-if (Triple.getArch() != llvm::Triple::x86_64) {
-  D.Diag(diag::err_drv_clang_unsupported)
-  << (std::string(XRayInstrumentOption) + " on " + Triple.str());
-}
+  if (Triple.getArch() != llvm::Triple::x86_64) {
+D.Diag(diag:

[PATCH] D45196: [libc++abi] Replace __sync_* functions with __libcpp_atomic_* functions.

2018-04-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma created this revision.
efriedma added reviewers: EricWF, compnerd.

This is basically part 2 of r313694.

It's a little unfortunate that I had to copy-paste atomic_support.h, but I 
don't really see any alternative.

The refstring.h changes are the same as the libcxx changes in r313694.


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D45196

Files:
  src/cxa_default_handlers.cpp
  src/cxa_exception.cpp
  src/cxa_handlers.cpp
  src/include/atomic_support.h
  src/include/refstring.h

Index: src/include/refstring.h
===
--- src/include/refstring.h
+++ src/include/refstring.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #endif
+#include "atomic_support.h"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -87,19 +88,19 @@
 : __imp_(s.__imp_)
 {
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
 }
 
 inline
 __libcpp_refstring& __libcpp_refstring::operator=(__libcpp_refstring const& s) _NOEXCEPT {
 bool adjust_old_count = __uses_refcount();
 struct _Rep_base *old_rep = rep_from_data(__imp_);
 __imp_ = s.__imp_;
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
 if (adjust_old_count)
 {
-if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
+if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0)
 {
 ::operator delete(old_rep);
 }
@@ -111,7 +112,7 @@
 __libcpp_refstring::~__libcpp_refstring() {
 if (__uses_refcount()) {
 _Rep_base* rep = rep_from_data(__imp_);
-if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
+if (__libcpp_atomic_add(&rep->count, count_t(-1)) < 0) {
 ::operator delete(rep);
 }
 }
Index: src/include/atomic_support.h
===
--- /dev/null
+++ src/include/atomic_support.h
@@ -0,0 +1,181 @@
+//===--===
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===
+
+// FIXME: This file is copied from libcxx/src/include/atomic_support.h. Instead
+// of duplicating the file in libc++abi we should require that the libc++
+// sources are available when building libc++abi.
+
+#ifndef ATOMIC_SUPPORT_H
+#define ATOMIC_SUPPORT_H
+
+#include "__config"
+#include "memory" // for __libcpp_relaxed_load
+
+#if defined(__clang__) && __has_builtin(__atomic_load_n) \
+   && __has_builtin(__atomic_store_n)\
+   && __has_builtin(__atomic_add_fetch)  \
+   && __has_builtin(__atomic_exchange_n) \
+   && __has_builtin(__atomic_compare_exchange_n) \
+   && defined(__ATOMIC_RELAXED)  \
+   && defined(__ATOMIC_CONSUME)  \
+   && defined(__ATOMIC_ACQUIRE)  \
+   && defined(__ATOMIC_RELEASE)  \
+   && defined(__ATOMIC_ACQ_REL)  \
+   && defined(__ATOMIC_SEQ_CST)
+#   define _LIBCXXABI_HAS_ATOMIC_BUILTINS
+#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
+#   define _LIBCXXABI_HAS_ATOMIC_BUILTINS
+#endif
+
+#if !defined(_LIBCXXABI_HAS_ATOMIC_BUILTINS) && !defined(_LIBCXXABI_HAS_NO_THREADS)
+# if defined(_LIBCPP_WARNING)
+_LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
+# else
+#   warning Building libc++ without __atomic builtins is unsupported
+# endif
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace {
+
+#if defined(_LIBCXXABI_HAS_ATOMIC_BUILTINS) && !defined(_LIBCXXABI_HAS_NO_THREADS)
+
+enum __libcpp_atomic_order {
+_AO_Relaxed = __ATOMIC_RELAXED,
+_AO_Consume = __ATOMIC_CONSUME,
+_AO_Acquire = __ATOMIC_ACQUIRE,
+_AO_Release = __ATOMIC_RELEASE,
+_AO_Acq_Rel = __ATOMIC_ACQ_REL,
+_AO_Seq = __ATOMIC_SEQ_CST
+};
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+void __libcpp_atomic_store(_ValueType* __dest, _FromType __val,
+   int __order = _AO_Seq)
+{
+__atomic_store_n(__dest, __val, __order);
+}
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
+{
+__atomic_store_n(__dest, __val, _AO_Relaxed);
+}
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+_ValueType __libcpp_atomic_load(_ValueType const* __val,
+int __order = _AO_Seq)
+{
+return __atomic_load_

[PATCH] D45174: non-zero-length bit-fields should make a class non-empty

2018-04-02 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

In https://reviews.llvm.org/D45174#1055125, @rsmith wrote:

> In https://reviews.llvm.org/D45174#1055048, @rsmith wrote:
>
> > I wonder if we can delete the `getNonVirtualSize()` check now -- I don't 
> > see any way that an empty class can have a nonzero nvsize except by this 
> > nonempty anonymous bit-fields situation.
>
>
> Yup, looks like:
>
>  if (!FoundBase) {
>   -if (MDCUsesEBO && BaseDecl->isEmpty() &&
>   -BaseLayout.getNonVirtualSize() == CharUnits::Zero()) {
>   +if (MDCUsesEBO && BaseDecl->isEmpty()) {
>   +  assert(BaseLayout.getNonVirtualSize() == CharUnits::Zero());
>  BaseOffset = CharUnits::Zero();
>} else {
>
>
> Zero test failures.


Yeah, I think this should be NFC for the MS ABI.




Comment at: ReleaseNotes.rst:68-72
+- Clang implements the proposed resolution of LWG issue 2358, along with the
+  `corresponding change to the Itanium C++ ABI
+  `_, which make classes
+  containing only unnamed non-zero-length bit-fields be considered non-empty.
+  This is an ABI break compared to prior Clang releases, but makes Clang

The "Clang" in the above paragraph has a lowercase "clang". I think we should 
choose a consistent capitalization.


Repository:
  rC Clang

https://reviews.llvm.org/D45174



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


[libcxx] r329038 - Fix fs::proximate tests on platforms where /net exists.

2018-04-02 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Mon Apr  2 18:52:12 2018
New Revision: 329038

URL: http://llvm.org/viewvc/llvm-project?rev=329038&view=rev
Log:
Fix fs::proximate tests on platforms where /net exists.

The proximate tests depended on `/net` not being a valid path,
however, on OS X it is.

Correct the tests to handle this.

Modified:

libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.proximate/proximate.pass.cpp

Modified: 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.proximate/proximate.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.proximate/proximate.pass.cpp?rev=329038&r1=329037&r2=329038&view=diff
==
--- 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.proximate/proximate.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.proximate/proximate.pass.cpp
 Mon Apr  2 18:52:12 2018
@@ -79,10 +79,10 @@ TEST_CASE(basic_test) {
   {"a", "/", relative_cwd / "a"},
   {"a/b", "/", relative_cwd / "a/b"},
   {"a", "/net", ".." / relative_cwd / "a"},
-  {"//net/", "//net", "/net/"},
-  {"//net", "//net/", ".."},
-  {"//net", "//net", "."},
-  {"//net/", "//net/", "."},
+  {"//foo/", "//foo", "/foo/"},
+  {"//foo", "//foo/", ".."},
+  {"//foo", "//foo", "."},
+  {"//foo/", "//foo/", "."},
   {"//base", "a", dot_dot_to_root / "../base"},
   {"a", "a", "."},
   {"a/b", "a/b", "."},


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


[PATCH] D45194: [Sema] Defer checking constexpr lambda until after we've finished the lambda class.

2018-04-02 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: rsmith, faisalv.

Previously, this caused ExprConstant to assert while verifying the lambda is 
constexpr:

  void f() {
  int x = 0;
  [=]() constexpr {
  return x;
  };
  }

The problem is that ActOnFinishFunctionBody evaluated the lambda's body before 
BuildLambdaExpr finished the lambda class. This patch fixes the problem by 
moving that check to BuildLambdaExpr.

PR36054

Thanks for taking a look!
Erik


Repository:
  rC Clang

https://reviews.llvm.org/D45194

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp


Index: clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
===
--- clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
+++ clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
@@ -270,4 +270,37 @@
 
 } // end ns test_lambda_is_cce
 
+namespace PR36054 {
+constexpr int fn() {
+  int Capture = 42;
+  return [=]() constexpr { return Capture; }();
+}
+
+static_assert(fn() == 42, "");
+
+template 
+constexpr int tfn() {
+  int Capture = 42;
+  return [=]() constexpr { return Capture; }();
+}
+
+static_assert(tfn() == 42, "");
+
+constexpr int gfn() {
+  int Capture = 42;
+  return [=](auto P) constexpr { return Capture + P; }(58);
+}
+
+static_assert(gfn() == 100, "");
+
+constexpr bool OtherCaptures() {
+  int Capture = 42;
+  constexpr auto Outer = [](auto P) constexpr { return 42 + P; };
+  auto Inner = [&](auto O) constexpr { return O(58) + Capture; };
+  return Inner(Outer) == 142;
+}
+
+static_assert(OtherCaptures(), "");
+} // namespace PR36054
+
 #endif // ndef CPP14_AND_EARLIER
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1604,17 +1604,27 @@
   ExplicitParams, ExplicitResultType,
   CaptureInits, EndLoc,
   ContainsUnexpandedParameterPack);
-  // If the lambda expression's call operator is not explicitly marked 
constexpr
-  // and we are not in a dependent context, analyze the call operator to infer
-  // its constexpr-ness, suppressing diagnostics while doing so.
-  if (getLangOpts().CPlusPlus17 && !CallOperator->isInvalidDecl() &&
-  !CallOperator->isConstexpr() &&
-  !isa(CallOperator->getBody()) &&
-  !Class->getDeclContext()->isDependentContext()) {
-TentativeAnalysisScope DiagnosticScopeGuard(*this);
-CallOperator->setConstexpr(
-CheckConstexprFunctionDecl(CallOperator) &&
-CheckConstexprFunctionBody(CallOperator, CallOperator->getBody()));
+
+  if (!CallOperator->isInvalidDecl()) {
+// If the call operator is explicitly marked constexpr, verify that that is
+// actually the case. This is done here instead of in
+// ActOnFinishFunctionBody because the constexpr evaluator needs access to
+// the completed lambda class to check this.
+if (CallOperator->isConstexpr()) {
+  if (!CheckConstexprFunctionDecl(CallOperator) ||
+  !CheckConstexprFunctionBody(CallOperator, CallOperator->getBody()))
+CallOperator->setInvalidDecl();
+}
+// Otherwise, if we're not in a dependent context, analyze the call 
operator
+// to infer its constexpr-ness, suppressing diagnostics while doing so.
+else if (getLangOpts().CPlusPlus17 &&
+ !isa(CallOperator->getBody()) &&
+ !Class->getDeclContext()->isDependentContext()) {
+  TentativeAnalysisScope DiagnosticScopeGuard(*this);
+  CallOperator->setConstexpr(
+  CheckConstexprFunctionDecl(CallOperator) &&
+  CheckConstexprFunctionBody(CallOperator, CallOperator->getBody()));
+}
   }
 
   // Emit delayed shadowing warnings now that the full capture list is known.
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12883,6 +12883,7 @@
 }
 
 if (!IsInstantiation && FD && FD->isConstexpr() && !FD->isInvalidDecl() &&
+!isLambdaCallOperator(FD) &&
 (!CheckConstexprFunctionDecl(FD) ||
  !CheckConstexprFunctionBody(FD, Body)))
   FD->setInvalidDecl();


Index: clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
===
--- clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
+++ clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
@@ -270,4 +270,37 @@
 
 } // end ns test_lambda_is_cce
 
+namespace PR36054 {
+constexpr int fn() {
+  int Capture = 42;
+  return [=]() constexpr { return Capture; }();
+}
+
+static_assert(fn() == 42, "");
+
+template 
+constexpr int tfn() {
+  int Capture = 42;
+  return [=]() constexpr { return Capture; }();
+}
+
+static_assert(tfn() == 42, "");
+
+conste

[PATCH] D42776: [Sema] Fix an assertion failure in constant expression evaluation of calls to functions with default arguments

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

I think this can be cleaned up a bit further, but I'm fine with that happening 
after the patch lands. Thanks!




Comment at: lib/AST/ExprConstant.cpp:455-456
 // values are stable.
-typedef std::map MapTy;
-typedef MapTy::const_iterator temp_iterator;
+typedef std::map VersionToValueMap;
+typedef std::map MapTy;
 /// Temporaries - Temporary lvalues materialized within this stack frame.

Have you considered using a pair as the key rather than 
a map-of-maps? It'd be preferable to only allocate one heap node rather than 
two for the (hopefully common) case where there is only one version of an 
object.



Comment at: lib/AST/ExprConstant.cpp:466
 
+/// The stack of integers for tracking version numbers for temporaries.
+SmallVector TempVersionStack = {1};

If we're using this for variables in loops too, we should generalize the name 
and the description to not talk about temporaries.


https://reviews.llvm.org/D42776



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


[PATCH] D45174: non-zero-length bit-fields should make a class non-empty

2018-04-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D45174#1055048, @rsmith wrote:

> I wonder if we can delete the `getNonVirtualSize()` check now -- I don't see 
> any way that an empty class can have a nonzero nvsize except by this nonempty 
> anonymous bit-fields situation.


Yup, looks like:

 if (!FoundBase) {
  -if (MDCUsesEBO && BaseDecl->isEmpty() &&
  -BaseLayout.getNonVirtualSize() == CharUnits::Zero()) {
  +if (MDCUsesEBO && BaseDecl->isEmpty()) {
  +  assert(BaseLayout.getNonVirtualSize() == CharUnits::Zero());
 BaseOffset = CharUnits::Zero();
   } else {

Zero test failures.


Repository:
  rC Clang

https://reviews.llvm.org/D45174



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


[PATCH] D45176: implement recent "standard-layout" changes

2018-04-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 140715.
rsmith edited the summary of this revision.
rsmith added a comment.

Patch updated to track "is C++11 standard-layout class" separately from "is 
standard-layout class" so that we can use the former for record layout in the 
targets that need it. This turned out to be less ugly than I'd feared.


https://reviews.llvm.org/D45176

Files:
  AST/ASTImporter.cpp
  AST/DeclCXX.cpp
  AST/RecordLayoutBuilder.cpp
  CXX/drs/dr14xx.cpp
  CXX/drs/dr16xx.cpp
  CXX/drs/dr18xx.cpp
  CXX/drs/dr21xx.cpp
  CXX/drs/dr22xx.cpp
  Layout/watchos-standard-layout.cpp
  ReleaseNotes.rst
  SemaCXX/type-traits.cpp
  Serialization/ASTReaderDecl.cpp
  Serialization/ASTWriter.cpp
  clang/AST/DeclCXX.h
  clang/AST/Type.h
  cxx_dr_status.html
  make_cxx_dr_status

Index: make_cxx_dr_status
===
--- make_cxx_dr_status
+++ make_cxx_dr_status
@@ -129,6 +129,9 @@
   elif status == 'na lib':
 avail = 'N/A (Library DR)'
 avail_style = ' class="na"'
+  elif status == 'na abi':
+avail = 'N/A (ABI constraint)'
+avail_style = ' class="na"'
   elif status.startswith('sup '):
 dup = status.split(' ', 1)[1]
 avail = 'Superseded by %s' % (dup, dup)
Index: cxx_dr_status.html
===
--- cxx_dr_status.html
+++ cxx_dr_status.html
@@ -8365,7 +8365,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1425";>1425
 CD3
 Base-class subobjects of standard-layout structs
-Unknown
+N/A (ABI constraint)
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1426";>1426
@@ -9847,7 +9847,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1672";>1672
 CD4
 Layout compatibility with multiple empty bases
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1673";>1673
@@ -10693,7 +10693,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1813";>1813
 CD4
 Direct vs indirect bases in standard-layout classes
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1814";>1814
@@ -11101,7 +11101,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1881";>1881
 CD4
 Standard-layout classes and unnamed bit-fields
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1882";>1882
@@ -12535,7 +12535,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2120";>2120
 CD4
 Array as first non-static data member in standard-layout class
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2121";>2121
@@ -13189,7 +13189,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2229";>2229
 tentatively ready
 Volatile unnamed bit-fields
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#2230";>2230
Index: SemaCXX/type-traits.cpp
===
--- SemaCXX/type-traits.cpp
+++ SemaCXX/type-traits.cpp
@@ -1353,6 +1353,59 @@
   int t43[F(__is_standard_layout(AnIncompleteType[1]))]; // expected-error {{incomplete type}}
   int t44[F(__is_standard_layout(void))];
   int t45[F(__is_standard_layout(const volatile void))];
+
+  struct HasAnonEmptyBitfield { int : 0; };
+  struct HasAnonBitfield { int : 4; };
+  struct DerivesFromBitfield : HasAnonBitfield {};
+  struct DerivesFromBitfieldWithBitfield : HasAnonBitfield { int : 5; };
+  struct DerivesFromBitfieldTwice : DerivesFromBitfield, HasAnonEmptyBitfield {};
+
+  int t50[T(__is_standard_layout(HasAnonEmptyBitfield))];
+  int t51[T(__is_standard_layout(HasAnonBitfield))];
+  int t52[T(__is_standard_layout(DerivesFromBitfield))];
+  int t53[F(__is_standard_layout(DerivesFromBitfieldWithBitfield))];
+  int t54[F(__is_standard_layout(DerivesFromBitfieldTwice))];
+
+  struct Empty {};
+  struct HasEmptyBase : Empty {};
+  struct HoldsEmptyBase { Empty e; };
+  struct HasRepeatedEmptyBase : Empty, HasEmptyBase {}; // expected-warning {{inaccessible}}
+  struct HasEmptyBaseAsMember : Empty { Empty e; };
+  struct HasEmptyBaseAsSubobjectOfMember1 : Empty { HoldsEmptyBase e; };
+  struct HasEmptyBaseAsSubobjectOfMember2 : Empty { HasEmptyBase e; };
+  struct HasEmptyBaseAsSubobjectOfMember3 : Empty { HoldsEmptyBase e[2]; };
+  struct HasEmptyIndirectBaseAsMember : HasEmptyBase { Empty e; };
+  struct HasEmptyIndirectBaseAsSecondMember : HasEmptyBase { int n; Empty e; };
+  struct HasEmptyIndirectBaseAfterBitfield : HasEmptyBase { int : 4; Empty e; };
+
+  int t60[T(__is_standard_layout(Empty))];
+  int t61[T(__is_standard_layout(HasEmptyBase))];
+  int t62[F(__is_standard_layout(HasRepeatedEmptyBase))];
+  int t63[F(__is_standard_layout(HasEmptyBaseAsMember))];
+  int t64[F(__is_standard_layout(HasEmptyBaseAsSubobjectOfMembe

[PATCH] D44773: [CMake] Use custom command and target to install libc++ headers

2018-04-02 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

ping


Repository:
  rCXX libc++

https://reviews.llvm.org/D44773



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


[PATCH] D44536: Avoid segfault when destructor is not yet known

2018-04-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D44536#1054929, @rsmith wrote:

> It seems that we have two options: either we valiantly try to support this:
>
> - we keep a list of types for which we've tried to form a 
> //delete-expression//, but found that the type was incomplete
> - when such a type is completed, we mark the destructor as used, triggering 
> its synthesis or instantiation if necessary, and likewise for the `operator 
> delete`
> - we change our `CXXDeleteExpr` representation so that we don't store any 
> information that might be changed by completing the class on the expression, 
> such as the selected `OperatorDelete` function and whether we're performing a 
> sized delete


Yeah, this is probably unworkable.  (Of course I'm brainstorming ways we could 
do it — we could have a global entry for late-realized destructor information.  
But it just seems like a terrible idea.)

> ... or we say that we're not interested in calling the destructor for code 
> like this that has undefined behavior. The latter is certainly my preference; 
> it seems hard to justify the complexity required to get this "right", 
> especially since we still won't get it right in cases where we choose to emit 
> some function definitions before the end of the TU.

I agree.

> I agree with John that tracking that we're in the "delete of incomplete class 
> type" case (or some equivalent state, such as a "need to run a cleanup" flag) 
> on the `CXXDeleteExpr` seems best. We should be careful to ensure that we 
> rebuild the expression in template instantiation when the "delete of 
> incomplete class type" flag is set, even if the expression is non-dependent, 
> though. That is, I think this should work:
> 
>   struct X { ~X(); };
>   struct A;
>   A *get();
>   template void f() { delete (&get)(); }
>   struct A { X x; };
>   A *get() { return new A; }
>   void g() { f<0>(); }
> 
> 
> ... even though we first form a (non-dependent) //delete-expression// for an 
> `A` at a point where `A` is incomplete.

Good point.  I agree that we should allow incomplete deletes to work as long as 
they've been completed by instantiation time.


Repository:
  rC Clang

https://reviews.llvm.org/D44536



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


[PATCH] D45145: [Driver] Wire up the -f[no-]rtlib-add-rpath flag and tests

2018-04-02 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL329032: [Driver] Wire up the -f[no-]rtlib-add-rpath flag and 
tests (authored by phosek, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45145?vs=140668&id=140708#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45145

Files:
  cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
  cfe/trunk/test/Driver/arch-specific-libdir-rpath.c

Index: cfe/trunk/test/Driver/arch-specific-libdir-rpath.c
===
--- cfe/trunk/test/Driver/arch-specific-libdir-rpath.c
+++ cfe/trunk/test/Driver/arch-specific-libdir-rpath.c
@@ -6,15 +6,14 @@
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Test that -rpath is not added under -fno-rtlib-add-rpath even if other
 // conditions are met.
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -frtlib-add-rpath \
+// RUN: -fno-rtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Test that -rpath is added only under the right circumstance even if
@@ -24,13 +23,13 @@
 // RUN: %clang %s -### 2>&1 -target x86_64-linux -fsanitize=undefined \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH but no RPATH for -fsanitizer=address w/o -shared-libasan
 // RUN: %clang %s -### 2>&1 -target x86_64-linux -fsanitize=undefined \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH, RPATH for -fsanitize=address -shared-libasan
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
@@ -44,7 +43,7 @@
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-AArch64,RPATH-AArch64 %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-AARCH64,RPATH-AARCH64 %s
 //
 // Add LIBPATH, RPATH with -fsanitize=address for Android
 // RUN: %clang %s -### 2>&1 -target x86_64-linux-android -fsanitize=address \
@@ -62,24 +61,30 @@
 // RUN: %clang %s -### 2>&1 -fsanitize=undefined -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH but no RPATH if no sanitizer or runtime is specified
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Do not add LIBPATH or RPATH if arch-specific subdir doesn't exist
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESDIR,NO-LIBPATH,NO-RPATH %s
-//
+
 // RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
-// LIBPATH-X86_64:  -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
-// RPATH-X86_64:"-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}"
-// LIBPATH-AArch64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)aarch64}}
-// RPATH-AArch64:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)aarch64}}"
-// NO-LIBPATH-NOT:  "-L{{[^"]*Inputs(/|)resource_dir}}"
-// NO-RPATH-NOT:"-rpath" {{.*(/|)Inputs(/|)resource_dir}}
+//
+// LIBPATH-X86_64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
+// RPATH-X86_64:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}"
+//
+// NO-LIBPATH-X86_64-NOT: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
+// NO-RPATH-X86_64-NOT:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}"
+//
+// LIBPATH-AARCH64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)aarch64}}
+// RPATH-AAARCH4:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)aarch64}}"
+//
+// NO-LIBPATH-NOT: "-L{{[^"]*Inputs(/|)resource_dir}}"
+// NO-RPATH-NOT:   "-rpath" {

[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

In https://reviews.llvm.org/D44883#1055018, @Quuxplusone wrote:

> @EricWF, is it important IYO that this warning not trigger in unevaluated 
> contexts even for non-dependently-typed variables?
>  This is the case that seems to be coming up in practice in libc++ tests, but 
> is hard to reason about because it's "only" deliberately contrived test code.
>
>   auto foo(std::exception& value)
>   noexcept(noexcept(value = value)) // ok to diagnose?
>   -> decltype(value = value)  // ok to diagnose?
>   {
>   static_assert(noexcept(value = value));  // ok to diagnose?
>   }


I don't think any of those cases should produce a warning. Self assignment 
doesn't actually take place, so it shouldn't produce a warning about a 
potential self-assignment.


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


r329032 - [Driver] Wire up the -f[no-]rtlib-add-rpath flag and tests

2018-04-02 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Mon Apr  2 16:36:14 2018
New Revision: 329032

URL: http://llvm.org/viewvc/llvm-project?rev=329032&view=rev
Log:
[Driver] Wire up the -f[no-]rtlib-add-rpath flag and tests

D30700 added the -f[no-]rtlib-add-rpath flag, but that flag was never
wired up in the driver and tests were updated to check whether it
actually does anything. This patch wires up the flag and updates test.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/test/Driver/arch-specific-libdir-rpath.c

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=329032&r1=329031&r2=329032&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Mon Apr  2 16:36:14 2018
@@ -463,6 +463,10 @@ void tools::AddGoldPlugin(const ToolChai
 
 void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
  ArgStringList &CmdArgs) {
+  if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
+options::OPT_fno_rtlib_add_rpath, false))
+return;
+
   std::string CandidateRPath = TC.getArchSpecificLibPath();
   if (TC.getVFS().exists(CandidateRPath)) {
 CmdArgs.push_back("-rpath");

Modified: cfe/trunk/test/Driver/arch-specific-libdir-rpath.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/arch-specific-libdir-rpath.c?rev=329032&r1=329031&r2=329032&view=diff
==
--- cfe/trunk/test/Driver/arch-specific-libdir-rpath.c (original)
+++ cfe/trunk/test/Driver/arch-specific-libdir-rpath.c Mon Apr  2 16:36:14 2018
@@ -6,7 +6,6 @@
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Test that -rpath is not added under -fno-rtlib-add-rpath even if other
@@ -14,7 +13,7 @@
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -frtlib-add-rpath \
+// RUN: -fno-rtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Test that -rpath is added only under the right circumstance even if
@@ -24,13 +23,13 @@
 // RUN: %clang %s -### 2>&1 -target x86_64-linux -fsanitize=undefined \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH but no RPATH for -fsanitizer=address w/o -shared-libasan
 // RUN: %clang %s -### 2>&1 -target x86_64-linux -fsanitize=undefined \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH, RPATH for -fsanitize=address -shared-libasan
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
@@ -44,7 +43,7 @@
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-AArch64,RPATH-AArch64 %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-AARCH64,RPATH-AARCH64 %s
 //
 // Add LIBPATH, RPATH with -fsanitize=address for Android
 // RUN: %clang %s -### 2>&1 -target x86_64-linux-android -fsanitize=address \
@@ -62,24 +61,30 @@
 // RUN: %clang %s -### 2>&1 -fsanitize=undefined -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH but no RPATH if no sanitizer or runtime is specified
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Do not add LIBPATH or RPATH if arch-specific subdir doesn't exist
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESD

[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

No, the analysis is intentionally syntactic; it should apply even on 
dependently-typed arguments (but not get re-checked on instantiation).  But I 
agree that the warning ought to be disabled in unevaluated contexts.


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[libcxx] r329031 - Implement P0430R2 - File system library on non-POSIX systems.

2018-04-02 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Mon Apr  2 16:35:24 2018
New Revision: 329031

URL: http://llvm.org/viewvc/llvm-project?rev=329031&view=rev
Log:
Implement P0430R2 - File system library on non-POSIX systems.

This patch implements P0430R2, who's largest change is adding the path::format
enumeration for supporting path format conversions in path constructors.

However, since libc++'s filesystem only really supports POSIX like systems,
there are no real changes needed. This patch simply adds the format enum
and then ignores it when it's passed to constructors.

Added:

libcxx/trunk/test/std/experimental/filesystem/fs.enum/enum.path.format.pass.cpp
Modified:
libcxx/trunk/include/experimental/filesystem

libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp
libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/experimental/filesystem
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=329031&r1=329030&r2=329031&view=diff
==
--- libcxx/trunk/include/experimental/filesystem (original)
+++ libcxx/trunk/include/experimental/filesystem Mon Apr  2 16:35:24 2018
@@ -721,24 +721,31 @@ public:
 typedef _VSTD::string_view __string_view;
 static _LIBCPP_CONSTEXPR value_type preferred_separator = '/';
 
+enum class _LIBCPP_ENUM_VIS format : unsigned char {
+  auto_format,
+  native_format,
+  generic_format
+};
+
 // constructors and destructor
 _LIBCPP_INLINE_VISIBILITY path() _NOEXCEPT {}
 _LIBCPP_INLINE_VISIBILITY path(const path& __p)  : __pn_(__p.__pn_) {}
 _LIBCPP_INLINE_VISIBILITY path(path&& __p) _NOEXCEPT : 
__pn_(_VSTD::move(__p.__pn_)) {}
 
 _LIBCPP_INLINE_VISIBILITY
-path(string_type&& __s) _NOEXCEPT : __pn_(_VSTD::move(__s)) {}
+path(string_type&& __s, format = format::auto_format) _NOEXCEPT
+: __pn_(_VSTD::move(__s)) {}
 
 template <
 class _Source,
 class = _EnableIfPathable<_Source, void>
 >
-path(const _Source& __src) {
+path(const _Source& __src, format = format::auto_format) {
 _SourceCVT<_Source>::__append_source(__pn_, __src);
 }
 
 template 
-path(_InputIt __first, _InputIt __last) {
+path(_InputIt __first, _InputIt __last, format = format::auto_format) {
 typedef typename iterator_traits<_InputIt>::value_type _ItVal;
 _PathCVT<_ItVal>::__append_range(__pn_, __first, __last);
 }
@@ -747,9 +754,11 @@ public:
 template 
  >
-path(const _Source& __src, const locale& __loc);
+path(const _Source& __src, const locale& __loc,
+ format = format::auto_format);
 template 
-path(_InputIt __first, _InputIt _last, const locale& __loc);
+path(_InputIt __first, _InputIt _last, const locale& __loc,
+ format = format::auto_format);
 
 _LIBCPP_INLINE_VISIBILITY
 ~path() = default;

Modified: 
libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp?rev=329031&r1=329030&r2=329031&view=diff
==
--- 
libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/filesystem/class.path/path.member/path.construct/source.pass.cpp
 Mon Apr  2 16:35:24 2018
@@ -29,8 +29,8 @@
 #include "filesystem_test_helper.hpp"
 
 
-template 
-void RunTestCase(MultiStringType const& MS) {
+template 
+void RunTestCaseImpl(MultiStringType const& MS, Args... args) {
   using namespace fs;
   const char* Expect = MS;
   const CharT* TestPath = MS;
@@ -41,44 +41,52 @@ void RunTestCase(MultiStringType const&
   // StringTypes
   {
 const std::basic_string S(TestPath);
-path p(S);
+path p(S, args...);
 assert(p.native() == Expect);
 assert(p.string() == TestPath);
 assert(p.string() == S);
   }
   {
 const std::basic_string_view S(TestPath);
-path p(S);
+path p(S, args...);
 assert(p.native() == Expect);
 assert(p.string() == TestPath);
 assert(p.string() == S);
   }
   // Char* pointers
   {
-path p(TestPath);
+path p(TestPath, args...);
 assert(p.native() == Expect);
 assert(p.string() == TestPath);
   }
   {
-path p(TestPath, TestPathEnd);
+path p(TestPath, TestPathEnd, args...);
 assert(p.native() == Expect);
 assert(p.string() == TestPath);
   }
   // Iterators
   {
 using It = input_iterator;
-path p(It{TestPath});
+path p(It{TestPath}, args...);
 assert(p.native() == Expect);
 assert(p.string() == TestPath);
   }
   {
 using It = input_iterator;
-path p(It{TestPath}, It{TestPathEnd});
+p

[PATCH] D45174: non-zero-length bit-fields should make a class non-empty

2018-04-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D45174#1054936, @rnk wrote:

> I've convinced myself that this is NFC for MS record layout because this is 
> the only place we use RD->isEmpty() that matters:
>
>   if (!FoundBase) {
> if (MDCUsesEBO && BaseDecl->isEmpty() &&
> BaseLayout.getNonVirtualSize() == CharUnits::Zero()) {
>   BaseOffset = CharUnits::Zero();
> } else {
>   // Otherwise, lay the base out at the end of the MDC.
>   BaseOffset = Size = Size.alignTo(Info.Alignment);
> }
>   }
>   
>
> In particular, that `getNonVirtualSize()` check returns false when unnamed 
> bitfields get involved.


I wonder if we can delete the `getNonVirtualSize()` check now -- I don't see 
any way that an empty class can have a nonzero nvsize except by this nonempty 
anonymous bit-fields situation.


Repository:
  rC Clang

https://reviews.llvm.org/D45174



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


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

> The warning is fundamentally about dataflow, but this doesn't apply to 
> unevaluated expressions. There are plenty of cases where a user might want to 
> ask if assignment is well formed on noexcept using only one variable. For 
> example:
> 
>   template  void foo(T& value) noexcept(noexcept(value = value)) { 
> /* perform an assignment somewhere */ }

My impression is that this case will not trigger the warning because the 
variable `value` is dependently typed.
I agree there should be a regression test for this exact case just to make sure 
of that.

@EricWF, is it important IYO that this warning not trigger in unevaluated 
contexts even for non-dependently-typed variables?
This is the case that seems to be coming up in practice in libc++ tests, but is 
hard to reason about because it's "only" deliberately contrived test code.

  auto foo(std::exception& value)
  noexcept(noexcept(value = value)) // ok to diagnose?
  -> decltype(value = value)  // ok to diagnose?
  {
  static_assert(noexcept(value = value));  // ok to diagnose?
  }


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D45013: Generate warning when over-aligned new call is required but not supported.

2018-04-02 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai accepted this revision.
vsapsai added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D45013#1053998, @EricWF wrote:

> In https://reviews.llvm.org/D45013#1052600, @vsapsai wrote:
>
> > Does it make sense to have a warning for `__libcpp_deallocate` and 
> > `get_temporary_buffer` too? Not sure about deallocate as you have allocated 
> > memory already and allocation has a warning. So for deallocation a warning 
> > can be too noisy. But for `get_temporary_buffer` the warning seems 
> > reasonable, unless I'm missing something.
>
>
> `get_temporary_buffer` shouldn't return a temporary buffer when the request 
> is over-aligned and aligned allocation isn't available; so I don't think we 
> should warn on it.


OK. Makes sense. We don't have data indicating it is a widespread issue that 
developers forget to address, so no need for the warning. Also 
`get_temporary_buffer` is deprecated in C++17, so there is not much value in 
investing into it.

Overall the change looks good to me, just a few minor NFC tweaks.




Comment at: include/memory:2030
 #else
-if (__is_overaligned_for_new(__alignof(_Tp)))
+if (_LIBCPP_IS_OVERALIGNED_FOR_NEW(__alignof(_Tp)))
 {

Is the indentation for these 2 ifs correct? They seem to be aligned with `#if` 
and not with `while`. Don't know if that is intentional.



Comment at: include/new:235-239
 #ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
-  return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
+#define _LIBCPP_IS_OVERALIGNED_FOR_NEW(__align) __align > 
__STDCPP_DEFAULT_NEW_ALIGNMENT__
 #else
-  return __align > alignment_of::value;
+#define _LIBCPP_ISOVERALIGNED_FOR_NEW(__align) __align > 
_VSTD::alignment_of<_VSTD::max_align_t>::value
 #endif

Seems non-critical, maybe put `__align` in parentheses like `(__align) > ...`? 
But I don't know what is libc++ style regarding macro arguments.


Repository:
  rCXX libc++

https://reviews.llvm.org/D45013



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


[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

`std::move` would definitely be special in this regard if there were a pressing 
benefit to be gained — i.e., if people were currently getting bitten by 
accidentally discarded calls of `std::move(x)`. But you haven't shown that 
people are getting bitten today; in fact I think you said the opposite, right? 
that there were *no* instances of this happening in the real codebases you 
tested? So in that case, this diagnostic doesn't have a pressing benefit IMHO, 
and Clang could safely wait for the library vendors to do the work.


Repository:
  rC Clang

https://reviews.llvm.org/D45163



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


[PATCH] D41316: [libcxx] Allow random_device to be built optionally

2018-04-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Yes, the standard says you're allowed to throw an exception from the 
random_device constructor, or use a PRNG with an arbitrary seed, or even just 
return zeros from operator(). But none of those behaviors are actually useful; 
the code will compile, but you won't get the expected randomness.  So I prefer 
this solution, even if it isn't strictly standard-compliant.

(I'll post an updated version with the tests fixed soon.)


https://reviews.llvm.org/D41316



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


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

One thing I would like to see in this patch is ensuring the warning doesn't get 
generated when the expression appears in unevaluated contexts, such as 
`decltype` and `noexcept`. The warning is fundamentally about dataflow, but 
this doesn't apply to unevaluated expressions.
There are plenty of cases where a user might want to ask if assignment is well 
formed on `noexcept` using only one variable. For example:

  template  void foo(T& value) noexcept(noexcept(value = value)) { /* 
perform an assignment somewhere */ }


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


r329025 - CodeGenCXX: support PreserveMostCC in MS ABI

2018-04-02 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Mon Apr  2 15:25:50 2018
New Revision: 329025

URL: http://llvm.org/viewvc/llvm-project?rev=329025&view=rev
Log:
CodeGenCXX: support PreserveMostCC in MS ABI

Microsoft has reserved 'U' for the PreserveMostCC which is used in the
swift runtime.  Add support for this.  This allows the swift runtime to
be built for Windows again.

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/Basic/Targets/X86.h
cfe/trunk/test/CodeGenCXX/msabi-swiftcall-cc.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=329025&r1=329024&r2=329025&view=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Mon Apr  2 15:25:50 2018
@@ -2184,6 +2184,7 @@ void MicrosoftCXXNameMangler::mangleCall
 case CC_X86FastCall: Out << 'I'; break;
 case CC_X86VectorCall: Out << 'Q'; break;
 case CC_Swift: Out << 'S'; break;
+case CC_PreserveMost: Out << 'U'; break;
 case CC_X86RegCall: Out << 'w'; break;
   }
 }

Modified: cfe/trunk/lib/Basic/Targets/X86.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.h?rev=329025&r1=329024&r2=329025&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.h (original)
+++ cfe/trunk/lib/Basic/Targets/X86.h Mon Apr  2 15:25:50 2018
@@ -287,6 +287,7 @@ public:
 case CC_X86VectorCall:
 case CC_X86RegCall:
 case CC_C:
+case CC_PreserveMost:
 case CC_Swift:
 case CC_X86Pascal:
 case CC_IntelOclBicc:

Modified: cfe/trunk/test/CodeGenCXX/msabi-swiftcall-cc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/msabi-swiftcall-cc.cpp?rev=329025&r1=329024&r2=329025&view=diff
==
--- cfe/trunk/test/CodeGenCXX/msabi-swiftcall-cc.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/msabi-swiftcall-cc.cpp Mon Apr  2 15:25:50 2018
@@ -1,28 +1,67 @@
 // RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fdeclspec -emit-llvm %s 
-o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -emit-llvm 
%s -o - | FileCheck %s -check-prefix CHECK-64
 
 void __attribute__((__swiftcall__)) f() {}
 // CHECK-DAG: @"?f@@YSXXZ"
+// CHECK-64-DAG: @"?f@@YSXXZ"
 
 void (__attribute__((__swiftcall__)) *p)();
 // CHECK-DAG: @"?p@@3P6SXXZA"
+// CHECK-64-DAG: @"?p@@3P6SXXZEA
 
 namespace {
 void __attribute__((__swiftcall__)) __attribute__((__used__)) f() { }
-// CHECK-DAG: "?f@?A@@YSXXZ"
 }
+// CHECK-DAG: @"?f@?A@@YSXXZ"
+// CHECK-64-DAG: @"?f@?A@@YSXXZ"
 
 namespace n {
 void __attribute__((__swiftcall__)) f() {}
-// CHECK-DAG: "?f@n@@YSXXZ"
 }
+// CHECK-DAG: @"?f@n@@YSXXZ"
+// CHECK-64-DAG: @"?f@n@@YSXXZ"
 
 struct __declspec(dllexport) S {
   S(const S &) = delete;
   S & operator=(const S &) = delete;
   void __attribute__((__swiftcall__)) m() { }
-  // CHECK-DAG: "?m@S@@QASXXZ"
 };
+// CHECK-DAG: @"?m@S@@QASXXZ"
+// CHECK-64-DAG: @"?m@S@@QEASXXZ"
 
 void f(void (__attribute__((__swiftcall__))())) {}
-// CHECK-DAG: "?f@@YAXP6SXXZ@Z"
+// CHECK-DAG: @"?f@@YAXP6SXXZ@Z"
+// CHECK-64-DAG: @"?f@@YAXP6SXXZ@Z"
+
+void __attribute__((__preserve_most__)) g() {}
+// CHECK-DAG: @"?g@@YUXXZ"
+// CHECK-64-DAG: @"?g@@YUXXZ"
+
+void (__attribute__((__preserve_most__)) *q)();
+// CHECK-DAG: @"?q@@3P6UXXZA"
+// CHECK-64-DAG: @"?q@@3P6UXXZEA"
+
+namespace {
+void __attribute__((__preserve_most__)) __attribute__((__used__)) g() {}
+}
+// CHECK-DAG: @"?g@?A@@YUXXZ"
+// CHECK-64-DAG: @"?g@?A@@YUXXZ"
+
+namespace n {
+void __attribute__((__preserve_most__)) g() {}
+}
+// CHECK-DAG: @"?g@n@@YUXXZ"
+// CHECK-64-DAG: @"?g@n@@YUXXZ"
+
+struct __declspec(dllexport) T {
+  T(const T &) = delete;
+  T & operator=(const T &) = delete;
+  void __attribute__((__preserve_most__)) m() {}
+};
+// CHECK-DAG: @"?m@T@@QAUXXZ"
+// CHECK-64-DAG: @"?m@T@@QEAUXXZ"
+
+void g(void (__attribute__((__preserve_most__))())) {}
+// CHECK-DAG: @"?g@@YAXP6UXXZ@Z"
+// CHECK-64-DAG: @"?g@@YAXP6UXXZ@Z"
 


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


[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D45163#1054925, @Quuxplusone wrote:

> > I think it wouldn't be unreasonable to ask standard library maintainers to 
> > add `[[nodiscard]]` to `std::move`
>
> +1. Also `std::forward`, for sure. Basically any metaprogramming function 
> that is statically known to return a reference to its argument.
>  This knowledge is already in the brains of library vendors; they ought to 
> just write it down in the form of `[[nodiscard]]` annotations. This PR smells 
> like Clang is trying to "cut out the middleman" and just make up its own 
> proprietary list of metaprogramming functions that are statically known to 
> return references to arguments, which is not the most effective or 
> futureproof way to go about it. Let the library vendors deal with it, please, 
> says me.


A few updates:

- `std::move()` *should* be a part of the next paper about `[[nodiscard]]`. Yay!
- https://reviews.llvm.org/D45179 *should* make those attributes usable in 
pre-C++17 code. For people using libc++.

But, some points still remain:

- `std::move()` is not `[[nodiscard]]` yet
- https://reviews.llvm.org/D45179 is not merged yet
- Even when either/both things happen, it won't really help those not using 
libc++ [trunk] / C++17-or-later. That is a *lot* of people.

I do agree with @Quuxplusone, we wouldn't want to pull the list of all the 
`[[nodiscard]]` functions from the standard into clang just because. (we could 
do that with `clang-tidy`)
But maybe `std::move()` is a bit special in this regard... ?


Repository:
  rC Clang

https://reviews.llvm.org/D45163



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


[libcxx] r329023 - [libcxx] Disable testing with system lib for 2 tests verifying debug mode.

2018-04-02 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon Apr  2 15:09:57 2018
New Revision: 329023

URL: http://llvm.org/viewvc/llvm-project?rev=329023&view=rev
Log:
[libcxx] Disable testing with system lib for 2 tests verifying debug mode.


Modified:

libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp

libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp

Modified: 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp?rev=329023&r1=329022&r2=329023&view=diff
==
--- 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp 
(original)
+++ 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception.pass.cpp 
Mon Apr  2 15:09:57 2018
@@ -14,6 +14,9 @@
 // MODULES_DEFINES: _LIBCPP_DEBUG_USE_EXCEPTIONS
 // MODULES_DEFINES: _LIBCPP_DEBUG=0
 
+// Can't test the system lib because this test enables debug mode
+// UNSUPPORTED: with_system_cxx_lib
+
 // 
 
 // class promise

Modified: 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp?rev=329023&r1=329022&r2=329023&view=diff
==
--- 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/thread/futures/futures.promise/set_exception_at_thread_exit.pass.cpp
 Mon Apr  2 15:09:57 2018
@@ -14,6 +14,9 @@
 // MODULES_DEFINES: _LIBCPP_DEBUG_USE_EXCEPTIONS
 // MODULES_DEFINES: _LIBCPP_DEBUG=0
 
+// Can't test the system lib because this test enables debug mode
+// UNSUPPORTED: with_system_cxx_lib
+
 // 
 
 // class promise


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


[PATCH] D45174: non-zero-length bit-fields should make a class non-empty

2018-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a subscriber: majnemer.
rnk added a comment.

In https://reviews.llvm.org/D45174#1054820, @rsmith wrote:

> +rnk This might also affect the MS ABI, but it does not result in any test 
> case failures at least (and MSVC's type trait matches our state after this 
> patch rather than before).


I've convinced myself that this is NFC for MS record layout because this is the 
only place we use RD->isEmpty() that matters:

  if (!FoundBase) {
if (MDCUsesEBO && BaseDecl->isEmpty() &&
BaseLayout.getNonVirtualSize() == CharUnits::Zero()) {
  BaseOffset = CharUnits::Zero();
} else {
  // Otherwise, lay the base out at the end of the MDC.
  BaseOffset = Size = Size.alignTo(Info.Alignment);
}
  }

In particular, that `getNonVirtualSize()` check returns false when unnamed 
bitfields get involved. Here's a layout:

  struct __declspec(empty_bases) A { char : 3; };
  struct __declspec(empty_bases) B { char : 3; };
  struct UseEmpty : A, B {
char space;
  } o[1];
  static_assert(sizeof(o) == 3, "incorrect layout");
  
  
  *** Dumping AST Record Layout
   0 | struct A (empty)
   0:0-2 |   char
 | [sizeof=1, align=1,
 |  nvsize=1, nvalign=1]
  
  *** Dumping AST Record Layout
   0 | struct B (empty)
   0:0-2 |   char
 | [sizeof=1, align=1,
 |  nvsize=1, nvalign=1]
  
  *** Dumping AST Record Layout
   0 | struct UseEmpty
   0 |   struct A (base) (empty)
   0:0-2 | char
   1 |   struct B (base) (empty)
   1:0-2 | char
   2 |   char space
 | [sizeof=3, align=1,
 |  nvsize=3, nvalign=1]

So even though these classes went from "empty" to "non-empty", we previously 
allocated space for them. I think @majnemer spent a while on that.


Repository:
  rC Clang

https://reviews.llvm.org/D45174



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


[PATCH] D44536: Avoid segfault when destructor is not yet known

2018-04-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D44536#1051232, @rjmccall wrote:

> Right.  Again, I'd like Richard to weigh in here, but my suspicion would be 
> that, somehow, the fact that e is an incomplete type when we type-check that 
> call is combining poorly with the fact that it's declared by the time that we 
> generate IR for it.  We probably do not record the existence of a pre-emptive 
> use of the destructor.  There is no other way to get into this situation 
> because every other thing that cares about the existence of a destructor 
> requires a complete type.


Yes, that's exactly the situation. In all other cases, we can mark the 
destructor itself as used, and trigger synthesis / instantiation at that point, 
but if the class is incomplete, we don't have a destructor declaration to mark, 
and we can't even generate one. (That's not the only problem, though: there is 
state we store on the `CXXDeleteExpr`, such as the `OperatorDelete` and the 
sized delete flag, that we also need a complete class type in order to 
correctly generate.)


Repository:
  rC Clang

https://reviews.llvm.org/D44536



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


[PATCH] D44536: Avoid segfault when destructor is not yet known

2018-04-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

It seems that we have two options: either we valiantly try to support this:

- we keep a list of types for which we've tried to form a 
//delete-expression//, but found that the type was incomplete
- when such a type is completed, we mark the destructor as used, triggering its 
synthesis or instantiation if necessary, and likewise for the `operator delete`
- we change our `CXXDeleteExpr` representation so that we don't store any 
information that might be changed by completing the class on the expression, 
such as the selected `OperatorDelete` function and whether we're performing a 
sized delete

... or we say that we're not interested in calling the destructor for code like 
this that has undefined behavior. The latter is certainly my preference; it 
seems hard to justify the complexity required to get this "right", especially 
since we still won't get it right in cases where we choose to emit some 
function definitions before the end of the TU.

I agree with John that tracking that we're in the "delete of incomplete class 
type" case (or some equivalent state, such as a "need to run a cleanup" flag) 
on the `CXXDeleteExpr` seems best. We should be careful to ensure that we 
rebuild the expression in template instantiation when the "delete of incomplete 
class type" flag is set, even if the expression is non-dependent, though. That 
is, I think this should work:

  struct X { ~X(); };
  struct A;
  A *get();
  template void f() { delete (&get)(); }
  struct A { X x; };
  A *get() { return new A; }
  void g() { f<0>(); }

... even though we first form a (non-dependent) //delete-expression// for an 
`A` at a point where `A` is incomplete. (Note: the above example is carefully 
contrived to cause `TreeTransform` to reuse the `CXXDeleteExpr` from the 
template AST in the instantiation. Sadly the implicit array-to-pointer decay in 
the `CallExpr` is enough to cause it to rebuild rather than reuse...)


Repository:
  rC Clang

https://reviews.llvm.org/D44536



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


[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

> I think it wouldn't be unreasonable to ask standard library maintainers to 
> add `[[nodiscard]]` to `std::move`

+1. Also `std::forward`, for sure. Basically any metaprogramming function that 
is statically known to return a reference to its argument.
This knowledge is already in the brains of library vendors; they ought to just 
write it down in the form of `[[nodiscard]]` annotations. This PR smells like 
Clang is trying to "cut out the middleman" and just make up its own proprietary 
list of metaprogramming functions that are statically known to return 
references to arguments, which is not the most effective or futureproof way to 
go about it. Let the library vendors deal with it, please, says me.


Repository:
  rC Clang

https://reviews.llvm.org/D45163



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


[PATCH] D41316: [libcxx] Allow random_device to be built optionally

2018-04-02 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

[rand.device]/2 seems to be the authoritative word here:

  If implementation limitations prevent generating nondeterministic random 
numbers, the implementation may employ a random number engine.


https://reviews.llvm.org/D41316



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


r328968 - Fix unused variable warning introduced at revision 328910.

2018-04-02 Thread Andrea Di Biagio via cfe-commits
Author: adibiagio
Date: Mon Apr  2 05:04:37 2018
New Revision: 328968

URL: http://llvm.org/viewvc/llvm-project?rev=328968&view=rev
Log:
Fix unused variable warning introduced at revision 328910.

Modified:
cfe/trunk/lib/Analysis/LiveVariables.cpp

Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=328968&r1=328967&r2=328968&view=diff
==
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Mon Apr  2 05:04:37 2018
@@ -383,8 +383,7 @@ void TransferFunctions::VisitDeclRefExpr
   bool InAssignment = LV.inAssignment[DR];
   if (const auto *BD = dyn_cast(D)) {
 if (!InAssignment)
-  val.liveBindings =
-  LV.BSetFact.add(val.liveBindings, cast(D));
+  val.liveBindings = LV.BSetFact.add(val.liveBindings, BD);
   } else if (const auto *VD = dyn_cast(D)) {
 if (!InAssignment && !isAlwaysAlive(VD))
   val.liveDecls = LV.DSetFact.add(val.liveDecls, VD);


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


[clang-tools-extra] r328932 - [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-04-02 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Sun Apr  1 04:51:57 2018
New Revision: 328932

URL: http://llvm.org/viewvc/llvm-project?rev=328932&view=rev
Log:
[clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility 
with clang static analyzer

This macro is widely used in many well-known projects, ex. Chromium.
But it's not set for clang-tidy, so for ex. DCHECK in Chromium is not 
considered as [[no-return]], and a lot of false-positive warnings about nullptr 
dereferenced are emitted.
This patch fixes the issue by explicitly added macro definition.

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

Added:

clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp  
 (with props)
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=328932&r1=328931&r2=328932&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Sun Apr  1 04:51:57 2018
@@ -481,6 +481,16 @@ void runClangTidy(clang::tidy::ClangTidy
   ClangTool Tool(Compilations, InputFiles,
  std::make_shared(), BaseFS);
 
+  // Add __clang_analyzer__ macro definition for compatibility with the clang
+  // static analyzer.
+  ArgumentsAdjuster ClangTidyMacroDefinitionInserter =
+  [&Context](const CommandLineArguments &Args, StringRef Filename) {
+ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
+CommandLineArguments AdjustedArgs = Args;
+AdjustedArgs.emplace_back("-D__clang_analyzer__");
+return AdjustedArgs;
+  };
+
   // Add extra arguments passed by the clang-tidy command-line.
   ArgumentsAdjuster PerFileExtraArgumentsInserter =
   [&Context](const CommandLineArguments &Args, StringRef Filename) {
@@ -515,6 +525,7 @@ void runClangTidy(clang::tidy::ClangTidy
 return AdjustedArgs;
   };
 
+  Tool.appendArgumentsAdjuster(ClangTidyMacroDefinitionInserter);
   Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
   Tool.appendArgumentsAdjuster(PluginArgumentsRemover);
   if (Profile)

Added: 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp?rev=328932&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
(added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
Sun Apr  1 04:51:57 2018
@@ -0,0 +1,8 @@
+// RUN: %check_clang_tidy %s * %t
+
+#if defined(__clang_analyzer__)
+#warning __clang_analyzer__ is defined
+#endif
+// CHECK-MESSAGES: :[[@LINE-2]]:2: warning: __clang_analyzer__ is defined 
[clang-diagnostic-#warnings]
+
+

Propchange: 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
--
svn:executable = *


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


[PATCH] D45185: [clang-format] Support lightweight Objective-C generics

2018-04-02 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak.
Herald added subscribers: cfe-commits, klimek.

Previously, `clang-format` didn't understand lightweight
Objective-C generics, which have the form:

  @interface Foo , ... > ...

The lightweight generic specifier list appears before the base
class, if present, but because it starts with < like the protocol
specifier list, `UnwrappedLineParser` was getting confused and
failed to parse interfaces with both generics and protocol lists:

  @interface Foo  : NSObject 

Since the parsed line would be incomplete, the format result
would be very confused (e.g., https://bugs.llvm.org/show_bug.cgi?id=24381).

This fixes the issue by explicitly parsing the ObjC lightweight
generic conformance list, so the line is fully parsed.

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

Test Plan: New tests added. Ran tests with:

  % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D45185

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -298,6 +298,18 @@
"+ (id)init;\n"
"@end");
 
+  verifyFormat("@interface Foo  : Bar  {\n"
+   "  int _i;\n"
+   "}\n"
+   "+ (id)init;\n"
+   "@end");
+
+  verifyFormat("@interface Foo > : Xyzzy  {\n"
+   "  int _i;\n"
+   "}\n"
+   "+ (id)init;\n"
+   "@end");
+
   verifyFormat("@interface Foo (HackStuff) {\n"
"  int _i;\n"
"}\n"
Index: lib/Format/UnwrappedLineParser.h
===
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -116,6 +116,7 @@
   // parses the record as a child block, i.e. if the class declaration is an
   // expression.
   void parseRecord(bool ParseAsExpr = false);
+  void parseObjCLightweightGenericList();
   void parseObjCProtocolList();
   void parseObjCUntilAtEnd();
   void parseObjCInterfaceOrImplementation();
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2120,6 +2120,26 @@
   // "} n, m;" will end up in one unwrapped line.
 }
 
+void UnwrappedLineParser::parseObjCLightweightGenericList() {
+  assert(FormatTok->Tok.is(tok::less) && "'<' expected.");
+  // Unlike protocol lists, generic parameterizations support
+  // nested angles:
+  //
+  // @interface Foo> :
+  // NSObject 
+  //
+  // so we need to count how many open angles we have left.
+  unsigned NumOpenAngles = 1;
+  do {
+nextToken();
+if (FormatTok->Tok.is(tok::less))
+  NumOpenAngles++;
+else if (FormatTok->Tok.is(tok::greater))
+  NumOpenAngles--;
+  } while (!eof() && NumOpenAngles != 0);
+  nextToken(); // Skip '>'.
+}
+
 void UnwrappedLineParser::parseObjCProtocolList() {
   assert(FormatTok->Tok.is(tok::less) && "'<' expected.");
   do
@@ -2155,7 +2175,11 @@
   nextToken();
   nextToken(); // interface name
 
-  // @interface can be followed by either a base class, or a category.
+  // @interface can be followed by a lightweight generic
+  // specialization list, then either a base class or a category.
+  if (FormatTok->Tok.is(tok::less))
+parseObjCLightweightGenericList();
+
   if (FormatTok->Tok.is(tok::colon)) {
 nextToken();
 nextToken(); // base class name


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -298,6 +298,18 @@
"+ (id)init;\n"
"@end");
 
+  verifyFormat("@interface Foo  : Bar  {\n"
+   "  int _i;\n"
+   "}\n"
+   "+ (id)init;\n"
+   "@end");
+
+  verifyFormat("@interface Foo > : Xyzzy  {\n"
+   "  int _i;\n"
+   "}\n"
+   "+ (id)init;\n"
+   "@end");
+
   verifyFormat("@interface Foo (HackStuff) {\n"
"  int _i;\n"
"}\n"
Index: lib/Format/UnwrappedLineParser.h
===
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -116,6 +116,7 @@
   // parses the record as a child block, i.e. if the class declaration is an
   // expression.
   void parseRecord(bool ParseAsExpr = false);
+  void parseObjCLightweightGenericList();
   void parseObjCProtocolList();
   void parseObjCUntilAtEnd();
   void parseObjCInterfaceOrImplementation();
Index: lib/Format/UnwrappedLineParser.cpp

[PATCH] D44995: [Driver] Include the Android multiarch includes.

2018-04-02 Thread Dan Albert via Phabricator via cfe-commits
danalbert added a comment.

Ping?


Repository:
  rC Clang

https://reviews.llvm.org/D44995



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


[PATCH] D45174: non-zero-length bit-fields should make a class non-empty

2018-04-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

+rnk This might also affect the MS ABI, but it does not result in any test case 
failures at least (and MSVC's type trait matches our state after this patch 
rather than before).


Repository:
  rC Clang

https://reviews.llvm.org/D45174



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


[PATCH] D45112: [MS] Emit vftable thunks for functions with incomplete prototypes

2018-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL329009: [MS] Emit vftable thunks for functions with 
incomplete prototypes (authored by rnk, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45112?vs=140499&id=140681#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45112

Files:
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/CodeGen/CGVTables.cpp
  cfe/trunk/lib/CodeGen/CGVTables.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/CodeGenTypes.h
  cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
  cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped-return.cpp
  cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped.cpp

Index: cfe/trunk/lib/CodeGen/CGCall.cpp
===
--- cfe/trunk/lib/CodeGen/CGCall.cpp
+++ cfe/trunk/lib/CodeGen/CGCall.cpp
@@ -514,8 +514,8 @@
 /// correct type, and the caller will bitcast the function to the correct
 /// prototype.
 const CGFunctionInfo &
-CodeGenTypes::arrangeMSMemberPointerThunk(const CXXMethodDecl *MD) {
-  assert(MD->isVirtual() && "only virtual memptrs have thunks");
+CodeGenTypes::arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD) {
+  assert(MD->isVirtual() && "only methods have thunks");
   CanQual FTP = GetFormalType(MD);
   CanQualType ArgTys[] = { GetThisType(Context, MD->getParent()) };
   return arrangeLLVMFunctionInfo(Context.VoidTy, /*instanceMethod=*/false,
Index: cfe/trunk/lib/CodeGen/CodeGenModule.h
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.h
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h
@@ -800,7 +800,8 @@
   ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
 
   /// Get the address of the thunk for the given global decl.
-  llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
+  llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
+ GlobalDecl GD);
 
   /// Get a reference to the target of VD.
   ConstantAddress GetWeakRefReference(const ValueDecl *VD);
Index: cfe/trunk/lib/CodeGen/CodeGenFunction.h
===
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h
@@ -1692,10 +1692,10 @@
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
 
   void StartThunk(llvm::Function *Fn, GlobalDecl GD,
-  const CGFunctionInfo &FnInfo);
+  const CGFunctionInfo &FnInfo, bool IsUnprototyped);
 
-  void EmitCallAndReturnForThunk(llvm::Constant *Callee,
- const ThunkInfo *Thunk);
+  void EmitCallAndReturnForThunk(llvm::Constant *Callee, const ThunkInfo *Thunk,
+ bool IsUnprototyped);
 
   void FinishThunk();
 
@@ -1705,7 +1705,8 @@
 
   /// Generate a thunk for the given method.
   void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
- GlobalDecl GD, const ThunkInfo &Thunk);
+ GlobalDecl GD, const ThunkInfo &Thunk,
+ bool IsUnprototyped);
 
   llvm::Function *GenerateVarArgsThunk(llvm::Function *Fn,
const CGFunctionInfo &FnInfo,
Index: cfe/trunk/lib/CodeGen/CGVTables.cpp
===
--- cfe/trunk/lib/CodeGen/CGVTables.cpp
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp
@@ -31,21 +31,9 @@
 CodeGenVTables::CodeGenVTables(CodeGenModule &CGM)
 : CGM(CGM), VTContext(CGM.getContext().getVTableContext()) {}
 
-llvm::Constant *CodeGenModule::GetAddrOfThunk(GlobalDecl GD,
-  const ThunkInfo &Thunk) {
-  const CXXMethodDecl *MD = cast(GD.getDecl());
-
-  // Compute the mangled name.
-  SmallString<256> Name;
-  llvm::raw_svector_ostream Out(Name);
-  if (const CXXDestructorDecl* DD = dyn_cast(MD))
-getCXXABI().getMangleContext().mangleCXXDtorThunk(DD, GD.getDtorType(),
-  Thunk.This, Out);
-  else
-getCXXABI().getMangleContext().mangleThunk(MD, Thunk, Out);
-
-  llvm::Type *Ty = getTypes().GetFunctionTypeForVTable(GD);
-  return GetOrCreateLLVMFunction(Name, Ty, GD, /*ForVTable=*/true,
+llvm::Constant *CodeGenModule::GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
+  GlobalDecl GD) {
+  return GetOrCreateLLVMFunction(Name, FnTy, GD, /*ForVTable=*/true,
  /*DontDefer=*/true, /*IsThunk=*/true);
 }
 
@@ -235,7 +223,8 @@
 }
 
 void CodeGenFunction::StartThunk(llvm::Function *Fn, GlobalDecl GD,
- const CGFunctionInfo &FnInfo) {
+ const CGFunctionInfo &FnInfo,
+ bool IsUnprototyped) {
   assert(!Cu

[PATCH] D45112: [MS] Emit vftable thunks for functions with incomplete prototypes

2018-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC329009: [MS] Emit vftable thunks for functions with 
incomplete prototypes (authored by rnk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45112?vs=140499&id=140680#toc

Repository:
  rC Clang

https://reviews.llvm.org/D45112

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CGVTables.h
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTypes.h
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/ms-thunks-unprototyped-return.cpp
  test/CodeGenCXX/ms-thunks-unprototyped.cpp

Index: lib/CodeGen/CodeGenTypes.h
===
--- lib/CodeGen/CodeGenTypes.h
+++ lib/CodeGen/CodeGenTypes.h
@@ -313,7 +313,8 @@
  const FunctionProtoType *type,
  RequiredArgs required,
  unsigned numPrefixArgs);
-  const CGFunctionInfo &arrangeMSMemberPointerThunk(const CXXMethodDecl *MD);
+  const CGFunctionInfo &
+  arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD);
   const CGFunctionInfo &arrangeMSCtorClosure(const CXXConstructorDecl *CD,
  CXXCtorType CT);
   const CGFunctionInfo &arrangeCXXMethodType(const CXXRecordDecl *RD,
Index: lib/CodeGen/CGVTables.h
===
--- lib/CodeGen/CGVTables.h
+++ lib/CodeGen/CGVTables.h
@@ -57,12 +57,10 @@
   /// Cache for the deleted virtual member call function.
   llvm::Constant *DeletedVirtualFn = nullptr;
 
-  /// emitThunk - Emit a single thunk.
-  void emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, bool ForVTable);
-
-  /// maybeEmitThunkForVTable - Emit the given thunk for the vtable if needed by
-  /// the ABI.
-  void maybeEmitThunkForVTable(GlobalDecl GD, const ThunkInfo &Thunk);
+  /// Get the address of a thunk and emit it if necessary.
+  llvm::Constant *maybeEmitThunk(GlobalDecl GD,
+ const ThunkInfo &ThunkAdjustments,
+ bool ForVTable);
 
   void addVTableComponent(ConstantArrayBuilder &builder,
   const VTableLayout &layout, unsigned idx,
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1951,7 +1951,8 @@
 return cast(GV);
 
   // Create the llvm::Function.
-  const CGFunctionInfo &FnInfo = CGM.getTypes().arrangeMSMemberPointerThunk(MD);
+  const CGFunctionInfo &FnInfo =
+  CGM.getTypes().arrangeUnprototypedMustTailThunk(MD);
   llvm::FunctionType *ThunkTy = CGM.getTypes().GetFunctionType(FnInfo);
   llvm::Function *ThunkFn =
   llvm::Function::Create(ThunkTy, llvm::Function::ExternalLinkage,
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -514,8 +514,8 @@
 /// correct type, and the caller will bitcast the function to the correct
 /// prototype.
 const CGFunctionInfo &
-CodeGenTypes::arrangeMSMemberPointerThunk(const CXXMethodDecl *MD) {
-  assert(MD->isVirtual() && "only virtual memptrs have thunks");
+CodeGenTypes::arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD) {
+  assert(MD->isVirtual() && "only methods have thunks");
   CanQual FTP = GetFormalType(MD);
   CanQualType ArgTys[] = { GetThisType(Context, MD->getParent()) };
   return arrangeLLVMFunctionInfo(Context.VoidTy, /*instanceMethod=*/false,
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -800,7 +800,8 @@
   ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr* E);
 
   /// Get the address of the thunk for the given global decl.
-  llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk);
+  llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
+ GlobalDecl GD);
 
   /// Get a reference to the target of VD.
   ConstantAddress GetWeakRefReference(const ValueDecl *VD);
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1692,10 +1692,10 @@
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
 
   void StartThunk(llvm::Function *Fn, GlobalDecl GD,
-  const CGFunctionInfo &FnInfo);
+  const CGFunctionInfo &FnInfo, bool IsUnprototyped);
 
-  void EmitCallAndReturnForThunk(llvm::Constant *Callee,
- const ThunkInfo *Thunk);
+  void EmitCallAndReturnForThunk(llvm::Constant *Callee, const ThunkInfo *Thunk,
+ 

r329009 - [MS] Emit vftable thunks for functions with incomplete prototypes

2018-04-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Apr  2 13:20:33 2018
New Revision: 329009

URL: http://llvm.org/viewvc/llvm-project?rev=329009&view=rev
Log:
[MS] Emit vftable thunks for functions with incomplete prototypes

Summary:
The following class hierarchy requires that we be able to emit a
this-adjusting thunk for B::foo in C's vftable:

  struct Incomplete;
  struct A {
virtual A* foo(Incomplete p) = 0;
  };
  struct B : virtual A {
void foo(Incomplete p) override;
  };
  struct C : B { int c; };

This TU is valid, but lacks a definition of 'Incomplete', which makes it
hard to build a thunk for the final overrider, B::foo.

Before this change, Clang gives up attempting to emit the thunk, because
it assumes that if the parameter types are incomplete, it must be
emitting the thunk for optimization purposes. This is untrue for the MS
ABI, where the implementation of B::foo has no idea what thunks C's
vftable may require. Clang needs to emit the thunk without necessarily
having access to the complete prototype of foo.

This change makes Clang emit a musttail variadic call when it needs such
a thunk. I call these "unprototyped" thunks, because they only prototype
the "this" parameter, which must always come first in the MS C++ ABI.

These thunks work, but they create ugly LLVM IR. If the call to the
thunk is devirtualized, it will be a call to a bitcast of a function
pointer. Today, LLVM cannot inline through such a call, but I want to
address that soon, because we also use this pattern for virtual member
pointer thunks.

This change also implements an old FIXME in the code about reusing the
thunk's computed CGFunctionInfo as much as possible. Now we don't end up
computing the thunk's mangled name and arranging it's prototype up to
around three times.

Fixes PR25641

Reviewers: rjmccall, rsmith, hans

Subscribers: Prazek, cfe-commits

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

Added:
cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped-return.cpp
cfe/trunk/test/CodeGenCXX/ms-thunks-unprototyped.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CGVTables.h
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/CodeGenTypes.h
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=329009&r1=329008&r2=329009&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Apr  2 13:20:33 2018
@@ -514,8 +514,8 @@ CodeGenTypes::arrangeGlobalDeclaration(G
 /// correct type, and the caller will bitcast the function to the correct
 /// prototype.
 const CGFunctionInfo &
-CodeGenTypes::arrangeMSMemberPointerThunk(const CXXMethodDecl *MD) {
-  assert(MD->isVirtual() && "only virtual memptrs have thunks");
+CodeGenTypes::arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD) {
+  assert(MD->isVirtual() && "only methods have thunks");
   CanQual FTP = GetFormalType(MD);
   CanQualType ArgTys[] = { GetThisType(Context, MD->getParent()) };
   return arrangeLLVMFunctionInfo(Context.VoidTy, /*instanceMethod=*/false,

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=329009&r1=329008&r2=329009&view=diff
==
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Mon Apr  2 13:20:33 2018
@@ -31,21 +31,9 @@ using namespace CodeGen;
 CodeGenVTables::CodeGenVTables(CodeGenModule &CGM)
 : CGM(CGM), VTContext(CGM.getContext().getVTableContext()) {}
 
-llvm::Constant *CodeGenModule::GetAddrOfThunk(GlobalDecl GD,
-  const ThunkInfo &Thunk) {
-  const CXXMethodDecl *MD = cast(GD.getDecl());
-
-  // Compute the mangled name.
-  SmallString<256> Name;
-  llvm::raw_svector_ostream Out(Name);
-  if (const CXXDestructorDecl* DD = dyn_cast(MD))
-getCXXABI().getMangleContext().mangleCXXDtorThunk(DD, GD.getDtorType(),
-  Thunk.This, Out);
-  else
-getCXXABI().getMangleContext().mangleThunk(MD, Thunk, Out);
-
-  llvm::Type *Ty = getTypes().GetFunctionTypeForVTable(GD);
-  return GetOrCreateLLVMFunction(Name, Ty, GD, /*ForVTable=*/true,
+llvm::Constant *CodeGenModule::GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
+  GlobalDecl GD) {
+  return GetOrCreateLLVMFunction(Name, FnTy, GD, /*ForVTable=*/true,
  /*DontDefer=*/true, /*IsThunk=*/true);
 }
 
@@ -235,7 +223,8 @@ CodeGenFunction::GenerateVarArgsThunk(ll
 }
 
 void CodeGenFunction::StartThunk(llvm::Function *Fn, GlobalDecl GD,
- const CGFunct

[PATCH] D45178: Fixes errors caused by https://reviews.llvm.org/D44960

2018-04-02 Thread Max Moroz via Phabricator via cfe-commits
Dor1s accepted this revision.
Dor1s added a comment.
This revision is now accepted and ready to land.

Looks good from my perspective, added Peter and Zachary who might know this 
code better :)


Repository:
  rC Clang

https://reviews.llvm.org/D45178



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


[PATCH] D5997: Mangling of member-expressions involving anonymous unions.

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

This was committed as r222402.


https://reviews.llvm.org/D5997



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


r329007 - Fix some DenseMap use-after-rehash bugs and hoist MethodVFTableLocation

2018-04-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Apr  2 13:00:39 2018
New Revision: 329007

URL: http://llvm.org/viewvc/llvm-project?rev=329007&view=rev
Log:
Fix some DenseMap use-after-rehash bugs and hoist MethodVFTableLocation

This re-lands r328845 with fixes for crbug.com/827810.

The initial motiviation was to hoist MethodVFTableLocation to global
scope so it could be forward declared.

In this patch, I noticed that MicrosoftVTableContext uses some risky
patterns. It has methods that return references to data stored in
DenseMaps. I've made some of them return by value for trivial structs
and I've moved some things into separate allocations.

Modified:
cfe/trunk/include/clang/AST/Mangle.h
cfe/trunk/include/clang/AST/VTableBuilder.h
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/VTableBuilder.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/include/clang/AST/Mangle.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Mangle.h?rev=329007&r1=329006&r2=329007&view=diff
==
--- cfe/trunk/include/clang/AST/Mangle.h (original)
+++ cfe/trunk/include/clang/AST/Mangle.h Mon Apr  2 13:00:39 2018
@@ -30,6 +30,7 @@ namespace clang {
   class CXXDestructorDecl;
   class CXXMethodDecl;
   class FunctionDecl;
+  struct MethodVFTableLocation;
   class NamedDecl;
   class ObjCMethodDecl;
   class StringLiteral;
@@ -201,7 +202,8 @@ public:
raw_ostream &Out) = 0;
 
   virtual void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
-raw_ostream &) = 0;
+const MethodVFTableLocation &ML,
+raw_ostream &Out) = 0;
 
   virtual void mangleCXXVirtualDisplacementMap(const CXXRecordDecl *SrcRD,
const CXXRecordDecl *DstRD,

Modified: cfe/trunk/include/clang/AST/VTableBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/VTableBuilder.h?rev=329007&r1=329006&r2=329007&view=diff
==
--- cfe/trunk/include/clang/AST/VTableBuilder.h (original)
+++ cfe/trunk/include/clang/AST/VTableBuilder.h Mon Apr  2 13:00:39 2018
@@ -479,41 +479,42 @@ struct VirtualBaseInfo {
   VPtrInfoVector VBPtrPaths;
 };
 
+struct MethodVFTableLocation {
+  /// If nonzero, holds the vbtable index of the virtual base with the vfptr.
+  uint64_t VBTableIndex;
+
+  /// If nonnull, holds the last vbase which contains the vfptr that the
+  /// method definition is adjusted to.
+  const CXXRecordDecl *VBase;
+
+  /// This is the offset of the vfptr from the start of the last vbase, or the
+  /// complete type if there are no virtual bases.
+  CharUnits VFPtrOffset;
+
+  /// Method's index in the vftable.
+  uint64_t Index;
+
+  MethodVFTableLocation()
+  : VBTableIndex(0), VBase(nullptr), VFPtrOffset(CharUnits::Zero()),
+Index(0) {}
+
+  MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase,
+CharUnits VFPtrOffset, uint64_t Index)
+  : VBTableIndex(VBTableIndex), VBase(VBase), VFPtrOffset(VFPtrOffset),
+Index(Index) {}
+
+  bool operator<(const MethodVFTableLocation &other) const {
+if (VBTableIndex != other.VBTableIndex) {
+  assert(VBase != other.VBase);
+  return VBTableIndex < other.VBTableIndex;
+}
+return std::tie(VFPtrOffset, Index) <
+   std::tie(other.VFPtrOffset, other.Index);
+  }
+};
+
 class MicrosoftVTableContext : public VTableContextBase {
 public:
-  struct MethodVFTableLocation {
-/// If nonzero, holds the vbtable index of the virtual base with the vfptr.
-uint64_t VBTableIndex;
-
-/// If nonnull, holds the last vbase which contains the vfptr that the
-/// method definition is adjusted to.
-const CXXRecordDecl *VBase;
-
-/// This is the offset of the vfptr from the start of the last vbase, or 
the
-/// complete type if there are no virtual bases.
-CharUnits VFPtrOffset;
-
-/// Method's index in the vftable.
-uint64_t Index;
-
-MethodVFTableLocation()
-: VBTableIndex(0), VBase(nullptr), VFPtrOffset(CharUnits::Zero()),
-  Index(0) {}
-
-MethodVFTableLocation(uint64_t VBTableIndex, const CXXRecordDecl *VBase,
-  CharUnits VFPtrOffset, uint64_t Index)
-: VBTableIndex(VBTableIndex), VBase(VBase),
-  VFPtrOffset(VFPtrOffset), Index(Index) {}
-
-bool operator<(const MethodVFTableLocation &other) const {
-  if (VBTableIndex != other.VBTableIndex) {
-assert(VBase != other.VBase);
-return VBTableIndex < other.VBTableIndex;
-  }
-  return std::tie(VFPtrOffset, Index) <
- std::tie(other.VFPtrOffset, other.Index);
-}
-  };
 
 private:
   ASTContext &Context

[PATCH] D45059: [clang-tidy] Add check to catch comparisons in TEMP_FAILURE_RETRY

2018-04-02 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added inline comments.



Comment at: clang-tidy/bugprone/ComparisonInTempFailureRetryCheck.cpp:78
+
+  diag(RHS.getOperatorLoc(),
+   "Top-level comparisons should be moved out of TEMP_FAILURE_RETRY");

JonasToth wrote:
> You could even provide a fixit to do this. But this can be done in later 
> patches, too.
I initially tried this, but a complete solution appears to be nontrivial when 
nested macros start to happen. Added a FIXME nonetheless. :)



Comment at: test/clang-tidy/bugprone-comparison-in-temp-failure-retry.c:1
+// RUN: %check_clang_tidy %s bugprone-comparison-in-temp-failure-retry %t
+

JonasToth wrote:
> Could you please add a test with control structures, like loops you used in 
> your example?
Added the `control_flow` function



Comment at: test/clang-tidy/bugprone-comparison-in-temp-failure-retry.c:5
+  ({   
\
+typeof(x) __z; 
\
+do 
\

JonasToth wrote:
> I think you could add one test, that shows using `long int` instead of 
> `typeof` is diagnosed, given glibc uses this approach (or even copy there 
> macro)
Added a variant with `long int` near the bottom.


https://reviews.llvm.org/D45059



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


[PATCH] D45059: [clang-tidy] Add check to catch comparisons in TEMP_FAILURE_RETRY

2018-04-02 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv updated this revision to Diff 140675.
george.burgess.iv marked 5 inline comments as done.
george.burgess.iv added a comment.

Addressed feedback


https://reviews.llvm.org/D45059

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/ComparisonInTempFailureRetryCheck.cpp
  clang-tidy/bugprone/ComparisonInTempFailureRetryCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-comparison-in-temp-failure-retry.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-comparison-in-temp-failure-retry.c

Index: test/clang-tidy/bugprone-comparison-in-temp-failure-retry.c
===
--- /dev/null
+++ test/clang-tidy/bugprone-comparison-in-temp-failure-retry.c
@@ -0,0 +1,148 @@
+// RUN: %check_clang_tidy %s bugprone-comparison-in-temp-failure-retry %t
+
+#define TEMP_FAILURE_RETRY(x)  \
+  ({   \
+typeof(x) __z; \
+do \
+  __z = (x);   \
+while (__z == -1); \
+__z;   \
+  })
+
+int foo();
+int bar(int a);
+
+void test() {
+  int i;
+  TEMP_FAILURE_RETRY((i = foo()));
+  TEMP_FAILURE_RETRY(foo());
+  TEMP_FAILURE_RETRY((foo()));
+
+  TEMP_FAILURE_RETRY(foo() == 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY [bugprone-comparison-in-temp-failure-retry]
+  TEMP_FAILURE_RETRY((foo() == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+  TEMP_FAILURE_RETRY((int)(foo() == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+  TEMP_FAILURE_RETRY(bar(foo() == 1));
+  TEMP_FAILURE_RETRY((bar(foo() == 1)));
+  TEMP_FAILURE_RETRY((bar(foo() == 1)) == 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+  TEMP_FAILURE_RETRY(((bar(foo() == 1)) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+  TEMP_FAILURE_RETRY((int)((bar(foo() == 1)) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+#define INDIRECT TEMP_FAILURE_RETRY
+  INDIRECT(foo());
+  INDIRECT((foo() == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+  INDIRECT(bar(foo() == 1));
+  INDIRECT((int)((bar(foo() == 1)) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+#define TFR(x) TEMP_FAILURE_RETRY(x)
+  TFR(foo());
+  TFR((foo() == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+  TFR(bar(foo() == 1));
+  TFR((int)((bar(foo() == 1)) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+#define ADD_TFR(x) (1 + TEMP_FAILURE_RETRY(x) + 1)
+  ADD_TFR(foo());
+  ADD_TFR(foo() == 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+  ADD_TFR(bar(foo() == 1));
+  ADD_TFR((int)((bar(foo() == 1)) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+#define ADDP_TFR(x) (1 + TEMP_FAILURE_RETRY((x)) + 1)
+  ADDP_TFR(foo());
+  ADDP_TFR((foo() == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+  ADDP_TFR(bar(foo() == 1));
+  ADDP_TFR((int)((bar(foo() == 1)) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+#define MACRO TEMP_FAILURE_RETRY(foo() == 1)
+  MACRO;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+  // Be sure that being a macro arg doesn't mess with this.
+#define ID(x) (x)
+  ID(ADDP_TFR(bar(foo() == 1)));
+  ID(ADDP_TFR(bar(foo() == 1) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+  ID(MACRO);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+
+#define CMP(x) x == 1
+  TEMP_FAILURE_RETRY(CMP(foo()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Top-level comparisons should be moved out of TEMP_FAILURE_RETRY
+}
+
+// Be

r329005 - [Attr] [NFC] Revert accidental change from r327405

2018-04-02 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Mon Apr  2 12:43:34 2018
New Revision: 329005

URL: http://llvm.org/viewvc/llvm-project?rev=329005&view=rev
Log:
[Attr] [NFC] Revert accidental change from r327405

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=329005&r1=329004&r2=329005&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Mon Apr  2 12:43:34 
2018
@@ -1231,7 +1231,7 @@ MallocChecker::MallocMemReturnsAttr(Chec
   if (Att->getModule() != II_malloc)
 return nullptr;
 
-  ParamIdx *I = Att->args_begin(), *E = Att->args_end();
+  OwnershipAttr::args_iterator I = Att->args_begin(), E = Att->args_end();
   if (I != E) {
 return MallocMemAux(C, CE, CE->getArg(I->getASTIndex()), UndefinedVal(),
 State);


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


[PATCH] D45178: Fixes errors caused by https://reviews.llvm.org/D44960

2018-04-02 Thread Yuke Liao via Phabricator via cfe-commits
liaoyuke updated this revision to Diff 140672.
liaoyuke added a comment.

Fix styles.


Repository:
  rC Clang

https://reviews.llvm.org/D45178

Files:
  lib/Basic/VirtualFileSystem.cpp
  unittests/Basic/VirtualFileSystemTest.cpp


Index: unittests/Basic/VirtualFileSystemTest.cpp
===
--- unittests/Basic/VirtualFileSystemTest.cpp
+++ unittests/Basic/VirtualFileSystemTest.cpp
@@ -442,16 +442,17 @@
   ScopedDir _dd(TestDirectory + "/d/d");
   ScopedDir _ddd(TestDirectory + "/d/d/d");
   ScopedLink _e("no_such_file", TestDirectory + "/e");
-  std::vector Expected = {_b, _bb, _d, _dd, _ddd};
 
-  std::vector Contents;
+  std::vector ExpectedBrokenSymlinks = {_a, _ba, _bc, _c, _e};
+  std::vector ExpectedNonBrokenSymlinks = {_b, _bb, _d, _dd, _ddd};
+  std::vector VisitedBrokenSymlinks;
+  std::vector VisitedNonBrokenSymlinks;
   std::error_code EC;
   for (vfs::recursive_directory_iterator I(*FS, Twine(TestDirectory), EC), E;
I != E; I.increment(EC)) {
-// Skip broken symlinks.
 auto EC2 = std::make_error_code(std::errc::no_such_file_or_directory);
 if (EC == EC2) {
-  EC.clear();
+   VisitedBrokenSymlinks.push_back(I->getName());
   continue;
 }
 // For bot debugging.
@@ -467,13 +468,20 @@
  << "EC message: " << EC2.message() << "\n";
 }
 ASSERT_FALSE(EC);
-Contents.push_back(I->getName());
+VisitedNonBrokenSymlinks.push_back(I->getName());
   }
 
-  // Check sorted contents.
-  std::sort(Contents.begin(), Contents.end());
-  EXPECT_EQ(Expected.size(), Contents.size());
-  EXPECT_TRUE(std::equal(Contents.begin(), Contents.end(), Expected.begin()));
+  // Check visited file names.
+  std::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end());
+  std::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end());
+  EXPECT_EQ(ExpectedBrokenSymlinks.size(), VisitedBrokenSymlinks.size());
+  EXPECT_TRUE(std::equal(VisitedBrokenSymlinks.begin(),
+ VisitedBrokenSymlinks.end(),
+ ExpectedBrokenSymlinks.begin()));
+  EXPECT_EQ(ExpectedNonBrokenSymlinks.size(), VisitedNonBrokenSymlinks.size());
+  EXPECT_TRUE(std::equal(VisitedNonBrokenSymlinks.begin(),
+ VisitedNonBrokenSymlinks.end(),
+ ExpectedNonBrokenSymlinks.begin()));
 }
 #endif
 
Index: lib/Basic/VirtualFileSystem.cpp
===
--- lib/Basic/VirtualFileSystem.cpp
+++ lib/Basic/VirtualFileSystem.cpp
@@ -242,25 +242,28 @@
   llvm::sys::fs::directory_iterator Iter;
 public:
   RealFSDirIter(const Twine &Path, std::error_code &EC) : Iter(Path, EC) {
-if (!EC && Iter != llvm::sys::fs::directory_iterator()) {
+if (Iter != llvm::sys::fs::directory_iterator()) {
   llvm::sys::fs::file_status S;
-  EC = llvm::sys::fs::status(Iter->path(), S, true);
+  std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S, true);
   CurrentEntry = Status::copyWithNewName(S, Iter->path());
+  if (!EC)
+EC = ErrorCode;
 }
   }
 
   std::error_code increment() override {
 std::error_code EC;
 Iter.increment(EC);
-if (EC) {
-  return EC;
-} else if (Iter == llvm::sys::fs::directory_iterator()) {
-  CurrentEntry = Status();
-} else {
-  llvm::sys::fs::file_status S;
-  EC = llvm::sys::fs::status(Iter->path(), S, true);
-  CurrentEntry = Status::copyWithNewName(S, Iter->path());
-}
+   if (Iter == llvm::sys::fs::directory_iterator()) {
+   CurrentEntry = Status();
+   } else {
+   llvm::sys::fs::file_status S;
+  std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S, true);
+   CurrentEntry = Status::copyWithNewName(S, Iter->path());
+  if (!EC)
+EC = ErrorCode;
+   }
+
 return EC;
   }
 };


Index: unittests/Basic/VirtualFileSystemTest.cpp
===
--- unittests/Basic/VirtualFileSystemTest.cpp
+++ unittests/Basic/VirtualFileSystemTest.cpp
@@ -442,16 +442,17 @@
   ScopedDir _dd(TestDirectory + "/d/d");
   ScopedDir _ddd(TestDirectory + "/d/d/d");
   ScopedLink _e("no_such_file", TestDirectory + "/e");
-  std::vector Expected = {_b, _bb, _d, _dd, _ddd};
 
-  std::vector Contents;
+  std::vector ExpectedBrokenSymlinks = {_a, _ba, _bc, _c, _e};
+  std::vector ExpectedNonBrokenSymlinks = {_b, _bb, _d, _dd, _ddd};
+  std::vector VisitedBrokenSymlinks;
+  std::vector VisitedNonBrokenSymlinks;
   std::error_code EC;
   for (vfs::recursive_directory_iterator I(*FS, Twine(TestDirectory), EC), E;
I != E; I.increment(EC)) {
-// Skip broken symlinks.
 auto EC2 = std::make_error_code(std::errc::no_such_file_or_directory);
 if (EC == EC2) {
-  EC.clear();
+			VisitedBrokenSymlinks.push_back(I->getName());
   continue;
 }
 // For bot debugging.
@@ -4

[PATCH] D45178: Fixes errors caused by https://reviews.llvm.org/D44960

2018-04-02 Thread Yuke Liao via Phabricator via cfe-commits
liaoyuke created this revision.
Herald added subscribers: cfe-commits, mgrang.

In https://reviews.llvm.org/D44960, file status check is executed every
time a real file system directory iterator is constructed or
incremented, and emits an error code. This change list fixes the errors
in VirtualFileSystem caused by https://reviews.llvm.org/D44960.


Repository:
  rC Clang

https://reviews.llvm.org/D45178

Files:
  lib/Basic/VirtualFileSystem.cpp
  unittests/Basic/VirtualFileSystemTest.cpp


Index: unittests/Basic/VirtualFileSystemTest.cpp
===
--- unittests/Basic/VirtualFileSystemTest.cpp
+++ unittests/Basic/VirtualFileSystemTest.cpp
@@ -442,16 +442,17 @@
   ScopedDir _dd(TestDirectory + "/d/d");
   ScopedDir _ddd(TestDirectory + "/d/d/d");
   ScopedLink _e("no_such_file", TestDirectory + "/e");
-  std::vector Expected = {_b, _bb, _d, _dd, _ddd};
 
-  std::vector Contents;
+  std::vector ExpectedBrokenSymlinks = {_a, _ba, _bc, _c, _e};
+  std::vector ExpectedNonBrokenSymlinks = {_b, _bb, _d, _dd, _ddd};
+  std::vector VisitedBrokenSymlinks;
+  std::vector VisitedNonBrokenSymlinks;
   std::error_code EC;
   for (vfs::recursive_directory_iterator I(*FS, Twine(TestDirectory), EC), E;
I != E; I.increment(EC)) {
-// Skip broken symlinks.
 auto EC2 = std::make_error_code(std::errc::no_such_file_or_directory);
 if (EC == EC2) {
-  EC.clear();
+   VisitedBrokenSymlinks.push_back(I->getName());
   continue;
 }
 // For bot debugging.
@@ -467,13 +468,20 @@
  << "EC message: " << EC2.message() << "\n";
 }
 ASSERT_FALSE(EC);
-Contents.push_back(I->getName());
+VisitedNonBrokenSymlinks.push_back(I->getName());
   }
 
-  // Check sorted contents.
-  std::sort(Contents.begin(), Contents.end());
-  EXPECT_EQ(Expected.size(), Contents.size());
-  EXPECT_TRUE(std::equal(Contents.begin(), Contents.end(), Expected.begin()));
+  // Check visited file names.
+  std::sort(VisitedBrokenSymlinks.begin(), VisitedBrokenSymlinks.end());
+  std::sort(VisitedNonBrokenSymlinks.begin(), VisitedNonBrokenSymlinks.end());
+  EXPECT_EQ(ExpectedBrokenSymlinks.size(), VisitedBrokenSymlinks.size());
+  EXPECT_TRUE(std::equal(VisitedBrokenSymlinks.begin(),
+ VisitedBrokenSymlinks.end(),
+ ExpectedBrokenSymlinks.begin()));
+  EXPECT_EQ(ExpectedNonBrokenSymlinks.size(), VisitedNonBrokenSymlinks.size());
+  EXPECT_TRUE(std::equal(VisitedNonBrokenSymlinks.begin(),
+ VisitedNonBrokenSymlinks.end(),
+ ExpectedNonBrokenSymlinks.begin()));
 }
 #endif
 
Index: lib/Basic/VirtualFileSystem.cpp
===
--- lib/Basic/VirtualFileSystem.cpp
+++ lib/Basic/VirtualFileSystem.cpp
@@ -242,25 +242,28 @@
   llvm::sys::fs::directory_iterator Iter;
 public:
   RealFSDirIter(const Twine &Path, std::error_code &EC) : Iter(Path, EC) {
-if (!EC && Iter != llvm::sys::fs::directory_iterator()) {
+if (Iter != llvm::sys::fs::directory_iterator()) {
   llvm::sys::fs::file_status S;
-  EC = llvm::sys::fs::status(Iter->path(), S, true);
+  std::error_code error_code = llvm::sys::fs::status(Iter->path(), S, 
true);
   CurrentEntry = Status::copyWithNewName(S, Iter->path());
+  if (!EC)
+EC = error_code;
 }
   }
 
   std::error_code increment() override {
 std::error_code EC;
 Iter.increment(EC);
-if (EC) {
-  return EC;
-} else if (Iter == llvm::sys::fs::directory_iterator()) {
-  CurrentEntry = Status();
-} else {
-  llvm::sys::fs::file_status S;
-  EC = llvm::sys::fs::status(Iter->path(), S, true);
-  CurrentEntry = Status::copyWithNewName(S, Iter->path());
-}
+   if (Iter == llvm::sys::fs::directory_iterator()) {
+   CurrentEntry = Status();
+   } else {
+   llvm::sys::fs::file_status S;
+  std::error_code error_code = llvm::sys::fs::status(Iter->path(), S, 
true);
+   CurrentEntry = Status::copyWithNewName(S, Iter->path());
+  if (!EC)
+EC = error_code;
+   }
+
 return EC;
   }
 };


Index: unittests/Basic/VirtualFileSystemTest.cpp
===
--- unittests/Basic/VirtualFileSystemTest.cpp
+++ unittests/Basic/VirtualFileSystemTest.cpp
@@ -442,16 +442,17 @@
   ScopedDir _dd(TestDirectory + "/d/d");
   ScopedDir _ddd(TestDirectory + "/d/d/d");
   ScopedLink _e("no_such_file", TestDirectory + "/e");
-  std::vector Expected = {_b, _bb, _d, _dd, _ddd};
 
-  std::vector Contents;
+  std::vector ExpectedBrokenSymlinks = {_a, _ba, _bc, _c, _e};
+  std::vector ExpectedNonBrokenSymlinks = {_b, _bb, _d, _dd, _ddd};
+  std::vector VisitedBrokenSymlinks;
+  std::vector VisitedNonBrokenSymlinks;
   std::error_code EC;
   for (vfs::recursive_directory_iterator I(*FS, Twine(TestDirectory), EC), E;
I != E; I.in

[PATCH] D45145: [Driver] Wire up the -f[no-]rtlib-add-rpath flag and tests

2018-04-02 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 140668.
phosek added a comment.

Thanks for the suggestion, I don't think we even need to rename the function 
since this already matches the pattern other functions use.


Repository:
  rC Clang

https://reviews.llvm.org/D45145

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/arch-specific-libdir-rpath.c

Index: clang/test/Driver/arch-specific-libdir-rpath.c
===
--- clang/test/Driver/arch-specific-libdir-rpath.c
+++ clang/test/Driver/arch-specific-libdir-rpath.c
@@ -6,15 +6,14 @@
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Test that -rpath is not added under -fno-rtlib-add-rpath even if other
 // conditions are met.
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -frtlib-add-rpath \
+// RUN: -fno-rtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Test that -rpath is added only under the right circumstance even if
@@ -24,13 +23,13 @@
 // RUN: %clang %s -### 2>&1 -target x86_64-linux -fsanitize=undefined \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH but no RPATH for -fsanitizer=address w/o -shared-libasan
 // RUN: %clang %s -### 2>&1 -target x86_64-linux -fsanitize=undefined \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH, RPATH for -fsanitize=address -shared-libasan
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
@@ -44,7 +43,7 @@
 // RUN: -fsanitize=address -shared-libasan \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-AArch64,RPATH-AArch64 %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-AARCH64,RPATH-AARCH64 %s
 //
 // Add LIBPATH, RPATH with -fsanitize=address for Android
 // RUN: %clang %s -### 2>&1 -target x86_64-linux-android -fsanitize=address \
@@ -62,24 +61,30 @@
 // RUN: %clang %s -### 2>&1 -fsanitize=undefined -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Add LIBPATH but no RPATH if no sanitizer or runtime is specified
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -frtlib-add-rpath \
-// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH %s
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
 //
 // Do not add LIBPATH or RPATH if arch-specific subdir doesn't exist
 // RUN: %clang %s -### 2>&1 -target x86_64-linux \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
 // RUN: -frtlib-add-rpath \
 // RUN:   | FileCheck --check-prefixes=RESDIR,NO-LIBPATH,NO-RPATH %s
-//
+
 // RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
-// LIBPATH-X86_64:  -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
-// RPATH-X86_64:"-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}"
-// LIBPATH-AArch64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)aarch64}}
-// RPATH-AArch64:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)aarch64}}"
-// NO-LIBPATH-NOT:  "-L{{[^"]*Inputs(/|)resource_dir}}"
-// NO-RPATH-NOT:"-rpath" {{.*(/|)Inputs(/|)resource_dir}}
+//
+// LIBPATH-X86_64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
+// RPATH-X86_64:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}"
+//
+// NO-LIBPATH-X86_64-NOT: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}
+// NO-RPATH-X86_64-NOT:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)x86_64}}"
+//
+// LIBPATH-AARCH64: -L[[RESDIR]]{{(/|)lib(/|)linux(/|)aarch64}}
+// RPATH-AAARCH4:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)linux(/|)aarch64}}"
+//
+// NO-LIBPATH-NOT: "-L{{[^"]*Inputs(/|)resource_dir}}"
+// NO-RPATH-NOT:   "-rpath" {{.*(/|)Inputs(/|)resource_dir}}
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===

[PATCH] D45177: CStringChecker, check strlcpy/strlcat

2018-04-02 Thread David CARLIER via Phabricator via cfe-commits
devnexen created this revision.
devnexen added reviewers: george.karpenkov, NoQ.
Herald added a subscriber: cfe-commits.

strlcpy/strlcat are bounded but unlike their strn* counterparts, they can 
overlap.


Repository:
  rC Clang

https://reviews.llvm.org/D45177

Files:
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  test/Analysis/bsd-string.c

Index: test/Analysis/bsd-string.c
===
--- /dev/null
+++ test/Analysis/bsd-string.c
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -verify %s
+
+#define NULL ((void *)0)
+
+typedef __typeof(sizeof(int)) size_t;
+size_t strlcpy(char *dst, const char *src, size_t n);
+size_t strlcat(char *dst, const char *src, size_t n);
+
+void f1() {
+  char overlap[] = "123456789";
+  strlcpy(overlap, overlap + 1, 3); // expected-warning{{Arguments must not be overlapping buffers}}
+}
+
+void f2() {
+  char buf[5];
+  strlcpy(buf, "abcd", sizeof(buf)); // expected-no-warning
+  strlcat(buf, "efgh", sizeof(buf)); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
+}
+
+void f3() {
+  char dst[2];
+  const char *src = "abdef";
+  strlcpy(dst, src, 5); // expected-warning{{Size argument is greater than the length of the destination buffer}}
+}
+
+void f4() {
+  strlcpy(NULL, "abcdef", 6); // expected-warning{{Null pointer argument in call to string copy function}}
+}
+
+void f5() {
+  strlcat(NULL, "abcdef", 6); // expected-warning{{Null pointer argument in call to string copy function}}
+}
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -97,14 +97,17 @@
   void evalStrcpy(CheckerContext &C, const CallExpr *CE) const;
   void evalStrncpy(CheckerContext &C, const CallExpr *CE) const;
   void evalStpcpy(CheckerContext &C, const CallExpr *CE) const;
+  void evalStrlcpy(CheckerContext &C, const CallExpr *CE) const;
   void evalStrcpyCommon(CheckerContext &C,
 const CallExpr *CE,
 bool returnEnd,
 bool isBounded,
-bool isAppending) const;
+bool isAppending,
+bool canOverlap = false) const;
 
   void evalStrcat(CheckerContext &C, const CallExpr *CE) const;
   void evalStrncat(CheckerContext &C, const CallExpr *CE) const;
+  void evalStrlcat(CheckerContext &C, const CallExpr *CE) const;
 
   void evalStrcmp(CheckerContext &C, const CallExpr *CE) const;
   void evalStrncmp(CheckerContext &C, const CallExpr *CE) const;
@@ -1397,6 +1400,18 @@
/* isAppending = */ false);
 }
 
+void CStringChecker::evalStrlcpy(CheckerContext &C, const CallExpr *CE) const {
+  if (CE->getNumArgs() < 3)
+return;
+
+  // char *strlcpy(char *dst, const char *src, size_t n);
+  evalStrcpyCommon(C, CE,
+   /* returnEnd = */ true,
+   /* isBounded = */ true,
+   /* isAppending = */ false,
+   /* canOverlap = */ true);
+}
+
 void CStringChecker::evalStrcat(CheckerContext &C, const CallExpr *CE) const {
   if (CE->getNumArgs() < 2)
 return;
@@ -1419,9 +1434,21 @@
/* isAppending = */ true);
 }
 
+void CStringChecker::evalStrlcat(CheckerContext &C, const CallExpr *CE) const {
+  if (CE->getNumArgs() < 3)
+return;
+
+  //char *strlcat(char *s1, const char *s2, size_t n);
+  evalStrcpyCommon(C, CE,
+   /* returnEnd = */ false,
+   /* isBounded = */ true,
+   /* isAppending = */ true,
+   /* canOverlap = */ true);
+}
+
 void CStringChecker::evalStrcpyCommon(CheckerContext &C, const CallExpr *CE,
   bool returnEnd, bool isBounded,
-  bool isAppending) const {
+  bool isAppending, bool canOverlap) const {
   CurrentFunctionDescription = "string copy function";
   ProgramStateRef state = C.getState();
   const LocationContext *LCtx = C.getLocationContext();
@@ -1459,6 +1486,12 @@
   SVal maxLastElementIndex = UnknownVal();
   const char *boundWarning = nullptr;
 
+  if (canOverlap)
+state = CheckOverlap(C, state, CE->getArg(2), Dst, srcExpr);
+
+  if (!state)
+return;
+
   // If the function is strncpy, strncat, etc... it is bounded.
   if (isBounded) {
 // Get the max number of characters to copy.
@@ -2095,10 +2128,14 @@
 evalFunction =  &CStringChecker::evalStrncpy;
   else if (C.isCLibraryFunction(FDecl, "stpcpy"))
 evalFunction =  &CStringChecker::evalStpcpy;
+  else if (C.isCLibraryFunction(FDecl, "strlcpy"))
+evalFunction =  &CStringChecker::evalStrlcpy;
   else if (C.isCLibraryFunction(FDecl, "str

[PATCH] D45176: implement recent "standard-layout" changes

2018-04-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: rjmccall.
Herald added subscribers: sunfish, aheejin, dschuff, sanjoy, jfb.

DR1672, DR1813, DR1881, DR2120: Implement recent fixes to "standard layout" 
rules.

The new rules say that a standard-layout struct has its first non-static data 
member and all base classes at offset 0, and consider a class to not be 
standard-layout if that would result in multiple subobjects of a single type 
having the same address.

John, this results in an ABI break for the three ABI variants that use "C++11 
POD" to determine whether to reuse tail padding (64-bit iOS, WatchOS, and 
wasm). For now, I've made this restore the former behavior under 
`-fclang-abi-compat=6`, but it's probably better to instead say that "C++11 
POD" takes into account standard-layout-as-specified-in-ISO-C++11 and thereby 
avoid any ABI change. What do you think?


Repository:
  rC Clang

https://reviews.llvm.org/D45176

Files:
  AST/ASTImporter.cpp
  AST/DeclCXX.cpp
  CXX/drs/dr14xx.cpp
  CXX/drs/dr16xx.cpp
  CXX/drs/dr18xx.cpp
  CXX/drs/dr21xx.cpp
  CXX/drs/dr22xx.cpp
  Layout/v6-standard-layout.cpp
  ReleaseNotes.rst
  SemaCXX/type-traits.cpp
  Serialization/ASTReaderDecl.cpp
  Serialization/ASTWriter.cpp
  clang/AST/DeclCXX.h
  cxx_dr_status.html
  make_cxx_dr_status

Index: make_cxx_dr_status
===
--- make_cxx_dr_status
+++ make_cxx_dr_status
@@ -129,6 +129,9 @@
   elif status == 'na lib':
 avail = 'N/A (Library DR)'
 avail_style = ' class="na"'
+  elif status == 'na abi':
+avail = 'N/A (ABI constraint)'
+avail_style = ' class="na"'
   elif status.startswith('sup '):
 dup = status.split(' ', 1)[1]
 avail = 'Superseded by %s' % (dup, dup)
Index: cxx_dr_status.html
===
--- cxx_dr_status.html
+++ cxx_dr_status.html
@@ -8365,7 +8365,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1425";>1425
 CD3
 Base-class subobjects of standard-layout structs
-Unknown
+N/A (ABI constraint)
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1426";>1426
@@ -9847,7 +9847,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1672";>1672
 CD4
 Layout compatibility with multiple empty bases
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1673";>1673
@@ -10693,7 +10693,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1813";>1813
 CD4
 Direct vs indirect bases in standard-layout classes
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1814";>1814
@@ -11101,7 +11101,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1881";>1881
 CD4
 Standard-layout classes and unnamed bit-fields
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1882";>1882
@@ -12535,7 +12535,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2120";>2120
 CD4
 Array as first non-static data member in standard-layout class
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2121";>2121
@@ -13189,7 +13189,7 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2229";>2229
 tentatively ready
 Volatile unnamed bit-fields
-Unknown
+SVN
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#2230";>2230
Index: SemaCXX/type-traits.cpp
===
--- SemaCXX/type-traits.cpp
+++ SemaCXX/type-traits.cpp
@@ -1353,6 +1353,59 @@
   int t43[F(__is_standard_layout(AnIncompleteType[1]))]; // expected-error {{incomplete type}}
   int t44[F(__is_standard_layout(void))];
   int t45[F(__is_standard_layout(const volatile void))];
+
+  struct HasAnonEmptyBitfield { int : 0; };
+  struct HasAnonBitfield { int : 4; };
+  struct DerivesFromBitfield : HasAnonBitfield {};
+  struct DerivesFromBitfieldWithBitfield : HasAnonBitfield { int : 5; };
+  struct DerivesFromBitfieldTwice : DerivesFromBitfield, HasAnonEmptyBitfield {};
+
+  int t50[T(__is_standard_layout(HasAnonEmptyBitfield))];
+  int t51[T(__is_standard_layout(HasAnonBitfield))];
+  int t52[T(__is_standard_layout(DerivesFromBitfield))];
+  int t53[F(__is_standard_layout(DerivesFromBitfieldWithBitfield))];
+  int t54[F(__is_standard_layout(DerivesFromBitfieldTwice))];
+
+  struct Empty {};
+  struct HasEmptyBase : Empty {};
+  struct HoldsEmptyBase { Empty e; };
+  struct HasRepeatedEmptyBase : Empty, HasEmptyBase {}; // expected-warning {{inaccessible}}
+  struct HasEmptyBaseAsMember : Empty { Empty e; };
+  struct HasEmptyBaseAsSubobjectOfMember1 : Empty { HoldsEmptyBase e; };
+  struct HasEmptyBaseAsSubobjectOfMember2 : Empty { HasEmptyBase e; };
+  struct HasEmptyBaseAsSubobjectOfMember3 : Empty { HoldsEmptyBase 

[PATCH] D43322: Diagnose cases of "return x" that should be "return std::move(x)" for efficiency

2018-04-02 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@rsmith ping?


Repository:
  rC Clang

https://reviews.llvm.org/D43322



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


[PATCH] D45174: non-zero-length bit-fields should make a class non-empty

2018-04-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: rjmccall.
Herald added a subscriber: sanjoy.

This implements the rule intended by the standard (see LWG 2358) and the rule 
presumably intended by the Itanium C++ ABI (see 
https://github.com/itanium-cxx-abi/cxx-abi/pull/51), and makes Clang match the 
behavior of GCC, ICC, and MSVC. A pedantic reading of both the standard and the 
ABI indicate that Clang is currently technically correct, but that's not worth 
much when it's clear that the wording is wrong in both those places.

This is an ABI break for classes that derive from a class that is empty other 
than one or more unnamed non-zero-length bit-fields. Such cases are expected to 
be rare, but -fclang-abi-compat=6 restores the old behavior just in case.


Repository:
  rC Clang

https://reviews.llvm.org/D45174

Files:
  AST/DeclCXX.cpp
  Layout/ms-x86-pack-and-align.cpp
  Layout/v6-empty.cpp
  ReleaseNotes.rst
  SemaCXX/type-traits.cpp

Index: SemaCXX/type-traits.cpp
===
--- SemaCXX/type-traits.cpp
+++ SemaCXX/type-traits.cpp
@@ -262,6 +262,7 @@
 typedef Empty EmptyAr[10];
 struct Bit0 { int : 0; };
 struct Bit0Cons { int : 0; Bit0Cons(); };
+struct AnonBitOnly { int : 3; };
 struct BitOnly { int x : 3; };
 struct DerivesVirt : virtual POD {};
 
@@ -287,6 +288,7 @@
   { int arr[F(__is_empty(EmptyAr))]; }
   { int arr[F(__is_empty(HasRef))]; }
   { int arr[F(__is_empty(HasVirt))]; }
+  { int arr[F(__is_empty(AnonBitOnly))]; }
   { int arr[F(__is_empty(BitOnly))]; }
   { int arr[F(__is_empty(void))]; }
   { int arr[F(__is_empty(IntArNB))]; }
Index: Layout/v6-empty.cpp
===
--- /dev/null
+++ Layout/v6-empty.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -fclang-abi-compat=6 -triple x86_64-linux-gnu -fdump-record-layouts %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V6
+// RUN: %clang_cc1 -fsyntax-only -fclang-abi-compat=7 -triple x86_64-linux-gnu -fdump-record-layouts %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V7
+
+// In Clang 6 and before, we determined that Nonempty was empty, so we
+// applied EBO to it.
+struct Nonempty { int : 4; };
+struct A : Nonempty { int n; };
+int k = sizeof(A);
+
+// CHECK:*** Dumping AST Record Layout
+// CHECK: 0 | struct A
+// CHECK-V6-NEXT: 0 |   struct Nonempty (base) (empty)
+// CHECK-V7-NEXT: 0 |   struct Nonempty (base){{$}}
+// CHECK-NEXT:0:0-3 | int
+// CHECK-V6-NEXT: 0 |   int n
+// CHECK-V7-NEXT: 4 |   int n
+// CHECK-V6-NEXT:   | [sizeof=4, dsize=4, align=4,
+// CHECK-V6-NEXT:   |  nvsize=4, nvalign=4]
+// CHECK-V7-NEXT:   | [sizeof=8, dsize=8, align=4,
+// CHECK-V7-NEXT:   |  nvsize=8, nvalign=4]
Index: Layout/ms-x86-pack-and-align.cpp
===
--- Layout/ms-x86-pack-and-align.cpp
+++ Layout/ms-x86-pack-and-align.cpp
@@ -188,12 +188,12 @@
 	__declspec(align(32)) char : 1;
 };
 // CHECK: *** Dumping AST Record Layout
-// CHECK-NEXT:0 | struct YA (empty)
+// CHECK-NEXT:0 | struct YA
 // CHECK-NEXT:0:0-0 |   char
 // CHECK-NEXT:  | [sizeof=32, align=32
 // CHECK-NEXT:  |  nvsize=32, nvalign=32]
 // CHECK-X64: *** Dumping AST Record Layout
-// CHECK-X64-NEXT:0 | struct YA (empty)
+// CHECK-X64-NEXT:0 | struct YA
 // CHECK-X64-NEXT:0:0-0 |   char
 // CHECK-X64-NEXT:  | [sizeof=32, align=32
 // CHECK-X64-NEXT:  |  nvsize=32, nvalign=32]
@@ -206,14 +206,14 @@
 // CHECK: *** Dumping AST Record Layout
 // CHECK-NEXT:0 | struct YB
 // CHECK-NEXT:0 |   char a
-// CHECK-NEXT:1 |   struct YA b (empty)
+// CHECK-NEXT:1 |   struct YA b
 // CHECK-NEXT:1:0-0 | char
 // CHECK-NEXT:  | [sizeof=33, align=1
 // CHECK-NEXT:  |  nvsize=33, nvalign=1]
 // CHECK-X64: *** Dumping AST Record Layout
 // CHECK-X64-NEXT:0 | struct YB
 // CHECK-X64-NEXT:0 |   char a
-// CHECK-X64-NEXT:1 |   struct YA b (empty)
+// CHECK-X64-NEXT:1 |   struct YA b
 // CHECK-X64-NEXT:1:0-0 | char
 // CHECK-X64-NEXT:  | [sizeof=33, align=1
 // CHECK-X64-NEXT:  |  nvsize=33, nvalign=1]
@@ -223,12 +223,12 @@
 	__declspec(align(32)) char : 1;
 };
 // CHECK: *** Dumping AST Record Layout
-// CHECK-NEXT:0 | struct YC (empty)
+// CHECK-NEXT:0 | struct YC
 // CHECK-NEXT:0:0-0 |   char
 // CHECK-NEXT:  | [sizeof=32, align=32
 // CHECK-NEXT:  |  nvsize=32, nvalign=32]
 // CHECK-X64: *** Dumping AST Record Layout
-// CHECK-X64-NEXT:0 | struct YC (empty)
+// CHECK-X64-NEXT:0 | struct YC
 // CHECK-X64-NEXT:0:0-0 |   char
 // CHECK-X64-NEXT:  | [sizeof=8, align=32
 // CHECK-X64-NEXT:  |  nvsize=8, nvalign=32]
@@ -241,14 +241,14 @@
 // CHECK: *** Dumping AST Record Layout
 // CHECK-NEXT:0 | struct YD
 // CHECK-NEXT:0 |   char a
-// CHECK-NEXT:1 |   struct YC b (empty)
+// CHECK-NEXT:1 |   struct YC b
 // CHECK-

[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

That seems reasonable.  And this summer would still be in time for the next 
release.


Repository:
  rC Clang

https://reviews.llvm.org/D45163



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


r329001 - Temporarily revert r328404:

2018-04-02 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Mon Apr  2 11:33:47 2018
New Revision: 329001

URL: http://llvm.org/viewvc/llvm-project?rev=329001&view=rev
Log:
Temporarily revert r328404:

commit 519b97132a4c960e8dedbfe4290d86970d92e995
Author: Richard Trieu 
Date:   Sat Mar 24 00:52:44 2018 +

[ODRHash] Support pointer and reference types.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328404 
91177308-0d34-0410-b5e6-96231b3b80d8

As it's breaking some tests. I've communicated with Richard offline about 
testcases.

Modified:
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=329001&r1=329000&r2=329001&view=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Mon Apr  2 11:33:47 2018
@@ -642,24 +642,6 @@ public:
 VisitFunctionType(T);
   }
 
-  void VisitPointerType(const PointerType *T) {
-AddQualType(T->getPointeeType());
-VisitType(T);
-  }
-
-  void VisitReferenceType(const ReferenceType *T) {
-AddQualType(T->getPointeeTypeAsWritten());
-VisitType(T);
-  }
-
-  void VisitLValueReferenceType(const LValueReferenceType *T) {
-VisitReferenceType(T);
-  }
-
-  void VisitRValueReferenceType(const RValueReferenceType *T) {
-VisitReferenceType(T);
-  }
-
   void VisitTypedefType(const TypedefType *T) {
 AddDecl(T->getDecl());
 QualType UnderlyingType = T->getDecl()->getUnderlyingType();

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=329001&r1=329000&r2=329001&view=diff
==
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Mon Apr  2 11:33:47 2018
@@ -2287,128 +2287,6 @@ Invalid1 i1;
 }  // namespace BaseClass
 
 
-namespace PointersAndReferences {
-#if defined(FIRST) || defined(SECOND)
-template struct Wrapper{};
-#endif
-
-#if defined(FIRST)
-struct S1 {
-  Wrapper x;
-};
-#elif defined(SECOND)
-struct S1 {
-  Wrapper x;
-};
-#else
-S1 s1;
-// expected-error@first.h:* {{PointersAndReferences::S1::x' from module 
'FirstModule' is not present in definition of 'PointersAndReferences::S1' in 
module 'SecondModule'}}
-// expected-note@second.h:* {{declaration of 'x' does not match}}
-#endif
-
-#if defined(FIRST)
-struct S2 {
-  Wrapper x;
-};
-#elif defined(SECOND)
-struct S2 {
-  Wrapper x;
-};
-#else
-S2 s2;
-// expected-error@first.h:* {{PointersAndReferences::S2::x' from module 
'FirstModule' is not present in definition of 'PointersAndReferences::S2' in 
module 'SecondModule'}}
-// expected-note@second.h:* {{declaration of 'x' does not match}}
-#endif
-
-#if defined(FIRST)
-struct S3 {
-  Wrapper x;
-};
-#elif defined(SECOND)
-struct S3 {
-  Wrapper x;
-};
-#else
-S3 s3;
-// expected-error@first.h:* {{PointersAndReferences::S3::x' from module 
'FirstModule' is not present in definition of 'PointersAndReferences::S3' in 
module 'SecondModule'}}
-// expected-note@second.h:* {{declaration of 'x' does not match}}
-#endif
-
-#if defined(FIRST)
-struct S4 {
-  Wrapper x;
-};
-#elif defined(SECOND)
-struct S4 {
-  Wrapper x;
-};
-#else
-S4 s4;
-// expected-error@first.h:* {{PointersAndReferences::S4::x' from module 
'FirstModule' is not present in definition of 'PointersAndReferences::S4' in 
module 'SecondModule'}}
-// expected-note@second.h:* {{declaration of 'x' does not match}}
-#endif
-
-#if defined(FIRST)
-struct S5 {
-  Wrapper x;
-};
-#elif defined(SECOND)
-struct S5 {
-  Wrapper x;
-};
-#else
-S5 s5;
-// expected-error@second.h:* {{'PointersAndReferences::S5::x' from module 
'SecondModule' is not present in definition of 'PointersAndReferences::S5' in 
module 'FirstModule'}}
-// expected-note@first.h:* {{declaration of 'x' does not match}}
-#endif
-
-#if defined(FIRST)
-struct S6 {
-  Wrapper x;
-};
-#elif defined(SECOND)
-struct S6 {
-  Wrapper x;
-};
-#else
-S6 s6;
-// expected-error@first.h:* {{PointersAndReferences::S6::x' from module 
'FirstModule' is not present in definition of 'PointersAndReferences::S6' in 
module 'SecondModule'}}
-// expected-note@second.h:* {{declaration of 'x' does not match}}
-#endif
-
-#define DECLS\
-  Wrapper x1; \
-  Wrapper x2;   \
-  Wrapper x3; \
-  Wrapper x4; \
-  Wrapper x5;\
-  Wrapper x6;   \
-  Wrapper x7;  \
-  Wrapper x8;  \
-  Wrapper x9;
-
-#if defined(FIRST) || defined(SECOND)
-struct Valid1 {
-  DECLS
-};
-#else
-Valid1 v1;
-#endif
-
-#if defined(FIRST) || defined(SECOND)
-struct Invalid1 {
-  DECLS
-  ACCESS
-};
-#else
-Invalid1 i1;
-// expected-error@second.h:* {{'PointersAndReferences::Invalid1' has different 
definitions in different modules; first difference is definition in module 
'SecondModule' found private access spe

r329000 - Add -fclang-abi-compat=6 flag for upcoming ABI changes.

2018-04-02 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Apr  2 11:29:44 2018
New Revision: 329000

URL: http://llvm.org/viewvc/llvm-project?rev=329000&view=rev
Log:
Add -fclang-abi-compat=6 flag for upcoming ABI changes.

Modified:
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=329000&r1=328999&r2=329000&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Mon Apr  2 11:29:44 2018
@@ -114,6 +114,13 @@ public:
 /// determining whether a class type can be passed or returned directly.
 Ver4,
 
+/// Attempt to be ABI-compatible with code generated by Clang 6.0.x
+/// (SVN r321711). This causes determination of whether a type is
+/// standard-layout to ignore collisions between empty base classes
+/// and between base classes and member subobjects, which affects
+/// whether we reuse base class tail padding in some ABIs.
+Ver6,
+
 /// Conform to the underlying platform's C and C++ ABIs as closely
 /// as we can.
 Latest

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=329000&r1=328999&r2=329000&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Apr  2 11:29:44 2018
@@ -2665,6 +2665,8 @@ static void ParseLangArgs(LangOptions &O
 Opts.setClangABICompat(LangOptions::ClangABI::Ver3_8);
   else if (Major <= 4)
 Opts.setClangABICompat(LangOptions::ClangABI::Ver4);
+  else if (Major <= 6)
+Opts.setClangABICompat(LangOptions::ClangABI::Ver6);
 } else if (Ver != "latest") {
   Diags.Report(diag::err_drv_invalid_value)
   << A->getAsString(Args) << A->getValue();


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


r328999 - Add helper to determine if a field is a zero-length bitfield.

2018-04-02 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Apr  2 11:29:43 2018
New Revision: 328999

URL: http://llvm.org/viewvc/llvm-project?rev=328999&view=rev
Log:
Add helper to determine if a field is a zero-length bitfield.

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=328999&r1=328998&r2=328999&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Apr  2 11:29:43 2018
@@ -2635,6 +2635,11 @@ public:
 BitField = false;
   }
 
+  /// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
+  /// at all and instead act as a separator between contiguous runs of other
+  /// bit-fields.
+  bool isZeroLengthBitField(const ASTContext &Ctx) const;
+
   /// Get the kind of (C++11) default member initializer that this field has.
   InClassInitStyle getInClassInitStyle() const {
 InitStorageKind storageKind = InitStorage.getInt();

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=328999&r1=328998&r2=328999&view=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Apr  2 11:29:43 2018
@@ -3691,6 +3691,11 @@ unsigned FieldDecl::getBitWidthValue(con
   return getBitWidth()->EvaluateKnownConstInt(Ctx).getZExtValue();
 }
 
+bool FieldDecl::isZeroLengthBitField(const ASTContext &Ctx) const {
+  return isUnnamedBitfield() && !getBitWidth()->isValueDependent() &&
+ getBitWidthValue(Ctx) == 0;
+}
+
 unsigned FieldDecl::getFieldIndex() const {
   const FieldDecl *Canonical = getCanonicalDecl();
   if (Canonical != this)

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=328999&r1=328998&r2=328999&view=diff
==
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Mon Apr  2 11:29:43 2018
@@ -1085,10 +1085,7 @@ void CXXRecordDecl::addedMember(Decl *D)
 //   T is a class type [...] with [...] no non-static data members other
 //   than bit-fields of length 0...
 if (data().Empty) {
-  if (!Field->isBitField() ||
-  (!Field->getBitWidth()->isTypeDependent() &&
-   !Field->getBitWidth()->isValueDependent() &&
-   Field->getBitWidthValue(Context) != 0))
+  if (!Field->isZeroLengthBitField(Context))
 data().Empty = false;
 }
   }

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=328999&r1=328998&r2=328999&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Apr  2 11:29:43 2018
@@ -906,8 +906,7 @@ getTypeExpansion(QualType Ty, const ASTC
   CharUnits UnionSize = CharUnits::Zero();
 
   for (const auto *FD : RD->fields()) {
-// Skip zero length bitfields.
-if (FD->isBitField() && FD->getBitWidthValue(Context) == 0)
+if (FD->isZeroLengthBitField(Context))
   continue;
 assert(!FD->isBitField() &&
"Cannot expand structure with bit-field members.");
@@ -928,8 +927,7 @@ getTypeExpansion(QualType Ty, const ASTC
   }
 
   for (const auto *FD : RD->fields()) {
-// Skip zero length bitfields.
-if (FD->isBitField() && FD->getBitWidthValue(Context) == 0)
+if (FD->isZeroLengthBitField(Context))
   continue;
 assert(!FD->isBitField() &&
"Cannot expand structure with bit-field members.");

Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=328999&r1=328998&r2=328999&view=diff
==
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Mon Apr  2 11:29:43 2018
@@ -294,8 +294,7 @@ void CGRecordLowering::lowerUnion() {
   // been doing and cause lit tests to change.
   for (const auto *Field : D->fields()) {
 if (Field->isBitField()) {
-  // Skip 0 sized bitfields.
-  if (Field->getBitWidthValue(Context) == 0)
+  if (Field->isZeroLengthBitField(Context))
 continue;
   llvm::Type *FieldType = getStorageType(Field);
   if (LayoutSize < getSize(FieldType))
@@ -38

[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

So.
https://bugs.llvm.org/show_bug.cgi?id=10011 was resolved by 
https://wg21.link/P0600 (which added `[[nodiscard]]` to `string.empty()`

We can do the same for `move`.
However, I have been promised a comprehensive paper listing all the (100s?) of 
places in the standard library which should be so marked, and I'm inclined to 
wait for it (but not for too long).
[ The next WG21 meeting is in June ]


Repository:
  rC Clang

https://reviews.llvm.org/D45163



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


[PATCH] D45145: [Driver] Wire up the -f[no-]rtlib-add-rpath flag and tests

2018-04-02 Thread Pirama Arumuga Nainar via Phabricator via cfe-commits
pirama added a comment.

Hi Petr, thanks for the fix (I dropped the ball on this one :( ).  Instead of 
duplicating the checks, does it make sense to fold check into 
addArchSpecificRPath and rename it to 'addArchSpecificRPathIfRequested' or 
something similar?


Repository:
  rC Clang

https://reviews.llvm.org/D45145



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


[clang-tools-extra] r328997 - Revert r328932 as it caused Windows and MacOS bot failures.

2018-04-02 Thread Mike Edwards via cfe-commits
Author: sqlbyme
Date: Mon Apr  2 11:02:36 2018
New Revision: 328997

URL: http://llvm.org/viewvc/llvm-project?rev=328997&view=rev
Log:
Revert r328932 as it caused Windows and MacOS bot failures.

http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/43991/

Removed:

clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=328997&r1=328996&r2=328997&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Mon Apr  2 11:02:36 2018
@@ -481,16 +481,6 @@ void runClangTidy(clang::tidy::ClangTidy
   ClangTool Tool(Compilations, InputFiles,
  std::make_shared(), BaseFS);
 
-  // Add __clang_analyzer__ macro definition for compatibility with the clang
-  // static analyzer.
-  ArgumentsAdjuster ClangTidyMacroDefinitionInserter =
-  [&Context](const CommandLineArguments &Args, StringRef Filename) {
-ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
-CommandLineArguments AdjustedArgs = Args;
-AdjustedArgs.emplace_back("-D__clang_analyzer__");
-return AdjustedArgs;
-  };
-
   // Add extra arguments passed by the clang-tidy command-line.
   ArgumentsAdjuster PerFileExtraArgumentsInserter =
   [&Context](const CommandLineArguments &Args, StringRef Filename) {
@@ -525,7 +515,6 @@ void runClangTidy(clang::tidy::ClangTidy
 return AdjustedArgs;
   };
 
-  Tool.appendArgumentsAdjuster(ClangTidyMacroDefinitionInserter);
   Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
   Tool.appendArgumentsAdjuster(PluginArgumentsRemover);
   if (Profile)

Removed: 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp?rev=328996&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-__clang_analyzer__macro.cpp 
(removed)
@@ -1,8 +0,0 @@
-// RUN: %check_clang_tidy %s * %t
-
-#if defined(__clang_analyzer__)
-#warning __clang_analyzer__ is defined
-#endif
-// CHECK-MESSAGES: :[[@LINE-2]]:2: warning: __clang_analyzer__ is defined 
[clang-diagnostic-#warnings]
-
-


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


[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Yeah, actually, I'm second-guessing myself.  Maybe this should just be a libc++ 
/ libstdc++ bug.


Repository:
  rC Clang

https://reviews.llvm.org/D45163



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


[PATCH] D44985: [CUDA] Let device-side shared variables be initialized with undef

2018-04-02 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328994: [CUDA] Let device-side shared variables be 
initialized with undef (authored by yaxunl, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44985?vs=140640&id=140648#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44985

Files:
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/test/CodeGenCUDA/address-spaces.cu
  cfe/trunk/test/CodeGenCUDA/device-var-init.cu

Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -229,12 +229,14 @@
   LangAS AS = GetGlobalVarAddressSpace(&D);
   unsigned TargetAS = getContext().getTargetAddressSpace(AS);
 
-  // Local address space cannot have an initializer.
+  // OpenCL variables in local address space and CUDA shared
+  // variables cannot have an initializer.
   llvm::Constant *Init = nullptr;
-  if (Ty.getAddressSpace() != LangAS::opencl_local)
-Init = EmitNullConstant(Ty);
-  else
+  if (Ty.getAddressSpace() == LangAS::opencl_local ||
+  D.hasAttr())
 Init = llvm::UndefValue::get(LTy);
+  else
+Init = EmitNullConstant(Ty);
 
   llvm::GlobalVariable *GV = new llvm::GlobalVariable(
   getModule(), LTy, Ty.isConstant(getContext()), Linkage, Init, Name,
Index: cfe/trunk/test/CodeGenCUDA/address-spaces.cu
===
--- cfe/trunk/test/CodeGenCUDA/address-spaces.cu
+++ cfe/trunk/test/CodeGenCUDA/address-spaces.cu
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm %s -o - -fcuda-is-device -triple nvptx-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -fcuda-is-device -triple amdgcn | FileCheck %s
 
 // Verifies Clang emits correct address spaces and addrspacecast instructions
 // for CUDA code.
@@ -19,11 +20,11 @@
   int data2;
 };
 
-// CHECK: @_ZZ5func0vE1a = internal addrspace(3) global %struct.MyStruct zeroinitializer
-// CHECK: @_ZZ5func1vE1a = internal addrspace(3) global float 0.00e+00
-// CHECK: @_ZZ5func2vE1a = internal addrspace(3) global [256 x float] zeroinitializer
-// CHECK: @_ZZ5func3vE1a = internal addrspace(3) global float 0.00e+00
-// CHECK: @_ZZ5func4vE1a = internal addrspace(3) global float 0.00e+00
+// CHECK: @_ZZ5func0vE1a = internal addrspace(3) global %struct.MyStruct undef
+// CHECK: @_ZZ5func1vE1a = internal addrspace(3) global float undef
+// CHECK: @_ZZ5func2vE1a = internal addrspace(3) global [256 x float] undef
+// CHECK: @_ZZ5func3vE1a = internal addrspace(3) global float undef
+// CHECK: @_ZZ5func4vE1a = internal addrspace(3) global float undef
 // CHECK: @b = addrspace(3) global float undef
 
 __device__ void foo() {
@@ -48,7 +49,7 @@
   ap->data2 = 2;
 }
 // CHECK: define void @_Z5func0v()
-// CHECK: store %struct.MyStruct* addrspacecast (%struct.MyStruct addrspace(3)* @_ZZ5func0vE1a to %struct.MyStruct*), %struct.MyStruct** %ap
+// CHECK: store %struct.MyStruct* addrspacecast (%struct.MyStruct addrspace(3)* @_ZZ5func0vE1a to %struct.MyStruct*), %struct.MyStruct** %{{.*}}
 
 __device__ void callee(float *ap) {
   *ap = 1.0f;
@@ -67,23 +68,23 @@
   *ap = 1.0f;
 }
 // CHECK: define void @_Z5func2v()
-// CHECK: store float* getelementptr inbounds ([256 x float], [256 x float]* addrspacecast ([256 x float] addrspace(3)* @_ZZ5func2vE1a to [256 x float]*), i32 0, i32 128), float** %ap
+// CHECK: store float* getelementptr inbounds ([256 x float], [256 x float]* addrspacecast ([256 x float] addrspace(3)* @_ZZ5func2vE1a to [256 x float]*), i{{32|64}} 0, i{{32|64}} 128), float** %{{.*}}
 
 __device__ void func3() {
   __shared__ float a;
   float *ap = reinterpret_cast(&a); // explicit cast
   *ap = 1.0f;
 }
 // CHECK: define void @_Z5func3v()
-// CHECK: store float* addrspacecast (float addrspace(3)* @_ZZ5func3vE1a to float*), float** %ap
+// CHECK: store float* addrspacecast (float addrspace(3)* @_ZZ5func3vE1a to float*), float** %{{.*}}
 
 __device__ void func4() {
   __shared__ float a;
   float *ap = (float *)&a; // explicit c-style cast
   *ap = 1.0f;
 }
 // CHECK: define void @_Z5func4v()
-// CHECK: store float* addrspacecast (float addrspace(3)* @_ZZ5func4vE1a to float*), float** %ap
+// CHECK: store float* addrspacecast (float addrspace(3)* @_ZZ5func4vE1a to float*), float** %{{.*}}
 
 __shared__ float b;
 
Index: cfe/trunk/test/CodeGenCUDA/device-var-init.cu
===
--- cfe/trunk/test/CodeGenCUDA/device-var-init.cu
+++ cfe/trunk/test/CodeGenCUDA/device-var-init.cu
@@ -1,10 +1,14 @@
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // Make sure we don't allow dynamic initialization for device
 // variables, but accept empty constructors allowed by CUDA.
 
 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -std=c++11 \
-// RUN: -fno-threadsafe-

r328994 - [CUDA] Let device-side shared variables be initialized with undef

2018-04-02 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Mon Apr  2 10:38:24 2018
New Revision: 328994

URL: http://llvm.org/viewvc/llvm-project?rev=328994&view=rev
Log:
[CUDA] Let device-side shared variables be initialized with undef

CUDA shared variable should be initialized with undef.

Patch by Greg Rodgers.
Revised and lit test added by Yaxun Liu.

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

Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenCUDA/address-spaces.cu
cfe/trunk/test/CodeGenCUDA/device-var-init.cu

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=328994&r1=328993&r2=328994&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Apr  2 10:38:24 2018
@@ -229,12 +229,14 @@ llvm::Constant *CodeGenModule::getOrCrea
   LangAS AS = GetGlobalVarAddressSpace(&D);
   unsigned TargetAS = getContext().getTargetAddressSpace(AS);
 
-  // Local address space cannot have an initializer.
+  // OpenCL variables in local address space and CUDA shared
+  // variables cannot have an initializer.
   llvm::Constant *Init = nullptr;
-  if (Ty.getAddressSpace() != LangAS::opencl_local)
-Init = EmitNullConstant(Ty);
-  else
+  if (Ty.getAddressSpace() == LangAS::opencl_local ||
+  D.hasAttr())
 Init = llvm::UndefValue::get(LTy);
+  else
+Init = EmitNullConstant(Ty);
 
   llvm::GlobalVariable *GV = new llvm::GlobalVariable(
   getModule(), LTy, Ty.isConstant(getContext()), Linkage, Init, Name,

Modified: cfe/trunk/test/CodeGenCUDA/address-spaces.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/address-spaces.cu?rev=328994&r1=328993&r2=328994&view=diff
==
--- cfe/trunk/test/CodeGenCUDA/address-spaces.cu (original)
+++ cfe/trunk/test/CodeGenCUDA/address-spaces.cu Mon Apr  2 10:38:24 2018
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm %s -o - -fcuda-is-device -triple 
nvptx-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -fcuda-is-device -triple amdgcn | 
FileCheck %s
 
 // Verifies Clang emits correct address spaces and addrspacecast instructions
 // for CUDA code.
@@ -19,11 +20,11 @@ struct MyStruct {
   int data2;
 };
 
-// CHECK: @_ZZ5func0vE1a = internal addrspace(3) global %struct.MyStruct 
zeroinitializer
-// CHECK: @_ZZ5func1vE1a = internal addrspace(3) global float 0.00e+00
-// CHECK: @_ZZ5func2vE1a = internal addrspace(3) global [256 x float] 
zeroinitializer
-// CHECK: @_ZZ5func3vE1a = internal addrspace(3) global float 0.00e+00
-// CHECK: @_ZZ5func4vE1a = internal addrspace(3) global float 0.00e+00
+// CHECK: @_ZZ5func0vE1a = internal addrspace(3) global %struct.MyStruct undef
+// CHECK: @_ZZ5func1vE1a = internal addrspace(3) global float undef
+// CHECK: @_ZZ5func2vE1a = internal addrspace(3) global [256 x float] undef
+// CHECK: @_ZZ5func3vE1a = internal addrspace(3) global float undef
+// CHECK: @_ZZ5func4vE1a = internal addrspace(3) global float undef
 // CHECK: @b = addrspace(3) global float undef
 
 __device__ void foo() {
@@ -48,7 +49,7 @@ __device__ void func0() {
   ap->data2 = 2;
 }
 // CHECK: define void @_Z5func0v()
-// CHECK: store %struct.MyStruct* addrspacecast (%struct.MyStruct 
addrspace(3)* @_ZZ5func0vE1a to %struct.MyStruct*), %struct.MyStruct** %ap
+// CHECK: store %struct.MyStruct* addrspacecast (%struct.MyStruct 
addrspace(3)* @_ZZ5func0vE1a to %struct.MyStruct*), %struct.MyStruct** %{{.*}}
 
 __device__ void callee(float *ap) {
   *ap = 1.0f;
@@ -67,7 +68,7 @@ __device__ void func2() {
   *ap = 1.0f;
 }
 // CHECK: define void @_Z5func2v()
-// CHECK: store float* getelementptr inbounds ([256 x float], [256 x float]* 
addrspacecast ([256 x float] addrspace(3)* @_ZZ5func2vE1a to [256 x float]*), 
i32 0, i32 128), float** %ap
+// CHECK: store float* getelementptr inbounds ([256 x float], [256 x float]* 
addrspacecast ([256 x float] addrspace(3)* @_ZZ5func2vE1a to [256 x float]*), 
i{{32|64}} 0, i{{32|64}} 128), float** %{{.*}}
 
 __device__ void func3() {
   __shared__ float a;
@@ -75,7 +76,7 @@ __device__ void func3() {
   *ap = 1.0f;
 }
 // CHECK: define void @_Z5func3v()
-// CHECK: store float* addrspacecast (float addrspace(3)* @_ZZ5func3vE1a to 
float*), float** %ap
+// CHECK: store float* addrspacecast (float addrspace(3)* @_ZZ5func3vE1a to 
float*), float** %{{.*}}
 
 __device__ void func4() {
   __shared__ float a;
@@ -83,7 +84,7 @@ __device__ void func4() {
   *ap = 1.0f;
 }
 // CHECK: define void @_Z5func4v()
-// CHECK: store float* addrspacecast (float addrspace(3)* @_ZZ5func4vE1a to 
float*), float** %ap
+// CHECK: store float* addrspacecast (float addrspace(3)* @_ZZ5func4vE1a to 
float*), float** %{{.*}}
 
 __shared__ float b;
 

Modified: cfe/trunk/test/CodeGenCUDA/device-var-init.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/

[PATCH] D45120: [coroutines] Add __builtin_coro_noop => llvm.coro.noop

2018-04-02 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov closed this revision.
GorNishanov added a comment.

Committed:

https://reviews.llvm.org/rC328993

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328993 
91177308-0d34-0410-b5e6-96231b3b80d8


https://reviews.llvm.org/D45120



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


[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(See also https://bugs.llvm.org/show_bug.cgi?id=10011 for a somewhat related 
discussion.)


Repository:
  rC Clang

https://reviews.llvm.org/D45163



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


r328993 - [coroutines] Add __builtin_coro_noop => llvm.coro.noop

2018-04-02 Thread Gor Nishanov via cfe-commits
Author: gornishanov
Date: Mon Apr  2 10:35:37 2018
New Revision: 328993

URL: http://llvm.org/viewvc/llvm-project?rev=328993&view=rev
Log:
[coroutines] Add __builtin_coro_noop => llvm.coro.noop

A recent addition to Coroutines TS (https://wg21.link/p0913) adds a pre-defined
coroutine noop_coroutine that does nothing. To implement this feature, we 
implemented
an llvm.coro.noop intrinsic that returns a coroutine handle to a coroutine that
does nothing when resumed or destroyed.

This patch adds a builtin __builtin_coro_noop() that maps to llvm.coro.noop 
intrinsic.

Related llvm change: https://reviews.llvm.org/D45114

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenCoroutines/coro-builtins.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=328993&r1=328992&r2=328993&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Mon Apr  2 10:35:37 2018
@@ -1391,6 +1391,7 @@ BUILTIN(__builtin_coro_promise, "v*v*IiI
 
 BUILTIN(__builtin_coro_size, "z", "n")
 BUILTIN(__builtin_coro_frame, "v*", "n")
+BUILTIN(__builtin_coro_noop, "v*", "n")
 BUILTIN(__builtin_coro_free, "v*v*", "n")
 
 BUILTIN(__builtin_coro_id, "v*Iiv*v*v*", "n")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=328993&r1=328992&r2=328993&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Apr  2 10:35:37 2018
@@ -2796,6 +2796,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 return EmitCoroutineIntrinsic(E, Intrinsic::coro_resume);
   case Builtin::BI__builtin_coro_frame:
 return EmitCoroutineIntrinsic(E, Intrinsic::coro_frame);
+  case Builtin::BI__builtin_coro_noop:
+return EmitCoroutineIntrinsic(E, Intrinsic::coro_noop);
   case Builtin::BI__builtin_coro_free:
 return EmitCoroutineIntrinsic(E, Intrinsic::coro_free);
   case Builtin::BI__builtin_coro_destroy:

Modified: cfe/trunk/test/CodeGenCoroutines/coro-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCoroutines/coro-builtins.c?rev=328993&r1=328992&r2=328993&view=diff
==
--- cfe/trunk/test/CodeGenCoroutines/coro-builtins.c (original)
+++ cfe/trunk/test/CodeGenCoroutines/coro-builtins.c Mon Apr  2 10:35:37 2018
@@ -17,6 +17,9 @@ void f(int n) {
   // CHECK-NEXT: call i1 @llvm.coro.alloc(token %[[COROID]])
   __builtin_coro_alloc();
 
+  // CHECK-NEXT: call i8* @llvm.coro.noop()
+  __builtin_coro_noop();
+
   // CHECK-NEXT: %[[SIZE:.+]] = call i64 @llvm.coro.size.i64()
   // CHECK-NEXT: %[[MEM:.+]] = call i8* @myAlloc(i64 %[[SIZE]])
   // CHECK-NEXT: %[[FRAME:.+]] = call i8* @llvm.coro.begin(token %[[COROID]], 
i8* %[[MEM]])


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


[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

LGTM.  I think it wouldn't be unreasonable to ask standard library maintainers 
to add `[[nodiscard]]` to `std::move`, but it's also not unreasonable for us to 
special-case some functions.


Repository:
  rC Clang

https://reviews.llvm.org/D45163



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


[PATCH] D44985: [CUDA] Let device-side shared variables be initialized with undef

2018-04-02 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.

LGTM, thanks.


https://reviews.llvm.org/D44985



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


[PATCH] D44985: [CUDA] Let device-side shared variables be initialized with undef

2018-04-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 140640.
yaxunl added a comment.

Only check attribute.


https://reviews.llvm.org/D44985

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenCUDA/address-spaces.cu
  test/CodeGenCUDA/device-var-init.cu

Index: test/CodeGenCUDA/device-var-init.cu
===
--- test/CodeGenCUDA/device-var-init.cu
+++ test/CodeGenCUDA/device-var-init.cu
@@ -1,10 +1,14 @@
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // Make sure we don't allow dynamic initialization for device
 // variables, but accept empty constructors allowed by CUDA.
 
 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -std=c++11 \
-// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck %s
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,NVPTX %s
+
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 \
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,AMDGCN %s
 
 #ifdef __clang__
 #include "Inputs/cuda.h"
@@ -105,68 +109,120 @@
 __constant__ EC_I_EC c_ec_i_ec;
 // CHECK: @c_ec_i_ec = addrspace(4) externally_initialized global %struct.EC_I_EC zeroinitializer,
 
+// CHECK: @_ZZ2dfvE4s_ec = internal addrspace(3) global %struct.EC undef
+// CHECK: @_ZZ2dfvE5s_etc = internal addrspace(3) global %struct.ETC undef
+
 // We should not emit global initializers for device-side variables.
 // CHECK-NOT: @__cxx_global_var_init
 
 // Make sure that initialization restrictions do not apply to local
 // variables.
 __device__ void df() {
+  // NVPTX:  %[[ec:.*]] = alloca %struct.EC
+  // NVPTX:  %[[ed:.*]] = alloca %struct.ED
+  // NVPTX:  %[[ecd:.*]] = alloca %struct.ECD
+  // NVPTX:  %[[etc:.*]] = alloca %struct.ETC
+  // NVPTX:  %[[uc:.*]] = alloca %struct.UC
+  // NVPTX:  %[[ud:.*]] = alloca %struct.UD
+  // NVPTX:  %[[eci:.*]] = alloca %struct.ECI
+  // NVPTX:  %[[nec:.*]] = alloca %struct.NEC
+  // NVPTX:  %[[ned:.*]] = alloca %struct.NED
+  // NVPTX:  %[[ncv:.*]] = alloca %struct.NCV
+  // NVPTX:  %[[vd:.*]] = alloca %struct.VD
+  // NVPTX:  %[[ncf:.*]] = alloca %struct.NCF
+  // NVPTX:  %[[ncfs:.*]] = alloca %struct.NCFS
+  // NVPTX:  %[[utc:.*]] = alloca %struct.UTC
+  // NVPTX:  %[[netc:.*]] = alloca %struct.NETC
+  // NVPTX:  %[[ec_i_ec:.*]] = alloca %struct.EC_I_EC
+  // NVPTX:  %[[ec_i_ec1:.*]] = alloca %struct.EC_I_EC1
+  // NVPTX:  %[[t_v_t:.*]] = alloca %struct.T_V_T
+  // NVPTX:  %[[t_b_nec:.*]] = alloca %struct.T_B_NEC
+  // NVPTX:  %[[t_f_nec:.*]] = alloca %struct.T_F_NEC
+  // NVPTX:  %[[t_fa_nec:.*]] = alloca %struct.T_FA_NEC
+  // NVPTX:  %[[t_b_ned:.*]] = alloca %struct.T_B_NED
+  // NVPTX:  %[[t_f_ned:.*]] = alloca %struct.T_F_NED
+  // NVPTX:  %[[t_fa_ned:.*]] = alloca %struct.T_FA_NED
+  // AMDGCN:  %[[ec:.*]] = addrspacecast %struct.EC addrspace(5)* %ec to %struct.EC*
+  // AMDGCN:  %[[ed:.*]] = addrspacecast %struct.ED addrspace(5)* %ed to %struct.ED*
+  // AMDGCN:  %[[ecd:.*]] = addrspacecast %struct.ECD addrspace(5)* %ecd to %struct.ECD*
+  // AMDGCN:  %[[etc:.*]] = addrspacecast %struct.ETC addrspace(5)* %etc to %struct.ETC*
+  // AMDGCN:  %[[uc:.*]] = addrspacecast %struct.UC addrspace(5)* %uc to %struct.UC*
+  // AMDGCN:  %[[ud:.*]] = addrspacecast %struct.UD addrspace(5)* %ud to %struct.UD*
+  // AMDGCN:  %[[eci:.*]] = addrspacecast %struct.ECI addrspace(5)* %eci to %struct.ECI*
+  // AMDGCN:  %[[nec:.*]] = addrspacecast %struct.NEC addrspace(5)* %nec to %struct.NEC*
+  // AMDGCN:  %[[ned:.*]] = addrspacecast %struct.NED addrspace(5)* %ned to %struct.NED*
+  // AMDGCN:  %[[ncv:.*]] = addrspacecast %struct.NCV addrspace(5)* %ncv to %struct.NCV*
+  // AMDGCN:  %[[vd:.*]] = addrspacecast %struct.VD addrspace(5)* %vd to %struct.VD*
+  // AMDGCN:  %[[ncf:.*]] = addrspacecast %struct.NCF addrspace(5)* %ncf to %struct.NCF*
+  // AMDGCN:  %[[ncfs:.*]] = addrspacecast %struct.NCFS addrspace(5)* %ncfs to %struct.NCFS*
+  // AMDGCN:  %[[utc:.*]] = addrspacecast %struct.UTC addrspace(5)* %utc to %struct.UTC*
+  // AMDGCN:  %[[netc:.*]] = addrspacecast %struct.NETC addrspace(5)* %netc to %struct.NETC*
+  // AMDGCN:  %[[ec_i_ec:.*]] = addrspacecast %struct.EC_I_EC addrspace(5)* %ec_i_ec to %struct.EC_I_EC*
+  // AMDGCN:  %[[ec_i_ec1:.*]] = addrspacecast %struct.EC_I_EC1 addrspace(5)* %ec_i_ec1 to %struct.EC_I_EC1*
+  // AMDGCN:  %[[t_v_t:.*]] = addrspacecast %struct.T_V_T addrspace(5)* %t_v_t to %struct.T_V_T*
+  // AMDGCN:  %[[t_b_nec:.*]] = addrspacecast %struct.T_B_NEC addrspace(5)* %t_b_nec to %struct.T_B_NEC*
+  // AMDGCN:  %[[t_f_nec:.*]] = addrspacecast %struct.T_F_NEC addrspace(5)* %t_f_nec to %struct.T_F_NEC*
+  // AMDGCN:  %[[t_fa_nec:.*]] = addrspacecast %struct.T_FA_NEC addrspace(5)* %t_fa_nec to %struct.T_FA_NEC*
+  // AMDGCN:  %[[t_b_ned:.*]] = addrspacecast %struct.T_B_NED addrspace(5)* %t_b_ned to %struct.T_B_NED*
+  // AMDGCN:  %[[t_f_ned:.*]] = addrspacecast %struct.T_F_NED addrspace(5)* %t_f_ne

[PATCH] D44985: [CUDA] Let device-side shared variables be initialized with undef

2018-04-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:235-240
+  if (Ty.getAddressSpace() != LangAS::opencl_local &&
+  !(getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
+D.hasAttr()))
 Init = EmitNullConstant(Ty);
   else
 Init = llvm::UndefValue::get(LTy);

rjmccall wrote:
> tra wrote:
> > This is too hard to read. Inverting it makes it somewhat easier to 
> > understand -- `either opencl_local or device-side CUDA shared are undef`.
> > ```
> >   if (Ty.getAddressSpace() == LangAS::opencl_local 
> >   || (getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
> >   D.hasAttr()))
> > Init = llvm::UndefValue::get(LTy);
> >   else
> > Init = EmitNullConstant(Ty);
> > ```
> > 
> I assume getLangOpts().CUDAIsDevice implies getLangOpts().CUDA, so you really 
> only need to check CUDAIsDevice.  But it might be faster still to just check 
> for the attribute.
Right. I think only attribute needs to be checked.


https://reviews.llvm.org/D44985



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


[PATCH] D44996: [clang-format] Ensure ObjC selectors with 0 args are annotated correctly

2018-04-02 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton marked 2 inline comments as done.
benhamilton added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:1347
+} else if (Current.isOneOf(tok::identifier, tok::kw_new) &&
+   Current.Previous && Current.Previous->is(TT_CastRParen) &&
+   Current.Previous->MatchingParen &&

benhamilton wrote:
> djasper wrote:
> > Isn't it wrong that we detect this as a cast r_paren in the first place?
> Fantastic question, I asked myself the same thing.
> 
> I tried a few variations on this (leaving it as `TT_Unknown`, making a new 
> type, etc.) and discovered there is at least one existing place which relies 
> on the `TT_CastRParen` type as an indicator of ObjC code. Example:
> 
> https://github.com/llvm-mirror/clang/blob/e37a191e99773959118155304ec2ed0bc0d591c2/lib/Format/TokenAnnotator.cpp#L394
> 
> I can fix those, but if I do so, I think it should be a separate diff. What 
> do you think?
@djasper and I talked about this on Friday and agreed we should follow up 
separately.

I filed https://bugs.llvm.org/show_bug.cgi?id=36976 to follow up.


Repository:
  rC Clang

https://reviews.llvm.org/D44996



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


[PATCH] D45169: [clang-format/ObjC] Do not detect "[]" as ObjC method expression

2018-04-02 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak.
Herald added subscribers: cfe-commits, klimek.

The following C++ code was being detected by
`guessLanguage()` as Objective-C:

  #define FOO(...) auto bar = [] __VA_ARGS__;

This was because `[] __VA_ARGS__` is not currently detected as a C++
lambda expression (it has no parens or braces), so
`TokenAnnotator::parseSquare()` incorrectly treats the opening square
as an ObjC method expression.

We have two options to fix this:

1. Parse `[] __VA_ARGS__` explicitly as a C++ lambda
2. Make it so `[]` is never parsed as an Objective-C method expression

This diff implements option 2, which causes the `[` to be parsed
as `TT_ArraySubscriptLSquare` instead of `TT_ObjCMethodExpr`.

Note that when I fixed this, it caused one change in formatting
behavior, where the following was implicitly relying on the `[`
being parsed as `TT_ObjCMethodExpr`:

  A a;

becomes:

  A a;

with `Style.PointerAlignment = Middle`.

I don't really know what the desired format is for this syntax; the
test was added by Janusz Sobczak and integrated by @djasper in
https://github.com/llvm-mirror/clang/commit/b511fe9818829d7ece0cc0b2ce1fbe04a1f0739a
.

I went ahead and changed the test for now.

Test Plan: New tests added. Ran tests with:

  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D45169

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6035,14 +6035,15 @@
   PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle;
   verifyFormat("delete *x;", PointerMiddle);
   verifyFormat("int * x;", PointerMiddle);
+  verifyFormat("int *[] x;", PointerMiddle);
   verifyFormat("template  f() {}", PointerMiddle);
   verifyFormat("int * f(int * a) {}", PointerMiddle);
   verifyFormat("int main(int argc, char ** argv) {}", PointerMiddle);
   verifyFormat("Test::Test(int b) : a(b * b) {}", PointerMiddle);
   verifyFormat("A a;", PointerMiddle);
   verifyFormat("A a;", PointerMiddle);
   verifyFormat("A a;", PointerMiddle);
-  verifyFormat("A a;", PointerMiddle);
+  verifyFormat("A a;", PointerMiddle);
   verifyFormat("A = new SomeType *[Length]();", PointerMiddle);
   verifyFormat("A = new SomeType *[Length];", PointerMiddle);
   verifyFormat("T ** t = new T *;", PointerMiddle);
@@ -12106,6 +12107,9 @@
   FormatStyle::LK_ObjC,
   guessLanguage("foo.h",
 "#define MY_POINT_MAKE(x, y) CGPointMake((x), (y));\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "#define FOO(...) auto bar = [] __VA_ARGS__;"));
 }
 
 TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -386,7 +386,7 @@
 bool StartsObjCMethodExpr =
 !CppArrayTemplates && Style.isCpp() && !IsCpp11AttributeSpecifier &&
 Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
-CurrentToken->isNot(tok::l_brace) &&
+!CurrentToken->isOneOf(tok::l_brace, tok::r_square) &&
 (!Parent ||
  Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
  tok::kw_return, tok::kw_throw) ||


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6035,14 +6035,15 @@
   PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle;
   verifyFormat("delete *x;", PointerMiddle);
   verifyFormat("int * x;", PointerMiddle);
+  verifyFormat("int *[] x;", PointerMiddle);
   verifyFormat("template  f() {}", PointerMiddle);
   verifyFormat("int * f(int * a) {}", PointerMiddle);
   verifyFormat("int main(int argc, char ** argv) {}", PointerMiddle);
   verifyFormat("Test::Test(int b) : a(b * b) {}", PointerMiddle);
   verifyFormat("A a;", PointerMiddle);
   verifyFormat("A a;", PointerMiddle);
   verifyFormat("A a;", PointerMiddle);
-  verifyFormat("A a;", PointerMiddle);
+  verifyFormat("A a;", PointerMiddle);
   verifyFormat("A = new SomeType *[Length]();", PointerMiddle);
   verifyFormat("A = new SomeType *[Length];", PointerMiddle);
   verifyFormat("T ** t = new T *;", PointerMiddle);
@@ -12106,6 +12107,9 @@
   FormatStyle::LK_ObjC,
   guessLanguage("foo.h",
 "#define MY_POINT_MAKE(x, y) CGPointMake((x), (y));\n"));
+  EXPECT_EQ(
+  FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "#define FOO(...) auto bar = [] __VA_ARGS__;"));
 }
 
 TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {
Index: lib/Format/TokenAnnotator.cpp
==

[PATCH] D45168: [clang-format/ObjC] Do not insert space after opening brace of ObjC dict literal

2018-04-02 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak, krasimir.
Herald added subscribers: cfe-commits, klimek.

https://reviews.llvm.org/D44816 attempted to fix a few cases where 
`clang-format` incorrectly
inserted a space before the closing brace of an Objective-C dictionary
literal.

This revealed there were still a few cases where we inserted a space
after the opening brace of an Objective-C dictionary literal.

This fixes the formatting to be consistent and adds more tests.

Test Plan: New tests added. Confirmed tests failed before

  diff and passed after diff.
  Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D45168

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1020,9 +1020,18 @@
   verifyFormat("int Foo() {\n"
"  a12345 = @{a12345 : a12345};\n"
"}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : @(a12345)};\n"
+   "}");
   verifyFormat("int Foo() {\n"
"  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
"}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{@(a12345) : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{@(a12345) : @YES};\n"
+   "}");
   Style.SpacesInContainerLiterals = false;
   verifyFormat("int Foo() {\n"
"  b12345 = @{b12345: b12345};\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,6 +2480,9 @@
 return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
 return false;
+  if (Left.is(tok::l_brace) && Left.endsSequence(TT_DictLiteral, tok::at))
+// Objective-C dictionary literal -> no space after opening brace.
+return false;
   if (Right.is(tok::r_brace) && Right.MatchingParen &&
   Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at))
 // Objective-C dictionary literal -> no space before closing brace.


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1020,9 +1020,18 @@
   verifyFormat("int Foo() {\n"
"  a12345 = @{a12345 : a12345};\n"
"}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{a12345 : @(a12345)};\n"
+   "}");
   verifyFormat("int Foo() {\n"
"  a12345 = @{(Foo *)a12345 : @(a12345)};\n"
"}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{@(a12345) : a12345};\n"
+   "}");
+  verifyFormat("int Foo() {\n"
+   "  a12345 = @{@(a12345) : @YES};\n"
+   "}");
   Style.SpacesInContainerLiterals = false;
   verifyFormat("int Foo() {\n"
"  b12345 = @{b12345: b12345};\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2480,6 +2480,9 @@
 return false;
   if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
 return false;
+  if (Left.is(tok::l_brace) && Left.endsSequence(TT_DictLiteral, tok::at))
+// Objective-C dictionary literal -> no space after opening brace.
+return false;
   if (Right.is(tok::r_brace) && Right.MatchingParen &&
   Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at))
 // Objective-C dictionary literal -> no space before closing brace.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Right.  I think it's fair to acknowledge that many data structure unit tests 
will contain a legitimate use of a user-defined self-assignment without feeling 
that that disqualifies the warning.

Note that the purpose of this kind of breadth testing is just to look for false 
positives.  It shouldn't be discouraging if the warning doesn't find any real 
bugs in existing code.


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44842: Add Parameters to DW_AT_name Attribute of Template Variables

2018-04-02 Thread Matthew Voss via Phabricator via cfe-commits
ormris added a comment.

//Ping//


Repository:
  rC Clang

https://reviews.llvm.org/D44842



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


[PATCH] D44934: [analyzer] Improve the modeling of `memset()`.

2018-04-02 Thread Henry Wong via Phabricator via cfe-commits
MTC added a comment.

Kindly ping!


Repository:
  rC Clang

https://reviews.llvm.org/D44934



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


[PATCH] D44934: [analyzer] Improve the modeling of `memset()`.

2018-04-02 Thread Henry Wong via Phabricator via cfe-commits
MTC updated this revision to Diff 140629.
MTC added a comment.

> Thank you for your reminding, I overlooked this point. However for 
> non-concrete character, the symbol value, if we just invalidate the region, 
> the constraint information of the non-concrete character will be lost. Do we 
> need to consider this?

Sorry for my hasty question, analyzer does not support to bind a symbol with a 
default binding.

The update of this diff is as follows.

- If the char value is not concrete, just invalidate the region.
- Add a test about symbolic char value.
- A little code refactoring.


Repository:
  rC Clang

https://reviews.llvm.org/D44934

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  lib/StaticAnalyzer/Core/ProgramState.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  lib/StaticAnalyzer/Core/Store.cpp
  test/Analysis/bstring.cpp
  test/Analysis/null-deref-ps-region.c
  test/Analysis/string.c

Index: test/Analysis/string.c
===
--- test/Analysis/string.c
+++ test/Analysis/string.c
@@ -1,7 +1,8 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
-// RUN: %clang_analyze_cc1 -DUSE_BUILTINS -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
-// RUN: %clang_analyze_cc1 -DVARIANT -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
-// RUN: %clang_analyze_cc1 -DUSE_BUILTINS -DVARIANT -analyzer-checker=alpha.security.taint,core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.cstring,unix.Malloc,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
+// RUN: %clang_analyze_cc1 -DUSE_BUILTINS -analyzer-checker=core,unix.cstring,unix.Malloc,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
+// RUN: %clang_analyze_cc1 -DVARIANT -analyzer-checker=core,unix.cstring,unix.Malloc,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
+// RUN: %clang_analyze_cc1 -DUSE_BUILTINS -DVARIANT -analyzer-checker=alpha.security.taint,core,unix.cstring,unix.Malloc,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
+// RUN: %clang_analyze_cc1 -DSUPPRESS_OUT_OF_BOUND -analyzer-checker=core,unix.cstring,unix.Malloc,alpha.unix.cstring.BufferOverlap,alpha.unix.cstring.NotNullTerminated,debug.ExprInspection -analyzer-store=region -Wno-null-dereference -verify %s
 
 //===--===
 // Declarations
@@ -1159,6 +1160,248 @@
   clang_analyzer_eval(str[1] == 'b'); // expected-warning{{UNKNOWN}}
 }
 
+//===--===
+// memset()
+//===--===
+
+void *memset( void *dest, int ch, size_t count );
+
+void* malloc(size_t size);
+void free(void*);
+
+void memset1_char_array_null() {
+  char str[] = "abcd";
+  clang_analyzer_eval(strlen(str) == 4); // expected-warning{{TRUE}}
+  memset(str, '\0', 2);
+  clang_analyzer_eval(strlen(str) == 0); // expected-warning{{TRUE}}
+}
+
+void memset2_char_array_null() {
+  char str[] = "abcd";
+  clang_analyzer_eval(strlen(str) == 4); // expected-warning{{TRUE}}
+  memset(str, '\0', strlen(str) + 1);
+  clang_analyzer_eval(strlen(str) == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(str[2] == 0);  // expected-warning{{TRUE}}
+}
+
+void memset3_char_malloc_null() {
+  char *str = (char *)malloc(10 * sizeof(char));
+  memset(str + 1, '\0', 8);
+  clang_analyzer_eval(str[1] == 0); // expected-warning{{UNKNOWN}}
+  free(str);
+}
+
+void memset4_char_malloc_null() {
+  char *str = (char *)malloc(10 * sizeof(char));
+  //void *str = malloc(10 * sizeof(char));
+  memset(str, '\0', 10);
+  clang_analyzer_eval(str[1] == 0);  // expected-warning{{TRUE}}
+  clang_analyzer_eval(strlen(str) == 0); // expected-warning{{TRUE}}
+  free(str);
+}
+
+#ifdef SUPPRESS_OUT_OF_BOUND
+void memset5_char_malloc_overflow_null() {
+  char *str = (char *)malloc(10 * sizeof(char));
+  memset(str, '\0', 12);
+  clang_analyzer_eval(str[1] == 0); // expected-warning{{UNKNOWN}}
+  free(str);
+}
+#endif
+
+void memset6_char_array_nonnull() {
+  char str[] = "abcd";
+  clang_analyzer_eval(strlen(str) == 4); // expected-warning{{TRUE}}
+  memset(str, '0', 2);
+  clang_analyzer_eval(str[0] == 'a');// expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(strlen(str) == 4); // expected-warning{{UNKNO

[PATCH] D45165: Use llvm::sys::fs::real_path() in clang.

2018-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: bruno.

No expected behavior change.


https://reviews.llvm.org/D45165

Files:
  lib/Basic/FileManager.cpp
  lib/Frontend/ModuleDependencyCollector.cpp


Index: lib/Frontend/ModuleDependencyCollector.cpp
===
--- lib/Frontend/ModuleDependencyCollector.cpp
+++ lib/Frontend/ModuleDependencyCollector.cpp
@@ -97,24 +97,6 @@
 
 }
 
-// TODO: move this to Support/Path.h and check for HAVE_REALPATH?
-static bool real_path(StringRef SrcPath, SmallVectorImpl &RealPath) {
-#ifdef LLVM_ON_UNIX
-  char CanonicalPath[PATH_MAX];
-
-  // TODO: emit a warning in case this fails...?
-  if (!realpath(SrcPath.str().c_str(), CanonicalPath))
-return false;
-
-  SmallString<256> RPath(CanonicalPath);
-  RealPath.swap(RPath);
-  return true;
-#else
-  // FIXME: Add support for systems without realpath.
-  return false;
-#endif
-}
-
 void ModuleDependencyCollector::attachToASTReader(ASTReader &R) {
   R.addListener(llvm::make_unique(*this));
 }
@@ -129,7 +111,7 @@
 static bool isCaseSensitivePath(StringRef Path) {
   SmallString<256> TmpDest = Path, UpperDest, RealDest;
   // Remove component traversals, links, etc.
-  if (!real_path(Path, TmpDest))
+  if (llvm::sys::fs::real_path(Path, TmpDest))
 return true; // Current default value in vfs.yaml
   Path = TmpDest;
 
@@ -139,7 +121,7 @@
   // already expects when sensitivity isn't setup.
   for (auto &C : Path)
 UpperDest.push_back(toUppercase(C));
-  if (real_path(UpperDest, RealDest) && Path.equals(RealDest))
+  if (!llvm::sys::fs::real_path(UpperDest, RealDest) && Path.equals(RealDest))
 return false;
   return true;
 }
@@ -189,7 +171,7 @@
   // Computing the real path is expensive, cache the search through the
   // parent path directory.
   if (DirWithSymLink == SymLinkMap.end()) {
-if (!real_path(Dir, RealPath))
+if (llvm::sys::fs::real_path(Dir, RealPath))
   return false;
 SymLinkMap[Dir] = RealPath.str();
   } else {
Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -534,23 +534,9 @@
 
   StringRef CanonicalName(Dir->getName());
 
-#ifdef LLVM_ON_UNIX
-  char CanonicalNameBuf[PATH_MAX];
-  if (realpath(Dir->getName().str().c_str(), CanonicalNameBuf))
+  SmallString CanonicalNameBuf;
+  if (!llvm::sys::fs::real_path(Dir->getName(), CanonicalNameBuf))
 CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
-#else
-  SmallString<256> CanonicalNameBuf(CanonicalName);
-  llvm::sys::fs::make_absolute(CanonicalNameBuf);
-  llvm::sys::path::native(CanonicalNameBuf);
-  // We've run into needing to remove '..' here in the wild though, so
-  // remove it.
-  // On Windows, symlinks are significantly less prevalent, so removing
-  // '..' is pretty safe.
-  // Ideally we'd have an equivalent of `realpath` and could implement
-  // sys::fs::canonical across all the platforms.
-  llvm::sys::path::remove_dots(CanonicalNameBuf, /* remove_dot_dot */ true);
-  CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
-#endif
 
   CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName));
   return CanonicalName;


Index: lib/Frontend/ModuleDependencyCollector.cpp
===
--- lib/Frontend/ModuleDependencyCollector.cpp
+++ lib/Frontend/ModuleDependencyCollector.cpp
@@ -97,24 +97,6 @@
 
 }
 
-// TODO: move this to Support/Path.h and check for HAVE_REALPATH?
-static bool real_path(StringRef SrcPath, SmallVectorImpl &RealPath) {
-#ifdef LLVM_ON_UNIX
-  char CanonicalPath[PATH_MAX];
-
-  // TODO: emit a warning in case this fails...?
-  if (!realpath(SrcPath.str().c_str(), CanonicalPath))
-return false;
-
-  SmallString<256> RPath(CanonicalPath);
-  RealPath.swap(RPath);
-  return true;
-#else
-  // FIXME: Add support for systems without realpath.
-  return false;
-#endif
-}
-
 void ModuleDependencyCollector::attachToASTReader(ASTReader &R) {
   R.addListener(llvm::make_unique(*this));
 }
@@ -129,7 +111,7 @@
 static bool isCaseSensitivePath(StringRef Path) {
   SmallString<256> TmpDest = Path, UpperDest, RealDest;
   // Remove component traversals, links, etc.
-  if (!real_path(Path, TmpDest))
+  if (llvm::sys::fs::real_path(Path, TmpDest))
 return true; // Current default value in vfs.yaml
   Path = TmpDest;
 
@@ -139,7 +121,7 @@
   // already expects when sensitivity isn't setup.
   for (auto &C : Path)
 UpperDest.push_back(toUppercase(C));
-  if (real_path(UpperDest, RealDest) && Path.equals(RealDest))
+  if (!llvm::sys::fs::real_path(UpperDest, RealDest) && Path.equals(RealDest))
 return false;
   return true;
 }
@@ -189,7 +171,7 @@
   // Computing the real path is expensive, cache the search through the
   // parent path directory.
   if (DirWithSymLink == SymLinkMap.end()) {
-if (!real_path(Dir, RealPath))
+i

Re: [PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread David Blaikie via cfe-commits
On Mon, Apr 2, 2018 at 8:05 AM Roman Lebedev via Phabricator <
revi...@reviews.llvm.org> wrote:

> lebedev.ri added a comment.
>
> In https://reviews.llvm.org/D44883#1054326, @thakis wrote:
>
> > In https://reviews.llvm.org/D44883#1048751, @dblaikie wrote:
> >
> > > Historically Clang's policy on warnings was, I think, much more
> > >  conservative than it seems to be today. There was a strong desire not
> to
> > >  implement off-by-default warnings, and to have warnings with an
> > >  exceptionally low false-positive rate - maybe the user-defined
> operator
> > >  detection was either assumed to, or demonstrated to, have a
> sufficiently
> > >  high false positive rate to not meet that high bar.
> >
> >
> > This is still the case. For a new warning, you should evaluate some
> large open-source codebase and measure true positive and false positive
> rate and post the numbers here.
>
>
> I did run it on stage-2 of LLVM itself. The only 'false-positives' so far
> are already present in trunk:
>

To clarify a little - "false positive" in the sense Nico (& I) are using it
is "any case in which the warning fired on code that was already working as
intended" (ie: where the warning didn't represent a real bug - or at least
represent a confusing/surprising thing that would be worth/benefit from
rewriting to some other less confusing form).

So the cases you found in the tests for certain self assignment would also
be false positives.

Not necessarily enough to warrant/argue against moving forward on this
warning, but they are imho, false positives for the purpose of discussions
like this.


> https://godbolt.org/g/SXc4Wd
>
>   void test_int () {
>   int b;
>   static_assert(noexcept(b &= b), "" );
>   }
>   void test_byte () {
>   std::byte b;
>   static_assert(noexcept(b &= (std::byte &)b), "" );
>   }
>
>   :4:30: warning: explicitly assigning value of variable of type
> 'int' to itself [-Wself-assign]
>
>   static_assert(noexcept(b &= b), "" );
>
>  ~ ^  ~
>
> Should it really warn when in unevaluated context?
> Dunno, but trunk already does that. Should that be changed?
>
> Which other large codebase do you want me to evaluate, so we can talk
> facts?
>
> >> (as for the flag splitting - that was sometimes done if the new variant
> of
> >>  a flag had enough bug-finding power that an existing codebase using the
> >>  existing flag behavior would need significant cleanup - by having the
> new
> >>  functionality under another flag name, existing codebases upgrading to
> a
> >>  newer compiler wouldn't be forced to either do all that cleanup
> up-front or
> >>  disable the flag & risk regressions... )
>
>
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D44883
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44231: [clang-tidy] Check for sizeof that call functions

2018-04-02 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

Is someone able to merge in my changes?


https://reviews.llvm.org/D44231



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


[PATCH] D45045: [DebugInfo] Generate debug information for labels.

2018-04-02 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai updated this revision to Diff 140627.
HsiangKai retitled this revision from "[DebugInfo] Generate DILabel metadata 
for labels." to "[DebugInfo] Generate debug information for labels.".
HsiangKai edited the summary of this revision.
Herald added a subscriber: eraman.

Repository:
  rC Clang

https://reviews.llvm.org/D45045

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CGStmt.cpp
  test/CodeGen/debug-label-inline.c
  test/CodeGen/debug-label.c

Index: test/CodeGen/debug-label.c
===
--- /dev/null
+++ test/CodeGen/debug-label.c
@@ -0,0 +1,16 @@
+// This test will test the correstness of generating DILabel and
+// llvm.dbg.label for labels.
+//
+// RUN: %clang_cc1 -emit-llvm %s -o - -emit-llvm -debug-info-kind=limited | FileCheck %s
+
+int f1(int a, int b) {
+  int sum;
+
+top:
+  // CHECK: call void @llvm.dbg.label(metadata [[LABEL_METADATA:!.*]]), !dbg [[LABEL_LOCATION:!.*]]
+  sum = a + b;
+  return sum;
+}
+
+// CHECK: [[LABEL_METADATA]] = !DILabel({{.*}}, name: "top", {{.*}}, line: 9)
+// CHECK: [[LABEL_LOCATION]] = !DILocation(line: 9,
Index: test/CodeGen/debug-label-inline.c
===
--- /dev/null
+++ test/CodeGen/debug-label-inline.c
@@ -0,0 +1,26 @@
+// This test will test the correctness of generating DILabel and
+// llvm.dbg.label when the label is in inlined functions.
+//
+// RUN: %clang_cc1 -O2 %s -o - -emit-llvm -debug-info-kind=limited | FileCheck %s
+inline int f1(int a, int b) {
+  int sum;
+
+top:
+  sum = a + b;
+  return sum;
+}
+
+extern int ga, gb;
+
+int f2(void) {
+  int result;
+
+  result = f1(ga, gb);
+  // CHECK: call void @llvm.dbg.label(metadata [[LABEL_METADATA:!.*]]), !dbg [[LABEL_LOCATION:!.*]]
+
+  return result;
+}
+
+// CHECK: [[INLINEDAT:!.*]] = distinct !DILocation(line: 18,
+// CHECK: [[LABEL_METADATA]] = !DILabel({{.*}}, name: "top", {{.*}}, line: 8)
+// CHECK: [[LABEL_LOCATION]] = !DILocation(line: 8, {{.*}}, inlinedAt: [[INLINEDAT]])
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -531,6 +531,18 @@
   }
 
   EmitBlock(Dest.getBlock());
+
+  // Emit debug info for the label only if it's reachable.
+  if (HaveInsertPoint()) {
+if (CGDebugInfo *DI = getDebugInfo()) {
+  if (CGM.getCodeGenOpts().getDebugInfo() >=
+  codegenoptions::LimitedDebugInfo) {
+DI->setLocation(D->getLocation());
+DI->EmitLabel(D, Builder);
+  }
+}
+  }
+
   incrementProfileCounter(D->getStmt());
 }
 
Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -395,6 +395,9 @@
llvm::Value *AI,
CGBuilderTy &Builder);
 
+  /// Emit call to \c llvm.dbg.label for an label.
+  void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder);
+
   /// Emit call to \c llvm.dbg.declare for an imported variable
   /// declaration in a block.
   void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3640,6 +3640,32 @@
   return EmitDeclare(VD, Storage, llvm::None, Builder);
 }
 
+void CGDebugInfo::EmitLabel(const LabelDecl *D,
+CGBuilderTy &Builder) {
+  assert(DebugKind >= codegenoptions::LimitedDebugInfo);
+  assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
+
+  if (D->hasAttr())
+return;
+
+  auto *Scope = cast(LexicalBlockStack.back());
+  llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
+
+  // Get location information.
+  unsigned Line = getLineNumber(D->getLocation());
+  unsigned Column = getColumnNumber(D->getLocation());
+
+  StringRef Name = D->getName();
+
+  // Create the descriptor for the label.
+  auto *L = DBuilder.createLabel(Scope, Name, Unit, Line);
+
+  // Insert an llvm.dbg.label into the current block.
+  DBuilder.insertLabel(L,
+   llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
+   Builder.GetInsertBlock());
+}
+
 llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
   llvm::DIType *Ty) {
   llvm::DIType *CachedTy = getTypeOrNull(QualTy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread Nico Weber via cfe-commits
On Mon, Apr 2, 2018 at 11:05 AM, Roman Lebedev via Phabricator via
cfe-commits  wrote:

> lebedev.ri added a comment.
>
> In https://reviews.llvm.org/D44883#1054326, @thakis wrote:
>
> > In https://reviews.llvm.org/D44883#1048751, @dblaikie wrote:
> >
> > > Historically Clang's policy on warnings was, I think, much more
> > >  conservative than it seems to be today. There was a strong desire not
> to
> > >  implement off-by-default warnings, and to have warnings with an
> > >  exceptionally low false-positive rate - maybe the user-defined
> operator
> > >  detection was either assumed to, or demonstrated to, have a
> sufficiently
> > >  high false positive rate to not meet that high bar.
> >
> >
> > This is still the case. For a new warning, you should evaluate some
> large open-source codebase and measure true positive and false positive
> rate and post the numbers here.
>
>
> I did run it on stage-2 of LLVM itself. The only 'false-positives' so far
> are already present in trunk:
> https://godbolt.org/g/SXc4Wd
>
>   void test_int () {
>   int b;
>   static_assert(noexcept(b &= b), "" );
>   }
>   void test_byte () {
>   std::byte b;
>   static_assert(noexcept(b &= (std::byte &)b), "" );
>   }
>
>   :4:30: warning: explicitly assigning value of variable of type
> 'int' to itself [-Wself-assign]
>
>   static_assert(noexcept(b &= b), "" );
>
>  ~ ^  ~
>
> Should it really warn when in unevaluated context?
> Dunno, but trunk already does that. Should that be changed?
>
> Which other large codebase do you want me to evaluate, so we can talk
> facts?
>

Either of OpenOffice, Firefox, or Chromium have been used in the past for
warning evaluation.


> >> (as for the flag splitting - that was sometimes done if the new variant
> of
> >>  a flag had enough bug-finding power that an existing codebase using the
> >>  existing flag behavior would need significant cleanup - by having the
> new
> >>  functionality under another flag name, existing codebases upgrading to
> a
> >>  newer compiler wouldn't be forced to either do all that cleanup
> up-front or
> >>  disable the flag & risk regressions... )
>
>
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D44883
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D44883#1054326, @thakis wrote:

> In https://reviews.llvm.org/D44883#1048751, @dblaikie wrote:
>
> > Historically Clang's policy on warnings was, I think, much more
> >  conservative than it seems to be today. There was a strong desire not to
> >  implement off-by-default warnings, and to have warnings with an
> >  exceptionally low false-positive rate - maybe the user-defined operator
> >  detection was either assumed to, or demonstrated to, have a sufficiently
> >  high false positive rate to not meet that high bar.
>
>
> This is still the case. For a new warning, you should evaluate some large 
> open-source codebase and measure true positive and false positive rate and 
> post the numbers here.


I did run it on stage-2 of LLVM itself. The only 'false-positives' so far are 
already present in trunk:
https://godbolt.org/g/SXc4Wd

  void test_int () {
  int b;
  static_assert(noexcept(b &= b), "" );
  }
  void test_byte () {
  std::byte b;
  static_assert(noexcept(b &= (std::byte &)b), "" );
  }

  :4:30: warning: explicitly assigning value of variable of type 'int' 
to itself [-Wself-assign]
  
  static_assert(noexcept(b &= b), "" );
  
 ~ ^  ~

Should it really warn when in unevaluated context?
Dunno, but trunk already does that. Should that be changed?

Which other large codebase do you want me to evaluate, so we can talk facts?

>> (as for the flag splitting - that was sometimes done if the new variant of
>>  a flag had enough bug-finding power that an existing codebase using the
>>  existing flag behavior would need significant cleanup - by having the new
>>  functionality under another flag name, existing codebases upgrading to a
>>  newer compiler wouldn't be forced to either do all that cleanup up-front or
>>  disable the flag & risk regressions... )




Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


Re: [PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread Nico Weber via cfe-commits
On Mon, Apr 2, 2018 at 10:54 AM, Nico Weber via Phabricator via cfe-commits
 wrote:

> thakis added a comment.
>
> In https://reviews.llvm.org/D44883#1048751, @dblaikie wrote:
>
> > Historically Clang's policy on warnings was, I think, much more
> >  conservative than it seems to be today. There was a strong desire not to
> >  implement off-by-default warnings, and to have warnings with an
> >  exceptionally low false-positive rate - maybe the user-defined operator
> >  detection was either assumed to, or demonstrated to, have a sufficiently
> >  high false positive rate to not meet that high bar.
>
> This is still the case. For a new warning, you should evaluate some large
> open-source codebase and measure true positive and false positive rate and
> post the numbers here.
>

(…and warnings that are useful but have a non-diminishing false positive
rate should go into clang-tidy instead.)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In https://reviews.llvm.org/D44883#1048751, @dblaikie wrote:

> Historically Clang's policy on warnings was, I think, much more
>  conservative than it seems to be today. There was a strong desire not to
>  implement off-by-default warnings, and to have warnings with an
>  exceptionally low false-positive rate - maybe the user-defined operator
>  detection was either assumed to, or demonstrated to, have a sufficiently
>  high false positive rate to not meet that high bar.


This is still the case. For a new warning, you should evaluate some large 
open-source codebase and measure true positive and false positive rate and post 
the numbers here.

> (as for the flag splitting - that was sometimes done if the new variant of
>  a flag had enough bug-finding power that an existing codebase using the
>  existing flag behavior would need significant cleanup - by having the new
>  functionality under another flag name, existing codebases upgrading to a
>  newer compiler wouldn't be forced to either do all that cleanup up-front or
>  disable the flag & risk regressions... )




Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44906: [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-04-02 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis added a subscriber: george.karpenkov.
zinovy.nis added a comment.

Looks like quotes are required.
Thanks for pointing! I'll submit a patch for this.

пн, 2 апр. 2018 г. в 17:28, Nico Weber via Phabricator <
revi...@reviews.llvm.org>:

> thakis added a comment.
> 
> Actually, it doesn't pass on non-Windows either:
>  
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/27665/steps/test/logs/stdio
> 
> Repository:
> 
>   rL LLVM
> 
> https://reviews.llvm.org/D44906


Repository:
  rL LLVM

https://reviews.llvm.org/D44906



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


Re: [PATCH] D44906: [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-04-02 Thread Zinovy Nis via cfe-commits
Looks like quotes are required.
Thanks for pointing! I'll submit a patch for this.

пн, 2 апр. 2018 г. в 17:28, Nico Weber via Phabricator <
revi...@reviews.llvm.org>:

> thakis added a comment.
>
> Actually, it doesn't pass on non-Windows either:
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/27665/steps/test/logs/stdio
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D44906
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44906: [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Actually, it doesn't pass on non-Windows either: 
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/27665/steps/test/logs/stdio


Repository:
  rL LLVM

https://reviews.llvm.org/D44906



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


[PATCH] D45163: [Sema] -Wunused-value: diagnose unused std::move() call results.

2018-04-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added reviewers: aaron.ballman, rsmith, rtrieu, rjmccall, dblaikie.

I have seen such a problem when reviewing https://reviews.llvm.org/D43341.
https://godbolt.org/g/aJYcaa

  #include 
  
  struct S {};
  
  void test(S a) {
  std::move(a);
  }

Since `std::move()` is not marked with `nodiscard` attribute in the standard
(should it be? how complicated would it be to write such a proposal?),
nothing diagnoses such code. But i really don't see why one would intentionally 
write that.
You have either forgot to assign/pass the result, or you wanted to cast to 
`void`.

Stage-2 self-hosting is green, no preparatory changes needed!


Repository:
  rC Clang

https://reviews.llvm.org/D45163

Files:
  docs/ReleaseNotes.rst
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/Sema/SemaStmt.cpp
  test/Analysis/MisusedMovedObject.cpp
  test/SemaCXX/warn-unused-result-nodiscard.cpp
  test/SemaCXX/warn-unused-xvalue.cpp

Index: test/SemaCXX/warn-unused-xvalue.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-unused-xvalue.cpp
@@ -0,0 +1,97 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// definitions for std::move
+namespace std {
+inline namespace foo {
+template 
+struct remove_reference { typedef T type; };
+template 
+struct remove_reference { typedef T type; };
+template 
+struct remove_reference { typedef T type; };
+
+template 
+typename remove_reference::type &&move(T &&t);
+} // namespace foo
+} // namespace std
+
+int f0();
+int &&f1();
+
+int global;
+
+void test_negative() {
+  // Ok. Should not warn
+  f0();
+  f1();
+
+  static_cast(f0()); // expected-warning {{expression result unused}}
+  static_cast(f1()); // expected-warning {{expression result unused}}
+
+  static_cast(global); // expected-warning {{expression result unused}}
+
+  (void)std::move(global);
+  (void)noexcept(std::move(global));
+  (void)sizeof(std::move(global));
+}
+
+// Unevaluated contexts should not trigger unused result warnings.
+template 
+auto foo(T) -> decltype(std::move(global), bool()) { // Should not warn.
+  return true;
+}
+
+void test_simple() {
+  int x = 1;
+
+  static_cast(x); // expected-warning {{ignoring return value of cast to rvalue reference of type 'int'}}
+  std::move(x);   // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+
+  using std::move;
+  move(x); // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+}
+
+void test_global() {
+  static_cast(global); // expected-warning {{ignoring return value of cast to rvalue reference of type 'int'}}
+  std::move(global);   // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+
+  using std::move;
+  move(global); // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+}
+
+void test_call() {
+  static_cast(f0());   // expected-warning {{ignoring return value of cast to rvalue reference of type 'int'}}
+  static_cast(f1());   // expected-warning {{ignoring return value of cast to rvalue reference of type 'int'}}
+  std::move(f0()); // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+  std::move(f1()); // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+
+  using std::move;
+  move(f0()); // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+  move(f1()); // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+}
+
+void arg(int a) {
+  static_cast(a); // expected-warning {{ignoring return value of cast to rvalue reference of type 'int'}}
+
+  std::move(a); // expected-warning {{ignoring return value of std::move() function returning rvalue reference of type 'int'}}
+}
+
+struct A {};
+struct B {
+  A a;
+};
+struct C {
+  C(){};
+  ~C() {}
+};
+void struct_test() {
+  A a;
+  std::move(a); // expected-warning{{ignoring return value of std::move() function returning rvalue reference of type 'A'}}
+
+  B b;
+  std::move(b);   // expected-warning{{ignoring return value of std::move() function returning rvalue reference of type 'B'}}
+  std::move(b.a); // expected-warning{{ignoring return value of std::move() function returning rvalue reference of type 'A'}}
+
+  C c;
+  std::move(c); // expected-warning{{ignoring return value of std::move() function returning rvalue reference of type 'C'}}
+}
Index: test/SemaCXX/warn-unused-result-nodiscard.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-unused-result-nodiscard.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+

[PATCH] D44906: [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

The test added here doesn't pass on Windows, and the change breaks another test 
on Windows: http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/9794


Repository:
  rL LLVM

https://reviews.llvm.org/D44906



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


[PATCH] D45161: [AST] Add new printing policy to suppress printing template arguments

2018-04-02 Thread Kalle Huttunen via Phabricator via cfe-commits
khuttun created this revision.
khuttun added reviewers: sepavloff, alexfh.
Herald added a subscriber: cfe-commits.

The purpose of this addition is to be able to write AST matchers that match 
class template member functions by fully qualified name, without the need to 
explicitly specify the template arguments in the name.

For example, to match the call to `S::f` here

  template 
  struct S {
void f();
  };
  
  void foo() {
S s;
s.f();
  }

the matcher currently needs to specify the template arguments:

  callExpr(callee(functionDecl(hasName("::S::f"

With the help of this change, it's possible to create a version of `hasName` 
that ignores the template arguments. The matcher could then be written as

  callExpr(callee(functionDecl(hasNameIgnoringTemplateArgs("::S::f"

The motivation for this change is to be able to add checking of class template 
member functions to clang-tidy checker bugprone-unused-return-value: 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-return-value.html

The discussion about this can be found in the code review for the checker: 
https://reviews.llvm.org/D41655?id=130461#inline-374438


Repository:
  rC Clang

https://reviews.llvm.org/D45161

Files:
  include/clang/AST/PrettyPrinter.h
  lib/AST/TypePrinter.cpp
  unittests/AST/NamedDeclPrinterTest.cpp

Index: unittests/AST/NamedDeclPrinterTest.cpp
===
--- unittests/AST/NamedDeclPrinterTest.cpp
+++ unittests/AST/NamedDeclPrinterTest.cpp
@@ -28,14 +28,19 @@
 
 namespace {
 
+using PrintingPolicyModifier = void (*)(PrintingPolicy &policy);
+
 class PrintMatch : public MatchFinder::MatchCallback {
   SmallString<1024> Printed;
   unsigned NumFoundDecls;
   bool SuppressUnwrittenScope;
+  PrintingPolicyModifier PolicyModifier;
 
 public:
-  explicit PrintMatch(bool suppressUnwrittenScope)
-: NumFoundDecls(0), SuppressUnwrittenScope(suppressUnwrittenScope) {}
+  explicit PrintMatch(bool suppressUnwrittenScope,
+  PrintingPolicyModifier PolicyModifier)
+  : NumFoundDecls(0), SuppressUnwrittenScope(suppressUnwrittenScope),
+PolicyModifier(PolicyModifier) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
 const NamedDecl *ND = Result.Nodes.getNodeAs("id");
@@ -48,6 +53,8 @@
 llvm::raw_svector_ostream Out(Printed);
 PrintingPolicy Policy = Result.Context->getPrintingPolicy();
 Policy.SuppressUnwrittenScope = SuppressUnwrittenScope;
+if (PolicyModifier)
+  PolicyModifier(Policy);
 ND->printQualifiedName(Out, Policy);
   }
 
@@ -64,8 +71,9 @@
 PrintedNamedDeclMatches(StringRef Code, const std::vector &Args,
 bool SuppressUnwrittenScope,
 const DeclarationMatcher &NodeMatch,
-StringRef ExpectedPrinted, StringRef FileName) {
-  PrintMatch Printer(SuppressUnwrittenScope);
+StringRef ExpectedPrinted, StringRef FileName,
+PrintingPolicyModifier PolicyModifier) {
+  PrintMatch Printer(SuppressUnwrittenScope, PolicyModifier);
   MatchFinder Finder;
   Finder.addMatcher(NodeMatch, &Printer);
   std::unique_ptr Factory =
@@ -94,26 +102,30 @@
 
 ::testing::AssertionResult
 PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
- StringRef ExpectedPrinted) {
+ StringRef ExpectedPrinted,
+ PrintingPolicyModifier PolicyModifier = nullptr) {
   std::vector Args(1, "-std=c++98");
   return PrintedNamedDeclMatches(Code,
  Args,
  /*SuppressUnwrittenScope*/ false,
  namedDecl(hasName(DeclName)).bind("id"),
  ExpectedPrinted,
- "input.cc");
+ "input.cc",
+ PolicyModifier);
 }
 
 ::testing::AssertionResult
-PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
-StringRef ExpectedPrinted) {
+PrintedWrittenNamedDeclCXX11Matches(
+StringRef Code, StringRef DeclName, StringRef ExpectedPrinted,
+PrintingPolicyModifier PolicyModifier = nullptr) {
   std::vector Args(1, "-std=c++11");
   return PrintedNamedDeclMatches(Code,
  Args,
  /*SuppressUnwrittenScope*/ true,
  namedDecl(hasName(DeclName)).bind("id"),
  ExpectedPrinted,
- "input.cc");
+ "input.cc",
+ PolicyModifier);
 }
 
 } // unnamed namespace
@@ -180,3 +192,20 @@
 "A",
 "X::A"));
 }
+
+TEST(NamedDeclPrinter, TestClassTemplateMemberFunction) {
+  ASSERT_TRUE(PrintedNamedDeclCXX98Matches(
+"template  struct 

[PATCH] D45160: [clang-apply-replacements] Make clang-apply-replacements installable

2018-04-02 Thread Zinovy Nis via Phabricator via cfe-commits
zinovy.nis created this revision.
Herald added subscribers: cfe-commits, mgorny.

Add a new target for install: **install-clang-apply-replacements**
So if you need clang-tidy and clang-apply-replacements tools only, you may 
build and install only these tools:

  make install-clang-tidy install-clang-apply-replacements


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45160

Files:
  clang-apply-replacements/tool/CMakeLists.txt


Index: clang-apply-replacements/tool/CMakeLists.txt
===
--- clang-apply-replacements/tool/CMakeLists.txt
+++ clang-apply-replacements/tool/CMakeLists.txt
@@ -2,7 +2,7 @@
   Support
   )
 
-add_clang_executable(clang-apply-replacements
+add_clang_tool(clang-apply-replacements
   ClangApplyReplacementsMain.cpp
   )
 target_link_libraries(clang-apply-replacements


Index: clang-apply-replacements/tool/CMakeLists.txt
===
--- clang-apply-replacements/tool/CMakeLists.txt
+++ clang-apply-replacements/tool/CMakeLists.txt
@@ -2,7 +2,7 @@
   Support
   )
 
-add_clang_executable(clang-apply-replacements
+add_clang_tool(clang-apply-replacements
   ClangApplyReplacementsMain.cpp
   )
 target_link_libraries(clang-apply-replacements
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43509: [libcxx][cmake] Remove libatomic temporarily from CMAKE_REQUIRED_LIBRARIES when configuring

2018-04-02 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

Ping.


Repository:
  rCXX libc++

https://reviews.llvm.org/D43509



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


[PATCH] D45149: MallocChecker, adding specific BSD calls

2018-04-02 Thread David CARLIER via Phabricator via cfe-commits
devnexen updated this revision to Diff 140607.
devnexen added a comment.

Using groups of functions.


https://reviews.llvm.org/D45149

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  test/Analysis/bsd-malloc.c

Index: test/Analysis/bsd-malloc.c
===
--- /dev/null
+++ test/Analysis/bsd-malloc.c
@@ -0,0 +1,28 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-openbsd -analyzer-checker=unix.Malloc -verify %s
+
+#define NULL  ((void *) 0)
+
+typedef __typeof(sizeof(int)) size_t;
+
+void *reallocarray(void *ptr, size_t nmemb, size_t size);
+void *recallocarray(void *ptr, size_t onmemb, size_t nmemb, size_t size);
+void freezero(void *ptr, size_t size);
+
+void f1() {
+  int *parr = NULL;
+  parr = reallocarray(NULL, 10, sizeof(*parr));
+  return; // expected-warning{{Potential leak of memory pointed to by 'parr'}}
+}
+
+void f2() {
+  int *parr = NULL;
+  parr = recallocarray(NULL, 10, 20, sizeof(*parr));
+  return; // expected-warning{{Potential leak of memory pointed to by 'parr'}}
+}
+
+void f3() {
+  int *parr = NULL;
+  parr = reallocarray(NULL, 10, sizeof(*parr));
+  freezero(parr, 10 * sizeof(*parr)); // expected-no-warning
+  freezero(parr, 10 * sizeof(*parr)); // expected-warning{{Attempt to free released memory}}
+}
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -171,18 +171,14 @@
 {
 public:
   MallocChecker()
-  : II_alloca(nullptr), II_win_alloca(nullptr), II_malloc(nullptr),
-II_free(nullptr), II_realloc(nullptr), II_calloc(nullptr),
-II_valloc(nullptr), II_reallocf(nullptr), II_strndup(nullptr),
-II_strdup(nullptr), II_win_strdup(nullptr), II_kmalloc(nullptr),
-II_if_nameindex(nullptr), II_if_freenameindex(nullptr),
-II_wcsdup(nullptr), II_win_wcsdup(nullptr), II_g_malloc(nullptr),
-II_g_malloc0(nullptr), II_g_realloc(nullptr), II_g_try_malloc(nullptr), 
-II_g_try_malloc0(nullptr), II_g_try_realloc(nullptr), 
-II_g_free(nullptr), II_g_memdup(nullptr), II_g_malloc_n(nullptr), 
-II_g_malloc0_n(nullptr), II_g_realloc_n(nullptr), 
-II_g_try_malloc_n(nullptr), II_g_try_malloc0_n(nullptr), 
-II_g_try_realloc_n(nullptr) {}
+  : II_kmalloc(nullptr), II_if_nameindex(nullptr),
+II_if_freenameindex(nullptr), II_valloc(nullptr),
+II_realloc(nullptr), II_calloc(nullptr),
+II_reallocarray(nullptr), II_recallocarray(nullptr),
+II_strndup(nullptr), II_g_memdup(nullptr),
+II_g_malloc0(nullptr), II_g_try_malloc0(nullptr),
+II_g_malloc0_n(nullptr), II_g_try_malloc0_n(nullptr),
+II_reallocf(nullptr), II_malloc(nullptr) {}
 
   /// In pessimistic mode, the checker assumes that it does not know which
   /// functions might free the memory.
@@ -242,18 +238,27 @@
   mutable std::unique_ptr BT_MismatchedDealloc;
   mutable std::unique_ptr BT_OffsetFree[CK_NumCheckKinds];
   mutable std::unique_ptr BT_UseZerroAllocated[CK_NumCheckKinds];
-  mutable IdentifierInfo *II_alloca, *II_win_alloca, *II_malloc, *II_free,
- *II_realloc, *II_calloc, *II_valloc, *II_reallocf,
- *II_strndup, *II_strdup, *II_win_strdup, *II_kmalloc,
- *II_if_nameindex, *II_if_freenameindex, *II_wcsdup,
- *II_win_wcsdup, *II_g_malloc, *II_g_malloc0, 
- *II_g_realloc, *II_g_try_malloc, *II_g_try_malloc0, 
- *II_g_try_realloc, *II_g_free, *II_g_memdup, 
- *II_g_malloc_n, *II_g_malloc0_n, *II_g_realloc_n, 
- *II_g_try_malloc_n, *II_g_try_malloc0_n, 
- *II_g_try_realloc_n;
   mutable Optional KernelZeroFlagVal;
 
+  mutable llvm::SmallSet AllocFunctions;
+  mutable llvm::SmallSet FreeFunctions;
+
+  mutable llvm::SmallSet AllocaFunctions;
+  mutable llvm::SmallSet SimpleMallocFunctions;
+
+  mutable llvm::SmallSet NZeroMallocFunctions;
+
+  mutable llvm::SmallSet NReallocFunctions;
+  mutable llvm::SmallSet ReallocFunctions;
+
+  mutable llvm::SmallSet StrdupFunctions;
+
+  mutable IdentifierInfo *II_kmalloc, *II_if_nameindex, *II_if_freenameindex,
+ *II_valloc, *II_realloc, *II_calloc, *II_reallocarray,
+ *II_recallocarray, *II_strndup, *II_g_memdup,
+ *II_g_malloc0, *II_g_try_malloc0, *II_g_malloc0_n,
+ *II_g_try_malloc0_n, *II_reallocf, *II_malloc;
+
   void initIdentifierInfo(ASTContext &C) const;
 
   /// \brief Determine family of a deallocation expression.
@@ -345,7 +350,8 @@
   ProgramStateRef ReallocMemAux(CheckerContext &C, const CallExpr *CE,
 bool FreesMemOnFailure,
 ProgramState

[PATCH] D45152: [MinGW] Add option for disabling looking for a mingw gcc in PATH

2018-04-02 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: include/clang/Driver/Options.td:1735
   MetaVarName<"">, Flags<[CC1Option]>;
+def ignore_gcc : Joined<["--"], "ignore-gcc">, Flags<[DriverOption]>,
+  HelpText<"Don't look for gcc for finding a suitable sysroot">;

Perhaps `--ignore-gcc-toolchain` would be better?


Repository:
  rC Clang

https://reviews.llvm.org/D45152



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


  1   2   >